brackeys-12/info_window.gd

239 lines
7.2 KiB
GDScript3
Raw Permalink Normal View History

2024-09-12 02:04:24 +00:00
extends Control
2024-09-14 00:09:38 +00:00
var window_tween
2024-09-14 01:02:26 +00:00
@onready var icon: TextureRect = $Icon
@onready var title: RichTextLabel = $Title
@onready var subtitle: RichTextLabel = $Subtitle
@onready var description: RichTextLabel = $Description
2024-09-15 06:15:37 +00:00
@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
2024-09-15 07:29:19 +00:00
@onready var color_rect_4: ColorRect = $ResourceAllocation/ColorRect4
@onready var description_2: RichTextLabel = $ResourceAllocation/Description2
2024-09-24 00:36:55 +00:00
@onready var color_rect_6: ColorRect = $ColorRect6
2024-09-14 01:02:26 +00:00
2024-09-15 06:15:37 +00:00
var recent_data
var close_tween
var minus_tween
var plus_tween
2024-09-24 00:36:55 +00:00
var destroy_tween
2024-09-12 02:04:24 +00:00
func _ready() -> void:
2024-09-14 00:09:38 +00:00
Triggerer.listen("show_info", _show_info_window)
Triggerer.listen("hide_info", _hide_info_window)
2024-09-14 00:20:51 +00:00
scale = Vector2.ZERO
2024-09-15 06:15:37 +00:00
Triggerer.listen("flood_level", _on_flood_level)
func _on_flood_level(data):
var value = int(data.value)
2024-09-15 07:29:19 +00:00
if recent_data and value >= recent_data.level:
2024-09-15 06:15:37 +00:00
Triggerer.trigger("hide_info")
2024-09-14 00:09:38 +00:00
func _show_info_window(data):
visible = true
2024-09-14 22:01:46 +00:00
var building_data = Data.data.buildings[data.key]
2024-09-14 01:02:26 +00:00
2024-09-14 00:09:38 +00:00
if window_tween:
window_tween.kill()
window_tween = create_tween()
2024-09-14 01:02:26 +00:00
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]
2024-09-15 06:15:37 +00:00
icon.texture = Data.data.images[data.key]
2024-09-24 00:36:55 +00:00
subtitle.text = "[center]%s" % [building_data.short if building_data.has("short") else ""]
2024-09-15 06:15:37 +00:00
if data.has("workers"):
rich_text_label_2.text = "[center]%d/%d" % [data.workers, data.max_workers]
2024-09-15 07:29:19 +00:00
description_3.text = "[center]EFFICIENCY: %d%%" % [data.efficiency]
2024-09-15 06:15:37 +00:00
resource_allocation.visible = true
else:
resource_allocation.visible = false
recent_data = data
2024-09-14 01:02:26 +00:00
)
2024-09-14 00:09:38 +00:00
window_tween.set_ease(Tween.EASE_OUT)
window_tween.set_trans(Tween.TRANS_BACK)
2024-09-14 00:20:51 +00:00
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({})
2024-09-15 07:29:19 +00:00
if recent_data and recent_data.has("progress"):
color_rect_4.scale.x = (float(recent_data.progress) / Data.data.buildings[recent_data.key].time)
if recent_data and recent_data.has("workers") and recent_data.workers > 0:
2024-09-24 01:07:44 +00:00
if recent_data.efficiency == 0:
description_2.text = "[center]STATUS: NO RESOURCES"
else:
description_2.text = "[center]STATUS: WORKING"
2024-09-15 07:29:19 +00:00
else:
description_2.text = "[center]STATUS: STOPPED"
2024-09-15 09:22:08 +00:00
if recent_data and recent_data.has("workers"):
2024-09-15 07:29:19 +00:00
description_3.text = "[center]EFFICIENCY: %d%%" % [recent_data.efficiency]
2024-09-15 08:02:55 +00:00
rich_text_label_2.text = "[center]%d/%d" % [recent_data.workers, recent_data.max_workers]
2024-09-15 07:29:19 +00:00
2024-09-12 02:04:24 +00:00
2024-09-14 00:09:38 +00:00
func _hide_info_window(_data):
if window_tween:
window_tween.kill()
window_tween = create_tween()
2024-09-14 00:20:51 +00:00
window_tween.set_ease(Tween.EASE_IN)
window_tween.set_trans(Tween.TRANS_QUAD)
window_tween.tween_property(self, "scale", Vector2.ZERO, 0.25)
2024-09-15 06:15:37 +00:00
func _on_mouse_handler_clicked() -> void:
2024-09-15 07:29:19 +00:00
if recent_data.workers > 0:
recent_data.workers -= 1
Persister.change_value("avail_population", 1)
rich_text_label_2.text = "[center]%d/%d" % [recent_data.workers, recent_data.max_workers]
if minus_tween:
minus_tween.kill()
minus_tween = create_tween()
minus_tween.set_trans(Tween.TRANS_QUAD)
minus_tween.tween_property(color_rect_2, "scale", Vector2.ONE * 0.95, 0.125)
minus_tween.tween_property(color_rect_2, "scale", Vector2.ONE, 0.125)
2024-09-15 06:15:37 +00:00
func _on_mouse_handler_hovered() -> void:
2024-09-15 07:29:19 +00:00
if minus_tween:
minus_tween.kill()
minus_tween = create_tween()
minus_tween.set_ease(Tween.EASE_OUT)
minus_tween.set_trans(Tween.TRANS_BACK)
minus_tween.tween_property(color_rect_2, "scale", Vector2.ONE * 1.05, 0.25)
2024-09-15 06:15:37 +00:00
func _on_mouse_handler_unhovered() -> void:
2024-09-15 07:29:19 +00:00
if minus_tween:
minus_tween.kill()
minus_tween = create_tween()
minus_tween.set_ease(Tween.EASE_OUT)
minus_tween.set_trans(Tween.TRANS_QUAD)
minus_tween.tween_property(color_rect_2, "scale", Vector2.ONE, 0.25)
2024-09-15 06:15:37 +00:00
func _on_mouse_handler_2_clicked() -> void:
2024-09-15 07:29:19 +00:00
if recent_data.workers < recent_data.max_workers and Persister.get_value("avail_population") > 0:
recent_data.workers += 1
Persister.change_value("avail_population", -1)
rich_text_label_2.text = "[center]%d/%d" % [recent_data.workers, recent_data.max_workers]
if plus_tween:
plus_tween.kill()
plus_tween = create_tween()
plus_tween.set_trans(Tween.TRANS_QUAD)
plus_tween.tween_property(color_rect_3, "scale", Vector2.ONE * 0.95, 0.125)
plus_tween.tween_property(color_rect_3, "scale", Vector2.ONE, 0.125)
2024-09-15 06:15:37 +00:00
func _on_mouse_handler_2_hovered() -> void:
2024-09-15 07:29:19 +00:00
if plus_tween:
plus_tween.kill()
plus_tween = create_tween()
plus_tween.set_ease(Tween.EASE_OUT)
plus_tween.set_trans(Tween.TRANS_BACK)
plus_tween.tween_property(color_rect_3, "scale", Vector2.ONE * 1.05, 0.25)
2024-09-15 06:15:37 +00:00
func _on_mouse_handler_2_unhovered() -> void:
2024-09-15 07:29:19 +00:00
if plus_tween:
plus_tween.kill()
plus_tween = create_tween()
plus_tween.set_ease(Tween.EASE_OUT)
plus_tween.set_trans(Tween.TRANS_QUAD)
plus_tween.tween_property(color_rect_3, "scale", Vector2.ONE, 0.25)
2024-09-15 06:15:37 +00:00
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)
2024-09-24 00:36:55 +00:00
func _on_destroy_handler_clicked() -> void:
Triggerer.trigger("destroy", {"tile": recent_data.coords})
Triggerer.trigger("hide_info")
var data = Data.data.buildings[recent_data.key]
if data.has("cost"):
for key in data.cost:
Persister.change_value(key, ceil(data.cost[key]/2))
if destroy_tween:
destroy_tween.kill()
destroy_tween = create_tween()
destroy_tween.set_trans(Tween.TRANS_QUAD)
destroy_tween.tween_property(color_rect_6, "scale", Vector2.ONE * 0.95, 0.125)
destroy_tween.tween_property(color_rect_6, "scale", Vector2.ONE, 0.125)
func _on_destroy_handler_hovered() -> void:
if destroy_tween:
destroy_tween.kill()
destroy_tween = create_tween()
destroy_tween.set_ease(Tween.EASE_OUT)
destroy_tween.set_trans(Tween.TRANS_BACK)
destroy_tween.tween_property(color_rect_6, "scale", Vector2.ONE * 1.05, 0.25)
func _on_destroy_handler_unhovered() -> void:
if close_tween:
close_tween.kill()
destroy_tween = create_tween()
destroy_tween.set_ease(Tween.EASE_OUT)
destroy_tween.set_trans(Tween.TRANS_QUAD)
destroy_tween.tween_property(color_rect_6, "scale", Vector2.ONE, 0.25)