LargeScreen/Modules/StateChangeButtonItem.gd
2024-12-19 19:13:12 +08:00

42 lines
831 B
GDScript

extends Button
@export var TextureNormal:Texture2D
@export var TextureNormalHigh:Texture2D
@export var TextureSelected:Texture2D
@export var TextureSelectedHigh:Texture2D
signal self_click(is_selected:bool)
var is_select:bool=false:
set(value):
if value:
$TextureRect.texture=TextureSelected
else:
$TextureRect.texture=TextureNormal
is_select=value
func _ready() -> void:
self.focus_mode=Control.FOCUS_NONE
self.button_down.connect(_button_down)
self.button_up.connect(_button_up)
func _button_down():
if is_select:
$TextureRect.texture=TextureSelectedHigh
else:
$TextureRect.texture=TextureNormalHigh
func _button_up():
if is_select:
$TextureRect.texture=TextureSelected
else:
$TextureRect.texture=TextureNormal
pass
func _pressed():
is_select=!is_select
self_click.emit(is_select)
pass