新增存档面板:组/槽两级列表浏览与删除
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
## 存档组条目(挂载于 SaveGroup.tscn,填充左侧组列表)。
|
||||||
|
extends HBoxContainer
|
||||||
|
|
||||||
|
## 请求选中该组。
|
||||||
|
signal group_selected(profile_id: int)
|
||||||
|
## 请求删除该组(数据删除与节点销毁由条目自身完成,父面板仅做状态校正)。
|
||||||
|
signal delete_requested(profile_id: int)
|
||||||
|
|
||||||
|
## 该条目对应的存档组 ID。
|
||||||
|
var group_id: int = 0
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
$LabelId.pressed.connect(func(): group_selected.emit(group_id))
|
||||||
|
|
||||||
|
func set_data(group: Dictionary) -> void:
|
||||||
|
group_id = int(group["id"])
|
||||||
|
$LabelId.text = str(group.get("name", "存档%d" % group_id))
|
||||||
|
|
||||||
|
func _on_button_del_button_up() -> void:
|
||||||
|
delete_requested.emit(group_id)
|
||||||
|
SaveSystem.delete_profile(group_id)
|
||||||
|
queue_free()
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://dos00byqj2c7m
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
[gd_scene format=3 uid="uid://t1jkqpmxb160"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://dos00byqj2c7m" path="res://src/UI/Panels/SaveGroup.gd" id="1_j6osu"]
|
||||||
|
[ext_resource type="Theme" uid="uid://btnjeju2d47x8" path="res://resources/save_menu_button_theme.tres" id="2_uoetd"]
|
||||||
|
|
||||||
|
[node name="SaveGroup" type="HBoxContainer" unique_id=1600113286]
|
||||||
|
anchors_preset = 10
|
||||||
|
anchor_right = 1.0
|
||||||
|
offset_bottom = 29.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
script = ExtResource("1_j6osu")
|
||||||
|
|
||||||
|
[node name="LabelId" type="Button" parent="." unique_id=253528830]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
size_flags_stretch_ratio = 3.0
|
||||||
|
text = "A"
|
||||||
|
|
||||||
|
[node name="ButtonDel" type="Button" parent="." unique_id=1248721049]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
theme = ExtResource("2_uoetd")
|
||||||
|
text = "Del"
|
||||||
|
|
||||||
|
[connection signal="button_up" from="ButtonDel" to="." method="_on_button_del_button_up"]
|
||||||
+80
-18
@@ -8,38 +8,100 @@ enum Mode { SAVE, LOAD }
|
|||||||
|
|
||||||
## 请求关闭面板(返回上级界面)。
|
## 请求关闭面板(返回上级界面)。
|
||||||
signal save_panel_esc_pressed
|
signal save_panel_esc_pressed
|
||||||
|
## 请求读档(LOAD 模式点槽位时发出)。
|
||||||
|
signal load_requested(profile_id: int, slot_name: String)
|
||||||
|
|
||||||
## 槽位条目场景。
|
## 槽位条目场景。
|
||||||
const SAVE_SLOT_SCENE := preload("res://src/UI/Panels/SaveSlot.tscn")
|
const SAVE_SLOT_SCENE := preload("res://src/UI/Panels/SaveSlot.tscn")
|
||||||
|
## 组条目场景。
|
||||||
|
const SAVE_GROUP_SCENE := preload("res://src/UI/Panels/SaveGroup.tscn")
|
||||||
|
|
||||||
#@onready var title_label: Label = %TitleLabel
|
@onready var group_container: VBoxContainer = %GroupContainer
|
||||||
#@onready var group_container: VBoxContainer = %GroupContainer
|
@onready var slot_list: VBoxContainer = %SlotItems
|
||||||
#@onready var slot_list: VBoxContainer = %SlotList
|
|
||||||
@onready var new_slot_button: Button = %Button_NewSlot
|
@onready var new_slot_button: Button = %Button_NewSlot
|
||||||
|
|
||||||
## 当前模式。
|
## 当前模式。
|
||||||
var mode: Mode = Mode.LOAD
|
var mode: Mode = Mode.LOAD
|
||||||
## 当前浏览的存档组 ID。
|
## 当前浏览的存档组 ID(0 = 未选中)。
|
||||||
#var _current_profile: int = 0
|
var _current_profile: int = 0
|
||||||
### 打开面板前的暂停状态(存档模式关闭时恢复)。
|
|
||||||
#var _was_paused := false
|
|
||||||
|
|
||||||
func open_load() -> void:
|
func open_load() -> void:
|
||||||
mode = Mode.SAVE
|
|
||||||
new_slot_button.visible = false
|
|
||||||
visible = true
|
|
||||||
pass
|
|
||||||
|
|
||||||
func open_save() -> void:
|
|
||||||
mode = Mode.LOAD
|
mode = Mode.LOAD
|
||||||
new_slot_button.visible = true
|
new_slot_button.visible = false
|
||||||
|
refresh_groups()
|
||||||
visible = true
|
visible = true
|
||||||
pass
|
|
||||||
|
func open_save() -> void:
|
||||||
|
mode = Mode.SAVE
|
||||||
|
new_slot_button.visible = true
|
||||||
|
refresh_groups()
|
||||||
|
visible = true
|
||||||
|
|
||||||
|
## 刷新左侧存档组列表(调用 SaveSystem.get_profiles() 动态创建条目)。
|
||||||
|
func refresh_groups() -> void:
|
||||||
|
_clear_children(group_container)
|
||||||
|
for group in SaveSystem.get_profiles():
|
||||||
|
var item := SAVE_GROUP_SCENE.instantiate()
|
||||||
|
item.set_data(group)
|
||||||
|
item.group_selected.connect(_on_group_selected)
|
||||||
|
item.delete_requested.connect(_on_group_delete_requested)
|
||||||
|
group_container.add_child(item)
|
||||||
|
print(group['id'])
|
||||||
|
# 校验当前选中组:已被删除则复位并清空右列
|
||||||
|
if _current_profile == 0 or _current_profile not in _get_profile_ids():
|
||||||
|
_current_profile = 0
|
||||||
|
refresh_slots(_current_profile)
|
||||||
|
|
||||||
|
## 当前所有组的 id 列表。
|
||||||
|
func _get_profile_ids() -> Array[int]:
|
||||||
|
var ids: Array[int] = []
|
||||||
|
for group in SaveSystem.get_profiles():
|
||||||
|
ids.append(int(group["id"]))
|
||||||
|
return ids
|
||||||
|
|
||||||
|
## 刷新右侧槽位列表(profile_id 为 0 时清空)。
|
||||||
|
func refresh_slots(profile_id: int) -> void:
|
||||||
|
_clear_children(slot_list)
|
||||||
|
if profile_id == 0:
|
||||||
|
return
|
||||||
|
for slot in SaveSystem.list_slots(profile_id):
|
||||||
|
var item := SAVE_SLOT_SCENE.instantiate()
|
||||||
|
item.set_data(profile_id, slot["name"], slot["date"])
|
||||||
|
item.load_requested.connect(_on_slot_load_requested)
|
||||||
|
item.delete_requested.connect(_on_slot_delete_requested)
|
||||||
|
slot_list.add_child(item)
|
||||||
|
print("--->");
|
||||||
|
print("---------------------->");
|
||||||
|
|
||||||
|
|
||||||
|
func _on_group_selected(profile_id: int) -> void:
|
||||||
|
_current_profile = profile_id
|
||||||
|
refresh_slots(profile_id)
|
||||||
|
|
||||||
|
func _on_group_delete_requested(profile_id: int) -> void:
|
||||||
|
# 条目已自行删数据并销毁,这里只校正选中状态
|
||||||
|
if _current_profile == profile_id:
|
||||||
|
_current_profile = 0
|
||||||
|
refresh_slots(_current_profile)
|
||||||
|
|
||||||
|
func _on_slot_load_requested(profile_id: int, slot_name: String) -> void:
|
||||||
|
load_requested.emit(profile_id, slot_name)
|
||||||
|
|
||||||
|
func _on_slot_delete_requested(profile_id: int, slot_name: String) -> void:
|
||||||
|
SaveSystem.delete_slot(profile_id, slot_name)
|
||||||
|
refresh_slots(profile_id)
|
||||||
|
|
||||||
|
## 清空容器的所有子节点。
|
||||||
|
func _clear_children(container: Node) -> void:
|
||||||
|
for child in container.get_children():
|
||||||
|
container.remove_child(child)
|
||||||
|
child.queue_free()
|
||||||
|
|
||||||
func _on_SavePanel_Esc_ButtonUp() -> void:
|
func _on_SavePanel_Esc_ButtonUp() -> void:
|
||||||
save_panel_esc_pressed.emit()
|
save_panel_esc_pressed.emit()
|
||||||
pass # Replace with function body.
|
|
||||||
|
|
||||||
|
|
||||||
func _on_SavePanel_NewSlot_ButtonUp() -> void:
|
func _on_SavePanel_NewSlot_ButtonUp() -> void:
|
||||||
pass # Replace with function body.
|
if _current_profile == 0:
|
||||||
|
return
|
||||||
|
SaveSystem.save(_current_profile)
|
||||||
|
refresh_slots(_current_profile)
|
||||||
|
|||||||
@@ -59,14 +59,28 @@ size_flags_stretch_ratio = 15.0
|
|||||||
|
|
||||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/ScrollContainer" unique_id=1858690088]
|
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/ScrollContainer" unique_id=1858690088]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
size_flags_vertical = 3
|
||||||
|
|
||||||
[node name="GroupContainer" type="VBoxContainer" parent="VBoxContainer/ScrollContainer/HBoxContainer" unique_id=1215509679]
|
[node name="GroupScroll" type="ScrollContainer" parent="VBoxContainer/ScrollContainer/HBoxContainer" unique_id=-2142055995]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
|
||||||
|
[node name="GroupContainer" type="VBoxContainer" parent="VBoxContainer/ScrollContainer/HBoxContainer/GroupScroll" unique_id=1215509679]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
|
||||||
[node name="SaveSlotList" type="VBoxContainer" parent="VBoxContainer/ScrollContainer/HBoxContainer" unique_id=1157397953]
|
[node name="SaveSlotList" type="ScrollContainer" parent="VBoxContainer/ScrollContainer/HBoxContainer" unique_id=2071143052]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
size_flags_stretch_ratio = 7.0
|
||||||
|
|
||||||
|
[node name="SlotItems" type="VBoxContainer" parent="VBoxContainer/ScrollContainer/HBoxContainer/SaveSlotList" unique_id=1079543554]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
size_flags_vertical = 3
|
||||||
|
|
||||||
[connection signal="button_up" from="VBoxContainer/HBoxContainer/Button_NewSlot" to="." method="_on_SavePanel_NewSlot_ButtonUp"]
|
[connection signal="button_up" from="VBoxContainer/HBoxContainer/Button_NewSlot" to="." method="_on_SavePanel_NewSlot_ButtonUp"]
|
||||||
[connection signal="button_up" from="VBoxContainer/HBoxContainer/Button_Esc" to="." method="_on_SavePanel_Esc_ButtonUp"]
|
[connection signal="button_up" from="VBoxContainer/HBoxContainer/Button_Esc" to="." method="_on_SavePanel_Esc_ButtonUp"]
|
||||||
|
|||||||
@@ -1 +1,22 @@
|
|||||||
extends Panel
|
## 存档槽位条目(挂载于 SaveSlot.tscn,填充右侧槽位列表)。
|
||||||
|
extends PanelContainer
|
||||||
|
|
||||||
|
## 请求读档该槽。
|
||||||
|
signal load_requested(profile_id: int, slot_name: String)
|
||||||
|
## 请求删除该槽。
|
||||||
|
signal delete_requested(profile_id: int, slot_name: String)
|
||||||
|
|
||||||
|
var _profile_id: int = 0
|
||||||
|
var _slot_name: String = ""
|
||||||
|
|
||||||
|
func set_data(profile_id: int, slot_name: String, date: String) -> void:
|
||||||
|
_profile_id = profile_id
|
||||||
|
_slot_name = slot_name
|
||||||
|
%SaveNameLabel.text = slot_name
|
||||||
|
%SaveSlotInfo.text = date
|
||||||
|
|
||||||
|
func _on_button_load_button_up() -> void:
|
||||||
|
load_requested.emit(_profile_id, _slot_name)
|
||||||
|
|
||||||
|
func _on_button_delete_button_up() -> void:
|
||||||
|
delete_requested.emit(_profile_id, _slot_name)
|
||||||
|
|||||||
+11
-11
@@ -4,22 +4,17 @@
|
|||||||
[ext_resource type="LabelSettings" uid="uid://bn06sljdiloor" path="res://resources/save_menu_label_settings.tres" id="2_lm8et"]
|
[ext_resource type="LabelSettings" uid="uid://bn06sljdiloor" path="res://resources/save_menu_label_settings.tres" id="2_lm8et"]
|
||||||
[ext_resource type="Theme" uid="uid://btnjeju2d47x8" path="res://resources/save_menu_button_theme.tres" id="2_m8lv8"]
|
[ext_resource type="Theme" uid="uid://btnjeju2d47x8" path="res://resources/save_menu_button_theme.tres" id="2_m8lv8"]
|
||||||
|
|
||||||
[node name="SaveSlot" type="Panel" unique_id=815772812]
|
[node name="SaveSlot" type="PanelContainer" unique_id=270996818]
|
||||||
anchors_preset = 14
|
anchors_preset = 10
|
||||||
anchor_top = 0.5
|
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
anchor_bottom = 0.5
|
offset_bottom = 50.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
custom_minimum_size = Vector2(0, 50)
|
||||||
|
size_flags_horizontal = 3
|
||||||
script = ExtResource("1_gsy4a")
|
script = ExtResource("1_gsy4a")
|
||||||
|
|
||||||
[node name="HBoxContainer" type="HBoxContainer" parent="." unique_id=1394744552]
|
[node name="HBoxContainer" type="HBoxContainer" parent="." unique_id=1394744552]
|
||||||
layout_mode = 1
|
layout_mode = 2
|
||||||
anchors_preset = 15
|
|
||||||
anchor_right = 1.0
|
|
||||||
anchor_bottom = 1.0
|
|
||||||
grow_horizontal = 2
|
|
||||||
grow_vertical = 2
|
|
||||||
|
|
||||||
[node name="SlotIndexLabel" type="Label" parent="HBoxContainer" unique_id=1779842797]
|
[node name="SlotIndexLabel" type="Label" parent="HBoxContainer" unique_id=1779842797]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
@@ -35,10 +30,12 @@ size_flags_horizontal = 3
|
|||||||
size_flags_stretch_ratio = 15.0
|
size_flags_stretch_ratio = 15.0
|
||||||
|
|
||||||
[node name="SaveNameLabel" type="Label" parent="HBoxContainer/VBoxContainer" unique_id=391910928]
|
[node name="SaveNameLabel" type="Label" parent="HBoxContainer/VBoxContainer" unique_id=391910928]
|
||||||
|
unique_name_in_owner = true
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_vertical = 3
|
size_flags_vertical = 3
|
||||||
|
|
||||||
[node name="SaveSlotInfo" type="Label" parent="HBoxContainer/VBoxContainer" unique_id=125642674]
|
[node name="SaveSlotInfo" type="Label" parent="HBoxContainer/VBoxContainer" unique_id=125642674]
|
||||||
|
unique_name_in_owner = true
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_vertical = 3
|
size_flags_vertical = 3
|
||||||
|
|
||||||
@@ -53,3 +50,6 @@ layout_mode = 2
|
|||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
theme = ExtResource("2_m8lv8")
|
theme = ExtResource("2_m8lv8")
|
||||||
text = "▶"
|
text = "▶"
|
||||||
|
|
||||||
|
[connection signal="button_up" from="HBoxContainer/ButtonDelete" to="." method="_on_button_delete_button_up"]
|
||||||
|
[connection signal="button_up" from="HBoxContainer/ButtonLoad" to="." method="_on_button_load_button_up"]
|
||||||
|
|||||||
Reference in New Issue
Block a user