brackeys-12/info_window.gd
2024-09-13 21:02:26 -04:00

50 lines
1.3 KiB
GDScript

extends Control
var window_tween
@onready var icon: TextureRect = $Icon
@onready var title: RichTextLabel = $Title
@onready var subtitle: RichTextLabel = $Subtitle
@onready var description: RichTextLabel = $Description
func _ready() -> void:
Triggerer.listen("show_info", _show_info_window)
Triggerer.listen("hide_info", _hide_info_window)
scale = Vector2.ZERO
func _show_info_window(data):
visible = true
var building_data = Data.data.buildings[data.Key]
if window_tween:
window_tween.kill()
window_tween = create_tween()
window_tween.set_ease(Tween.EASE_IN)
window_tween.set_trans(Tween.TRANS_QUAD)
window_tween.tween_property(self, "scale", Vector2.ZERO, 0.25)
window_tween.tween_callback(func():
title.text = "[center]%s" % [building_data.name]
)
window_tween.set_ease(Tween.EASE_OUT)
window_tween.set_trans(Tween.TRANS_BACK)
window_tween.tween_property(self, "scale", Vector2.ONE, 0.5)
func _process(delta: float) -> void:
if Input.is_action_just_pressed("rclick"):
_hide_info_window({})
func _hide_info_window(_data):
if window_tween:
window_tween.kill()
window_tween = create_tween()
window_tween.set_ease(Tween.EASE_IN)
window_tween.set_trans(Tween.TRANS_QUAD)
window_tween.tween_property(self, "scale", Vector2.ZERO, 0.25)