aboutsummaryrefslogtreecommitdiff
path: root/client/settings.gd
diff options
context:
space:
mode:
Diffstat (limited to 'client/settings.gd')
-rw-r--r--client/settings.gd165
1 files changed, 165 insertions, 0 deletions
diff --git a/client/settings.gd b/client/settings.gd
new file mode 100644
index 00000000..2c3ae9a5
--- /dev/null
+++ b/client/settings.gd
@@ -0,0 +1,165 @@
+# Hurry Curry! - a game about cooking
+# Copyright 2024 metamuffin
+# Copyright 2024 tpart
+# Copyright 2024 nokoe
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, version 3 of the License only.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+#
+extends Node
+class_name Settings
+
+static func get_root():
+ return SettingsRoot.new([
+ SettingsCategory.new("gameplay", [
+ ToggleSetting.new("interpolate_camera_rotation", false),
+ ToggleSetting.new("invert_camera", false),
+ ToggleSetting.new("usernames", true),
+ ToggleSetting.new("setup_complete", false),
+ ToggleSetting.new("tutorial_started", false),
+ ToggleSetting.new("latch_boost", true),
+ ]),
+ SettingsCategory.new("graphics", [
+ PresetRow.new("preset", {
+ "low": {"ui_blur": true, "aa": "disabled", "ssao": false, "taa": false, "shadows": false, "glow": false, "grass_amount": 0, "lq_trees": true},
+ "medium": {"ui_blur": true, "aa": "fx", "ssao": false, "taa": false, "shadows": true, "glow": false, "grass_amount": 0, "lq_trees": false},
+ "high": {"ui_blur": true, "aa": "ms2x", "ssao": true, "taa": false, "shadows": true, "glow": true, "grass_amount": 16, "lq_trees": false}
+ }),
+ DropdownSetting.new("fullscreen", "keep", ["keep", "always", "never"]),
+ DropdownSetting.new("aa", "ms2x" if Global.on_high_end() else "disabled", ["disabled", "fx", "ms2x", "ms4x"]),
+ ToggleSetting.new("ssao", true if Global.on_high_end() else false),
+ ToggleSetting.new("taa", false),
+ DropdownSetting.new("gi", "disabled", ["disabled", "sdfgi", "voxelgi"]),
+ ToggleSetting.new("shadows", true if Global.on_high_end() else false),
+ ToggleSetting.new("glow", true if Global.on_high_end() else false),
+ RangeSetting.new("grass_amount", 16 if Global.on_high_end() else 0, 0, 32, false),
+ ToggleSetting.new("lq_trees", false if Global.on_high_end() else true),
+ ToggleSetting.new("debug_info", false),
+ ToggleSetting.new("ui_blur", true)
+ ]),
+ SettingsCategory.new("audio", [
+ RangeSetting.new("master_volume", 0, -30, 0),
+ RangeSetting.new("music_volume", 0, -30, 0),
+ RangeSetting.new("sfx_volume", 0, -30, 0),
+ ]),
+ SettingsCategory.new("ui", [
+ DropdownSetting.new("touch_controls", "automatic", ["automatic", "enabled", "disabled"]),
+ DropdownSetting.new("language", "system", Global.language_list()),
+ DropdownSetting.new("scale_mode", "resize", ["resize", "disabled"]),
+ RangeSetting.new("scale_factor", 1. if not Global.on_mobile() else 1.5, 0.5, 1.5, 3),
+ ]),
+ SettingsCategory.new("input",
+ InputManager.input_map_to_settings(InputManager.default_input_map)
+ ),
+ SettingsCategory.new("other", [
+ TextSetting.new("server_binary", ""),
+ TextSetting.new("server_data", ""),
+ ])
+ ])
+
+static func trigger_hook(key: String, value):
+ if Settings.change_hooks_display.get(key) != null: Settings.change_hooks_display.get(key).call(value)
+ if Settings.change_hooks_apply.get(key) != null: Settings.change_hooks_apply.get(key).call(value)
+ if key.find(".") != -1: trigger_hook(key.rsplit(".", false, 1)[0], null)
+
+static func hook_changed(key: String, display: bool, callable: Callable):
+ if display: change_hooks_display[key] = callable
+ else: change_hooks_apply[key] = callable
+
+static func hook_changed_init(key: String, display: bool, callable: Callable):
+ hook_changed(key, display, callable)
+ callable.call(Global.get_setting(key))
+
+static func get_category_dict(prefix: String):
+ var map = {}
+ for k in Global.settings.keys():
+ var kn = k.trim_prefix(prefix+".")
+ if kn == k: continue
+ map[kn] = Global.get_setting(k)
+ return map
+
+static var change_hooks_display = {}
+static var change_hooks_apply = {
+ "input": h_input,
+ "graphics.aa": h_aa,
+ "graphics.taa": h_taa,
+ "graphics.fullscreen": h_fullscreen,
+ "ui.scale_mode": h_scale_mode,
+ "ui.scale_factor": h_scale_factor,
+ "ui.language": h_language,
+ "audio.master_volume": h_volume_master,
+ "audio.music_volume": h_volume_music,
+ "audio.sfx_volume": h_volume_sfx,
+}
+
+static func apply_initial():
+ for key in change_hooks_apply.keys():
+ change_hooks_apply[key].call(Global.get_setting(key))
+
+static func h_aa(mode):
+ match mode:
+ "disabled":
+ Global.get_viewport().msaa_2d = Viewport.MSAA_DISABLED
+ Global.get_viewport().msaa_3d = Viewport.MSAA_DISABLED
+ Global.get_viewport().screen_space_aa = Viewport.SCREEN_SPACE_AA_DISABLED
+ "fx":
+ Global.get_viewport().msaa_2d = Viewport.MSAA_DISABLED
+ Global.get_viewport().msaa_3d = Viewport.MSAA_DISABLED
+ Global.get_viewport().screen_space_aa = Viewport.SCREEN_SPACE_AA_FXAA
+ "ms2x":
+ Global.get_viewport().msaa_2d = Viewport.MSAA_2X
+ Global.get_viewport().msaa_3d = Viewport.MSAA_2X
+ Global.get_viewport().screen_space_aa = Viewport.SCREEN_SPACE_AA_DISABLED
+ "ms4x":
+ Global.get_viewport().msaa_2d = Viewport.MSAA_4X
+ Global.get_viewport().msaa_3d = Viewport.MSAA_4X
+ Global.get_viewport().screen_space_aa = Viewport.SCREEN_SPACE_AA_DISABLED
+
+static func h_taa(enabled):
+ Global.get_viewport().use_taa = enabled
+
+static func h_scale_mode(mode: String):
+ match mode:
+ "resize": Global.get_tree().root.content_scale_mode = Window.CONTENT_SCALE_MODE_CANVAS_ITEMS
+ "disabled": Global.get_tree().root.content_scale_mode = Window.CONTENT_SCALE_MODE_DISABLED
+
+static func h_scale_factor(value: float):
+ Global.get_tree().root.content_scale_factor = value
+
+static func h_volume_master(value: float): Sound.set_volume(0, value)
+static func h_volume_music(value: float): Sound.set_volume(1, value)
+static func h_volume_sfx(value: float): Sound.set_volume(2, value)
+
+static func h_touch(mode: String):
+ match mode:
+ "enabled": Global.using_touch = true
+ "disabled": Global.using_touch = false
+ Global.using_touch_change.emit()
+
+static func h_language(language: String):
+ if language == "system": language = OS.get_locale_language()
+ TranslationServer.set_locale(language)
+
+static func h_fullscreen(mode: String):
+ match mode:
+ "keep": pass
+ "always": DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
+ "never": if DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_FULLSCREEN:
+ DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
+
+static func h_input(_x):
+ InputManager.apply_input_map(Settings.get_category_dict("input"))
+
+# TODO whatever this does
+# if not get_setting("tutorial_started"):
+# for k in profile["hints"].keys():
+# set_hint(k, false)