checheche/Robo-Bus-A31-HMI/Modules/setting_tabs.gd

49 lines
1.7 KiB
GDScript

extends MarginContainer
@export var item1:String="default1"
@export var item2:String="default_2"
@export var normal_color:Color=Color("676767")
@export var select_color:Color=Color("FFFFFF")
#移动背景
@onready var texture_rect: TextureRect = $Control/TextureRect
#需要连接信号的节点数组
@export var nodearr : Array[Node]
signal Onclick(State:int)
var SelectNode = null:
set(value):
if value != SelectNode:
if SelectNode==null:
for i in nodearr:
i.get_node("item_name").add_theme_color_override("font_color",normal_color)
else:
SelectNode.get_node("item_name").add_theme_color_override("font_color",normal_color)
value.get_node("item_name").add_theme_color_override("font_color",select_color)
var tween = create_tween()
tween.parallel().tween_property(texture_rect, "global_position", value.global_position, 0.2).set_ease(Tween.EASE_OUT)
tween.parallel().tween_property(texture_rect,"size",value.size,0.2).set_ease(Tween.EASE_OUT)
SelectNode = value
var OnClickIsCooling = false:
set(value):
OnClickIsCooling = value
await get_tree().create_timer(0.2).timeout
OnClickIsCooling = false
func _ready() -> void:
$HBoxContainer/Item1/item_name.text=item1
$HBoxContainer/Item2/item_name.text=item2
await get_tree().create_timer(0.1).timeout
for i in nodearr:
i.get_node("item_name").add_theme_color_override("font_color",normal_color)
%Item1.get_node("item_name").add_theme_color_override("font_color",select_color)
for node : BaseControl in nodearr:
node.on_click.connect(func(_node):
if !OnClickIsCooling:
SelectNode = _node
OnClickIsCooling = true
Onclick.emit(_node.get_child(0).get_index())
)
pass # Replace with function body.