brackeys-12/info_window.gd
2024-09-15 02:15:37 -04:00

134 lines
3.6 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
@onready var rich_text_label_2: RichTextLabel = $ResourceAllocation/RichTextLabel2
@onready var resource_allocation: Control = $ResourceAllocation
@onready var description_3: RichTextLabel = $ResourceAllocation/Description3
@onready var color_rect_5: ColorRect = $ColorRect5
@onready var color_rect_2: ColorRect = $ResourceAllocation/ColorRect2
@onready var color_rect_3: ColorRect = $ResourceAllocation/ColorRect3
var recent_data
var close_tween
var minus_tween
var plus_tween
func _ready() -> void:
Triggerer.listen("show_info", _show_info_window)
Triggerer.listen("hide_info", _hide_info_window)
scale = Vector2.ZERO
Triggerer.listen("flood_level", _on_flood_level)
func _on_flood_level(data):
var value = int(data.value)
if value >= recent_data.level:
Triggerer.trigger("hide_info")
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]
icon.texture = Data.data.images[data.key]
subtitle.text = "[center]%s" % [building_data.short]
if data.has("workers"):
rich_text_label_2.text = "[center]%d/%d" % [data.workers, data.max_workers]
description_3.text = "[center]EFFICIENCY: %d%" % [data.efficiency]
resource_allocation.visible = true
else:
resource_allocation.visible = false
recent_data = data
)
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)
func _on_mouse_handler_clicked() -> void:
pass # Replace with function body.
func _on_mouse_handler_hovered() -> void:
pass # Replace with function body.
func _on_mouse_handler_unhovered() -> void:
pass # Replace with function body.
func _on_mouse_handler_2_clicked() -> void:
pass # Replace with function body.
func _on_mouse_handler_2_hovered() -> void:
pass # Replace with function body.
func _on_mouse_handler_2_unhovered() -> void:
pass # Replace with function body.
func _on_mouse_handler_3_clicked() -> void:
Triggerer.trigger("hide_info")
if close_tween:
close_tween.kill()
close_tween = create_tween()
close_tween.set_trans(Tween.TRANS_QUAD)
close_tween.tween_property(color_rect_5, "scale", Vector2.ONE * 0.95, 0.125)
close_tween.tween_property(color_rect_5, "scale", Vector2.ONE, 0.125)
func _on_mouse_handler_3_hovered() -> void:
if close_tween:
close_tween.kill()
close_tween = create_tween()
close_tween.set_ease(Tween.EASE_OUT)
close_tween.set_trans(Tween.TRANS_BACK)
close_tween.tween_property(color_rect_5, "scale", Vector2.ONE * 1.05, 0.25)
func _on_mouse_handler_3_unhovered() -> void:
if close_tween:
close_tween.kill()
close_tween = create_tween()
close_tween.set_ease(Tween.EASE_OUT)
close_tween.set_trans(Tween.TRANS_QUAD)
close_tween.tween_property(color_rect_5, "scale", Vector2.ONE, 0.25)