aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/game.gd2
-rw-r--r--client/global.gd51
-rw-r--r--client/menu/character_menu.gd14
-rw-r--r--client/menu/main_menu.gd4
-rw-r--r--client/menu/settings_menu.gd15
-rw-r--r--client/menu/settings_row.gd36
-rw-r--r--client/menu/settings_row.tscn24
7 files changed, 120 insertions, 26 deletions
diff --git a/client/game.gd b/client/game.gd
index 3ee960f7..ab2cdfbd 100644
--- a/client/game.gd
+++ b/client/game.gd
@@ -154,7 +154,7 @@ func _ready():
p.bubble.set_text(item_names[item])
)
- mp.send_join(Global.settings["username"], Global.settings["character"])
+ mp.send_join(Global.profile["username"], Global.profile["character"])
func _process(delta):
marker.position = lerp(marker.position, marker_target, delta * 40.0)
diff --git a/client/global.gd b/client/global.gd
index 095deec8..be230890 100644
--- a/client/global.gd
+++ b/client/global.gd
@@ -17,36 +17,55 @@
#
extends Node
-const DEFAULT_SETTINGS := {
+const DEFAULT_PROFILE := {
"username": "Giovanni",
"character": 0,
"last_server_url": ""
}
-var settings := DEFAULT_SETTINGS.duplicate(true)
+var default_settings := {
+ "interpolate_camera_rotation": {
+ "value": true,
+ "description": tr("Interpolate the camera rotation")
+ },
+ "test": {
+ "value": "hehe",
+ "description": tr("Just a test value")
+ },
+}
+
+var profile: Dictionary
+var settings: Dictionary
var server_url = ""
var error_message = ""
func _ready():
- load_profile()
+ profile = load_dict("user://profile", DEFAULT_PROFILE)
+ settings = load_dict("user://settings", default_settings)
func save_profile():
- var f = FileAccess.open("user://profile", FileAccess.WRITE)
- f.store_var(settings.duplicate(true))
+ save_dict("user://profile", profile)
+
+func save_settings():
+ save_dict("user://settings", settings)
- print("Saved settings: ", settings)
+func save_dict(path: String, dict: Dictionary):
+ var f = FileAccess.open(path, FileAccess.WRITE)
+ f.store_var(dict.duplicate(true))
-func load_profile():
+func load_dict(path: String, default: Dictionary) -> Dictionary:
# TOCTOU here. Godot docs says its fine.
- if not FileAccess.file_exists("user://profile"):
+ if not FileAccess.file_exists(path):
print("Skip profile load")
- return
- var f = FileAccess.open("user://profile", FileAccess.READ)
- var saved_settings = f.get_var()
- if saved_settings != null and saved_settings is Dictionary:
- for i in DEFAULT_SETTINGS.keys():
- if saved_settings.has(i):
- settings[i] = saved_settings[i]
+ return default
+ var f = FileAccess.open(path, FileAccess.READ)
+ var saved_dict = f.get_var()
+ var res: Dictionary = {}
+ if saved_dict != null and saved_dict is Dictionary:
+ for i in default.keys():
+ if saved_dict.has(i):
+ res[i] = saved_dict[i]
- print("Loaded settings: ", settings)
+ print("Loaded dict: ", res)
+ return res
diff --git a/client/menu/character_menu.gd b/client/menu/character_menu.gd
index f4b878be..fd4e3707 100644
--- a/client/menu/character_menu.gd
+++ b/client/menu/character_menu.gd
@@ -19,21 +19,21 @@ extends Control
@onready var num_hairstyles := character.hairstyles.keys().size()
func _ready():
- $VBoxContainer/top_panel/a/username.text = Global.settings["username"]
- character.select_hairstyle(Global.settings["character"])
+ $VBoxContainer/top_panel/a/username.text = Global.profile["username"]
+ character.select_hairstyle(Global.profile["character"])
func _on_back_pressed():
$SceneTransition.transition_to("res://menu/main_menu.tscn")
func _on_username_text_changed(new_text):
- Global.settings["username"] = new_text
+ Global.profile["username"] = new_text
func _on_character_back_pressed():
- Global.settings["character"] = (Global.settings["character"] - 1) % num_hairstyles
- character.select_hairstyle(Global.settings["character"])
+ Global.profile["character"] = (Global.profile["character"] - 1) % num_hairstyles
+ character.select_hairstyle(Global.profile["character"])
Global.save_profile()
func _on_character_forward_pressed():
- Global.settings["character"] = (Global.settings["character"] + 1) % num_hairstyles
- character.select_hairstyle(Global.settings["character"])
+ Global.profile["character"] = (Global.profile["character"] + 1) % num_hairstyles
+ character.select_hairstyle(Global.profile["character"])
Global.save_profile()
diff --git a/client/menu/main_menu.gd b/client/menu/main_menu.gd
index 31ca5462..bd4cdcb0 100644
--- a/client/menu/main_menu.gd
+++ b/client/menu/main_menu.gd
@@ -25,7 +25,7 @@ func _ready():
quick_connect.grab_focus()
if OS.has_feature("web"):
quit_button.hide()
- connect_uri.text = Global.settings["last_server_url"]
+ connect_uri.text = Global.profile["last_server_url"]
func _on_quit_pressed():
transition.quit()
@@ -35,7 +35,7 @@ func _on_credits_pressed():
func _on_connect_pressed():
var url = $side/margin/options/connect/uri.text
- Global.settings["last_server_url"] = url
+ Global.profile["last_server_url"] = url
Global.save_profile()
connect_to(url)
diff --git a/client/menu/settings_menu.gd b/client/menu/settings_menu.gd
index a023cf36..f7abd9e6 100644
--- a/client/menu/settings_menu.gd
+++ b/client/menu/settings_menu.gd
@@ -15,5 +15,20 @@
#
extends Control
+@onready var options: VBoxContainer = $outer_gap/panel/inner_gap/options
+
+var settings: Dictionary
+
func _on_back_pressed():
+ for k in settings.keys():
+ Global.settings[k]["value"] = settings[k].get_value()
+ Global.save_settings()
$SceneTransition.transition_to("res://menu/main_menu.tscn")
+
+func _ready():
+ for k in Global.settings.keys():
+ var v = Global.settings[k]
+ var row: SettingsRow = preload("res://menu/settings_row.tscn").instantiate()
+ row.setup(v["description"], v["value"])
+ options.add_child(row)
+ settings[k] = row
diff --git a/client/menu/settings_row.gd b/client/menu/settings_row.gd
new file mode 100644
index 00000000..ee4b8cb9
--- /dev/null
+++ b/client/menu/settings_row.gd
@@ -0,0 +1,36 @@
+class_name SettingsRow
+extends PanelContainer
+
+@onready var value_parent = $HBoxContainer/BoxContainer
+@onready var label = $HBoxContainer/Label
+
+var value_node
+var description = tr("no value was given to the row")
+
+func setup(description_: String, value):
+ description = description_
+ if value is bool:
+ value_node = CheckButton.new()
+ value_node.button_pressed = value
+ elif value is String:
+ value_node = LineEdit.new()
+ value_node.text = value
+
+func _ready():
+ if value_node != null:
+ var c: Control = value_node
+ c.size_flags_vertical = Control.SIZE_EXPAND_FILL
+ c.size_flags_horizontal = Control.SIZE_EXPAND_FILL
+ label.text = description
+ value_parent.add_child(c)
+
+func get_value():
+ if value_node != null:
+ if value_node is CheckButton:
+ return value_node.button_pressed
+ elif value_node is LineEdit:
+ return value_node.text
+ else:
+ return null
+ else:
+ return null
diff --git a/client/menu/settings_row.tscn b/client/menu/settings_row.tscn
new file mode 100644
index 00000000..b083d291
--- /dev/null
+++ b/client/menu/settings_row.tscn
@@ -0,0 +1,24 @@
+[gd_scene load_steps=2 format=3 uid="uid://o5e5vpem8w0k"]
+
+[ext_resource type="Script" path="res://menu/settings_row.gd" id="1_lxjnc"]
+
+[node name="SettingsRow" type="PanelContainer"]
+offset_right = 105.0
+offset_bottom = 23.0
+size_flags_horizontal = 3
+script = ExtResource("1_lxjnc")
+
+[node name="HBoxContainer" type="HBoxContainer" parent="."]
+layout_mode = 2
+
+[node name="Label" type="Label" parent="HBoxContainer"]
+layout_mode = 2
+size_flags_horizontal = 3
+
+[node name="BoxContainer" type="BoxContainer" parent="HBoxContainer"]
+custom_minimum_size = Vector2(300, 50)
+layout_mode = 2
+alignment = 2
+
+[node name="Button" type="Button" parent="HBoxContainer"]
+layout_mode = 2