106 lines
4.2 KiB
GDScript
106 lines
4.2 KiB
GDScript
## 顶部信息栏 HUD(挂载于 TopBarHUD.tscn)。
|
|
## 显示资源(灵石/声望/灵米/灵气浓度)与时间,提供时间流速控制与返回主菜单入口。
|
|
extends Control
|
|
|
|
## 请求返回主菜单。
|
|
signal sign_return_mainmenu
|
|
## 请求打开弟子名录面板。
|
|
signal sign_open_disciples
|
|
## 请求打开建筑面板。
|
|
signal sign_open_buildings
|
|
## 请求打开存档面板。
|
|
signal sign_open_save
|
|
|
|
@onready var time_label: Label = %Value_Time
|
|
@onready var currency_label: Label = %Value_Currency
|
|
@onready var reputation_label: Label = %Value_Reputation
|
|
@onready var qi_label: Label = %Value_Qi
|
|
@onready var food_label: Label = %Value_Food
|
|
@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 := speed_buttons[i]
|
|
btn.toggle_mode = true
|
|
btn.button_up.connect(_on_speed_button_up.bind(i))
|
|
# 时间:每日推进时刷新日期
|
|
TimeSystem.day_passed.connect(_on_day_passed)
|
|
# 资源数值:信号仅在变化时触发,初始值需手动设置一次
|
|
SectManager.spirit_stones_changed.connect(_on_spirit_stones_changed)
|
|
SectManager.reputation_changed.connect(_on_reputation_changed)
|
|
SectManager.food_changed.connect(_on_food_changed)
|
|
currency_label.text = str(SectManager.spirit_stones)
|
|
reputation_label.text = str(SectManager.reputation)
|
|
food_label.text = str(SectManager.food)
|
|
# 灵气浓度:当前为配置固定值(D6 建筑系统接入后动态刷新)
|
|
qi_label.text = "%d%%" % roundi(GameConfig.qi_concentration * 100)
|
|
time_label.text = TimeSystem.get_date_text()
|
|
_apply_hud_font()
|
|
_update_speed_ui()
|
|
|
|
## 每日推进时刷新日期显示。
|
|
func _on_day_passed(_year: int, _month: int, _day: int) -> void:
|
|
time_label.text = TimeSystem.get_date_text()
|
|
|
|
## 灵石数量变化时刷新显示。
|
|
## @param new_value: 变化后的灵石总量
|
|
func _on_spirit_stones_changed(new_value: int, _delta: int) -> void:
|
|
currency_label.text = str(new_value)
|
|
|
|
## 声望变化时刷新显示。
|
|
## @param new_value: 变化后的声望总量
|
|
func _on_reputation_changed(new_value: int, _delta: int) -> void:
|
|
reputation_label.text = str(new_value)
|
|
|
|
## 灵米(食物)变化时刷新显示。
|
|
## @param new_value: 变化后的灵米总量
|
|
func _on_food_changed(new_value: int, _delta: int) -> void:
|
|
food_label.text = str(new_value)
|
|
|
|
## 点击"返回"按钮。
|
|
func _on_button_return_button_up() -> void:
|
|
sign_return_mainmenu.emit()
|
|
|
|
## 点击"管理"按钮:请求打开弟子名录面板(由 MainGame 处理)。
|
|
func _on_button_staff_management_button_up() -> void:
|
|
sign_open_disciples.emit()
|
|
|
|
## 点击"资源"按钮:请求打开建筑面板(由 MainGame 处理)。
|
|
func _on_button_resources_management_button_up() -> void:
|
|
sign_open_buildings.emit()
|
|
|
|
## 点击"存档"按钮:请求打开存档面板(由 MainGame 处理)。
|
|
func _on_button_save_button_up() -> void:
|
|
sign_open_save.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()
|
|
|
|
## 应用配置中的 HUD 字体大小(GameConfig.hud_font_size)。
|
|
## 标签共用同一 LabelSettings 资源,改一处全生效;按钮逐个覆盖。
|
|
func _apply_hud_font() -> void:
|
|
var size := GameConfig.hud_font_size
|
|
var settings: LabelSettings = $VBoxContainer/HBoxContainer3/HBoxContainer/VBoxContainer/HBoxContainer/Label_Currency.label_settings
|
|
if settings != null:
|
|
settings.font_size = size
|
|
for btn in $VBoxContainer.find_children("*", "Button", true, false):
|
|
btn.add_theme_font_size_override("font_size", size)
|
|
|
|
## 刷新速度组 UI:暂停按钮文字与各档位按下状态。
|
|
## 选中档位用 toggle 的 pressed 状态表达(原生高亮),暂停时禁用档位按钮。
|
|
func _update_speed_ui() -> void:
|
|
pause_button.text = "继续" if TimeSystem.paused else "暂停"
|
|
for i in speed_buttons.size():
|
|
var btn := speed_buttons[i]
|
|
btn.set_pressed_no_signal(i == TimeSystem.speed_index)
|
|
btn.disabled = TimeSystem.paused
|