challenge-editor/scene/select_button.gd
2024-09-11 22:50:02 +08:00

30 lines
1.0 KiB
GDScript

extends Button
const SELECTED = preload("res://res/ui/ui_003_select/selected.tres")
const UNSELECTED = preload("res://res/ui/ui_003_select/unselected.tres")
var id:String=""
var is_selected:bool=false:
set(val):
if is_selected!=val:
match val:
true:
var tween=get_tree().create_tween()
add_theme_stylebox_override("normal",SELECTED)
add_theme_stylebox_override("pressed",SELECTED)
add_theme_stylebox_override("hover",SELECTED)
add_theme_stylebox_override("hover_pressed",SELECTED)
z_index+=1
tween.tween_property(self, "custom_minimum_size:x", 385, 0.2)
pass
false:
var tween=get_tree().create_tween()
add_theme_stylebox_override("normal",UNSELECTED)
add_theme_stylebox_override("pressed",UNSELECTED)
add_theme_stylebox_override("hover",UNSELECTED)
add_theme_stylebox_override("hover_pressed",UNSELECTED)
z_index-=1
tween.tween_property(self, "custom_minimum_size:x", 320, 0.2)
pass
is_selected=val
func set_texture(texture:Texture2D):
$TextureRect.texture=texture