From 1910f91f17d1e0b6339acd172e9f9e7c24b0124b Mon Sep 17 00:00:00 2001 From: Christian Kaiser Date: Thu, 11 Jan 2024 17:13:23 -0300 Subject: [PATCH] Improve "Add" button consistency in Project Settings * Adds an icon to all the input-adjacent add/remove buttons * Adds a separator next to the action map "add" button * Changes the Shader Globals editor to be consistent with the others * Adds a clear button to the shader global name input --- editor/action_map_editor.cpp | 4 ++++ editor/editor_autoload_settings.cpp | 1 + editor/group_settings_editor.cpp | 3 +++ editor/project_settings_editor.cpp | 2 ++ editor/shader_globals_editor.cpp | 34 ++++++++++++++++++++++++----- editor/shader_globals_editor.h | 3 +++ 6 files changed, 41 insertions(+), 6 deletions(-) diff --git a/editor/action_map_editor.cpp b/editor/action_map_editor.cpp index 7bb6ec0d5d1..d7302d873fa 100644 --- a/editor/action_map_editor.cpp +++ b/editor/action_map_editor.cpp @@ -36,6 +36,7 @@ #include "editor/event_listener_line_edit.h" #include "editor/input_event_configuration_dialog.h" #include "scene/gui/check_button.h" +#include "scene/gui/separator.h" #include "scene/gui/tree.h" #include "scene/scene_string_names.h" @@ -357,6 +358,7 @@ void ActionMapEditor::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { action_list_search->set_right_icon(get_editor_theme_icon(SNAME("Search"))); + add_button->set_icon(get_editor_theme_icon(SNAME("Add"))); if (!actions_cache.is_empty()) { update_action_list(); } @@ -570,6 +572,8 @@ ActionMapEditor::ActionMapEditor() { // Disable the button and set its tooltip. _add_edit_text_changed(add_edit->get_text()); + add_hbox->add_child(memnew(VSeparator)); + show_builtin_actions_checkbutton = memnew(CheckButton); show_builtin_actions_checkbutton->set_text(TTR("Show Built-in Actions")); show_builtin_actions_checkbutton->connect("toggled", callable_mp(this, &ActionMapEditor::set_show_builtin_actions)); diff --git a/editor/editor_autoload_settings.cpp b/editor/editor_autoload_settings.cpp index 6a167e43689..45de4a54aeb 100644 --- a/editor/editor_autoload_settings.cpp +++ b/editor/editor_autoload_settings.cpp @@ -65,6 +65,7 @@ void EditorAutoloadSettings::_notification(int p_what) { case NOTIFICATION_THEME_CHANGED: { browse_button->set_icon(get_editor_theme_icon(SNAME("Folder"))); + add_autoload->set_icon(get_editor_theme_icon(SNAME("Add"))); } break; case NOTIFICATION_VISIBILITY_CHANGED: { diff --git a/editor/group_settings_editor.cpp b/editor/group_settings_editor.cpp index a91154ae361..42e117f4c18 100644 --- a/editor/group_settings_editor.cpp +++ b/editor/group_settings_editor.cpp @@ -45,6 +45,9 @@ void GroupSettingsEditor::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { update_groups(); } break; + case NOTIFICATION_THEME_CHANGED: { + add_button->set_icon(get_editor_theme_icon(SNAME("Add"))); + } break; } } diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp index b7a5521ffd8..1b0d791ff1c 100644 --- a/editor/project_settings_editor.cpp +++ b/editor/project_settings_editor.cpp @@ -556,6 +556,8 @@ void ProjectSettingsEditor::_update_action_map_editor() { } void ProjectSettingsEditor::_update_theme() { + add_button->set_icon(get_editor_theme_icon(SNAME("Add"))); + del_button->set_icon(get_editor_theme_icon(SNAME("Remove"))); search_box->set_right_icon(get_editor_theme_icon(SNAME("Search"))); restart_close_button->set_icon(get_editor_theme_icon(SNAME("Close"))); restart_container->add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), SNAME("Tree"))); diff --git a/editor/shader_globals_editor.cpp b/editor/shader_globals_editor.cpp index 2a5290307c3..46f520df458 100644 --- a/editor/shader_globals_editor.cpp +++ b/editor/shader_globals_editor.cpp @@ -344,15 +344,29 @@ static Variant create_var(RS::GlobalShaderParameterType p_type) { } } -void ShaderGlobalsEditor::_variable_added() { - String var = variable_name->get_text().strip_edges(); - if (var.is_empty() || !var.is_valid_identifier()) { - EditorNode::get_singleton()->show_warning(TTR("Please specify a valid shader uniform identifier name.")); - return; +String ShaderGlobalsEditor::_check_new_variable_name(const String &p_variable_name) { + if (p_variable_name.is_empty()) { + return TTR("Name cannot be empty."); } + if (!p_variable_name.is_valid_identifier()) { + return TTR("Name must be a valid identifier."); + } + + return ""; +} + +void ShaderGlobalsEditor::_variable_name_text_changed(const String &p_variable_name) { + const String &warning = _check_new_variable_name(p_variable_name.strip_edges()); + variable_add->set_tooltip_text(warning); + variable_add->set_disabled(!warning.is_empty()); +} + +void ShaderGlobalsEditor::_variable_added() { + String var = variable_name->get_text().strip_edges(); + if (RenderingServer::get_singleton()->global_shader_parameter_get(var).get_type() != Variant::NIL) { - EditorNode::get_singleton()->show_warning(vformat(TTR("Global shader parameter '%s' already exists'"), var)); + EditorNode::get_singleton()->show_warning(vformat(TTR("Global shader parameter '%s' already exists."), var)); return; } @@ -416,6 +430,10 @@ void ShaderGlobalsEditor::_notification(int p_what) { } } break; + case NOTIFICATION_THEME_CHANGED: { + variable_add->set_icon(get_editor_theme_icon(SNAME("Add"))); + } break; + case NOTIFICATION_PREDELETE: { inspector->edit(nullptr); } break; @@ -431,6 +449,9 @@ ShaderGlobalsEditor::ShaderGlobalsEditor() { add_menu_hb->add_child(memnew(Label(TTR("Name:")))); variable_name = memnew(LineEdit); variable_name->set_h_size_flags(SIZE_EXPAND_FILL); + variable_name->set_clear_button_enabled(true); + variable_name->connect("text_changed", callable_mp(this, &ShaderGlobalsEditor::_variable_name_text_changed)); + add_menu_hb->add_child(variable_name); add_menu_hb->add_child(memnew(Label(TTR("Type:")))); @@ -443,6 +464,7 @@ ShaderGlobalsEditor::ShaderGlobalsEditor() { } variable_add = memnew(Button(TTR("Add"))); + variable_add->set_disabled(true); add_menu_hb->add_child(variable_add); variable_add->connect("pressed", callable_mp(this, &ShaderGlobalsEditor::_variable_added)); diff --git a/editor/shader_globals_editor.h b/editor/shader_globals_editor.h index 590da342d48..fc50564aae9 100644 --- a/editor/shader_globals_editor.h +++ b/editor/shader_globals_editor.h @@ -49,6 +49,9 @@ class ShaderGlobalsEditor : public VBoxContainer { OptionButton *variable_type = nullptr; Button *variable_add = nullptr; + String _check_new_variable_name(const String &p_variable_name); + + void _variable_name_text_changed(const String &p_variable_name); void _variable_added(); void _variable_deleted(const String &p_variable); void _changed();