2024-09-12 02:04:24 +00:00
|
|
|
extends TextureRect
|
|
|
|
|
|
|
|
signal clicked
|
|
|
|
|
|
|
|
@export var key: String = "production"
|
|
|
|
@export var text: String = "Resource"
|
|
|
|
@export var width: float = 66
|
|
|
|
|
|
|
|
@onready var rich_text_label: RichTextLabel = $RichTextLabel
|
|
|
|
@onready var collision_shape_2d: CollisionShape2D = $MouseHandler/CollisionShape2D
|
|
|
|
|
2024-09-15 01:09:17 +00:00
|
|
|
var text_tween
|
|
|
|
|
2024-09-12 02:04:24 +00:00
|
|
|
func _ready() -> void:
|
|
|
|
rich_text_label.text = "[center]%s" % [text]
|
|
|
|
custom_minimum_size.x = width
|
|
|
|
|
|
|
|
collision_shape_2d.shape = RectangleShape2D.new()
|
|
|
|
collision_shape_2d.shape.size = Vector2(width - 20, 10)
|
|
|
|
collision_shape_2d.position.x = 33 - ((66 - width) / 2)
|
|
|
|
|
|
|
|
|
|
|
|
func _on_mouse_handler_clicked() -> void:
|
|
|
|
clicked.emit()
|
2024-09-15 01:09:17 +00:00
|
|
|
|
|
|
|
if text_tween:
|
|
|
|
text_tween.kill()
|
|
|
|
|
|
|
|
text_tween = create_tween()
|
|
|
|
text_tween.set_ease(Tween.EASE_OUT)
|
|
|
|
text_tween.set_trans(Tween.TRANS_BACK)
|
|
|
|
text_tween.tween_property(rich_text_label, "scale", Vector2.ONE * 0.95, 0.25)
|
|
|
|
text_tween.set_trans(Tween.TRANS_QUAD)
|
|
|
|
text_tween.tween_property(rich_text_label, "scale", Vector2.ONE, 0.05)
|
|
|
|
|
2024-09-12 02:04:24 +00:00
|
|
|
|
|
|
|
func select():
|
|
|
|
rich_text_label.self_modulate = Color(1, 1, 1, 1)
|
2024-09-15 01:09:17 +00:00
|
|
|
self_modulate = Color(1, 1, 1, 0.784)
|
2024-09-12 02:04:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
func unselect():
|
|
|
|
rich_text_label.self_modulate = Color(1, 1, 1, 0.4)
|
2024-09-15 01:09:17 +00:00
|
|
|
self_modulate = Color(1, 1, 1, 0.4)
|
|
|
|
|
|
|
|
|
|
|
|
func _on_mouse_handler_hovered() -> void:
|
|
|
|
if text_tween:
|
|
|
|
text_tween.kill()
|
|
|
|
|
|
|
|
text_tween = create_tween()
|
|
|
|
text_tween.set_ease(Tween.EASE_OUT)
|
|
|
|
text_tween.set_trans(Tween.TRANS_BACK)
|
|
|
|
text_tween.tween_property(rich_text_label, "scale", Vector2.ONE * 1.02, 0.25)
|
|
|
|
|
|
|
|
|
|
|
|
func _on_mouse_handler_unhovered() -> void:
|
|
|
|
if text_tween:
|
|
|
|
text_tween.kill()
|
|
|
|
|
|
|
|
text_tween = create_tween()
|
|
|
|
text_tween.set_ease(Tween.EASE_OUT)
|
|
|
|
text_tween.set_trans(Tween.TRANS_QUAD)
|
|
|
|
text_tween.tween_property(rich_text_label, "scale", Vector2.ONE, 0.05)
|