From 10ac0f9f808fe979314e0f8418e48943587480f0 Mon Sep 17 00:00:00 2001
From: myin <minyin142p@gmail.com>
Date: Sat, 19 Aug 2023 12:11:30 +0200
Subject: [PATCH] feat: add ui opening animations

---
 godot/src/menu/store/Store.gd   |  18 ++--
 godot/src/menu/store/store.tscn |  60 ++++++++++++-
 godot/src/start.gd              |  13 ++-
 godot/src/start.tscn            | 147 +++++++++++++++++++++++++++++++-
 4 files changed, 225 insertions(+), 13 deletions(-)

diff --git a/godot/src/menu/store/Store.gd b/godot/src/menu/store/Store.gd
index e2f10d7..7f6bb8a 100644
--- a/godot/src/menu/store/Store.gd
+++ b/godot/src/menu/store/Store.gd
@@ -7,21 +7,27 @@ extends Control
 @onready var store_container := $PanelContainer
 @onready var anim := $AnimationPlayer
 
+@onready var store_pos = store_container.position
+
 var showing_showcase = false
 
 func _ready():
-	store_container.hide()
-	showcase.hide()
+	anim.play("RESET")
 	
 	for child in pack_container.get_children():
 		child.pressed.connect(func(): _unpack_gacha(child))
 
 func _on_store_pressed():
-	if store_container.visible:
-		store_container.hide()
-		showcase.hide()
+	if anim.is_playing():
+		return
+	
+	if store_container.position.y < 0:
+		anim.play("show_store")
+		print("show")
 	else:
-		store_container.show()
+		anim.play_backwards("show_store")
+		print("hide")
+
 
 func _unpack_gacha(pack: GachaPack):
 	if GameManager.points.use_points(pack.price):
diff --git a/godot/src/menu/store/store.tscn b/godot/src/menu/store/store.tscn
index 44fd7c6..df63356 100644
--- a/godot/src/menu/store/store.tscn
+++ b/godot/src/menu/store/store.tscn
@@ -1,4 +1,4 @@
-[gd_scene load_steps=9 format=3 uid="uid://djrft25koko4s"]
+[gd_scene load_steps=10 format=3 uid="uid://djrft25koko4s"]
 
 [ext_resource type="Script" path="res://src/menu/store/Store.gd" id="1_vq516"]
 [ext_resource type="PackedScene" uid="uid://hbh72ag1wvh" path="res://src/menu/store/gacha_pack.tscn" id="2_4wsp4"]
@@ -44,6 +44,30 @@ tracks/2/keys = {
 "update": 0,
 "values": [Vector2(1e-05, 1e-05)]
 }
+tracks/3/type = "value"
+tracks/3/imported = false
+tracks/3/enabled = true
+tracks/3/path = NodePath("PanelContainer:position")
+tracks/3/interp = 1
+tracks/3/loop_wrap = true
+tracks/3/keys = {
+"times": PackedFloat32Array(0),
+"transitions": PackedFloat32Array(1),
+"update": 0,
+"values": [Vector2(149, -1500)]
+}
+tracks/4/type = "value"
+tracks/4/imported = false
+tracks/4/enabled = true
+tracks/4/path = NodePath("PanelContainer:visible")
+tracks/4/interp = 1
+tracks/4/loop_wrap = true
+tracks/4/keys = {
+"times": PackedFloat32Array(0),
+"transitions": PackedFloat32Array(1),
+"update": 1,
+"values": [true]
+}
 
 [sub_resource type="Animation" id="Animation_anq1q"]
 resource_name = "showcase"
@@ -85,9 +109,38 @@ tracks/2/keys = {
 "values": [Vector2(1e-05, 1e-05), Vector2(1, 1)]
 }
 
+[sub_resource type="Animation" id="Animation_giphs"]
+resource_name = "show_store"
+length = 0.5
+tracks/0/type = "value"
+tracks/0/imported = false
+tracks/0/enabled = true
+tracks/0/path = NodePath("PanelContainer:position")
+tracks/0/interp = 2
+tracks/0/loop_wrap = true
+tracks/0/keys = {
+"times": PackedFloat32Array(0, 0.5),
+"transitions": PackedFloat32Array(3, 1),
+"update": 0,
+"values": [Vector2(149, -1500), Vector2(149, 265)]
+}
+tracks/1/type = "value"
+tracks/1/imported = false
+tracks/1/enabled = true
+tracks/1/path = NodePath("PanelContainer:visible")
+tracks/1/interp = 1
+tracks/1/loop_wrap = true
+tracks/1/keys = {
+"times": PackedFloat32Array(0),
+"transitions": PackedFloat32Array(1),
+"update": 1,
+"values": [true]
+}
+
 [sub_resource type="AnimationLibrary" id="AnimationLibrary_y30a3"]
 _data = {
 "RESET": SubResource("Animation_pkyus"),
+"show_store": SubResource("Animation_giphs"),
 "showcase": SubResource("Animation_anq1q")
 }
 
