From f87cc28c5759c48a333ea998ac33573f6f32ea3a Mon Sep 17 00:00:00 2001 From: vaporvee Date: Wed, 15 Oct 2025 05:36:33 +0200 Subject: [PATCH] fixed saving & added first basic save creation menu --- scenes/autoloads/event_manager.tscn | 1 + scenes/filter/pixelize.tscn | 3 +- scenes/menus/main_menu.tscn | 30 +++++++++++++++---- scenes/menus/profile_creator.tscn | 46 +++++++++++++++++++++++++++++ scripts/autoloads/save.gd | 18 ++++------- scripts/autoloads/windowman.gd | 6 ++-- scripts/menus/main_menu.gd | 7 +++-- scripts/menus/profile_creator.gd | 44 +++++++++++++++++++++++++++ scripts/resources/config.gd | 2 +- scripts/resources/profile.gd | 11 ++++--- scripts/resources/save_file.gd | 14 +++++++++ scripts/resources/save_file.gd.uid | 1 + 12 files changed, 155 insertions(+), 28 deletions(-) create mode 100644 scripts/resources/save_file.gd create mode 100644 scripts/resources/save_file.gd.uid diff --git a/scenes/autoloads/event_manager.tscn b/scenes/autoloads/event_manager.tscn index e2b5cf2..679f78a 100644 --- a/scenes/autoloads/event_manager.tscn +++ b/scenes/autoloads/event_manager.tscn @@ -12,4 +12,5 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +mouse_filter = 2 color = Color(0, 0, 0, 1) diff --git a/scenes/filter/pixelize.tscn b/scenes/filter/pixelize.tscn index 3f4d2c6..b71ad0f 100644 --- a/scenes/filter/pixelize.tscn +++ b/scenes/filter/pixelize.tscn @@ -12,11 +12,12 @@ shader_parameter/limit_subpixels = true [node name="Pixelize" type="CanvasLayer"] [node name="ColorRect" type="ColorRect" parent="."] +visible = false material = SubResource("ShaderMaterial_83vy4") anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -mouse_filter = 1 +mouse_filter = 2 metadata/_edit_lock_ = true diff --git a/scenes/menus/main_menu.tscn b/scenes/menus/main_menu.tscn index 4e0bdd6..0fbadd6 100644 --- a/scenes/menus/main_menu.tscn +++ b/scenes/menus/main_menu.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=2 format=3 uid="uid://dgq21ggr3br2g"] +[gd_scene load_steps=3 format=3 uid="uid://dgq21ggr3br2g"] [ext_resource type="Script" uid="uid://bfgqkpn60hhwj" path="res://scripts/menus/main_menu.gd" id="1_xqga4"] +[ext_resource type="PackedScene" uid="uid://cd657k2lc3gyc" path="res://scenes/menus/profile_creator.tscn" id="2_ovrgc"] [node name="MainMenu" type="Control"] layout_mode = 3 @@ -11,7 +12,22 @@ grow_horizontal = 2 grow_vertical = 2 script = ExtResource("1_xqga4") -[node name="VBoxContainer" type="VBoxContainer" parent="."] +[node name="TabContainer" type="TabContainer" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +current_tab = 0 +tabs_visible = false +drag_to_rearrange_enabled = true + +[node name="Main" type="Control" parent="TabContainer"] +layout_mode = 2 +metadata/_tab_index = 0 + +[node name="VBoxContainer" type="VBoxContainer" parent="TabContainer/Main"] layout_mode = 1 anchors_preset = 8 anchor_left = 0.5 @@ -25,11 +41,15 @@ offset_bottom = 20.0 grow_horizontal = 2 grow_vertical = 2 -[node name="Button" type="Button" parent="VBoxContainer"] +[node name="Button" type="Button" parent="TabContainer/Main/VBoxContainer"] layout_mode = 2 theme_override_font_sizes/font_size = 8 text = "Start" -[node name="MenuSlot" type="CanvasLayer" parent="."] +[node name="ProfileCreator" parent="TabContainer" instance=ExtResource("2_ovrgc")] +visible = false +layout_mode = 2 +metadata/_tab_index = 1 -[connection signal="pressed" from="VBoxContainer/Button" to="." method="_on_start_button_pressed"] +[connection signal="pressed" from="TabContainer/Main/VBoxContainer/Button" to="." method="_on_start_button_pressed"] +[connection signal="exit" from="TabContainer/ProfileCreator" to="." method="_on_profile_creator_exit"] diff --git a/scenes/menus/profile_creator.tscn b/scenes/menus/profile_creator.tscn index de61dbc..050fc99 100644 --- a/scenes/menus/profile_creator.tscn +++ b/scenes/menus/profile_creator.tscn @@ -10,3 +10,49 @@ anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 script = ExtResource("1_4xjd5") + +[node name="VBoxContainer" type="VBoxContainer" parent="."] +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -74.0 +offset_top = -21.5 +offset_right = 74.0 +offset_bottom = 21.5 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="LineEdit" type="LineEdit" parent="VBoxContainer"] +layout_mode = 2 +placeholder_text = "Name him" +editable = false +context_menu_enabled = false +emoji_menu_enabled = false +virtual_keyboard_enabled = false +virtual_keyboard_show_on_focus = false +clear_button_enabled = true +selecting_enabled = false +caret_blink = true + +[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"] +layout_mode = 2 +alignment = 1 + +[node name="Back" type="Button" parent="VBoxContainer/HBoxContainer"] +custom_minimum_size = Vector2(50, 0) +layout_mode = 2 +theme_override_font_sizes/font_size = 8 +text = "Back" + +[node name="Next" type="Button" parent="VBoxContainer/HBoxContainer"] +custom_minimum_size = Vector2(50, 0) +layout_mode = 2 +size_flags_vertical = 4 +theme_override_font_sizes/font_size = 8 +text = "Next" + +[connection signal="pressed" from="VBoxContainer/HBoxContainer/Back" to="." method="_on_back_button_pressed"] +[connection signal="pressed" from="VBoxContainer/HBoxContainer/Next" to="." method="_on_next_pressed"] diff --git a/scripts/autoloads/save.gd b/scripts/autoloads/save.gd index d0fec4e..e5672d1 100644 --- a/scripts/autoloads/save.gd +++ b/scripts/autoloads/save.gd @@ -4,16 +4,11 @@ extends Node var file: ConfigFile = ConfigFile.new() var save_path: String = "user://save.binary" -func get_section_name(res: Resource) -> String: - return res.resource_name if res.resource_name != "" else res.get_class() - -func save(res: Resource) -> bool: +func save(res: SaveFile) -> bool: if not is_instance_valid(res): push_error("cannot save: invalid resource") return false - var section_name: String = get_section_name(res) - if FileAccess.file_exists(save_path) and file.load(save_path) != OK: printerr("Save file corrupted!") return false @@ -23,26 +18,25 @@ func save(res: Resource) -> bool: for property in res.get_property_list(): if property.usage & PROPERTY_USAGE_STORAGE: var v_name: String = property.name - file.set_value(section_name, v_name, res.get(v_name)) + file.set_value(res.save_name, v_name, res.get(v_name)) return file.save(save_path) == OK -func load(res: Resource) -> bool: +func load(res: SaveFile) -> bool: if not FileAccess.file_exists(save_path): return true if file.load(save_path) != OK: printerr("Save file corrupted!") return false - - var section_name: String = get_section_name(res) + var props := [] for p in res.get_property_list(): if p.usage & PROPERTY_USAGE_STORAGE: props.append(p.name) - for key in file.get_section_keys(section_name): + for key in file.get_section_keys(res.save_name): if key in props: - res.set(key, file.get_value(section_name, key)) + res.set(key, file.get_value(res.save_name, key)) return true func delete() -> void: diff --git a/scripts/autoloads/windowman.gd b/scripts/autoloads/windowman.gd index a412748..67e2648 100644 --- a/scripts/autoloads/windowman.gd +++ b/scripts/autoloads/windowman.gd @@ -1,15 +1,15 @@ extends Node -var config: Config = Config.new() +var config: Config = Config.new("config") func _ready() -> void: - Save.load(config) + config.load() toggle_fullscreen() func _process(_delta: float) -> void: if Input.is_action_just_pressed("fullscreen"): config.fullscreen = !config.fullscreen - Save.save(config) + config.save() toggle_fullscreen() func _notification(what: int) -> void: diff --git a/scripts/menus/main_menu.gd b/scripts/menus/main_menu.gd index 3ff1add..abb1c59 100644 --- a/scripts/menus/main_menu.gd +++ b/scripts/menus/main_menu.gd @@ -1,6 +1,9 @@ extends Control - +@onready var tab_container: TabContainer = $TabContainer func _on_start_button_pressed() -> void: - pass # Replace with function body. + tab_container.current_tab = 1 + +func _on_profile_creator_exit() -> void: + tab_container.current_tab = 0 diff --git a/scripts/menus/profile_creator.gd b/scripts/menus/profile_creator.gd index e07a0bf..97119a1 100644 --- a/scripts/menus/profile_creator.gd +++ b/scripts/menus/profile_creator.gd @@ -1 +1,45 @@ extends Control + +signal exit + +var profile: Profile = Profile.new("profile") +@onready var next: Button = $VBoxContainer/HBoxContainer/Next +@onready var line_edit: LineEdit = $VBoxContainer/LineEdit + +@onready var max_index: int = profile.named_things.keys().size() - 1 +var index: int = 0 + +func _ready() -> void: + next.disabled = index == max_index + +func _on_back_button_pressed() -> void: + if index == 0: + exit.emit() + else: + index -= 1 + update_name() + +func _on_next_pressed() -> void: + index += 1 + update_name() + +func update_name() -> void: + if index == max_index: + next.text = "Finish" + elif index > max_index: + profile.save() + index = max_index + return + else: + next.text = "Next" + + var labels: Dictionary = { + "player_name": "Name him", + "villain_friend": "Name him too", + "stupid_friend": "And also name him", + "favourite_candy": "Favourite candy?" + } + + var label: String = labels[profile.named_things.keys()[index]] + line_edit.placeholder_text = label + diff --git a/scripts/resources/config.gd b/scripts/resources/config.gd index 1616f7b..74cc564 100644 --- a/scripts/resources/config.gd +++ b/scripts/resources/config.gd @@ -1,4 +1,4 @@ class_name Config -extends Resource +extends SaveFile @export var fullscreen: bool = ProjectSettings.get_setting("display/window/size/mode") == Window.MODE_EXCLUSIVE_FULLSCREEN | Window.MODE_FULLSCREEN diff --git a/scripts/resources/profile.gd b/scripts/resources/profile.gd index 952a9d8..62db890 100644 --- a/scripts/resources/profile.gd +++ b/scripts/resources/profile.gd @@ -1,6 +1,9 @@ class_name Profile -extends Resource +extends SaveFile -@export var your_name: String = "Joel" -@export var villain_friend_name: String = "Josh" -@export var stupid_friend_name: String = "Kevin" +@export var named_things: Dictionary[StringName, String] = { + "player_name": "Joel", + "villain_friend": "Josh", + "stupid_friend": "Kevin", + "favourite_candy": "Chocolate" +} diff --git a/scripts/resources/save_file.gd b/scripts/resources/save_file.gd new file mode 100644 index 0000000..2d5d97b --- /dev/null +++ b/scripts/resources/save_file.gd @@ -0,0 +1,14 @@ +class_name SaveFile +extends Resource + +@export var save_name = "Save" + +func _init(p_save_name = "Save") -> void: + save_name = p_save_name + +func save() -> void: Save.save(self) +func load() -> void: Save.load(self) + +func reset() -> void: + Save.file.erase_section(save_name) + Save.file.save(Save.save_path) diff --git a/scripts/resources/save_file.gd.uid b/scripts/resources/save_file.gd.uid new file mode 100644 index 0000000..c2b5e4b --- /dev/null +++ b/scripts/resources/save_file.gd.uid @@ -0,0 +1 @@ +uid://dru7lnuaadb87