mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-06-27 17:42:04 +08:00
@@ -114,7 +114,6 @@ class WifiButton(BigButton):
|
||||
self._network_missing = False
|
||||
self._network_forgetting = False
|
||||
self._wrong_password = False
|
||||
self._shake_start: float | None = None
|
||||
|
||||
def update_network(self, network: Network):
|
||||
self._network = network
|
||||
@@ -144,7 +143,7 @@ class WifiButton(BigButton):
|
||||
|
||||
def set_wrong_password(self):
|
||||
self._wrong_password = True
|
||||
self._shake_start = rl.get_time()
|
||||
self.trigger_shake()
|
||||
|
||||
@property
|
||||
def network(self) -> Network:
|
||||
@@ -165,20 +164,6 @@ class WifiButton(BigButton):
|
||||
def _get_label_font_size(self):
|
||||
return 48
|
||||
|
||||
@property
|
||||
def _shake_offset(self) -> float:
|
||||
SHAKE_DURATION = 0.5
|
||||
SHAKE_AMPLITUDE = 24.0
|
||||
SHAKE_FREQUENCY = 32.0
|
||||
t = rl.get_time() - (self._shake_start or 0.0)
|
||||
if t > SHAKE_DURATION:
|
||||
return 0.0
|
||||
decay = 1.0 - t / SHAKE_DURATION
|
||||
return decay * SHAKE_AMPLITUDE * math.sin(t * SHAKE_FREQUENCY)
|
||||
|
||||
def set_position(self, x: float, y: float) -> None:
|
||||
super().set_position(x + self._shake_offset, y)
|
||||
|
||||
def _draw_content(self, btn_y: float):
|
||||
self._label.set_color(LABEL_COLOR)
|
||||
label_rect = rl.Rectangle(self._rect.x + self.LABEL_PADDING, btn_y + LABEL_VERTICAL_PADDING,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import math
|
||||
import pyray as rl
|
||||
from typing import Union
|
||||
from enum import Enum
|
||||
@@ -115,6 +116,7 @@ class BigButton(Widget):
|
||||
self.set_icon(icon)
|
||||
|
||||
self._scale_filter = BounceFilter(1.0, 0.1, 1 / gui_app.target_fps)
|
||||
self._shake_start: float | None = None
|
||||
|
||||
self._rotate_icon_t: float | None = None
|
||||
|
||||
@@ -174,6 +176,23 @@ class BigButton(Widget):
|
||||
def get_text(self):
|
||||
return self.text
|
||||
|
||||
def trigger_shake(self):
|
||||
self._shake_start = rl.get_time()
|
||||
|
||||
@property
|
||||
def _shake_offset(self) -> float:
|
||||
SHAKE_DURATION = 0.5
|
||||
SHAKE_AMPLITUDE = 24.0
|
||||
SHAKE_FREQUENCY = 32.0
|
||||
t = rl.get_time() - (self._shake_start or 0.0)
|
||||
if t > SHAKE_DURATION:
|
||||
return 0.0
|
||||
decay = 1.0 - t / SHAKE_DURATION
|
||||
return decay * SHAKE_AMPLITUDE * math.sin(t * SHAKE_FREQUENCY)
|
||||
|
||||
def set_position(self, x: float, y: float) -> None:
|
||||
super().set_position(x + self._shake_offset, y)
|
||||
|
||||
def _draw_content(self, btn_y: float):
|
||||
# LABEL ------------------------------------------------------------------
|
||||
label_x = self._rect.x + LABEL_HORIZONTAL_PADDING
|
||||
|
||||
Reference in New Issue
Block a user