aboutsummaryrefslogtreecommitdiff
path: root/client/menu/settings
diff options
context:
space:
mode:
Diffstat (limited to 'client/menu/settings')
-rw-r--r--client/menu/settings/dropdown_setting.gd40
-rw-r--r--client/menu/settings/game_setting.gd51
-rw-r--r--client/menu/settings/range_setting.gd42
-rw-r--r--client/menu/settings/settings_menu.gd43
-rw-r--r--client/menu/settings/settings_row.gd36
-rw-r--r--client/menu/settings/settings_row.tscn39
-rw-r--r--client/menu/settings/text_setting.gd38
-rw-r--r--client/menu/settings/toggle_setting.gd34
8 files changed, 323 insertions, 0 deletions
diff --git a/client/menu/settings/dropdown_setting.gd b/client/menu/settings/dropdown_setting.gd
new file mode 100644
index 00000000..47f7355b
--- /dev/null
+++ b/client/menu/settings/dropdown_setting.gd
@@ -0,0 +1,40 @@
+# Undercooked - a game about cooking
+# 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/>.
+#
+class_name DropdownSetting
+extends GameSetting
+
+var options: Array
+
+func _init(new_description: String, new_preset: int, new_options: Array):
+ assert(new_preset < new_options.size())
+ super(new_description, new_preset)
+ options = new_options
+
+func _update_row():
+ super()
+ row.value_node = OptionButton.new()
+ for i in options:
+ row.value_node.add_item(i)
+ row.value_node.select(_value)
+
+func fetch_setting():
+ if row != null:
+ _value = row.value_node.selected
+
+func set_value(v):
+ super(v)
+ if row != null:
+ row.value_node.selected = _value
diff --git a/client/menu/settings/game_setting.gd b/client/menu/settings/game_setting.gd
new file mode 100644
index 00000000..67dca232
--- /dev/null
+++ b/client/menu/settings/game_setting.gd
@@ -0,0 +1,51 @@
+# Undercooked - a game about cooking
+# 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/>.
+#
+class_name GameSetting
+extends Object
+
+var preset
+var _value
+var description: String
+
+var row: SettingsRow
+
+func _init(new_description: String, new_preset):
+ _value = new_preset
+ preset = new_preset
+ description = new_description
+
+func reset():
+ set_value(preset)
+
+func get_row() -> SettingsRow:
+ _update_row()
+ return row
+
+func _update_row():
+ if row != null:
+ row.queue_free()
+ row = preload("res://menu/settings/settings_row.tscn").instantiate()
+ row.description = description
+ row.reset.connect(reset)
+
+func fetch_setting():
+ pass
+
+func get_value():
+ return _value
+
+func set_value(v):
+ _value = v
diff --git a/client/menu/settings/range_setting.gd b/client/menu/settings/range_setting.gd
new file mode 100644
index 00000000..97229db9
--- /dev/null
+++ b/client/menu/settings/range_setting.gd
@@ -0,0 +1,42 @@
+# Undercooked - a game about cooking
+# 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/>.
+#
+class_name RangeSetting
+extends GameSetting
+
+var min_value: float
+var max_value: float
+
+func _init(new_description: String, new_preset: float, new_min_value: float, new_max_value: float):
+ super(new_description, new_preset)
+ min_value = new_min_value
+ max_value = new_max_value
+
+func _update_row():
+ super()
+ row.value_node = HSlider.new()
+ row.value_node.min_value = min_value
+ row.value_node.max_value = max_value
+ row.value_node.tick_count = abs(max_value - min_value)
+ row.value_node.value = _value
+
+func fetch_setting():
+ if row != null:
+ _value = row.value_node.value
+
+func set_value(v):
+ super(v)
+ if row != null:
+ row.value_node.value = _value
diff --git a/client/menu/settings/settings_menu.gd b/client/menu/settings/settings_menu.gd
new file mode 100644
index 00000000..bdced23b
--- /dev/null
+++ b/client/menu/settings/settings_menu.gd
@@ -0,0 +1,43 @@
+# Undercooked - a game about cooking
+# Copyright 2024 metamuffin
+#
+# 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 Control
+
+@onready var options: VBoxContainer = $OuterGap/Panel/InnerGap/VBoxContainer/ScrollContainer/Options
+@onready var menu_manager: MenuManager = get_parent()
+
+func _on_back_pressed():
+ Global.save_settings()
+ Global.update_language()
+ Global.update_fullscreen()
+ menu_manager.go_back()
+
+func _ready():
+ update_rows()
+
+func show_graphis():
+ menu_manager.goto("settings_graphics")
+
+func update_rows(fix_focus = false):
+ for c in options.get_children():
+ c.queue_free()
+
+ for k in Global.settings.keys():
+ var row: SettingsRow = Global.settings[k].get_row()
+ options.add_child(row)
+
+ if fix_focus:
+ await get_tree().process_frame
+ Global.focus_first_button(self)
diff --git a/client/menu/settings/settings_row.gd b/client/menu/settings/settings_row.gd
new file mode 100644
index 00000000..8c71a8c5
--- /dev/null
+++ b/client/menu/settings/settings_row.gd
@@ -0,0 +1,36 @@
+# Undercooked - a game about cooking
+# 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/>.
+#
+class_name SettingsRow
+extends PanelContainer
+
+signal reset()
+
+@onready var value_parent = $HBoxContainer/BoxContainer
+@onready var label = $HBoxContainer/Label
+
+var value_node: Node
+var description = tr("no value was given to the row")
+
+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 _on_reset_pressed():
+ reset.emit()
diff --git a/client/menu/settings/settings_row.tscn b/client/menu/settings/settings_row.tscn
new file mode 100644
index 00000000..d9c1f215
--- /dev/null
+++ b/client/menu/settings/settings_row.tscn
@@ -0,0 +1,39 @@
+[gd_scene load_steps=6 format=3 uid="uid://o5e5vpem8w0k"]
+
+[ext_resource type="Theme" uid="uid://b0qmvo504e457" path="res://menu/theme/theme.tres" id="1_iij3k"]
+[ext_resource type="Script" path="res://menu/settings/settings_row.gd" id="2_l8i7p"]
+[ext_resource type="FontFile" uid="uid://5ixo6b3bd3km" path="res://menu/theme/font-josefin-sans.woff2" id="3_7k5da"]
+
+[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_pk3rs"]
+content_margin_left = 16.0
+
+[sub_resource type="FontVariation" id="FontVariation_o6i7s"]
+base_font = ExtResource("3_7k5da")
+
+[node name="SettingsRow" type="PanelContainer"]
+offset_right = 105.0
+offset_bottom = 23.0
+size_flags_horizontal = 3
+theme = ExtResource("1_iij3k")
+script = ExtResource("2_l8i7p")
+
+[node name="HBoxContainer" type="HBoxContainer" parent="."]
+layout_mode = 2
+
+[node name="Label" type="Label" parent="HBoxContainer"]
+layout_mode = 2
+size_flags_horizontal = 3
+theme_override_styles/normal = SubResource("StyleBoxEmpty_pk3rs")
+
+[node name="BoxContainer" type="BoxContainer" parent="HBoxContainer"]
+custom_minimum_size = Vector2(300, 50)
+layout_mode = 2
+alignment = 2
+
+[node name="Reset" type="Button" parent="HBoxContainer"]
+layout_mode = 2
+theme_override_fonts/font = SubResource("FontVariation_o6i7s")
+theme_override_font_sizes/font_size = 24
+text = "↺"
+
+[connection signal="pressed" from="HBoxContainer/Reset" to="." method="_on_reset_pressed"]
diff --git a/client/menu/settings/text_setting.gd b/client/menu/settings/text_setting.gd
new file mode 100644
index 00000000..c8aa49d4
--- /dev/null
+++ b/client/menu/settings/text_setting.gd
@@ -0,0 +1,38 @@
+# Undercooked - a game about cooking
+# 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/>.
+#
+class_name TextSetting
+extends GameSetting
+
+var placeholder: String
+
+func _init(new_description: String, new_preset: String, new_placeholder: String = ""):
+ super(new_description, new_preset)
+ placeholder = new_placeholder
+
+func _update_row():
+ super()
+ row.value_node = LineEdit.new()
+ row.value_node.text = _value
+ row.value_node.placeholder_text = placeholder
+
+func fetch_setting():
+ if row != null:
+ _value = row.value_node.text
+
+func set_value(v):
+ super(v)
+ if row != null:
+ row.value_node.text = _value
diff --git a/client/menu/settings/toggle_setting.gd b/client/menu/settings/toggle_setting.gd
new file mode 100644
index 00000000..90e42264
--- /dev/null
+++ b/client/menu/settings/toggle_setting.gd
@@ -0,0 +1,34 @@
+# Undercooked - a game about cooking
+# 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/>.
+#
+class_name ToggleSetting
+extends GameSetting
+
+func _init(new_description: String, new_preset: bool):
+ super(new_description, new_preset)
+
+func fetch_setting():
+ if row != null:
+ _value = row.value_node.button_pressed
+
+func _update_row():
+ super()
+ row.value_node = CheckButton.new()
+ row.value_node.button_pressed = _value
+
+func set_value(v):
+ super(v)
+ if row != null:
+ row.value_node.button_pressed = _value