194 lines
5.9 KiB
GDScript
194 lines
5.9 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
|
|
@onready var color_rect_4: ColorRect = $ResourceAllocation/ColorRect4
|
|
@onready var description_2: RichTextLabel = $ResourceAllocation/Description2
|
|
|
|
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 recent_data and 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({})
|
|
|
|
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:
|
|
description_2.text = "[center]STATUS: WORKING"
|
|
else:
|
|
description_2.text = "[center]STATUS: STOPPED"
|
|
|
|
if recent_data and recent_data.has("workers"):
|
|
description_3.text = "[center]EFFICIENCY: %d%%" % [recent_data.efficiency]
|
|
rich_text_label_2.text = "[center]%d/%d" % [recent_data.workers, recent_data.max_workers]
|
|
|
|
|
|
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:
|
|
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)
|
|
|
|
|
|
func _on_mouse_handler_hovered() -> void:
|
|
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)
|
|
|
|
|
|
func _on_mouse_handler_unhovered() -> void:
|
|
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)
|
|
|
|
|
|
func _on_mouse_handler_2_clicked() -> void:
|
|
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)
|
|
|
|
|
|
func _on_mouse_handler_2_hovered() -> void:
|
|
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)
|
|
|
|
|
|
func _on_mouse_handler_2_unhovered() -> void:
|
|
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)
|
|
|
|
|
|
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)
|