feat: 实现时间流动完整逻辑并同步 HUD 显示
- TimeSystem 支持月/年进位,仅游戏场景推进 - HUD 时间标签订阅 day_passed 实时更新 - 新游戏时重置年月日
This commit is contained in:
+23
-6
@@ -3,25 +3,36 @@ extends Node
|
||||
signal day_passed(year, month, day)
|
||||
|
||||
const SPEEDS := [1.0, 5.0, 20.0]
|
||||
var speed_index := 0
|
||||
const DAYS_PER_MONTH := 30
|
||||
const MONTHS_PER_YEAR := 12
|
||||
|
||||
const DAY_LENGTH := 5.0
|
||||
var speed_index := 0
|
||||
const DAY_LENGTH := 0.5
|
||||
var speed := 1.0
|
||||
var paused := false
|
||||
var _elapsed := 0.0
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if paused:
|
||||
if paused or not _is_in_game():
|
||||
return
|
||||
_elapsed += delta * speed
|
||||
if _elapsed >= DAY_LENGTH:
|
||||
_elapsed -= DAY_LENGTH
|
||||
_advance()
|
||||
|
||||
func _is_in_game() -> bool:
|
||||
var scene := get_tree().current_scene
|
||||
return scene != null and scene.name == "MainGame"
|
||||
|
||||
func _advance() -> void:
|
||||
# GameState.year, GameState.month, GameState.day 推进
|
||||
GameState.day = GameState.day + 1;
|
||||
day_passed.emit()
|
||||
GameState.day += 1
|
||||
if GameState.day > DAYS_PER_MONTH:
|
||||
GameState.day = 1
|
||||
GameState.month += 1
|
||||
if GameState.month > MONTHS_PER_YEAR:
|
||||
GameState.month = 1
|
||||
GameState.year += 1
|
||||
day_passed.emit(GameState.year, GameState.month, GameState.day)
|
||||
|
||||
func cycle_speed() -> float:
|
||||
speed_index = (speed_index + 1) % SPEEDS.size()
|
||||
@@ -38,3 +49,9 @@ func toggle_pause() -> bool:
|
||||
|
||||
func get_speed_label() -> String:
|
||||
return "x%d" % int(speed)
|
||||
|
||||
func get_current_date() -> Array:
|
||||
return [GameState.year, GameState.month, GameState.day]
|
||||
|
||||
func get_date_text() -> String:
|
||||
return "%d年 %d月 %d日" % [GameState.year, GameState.month, GameState.day]
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
[sub_resource type="LabelSettings" id="LabelSettings_bn2o5"]
|
||||
font = ExtResource("1_pa2rn")
|
||||
font_size = 32
|
||||
|
||||
[node name="TopBarHud" type="Control" unique_id=1115394694]
|
||||
layout_mode = 3
|
||||
@@ -46,6 +47,7 @@ label_settings = SubResource("LabelSettings_bn2o5")
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 8
|
||||
size_flags_stretch_ratio = 2.0
|
||||
label_settings = SubResource("LabelSettings_bn2o5")
|
||||
|
||||
[node name="Label_Reputation" type="Label" parent="HBoxContainer" unique_id=985110673]
|
||||
|
||||
@@ -10,7 +10,12 @@ 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()
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
extends Control
|
||||
|
||||
func MainMenu_NewGame_ButtonUp() -> void:
|
||||
GameState.request_new_game()
|
||||
get_tree().change_scene_to_file("res://src/Core/MainGame.tscn")
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
func MainMenu_LoadGame_ButtonUp() -> void:
|
||||
|
||||
Reference in New Issue
Block a user