@@ -108,6 +161,10 @@ layout_mode = 1
 anchors_preset = 15
 anchor_right = 1.0
 anchor_bottom = 1.0
+offset_left = 149.0
+offset_top = -1500.0
+offset_right = -149.0
+offset_bottom = -2030.0
 grow_horizontal = 2
 grow_vertical = 2
 
@@ -148,6 +205,7 @@ layout_mode = 2
 texture_normal = ExtResource("3_eipe8")
 
 [node name="Showcase" type="Control" parent="."]
+visible = false
 layout_mode = 1
 anchors_preset = 15
 anchor_right = 1.0
diff --git a/godot/src/start.gd b/godot/src/start.gd
index 77fd178..54b0d3f 100644
--- a/godot/src/start.gd
+++ b/godot/src/start.gd
@@ -1,26 +1,33 @@
 extends Control
 
 @export var selectables: Control
+@export var select_container: Control
 
 @onready var bgm := $BGM
 @onready var start_sound := $StartSound
 
 @onready var piece_select := $PieceSelect
+@onready var anim := $AnimationPlayer
 
 func _ready():
-	piece_select.hide()
+	anim.play("RESET")
 	GameManager.game_started.connect(_on_game_start)
 
 func _on_game_start():
-	selectables.close()
 	create_tween().tween_property(bgm, "volume_db", -50, 1.0).set_trans(Tween.TRANS_CUBIC)
 	start_sound.play()
 
 func _on_play_pressed():
-	piece_select.show()
+	select_container.pivot_offset = select_container.size / 2
+	anim.play("show_pieces")
 
 func _on_check_energy_timer_timeout():
 	GameManager.energy.restore()
 
 func _on_start_pressed():
 	GameManager.start_game()
+
+func _on_piece_select_on_hide():
+	anim.play_backwards("show_pieces")
+	await anim.animation_finished
+	piece_select.hide()
diff --git a/godot/src/start.tscn b/godot/src/start.tscn
index a97e8bf..2a5c2e0 100644
--- a/godot/src/start.tscn
+++ b/godot/src/start.tscn
@@ -1,4 +1,4 @@
-[gd_scene load_steps=19 format=3 uid="uid://qdwfqb2qwrxb"]
+[gd_scene load_steps=22 format=3 uid="uid://qdwfqb2qwrxb"]
 
 [ext_resource type="Theme" uid="uid://cvvavdkxk7llv" path="res://theme/theme.tres" id="1_rg8bf"]
 [ext_resource type="Script" path="res://src/start.gd" id="2_af8bd"]
@@ -30,7 +30,130 @@ shader_parameter/background = SubResource("GradientTexture2D_jd218")
 [sub_resource type="LabelSettings" id="LabelSettings_pco7m"]
 font_size = 72
 
-[node name="Start" type="Control" node_paths=PackedStringArray("selectables")]
+[sub_resource type="Animation" id="Animation_20ldf"]
+resource_name = "show_pieces"
+length = 0.5
+tracks/0/type = "value"
+tracks/0/imported = false
+tracks/0/enabled = true
+tracks/0/path = NodePath("PieceSelect:visible")
+tracks/0/interp = 1
+tracks/0/loop_wrap = true
+tracks/0/keys = {
+"times": PackedFloat32Array(0),
+"transitions": PackedFloat32Array(1),
+"update": 1,
+"values": [true]
+}
+tracks/1/type = "value"
+tracks/1/imported = false
+tracks/1/enabled = true
+tracks/1/path = NodePath("PieceSelect/PieceSelect:scale")
+tracks/1/interp = 2
+tracks/1/loop_wrap = true
+tracks/1/keys = {
+"times": PackedFloat32Array(0, 0.5),
+"transitions": PackedFloat32Array(3, 3),
+"update": 0,
+"values": [Vector2(1e-05, 1e-05), Vector2(1, 1)]
+}
+tracks/2/type = "value"
+tracks/2/imported = false
+tracks/2/enabled = true
+tracks/2/path = NodePath("PieceSelect/Blocker:visible")
+tracks/2/interp = 1
+tracks/2/loop_wrap = true
+tracks/2/keys = {
+"times": PackedFloat32Array(0, 0.4, 0.5),
+"transitions": PackedFloat32Array(1, 1, 1),
+"update": 1,
+"values": [true, true, false]
+}
+tracks/3/type = "value"
+tracks/3/imported = false
+tracks/3/enabled = true
+tracks/3/path = NodePath("PieceSelect/Selectables:visible")
+tracks/3/interp = 1
+tracks/3/loop_wrap = true
+tracks/3/keys = {
+"times": PackedFloat32Array(0),
+"transitions": PackedFloat32Array(1),
+"update": 1,
+"values": [false]
+}
+tracks/4/type = "method"
+tracks/4/imported = false
+tracks/4/enabled = true
+tracks/4/path = NodePath("PieceSelect/Selectables")
+tracks/4/interp = 1
+tracks/4/loop_wrap = true
+tracks/4/keys = {
+"times": PackedFloat32Array(0.5),
+"transitions": PackedFloat32Array(1),
+"values": [{
+"args": [],
+"method": &"close"
+}]
+}
+
+[sub_resource type="Animation" id="Animation_0sthp"]
+length = 0.001
+tracks/0/type = "value"
+tracks/0/imported = false
+tracks/0/enabled = true
+tracks/0/path = NodePath("PieceSelect:visible")
+tracks/0/interp = 1
+tracks/0/loop_wrap = true
+tracks/0/keys = {
+"times": PackedFloat32Array(0),
+"transitions": PackedFloat32Array(1),
+"update": 1,
+"values": [false]
+}
+tracks/1/type = "value"
+tracks/1/imported = false
+tracks/1/enabled = true
+tracks/1/path = NodePath("PieceSelect/PieceSelect:scale")
+tracks/1/interp = 1
+tracks/1/loop_wrap = true
+tracks/1/keys = {
+"times": PackedFloat32Array(0),
+"transitions": PackedFloat32Array(1),
+"update": 0,
+"values": [Vector2(1e-05, 1e-05)]
+}
+tracks/2/type = "value"
+tracks/2/imported = false
+tracks/2/enabled = true
+tracks/2/path = NodePath("PieceSelect/Blocker:visible")
+tracks/2/interp = 1
+tracks/2/loop_wrap = true
+tracks/2/keys = {
+"times": PackedFloat32Array(0),
+"transitions": PackedFloat32Array(1),
+"update": 1,
+"values": [true]
+}
+tracks/3/type = "value"
+tracks/3/imported = false
+tracks/3/enabled = true
+tracks/3/path = NodePath("PieceSelect/Selectables:visible")
+tracks/3/interp = 1
+tracks/3/loop_wrap = true
+tracks/3/keys = {
+"times": PackedFloat32Array(0),
+"transitions": PackedFloat32Array(1),
+"update": 1,
+"values": [false]
+}
+
+[sub_resource type="AnimationLibrary" id="AnimationLibrary_j8rit"]
+_data = {
+"RESET": SubResource("Animation_0sthp"),
+"show_pieces": SubResource("Animation_20ldf")
+}
+
+[node name="Start" type="Control" node_paths=PackedStringArray("selectables", "select_container")]
 layout_mode = 3
 anchors_preset = 15
 anchor_right = 1.0
