brackeys-12/ui.gd

70 lines
2.3 KiB
GDScript3
Raw Normal View History

2024-09-15 02:50:11 +00:00
extends CanvasLayer
@onready var animation_player: AnimationPlayer = $AnimationPlayer
2024-09-15 07:29:19 +00:00
@onready var wood_count_label_2: Label = $UI/Background/Control3/WoodCountLabel2
2024-09-15 08:02:55 +00:00
@onready var restart: Control = $Restart
@onready var color_rect_2: ColorRect = $Restart/ColorRect2
2024-09-15 07:29:19 +00:00
var available_tween
2024-09-15 08:02:55 +00:00
var restart_tween
2024-09-15 02:50:11 +00:00
2024-09-15 03:23:38 +00:00
func _ready() -> void:
2024-09-15 04:25:59 +00:00
Persister.persist_data("wood", 50)
Persister.persist_data("stone", 50)
2024-09-15 03:43:31 +00:00
Persister.persist_data("population", 3)
2024-09-15 07:29:19 +00:00
Persister.persist_data("avail_population", 3)
2024-09-15 07:43:45 +00:00
Persister.persist_data("food", 10)
Persister.persist_data("water", 10)
2024-09-15 03:43:31 +00:00
Persister.persist_data("max_population", 3)
2024-09-15 07:29:19 +00:00
Triggerer.listen("show_info", _on_show_info)
Triggerer.listen("hide_info", _on_hide_info)
2024-09-15 02:50:11 +00:00
func _process(delta: float) -> void:
if Input.is_action_just_pressed("lclick") and not Persister.get_value("game_started"):
Persister.persist_data("game_started", true)
animation_player.play("start")
2024-09-15 07:29:19 +00:00
wood_count_label_2.text = "%d available" % [Persister.get_value("avail_population")]
2024-09-15 08:02:55 +00:00
if Input.is_action_just_pressed("restart"):
if restart_tween:
restart_tween.kill()
restart_tween = create_tween()
restart_tween.set_parallel()
restart_tween.tween_property(restart, "modulate", Color.WHITE, 0.5)
restart_tween.tween_property(color_rect_2, "scale:x", 1, 1).set_delay(0.1)
restart_tween.chain()
restart_tween.tween_callback(func():
Persister.clear_category(PersisterEnums.Scope.RUN)
get_tree().change_scene_to_packed(preload("res://Main.tscn"))
)
if Input.is_action_just_released("restart"):
if restart_tween:
restart_tween.kill()
restart_tween = create_tween()
restart_tween.set_parallel()
restart_tween.tween_property(color_rect_2, "scale:x", 0, 1)
restart_tween.tween_property(restart, "modulate", Color.TRANSPARENT, 0.5)
2024-09-15 07:29:19 +00:00
func _on_show_info(_data):
if available_tween:
available_tween.kill()
available_tween = create_tween()
available_tween.set_ease(Tween.EASE_OUT)
available_tween.set_trans(Tween.TRANS_BACK)
available_tween.tween_property(wood_count_label_2, "scale", Vector2.ONE, 0.5)
func _on_hide_info(_data):
if available_tween:
available_tween.kill()
available_tween = create_tween()
available_tween.set_ease(Tween.EASE_OUT)
available_tween.set_trans(Tween.TRANS_QUAD)
available_tween.tween_property(wood_count_label_2, "scale", Vector2.ZERO, 0.5)