diff options
Diffstat (limited to 'editor')
-rw-r--r-- | editor/editor_spin_slider.cpp | 2 | ||||
-rw-r--r-- | editor/editor_toaster.cpp | 17 | ||||
-rw-r--r-- | editor/editor_toaster.h | 2 | ||||
-rw-r--r-- | editor/plugins/theme_editor_plugin.cpp | 37 | ||||
-rw-r--r-- | editor/plugins/theme_editor_plugin.h | 7 |
5 files changed, 52 insertions, 13 deletions
diff --git a/editor/editor_spin_slider.cpp b/editor/editor_spin_slider.cpp index ce33f54243..111c8c699e 100644 --- a/editor/editor_spin_slider.cpp +++ b/editor/editor_spin_slider.cpp @@ -388,7 +388,7 @@ void EditorSpinSlider::_draw_spin_slider() { // Draw the horizontal slider's grabber. c.a = 0.9; - const Rect2 grabber_rect = Rect2(ofs + gofs, svofs + 1, grabber_w, 2 * EDSCALE); + const Rect2 grabber_rect = Rect2(ofs + gofs, svofs, grabber_w, 4 * EDSCALE); draw_rect(grabber_rect, c); grabbing_spinner_mouse_pos = get_global_position() + grabber_rect.get_center(); diff --git a/editor/editor_toaster.cpp b/editor/editor_toaster.cpp index 0d9a546b8e..05b895519d 100644 --- a/editor/editor_toaster.cpp +++ b/editor/editor_toaster.cpp @@ -173,11 +173,7 @@ void EditorToaster::_error_handler(void *p_self, const char *p_func, const char } Severity severity = (p_type == ERR_HANDLER_WARNING) ? SEVERITY_WARNING : SEVERITY_ERROR; - if (Thread::get_caller_id() != Thread::get_main_id()) { - EditorToaster::get_singleton()->call_deferred(SNAME("popup_str"), err_str, severity, tooltip_str); - } else { - EditorToaster::get_singleton()->popup_str(err_str, severity, tooltip_str); - } + EditorToaster::get_singleton()->popup_str(err_str, severity, tooltip_str); } } @@ -387,6 +383,12 @@ Control *EditorToaster::popup(Control *p_control, Severity p_severity, double p_ } void EditorToaster::popup_str(String p_message, Severity p_severity, String p_tooltip) { + // Since "_popup_str" adds nodes to the tree, and since the "add_child" method is not + // thread-safe, it's better to defer the call to the next cycle to be thread-safe. + call_deferred(SNAME("_popup_str"), p_message, p_severity, p_tooltip); +} + +void EditorToaster::_popup_str(String p_message, Severity p_severity, String p_tooltip) { // Check if we already have a popup with the given message. Control *control = nullptr; for (KeyValue<Control *, Toast> element : toasts) { @@ -440,6 +442,11 @@ EditorToaster *EditorToaster::get_singleton() { return singleton; } +void EditorToaster::_bind_methods() { + // Binding method to make it defer-able. + ClassDB::bind_method(D_METHOD("_popup_str", "message", "severity", "tooltip"), &EditorToaster::_popup_str); +} + EditorToaster::EditorToaster() { set_notify_transform(true); set_process_internal(true); diff --git a/editor/editor_toaster.h b/editor/editor_toaster.h index aac80d8fb1..502498986a 100644 --- a/editor/editor_toaster.h +++ b/editor/editor_toaster.h @@ -94,9 +94,11 @@ private: void _set_notifications_enabled(bool p_enabled); void _repop_old(); + void _popup_str(String p_message, Severity p_severity, String p_tooltip); protected: static EditorToaster *singleton; + static void _bind_methods(); void _notification(int p_what); diff --git a/editor/plugins/theme_editor_plugin.cpp b/editor/plugins/theme_editor_plugin.cpp index 89016b8758..b5d2b571f5 100644 --- a/editor/plugins/theme_editor_plugin.cpp +++ b/editor/plugins/theme_editor_plugin.cpp @@ -1996,7 +1996,7 @@ void ThemeTypeDialog::_dialog_about_to_show() { } void ThemeTypeDialog::ok_pressed() { - emit_signal(SNAME("type_selected"), add_type_filter->get_text().strip_edges()); + _add_type_selected(add_type_filter->get_text().strip_edges()); } void ThemeTypeDialog::_update_add_type_options(const String &p_filter) { @@ -2042,12 +2042,25 @@ void ThemeTypeDialog::_add_type_options_cbk(int p_index) { } void ThemeTypeDialog::_add_type_dialog_entered(const String &p_value) { - emit_signal(SNAME("type_selected"), p_value.strip_edges()); - hide(); + _add_type_selected(p_value.strip_edges()); } void ThemeTypeDialog::_add_type_dialog_activated(int p_index) { - emit_signal(SNAME("type_selected"), add_type_options->get_item_text(p_index)); + _add_type_selected(add_type_options->get_item_text(p_index)); +} + +void ThemeTypeDialog::_add_type_selected(const String &p_type_name) { + pre_submitted_value = p_type_name; + if (p_type_name.is_empty()) { + add_type_confirmation->popup_centered(); + return; + } + + _add_type_confirmed(); +} + +void ThemeTypeDialog::_add_type_confirmed() { + emit_signal(SNAME("type_selected"), pre_submitted_value); hide(); } @@ -2082,11 +2095,13 @@ void ThemeTypeDialog::set_include_own_types(bool p_enable) { } ThemeTypeDialog::ThemeTypeDialog() { + set_hide_on_ok(false); + VBoxContainer *add_type_vb = memnew(VBoxContainer); add_child(add_type_vb); Label *add_type_filter_label = memnew(Label); - add_type_filter_label->set_text(TTR("Name:")); + add_type_filter_label->set_text(TTR("Filter the list of types or create a new custom type:")); add_type_vb->add_child(add_type_filter_label); add_type_filter = memnew(LineEdit); @@ -2095,7 +2110,7 @@ ThemeTypeDialog::ThemeTypeDialog() { add_type_filter->connect("text_submitted", callable_mp(this, &ThemeTypeDialog::_add_type_dialog_entered)); Label *add_type_options_label = memnew(Label); - add_type_options_label->set_text(TTR("Node Types:")); + add_type_options_label->set_text(TTR("Available Node-based types:")); add_type_vb->add_child(add_type_options_label); add_type_options = memnew(ItemList); @@ -2103,6 +2118,12 @@ ThemeTypeDialog::ThemeTypeDialog() { add_type_vb->add_child(add_type_options); add_type_options->connect("item_selected", callable_mp(this, &ThemeTypeDialog::_add_type_options_cbk)); add_type_options->connect("item_activated", callable_mp(this, &ThemeTypeDialog::_add_type_dialog_activated)); + + add_type_confirmation = memnew(ConfirmationDialog); + add_type_confirmation->set_title(TTR("Type name is empty!")); + add_type_confirmation->set_text(TTR("Are you sure you want to create an empty type?")); + add_type_confirmation->connect("confirmed", callable_mp(this, &ThemeTypeDialog::_add_type_confirmed)); + add_child(add_type_confirmation); } VBoxContainer *ThemeTypeEditor::_create_item_list(Theme::DataType p_data_type) { @@ -2603,6 +2624,7 @@ void ThemeTypeEditor::_list_type_selected(int p_index) { void ThemeTypeEditor::_add_type_button_cbk() { add_type_mode = ADD_THEME_TYPE; add_type_dialog->set_title(TTR("Add Item Type")); + add_type_dialog->get_ok_button()->set_text(TTR("Add Type")); add_type_dialog->set_include_own_types(false); add_type_dialog->popup_centered(Size2(560, 420) * EDSCALE); } @@ -2969,7 +2991,8 @@ void ThemeTypeEditor::_type_variation_changed(const String p_value) { void ThemeTypeEditor::_add_type_variation_cbk() { add_type_mode = ADD_VARIATION_BASE; - add_type_dialog->set_title(TTR("Add Variation Base Type")); + add_type_dialog->set_title(TTR("Set Variation Base Type")); + add_type_dialog->get_ok_button()->set_text(TTR("Set Base Type")); add_type_dialog->set_include_own_types(true); add_type_dialog->popup_centered(Size2(560, 420) * EDSCALE); } diff --git a/editor/plugins/theme_editor_plugin.h b/editor/plugins/theme_editor_plugin.h index f5ad577aff..bd1bf216e1 100644 --- a/editor/plugins/theme_editor_plugin.h +++ b/editor/plugins/theme_editor_plugin.h @@ -31,6 +31,7 @@ #ifndef THEME_EDITOR_PLUGIN_H #define THEME_EDITOR_PLUGIN_H +#include "scene/gui/dialogs.h" #include "scene/gui/margin_container.h" #include "scene/gui/option_button.h" #include "scene/gui/scroll_container.h" @@ -270,8 +271,11 @@ class ThemeTypeDialog : public ConfirmationDialog { Ref<Theme> edited_theme; bool include_own_types = false; + String pre_submitted_value; + LineEdit *add_type_filter; ItemList *add_type_options; + ConfirmationDialog *add_type_confirmation; void _dialog_about_to_show(); void ok_pressed() override; @@ -283,6 +287,9 @@ class ThemeTypeDialog : public ConfirmationDialog { void _add_type_dialog_entered(const String &p_value); void _add_type_dialog_activated(int p_index); + void _add_type_selected(const String &p_type_name); + void _add_type_confirmed(); + protected: void _notification(int p_what); static void _bind_methods(); |