50 lines
1.9 KiB
GDScript
50 lines
1.9 KiB
GDScript
## 顶部信息栏 HUD(挂载于 TopBarHUD.tscn)。
|
|
## 显示灵石/时间/声望,提供时间流速控制与返回主菜单入口。
|
|
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)
|
|
|
|
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))
|
|
TimeSystem.day_passed.connect(_on_day_passed)
|
|
_update_speed_ui()
|
|
$HBoxContainer/Value_Time.text = TimeSystem.get_date_text()
|
|
|
|
## 每日推进时刷新日期显示。
|
|
func _on_day_passed(_year: int, _month: int, _day: int) -> void:
|
|
$HBoxContainer/Value_Time.text = TimeSystem.get_date_text()
|
|
|
|
## 点击"返回"按钮。
|
|
func _on_button_return_button_up() -> void:
|
|
sign_return_mainmenu.emit()
|
|
|
|
## 点击暂停/继续按钮,切换后刷新按钮状态。
|
|
func _on_button_pause_button_up() -> void:
|
|
TimeSystem.toggle_pause()
|
|
_update_speed_ui()
|
|
|
|
## 点击流速档位按钮。
|
|
## @param index: 目标档位索引(由 _ready 中 bind 传入)
|
|
func _on_speed_button_up(index: int) -> void:
|
|
TimeSystem.set_speed_index(index)
|
|
_update_speed_ui()
|
|
|
|
## 刷新速度组 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])
|
|
var active := (i == TimeSystem.speed_index) and not TimeSystem.paused
|
|
btn.modulate = ACTIVE_COLOR if active else INACTIVE_COLOR
|