brackeys-12/ui/building_icon.gd

64 lines
1.6 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-12 02:40:54 +00:00
@onready var texture_rect: TextureRect = $TextureRect
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
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)
hover_tween.tween_property(self, "scale", Vector2.ONE * 0.95, 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)
hover_tween.tween_property(self, "scale", Vector2.ONE * 1.05, 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)
hover_tween.tween_property(self, "scale", Vector2.ONE, 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)
hover_tween.tween_property(self, "scale", Vector2.ONE, 0.25)