add button animations and refactor ui animation functions

This commit is contained in:
2024-10-21 13:35:56 +10:00
parent 852e718a77
commit c40d2de56b
7 changed files with 123 additions and 47 deletions

View File

@@ -48,32 +48,41 @@ func _on_quit_button_pressed() -> void:
func _open_animation() -> void:
if _tween:
_tween.stop()
panel.scale = Vector2.ZERO
controls_info.position = Vector2(_controls_info_pos.x, 1080)
_tween = create_tween()
_tween.set_pause_mode(Tween.TWEEN_PAUSE_PROCESS)
(
_tween
.tween_property(controls_info, "position", _controls_info_pos, OPEN_TWEEN_DURATION)
.set_ease(Tween.EASE_OUT)
.set_trans(Tween.TRANS_ELASTIC)
)
await (
_tween
.parallel()
.tween_property(panel, "scale", Vector2.ONE, OPEN_TWEEN_DURATION)
.set_ease(Tween.EASE_OUT)
.set_trans(Tween.TRANS_ELASTIC)
.finished
await _animate(
Vector2.ZERO,
Vector2(_controls_info_pos.x, 1080),
Vector2.ONE,
_controls_info_pos,
OPEN_TWEEN_DURATION,
Tween.EASE_OUT,
Tween.TRANS_ELASTIC,
)
func _close_animation() -> void:
await _animate(
Vector2.ONE,
_controls_info_pos,
Vector2.ZERO,
Vector2(_controls_info_pos.x, 1080),
CLOSE_TWEEN_DURATION,
Tween.EASE_IN,
Tween.TRANS_BACK,
)
func _animate(
panel_scale_init: Vector2,
controls_info_pos_init: Vector2,
panel_scale_new: Vector2,
controls_info_pos_new: Vector2,
duration: float,
ease_type: Tween.EaseType,
trans_type: Tween.TransitionType,
) -> void:
if _tween:
_tween.stop()
panel.scale = Vector2.ONE
controls_info.position = _controls_info_pos
panel.scale = panel_scale_init
controls_info.position = controls_info_pos_init
_tween = create_tween()
_tween.set_pause_mode(Tween.TWEEN_PAUSE_PROCESS)
(
@@ -81,17 +90,17 @@ func _close_animation() -> void:
.tween_property(
controls_info,
"position",
Vector2(_controls_info_pos.x, 1080),
CLOSE_TWEEN_DURATION,
controls_info_pos_new,
duration,
)
.set_ease(Tween.EASE_IN)
.set_trans(Tween.TRANS_BACK)
.set_ease(ease_type)
.set_trans(trans_type)
)
await (
_tween
.parallel()
.tween_property(panel, "scale", Vector2.ZERO, CLOSE_TWEEN_DURATION)
.set_ease(Tween.EASE_IN)
.set_trans(Tween.TRANS_BACK)
.tween_property(panel, "scale", panel_scale_new, duration)
.set_ease(ease_type)
.set_trans(trans_type)
.finished
)
)