@@ -40,6 +163,7 @@ grow_vertical = 2
 theme = ExtResource("1_rg8bf")
 script = ExtResource("2_af8bd")
 selectables = NodePath("PieceSelect/Selectables")
+select_container = NodePath("PieceSelect/PieceSelect")
 
 [node name="ColorRect" type="ColorRect" parent="."]
 material = SubResource("ShaderMaterial_7ekah")
@@ -115,7 +239,11 @@ layout_mode = 2
 disabled = true
 text = "Store"
 
+[node name="Store" parent="." instance=ExtResource("14_6p00d")]
+layout_mode = 1
+
 [node name="PieceSelect" type="Control" parent="."]
+visible = false
 layout_mode = 1
 anchors_preset = 15
 anchor_right = 1.0
@@ -124,6 +252,7 @@ grow_horizontal = 2
 grow_vertical = 2
 theme = ExtResource("1_rg8bf")
 script = ExtResource("9_qgams")
+external = true
 
 [node name="PieceSelect" type="PanelContainer" parent="PieceSelect"]
 custom_minimum_size = Vector2(0, 100)
@@ -137,6 +266,7 @@ offset_top = -50.0
 offset_bottom = 50.0
 grow_horizontal = 2
 grow_vertical = 2
+scale = Vector2(1e-05, 1e-05)
 
 [node name="MarginContainer" type="MarginContainer" parent="PieceSelect/PieceSelect"]
 layout_mode = 2
@@ -179,8 +309,13 @@ size_flags_horizontal = 3
 size_flags_vertical = 4
 alignment = 1
 
-[node name="Store" parent="." instance=ExtResource("14_6p00d")]
+[node name="Blocker" type="Control" parent="PieceSelect"]
 layout_mode = 1
+anchors_preset = 15
+anchor_right = 1.0
+anchor_bottom = 1.0
+grow_horizontal = 2
+grow_vertical = 2
 
 [node name="CheckEnergyTimer" type="Timer" parent="."]
 autostart = true
@@ -194,7 +329,13 @@ autoplay = true
 stream = ExtResource("8_5k2wf")
 volume_db = -15.0
 
+[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
+libraries = {
+"": SubResource("AnimationLibrary_j8rit")
+}
+
 [connection signal="pressed" from="Menu/VBoxContainer/Play" to="." method="_on_play_pressed"]
 [connection signal="hidden" from="PieceSelect" to="PieceSelect/Selectables" method="close"]
+[connection signal="on_hide" from="PieceSelect" to="." method="_on_piece_select_on_hide"]
 [connection signal="pressed" from="PieceSelect/PieceSelect/MarginContainer/VBoxContainer/Start" to="." method="_on_start_pressed"]
 [connection signal="timeout" from="CheckEnergyTimer" to="." method="_on_check_energy_timer_timeout"]