diff options
author | megalobyte <megalobyte@protonmail.com> | 2022-02-15 21:44:22 -0500 |
---|---|---|
committer | megalobyte <megalobyte@protonmail.com> | 2022-02-16 08:44:37 -0500 |
commit | 8824b6c5e9dc6a24a17452ded0c800ec267f812f (patch) | |
tree | 9902ce6e7a98f5deb6639b25c7e8d16354629889 | |
parent | 98b97d34df7f3ab2cafc3847358c231c3d357b40 (diff) |
Update if == NOTIFICATION_* to switch statements to match coding style
38 files changed, 1131 insertions, 1013 deletions
diff --git a/editor/import/dynamic_font_import_settings.cpp b/editor/import/dynamic_font_import_settings.cpp index 864e69a16e..8486d170a7 100644 --- a/editor/import/dynamic_font_import_settings.cpp +++ b/editor/import/dynamic_font_import_settings.cpp @@ -900,13 +900,18 @@ String DynamicFontImportSettings::_pad_zeros(const String &p_hex) const { } void DynamicFontImportSettings::_notification(int p_what) { - if (p_what == NOTIFICATION_READY) { - connect("confirmed", callable_mp(this, &DynamicFontImportSettings::_re_import)); - } else if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { - add_lang->set_icon(add_var->get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))); - add_script->set_icon(add_var->get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))); - add_var->set_icon(add_var->get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))); - add_ot->set_icon(add_var->get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))); + switch (p_what) { + case NOTIFICATION_READY: { + connect("confirmed", callable_mp(this, &DynamicFontImportSettings::_re_import)); + } break; + + case NOTIFICATION_ENTER_TREE: + case NOTIFICATION_THEME_CHANGED: { + add_lang->set_icon(add_var->get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))); + add_script->set_icon(add_var->get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))); + add_var->set_icon(add_var->get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))); + add_ot->set_icon(add_var->get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))); + } break; } } diff --git a/editor/import/scene_import_settings.cpp b/editor/import/scene_import_settings.cpp index a3fb753d7f..488bd02de4 100644 --- a/editor/import/scene_import_settings.cpp +++ b/editor/import/scene_import_settings.cpp @@ -837,8 +837,10 @@ void SceneImportSettings::_re_import() { } void SceneImportSettings::_notification(int p_what) { - if (p_what == NOTIFICATION_READY) { - connect("confirmed", callable_mp(this, &SceneImportSettings::_re_import)); + switch (p_what) { + case NOTIFICATION_READY: { + connect("confirmed", callable_mp(this, &SceneImportSettings::_re_import)); + } break; } } diff --git a/editor/import_defaults_editor.cpp b/editor/import_defaults_editor.cpp index 767e2a7fad..ca979c094f 100644 --- a/editor/import_defaults_editor.cpp +++ b/editor/import_defaults_editor.cpp @@ -80,8 +80,10 @@ protected: }; void ImportDefaultsEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_PREDELETE) { - inspector->edit(nullptr); + switch (p_what) { + case NOTIFICATION_PREDELETE: { + inspector->edit(nullptr); + } break; } } diff --git a/editor/localization_editor.cpp b/editor/localization_editor.cpp index 401ba02099..cd9986d527 100644 --- a/editor/localization_editor.cpp +++ b/editor/localization_editor.cpp @@ -40,25 +40,27 @@ #include "scene/gui/control.h" void LocalizationEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { - translation_list->connect("button_pressed", callable_mp(this, &LocalizationEditor::_translation_delete)); - translation_pot_list->connect("button_pressed", callable_mp(this, &LocalizationEditor::_pot_delete)); - - List<String> tfn; - ResourceLoader::get_recognized_extensions_for_type("Translation", &tfn); - for (const String &E : tfn) { - translation_file_open->add_filter("*." + E); - } + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + translation_list->connect("button_pressed", callable_mp(this, &LocalizationEditor::_translation_delete)); + translation_pot_list->connect("button_pressed", callable_mp(this, &LocalizationEditor::_pot_delete)); + + List<String> tfn; + ResourceLoader::get_recognized_extensions_for_type("Translation", &tfn); + for (const String &E : tfn) { + translation_file_open->add_filter("*." + E); + } - List<String> rfn; - ResourceLoader::get_recognized_extensions_for_type("Resource", &rfn); - for (const String &E : rfn) { - translation_res_file_open_dialog->add_filter("*." + E); - translation_res_option_file_open_dialog->add_filter("*." + E); - } + List<String> rfn; + ResourceLoader::get_recognized_extensions_for_type("Resource", &rfn); + for (const String &E : rfn) { + translation_res_file_open_dialog->add_filter("*." + E); + translation_res_option_file_open_dialog->add_filter("*." + E); + } - _update_pot_file_extensions(); - pot_generate_dialog->add_filter("*.pot"); + _update_pot_file_extensions(); + pot_generate_dialog->add_filter("*.pot"); + } break; } } diff --git a/editor/node_dock.cpp b/editor/node_dock.cpp index 9b06435648..18545d3c9a 100644 --- a/editor/node_dock.cpp +++ b/editor/node_dock.cpp @@ -52,9 +52,12 @@ void NodeDock::_bind_methods() { } void NodeDock::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { - connections_button->set_icon(get_theme_icon(SNAME("Signals"), SNAME("EditorIcons"))); - groups_button->set_icon(get_theme_icon(SNAME("Groups"), SNAME("EditorIcons"))); + switch (p_what) { + case NOTIFICATION_ENTER_TREE: + case NOTIFICATION_THEME_CHANGED: { + connections_button->set_icon(get_theme_icon(SNAME("Signals"), SNAME("EditorIcons"))); + groups_button->set_icon(get_theme_icon(SNAME("Groups"), SNAME("EditorIcons"))); + } break; } } diff --git a/editor/plugin_config_dialog.cpp b/editor/plugin_config_dialog.cpp index 5786d24d23..48ea3013f7 100644 --- a/editor/plugin_config_dialog.cpp +++ b/editor/plugin_config_dialog.cpp @@ -160,6 +160,7 @@ void PluginConfigDialog::_notification(int p_what) { name_edit->grab_focus(); } } break; + case NOTIFICATION_READY: { connect("confirmed", callable_mp(this, &PluginConfigDialog::_on_confirmed)); get_cancel_button()->connect("pressed", callable_mp(this, &PluginConfigDialog::_on_cancelled)); diff --git a/editor/plugins/abstract_polygon_2d_editor.cpp b/editor/plugins/abstract_polygon_2d_editor.cpp index 8f6ac149aa..5a2696fff1 100644 --- a/editor/plugins/abstract_polygon_2d_editor.cpp +++ b/editor/plugins/abstract_polygon_2d_editor.cpp @@ -154,6 +154,7 @@ void AbstractPolygon2DEditor::_notification(int p_what) { button_edit->set_icon(get_theme_icon(SNAME("CurveEdit"), SNAME("EditorIcons"))); button_delete->set_icon(get_theme_icon(SNAME("CurveDelete"), SNAME("EditorIcons"))); } break; + case NOTIFICATION_READY: { disable_polygon_editing(false, String()); diff --git a/editor/plugins/animation_blend_space_1d_editor.cpp b/editor/plugins/animation_blend_space_1d_editor.cpp index 4156c14a7e..fe8b462084 100644 --- a/editor/plugins/animation_blend_space_1d_editor.cpp +++ b/editor/plugins/animation_blend_space_1d_editor.cpp @@ -531,39 +531,42 @@ void AnimationNodeBlendSpace1DEditor::_open_editor() { } void AnimationNodeBlendSpace1DEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { - error_panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("bg"), SNAME("Tree"))); - error_label->add_theme_color_override("font_color", get_theme_color(SNAME("error_color"), SNAME("Editor"))); - panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("bg"), SNAME("Tree"))); - tool_blend->set_icon(get_theme_icon(SNAME("EditPivot"), SNAME("EditorIcons"))); - tool_select->set_icon(get_theme_icon(SNAME("ToolSelect"), SNAME("EditorIcons"))); - tool_create->set_icon(get_theme_icon(SNAME("EditKey"), SNAME("EditorIcons"))); - tool_erase->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"))); - snap->set_icon(get_theme_icon(SNAME("SnapGrid"), SNAME("EditorIcons"))); - open_editor->set_icon(get_theme_icon(SNAME("Edit"), SNAME("EditorIcons"))); - } - - if (p_what == NOTIFICATION_PROCESS) { - String error; - - if (!AnimationTreeEditor::get_singleton()->get_tree()->is_active()) { - error = TTR("AnimationTree is inactive.\nActivate to enable playback, check node warnings if activation fails."); - } else if (AnimationTreeEditor::get_singleton()->get_tree()->is_state_invalid()) { - error = AnimationTreeEditor::get_singleton()->get_tree()->get_invalid_state_reason(); - } + switch (p_what) { + case NOTIFICATION_ENTER_TREE: + case NOTIFICATION_THEME_CHANGED: { + error_panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("bg"), SNAME("Tree"))); + error_label->add_theme_color_override("font_color", get_theme_color(SNAME("error_color"), SNAME("Editor"))); + panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("bg"), SNAME("Tree"))); + tool_blend->set_icon(get_theme_icon(SNAME("EditPivot"), SNAME("EditorIcons"))); + tool_select->set_icon(get_theme_icon(SNAME("ToolSelect"), SNAME("EditorIcons"))); + tool_create->set_icon(get_theme_icon(SNAME("EditKey"), SNAME("EditorIcons"))); + tool_erase->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"))); + snap->set_icon(get_theme_icon(SNAME("SnapGrid"), SNAME("EditorIcons"))); + open_editor->set_icon(get_theme_icon(SNAME("Edit"), SNAME("EditorIcons"))); + } break; + + case NOTIFICATION_PROCESS: { + String error; + + if (!AnimationTreeEditor::get_singleton()->get_tree()->is_active()) { + error = TTR("AnimationTree is inactive.\nActivate to enable playback, check node warnings if activation fails."); + } else if (AnimationTreeEditor::get_singleton()->get_tree()->is_state_invalid()) { + error = AnimationTreeEditor::get_singleton()->get_tree()->get_invalid_state_reason(); + } - if (error != error_label->get_text()) { - error_label->set_text(error); - if (!error.is_empty()) { - error_panel->show(); - } else { - error_panel->hide(); + if (error != error_label->get_text()) { + error_label->set_text(error); + if (!error.is_empty()) { + error_panel->show(); + } else { + error_panel->hide(); + } } - } - } + } break; - if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { - set_process(is_visible_in_tree()); + case NOTIFICATION_VISIBILITY_CHANGED: { + set_process(is_visible_in_tree()); + } break; } } diff --git a/editor/plugins/animation_blend_space_2d_editor.cpp b/editor/plugins/animation_blend_space_2d_editor.cpp index 6d876aba44..506a709728 100644 --- a/editor/plugins/animation_blend_space_2d_editor.cpp +++ b/editor/plugins/animation_blend_space_2d_editor.cpp @@ -731,49 +731,52 @@ void AnimationNodeBlendSpace2DEditor::_edit_point_pos(double) { } void AnimationNodeBlendSpace2DEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { - error_panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("bg"), SNAME("Tree"))); - error_label->add_theme_color_override("font_color", get_theme_color(SNAME("error_color"), SNAME("Editor"))); - panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("bg"), SNAME("Tree"))); - tool_blend->set_icon(get_theme_icon(SNAME("EditPivot"), SNAME("EditorIcons"))); - tool_select->set_icon(get_theme_icon(SNAME("ToolSelect"), SNAME("EditorIcons"))); - tool_create->set_icon(get_theme_icon(SNAME("EditKey"), SNAME("EditorIcons"))); - tool_triangle->set_icon(get_theme_icon(SNAME("ToolTriangle"), SNAME("EditorIcons"))); - tool_erase->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"))); - snap->set_icon(get_theme_icon(SNAME("SnapGrid"), SNAME("EditorIcons"))); - open_editor->set_icon(get_theme_icon(SNAME("Edit"), SNAME("EditorIcons"))); - auto_triangles->set_icon(get_theme_icon(SNAME("AutoTriangle"), SNAME("EditorIcons"))); - interpolation->clear(); - interpolation->add_icon_item(get_theme_icon(SNAME("TrackContinuous"), SNAME("EditorIcons")), "", 0); - interpolation->add_icon_item(get_theme_icon(SNAME("TrackDiscrete"), SNAME("EditorIcons")), "", 1); - interpolation->add_icon_item(get_theme_icon(SNAME("TrackCapture"), SNAME("EditorIcons")), "", 2); - } - - if (p_what == NOTIFICATION_PROCESS) { - String error; - - if (!AnimationTreeEditor::get_singleton()->get_tree()) { - error = TTR("BlendSpace2D does not belong to an AnimationTree node."); - } else if (!AnimationTreeEditor::get_singleton()->get_tree()->is_active()) { - error = TTR("AnimationTree is inactive.\nActivate to enable playback, check node warnings if activation fails."); - } else if (AnimationTreeEditor::get_singleton()->get_tree()->is_state_invalid()) { - error = AnimationTreeEditor::get_singleton()->get_tree()->get_invalid_state_reason(); - } else if (blend_space->get_triangle_count() == 0) { - error = TTR("No triangles exist, so no blending can take place."); - } + switch (p_what) { + case NOTIFICATION_ENTER_TREE: + case NOTIFICATION_THEME_CHANGED: { + error_panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("bg"), SNAME("Tree"))); + error_label->add_theme_color_override("font_color", get_theme_color(SNAME("error_color"), SNAME("Editor"))); + panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("bg"), SNAME("Tree"))); + tool_blend->set_icon(get_theme_icon(SNAME("EditPivot"), SNAME("EditorIcons"))); + tool_select->set_icon(get_theme_icon(SNAME("ToolSelect"), SNAME("EditorIcons"))); + tool_create->set_icon(get_theme_icon(SNAME("EditKey"), SNAME("EditorIcons"))); + tool_triangle->set_icon(get_theme_icon(SNAME("ToolTriangle"), SNAME("EditorIcons"))); + tool_erase->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"))); + snap->set_icon(get_theme_icon(SNAME("SnapGrid"), SNAME("EditorIcons"))); + open_editor->set_icon(get_theme_icon(SNAME("Edit"), SNAME("EditorIcons"))); + auto_triangles->set_icon(get_theme_icon(SNAME("AutoTriangle"), SNAME("EditorIcons"))); + interpolation->clear(); + interpolation->add_icon_item(get_theme_icon(SNAME("TrackContinuous"), SNAME("EditorIcons")), "", 0); + interpolation->add_icon_item(get_theme_icon(SNAME("TrackDiscrete"), SNAME("EditorIcons")), "", 1); + interpolation->add_icon_item(get_theme_icon(SNAME("TrackCapture"), SNAME("EditorIcons")), "", 2); + } break; + + case NOTIFICATION_PROCESS: { + String error; + + if (!AnimationTreeEditor::get_singleton()->get_tree()) { + error = TTR("BlendSpace2D does not belong to an AnimationTree node."); + } else if (!AnimationTreeEditor::get_singleton()->get_tree()->is_active()) { + error = TTR("AnimationTree is inactive.\nActivate to enable playback, check node warnings if activation fails."); + } else if (AnimationTreeEditor::get_singleton()->get_tree()->is_state_invalid()) { + error = AnimationTreeEditor::get_singleton()->get_tree()->get_invalid_state_reason(); + } else if (blend_space->get_triangle_count() == 0) { + error = TTR("No triangles exist, so no blending can take place."); + } - if (error != error_label->get_text()) { - error_label->set_text(error); - if (!error.is_empty()) { - error_panel->show(); - } else { - error_panel->hide(); + if (error != error_label->get_text()) { + error_label->set_text(error); + if (!error.is_empty()) { + error_panel->show(); + } else { + error_panel->hide(); + } } - } - } + } break; - if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { - set_process(is_visible_in_tree()); + case NOTIFICATION_VISIBILITY_CHANGED: { + set_process(is_visible_in_tree()); + } break; } } diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp index 14dd782b73..0b3164aada 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.cpp +++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp @@ -734,80 +734,95 @@ void AnimationNodeBlendTreeEditor::_removed_from_graph() { } } +void AnimationNodeBlendTreeEditor::_update_editor_settings() { + graph->get_panner()->setup((ViewPanner::ControlScheme)EDITOR_GET("editors/panning/sub_editors_panning_scheme").operator int(), ED_GET_SHORTCUT("canvas_item_editor/pan_view"), bool(EditorSettings::get_singleton()->get("editors/panning/simple_panning"))); + graph->set_warped_panning(bool(EditorSettings::get_singleton()->get("editors/panning/warped_mouse_panning"))); +} + +void AnimationNodeBlendTreeEditor::_update_theme() { + error_panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("bg"), SNAME("Tree"))); + error_label->add_theme_color_override("font_color", get_theme_color(SNAME("error_color"), SNAME("Editor"))); +} + void AnimationNodeBlendTreeEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE || p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { - graph->get_panner()->setup((ViewPanner::ControlScheme)EDITOR_GET("editors/panning/sub_editors_panning_scheme").operator int(), ED_GET_SHORTCUT("canvas_item_editor/pan_view"), bool(EditorSettings::get_singleton()->get("editors/panning/simple_panning"))); - graph->set_warped_panning(bool(EditorSettings::get_singleton()->get("editors/panning/warped_mouse_panning"))); - } + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + _update_editor_settings(); + _update_theme(); + } break; - if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { - error_panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("bg"), SNAME("Tree"))); - error_label->add_theme_color_override("font_color", get_theme_color(SNAME("error_color"), SNAME("Editor"))); + case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { + _update_editor_settings(); + } break; - if (p_what == NOTIFICATION_THEME_CHANGED && is_visible_in_tree()) { - _update_graph(); - } - } + case NOTIFICATION_THEME_CHANGED: { + _update_theme(); - if (p_what == NOTIFICATION_PROCESS) { - String error; + if (is_visible_in_tree()) { + _update_graph(); + } + } break; - if (!AnimationTreeEditor::get_singleton()->get_tree()->is_active()) { - error = TTR("AnimationTree is inactive.\nActivate to enable playback, check node warnings if activation fails."); - } else if (AnimationTreeEditor::get_singleton()->get_tree()->is_state_invalid()) { - error = AnimationTreeEditor::get_singleton()->get_tree()->get_invalid_state_reason(); - } + case NOTIFICATION_PROCESS: { + String error; - if (error != error_label->get_text()) { - error_label->set_text(error); - if (!error.is_empty()) { - error_panel->show(); - } else { - error_panel->hide(); + if (!AnimationTreeEditor::get_singleton()->get_tree()->is_active()) { + error = TTR("AnimationTree is inactive.\nActivate to enable playback, check node warnings if activation fails."); + } else if (AnimationTreeEditor::get_singleton()->get_tree()->is_state_invalid()) { + error = AnimationTreeEditor::get_singleton()->get_tree()->get_invalid_state_reason(); } - } - List<AnimationNodeBlendTree::NodeConnection> conns; - blend_tree->get_node_connections(&conns); - for (const AnimationNodeBlendTree::NodeConnection &E : conns) { - float activity = 0; - StringName path = AnimationTreeEditor::get_singleton()->get_base_path() + E.input_node; - if (AnimationTreeEditor::get_singleton()->get_tree() && !AnimationTreeEditor::get_singleton()->get_tree()->is_state_invalid()) { - activity = AnimationTreeEditor::get_singleton()->get_tree()->get_connection_activity(path, E.input_index); + if (error != error_label->get_text()) { + error_label->set_text(error); + if (!error.is_empty()) { + error_panel->show(); + } else { + error_panel->hide(); + } } - graph->set_connection_activity(E.output_node, 0, E.input_node, E.input_index, activity); - } - AnimationTree *graph_player = AnimationTreeEditor::get_singleton()->get_tree(); - AnimationPlayer *player = nullptr; - if (graph_player->has_node(graph_player->get_animation_player())) { - player = Object::cast_to<AnimationPlayer>(graph_player->get_node(graph_player->get_animation_player())); - } + List<AnimationNodeBlendTree::NodeConnection> conns; + blend_tree->get_node_connections(&conns); + for (const AnimationNodeBlendTree::NodeConnection &E : conns) { + float activity = 0; + StringName path = AnimationTreeEditor::get_singleton()->get_base_path() + E.input_node; + if (AnimationTreeEditor::get_singleton()->get_tree() && !AnimationTreeEditor::get_singleton()->get_tree()->is_state_invalid()) { + activity = AnimationTreeEditor::get_singleton()->get_tree()->get_connection_activity(path, E.input_index); + } + graph->set_connection_activity(E.output_node, 0, E.input_node, E.input_index, activity); + } - if (player) { - for (const KeyValue<StringName, ProgressBar *> &E : animations) { - Ref<AnimationNodeAnimation> an = blend_tree->get_node(E.key); - if (an.is_valid()) { - if (player->has_animation(an->get_animation())) { - Ref<Animation> anim = player->get_animation(an->get_animation()); - if (anim.is_valid()) { - E.value->set_max(anim->get_length()); - //StringName path = AnimationTreeEditor::get_singleton()->get_base_path() + E.input_node; - StringName time_path = AnimationTreeEditor::get_singleton()->get_base_path() + String(E.key) + "/time"; - E.value->set_value(AnimationTreeEditor::get_singleton()->get_tree()->get(time_path)); + AnimationTree *graph_player = AnimationTreeEditor::get_singleton()->get_tree(); + AnimationPlayer *player = nullptr; + if (graph_player->has_node(graph_player->get_animation_player())) { + player = Object::cast_to<AnimationPlayer>(graph_player->get_node(graph_player->get_animation_player())); + } + + if (player) { + for (const KeyValue<StringName, ProgressBar *> &E : animations) { + Ref<AnimationNodeAnimation> an = blend_tree->get_node(E.key); + if (an.is_valid()) { + if (player->has_animation(an->get_animation())) { + Ref<Animation> anim = player->get_animation(an->get_animation()); + if (anim.is_valid()) { + E.value->set_max(anim->get_length()); + //StringName path = AnimationTreeEditor::get_singleton()->get_base_path() + E.input_node; + StringName time_path = AnimationTreeEditor::get_singleton()->get_base_path() + String(E.key) + "/time"; + E.value->set_value(AnimationTreeEditor::get_singleton()->get_tree()->get(time_path)); + } } } } } - } - for (int i = 0; i < visible_properties.size(); i++) { - visible_properties[i]->update_property(); - } - } + for (int i = 0; i < visible_properties.size(); i++) { + visible_properties[i]->update_property(); + } + } break; - if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { - set_process(is_visible_in_tree()); + case NOTIFICATION_VISIBILITY_CHANGED: { + set_process(is_visible_in_tree()); + } break; } } diff --git a/editor/plugins/animation_blend_tree_editor_plugin.h b/editor/plugins/animation_blend_tree_editor_plugin.h index b1b905a3f5..c111f9245e 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.h +++ b/editor/plugins/animation_blend_tree_editor_plugin.h @@ -119,6 +119,9 @@ class AnimationNodeBlendTreeEditor : public AnimationTreeNodeEditorPlugin { void _property_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing); void _removed_from_graph(); + void _update_editor_settings(); + void _update_theme(); + EditorFileDialog *open_file; Ref<AnimationNode> file_loaded; void _file_opened(const String &p_file); diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index 28b1126102..ad126d28f6 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -94,6 +94,7 @@ void AnimationPlayerEditor::_notification(int p_what) { last_active = player->is_playing(); updating = false; } break; + case NOTIFICATION_ENTER_TREE: { tool_anim->get_popup()->connect("id_pressed", callable_mp(this, &AnimationPlayerEditor::_animation_tool_menu)); @@ -105,9 +106,11 @@ void AnimationPlayerEditor::_notification(int p_what) { add_theme_style_override("panel", EditorNode::get_singleton()->get_gui_base()->get_theme_stylebox(SNAME("panel"), SNAME("Panel"))); } break; + case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { add_theme_style_override("panel", EditorNode::get_singleton()->get_gui_base()->get_theme_stylebox(SNAME("panel"), SNAME("Panel"))); } break; + case NOTIFICATION_TRANSLATION_CHANGED: case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: case NOTIFICATION_THEME_CHANGED: { diff --git a/editor/plugins/animation_state_machine_editor.cpp b/editor/plugins/animation_state_machine_editor.cpp index 5e32c77511..6c284f2268 100644 --- a/editor/plugins/animation_state_machine_editor.cpp +++ b/editor/plugins/animation_state_machine_editor.cpp @@ -884,169 +884,174 @@ void AnimationNodeStateMachineEditor::_update_graph() { } void AnimationNodeStateMachineEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED || p_what == NOTIFICATION_LAYOUT_DIRECTION_CHANGED || p_what == NOTIFICATION_TRANSLATION_CHANGED) { - error_panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("bg"), SNAME("Tree"))); - error_label->add_theme_color_override("font_color", get_theme_color(SNAME("error_color"), SNAME("Editor"))); - panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("bg"), SNAME("Tree"))); - - tool_select->set_icon(get_theme_icon(SNAME("ToolSelect"), SNAME("EditorIcons"))); - tool_create->set_icon(get_theme_icon(SNAME("ToolAddNode"), SNAME("EditorIcons"))); - tool_connect->set_icon(get_theme_icon(SNAME("ToolConnect"), SNAME("EditorIcons"))); - - transition_mode->clear(); - transition_mode->add_icon_item(get_theme_icon(SNAME("TransitionImmediate"), SNAME("EditorIcons")), TTR("Immediate")); - transition_mode->add_icon_item(get_theme_icon(SNAME("TransitionSync"), SNAME("EditorIcons")), TTR("Sync")); - transition_mode->add_icon_item(get_theme_icon(SNAME("TransitionEnd"), SNAME("EditorIcons")), TTR("At End")); - - tool_erase->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"))); - tool_autoplay->set_icon(get_theme_icon(SNAME("AutoPlay"), SNAME("EditorIcons"))); - tool_end->set_icon(get_theme_icon(SNAME("AutoEnd"), SNAME("EditorIcons"))); - - play_mode->clear(); - play_mode->add_icon_item(get_theme_icon(SNAME("PlayTravel"), SNAME("EditorIcons")), TTR("Travel")); - play_mode->add_icon_item(get_theme_icon(SNAME("Play"), SNAME("EditorIcons")), TTR("Immediate")); - } - - if (p_what == NOTIFICATION_PROCESS) { - String error; - - Ref<AnimationNodeStateMachinePlayback> playback = AnimationTreeEditor::get_singleton()->get_tree()->get(AnimationTreeEditor::get_singleton()->get_base_path() + "playback"); - - if (error_time > 0) { - error = error_text; - error_time -= get_process_delta_time(); - } else if (!AnimationTreeEditor::get_singleton()->get_tree()->is_active()) { - error = TTR("AnimationTree is inactive.\nActivate to enable playback, check node warnings if activation fails."); - } else if (AnimationTreeEditor::get_singleton()->get_tree()->is_state_invalid()) { - error = AnimationTreeEditor::get_singleton()->get_tree()->get_invalid_state_reason(); - /*} else if (state_machine->get_parent().is_valid() && state_machine->get_parent()->is_class("AnimationNodeStateMachine")) { - if (state_machine->get_start_node() == StringName() || state_machine->get_end_node() == StringName()) { - error = TTR("Start and end nodes are needed for a sub-transition."); - }*/ - } else if (playback.is_null()) { - error = vformat(TTR("No playback resource set at path: %s."), AnimationTreeEditor::get_singleton()->get_base_path() + "playback"); - } - - if (error != error_label->get_text()) { - error_label->set_text(error); - if (!error.is_empty()) { - error_panel->show(); - } else { - error_panel->hide(); + switch (p_what) { + case NOTIFICATION_ENTER_TREE: + case NOTIFICATION_THEME_CHANGED: + case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: + case NOTIFICATION_TRANSLATION_CHANGED: { + error_panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("bg"), SNAME("Tree"))); + error_label->add_theme_color_override("font_color", get_theme_color(SNAME("error_color"), SNAME("Editor"))); + panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("bg"), SNAME("Tree"))); + + tool_select->set_icon(get_theme_icon(SNAME("ToolSelect"), SNAME("EditorIcons"))); + tool_create->set_icon(get_theme_icon(SNAME("ToolAddNode"), SNAME("EditorIcons"))); + tool_connect->set_icon(get_theme_icon(SNAME("ToolConnect"), SNAME("EditorIcons"))); + + transition_mode->clear(); + transition_mode->add_icon_item(get_theme_icon(SNAME("TransitionImmediate"), SNAME("EditorIcons")), TTR("Immediate")); + transition_mode->add_icon_item(get_theme_icon(SNAME("TransitionSync"), SNAME("EditorIcons")), TTR("Sync")); + transition_mode->add_icon_item(get_theme_icon(SNAME("TransitionEnd"), SNAME("EditorIcons")), TTR("At End")); + + tool_erase->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"))); + tool_autoplay->set_icon(get_theme_icon(SNAME("AutoPlay"), SNAME("EditorIcons"))); + tool_end->set_icon(get_theme_icon(SNAME("AutoEnd"), SNAME("EditorIcons"))); + + play_mode->clear(); + play_mode->add_icon_item(get_theme_icon(SNAME("PlayTravel"), SNAME("EditorIcons")), TTR("Travel")); + play_mode->add_icon_item(get_theme_icon(SNAME("Play"), SNAME("EditorIcons")), TTR("Immediate")); + } break; + + case NOTIFICATION_PROCESS: { + String error; + + Ref<AnimationNodeStateMachinePlayback> playback = AnimationTreeEditor::get_singleton()->get_tree()->get(AnimationTreeEditor::get_singleton()->get_base_path() + "playback"); + + if (error_time > 0) { + error = error_text; + error_time -= get_process_delta_time(); + } else if (!AnimationTreeEditor::get_singleton()->get_tree()->is_active()) { + error = TTR("AnimationTree is inactive.\nActivate to enable playback, check node warnings if activation fails."); + } else if (AnimationTreeEditor::get_singleton()->get_tree()->is_state_invalid()) { + error = AnimationTreeEditor::get_singleton()->get_tree()->get_invalid_state_reason(); + /*} else if (state_machine->get_parent().is_valid() && state_machine->get_parent()->is_class("AnimationNodeStateMachine")) { + if (state_machine->get_start_node() == StringName() || state_machine->get_end_node() == StringName()) { + error = TTR("Start and end nodes are needed for a sub-transition."); + }*/ + } else if (playback.is_null()) { + error = vformat(TTR("No playback resource set at path: %s."), AnimationTreeEditor::get_singleton()->get_base_path() + "playback"); } - } - for (int i = 0; i < transition_lines.size(); i++) { - int tidx = -1; - for (int j = 0; j < state_machine->get_transition_count(); j++) { - if (transition_lines[i].from_node == state_machine->get_transition_from(j) && transition_lines[i].to_node == state_machine->get_transition_to(j)) { - tidx = j; - break; + if (error != error_label->get_text()) { + error_label->set_text(error); + if (!error.is_empty()) { + error_panel->show(); + } else { + error_panel->hide(); } } - if (tidx == -1) { //missing transition, should redraw - state_machine_draw->update(); - break; - } + for (int i = 0; i < transition_lines.size(); i++) { + int tidx = -1; + for (int j = 0; j < state_machine->get_transition_count(); j++) { + if (transition_lines[i].from_node == state_machine->get_transition_from(j) && transition_lines[i].to_node == state_machine->get_transition_to(j)) { + tidx = j; + break; + } + } - if (transition_lines[i].disabled != state_machine->get_transition(tidx)->is_disabled()) { - state_machine_draw->update(); - break; - } + if (tidx == -1) { //missing transition, should redraw + state_machine_draw->update(); + break; + } - if (transition_lines[i].auto_advance != state_machine->get_transition(tidx)->has_auto_advance()) { - state_machine_draw->update(); - break; - } + if (transition_lines[i].disabled != state_machine->get_transition(tidx)->is_disabled()) { + state_machine_draw->update(); + break; + } - if (transition_lines[i].advance_condition_name != state_machine->get_transition(tidx)->get_advance_condition_name()) { - state_machine_draw->update(); - break; - } + if (transition_lines[i].auto_advance != state_machine->get_transition(tidx)->has_auto_advance()) { + state_machine_draw->update(); + break; + } - if (transition_lines[i].mode != state_machine->get_transition(tidx)->get_switch_mode()) { - state_machine_draw->update(); - break; - } + if (transition_lines[i].advance_condition_name != state_machine->get_transition(tidx)->get_advance_condition_name()) { + state_machine_draw->update(); + break; + } - bool acstate = transition_lines[i].advance_condition_name != StringName() && bool(AnimationTreeEditor::get_singleton()->get_tree()->get(AnimationTreeEditor::get_singleton()->get_base_path() + String(transition_lines[i].advance_condition_name))); + if (transition_lines[i].mode != state_machine->get_transition(tidx)->get_switch_mode()) { + state_machine_draw->update(); + break; + } - if (transition_lines[i].advance_condition_state != acstate) { - state_machine_draw->update(); - break; + bool acstate = transition_lines[i].advance_condition_name != StringName() && bool(AnimationTreeEditor::get_singleton()->get_tree()->get(AnimationTreeEditor::get_singleton()->get_base_path() + String(transition_lines[i].advance_condition_name))); + + if (transition_lines[i].advance_condition_state != acstate) { + state_machine_draw->update(); + break; + } } - } - bool same_travel_path = true; - Vector<StringName> tp; - bool is_playing = false; - StringName current_node; - StringName blend_from_node; - play_pos = 0; - current_length = 0; - - if (playback.is_valid()) { - tp = playback->get_travel_path(); - is_playing = playback->is_playing(); - current_node = playback->get_current_node(); - blend_from_node = playback->get_blend_from_node(); - play_pos = playback->get_current_play_pos(); - current_length = playback->get_current_length(); - } + bool same_travel_path = true; + Vector<StringName> tp; + bool is_playing = false; + StringName current_node; + StringName blend_from_node; + play_pos = 0; + current_length = 0; + + if (playback.is_valid()) { + tp = playback->get_travel_path(); + is_playing = playback->is_playing(); + current_node = playback->get_current_node(); + blend_from_node = playback->get_blend_from_node(); + play_pos = playback->get_current_play_pos(); + current_length = playback->get_current_length(); + } - { - if (last_travel_path.size() != tp.size()) { - same_travel_path = false; - } else { - for (int i = 0; i < last_travel_path.size(); i++) { - if (last_travel_path[i] != tp[i]) { - same_travel_path = false; - break; + { + if (last_travel_path.size() != tp.size()) { + same_travel_path = false; + } else { + for (int i = 0; i < last_travel_path.size(); i++) { + if (last_travel_path[i] != tp[i]) { + same_travel_path = false; + break; + } } } } - } - //update if travel state changed - if (!same_travel_path || last_active != is_playing || last_current_node != current_node || last_blend_from_node != blend_from_node) { - state_machine_draw->update(); - last_travel_path = tp; - last_current_node = current_node; - last_active = is_playing; - last_blend_from_node = blend_from_node; - state_machine_play_pos->update(); - } + //update if travel state changed + if (!same_travel_path || last_active != is_playing || last_current_node != current_node || last_blend_from_node != blend_from_node) { + state_machine_draw->update(); + last_travel_path = tp; + last_current_node = current_node; + last_active = is_playing; + last_blend_from_node = blend_from_node; + state_machine_play_pos->update(); + } - { - if (current_node != StringName() && state_machine->has_node(current_node)) { - String next = current_node; - Ref<AnimationNodeStateMachine> anodesm = state_machine->get_node(next); - Ref<AnimationNodeStateMachinePlayback> current_node_playback; - - while (anodesm.is_valid()) { - current_node_playback = AnimationTreeEditor::get_singleton()->get_tree()->get(AnimationTreeEditor::get_singleton()->get_base_path() + next + "/playback"); - next += "/" + current_node_playback->get_current_node(); - anodesm = anodesm->get_node(current_node_playback->get_current_node()); - } + { + if (current_node != StringName() && state_machine->has_node(current_node)) { + String next = current_node; + Ref<AnimationNodeStateMachine> anodesm = state_machine->get_node(next); + Ref<AnimationNodeStateMachinePlayback> current_node_playback; - // when current_node is a state machine, use playback of current_node to set play_pos - if (current_node_playback.is_valid()) { - play_pos = current_node_playback->get_current_play_pos(); - current_length = current_node_playback->get_current_length(); + while (anodesm.is_valid()) { + current_node_playback = AnimationTreeEditor::get_singleton()->get_tree()->get(AnimationTreeEditor::get_singleton()->get_base_path() + next + "/playback"); + next += "/" + current_node_playback->get_current_node(); + anodesm = anodesm->get_node(current_node_playback->get_current_node()); + } + + // when current_node is a state machine, use playback of current_node to set play_pos + if (current_node_playback.is_valid()) { + play_pos = current_node_playback->get_current_play_pos(); + current_length = current_node_playback->get_current_length(); + } } } - } - if (last_play_pos != play_pos) { - last_play_pos = play_pos; - state_machine_play_pos->update(); - } - } + if (last_play_pos != play_pos) { + last_play_pos = play_pos; + state_machine_play_pos->update(); + } + } break; - if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { - over_node = StringName(); - set_process(is_visible_in_tree()); + case NOTIFICATION_VISIBILITY_CHANGED: { + over_node = StringName(); + set_process(is_visible_in_tree()); + } break; } } diff --git a/editor/plugins/animation_tree_editor_plugin.cpp b/editor/plugins/animation_tree_editor_plugin.cpp index f7057f375e..7ea6906d72 100644 --- a/editor/plugins/animation_tree_editor_plugin.cpp +++ b/editor/plugins/animation_tree_editor_plugin.cpp @@ -145,19 +145,21 @@ void AnimationTreeEditor::enter_editor(const String &p_path) { } void AnimationTreeEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_PROCESS) { - ObjectID root; - if (tree && tree->get_tree_root().is_valid()) { - root = tree->get_tree_root()->get_instance_id(); - } + switch (p_what) { + case NOTIFICATION_PROCESS: { + ObjectID root; + if (tree && tree->get_tree_root().is_valid()) { + root = tree->get_tree_root()->get_instance_id(); + } - if (root != current_root) { - edit_path(Vector<String>()); - } + if (root != current_root) { + edit_path(Vector<String>()); + } - if (button_path.size() != edited_path.size()) { - edit_path(edited_path); - } + if (button_path.size() != edited_path.size()) { + edit_path(edited_path); + } + } break; } } diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp index 7ab9fa05f7..9e9915cfa4 100644 --- a/editor/plugins/asset_library_editor_plugin.cpp +++ b/editor/plugins/asset_library_editor_plugin.cpp @@ -68,11 +68,13 @@ void EditorAssetLibraryItem::set_image(int p_type, int p_index, const Ref<Textur } void EditorAssetLibraryItem::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { - icon->set_normal_texture(get_theme_icon(SNAME("ProjectIconLoading"), SNAME("EditorIcons"))); - category->add_theme_color_override("font_color", Color(0.5, 0.5, 0.5)); - author->add_theme_color_override("font_color", Color(0.5, 0.5, 0.5)); - price->add_theme_color_override("font_color", Color(0.5, 0.5, 0.5)); + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + icon->set_normal_texture(get_theme_icon(SNAME("ProjectIconLoading"), SNAME("EditorIcons"))); + category->add_theme_color_override("font_color", Color(0.5, 0.5, 0.5)); + author->add_theme_color_override("font_color", Color(0.5, 0.5, 0.5)); + price->add_theme_color_override("font_color", Color(0.5, 0.5, 0.5)); + } break; } } @@ -406,6 +408,7 @@ void EditorAssetLibraryItemDownload::_notification(int p_what) { status->add_theme_color_override("font_color", get_theme_color(SNAME("status_color"), SNAME("AssetLib"))); dismiss_button->set_normal_texture(get_theme_icon(SNAME("dismiss"), SNAME("AssetLib"))); } break; + case NOTIFICATION_PROCESS: { // Make the progress bar visible again when retrying the download. progress->set_modulate(Color(1, 1, 1, 1)); @@ -576,6 +579,7 @@ void EditorAssetLibrary::_notification(int p_what) { case NOTIFICATION_READY: { error_label->raise(); } break; + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { error_tr->set_texture(get_theme_icon(SNAME("Error"), SNAME("EditorIcons"))); @@ -584,6 +588,7 @@ void EditorAssetLibrary::_notification(int p_what) { downloads_scroll->add_theme_style_override("bg", get_theme_stylebox(SNAME("bg"), SNAME("Tree"))); error_label->add_theme_color_override("color", get_theme_color(SNAME("error_color"), SNAME("Editor"))); } break; + case NOTIFICATION_VISIBILITY_CHANGED: { if (is_visible()) { // Focus the search box automatically when switching to the Templates tab (in the Project Manager) @@ -596,6 +601,7 @@ void EditorAssetLibrary::_notification(int p_what) { } } } break; + case NOTIFICATION_PROCESS: { HTTPClient::Status s = request->get_http_client_status(); const bool loading = s != HTTPClient::STATUS_DISCONNECTED; @@ -612,6 +618,7 @@ void EditorAssetLibrary::_notification(int p_what) { } } break; + case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { _update_repository_options(); setup_http_request(request); diff --git a/editor/plugins/audio_stream_editor_plugin.cpp b/editor/plugins/audio_stream_editor_plugin.cpp index c77ff5778a..a60e49ca9d 100644 --- a/editor/plugins/audio_stream_editor_plugin.cpp +++ b/editor/plugins/audio_stream_editor_plugin.cpp @@ -39,29 +39,32 @@ #include "editor/editor_settings.h" void AudioStreamEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_READY) { - AudioStreamPreviewGenerator::get_singleton()->connect("preview_updated", callable_mp(this, &AudioStreamEditor::_preview_changed)); - } - - if (p_what == NOTIFICATION_THEME_CHANGED || p_what == NOTIFICATION_ENTER_TREE) { - _play_button->set_icon(get_theme_icon(SNAME("MainPlay"), SNAME("EditorIcons"))); - _stop_button->set_icon(get_theme_icon(SNAME("Stop"), SNAME("EditorIcons"))); - _preview->set_color(get_theme_color(SNAME("dark_color_2"), SNAME("Editor"))); - set_color(get_theme_color(SNAME("dark_color_1"), SNAME("Editor"))); - - _indicator->update(); - _preview->update(); - } - - if (p_what == NOTIFICATION_PROCESS) { - _current = _player->get_playback_position(); - _indicator->update(); - } - - if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { - if (!is_visible_in_tree()) { - _stop(); - } + switch (p_what) { + case NOTIFICATION_READY: { + AudioStreamPreviewGenerator::get_singleton()->connect("preview_updated", callable_mp(this, &AudioStreamEditor::_preview_changed)); + } break; + + case NOTIFICATION_THEME_CHANGED: + case NOTIFICATION_ENTER_TREE: { + _play_button->set_icon(get_theme_icon(SNAME("MainPlay"), SNAME("EditorIcons"))); + _stop_button->set_icon(get_theme_icon(SNAME("Stop"), SNAME("EditorIcons"))); + _preview->set_color(get_theme_color(SNAME("dark_color_2"), SNAME("Editor"))); + set_color(get_theme_color(SNAME("dark_color_1"), SNAME("Editor"))); + + _indicator->update(); + _preview->update(); + } break; + + case NOTIFICATION_PROCESS: { + _current = _player->get_playback_position(); + _indicator->update(); + } break; + + case NOTIFICATION_VISIBILITY_CHANGED: { + if (!is_visible_in_tree()) { + _stop(); + } + } break; } } diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 06ca89da51..76558eb946 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -3694,149 +3694,154 @@ void CanvasItemEditor::set_current_tool(Tool p_tool) { _button_tool_select(p_tool); } +void CanvasItemEditor::_update_editor_settings() { + select_button->set_icon(get_theme_icon(SNAME("ToolSelect"), SNAME("EditorIcons"))); + list_select_button->set_icon(get_theme_icon(SNAME("ListSelect"), SNAME("EditorIcons"))); + move_button->set_icon(get_theme_icon(SNAME("ToolMove"), SNAME("EditorIcons"))); + scale_button->set_icon(get_theme_icon(SNAME("ToolScale"), SNAME("EditorIcons"))); + rotate_button->set_icon(get_theme_icon(SNAME("ToolRotate"), SNAME("EditorIcons"))); + smart_snap_button->set_icon(get_theme_icon(SNAME("Snap"), SNAME("EditorIcons"))); + grid_snap_button->set_icon(get_theme_icon(SNAME("SnapGrid"), SNAME("EditorIcons"))); + snap_config_menu->set_icon(get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons"))); + skeleton_menu->set_icon(get_theme_icon(SNAME("Bone"), SNAME("EditorIcons"))); + override_camera_button->set_icon(get_theme_icon(SNAME("Camera2D"), SNAME("EditorIcons"))); + pan_button->set_icon(get_theme_icon(SNAME("ToolPan"), SNAME("EditorIcons"))); + ruler_button->set_icon(get_theme_icon(SNAME("Ruler"), SNAME("EditorIcons"))); + pivot_button->set_icon(get_theme_icon(SNAME("EditPivot"), SNAME("EditorIcons"))); + select_handle = get_theme_icon(SNAME("EditorHandle"), SNAME("EditorIcons")); + anchor_handle = get_theme_icon(SNAME("EditorControlAnchor"), SNAME("EditorIcons")); + lock_button->set_icon(get_theme_icon(SNAME("Lock"), SNAME("EditorIcons"))); + unlock_button->set_icon(get_theme_icon(SNAME("Unlock"), SNAME("EditorIcons"))); + group_button->set_icon(get_theme_icon(SNAME("Group"), SNAME("EditorIcons"))); + ungroup_button->set_icon(get_theme_icon(SNAME("Ungroup"), SNAME("EditorIcons"))); + key_loc_button->set_icon(get_theme_icon(SNAME("KeyPosition"), SNAME("EditorIcons"))); + key_rot_button->set_icon(get_theme_icon(SNAME("KeyRotation"), SNAME("EditorIcons"))); + key_scale_button->set_icon(get_theme_icon(SNAME("KeyScale"), SNAME("EditorIcons"))); + key_insert_button->set_icon(get_theme_icon(SNAME("Key"), SNAME("EditorIcons"))); + key_auto_insert_button->set_icon(get_theme_icon(SNAME("AutoKey"), SNAME("EditorIcons"))); + // Use a different color for the active autokey icon to make them easier + // to distinguish from the other key icons at the top. On a light theme, + // the icon will be dark, so we need to lighten it before blending it + // with the red color. + const Color key_auto_color = EditorSettings::get_singleton()->is_dark_theme() ? Color(1, 1, 1) : Color(4.25, 4.25, 4.25); + key_auto_insert_button->add_theme_color_override("icon_pressed_color", key_auto_color.lerp(Color(1, 0, 0), 0.55)); + animation_menu->set_icon(get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons"))); + + _update_context_menu_stylebox(); + + panner->setup((ViewPanner::ControlScheme)EDITOR_GET("editors/panning/2d_editor_panning_scheme").operator int(), ED_GET_SHORTCUT("canvas_item_editor/pan_view"), bool(EditorSettings::get_singleton()->get("editors/panning/simple_panning"))); + pan_speed = int(EditorSettings::get_singleton()->get("editors/panning/2d_editor_pan_speed")); + warped_panning = bool(EditorSettings::get_singleton()->get("editors/panning/warped_mouse_panning")); +} + void CanvasItemEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_PHYSICS_PROCESS) { - EditorNode::get_singleton()->get_scene_root()->set_snap_controls_to_pixels(GLOBAL_GET("gui/common/snap_controls_to_pixels")); + switch (p_what) { + case NOTIFICATION_PHYSICS_PROCESS: { + EditorNode::get_singleton()->get_scene_root()->set_snap_controls_to_pixels(GLOBAL_GET("gui/common/snap_controls_to_pixels")); - int nb_having_pivot = 0; + int nb_having_pivot = 0; - // Update the viewport if the canvas_item changes - List<CanvasItem *> selection = _get_edited_canvas_items(true); - for (CanvasItem *canvas_item : selection) { - CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item); + // Update the viewport if the canvas_item changes + List<CanvasItem *> selection = _get_edited_canvas_items(true); + for (CanvasItem *canvas_item : selection) { + CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item); - Rect2 rect; - if (canvas_item->_edit_use_rect()) { - rect = canvas_item->_edit_get_rect(); - } else { - rect = Rect2(); - } - Transform2D xform = canvas_item->get_transform(); + Rect2 rect; + if (canvas_item->_edit_use_rect()) { + rect = canvas_item->_edit_get_rect(); + } else { + rect = Rect2(); + } + Transform2D xform = canvas_item->get_transform(); - if (rect != se->prev_rect || xform != se->prev_xform) { - viewport->update(); - se->prev_rect = rect; - se->prev_xform = xform; + if (rect != se->prev_rect || xform != se->prev_xform) { + viewport->update(); + se->prev_rect = rect; + se->prev_xform = xform; + } + + Control *control = Object::cast_to<Control>(canvas_item); + if (control) { + real_t anchors[4]; + Vector2 pivot; + + pivot = control->get_pivot_offset(); + anchors[SIDE_LEFT] = control->get_anchor(SIDE_LEFT); + anchors[SIDE_RIGHT] = control->get_anchor(SIDE_RIGHT); + anchors[SIDE_TOP] = control->get_anchor(SIDE_TOP); + anchors[SIDE_BOTTOM] = control->get_anchor(SIDE_BOTTOM); + + if (pivot != se->prev_pivot || anchors[SIDE_LEFT] != se->prev_anchors[SIDE_LEFT] || anchors[SIDE_RIGHT] != se->prev_anchors[SIDE_RIGHT] || anchors[SIDE_TOP] != se->prev_anchors[SIDE_TOP] || anchors[SIDE_BOTTOM] != se->prev_anchors[SIDE_BOTTOM]) { + se->prev_pivot = pivot; + se->prev_anchors[SIDE_LEFT] = anchors[SIDE_LEFT]; + se->prev_anchors[SIDE_RIGHT] = anchors[SIDE_RIGHT]; + se->prev_anchors[SIDE_TOP] = anchors[SIDE_TOP]; + se->prev_anchors[SIDE_BOTTOM] = anchors[SIDE_BOTTOM]; + viewport->update(); + } + } + + if (canvas_item->_edit_use_pivot()) { + nb_having_pivot++; + } } - Control *control = Object::cast_to<Control>(canvas_item); - if (control) { - real_t anchors[4]; - Vector2 pivot; - - pivot = control->get_pivot_offset(); - anchors[SIDE_LEFT] = control->get_anchor(SIDE_LEFT); - anchors[SIDE_RIGHT] = control->get_anchor(SIDE_RIGHT); - anchors[SIDE_TOP] = control->get_anchor(SIDE_TOP); - anchors[SIDE_BOTTOM] = control->get_anchor(SIDE_BOTTOM); - - if (pivot != se->prev_pivot || anchors[SIDE_LEFT] != se->prev_anchors[SIDE_LEFT] || anchors[SIDE_RIGHT] != se->prev_anchors[SIDE_RIGHT] || anchors[SIDE_TOP] != se->prev_anchors[SIDE_TOP] || anchors[SIDE_BOTTOM] != se->prev_anchors[SIDE_BOTTOM]) { - se->prev_pivot = pivot; - se->prev_anchors[SIDE_LEFT] = anchors[SIDE_LEFT]; - se->prev_anchors[SIDE_RIGHT] = anchors[SIDE_RIGHT]; - se->prev_anchors[SIDE_TOP] = anchors[SIDE_TOP]; - se->prev_anchors[SIDE_BOTTOM] = anchors[SIDE_BOTTOM]; + // Activate / Deactivate the pivot tool + pivot_button->set_disabled(nb_having_pivot == 0); + + // Update the viewport if bones changes + for (KeyValue<BoneKey, BoneList> &E : bone_list) { + Object *b = ObjectDB::get_instance(E.key.from); + if (!b) { viewport->update(); + break; } - } - if (canvas_item->_edit_use_pivot()) { - nb_having_pivot++; - } - } + Node2D *b2 = Object::cast_to<Node2D>(b); + if (!b2 || !b2->is_inside_tree()) { + continue; + } - // Activate / Deactivate the pivot tool - pivot_button->set_disabled(nb_having_pivot == 0); + Transform2D global_xform = b2->get_global_transform(); - // Update the viewport if bones changes - for (KeyValue<BoneKey, BoneList> &E : bone_list) { - Object *b = ObjectDB::get_instance(E.key.from); - if (!b) { - viewport->update(); - break; + if (global_xform != E.value.xform) { + E.value.xform = global_xform; + viewport->update(); + } + + Bone2D *bone = Object::cast_to<Bone2D>(b); + if (bone && bone->get_length() != E.value.length) { + E.value.length = bone->get_length(); + viewport->update(); + } } + } break; - Node2D *b2 = Object::cast_to<Node2D>(b); - if (!b2 || !b2->is_inside_tree()) { - continue; + case NOTIFICATION_ENTER_TREE: { + select_sb->set_texture(get_theme_icon(SNAME("EditorRect2D"), SNAME("EditorIcons"))); + for (int i = 0; i < 4; i++) { + select_sb->set_margin_size(Side(i), 4); + select_sb->set_default_margin(Side(i), 4); } - Transform2D global_xform = b2->get_global_transform(); + AnimationPlayerEditor::get_singleton()->get_track_editor()->connect("visibility_changed", callable_mp(this, &CanvasItemEditor::_keying_changed)); + _keying_changed(); + _update_editor_settings(); + } break; - if (global_xform != E.value.xform) { - E.value.xform = global_xform; - viewport->update(); - } + case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { + select_sb->set_texture(get_theme_icon(SNAME("EditorRect2D"), SNAME("EditorIcons"))); + _update_editor_settings(); + } break; - Bone2D *bone = Object::cast_to<Bone2D>(b); - if (bone && bone->get_length() != E.value.length) { - E.value.length = bone->get_length(); - viewport->update(); - } - } - } + case NOTIFICATION_VISIBILITY_CHANGED: { + if (!is_visible() && override_camera_button->is_pressed()) { + EditorDebuggerNode *debugger = EditorDebuggerNode::get_singleton(); - if (p_what == NOTIFICATION_ENTER_TREE) { - select_sb->set_texture(get_theme_icon(SNAME("EditorRect2D"), SNAME("EditorIcons"))); - for (int i = 0; i < 4; i++) { - select_sb->set_margin_size(Side(i), 4); - select_sb->set_default_margin(Side(i), 4); - } - - AnimationPlayerEditor::get_singleton()->get_track_editor()->connect("visibility_changed", callable_mp(this, &CanvasItemEditor::_keying_changed)); - _keying_changed(); - - } else if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { - select_sb->set_texture(get_theme_icon(SNAME("EditorRect2D"), SNAME("EditorIcons"))); - } - - if (p_what == NOTIFICATION_ENTER_TREE || p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { - select_button->set_icon(get_theme_icon(SNAME("ToolSelect"), SNAME("EditorIcons"))); - list_select_button->set_icon(get_theme_icon(SNAME("ListSelect"), SNAME("EditorIcons"))); - move_button->set_icon(get_theme_icon(SNAME("ToolMove"), SNAME("EditorIcons"))); - scale_button->set_icon(get_theme_icon(SNAME("ToolScale"), SNAME("EditorIcons"))); - rotate_button->set_icon(get_theme_icon(SNAME("ToolRotate"), SNAME("EditorIcons"))); - smart_snap_button->set_icon(get_theme_icon(SNAME("Snap"), SNAME("EditorIcons"))); - grid_snap_button->set_icon(get_theme_icon(SNAME("SnapGrid"), SNAME("EditorIcons"))); - snap_config_menu->set_icon(get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons"))); - skeleton_menu->set_icon(get_theme_icon(SNAME("Bone"), SNAME("EditorIcons"))); - override_camera_button->set_icon(get_theme_icon(SNAME("Camera2D"), SNAME("EditorIcons"))); - pan_button->set_icon(get_theme_icon(SNAME("ToolPan"), SNAME("EditorIcons"))); - ruler_button->set_icon(get_theme_icon(SNAME("Ruler"), SNAME("EditorIcons"))); - pivot_button->set_icon(get_theme_icon(SNAME("EditPivot"), SNAME("EditorIcons"))); - select_handle = get_theme_icon(SNAME("EditorHandle"), SNAME("EditorIcons")); - anchor_handle = get_theme_icon(SNAME("EditorControlAnchor"), SNAME("EditorIcons")); - lock_button->set_icon(get_theme_icon(SNAME("Lock"), SNAME("EditorIcons"))); - unlock_button->set_icon(get_theme_icon(SNAME("Unlock"), SNAME("EditorIcons"))); - group_button->set_icon(get_theme_icon(SNAME("Group"), SNAME("EditorIcons"))); - ungroup_button->set_icon(get_theme_icon(SNAME("Ungroup"), SNAME("EditorIcons"))); - key_loc_button->set_icon(get_theme_icon(SNAME("KeyPosition"), SNAME("EditorIcons"))); - key_rot_button->set_icon(get_theme_icon(SNAME("KeyRotation"), SNAME("EditorIcons"))); - key_scale_button->set_icon(get_theme_icon(SNAME("KeyScale"), SNAME("EditorIcons"))); - key_insert_button->set_icon(get_theme_icon(SNAME("Key"), SNAME("EditorIcons"))); - key_auto_insert_button->set_icon(get_theme_icon(SNAME("AutoKey"), SNAME("EditorIcons"))); - // Use a different color for the active autokey icon to make them easier - // to distinguish from the other key icons at the top. On a light theme, - // the icon will be dark, so we need to lighten it before blending it - // with the red color. - const Color key_auto_color = EditorSettings::get_singleton()->is_dark_theme() ? Color(1, 1, 1) : Color(4.25, 4.25, 4.25); - key_auto_insert_button->add_theme_color_override("icon_pressed_color", key_auto_color.lerp(Color(1, 0, 0), 0.55)); - animation_menu->set_icon(get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons"))); - - _update_context_menu_stylebox(); - - panner->setup((ViewPanner::ControlScheme)EDITOR_GET("editors/panning/2d_editor_panning_scheme").operator int(), ED_GET_SHORTCUT("canvas_item_editor/pan_view"), bool(EditorSettings::get_singleton()->get("editors/panning/simple_panning"))); - pan_speed = int(EditorSettings::get_singleton()->get("editors/panning/2d_editor_pan_speed")); - warped_panning = bool(EditorSettings::get_singleton()->get("editors/panning/warped_mouse_panning")); - } - - if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { - if (!is_visible() && override_camera_button->is_pressed()) { - EditorDebuggerNode *debugger = EditorDebuggerNode::get_singleton(); - - debugger->set_camera_override(EditorDebuggerNode::OVERRIDE_NONE); - override_camera_button->set_pressed(false); - } + debugger->set_camera_override(EditorDebuggerNode::OVERRIDE_NONE); + override_camera_button->set_pressed(false); + } + } break; } } @@ -5702,29 +5707,32 @@ Node *CanvasItemEditorViewport::_make_texture_node_type(String texture_node_type return node; } -void CanvasItemEditorViewport::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { - List<BaseButton *> btn_list; - button_group->get_buttons(&btn_list); - - for (int i = 0; i < btn_list.size(); i++) { - CheckBox *check = Object::cast_to<CheckBox>(btn_list[i]); - check->set_icon(get_theme_icon(check->get_text(), SNAME("EditorIcons"))); - } +void CanvasItemEditorViewport::_update_theme() { + List<BaseButton *> btn_list; + button_group->get_buttons(&btn_list); - label->add_theme_color_override("font_color", get_theme_color(SNAME("warning_color"), SNAME("Editor"))); + for (int i = 0; i < btn_list.size(); i++) { + CheckBox *check = Object::cast_to<CheckBox>(btn_list[i]); + check->set_icon(get_theme_icon(check->get_text(), SNAME("EditorIcons"))); } + label->add_theme_color_override("font_color", get_theme_color(SNAME("warning_color"), SNAME("Editor"))); +} + +void CanvasItemEditorViewport::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_THEME_CHANGED: { + _update_theme(); + } break; + case NOTIFICATION_ENTER_TREE: { + _update_theme(); connect("mouse_exited", callable_mp(this, &CanvasItemEditorViewport::_on_mouse_exit)); } break; + case NOTIFICATION_EXIT_TREE: { disconnect("mouse_exited", callable_mp(this, &CanvasItemEditorViewport::_on_mouse_exit)); } break; - - default: - break; } } diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h index 6c1b18acf4..57760475a1 100644 --- a/editor/plugins/canvas_item_editor_plugin.h +++ b/editor/plugins/canvas_item_editor_plugin.h @@ -389,6 +389,7 @@ private: void _add_node_pressed(int p_result); void _node_created(Node *p_node); void _reset_create_position(); + void _update_editor_settings(); UndoRedo *undo_redo; @@ -607,6 +608,7 @@ class CanvasItemEditorViewport : public Control { bool _create_instance(Node *parent, String &path, const Point2 &p_point); void _perform_drop_data(); void _show_resource_type_selector(); + void _update_theme(); static void _bind_methods(); diff --git a/editor/plugins/cpu_particles_2d_editor_plugin.cpp b/editor/plugins/cpu_particles_2d_editor_plugin.cpp index 786c0e002d..79025041d3 100644 --- a/editor/plugins/cpu_particles_2d_editor_plugin.cpp +++ b/editor/plugins/cpu_particles_2d_editor_plugin.cpp @@ -224,10 +224,12 @@ void CPUParticles2DEditorPlugin::_generate_emission_mask() { } void CPUParticles2DEditorPlugin::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { - menu->get_popup()->connect("id_pressed", callable_mp(this, &CPUParticles2DEditorPlugin::_menu_callback)); - menu->set_icon(epoints->get_theme_icon(SNAME("CPUParticles2D"), SNAME("EditorIcons"))); - file->connect("file_selected", callable_mp(this, &CPUParticles2DEditorPlugin::_file_selected)); + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + menu->get_popup()->connect("id_pressed", callable_mp(this, &CPUParticles2DEditorPlugin::_menu_callback)); + menu->set_icon(epoints->get_theme_icon(SNAME("CPUParticles2D"), SNAME("EditorIcons"))); + file->connect("file_selected", callable_mp(this, &CPUParticles2DEditorPlugin::_file_selected)); + } break; } } diff --git a/editor/plugins/cpu_particles_3d_editor_plugin.cpp b/editor/plugins/cpu_particles_3d_editor_plugin.cpp index 046a48337a..775c2dbb2a 100644 --- a/editor/plugins/cpu_particles_3d_editor_plugin.cpp +++ b/editor/plugins/cpu_particles_3d_editor_plugin.cpp @@ -43,8 +43,10 @@ void CPUParticles3DEditor::_node_removed(Node *p_node) { } void CPUParticles3DEditor::_notification(int p_notification) { - if (p_notification == NOTIFICATION_ENTER_TREE) { - options->set_icon(get_theme_icon(SNAME("CPUParticles3D"), SNAME("EditorIcons"))); + switch (p_notification) { + case NOTIFICATION_ENTER_TREE: { + options->set_icon(get_theme_icon(SNAME("CPUParticles3D"), SNAME("EditorIcons"))); + } break; } } diff --git a/editor/plugins/curve_editor_plugin.cpp b/editor/plugins/curve_editor_plugin.cpp index d221d8aeaf..6d1a86765a 100644 --- a/editor/plugins/curve_editor_plugin.cpp +++ b/editor/plugins/curve_editor_plugin.cpp @@ -97,8 +97,10 @@ Size2 CurveEditor::get_minimum_size() const { } void CurveEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_DRAW) { - _draw(); + switch (p_what) { + case NOTIFICATION_DRAW: { + _draw(); + } break; } } diff --git a/editor/plugins/debugger_editor_plugin.cpp b/editor/plugins/debugger_editor_plugin.cpp index 32f58c6931..501becac57 100644 --- a/editor/plugins/debugger_editor_plugin.cpp +++ b/editor/plugins/debugger_editor_plugin.cpp @@ -177,8 +177,10 @@ void DebuggerEditorPlugin::_menu_option(int p_option) { } void DebuggerEditorPlugin::_notification(int p_what) { - if (p_what == NOTIFICATION_READY) { - _update_debug_options(); + switch (p_what) { + case NOTIFICATION_READY: { + _update_debug_options(); + } break; } } diff --git a/editor/plugins/font_editor_plugin.cpp b/editor/plugins/font_editor_plugin.cpp index e14304a2c8..b9de621bcb 100644 --- a/editor/plugins/font_editor_plugin.cpp +++ b/editor/plugins/font_editor_plugin.cpp @@ -33,14 +33,16 @@ #include "editor/editor_scale.h" void FontDataPreview::_notification(int p_what) { - if (p_what == NOTIFICATION_DRAW) { - Color text_color = get_theme_color(SNAME("font_color"), SNAME("Label")); - Color line_color = text_color; - line_color.a *= 0.6; - Vector2 pos = (get_size() - line->get_size()) / 2; - line->draw(get_canvas_item(), pos, text_color); - draw_line(Vector2(0, pos.y + line->get_line_ascent()), Vector2(pos.x - 5, pos.y + line->get_line_ascent()), line_color); - draw_line(Vector2(pos.x + line->get_size().x + 5, pos.y + line->get_line_ascent()), Vector2(get_size().x, pos.y + line->get_line_ascent()), line_color); + switch (p_what) { + case NOTIFICATION_DRAW: { + Color text_color = get_theme_color(SNAME("font_color"), SNAME("Label")); + Color line_color = text_color; + line_color.a *= 0.6; + Vector2 pos = (get_size() - line->get_size()) / 2; + line->draw(get_canvas_item(), pos, text_color); + draw_line(Vector2(0, pos.y + line->get_line_ascent()), Vector2(pos.x - 5, pos.y + line->get_line_ascent()), line_color); + draw_line(Vector2(pos.x + line->get_size().x + 5, pos.y + line->get_line_ascent()), Vector2(get_size().x, pos.y + line->get_line_ascent()), line_color); + } break; } } diff --git a/editor/plugins/gpu_particles_2d_editor_plugin.cpp b/editor/plugins/gpu_particles_2d_editor_plugin.cpp index fdfd4b5832..b15aec87d9 100644 --- a/editor/plugins/gpu_particles_2d_editor_plugin.cpp +++ b/editor/plugins/gpu_particles_2d_editor_plugin.cpp @@ -354,11 +354,13 @@ void GPUParticles2DEditorPlugin::_generate_emission_mask() { } void GPUParticles2DEditorPlugin::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { - menu->get_popup()->connect("id_pressed", callable_mp(this, &GPUParticles2DEditorPlugin::_menu_callback)); - menu->set_icon(menu->get_theme_icon(SNAME("GPUParticles2D"), SNAME("EditorIcons"))); - file->connect("file_selected", callable_mp(this, &GPUParticles2DEditorPlugin::_file_selected)); - EditorNode::get_singleton()->get_editor_selection()->connect("selection_changed", callable_mp(this, &GPUParticles2DEditorPlugin::_selection_changed)); + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + menu->get_popup()->connect("id_pressed", callable_mp(this, &GPUParticles2DEditorPlugin::_menu_callback)); + menu->set_icon(menu->get_theme_icon(SNAME("GPUParticles2D"), SNAME("EditorIcons"))); + file->connect("file_selected", callable_mp(this, &GPUParticles2DEditorPlugin::_file_selected)); + EditorNode::get_singleton()->get_editor_selection()->connect("selection_changed", callable_mp(this, &GPUParticles2DEditorPlugin::_selection_changed)); + } break; } } diff --git a/editor/plugins/gpu_particles_3d_editor_plugin.cpp b/editor/plugins/gpu_particles_3d_editor_plugin.cpp index ec61c01705..293d1c3913 100644 --- a/editor/plugins/gpu_particles_3d_editor_plugin.cpp +++ b/editor/plugins/gpu_particles_3d_editor_plugin.cpp @@ -231,9 +231,11 @@ void GPUParticles3DEditor::_node_removed(Node *p_node) { } void GPUParticles3DEditor::_notification(int p_notification) { - if (p_notification == NOTIFICATION_ENTER_TREE) { - options->set_icon(options->get_popup()->get_theme_icon(SNAME("GPUParticles3D"), SNAME("EditorIcons"))); - get_tree()->connect("node_removed", callable_mp(this, &GPUParticles3DEditor::_node_removed)); + switch (p_notification) { + case NOTIFICATION_ENTER_TREE: { + options->set_icon(options->get_popup()->get_theme_icon(SNAME("GPUParticles3D"), SNAME("EditorIcons"))); + get_tree()->connect("node_removed", callable_mp(this, &GPUParticles3DEditor::_node_removed)); + } break; } } diff --git a/editor/plugins/gpu_particles_collision_sdf_editor_plugin.cpp b/editor/plugins/gpu_particles_collision_sdf_editor_plugin.cpp index f63a31e869..affe10a01d 100644 --- a/editor/plugins/gpu_particles_collision_sdf_editor_plugin.cpp +++ b/editor/plugins/gpu_particles_collision_sdf_editor_plugin.cpp @@ -66,41 +66,43 @@ bool GPUParticlesCollisionSDF3DEditorPlugin::handles(Object *p_object) const { } void GPUParticlesCollisionSDF3DEditorPlugin::_notification(int p_what) { - if (p_what == NOTIFICATION_PROCESS) { - if (!col_sdf) { - return; - } + switch (p_what) { + case NOTIFICATION_PROCESS: { + if (!col_sdf) { + return; + } - // Set information tooltip on the Bake button. This information is useful - // to optimize performance (video RAM size) and reduce collision tunneling (individual cell size). + // Set information tooltip on the Bake button. This information is useful + // to optimize performance (video RAM size) and reduce collision tunneling (individual cell size). - const Vector3i size = col_sdf->get_estimated_cell_size(); + const Vector3i size = col_sdf->get_estimated_cell_size(); - const Vector3 extents = col_sdf->get_extents(); + const Vector3 extents = col_sdf->get_extents(); - int data_size = 2; - const double size_mb = size.x * size.y * size.z * data_size / (1024.0 * 1024.0); - // Add a qualitative measurement to help the user assess whether a GPUParticlesCollisionSDF3D node is using a lot of VRAM. - String size_quality; - if (size_mb < 8.0) { - size_quality = TTR("Low"); - } else if (size_mb < 32.0) { - size_quality = TTR("Moderate"); - } else { - size_quality = TTR("High"); - } + int data_size = 2; + const double size_mb = size.x * size.y * size.z * data_size / (1024.0 * 1024.0); + // Add a qualitative measurement to help the user assess whether a GPUParticlesCollisionSDF3D node is using a lot of VRAM. + String size_quality; + if (size_mb < 8.0) { + size_quality = TTR("Low"); + } else if (size_mb < 32.0) { + size_quality = TTR("Moderate"); + } else { + size_quality = TTR("High"); + } - String text; - text += vformat(TTR("Subdivisions: %s"), vformat(String::utf8("%d × %d × %d"), size.x, size.y, size.z)) + "\n"; - text += vformat(TTR("Cell size: %s"), vformat(String::utf8("%.3f × %.3f × %.3f"), extents.x / size.x, extents.y / size.y, extents.z / size.z)) + "\n"; - text += vformat(TTR("Video RAM size: %s MB (%s)"), String::num(size_mb, 2), size_quality); + String text; + text += vformat(TTR("Subdivisions: %s"), vformat(String::utf8("%d × %d × %d"), size.x, size.y, size.z)) + "\n"; + text += vformat(TTR("Cell size: %s"), vformat(String::utf8("%.3f × %.3f × %.3f"), extents.x / size.x, extents.y / size.y, extents.z / size.z)) + "\n"; + text += vformat(TTR("Video RAM size: %s MB (%s)"), String::num(size_mb, 2), size_quality); - // Only update the tooltip when needed to avoid constant redrawing. - if (bake->get_tooltip(Point2()) == text) { - return; - } + // Only update the tooltip when needed to avoid constant redrawing. + if (bake->get_tooltip(Point2()) == text) { + return; + } - bake->set_tooltip(text); + bake->set_tooltip(text); + } break; } } diff --git a/editor/plugins/gradient_editor_plugin.cpp b/editor/plugins/gradient_editor_plugin.cpp index 3f5b687430..e9d7808684 100644 --- a/editor/plugins/gradient_editor_plugin.cpp +++ b/editor/plugins/gradient_editor_plugin.cpp @@ -91,13 +91,15 @@ GradientEditor::GradientEditor() { /////////////////////// void GradientReverseButton::_notification(int p_what) { - if (p_what == NOTIFICATION_DRAW) { - Ref<Texture2D> icon = get_theme_icon(SNAME("ReverseGradient"), SNAME("EditorIcons")); - if (is_pressed()) { - draw_texture_rect(icon, Rect2(margin, margin, icon->get_width(), icon->get_height()), false, get_theme_color(SNAME("icon_pressed_color"), SNAME("Button"))); - } else { - draw_texture_rect(icon, Rect2(margin, margin, icon->get_width(), icon->get_height())); - } + switch (p_what) { + case NOTIFICATION_DRAW: { + Ref<Texture2D> icon = get_theme_icon(SNAME("ReverseGradient"), SNAME("EditorIcons")); + if (is_pressed()) { + draw_texture_rect(icon, Rect2(margin, margin, icon->get_width(), icon->get_height()), false, get_theme_color(SNAME("icon_pressed_color"), SNAME("Button"))); + } else { + draw_texture_rect(icon, Rect2(margin, margin, icon->get_width(), icon->get_height())); + } + } break; } } diff --git a/editor/plugins/material_editor_plugin.cpp b/editor/plugins/material_editor_plugin.cpp index f3759da47f..daa864cfa1 100644 --- a/editor/plugins/material_editor_plugin.cpp +++ b/editor/plugins/material_editor_plugin.cpp @@ -38,31 +38,33 @@ #include "scene/resources/sky_material.h" void MaterialEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_READY) { - //get_scene()->connect("node_removed",this,"_node_removed"); + switch (p_what) { + case NOTIFICATION_READY: { + //get_scene()->connect("node_removed",this,"_node_removed"); - if (first_enter) { - //it's in propertyeditor so.. could be moved around + if (first_enter) { + //it's in propertyeditor so.. could be moved around - light_1_switch->set_normal_texture(get_theme_icon(SNAME("MaterialPreviewLight1"), SNAME("EditorIcons"))); - light_1_switch->set_pressed_texture(get_theme_icon(SNAME("MaterialPreviewLight1Off"), SNAME("EditorIcons"))); - light_2_switch->set_normal_texture(get_theme_icon(SNAME("MaterialPreviewLight2"), SNAME("EditorIcons"))); - light_2_switch->set_pressed_texture(get_theme_icon(SNAME("MaterialPreviewLight2Off"), SNAME("EditorIcons"))); + light_1_switch->set_normal_texture(get_theme_icon(SNAME("MaterialPreviewLight1"), SNAME("EditorIcons"))); + light_1_switch->set_pressed_texture(get_theme_icon(SNAME("MaterialPreviewLight1Off"), SNAME("EditorIcons"))); + light_2_switch->set_normal_texture(get_theme_icon(SNAME("MaterialPreviewLight2"), SNAME("EditorIcons"))); + light_2_switch->set_pressed_texture(get_theme_icon(SNAME("MaterialPreviewLight2Off"), SNAME("EditorIcons"))); - sphere_switch->set_normal_texture(get_theme_icon(SNAME("MaterialPreviewSphereOff"), SNAME("EditorIcons"))); - sphere_switch->set_pressed_texture(get_theme_icon(SNAME("MaterialPreviewSphere"), SNAME("EditorIcons"))); - box_switch->set_normal_texture(get_theme_icon(SNAME("MaterialPreviewCubeOff"), SNAME("EditorIcons"))); - box_switch->set_pressed_texture(get_theme_icon(SNAME("MaterialPreviewCube"), SNAME("EditorIcons"))); + sphere_switch->set_normal_texture(get_theme_icon(SNAME("MaterialPreviewSphereOff"), SNAME("EditorIcons"))); + sphere_switch->set_pressed_texture(get_theme_icon(SNAME("MaterialPreviewSphere"), SNAME("EditorIcons"))); + box_switch->set_normal_texture(get_theme_icon(SNAME("MaterialPreviewCubeOff"), SNAME("EditorIcons"))); + box_switch->set_pressed_texture(get_theme_icon(SNAME("MaterialPreviewCube"), SNAME("EditorIcons"))); - first_enter = false; - } - } + first_enter = false; + } + } break; - if (p_what == NOTIFICATION_DRAW) { - Ref<Texture2D> checkerboard = get_theme_icon(SNAME("Checkerboard"), SNAME("EditorIcons")); - Size2 size = get_size(); + case NOTIFICATION_DRAW: { + Ref<Texture2D> checkerboard = get_theme_icon(SNAME("Checkerboard"), SNAME("EditorIcons")); + Size2 size = get_size(); - draw_texture_rect(checkerboard, Rect2(Point2(), size), true); + draw_texture_rect(checkerboard, Rect2(Point2(), size), true); + } break; } } diff --git a/editor/plugins/mesh_editor_plugin.cpp b/editor/plugins/mesh_editor_plugin.cpp index 8711559dbf..4760b61dc8 100644 --- a/editor/plugins/mesh_editor_plugin.cpp +++ b/editor/plugins/mesh_editor_plugin.cpp @@ -49,18 +49,20 @@ void MeshEditor::gui_input(const Ref<InputEvent> &p_event) { } void MeshEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_READY) { - //get_scene()->connect("node_removed",this,"_node_removed"); - - if (first_enter) { - //it's in propertyeditor so. could be moved around - - light_1_switch->set_normal_texture(get_theme_icon(SNAME("MaterialPreviewLight1"), SNAME("EditorIcons"))); - light_1_switch->set_pressed_texture(get_theme_icon(SNAME("MaterialPreviewLight1Off"), SNAME("EditorIcons"))); - light_2_switch->set_normal_texture(get_theme_icon(SNAME("MaterialPreviewLight2"), SNAME("EditorIcons"))); - light_2_switch->set_pressed_texture(get_theme_icon(SNAME("MaterialPreviewLight2Off"), SNAME("EditorIcons"))); - first_enter = false; - } + switch (p_what) { + case NOTIFICATION_READY: { + //get_scene()->connect("node_removed",this,"_node_removed"); + + if (first_enter) { + //it's in propertyeditor so. could be moved around + + light_1_switch->set_normal_texture(get_theme_icon(SNAME("MaterialPreviewLight1"), SNAME("EditorIcons"))); + light_1_switch->set_pressed_texture(get_theme_icon(SNAME("MaterialPreviewLight1Off"), SNAME("EditorIcons"))); + light_2_switch->set_normal_texture(get_theme_icon(SNAME("MaterialPreviewLight2"), SNAME("EditorIcons"))); + light_2_switch->set_pressed_texture(get_theme_icon(SNAME("MaterialPreviewLight2Off"), SNAME("EditorIcons"))); + first_enter = false; + } + } break; } } diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index 52671f224e..3d3738ad47 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -82,28 +82,32 @@ #define MAX_FOV 179 void ViewportRotationControl::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { - axis_menu_options.clear(); - axis_menu_options.push_back(Node3DEditorViewport::VIEW_RIGHT); - axis_menu_options.push_back(Node3DEditorViewport::VIEW_TOP); - axis_menu_options.push_back(Node3DEditorViewport::VIEW_REAR); - axis_menu_options.push_back(Node3DEditorViewport::VIEW_LEFT); - axis_menu_options.push_back(Node3DEditorViewport::VIEW_BOTTOM); - axis_menu_options.push_back(Node3DEditorViewport::VIEW_FRONT); - - axis_colors.clear(); - axis_colors.push_back(get_theme_color(SNAME("axis_x_color"), SNAME("Editor"))); - axis_colors.push_back(get_theme_color(SNAME("axis_y_color"), SNAME("Editor"))); - axis_colors.push_back(get_theme_color(SNAME("axis_z_color"), SNAME("Editor"))); - update(); + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + axis_menu_options.clear(); + axis_menu_options.push_back(Node3DEditorViewport::VIEW_RIGHT); + axis_menu_options.push_back(Node3DEditorViewport::VIEW_TOP); + axis_menu_options.push_back(Node3DEditorViewport::VIEW_REAR); + axis_menu_options.push_back(Node3DEditorViewport::VIEW_LEFT); + axis_menu_options.push_back(Node3DEditorViewport::VIEW_BOTTOM); + axis_menu_options.push_back(Node3DEditorViewport::VIEW_FRONT); + + axis_colors.clear(); + axis_colors.push_back(get_theme_color(SNAME("axis_x_color"), SNAME("Editor"))); + axis_colors.push_back(get_theme_color(SNAME("axis_y_color"), SNAME("Editor"))); + axis_colors.push_back(get_theme_color(SNAME("axis_z_color"), SNAME("Editor"))); + update(); - if (!is_connected("mouse_exited", callable_mp(this, &ViewportRotationControl::_on_mouse_exited))) { - connect("mouse_exited", callable_mp(this, &ViewportRotationControl::_on_mouse_exited)); - } - } + if (!is_connected("mouse_exited", callable_mp(this, &ViewportRotationControl::_on_mouse_exited))) { + connect("mouse_exited", callable_mp(this, &ViewportRotationControl::_on_mouse_exited)); + } + } break; - if (p_what == NOTIFICATION_DRAW && viewport != nullptr) { - _draw(); + case NOTIFICATION_DRAW: { + if (viewport != nullptr) { + _draw(); + } + } break; } } @@ -2422,279 +2426,281 @@ void Node3DEditorViewport::_project_settings_changed() { } void Node3DEditorViewport::_notification(int p_what) { - if (p_what == NOTIFICATION_READY) { - EditorNode::get_singleton()->connect("project_settings_changed", callable_mp(this, &Node3DEditorViewport::_project_settings_changed)); - } + switch (p_what) { + case NOTIFICATION_READY: { + EditorNode::get_singleton()->connect("project_settings_changed", callable_mp(this, &Node3DEditorViewport::_project_settings_changed)); + } break; - if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { - bool visible = is_visible_in_tree(); + case NOTIFICATION_VISIBILITY_CHANGED: { + bool visible = is_visible_in_tree(); - set_process(visible); + set_process(visible); - if (visible) { - orthogonal = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_ORTHOGONAL)); - _update_name(); - _update_camera(0); - } else { - set_freelook_active(false); - } - call_deferred(SNAME("update_transform_gizmo_view")); - rotation_control->set_visible(EditorSettings::get_singleton()->get("editors/3d/navigation/show_viewport_rotation_gizmo")); - } + if (visible) { + orthogonal = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_ORTHOGONAL)); + _update_name(); + _update_camera(0); + } else { + set_freelook_active(false); + } + call_deferred(SNAME("update_transform_gizmo_view")); + rotation_control->set_visible(EditorSettings::get_singleton()->get("editors/3d/navigation/show_viewport_rotation_gizmo")); + } break; - if (p_what == NOTIFICATION_RESIZED) { - call_deferred(SNAME("update_transform_gizmo_view")); - } + case NOTIFICATION_RESIZED: { + call_deferred(SNAME("update_transform_gizmo_view")); + } break; - if (p_what == NOTIFICATION_PROCESS) { - real_t delta = get_process_delta_time(); + case NOTIFICATION_PROCESS: { + real_t delta = get_process_delta_time(); - if (zoom_indicator_delay > 0) { - zoom_indicator_delay -= delta; - if (zoom_indicator_delay <= 0) { - surface->update(); - zoom_limit_label->hide(); + if (zoom_indicator_delay > 0) { + zoom_indicator_delay -= delta; + if (zoom_indicator_delay <= 0) { + surface->update(); + zoom_limit_label->hide(); + } } - } - _update_freelook(delta); + _update_freelook(delta); - Node *scene_root = SceneTreeDock::get_singleton()->get_editor_data()->get_edited_scene_root(); - if (previewing_cinema && scene_root != nullptr) { - Camera3D *cam = scene_root->get_viewport()->get_camera_3d(); - if (cam != nullptr && cam != previewing) { - //then switch the viewport's camera to the scene's viewport camera - if (previewing != nullptr) { - previewing->disconnect("tree_exited", callable_mp(this, &Node3DEditorViewport::_preview_exited_scene)); + Node *scene_root = SceneTreeDock::get_singleton()->get_editor_data()->get_edited_scene_root(); + if (previewing_cinema && scene_root != nullptr) { + Camera3D *cam = scene_root->get_viewport()->get_camera_3d(); + if (cam != nullptr && cam != previewing) { + //then switch the viewport's camera to the scene's viewport camera + if (previewing != nullptr) { + previewing->disconnect("tree_exited", callable_mp(this, &Node3DEditorViewport::_preview_exited_scene)); + } + previewing = cam; + previewing->connect("tree_exited", callable_mp(this, &Node3DEditorViewport::_preview_exited_scene)); + RS::get_singleton()->viewport_attach_camera(viewport->get_viewport_rid(), cam->get_camera()); + surface->update(); } - previewing = cam; - previewing->connect("tree_exited", callable_mp(this, &Node3DEditorViewport::_preview_exited_scene)); - RS::get_singleton()->viewport_attach_camera(viewport->get_viewport_rid(), cam->get_camera()); - surface->update(); } - } - _update_camera(delta); + _update_camera(delta); - Map<Node *, Object *> &selection = editor_selection->get_selection(); + Map<Node *, Object *> &selection = editor_selection->get_selection(); - bool changed = false; - bool exist = false; + bool changed = false; + bool exist = false; - for (const KeyValue<Node *, Object *> &E : selection) { - Node3D *sp = Object::cast_to<Node3D>(E.key); - if (!sp) { - continue; - } + for (const KeyValue<Node *, Object *> &E : selection) { + Node3D *sp = Object::cast_to<Node3D>(E.key); + if (!sp) { + continue; + } - Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp); - if (!se) { - continue; - } + Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp); + if (!se) { + continue; + } - Transform3D t = sp->get_global_gizmo_transform(); - VisualInstance3D *vi = Object::cast_to<VisualInstance3D>(sp); - AABB new_aabb = vi ? vi->get_aabb() : _calculate_spatial_bounds(sp); + Transform3D t = sp->get_global_gizmo_transform(); + VisualInstance3D *vi = Object::cast_to<VisualInstance3D>(sp); + AABB new_aabb = vi ? vi->get_aabb() : _calculate_spatial_bounds(sp); - exist = true; - if (se->last_xform == t && se->aabb == new_aabb && !se->last_xform_dirty) { - continue; - } - changed = true; - se->last_xform_dirty = false; - se->last_xform = t; + exist = true; + if (se->last_xform == t && se->aabb == new_aabb && !se->last_xform_dirty) { + continue; + } + changed = true; + se->last_xform_dirty = false; + se->last_xform = t; - se->aabb = new_aabb; + se->aabb = new_aabb; - Transform3D t_offset = t; + Transform3D t_offset = t; - // apply AABB scaling before item's global transform - { - const Vector3 offset(0.005, 0.005, 0.005); - Basis aabb_s; - aabb_s.scale(se->aabb.size + offset); - t.translate(se->aabb.position - offset / 2); - t.basis = t.basis * aabb_s; - } - { - const Vector3 offset(0.01, 0.01, 0.01); - Basis aabb_s; - aabb_s.scale(se->aabb.size + offset); - t_offset.translate(se->aabb.position - offset / 2); - t_offset.basis = t_offset.basis * aabb_s; + // apply AABB scaling before item's global transform + { + const Vector3 offset(0.005, 0.005, 0.005); + Basis aabb_s; + aabb_s.scale(se->aabb.size + offset); + t.translate(se->aabb.position - offset / 2); + t.basis = t.basis * aabb_s; + } + { + const Vector3 offset(0.01, 0.01, 0.01); + Basis aabb_s; + aabb_s.scale(se->aabb.size + offset); + t_offset.translate(se->aabb.position - offset / 2); + t_offset.basis = t_offset.basis * aabb_s; + } + + RenderingServer::get_singleton()->instance_set_transform(se->sbox_instance, t); + RenderingServer::get_singleton()->instance_set_transform(se->sbox_instance_offset, t_offset); + RenderingServer::get_singleton()->instance_set_transform(se->sbox_instance_xray, t); + RenderingServer::get_singleton()->instance_set_transform(se->sbox_instance_xray_offset, t_offset); } - RenderingServer::get_singleton()->instance_set_transform(se->sbox_instance, t); - RenderingServer::get_singleton()->instance_set_transform(se->sbox_instance_offset, t_offset); - RenderingServer::get_singleton()->instance_set_transform(se->sbox_instance_xray, t); - RenderingServer::get_singleton()->instance_set_transform(se->sbox_instance_xray_offset, t_offset); - } + if (changed || (spatial_editor->is_gizmo_visible() && !exist)) { + spatial_editor->update_transform_gizmo(); + } - if (changed || (spatial_editor->is_gizmo_visible() && !exist)) { - spatial_editor->update_transform_gizmo(); - } + if (message_time > 0) { + if (message != last_message) { + surface->update(); + last_message = message; + } - if (message_time > 0) { - if (message != last_message) { - surface->update(); - last_message = message; + message_time -= get_physics_process_delta_time(); + if (message_time < 0) { + surface->update(); + } } - message_time -= get_physics_process_delta_time(); - if (message_time < 0) { - surface->update(); + bool show_info = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_INFORMATION)); + if (show_info != info_label->is_visible()) { + info_label->set_visible(show_info); } - } - bool show_info = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_INFORMATION)); - if (show_info != info_label->is_visible()) { - info_label->set_visible(show_info); - } + Camera3D *current_camera; - Camera3D *current_camera; + if (previewing) { + current_camera = previewing; + } else { + current_camera = camera; + } + + if (show_info) { + const String viewport_size = vformat(String::utf8("%d × %d"), viewport->get_size().x, viewport->get_size().y); + String text; + text += vformat(TTR("X: %s\n"), rtos(current_camera->get_position().x).pad_decimals(1)); + text += vformat(TTR("Y: %s\n"), rtos(current_camera->get_position().y).pad_decimals(1)); + text += vformat(TTR("Z: %s\n"), rtos(current_camera->get_position().z).pad_decimals(1)); + text += "\n"; + text += vformat( + TTR("Size: %s (%.1fMP)\n"), + viewport_size, + viewport->get_size().x * viewport->get_size().y * 0.000001); + + text += "\n"; + text += vformat(TTR("Objects: %d\n"), viewport->get_render_info(Viewport::RENDER_INFO_TYPE_VISIBLE, Viewport::RENDER_INFO_OBJECTS_IN_FRAME)); + text += vformat(TTR("Primitives: %d\n"), viewport->get_render_info(Viewport::RENDER_INFO_TYPE_VISIBLE, Viewport::RENDER_INFO_PRIMITIVES_IN_FRAME)); + text += vformat(TTR("Draw Calls: %d"), viewport->get_render_info(Viewport::RENDER_INFO_TYPE_VISIBLE, Viewport::RENDER_INFO_DRAW_CALLS_IN_FRAME)); + + info_label->set_text(text); + } + + // FPS Counter. + bool show_fps = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_FRAME_TIME)); + + if (show_fps != fps_label->is_visible()) { + cpu_time_label->set_visible(show_fps); + gpu_time_label->set_visible(show_fps); + fps_label->set_visible(show_fps); + RS::get_singleton()->viewport_set_measure_render_time(viewport->get_viewport_rid(), show_fps); + for (int i = 0; i < FRAME_TIME_HISTORY; i++) { + cpu_time_history[i] = 0; + gpu_time_history[i] = 0; + } + cpu_time_history_index = 0; + gpu_time_history_index = 0; + } + if (show_fps) { + cpu_time_history[cpu_time_history_index] = RS::get_singleton()->viewport_get_measured_render_time_cpu(viewport->get_viewport_rid()); + cpu_time_history_index = (cpu_time_history_index + 1) % FRAME_TIME_HISTORY; + double cpu_time = 0.0; + for (int i = 0; i < FRAME_TIME_HISTORY; i++) { + cpu_time += cpu_time_history[i]; + } + cpu_time /= FRAME_TIME_HISTORY; + // Prevent unrealistically low values. + cpu_time = MAX(0.01, cpu_time); + + gpu_time_history[gpu_time_history_index] = RS::get_singleton()->viewport_get_measured_render_time_gpu(viewport->get_viewport_rid()); + gpu_time_history_index = (gpu_time_history_index + 1) % FRAME_TIME_HISTORY; + double gpu_time = 0.0; + for (int i = 0; i < FRAME_TIME_HISTORY; i++) { + gpu_time += gpu_time_history[i]; + } + gpu_time /= FRAME_TIME_HISTORY; + // Prevent division by zero for the FPS counter (and unrealistically low values). + // This limits the reported FPS to 100000. + gpu_time = MAX(0.01, gpu_time); + + // Color labels depending on performance level ("good" = green, "OK" = yellow, "bad" = red). + // Middle point is at 15 ms. + cpu_time_label->set_text(vformat(TTR("CPU Time: %s ms"), rtos(cpu_time).pad_decimals(2))); + cpu_time_label->add_theme_color_override( + "font_color", + frame_time_gradient->get_color_at_offset( + Math::range_lerp(cpu_time, 0, 30, 0, 1))); + + gpu_time_label->set_text(vformat(TTR("GPU Time: %s ms"), rtos(gpu_time).pad_decimals(2))); + // Middle point is at 15 ms. + gpu_time_label->add_theme_color_override( + "font_color", + frame_time_gradient->get_color_at_offset( + Math::range_lerp(gpu_time, 0, 30, 0, 1))); + + const double fps = 1000.0 / gpu_time; + fps_label->set_text(vformat(TTR("FPS: %d"), fps)); + // Middle point is at 60 FPS. + fps_label->add_theme_color_override( + "font_color", + frame_time_gradient->get_color_at_offset( + Math::range_lerp(fps, 110, 10, 0, 1))); + } + + bool show_cinema = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_CINEMATIC_PREVIEW)); + cinema_label->set_visible(show_cinema); + if (show_cinema) { + float cinema_half_width = cinema_label->get_size().width / 2.0f; + cinema_label->set_anchor_and_offset(SIDE_LEFT, 0.5f, -cinema_half_width); + } - if (previewing) { - current_camera = previewing; - } else { - current_camera = camera; - } - - if (show_info) { - const String viewport_size = vformat(String::utf8("%d × %d"), viewport->get_size().x, viewport->get_size().y); - String text; - text += vformat(TTR("X: %s\n"), rtos(current_camera->get_position().x).pad_decimals(1)); - text += vformat(TTR("Y: %s\n"), rtos(current_camera->get_position().y).pad_decimals(1)); - text += vformat(TTR("Z: %s\n"), rtos(current_camera->get_position().z).pad_decimals(1)); - text += "\n"; - text += vformat( - TTR("Size: %s (%.1fMP)\n"), - viewport_size, - viewport->get_size().x * viewport->get_size().y * 0.000001); - - text += "\n"; - text += vformat(TTR("Objects: %d\n"), viewport->get_render_info(Viewport::RENDER_INFO_TYPE_VISIBLE, Viewport::RENDER_INFO_OBJECTS_IN_FRAME)); - text += vformat(TTR("Primitives: %d\n"), viewport->get_render_info(Viewport::RENDER_INFO_TYPE_VISIBLE, Viewport::RENDER_INFO_PRIMITIVES_IN_FRAME)); - text += vformat(TTR("Draw Calls: %d"), viewport->get_render_info(Viewport::RENDER_INFO_TYPE_VISIBLE, Viewport::RENDER_INFO_DRAW_CALLS_IN_FRAME)); - - info_label->set_text(text); - } - - // FPS Counter. - bool show_fps = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_FRAME_TIME)); - - if (show_fps != fps_label->is_visible()) { - cpu_time_label->set_visible(show_fps); - gpu_time_label->set_visible(show_fps); - fps_label->set_visible(show_fps); - RS::get_singleton()->viewport_set_measure_render_time(viewport->get_viewport_rid(), show_fps); - for (int i = 0; i < FRAME_TIME_HISTORY; i++) { - cpu_time_history[i] = 0; - gpu_time_history[i] = 0; - } - cpu_time_history_index = 0; - gpu_time_history_index = 0; - } - if (show_fps) { - cpu_time_history[cpu_time_history_index] = RS::get_singleton()->viewport_get_measured_render_time_cpu(viewport->get_viewport_rid()); - cpu_time_history_index = (cpu_time_history_index + 1) % FRAME_TIME_HISTORY; - double cpu_time = 0.0; - for (int i = 0; i < FRAME_TIME_HISTORY; i++) { - cpu_time += cpu_time_history[i]; - } - cpu_time /= FRAME_TIME_HISTORY; - // Prevent unrealistically low values. - cpu_time = MAX(0.01, cpu_time); - - gpu_time_history[gpu_time_history_index] = RS::get_singleton()->viewport_get_measured_render_time_gpu(viewport->get_viewport_rid()); - gpu_time_history_index = (gpu_time_history_index + 1) % FRAME_TIME_HISTORY; - double gpu_time = 0.0; - for (int i = 0; i < FRAME_TIME_HISTORY; i++) { - gpu_time += gpu_time_history[i]; - } - gpu_time /= FRAME_TIME_HISTORY; - // Prevent division by zero for the FPS counter (and unrealistically low values). - // This limits the reported FPS to 100000. - gpu_time = MAX(0.01, gpu_time); - - // Color labels depending on performance level ("good" = green, "OK" = yellow, "bad" = red). - // Middle point is at 15 ms. - cpu_time_label->set_text(vformat(TTR("CPU Time: %s ms"), rtos(cpu_time).pad_decimals(2))); - cpu_time_label->add_theme_color_override( - "font_color", - frame_time_gradient->get_color_at_offset( - Math::range_lerp(cpu_time, 0, 30, 0, 1))); - - gpu_time_label->set_text(vformat(TTR("GPU Time: %s ms"), rtos(gpu_time).pad_decimals(2))); - // Middle point is at 15 ms. - gpu_time_label->add_theme_color_override( - "font_color", - frame_time_gradient->get_color_at_offset( - Math::range_lerp(gpu_time, 0, 30, 0, 1))); - - const double fps = 1000.0 / gpu_time; - fps_label->set_text(vformat(TTR("FPS: %d"), fps)); - // Middle point is at 60 FPS. - fps_label->add_theme_color_override( - "font_color", - frame_time_gradient->get_color_at_offset( - Math::range_lerp(fps, 110, 10, 0, 1))); - } - - bool show_cinema = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_CINEMATIC_PREVIEW)); - cinema_label->set_visible(show_cinema); - if (show_cinema) { - float cinema_half_width = cinema_label->get_size().width / 2.0f; - cinema_label->set_anchor_and_offset(SIDE_LEFT, 0.5f, -cinema_half_width); - } - - if (lock_rotation) { - float locked_half_width = locked_label->get_size().width / 2.0f; - locked_label->set_anchor_and_offset(SIDE_LEFT, 0.5f, -locked_half_width); - } - } - - if (p_what == NOTIFICATION_ENTER_TREE) { - surface->connect("draw", callable_mp(this, &Node3DEditorViewport::_draw)); - surface->connect("gui_input", callable_mp(this, &Node3DEditorViewport::_sinput)); - surface->connect("mouse_entered", callable_mp(this, &Node3DEditorViewport::_surface_mouse_enter)); - surface->connect("mouse_exited", callable_mp(this, &Node3DEditorViewport::_surface_mouse_exit)); - surface->connect("focus_entered", callable_mp(this, &Node3DEditorViewport::_surface_focus_enter)); - surface->connect("focus_exited", callable_mp(this, &Node3DEditorViewport::_surface_focus_exit)); - - _init_gizmo_instance(index); - } - - if (p_what == NOTIFICATION_EXIT_TREE) { - _finish_gizmo_instances(); - } + if (lock_rotation) { + float locked_half_width = locked_label->get_size().width / 2.0f; + locked_label->set_anchor_and_offset(SIDE_LEFT, 0.5f, -locked_half_width); + } + } break; - if (p_what == NOTIFICATION_THEME_CHANGED) { - view_menu->set_icon(get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons"))); - preview_camera->set_icon(get_theme_icon(SNAME("Camera3D"), SNAME("EditorIcons"))); - Control *gui_base = EditorNode::get_singleton()->get_gui_base(); + case NOTIFICATION_ENTER_TREE: { + surface->connect("draw", callable_mp(this, &Node3DEditorViewport::_draw)); + surface->connect("gui_input", callable_mp(this, &Node3DEditorViewport::_sinput)); + surface->connect("mouse_entered", callable_mp(this, &Node3DEditorViewport::_surface_mouse_enter)); + surface->connect("mouse_exited", callable_mp(this, &Node3DEditorViewport::_surface_mouse_exit)); + surface->connect("focus_entered", callable_mp(this, &Node3DEditorViewport::_surface_focus_enter)); + surface->connect("focus_exited", callable_mp(this, &Node3DEditorViewport::_surface_focus_exit)); + + _init_gizmo_instance(index); + } break; - view_menu->add_theme_style_override("normal", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); - view_menu->add_theme_style_override("hover", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); - view_menu->add_theme_style_override("pressed", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); - view_menu->add_theme_style_override("focus", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); - view_menu->add_theme_style_override("disabled", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); - - preview_camera->add_theme_style_override("normal", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); - preview_camera->add_theme_style_override("hover", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); - preview_camera->add_theme_style_override("pressed", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); - preview_camera->add_theme_style_override("focus", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); - preview_camera->add_theme_style_override("disabled", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); - - frame_time_gradient->set_color(0, get_theme_color(SNAME("success_color"), SNAME("Editor"))); - frame_time_gradient->set_color(1, get_theme_color(SNAME("warning_color"), SNAME("Editor"))); - frame_time_gradient->set_color(2, get_theme_color(SNAME("error_color"), SNAME("Editor"))); + case NOTIFICATION_EXIT_TREE: { + _finish_gizmo_instances(); + } break; - info_label->add_theme_style_override("normal", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); - cpu_time_label->add_theme_style_override("normal", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); - gpu_time_label->add_theme_style_override("normal", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); - fps_label->add_theme_style_override("normal", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); - cinema_label->add_theme_style_override("normal", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); - locked_label->add_theme_style_override("normal", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); + case NOTIFICATION_THEME_CHANGED: { + view_menu->set_icon(get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons"))); + preview_camera->set_icon(get_theme_icon(SNAME("Camera3D"), SNAME("EditorIcons"))); + Control *gui_base = EditorNode::get_singleton()->get_gui_base(); + + view_menu->add_theme_style_override("normal", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); + view_menu->add_theme_style_override("hover", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); + view_menu->add_theme_style_override("pressed", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); + view_menu->add_theme_style_override("focus", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); + view_menu->add_theme_style_override("disabled", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); + + preview_camera->add_theme_style_override("normal", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); + preview_camera->add_theme_style_override("hover", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); + preview_camera->add_theme_style_override("pressed", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); + preview_camera->add_theme_style_override("focus", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); + preview_camera->add_theme_style_override("disabled", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); + + frame_time_gradient->set_color(0, get_theme_color(SNAME("success_color"), SNAME("Editor"))); + frame_time_gradient->set_color(1, get_theme_color(SNAME("warning_color"), SNAME("Editor"))); + frame_time_gradient->set_color(2, get_theme_color(SNAME("error_color"), SNAME("Editor"))); + + info_label->add_theme_style_override("normal", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); + cpu_time_label->add_theme_style_override("normal", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); + gpu_time_label->add_theme_style_override("normal", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); + fps_label->add_theme_style_override("normal", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); + cinema_label->add_theme_style_override("normal", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); + locked_label->add_theme_style_override("normal", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); + } break; } } @@ -4799,197 +4805,202 @@ void Node3DEditorViewportContainer::gui_input(const Ref<InputEvent> &p_event) { } void Node3DEditorViewportContainer::_notification(int p_what) { - if (p_what == NOTIFICATION_MOUSE_ENTER || p_what == NOTIFICATION_MOUSE_EXIT) { - mouseover = (p_what == NOTIFICATION_MOUSE_ENTER); - update(); - } + switch (p_what) { + case NOTIFICATION_MOUSE_ENTER: + case NOTIFICATION_MOUSE_EXIT: { + mouseover = (p_what == NOTIFICATION_MOUSE_ENTER); + update(); + } break; - if (p_what == NOTIFICATION_DRAW && mouseover) { - Ref<Texture2D> h_grabber = get_theme_icon(SNAME("grabber"), SNAME("HSplitContainer")); - Ref<Texture2D> v_grabber = get_theme_icon(SNAME("grabber"), SNAME("VSplitContainer")); + case NOTIFICATION_DRAW: { + if (mouseover) { + Ref<Texture2D> h_grabber = get_theme_icon(SNAME("grabber"), SNAME("HSplitContainer")); + Ref<Texture2D> v_grabber = get_theme_icon(SNAME("grabber"), SNAME("VSplitContainer")); - Ref<Texture2D> hdiag_grabber = get_theme_icon(SNAME("GuiViewportHdiagsplitter"), SNAME("EditorIcons")); - Ref<Texture2D> vdiag_grabber = get_theme_icon(SNAME("GuiViewportVdiagsplitter"), SNAME("EditorIcons")); - Ref<Texture2D> vh_grabber = get_theme_icon(SNAME("GuiViewportVhsplitter"), SNAME("EditorIcons")); + Ref<Texture2D> hdiag_grabber = get_theme_icon(SNAME("GuiViewportHdiagsplitter"), SNAME("EditorIcons")); + Ref<Texture2D> vdiag_grabber = get_theme_icon(SNAME("GuiViewportVdiagsplitter"), SNAME("EditorIcons")); + Ref<Texture2D> vh_grabber = get_theme_icon(SNAME("GuiViewportVhsplitter"), SNAME("EditorIcons")); - Vector2 size = get_size(); + Vector2 size = get_size(); - int h_sep = get_theme_constant(SNAME("separation"), SNAME("HSplitContainer")); + int h_sep = get_theme_constant(SNAME("separation"), SNAME("HSplitContainer")); - int v_sep = get_theme_constant(SNAME("separation"), SNAME("VSplitContainer")); + int v_sep = get_theme_constant(SNAME("separation"), SNAME("VSplitContainer")); - int mid_w = size.width * ratio_h; - int mid_h = size.height * ratio_v; + int mid_w = size.width * ratio_h; + int mid_h = size.height * ratio_v; - int size_left = mid_w - h_sep / 2; - int size_bottom = size.height - mid_h - v_sep / 2; + int size_left = mid_w - h_sep / 2; + int size_bottom = size.height - mid_h - v_sep / 2; - switch (view) { - case VIEW_USE_1_VIEWPORT: { - // Nothing to show. + switch (view) { + case VIEW_USE_1_VIEWPORT: { + // Nothing to show. - } break; - case VIEW_USE_2_VIEWPORTS: { - draw_texture(v_grabber, Vector2((size.width - v_grabber->get_width()) / 2, mid_h - v_grabber->get_height() / 2)); - set_default_cursor_shape(CURSOR_VSPLIT); + } break; + case VIEW_USE_2_VIEWPORTS: { + draw_texture(v_grabber, Vector2((size.width - v_grabber->get_width()) / 2, mid_h - v_grabber->get_height() / 2)); + set_default_cursor_shape(CURSOR_VSPLIT); - } break; - case VIEW_USE_2_VIEWPORTS_ALT: { - draw_texture(h_grabber, Vector2(mid_w - h_grabber->get_width() / 2, (size.height - h_grabber->get_height()) / 2)); - set_default_cursor_shape(CURSOR_HSPLIT); + } break; + case VIEW_USE_2_VIEWPORTS_ALT: { + draw_texture(h_grabber, Vector2(mid_w - h_grabber->get_width() / 2, (size.height - h_grabber->get_height()) / 2)); + set_default_cursor_shape(CURSOR_HSPLIT); - } break; - case VIEW_USE_3_VIEWPORTS: { - if ((hovering_v && hovering_h && !dragging_v && !dragging_h) || (dragging_v && dragging_h)) { - draw_texture(hdiag_grabber, Vector2(mid_w - hdiag_grabber->get_width() / 2, mid_h - v_grabber->get_height() / 4)); - set_default_cursor_shape(CURSOR_DRAG); - } else if ((hovering_v && !dragging_h) || dragging_v) { - draw_texture(v_grabber, Vector2((size.width - v_grabber->get_width()) / 2, mid_h - v_grabber->get_height() / 2)); - set_default_cursor_shape(CURSOR_VSPLIT); - } else if (hovering_h || dragging_h) { - draw_texture(h_grabber, Vector2(mid_w - h_grabber->get_width() / 2, mid_h + v_grabber->get_height() / 2 + (size_bottom - h_grabber->get_height()) / 2)); - set_default_cursor_shape(CURSOR_HSPLIT); - } + } break; + case VIEW_USE_3_VIEWPORTS: { + if ((hovering_v && hovering_h && !dragging_v && !dragging_h) || (dragging_v && dragging_h)) { + draw_texture(hdiag_grabber, Vector2(mid_w - hdiag_grabber->get_width() / 2, mid_h - v_grabber->get_height() / 4)); + set_default_cursor_shape(CURSOR_DRAG); + } else if ((hovering_v && !dragging_h) || dragging_v) { + draw_texture(v_grabber, Vector2((size.width - v_grabber->get_width()) / 2, mid_h - v_grabber->get_height() / 2)); + set_default_cursor_shape(CURSOR_VSPLIT); + } else if (hovering_h || dragging_h) { + draw_texture(h_grabber, Vector2(mid_w - h_grabber->get_width() / 2, mid_h + v_grabber->get_height() / 2 + (size_bottom - h_grabber->get_height()) / 2)); + set_default_cursor_shape(CURSOR_HSPLIT); + } - } break; - case VIEW_USE_3_VIEWPORTS_ALT: { - if ((hovering_v && hovering_h && !dragging_v && !dragging_h) || (dragging_v && dragging_h)) { - draw_texture(vdiag_grabber, Vector2(mid_w - vdiag_grabber->get_width() + v_grabber->get_height() / 4, mid_h - vdiag_grabber->get_height() / 2)); - set_default_cursor_shape(CURSOR_DRAG); - } else if ((hovering_v && !dragging_h) || dragging_v) { - draw_texture(v_grabber, Vector2((size_left - v_grabber->get_width()) / 2, mid_h - v_grabber->get_height() / 2)); - set_default_cursor_shape(CURSOR_VSPLIT); - } else if (hovering_h || dragging_h) { - draw_texture(h_grabber, Vector2(mid_w - h_grabber->get_width() / 2, (size.height - h_grabber->get_height()) / 2)); - set_default_cursor_shape(CURSOR_HSPLIT); - } + } break; + case VIEW_USE_3_VIEWPORTS_ALT: { + if ((hovering_v && hovering_h && !dragging_v && !dragging_h) || (dragging_v && dragging_h)) { + draw_texture(vdiag_grabber, Vector2(mid_w - vdiag_grabber->get_width() + v_grabber->get_height() / 4, mid_h - vdiag_grabber->get_height() / 2)); + set_default_cursor_shape(CURSOR_DRAG); + } else if ((hovering_v && !dragging_h) || dragging_v) { + draw_texture(v_grabber, Vector2((size_left - v_grabber->get_width()) / 2, mid_h - v_grabber->get_height() / 2)); + set_default_cursor_shape(CURSOR_VSPLIT); + } else if (hovering_h || dragging_h) { + draw_texture(h_grabber, Vector2(mid_w - h_grabber->get_width() / 2, (size.height - h_grabber->get_height()) / 2)); + set_default_cursor_shape(CURSOR_HSPLIT); + } - } break; - case VIEW_USE_4_VIEWPORTS: { - Vector2 half(mid_w, mid_h); - if ((hovering_v && hovering_h && !dragging_v && !dragging_h) || (dragging_v && dragging_h)) { - draw_texture(vh_grabber, half - vh_grabber->get_size() / 2.0); - set_default_cursor_shape(CURSOR_DRAG); - } else if ((hovering_v && !dragging_h) || dragging_v) { - draw_texture(v_grabber, half - v_grabber->get_size() / 2.0); - set_default_cursor_shape(CURSOR_VSPLIT); - } else if (hovering_h || dragging_h) { - draw_texture(h_grabber, half - h_grabber->get_size() / 2.0); - set_default_cursor_shape(CURSOR_HSPLIT); - } + } break; + case VIEW_USE_4_VIEWPORTS: { + Vector2 half(mid_w, mid_h); + if ((hovering_v && hovering_h && !dragging_v && !dragging_h) || (dragging_v && dragging_h)) { + draw_texture(vh_grabber, half - vh_grabber->get_size() / 2.0); + set_default_cursor_shape(CURSOR_DRAG); + } else if ((hovering_v && !dragging_h) || dragging_v) { + draw_texture(v_grabber, half - v_grabber->get_size() / 2.0); + set_default_cursor_shape(CURSOR_VSPLIT); + } else if (hovering_h || dragging_h) { + draw_texture(h_grabber, half - h_grabber->get_size() / 2.0); + set_default_cursor_shape(CURSOR_HSPLIT); + } - } break; - } - } + } break; + } + } + } break; - if (p_what == NOTIFICATION_SORT_CHILDREN) { - Node3DEditorViewport *viewports[4]; - int vc = 0; - for (int i = 0; i < get_child_count(); i++) { - viewports[vc] = Object::cast_to<Node3DEditorViewport>(get_child(i)); - if (viewports[vc]) { - vc++; + case NOTIFICATION_SORT_CHILDREN: { + Node3DEditorViewport *viewports[4]; + int vc = 0; + for (int i = 0; i < get_child_count(); i++) { + viewports[vc] = Object::cast_to<Node3DEditorViewport>(get_child(i)); + if (viewports[vc]) { + vc++; + } } - } - ERR_FAIL_COND(vc != 4); + ERR_FAIL_COND(vc != 4); - Size2 size = get_size(); + Size2 size = get_size(); - if (size.x < 10 || size.y < 10) { - for (int i = 0; i < 4; i++) { - viewports[i]->hide(); + if (size.x < 10 || size.y < 10) { + for (int i = 0; i < 4; i++) { + viewports[i]->hide(); + } + return; } - return; - } - int h_sep = get_theme_constant(SNAME("separation"), SNAME("HSplitContainer")); + int h_sep = get_theme_constant(SNAME("separation"), SNAME("HSplitContainer")); - int v_sep = get_theme_constant(SNAME("separation"), SNAME("VSplitContainer")); + int v_sep = get_theme_constant(SNAME("separation"), SNAME("VSplitContainer")); - int mid_w = size.width * ratio_h; - int mid_h = size.height * ratio_v; + int mid_w = size.width * ratio_h; + int mid_h = size.height * ratio_v; - int size_left = mid_w - h_sep / 2; - int size_right = size.width - mid_w - h_sep / 2; + int size_left = mid_w - h_sep / 2; + int size_right = size.width - mid_w - h_sep / 2; - int size_top = mid_h - v_sep / 2; - int size_bottom = size.height - mid_h - v_sep / 2; + int size_top = mid_h - v_sep / 2; + int size_bottom = size.height - mid_h - v_sep / 2; - switch (view) { - case VIEW_USE_1_VIEWPORT: { - viewports[0]->show(); - for (int i = 1; i < 4; i++) { - viewports[i]->hide(); - } + switch (view) { + case VIEW_USE_1_VIEWPORT: { + viewports[0]->show(); + for (int i = 1; i < 4; i++) { + viewports[i]->hide(); + } - fit_child_in_rect(viewports[0], Rect2(Vector2(), size)); + fit_child_in_rect(viewports[0], Rect2(Vector2(), size)); - } break; - case VIEW_USE_2_VIEWPORTS: { - for (int i = 0; i < 4; i++) { - if (i == 1 || i == 3) { - viewports[i]->hide(); - } else { - viewports[i]->show(); + } break; + case VIEW_USE_2_VIEWPORTS: { + for (int i = 0; i < 4; i++) { + if (i == 1 || i == 3) { + viewports[i]->hide(); + } else { + viewports[i]->show(); + } } - } - fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size.width, size_top))); - fit_child_in_rect(viewports[2], Rect2(Vector2(0, mid_h + v_sep / 2), Vector2(size.width, size_bottom))); + fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size.width, size_top))); + fit_child_in_rect(viewports[2], Rect2(Vector2(0, mid_h + v_sep / 2), Vector2(size.width, size_bottom))); - } break; - case VIEW_USE_2_VIEWPORTS_ALT: { - for (int i = 0; i < 4; i++) { - if (i == 1 || i == 3) { - viewports[i]->hide(); - } else { - viewports[i]->show(); + } break; + case VIEW_USE_2_VIEWPORTS_ALT: { + for (int i = 0; i < 4; i++) { + if (i == 1 || i == 3) { + viewports[i]->hide(); + } else { + viewports[i]->show(); + } } - } - fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size_left, size.height))); - fit_child_in_rect(viewports[2], Rect2(Vector2(mid_w + h_sep / 2, 0), Vector2(size_right, size.height))); + fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size_left, size.height))); + fit_child_in_rect(viewports[2], Rect2(Vector2(mid_w + h_sep / 2, 0), Vector2(size_right, size.height))); - } break; - case VIEW_USE_3_VIEWPORTS: { - for (int i = 0; i < 4; i++) { - if (i == 1) { - viewports[i]->hide(); - } else { - viewports[i]->show(); + } break; + case VIEW_USE_3_VIEWPORTS: { + for (int i = 0; i < 4; i++) { + if (i == 1) { + viewports[i]->hide(); + } else { + viewports[i]->show(); + } } - } - fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size.width, size_top))); - fit_child_in_rect(viewports[2], Rect2(Vector2(0, mid_h + v_sep / 2), Vector2(size_left, size_bottom))); - fit_child_in_rect(viewports[3], Rect2(Vector2(mid_w + h_sep / 2, mid_h + v_sep / 2), Vector2(size_right, size_bottom))); + fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size.width, size_top))); + fit_child_in_rect(viewports[2], Rect2(Vector2(0, mid_h + v_sep / 2), Vector2(size_left, size_bottom))); + fit_child_in_rect(viewports[3], Rect2(Vector2(mid_w + h_sep / 2, mid_h + v_sep / 2), Vector2(size_right, size_bottom))); - } break; - case VIEW_USE_3_VIEWPORTS_ALT: { - for (int i = 0; i < 4; i++) { - if (i == 1) { - viewports[i]->hide(); - } else { - viewports[i]->show(); + } break; + case VIEW_USE_3_VIEWPORTS_ALT: { + for (int i = 0; i < 4; i++) { + if (i == 1) { + viewports[i]->hide(); + } else { + viewports[i]->show(); + } } - } - fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size_left, size_top))); - fit_child_in_rect(viewports[2], Rect2(Vector2(0, mid_h + v_sep / 2), Vector2(size_left, size_bottom))); - fit_child_in_rect(viewports[3], Rect2(Vector2(mid_w + h_sep / 2, 0), Vector2(size_right, size.height))); + fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size_left, size_top))); + fit_child_in_rect(viewports[2], Rect2(Vector2(0, mid_h + v_sep / 2), Vector2(size_left, size_bottom))); + fit_child_in_rect(viewports[3], Rect2(Vector2(mid_w + h_sep / 2, 0), Vector2(size_right, size.height))); - } break; - case VIEW_USE_4_VIEWPORTS: { - for (int i = 0; i < 4; i++) { - viewports[i]->show(); - } + } break; + case VIEW_USE_4_VIEWPORTS: { + for (int i = 0; i < 4; i++) { + viewports[i]->show(); + } - fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size_left, size_top))); - fit_child_in_rect(viewports[1], Rect2(Vector2(mid_w + h_sep / 2, 0), Vector2(size_right, size_top))); - fit_child_in_rect(viewports[2], Rect2(Vector2(0, mid_h + v_sep / 2), Vector2(size_left, size_bottom))); - fit_child_in_rect(viewports[3], Rect2(Vector2(mid_w + h_sep / 2, mid_h + v_sep / 2), Vector2(size_right, size_bottom))); + fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size_left, size_top))); + fit_child_in_rect(viewports[1], Rect2(Vector2(mid_w + h_sep / 2, 0), Vector2(size_right, size_top))); + fit_child_in_rect(viewports[2], Rect2(Vector2(0, mid_h + v_sep / 2), Vector2(size_left, size_bottom))); + fit_child_in_rect(viewports[3], Rect2(Vector2(mid_w + h_sep / 2, mid_h + v_sep / 2), Vector2(size_right, size_bottom))); - } break; - } + } break; + } + } break; } } @@ -6951,6 +6962,7 @@ void Node3DEditor::_notification(int p_what) { sun_state->set_custom_minimum_size(sun_vb->get_combined_minimum_size()); environ_state->set_custom_minimum_size(environ_vb->get_combined_minimum_size()); } break; + case NOTIFICATION_ENTER_TREE: { _update_theme(); _register_all_gizmos(); @@ -6958,9 +6970,11 @@ void Node3DEditor::_notification(int p_what) { _init_indicators(); update_all_gizmos(); } break; + case NOTIFICATION_EXIT_TREE: { _finish_indicators(); } break; + case NOTIFICATION_THEME_CHANGED: { _update_theme(); _update_gizmos_menu_theme(); @@ -6968,11 +6982,13 @@ void Node3DEditor::_notification(int p_what) { sun_title->add_theme_font_override("font", get_theme_font(SNAME("title_font"), SNAME("Window"))); environ_title->add_theme_font_override("font", get_theme_font(SNAME("title_font"), SNAME("Window"))); } break; + case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { // Update grid color by rebuilding grid. _finish_grid(); _init_grid(); } break; + case NOTIFICATION_VISIBILITY_CHANGED: { if (!is_visible() && tool_option_button[TOOL_OPT_OVERRIDE_CAMERA]->is_pressed()) { EditorDebuggerNode *debugger = EditorDebuggerNode::get_singleton(); diff --git a/editor/plugins/ot_features_plugin.cpp b/editor/plugins/ot_features_plugin.cpp index 719b9ecc7c..f8e6054848 100644 --- a/editor/plugins/ot_features_plugin.cpp +++ b/editor/plugins/ot_features_plugin.cpp @@ -46,12 +46,15 @@ void OpenTypeFeaturesEditor::update_property() { } void OpenTypeFeaturesEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { - Color base = get_theme_color(SNAME("accent_color"), SNAME("Editor")); - - button->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"))); - button->set_size(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"))->get_size()); - spin->set_custom_label_color(true, base); + switch (p_what) { + case NOTIFICATION_ENTER_TREE: + case NOTIFICATION_THEME_CHANGED: { + Color base = get_theme_color(SNAME("accent_color"), SNAME("Editor")); + + button->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"))); + button->set_size(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"))->get_size()); + spin->set_custom_label_color(true, base); + } break; } } @@ -139,10 +142,13 @@ void OpenTypeFeaturesAdd::_features_menu() { } void OpenTypeFeaturesAdd::_notification(int p_what) { - if (p_what == NOTIFICATION_THEME_CHANGED || p_what == NOTIFICATION_ENTER_TREE) { - set_label(""); - button->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))); - button->set_size(get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))->get_size()); + switch (p_what) { + case NOTIFICATION_THEME_CHANGED: + case NOTIFICATION_ENTER_TREE: { + set_label(""); + button->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))); + button->set_size(get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))->get_size()); + } break; } } diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp index 22b79921bb..62987dfe0f 100644 --- a/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/editor/plugins/polygon_2d_editor_plugin.cpp @@ -69,6 +69,7 @@ void Polygon2DEditor::_notification(int p_what) { case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { uv_panner->setup((ViewPanner::ControlScheme)EDITOR_GET("editors/panning/sub_editors_panning_scheme").operator int(), ED_GET_SHORTCUT("canvas_item_editor/pan_view"), bool(EditorSettings::get_singleton()->get("editors/panning/simple_panning"))); } break; + case NOTIFICATION_READY: { button_uv->set_icon(get_theme_icon(SNAME("Uv"), SNAME("EditorIcons"))); @@ -96,6 +97,7 @@ void Polygon2DEditor::_notification(int p_what) { uv_edit_draw->add_theme_style_override("panel", get_theme_stylebox(SNAME("bg"), SNAME("Tree"))); bone_scroll->add_theme_style_override("bg", get_theme_stylebox(SNAME("bg"), SNAME("Tree"))); } break; + case NOTIFICATION_VISIBILITY_CHANGED: { if (!is_visible()) { uv_edit->hide(); diff --git a/editor/plugins/polygon_3d_editor_plugin.cpp b/editor/plugins/polygon_3d_editor_plugin.cpp index 6cba3e2861..2d4812c55b 100644 --- a/editor/plugins/polygon_3d_editor_plugin.cpp +++ b/editor/plugins/polygon_3d_editor_plugin.cpp @@ -50,6 +50,7 @@ void Polygon3DEditor::_notification(int p_what) { get_tree()->connect("node_removed", callable_mp(this, &Polygon3DEditor::_node_removed)); } break; + case NOTIFICATION_PROCESS: { if (!node) { return; diff --git a/editor/plugins/replication_editor_plugin.cpp b/editor/plugins/replication_editor_plugin.cpp index 604cbcd103..e4c1c69804 100644 --- a/editor/plugins/replication_editor_plugin.cpp +++ b/editor/plugins/replication_editor_plugin.cpp @@ -94,10 +94,15 @@ void ReplicationEditor::_bind_methods() { } void ReplicationEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE || p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { - add_theme_style_override("panel", EditorNode::get_singleton()->get_gui_base()->get_theme_stylebox(SNAME("panel"), SNAME("Panel"))); - } else if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { - update_keying(); + switch (p_what) { + case NOTIFICATION_ENTER_TREE: + case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { + add_theme_style_override("panel", EditorNode::get_singleton()->get_gui_base()->get_theme_stylebox(SNAME("panel"), SNAME("Panel"))); + } break; + + case NOTIFICATION_VISIBILITY_CHANGED: { + update_keying(); + } break; } } @@ -355,13 +360,15 @@ void ReplicationEditorPlugin::_property_keyed(const String &p_keyed, const Varia } void ReplicationEditorPlugin::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { - //Node3DEditor::get_singleton()->connect("transform_key_request", callable_mp(this, &AnimationPlayerEditorPlugin::_transform_key_request)); - InspectorDock::get_inspector_singleton()->connect("property_keyed", callable_mp(this, &ReplicationEditorPlugin::_property_keyed)); - repl_editor->connect("keying_changed", callable_mp(this, &ReplicationEditorPlugin::_keying_changed)); - // TODO make lock usable. - //InspectorDock::get_inspector_singleton()->connect("object_inspected", callable_mp(repl_editor, &ReplicationEditor::update_keying)); - get_tree()->connect("node_removed", callable_mp(this, &ReplicationEditorPlugin::_node_removed)); + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + //Node3DEditor::get_singleton()->connect("transform_key_request", callable_mp(this, &AnimationPlayerEditorPlugin::_transform_key_request)); + InspectorDock::get_inspector_singleton()->connect("property_keyed", callable_mp(this, &ReplicationEditorPlugin::_property_keyed)); + repl_editor->connect("keying_changed", callable_mp(this, &ReplicationEditorPlugin::_keying_changed)); + // TODO make lock usable. + //InspectorDock::get_inspector_singleton()->connect("object_inspected", callable_mp(repl_editor, &ReplicationEditor::update_keying)); + get_tree()->connect("node_removed", callable_mp(this, &ReplicationEditorPlugin::_node_removed)); + } break; } } diff --git a/editor/plugins/resource_preloader_editor_plugin.cpp b/editor/plugins/resource_preloader_editor_plugin.cpp index e04e3c146f..b7aef7f1bb 100644 --- a/editor/plugins/resource_preloader_editor_plugin.cpp +++ b/editor/plugins/resource_preloader_editor_plugin.cpp @@ -38,15 +38,10 @@ #include "editor/editor_settings.h" void ResourcePreloaderEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { - load->set_icon(get_theme_icon(SNAME("Folder"), SNAME("EditorIcons"))); - } - - if (p_what == NOTIFICATION_READY) { - //NodePath("/root")->connect("node_removed", this,"_node_removed",Vector<Variant>(),true); - } - - if (p_what == NOTIFICATION_DRAW) { + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + load->set_icon(get_theme_icon(SNAME("Folder"), SNAME("EditorIcons"))); + } break; } } diff --git a/editor/plugins/root_motion_editor_plugin.cpp b/editor/plugins/root_motion_editor_plugin.cpp index 34b39d2a17..bfb672d694 100644 --- a/editor/plugins/root_motion_editor_plugin.cpp +++ b/editor/plugins/root_motion_editor_plugin.cpp @@ -233,9 +233,12 @@ void EditorPropertyRootMotion::setup(const NodePath &p_base_hint) { } void EditorPropertyRootMotion::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { - Ref<Texture2D> t = get_theme_icon(SNAME("Clear"), SNAME("EditorIcons")); - clear->set_icon(t); + switch (p_what) { + case NOTIFICATION_ENTER_TREE: + case NOTIFICATION_THEME_CHANGED: { + Ref<Texture2D> t = get_theme_icon(SNAME("Clear"), SNAME("EditorIcons")); + clear->set_icon(t); + } break; } } diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 315879d4ac..205464daee 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -356,6 +356,7 @@ void ScriptEditorQuickOpen::_notification(int p_what) { case NOTIFICATION_VISIBILITY_CHANGED: { search_box->set_right_icon(search_options->get_theme_icon(SNAME("Search"), SNAME("EditorIcons"))); } break; + case NOTIFICATION_EXIT_TREE: { disconnect("confirmed", callable_mp(this, &ScriptEditorQuickOpen::_confirmed)); } break; @@ -1667,9 +1668,6 @@ void ScriptEditor::_notification(int p_what) { } } break; - - default: - break; } } diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 4a47766fc0..b87f2995ed 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -1343,8 +1343,6 @@ void ScriptTextEditor::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { code_editor->get_text_editor()->set_gutter_width(connection_gutter, code_editor->get_text_editor()->get_line_height()); } break; - default: - break; } } |