39 lines
1.2 KiB
GDScript
39 lines
1.2 KiB
GDScript
extends TextureRect
|
|
class_name MenuOption
|
|
|
|
signal pressed
|
|
|
|
# Original modulate to return to after hover
|
|
var _original_modulate: Color
|
|
|
|
func _ready():
|
|
# Make this texture rect clickable
|
|
mouse_filter = Control.MOUSE_FILTER_STOP
|
|
|
|
# Save original modulate color
|
|
_original_modulate = modulate
|
|
|
|
# Connect the gui_input signal to our own handler
|
|
connect("gui_input", Callable(self, "_on_gui_input"))
|
|
|
|
# Connect hover signals for better user experience
|
|
connect("mouse_entered", Callable(self, "_on_mouse_entered"))
|
|
connect("mouse_exited", Callable(self, "_on_mouse_exited"))
|
|
|
|
func _on_gui_input(event):
|
|
if event is InputEventMouseButton:
|
|
if event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
|
|
emit_signal("pressed")
|
|
get_viewport().set_input_as_handled()
|
|
|
|
func _on_mouse_entered():
|
|
# Change appearance when mouse hovers
|
|
modulate = Color(1.2, 1.2, 0.8) # Slight yellowish tint and brightening
|
|
|
|
# Optional: Add a hover sound effect
|
|
# if has_node("/root/SoundManager"):
|
|
# get_node("/root/SoundManager").play_hover_sound()
|
|
|
|
func _on_mouse_exited():
|
|
# Restore original appearance
|
|
modulate = _original_modulate
|