feat: HUD 增加时间流速控制,新增 Settings 持久化
- 顶栏改为暂停/1x/5x/20x 按钮组,当前档位高亮 - TimeSystem 支持暂停与档位切换 - 新增 Settings 单例,存档默认流速并开机应用 - GameState 补充年月日,支持 12x30 历法推进
This commit is contained in:
@@ -18,6 +18,7 @@ config/features=PackedStringArray("4.7", "Forward Plus")
|
||||
|
||||
GameState="*res://src/Core/GameState.gd"
|
||||
TimeSystem="*res://src/Core/TimeSystem.gd"
|
||||
Settings="*res://src/Core/Settings.gd"
|
||||
|
||||
[display]
|
||||
|
||||
|
||||
@@ -5,9 +5,17 @@ enum GameMode { NEW_GAME, LOAD_GAME }
|
||||
var mode: GameMode = GameMode.NEW_GAME
|
||||
var save_id: String = ""
|
||||
|
||||
# 游戏内时间(12 月 × 30 天 = 360 天/年)
|
||||
var year: int = 1
|
||||
var month: int = 1
|
||||
var day: int = 1
|
||||
|
||||
func request_new_game() -> void:
|
||||
mode = GameMode.NEW_GAME
|
||||
save_id = ""
|
||||
year = 1
|
||||
month = 1
|
||||
day = 1
|
||||
|
||||
func request_load_game(id: String) -> void:
|
||||
mode = GameMode.LOAD_GAME
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
extends Node
|
||||
|
||||
func _ready() -> void:
|
||||
TimeSystem.speed_index = Settings.default_speed_index
|
||||
TimeSystem.speed = TimeSystem.SPEEDS[TimeSystem.speed_index]
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
extends Node
|
||||
|
||||
const SAVE_PATH := "user://settings.cfg"
|
||||
var default_speed_index := 1 # 默认 5x
|
||||
|
||||
func load_settings() -> void:
|
||||
var cfg := ConfigFile.new()
|
||||
if cfg.load(SAVE_PATH) == OK:
|
||||
default_speed_index = cfg.get_value("time", "speed_index", 1)
|
||||
|
||||
func save_settings() -> void:
|
||||
var cfg := ConfigFile.new()
|
||||
cfg.set_value("time", "speed_index", default_speed_index)
|
||||
cfg.save(SAVE_PATH)
|
||||
@@ -0,0 +1 @@
|
||||
uid://exwk46qy4x6t
|
||||
@@ -2,11 +2,17 @@ extends Node
|
||||
|
||||
signal day_passed(year, month, day)
|
||||
|
||||
const SPEEDS := [1.0, 5.0, 20.0]
|
||||
var speed_index := 0
|
||||
|
||||
const DAY_LENGTH := 5.0
|
||||
var speed := 1.0
|
||||
var paused := false
|
||||
var _elapsed := 0.0
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if paused:
|
||||
return
|
||||
_elapsed += delta * speed
|
||||
if _elapsed >= DAY_LENGTH:
|
||||
_elapsed -= DAY_LENGTH
|
||||
@@ -16,3 +22,19 @@ func _advance() -> void:
|
||||
# GameState.year, GameState.month, GameState.day 推进
|
||||
GameState.day = GameState.day + 1;
|
||||
day_passed.emit()
|
||||
|
||||
func cycle_speed() -> float:
|
||||
speed_index = (speed_index + 1) % SPEEDS.size()
|
||||
speed = SPEEDS[speed_index]
|
||||
return speed
|
||||
|
||||
func set_speed_index(index: int) -> void:
|
||||
speed_index = clampi(index, 0, SPEEDS.size() - 1)
|
||||
speed = SPEEDS[speed_index]
|
||||
|
||||
func toggle_pause() -> bool:
|
||||
paused = not paused
|
||||
return paused
|
||||
|
||||
func get_speed_label() -> String:
|
||||
return "x%d" % int(speed)
|
||||
|
||||
@@ -61,6 +61,35 @@ size_flags_horizontal = 3
|
||||
size_flags_vertical = 8
|
||||
label_settings = SubResource("LabelSettings_bn2o5")
|
||||
|
||||
[node name="SpeedGroup" type="HBoxContainer" parent="HBoxContainer" unique_id=2144893126]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
theme_override_constants/separation = 4
|
||||
|
||||
[node name="Button_Pause" type="Button" parent="HBoxContainer/SpeedGroup" unique_id=2144893127]
|
||||
custom_minimum_size = Vector2(64, 0)
|
||||
layout_mode = 2
|
||||
theme_override_fonts/font = ExtResource("1_pa2rn")
|
||||
text = "暂停"
|
||||
|
||||
[node name="Button_Speed1" type="Button" parent="HBoxContainer/SpeedGroup" unique_id=2144893128]
|
||||
custom_minimum_size = Vector2(48, 0)
|
||||
layout_mode = 2
|
||||
theme_override_fonts/font = ExtResource("1_pa2rn")
|
||||
text = "1x"
|
||||
|
||||
[node name="Button_Speed5" type="Button" parent="HBoxContainer/SpeedGroup" unique_id=2144893129]
|
||||
custom_minimum_size = Vector2(48, 0)
|
||||
layout_mode = 2
|
||||
theme_override_fonts/font = ExtResource("1_pa2rn")
|
||||
text = "5x"
|
||||
|
||||
[node name="Button_Speed20" type="Button" parent="HBoxContainer/SpeedGroup" unique_id=2144893130]
|
||||
custom_minimum_size = Vector2(48, 0)
|
||||
layout_mode = 2
|
||||
theme_override_fonts/font = ExtResource("1_pa2rn")
|
||||
text = "20x"
|
||||
|
||||
[node name="placeholder_1" type="Label" parent="HBoxContainer" unique_id=1042446504]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
@@ -117,4 +146,5 @@ size_flags_horizontal = 3
|
||||
theme_override_fonts/font = ExtResource("1_pa2rn")
|
||||
text = "返回"
|
||||
|
||||
[connection signal="button_up" from="HBoxContainer/SpeedGroup/Button_Pause" to="." method="_on_button_pause_button_up"]
|
||||
[connection signal="button_up" from="HBoxContainer/Button_Return" to="." method="_on_button_return_button_up"]
|
||||
|
||||
@@ -2,7 +2,31 @@ extends Control
|
||||
|
||||
signal sign_return_mainmenu
|
||||
|
||||
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))
|
||||
_update_speed_ui()
|
||||
|
||||
func _on_button_return_button_up() -> void:
|
||||
sign_return_mainmenu.emit()
|
||||
pass # Replace with function body.
|
||||
|
||||
func _on_button_pause_button_up() -> void:
|
||||
TimeSystem.toggle_pause()
|
||||
_update_speed_ui()
|
||||
|
||||
func _on_speed_button_up(index: int) -> void:
|
||||
TimeSystem.set_speed_index(index)
|
||||
_update_speed_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
|
||||
|
||||
Reference in New Issue
Block a user