fixed saving & added first basic save creation menu
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
14
scripts/resources/save_file.gd
Normal file
14
scripts/resources/save_file.gd
Normal file
@@ -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)
|
||||
1
scripts/resources/save_file.gd.uid
Normal file
1
scripts/resources/save_file.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dru7lnuaadb87
|
||||
Reference in New Issue
Block a user