diff options
author | tpart <tpart120@proton.me> | 2024-08-31 13:20:11 +0200 |
---|---|---|
committer | tpart <tpart120@proton.me> | 2024-08-31 13:20:11 +0200 |
commit | 260b29c9f5c010c67fbf0b38b0aac859effb46f1 (patch) | |
tree | eaa9efdcf52ba59dab7742a78acb8a3c36bb1751 | |
parent | d765bd2fc2cc303bf14699f32d93be8f448c4bfd (diff) | |
download | hurrycurry-260b29c9f5c010c67fbf0b38b0aac859effb46f1.tar hurrycurry-260b29c9f5c010c67fbf0b38b0aac859effb46f1.tar.bz2 hurrycurry-260b29c9f5c010c67fbf0b38b0aac859effb46f1.tar.zst |
Add settings categories
-rw-r--r-- | client/global.gd | 81 | ||||
-rw-r--r-- | client/menu/settings.gd | 44 | ||||
-rw-r--r-- | client/menu/settings.tscn | 13 | ||||
-rw-r--r-- | client/menu/settings/settings_category.gd | 26 |
4 files changed, 104 insertions, 60 deletions
diff --git a/client/global.gd b/client/global.gd index 9521eed7..6d261814 100644 --- a/client/global.gd +++ b/client/global.gd @@ -43,35 +43,47 @@ var languages := language_array() var using_joypad := false var using_touch := false -var default_settings := { - "language": DropdownSetting.new(tr("Language"), 0, languages.map(func(e): return e[1])), - "master_volume": RangeSetting.new(tr("Master Volume"), 0, -30, 0), - "music_volume": RangeSetting.new(tr("Music Volume"), 0, -30, 0), - "sfx_volume": RangeSetting.new(tr("SFX Volume"), 0, -30, 0), - "fullscreen": DropdownSetting.new(tr("Fullscreen"), 0, [tr("Keep"), tr("Always"), tr("Never")]), - "touch_controls": DropdownSetting.new(tr("Enable touch screen controls"), 0, [tr("Automatic"), tr("Enabled"), tr("Disabled")]), - "interpolate_camera_rotation": ToggleSetting.new(tr("Smooth camera rotation"), true), - "invert_camera": ToggleSetting.new(tr("Invert camera movement"), false), - "usernames": ToggleSetting.new(tr("Show username tags"), true), - "server_binary": TextSetting.new(tr("Server binary (leave empty to search PATH)"), "", tr("Enter path")), - "server_data": TextSetting.new(tr("Server data directory (leave empty to auto-detect)"), "", tr("Enter path")), - "ui_scale_mode": DropdownSetting.new(tr("UI scale mode"), 0, [tr("Resize"), tr("Disabled")]), - "ui_scale_factor": RangeSetting.new(tr("UI scale factor"), 1. if not on_mobile() else 1.5, 0.5, 1.5, 3), - "aa": DropdownSetting.new(tr("Anti-aliasing"), 2 if on_high_end() else 0, [tr("Disabled"), "FXAA", "MSAA 2x", "MSAA 4x"]), - "ssao": ToggleSetting.new(tr("Ambient occlusion"), true if on_high_end() else false), - "taa": ToggleSetting.new(tr("Temporal Anti-Aliasing"), false), - "gi": DropdownSetting.new(tr("Global illumination"), 0, [tr("Disabled"), tr("SDFGI"), tr("Voxel GI")]), - "shadows": ToggleSetting.new(tr("Enable shadows"), true if on_high_end() else false), - "glow": ToggleSetting.new(tr("Enable glow"), true if on_high_end() else false), - "debug_info": ToggleSetting.new(tr("Display debug info (Framerate, etc.)"), false), - "grass_amount": RangeSetting.new(tr("3D grass amount per grass tile"), 16 if on_high_end() else 0, 0, 32, false), - "lq_trees": ToggleSetting.new(tr("Low-poly trees"), false if on_high_end() else true), - "setup_complete": ToggleSetting.new(tr("Initial setup complete. (Uncheck and restart to reenter)"), false), - "tutorial_started": ToggleSetting.new(tr("Tutorial started"), false), - "latch_boost": ToggleSetting.new(tr("Always extend boost to maximum duration"), true), - "ui_blur": ToggleSetting.new(tr("Enable UI blur"), true) -} +var default_settings := [ + SettingsCategory.new(tr("Gameplay"), "gameplay", { + "touch_controls": DropdownSetting.new(tr("Enable touch screen controls"), 0, [tr("Automatic"), tr("Enabled"), tr("Disabled")]), + "interpolate_camera_rotation": ToggleSetting.new(tr("Smooth camera rotation"), true), + "invert_camera": ToggleSetting.new(tr("Invert camera movement"), false), + "usernames": ToggleSetting.new(tr("Show username tags"), true), + "setup_complete": ToggleSetting.new(tr("Initial setup complete. (Uncheck and restart to reenter)"), false), + "tutorial_started": ToggleSetting.new(tr("Tutorial started"), false), + "latch_boost": ToggleSetting.new(tr("Always extend boost to maximum duration"), true), + }), + SettingsCategory.new(tr("User interface"), "ui", { + "language": DropdownSetting.new(tr("Language"), 0, languages.map(func(e): return e[1])), + "ui_scale_mode": DropdownSetting.new(tr("UI scale mode"), 0, [tr("Resize"), tr("Disabled")]), + "ui_scale_factor": RangeSetting.new(tr("UI scale factor"), 1. if not on_mobile() else 1.5, 0.5, 1.5, 3), + }), + SettingsCategory.new(tr("Graphics"), "graphics", { + "fullscreen": DropdownSetting.new(tr("Fullscreen"), 0, [tr("Keep"), tr("Always"), tr("Never")]), + "aa": DropdownSetting.new(tr("Anti-aliasing"), 2 if on_high_end() else 0, [tr("Disabled"), "FXAA", "MSAA 2x", "MSAA 4x"]), + "ssao": ToggleSetting.new(tr("Ambient occlusion"), true if on_high_end() else false), + "taa": ToggleSetting.new(tr("Temporal Anti-Aliasing"), false), + "gi": DropdownSetting.new(tr("Global illumination"), 0, [tr("Disabled"), tr("SDFGI"), tr("Voxel GI")]), + "shadows": ToggleSetting.new(tr("Enable shadows"), true if on_high_end() else false), + "glow": ToggleSetting.new(tr("Enable glow"), true if on_high_end() else false), + "grass_amount": RangeSetting.new(tr("3D grass amount per grass tile"), 16 if on_high_end() else 0, 0, 32, false), + "lq_trees": ToggleSetting.new(tr("Low-poly trees"), false if on_high_end() else true), + "ui_blur": ToggleSetting.new(tr("Enable UI blur"), true) + }), + SettingsCategory.new(tr("Audio"), "audio", { + "master_volume": RangeSetting.new(tr("Master Volume"), 0, -30, 0), + "music_volume": RangeSetting.new(tr("Music Volume"), 0, -30, 0), + "sfx_volume": RangeSetting.new(tr("SFX Volume"), 0, -30, 0), + }), + SettingsCategory.new(tr("Other"), "other", { + "server_binary": TextSetting.new(tr("Server binary (leave empty to search PATH)"), "", tr("Enter path")), + "server_data": TextSetting.new(tr("Server data directory (leave empty to auto-detect)"), "", tr("Enter path")), + "debug_info": ToggleSetting.new(tr("Display debug info (Framerate, etc.)"), false), + }) + ] +# Profile and settings are stored in a Dictionary[String, GameSetting] +# Unlike the default settings, the settings dictionary is not split into categories. var profile: Dictionary var settings: Dictionary @@ -262,7 +274,10 @@ func load_dict(path: String, default: Dictionary) -> Dictionary: return saved_dict func load_settings(path: String): - settings = default_settings + for category: SettingsCategory in default_settings: + for k: String in category.settings.keys(): + settings[k] = category.settings[k] + if not FileAccess.file_exists(path): print("Skip settings load") return @@ -270,11 +285,9 @@ func load_settings(path: String): var saved_dict = f.get_var() if saved_dict != null and saved_dict is Dictionary: - for k in default_settings.keys(): - var setting: GameSetting = default_settings[k] - if saved_dict.has(k) and typeof(setting.get_value()) == typeof(saved_dict[k]): - setting.set_value(saved_dict[k]) - settings[k] = setting + for k in settings.keys(): + if saved_dict.has(k) and typeof(settings[k].get_value()) == typeof(saved_dict[k]): + settings[k].set_value(saved_dict[k]) save_settings() # Save updated keys diff --git a/client/menu/settings.gd b/client/menu/settings.gd index 27e08db7..93155a93 100644 --- a/client/menu/settings.gd +++ b/client/menu/settings.gd @@ -16,7 +16,7 @@ # extends Menu -@onready var options: VBoxContainer = $OuterGap/Panel/InnerGap/VBoxContainer/ScrollContainer/Options +@onready var settings_tabs: TabContainer = $OuterGap/Panel/InnerGap/VBoxContainer/TabContainer func _ready(): super() @@ -31,25 +31,35 @@ func exit(): super() func update_rows(fix_focus = false): - for c in options.get_children(): + for c in settings_tabs.get_children(): c.queue_free() - for i in Global.presets: - var label := Label.new() - label.text = i.label - var hbox := HBoxContainer.new() - var spacer := Control.new() - spacer.size_flags_horizontal = Control.SIZE_EXPAND - hbox.add_child(label) - hbox.add_child(spacer) - options.add_child(hbox) - for b in i.buttons(): - hbox.add_child(b) - - for k in Global.settings.keys(): - var row: SettingsRow = Global.settings[k].get_row() - options.add_child(row) +# TODO: Re-implement presets in new system +# for i in Global.presets: +# var label := Label.new() +# label.text = i.label +# var hbox := HBoxContainer.new() +# var spacer := Control.new() +# spacer.size_flags_horizontal = Control.SIZE_EXPAND +# hbox.add_child(label) +# hbox.add_child(spacer) +# options.add_child(hbox) +# for b in i.buttons(): +# hbox.add_child(b) + for category: SettingsCategory in Global.default_settings: + var category_settings = category.settings + var scroll := ScrollContainerCustom.new() + var options := VBoxContainer.new() + scroll.name = category.name + scroll.size_flags_horizontal = Control.SIZE_EXPAND_FILL + settings_tabs.add_child(scroll) + options.size_flags_horizontal = Control.SIZE_EXPAND_FILL + scroll.add_child(options) + for k: String in category_settings.keys(): + var row: SettingsRow = Global.settings[k].get_row() + options.add_child(row) + if fix_focus: pass # TODO: Not implemented! diff --git a/client/menu/settings.tscn b/client/menu/settings.tscn index b7918339..9f523f7c 100644 --- a/client/menu/settings.tscn +++ b/client/menu/settings.tscn @@ -4,7 +4,8 @@ [ext_resource type="Script" path="res://menu/settings.gd" id="2_3hgm8"] [ext_resource type="Material" uid="uid://beea1pc5nt67r" path="res://menu/theme/dark_blur_material.tres" id="3_8nykw"] [ext_resource type="Script" path="res://menu/blur_setup.gd" id="4_v6q3y"] -[ext_resource type="Script" path="res://menu/scroll_container_custom.gd" id="4_vfb63"] + +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_85urc"] [node name="SettingsMenu" type="Control"] layout_mode = 3 @@ -51,16 +52,10 @@ size_flags_horizontal = 0 theme_override_font_sizes/font_size = 36 text = "Settings" -[node name="ScrollContainer" type="ScrollContainer" parent="OuterGap/Panel/InnerGap/VBoxContainer"] -layout_mode = 2 -size_flags_vertical = 3 -follow_focus = true -script = ExtResource("4_vfb63") - -[node name="Options" type="VBoxContainer" parent="OuterGap/Panel/InnerGap/VBoxContainer/ScrollContainer"] +[node name="TabContainer" type="TabContainer" parent="OuterGap/Panel/InnerGap/VBoxContainer"] layout_mode = 2 -size_flags_horizontal = 3 size_flags_vertical = 3 +theme_override_styles/panel = SubResource("StyleBoxEmpty_85urc") [node name="Back" type="Button" parent="OuterGap/Panel/InnerGap/VBoxContainer"] layout_mode = 2 diff --git a/client/menu/settings/settings_category.gd b/client/menu/settings/settings_category.gd new file mode 100644 index 00000000..e3c2ac09 --- /dev/null +++ b/client/menu/settings/settings_category.gd @@ -0,0 +1,26 @@ +# Hurry Curry! - a game about cooking +# Copyright 2024 tpart +# +# 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/>. +# +class_name SettingsCategory +extends Object + +var name: String +var id: String +var settings: Dictionary # Dictionary[String, GameSetting] + +func _init(new_name: String, new_id: String, new_settings: Dictionary): + name = new_name + id = new_id + settings = new_settings |