fix: 场景分组改代码注册,HUD 速度按钮改 toggle 模式

- MainGame 用 add_to_group 注册 game_scene,修复分组未生效导致时间不推进
- 速度按钮改用 toggle_mode + pressed 状态高亮,暂停时禁用
This commit is contained in:
2026-08-03 22:37:55 +08:00
parent b6c76d83d7
commit 1cbfd12574
2 changed files with 11 additions and 9 deletions
+3
View File
@@ -3,6 +3,9 @@
extends Node
func _ready() -> void:
# 注册为游戏世界场景(供 TimeSystem 判断是否推进时间)
add_to_group("game_scene")
# 应用用户设置中的默认流速
TimeSystem.apply_default_speed()
## 顶部 HUD 的返回主菜单请求。
+8 -9
View File
@@ -5,18 +5,15 @@ extends Control
## 请求返回主菜单。
signal sign_return_mainmenu
## 激活档位按钮颜色。
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():
speed_buttons[i].button_up.connect(_on_speed_button_up.bind(i))
var btn := speed_buttons[i]
btn.toggle_mode = true
btn.button_up.connect(_on_speed_button_up.bind(i))
TimeSystem.day_passed.connect(_on_day_passed)
_update_speed_ui()
time_label.text = TimeSystem.get_date_text()
@@ -40,9 +37,11 @@ func _on_speed_button_up(index: int) -> void:
TimeSystem.set_speed_index(index)
_update_speed_ui()
## 刷新速度组 UI:暂停按钮文字与各档位高亮状态。
## 刷新速度组 UI:暂停按钮文字与各档位按下状态。
## 选中档位用 toggle 的 pressed 状态表达(原生高亮),暂停时禁用档位按钮。
func _update_speed_ui() -> void:
pause_button.text = "继续" if TimeSystem.paused else "暂停"
for i in speed_buttons.size():
var active := (i == TimeSystem.speed_index) and not TimeSystem.paused
speed_buttons[i].modulate = ACTIVE_COLOR if active else INACTIVE_COLOR
var btn := speed_buttons[i]
btn.set_pressed_no_signal(i == TimeSystem.speed_index)
btn.disabled = TimeSystem.paused