refactor: HUD 节点改用唯一名称引用,场景识别改用分组

- TopBarHUD 用 @onready + % 唯一名称替代硬编码路径
- TimeSystem 用 game_scene 分组替代场景名字符串比较
This commit is contained in:
2026-08-03 22:33:40 +08:00
parent 476834176c
commit b6c76d83d7
4 changed files with 19 additions and 13 deletions
+11 -12
View File
@@ -5,24 +5,25 @@ extends Control
## 请求返回主菜单。
signal sign_return_mainmenu
## 三个流速按钮的节点名(与 tscn 中的 SpeedGroup 子节点对应)。
const SPEED_BUTTONS := ["Button_Speed1", "Button_Speed5", "Button_Speed20"]
## 激活档位按钮颜色。
const ACTIVE_COLOR := Color(1.0, 1.0, 1.0)
## 未激活档位按钮颜色。
const INACTIVE_COLOR := Color(0.55, 0.55, 0.55)
@onready var time_label: Label = %Value_Time
@onready var pause_button: Button = %Button_Pause
@onready var speed_buttons: Array[Button] = [%Button_Speed1, %Button_Speed5, %Button_Speed20]
func _ready() -> void:
for i in SPEED_BUTTONS.size():
var btn: Button = $HBoxContainer/SpeedGroup.get_node(SPEED_BUTTONS[i])
btn.button_up.connect(_on_speed_button_up.bind(i))
for i in speed_buttons.size():
speed_buttons[i].button_up.connect(_on_speed_button_up.bind(i))
TimeSystem.day_passed.connect(_on_day_passed)
_update_speed_ui()
$HBoxContainer/Value_Time.text = TimeSystem.get_date_text()
time_label.text = TimeSystem.get_date_text()
## 每日推进时刷新日期显示。
func _on_day_passed(_year: int, _month: int, _day: int) -> void:
$HBoxContainer/Value_Time.text = TimeSystem.get_date_text()
time_label.text = TimeSystem.get_date_text()
## 点击"返回"按钮。
func _on_button_return_button_up() -> void:
@@ -41,9 +42,7 @@ func _on_speed_button_up(index: int) -> void:
## 刷新速度组 UI:暂停按钮文字与各档位高亮状态。
func _update_speed_ui() -> void:
var pause_btn: Button = $HBoxContainer/SpeedGroup/Button_Pause
pause_btn.text = "继续" if TimeSystem.paused else "暂停"
for i in SPEED_BUTTONS.size():
var btn: Button = $HBoxContainer/SpeedGroup.get_node(SPEED_BUTTONS[i])
pause_button.text = "继续" if TimeSystem.paused else "暂停"
for i in speed_buttons.size():
var active := (i == TimeSystem.speed_index) and not TimeSystem.paused
btn.modulate = ACTIVE_COLOR if active else INACTIVE_COLOR
speed_buttons[i].modulate = ACTIVE_COLOR if active else INACTIVE_COLOR