diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/menu/settings/path_setting.gd | 57 | ||||
-rw-r--r-- | client/menu/settings/path_setting.gd.uid | 1 | ||||
-rw-r--r-- | client/menu/settings/text_setting.gd | 15 | ||||
-rw-r--r-- | client/settings.gd | 6 |
4 files changed, 69 insertions, 10 deletions
diff --git a/client/menu/settings/path_setting.gd b/client/menu/settings/path_setting.gd new file mode 100644 index 00000000..7be29cec --- /dev/null +++ b/client/menu/settings/path_setting.gd @@ -0,0 +1,57 @@ +# Hurry Curry! - a game about cooking +# Copyright 2025 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 PathSetting +extends TextSetting + +var access: FileDialog.Access +var file_mode: FileDialog.FileMode + +func _init(new_id: String, + new_default: String, + file_mode: FileDialog.FileMode, + new_placeholder: String = "", + access: FileDialog.Access = FileDialog.Access.ACCESS_FILESYSTEM +): + super(new_id, new_default) + placeholder = new_placeholder + self.access = access + self.file_mode = file_mode + +func create_row(): + var row = super () + var input: LineEdit = row.value_node; + input.size_flags_horizontal = Control.SIZE_EXPAND_FILL + row.value_node = HBoxContainer.new() + row.value_node.add_child(input) + var button := Button.new() + row.value_node.add_child(button) + button.pressed.connect(func(): + var d := FileDialog.new() + Global.focused_menu.add_child(d) + d.move_to_center() + d.use_native_dialog = true + d.borderless = true + d.dir_selected.connect(_selected.bind(input)) + d.file_selected.connect(_selected.bind(input)) + d.file_mode = file_mode + d.access = access + d.show() + ) + return row + +func _selected(path: String, input: LineEdit): + input.text = path + input.text_changed.emit(path) diff --git a/client/menu/settings/path_setting.gd.uid b/client/menu/settings/path_setting.gd.uid new file mode 100644 index 00000000..a524b17c --- /dev/null +++ b/client/menu/settings/path_setting.gd.uid @@ -0,0 +1 @@ +uid://cj5jf7t771j5b diff --git a/client/menu/settings/text_setting.gd b/client/menu/settings/text_setting.gd index 5fe9dd85..30f8b2fe 100644 --- a/client/menu/settings/text_setting.gd +++ b/client/menu/settings/text_setting.gd @@ -25,14 +25,15 @@ func _init(new_id: String, new_default: String, new_placeholder: String = ""): func create_row(): var row = super() - row.value_node = LineEdit.new() - row.value_node.placeholder_text = placeholder - row.value_node.text_changed.connect(func(text): Global.set_setting(key, text)) + var input := LineEdit.new() + input.placeholder_text = placeholder + input.text_changed.connect(func(text): Global.set_setting(key, text)) Settings.hook_changed_init(key, true, func(text): - if is_instance_valid(row): - var pos = row.value_node.caret_column - row.value_node.text = text - row.value_node.caret_column = pos + if is_instance_valid(input): + var pos = input.caret_column + input.text = text + input.caret_column = pos ) + row.value_node = input return row diff --git a/client/settings.gd b/client/settings.gd index 00b02c24..f225ee9f 100644 --- a/client/settings.gd +++ b/client/settings.gd @@ -66,9 +66,9 @@ static func get_root(): InputManager.input_map_to_settings(InputManager.default_input_map) ), SettingsCategory.new("server", [ - TextSetting.new("binary_path", ""), - TextSetting.new("editor_binary_path", ""), - TextSetting.new("data_path", ""), + PathSetting.new("binary_path", "", FileDialog.FileMode.FILE_MODE_OPEN_FILE), + PathSetting.new("editor_binary_path", "", FileDialog.FileMode.FILE_MODE_OPEN_DIR), + PathSetting.new("data_path", "", FileDialog.FileMode.FILE_MODE_OPEN_DIR), TextSetting.new("name", "A Hurry Curry! Server"), ToggleSetting.new("upnp", false), ToggleSetting.new("mdns", true), |