add ui opening and closing animations

This commit is contained in:
Teatov 2024-10-21 13:09:38 +10:00
parent fc7cb75b23
commit 852e718a77
7 changed files with 102 additions and 2 deletions

View File

@ -90,3 +90,7 @@ toggle_confinement={
3d_physics/layer_2="units"
3d_physics/layer_3="Layer 3"
3d_physics/layer_9="items"
[rendering]
anti_aliasing/quality/msaa_3d=2

View File

@ -49,6 +49,7 @@ offset_right = 80.0
offset_bottom = 55.5
grow_horizontal = 2
grow_vertical = 2
pivot_offset = Vector2(81, 54.5)
theme_override_styles/panel = SubResource("StyleBoxTexture_k576p")
[node name="QuitButton" type="TextureButton" parent="Panel"]

View File

@ -41,6 +41,7 @@ func open(at: Anthill) -> void:
_anthill = at
set_target(_anthill.ui_origin)
counter.initialize(_anthill.honeydew, _anthill.max_honeydew)
_open_animation()
func close() -> void:

View File

@ -55,6 +55,7 @@ func open(at: Anthill) -> void:
)
set_target(_anthill.ui_origin)
counter.initialize(_anthill.honeydew, _anthill.max_honeydew)
_open_animation()
func close() -> void:

View File

@ -1,7 +1,11 @@
extends Control
class_name CloseableUI
const OPEN_TWEEN_DURATION: float = 0.5
const CLOSE_TWEEN_DURATION: float = 0.25
var _is_mouse_over: bool = false
var _tween: Tween
func _ready() -> void:
@ -28,4 +32,32 @@ func _input(event: InputEvent) -> void:
func close() -> void:
await _close_animation()
visible = false
func _open_animation() -> void:
if _tween:
_tween.stop()
scale = Vector2.ZERO
_tween = create_tween()
await (
_tween
.tween_property(self, "scale", Vector2.ONE, OPEN_TWEEN_DURATION)
.set_ease(Tween.EASE_OUT)
.set_trans(Tween.TRANS_ELASTIC)
.finished
)
func _close_animation() -> void:
if _tween:
_tween.stop()
scale = Vector2.ONE
_tween = create_tween()
await (
_tween
.tween_property(self, "scale", Vector2.ZERO, CLOSE_TWEEN_DURATION)
.set_ease(Tween.EASE_IN)
.set_trans(Tween.TRANS_BACK)
.finished
)

View File

@ -1,8 +1,16 @@
extends Panel
class_name PauseMenu
const OPEN_TWEEN_DURATION: float = 0.5
const CLOSE_TWEEN_DURATION: float = 0.25
var _tween: Tween
@onready var cancel_button: BaseButton = $Panel/CancelButton
@onready var quit_button: BaseButton = $Panel/QuitButton
@onready var panel: Control = $Panel
@onready var controls_info: Control = $ControlsInfo
@onready var _controls_info_pos: Vector2 = controls_info.position
func _ready() -> void:
@ -20,11 +28,13 @@ func _input(event: InputEvent) -> void:
else:
visible = true
get_tree().paused = true
_open_animation()
func _close() -> void:
visible = false
get_tree().paused = false
await _close_animation()
visible = false
func _on_cancel_button_pressed() -> void:
@ -35,3 +45,53 @@ func _on_cancel_button_pressed() -> void:
func _on_quit_button_pressed() -> void:
print("quit")
get_tree().quit()
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
)
func _close_animation() -> void:
if _tween:
_tween.stop()
panel.scale = Vector2.ONE
controls_info.position = _controls_info_pos
_tween = create_tween()
_tween.set_pause_mode(Tween.TWEEN_PAUSE_PROCESS)
(
_tween
.tween_property(
controls_info,
"position",
Vector2(_controls_info_pos.x, 1080),
CLOSE_TWEEN_DURATION,
)
.set_ease(Tween.EASE_IN)
.set_trans(Tween.TRANS_BACK)
)
await (
_tween
.parallel()
.tween_property(panel, "scale", Vector2.ZERO, CLOSE_TWEEN_DURATION)
.set_ease(Tween.EASE_IN)
.set_trans(Tween.TRANS_BACK)
.finished
)

View File

@ -45,6 +45,7 @@ func open(who: Unit) -> void:
visible = true
unit = who
set_target(unit.ui_origin)
_open_animation()
func close() -> void: