brackeys-12/ui/building_icon.gd

104 lines
3.2 KiB
GDScript3
Raw Normal View History

2024-09-12 02:40:54 +00:00
extends ColorRect
2024-09-14 00:09:38 +00:00
var key
var clicked = false
2024-09-15 05:37:02 +00:00
@export var left = false
2024-09-14 00:09:38 +00:00
2024-09-12 02:40:54 +00:00
@onready var texture_rect: TextureRect = $TextureRect
2024-09-15 05:37:02 +00:00
@onready var rich_text_label: RichTextLabel = $ColorRect/RichTextLabel
@onready var rich_text_label_2: RichTextLabel = $ColorRect/RichTextLabel2
@onready var rich_text_label_3: RichTextLabel = $ColorRect/RichTextLabel3
@onready var rich_text_label_4: RichTextLabel = $ColorRect/RichTextLabel4
@onready var color_rect: ColorRect = $ColorRect
2024-09-14 00:09:38 +00:00
2024-09-15 01:09:17 +00:00
var hover_tween
2024-09-14 00:09:38 +00:00
2024-09-15 05:37:02 +00:00
func _ready() -> void:
if left:
color_rect.position += Vector2(20, 0)
func _created():
var data = Data.data.buildings[key]
rich_text_label.text = "[center][smallwave]%s" % [data.name]
rich_text_label_2.text = "[center]%s" % [data.short]
if data.cost.has("wood") and data.cost.has("stone"):
rich_text_label_3.text = "[center]%s stone" % [data.cost.stone]
rich_text_label_3.modulate = Color.html("#425a67")
rich_text_label_4.modulate = Color.html("#884244")
rich_text_label_4.text = "[center]%s wood" % [data.cost.wood]
elif data.cost.has("wood"):
rich_text_label_3.text = "[center]%s wood" % [data.cost.wood]
rich_text_label_4.text = ""
rich_text_label_3.modulate = Color.html("#884244")
else:
rich_text_label_3.text = "[center]%s stone" % [data.cost.stone]
rich_text_label_4.text = ""
rich_text_label_3.modulate = Color.html("#425a67")
2024-09-14 00:09:38 +00:00
func _on_mouse_handler_clicked() -> void:
clicked = true
2024-09-15 01:09:17 +00:00
if hover_tween:
hover_tween.kill()
hover_tween = create_tween()
hover_tween.set_ease(Tween.EASE_OUT)
hover_tween.set_trans(Tween.TRANS_BACK)
2024-09-15 05:37:02 +00:00
hover_tween.set_parallel()
2024-09-15 01:09:17 +00:00
hover_tween.tween_property(self, "scale", Vector2.ONE * 0.95, 0.25)
2024-09-15 05:37:02 +00:00
hover_tween.tween_property(color_rect, "scale", Vector2.ONE, 0.25)
2024-09-14 00:09:38 +00:00
func _on_mouse_handler_hovered() -> void:
2024-09-15 01:09:17 +00:00
if hover_tween:
hover_tween.kill()
hover_tween = create_tween()
hover_tween.set_ease(Tween.EASE_OUT)
hover_tween.set_trans(Tween.TRANS_BACK)
2024-09-15 05:37:02 +00:00
hover_tween.set_parallel()
2024-09-15 01:09:17 +00:00
hover_tween.tween_property(self, "scale", Vector2.ONE * 1.05, 0.25)
2024-09-15 05:37:02 +00:00
hover_tween.tween_property(color_rect, "scale", Vector2.ONE, 0.25)
2024-09-14 00:09:38 +00:00
func _on_mouse_handler_unhovered() -> void:
if clicked:
2024-09-14 22:01:46 +00:00
#Triggerer.trigger("drag_building", { "key": key })
Persister.persist_data("drag_mode", true)
Persister.persist_data("building_mode", true)
Persister.persist_data("building_key", key)
2024-09-14 00:09:38 +00:00
clicked = false
2024-09-15 01:09:17 +00:00
if hover_tween:
hover_tween.kill()
hover_tween = create_tween()
hover_tween.set_ease(Tween.EASE_OUT)
hover_tween.set_trans(Tween.TRANS_QUAD)
2024-09-15 05:37:02 +00:00
hover_tween.set_parallel()
2024-09-15 01:09:17 +00:00
hover_tween.tween_property(self, "scale", Vector2.ONE, 0.25)
2024-09-15 05:37:02 +00:00
hover_tween.tween_property(color_rect, "scale", Vector2.ZERO, 0.25)
2024-09-14 00:09:38 +00:00
func _on_mouse_handler_released() -> void:
if clicked:
2024-09-14 22:01:46 +00:00
#Triggerer.trigger("select_building", { "key": key })
Persister.persist_data("drag_mode", false)
Persister.persist_data("building_mode", true)
Persister.persist_data("building_key", key)
2024-09-14 00:09:38 +00:00
clicked = false
2024-09-15 01:09:17 +00:00
if hover_tween:
hover_tween.kill()
hover_tween = create_tween()
hover_tween.set_ease(Tween.EASE_OUT)
hover_tween.set_trans(Tween.TRANS_BACK)
2024-09-15 05:37:02 +00:00
hover_tween.set_parallel()
2024-09-15 01:09:17 +00:00
hover_tween.tween_property(self, "scale", Vector2.ONE, 0.25)
2024-09-15 05:37:02 +00:00
hover_tween.tween_property(color_rect, "scale", Vector2.ZERO, 0.25)