From d21d6ead219abe4f8d9fbddef4b69d37138fecaa Mon Sep 17 00:00:00 2001 From: kobewi Date: Sat, 12 Apr 2025 11:28:29 +0200 Subject: [PATCH] Support custom features in project settings dialog --- editor/project_settings_editor.cpp | 49 ++++++++++++++++++------------ editor/project_settings_editor.h | 9 +++++- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp index db5113fa703..cf9f8080b36 100644 --- a/editor/project_settings_editor.cpp +++ b/editor/project_settings_editor.cpp @@ -42,8 +42,6 @@ #include "scene/gui/check_button.h" #include "servers/movie_writer/movie_writer.h" -ProjectSettingsEditor *ProjectSettingsEditor::singleton = nullptr; - void ProjectSettingsEditor::connect_filesystem_dock_signals(FileSystemDock *p_fs_dock) { localization_editor->connect_filesystem_dock_signals(p_fs_dock); group_settings->connect_filesystem_dock_signals(p_fs_dock); @@ -179,35 +177,45 @@ void ProjectSettingsEditor::_property_box_changed(const String &p_text) { } void ProjectSettingsEditor::_feature_selected(int p_index) { - Vector t = property_box->get_text().strip_edges().split(".", true, 1); - const String feature = p_index ? "." + feature_box->get_item_text(p_index) : ""; - property_box->set_text(t[0] + feature); + const String property = property_box->get_text().strip_edges().get_slicec('.', 0); + if (p_index == FEATURE_ALL) { + property_box->set_text(property); + } else if (p_index == FEATURE_CUSTOM) { + property_box->set_text(property + ".custom"); + const int len = property.length() + 1; + property_box->select(len); + property_box->set_caret_column(len); + property_box->grab_focus(); + } else { + property_box->set_text(property + "." + feature_box->get_item_text(p_index)); + }; _update_property_box(); } void ProjectSettingsEditor::_update_property_box() { const String setting = _get_setting_name(); - const Vector t = setting.split(".", true, 1); - const String &name = t[0]; - const String feature = (t.size() == 2) ? t[1] : ""; - bool feature_invalid = (t.size() == 2) && (t[1].is_empty()); + int slices = setting.get_slice_count("."); + const String name = setting.get_slicec('.', 0); + const String feature = setting.get_slicec('.', 1); + bool feature_invalid = slices > 2 || (slices == 2 && feature.is_empty()); add_button->set_disabled(true); del_button->set_disabled(true); - if (!feature.is_empty()) { - feature_invalid = true; - for (int i = 1; i < feature_box->get_item_count(); i++) { + if (feature.is_empty() || feature_invalid) { + feature_box->select(FEATURE_ALL); + } else { + bool is_custom = true; + for (int i = FEATURE_FIRST; i < feature_box->get_item_count(); i++) { if (feature == feature_box->get_item_text(i)) { - feature_invalid = false; + is_custom = false; feature_box->select(i); break; } } - } - - if (feature.is_empty() || feature_invalid) { - feature_box->select(0); + if (is_custom) { + feature_box->select(FEATURE_CUSTOM); + } } if (property_box->get_text().is_empty()) { @@ -330,8 +338,11 @@ void ProjectSettingsEditor::_add_feature_overrides() { } feature_box->clear(); - feature_box->add_item(TTR("(All)"), 0); // So it is always on top. - int id = 1; + feature_box->add_item(TTR("(All)"), FEATURE_ALL); // So it is always on top. + feature_box->add_item(TTR("Custom"), FEATURE_CUSTOM); + feature_box->add_separator(); + + int id = FEATURE_FIRST; for (const String &E : presets) { feature_box->add_item(E, id++); } diff --git a/editor/project_settings_editor.h b/editor/project_settings_editor.h index a6f846ca8ad..9506458ea51 100644 --- a/editor/project_settings_editor.h +++ b/editor/project_settings_editor.h @@ -49,7 +49,14 @@ class FileSystemDock; class ProjectSettingsEditor : public AcceptDialog { GDCLASS(ProjectSettingsEditor, AcceptDialog); - static ProjectSettingsEditor *singleton; + inline static ProjectSettingsEditor *singleton = nullptr; + + enum { + FEATURE_ALL, + FEATURE_CUSTOM, + FEATURE_FIRST, + }; + ProjectSettings *ps = nullptr; Timer *timer = nullptr;