diff --git a/src/Core/MainGame.tscn b/src/Core/MainGame.tscn index c740df3..020596b 100644 --- a/src/Core/MainGame.tscn +++ b/src/Core/MainGame.tscn @@ -4,6 +4,7 @@ [ext_resource type="PackedScene" uid="uid://dl0tb68vsw3c6" path="res://src/UI/HUD/TopBarHUD.tscn" id="1_g6xmk"] [node name="MainGame" type="Node" unique_id=2053561265] +groups = ["game_scene"] script = ExtResource("1_8bu23") [node name="TopBarHud" parent="." unique_id=1115394694 instance=ExtResource("1_g6xmk")] diff --git a/src/Core/TimeSystem.gd b/src/Core/TimeSystem.gd index 7823c6f..6fa76fe 100644 --- a/src/Core/TimeSystem.gd +++ b/src/Core/TimeSystem.gd @@ -51,9 +51,10 @@ func _process(delta: float) -> void: ## 判断当前场景是否为游戏世界场景(主菜单/存档界面不推进时间)。 +## 通过 "game_scene" 分组识别,而非场景名。 func _is_in_game() -> bool: var scene := get_tree().current_scene - return scene != null and scene.name == "MainGame" + return scene != null and scene.is_in_group("game_scene") ## 推进一日并广播对应信号,跨月/跨年时补发 month_passed / year_passed。 diff --git a/src/UI/HUD/TopBarHUD.tscn b/src/UI/HUD/TopBarHUD.tscn index b8b54c6..6cf5ea0 100644 --- a/src/UI/HUD/TopBarHUD.tscn +++ b/src/UI/HUD/TopBarHUD.tscn @@ -49,6 +49,7 @@ size_flags_horizontal = 3 size_flags_vertical = 8 size_flags_stretch_ratio = 2.0 label_settings = SubResource("LabelSettings_bn2o5") +unique_name_in_owner = true [node name="Label_Reputation" type="Label" parent="HBoxContainer" unique_id=985110673] layout_mode = 2 @@ -74,6 +75,7 @@ layout_mode = 2 theme_override_fonts/font = ExtResource("1_pa2rn") theme_override_font_sizes/font_size = 32 text = "暂停" +unique_name_in_owner = true [node name="Button_Speed1" type="Button" parent="HBoxContainer/SpeedGroup" unique_id=2144893128] custom_minimum_size = Vector2(48, 0) @@ -81,6 +83,7 @@ layout_mode = 2 theme_override_fonts/font = ExtResource("1_pa2rn") theme_override_font_sizes/font_size = 32 text = "1x" +unique_name_in_owner = true [node name="Button_Speed5" type="Button" parent="HBoxContainer/SpeedGroup" unique_id=2144893129] custom_minimum_size = Vector2(48, 0) @@ -88,6 +91,7 @@ layout_mode = 2 theme_override_fonts/font = ExtResource("1_pa2rn") theme_override_font_sizes/font_size = 32 text = "5x" +unique_name_in_owner = true [node name="Button_Speed20" type="Button" parent="HBoxContainer/SpeedGroup" unique_id=2144893130] custom_minimum_size = Vector2(48, 0) @@ -95,6 +99,7 @@ layout_mode = 2 theme_override_fonts/font = ExtResource("1_pa2rn") theme_override_font_sizes/font_size = 32 text = "20x" +unique_name_in_owner = true [node name="placeholder_1" type="Label" parent="HBoxContainer" unique_id=1042446504] layout_mode = 2 diff --git a/src/UI/HUD/top_bar_hud.gd b/src/UI/HUD/top_bar_hud.gd index 74f0991..ba3d628 100644 --- a/src/UI/HUD/top_bar_hud.gd +++ b/src/UI/HUD/top_bar_hud.gd @@ -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