diff options
Diffstat (limited to 'editor/plugins')
114 files changed, 2136 insertions, 3802 deletions
diff --git a/editor/plugins/abstract_polygon_2d_editor.cpp b/editor/plugins/abstract_polygon_2d_editor.cpp index beb3d760c0..1abba45f9e 100644 --- a/editor/plugins/abstract_polygon_2d_editor.cpp +++ b/editor/plugins/abstract_polygon_2d_editor.cpp @@ -35,99 +35,84 @@ #include "editor/editor_scale.h" bool AbstractPolygon2DEditor::Vertex::operator==(const AbstractPolygon2DEditor::Vertex &p_vertex) const { - return polygon == p_vertex.polygon && vertex == p_vertex.vertex; } bool AbstractPolygon2DEditor::Vertex::operator!=(const AbstractPolygon2DEditor::Vertex &p_vertex) const { - return !(*this == p_vertex); } bool AbstractPolygon2DEditor::Vertex::valid() const { - return vertex >= 0; } bool AbstractPolygon2DEditor::_is_empty() const { - - if (!_get_node()) + if (!_get_node()) { return true; + } const int n = _get_polygon_count(); for (int i = 0; i < n; i++) { - Vector<Vector2> vertices = _get_polygon(i); - if (vertices.size() != 0) + if (vertices.size() != 0) { return false; + } } return true; } bool AbstractPolygon2DEditor::_is_line() const { - return false; } bool AbstractPolygon2DEditor::_has_uv() const { - return false; } int AbstractPolygon2DEditor::_get_polygon_count() const { - return 1; } Variant AbstractPolygon2DEditor::_get_polygon(int p_idx) const { - return _get_node()->get("polygon"); } void AbstractPolygon2DEditor::_set_polygon(int p_idx, const Variant &p_polygon) const { - _get_node()->set("polygon", p_polygon); } void AbstractPolygon2DEditor::_action_set_polygon(int p_idx, const Variant &p_previous, const Variant &p_polygon) { - Node2D *node = _get_node(); undo_redo->add_do_method(node, "set_polygon", p_polygon); undo_redo->add_undo_method(node, "set_polygon", p_previous); } Vector2 AbstractPolygon2DEditor::_get_offset(int p_idx) const { - return Vector2(0, 0); } void AbstractPolygon2DEditor::_commit_action() { - undo_redo->add_do_method(canvas_item_editor, "update_viewport"); undo_redo->add_undo_method(canvas_item_editor, "update_viewport"); undo_redo->commit_action(); } void AbstractPolygon2DEditor::_action_add_polygon(const Variant &p_polygon) { - _action_set_polygon(0, p_polygon); } void AbstractPolygon2DEditor::_action_remove_polygon(int p_idx) { - _action_set_polygon(p_idx, _get_polygon(p_idx), Vector<Vector2>()); } void AbstractPolygon2DEditor::_action_set_polygon(int p_idx, const Variant &p_polygon) { - _action_set_polygon(p_idx, _get_polygon(p_idx), p_polygon); } bool AbstractPolygon2DEditor::_has_resource() const { - return true; } @@ -135,18 +120,14 @@ void AbstractPolygon2DEditor::_create_resource() { } void AbstractPolygon2DEditor::_menu_option(int p_option) { - switch (p_option) { - case MODE_CREATE: { - mode = MODE_CREATE; button_create->set_pressed(true); button_edit->set_pressed(false); button_delete->set_pressed(false); } break; case MODE_EDIT: { - _wip_close(); mode = MODE_EDIT; button_create->set_pressed(false); @@ -154,7 +135,6 @@ void AbstractPolygon2DEditor::_menu_option(int p_option) { button_delete->set_pressed(false); } break; case MODE_DELETE: { - _wip_close(); mode = MODE_DELETE; button_create->set_pressed(false); @@ -165,11 +145,8 @@ void AbstractPolygon2DEditor::_menu_option(int p_option) { } void AbstractPolygon2DEditor::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_READY: { - disable_polygon_editing(false, String()); button_create->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon("CurveCreate", "EditorIcons")); @@ -184,7 +161,6 @@ void AbstractPolygon2DEditor::_notification(int p_what) { } void AbstractPolygon2DEditor::_node_removed(Node *p_node) { - if (p_node == _get_node()) { edit(nullptr); hide(); @@ -194,14 +170,12 @@ void AbstractPolygon2DEditor::_node_removed(Node *p_node) { } void AbstractPolygon2DEditor::_wip_changed() { - if (wip_active && _is_line()) { _set_polygon(0, wip); } } void AbstractPolygon2DEditor::_wip_cancel() { - wip.clear(); wip_active = false; @@ -213,14 +187,13 @@ void AbstractPolygon2DEditor::_wip_cancel() { } void AbstractPolygon2DEditor::_wip_close() { - if (!wip_active) + if (!wip_active) { return; + } if (_is_line()) { - _set_polygon(0, wip); } else if (wip.size() >= (_is_line() ? 2 : 3)) { - undo_redo->create_action(TTR("Create Polygon")); _action_add_polygon(wip); if (_has_uv()) { @@ -229,7 +202,6 @@ void AbstractPolygon2DEditor::_wip_close() { } _commit_action(); } else { - return; } @@ -247,7 +219,6 @@ void AbstractPolygon2DEditor::_wip_close() { } void AbstractPolygon2DEditor::disable_polygon_editing(bool p_disable, String p_reason) { - _polygon_editing_enabled = !p_disable; button_create->set_disabled(p_disable); @@ -255,12 +226,10 @@ void AbstractPolygon2DEditor::disable_polygon_editing(bool p_disable, String p_r button_delete->set_disabled(p_disable); if (p_disable) { - button_create->set_tooltip(p_reason); button_edit->set_tooltip(p_reason); button_delete->set_tooltip(p_reason); } else { - button_create->set_tooltip(TTR("Create points.")); button_edit->set_tooltip(TTR("Edit points.\nLMB: Move Point\nRMB: Erase Point")); button_delete->set_tooltip(TTR("Erase points.")); @@ -268,14 +237,13 @@ void AbstractPolygon2DEditor::disable_polygon_editing(bool p_disable, String p_r } bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { - - if (!_get_node() || !_polygon_editing_enabled) + if (!_get_node() || !_polygon_editing_enabled) { return false; + } Ref<InputEventMouseButton> mb = p_event; if (!_has_resource()) { - if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed()) { create_resource->set_text(String("No polygon resource on this node.\nCreate and assign one?")); create_resource->popup_centered(); @@ -284,11 +252,11 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) } CanvasItemEditor::Tool tool = CanvasItemEditor::get_singleton()->get_current_tool(); - if (tool != CanvasItemEditor::TOOL_SELECT) + if (tool != CanvasItemEditor::TOOL_SELECT) { return false; + } if (mb.is_valid()) { - Transform2D xform = canvas_item_editor->get_canvas_transform() * _get_node()->get_global_transform(); Vector2 gpoint = mb->get_position(); @@ -297,17 +265,16 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) if (mode == MODE_EDIT || (_is_line() && mode == MODE_CREATE)) { if (mb->get_button_index() == BUTTON_LEFT) { if (mb->is_pressed()) { - if (mb->get_control() || mb->get_shift() || mb->get_alt()) + if (mb->get_control() || mb->get_shift() || mb->get_alt()) { return false; + } const PosVertex insert = closest_edge_point(gpoint); if (insert.valid()) { - Vector<Vector2> vertices = _get_polygon(insert.polygon); if (vertices.size() < (_is_line() ? 2 : 3)) { - vertices.push_back(cpoint); undo_redo->create_action(TTR("Edit Polygon")); selected_point = Vertex(insert.polygon, vertices.size()); @@ -315,7 +282,6 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) _commit_action(); return true; } else { - Vector<Vector2> vertices2 = _get_polygon(insert.polygon); pre_move_edit = vertices2; edited_point = PosVertex(insert.polygon, insert.vertex + 1, xform.affine_inverse().xform(insert.pos)); @@ -329,12 +295,10 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) return true; } } else { - //look for points to move const PosVertex closest = closest_point(gpoint); if (closest.valid()) { - pre_move_edit = _get_polygon(closest.polygon); edited_point = PosVertex(closest, xform.affine_inverse().xform(closest.pos)); selected_point = closest; @@ -342,14 +306,11 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) canvas_item_editor->update_viewport(); return true; } else { - selected_point = Vertex(); } } } else { - if (edited_point.valid()) { - //apply Vector<Vector2> vertices = _get_polygon(edited_point.polygon); @@ -365,23 +326,18 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) } } } else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed() && !edited_point.valid()) { - const PosVertex closest = closest_point(gpoint); if (closest.valid()) { - remove_point(closest); return true; } } } else if (mode == MODE_DELETE) { - if (mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) { - const PosVertex closest = closest_point(gpoint); if (closest.valid()) { - remove_point(closest); return true; } @@ -389,11 +345,8 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) } if (mode == MODE_CREATE) { - if (mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) { - if (_is_line()) { - // for lines, we don't have a wip mode, and we can undo each single add point. Vector<Vector2> vertices = _get_polygon(0); vertices.push_back(cpoint); @@ -402,7 +355,6 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) _commit_action(); return true; } else if (!wip_active) { - wip.clear(); wip.push_back(cpoint); wip_active = true; @@ -414,7 +366,6 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) edge_point = PosVertex(); return true; } else { - const real_t grab_threshold = EDITOR_GET("editors/poly_editor/point_grab_radius"); if (!_is_line() && wip.size() > 1 && xform.xform(wip[0]).distance_to(gpoint) < grab_threshold) { @@ -423,7 +374,6 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) return true; } else { - //add wip point wip.push_back(cpoint); _wip_changed(); @@ -442,11 +392,9 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) Ref<InputEventMouseMotion> mm = p_event; if (mm.is_valid()) { - Vector2 gpoint = mm->get_position(); if (edited_point.valid() && (wip_active || (mm->get_button_mask() & BUTTON_MASK_LEFT))) { - Vector2 cpoint = _get_node()->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint))); //Move the point in a single axis. Should only work when editing a polygon and while holding shift. @@ -462,7 +410,6 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) edited_point = PosVertex(edited_point, cpoint); if (!wip_active) { - Vector<Vector2> vertices = _get_polygon(edited_point.polygon); ERR_FAIL_INDEX_V(edited_point.vertex, vertices.size(), false); vertices.write[edited_point.vertex] = cpoint - _get_offset(edited_point.polygon); @@ -471,25 +418,20 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) canvas_item_editor->update_viewport(); } else if (mode == MODE_EDIT || (_is_line() && mode == MODE_CREATE)) { - const PosVertex onEdgeVertex = closest_edge_point(gpoint); if (onEdgeVertex.valid()) { - hover_point = Vertex(); edge_point = onEdgeVertex; canvas_item_editor->update_viewport(); } else { - if (edge_point.valid()) { - edge_point = PosVertex(); canvas_item_editor->update_viewport(); } const PosVertex new_hover_point = closest_point(gpoint); if (hover_point != new_hover_point) { - hover_point = new_hover_point; canvas_item_editor->update_viewport(); } @@ -500,13 +442,9 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) Ref<InputEventKey> k = p_event; if (k.is_valid() && k->is_pressed()) { - if (k->get_keycode() == KEY_DELETE || k->get_keycode() == KEY_BACKSPACE) { - if (wip_active && selected_point.polygon == -1) { - if (wip.size() > selected_point.vertex) { - wip.remove(selected_point.vertex); _wip_changed(); selected_point = wip.size() - 1; @@ -514,17 +452,14 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) return true; } } else { - const Vertex active_point = get_active_point(); if (active_point.valid()) { - remove_point(active_point); return true; } } } else if (wip_active && k->get_keycode() == KEY_ENTER) { - _wip_close(); } else if (wip_active && k->get_keycode() == KEY_ESCAPE) { _wip_cancel(); @@ -535,9 +470,9 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) } void AbstractPolygon2DEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { - - if (!_get_node()) + if (!_get_node()) { return; + } Transform2D xform = canvas_item_editor->get_canvas_transform() * _get_node()->get_global_transform(); // All polygon points are sharp, so use the sharp handle icon @@ -548,31 +483,28 @@ void AbstractPolygon2DEditor::forward_canvas_draw_over_viewport(Control *p_overl const bool is_closed = !_is_line(); for (int j = -1; j < n_polygons; j++) { - - if (wip_active && wip_destructive && j != -1) + if (wip_active && wip_destructive && j != -1) { continue; + } Vector<Vector2> points; Vector2 offset; if (wip_active && j == edited_point.polygon) { - points = Variant(wip); offset = Vector2(0, 0); } else { - - if (j == -1) + if (j == -1) { continue; + } points = _get_polygon(j); offset = _get_offset(j); } if (!wip_active && j == edited_point.polygon && EDITOR_GET("editors/poly_editor/show_previous_outline")) { - const Color col = Color(0.5, 0.5, 0.5); // FIXME polygon->get_outline_color(); const int n = pre_move_edit.size(); for (int i = 0; i < n - (is_closed ? 0 : 1); i++) { - Vector2 p, p2; p = pre_move_edit[i] + offset; p2 = pre_move_edit[(i + 1) % n] + offset; @@ -588,20 +520,19 @@ void AbstractPolygon2DEditor::forward_canvas_draw_over_viewport(Control *p_overl const Color col = Color(1, 0.3, 0.1, 0.8); for (int i = 0; i < n_points; i++) { - const Vertex vertex(j, i); const Vector2 p = (vertex == edited_point) ? edited_point.pos : (points[i] + offset); const Vector2 point = xform.xform(p); if (is_closed || i < n_points - 1) { - Vector2 p2; if (j == edited_point.polygon && - ((wip_active && i == n_points - 1) || (((i + 1) % n_points) == edited_point.vertex))) + ((wip_active && i == n_points - 1) || (((i + 1) % n_points) == edited_point.vertex))) { p2 = edited_point.pos; - else + } else { p2 = points[(i + 1) % n_points] + offset; + } const Vector2 next_point = xform.xform(p2); p_overlay->draw_line(point, next_point, col, Math::round(2 * EDSCALE)); @@ -609,7 +540,6 @@ void AbstractPolygon2DEditor::forward_canvas_draw_over_viewport(Control *p_overl } for (int i = 0; i < n_points; i++) { - const Vertex vertex(j, i); const Vector2 p = (vertex == edited_point) ? edited_point.pos : (points[i] + offset); @@ -628,26 +558,25 @@ void AbstractPolygon2DEditor::forward_canvas_draw_over_viewport(Control *p_overl } if (edge_point.valid()) { - Ref<Texture2D> add_handle = get_theme_icon("EditorHandleAdd", "EditorIcons"); p_overlay->draw_texture(add_handle, edge_point.pos - add_handle->get_size() * 0.5); } } void AbstractPolygon2DEditor::edit(Node *p_polygon) { - - if (!canvas_item_editor) + if (!canvas_item_editor) { canvas_item_editor = CanvasItemEditor::get_singleton(); + } if (p_polygon) { - _set_node(p_polygon); // Enable the pencil tool if the polygon is empty. - if (_is_empty()) + if (_is_empty()) { _menu_option(MODE_CREATE); - else + } else { _menu_option(MODE_EDIT); + } wip.clear(); wip_active = false; @@ -657,7 +586,6 @@ void AbstractPolygon2DEditor::edit(Node *p_polygon) { canvas_item_editor->update_viewport(); } else { - _set_node(nullptr); } } @@ -666,38 +594,35 @@ void AbstractPolygon2DEditor::_bind_methods() { } void AbstractPolygon2DEditor::remove_point(const Vertex &p_vertex) { - Vector<Vector2> vertices = _get_polygon(p_vertex.polygon); if (vertices.size() > (_is_line() ? 2 : 3)) { - vertices.remove(p_vertex.vertex); undo_redo->create_action(TTR("Edit Polygon (Remove Point)")); _action_set_polygon(p_vertex.polygon, vertices); _commit_action(); } else { - undo_redo->create_action(TTR("Remove Polygon And Point")); _action_remove_polygon(p_vertex.polygon); _commit_action(); } - if (_is_empty()) + if (_is_empty()) { _menu_option(MODE_CREATE); + } hover_point = Vertex(); - if (selected_point == p_vertex) + if (selected_point == p_vertex) { selected_point = Vertex(); + } } AbstractPolygon2DEditor::Vertex AbstractPolygon2DEditor::get_active_point() const { - return hover_point.valid() ? hover_point : selected_point; } AbstractPolygon2DEditor::PosVertex AbstractPolygon2DEditor::closest_point(const Vector2 &p_pos) const { - const real_t grab_threshold = EDITOR_GET("editors/poly_editor/point_grab_radius"); const int n_polygons = _get_polygon_count(); @@ -707,13 +632,11 @@ AbstractPolygon2DEditor::PosVertex AbstractPolygon2DEditor::closest_point(const real_t closest_dist = 1e10; for (int j = 0; j < n_polygons; j++) { - Vector<Vector2> points = _get_polygon(j); const Vector2 offset = _get_offset(j); const int n_points = points.size(); for (int i = 0; i < n_points; i++) { - Vector2 cp = xform.xform(points[i] + offset); real_t d = cp.distance_to(p_pos); @@ -728,7 +651,6 @@ AbstractPolygon2DEditor::PosVertex AbstractPolygon2DEditor::closest_point(const } AbstractPolygon2DEditor::PosVertex AbstractPolygon2DEditor::closest_edge_point(const Vector2 &p_pos) const { - const real_t grab_threshold = EDITOR_GET("editors/poly_editor/point_grab_radius"); const real_t eps = grab_threshold * 2; const real_t eps2 = eps * eps; @@ -740,21 +662,20 @@ AbstractPolygon2DEditor::PosVertex AbstractPolygon2DEditor::closest_edge_point(c real_t closest_dist = 1e10; for (int j = 0; j < n_polygons; j++) { - Vector<Vector2> points = _get_polygon(j); const Vector2 offset = _get_offset(j); const int n_points = points.size(); const int n_segments = n_points - (_is_line() ? 1 : 0); for (int i = 0; i < n_segments; i++) { - Vector2 segment[2] = { xform.xform(points[i] + offset), xform.xform(points[(i + 1) % n_points] + offset) }; Vector2 cp = Geometry::get_closest_point_to_segment_2d(p_pos, segment); - if (cp.distance_squared_to(segment[0]) < eps2 || cp.distance_squared_to(segment[1]) < eps2) + if (cp.distance_squared_to(segment[0]) < eps2 || cp.distance_squared_to(segment[1]) < eps2) { continue; //not valid to reuse point + } real_t d = cp.distance_to(p_pos); if (d < closest_dist && d < grab_threshold) { @@ -768,7 +689,6 @@ AbstractPolygon2DEditor::PosVertex AbstractPolygon2DEditor::closest_edge_point(c } AbstractPolygon2DEditor::AbstractPolygon2DEditor(EditorNode *p_editor, bool p_wip_destructive) { - canvas_item_editor = nullptr; editor = p_editor; undo_redo = EditorNode::get_undo_redo(); @@ -805,22 +725,17 @@ AbstractPolygon2DEditor::AbstractPolygon2DEditor(EditorNode *p_editor, bool p_wi } void AbstractPolygon2DEditorPlugin::edit(Object *p_object) { - polygon_editor->edit(Object::cast_to<Node>(p_object)); } bool AbstractPolygon2DEditorPlugin::handles(Object *p_object) const { - return p_object->is_class(klass); } void AbstractPolygon2DEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { - polygon_editor->show(); } else { - polygon_editor->hide(); polygon_editor->edit(nullptr); } diff --git a/editor/plugins/abstract_polygon_2d_editor.h b/editor/plugins/abstract_polygon_2d_editor.h index 7d4a3a0f98..d5b3a916d1 100644 --- a/editor/plugins/abstract_polygon_2d_editor.h +++ b/editor/plugins/abstract_polygon_2d_editor.h @@ -39,7 +39,6 @@ class CanvasItemEditor; class AbstractPolygon2DEditor : public HBoxContainer { - GDCLASS(AbstractPolygon2DEditor, HBoxContainer); ToolButton *button_create; @@ -151,7 +150,6 @@ public: }; class AbstractPolygon2DEditorPlugin : public EditorPlugin { - GDCLASS(AbstractPolygon2DEditorPlugin, EditorPlugin); AbstractPolygon2DEditor *polygon_editor; diff --git a/editor/plugins/animation_blend_space_1d_editor.cpp b/editor/plugins/animation_blend_space_1d_editor.cpp index eb50df2166..75eacf56ec 100644 --- a/editor/plugins/animation_blend_space_1d_editor.cpp +++ b/editor/plugins/animation_blend_space_1d_editor.cpp @@ -81,8 +81,9 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_gui_input(const Ref<InputEven for (List<StringName>::Element *E = classes.front(); E; E = E->next()) { String name = String(E->get()).replace_first("AnimationNode", ""); - if (name == "Animation") + if (name == "Animation") { continue; + } int idx = menu->get_item_count(); menu->add_item(vformat("Add %s", name), idx); @@ -117,7 +118,6 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_gui_input(const Ref<InputEven _update_tool_erase(); for (int i = 0; i < points.size(); i++) { - if (Math::abs(float(points[i] - mb->get_position().x)) < 10 * EDSCALE) { selected_point = i; @@ -196,7 +196,6 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_gui_input(const Ref<InputEven } void AnimationNodeBlendSpace1DEditor::_blend_space_draw() { - Color linecolor = get_theme_color("font_color", "Label"); Color linecolor_soft = linecolor; linecolor_soft.a *= 0.5; @@ -227,7 +226,6 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_draw() { } if (snap->is_pressed()) { - linecolor_soft.a = linecolor.a * 0.1; if (blend_space->get_snap() > 0) { @@ -303,9 +301,9 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_draw() { } void AnimationNodeBlendSpace1DEditor::_update_space() { - - if (updating) + if (updating) { return; + } updating = true; @@ -322,8 +320,9 @@ void AnimationNodeBlendSpace1DEditor::_update_space() { } void AnimationNodeBlendSpace1DEditor::_config_changed(double) { - if (updating) + if (updating) { return; + } updating = true; undo_redo->create_action(TTR("Change BlendSpace1D Limits")); @@ -342,8 +341,9 @@ void AnimationNodeBlendSpace1DEditor::_config_changed(double) { } void AnimationNodeBlendSpace1DEditor::_labels_changed(String) { - if (updating) + if (updating) { return; + } updating = true; undo_redo->create_action(TTR("Change BlendSpace1D Labels"), UndoRedo::MERGE_ENDS); @@ -360,7 +360,6 @@ void AnimationNodeBlendSpace1DEditor::_snap_toggled() { } void AnimationNodeBlendSpace1DEditor::_file_opened(const String &p_file) { - file_loaded = ResourceLoader::load(p_file); if (file_loaded.is_valid()) { _add_menu_type(MENU_LOAD_FILE_CONFIRM); @@ -370,7 +369,6 @@ void AnimationNodeBlendSpace1DEditor::_file_opened(const String &p_file) { void AnimationNodeBlendSpace1DEditor::_add_menu_type(int p_index) { Ref<AnimationRootNode> node; if (p_index == MENU_LOAD_FILE) { - open_file->clear_filters(); List<String> filters; ResourceLoader::get_recognized_extensions_for_type("AnimationRootNode", &filters); @@ -383,7 +381,6 @@ void AnimationNodeBlendSpace1DEditor::_add_menu_type(int p_index) { node = file_loaded; file_loaded.unref(); } else if (p_index == MENU_PASTE) { - node = EditorSettings::get_singleton()->get_resource_clipboard(); } else { String type = menu->get_item_metadata(p_index); @@ -432,7 +429,6 @@ void AnimationNodeBlendSpace1DEditor::_add_animation_type(int p_index) { } void AnimationNodeBlendSpace1DEditor::_tool_switch(int p_tool) { - if (p_tool == 0) { tool_erase->show(); tool_erase_sep->show(); @@ -446,8 +442,9 @@ void AnimationNodeBlendSpace1DEditor::_tool_switch(int p_tool) { } void AnimationNodeBlendSpace1DEditor::_update_edited_point_pos() { - if (updating) + if (updating) { return; + } if (selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) { float pos = blend_space->get_blend_point_position(selected_point); @@ -467,7 +464,6 @@ void AnimationNodeBlendSpace1DEditor::_update_edited_point_pos() { } void AnimationNodeBlendSpace1DEditor::_update_tool_erase() { - bool point_valid = selected_point >= 0 && selected_point < blend_space->get_blend_point_count(); tool_erase->set_disabled(!point_valid); @@ -504,8 +500,9 @@ void AnimationNodeBlendSpace1DEditor::_erase_selected() { } void AnimationNodeBlendSpace1DEditor::_edit_point_pos(double) { - if (updating) + if (updating) { return; + } updating = true; undo_redo->create_action(TTR("Move BlendSpace1D Node Point")); @@ -522,7 +519,6 @@ void AnimationNodeBlendSpace1DEditor::_edit_point_pos(double) { } void AnimationNodeBlendSpace1DEditor::_open_editor() { - if (selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) { Ref<AnimationNode> an = blend_space->get_blend_point_node(selected_point); ERR_FAIL_COND(an.is_null()); @@ -575,13 +571,11 @@ void AnimationNodeBlendSpace1DEditor::_bind_methods() { } bool AnimationNodeBlendSpace1DEditor::can_edit(const Ref<AnimationNode> &p_node) { - Ref<AnimationNodeBlendSpace1D> b1d = p_node; return b1d.is_valid(); } void AnimationNodeBlendSpace1DEditor::edit(const Ref<AnimationNode> &p_node) { - blend_space = p_node; if (!blend_space.is_null()) { diff --git a/editor/plugins/animation_blend_space_1d_editor.h b/editor/plugins/animation_blend_space_1d_editor.h index 346ad36cff..8cfd6714ad 100644 --- a/editor/plugins/animation_blend_space_1d_editor.h +++ b/editor/plugins/animation_blend_space_1d_editor.h @@ -42,7 +42,6 @@ #include "scene/gui/tree.h" class AnimationNodeBlendSpace1DEditor : public AnimationTreeNodeEditorPlugin { - GDCLASS(AnimationNodeBlendSpace1DEditor, AnimationTreeNodeEditorPlugin); Ref<AnimationNodeBlendSpace1D> blend_space; diff --git a/editor/plugins/animation_blend_space_2d_editor.cpp b/editor/plugins/animation_blend_space_2d_editor.cpp index 4ea84e716b..df67482dfb 100644 --- a/editor/plugins/animation_blend_space_2d_editor.cpp +++ b/editor/plugins/animation_blend_space_2d_editor.cpp @@ -43,7 +43,6 @@ #include "scene/main/window.h" bool AnimationNodeBlendSpace2DEditor::can_edit(const Ref<AnimationNode> &p_node) { - Ref<AnimationNodeBlendSpace2D> bs2d = p_node; return bs2d.is_valid(); } @@ -53,7 +52,6 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_changed() { } void AnimationNodeBlendSpace2DEditor::edit(const Ref<AnimationNode> &p_node) { - if (blend_space.is_valid()) { blend_space->disconnect("triangles_updated", callable_mp(this, &AnimationNodeBlendSpace2DEditor::_blend_space_changed)); } @@ -71,7 +69,6 @@ StringName AnimationNodeBlendSpace2DEditor::get_blend_position_path() const { } void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEvent> &p_event) { - Ref<InputEventKey> k = p_event; if (tool_select->is_pressed() && k.is_valid() && k->is_pressed() && k->get_keycode() == KEY_DELETE && !k->is_echo()) { if (selected_point != -1 || selected_triangle != -1) { @@ -107,10 +104,10 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven } for (List<StringName>::Element *E = classes.front(); E; E = E->next()) { - String name = String(E->get()).replace_first("AnimationNode", ""); - if (name == "Animation") + if (name == "Animation") { continue; // nope + } int idx = menu->get_item_count(); menu->add_item(vformat("Add %s", name), idx); menu->set_item_metadata(idx, E->get()); @@ -138,7 +135,6 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven } if (mb.is_valid() && mb->is_pressed() && tool_select->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { - blend_space_draw->update(); //update anyway //try to see if a point can be selected selected_point = -1; @@ -146,7 +142,6 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven _update_tool_erase(); for (int i = 0; i < points.size(); i++) { - if (points[i].distance_to(mb->get_position()) < 10 * EDSCALE) { selected_point = i; Ref<AnimationNode> node = blend_space->get_blend_point_node(i); @@ -180,15 +175,14 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven } if (mb.is_valid() && mb->is_pressed() && tool_triangle->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { - blend_space_draw->update(); //update anyway //try to see if a point can be selected selected_point = -1; for (int i = 0; i < points.size(); i++) { - - if (making_triangle.find(i) != -1) + if (making_triangle.find(i) != -1) { continue; + } if (points[i].distance_to(mb->get_position()) < 10 * EDSCALE) { making_triangle.push_back(i); @@ -243,7 +237,6 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven } if (mb.is_valid() && mb->is_pressed() && tool_blend->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { - Vector2 blend_pos = (mb->get_position() / blend_space_draw->get_size()); blend_pos.y = 1.0 - blend_pos.y; blend_pos *= (blend_space->get_max_space() - blend_space->get_min_space()); @@ -278,7 +271,6 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven } if (mm.is_valid() && tool_blend->is_pressed() && mm->get_button_mask() & BUTTON_MASK_LEFT) { - Vector2 blend_pos = (mm->get_position() / blend_space_draw->get_size()); blend_pos.y = 1.0 - blend_pos.y; blend_pos *= (blend_space->get_max_space() - blend_space->get_min_space()); @@ -291,7 +283,6 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven } void AnimationNodeBlendSpace2DEditor::_file_opened(const String &p_file) { - file_loaded = ResourceLoader::load(p_file); if (file_loaded.is_valid()) { _add_menu_type(MENU_LOAD_FILE_CONFIRM); @@ -299,10 +290,8 @@ void AnimationNodeBlendSpace2DEditor::_file_opened(const String &p_file) { } void AnimationNodeBlendSpace2DEditor::_add_menu_type(int p_index) { - Ref<AnimationRootNode> node; if (p_index == MENU_LOAD_FILE) { - open_file->clear_filters(); List<String> filters; ResourceLoader::get_recognized_extensions_for_type("AnimationRootNode", &filters); @@ -315,7 +304,6 @@ void AnimationNodeBlendSpace2DEditor::_add_menu_type(int p_index) { node = file_loaded; file_loaded.unref(); } else if (p_index == MENU_PASTE) { - node = EditorSettings::get_singleton()->get_resource_clipboard(); } else { String type = menu->get_item_metadata(p_index); @@ -346,7 +334,6 @@ void AnimationNodeBlendSpace2DEditor::_add_menu_type(int p_index) { } void AnimationNodeBlendSpace2DEditor::_add_animation_type(int p_index) { - Ref<AnimationNodeAnimation> anim; anim.instance(); @@ -405,7 +392,6 @@ void AnimationNodeBlendSpace2DEditor::_tool_switch(int p_tool) { } void AnimationNodeBlendSpace2DEditor::_blend_space_draw() { - Color linecolor = get_theme_color("font_color", "Label"); Color linecolor_soft = linecolor; linecolor_soft.a *= 0.5; @@ -438,14 +424,11 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_draw() { } if (snap->is_pressed()) { - linecolor_soft.a = linecolor.a * 0.1; if (blend_space->get_snap().x > 0) { - int prev_idx = 0; for (int i = 0; i < s.x; i++) { - float v = blend_space->get_min_space().x + i * (blend_space->get_max_space().x - blend_space->get_min_space().x) / s.x; int idx = int(v / blend_space->get_snap().x); @@ -458,10 +441,8 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_draw() { } if (blend_space->get_snap().y > 0) { - int prev_idx = 0; for (int i = 0; i < s.y; i++) { - float v = blend_space->get_max_space().y - i * (blend_space->get_max_space().y - blend_space->get_min_space().y) / s.y; int idx = int(v / blend_space->get_snap().y); @@ -476,7 +457,6 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_draw() { //triangles first for (int i = 0; i < blend_space->get_triangle_count(); i++) { - Vector<Vector2> points; points.resize(3); @@ -518,7 +498,6 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_draw() { points.clear(); for (int i = 0; i < blend_space->get_blend_point_count(); i++) { - Vector2 point = blend_space->get_blend_point_position(i); if (dragging_selected && selected_point == i) { point += drag_ofs; @@ -597,14 +576,13 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_draw() { } void AnimationNodeBlendSpace2DEditor::_snap_toggled() { - blend_space_draw->update(); } void AnimationNodeBlendSpace2DEditor::_update_space() { - - if (updating) + if (updating) { return; + } updating = true; @@ -636,8 +614,9 @@ void AnimationNodeBlendSpace2DEditor::_update_space() { } void AnimationNodeBlendSpace2DEditor::_config_changed(double) { - if (updating) + if (updating) { return; + } updating = true; undo_redo->create_action(TTR("Change BlendSpace2D Limits")); @@ -658,8 +637,9 @@ void AnimationNodeBlendSpace2DEditor::_config_changed(double) { } void AnimationNodeBlendSpace2DEditor::_labels_changed(String) { - if (updating) + if (updating) { return; + } updating = true; undo_redo->create_action(TTR("Change BlendSpace2D Labels"), UndoRedo::MERGE_ENDS); @@ -674,9 +654,7 @@ void AnimationNodeBlendSpace2DEditor::_labels_changed(String) { } void AnimationNodeBlendSpace2DEditor::_erase_selected() { - if (selected_point != -1) { - updating = true; undo_redo->create_action(TTR("Remove BlendSpace2D Point")); undo_redo->add_do_method(blend_space.ptr(), "remove_blend_point", selected_point); @@ -699,7 +677,6 @@ void AnimationNodeBlendSpace2DEditor::_erase_selected() { blend_space_draw->update(); } else if (selected_triangle != -1) { - updating = true; undo_redo->create_action(TTR("Remove BlendSpace2D Triangle")); undo_redo->add_do_method(blend_space.ptr(), "remove_triangle", selected_triangle); @@ -715,8 +692,9 @@ void AnimationNodeBlendSpace2DEditor::_erase_selected() { } void AnimationNodeBlendSpace2DEditor::_update_edited_point_pos() { - if (updating) + if (updating) { return; + } if (selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) { Vector2 pos = blend_space->get_blend_point_position(selected_point); @@ -735,8 +713,9 @@ void AnimationNodeBlendSpace2DEditor::_update_edited_point_pos() { } void AnimationNodeBlendSpace2DEditor::_edit_point_pos(double) { - if (updating) + if (updating) { return; + } updating = true; undo_redo->create_action(TTR("Move Node Point")); undo_redo->add_do_method(blend_space.ptr(), "set_blend_point_position", selected_point, Vector2(edit_x->get_value(), edit_y->get_value())); @@ -752,7 +731,6 @@ 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("bg", "Tree")); error_label->add_theme_color_override("font_color", get_theme_color("error_color", "Editor")); @@ -772,7 +750,6 @@ void AnimationNodeBlendSpace2DEditor::_notification(int p_what) { } if (p_what == NOTIFICATION_PROCESS) { - String error; if (!AnimationTreeEditor::get_singleton()->get_tree()) { @@ -801,7 +778,6 @@ void AnimationNodeBlendSpace2DEditor::_notification(int p_what) { } void AnimationNodeBlendSpace2DEditor::_open_editor() { - if (selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) { Ref<AnimationNode> an = blend_space->get_blend_point_node(selected_point); ERR_FAIL_COND(an.is_null()); @@ -814,7 +790,6 @@ void AnimationNodeBlendSpace2DEditor::_removed_from_graph() { } void AnimationNodeBlendSpace2DEditor::_auto_triangles_toggled() { - undo_redo->create_action(TTR("Toggle Auto Triangles")); undo_redo->add_do_method(blend_space.ptr(), "set_auto_triangles", auto_triangles->is_pressed()); undo_redo->add_undo_method(blend_space.ptr(), "set_auto_triangles", blend_space->get_auto_triangles()); @@ -824,7 +799,6 @@ void AnimationNodeBlendSpace2DEditor::_auto_triangles_toggled() { } void AnimationNodeBlendSpace2DEditor::_bind_methods() { - ClassDB::bind_method("_update_space", &AnimationNodeBlendSpace2DEditor::_update_space); ClassDB::bind_method("_update_tool_erase", &AnimationNodeBlendSpace2DEditor::_update_tool_erase); @@ -836,7 +810,6 @@ void AnimationNodeBlendSpace2DEditor::_bind_methods() { AnimationNodeBlendSpace2DEditor *AnimationNodeBlendSpace2DEditor::singleton = nullptr; AnimationNodeBlendSpace2DEditor::AnimationNodeBlendSpace2DEditor() { - singleton = this; updating = false; diff --git a/editor/plugins/animation_blend_space_2d_editor.h b/editor/plugins/animation_blend_space_2d_editor.h index 50b0d9a06c..b430a12297 100644 --- a/editor/plugins/animation_blend_space_2d_editor.h +++ b/editor/plugins/animation_blend_space_2d_editor.h @@ -42,7 +42,6 @@ #include "scene/gui/tree.h" class AnimationNodeBlendSpace2DEditor : public AnimationTreeNodeEditorPlugin { - GDCLASS(AnimationNodeBlendSpace2DEditor, AnimationTreeNodeEditorPlugin); Ref<AnimationNodeBlendSpace2D> blend_space; diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp index 23e547f55d..82d942821f 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.cpp +++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp @@ -43,7 +43,6 @@ #include "scene/main/window.h" void AnimationNodeBlendTreeEditor::add_custom_type(const String &p_name, const Ref<Script> &p_script) { - for (int i = 0; i < add_options.size(); i++) { ERR_FAIL_COND(add_options[i].script == p_script); } @@ -57,7 +56,6 @@ void AnimationNodeBlendTreeEditor::add_custom_type(const String &p_name, const R } void AnimationNodeBlendTreeEditor::remove_custom_type(const Ref<Script> &p_script) { - for (int i = 0; i < add_options.size(); i++) { if (add_options[i].script == p_script) { add_options.remove(i); @@ -69,7 +67,6 @@ void AnimationNodeBlendTreeEditor::remove_custom_type(const Ref<Script> &p_scrip } void AnimationNodeBlendTreeEditor::_update_options_menu() { - add_node->get_popup()->clear(); for (int i = 0; i < add_options.size(); i++) { add_node->get_popup()->add_item(add_options[i].name, i); @@ -86,12 +83,10 @@ void AnimationNodeBlendTreeEditor::_update_options_menu() { } Size2 AnimationNodeBlendTreeEditor::get_minimum_size() const { - return Size2(10, 200); } void AnimationNodeBlendTreeEditor::_property_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing) { - AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_tree(); updating = true; undo_redo->create_action(TTR("Parameter Changed") + ": " + String(p_property), UndoRedo::MERGE_ENDS); @@ -104,9 +99,9 @@ void AnimationNodeBlendTreeEditor::_property_changed(const StringName &p_propert } void AnimationNodeBlendTreeEditor::_update_graph() { - - if (updating) + if (updating) { return; + } visible_properties.clear(); @@ -115,7 +110,6 @@ void AnimationNodeBlendTreeEditor::_update_graph() { graph->clear_connections(); //erase all nodes for (int i = 0; i < graph->get_child_count(); i++) { - if (Object::cast_to<GraphNode>(graph->get_child(i))) { memdelete(graph->get_child(i)); i--; @@ -128,7 +122,6 @@ void AnimationNodeBlendTreeEditor::_update_graph() { blend_tree->get_node_list(&nodes); for (List<StringName>::Element *E = nodes.front(); E; E = E->next()) { - GraphNode *node = memnew(GraphNode); graph->add_child(node); @@ -163,7 +156,6 @@ void AnimationNodeBlendTreeEditor::_update_graph() { List<PropertyInfo> pinfo; agnode->get_parameter_list(&pinfo); for (List<PropertyInfo>::Element *F = pinfo.front(); F; F = F->next()) { - if (!(F->get().usage & PROPERTY_USAGE_EDITOR)) { continue; } @@ -192,7 +184,6 @@ void AnimationNodeBlendTreeEditor::_update_graph() { } if (agnode->has_filter()) { - node->add_child(memnew(HSeparator)); Button *edit_filters = memnew(Button); edit_filters->set_text(TTR("Edit Filters")); @@ -204,7 +195,6 @@ void AnimationNodeBlendTreeEditor::_update_graph() { Ref<AnimationNodeAnimation> anim = agnode; if (anim.is_valid()) { - MenuButton *mb = memnew(MenuButton); mb->set_text(anim->get_animation()); mb->set_icon(get_theme_icon("Animation", "EditorIcons")); @@ -259,7 +249,6 @@ void AnimationNodeBlendTreeEditor::_update_graph() { blend_tree->get_node_connections(&connections); for (List<AnimationNodeBlendTree::NodeConnection>::Element *E = connections.front(); E; E = E->next()) { - StringName from = E->get().output_node; StringName to = E->get().input_node; int to_idx = E->get().input_index; @@ -269,7 +258,6 @@ void AnimationNodeBlendTreeEditor::_update_graph() { } void AnimationNodeBlendTreeEditor::_file_opened(const String &p_file) { - file_loaded = ResourceLoader::load(p_file); if (file_loaded.is_valid()) { _add_node(MENU_LOAD_FILE_CONFIRM); @@ -277,13 +265,11 @@ void AnimationNodeBlendTreeEditor::_file_opened(const String &p_file) { } void AnimationNodeBlendTreeEditor::_add_node(int p_idx) { - Ref<AnimationNode> anode; String base_name; if (p_idx == MENU_LOAD_FILE) { - open_file->clear_filters(); List<String> filters; ResourceLoader::get_recognized_extensions_for_type("AnimationNode", &filters); @@ -297,7 +283,6 @@ void AnimationNodeBlendTreeEditor::_add_node(int p_idx) { file_loaded.unref(); base_name = anode->get_class(); } else if (p_idx == MENU_PASTE) { - anode = EditorSettings::get_singleton()->get_resource_clipboard(); ERR_FAIL_COND(!anode.is_valid()); base_name = anode->get_class(); @@ -347,7 +332,6 @@ void AnimationNodeBlendTreeEditor::_add_node(int p_idx) { } void AnimationNodeBlendTreeEditor::_node_dragged(const Vector2 &p_from, const Vector2 &p_to, const StringName &p_which) { - updating = true; undo_redo->create_action(TTR("Node Moved")); undo_redo->add_do_method(blend_tree.ptr(), "set_node_position", p_which, p_to / EDSCALE); @@ -359,7 +343,6 @@ void AnimationNodeBlendTreeEditor::_node_dragged(const Vector2 &p_from, const Ve } void AnimationNodeBlendTreeEditor::_connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index) { - AnimationNodeBlendTree::ConnectionError err = blend_tree->can_connect_node(p_to, p_to_index, p_from); if (err != AnimationNodeBlendTree::CONNECTION_OK) { @@ -376,7 +359,6 @@ void AnimationNodeBlendTreeEditor::_connection_request(const String &p_from, int } void AnimationNodeBlendTreeEditor::_disconnection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index) { - graph->disconnect_node(p_from, p_from_index, p_to, p_to_index); updating = true; @@ -390,7 +372,6 @@ void AnimationNodeBlendTreeEditor::_disconnection_request(const String &p_from, } void AnimationNodeBlendTreeEditor::_anim_selected(int p_index, Array p_options, const String &p_node) { - String option = p_options[p_index]; Ref<AnimationNodeAnimation> anim = blend_tree->get_node(p_node); @@ -405,7 +386,6 @@ void AnimationNodeBlendTreeEditor::_anim_selected(int p_index, Array p_options, } void AnimationNodeBlendTreeEditor::_delete_request(const String &p_which) { - undo_redo->create_action(TTR("Delete Node")); undo_redo->add_do_method(blend_tree.ptr(), "remove_node", p_which); undo_redo->add_undo_method(blend_tree.ptr(), "add_node", p_which, blend_tree->get_node(p_which), blend_tree.ptr()->get_node_position(p_which)); @@ -425,7 +405,6 @@ void AnimationNodeBlendTreeEditor::_delete_request(const String &p_which) { } void AnimationNodeBlendTreeEditor::_delete_nodes_request() { - List<StringName> to_erase; for (int i = 0; i < graph->get_child_count(); i++) { @@ -437,8 +416,9 @@ void AnimationNodeBlendTreeEditor::_delete_nodes_request() { } } - if (to_erase.empty()) + if (to_erase.empty()) { return; + } undo_redo->create_action(TTR("Delete Node(s)")); @@ -450,7 +430,6 @@ void AnimationNodeBlendTreeEditor::_delete_nodes_request() { } void AnimationNodeBlendTreeEditor::_popup_request(const Vector2 &p_position) { - _update_options_menu(); use_popup_menu_position = true; popup_menu_position = graph->get_local_mouse_position(); @@ -459,7 +438,6 @@ void AnimationNodeBlendTreeEditor::_popup_request(const Vector2 &p_position) { } void AnimationNodeBlendTreeEditor::_node_selected(Object *p_node) { - GraphNode *gn = Object::cast_to<GraphNode>(p_node); ERR_FAIL_COND(!gn); @@ -472,14 +450,12 @@ void AnimationNodeBlendTreeEditor::_node_selected(Object *p_node) { } void AnimationNodeBlendTreeEditor::_open_in_editor(const String &p_which) { - Ref<AnimationNode> an = blend_tree->get_node(p_which); ERR_FAIL_COND(!an.is_valid()); AnimationTreeEditor::get_singleton()->enter_editor(p_which); } void AnimationNodeBlendTreeEditor::_filter_toggled() { - updating = true; undo_redo->create_action(TTR("Toggle Filter On/Off")); undo_redo->add_do_method(_filter_edit.ptr(), "set_filter_enabled", filter_enabled->is_pressed()); @@ -491,7 +467,6 @@ void AnimationNodeBlendTreeEditor::_filter_toggled() { } void AnimationNodeBlendTreeEditor::_filter_edited() { - TreeItem *edited = filters->get_edited(); ERR_FAIL_COND(!edited); @@ -509,9 +484,9 @@ void AnimationNodeBlendTreeEditor::_filter_edited() { } bool AnimationNodeBlendTreeEditor::_update_filters(const Ref<AnimationNode> &anode) { - - if (updating || _filter_edit != anode) + if (updating || _filter_edit != anode) { return false; + } NodePath player_path = AnimationTreeEditor::get_singleton()->get_tree()->get_animation_player(); @@ -542,7 +517,6 @@ bool AnimationNodeBlendTreeEditor::_update_filters(const Ref<AnimationNode> &ano player->get_animation_list(&animations); for (List<StringName>::Element *E = animations.front(); E; E = E->next()) { - Ref<Animation> anim = player->get_animation(E->get()); for (int i = 0; i < anim->get_track_count(); i++) { String track_path = anim->track_get_path(i); @@ -577,7 +551,6 @@ bool AnimationNodeBlendTreeEditor::_update_filters(const Ref<AnimationNode> &ano Map<String, TreeItem *> parenthood; for (Set<String>::Element *E = paths.front(); E; E = E->next()) { - NodePath path = E->get(); TreeItem *ti = nullptr; String accum; @@ -612,11 +585,11 @@ bool AnimationNodeBlendTreeEditor::_update_filters(const Ref<AnimationNode> &ano if (base->has_node(accum)) { node = base->get_node(accum); } - if (!node) + if (!node) { continue; //no node, can't edit + } if (path.get_subname_count()) { - String concat = path.get_concatenated_subnames(); Skeleton3D *skeleton = Object::cast_to<Skeleton3D>(node); @@ -697,13 +670,13 @@ bool AnimationNodeBlendTreeEditor::_update_filters(const Ref<AnimationNode> &ano } void AnimationNodeBlendTreeEditor::_edit_filters(const String &p_which) { - Ref<AnimationNode> anode = blend_tree->get_node(p_which); ERR_FAIL_COND(!anode.is_valid()); _filter_edit = anode; - if (!_update_filters(anode)) + if (!_update_filters(anode)) { return; + } filter_dialog->popup_centered(Size2(500, 500) * EDSCALE); } @@ -715,18 +688,16 @@ void AnimationNodeBlendTreeEditor::_removed_from_graph() { } void AnimationNodeBlendTreeEditor::_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("bg", "Tree")); error_label->add_theme_color_override("font_color", get_theme_color("error_color", "Editor")); - if (p_what == NOTIFICATION_THEME_CHANGED && is_visible_in_tree()) + if (p_what == NOTIFICATION_THEME_CHANGED && is_visible_in_tree()) { _update_graph(); + } } if (p_what == NOTIFICATION_PROCESS) { - String error; if (!AnimationTreeEditor::get_singleton()->get_tree()->is_active()) { @@ -789,15 +760,15 @@ void AnimationNodeBlendTreeEditor::_notification(int p_what) { } void AnimationNodeBlendTreeEditor::_scroll_changed(const Vector2 &p_scroll) { - if (updating) + if (updating) { return; + } updating = true; blend_tree->set_graph_offset(p_scroll / EDSCALE); updating = false; } void AnimationNodeBlendTreeEditor::_bind_methods() { - ClassDB::bind_method("_update_graph", &AnimationNodeBlendTreeEditor::_update_graph); ClassDB::bind_method("_update_filters", &AnimationNodeBlendTreeEditor::_update_filters); } @@ -805,7 +776,6 @@ void AnimationNodeBlendTreeEditor::_bind_methods() { AnimationNodeBlendTreeEditor *AnimationNodeBlendTreeEditor::singleton = nullptr; void AnimationNodeBlendTreeEditor::_node_renamed(const String &p_text, Ref<AnimationNode> p_node) { - String prev_name = blend_tree->get_node_name(p_node); ERR_FAIL_COND(prev_name == String()); GraphNode *gn = Object::cast_to<GraphNode>(graph->get_node(prev_name)); @@ -858,7 +828,6 @@ void AnimationNodeBlendTreeEditor::_node_renamed(const String &p_text, Ref<Anima blend_tree->get_node_connections(&connections); for (List<AnimationNodeBlendTree::NodeConnection>::Element *E = connections.front(); E; E = E->next()) { - StringName from = E->get().output_node; StringName to = E->get().input_node; int to_idx = E->get().input_index; @@ -888,7 +857,6 @@ bool AnimationNodeBlendTreeEditor::can_edit(const Ref<AnimationNode> &p_node) { } void AnimationNodeBlendTreeEditor::edit(const Ref<AnimationNode> &p_node) { - if (blend_tree.is_valid()) { blend_tree->disconnect("removed_from_graph", callable_mp(this, &AnimationNodeBlendTreeEditor::_removed_from_graph)); } @@ -905,7 +873,6 @@ void AnimationNodeBlendTreeEditor::edit(const Ref<AnimationNode> &p_node) { } AnimationNodeBlendTreeEditor::AnimationNodeBlendTreeEditor() { - singleton = this; updating = false; use_popup_menu_position = false; diff --git a/editor/plugins/animation_blend_tree_editor_plugin.h b/editor/plugins/animation_blend_tree_editor_plugin.h index 4f5badea9f..6bdb7e7909 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.h +++ b/editor/plugins/animation_blend_tree_editor_plugin.h @@ -44,7 +44,6 @@ class ProgressBar; class AnimationNodeBlendTreeEditor : public AnimationTreeNodeEditorPlugin { - GDCLASS(AnimationNodeBlendTreeEditor, AnimationTreeNodeEditorPlugin); Ref<AnimationNodeBlendTree> blend_tree; diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index 0a252cc0a3..1e0a9535e2 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -44,7 +44,6 @@ #include "servers/rendering_server.h" void AnimationPlayerEditor::_node_removed(Node *p_node) { - if (player && player == p_node) { player = nullptr; @@ -58,24 +57,21 @@ void AnimationPlayerEditor::_node_removed(Node *p_node) { } void AnimationPlayerEditor::_notification(int p_what) { - switch (p_what) { case NOTIFICATION_PROCESS: { - - if (!player) + if (!player) { return; + } updating = true; if (player->is_playing()) { - { String animname = player->get_assigned_animation(); if (player->has_animation(animname)) { Ref<Animation> anim = player->get_animation(animname); if (!anim.is_null()) { - frame->set_max(anim->get_length()); } } @@ -96,7 +92,6 @@ void AnimationPlayerEditor::_notification(int p_what) { updating = false; } break; case NOTIFICATION_ENTER_TREE: { - tool_anim->get_popup()->connect("id_pressed", callable_mp(this, &AnimationPlayerEditor::_animation_tool_menu)); onion_skinning->get_popup()->connect("id_pressed", callable_mp(this, &AnimationPlayerEditor::_onion_skinning_menu)); @@ -108,11 +103,9 @@ void AnimationPlayerEditor::_notification(int p_what) { add_theme_style_override("panel", editor->get_gui_base()->get_theme_stylebox("panel", "Panel")); } break; case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { - add_theme_style_override("panel", editor->get_gui_base()->get_theme_stylebox("panel", "Panel")); } break; case NOTIFICATION_THEME_CHANGED: { - autoplay->set_icon(get_theme_icon("AutoPlay", "EditorIcons")); play->set_icon(get_theme_icon("PlayStart", "EditorIcons")); @@ -147,9 +140,9 @@ void AnimationPlayerEditor::_notification(int p_what) { } void AnimationPlayerEditor::_autoplay_pressed() { - - if (updating) + if (updating) { return; + } if (animation->get_item_count() == 0) { return; } @@ -176,17 +169,15 @@ void AnimationPlayerEditor::_autoplay_pressed() { } void AnimationPlayerEditor::_play_pressed() { - String current; if (animation->get_selected() >= 0 && animation->get_selected() < animation->get_item_count()) { - current = animation->get_item_text(animation->get_selected()); } if (current != "") { - - if (current == player->get_assigned_animation()) + if (current == player->get_assigned_animation()) { player->stop(); //so it won't blend with itself + } player->play(current); } @@ -195,19 +186,15 @@ void AnimationPlayerEditor::_play_pressed() { } void AnimationPlayerEditor::_play_from_pressed() { - String current; if (animation->get_selected() >= 0 && animation->get_selected() < animation->get_item_count()) { - current = animation->get_item_text(animation->get_selected()); } if (current != "") { - float time = player->get_current_animation_position(); if (current == player->get_assigned_animation() && player->is_playing()) { - player->stop(); //so it won't blend with itself } @@ -220,17 +207,15 @@ void AnimationPlayerEditor::_play_from_pressed() { } void AnimationPlayerEditor::_play_bw_pressed() { - String current; if (animation->get_selected() >= 0 && animation->get_selected() < animation->get_item_count()) { - current = animation->get_item_text(animation->get_selected()); } if (current != "") { - - if (current == player->get_assigned_animation()) + if (current == player->get_assigned_animation()) { player->stop(); //so it won't blend with itself + } player->play(current, -1, -1, true); } @@ -239,18 +224,16 @@ void AnimationPlayerEditor::_play_bw_pressed() { } void AnimationPlayerEditor::_play_bw_from_pressed() { - String current; if (animation->get_selected() >= 0 && animation->get_selected() < animation->get_item_count()) { - current = animation->get_item_text(animation->get_selected()); } if (current != "") { - float time = player->get_current_animation_position(); - if (current == player->get_assigned_animation()) + if (current == player->get_assigned_animation()) { player->stop(); //so it won't blend with itself + } player->play(current, -1, -1, true); player->seek(time); @@ -259,8 +242,8 @@ void AnimationPlayerEditor::_play_bw_from_pressed() { //unstop stop->set_pressed(false); } -void AnimationPlayerEditor::_stop_pressed() { +void AnimationPlayerEditor::_stop_pressed() { if (!player) { return; } @@ -271,24 +254,21 @@ void AnimationPlayerEditor::_stop_pressed() { } void AnimationPlayerEditor::_animation_selected(int p_which) { - - if (updating) + if (updating) { return; + } // when selecting an animation, the idea is that the only interesting behavior // ui-wise is that it should play/blend the next one if currently playing String current; if (animation->get_selected() >= 0 && animation->get_selected() < animation->get_item_count()) { - current = animation->get_item_text(animation->get_selected()); } if (current != "") { - player->set_assigned_animation(current); Ref<Animation> anim = player->get_animation(current); { - track_editor->set_animation(anim); Node *root = player->get_node(player->get_root()); if (root) { @@ -310,7 +290,6 @@ void AnimationPlayerEditor::_animation_selected(int p_which) { } void AnimationPlayerEditor::_animation_new() { - renaming = false; name_title->set_text(TTR("New Animation Name:")); @@ -318,8 +297,9 @@ void AnimationPlayerEditor::_animation_new() { String base = TTR("New Anim"); while (true) { String attempt = base; - if (count > 1) + if (count > 1) { attempt += " (" + itos(count) + ")"; + } if (player->has_animation(attempt)) { count++; continue; @@ -333,10 +313,11 @@ void AnimationPlayerEditor::_animation_new() { name->select_all(); name->grab_focus(); } -void AnimationPlayerEditor::_animation_rename() { - if (animation->get_item_count() == 0) +void AnimationPlayerEditor::_animation_rename() { + if (animation->get_item_count() == 0) { return; + } int selected = animation->get_selected(); String selected_name = animation->get_item_text(selected); @@ -347,6 +328,7 @@ void AnimationPlayerEditor::_animation_rename() { name->select_all(); name->grab_focus(); } + void AnimationPlayerEditor::_animation_load() { ERR_FAIL_COND(!player); file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE); @@ -355,7 +337,6 @@ void AnimationPlayerEditor::_animation_load() { ResourceLoader::get_recognized_extensions_for_type("Animation", &extensions); for (List<String>::Element *E = extensions.front(); E; E = E->next()) { - file->add_filter("*." + E->get() + " ; " + E->get().to_upper()); } @@ -364,10 +345,10 @@ void AnimationPlayerEditor::_animation_load() { } void AnimationPlayerEditor::_animation_save_in_path(const Ref<Resource> &p_resource, const String &p_path) { - int flg = 0; - if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources")) + if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources")) { flg |= ResourceSaver::FLAG_COMPRESS; + } String path = ProjectSettings::get_singleton()->localize_path(p_path); Error err = ResourceSaver::save(path, p_resource, flg | ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS); @@ -382,7 +363,6 @@ void AnimationPlayerEditor::_animation_save_in_path(const Ref<Resource> &p_resou } void AnimationPlayerEditor::_animation_save(const Ref<Resource> &p_resource) { - if (p_resource->get_path().is_resource_file()) { _animation_save_in_path(p_resource, p_resource->get_path()); } else { @@ -391,14 +371,12 @@ void AnimationPlayerEditor::_animation_save(const Ref<Resource> &p_resource) { } void AnimationPlayerEditor::_animation_save_as(const Ref<Resource> &p_resource) { - file->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE); List<String> extensions; ResourceSaver::get_recognized_extensions(p_resource, &extensions); file->clear_filters(); for (int i = 0; i < extensions.size(); i++) { - file->add_filter("*." + extensions[i] + " ; " + extensions[i].to_upper()); } @@ -412,7 +390,6 @@ void AnimationPlayerEditor::_animation_save_as(const Ref<Resource> &p_resource) } } } else { - String existing; if (extensions.size()) { if (p_resource->get_name() != "") { @@ -429,9 +406,9 @@ void AnimationPlayerEditor::_animation_save_as(const Ref<Resource> &p_resource) } void AnimationPlayerEditor::_animation_remove() { - - if (animation->get_item_count() == 0) + if (animation->get_item_count() == 0) { return; + } String current = animation->get_item_text(animation->get_selected()); @@ -440,7 +417,6 @@ void AnimationPlayerEditor::_animation_remove() { } void AnimationPlayerEditor::_animation_remove_confirmed() { - String current = animation->get_item_text(animation->get_selected()); Ref<Animation> anim = player->get_animation(current); @@ -463,12 +439,9 @@ void AnimationPlayerEditor::_animation_remove_confirmed() { } void AnimationPlayerEditor::_select_anim_by_name(const String &p_anim) { - int idx = -1; for (int i = 0; i < animation->get_item_count(); i++) { - if (animation->get_item_text(i) == p_anim) { - idx = i; break; } @@ -482,7 +455,6 @@ void AnimationPlayerEditor::_select_anim_by_name(const String &p_anim) { } double AnimationPlayerEditor::_get_editor_step() const { - // Returns the effective snapping value depending on snapping modifiers, or 0 if snapping is disabled. if (track_editor->is_snap_enabled()) { const String current = player->get_assigned_animation(); @@ -497,7 +469,6 @@ double AnimationPlayerEditor::_get_editor_step() const { } void AnimationPlayerEditor::_animation_name_edited() { - player->stop(); String new_name = name->get_text(); @@ -534,7 +505,6 @@ void AnimationPlayerEditor::_animation_name_edited() { _select_anim_by_name(new_name); } else { - Ref<Animation> new_anim = Ref<Animation>(memnew(Animation)); new_anim->set_name(new_name); @@ -556,9 +526,9 @@ void AnimationPlayerEditor::_animation_name_edited() { } void AnimationPlayerEditor::_blend_editor_next_changed(const int p_idx) { - - if (animation->get_item_count() == 0) + if (animation->get_item_count() == 0) { return; + } String current = animation->get_item_text(animation->get_selected()); @@ -571,14 +541,15 @@ void AnimationPlayerEditor::_blend_editor_next_changed(const int p_idx) { } void AnimationPlayerEditor::_animation_blend() { - - if (updating_blends) + if (updating_blends) { return; + } blend_editor.tree->clear(); - if (animation->get_item_count() == 0) + if (animation->get_item_count() == 0) { return; + } String current = animation->get_item_text(animation->get_selected()); @@ -599,7 +570,6 @@ void AnimationPlayerEditor::_animation_blend() { blend_editor.next->add_item("", i); for (List<StringName>::Element *E = anims.front(); E; E = E->next()) { - String to = E->get(); TreeItem *blend = blend_editor.tree->create_item(root); blend->set_editable(0, false); @@ -627,18 +597,20 @@ void AnimationPlayerEditor::_animation_blend() { } void AnimationPlayerEditor::_blend_edited() { - - if (updating_blends) + if (updating_blends) { return; + } - if (animation->get_item_count() == 0) + if (animation->get_item_count() == 0) { return; + } String current = animation->get_item_text(animation->get_selected()); TreeItem *selected = blend_editor.tree->get_edited(); - if (!selected) + if (!selected) { return; + } updating_blends = true; String to = selected->get_text(0); @@ -655,15 +627,14 @@ void AnimationPlayerEditor::_blend_edited() { } void AnimationPlayerEditor::ensure_visibility() { - - if (player && pin->is_pressed()) + if (player && pin->is_pressed()) { return; // another player is pinned, don't reset + } _animation_edit(); } Dictionary AnimationPlayerEditor::get_state() const { - Dictionary d; d["visible"] = is_visible_in_tree(); @@ -675,8 +646,8 @@ Dictionary AnimationPlayerEditor::get_state() const { return d; } -void AnimationPlayerEditor::set_state(const Dictionary &p_state) { +void AnimationPlayerEditor::set_state(const Dictionary &p_state) { if (!p_state.has("visible") || !p_state["visible"]) { return; } @@ -685,7 +656,6 @@ void AnimationPlayerEditor::set_state(const Dictionary &p_state) { } if (p_state.has("player")) { - Node *n = EditorNode::get_singleton()->get_edited_scene()->get_node(p_state["player"]); if (Object::cast_to<AnimationPlayer>(n) && EditorNode::get_singleton()->get_editor_selection()->is_selected(n)) { player = Object::cast_to<AnimationPlayer>(n); @@ -710,7 +680,6 @@ void AnimationPlayerEditor::set_state(const Dictionary &p_state) { } void AnimationPlayerEditor::_animation_resource_edit() { - if (animation->get_item_count()) { String current = animation->get_item_text(animation->get_selected()); Ref<Animation> anim = player->get_animation(current); @@ -719,7 +688,6 @@ void AnimationPlayerEditor::_animation_resource_edit() { } void AnimationPlayerEditor::_animation_edit() { - if (animation->get_item_count()) { String current = animation->get_item_text(animation->get_selected()); Ref<Animation> anim = player->get_animation(current); @@ -736,7 +704,6 @@ void AnimationPlayerEditor::_animation_edit() { } void AnimationPlayerEditor::_dialog_action(String p_file) { - switch (current_option) { case RESOURCE_LOAD: { ERR_FAIL_COND(!player); @@ -745,16 +712,15 @@ void AnimationPlayerEditor::_dialog_action(String p_file) { ERR_FAIL_COND_MSG(res.is_null(), "Cannot load Animation from file '" + p_file + "'."); ERR_FAIL_COND_MSG(!res->is_class("Animation"), "Loaded resource from file '" + p_file + "' is not Animation."); if (p_file.find_last("/") != -1) { - p_file = p_file.substr(p_file.find_last("/") + 1, p_file.length()); } if (p_file.find_last("\\") != -1) { - p_file = p_file.substr(p_file.find_last("\\") + 1, p_file.length()); } - if (p_file.find(".") != -1) + if (p_file.find(".") != -1) { p_file = p_file.substr(0, p_file.find(".")); + } undo_redo->create_action(TTR("Load Animation")); undo_redo->add_do_method(player, "add_animation", p_file, res); @@ -768,7 +734,6 @@ void AnimationPlayerEditor::_dialog_action(String p_file) { break; } case RESOURCE_SAVE: { - String current = animation->get_item_text(animation->get_selected()); if (current != "") { Ref<Animation> anim = player->get_animation(current); @@ -784,24 +749,20 @@ void AnimationPlayerEditor::_dialog_action(String p_file) { } void AnimationPlayerEditor::_scale_changed(const String &p_scale) { - player->set_speed_scale(p_scale.to_double()); } void AnimationPlayerEditor::_update_animation() { - // the purpose of _update_animation is to reflect the current state // of the animation player in the current editor.. updating = true; if (player->is_playing()) { - play->set_pressed(true); stop->set_pressed(false); } else { - play->set_pressed(false); stop->set_pressed(true); } @@ -810,7 +771,6 @@ void AnimationPlayerEditor::_update_animation() { String current = player->get_assigned_animation(); for (int i = 0; i < animation->get_item_count(); i++) { - if (animation->get_item_text(i) == current) { animation->select(i); break; @@ -821,11 +781,11 @@ void AnimationPlayerEditor::_update_animation() { } void AnimationPlayerEditor::_update_player() { - updating = true; List<StringName> animlist; - if (player) + if (player) { player->get_animation_list(&animlist); + } animation->clear(); @@ -860,14 +820,15 @@ void AnimationPlayerEditor::_update_player() { int active_idx = -1; for (List<StringName>::Element *E = animlist.front(); E; E = E->next()) { - - if (player->get_autoplay() == E->get()) + if (player->get_autoplay() == E->get()) { animation->add_icon_item(autoplay_icon, E->get()); - else + } else { animation->add_item(E->get()); + } - if (player->get_assigned_animation() == E->get()) + if (player->get_assigned_animation() == E->get()) { active_idx = animation->get_item_count() - 1; + } } updating = false; @@ -877,7 +838,6 @@ void AnimationPlayerEditor::_update_player() { _animation_selected(active_idx); } else if (animation->get_item_count() > 0) { - animation->select(0); autoplay->set_pressed(animation->get_item_text(0) == player->get_autoplay()); _animation_selected(0); @@ -899,38 +859,41 @@ void AnimationPlayerEditor::_update_player() { } void AnimationPlayerEditor::edit(AnimationPlayer *p_player) { - - if (player && pin->is_pressed()) + if (player && pin->is_pressed()) { return; // Ignore, pinned. + } player = p_player; if (player) { _update_player(); if (onion.enabled) { - if (animation->get_item_count() > 0) + if (animation->get_item_count() > 0) { _start_onion_skinning(); - else + } else { _stop_onion_skinning(); + } } track_editor->show_select_node_warning(false); } else { - if (onion.enabled) + if (onion.enabled) { _stop_onion_skinning(); + } track_editor->show_select_node_warning(true); } } void AnimationPlayerEditor::forward_canvas_force_draw_over_viewport(Control *p_overlay) { - - if (!onion.can_overlay) + if (!onion.can_overlay) { return; + } // Can happen on viewport resize, at least. - if (!_are_onion_layers_valid()) + if (!_are_onion_layers_valid()) { return; + } RID ci = p_overlay->get_canvas_item(); Rect2 src_rect = p_overlay->get_global_rect(); @@ -973,22 +936,21 @@ void AnimationPlayerEditor::forward_canvas_force_draw_over_viewport(Control *p_o } void AnimationPlayerEditor::_animation_duplicate() { - - if (!animation->get_item_count()) + if (!animation->get_item_count()) { return; + } String current = animation->get_item_text(animation->get_selected()); Ref<Animation> anim = player->get_animation(current); - if (!anim.is_valid()) + if (!anim.is_valid()) { return; + } Ref<Animation> new_anim = memnew(Animation); List<PropertyInfo> plist; anim->get_property_list(&plist); for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { - if (E->get().usage & PROPERTY_USAGE_STORAGE) { - new_anim->set(E->get().name, anim->get(E->get().name)); } } @@ -1009,9 +971,7 @@ void AnimationPlayerEditor::_animation_duplicate() { undo_redo->commit_action(); for (int i = 0; i < animation->get_item_count(); i++) { - if (animation->get_item_text(i) == new_name) { - animation->select(i); _animation_selected(i); return; @@ -1020,7 +980,6 @@ void AnimationPlayerEditor::_animation_duplicate() { } void AnimationPlayerEditor::_seek_value_changed(float p_value, bool p_set) { - if (updating || !player || player->is_playing()) { return; }; @@ -1056,41 +1015,42 @@ void AnimationPlayerEditor::_seek_value_changed(float p_value, bool p_set) { }; void AnimationPlayerEditor::_animation_player_changed(Object *p_pl) { - if (player == p_pl && is_visible_in_tree()) { - _update_player(); - if (blend_editor.dialog->is_visible()) + if (blend_editor.dialog->is_visible()) { _animation_blend(); // Update. + } } } void AnimationPlayerEditor::_list_changed() { - - if (is_visible_in_tree()) + if (is_visible_in_tree()) { _update_player(); + } } void AnimationPlayerEditor::_animation_key_editor_anim_len_changed(float p_len) { - frame->set_max(p_len); } void AnimationPlayerEditor::_animation_key_editor_seek(float p_pos, bool p_drag) { - timeline_position = p_pos; - if (!is_visible_in_tree()) + if (!is_visible_in_tree()) { return; + } - if (!player) + if (!player) { return; + } - if (player->is_playing()) + if (player->is_playing()) { return; + } - if (!player->has_animation(player->get_assigned_animation())) + if (!player->has_animation(player->get_assigned_animation())) { return; + } updating = true; frame->set_value(Math::stepify(p_pos, _get_editor_step())); @@ -1101,7 +1061,6 @@ void AnimationPlayerEditor::_animation_key_editor_seek(float p_pos, bool p_drag) } void AnimationPlayerEditor::_animation_tool_menu(int p_option) { - String current; if (animation->get_selected() >= 0 && animation->get_selected() < animation->get_item_count()) { current = animation->get_item_text(animation->get_selected()); @@ -1113,47 +1072,37 @@ void AnimationPlayerEditor::_animation_tool_menu(int p_option) { } switch (p_option) { - case TOOL_NEW_ANIM: { - _animation_new(); } break; case TOOL_LOAD_ANIM: { - _animation_load(); } break; case TOOL_SAVE_ANIM: { - if (anim.is_valid()) { _animation_save(anim); } } break; case TOOL_SAVE_AS_ANIM: { - if (anim.is_valid()) { _animation_save_as(anim); } } break; case TOOL_DUPLICATE_ANIM: { - _animation_duplicate(); [[fallthrough]]; // Allow immediate rename after animation is duplicated } case TOOL_RENAME_ANIM: { - _animation_rename(); } break; case TOOL_EDIT_TRANSITIONS: { - _animation_blend(); } break; case TOOL_REMOVE_ANIM: { - _animation_remove(); } break; case TOOL_COPY_ANIM: { - if (!animation->get_item_count()) { error_dialog->set_text(TTR("No animation to copy!")); error_dialog->popup_centered(); @@ -1165,7 +1114,6 @@ void AnimationPlayerEditor::_animation_tool_menu(int p_option) { EditorSettings::get_singleton()->set_resource_clipboard(anim2); } break; case TOOL_PASTE_ANIM: { - Ref<Animation> anim2 = EditorSettings::get_singleton()->get_resource_clipboard(); if (!anim2.is_valid()) { error_dialog->set_text(TTR("No animation resource on clipboard!")); @@ -1181,7 +1129,6 @@ void AnimationPlayerEditor::_animation_tool_menu(int p_option) { int idx = 1; String base = name; while (player->has_animation(name)) { - idx++; name = base + " " + itos(idx); } @@ -1196,7 +1143,6 @@ void AnimationPlayerEditor::_animation_tool_menu(int p_option) { _select_anim_by_name(name); } break; case TOOL_EDIT_RESOURCE: { - if (!animation->get_item_count()) { error_dialog->set_text(TTR("No animation to edit!")); error_dialog->popup_centered(); @@ -1211,30 +1157,26 @@ void AnimationPlayerEditor::_animation_tool_menu(int p_option) { } void AnimationPlayerEditor::_onion_skinning_menu(int p_option) { - PopupMenu *menu = onion_skinning->get_popup(); int idx = menu->get_item_index(p_option); switch (p_option) { - case ONION_SKINNING_ENABLE: { - onion.enabled = !onion.enabled; - if (onion.enabled) + if (onion.enabled) { _start_onion_skinning(); - else + } else { _stop_onion_skinning(); + } } break; case ONION_SKINNING_PAST: { - // Ensure at least one of past/future is checked. onion.past = onion.future ? !onion.past : true; menu->set_item_checked(idx, onion.past); } break; case ONION_SKINNING_FUTURE: { - // Ensure at least one of past/future is checked. onion.future = onion.past ? !onion.future : true; menu->set_item_checked(idx, onion.future); @@ -1242,7 +1184,6 @@ void AnimationPlayerEditor::_onion_skinning_menu(int p_option) { case ONION_SKINNING_1_STEP: // Fall-through. case ONION_SKINNING_2_STEPS: case ONION_SKINNING_3_STEPS: { - onion.steps = (p_option - ONION_SKINNING_1_STEP) + 1; int one_frame_idx = menu->get_item_index(ONION_SKINNING_1_STEP); for (int i = 0; i <= ONION_SKINNING_LAST_STEPS_OPTION - ONION_SKINNING_1_STEP; i++) { @@ -1250,17 +1191,14 @@ void AnimationPlayerEditor::_onion_skinning_menu(int p_option) { } } break; case ONION_SKINNING_DIFFERENCES_ONLY: { - onion.differences_only = !onion.differences_only; menu->set_item_checked(idx, onion.differences_only); } break; case ONION_SKINNING_FORCE_WHITE_MODULATE: { - onion.force_white_modulate = !onion.force_white_modulate; menu->set_item_checked(idx, onion.force_white_modulate); } break; case ONION_SKINNING_INCLUDE_GIZMOS: { - onion.include_gizmos = !onion.include_gizmos; menu->set_item_checked(idx, onion.include_gizmos); } break; @@ -1268,40 +1206,37 @@ void AnimationPlayerEditor::_onion_skinning_menu(int p_option) { } void AnimationPlayerEditor::_unhandled_key_input(const Ref<InputEvent> &p_ev) { - Ref<InputEventKey> k = p_ev; if (is_visible_in_tree() && k.is_valid() && k->is_pressed() && !k->is_echo() && !k->get_alt() && !k->get_control() && !k->get_metakey()) { - switch (k->get_keycode()) { - case KEY_A: { - if (!k->get_shift()) + if (!k->get_shift()) { _play_bw_from_pressed(); - else + } else { _play_bw_pressed(); + } } break; case KEY_S: { _stop_pressed(); } break; case KEY_D: { - if (!k->get_shift()) + if (!k->get_shift()) { _play_from_pressed(); - else + } else { _play_pressed(); + } } break; } } } void AnimationPlayerEditor::_editor_visibility_changed() { - if (is_visible() && animation->get_item_count() > 0) { _start_onion_skinning(); } } bool AnimationPlayerEditor::_are_onion_layers_valid() { - ERR_FAIL_COND_V(!onion.past && !onion.future, false); Point2 capture_size = get_tree()->get_root()->get_size(); @@ -1309,7 +1244,6 @@ bool AnimationPlayerEditor::_are_onion_layers_valid() { } void AnimationPlayerEditor::_allocate_onion_layers() { - _free_onion_layers(); int captures = onion.get_needed_capture_count(); @@ -1338,7 +1272,6 @@ void AnimationPlayerEditor::_allocate_onion_layers() { } void AnimationPlayerEditor::_free_onion_layers() { - for (int i = 0; i < onion.captures.size(); i++) { if (onion.captures[i].is_valid()) { RS::get_singleton()->free(onion.captures[i]); @@ -1349,11 +1282,11 @@ void AnimationPlayerEditor::_free_onion_layers() { } void AnimationPlayerEditor::_prepare_onion_layers_1() { - // This would be called per viewport and we want to act once only. int64_t frame = get_tree()->get_frame(); - if (frame == onion.last_frame) + if (frame == onion.last_frame) { return; + } if (!onion.enabled || !is_processing() || !is_visible() || !get_player()) { _stop_onion_skinning(); @@ -1366,8 +1299,9 @@ void AnimationPlayerEditor::_prepare_onion_layers_1() { onion.can_overlay = false; plugin->update_overlays(); - if (player->is_playing()) + if (player->is_playing()) { return; + } // And go to next step afterwards. call_deferred("_prepare_onion_layers_2"); @@ -1378,13 +1312,14 @@ void AnimationPlayerEditor::_prepare_onion_layers_1_deferred() { } void AnimationPlayerEditor::_prepare_onion_layers_2() { - Ref<Animation> anim = player->get_animation(player->get_assigned_animation()); - if (!anim.is_valid()) + if (!anim.is_valid()) { return; + } - if (!_are_onion_layers_valid()) + if (!_are_onion_layers_valid()) { _allocate_onion_layers(); + } // Hide superfluous elements that would make the overlay unnecessary cluttered. Dictionary canvas_edit_state; @@ -1455,11 +1390,11 @@ void AnimationPlayerEditor::_prepare_onion_layers_2() { int cidx = 0; onion.capture.material->set_shader_param("dir_color", onion.force_white_modulate ? Color(1, 1, 1) : Color(EDITOR_GET("editors/animation/onion_layers_past_color"))); for (int step_off = step_off_a; step_off <= step_off_b; step_off++) { - if (step_off == 0) { // Skip present step and switch to the color of future. - if (!onion.force_white_modulate) + if (!onion.force_white_modulate) { onion.capture.material->set_shader_param("dir_color", EDITOR_GET("editors/animation/onion_layers_future_color")); + } continue; } @@ -1507,7 +1442,6 @@ void AnimationPlayerEditor::_prepare_onion_layers_2() { } void AnimationPlayerEditor::_start_onion_skinning() { - // FIXME: Using "idle_frame" makes onion layers update one frame behind the current. if (!get_tree()->is_connected("idle_frame", callable_mp(this, &AnimationPlayerEditor::_prepare_onion_layers_1_deferred))) { get_tree()->connect("idle_frame", callable_mp(this, &AnimationPlayerEditor::_prepare_onion_layers_1_deferred)); @@ -1515,9 +1449,7 @@ void AnimationPlayerEditor::_start_onion_skinning() { } void AnimationPlayerEditor::_stop_onion_skinning() { - if (get_tree()->is_connected("idle_frame", callable_mp(this, &AnimationPlayerEditor::_prepare_onion_layers_1_deferred))) { - get_tree()->disconnect("idle_frame", callable_mp(this, &AnimationPlayerEditor::_prepare_onion_layers_1_deferred)); _free_onion_layers(); @@ -1529,12 +1461,10 @@ void AnimationPlayerEditor::_stop_onion_skinning() { } void AnimationPlayerEditor::_pin_pressed() { - EditorNode::get_singleton()->get_scene_tree_dock()->get_tree_editor()->update_tree(); } void AnimationPlayerEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_animation_new"), &AnimationPlayerEditor::_animation_new); ClassDB::bind_method(D_METHOD("_animation_rename"), &AnimationPlayerEditor::_animation_rename); ClassDB::bind_method(D_METHOD("_animation_load"), &AnimationPlayerEditor::_animation_load); @@ -1556,7 +1486,6 @@ void AnimationPlayerEditor::_bind_methods() { AnimationPlayerEditor *AnimationPlayerEditor::singleton = nullptr; AnimationPlayer *AnimationPlayerEditor::get_player() const { - return player; } @@ -1800,39 +1729,33 @@ AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor, AnimationPlay } AnimationPlayerEditor::~AnimationPlayerEditor() { - _free_onion_layers(); RS::get_singleton()->free(onion.capture.canvas); RS::get_singleton()->free(onion.capture.canvas_item); } void AnimationPlayerEditorPlugin::_notification(int p_what) { - switch (p_what) { case NOTIFICATION_ENTER_TREE: { - set_force_draw_over_forwarding_enabled(); } break; } } void AnimationPlayerEditorPlugin::edit(Object *p_object) { - anim_editor->set_undo_redo(&get_undo_redo()); - if (!p_object) + if (!p_object) { return; + } anim_editor->edit(Object::cast_to<AnimationPlayer>(p_object)); } bool AnimationPlayerEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("AnimationPlayer"); } void AnimationPlayerEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { - editor->make_bottom_panel_item_visible(anim_editor); anim_editor->set_process(true); anim_editor->ensure_visibility(); @@ -1840,7 +1763,6 @@ void AnimationPlayerEditorPlugin::make_visible(bool p_visible) { } AnimationPlayerEditorPlugin::AnimationPlayerEditorPlugin(EditorNode *p_node) { - editor = p_node; anim_editor = memnew(AnimationPlayerEditor(editor, this)); anim_editor->set_undo_redo(EditorNode::get_undo_redo()); diff --git a/editor/plugins/animation_player_editor_plugin.h b/editor/plugins/animation_player_editor_plugin.h index 1abefad635..18f2d3b25e 100644 --- a/editor/plugins/animation_player_editor_plugin.h +++ b/editor/plugins/animation_player_editor_plugin.h @@ -43,7 +43,6 @@ class AnimationTrackEditor; class AnimationPlayerEditorPlugin; class AnimationPlayerEditor : public VBoxContainer { - GDCLASS(AnimationPlayerEditor, VBoxContainer); EditorNode *editor; @@ -114,7 +113,6 @@ class AnimationPlayerEditor : public VBoxContainer { int current_option; struct BlendEditor { - AcceptDialog *dialog; Tree *tree; OptionButton *next; @@ -244,7 +242,6 @@ public: }; class AnimationPlayerEditorPlugin : public EditorPlugin { - GDCLASS(AnimationPlayerEditorPlugin, EditorPlugin); AnimationPlayerEditor *anim_editor; diff --git a/editor/plugins/animation_state_machine_editor.cpp b/editor/plugins/animation_state_machine_editor.cpp index 509bf59716..652754a146 100644 --- a/editor/plugins/animation_state_machine_editor.cpp +++ b/editor/plugins/animation_state_machine_editor.cpp @@ -43,17 +43,14 @@ #include "scene/main/window.h" bool AnimationNodeStateMachineEditor::can_edit(const Ref<AnimationNode> &p_node) { - Ref<AnimationNodeStateMachine> ansm = p_node; return ansm.is_valid(); } void AnimationNodeStateMachineEditor::edit(const Ref<AnimationNode> &p_node) { - state_machine = p_node; if (state_machine.is_valid()) { - selected_transition_from = StringName(); selected_transition_to = StringName(); selected_node = StringName(); @@ -63,10 +60,10 @@ void AnimationNodeStateMachineEditor::edit(const Ref<AnimationNode> &p_node) { } void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEvent> &p_event) { - Ref<AnimationNodeStateMachinePlayback> playback = AnimationTreeEditor::get_singleton()->get_tree()->get(AnimationTreeEditor::get_singleton()->get_base_path() + "playback"); - if (playback.is_null()) + if (playback.is_null()) { return; + } Ref<InputEventKey> k = p_event; if (tool_select->is_pressed() && k.is_valid() && k->is_pressed() && k->get_keycode() == KEY_DELETE && !k->is_echo()) { @@ -104,10 +101,10 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv } for (List<StringName>::Element *E = classes.front(); E; E = E->next()) { - String name = String(E->get()).replace_first("AnimationNode", ""); - if (name == "Animation") + if (name == "Animation") { continue; // nope + } int idx = menu->get_item_count(); menu->add_item(vformat("Add %s", name), idx); menu->set_item_metadata(idx, E->get()); @@ -128,7 +125,6 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv // select node or push a field inside if (mb.is_valid() && !mb->get_shift() && mb->is_pressed() && tool_select->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { - selected_transition_from = StringName(); selected_transition_to = StringName(); selected_node = StringName(); @@ -191,7 +187,6 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv int closest = -1; float closest_d = 1e20; for (int i = 0; i < transition_lines.size(); i++) { - Vector2 s[2] = { transition_lines[i].from, transition_lines[i].to @@ -222,9 +217,7 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv //end moving node if (mb.is_valid() && dragging_selected_attempt && mb->get_button_index() == BUTTON_LEFT && !mb->is_pressed()) { - if (dragging_selected) { - Ref<AnimationNode> an = state_machine->get_node(selected_node); updating = true; undo_redo->create_action(TTR("Move Node")); @@ -245,7 +238,6 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv //connect nodes if (mb.is_valid() && ((tool_select->is_pressed() && mb->get_shift()) || tool_connect->is_pressed()) && mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) { - for (int i = node_rects.size() - 1; i >= 0; i--) { //inverse to draw order if (node_rects[i].node.has_point(mb->get_position())) { //select node since nothing else was selected connecting = true; @@ -259,14 +251,11 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv //end connecting nodes if (mb.is_valid() && connecting && mb->get_button_index() == BUTTON_LEFT && !mb->is_pressed()) { - if (connecting_to_node != StringName()) { - if (state_machine->has_transition(connecting_from, connecting_to_node)) { EditorNode::get_singleton()->show_warning(TTR("Transition exists!")); } else { - Ref<AnimationNodeStateMachineTransition> tr; tr.instance(); tr->set_switch_mode(AnimationNodeStateMachineTransition::SwitchMode(transition_mode->get_selected())); @@ -296,14 +285,12 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv //pan window if (mm.is_valid() && mm->get_button_mask() & BUTTON_MASK_MIDDLE) { - h_scroll->set_value(h_scroll->get_value() - mm->get_relative().x); v_scroll->set_value(v_scroll->get_value() - mm->get_relative().y); } //move mouse while connecting if (mm.is_valid() && connecting) { - connecting_to = mm->get_position(); connecting_to_node = StringName(); state_machine_draw->update(); @@ -318,7 +305,6 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv //move mouse while moving a node if (mm.is_valid() && dragging_selected_attempt) { - dragging_selected = true; drag_ofs = mm->get_position() - drag_from; snap_x = StringName(); @@ -333,8 +319,9 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv float best_d_y = 1e20; for (List<StringName>::Element *E = nodes.front(); E; E = E->next()) { - if (E->get() == selected_node) + if (E->get() == selected_node) { continue; + } Vector2 npos = state_machine->get_node_position(E->get()); float d_x = ABS(npos.x - cpos.x); @@ -358,14 +345,12 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv //put ibeam (text cursor) over names to make it clearer that they are editable if (mm.is_valid()) { - state_machine_draw->grab_focus(); bool over_text_now = false; String new_over_node = StringName(); int new_over_node_what = -1; if (tool_select->is_pressed()) { - for (int i = node_rects.size() - 1; i >= 0; i--) { //inverse to draw order if (node_rects[i].name.has_point(mm->get_position())) { @@ -392,7 +377,6 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv } if (over_text != over_text_now) { - if (over_text_now) { state_machine_draw->set_default_cursor_shape(CURSOR_IBEAM); } else { @@ -405,7 +389,6 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv } void AnimationNodeStateMachineEditor::_file_opened(const String &p_file) { - file_loaded = ResourceLoader::load(p_file); if (file_loaded.is_valid()) { _add_menu_type(MENU_LOAD_FILE_CONFIRM); @@ -413,12 +396,10 @@ void AnimationNodeStateMachineEditor::_file_opened(const String &p_file) { } void AnimationNodeStateMachineEditor::_add_menu_type(int p_index) { - String base_name; Ref<AnimationRootNode> node; if (p_index == MENU_LOAD_FILE) { - open_file->clear_filters(); List<String> filters; ResourceLoader::get_recognized_extensions_for_type("AnimationRootNode", &filters); @@ -431,7 +412,6 @@ void AnimationNodeStateMachineEditor::_add_menu_type(int p_index) { node = file_loaded; file_loaded.unref(); } else if (p_index == MENU_PASTE) { - node = EditorSettings::get_singleton()->get_resource_clipboard(); } else { @@ -452,7 +432,6 @@ void AnimationNodeStateMachineEditor::_add_menu_type(int p_index) { } if (base_name == String()) { - base_name = node->get_class().replace_first("AnimationNode", ""); } @@ -476,7 +455,6 @@ void AnimationNodeStateMachineEditor::_add_menu_type(int p_index) { } void AnimationNodeStateMachineEditor::_add_animation_type(int p_index) { - Ref<AnimationNodeAnimation> anim; anim.instance(); @@ -503,7 +481,6 @@ void AnimationNodeStateMachineEditor::_add_animation_type(int p_index) { } void AnimationNodeStateMachineEditor::_connection_draw(const Vector2 &p_from, const Vector2 &p_to, AnimationNodeStateMachineTransition::SwitchMode p_mode, bool p_enabled, bool p_selected, bool p_travel, bool p_auto_advance) { - Color linecolor = get_theme_color("font_color", "Label"); Color icon_color(1, 1, 1); Color accent = get_theme_color("accent_color", "Editor"); @@ -546,9 +523,9 @@ void AnimationNodeStateMachineEditor::_connection_draw(const Vector2 &p_from, co } void AnimationNodeStateMachineEditor::_clip_src_line_to_rect(Vector2 &r_from, Vector2 &r_to, const Rect2 &p_rect) { - - if (r_to == r_from) + if (r_to == r_from) { return; + } //this could be optimized... Vector2 n = (r_to - r_from).normalized(); @@ -558,9 +535,9 @@ void AnimationNodeStateMachineEditor::_clip_src_line_to_rect(Vector2 &r_from, Ve } void AnimationNodeStateMachineEditor::_clip_dst_line_to_rect(Vector2 &r_from, Vector2 &r_to, const Rect2 &p_rect) { - - if (r_to == r_from) + if (r_to == r_from) { return; + } //this could be optimized... Vector2 n = (r_to - r_from).normalized(); @@ -570,7 +547,6 @@ void AnimationNodeStateMachineEditor::_clip_dst_line_to_rect(Vector2 &r_from, Ve } void AnimationNodeStateMachineEditor::_state_machine_draw() { - Ref<AnimationNodeStateMachinePlayback> playback = AnimationTreeEditor::get_singleton()->get_tree()->get(AnimationTreeEditor::get_singleton()->get_base_path() + "playback"); Ref<StyleBox> style = get_theme_stylebox("state_machine_frame", "GraphNode"); @@ -611,7 +587,6 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() { //snap lines if (dragging_selected) { - Vector2 from = (state_machine->get_node_position(selected_node) * EDSCALE) + drag_ofs - state_machine->get_graph_offset() * EDSCALE; if (snap_x != StringName()) { Vector2 to = (state_machine->get_node_position(snap_x) * EDSCALE) - state_machine->get_graph_offset() * EDSCALE; @@ -625,7 +600,6 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() { //pre pass nodes so we know the rectangles for (List<StringName>::Element *E = nodes.front(); E; E = E->next()) { - Ref<AnimationNode> anode = state_machine->get_node(E->get()); String name = E->get(); bool needs_editor = EditorNode::get_singleton()->item_has_editor(anode.ptr()); @@ -691,7 +665,6 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() { //draw transition lines for (int i = 0; i < state_machine->get_transition_count(); i++) { - TransitionLine tl; tl.from_node = state_machine->get_transition_from(i); Vector2 ofs_from = (dragging_selected && tl.from_node == selected_node) ? drag_ofs : Vector2(); @@ -733,7 +706,6 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() { } if (travel_path.size()) { - if (current == tl.from_node && travel_path[0] == tl.to_node) { travel = true; } else { @@ -759,7 +731,6 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() { //draw actual nodes for (int i = 0; i < node_rects.size(); i++) { - String name = node_rects[i].node_name; Ref<AnimationNode> anode = state_machine->get_node(name); bool needs_editor = AnimationTreeEditor::get_singleton()->can_edit(anode); @@ -786,7 +757,6 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() { } if (state_machine->get_end_node() == name) { - int endofs = nr.node.size.x - font->get_string_size(TTR("End")).x; state_machine_draw->draw_string(font, offset + Vector2(endofs, -font->get_height() - 3 * EDSCALE + font->get_ascent()), TTR("End"), font_color); } @@ -844,11 +814,11 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() { } void AnimationNodeStateMachineEditor::_state_machine_pos_draw() { - Ref<AnimationNodeStateMachinePlayback> playback = AnimationTreeEditor::get_singleton()->get_tree()->get(AnimationTreeEditor::get_singleton()->get_base_path() + "playback"); - if (!playback.is_valid() || !playback->is_playing()) + if (!playback.is_valid() || !playback->is_playing()) { return; + } int idx = -1; for (int i = 0; i < node_rects.size(); i++) { @@ -858,8 +828,9 @@ void AnimationNodeStateMachineEditor::_state_machine_pos_draw() { } } - if (idx == -1) + if (idx == -1) { return; + } const NodeRect &nr = node_rects[idx]; @@ -891,9 +862,9 @@ void AnimationNodeStateMachineEditor::_state_machine_pos_draw() { } void AnimationNodeStateMachineEditor::_update_graph() { - - if (updating) + if (updating) { return; + } updating = true; @@ -903,7 +874,6 @@ void AnimationNodeStateMachineEditor::_update_graph() { } void AnimationNodeStateMachineEditor::_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("bg", "Tree")); error_label->add_theme_color_override("font_color", get_theme_color("error_color", "Editor")); @@ -928,7 +898,6 @@ void AnimationNodeStateMachineEditor::_notification(int p_what) { } if (p_what == NOTIFICATION_PROCESS) { - String error; Ref<AnimationNodeStateMachinePlayback> playback = AnimationTreeEditor::get_singleton()->get_tree()->get(AnimationTreeEditor::get_singleton()->get_base_path() + "playback"); @@ -1017,7 +986,6 @@ void AnimationNodeStateMachineEditor::_notification(int p_what) { } { - if (last_travel_path.size() != tp.size()) { same_travel_path = false; } else { @@ -1032,7 +1000,6 @@ void AnimationNodeStateMachineEditor::_notification(int p_what) { //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; @@ -1043,7 +1010,6 @@ void AnimationNodeStateMachineEditor::_notification(int p_what) { { 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; @@ -1063,7 +1029,6 @@ void AnimationNodeStateMachineEditor::_notification(int p_what) { } if (last_play_pos != play_pos) { - last_play_pos = play_pos; state_machine_play_pos->update(); } @@ -1076,17 +1041,14 @@ void AnimationNodeStateMachineEditor::_notification(int p_what) { } void AnimationNodeStateMachineEditor::_open_editor(const String &p_name) { - AnimationTreeEditor::get_singleton()->enter_editor(p_name); } void AnimationNodeStateMachineEditor::_removed_from_graph() { - EditorNode::get_singleton()->edit_item(nullptr); } void AnimationNodeStateMachineEditor::_name_edited(const String &p_text) { - const String &new_name = p_text; ERR_FAIL_COND(new_name == "" || new_name.find(".") != -1 || new_name.find("/") != -1); @@ -1117,24 +1079,23 @@ void AnimationNodeStateMachineEditor::_name_edited(const String &p_text) { } void AnimationNodeStateMachineEditor::_name_edited_focus_out() { - - if (updating) + if (updating) { return; + } _name_edited(name_edit->get_text()); } void AnimationNodeStateMachineEditor::_scroll_changed(double) { - - if (updating) + if (updating) { return; + } state_machine->set_graph_offset(Vector2(h_scroll->get_value(), v_scroll->get_value())); state_machine_draw->update(); } void AnimationNodeStateMachineEditor::_erase_selected() { - if (selected_node != StringName() && state_machine->has_node(selected_node)) { updating = true; undo_redo->create_action(TTR("Node Removed")); @@ -1158,7 +1119,6 @@ void AnimationNodeStateMachineEditor::_erase_selected() { } if (selected_transition_to != StringName() && selected_transition_from != StringName() && state_machine->has_transition(selected_transition_from, selected_transition_to)) { - Ref<AnimationNodeStateMachineTransition> tr = state_machine->get_transition(state_machine->find_transition(selected_transition_from, selected_transition_to)); updating = true; undo_redo->create_action(TTR("Transition Removed")); @@ -1176,9 +1136,7 @@ void AnimationNodeStateMachineEditor::_erase_selected() { } void AnimationNodeStateMachineEditor::_autoplay_selected() { - if (selected_node != StringName() && state_machine->has_node(selected_node)) { - StringName new_start_node; if (state_machine->get_start_node() == selected_node) { //toggle it new_start_node = StringName(); @@ -1199,9 +1157,7 @@ void AnimationNodeStateMachineEditor::_autoplay_selected() { } void AnimationNodeStateMachineEditor::_end_selected() { - if (selected_node != StringName() && state_machine->has_node(selected_node)) { - StringName new_end_node; if (state_machine->get_end_node() == selected_node) { //toggle it new_end_node = StringName(); @@ -1220,8 +1176,8 @@ void AnimationNodeStateMachineEditor::_end_selected() { state_machine_draw->update(); } } -void AnimationNodeStateMachineEditor::_update_mode() { +void AnimationNodeStateMachineEditor::_update_mode() { if (tool_select->is_pressed()) { tool_erase_hb->show(); tool_erase->set_disabled(selected_node == StringName() && selected_transition_from == StringName() && selected_transition_to == StringName()); @@ -1233,7 +1189,6 @@ void AnimationNodeStateMachineEditor::_update_mode() { } void AnimationNodeStateMachineEditor::_bind_methods() { - ClassDB::bind_method("_update_graph", &AnimationNodeStateMachineEditor::_update_graph); ClassDB::bind_method("_removed_from_graph", &AnimationNodeStateMachineEditor::_removed_from_graph); @@ -1244,7 +1199,6 @@ void AnimationNodeStateMachineEditor::_bind_methods() { AnimationNodeStateMachineEditor *AnimationNodeStateMachineEditor::singleton = nullptr; AnimationNodeStateMachineEditor::AnimationNodeStateMachineEditor() { - singleton = this; updating = false; diff --git a/editor/plugins/animation_state_machine_editor.h b/editor/plugins/animation_state_machine_editor.h index 5c4fc87df5..022c32ef48 100644 --- a/editor/plugins/animation_state_machine_editor.h +++ b/editor/plugins/animation_state_machine_editor.h @@ -42,7 +42,6 @@ #include "scene/gui/tree.h" class AnimationNodeStateMachineEditor : public AnimationTreeNodeEditorPlugin { - GDCLASS(AnimationNodeStateMachineEditor, AnimationTreeNodeEditorPlugin); Ref<AnimationNodeStateMachine> state_machine; diff --git a/editor/plugins/animation_tree_editor_plugin.cpp b/editor/plugins/animation_tree_editor_plugin.cpp index 9c48444e3e..ec3e25f999 100644 --- a/editor/plugins/animation_tree_editor_plugin.cpp +++ b/editor/plugins/animation_tree_editor_plugin.cpp @@ -48,9 +48,9 @@ #include "scene/scene_string_names.h" void AnimationTreeEditor::edit(AnimationTree *p_tree) { - - if (tree == p_tree) + if (tree == p_tree) { return; + } tree = p_tree; @@ -64,7 +64,6 @@ void AnimationTreeEditor::edit(AnimationTree *p_tree) { } void AnimationTreeEditor::_path_button_pressed(int p_path) { - edited_path.clear(); for (int i = 0; i <= p_path; i++) { edited_path.push_back(button_path[i]); @@ -100,7 +99,6 @@ void AnimationTreeEditor::_update_path() { } void AnimationTreeEditor::edit_path(const Vector<String> &p_path) { - button_path.clear(); Ref<AnimationNode> node = tree->get_tree_root(); @@ -109,7 +107,6 @@ void AnimationTreeEditor::edit_path(const Vector<String> &p_path) { current_root = node->get_instance_id(); for (int i = 0; i < p_path.size(); i++) { - Ref<AnimationNode> child = node->get_child_by_name(p_path[i]); ERR_BREAK(child.is_null()); node = child; @@ -140,7 +137,6 @@ Vector<String> AnimationTreeEditor::get_edited_path() const { } void AnimationTreeEditor::enter_editor(const String &p_path) { - Vector<String> path = edited_path; path.push_back(p_path); edit_path(path); @@ -204,19 +200,20 @@ bool AnimationTreeEditor::can_edit(const Ref<AnimationNode> &p_node) const { } Vector<String> AnimationTreeEditor::get_animation_list() { - if (!singleton->is_visible()) { return Vector<String>(); } AnimationTree *tree = singleton->tree; - if (!tree || !tree->has_node(tree->get_animation_player())) + if (!tree || !tree->has_node(tree->get_animation_player())) { return Vector<String>(); + } AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(tree->get_node(tree->get_animation_player())); - if (!ap) + if (!ap) { return Vector<String>(); + } List<StringName> anims; ap->get_animation_list(&anims); @@ -229,7 +226,6 @@ Vector<String> AnimationTreeEditor::get_animation_list() { } AnimationTreeEditor::AnimationTreeEditor() { - AnimationNodeAnimation::get_editable_animation_list = get_animation_list; path_edit = memnew(ScrollContainer); add_child(path_edit); @@ -253,17 +249,14 @@ AnimationTreeEditor::AnimationTreeEditor() { } void AnimationTreeEditorPlugin::edit(Object *p_object) { - anim_tree_editor->edit(Object::cast_to<AnimationTree>(p_object)); } bool AnimationTreeEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("AnimationTree"); } void AnimationTreeEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { //editor->hide_animation_player_editors(); //editor->animation_panel_make_visible(true); @@ -271,16 +264,15 @@ void AnimationTreeEditorPlugin::make_visible(bool p_visible) { editor->make_bottom_panel_item_visible(anim_tree_editor); anim_tree_editor->set_process(true); } else { - - if (anim_tree_editor->is_visible_in_tree()) + if (anim_tree_editor->is_visible_in_tree()) { editor->hide_bottom_panel(); + } button->hide(); anim_tree_editor->set_process(false); } } AnimationTreeEditorPlugin::AnimationTreeEditorPlugin(EditorNode *p_node) { - editor = p_node; anim_tree_editor = memnew(AnimationTreeEditor); anim_tree_editor->set_custom_minimum_size(Size2(0, 300) * EDSCALE); diff --git a/editor/plugins/animation_tree_editor_plugin.h b/editor/plugins/animation_tree_editor_plugin.h index 0b93b0fd8e..25af81ea9b 100644 --- a/editor/plugins/animation_tree_editor_plugin.h +++ b/editor/plugins/animation_tree_editor_plugin.h @@ -49,7 +49,6 @@ public: }; class AnimationTreeEditor : public VBoxContainer { - GDCLASS(AnimationTreeEditor, VBoxContainer); ScrollContainer *path_edit; @@ -95,7 +94,6 @@ public: }; class AnimationTreeEditorPlugin : public EditorPlugin { - GDCLASS(AnimationTreeEditorPlugin, EditorPlugin); AnimationTreeEditor *anim_tree_editor; diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp index 1928d49556..da170cd498 100644 --- a/editor/plugins/asset_library_editor_plugin.cpp +++ b/editor/plugins/asset_library_editor_plugin.cpp @@ -40,7 +40,6 @@ #include "editor/project_settings_editor.h" void EditorAssetLibraryItem::configure(const String &p_title, int p_asset_id, const String &p_category, int p_category_id, const String &p_author, int p_author_id, const String &p_cost) { - title->set_text(p_title); asset_id = p_asset_id; category->set_text(p_category); @@ -51,7 +50,6 @@ void EditorAssetLibraryItem::configure(const String &p_title, int p_asset_id, co } void EditorAssetLibraryItem::set_image(int p_type, int p_index, const Ref<Texture2D> &p_image) { - ERR_FAIL_COND(p_type != EditorAssetLibrary::IMAGE_QUEUE_ICON); ERR_FAIL_COND(p_index != 0); @@ -59,9 +57,7 @@ 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("ProjectIconLoading", "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)); @@ -70,21 +66,18 @@ void EditorAssetLibraryItem::_notification(int p_what) { } void EditorAssetLibraryItem::_asset_clicked() { - emit_signal("asset_selected", asset_id); } void EditorAssetLibraryItem::_category_clicked() { - emit_signal("category_selected", category_id); } -void EditorAssetLibraryItem::_author_clicked() { +void EditorAssetLibraryItem::_author_clicked() { emit_signal("author_selected", author_id); } void EditorAssetLibraryItem::_bind_methods() { - ClassDB::bind_method("set_image", &EditorAssetLibraryItem::set_image); ADD_SIGNAL(MethodInfo("asset_selected")); ADD_SIGNAL(MethodInfo("category_selected")); @@ -92,7 +85,6 @@ void EditorAssetLibraryItem::_bind_methods() { } EditorAssetLibraryItem::EditorAssetLibraryItem() { - Ref<StyleBoxEmpty> border; border.instance(); border->set_default_margin(MARGIN_LEFT, 5 * EDSCALE); @@ -143,16 +135,12 @@ EditorAssetLibraryItem::EditorAssetLibraryItem() { ////////////////////////////////////////////////////////////////////////////// void EditorAssetLibraryItemDescription::set_image(int p_type, int p_index, const Ref<Texture2D> &p_image) { - switch (p_type) { - case EditorAssetLibrary::IMAGE_QUEUE_ICON: { - item->call("set_image", p_type, p_index, p_image); icon = p_image; } break; case EditorAssetLibrary::IMAGE_QUEUE_THUMBNAIL: { - for (int i = 0; i < preview_images.size(); i++) { if (preview_images[i].id == p_index) { if (preview_images[i].is_video) { @@ -181,7 +169,6 @@ void EditorAssetLibraryItemDescription::set_image(int p_type, int p_index, const } } break; case EditorAssetLibrary::IMAGE_QUEUE_SCREENSHOT: { - for (int i = 0; i < preview_images.size(); i++) { if (preview_images[i].id == p_index) { preview_images.write[i].image = p_image; @@ -231,7 +218,6 @@ void EditorAssetLibraryItemDescription::_preview_click(int p_id) { } void EditorAssetLibraryItemDescription::configure(const String &p_title, int p_asset_id, const String &p_category, int p_category_id, const String &p_author, int p_author_id, const String &p_cost, int p_version, const String &p_version_string, const String &p_description, const String &p_download_url, const String &p_browse_url, const String &p_sha256_hash) { - asset_id = p_asset_id; title = p_title; download_url = p_download_url; @@ -249,7 +235,6 @@ void EditorAssetLibraryItemDescription::configure(const String &p_title, int p_a } void EditorAssetLibraryItemDescription::add_preview(int p_id, bool p_video, const String &p_url) { - Preview preview; preview.id = p_id; preview.video_link = p_url; @@ -270,7 +255,6 @@ void EditorAssetLibraryItemDescription::add_preview(int p_id, bool p_video, cons } EditorAssetLibraryItemDescription::EditorAssetLibraryItemDescription() { - HBoxContainer *hbox = memnew(HBoxContainer); add_child(hbox); VBoxContainer *desc_vbox = memnew(VBoxContainer); @@ -314,14 +298,13 @@ EditorAssetLibraryItemDescription::EditorAssetLibraryItemDescription() { get_ok()->set_text(TTR("Download")); get_cancel()->set_text(TTR("Close")); } + /////////////////////////////////////////////////////////////////////////////////// void EditorAssetLibraryItemDownload::_http_download_completed(int p_status, int p_code, const PackedStringArray &headers, const PackedByteArray &p_data) { - String error_text; switch (p_status) { - case HTTPRequest::RESULT_CHUNKED_BODY_SIZE_MISMATCH: case HTTPRequest::RESULT_CONNECTION_ERROR: case HTTPRequest::RESULT_BODY_SIZE_LIMIT_EXCEEDED: { @@ -388,29 +371,25 @@ void EditorAssetLibraryItemDownload::_http_download_completed(int p_status, int } void EditorAssetLibraryItemDownload::configure(const String &p_title, int p_asset_id, const Ref<Texture2D> &p_preview, const String &p_download_url, const String &p_sha256_hash) { - title->set_text(p_title); icon->set_texture(p_preview); asset_id = p_asset_id; - if (!p_preview.is_valid()) + if (!p_preview.is_valid()) { icon->set_texture(get_theme_icon("FileBrokenBigThumb", "EditorIcons")); + } host = p_download_url; sha256 = p_sha256_hash; _make_request(); } void EditorAssetLibraryItemDownload::_notification(int p_what) { - switch (p_what) { - // FIXME: The editor crashes if 'NOTICATION_THEME_CHANGED' is used. case NOTIFICATION_ENTER_TREE: { - add_theme_style_override("panel", get_theme_stylebox("panel", "TabContainer")); dismiss->set_normal_texture(get_theme_icon("Close", "EditorIcons")); } break; case NOTIFICATION_PROCESS: { - // Make the progress bar visible again when retrying the download. progress->set_modulate(Color(1, 1, 1, 1)); @@ -438,7 +417,6 @@ void EditorAssetLibraryItemDownload::_notification(int p_what) { if (cstatus != prev_status) { switch (cstatus) { - case HTTPClient::STATUS_RESOLVING: { status->set_text(TTR("Resolving...")); progress->set_max(1); @@ -462,15 +440,14 @@ void EditorAssetLibraryItemDownload::_notification(int p_what) { } break; } } -void EditorAssetLibraryItemDownload::_close() { +void EditorAssetLibraryItemDownload::_close() { // Clean up downloaded file. DirAccess::remove_file_or_error(download->get_download_file()); queue_delete(); } void EditorAssetLibraryItemDownload::_install() { - String file = download->get_download_file(); if (external_install) { @@ -494,12 +471,10 @@ void EditorAssetLibraryItemDownload::_make_request() { } void EditorAssetLibraryItemDownload::_bind_methods() { - ADD_SIGNAL(MethodInfo("install_asset", PropertyInfo(Variant::STRING, "zip_path"), PropertyInfo(Variant::STRING, "name"))); } EditorAssetLibraryItemDownload::EditorAssetLibraryItemDownload() { - HBoxContainer *hb = memnew(HBoxContainer); add_child(hb); icon = memnew(TextureRect); @@ -566,11 +541,8 @@ EditorAssetLibraryItemDownload::EditorAssetLibraryItemDownload() { //////////////////////////////////////////////////////////////////////////////// void EditorAssetLibrary::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_READY: { - error_tr->set_texture(get_theme_icon("Error", "EditorIcons")); filter->set_right_icon(get_theme_icon("Search", "EditorIcons")); filter->set_clear_button_enabled(true); @@ -578,13 +550,11 @@ void EditorAssetLibrary::_notification(int p_what) { error_label->raise(); } break; case NOTIFICATION_VISIBILITY_CHANGED: { - if (is_visible() && initial_loading) { _repository_changed(0); // Update when shown for the first time. } } break; case NOTIFICATION_PROCESS: { - HTTPClient::Status s = request->get_http_client_status(); const bool loading = s != HTTPClient::STATUS_DISCONNECTED; @@ -601,7 +571,6 @@ void EditorAssetLibrary::_notification(int p_what) { } break; case NOTIFICATION_THEME_CHANGED: { - library_scroll_bg->add_theme_style_override("panel", get_theme_stylebox("bg", "Tree")); downloads_scroll->add_theme_style_override("bg", get_theme_stylebox("bg", "Tree")); error_tr->set_texture(get_theme_icon("Error", "EditorIcons")); @@ -612,13 +581,10 @@ void EditorAssetLibrary::_notification(int p_what) { } void EditorAssetLibrary::_unhandled_input(const Ref<InputEvent> &p_event) { - const Ref<InputEventKey> key = p_event; if (key.is_valid() && key->is_pressed()) { - if (key->get_keycode_with_modifiers() == (KEY_MASK_CMD | KEY_F) && is_visible_in_tree()) { - filter->grab_focus(); filter->select_all(); accept_event(); @@ -627,16 +593,14 @@ void EditorAssetLibrary::_unhandled_input(const Ref<InputEvent> &p_event) { } void EditorAssetLibrary::_install_asset() { - ERR_FAIL_COND(!description); for (int i = 0; i < downloads_hb->get_child_count(); i++) { - EditorAssetLibraryItemDownload *d = Object::cast_to<EditorAssetLibraryItemDownload>(downloads_hb->get_child(i)); if (d && d->get_asset_id() == description->get_asset_id()) { - - if (EditorNode::get_singleton() != nullptr) + if (EditorNode::get_singleton() != nullptr) { EditorNode::get_singleton()->show_warning(TTR("Download for this asset is already in progress!")); + } return; } } @@ -676,16 +640,14 @@ const char *EditorAssetLibrary::support_key[SUPPORT_MAX] = { }; void EditorAssetLibrary::_select_author(int p_id) { - // Open author window. } void EditorAssetLibrary::_select_category(int p_id) { - for (int i = 0; i < categories->get_item_count(); i++) { - - if (i == 0) + if (i == 0) { continue; + } int id = categories->get_item_metadata(i); if (id == p_id) { categories->select(i); @@ -694,8 +656,8 @@ void EditorAssetLibrary::_select_category(int p_id) { } } } -void EditorAssetLibrary::_select_asset(int p_id) { +void EditorAssetLibrary::_select_asset(int p_id) { _api_request("asset/" + itos(p_id), REQUESTING_ASSET); } @@ -780,11 +742,9 @@ void EditorAssetLibrary::_image_update(bool use_cache, bool final, const PackedB } void EditorAssetLibrary::_image_request_completed(int p_status, int p_code, const PackedStringArray &headers, const PackedByteArray &p_data, int p_queue_id) { - ERR_FAIL_COND(!image_queue.has(p_queue_id)); if (p_status == HTTPRequest::RESULT_SUCCESS && p_code < HTTPClient::RESPONSE_BAD_REQUEST) { - if (p_code != HTTPClient::RESPONSE_NOT_MODIFIED) { for (int i = 0; i < headers.size(); i++) { if (headers[i].findn("ETag:") == 0) { // Save etag @@ -830,14 +790,12 @@ void EditorAssetLibrary::_image_request_completed(int p_status, int p_code, cons } void EditorAssetLibrary::_update_image_queue() { - const int max_images = 6; int current_images = 0; List<int> to_delete; for (Map<int, ImageQueue>::Element *E = image_queue.front(); E; E = E->next()) { if (!E->get().active && current_images < max_images) { - String cache_filename_base = EditorSettings::get_singleton()->get_cache_dir().plus_file("assetimage_" + E->get().image_url.md5_text()); Vector<String> headers; @@ -870,7 +828,6 @@ void EditorAssetLibrary::_update_image_queue() { } void EditorAssetLibrary::_request_image(ObjectID p_for, String p_image_url, ImageType p_type, int p_image_index) { - ImageQueue iq; iq.image_url = p_image_url; iq.image_index = p_image_index; @@ -911,7 +868,6 @@ void EditorAssetLibrary::_rerun_search(int p_ignore) { } void EditorAssetLibrary::_search(int p_page) { - String args; if (templates_only) { @@ -935,7 +891,6 @@ void EditorAssetLibrary::_search(int p_page) { } if (categories->get_selected() > 0) { - args += "&category=" + itos(categories->get_item_metadata(categories->get_selected())); } @@ -956,24 +911,25 @@ void EditorAssetLibrary::_search(int p_page) { } void EditorAssetLibrary::_search_text_entered(const String &p_text) { - _search(); } HBoxContainer *EditorAssetLibrary::_make_pages(int p_page, int p_page_count, int p_page_len, int p_total_items, int p_current_items) { - HBoxContainer *hbc = memnew(HBoxContainer); - if (p_page_count < 2) + if (p_page_count < 2) { return hbc; + } //do the mario int from = p_page - 5; - if (from < 0) + if (from < 0) { from = 0; + } int to = from + 10; - if (to > p_page_count) + if (to > p_page_count) { to = p_page_count; + } hbc->add_spacer(); hbc->add_theme_constant_override("separation", 5 * EDSCALE); @@ -1000,9 +956,7 @@ HBoxContainer *EditorAssetLibrary::_make_pages(int p_page, int p_page_count, int hbc->add_child(memnew(VSeparator)); for (int i = from; i < to; i++) { - if (i == p_page) { - Button *current = memnew(Button); current->set_text(itos(i + 1)); current->set_disabled(true); @@ -1010,7 +964,6 @@ HBoxContainer *EditorAssetLibrary::_make_pages(int p_page, int p_page_count, int hbc->add_child(current); } else { - Button *current = memnew(Button); current->set_text(itos(i + 1)); current->connect("pressed", callable_mp(this, &EditorAssetLibrary::_search), varray(i)); @@ -1046,7 +999,6 @@ HBoxContainer *EditorAssetLibrary::_make_pages(int p_page, int p_page_count, int } void EditorAssetLibrary::_api_request(const String &p_request, RequestType p_request_type, const String &p_arguments) { - if (requesting != REQUESTING_NONE) { request->cancel_request(); } @@ -1058,7 +1010,6 @@ void EditorAssetLibrary::_api_request(const String &p_request, RequestType p_req } void EditorAssetLibrary::_http_request_completed(int p_status, int p_code, const PackedStringArray &headers, const PackedByteArray &p_data) { - String str; { @@ -1070,7 +1021,6 @@ void EditorAssetLibrary::_http_request_completed(int p_status, int p_code, const bool error_abort = true; switch (p_status) { - case HTTPRequest::RESULT_CANT_RESOLVE: { error_label->set_text(TTR("Can't resolve hostname:") + " " + host); } break; @@ -1097,7 +1047,6 @@ void EditorAssetLibrary::_http_request_completed(int p_status, int p_code, const if (p_code != 200) { error_label->set_text(TTR("Request failed, return code:") + " " + itos(p_code)); } else { - error_abort = false; } } break; @@ -1122,7 +1071,6 @@ void EditorAssetLibrary::_http_request_completed(int p_status, int p_code, const switch (requested) { case REQUESTING_CONFIG: { - categories->clear(); categories->add_item(TTR("All")); categories->set_item_metadata(0, 0); @@ -1130,8 +1078,9 @@ void EditorAssetLibrary::_http_request_completed(int p_status, int p_code, const Array clist = d["categories"]; for (int i = 0; i < clist.size(); i++) { Dictionary cat = clist[i]; - if (!cat.has("name") || !cat.has("id")) + if (!cat.has("name") || !cat.has("id")) { continue; + } String name = cat["name"]; int id = cat["id"]; categories->add_item(name); @@ -1143,7 +1092,6 @@ void EditorAssetLibrary::_http_request_completed(int p_status, int p_code, const _search(); } break; case REQUESTING_SEARCH: { - initial_loading = false; // The loading text only needs to be displayed before the first page is loaded. @@ -1214,7 +1162,6 @@ void EditorAssetLibrary::_http_request_completed(int p_status, int p_code, const } for (int i = 0; i < result.size(); i++) { - Dictionary r = result[i]; ERR_CONTINUE(!r.has("title")); @@ -1273,7 +1220,6 @@ void EditorAssetLibrary::_http_request_completed(int p_status, int p_code, const Array previews = d["previews"]; for (int i = 0; i < previews.size(); i++) { - Dictionary p = previews[i]; ERR_CONTINUE(!p.has("type")); @@ -1303,7 +1249,6 @@ void EditorAssetLibrary::_http_request_completed(int p_status, int p_code, const } void EditorAssetLibrary::_asset_file_selected(const String &p_file) { - if (asset_installer) { memdelete(asset_installer); asset_installer = nullptr; @@ -1315,18 +1260,15 @@ void EditorAssetLibrary::_asset_file_selected(const String &p_file) { } void EditorAssetLibrary::_asset_open() { - asset_open->popup_centered_ratio(); } void EditorAssetLibrary::_manage_plugins() { - ProjectSettingsEditor::get_singleton()->popup_project_settings(); ProjectSettingsEditor::get_singleton()->set_plugins_page(); } void EditorAssetLibrary::_install_external_asset(String p_zip_path, String p_title) { - emit_signal("install_asset", p_zip_path, p_title); } @@ -1335,14 +1277,12 @@ void EditorAssetLibrary::disable_community_support() { } void EditorAssetLibrary::_bind_methods() { - ClassDB::bind_method("_unhandled_input", &EditorAssetLibrary::_unhandled_input); ADD_SIGNAL(MethodInfo("install_asset", PropertyInfo(Variant::STRING, "zip_path"), PropertyInfo(Variant::STRING, "name"))); } EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) { - requesting = REQUESTING_NONE; templates_only = p_templates_only; initial_loading = true; @@ -1364,8 +1304,9 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) { search->connect("pressed", callable_mp(this, &EditorAssetLibrary::_search), make_binds(0)); search_hb->add_child(search); - if (!p_templates_only) + if (!p_templates_only) { search_hb->add_child(memnew(VSeparator)); + } Button *open_asset = memnew(Button); open_asset->set_text(TTR("Import...")); @@ -1527,18 +1468,14 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) { /////// void AssetLibraryEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { - addon_library->show(); } else { - addon_library->hide(); } } AssetLibraryEditorPlugin::AssetLibraryEditorPlugin(EditorNode *p_node) { - editor = p_node; addon_library = memnew(EditorAssetLibrary); addon_library->set_v_size_flags(Control::SIZE_EXPAND_FILL); diff --git a/editor/plugins/asset_library_editor_plugin.h b/editor/plugins/asset_library_editor_plugin.h index 536a855d03..d5d381dee3 100644 --- a/editor/plugins/asset_library_editor_plugin.h +++ b/editor/plugins/asset_library_editor_plugin.h @@ -50,7 +50,6 @@ #include "scene/main/http_request.h" class EditorAssetLibraryItem : public PanelContainer { - GDCLASS(EditorAssetLibraryItem, PanelContainer); TextureButton *icon; @@ -81,7 +80,6 @@ public: }; class EditorAssetLibraryItemDescription : public ConfirmationDialog { - GDCLASS(EditorAssetLibraryItemDescription, ConfirmationDialog); EditorAssetLibraryItem *item; @@ -129,7 +127,6 @@ public: }; class EditorAssetLibraryItemDownload : public PanelContainer { - GDCLASS(EditorAssetLibraryItemDownload, PanelContainer); TextureRect *icon; @@ -237,7 +234,6 @@ class EditorAssetLibrary : public PanelContainer { }; struct ImageQueue { - bool active; int queue_id; ImageType image_type; @@ -309,7 +305,6 @@ public: }; class AssetLibraryEditorPlugin : public EditorPlugin { - GDCLASS(AssetLibraryEditorPlugin, EditorPlugin); EditorAssetLibrary *addon_library; diff --git a/editor/plugins/audio_stream_editor_plugin.cpp b/editor/plugins/audio_stream_editor_plugin.cpp index 0459ac7618..3b7a9320f0 100644 --- a/editor/plugins/audio_stream_editor_plugin.cpp +++ b/editor/plugins/audio_stream_editor_plugin.cpp @@ -37,7 +37,6 @@ #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)); } @@ -75,7 +74,6 @@ void AudioStreamEditor::_draw_preview() { lines.resize(size.width * 2); for (int i = 0; i < size.width; i++) { - float ofs = i * preview_len / size.width; float ofs_n = (i + 1) * preview_len / size.width; float max = preview->get_max(ofs, ofs_n) * 0.5 + 0.5; @@ -93,21 +91,19 @@ void AudioStreamEditor::_draw_preview() { } void AudioStreamEditor::_preview_changed(ObjectID p_which) { - if (stream.is_valid() && stream->get_instance_id() == p_which) { _preview->update(); } } void AudioStreamEditor::_changed_callback(Object *p_changed, const char *p_prop) { - - if (!is_visible()) + if (!is_visible()) { return; + } update(); } void AudioStreamEditor::_play() { - if (_player->is_playing()) { _player->stop(); _play_button->set_icon(get_theme_icon("MainPlay", "EditorIcons")); @@ -120,7 +116,6 @@ void AudioStreamEditor::_play() { } void AudioStreamEditor::_stop() { - _player->stop(); _play_button->set_icon(get_theme_icon("MainPlay", "EditorIcons")); _current = 0; @@ -129,7 +124,6 @@ void AudioStreamEditor::_stop() { } void AudioStreamEditor::_on_finished() { - _play_button->set_icon(get_theme_icon("MainPlay", "EditorIcons")); if (_current == _player->get_stream()->get_length()) { _current = 0; @@ -138,7 +132,6 @@ void AudioStreamEditor::_on_finished() { } void AudioStreamEditor::_draw_indicator() { - if (!stream.is_valid()) { return; } @@ -178,9 +171,9 @@ void AudioStreamEditor::_seek_to(real_t p_x) { } void AudioStreamEditor::edit(Ref<AudioStream> p_stream) { - - if (!stream.is_null()) + if (!stream.is_null()) { stream->remove_change_receptor(this); + } stream = p_stream; _player->set_stream(stream); @@ -200,7 +193,6 @@ void AudioStreamEditor::_bind_methods() { } AudioStreamEditor::AudioStreamEditor() { - set_custom_minimum_size(Size2(1, 100) * EDSCALE); _current = 0; _dragging = false; @@ -251,26 +243,23 @@ AudioStreamEditor::AudioStreamEditor() { } void AudioStreamEditorPlugin::edit(Object *p_object) { - AudioStream *s = Object::cast_to<AudioStream>(p_object); - if (!s) + if (!s) { return; + } audio_editor->edit(Ref<AudioStream>(s)); } bool AudioStreamEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("AudioStream"); } void AudioStreamEditorPlugin::make_visible(bool p_visible) { - audio_editor->set_visible(p_visible); } AudioStreamEditorPlugin::AudioStreamEditorPlugin(EditorNode *p_node) { - editor = p_node; audio_editor = memnew(AudioStreamEditor); add_control_to_container(CONTAINER_PROPERTY_EDITOR_BOTTOM, audio_editor); diff --git a/editor/plugins/audio_stream_editor_plugin.h b/editor/plugins/audio_stream_editor_plugin.h index 2191b541f6..dd7caaa15e 100644 --- a/editor/plugins/audio_stream_editor_plugin.h +++ b/editor/plugins/audio_stream_editor_plugin.h @@ -38,7 +38,6 @@ #include "scene/resources/texture.h" class AudioStreamEditor : public ColorRect { - GDCLASS(AudioStreamEditor, ColorRect); Ref<AudioStream> stream; @@ -73,7 +72,6 @@ public: }; class AudioStreamEditorPlugin : public EditorPlugin { - GDCLASS(AudioStreamEditorPlugin, EditorPlugin); AudioStreamEditor *audio_editor; diff --git a/editor/plugins/baked_lightmap_editor_plugin.cpp b/editor/plugins/baked_lightmap_editor_plugin.cpp index f754dd4725..8fbe1646f7 100644 --- a/editor/plugins/baked_lightmap_editor_plugin.cpp +++ b/editor/plugins/baked_lightmap_editor_plugin.cpp @@ -31,7 +31,6 @@ #include "baked_lightmap_editor_plugin.h" void BakedLightmapEditorPlugin::_bake_select_file(const String &p_file) { - if (lightmap) { BakedLightmap::BakeError err; if (get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root() == lightmap) { @@ -71,30 +70,26 @@ void BakedLightmapEditorPlugin::_bake_select_file(const String &p_file) { } void BakedLightmapEditorPlugin::_bake() { - _bake_select_file(""); } void BakedLightmapEditorPlugin::edit(Object *p_object) { - BakedLightmap *s = Object::cast_to<BakedLightmap>(p_object); - if (!s) + if (!s) { return; + } lightmap = s; } bool BakedLightmapEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("BakedLightmap"); } void BakedLightmapEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { bake->show(); } else { - bake->hide(); } } @@ -102,7 +97,6 @@ void BakedLightmapEditorPlugin::make_visible(bool p_visible) { EditorProgress *BakedLightmapEditorPlugin::tmp_progress = nullptr; bool BakedLightmapEditorPlugin::bake_func_step(float p_progress, const String &p_description, void *, bool p_refresh) { - if (!tmp_progress) { tmp_progress = memnew(EditorProgress("bake_lightmaps", TTR("Bake Lightmaps"), 1000, false)); ERR_FAIL_COND_V(tmp_progress == nullptr, false); @@ -118,12 +112,10 @@ void BakedLightmapEditorPlugin::bake_func_end() { } void BakedLightmapEditorPlugin::_bind_methods() { - ClassDB::bind_method("_bake", &BakedLightmapEditorPlugin::_bake); } BakedLightmapEditorPlugin::BakedLightmapEditorPlugin(EditorNode *p_node) { - editor = p_node; bake = memnew(ToolButton); bake->set_icon(editor->get_gui_base()->get_theme_icon("Bake", "EditorIcons")); diff --git a/editor/plugins/baked_lightmap_editor_plugin.h b/editor/plugins/baked_lightmap_editor_plugin.h index 2dbc09fc1d..67fb368a86 100644 --- a/editor/plugins/baked_lightmap_editor_plugin.h +++ b/editor/plugins/baked_lightmap_editor_plugin.h @@ -37,7 +37,6 @@ #include "scene/resources/material.h" class BakedLightmapEditorPlugin : public EditorPlugin { - GDCLASS(BakedLightmapEditorPlugin, EditorPlugin); BakedLightmap *lightmap; diff --git a/editor/plugins/camera_3d_editor_plugin.cpp b/editor/plugins/camera_3d_editor_plugin.cpp index 8bc1374269..48f9f208a5 100644 --- a/editor/plugins/camera_3d_editor_plugin.cpp +++ b/editor/plugins/camera_3d_editor_plugin.cpp @@ -33,7 +33,6 @@ #include "node_3d_editor_plugin.h" void Camera3DEditor::_node_removed(Node *p_node) { - if (p_node == node) { node = nullptr; Node3DEditor::get_singleton()->set_custom_camera(nullptr); @@ -42,7 +41,6 @@ void Camera3DEditor::_node_removed(Node *p_node) { } void Camera3DEditor::_pressed() { - Node *sn = (node && preview->is_pressed()) ? node : nullptr; Node3DEditor::get_singleton()->set_custom_camera(sn); } @@ -51,23 +49,21 @@ void Camera3DEditor::_bind_methods() { } void Camera3DEditor::edit(Node *p_camera) { - node = p_camera; if (!node) { preview->set_pressed(false); Node3DEditor::get_singleton()->set_custom_camera(nullptr); } else { - - if (preview->is_pressed()) + if (preview->is_pressed()) { Node3DEditor::get_singleton()->set_custom_camera(p_camera); - else + } else { Node3DEditor::get_singleton()->set_custom_camera(nullptr); + } } } Camera3DEditor::Camera3DEditor() { - preview = memnew(Button); add_child(preview); @@ -83,18 +79,15 @@ Camera3DEditor::Camera3DEditor() { } void Camera3DEditorPlugin::edit(Object *p_object) { - Node3DEditor::get_singleton()->set_can_preview(Object::cast_to<Camera3D>(p_object)); //camera_editor->edit(Object::cast_to<Node>(p_object)); } bool Camera3DEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("Camera3D"); } void Camera3DEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { //Node3DEditor::get_singleton()->set_can_preview(Object::cast_to<Camera3D>(p_object)); } else { @@ -103,7 +96,6 @@ void Camera3DEditorPlugin::make_visible(bool p_visible) { } Camera3DEditorPlugin::Camera3DEditorPlugin(EditorNode *p_node) { - editor = p_node; /* camera_editor = memnew( CameraEditor ); editor->get_viewport()->add_child(camera_editor); diff --git a/editor/plugins/camera_3d_editor_plugin.h b/editor/plugins/camera_3d_editor_plugin.h index 1e57ac7cd2..2603229a46 100644 --- a/editor/plugins/camera_3d_editor_plugin.h +++ b/editor/plugins/camera_3d_editor_plugin.h @@ -36,7 +36,6 @@ #include "scene/3d/camera_3d.h" class Camera3DEditor : public Control { - GDCLASS(Camera3DEditor, Control); Panel *panel; @@ -55,7 +54,6 @@ public: }; class Camera3DEditorPlugin : public EditorPlugin { - GDCLASS(Camera3DEditorPlugin, EditorPlugin); //CameraEditor *camera_editor; diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index b5fcf82d76..744c7907af 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -61,7 +61,6 @@ #define MOVE_HANDLE_DISTANCE 25 class SnapDialog : public ConfirmationDialog { - GDCLASS(SnapDialog, ConfirmationDialog); friend class CanvasItemEditor; @@ -252,7 +251,6 @@ void CanvasItemEditor::_snap_if_closer_float( float &r_current_snap, SnapTarget &r_current_snap_target, float p_target_value, SnapTarget p_snap_target, float p_radius) { - float radius = p_radius / zoom; float dist = Math::abs(p_value - p_target_value); if ((p_radius < 0 || dist < radius) && (r_current_snap_target == SNAP_TARGET_NONE || dist < Math::abs(r_current_snap - p_value))) { @@ -267,7 +265,6 @@ void CanvasItemEditor::_snap_if_closer_point( Point2 p_target_value, SnapTarget p_snap_target, real_t rotation, float p_radius) { - Transform2D rot_trans = Transform2D(rotation, Point2()); p_value = rot_trans.inverse().xform(p_value); p_target_value = rot_trans.inverse().xform(p_target_value); @@ -330,7 +327,6 @@ void CanvasItemEditor::_snap_other_nodes( } Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, unsigned int p_forced_modes, const CanvasItem *p_self_canvas_item, List<CanvasItem *> p_other_nodes_exceptions) { - snap_target[0] = SNAP_TARGET_NONE; snap_target[1] = SNAP_TARGET_NONE; @@ -474,11 +470,11 @@ float CanvasItemEditor::snap_angle(float p_target, float p_start) const { } void CanvasItemEditor::_unhandled_key_input(const Ref<InputEvent> &p_ev) { - Ref<InputEventKey> k = p_ev; - if (!is_visible_in_tree()) + if (!is_visible_in_tree()) { return; + } if (k->get_keycode() == KEY_CONTROL || k->get_keycode() == KEY_ALT || k->get_keycode() == KEY_SHIFT) { viewport->update(); @@ -492,28 +488,29 @@ void CanvasItemEditor::_unhandled_key_input(const Ref<InputEvent> &p_ev) { } else if ((grid_snap_active || show_grid) && divide_grid_step_shortcut.is_valid() && divide_grid_step_shortcut->is_shortcut(p_ev)) { // Divide the grid size Point2 new_grid_step = grid_step * Math::pow(2.0, grid_step_multiplier - 1); - if (new_grid_step.x >= 1.0 && new_grid_step.y >= 1.0) + if (new_grid_step.x >= 1.0 && new_grid_step.y >= 1.0) { grid_step_multiplier--; + } viewport->update(); } } } Object *CanvasItemEditor::_get_editor_data(Object *p_what) { - CanvasItem *ci = Object::cast_to<CanvasItem>(p_what); - if (!ci) + if (!ci) { return nullptr; + } return memnew(CanvasItemEditorSelectedItem); } void CanvasItemEditor::_keying_changed() { - - if (AnimationPlayerEditor::singleton->get_track_editor()->is_visible_in_tree()) + if (AnimationPlayerEditor::singleton->get_track_editor()->is_visible_in_tree()) { animation_hb->show(); - else + } else { animation_hb->hide(); + } } Rect2 CanvasItemEditor::_get_encompassing_rect_from_list(List<CanvasItem *> p_list) { @@ -539,10 +536,12 @@ Rect2 CanvasItemEditor::_get_encompassing_rect_from_list(List<CanvasItem *> p_li } void CanvasItemEditor::_expand_encompassing_rect_using_children(Rect2 &r_rect, const Node *p_node, bool &r_first, const Transform2D &p_parent_xform, const Transform2D &p_canvas_xform, bool include_locked_nodes) { - if (!p_node) + if (!p_node) { return; - if (Object::cast_to<Viewport>(p_node)) + } + if (Object::cast_to<Viewport>(p_node)) { return; + } const CanvasItem *canvas_item = Object::cast_to<CanvasItem>(p_node); @@ -578,10 +577,12 @@ Rect2 CanvasItemEditor::_get_encompassing_rect(const Node *p_node) { } void CanvasItemEditor::_find_canvas_items_at_pos(const Point2 &p_pos, Node *p_node, Vector<_SelectResult> &r_items, const Transform2D &p_parent_xform, const Transform2D &p_canvas_xform) { - if (!p_node) + if (!p_node) { return; - if (Object::cast_to<Viewport>(p_node)) + } + if (Object::cast_to<Viewport>(p_node)) { return; + } const real_t grab_distance = EDITOR_GET("editors/poly_editor/point_grab_radius"); CanvasItem *canvas_item = Object::cast_to<CanvasItem>(p_node); @@ -615,7 +616,6 @@ void CanvasItemEditor::_find_canvas_items_at_pos(const Point2 &p_pos, Node *p_no } void CanvasItemEditor::_get_canvas_items_at_pos(const Point2 &p_pos, Vector<_SelectResult> &r_items, bool p_allow_locked) { - Node *scene = editor->get_edited_scene(); _find_canvas_items_at_pos(p_pos, scene, r_items); @@ -667,8 +667,9 @@ void CanvasItemEditor::_get_bones_at_pos(const Point2 &p_pos, Vector<_SelectResu Node2D *from_node = Object::cast_to<Node2D>(ObjectDB::get_instance(E->key().from)); Vector<Vector2> bone_shape; - if (!_get_bone_shape(&bone_shape, nullptr, E)) + if (!_get_bone_shape(&bone_shape, nullptr, E)) { continue; + } // Check if the point is inside the Polygon2D if (Geometry::is_point_in_polygon(screen_pos, bone_shape)) { @@ -680,8 +681,9 @@ void CanvasItemEditor::_get_bones_at_pos(const Point2 &p_pos, Vector<_SelectResu break; } } - if (duplicate) + if (duplicate) { continue; + } // Else, add it _SelectResult res; @@ -700,21 +702,25 @@ bool CanvasItemEditor::_get_bone_shape(Vector<Vector2> *shape, Vector<Vector2> * Node2D *from_node = Object::cast_to<Node2D>(ObjectDB::get_instance(bone->key().from)); Node2D *to_node = Object::cast_to<Node2D>(ObjectDB::get_instance(bone->key().to)); - if (!from_node) + if (!from_node) { return false; - if (!from_node->is_inside_tree()) + } + if (!from_node->is_inside_tree()) { return false; //may have been removed + } - if (!to_node && bone->get().length == 0) + if (!to_node && bone->get().length == 0) { return false; + } Vector2 from = transform.xform(from_node->get_global_position()); Vector2 to; - if (to_node) + if (to_node) { to = transform.xform(to_node->get_global_position()); - else + } else { to = transform.xform(from_node->get_global_transform().xform(Vector2(bone->get().length, 0))); + } Vector2 rel = to - from; Vector2 relt = rel.tangent().normalized() * bone_width; @@ -742,10 +748,12 @@ bool CanvasItemEditor::_get_bone_shape(Vector<Vector2> *shape, Vector<Vector2> * } void CanvasItemEditor::_find_canvas_items_in_rect(const Rect2 &p_rect, Node *p_node, List<CanvasItem *> *r_items, const Transform2D &p_parent_xform, const Transform2D &p_canvas_xform) { - if (!p_node) + if (!p_node) { return; - if (Object::cast_to<Viewport>(p_node)) + } + if (Object::cast_to<Viewport>(p_node)) { return; + } CanvasItem *canvas_item = Object::cast_to<CanvasItem>(p_node); Node *scene = editor->get_edited_scene(); @@ -778,7 +786,6 @@ void CanvasItemEditor::_find_canvas_items_in_rect(const Rect2 &p_rect, Node *p_n p_rect.has_point(xform.xform(rect.position + Vector2(rect.size.x, 0))) && p_rect.has_point(xform.xform(rect.position + Vector2(rect.size.x, rect.size.y))) && p_rect.has_point(xform.xform(rect.position + Vector2(0, rect.size.y)))) { - r_items->push_back(canvas_item); } } else { @@ -861,10 +868,12 @@ Vector2 CanvasItemEditor::_position_to_anchor(const Control *p_control, Vector2 } void CanvasItemEditor::_save_canvas_item_ik_chain(const CanvasItem *p_canvas_item, List<float> *p_bones_length, List<Dictionary> *p_bones_state) { - if (p_bones_length) + if (p_bones_length) { *p_bones_length = List<float>(); - if (p_bones_state) + } + if (p_bones_state) { *p_bones_state = List<Dictionary>(); + } const Node2D *bone = Object::cast_to<Node2D>(p_canvas_item); if (bone && bone->has_meta("_edit_bone_")) { @@ -890,10 +899,12 @@ void CanvasItemEditor::_save_canvas_item_ik_chain(const CanvasItem *p_canvas_ite for (List<const Node2D *>::Element *bone_E = bone_ik_list.front(); bone_E; bone_E = bone_E->next()) { bone_xform = bone_xform * bone->get_transform().affine_inverse(); const Node2D *parent_bone = bone_E->get(); - if (p_bones_length) + if (p_bones_length) { p_bones_length->push_back(parent_bone->get_global_transform().get_origin().distance_to(bone->get_global_position())); - if (p_bones_state) + } + if (p_bones_state) { p_bones_state->push_back(parent_bone->_edit_get_state()); + } bone = parent_bone; } } @@ -965,18 +976,18 @@ void CanvasItemEditor::_snap_changed() { } void CanvasItemEditor::_selection_result_pressed(int p_result) { - - if (selection_results.size() <= p_result) + if (selection_results.size() <= p_result) { return; + } CanvasItem *item = selection_results[p_result].item; - if (item) + if (item) { _select_click_on_item(item, Point2(), selection_menu_additive_selection); + } } void CanvasItemEditor::_selection_menu_hide() { - selection_results.clear(); selection_menu->clear(); selection_menu->set_size(Vector2(0, 0)); @@ -1027,7 +1038,6 @@ bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref<InputEvent> &p_eve // Start dragging a guide if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && b->is_pressed()) { - // Press button if (b->get_position().x < RULER_WIDTH && b->get_position().y < RULER_WIDTH) { // Drag a new double guide @@ -1274,8 +1284,9 @@ bool CanvasItemEditor::_gui_input_zoom_or_pan(const Ref<InputEvent> &p_event, bo } } - if (is_pan_key) + if (is_pan_key) { pan_pressed = k->is_pressed(); + } } Ref<InputEventMouseMotion> m = p_event; @@ -1362,10 +1373,11 @@ bool CanvasItemEditor::_gui_input_pivot(const Ref<InputEvent> &p_event) { drag_to = transform.affine_inverse().xform(m->get_position()); _restore_canvas_item_state(drag_selection); Vector2 new_pos; - if (drag_selection.size() == 1) + if (drag_selection.size() == 1) { new_pos = snap_point(drag_to, SNAP_NODE_SIDES | SNAP_NODE_CENTER | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, 0, drag_selection[0]); - else + } else { new_pos = snap_point(drag_to, SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL); + } for (List<CanvasItem *>::Element *E = drag_selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get(); canvas_item->_edit_set_pivot(canvas_item->get_global_transform_with_canvas().affine_inverse().xform(new_pos)); @@ -1397,7 +1409,6 @@ void CanvasItemEditor::_solve_IK(Node2D *leaf_node, Point2 target_position) { if (se) { int nb_bones = se->pre_drag_bones_undo_state.size(); if (nb_bones > 0) { - // Build the node list Point2 leaf_pos = target_position; @@ -1475,8 +1486,9 @@ bool CanvasItemEditor::_gui_input_rotate(const Ref<InputEvent> &p_event) { // Remove not movable nodes for (List<CanvasItem *>::Element *E = selection.front(); E; E = E->next()) { - if (!_is_node_movable(E->get(), true)) + if (!_is_node_movable(E->get(), true)) { selection.erase(E); + } } drag_selection = selection; @@ -1624,28 +1636,36 @@ bool CanvasItemEditor::_gui_input_anchors(const Ref<InputEvent> &p_event) { switch (drag_type) { case DRAG_ANCHOR_TOP_LEFT: - if (!use_single_axis || !use_y) + if (!use_single_axis || !use_y) { control->set_anchor(MARGIN_LEFT, new_anchor.x, false, false); - if (!use_single_axis || use_y) + } + if (!use_single_axis || use_y) { control->set_anchor(MARGIN_TOP, new_anchor.y, false, false); + } break; case DRAG_ANCHOR_TOP_RIGHT: - if (!use_single_axis || !use_y) + if (!use_single_axis || !use_y) { control->set_anchor(MARGIN_RIGHT, new_anchor.x, false, false); - if (!use_single_axis || use_y) + } + if (!use_single_axis || use_y) { control->set_anchor(MARGIN_TOP, new_anchor.y, false, false); + } break; case DRAG_ANCHOR_BOTTOM_RIGHT: - if (!use_single_axis || !use_y) + if (!use_single_axis || !use_y) { control->set_anchor(MARGIN_RIGHT, new_anchor.x, false, false); - if (!use_single_axis || use_y) + } + if (!use_single_axis || use_y) { control->set_anchor(MARGIN_BOTTOM, new_anchor.y, false, false); + } break; case DRAG_ANCHOR_BOTTOM_LEFT: - if (!use_single_axis || !use_y) + if (!use_single_axis || !use_y) { control->set_anchor(MARGIN_LEFT, new_anchor.x, false, false); - if (!use_single_axis || use_y) + } + if (!use_single_axis || use_y) { control->set_anchor(MARGIN_BOTTOM, new_anchor.y, false, false); + } break; case DRAG_ANCHOR_ALL: if (!use_single_axis || !use_y) { @@ -1723,13 +1743,15 @@ bool CanvasItemEditor::_gui_input_resize(const Ref<InputEvent> &p_event) { Vector2 ofs = ((endpoints[i] - endpoints[prev]).normalized() + ((endpoints[i] - endpoints[next]).normalized())).normalized(); ofs *= (select_handle->get_size().width / 2); ofs += endpoints[i]; - if (ofs.distance_to(b->get_position()) < radius) + if (ofs.distance_to(b->get_position()) < radius) { resize_drag = dragger[i * 2]; + } ofs = (endpoints[i] + endpoints[next]) / 2; ofs += (endpoints[next] - endpoints[i]).tangent().normalized() * (select_handle->get_size().width / 2); - if (ofs.distance_to(b->get_position()) < radius) + if (ofs.distance_to(b->get_position()) < radius) { resize_drag = dragger[i * 2 + 1]; + } } if (resize_drag != DRAG_NONE) { @@ -1866,7 +1888,6 @@ bool CanvasItemEditor::_gui_input_resize(const Ref<InputEvent> &p_event) { } bool CanvasItemEditor::_gui_input_scale(const Ref<InputEvent> &p_event) { - Ref<InputEventMouseButton> b = p_event; Ref<InputEventMouseMotion> m = p_event; @@ -1878,7 +1899,6 @@ bool CanvasItemEditor::_gui_input_scale(const Ref<InputEvent> &p_event) { CanvasItem *canvas_item = selection[0]; if (_is_node_movable(canvas_item)) { - Transform2D xform = transform * canvas_item->get_global_transform_with_canvas(); Transform2D unscaled_transform = (xform * canvas_item->get_transform().affine_inverse() * canvas_item->_edit_get_transform()).orthonormalized(); Transform2D simple_xform = viewport->get_transform() * unscaled_transform; @@ -2041,7 +2061,6 @@ bool CanvasItemEditor::_gui_input_move(const Ref<InputEvent> &p_event) { if (drag_type == DRAG_MOVE || drag_type == DRAG_MOVE_X || drag_type == DRAG_MOVE_Y) { // Move the nodes if (m.is_valid()) { - // Save the ik chain for reapplying before IK solve Vector<List<Dictionary>> all_bones_ik_states; for (List<CanvasItem *>::Element *E = drag_selection.front(); E; E = E->next()) { @@ -2143,7 +2162,6 @@ bool CanvasItemEditor::_gui_input_move(const Ref<InputEvent> &p_event) { } if (drag_selection.size() > 0) { - // Save the ik chain for reapplying before IK solve Vector<List<Dictionary>> all_bones_ik_states; for (List<CanvasItem *>::Element *E = drag_selection.front(); E; E = E->next()) { @@ -2158,20 +2176,23 @@ bool CanvasItemEditor::_gui_input_move(const Ref<InputEvent> &p_event) { bool move_local_base_rotated = k->get_control() || k->get_metakey(); Vector2 dir; - if (k->get_keycode() == KEY_UP) + if (k->get_keycode() == KEY_UP) { dir += Vector2(0, -1); - else if (k->get_keycode() == KEY_DOWN) + } else if (k->get_keycode() == KEY_DOWN) { dir += Vector2(0, 1); - else if (k->get_keycode() == KEY_LEFT) + } else if (k->get_keycode() == KEY_LEFT) { dir += Vector2(-1, 0); - else if (k->get_keycode() == KEY_RIGHT) + } else if (k->get_keycode() == KEY_RIGHT) { dir += Vector2(1, 0); - if (k->get_shift()) + } + if (k->get_shift()) { dir *= grid_step * Math::pow(2.0, grid_step_multiplier); + } drag_to += dir; - if (k->get_shift()) + if (k->get_shift()) { drag_to = drag_to.snapped(grid_step * Math::pow(2.0, grid_step_multiplier)); + } Point2 previous_pos; if (drag_selection.size() == 1) { @@ -2310,8 +2331,9 @@ bool CanvasItemEditor::_gui_input_select(const Ref<InputEvent> &p_event) { Point2 click = transform.affine_inverse().xform(b->get_position()); Node *scene = editor->get_edited_scene(); - if (!scene) + if (!scene) { return true; + } // Find the item to select CanvasItem *canvas_item = nullptr; @@ -2379,10 +2401,12 @@ bool CanvasItemEditor::_gui_input_select(const Ref<InputEvent> &p_event) { Point2 bsfrom = drag_from; Point2 bsto = box_selecting_to; - if (bsfrom.x > bsto.x) + if (bsfrom.x > bsto.x) { SWAP(bsfrom.x, bsto.x); - if (bsfrom.y > bsto.y) + } + if (bsfrom.y > bsto.y) { SWAP(bsfrom.y, bsto.y); + } _find_canvas_items_in_rect(Rect2(bsfrom, bsto - bsfrom), scene, &selitems); for (List<CanvasItem *>::Element *E = selitems.front(); E; E = E->next()) { @@ -2419,16 +2443,17 @@ bool CanvasItemEditor::_gui_input_select(const Ref<InputEvent> &p_event) { } bool CanvasItemEditor::_gui_input_ruler_tool(const Ref<InputEvent> &p_event) { - - if (tool != TOOL_RULER) + if (tool != TOOL_RULER) { return false; + } Ref<InputEventMouseButton> b = p_event; Ref<InputEventMouseMotion> m = p_event; Point2 previous_origin = ruler_tool_origin; - if (!ruler_tool_active) + if (!ruler_tool_active) { ruler_tool_origin = snap_point(viewport->get_local_mouse_position() / zoom + view_offset); + } if (b.is_valid() && b->get_button_index() == BUTTON_LEFT) { if (b->is_pressed()) { @@ -2442,7 +2467,6 @@ bool CanvasItemEditor::_gui_input_ruler_tool(const Ref<InputEvent> &p_event) { } if (m.is_valid() && (ruler_tool_active || (grid_snap_active && previous_origin != ruler_tool_origin))) { - viewport->update(); return true; } @@ -2451,7 +2475,6 @@ bool CanvasItemEditor::_gui_input_ruler_tool(const Ref<InputEvent> &p_event) { } bool CanvasItemEditor::_gui_input_hover(const Ref<InputEvent> &p_event) { - Ref<InputEventMouseMotion> m = p_event; if (m.is_valid()) { Point2 click = transform.affine_inverse().xform(m->get_position()); @@ -2466,8 +2489,9 @@ bool CanvasItemEditor::_gui_input_hover(const Ref<InputEvent> &p_event) { for (int i = 0; i < hovering_results_items.size(); i++) { CanvasItem *canvas_item = hovering_results_items[i].item; - if (canvas_item->_edit_use_rect()) + if (canvas_item->_edit_use_rect()) { continue; + } _HoverResult hover_result; hover_result.position = canvas_item->get_global_transform_with_canvas().get_origin(); @@ -2536,8 +2560,9 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) { accepted = (_gui_input_zoom_or_pan(p_event, accepted) || accepted); - if (accepted) + if (accepted) { accept_event(); + } // Handles the mouse hovering _gui_input_hover(p_event); @@ -2589,10 +2614,11 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) { break; } - if (is_hovering_h_guide) + if (is_hovering_h_guide) { c = CURSOR_VSIZE; - else if (is_hovering_v_guide) + } else if (is_hovering_v_guide) { c = CURSOR_HSIZE; + } viewport->set_default_cursor_shape(c); @@ -2646,7 +2672,6 @@ void CanvasItemEditor::_draw_focus() { } void CanvasItemEditor::_draw_guides() { - Color guide_color = EditorSettings::get_singleton()->get("editors/2d/guides_color"); Transform2D xform = viewport_scrollable->get_transform() * transform; @@ -2654,8 +2679,9 @@ void CanvasItemEditor::_draw_guides() { if (EditorNode::get_singleton()->get_edited_scene() && EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_vertical_guides_")) { Array vguides = EditorNode::get_singleton()->get_edited_scene()->get_meta("_edit_vertical_guides_"); for (int i = 0; i < vguides.size(); i++) { - if (drag_type == DRAG_V_GUIDE && i == dragged_guide_index) + if (drag_type == DRAG_V_GUIDE && i == dragged_guide_index) { continue; + } float x = xform.xform(Point2(vguides[i], 0)).x; viewport->draw_line(Point2(x, 0), Point2(x, viewport->get_size().y), guide_color, Math::round(EDSCALE)); } @@ -2664,8 +2690,9 @@ void CanvasItemEditor::_draw_guides() { if (EditorNode::get_singleton()->get_edited_scene() && EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_horizontal_guides_")) { Array hguides = EditorNode::get_singleton()->get_edited_scene()->get_meta("_edit_horizontal_guides_"); for (int i = 0; i < hguides.size(); i++) { - if (drag_type == DRAG_H_GUIDE && i == dragged_guide_index) + if (drag_type == DRAG_H_GUIDE && i == dragged_guide_index) { continue; + } float y = xform.xform(Point2(0, hguides[i])).y; viewport->draw_line(Point2(0, y), Point2(viewport->get_size().x, y), guide_color, Math::round(EDSCALE)); } @@ -2793,7 +2820,6 @@ void CanvasItemEditor::_draw_rulers() { } void CanvasItemEditor::_draw_grid() { - if (show_grid || grid_snap_active) { // Draw the grid Vector2 real_grid_offset; @@ -2866,9 +2892,9 @@ void CanvasItemEditor::_draw_grid() { } void CanvasItemEditor::_draw_ruler_tool() { - - if (tool != TOOL_RULER) + if (tool != TOOL_RULER) { return; + } if (ruler_tool_active) { Color ruler_primary_color = get_theme_color("accent_color", "Editor"); @@ -2967,7 +2993,6 @@ void CanvasItemEditor::_draw_ruler_tool() { } if (grid_snap_active) { - text_pos = (begin + end) / 2 + Vector2(-text_width / 2, text_height / 2); text_pos.x = CLAMP(text_pos.x, text_width / 2, viewport->get_rect().size.x - text_width * 1.5); text_pos.y = CLAMP(text_pos.y, text_height * 2.5, viewport->get_rect().size.y - text_height / 2); @@ -2987,7 +3012,6 @@ void CanvasItemEditor::_draw_ruler_tool() { } } } else { - if (grid_snap_active) { Ref<Texture2D> position_icon = get_theme_icon("EditorPosition", "EditorIcons"); viewport->draw_texture(get_theme_icon("EditorPosition", "EditorIcons"), (ruler_tool_origin - view_offset) * zoom - position_icon->get_size() / 2); @@ -2999,7 +3023,6 @@ void CanvasItemEditor::_draw_control_anchors(Control *control) { Transform2D xform = transform * control->get_global_transform_with_canvas(); RID ci = viewport->get_canvas_item(); if (tool == TOOL_SELECT && !Object::cast_to<Container>(control->get_parent())) { - // Compute the anchors float anchors_values[4]; anchors_values[0] = control->get_anchor(MARGIN_LEFT); @@ -3264,7 +3287,6 @@ void CanvasItemEditor::_draw_selection() { viewport->draw_line(endpoints[i], endpoints[(i + 1) % 4], c, Math::round(2 * EDSCALE)); } } else { - Transform2D unscaled_transform = (xform * canvas_item->get_transform().affine_inverse() * canvas_item->_edit_get_transform()).orthonormalized(); Transform2D simple_xform = viewport->get_transform() * unscaled_transform; viewport->draw_set_transform_matrix(simple_xform); @@ -3275,7 +3297,6 @@ void CanvasItemEditor::_draw_selection() { if (single && !item_locked && (tool == TOOL_SELECT || tool == TOOL_MOVE || tool == TOOL_SCALE || tool == TOOL_ROTATE || tool == TOOL_EDIT_PIVOT)) { //kind of sucks // Draw the pivot if (canvas_item->_edit_use_pivot()) { - // Draw the node's pivot Transform2D unscaled_transform = (xform * canvas_item->get_transform().affine_inverse() * canvas_item->_edit_get_transform()).orthonormalized(); Transform2D simple_xform = viewport->get_transform() * unscaled_transform; @@ -3453,15 +3474,12 @@ void CanvasItemEditor::_draw_straight_line(Point2 p_from, Point2 p_to, Color p_c } void CanvasItemEditor::_draw_axis() { - if (show_origin) { - _draw_straight_line(Point2(), Point2(1, 0), get_theme_color("axis_x_color", "Editor") * Color(1, 1, 1, 0.75)); _draw_straight_line(Point2(), Point2(0, 1), get_theme_color("axis_y_color", "Editor") * Color(1, 1, 1, 0.75)); } if (show_viewport) { - RID ci = viewport->get_canvas_item(); Color area_axis_color = EditorSettings::get_singleton()->get("editors/2d/viewport_border_color"); @@ -3492,15 +3510,16 @@ void CanvasItemEditor::_draw_bones() { Color bone_selected_color = EditorSettings::get_singleton()->get("editors/2d/bone_selected_color"); for (Map<BoneKey, BoneList>::Element *E = bone_list.front(); E; E = E->next()) { - Vector<Vector2> bone_shape; Vector<Vector2> bone_shape_outline; - if (!_get_bone_shape(&bone_shape, &bone_shape_outline, E)) + if (!_get_bone_shape(&bone_shape, &bone_shape_outline, E)) { continue; + } Node2D *from_node = Object::cast_to<Node2D>(ObjectDB::get_instance(E->key().from)); - if (!from_node->is_visible_in_tree()) + if (!from_node->is_visible_in_tree()) { continue; + } Vector<Color> colors; if (from_node->has_meta("_edit_ik_")) { @@ -3543,11 +3562,13 @@ void CanvasItemEditor::_draw_invisible_nodes_positions(Node *p_node, const Trans ERR_FAIL_COND(!p_node); Node *scene = editor->get_edited_scene(); - if (p_node != scene && p_node->get_owner() != scene && !scene->is_editable_instance(p_node->get_owner())) + if (p_node != scene && p_node->get_owner() != scene && !scene->is_editable_instance(p_node->get_owner())) { return; + } CanvasItem *canvas_item = Object::cast_to<CanvasItem>(p_node); - if (canvas_item && !canvas_item->is_visible()) + if (canvas_item && !canvas_item->is_visible()) { return; + } Transform2D parent_xform = p_parent_xform; Transform2D canvas_xform = p_canvas_xform; @@ -3581,7 +3602,6 @@ void CanvasItemEditor::_draw_hover() { List<Rect2> previous_rects; for (int i = 0; i < hovering_results.size(); i++) { - Ref<Texture2D> node_icon = hovering_results[i].icon; String node_name = hovering_results[i].name; @@ -3611,11 +3631,13 @@ void CanvasItemEditor::_draw_locks_and_groups(Node *p_node, const Transform2D &p ERR_FAIL_COND(!p_node); Node *scene = editor->get_edited_scene(); - if (p_node != scene && p_node->get_owner() != scene && !scene->is_editable_instance(p_node->get_owner())) + if (p_node != scene && p_node->get_owner() != scene && !scene->is_editable_instance(p_node->get_owner())) { return; + } CanvasItem *canvas_item = Object::cast_to<CanvasItem>(p_node); - if (canvas_item && !canvas_item->is_visible()) + if (canvas_item && !canvas_item->is_visible()) { return; + } Transform2D parent_xform = p_parent_xform; Transform2D canvas_xform = p_canvas_xform; @@ -3717,7 +3739,6 @@ bool CanvasItemEditor::_build_bones_list(Node *p_node) { } void CanvasItemEditor::_draw_viewport() { - // Update the transform transform = Transform2D(); transform.scale_basis(Size2(zoom, zoom)); @@ -3777,10 +3798,12 @@ void CanvasItemEditor::_draw_viewport() { } _draw_bones(); - if (show_rulers) + if (show_rulers) { _draw_rulers(); - if (show_guides) + } + if (show_guides) { _draw_guides(); + } _draw_smart_snapping(); _draw_focus(); _draw_hover(); @@ -3796,7 +3819,6 @@ void CanvasItemEditor::set_current_tool(Tool p_tool) { } 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")); @@ -3882,10 +3904,8 @@ void CanvasItemEditor::_notification(int p_what) { // Update the viewport if bones changes for (Map<BoneKey, BoneList>::Element *E = bone_list.front(); E; E = E->next()) { - Object *b = ObjectDB::get_instance(E->key().from); if (!b) { - viewport->update(); break; } @@ -3898,14 +3918,12 @@ void CanvasItemEditor::_notification(int p_what) { Transform2D global_xform = b2->get_global_transform(); if (global_xform != E->get().xform) { - E->get().xform = global_xform; viewport->update(); } Bone2D *bone = Object::cast_to<Bone2D>(b); if (bone && bone->get_default_length() != E->get().length) { - E->get().length = bone->get_default_length(); viewport->update(); } @@ -3913,7 +3931,6 @@ void CanvasItemEditor::_notification(int p_what) { } if (p_what == NOTIFICATION_ENTER_TREE) { - select_sb->set_texture(get_theme_icon("EditorRect2D", "EditorIcons")); for (int i = 0; i < 4; i++) { select_sb->set_margin_size(Margin(i), 4); @@ -3926,7 +3943,6 @@ void CanvasItemEditor::_notification(int p_what) { get_tree()->connect("node_removed", callable_mp(this, &CanvasItemEditor::_tree_changed), varray()); } else if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { - select_sb->set_texture(get_theme_icon("EditorRect2D", "EditorIcons")); } @@ -4034,10 +4050,12 @@ void CanvasItemEditor::_selection_changed() { List<Node *> selection = editor_selection->get_selected_node_list(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { Control *control = Object::cast_to<Control>(E->get()); - if (!control) + if (!control) { continue; - if (Object::cast_to<Container>(control->get_parent())) + } + if (Object::cast_to<Container>(control->get_parent())) { continue; + } nbValidControls++; if (control->has_meta("_edit_use_anchors_") && control->get_meta("_edit_use_anchors_")) { @@ -4054,7 +4072,6 @@ void CanvasItemEditor::_selection_changed() { } void CanvasItemEditor::edit(CanvasItem *p_canvas_item) { - Array selection = editor_selection->get_selected_nodes(); if (selection.size() != 1 || (Node *)selection[0] != p_canvas_item) { drag_type = DRAG_NONE; @@ -4066,16 +4083,15 @@ void CanvasItemEditor::edit(CanvasItem *p_canvas_item) { } void CanvasItemEditor::_queue_update_bone_list() { - - if (bone_list_dirty) + if (bone_list_dirty) { return; + } call_deferred("_update_bone_list"); bone_list_dirty = true; } void CanvasItemEditor::_update_bone_list() { - bone_last_frame++; if (editor->get_edited_scene()) { @@ -4107,7 +4123,6 @@ void CanvasItemEditor::_tree_changed(Node *) { } void CanvasItemEditor::_update_scrollbars() { - updating_scroll = true; // Move the zoom buttons. @@ -4225,9 +4240,9 @@ void CanvasItemEditor::_popup_warning_temporarily(Control *p_control, const floa } void CanvasItemEditor::_update_scroll(float) { - - if (updating_scroll) + if (updating_scroll) { return; + } view_offset.x = h_scroll->get_value(); view_offset.y = v_scroll->get_value(); @@ -4240,7 +4255,6 @@ void CanvasItemEditor::_set_anchors_and_margins_preset(Control::LayoutPreset p_p undo_redo->create_action(TTR("Change Anchors and Margins")); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Control *control = Object::cast_to<Control>(E->get()); if (control) { undo_redo->add_do_method(control, "set_anchors_preset", p_preset); @@ -4282,7 +4296,6 @@ void CanvasItemEditor::_set_anchors_and_margins_to_keep_ratio() { undo_redo->create_action(TTR("Change Anchors and Margins")); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Control *control = Object::cast_to<Control>(E->get()); if (control) { Point2 top_left_anchor = _position_to_anchor(control, Point2()); @@ -4310,7 +4323,6 @@ void CanvasItemEditor::_set_anchors_preset(Control::LayoutPreset p_preset) { undo_redo->create_action(TTR("Change Anchors")); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Control *control = Object::cast_to<Control>(E->get()); if (control) { undo_redo->add_do_method(control, "set_anchors_preset", p_preset); @@ -4322,8 +4334,9 @@ void CanvasItemEditor::_set_anchors_preset(Control::LayoutPreset p_preset) { } void CanvasItemEditor::_zoom_on_position(float p_zoom, Point2 p_position) { - if (p_zoom < MIN_ZOOM || p_zoom > MAX_ZOOM) + if (p_zoom < MIN_ZOOM || p_zoom > MAX_ZOOM) { return; + } float prev_zoom = zoom; zoom = p_zoom; @@ -4383,6 +4396,7 @@ void CanvasItemEditor::_button_toggle_grid_snap(bool p_status) { grid_snap_active = p_status; viewport->update(); } + void CanvasItemEditor::_button_override_camera(bool p_pressed) { EditorDebuggerNode *debugger = EditorDebuggerNode::get_singleton(); @@ -4394,7 +4408,6 @@ void CanvasItemEditor::_button_override_camera(bool p_pressed) { } void CanvasItemEditor::_button_tool_select(int p_index) { - ToolButton *tb[TOOL_MAX] = { select_button, list_select_button, move_button, scale_button, rotate_button, pivot_button, pan_button, ruler_button }; for (int i = 0; i < TOOL_MAX; i++) { tb[i]->set_pressed(i == p_index); @@ -4405,27 +4418,30 @@ void CanvasItemEditor::_button_tool_select(int p_index) { } void CanvasItemEditor::_insert_animation_keys(bool p_location, bool p_rotation, bool p_scale, bool p_on_existing) { - Map<Node *, Object *> &selection = editor_selection->get_selection(); for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) { - CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key()); - if (!canvas_item || !canvas_item->is_visible_in_tree()) + if (!canvas_item || !canvas_item->is_visible_in_tree()) { continue; + } - if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) { continue; + } if (Object::cast_to<Node2D>(canvas_item)) { Node2D *n2d = Object::cast_to<Node2D>(canvas_item); - if (key_pos && p_location) + if (key_pos && p_location) { AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(n2d, "position", n2d->get_position(), p_on_existing); - if (key_rot && p_rotation) + } + if (key_rot && p_rotation) { AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(n2d, "rotation_degrees", Math::rad2deg(n2d->get_rotation()), p_on_existing); - if (key_scale && p_scale) + } + if (key_scale && p_scale) { AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(n2d, "scale", n2d->get_scale(), p_on_existing); + } if (n2d->has_meta("_edit_bone_") && n2d->get_parent_item()) { //look for an IK chain @@ -4435,42 +4451,45 @@ void CanvasItemEditor::_insert_animation_keys(bool p_location, bool p_rotation, bool has_chain = false; while (n) { - ik_chain.push_back(n); if (n->has_meta("_edit_ik_")) { has_chain = true; break; } - if (!n->get_parent_item()) + if (!n->get_parent_item()) { break; + } n = Object::cast_to<Node2D>(n->get_parent_item()); } if (has_chain && ik_chain.size()) { - for (List<Node2D *>::Element *F = ik_chain.front(); F; F = F->next()) { - - if (key_pos) + if (key_pos) { AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(F->get(), "position", F->get()->get_position(), p_on_existing); - if (key_rot) + } + if (key_rot) { AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(F->get(), "rotation_degrees", Math::rad2deg(F->get()->get_rotation()), p_on_existing); - if (key_scale) + } + if (key_scale) { AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(F->get(), "scale", F->get()->get_scale(), p_on_existing); + } } } } } else if (Object::cast_to<Control>(canvas_item)) { - Control *ctrl = Object::cast_to<Control>(canvas_item); - if (key_pos) + if (key_pos) { AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(ctrl, "rect_position", ctrl->get_position(), p_on_existing); - if (key_rot) + } + if (key_rot) { AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(ctrl, "rect_rotation", ctrl->get_rotation_degrees(), p_on_existing); - if (key_scale) + } + if (key_scale) { AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(ctrl, "rect_size", ctrl->get_size(), p_on_existing); + } } } } @@ -4479,8 +4498,9 @@ void CanvasItemEditor::_button_toggle_anchor_mode(bool p_status) { List<CanvasItem *> selection = _get_edited_canvas_items(false, false); for (List<CanvasItem *>::Element *E = selection.front(); E; E = E->next()) { Control *control = Object::cast_to<Control>(E->get()); - if (!control || Object::cast_to<Container>(control->get_parent())) + if (!control || Object::cast_to<Container>(control->get_parent())) { continue; + } control->set_meta("_edit_use_anchors_", p_status); } @@ -4619,10 +4639,12 @@ void CanvasItemEditor::_popup_callback(int p_op) { List<Node *> selection = editor_selection->get_selected_node_list(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get()); - if (!canvas_item || !canvas_item->is_inside_tree()) + if (!canvas_item || !canvas_item->is_inside_tree()) { continue; - if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) + } + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) { continue; + } undo_redo->add_do_method(canvas_item, "set_meta", "_edit_lock_", true); undo_redo->add_undo_method(canvas_item, "remove_meta", "_edit_lock_"); @@ -4639,10 +4661,12 @@ void CanvasItemEditor::_popup_callback(int p_op) { List<Node *> selection = editor_selection->get_selected_node_list(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get()); - if (!canvas_item || !canvas_item->is_inside_tree()) + if (!canvas_item || !canvas_item->is_inside_tree()) { continue; - if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) + } + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) { continue; + } undo_redo->add_do_method(canvas_item, "remove_meta", "_edit_lock_"); undo_redo->add_undo_method(canvas_item, "set_meta", "_edit_lock_", true); @@ -4659,10 +4683,12 @@ void CanvasItemEditor::_popup_callback(int p_op) { List<Node *> selection = editor_selection->get_selected_node_list(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get()); - if (!canvas_item || !canvas_item->is_inside_tree()) + if (!canvas_item || !canvas_item->is_inside_tree()) { continue; - if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) + } + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) { continue; + } undo_redo->add_do_method(canvas_item, "set_meta", "_edit_group_", true); undo_redo->add_undo_method(canvas_item, "remove_meta", "_edit_group_"); @@ -4679,10 +4705,12 @@ void CanvasItemEditor::_popup_callback(int p_op) { List<Node *> selection = editor_selection->get_selected_node_list(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get()); - if (!canvas_item || !canvas_item->is_inside_tree()) + if (!canvas_item || !canvas_item->is_inside_tree()) { continue; - if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) + } + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) { continue; + } undo_redo->add_do_method(canvas_item, "remove_meta", "_edit_group_"); undo_redo->add_undo_method(canvas_item, "set_meta", "_edit_group_", true); @@ -4796,41 +4824,36 @@ void CanvasItemEditor::_popup_callback(int p_op) { case ANIM_INSERT_KEY: case ANIM_INSERT_KEY_EXISTING: { - bool existing = p_op == ANIM_INSERT_KEY_EXISTING; _insert_animation_keys(true, true, true, existing); } break; case ANIM_INSERT_POS: { - key_pos = key_loc_button->is_pressed(); } break; case ANIM_INSERT_ROT: { - key_rot = key_rot_button->is_pressed(); } break; case ANIM_INSERT_SCALE: { - key_scale = key_scale_button->is_pressed(); } break; case ANIM_COPY_POSE: { - pose_clipboard.clear(); Map<Node *, Object *> &selection = editor_selection->get_selection(); for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) { - CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key()); - if (!canvas_item || !canvas_item->is_visible_in_tree()) + if (!canvas_item || !canvas_item->is_visible_in_tree()) { continue; + } - if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) { continue; + } if (Object::cast_to<Node2D>(canvas_item)) { - Node2D *n2d = Object::cast_to<Node2D>(canvas_item); PoseClipboard pc; pc.pos = n2d->get_position(); @@ -4843,16 +4866,16 @@ void CanvasItemEditor::_popup_callback(int p_op) { } break; case ANIM_PASTE_POSE: { - - if (!pose_clipboard.size()) + if (!pose_clipboard.size()) { break; + } undo_redo->create_action(TTR("Paste Pose")); for (List<PoseClipboard>::Element *E = pose_clipboard.front(); E; E = E->next()) { - Node2D *n2d = Object::cast_to<Node2D>(ObjectDB::get_instance(E->get().id)); - if (!n2d) + if (!n2d) { continue; + } undo_redo->add_do_method(n2d, "set_position", E->get().pos); undo_redo->add_do_method(n2d, "set_rotation", E->get().rot); undo_redo->add_do_method(n2d, "set_scale", E->get().scale); @@ -4864,33 +4887,36 @@ void CanvasItemEditor::_popup_callback(int p_op) { } break; case ANIM_CLEAR_POSE: { - Map<Node *, Object *> &selection = editor_selection->get_selection(); for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) { - CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key()); - if (!canvas_item || !canvas_item->is_visible_in_tree()) + if (!canvas_item || !canvas_item->is_visible_in_tree()) { continue; + } - if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) { continue; + } if (Object::cast_to<Node2D>(canvas_item)) { Node2D *n2d = Object::cast_to<Node2D>(canvas_item); - if (key_pos) + if (key_pos) { n2d->set_position(Vector2()); - if (key_rot) + } + if (key_rot) { n2d->set_rotation(0); - if (key_scale) + } + if (key_scale) { n2d->set_scale(Vector2(1, 1)); + } } else if (Object::cast_to<Control>(canvas_item)) { - Control *ctrl = Object::cast_to<Control>(canvas_item); - if (key_pos) + if (key_pos) { ctrl->set_position(Point2()); + } /* if (key_scale) AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(ctrl,"rect/size",ctrl->get_size()); @@ -4900,7 +4926,6 @@ void CanvasItemEditor::_popup_callback(int p_op) { } break; case CLEAR_GUIDES: { - Node *const root = EditorNode::get_singleton()->get_edited_scene(); if (root && (root->has_meta("_edit_horizontal_guides_") || root->has_meta("_edit_vertical_guides_"))) { @@ -4924,12 +4949,10 @@ void CanvasItemEditor::_popup_callback(int p_op) { } break; case VIEW_CENTER_TO_SELECTION: case VIEW_FRAME_TO_SELECTION: { - _focus_selection(p_op); } break; case PREVIEW_CANVAS_SCALE: { - bool preview = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(PREVIEW_CANVAS_SCALE)); preview = !preview; RS::get_singleton()->canvas_set_disable_scale(!preview); @@ -4937,21 +4960,23 @@ void CanvasItemEditor::_popup_callback(int p_op) { } break; case SKELETON_MAKE_BONES: { - Map<Node *, Object *> &selection = editor_selection->get_selection(); undo_redo->create_action(TTR("Create Custom Bone(s) from Node(s)")); for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) { - Node2D *n2d = Object::cast_to<Node2D>(E->key()); - if (!n2d) + if (!n2d) { continue; - if (!n2d->is_visible_in_tree()) + } + if (!n2d->is_visible_in_tree()) { continue; - if (!n2d->get_parent_item()) + } + if (!n2d->get_parent_item()) { continue; - if (n2d->has_meta("_edit_bone_") && n2d->get_meta("_edit_bone_")) + } + if (n2d->has_meta("_edit_bone_") && n2d->get_meta("_edit_bone_")) { continue; + } undo_redo->add_do_method(n2d, "set_meta", "_edit_bone_", true); undo_redo->add_undo_method(n2d, "remove_meta", "_edit_bone_"); @@ -4964,19 +4989,20 @@ void CanvasItemEditor::_popup_callback(int p_op) { } break; case SKELETON_CLEAR_BONES: { - Map<Node *, Object *> &selection = editor_selection->get_selection(); undo_redo->create_action(TTR("Clear Bones")); for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) { - Node2D *n2d = Object::cast_to<Node2D>(E->key()); - if (!n2d) + if (!n2d) { continue; - if (!n2d->is_visible_in_tree()) + } + if (!n2d->is_visible_in_tree()) { continue; - if (!n2d->has_meta("_edit_bone_")) + } + if (!n2d->has_meta("_edit_bone_")) { continue; + } undo_redo->add_do_method(n2d, "remove_meta", "_edit_bone_"); undo_redo->add_undo_method(n2d, "set_meta", "_edit_bone_", n2d->get_meta("_edit_bone_")); @@ -4989,19 +5015,20 @@ void CanvasItemEditor::_popup_callback(int p_op) { } break; case SKELETON_SET_IK_CHAIN: { - List<Node *> selection = editor_selection->get_selected_node_list(); undo_redo->create_action(TTR("Make IK Chain")); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get()); - if (!canvas_item || !canvas_item->is_visible_in_tree()) + if (!canvas_item || !canvas_item->is_visible_in_tree()) { continue; - if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) + } + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) { continue; - if (canvas_item->has_meta("_edit_ik_") && canvas_item->get_meta("_edit_ik_")) + } + if (canvas_item->has_meta("_edit_ik_") && canvas_item->get_meta("_edit_ik_")) { continue; + } undo_redo->add_do_method(canvas_item, "set_meta", "_edit_ik_", true); undo_redo->add_undo_method(canvas_item, "remove_meta", "_edit_ik_"); @@ -5012,19 +5039,20 @@ void CanvasItemEditor::_popup_callback(int p_op) { } break; case SKELETON_CLEAR_IK_CHAIN: { - Map<Node *, Object *> &selection = editor_selection->get_selection(); undo_redo->create_action(TTR("Clear IK Chain")); for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) { - CanvasItem *n2d = Object::cast_to<CanvasItem>(E->key()); - if (!n2d) + if (!n2d) { continue; - if (!n2d->is_visible_in_tree()) + } + if (!n2d->is_visible_in_tree()) { continue; - if (!n2d->has_meta("_edit_ik_")) + } + if (!n2d->has_meta("_edit_ik_")) { continue; + } undo_redo->add_do_method(n2d, "remove_meta", "_edit_ik_"); undo_redo->add_undo_method(n2d, "set_meta", "_edit_ik_", n2d->get_meta("_edit_ik_")); @@ -5045,10 +5073,12 @@ void CanvasItemEditor::_focus_selection(int p_op) { Map<Node *, Object *> &selection = editor_selection->get_selection(); for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key()); - if (!canvas_item) + if (!canvas_item) { continue; - if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) + } + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) { continue; + } // counting invisible items, for now //if (!canvas_item->is_visible_in_tree()) continue; @@ -5074,11 +5104,11 @@ void CanvasItemEditor::_focus_selection(int p_op) { rect = rect.merge(canvas_item_rect); } }; - if (count == 0) + if (count == 0) { return; + } if (p_op == VIEW_CENTER_TO_SELECTION) { - center = rect.position + rect.size / 2; Vector2 offset = viewport->get_size() / 2 - editor->get_scene_root()->get_global_canvas_transform().xform(center); view_offset.x -= Math::round(offset.x / zoom); @@ -5100,7 +5130,6 @@ void CanvasItemEditor::_focus_selection(int p_op) { } void CanvasItemEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_update_override_camera_button", "game_running"), &CanvasItemEditor::_update_override_camera_button); ClassDB::bind_method("_get_editor_data", &CanvasItemEditor::_get_editor_data); ClassDB::bind_method("_unhandled_key_input", &CanvasItemEditor::_unhandled_key_input); @@ -5114,7 +5143,6 @@ void CanvasItemEditor::_bind_methods() { } Dictionary CanvasItemEditor::get_state() const { - Dictionary state; // Take the editor scale into account. state["zoom"] = zoom / MAX(1, EDSCALE); @@ -5151,7 +5179,6 @@ Dictionary CanvasItemEditor::get_state() const { } void CanvasItemEditor::set_state(const Dictionary &p_state) { - bool update_scrollbars = false; Dictionary state = p_state; if (state.has("zoom")) { @@ -5336,7 +5363,6 @@ void CanvasItemEditor::add_control_to_info_overlay(Control *p_control) { } void CanvasItemEditor::remove_control_from_info_overlay(Control *p_control) { - info_overlay->remove_child(p_control); info_overlay->set_margin(MARGIN_LEFT, (show_rulers ? RULER_WIDTH : 0) + 10); } @@ -5348,17 +5374,14 @@ void CanvasItemEditor::add_control_to_menu_panel(Control *p_control) { } void CanvasItemEditor::remove_control_from_menu_panel(Control *p_control) { - hb->remove_child(p_control); } HSplitContainer *CanvasItemEditor::get_palette_split() { - return palette_split; } VSplitContainer *CanvasItemEditor::get_bottom_split() { - return bottom_split; } @@ -5367,7 +5390,6 @@ void CanvasItemEditor::focus_selection() { } CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { - key_pos = true; key_rot = true; key_scale = false; @@ -5826,25 +5848,21 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { CanvasItemEditor *CanvasItemEditor::singleton = nullptr; void CanvasItemEditorPlugin::edit(Object *p_object) { - canvas_item_editor->set_undo_redo(&get_undo_redo()); canvas_item_editor->edit(Object::cast_to<CanvasItem>(p_object)); } bool CanvasItemEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("CanvasItem"); } void CanvasItemEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { canvas_item_editor->show(); canvas_item_editor->set_physics_process(true); RenderingServer::get_singleton()->viewport_set_hide_canvas(editor->get_scene_root()->get_viewport_rid(), false); } else { - canvas_item_editor->hide(); canvas_item_editor->set_physics_process(false); RenderingServer::get_singleton()->viewport_set_hide_canvas(editor->get_scene_root()->get_viewport_rid(), true); @@ -5852,16 +5870,14 @@ void CanvasItemEditorPlugin::make_visible(bool p_visible) { } Dictionary CanvasItemEditorPlugin::get_state() const { - return canvas_item_editor->get_state(); } -void CanvasItemEditorPlugin::set_state(const Dictionary &p_state) { +void CanvasItemEditorPlugin::set_state(const Dictionary &p_state) { canvas_item_editor->set_state(p_state); } CanvasItemEditorPlugin::CanvasItemEditorPlugin(EditorNode *p_node) { - editor = p_node; canvas_item_editor = memnew(CanvasItemEditor(editor)); canvas_item_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL); @@ -5887,8 +5903,9 @@ void CanvasItemEditorViewport::_on_select_type(Object *selected) { } void CanvasItemEditorViewport::_on_change_type_confirmed() { - if (!button_group->get_pressed_button()) + if (!button_group->get_pressed_button()) { return; + } CheckBox *check = Object::cast_to<CheckBox>(button_group->get_pressed_button()); default_type = check->get_text(); @@ -5897,7 +5914,6 @@ void CanvasItemEditorViewport::_on_change_type_confirmed() { } void CanvasItemEditorViewport::_on_change_type_closed() { - _remove_preview(); } @@ -5929,8 +5945,9 @@ void CanvasItemEditorViewport::_create_preview(const Vector<String> &files) cons } } - if (add_preview) + if (add_preview) { editor->get_scene_root()->add_child(preview_node); + } } void CanvasItemEditorViewport::_remove_preview() { @@ -6104,20 +6121,21 @@ void CanvasItemEditorViewport::_perform_drop_data() { Ref<Texture2D> texture = Ref<Texture2D>(Object::cast_to<Texture2D>(*res)); if (texture != nullptr && texture.is_valid()) { Node *child; - if (default_type == "Light2D") + if (default_type == "Light2D") { child = memnew(Light2D); - else if (default_type == "GPUParticles2D") + } else if (default_type == "GPUParticles2D") { child = memnew(GPUParticles2D); - else if (default_type == "Polygon2D") + } else if (default_type == "Polygon2D") { child = memnew(Polygon2D); - else if (default_type == "TouchScreenButton") + } else if (default_type == "TouchScreenButton") { child = memnew(TouchScreenButton); - else if (default_type == "TextureRect") + } else if (default_type == "TextureRect") { child = memnew(TextureRect); - else if (default_type == "NinePatchRect") + } else if (default_type == "NinePatchRect") { child = memnew(NinePatchRect); - else + } else { child = memnew(Sprite2D); // default + } _create_nodes(target_node, child, path, drop_pos); } @@ -6203,7 +6221,6 @@ void CanvasItemEditorViewport::_show_resource_type_selector() { } bool CanvasItemEditorViewport::_only_packed_scenes_selected() const { - for (int i = 0; i < selected_files.size(); ++i) { if (ResourceLoader::load(selected_files[i])->get_class() != "PackedScene") { return false; @@ -6222,8 +6239,9 @@ void CanvasItemEditorViewport::drop_data(const Point2 &p_point, const Variant &p if (d.has("type") && String(d["type"]) == "files") { selected_files = d["files"]; } - if (selected_files.size() == 0) + if (selected_files.size() == 0) { return; + } List<Node *> list = editor->get_editor_selection()->get_selected_node_list(); if (list.size() == 0) { diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h index 77f23dfd6d..a686c98f65 100644 --- a/editor/plugins/canvas_item_editor_plugin.h +++ b/editor/plugins/canvas_item_editor_plugin.h @@ -43,7 +43,6 @@ class CanvasItemEditorViewport; class CanvasItemEditorSelectedItem : public Object { - GDCLASS(CanvasItemEditorSelectedItem, Object); public: @@ -65,7 +64,6 @@ public: }; class CanvasItemEditor : public VBoxContainer { - GDCLASS(CanvasItemEditor, VBoxContainer); public: @@ -290,7 +288,6 @@ private: MenuOption last_option; struct _SelectResult { - CanvasItem *item; float z_index; bool has_z; @@ -301,7 +298,6 @@ private: Vector<_SelectResult> selection_results; struct _HoverResult { - Point2 position; Ref<Texture2D> icon; String name; @@ -309,7 +305,6 @@ private: Vector<_HoverResult> hovering_results; struct BoneList { - Transform2D xform; float length = 0.f; uint64_t last_pass = 0; @@ -323,10 +318,11 @@ private: ObjectID from; ObjectID to; _FORCE_INLINE_ bool operator<(const BoneKey &p_key) const { - if (from == p_key.from) + if (from == p_key.from) { return to < p_key.to; - else + } else { return from < p_key.from; + } } }; @@ -646,7 +642,6 @@ public: }; class CanvasItemEditorPlugin : public EditorPlugin { - GDCLASS(CanvasItemEditorPlugin, EditorPlugin); CanvasItemEditor *canvas_item_editor; diff --git a/editor/plugins/collision_polygon_2d_editor_plugin.cpp b/editor/plugins/collision_polygon_2d_editor_plugin.cpp index 87e9987aa1..08d6fc966d 100644 --- a/editor/plugins/collision_polygon_2d_editor_plugin.cpp +++ b/editor/plugins/collision_polygon_2d_editor_plugin.cpp @@ -31,12 +31,10 @@ #include "collision_polygon_2d_editor_plugin.h" Node2D *CollisionPolygon2DEditor::_get_node() const { - return node; } void CollisionPolygon2DEditor::_set_node(Node *p_polygon) { - node = Object::cast_to<CollisionPolygon2D>(p_polygon); } diff --git a/editor/plugins/collision_polygon_2d_editor_plugin.h b/editor/plugins/collision_polygon_2d_editor_plugin.h index a4fa7c7b3b..b0be92db44 100644 --- a/editor/plugins/collision_polygon_2d_editor_plugin.h +++ b/editor/plugins/collision_polygon_2d_editor_plugin.h @@ -35,7 +35,6 @@ #include "scene/2d/collision_polygon_2d.h" class CollisionPolygon2DEditor : public AbstractPolygon2DEditor { - GDCLASS(CollisionPolygon2DEditor, AbstractPolygon2DEditor); CollisionPolygon2D *node; @@ -49,7 +48,6 @@ public: }; class CollisionPolygon2DEditorPlugin : public AbstractPolygon2DEditorPlugin { - GDCLASS(CollisionPolygon2DEditorPlugin, AbstractPolygon2DEditorPlugin); public: diff --git a/editor/plugins/collision_polygon_3d_editor_plugin.cpp b/editor/plugins/collision_polygon_3d_editor_plugin.cpp index 1cee1a040f..c61d410d38 100644 --- a/editor/plugins/collision_polygon_3d_editor_plugin.cpp +++ b/editor/plugins/collision_polygon_3d_editor_plugin.cpp @@ -39,11 +39,8 @@ #include "scene/3d/camera_3d.h" void CollisionPolygon3DEditor::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_READY: { - button_create->set_icon(get_theme_icon("Edit", "EditorIcons")); button_edit->set_icon(get_theme_icon("MovePoint", "EditorIcons")); button_edit->set_pressed(true); @@ -63,29 +60,26 @@ void CollisionPolygon3DEditor::_notification(int p_what) { } break; } } -void CollisionPolygon3DEditor::_node_removed(Node *p_node) { +void CollisionPolygon3DEditor::_node_removed(Node *p_node) { if (p_node == node) { node = nullptr; - if (imgeom->get_parent() == p_node) + if (imgeom->get_parent() == p_node) { p_node->remove_child(imgeom); + } hide(); set_process(false); } } void CollisionPolygon3DEditor::_menu_option(int p_option) { - switch (p_option) { - case MODE_CREATE: { - mode = MODE_CREATE; button_create->set_pressed(true); button_edit->set_pressed(false); } break; case MODE_EDIT: { - mode = MODE_EDIT; button_create->set_pressed(false); button_edit->set_pressed(true); @@ -94,7 +88,6 @@ void CollisionPolygon3DEditor::_menu_option(int p_option) { } void CollisionPolygon3DEditor::_wip_close() { - undo_redo->create_action(TTR("Create Polygon3D")); undo_redo->add_undo_method(node, "set_polygon", node->call("get_polygon")); undo_redo->add_do_method(node, "set_polygon", wip); @@ -110,9 +103,9 @@ void CollisionPolygon3DEditor::_wip_close() { } bool CollisionPolygon3DEditor::forward_spatial_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) { - - if (!node) + if (!node) { return false; + } Transform gt = node->get_global_transform(); Transform gi = gt.affine_inverse(); @@ -123,15 +116,15 @@ bool CollisionPolygon3DEditor::forward_spatial_gui_input(Camera3D *p_camera, con Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid()) { - Vector2 gpoint = mb->get_position(); Vector3 ray_from = p_camera->project_ray_origin(gpoint); Vector3 ray_dir = p_camera->project_ray_normal(gpoint); Vector3 spoint; - if (!p.intersects_ray(ray_from, ray_dir, &spoint)) + if (!p.intersects_ray(ray_from, ray_dir, &spoint)) { return false; + } spoint = gi.xform(spoint); @@ -147,13 +140,9 @@ bool CollisionPolygon3DEditor::forward_spatial_gui_input(Camera3D *p_camera, con real_t grab_threshold = EDITOR_GET("editors/poly_editor/point_grab_radius"); switch (mode) { - case MODE_CREATE: { - if (mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) { - if (!wip_active) { - wip.clear(); wip.push_back(cpoint); wip_active = true; @@ -163,14 +152,12 @@ bool CollisionPolygon3DEditor::forward_spatial_gui_input(Camera3D *p_camera, con edited_point = 1; return true; } else { - if (wip.size() > 1 && p_camera->unproject_position(gt.xform(Vector3(wip[0].x, wip[0].y, depth))).distance_to(gpoint) < grab_threshold) { //wip closed _wip_close(); return true; } else { - wip.push_back(cpoint); edited_point = wip.size(); snap_ignore = false; @@ -185,14 +172,10 @@ bool CollisionPolygon3DEditor::forward_spatial_gui_input(Camera3D *p_camera, con } break; case MODE_EDIT: { - if (mb->get_button_index() == BUTTON_LEFT) { if (mb->is_pressed()) { - if (mb->get_control()) { - if (poly.size() < 3) { - undo_redo->create_action(TTR("Edit Poly")); undo_redo->add_undo_method(node, "set_polygon", poly); poly.push_back(cpoint); @@ -208,15 +191,15 @@ bool CollisionPolygon3DEditor::forward_spatial_gui_input(Camera3D *p_camera, con Vector2 closest_pos; real_t closest_dist = 1e10; for (int i = 0; i < poly.size(); i++) { - Vector2 points[2] = { p_camera->unproject_position(gt.xform(Vector3(poly[i].x, poly[i].y, depth))), p_camera->unproject_position(gt.xform(Vector3(poly[(i + 1) % poly.size()].x, poly[(i + 1) % poly.size()].y, depth))) }; Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint, points); - if (cp.distance_squared_to(points[0]) < CMP_EPSILON2 || cp.distance_squared_to(points[1]) < CMP_EPSILON2) + if (cp.distance_squared_to(points[0]) < CMP_EPSILON2 || cp.distance_squared_to(points[1]) < CMP_EPSILON2) { continue; //not valid to reuse point + } real_t d = cp.distance_to(gpoint); if (d < closest_dist && d < grab_threshold) { @@ -227,7 +210,6 @@ bool CollisionPolygon3DEditor::forward_spatial_gui_input(Camera3D *p_camera, con } if (closest_idx >= 0) { - pre_move_edit = poly; poly.insert(closest_idx + 1, cpoint); edited_point = closest_idx + 1; @@ -239,14 +221,12 @@ bool CollisionPolygon3DEditor::forward_spatial_gui_input(Camera3D *p_camera, con return true; } } else { - //look for points to move int closest_idx = -1; Vector2 closest_pos; real_t closest_dist = 1e10; for (int i = 0; i < poly.size(); i++) { - Vector2 cp = p_camera->unproject_position(gt.xform(Vector3(poly[i].x, poly[i].y, depth))); real_t d = cp.distance_to(gpoint); @@ -258,7 +238,6 @@ bool CollisionPolygon3DEditor::forward_spatial_gui_input(Camera3D *p_camera, con } if (closest_idx >= 0) { - pre_move_edit = poly; edited_point = closest_idx; edited_point_pos = poly[closest_idx]; @@ -268,11 +247,9 @@ bool CollisionPolygon3DEditor::forward_spatial_gui_input(Camera3D *p_camera, con } } } else { - snap_ignore = false; if (edited_point != -1) { - //apply ERR_FAIL_INDEX_V(edited_point, poly.size(), false); @@ -290,12 +267,10 @@ bool CollisionPolygon3DEditor::forward_spatial_gui_input(Camera3D *p_camera, con } } if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed() && edited_point == -1) { - int closest_idx = -1; Vector2 closest_pos; real_t closest_dist = 1e10; for (int i = 0; i < poly.size(); i++) { - Vector2 cp = p_camera->unproject_position(gt.xform(Vector3(poly[i].x, poly[i].y, depth))); real_t d = cp.distance_to(gpoint); @@ -307,7 +282,6 @@ bool CollisionPolygon3DEditor::forward_spatial_gui_input(Camera3D *p_camera, con } if (closest_idx >= 0) { - undo_redo->create_action(TTR("Edit Poly (Remove Point)")); undo_redo->add_undo_method(node, "set_polygon", poly); poly.remove(closest_idx); @@ -327,7 +301,6 @@ bool CollisionPolygon3DEditor::forward_spatial_gui_input(Camera3D *p_camera, con if (mm.is_valid()) { if (edited_point != -1 && (wip_active || mm->get_button_mask() & BUTTON_MASK_LEFT)) { - Vector2 gpoint = mm->get_position(); Vector3 ray_from = p_camera->project_ray_origin(gpoint); @@ -335,8 +308,9 @@ bool CollisionPolygon3DEditor::forward_spatial_gui_input(Camera3D *p_camera, con Vector3 spoint; - if (!p.intersects_ray(ray_from, ray_dir, &spoint)) + if (!p.intersects_ray(ray_from, ray_dir, &spoint)) { return false; + } spoint = gi.xform(spoint); @@ -361,24 +335,25 @@ bool CollisionPolygon3DEditor::forward_spatial_gui_input(Camera3D *p_camera, con } float CollisionPolygon3DEditor::_get_depth() { - - if (bool(node->call("_has_editable_3d_polygon_no_depth"))) + if (bool(node->call("_has_editable_3d_polygon_no_depth"))) { return 0; + } return float(node->call("get_depth")); } void CollisionPolygon3DEditor::_polygon_draw() { - - if (!node) + if (!node) { return; + } Vector<Vector2> poly; - if (wip_active) + if (wip_active) { poly = wip; - else + } else { poly = node->call("get_polygon"); + } float depth = _get_depth() * 0.5; @@ -389,18 +364,19 @@ void CollisionPolygon3DEditor::_polygon_draw() { Rect2 rect; for (int i = 0; i < poly.size(); i++) { - Vector2 p, p2; p = i == edited_point ? edited_point_pos : poly[i]; - if ((wip_active && i == poly.size() - 1) || (((i + 1) % poly.size()) == edited_point)) + if ((wip_active && i == poly.size() - 1) || (((i + 1) % poly.size()) == edited_point)) { p2 = edited_point_pos; - else + } else { p2 = poly[(i + 1) % poly.size()]; + } - if (i == 0) + if (i == 0) { rect.position = p; - else + } else { rect.expand_to(p); + } Vector3 point = Vector3(p.x, p.y, depth); Vector3 next_point = Vector3(p2.x, p2.y, depth); @@ -465,18 +441,17 @@ void CollisionPolygon3DEditor::_polygon_draw() { m->clear_surfaces(); - if (poly.size() == 0) + if (poly.size() == 0) { return; + } Array a; a.resize(Mesh::ARRAY_MAX); Vector<Vector3> va; { - va.resize(poly.size()); Vector3 *w = va.ptrw(); for (int i = 0; i < poly.size(); i++) { - Vector2 p, p2; p = i == edited_point ? edited_point_pos : poly[i]; @@ -490,9 +465,7 @@ void CollisionPolygon3DEditor::_polygon_draw() { } void CollisionPolygon3DEditor::edit(Node *p_collision_polygon) { - if (p_collision_polygon) { - node = Object::cast_to<Node3D>(p_collision_polygon); //Enable the pencil tool if the polygon is empty if (Vector<Vector2>(node->call("get_polygon")).size() == 0) { @@ -509,20 +482,19 @@ void CollisionPolygon3DEditor::edit(Node *p_collision_polygon) { } else { node = nullptr; - if (imgeom->get_parent()) + if (imgeom->get_parent()) { imgeom->get_parent()->remove_child(imgeom); + } set_process(false); } } void CollisionPolygon3DEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_polygon_draw"), &CollisionPolygon3DEditor::_polygon_draw); } CollisionPolygon3DEditor::CollisionPolygon3DEditor(EditorNode *p_editor) { - node = nullptr; editor = p_editor; undo_redo = EditorNode::get_undo_redo(); @@ -570,33 +542,27 @@ CollisionPolygon3DEditor::CollisionPolygon3DEditor(EditorNode *p_editor) { } CollisionPolygon3DEditor::~CollisionPolygon3DEditor() { - memdelete(imgeom); } void Polygon3DEditorPlugin::edit(Object *p_object) { - collision_polygon_editor->edit(Object::cast_to<Node>(p_object)); } bool Polygon3DEditorPlugin::handles(Object *p_object) const { - return Object::cast_to<Node3D>(p_object) && bool(p_object->call("_is_editable_3d_polygon")); } void Polygon3DEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { collision_polygon_editor->show(); } else { - collision_polygon_editor->hide(); collision_polygon_editor->edit(nullptr); } } Polygon3DEditorPlugin::Polygon3DEditorPlugin(EditorNode *p_node) { - editor = p_node; collision_polygon_editor = memnew(CollisionPolygon3DEditor(p_node)); Node3DEditor::get_singleton()->add_control_to_menu_panel(collision_polygon_editor); diff --git a/editor/plugins/collision_polygon_3d_editor_plugin.h b/editor/plugins/collision_polygon_3d_editor_plugin.h index 9751b1f79e..5215cbb678 100644 --- a/editor/plugins/collision_polygon_3d_editor_plugin.h +++ b/editor/plugins/collision_polygon_3d_editor_plugin.h @@ -41,7 +41,6 @@ class CanvasItemEditor; class CollisionPolygon3DEditor : public HBoxContainer { - GDCLASS(CollisionPolygon3DEditor, HBoxContainer); UndoRedo *undo_redo; @@ -97,7 +96,6 @@ public: }; class Polygon3DEditorPlugin : public EditorPlugin { - GDCLASS(Polygon3DEditorPlugin, EditorPlugin); CollisionPolygon3DEditor *collision_polygon_editor; diff --git a/editor/plugins/collision_shape_2d_editor_plugin.cpp b/editor/plugins/collision_shape_2d_editor_plugin.cpp index 8973dca963..0f381c06b4 100644 --- a/editor/plugins/collision_shape_2d_editor_plugin.cpp +++ b/editor/plugins/collision_shape_2d_editor_plugin.cpp @@ -40,14 +40,12 @@ #include "scene/resources/segment_shape_2d.h" void CollisionShape2DEditor::_node_removed(Node *p_node) { - if (p_node == node) { node = nullptr; } } Variant CollisionShape2DEditor::get_handle_value(int idx) const { - switch (shape_type) { case CAPSULE_SHAPE: { Ref<CapsuleShape2D> capsule = node->get_shape(); @@ -70,11 +68,9 @@ Variant CollisionShape2DEditor::get_handle_value(int idx) const { } break; case CONCAVE_POLYGON_SHAPE: { - } break; case CONVEX_POLYGON_SHAPE: { - } break; case LINE_SHAPE: { @@ -122,7 +118,6 @@ Variant CollisionShape2DEditor::get_handle_value(int idx) const { } void CollisionShape2DEditor::set_handle(int idx, Point2 &p_point) { - switch (shape_type) { case CAPSULE_SHAPE: { if (idx < 2) { @@ -150,11 +145,9 @@ void CollisionShape2DEditor::set_handle(int idx, Point2 &p_point) { } break; case CONCAVE_POLYGON_SHAPE: { - } break; case CONVEX_POLYGON_SHAPE: { - } break; case LINE_SHAPE: { @@ -217,7 +210,6 @@ void CollisionShape2DEditor::set_handle(int idx, Point2 &p_point) { } void CollisionShape2DEditor::commit_handle(int idx, Variant &p_org) { - undo_redo->create_action(TTR("Set Handle")); switch (shape_type) { @@ -249,11 +241,9 @@ void CollisionShape2DEditor::commit_handle(int idx, Variant &p_org) { } break; case CONCAVE_POLYGON_SHAPE: { - } break; case CONVEX_POLYGON_SHAPE: { - } break; case LINE_SHAPE: { @@ -314,7 +304,6 @@ void CollisionShape2DEditor::commit_handle(int idx, Variant &p_org) { } bool CollisionShape2DEditor::forward_canvas_gui_input(const Ref<InputEvent> &p_event) { - if (!node) { return false; } @@ -331,7 +320,6 @@ bool CollisionShape2DEditor::forward_canvas_gui_input(const Ref<InputEvent> &p_e Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); if (mb.is_valid()) { - Vector2 gpoint = mb->get_position(); if (mb->get_button_index() == BUTTON_LEFT) { @@ -373,7 +361,6 @@ bool CollisionShape2DEditor::forward_canvas_gui_input(const Ref<InputEvent> &p_e Ref<InputEventMouseMotion> mm = p_event; if (mm.is_valid()) { - if (edit_handle == -1 || !pressed) { return false; } @@ -390,7 +377,6 @@ bool CollisionShape2DEditor::forward_canvas_gui_input(const Ref<InputEvent> &p_e } void CollisionShape2DEditor::_get_current_shape_type() { - if (!node) { return; } @@ -425,7 +411,6 @@ void CollisionShape2DEditor::_get_current_shape_type() { } void CollisionShape2DEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { - if (!node) { return; } @@ -474,11 +459,9 @@ void CollisionShape2DEditor::forward_canvas_draw_over_viewport(Control *p_overla } break; case CONCAVE_POLYGON_SHAPE: { - } break; case CONVEX_POLYGON_SHAPE: { - } break; case LINE_SHAPE: { @@ -533,9 +516,7 @@ void CollisionShape2DEditor::forward_canvas_draw_over_viewport(Control *p_overla } void CollisionShape2DEditor::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_ENTER_TREE: { get_tree()->connect("node_removed", callable_mp(this, &CollisionShape2DEditor::_node_removed)); } break; @@ -547,7 +528,6 @@ void CollisionShape2DEditor::_notification(int p_what) { } void CollisionShape2DEditor::edit(Node *p_node) { - if (!canvas_item_editor) { canvas_item_editor = CanvasItemEditor::get_singleton(); } @@ -568,12 +548,10 @@ void CollisionShape2DEditor::edit(Node *p_node) { } void CollisionShape2DEditor::_bind_methods() { - ClassDB::bind_method("_get_current_shape_type", &CollisionShape2DEditor::_get_current_shape_type); } CollisionShape2DEditor::CollisionShape2DEditor(EditorNode *p_editor) { - node = nullptr; canvas_item_editor = nullptr; editor = p_editor; @@ -585,24 +563,20 @@ CollisionShape2DEditor::CollisionShape2DEditor(EditorNode *p_editor) { } void CollisionShape2DEditorPlugin::edit(Object *p_obj) { - collision_shape_2d_editor->edit(Object::cast_to<Node>(p_obj)); } bool CollisionShape2DEditorPlugin::handles(Object *p_obj) const { - return p_obj->is_class("CollisionShape2D"); } void CollisionShape2DEditorPlugin::make_visible(bool visible) { - if (!visible) { edit(nullptr); } } CollisionShape2DEditorPlugin::CollisionShape2DEditorPlugin(EditorNode *p_editor) { - editor = p_editor; collision_shape_2d_editor = memnew(CollisionShape2DEditor(p_editor)); diff --git a/editor/plugins/cpu_particles_2d_editor_plugin.cpp b/editor/plugins/cpu_particles_2d_editor_plugin.cpp index ef4d7d7646..008de7cfb4 100644 --- a/editor/plugins/cpu_particles_2d_editor_plugin.cpp +++ b/editor/plugins/cpu_particles_2d_editor_plugin.cpp @@ -37,53 +37,42 @@ #include "scene/resources/particles_material.h" void CPUParticles2DEditorPlugin::edit(Object *p_object) { - particles = Object::cast_to<CPUParticles2D>(p_object); } bool CPUParticles2DEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("CPUParticles2D"); } void CPUParticles2DEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { - toolbar->show(); } else { - toolbar->hide(); } } void CPUParticles2DEditorPlugin::_file_selected(const String &p_file) { - source_emission_file = p_file; emission_mask->popup_centered(); } void CPUParticles2DEditorPlugin::_menu_callback(int p_idx) { - switch (p_idx) { case MENU_LOAD_EMISSION_MASK: { - file->popup_centered_ratio(); } break; case MENU_CLEAR_EMISSION_MASK: { - emission_mask->popup_centered(); } break; case MENU_RESTART: { - particles->restart(); } } } void CPUParticles2DEditorPlugin::_generate_emission_mask() { - Ref<Image> img; img.instance(); Error err = ImageLoader::load_image(source_emission_file, img); @@ -123,13 +112,10 @@ void CPUParticles2DEditorPlugin::_generate_emission_mask() { for (int i = 0; i < s.width; i++) { for (int j = 0; j < s.height; j++) { - uint8_t a = r[(j * s.width + i) * 4 + 3]; if (a > 128) { - if (emode == EMISSION_MODE_SOLID) { - if (capture_colors) { valid_colors.write[vpc * 4 + 0] = r[(j * s.width + i) * 4 + 0]; valid_colors.write[vpc * 4 + 1] = r[(j * s.width + i) * 4 + 1]; @@ -139,19 +125,18 @@ void CPUParticles2DEditorPlugin::_generate_emission_mask() { valid_positions.write[vpc++] = Point2(i, j); } else { - bool on_border = false; for (int x = i - 1; x <= i + 1; x++) { for (int y = j - 1; y <= j + 1; y++) { - if (x < 0 || y < 0 || x >= s.width || y >= s.height || r[(y * s.width + x) * 4 + 3] <= 128) { on_border = true; break; } } - if (on_border) + if (on_border) { break; + } } if (on_border) { @@ -161,9 +146,9 @@ void CPUParticles2DEditorPlugin::_generate_emission_mask() { Vector2 normal; for (int x = i - 2; x <= i + 2; x++) { for (int y = j - 2; y <= j + 2; y++) { - - if (x == i && y == j) + if (x == i && y == j) { continue; + } if (x < 0 || y < 0 || x >= s.width || y >= s.height || r[(y * s.width + x) * 4 + 3] <= 128) { normal += Vector2(x - i, y - j).normalized(); @@ -237,9 +222,7 @@ 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("CPUParticles2D", "EditorIcons")); file->connect("file_selected", callable_mp(this, &CPUParticles2DEditorPlugin::_file_selected)); @@ -250,7 +233,6 @@ void CPUParticles2DEditorPlugin::_bind_methods() { } CPUParticles2DEditorPlugin::CPUParticles2DEditorPlugin(EditorNode *p_node) { - particles = nullptr; editor = p_node; undo_redo = editor->get_undo_redo(); diff --git a/editor/plugins/cpu_particles_2d_editor_plugin.h b/editor/plugins/cpu_particles_2d_editor_plugin.h index 21b06b6489..fecbb8b1cd 100644 --- a/editor/plugins/cpu_particles_2d_editor_plugin.h +++ b/editor/plugins/cpu_particles_2d_editor_plugin.h @@ -39,7 +39,6 @@ #include "scene/gui/file_dialog.h" class CPUParticles2DEditorPlugin : public EditorPlugin { - GDCLASS(CPUParticles2DEditorPlugin, EditorPlugin); enum { diff --git a/editor/plugins/cpu_particles_3d_editor_plugin.cpp b/editor/plugins/cpu_particles_3d_editor_plugin.cpp index 59a353a581..ef26ecd767 100644 --- a/editor/plugins/cpu_particles_3d_editor_plugin.cpp +++ b/editor/plugins/cpu_particles_3d_editor_plugin.cpp @@ -33,7 +33,6 @@ #include "editor/plugins/node_3d_editor_plugin.h" void CPUParticles3DEditor::_node_removed(Node *p_node) { - if (p_node == node) { node = nullptr; hide(); @@ -41,24 +40,19 @@ 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("CPUParticles3D", "EditorIcons")); } } void CPUParticles3DEditor::_menu_option(int p_option) { - switch (p_option) { - case MENU_OPTION_CREATE_EMISSION_VOLUME_FROM_NODE: { - emission_tree_dialog->popup_centered_ratio(); } break; case MENU_OPTION_RESTART: { - node->restart(); } break; @@ -66,13 +60,11 @@ void CPUParticles3DEditor::_menu_option(int p_option) { } void CPUParticles3DEditor::edit(CPUParticles3D *p_particles) { - base_node = p_particles; node = p_particles; } void CPUParticles3DEditor::_generate_emission_points() { - /// hacer codigo aca Vector<Vector3> points; Vector<Vector3> normals; @@ -95,7 +87,6 @@ void CPUParticles3DEditor::_bind_methods() { } CPUParticles3DEditor::CPUParticles3DEditor() { - particles_editor_hb = memnew(HBoxContainer); Node3DEditor::get_singleton()->add_control_to_menu_panel(particles_editor_hb); options = memnew(MenuButton); @@ -110,17 +101,14 @@ CPUParticles3DEditor::CPUParticles3DEditor() { } void CPUParticles3DEditorPlugin::edit(Object *p_object) { - particles_editor->edit(Object::cast_to<CPUParticles3D>(p_object)); } bool CPUParticles3DEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("CPUParticles3D"); } void CPUParticles3DEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { particles_editor->show(); particles_editor->particles_editor_hb->show(); @@ -132,7 +120,6 @@ void CPUParticles3DEditorPlugin::make_visible(bool p_visible) { } CPUParticles3DEditorPlugin::CPUParticles3DEditorPlugin(EditorNode *p_node) { - editor = p_node; particles_editor = memnew(CPUParticles3DEditor); editor->get_viewport()->add_child(particles_editor); diff --git a/editor/plugins/cpu_particles_3d_editor_plugin.h b/editor/plugins/cpu_particles_3d_editor_plugin.h index 796c842e07..d9680496ba 100644 --- a/editor/plugins/cpu_particles_3d_editor_plugin.h +++ b/editor/plugins/cpu_particles_3d_editor_plugin.h @@ -35,7 +35,6 @@ #include "scene/3d/cpu_particles_3d.h" class CPUParticles3DEditor : public GPUParticles3DEditorBase { - GDCLASS(CPUParticles3DEditor, GPUParticles3DEditorBase); enum Menu { @@ -65,7 +64,6 @@ public: }; class CPUParticles3DEditorPlugin : public EditorPlugin { - GDCLASS(CPUParticles3DEditorPlugin, EditorPlugin); CPUParticles3DEditor *particles_editor; diff --git a/editor/plugins/curve_editor_plugin.cpp b/editor/plugins/curve_editor_plugin.cpp index fc8eef52c0..539ab03f5b 100644 --- a/editor/plugins/curve_editor_plugin.cpp +++ b/editor/plugins/curve_editor_plugin.cpp @@ -65,9 +65,9 @@ CurveEditor::CurveEditor() { } void CurveEditor::set_curve(Ref<Curve> curve) { - - if (curve == _curve_ref) + if (curve == _curve_ref) { return; + } if (_curve_ref.is_valid()) { _curve_ref->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &CurveEditor::_curve_changed)); @@ -96,24 +96,23 @@ Size2 CurveEditor::get_minimum_size() const { } void CurveEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_DRAW) + if (p_what == NOTIFICATION_DRAW) { _draw(); + } } void CurveEditor::on_gui_input(const Ref<InputEvent> &p_event) { - Ref<InputEventMouseButton> mb_ref = p_event; if (mb_ref.is_valid()) { - const InputEventMouseButton &mb = **mb_ref; if (mb.is_pressed() && !_dragging) { - Vector2 mpos = mb.get_position(); _selected_tangent = get_tangent_at(mpos); - if (_selected_tangent == TANGENT_NONE) + if (_selected_tangent == TANGENT_NONE) { set_selected_point(get_point_at(mpos)); + } switch (mb.get_button_index()) { case BUTTON_RIGHT: @@ -134,7 +133,6 @@ void CurveEditor::on_gui_input(const Ref<InputEvent> &p_event) { if (!mb.is_pressed() && _dragging && mb.get_button_index() == BUTTON_LEFT) { _dragging = false; if (_has_undo_data) { - UndoRedo &ur = *EditorNode::get_singleton()->get_undo_redo(); ur.create_action(_selected_tangent == TANGENT_NONE ? TTR("Modify Curve Point") : TTR("Modify Curve Tangent")); @@ -151,13 +149,11 @@ void CurveEditor::on_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseMotion> mm_ref = p_event; if (mm_ref.is_valid()) { - const InputEventMouseMotion &mm = **mm_ref; Vector2 mpos = mm.get_position(); if (_dragging && _curve_ref.is_valid()) { - if (_selected_point != -1) { Curve &curve = **_curve_ref; @@ -189,10 +185,11 @@ void CurveEditor::on_gui_input(const Ref<InputEvent> &p_event) { set_selected_point(i); // This is to prevent the user from losing a point out of view. - if (point_pos.y < curve.get_min_value()) + if (point_pos.y < curve.get_min_value()) { point_pos.y = curve.get_min_value(); - else if (point_pos.y > curve.get_max_value()) + } else if (point_pos.y > curve.get_max_value()) { point_pos.y = curve.get_max_value(); + } curve.set_point_value(_selected_point, point_pos.y); @@ -205,10 +202,11 @@ void CurveEditor::on_gui_input(const Ref<InputEvent> &p_event) { Vector2 dir = (control_pos - point_pos).normalized(); real_t tangent; - if (!Math::is_zero_approx(dir.x)) + if (!Math::is_zero_approx(dir.x)) { tangent = dir.y / dir.x; - else + } else { tangent = 9999 * (dir.y >= 0 ? 1 : -1); + } bool link = !Input::get_singleton()->is_key_pressed(KEY_SHIFT); @@ -216,14 +214,16 @@ void CurveEditor::on_gui_input(const Ref<InputEvent> &p_event) { curve.set_point_left_tangent(_selected_point, tangent); // Note: if a tangent is set to linear, it shouldn't be linked to the other - if (link && _selected_point != (curve.get_point_count() - 1) && curve.get_point_right_mode(_selected_point) != Curve::TANGENT_LINEAR) + if (link && _selected_point != (curve.get_point_count() - 1) && curve.get_point_right_mode(_selected_point) != Curve::TANGENT_LINEAR) { curve.set_point_right_tangent(_selected_point, tangent); + } } else { curve.set_point_right_tangent(_selected_point, tangent); - if (link && _selected_point != 0 && curve.get_point_left_mode(_selected_point) != Curve::TANGENT_LINEAR) + if (link && _selected_point != 0 && curve.get_point_left_mode(_selected_point) != Curve::TANGENT_LINEAR) { curve.set_point_left_tangent(_selected_point, tangent); + } } } } @@ -238,8 +238,9 @@ void CurveEditor::on_gui_input(const Ref<InputEvent> &p_event) { const InputEventKey &key = **key_ref; if (key.is_pressed() && _selected_point != -1) { - if (key.get_keycode() == KEY_DELETE) + if (key.get_keycode() == KEY_DELETE) { remove_point(_selected_point); + } } } } @@ -358,8 +359,9 @@ void CurveEditor::open_context_menu(Vector2 pos) { _context_menu->set_item_checked(_context_menu->get_item_index(CONTEXT_LINEAR), is_linear); } else { - if (_selected_point > 0 || _selected_point + 1 < _curve_ref->get_point_count()) + if (_selected_point > 0 || _selected_point + 1 < _curve_ref->get_point_count()) { _context_menu->add_separator(); + } if (_selected_point > 0) { _context_menu->add_check_item(TTR("Left Linear"), CONTEXT_LEFT_LINEAR); @@ -384,8 +386,9 @@ void CurveEditor::open_context_menu(Vector2 pos) { } int CurveEditor::get_point_at(Vector2 pos) const { - if (_curve_ref.is_null()) + if (_curve_ref.is_null()) { return -1; + } const Curve &curve = **_curve_ref; const float r = _hover_radius * _hover_radius; @@ -401,8 +404,9 @@ int CurveEditor::get_point_at(Vector2 pos) const { } CurveEditor::TangentIndex CurveEditor::get_tangent_at(Vector2 pos) const { - if (_curve_ref.is_null() || _selected_point < 0) + if (_curve_ref.is_null() || _selected_point < 0) { return TANGENT_NONE; + } if (_selected_point != 0) { Vector2 control_pos = get_tangent_view_pos(_selected_point, TANGENT_LEFT); @@ -428,10 +432,11 @@ void CurveEditor::add_point(Vector2 pos) { ur.create_action(TTR("Remove Curve Point")); Vector2 point_pos = get_world_pos(pos); - if (point_pos.y < 0.0) + if (point_pos.y < 0.0) { point_pos.y = 0.0; - else if (point_pos.y > 1.0) + } else if (point_pos.y > 1.0) { point_pos.y = 1.0; + } // Small trick to get the point index to feed the undo method int i = _curve_ref->add_point(point_pos); @@ -454,11 +459,13 @@ void CurveEditor::remove_point(int index) { ur.add_do_method(*_curve_ref, "remove_point", index); ur.add_undo_method(*_curve_ref, "add_point", p.pos, p.left_tangent, p.right_tangent, p.left_mode, p.right_mode); - if (index == _selected_point) + if (index == _selected_point) { set_selected_point(-1); + } - if (index == _hover_point) + if (index == _hover_point) { set_hover_point_index(-1); + } ur.commit_action(); } @@ -469,11 +476,11 @@ void CurveEditor::toggle_linear(TangentIndex tangent) { UndoRedo &ur = *EditorNode::get_singleton()->get_undo_redo(); ur.create_action(TTR("Toggle Curve Linear Tangent")); - if (tangent == TANGENT_NONE) + if (tangent == TANGENT_NONE) { tangent = _selected_tangent; + } if (tangent == TANGENT_LEFT) { - bool is_linear = _curve_ref->get_point_left_mode(_selected_point) == Curve::TANGENT_LINEAR; Curve::TangentMode prev_mode = _curve_ref->get_point_left_mode(_selected_point); @@ -483,7 +490,6 @@ void CurveEditor::toggle_linear(TangentIndex tangent) { ur.add_undo_method(*_curve_ref, "set_point_left_mode", _selected_point, prev_mode); } else { - bool is_linear = _curve_ref->get_point_right_mode(_selected_point) == Curve::TANGENT_LINEAR; Curve::TangentMode prev_mode = _curve_ref->get_point_right_mode(_selected_point); @@ -538,12 +544,12 @@ void CurveEditor::update_view_transform() { } Vector2 CurveEditor::get_tangent_view_pos(int i, TangentIndex tangent) const { - Vector2 dir; - if (tangent == TANGENT_LEFT) + if (tangent == TANGENT_LEFT) { dir = -Vector2(1, _curve_ref->get_point_left_tangent(i)); - else + } else { dir = Vector2(1, _curve_ref->get_point_right_tangent(i)); + } Vector2 point_pos = get_view_pos(_curve_ref->get_point_position(i)); Vector2 control_pos = get_view_pos(_curve_ref->get_point_position(i) + dir); @@ -562,7 +568,6 @@ Vector2 CurveEditor::get_world_pos(Vector2 view_pos) const { // Uses non-baked points, but takes advantage of ordered iteration to be faster template <typename T> static void plot_curve_accurate(const Curve &curve, float step, T plot_func) { - if (curve.get_point_count() <= 1) { // Not enough points to make a curve, so it's just a straight line float y = curve.interpolate(0); @@ -600,7 +605,6 @@ static void plot_curve_accurate(const Curve &curve, float step, T plot_func) { } struct CanvasItemPlotCurve { - CanvasItem &ci; Color color1; Color color2; @@ -617,8 +621,9 @@ struct CanvasItemPlotCurve { }; void CurveEditor::_draw() { - if (_curve_ref.is_null()) + if (_curve_ref.is_null()) { return; + } Curve &curve = **_curve_ref; update_view_transform(); @@ -685,7 +690,6 @@ void CurveEditor::_draw() { // Draw tangents for current point if (_selected_point >= 0) { - const Color tangent_color = get_theme_color("accent_color", "Editor"); int i = _selected_point; @@ -754,12 +758,10 @@ void CurveEditor::_bind_methods() { //--------------- bool EditorInspectorPluginCurve::can_handle(Object *p_object) { - return Object::cast_to<Curve>(p_object) != nullptr; } void EditorInspectorPluginCurve::parse_begin(Object *p_object) { - Curve *curve = Object::cast_to<Curve>(p_object); ERR_FAIL_COND(!curve); Ref<Curve> c(curve); @@ -785,7 +787,6 @@ bool CurvePreviewGenerator::handles(const String &p_type) const { } Ref<Texture2D> CurvePreviewGenerator::generate(const Ref<Resource> &p_from, const Size2 &p_size) const { - Ref<Curve> curve_ref = p_from; ERR_FAIL_COND_V_MSG(curve_ref.is_null(), Ref<Texture2D>(), "It's not a reference to a valid Resource object."); Curve &curve = **curve_ref; @@ -811,7 +812,6 @@ Ref<Texture2D> CurvePreviewGenerator::generate(const Ref<Resource> &p_from, cons int prev_y = 0; for (int x = 0; x < im.get_width(); ++x) { - float t = static_cast<float>(x) / im.get_width(); float v = (curve.interpolate_baked(t) - curve.get_min_value()) / range_y; int y = CLAMP(im.get_height() - v * im.get_height(), 0, im.get_height()); diff --git a/editor/plugins/debugger_editor_plugin.cpp b/editor/plugins/debugger_editor_plugin.cpp index e0d345663c..0ca479555d 100644 --- a/editor/plugins/debugger_editor_plugin.cpp +++ b/editor/plugins/debugger_editor_plugin.cpp @@ -114,7 +114,6 @@ void DebuggerEditorPlugin::_select_run_count(int p_index) { void DebuggerEditorPlugin::_menu_option(int p_option) { switch (p_option) { case RUN_FILE_SERVER: { - bool ischecked = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(RUN_FILE_SERVER)); if (ischecked) { @@ -128,7 +127,6 @@ void DebuggerEditorPlugin::_menu_option(int p_option) { } break; case RUN_LIVE_DEBUG: { - bool ischecked = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(RUN_LIVE_DEBUG)); debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_LIVE_DEBUG), !ischecked); @@ -137,28 +135,24 @@ void DebuggerEditorPlugin::_menu_option(int p_option) { } break; case RUN_DEPLOY_REMOTE_DEBUG: { - bool ischecked = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEPLOY_REMOTE_DEBUG)); debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEPLOY_REMOTE_DEBUG), !ischecked); EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_deploy_remote_debug", !ischecked); } break; case RUN_DEBUG_COLLISONS: { - bool ischecked = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEBUG_COLLISONS)); debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEBUG_COLLISONS), !ischecked); EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_debug_collisons", !ischecked); } break; case RUN_DEBUG_NAVIGATION: { - bool ischecked = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEBUG_NAVIGATION)); debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEBUG_NAVIGATION), !ischecked); EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_debug_navigation", !ischecked); } break; case RUN_RELOAD_SCRIPTS: { - bool ischecked = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(RUN_RELOAD_SCRIPTS)); debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_RELOAD_SCRIPTS), !ischecked); @@ -170,8 +164,9 @@ void DebuggerEditorPlugin::_menu_option(int p_option) { } void DebuggerEditorPlugin::_notification(int p_what) { - if (p_what == NOTIFICATION_READY) + if (p_what == NOTIFICATION_READY) { _update_debug_options(); + } } void DebuggerEditorPlugin::_update_debug_options() { @@ -183,18 +178,24 @@ void DebuggerEditorPlugin::_update_debug_options() { bool check_reload_scripts = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_reload_scripts", false); int instances = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_instances", 1); - if (check_deploy_remote) + if (check_deploy_remote) { _menu_option(RUN_DEPLOY_REMOTE_DEBUG); - if (check_file_server) + } + if (check_file_server) { _menu_option(RUN_FILE_SERVER); - if (check_debug_collisions) + } + if (check_debug_collisions) { _menu_option(RUN_DEBUG_COLLISONS); - if (check_debug_navigation) + } + if (check_debug_navigation) { _menu_option(RUN_DEBUG_NAVIGATION); - if (check_live_debug) + } + if (check_live_debug) { _menu_option(RUN_LIVE_DEBUG); - if (check_reload_scripts) + } + if (check_reload_scripts) { _menu_option(RUN_RELOAD_SCRIPTS); + } int len = instances_menu->get_item_count(); for (int idx = 0; idx < len; idx++) { diff --git a/editor/plugins/debugger_editor_plugin.h b/editor/plugins/debugger_editor_plugin.h index 5ec6399921..465041b5a7 100644 --- a/editor/plugins/debugger_editor_plugin.h +++ b/editor/plugins/debugger_editor_plugin.h @@ -39,7 +39,6 @@ class MenuButton; class PopupMenu; class DebuggerEditorPlugin : public EditorPlugin { - GDCLASS(DebuggerEditorPlugin, EditorPlugin); private: diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp index 2db0903f04..9cb167b41c 100644 --- a/editor/plugins/editor_preview_plugins.cpp +++ b/editor/plugins/editor_preview_plugins.cpp @@ -43,9 +43,9 @@ #include "servers/audio/audio_stream.h" void post_process_preview(Ref<Image> p_image) { - - if (p_image->get_format() != Image::FORMAT_RGBA8) + if (p_image->get_format() != Image::FORMAT_RGBA8) { p_image->convert(Image::FORMAT_RGBA8); + } const int w = p_image->get_width(); const int h = p_image->get_height(); @@ -71,7 +71,6 @@ void post_process_preview(Ref<Image> p_image) { } bool EditorTexturePreviewPlugin::handles(const String &p_type) const { - return ClassDB::is_parent_class(p_type, "Texture2D"); } @@ -80,7 +79,6 @@ bool EditorTexturePreviewPlugin::generate_small_preview_automatically() const { } Ref<Texture2D> EditorTexturePreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const { - Ref<Image> img; Ref<AtlasTexture> atex = p_from; Ref<LargeTexture> ltex = p_from; @@ -108,14 +106,16 @@ Ref<Texture2D> EditorTexturePreviewPlugin::generate(const RES &p_from, const Siz } } - if (img.is_null() || img->empty()) + if (img.is_null() || img->empty()) { return Ref<Texture2D>(); + } img->clear_mipmaps(); if (img->is_compressed()) { - if (img->decompress() != OK) + if (img->decompress() != OK) { return Ref<Texture2D>(); + } } else if (img->get_format() != Image::FORMAT_RGB8 && img->get_format() != Image::FORMAT_RGBA8) { img->convert(Image::FORMAT_RGBA8); } @@ -143,23 +143,23 @@ EditorTexturePreviewPlugin::EditorTexturePreviewPlugin() { //////////////////////////////////////////////////////////////////////////// bool EditorImagePreviewPlugin::handles(const String &p_type) const { - return p_type == "Image"; } Ref<Texture2D> EditorImagePreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const { - Ref<Image> img = p_from; - if (img.is_null() || img->empty()) + if (img.is_null() || img->empty()) { return Ref<Image>(); + } img = img->duplicate(); img->clear_mipmaps(); if (img->is_compressed()) { - if (img->decompress() != OK) + if (img->decompress() != OK) { return Ref<Image>(); + } } else if (img->get_format() != Image::FORMAT_RGB8 && img->get_format() != Image::FORMAT_RGBA8) { img->convert(Image::FORMAT_RGBA8); } @@ -188,15 +188,14 @@ EditorImagePreviewPlugin::EditorImagePreviewPlugin() { bool EditorImagePreviewPlugin::generate_small_preview_automatically() const { return true; } + //////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////// bool EditorBitmapPreviewPlugin::handles(const String &p_type) const { - return ClassDB::is_parent_class(p_type, "BitMap"); } Ref<Texture2D> EditorBitmapPreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const { - Ref<BitMap> bm = p_from; if (bm->get_size() == Size2()) { @@ -226,8 +225,9 @@ Ref<Texture2D> EditorBitmapPreviewPlugin::generate(const RES &p_from, const Size img->create(bm->get_size().width, bm->get_size().height, false, Image::FORMAT_L8, data); if (img->is_compressed()) { - if (img->decompress() != OK) + if (img->decompress() != OK) { return Ref<Texture2D>(); + } } else if (img->get_format() != Image::FORMAT_RGB8 && img->get_format() != Image::FORMAT_RGBA8) { img->convert(Image::FORMAT_RGBA8); } @@ -259,17 +259,14 @@ EditorBitmapPreviewPlugin::EditorBitmapPreviewPlugin() { /////////////////////////////////////////////////////////////////////////// bool EditorPackedScenePreviewPlugin::handles(const String &p_type) const { - return ClassDB::is_parent_class(p_type, "PackedScene"); } Ref<Texture2D> EditorPackedScenePreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const { - return generate_from_path(p_from->get_path(), p_size); } Ref<Texture2D> EditorPackedScenePreviewPlugin::generate_from_path(const String &p_path, const Size2 &p_size) const { - String temp_path = EditorSettings::get_singleton()->get_cache_dir(); String cache_base = ProjectSettings::get_singleton()->globalize_path(p_path).md5_text(); cache_base = temp_path.plus_file("resthumb-" + cache_base); @@ -278,14 +275,14 @@ Ref<Texture2D> EditorPackedScenePreviewPlugin::generate_from_path(const String & String path = cache_base + ".png"; - if (!FileAccess::exists(path)) + if (!FileAccess::exists(path)) { return Ref<Texture2D>(); + } Ref<Image> img; img.instance(); Error err = img->load(path); if (err == OK) { - Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture)); post_process_preview(img); @@ -303,17 +300,14 @@ EditorPackedScenePreviewPlugin::EditorPackedScenePreviewPlugin() { ////////////////////////////////////////////////////////////////// void EditorMaterialPreviewPlugin::_preview_done(const Variant &p_udata) { - preview_done = true; } void EditorMaterialPreviewPlugin::_bind_methods() { - ClassDB::bind_method("_preview_done", &EditorMaterialPreviewPlugin::_preview_done); } bool EditorMaterialPreviewPlugin::handles(const String &p_type) const { - return ClassDB::is_parent_class(p_type, "Material"); //any material } @@ -322,12 +316,10 @@ bool EditorMaterialPreviewPlugin::generate_small_preview_automatically() const { } Ref<Texture2D> EditorMaterialPreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const { - Ref<Material> material = p_from; ERR_FAIL_COND_V(material.is_null(), Ref<Texture2D>()); if (material->get_shader_mode() == Shader::MODE_SPATIAL) { - RS::get_singleton()->mesh_surface_set_material(sphere, 0, material->get_rid()); RS::get_singleton()->viewport_set_update_mode(viewport, RS::VIEWPORT_UPDATE_ONCE); //once used for capture @@ -357,7 +349,6 @@ Ref<Texture2D> EditorMaterialPreviewPlugin::generate(const RES &p_from, const Si } EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() { - scenario = RS::get_singleton()->scenario_create(); viewport = RS::get_singleton()->viewport_create(); @@ -408,7 +399,6 @@ EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() { double zr1 = Math::cos(lat1); for (int j = lons; j >= 1; j--) { - double lng0 = 2 * Math_PI * (double)(j - 1) / lons; double x0 = Math::cos(lng0); double y0 = Math::sin(lng0); @@ -462,7 +452,6 @@ EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() { } EditorMaterialPreviewPlugin::~EditorMaterialPreviewPlugin() { - RS::get_singleton()->free(sphere); RS::get_singleton()->free(sphere_instance); RS::get_singleton()->free(viewport); @@ -477,24 +466,23 @@ EditorMaterialPreviewPlugin::~EditorMaterialPreviewPlugin() { /////////////////////////////////////////////////////////////////////////// static bool _is_text_char(CharType c) { - return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_'; } bool EditorScriptPreviewPlugin::handles(const String &p_type) const { - return ClassDB::is_parent_class(p_type, "Script"); } Ref<Texture2D> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const { - Ref<Script> scr = p_from; - if (scr.is_null()) + if (scr.is_null()) { return Ref<Texture2D>(); + } String code = scr->get_source_code().strip_edges(); - if (code == "") + if (code == "") { return Ref<Texture2D>(); + } List<String> kwors; scr->get_language()->get_reserved_words(&kwors); @@ -502,7 +490,6 @@ Ref<Texture2D> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size Set<String> keywords; for (List<String>::Element *E = kwors.front(); E; E = E->next()) { - keywords.insert(E->get()); } @@ -518,8 +505,9 @@ Ref<Texture2D> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size Color text_color = EditorSettings::get_singleton()->get("text_editor/highlighting/text_color"); Color symbol_color = EditorSettings::get_singleton()->get("text_editor/highlighting/symbol_color"); - if (bg_color.a == 0) + if (bg_color.a == 0) { bg_color = Color(0, 0, 0, 0); + } bg_color.a = MAX(bg_color.a, 0.2); // some background for (int i = 0; i < thumbnail_size; i++) { @@ -536,7 +524,6 @@ Ref<Texture2D> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size bool prev_is_text = false; bool in_keyword = false; for (int i = 0; i < code.length(); i++) { - CharType c = code[i]; if (c > 32) { if (col < thumbnail_size) { @@ -553,15 +540,17 @@ Ref<Texture2D> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size pos++; } String word = code.substr(i, pos - i); - if (keywords.has(word)) + if (keywords.has(word)) { in_keyword = true; + } } else if (!_is_text_char(c)) { in_keyword = false; } - if (in_keyword) + if (in_keyword) { color = keyword_color; + } Color ul = color; ul.a *= 0.5; @@ -571,15 +560,15 @@ Ref<Texture2D> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size prev_is_text = _is_text_char(c); } } else { - prev_is_text = false; in_keyword = false; if (c == '\n') { col = x0; line++; - if (line >= available_height / 2) + if (line >= available_height / 2) { break; + } } else if (c == '\t') { col += 3; } @@ -597,15 +586,14 @@ Ref<Texture2D> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size EditorScriptPreviewPlugin::EditorScriptPreviewPlugin() { } + /////////////////////////////////////////////////////////////////// bool EditorAudioStreamPreviewPlugin::handles(const String &p_type) const { - return ClassDB::is_parent_class(p_type, "AudioStream"); } Ref<Texture2D> EditorAudioStreamPreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const { - Ref<AudioStream> stream = p_from; ERR_FAIL_COND_V(stream.is_null(), Ref<Texture2D>()); @@ -635,7 +623,6 @@ Ref<Texture2D> EditorAudioStreamPreviewPlugin::generate(const RES &p_from, const playback->stop(); for (int i = 0; i < w; i++) { - float max = -1000; float min = 1000; int from = uint64_t(i) * frame_length / w; @@ -647,7 +634,6 @@ Ref<Texture2D> EditorAudioStreamPreviewPlugin::generate(const RES &p_from, const } for (int j = from; j < to; j++) { - max = MAX(max, frames[j].l); max = MAX(max, frames[j].r); @@ -688,21 +674,18 @@ EditorAudioStreamPreviewPlugin::EditorAudioStreamPreviewPlugin() { /////////////////////////////////////////////////////////////////////////// void EditorMeshPreviewPlugin::_preview_done(const Variant &p_udata) { - preview_done = true; } void EditorMeshPreviewPlugin::_bind_methods() { - ClassDB::bind_method("_preview_done", &EditorMeshPreviewPlugin::_preview_done); } -bool EditorMeshPreviewPlugin::handles(const String &p_type) const { +bool EditorMeshPreviewPlugin::handles(const String &p_type) const { return ClassDB::is_parent_class(p_type, "Mesh"); //any Mesh } Ref<Texture2D> EditorMeshPreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const { - Ref<Mesh> mesh = p_from; ERR_FAIL_COND_V(mesh.is_null(), Ref<Texture2D>()); @@ -716,8 +699,9 @@ Ref<Texture2D> EditorMeshPreviewPlugin::generate(const RES &p_from, const Size2 xform.basis = Basis().rotated(Vector3(1, 0, 0), Math_PI * 0.125) * xform.basis; AABB rot_aabb = xform.xform(aabb); float m = MAX(rot_aabb.size.x, rot_aabb.size.y) * 0.5; - if (m == 0) + if (m == 0) { return Ref<Texture2D>(); + } m = 1.0 / m; m *= 0.5; xform.basis.scale(Vector3(m, m, m)); @@ -758,7 +742,6 @@ Ref<Texture2D> EditorMeshPreviewPlugin::generate(const RES &p_from, const Size2 } EditorMeshPreviewPlugin::EditorMeshPreviewPlugin() { - scenario = RS::get_singleton()->scenario_create(); viewport = RS::get_singleton()->viewport_create(); @@ -792,7 +775,6 @@ EditorMeshPreviewPlugin::EditorMeshPreviewPlugin() { } EditorMeshPreviewPlugin::~EditorMeshPreviewPlugin() { - //RS::get_singleton()->free(sphere); RS::get_singleton()->free(mesh_instance); RS::get_singleton()->free(viewport); @@ -807,22 +789,18 @@ EditorMeshPreviewPlugin::~EditorMeshPreviewPlugin() { /////////////////////////////////////////////////////////////////////////// void EditorFontPreviewPlugin::_preview_done(const Variant &p_udata) { - preview_done = true; } void EditorFontPreviewPlugin::_bind_methods() { - ClassDB::bind_method("_preview_done", &EditorFontPreviewPlugin::_preview_done); } bool EditorFontPreviewPlugin::handles(const String &p_type) const { - return ClassDB::is_parent_class(p_type, "DynamicFontData") || ClassDB::is_parent_class(p_type, "DynamicFont"); } Ref<Texture2D> EditorFontPreviewPlugin::generate_from_path(const String &p_path, const Size2 &p_size) const { - RES res = ResourceLoader::load(p_path); Ref<DynamicFont> sampled_font; if (res->is_class("DynamicFont")) { @@ -881,7 +859,6 @@ Ref<Texture2D> EditorFontPreviewPlugin::generate_from_path(const String &p_path, } Ref<Texture2D> EditorFontPreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const { - String path = p_from->get_path(); if (!FileAccess::exists(path)) { return Ref<Texture2D>(); @@ -890,7 +867,6 @@ Ref<Texture2D> EditorFontPreviewPlugin::generate(const RES &p_from, const Size2 } EditorFontPreviewPlugin::EditorFontPreviewPlugin() { - viewport = RS::get_singleton()->viewport_create(); RS::get_singleton()->viewport_set_update_mode(viewport, RS::VIEWPORT_UPDATE_DISABLED); RS::get_singleton()->viewport_set_size(viewport, 128, 128); @@ -905,7 +881,6 @@ EditorFontPreviewPlugin::EditorFontPreviewPlugin() { } EditorFontPreviewPlugin::~EditorFontPreviewPlugin() { - RS::get_singleton()->free(canvas_item); RS::get_singleton()->free(canvas); RS::get_singleton()->free(viewport); diff --git a/editor/plugins/editor_preview_plugins.h b/editor/plugins/editor_preview_plugins.h index 840fa2410a..8a9d6a93fb 100644 --- a/editor/plugins/editor_preview_plugins.h +++ b/editor/plugins/editor_preview_plugins.h @@ -69,7 +69,6 @@ public: }; class EditorPackedScenePreviewPlugin : public EditorResourcePreviewGenerator { - public: virtual bool handles(const String &p_type) const; virtual Ref<Texture2D> generate(const RES &p_from, const Size2 &p_size) const; @@ -79,7 +78,6 @@ public: }; class EditorMaterialPreviewPlugin : public EditorResourcePreviewGenerator { - GDCLASS(EditorMaterialPreviewPlugin, EditorResourcePreviewGenerator); RID scenario; @@ -125,7 +123,6 @@ public: }; class EditorMeshPreviewPlugin : public EditorResourcePreviewGenerator { - GDCLASS(EditorMeshPreviewPlugin, EditorResourcePreviewGenerator); RID scenario; @@ -153,7 +150,6 @@ public: }; class EditorFontPreviewPlugin : public EditorResourcePreviewGenerator { - GDCLASS(EditorFontPreviewPlugin, EditorResourcePreviewGenerator); RID viewport; diff --git a/editor/plugins/gi_probe_editor_plugin.cpp b/editor/plugins/gi_probe_editor_plugin.cpp index 6a171c4703..94f771e643 100644 --- a/editor/plugins/gi_probe_editor_plugin.cpp +++ b/editor/plugins/gi_probe_editor_plugin.cpp @@ -31,7 +31,6 @@ #include "gi_probe_editor_plugin.h" void GIProbeEditorPlugin::_bake() { - if (gi_probe) { if (gi_probe->get_probe_data().is_null()) { String path = get_tree()->get_edited_scene_root()->get_filename(); @@ -50,21 +49,19 @@ void GIProbeEditorPlugin::_bake() { } void GIProbeEditorPlugin::edit(Object *p_object) { - GIProbe *s = Object::cast_to<GIProbe>(p_object); - if (!s) + if (!s) { return; + } gi_probe = s; } bool GIProbeEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("GIProbe"); } void GIProbeEditorPlugin::_notification(int p_what) { - if (p_what == NOTIFICATION_PROCESS) { if (!gi_probe) { return; @@ -102,12 +99,10 @@ void GIProbeEditorPlugin::_notification(int p_what) { } void GIProbeEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { bake_hb->show(); set_process(true); } else { - bake_hb->hide(); set_process(false); } @@ -116,14 +111,12 @@ void GIProbeEditorPlugin::make_visible(bool p_visible) { EditorProgress *GIProbeEditorPlugin::tmp_progress = nullptr; void GIProbeEditorPlugin::bake_func_begin(int p_steps) { - ERR_FAIL_COND(tmp_progress != nullptr); tmp_progress = memnew(EditorProgress("bake_gi", TTR("Bake GI Probe"), p_steps)); } void GIProbeEditorPlugin::bake_func_step(int p_step, const String &p_description) { - ERR_FAIL_COND(tmp_progress == nullptr); tmp_progress->step(p_description, p_step, false); } @@ -147,7 +140,6 @@ void GIProbeEditorPlugin::_bind_methods() { } GIProbeEditorPlugin::GIProbeEditorPlugin(EditorNode *p_node) { - editor = p_node; bake_hb = memnew(HBoxContainer); bake_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL); diff --git a/editor/plugins/gi_probe_editor_plugin.h b/editor/plugins/gi_probe_editor_plugin.h index 2068ebaaa8..508c3d825b 100644 --- a/editor/plugins/gi_probe_editor_plugin.h +++ b/editor/plugins/gi_probe_editor_plugin.h @@ -37,7 +37,6 @@ #include "scene/resources/material.h" class GIProbeEditorPlugin : public EditorPlugin { - GDCLASS(GIProbeEditorPlugin, EditorPlugin); GIProbe *gi_probe; diff --git a/editor/plugins/gpu_particles_2d_editor_plugin.cpp b/editor/plugins/gpu_particles_2d_editor_plugin.cpp index 5c35285c22..01420dac3e 100644 --- a/editor/plugins/gpu_particles_2d_editor_plugin.cpp +++ b/editor/plugins/gpu_particles_2d_editor_plugin.cpp @@ -37,54 +37,45 @@ #include "scene/resources/particles_material.h" void GPUParticles2DEditorPlugin::edit(Object *p_object) { - particles = Object::cast_to<GPUParticles2D>(p_object); } bool GPUParticles2DEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("GPUParticles2D"); } void GPUParticles2DEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { - toolbar->show(); } else { - toolbar->hide(); } } void GPUParticles2DEditorPlugin::_file_selected(const String &p_file) { - source_emission_file = p_file; emission_mask->popup_centered(); } void GPUParticles2DEditorPlugin::_menu_callback(int p_idx) { - switch (p_idx) { case MENU_GENERATE_VISIBILITY_RECT: { float gen_time = particles->get_lifetime(); - if (gen_time < 1.0) + if (gen_time < 1.0) { generate_seconds->set_value(1.0); - else + } else { generate_seconds->set_value(trunc(gen_time) + 1.0); + } generate_visibility_rect->popup_centered(); } break; case MENU_LOAD_EMISSION_MASK: { - file->popup_centered_ratio(); } break; case MENU_CLEAR_EMISSION_MASK: { - emission_mask->popup_centered(); } break; case MENU_OPTION_CONVERT_TO_CPU_PARTICLES: { - CPUParticles2D *cpu_particles = memnew(CPUParticles2D); cpu_particles->convert_from_particles(particles); cpu_particles->set_name(particles->get_name()); @@ -103,14 +94,12 @@ void GPUParticles2DEditorPlugin::_menu_callback(int p_idx) { } break; case MENU_RESTART: { - particles->restart(); } } } void GPUParticles2DEditorPlugin::_generate_visibility_rect() { - float time = generate_seconds->get_value(); float running = 0.0; @@ -125,16 +114,16 @@ void GPUParticles2DEditorPlugin::_generate_visibility_rect() { Rect2 rect; while (running < time) { - uint64_t ticks = OS::get_singleton()->get_ticks_usec(); ep.step("Generating...", int(running), true); OS::get_singleton()->delay_usec(1000); Rect2 capture = particles->capture_rect(); - if (rect == Rect2()) + if (rect == Rect2()) { rect = capture; - else + } else { rect = rect.merge(capture); + } running += (OS::get_singleton()->get_ticks_usec() - ticks) / 1000000.0; } @@ -150,7 +139,6 @@ void GPUParticles2DEditorPlugin::_generate_visibility_rect() { } void GPUParticles2DEditorPlugin::_generate_emission_mask() { - Ref<ParticlesMaterial> pm = particles->get_process_material(); if (!pm.is_valid()) { EditorNode::get_singleton()->show_warning(TTR("Can only set point into a ParticlesMaterial process material")); @@ -196,13 +184,10 @@ void GPUParticles2DEditorPlugin::_generate_emission_mask() { for (int i = 0; i < s.width; i++) { for (int j = 0; j < s.height; j++) { - uint8_t a = r[(j * s.width + i) * 4 + 3]; if (a > 128) { - if (emode == EMISSION_MODE_SOLID) { - if (capture_colors) { valid_colors.write[vpc * 4 + 0] = r[(j * s.width + i) * 4 + 0]; valid_colors.write[vpc * 4 + 1] = r[(j * s.width + i) * 4 + 1]; @@ -212,19 +197,18 @@ void GPUParticles2DEditorPlugin::_generate_emission_mask() { valid_positions.write[vpc++] = Point2(i, j); } else { - bool on_border = false; for (int x = i - 1; x <= i + 1; x++) { for (int y = j - 1; y <= j + 1; y++) { - if (x < 0 || y < 0 || x >= s.width || y >= s.height || r[(y * s.width + x) * 4 + 3] <= 128) { on_border = true; break; } } - if (on_border) + if (on_border) { break; + } } if (on_border) { @@ -234,9 +218,9 @@ void GPUParticles2DEditorPlugin::_generate_emission_mask() { Vector2 normal; for (int x = i - 2; x <= i + 2; x++) { for (int y = j - 2; y <= j + 2; y++) { - - if (x == i && y == j) + if (x == i && y == j) { continue; + } if (x < 0 || y < 0 || x >= s.width || y >= s.height || r[(y * s.width + x) * 4 + 3] <= 128) { normal += Vector2(x - i, y - j).normalized(); @@ -281,7 +265,6 @@ void GPUParticles2DEditorPlugin::_generate_emission_mask() { uint8_t *tw = texdata.ptrw(); float *twf = (float *)tw; for (int i = 0; i < vpc; i++) { - twf[i * 2 + 0] = valid_positions[i].x; twf[i * 2 + 1] = valid_positions[i].y; } @@ -298,14 +281,12 @@ void GPUParticles2DEditorPlugin::_generate_emission_mask() { pm->set_emission_point_count(vpc); if (capture_colors) { - Vector<uint8_t> colordata; colordata.resize(w * h * 4); //use RG texture { uint8_t *tw = colordata.ptrw(); for (int i = 0; i < vpc * 4; i++) { - tw[i] = valid_colors[i]; } } @@ -346,9 +327,7 @@ 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("GPUParticles2D", "EditorIcons")); file->connect("file_selected", callable_mp(this, &GPUParticles2DEditorPlugin::_file_selected)); @@ -359,7 +338,6 @@ void GPUParticles2DEditorPlugin::_bind_methods() { } GPUParticles2DEditorPlugin::GPUParticles2DEditorPlugin(EditorNode *p_node) { - particles = nullptr; editor = p_node; undo_redo = editor->get_undo_redo(); diff --git a/editor/plugins/gpu_particles_2d_editor_plugin.h b/editor/plugins/gpu_particles_2d_editor_plugin.h index 008d04a211..c76cecb3a2 100644 --- a/editor/plugins/gpu_particles_2d_editor_plugin.h +++ b/editor/plugins/gpu_particles_2d_editor_plugin.h @@ -39,7 +39,6 @@ #include "scene/gui/file_dialog.h" class GPUParticles2DEditorPlugin : public EditorPlugin { - GDCLASS(GPUParticles2DEditorPlugin, EditorPlugin); enum { diff --git a/editor/plugins/gpu_particles_3d_editor_plugin.cpp b/editor/plugins/gpu_particles_3d_editor_plugin.cpp index 7f80acc176..fa507dd3d7 100644 --- a/editor/plugins/gpu_particles_3d_editor_plugin.cpp +++ b/editor/plugins/gpu_particles_3d_editor_plugin.cpp @@ -36,25 +36,22 @@ #include "scene/resources/particles_material.h" bool GPUParticles3DEditorBase::_generate(Vector<Vector3> &points, Vector<Vector3> &normals) { - bool use_normals = emission_fill->get_selected() == 1; if (emission_fill->get_selected() < 2) { - float area_accum = 0; Map<float, int> triangle_area_map; for (int i = 0; i < geometry.size(); i++) { - float area = geometry[i].get_area(); - if (area < CMP_EPSILON) + if (area < CMP_EPSILON) { continue; + } triangle_area_map[area_accum] = i; area_accum += area; } if (!triangle_area_map.size() || area_accum == 0) { - EditorNode::get_singleton()->show_warning(TTR("The geometry's faces don't contain any area.")); return false; } @@ -62,7 +59,6 @@ bool GPUParticles3DEditorBase::_generate(Vector<Vector3> &points, Vector<Vector3 int emissor_count = emission_amount->get_value(); for (int i = 0; i < emissor_count; i++) { - float areapos = Math::random(0.0f, area_accum); Map<float, int>::Element *E = triangle_area_map.find_closest(areapos); @@ -84,11 +80,9 @@ bool GPUParticles3DEditorBase::_generate(Vector<Vector3> &points, Vector<Vector3 } } } else { - int gcount = geometry.size(); if (gcount == 0) { - EditorNode::get_singleton()->show_warning(TTR("The geometry doesn't contain any faces.")); return false; } @@ -98,24 +92,21 @@ bool GPUParticles3DEditorBase::_generate(Vector<Vector3> &points, Vector<Vector3 AABB aabb; for (int i = 0; i < gcount; i++) { - for (int j = 0; j < 3; j++) { - - if (i == 0 && j == 0) + if (i == 0 && j == 0) { aabb.position = r[i].vertex[j]; - else + } else { aabb.expand_to(r[i].vertex[j]); + } } } int emissor_count = emission_amount->get_value(); for (int i = 0; i < emissor_count; i++) { - int attempts = 5; for (int j = 0; j < attempts; j++) { - Vector3 dir; dir[Math::rand() % 3] = 1.0; Vector3 ofs = (Vector3(1, 1, 1) - dir) * Vector3(Math::randf(), Math::randf(), Math::randf()) * aabb.size + aabb.position; @@ -129,24 +120,25 @@ bool GPUParticles3DEditorBase::_generate(Vector<Vector3> &points, Vector<Vector3 float max = -1e7, min = 1e7; for (int k = 0; k < gcount; k++) { - const Face3 &f3 = r[k]; Vector3 res; if (f3.intersects_segment(ofs, ofsv, &res)) { - res -= ofs; float d = dir.dot(res); - if (d < min) + if (d < min) { min = d; - if (d > max) + } + if (d > max) { max = d; + } } } - if (max < min) + if (max < min) { continue; //lost attempt + } float val = min + (max - min) * Math::randf(); @@ -162,20 +154,18 @@ bool GPUParticles3DEditorBase::_generate(Vector<Vector3> &points, Vector<Vector3 } void GPUParticles3DEditorBase::_node_selected(const NodePath &p_path) { - Node *sel = get_node(p_path); - if (!sel) + if (!sel) { return; + } if (!sel->is_class("Node3D")) { - EditorNode::get_singleton()->show_warning(vformat(TTR("\"%s\" doesn't inherit from Node3D."), sel->get_name())); return; } VisualInstance3D *vi = Object::cast_to<VisualInstance3D>(sel); if (!vi) { - EditorNode::get_singleton()->show_warning(vformat(TTR("\"%s\" doesn't contain geometry."), sel->get_name())); return; } @@ -183,7 +173,6 @@ void GPUParticles3DEditorBase::_node_selected(const NodePath &p_path) { geometry = vi->get_faces(VisualInstance3D::FACES_SOLID); if (geometry.size() == 0) { - EditorNode::get_singleton()->show_warning(vformat(TTR("\"%s\" doesn't contain face geometry."), sel->get_name())); return; } @@ -206,7 +195,6 @@ void GPUParticles3DEditorBase::_bind_methods() { } GPUParticles3DEditorBase::GPUParticles3DEditorBase() { - emission_dialog = memnew(ConfirmationDialog); emission_dialog->set_title(TTR("Create Emitter")); add_child(emission_dialog); @@ -234,7 +222,6 @@ GPUParticles3DEditorBase::GPUParticles3DEditorBase() { } void GPUParticles3DEditor::_node_removed(Node *p_node) { - if (p_node == node) { node = nullptr; hide(); @@ -242,7 +229,6 @@ 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("GPUParticles3D", "EditorIcons")); get_tree()->connect("node_removed", callable_mp(this, &GPUParticles3DEditor::_node_removed)); @@ -250,16 +236,15 @@ void GPUParticles3DEditor::_notification(int p_notification) { } void GPUParticles3DEditor::_menu_option(int p_option) { - switch (p_option) { - case MENU_OPTION_GENERATE_AABB: { float gen_time = node->get_lifetime(); - if (gen_time < 1.0) + if (gen_time < 1.0) { generate_seconds->set_value(1.0); - else + } else { generate_seconds->set_value(trunc(gen_time) + 1.0); + } generate_aabb->popup_centered(); } break; case MENU_OPTION_CREATE_EMISSION_VOLUME_FROM_NODE: { @@ -273,7 +258,6 @@ void GPUParticles3DEditor::_menu_option(int p_option) { } break; case MENU_OPTION_CONVERT_TO_CPU_PARTICLES: { - CPUParticles3D *cpu_particles = memnew(CPUParticles3D); cpu_particles->convert_from_particles(node); cpu_particles->set_name(node->get_name()); @@ -291,7 +275,6 @@ void GPUParticles3DEditor::_menu_option(int p_option) { } break; case MENU_OPTION_RESTART: { - node->restart(); } break; @@ -299,7 +282,6 @@ void GPUParticles3DEditor::_menu_option(int p_option) { } void GPUParticles3DEditor::_generate_aabb() { - float time = generate_seconds->get_value(); float running = 0.0; @@ -315,16 +297,16 @@ void GPUParticles3DEditor::_generate_aabb() { AABB rect; while (running < time) { - uint64_t ticks = OS::get_singleton()->get_ticks_usec(); ep.step("Generating...", int(running), true); OS::get_singleton()->delay_usec(1000); AABB capture = node->capture_aabb(); - if (rect == AABB()) + if (rect == AABB()) { rect = capture; - else + } else { rect.merge_with(capture); + } running += (OS::get_singleton()->get_ticks_usec() - ticks) / 1000000.0; } @@ -341,13 +323,11 @@ void GPUParticles3DEditor::_generate_aabb() { } void GPUParticles3DEditor::edit(GPUParticles3D *p_particles) { - base_node = p_particles; node = p_particles; } void GPUParticles3DEditor::_generate_emission_points() { - /// hacer codigo aca Vector<Vector3> points; Vector<Vector3> normals; @@ -385,7 +365,6 @@ void GPUParticles3DEditor::_generate_emission_points() { ERR_FAIL_COND(material.is_null()); if (normals.size() > 0) { - material->set_emission_shape(ParticlesMaterial::EMISSION_SHAPE_DIRECTED_POINTS); material->set_emission_point_count(point_count); material->set_emission_point_texture(tex); @@ -412,7 +391,6 @@ void GPUParticles3DEditor::_generate_emission_points() { material->set_emission_normal_texture(tex2); } else { - material->set_emission_shape(ParticlesMaterial::EMISSION_SHAPE_POINTS); material->set_emission_point_count(point_count); material->set_emission_point_texture(tex); @@ -423,7 +401,6 @@ void GPUParticles3DEditor::_bind_methods() { } GPUParticles3DEditor::GPUParticles3DEditor() { - node = nullptr; particles_editor_hb = memnew(HBoxContainer); Node3DEditor::get_singleton()->add_control_to_menu_panel(particles_editor_hb); @@ -456,17 +433,14 @@ GPUParticles3DEditor::GPUParticles3DEditor() { } void GPUParticles3DEditorPlugin::edit(Object *p_object) { - particles_editor->edit(Object::cast_to<GPUParticles3D>(p_object)); } bool GPUParticles3DEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("GPUParticles3D"); } void GPUParticles3DEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { particles_editor->show(); particles_editor->particles_editor_hb->show(); @@ -478,7 +452,6 @@ void GPUParticles3DEditorPlugin::make_visible(bool p_visible) { } GPUParticles3DEditorPlugin::GPUParticles3DEditorPlugin(EditorNode *p_node) { - editor = p_node; particles_editor = memnew(GPUParticles3DEditor); editor->get_viewport()->add_child(particles_editor); diff --git a/editor/plugins/gpu_particles_3d_editor_plugin.h b/editor/plugins/gpu_particles_3d_editor_plugin.h index cf1cff32c0..7838a63436 100644 --- a/editor/plugins/gpu_particles_3d_editor_plugin.h +++ b/editor/plugins/gpu_particles_3d_editor_plugin.h @@ -37,7 +37,6 @@ #include "scene/gui/spin_box.h" class GPUParticles3DEditorBase : public Control { - GDCLASS(GPUParticles3DEditorBase, Control); protected: @@ -65,7 +64,6 @@ public: }; class GPUParticles3DEditor : public GPUParticles3DEditorBase { - GDCLASS(GPUParticles3DEditor, GPUParticles3DEditorBase); ConfirmationDialog *generate_aabb; @@ -101,7 +99,6 @@ public: }; class GPUParticles3DEditorPlugin : public EditorPlugin { - GDCLASS(GPUParticles3DEditorPlugin, EditorPlugin); GPUParticles3DEditor *particles_editor; diff --git a/editor/plugins/gradient_editor_plugin.cpp b/editor/plugins/gradient_editor_plugin.cpp index 67de610ae7..13b5c8cef5 100644 --- a/editor/plugins/gradient_editor_plugin.cpp +++ b/editor/plugins/gradient_editor_plugin.cpp @@ -37,10 +37,11 @@ Size2 GradientEditor::get_minimum_size() const { return Size2(0, 60) * EDSCALE; } -void GradientEditor::_gradient_changed() { - if (editing) +void GradientEditor::_gradient_changed() { + if (editing) { return; + } editing = true; Vector<Gradient::Point> points = gradient->get_points(); @@ -49,7 +50,6 @@ void GradientEditor::_gradient_changed() { } void GradientEditor::_ramp_changed() { - editing = true; UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo(); undo_redo->create_action(TTR("Gradient Edited")); @@ -78,12 +78,10 @@ GradientEditor::GradientEditor() { /////////////////////// bool EditorInspectorPluginGradient::can_handle(Object *p_object) { - return Object::cast_to<Gradient>(p_object) != nullptr; } void EditorInspectorPluginGradient::parse_begin(Object *p_object) { - Gradient *gradient = Object::cast_to<Gradient>(p_object); Ref<Gradient> g(gradient); @@ -93,7 +91,6 @@ void EditorInspectorPluginGradient::parse_begin(Object *p_object) { } GradientEditorPlugin::GradientEditorPlugin(EditorNode *p_node) { - Ref<EditorInspectorPluginGradient> plugin; plugin.instance(); add_inspector_plugin(plugin); diff --git a/editor/plugins/gradient_editor_plugin.h b/editor/plugins/gradient_editor_plugin.h index 9ebd9610e5..0641d54d5c 100644 --- a/editor/plugins/gradient_editor_plugin.h +++ b/editor/plugins/gradient_editor_plugin.h @@ -62,7 +62,6 @@ public: }; class GradientEditorPlugin : public EditorPlugin { - GDCLASS(GradientEditorPlugin, EditorPlugin); public: diff --git a/editor/plugins/item_list_editor_plugin.cpp b/editor/plugins/item_list_editor_plugin.cpp index 1dbc78804b..7402baad57 100644 --- a/editor/plugins/item_list_editor_plugin.cpp +++ b/editor/plugins/item_list_editor_plugin.cpp @@ -34,16 +34,15 @@ #include "editor/editor_scale.h" bool ItemListPlugin::_set(const StringName &p_name, const Variant &p_value) { - String name = p_name; int idx = name.get_slice("/", 0).to_int(); String what = name.get_slice("/", 1); - if (what == "text") + if (what == "text") { set_item_text(idx, p_value); - else if (what == "icon") + } else if (what == "icon") { set_item_icon(idx, p_value); - else if (what == "checkable") { + } else if (what == "checkable") { // This keeps compatibility to/from versions where this property was a boolean, before radio buttons switch ((int)p_value) { case 0: @@ -54,54 +53,54 @@ bool ItemListPlugin::_set(const StringName &p_name, const Variant &p_value) { set_item_radio_checkable(idx, true); break; } - } else if (what == "checked") + } else if (what == "checked") { set_item_checked(idx, p_value); - else if (what == "id") + } else if (what == "id") { set_item_id(idx, p_value); - else if (what == "enabled") + } else if (what == "enabled") { set_item_enabled(idx, p_value); - else if (what == "separator") + } else if (what == "separator") { set_item_separator(idx, p_value); - else + } else { return false; + } return true; } bool ItemListPlugin::_get(const StringName &p_name, Variant &r_ret) const { - String name = p_name; int idx = name.get_slice("/", 0).to_int(); String what = name.get_slice("/", 1); - if (what == "text") + if (what == "text") { r_ret = get_item_text(idx); - else if (what == "icon") + } else if (what == "icon") { r_ret = get_item_icon(idx); - else if (what == "checkable") { + } else if (what == "checkable") { // This keeps compatibility to/from versions where this property was a boolean, before radio buttons if (!is_item_checkable(idx)) { r_ret = 0; } else { r_ret = is_item_radio_checkable(idx) ? 2 : 1; } - } else if (what == "checked") + } else if (what == "checked") { r_ret = is_item_checked(idx); - else if (what == "id") + } else if (what == "id") { r_ret = get_item_id(idx); - else if (what == "enabled") + } else if (what == "enabled") { r_ret = is_item_enabled(idx); - else if (what == "separator") + } else if (what == "separator") { r_ret = is_item_separator(idx); - else + } else { return false; + } return true; } -void ItemListPlugin::_get_property_list(List<PropertyInfo> *p_list) const { +void ItemListPlugin::_get_property_list(List<PropertyInfo> *p_list) const { for (int i = 0; i < get_item_count(); i++) { - String base = itos(i) + "/"; p_list->push_back(PropertyInfo(Variant::STRING, base + "text")); @@ -114,14 +113,17 @@ void ItemListPlugin::_get_property_list(List<PropertyInfo> *p_list) const { p_list->push_back(PropertyInfo(Variant::BOOL, base + "checked")); } - if (flags & FLAG_ID) + if (flags & FLAG_ID) { p_list->push_back(PropertyInfo(Variant::INT, base + "id", PROPERTY_HINT_RANGE, "-1,4096")); + } - if (flags & FLAG_ENABLE) + if (flags & FLAG_ENABLE) { p_list->push_back(PropertyInfo(Variant::BOOL, base + "enabled")); + } - if (flags & FLAG_SEPARATOR) + if (flags & FLAG_SEPARATOR) { p_list->push_back(PropertyInfo(Variant::BOOL, base + "separator")); + } } } @@ -130,120 +132,100 @@ void ItemListPlugin::_get_property_list(List<PropertyInfo> *p_list) const { /////////////////////////////////////////////////////////////// void ItemListOptionButtonPlugin::set_object(Object *p_object) { - ob = Object::cast_to<OptionButton>(p_object); } bool ItemListOptionButtonPlugin::handles(Object *p_object) const { - return p_object->is_class("OptionButton"); } int ItemListOptionButtonPlugin::get_flags() const { - return FLAG_ICON | FLAG_ID | FLAG_ENABLE; } void ItemListOptionButtonPlugin::add_item() { - ob->add_item(vformat(TTR("Item %d"), ob->get_item_count())); _change_notify(); } int ItemListOptionButtonPlugin::get_item_count() const { - return ob->get_item_count(); } void ItemListOptionButtonPlugin::erase(int p_idx) { - ob->remove_item(p_idx); _change_notify(); } ItemListOptionButtonPlugin::ItemListOptionButtonPlugin() { - ob = nullptr; } /////////////////////////////////////////////////////////////// void ItemListPopupMenuPlugin::set_object(Object *p_object) { - - if (p_object->is_class("MenuButton")) + if (p_object->is_class("MenuButton")) { pp = Object::cast_to<MenuButton>(p_object)->get_popup(); - else + } else { pp = Object::cast_to<PopupMenu>(p_object); + } } bool ItemListPopupMenuPlugin::handles(Object *p_object) const { - return p_object->is_class("PopupMenu") || p_object->is_class("MenuButton"); } int ItemListPopupMenuPlugin::get_flags() const { - return FLAG_ICON | FLAG_CHECKABLE | FLAG_ID | FLAG_ENABLE | FLAG_SEPARATOR; } void ItemListPopupMenuPlugin::add_item() { - pp->add_item(vformat(TTR("Item %d"), pp->get_item_count())); _change_notify(); } int ItemListPopupMenuPlugin::get_item_count() const { - return pp->get_item_count(); } void ItemListPopupMenuPlugin::erase(int p_idx) { - pp->remove_item(p_idx); _change_notify(); } ItemListPopupMenuPlugin::ItemListPopupMenuPlugin() { - pp = nullptr; } /////////////////////////////////////////////////////////////// void ItemListItemListPlugin::set_object(Object *p_object) { - pp = Object::cast_to<ItemList>(p_object); } bool ItemListItemListPlugin::handles(Object *p_object) const { - return p_object->is_class("ItemList"); } int ItemListItemListPlugin::get_flags() const { - return FLAG_ICON | FLAG_ENABLE; } void ItemListItemListPlugin::add_item() { - pp->add_item(vformat(TTR("Item %d"), pp->get_item_count())); _change_notify(); } int ItemListItemListPlugin::get_item_count() const { - return pp->get_item_count(); } void ItemListItemListPlugin::erase(int p_idx) { - pp->remove_item(p_idx); _change_notify(); } ItemListItemListPlugin::ItemListItemListPlugin() { - pp = nullptr; } @@ -252,7 +234,6 @@ ItemListItemListPlugin::ItemListItemListPlugin() { /////////////////////////////////////////////////////////////// void ItemListEditor::_node_removed(Node *p_node) { - if (p_node == item_list) { item_list = nullptr; hide(); @@ -261,34 +242,32 @@ void ItemListEditor::_node_removed(Node *p_node) { } void ItemListEditor::_notification(int p_notification) { - if (p_notification == NOTIFICATION_ENTER_TREE || p_notification == NOTIFICATION_THEME_CHANGED) { - add_button->set_icon(get_theme_icon("Add", "EditorIcons")); del_button->set_icon(get_theme_icon("Remove", "EditorIcons")); } else if (p_notification == NOTIFICATION_READY) { - get_tree()->connect("node_removed", callable_mp(this, &ItemListEditor::_node_removed)); } } void ItemListEditor::_add_pressed() { - - if (selected_idx == -1) + if (selected_idx == -1) { return; + } item_plugins[selected_idx]->add_item(); } void ItemListEditor::_delete_pressed() { - - if (selected_idx == -1) + if (selected_idx == -1) { return; + } String current_selected = (String)property_editor->get_selected_path(); - if (current_selected == "") + if (current_selected == "") { return; + } // FIXME: Currently relying on selecting a *property* to derive what item to delete // e.g. you select "1/enabled" to delete item 1. @@ -301,12 +280,10 @@ void ItemListEditor::_delete_pressed() { } void ItemListEditor::_edit_items() { - dialog->popup_centered_clamped(Vector2(425, 1200) * EDSCALE, 0.8); } void ItemListEditor::edit(Node *p_item_list) { - item_list = p_item_list; if (!item_list) { @@ -317,7 +294,6 @@ void ItemListEditor::edit(Node *p_item_list) { for (int i = 0; i < item_plugins.size(); i++) { if (item_plugins[i]->handles(p_item_list)) { - item_plugins[i]->set_object(p_item_list); property_editor->edit(item_plugins[i]); @@ -333,7 +309,6 @@ void ItemListEditor::edit(Node *p_item_list) { } bool ItemListEditor::handles(Object *p_object) const { - for (int i = 0; i < item_plugins.size(); i++) { if (item_plugins[i]->handles(p_object)) { return true; @@ -347,7 +322,6 @@ void ItemListEditor::_bind_methods() { } ItemListEditor::ItemListEditor() { - selected_idx = -1; item_list = nullptr; @@ -386,34 +360,29 @@ ItemListEditor::ItemListEditor() { } ItemListEditor::~ItemListEditor() { - - for (int i = 0; i < item_plugins.size(); i++) + for (int i = 0; i < item_plugins.size(); i++) { memdelete(item_plugins[i]); + } } void ItemListEditorPlugin::edit(Object *p_object) { - item_list_editor->edit(Object::cast_to<Node>(p_object)); } bool ItemListEditorPlugin::handles(Object *p_object) const { - return item_list_editor->handles(p_object); } void ItemListEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { item_list_editor->show(); } else { - item_list_editor->hide(); item_list_editor->edit(nullptr); } } ItemListEditorPlugin::ItemListEditorPlugin(EditorNode *p_node) { - editor = p_node; item_list_editor = memnew(ItemListEditor); CanvasItemEditor::get_singleton()->add_control_to_menu_panel(item_list_editor); diff --git a/editor/plugins/item_list_editor_plugin.h b/editor/plugins/item_list_editor_plugin.h index 8dcf938139..61dd617e3b 100644 --- a/editor/plugins/item_list_editor_plugin.h +++ b/editor/plugins/item_list_editor_plugin.h @@ -40,7 +40,6 @@ #include "scene/gui/popup_menu.h" class ItemListPlugin : public Object { - GDCLASS(ItemListPlugin, Object); protected: @@ -96,7 +95,6 @@ public: /////////////////////////////////////////////////////////////// class ItemListOptionButtonPlugin : public ItemListPlugin { - GDCLASS(ItemListOptionButtonPlugin, ItemListPlugin); OptionButton *ob; @@ -126,7 +124,6 @@ public: }; class ItemListPopupMenuPlugin : public ItemListPlugin { - GDCLASS(ItemListPopupMenuPlugin, ItemListPlugin); PopupMenu *pp; @@ -169,7 +166,6 @@ public: /////////////////////////////////////////////////////////////// class ItemListItemListPlugin : public ItemListPlugin { - GDCLASS(ItemListItemListPlugin, ItemListPlugin); ItemList *pp; @@ -198,7 +194,6 @@ public: /////////////////////////////////////////////////////////////// class ItemListEditor : public HBoxContainer { - GDCLASS(ItemListEditor, HBoxContainer); Node *item_list; @@ -235,7 +230,6 @@ public: }; class ItemListEditorPlugin : public EditorPlugin { - GDCLASS(ItemListEditorPlugin, EditorPlugin); ItemListEditor *item_list_editor; diff --git a/editor/plugins/light_occluder_2d_editor_plugin.cpp b/editor/plugins/light_occluder_2d_editor_plugin.cpp index f8550a884b..e422140efa 100644 --- a/editor/plugins/light_occluder_2d_editor_plugin.cpp +++ b/editor/plugins/light_occluder_2d_editor_plugin.cpp @@ -31,10 +31,8 @@ #include "light_occluder_2d_editor_plugin.h" Ref<OccluderPolygon2D> LightOccluder2DEditor::_ensure_occluder() const { - Ref<OccluderPolygon2D> occluder = node->get_occluder_polygon(); if (!occluder.is_valid()) { - occluder = Ref<OccluderPolygon2D>(memnew(OccluderPolygon2D)); node->set_occluder_polygon(occluder); } @@ -42,64 +40,59 @@ Ref<OccluderPolygon2D> LightOccluder2DEditor::_ensure_occluder() const { } Node2D *LightOccluder2DEditor::_get_node() const { - return node; } void LightOccluder2DEditor::_set_node(Node *p_polygon) { - node = Object::cast_to<LightOccluder2D>(p_polygon); } bool LightOccluder2DEditor::_is_line() const { - Ref<OccluderPolygon2D> occluder = node->get_occluder_polygon(); - if (occluder.is_valid()) + if (occluder.is_valid()) { return !occluder->is_closed(); - else + } else { return false; + } } int LightOccluder2DEditor::_get_polygon_count() const { - Ref<OccluderPolygon2D> occluder = node->get_occluder_polygon(); - if (occluder.is_valid()) + if (occluder.is_valid()) { return occluder->get_polygon().size(); - else + } else { return 0; + } } Variant LightOccluder2DEditor::_get_polygon(int p_idx) const { - Ref<OccluderPolygon2D> occluder = node->get_occluder_polygon(); - if (occluder.is_valid()) + if (occluder.is_valid()) { return occluder->get_polygon(); - else + } else { return Variant(Vector<Vector2>()); + } } void LightOccluder2DEditor::_set_polygon(int p_idx, const Variant &p_polygon) const { - Ref<OccluderPolygon2D> occluder = _ensure_occluder(); occluder->set_polygon(p_polygon); } void LightOccluder2DEditor::_action_set_polygon(int p_idx, const Variant &p_previous, const Variant &p_polygon) { - Ref<OccluderPolygon2D> occluder = _ensure_occluder(); undo_redo->add_do_method(occluder.ptr(), "set_polygon", p_polygon); undo_redo->add_undo_method(occluder.ptr(), "set_polygon", p_previous); } bool LightOccluder2DEditor::_has_resource() const { - return node && node->get_occluder_polygon().is_valid(); } void LightOccluder2DEditor::_create_resource() { - - if (!node) + if (!node) { return; + } undo_redo->create_action(TTR("Create Occluder Polygon")); undo_redo->add_do_method(node, "set_occluder_polygon", Ref<OccluderPolygon2D>(memnew(OccluderPolygon2D))); @@ -111,7 +104,6 @@ void LightOccluder2DEditor::_create_resource() { LightOccluder2DEditor::LightOccluder2DEditor(EditorNode *p_editor) : AbstractPolygon2DEditor(p_editor) { - node = nullptr; } diff --git a/editor/plugins/light_occluder_2d_editor_plugin.h b/editor/plugins/light_occluder_2d_editor_plugin.h index 74ae9e0889..11c9f2b2a4 100644 --- a/editor/plugins/light_occluder_2d_editor_plugin.h +++ b/editor/plugins/light_occluder_2d_editor_plugin.h @@ -35,7 +35,6 @@ #include "scene/2d/light_occluder_2d.h" class LightOccluder2DEditor : public AbstractPolygon2DEditor { - GDCLASS(LightOccluder2DEditor, AbstractPolygon2DEditor); LightOccluder2D *node; @@ -61,7 +60,6 @@ public: }; class LightOccluder2DEditorPlugin : public AbstractPolygon2DEditorPlugin { - GDCLASS(LightOccluder2DEditorPlugin, AbstractPolygon2DEditorPlugin); public: diff --git a/editor/plugins/line_2d_editor_plugin.cpp b/editor/plugins/line_2d_editor_plugin.cpp index 5b887390a6..77eeb19d26 100644 --- a/editor/plugins/line_2d_editor_plugin.cpp +++ b/editor/plugins/line_2d_editor_plugin.cpp @@ -31,32 +31,26 @@ #include "line_2d_editor_plugin.h" Node2D *Line2DEditor::_get_node() const { - return node; } void Line2DEditor::_set_node(Node *p_line) { - node = Object::cast_to<Line2D>(p_line); } bool Line2DEditor::_is_line() const { - return true; } Variant Line2DEditor::_get_polygon(int p_idx) const { - return _get_node()->get("points"); } void Line2DEditor::_set_polygon(int p_idx, const Variant &p_polygon) const { - _get_node()->set("points", p_polygon); } void Line2DEditor::_action_set_polygon(int p_idx, const Variant &p_previous, const Variant &p_polygon) { - Node2D *node = _get_node(); undo_redo->add_do_method(node, "set_points", p_polygon); undo_redo->add_undo_method(node, "set_points", p_previous); diff --git a/editor/plugins/line_2d_editor_plugin.h b/editor/plugins/line_2d_editor_plugin.h index ef54dbc3f7..bf411a070a 100644 --- a/editor/plugins/line_2d_editor_plugin.h +++ b/editor/plugins/line_2d_editor_plugin.h @@ -35,7 +35,6 @@ #include "scene/2d/line_2d.h" class Line2DEditor : public AbstractPolygon2DEditor { - GDCLASS(Line2DEditor, AbstractPolygon2DEditor); Line2D *node; @@ -54,7 +53,6 @@ public: }; class Line2DEditorPlugin : public AbstractPolygon2DEditorPlugin { - GDCLASS(Line2DEditorPlugin, AbstractPolygon2DEditorPlugin); public: diff --git a/editor/plugins/material_editor_plugin.cpp b/editor/plugins/material_editor_plugin.cpp index f63bcb69b8..e49cfd51f7 100644 --- a/editor/plugins/material_editor_plugin.cpp +++ b/editor/plugins/material_editor_plugin.cpp @@ -36,9 +36,7 @@ #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"); if (first_enter) { @@ -59,7 +57,6 @@ void MaterialEditor::_notification(int p_what) { } if (p_what == NOTIFICATION_DRAW) { - Ref<Texture2D> checkerboard = get_theme_icon("Checkerboard", "EditorIcons"); Size2 size = get_size(); @@ -68,20 +65,17 @@ void MaterialEditor::_notification(int p_what) { } void MaterialEditor::edit(Ref<Material> p_material, const Ref<Environment> &p_env) { - material = p_material; camera->set_environment(p_env); if (!material.is_null()) { sphere_instance->set_material_override(material); box_instance->set_material_override(material); } else { - hide(); } } void MaterialEditor::_button_pressed(Node *p_button) { - if (p_button == light_1_switch) { light1->set_visible(!light_1_switch->is_pressed()); } @@ -111,7 +105,6 @@ void MaterialEditor::_bind_methods() { } MaterialEditor::MaterialEditor() { - vc = memnew(SubViewportContainer); vc->set_stretch(true); add_child(vc); @@ -209,16 +202,15 @@ MaterialEditor::MaterialEditor() { /////////////////////// bool EditorInspectorPluginMaterial::can_handle(Object *p_object) { - Material *material = Object::cast_to<Material>(p_object); - if (!material) + if (!material) { return false; + } return material->get_shader_mode() == Shader::MODE_SPATIAL; } void EditorInspectorPluginMaterial::parse_begin(Object *p_object) { - Material *material = Object::cast_to<Material>(p_object); if (!material) { return; @@ -240,23 +232,21 @@ EditorInspectorPluginMaterial::EditorInspectorPluginMaterial() { } MaterialEditorPlugin::MaterialEditorPlugin(EditorNode *p_node) { - Ref<EditorInspectorPluginMaterial> plugin; plugin.instance(); add_inspector_plugin(plugin); } String StandardMaterial3DConversionPlugin::converts_to() const { - return "ShaderMaterial"; } -bool StandardMaterial3DConversionPlugin::handles(const Ref<Resource> &p_resource) const { +bool StandardMaterial3DConversionPlugin::handles(const Ref<Resource> &p_resource) const { Ref<StandardMaterial3D> mat = p_resource; return mat.is_valid(); } -Ref<Resource> StandardMaterial3DConversionPlugin::convert(const Ref<Resource> &p_resource) const { +Ref<Resource> StandardMaterial3DConversionPlugin::convert(const Ref<Resource> &p_resource) const { Ref<StandardMaterial3D> mat = p_resource; ERR_FAIL_COND_V(!mat.is_valid(), Ref<Resource>()); @@ -276,7 +266,6 @@ Ref<Resource> StandardMaterial3DConversionPlugin::convert(const Ref<Resource> &p RS::get_singleton()->shader_get_param_list(mat->get_shader_rid(), ¶ms); for (List<PropertyInfo>::Element *E = params.front(); E; E = E->next()) { - // Texture parameter has to be treated specially since StandardMaterial3D saved it // as RID but ShaderMaterial needs Texture itself Ref<Texture2D> texture = mat->get_texture_by_name(E->get().name); @@ -293,16 +282,15 @@ Ref<Resource> StandardMaterial3DConversionPlugin::convert(const Ref<Resource> &p } String ParticlesMaterialConversionPlugin::converts_to() const { - return "ShaderMaterial"; } -bool ParticlesMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const { +bool ParticlesMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const { Ref<ParticlesMaterial> mat = p_resource; return mat.is_valid(); } -Ref<Resource> ParticlesMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const { +Ref<Resource> ParticlesMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const { Ref<ParticlesMaterial> mat = p_resource; ERR_FAIL_COND_V(!mat.is_valid(), Ref<Resource>()); @@ -331,16 +319,15 @@ Ref<Resource> ParticlesMaterialConversionPlugin::convert(const Ref<Resource> &p_ } String CanvasItemMaterialConversionPlugin::converts_to() const { - return "ShaderMaterial"; } -bool CanvasItemMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const { +bool CanvasItemMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const { Ref<CanvasItemMaterial> mat = p_resource; return mat.is_valid(); } -Ref<Resource> CanvasItemMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const { +Ref<Resource> CanvasItemMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const { Ref<CanvasItemMaterial> mat = p_resource; ERR_FAIL_COND_V(!mat.is_valid(), Ref<Resource>()); @@ -369,16 +356,15 @@ Ref<Resource> CanvasItemMaterialConversionPlugin::convert(const Ref<Resource> &p } String ProceduralSkyMaterialConversionPlugin::converts_to() const { - return "ShaderMaterial"; } -bool ProceduralSkyMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const { +bool ProceduralSkyMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const { Ref<ProceduralSkyMaterial> mat = p_resource; return mat.is_valid(); } -Ref<Resource> ProceduralSkyMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const { +Ref<Resource> ProceduralSkyMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const { Ref<ProceduralSkyMaterial> mat = p_resource; ERR_FAIL_COND_V(!mat.is_valid(), Ref<Resource>()); @@ -407,16 +393,15 @@ Ref<Resource> ProceduralSkyMaterialConversionPlugin::convert(const Ref<Resource> } String PanoramaSkyMaterialConversionPlugin::converts_to() const { - return "ShaderMaterial"; } -bool PanoramaSkyMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const { +bool PanoramaSkyMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const { Ref<PanoramaSkyMaterial> mat = p_resource; return mat.is_valid(); } -Ref<Resource> PanoramaSkyMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const { +Ref<Resource> PanoramaSkyMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const { Ref<PanoramaSkyMaterial> mat = p_resource; ERR_FAIL_COND_V(!mat.is_valid(), Ref<Resource>()); @@ -445,16 +430,15 @@ Ref<Resource> PanoramaSkyMaterialConversionPlugin::convert(const Ref<Resource> & } String PhysicalSkyMaterialConversionPlugin::converts_to() const { - return "ShaderMaterial"; } -bool PhysicalSkyMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const { +bool PhysicalSkyMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const { Ref<PhysicalSkyMaterial> mat = p_resource; return mat.is_valid(); } -Ref<Resource> PhysicalSkyMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const { +Ref<Resource> PhysicalSkyMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const { Ref<PhysicalSkyMaterial> mat = p_resource; ERR_FAIL_COND_V(!mat.is_valid(), Ref<Resource>()); diff --git a/editor/plugins/material_editor_plugin.h b/editor/plugins/material_editor_plugin.h index 50036e4f72..e03cb1b3ab 100644 --- a/editor/plugins/material_editor_plugin.h +++ b/editor/plugins/material_editor_plugin.h @@ -44,7 +44,6 @@ class SubViewportContainer; class MaterialEditor : public Control { - GDCLASS(MaterialEditor, Control); SubViewportContainer *vc; @@ -91,7 +90,6 @@ public: }; class MaterialEditorPlugin : public EditorPlugin { - GDCLASS(MaterialEditorPlugin, EditorPlugin); public: diff --git a/editor/plugins/mesh_editor_plugin.cpp b/editor/plugins/mesh_editor_plugin.cpp index 3e603fa499..9d396467c3 100644 --- a/editor/plugins/mesh_editor_plugin.cpp +++ b/editor/plugins/mesh_editor_plugin.cpp @@ -33,15 +33,13 @@ #include "editor/editor_scale.h" void MeshEditor::_gui_input(Ref<InputEvent> p_event) { - Ref<InputEventMouseMotion> mm = p_event; if (mm.is_valid() && mm->get_button_mask() & BUTTON_MASK_LEFT) { - rot_x -= mm->get_relative().y * 0.01; rot_y -= mm->get_relative().x * 0.01; - if (rot_x < -Math_PI / 2) + if (rot_x < -Math_PI / 2) { rot_x = -Math_PI / 2; - else if (rot_x > Math_PI / 2) { + } else if (rot_x > Math_PI / 2) { rot_x = Math_PI / 2; } _update_rotation(); @@ -49,9 +47,7 @@ void MeshEditor::_gui_input(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) { @@ -67,7 +63,6 @@ void MeshEditor::_notification(int p_what) { } void MeshEditor::_update_rotation() { - Transform t; t.basis.rotate(Vector3(0, 1, 0), -rot_y); t.basis.rotate(Vector3(1, 0, 0), -rot_x); @@ -75,7 +70,6 @@ void MeshEditor::_update_rotation() { } void MeshEditor::edit(Ref<Mesh> p_mesh) { - mesh = p_mesh; mesh_instance->set_mesh(mesh); @@ -98,7 +92,6 @@ void MeshEditor::edit(Ref<Mesh> p_mesh) { } void MeshEditor::_button_pressed(Node *p_button) { - if (p_button == light_1_switch) { light1->set_visible(!light_1_switch->is_pressed()); } @@ -109,12 +102,10 @@ void MeshEditor::_button_pressed(Node *p_button) { } void MeshEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_gui_input"), &MeshEditor::_gui_input); } MeshEditor::MeshEditor() { - viewport = memnew(SubViewport); Ref<World3D> world_3d; world_3d.instance(); @@ -172,12 +163,10 @@ MeshEditor::MeshEditor() { /////////////////////// bool EditorInspectorPluginMesh::can_handle(Object *p_object) { - return Object::cast_to<Mesh>(p_object) != nullptr; } void EditorInspectorPluginMesh::parse_begin(Object *p_object) { - Mesh *mesh = Object::cast_to<Mesh>(p_object); if (!mesh) { return; @@ -190,7 +179,6 @@ void EditorInspectorPluginMesh::parse_begin(Object *p_object) { } MeshEditorPlugin::MeshEditorPlugin(EditorNode *p_node) { - Ref<EditorInspectorPluginMesh> plugin; plugin.instance(); add_inspector_plugin(plugin); diff --git a/editor/plugins/mesh_editor_plugin.h b/editor/plugins/mesh_editor_plugin.h index 072e21f260..6f171a0eab 100644 --- a/editor/plugins/mesh_editor_plugin.h +++ b/editor/plugins/mesh_editor_plugin.h @@ -40,7 +40,6 @@ #include "scene/resources/material.h" class MeshEditor : public SubViewportContainer { - GDCLASS(MeshEditor, SubViewportContainer); float rot_x; @@ -82,7 +81,6 @@ public: }; class MeshEditorPlugin : public EditorPlugin { - GDCLASS(MeshEditorPlugin, EditorPlugin); public: diff --git a/editor/plugins/mesh_instance_3d_editor_plugin.cpp b/editor/plugins/mesh_instance_3d_editor_plugin.cpp index 7819f62bc7..1b65987af0 100644 --- a/editor/plugins/mesh_instance_3d_editor_plugin.cpp +++ b/editor/plugins/mesh_instance_3d_editor_plugin.cpp @@ -38,7 +38,6 @@ #include "scene/gui/box_container.h" void MeshInstance3DEditor::_node_removed(Node *p_node) { - if (p_node == node) { node = nullptr; options->hide(); @@ -46,12 +45,10 @@ void MeshInstance3DEditor::_node_removed(Node *p_node) { } void MeshInstance3DEditor::edit(MeshInstance3D *p_mesh) { - node = p_mesh; } void MeshInstance3DEditor::_menu_option(int p_option) { - Ref<Mesh> mesh = node->get_mesh(); if (mesh.is_null()) { err_dialog->set_text(TTR("Mesh is empty!")); @@ -61,7 +58,6 @@ void MeshInstance3DEditor::_menu_option(int p_option) { switch (p_option) { case MENU_OPTION_CREATE_STATIC_TRIMESH_BODY: { - EditorSelection *editor_selection = EditorNode::get_singleton()->get_editor_selection(); UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); @@ -95,18 +91,20 @@ void MeshInstance3DEditor::_menu_option(int p_option) { ur->create_action(TTR("Create Static Trimesh Body")); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - MeshInstance3D *instance = Object::cast_to<MeshInstance3D>(E->get()); - if (!instance) + if (!instance) { continue; + } Ref<Mesh> m = instance->get_mesh(); - if (m.is_null()) + if (m.is_null()) { continue; + } Ref<Shape3D> shape = m->create_trimesh_shape(); - if (shape.is_null()) + if (shape.is_null()) { continue; + } CollisionShape3D *cshape = memnew(CollisionShape3D); cshape->set_shape(shape); @@ -127,7 +125,6 @@ void MeshInstance3DEditor::_menu_option(int p_option) { } break; case MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE: { - if (node == get_tree()->get_edited_scene_root()) { err_dialog->set_text(TTR("This doesn't work on scene root!")); err_dialog->popup_centered(); @@ -135,8 +132,9 @@ void MeshInstance3DEditor::_menu_option(int p_option) { } Ref<Shape3D> shape = mesh->create_trimesh_shape(); - if (shape.is_null()) + if (shape.is_null()) { return; + } CollisionShape3D *cshape = memnew(CollisionShape3D); cshape->set_shape(shape); @@ -155,7 +153,6 @@ void MeshInstance3DEditor::_menu_option(int p_option) { ur->commit_action(); } break; case MENU_OPTION_CREATE_SINGLE_CONVEX_COLLISION_SHAPE: { - if (node == get_tree()->get_edited_scene_root()) { err_dialog->set_text(TTR("Can't create a single convex collision shape for the scene root.")); err_dialog->popup_centered(); @@ -189,7 +186,6 @@ void MeshInstance3DEditor::_menu_option(int p_option) { } break; case MENU_OPTION_CREATE_MULTIPLE_CONVEX_COLLISION_SHAPES: { - if (node == get_tree()->get_edited_scene_root()) { err_dialog->set_text(TTR("Can't create multiple convex collision shapes for the scene root.")); err_dialog->popup_centered(); @@ -208,7 +204,6 @@ void MeshInstance3DEditor::_menu_option(int p_option) { ur->create_action(TTR("Create Multiple Convex Shapes")); for (int i = 0; i < shapes.size(); i++) { - CollisionShape3D *cshape = memnew(CollisionShape3D); cshape->set_shape(shapes[i]); cshape->set_transform(node->get_transform()); @@ -226,11 +221,11 @@ void MeshInstance3DEditor::_menu_option(int p_option) { } break; case MENU_OPTION_CREATE_NAVMESH: { - Ref<NavigationMesh> nmesh = memnew(NavigationMesh); - if (nmesh.is_null()) + if (nmesh.is_null()) { return; + } nmesh->create_from_mesh(mesh); NavigationRegion3D *nmi = memnew(NavigationRegion3D); @@ -250,11 +245,9 @@ void MeshInstance3DEditor::_menu_option(int p_option) { } break; case MENU_OPTION_CREATE_OUTLINE_MESH: { - outline_dialog->popup_centered(Vector2(200, 90)); } break; case MENU_OPTION_CREATE_UV2: { - Ref<ArrayMesh> mesh2 = node->get_mesh(); if (!mesh2.is_valid()) { err_dialog->set_text(TTR("Contained Mesh is not of type ArrayMesh.")); @@ -292,15 +285,15 @@ void MeshInstance3DEditor::_menu_option(int p_option) { } struct MeshInstance3DEditorEdgeSort { - Vector2 a; Vector2 b; bool operator<(const MeshInstance3DEditorEdgeSort &p_b) const { - if (a == p_b.a) + if (a == p_b.a) { return b < p_b.b; - else + } else { return a < p_b.a; + } } MeshInstance3DEditorEdgeSort() {} @@ -316,15 +309,15 @@ struct MeshInstance3DEditorEdgeSort { }; void MeshInstance3DEditor::_create_uv_lines(int p_layer) { - Ref<Mesh> mesh = node->get_mesh(); ERR_FAIL_COND(!mesh.is_valid()); Set<MeshInstance3DEditorEdgeSort> edges; uv_lines.clear(); for (int i = 0; i < mesh->get_surface_count(); i++) { - if (mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) + if (mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) { continue; + } Array a = mesh->surface_get_arrays(i); Vector<Vector2> uv = a[p_layer == 0 ? Mesh::ARRAY_TEX_UV : Mesh::ARRAY_TEX_UV2]; @@ -349,9 +342,7 @@ void MeshInstance3DEditor::_create_uv_lines(int p_layer) { } for (int j = 0; j < ic; j += 3) { - for (int k = 0; k < 3; k++) { - MeshInstance3DEditorEdgeSort edge; if (ri) { edge.a = r[ri[j + k]]; @@ -361,8 +352,9 @@ void MeshInstance3DEditor::_create_uv_lines(int p_layer) { edge.b = r[j + ((k + 1) % 3)]; } - if (edges.has(edge)) + if (edges.has(edge)) { continue; + } uv_lines.push_back(edge.a); uv_lines.push_back(edge.b); @@ -375,9 +367,9 @@ void MeshInstance3DEditor::_create_uv_lines(int p_layer) { } void MeshInstance3DEditor::_debug_uv_draw() { - - if (uv_lines.size() == 0) + if (uv_lines.size() == 0) { return; + } debug_uv->set_clip_contents(true); debug_uv->draw_rect(Rect2(Vector2(), debug_uv->get_size()), Color(0.2, 0.2, 0.0)); @@ -386,7 +378,6 @@ void MeshInstance3DEditor::_debug_uv_draw() { } void MeshInstance3DEditor::_create_outline_mesh() { - Ref<Mesh> mesh = node->get_mesh(); if (mesh.is_null()) { err_dialog->set_text(TTR("MeshInstance3D lacks a Mesh.")); @@ -435,7 +426,6 @@ void MeshInstance3DEditor::_bind_methods() { } MeshInstance3DEditor::MeshInstance3DEditor() { - options = memnew(MenuButton); options->set_switch_on_hover(true); Node3DEditor::get_singleton()->add_control_to_menu_panel(options); @@ -495,28 +485,23 @@ MeshInstance3DEditor::MeshInstance3DEditor() { } void MeshInstance3DEditorPlugin::edit(Object *p_object) { - mesh_editor->edit(Object::cast_to<MeshInstance3D>(p_object)); } bool MeshInstance3DEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("MeshInstance3D"); } void MeshInstance3DEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { mesh_editor->options->show(); } else { - mesh_editor->options->hide(); mesh_editor->edit(nullptr); } } MeshInstance3DEditorPlugin::MeshInstance3DEditorPlugin(EditorNode *p_node) { - editor = p_node; mesh_editor = memnew(MeshInstance3DEditor); editor->get_viewport()->add_child(mesh_editor); diff --git a/editor/plugins/mesh_instance_3d_editor_plugin.h b/editor/plugins/mesh_instance_3d_editor_plugin.h index a5d90c42d5..3350a792bc 100644 --- a/editor/plugins/mesh_instance_3d_editor_plugin.h +++ b/editor/plugins/mesh_instance_3d_editor_plugin.h @@ -37,7 +37,6 @@ #include "scene/gui/spin_box.h" class MeshInstance3DEditor : public Control { - GDCLASS(MeshInstance3DEditor, Control); enum Menu { @@ -84,7 +83,6 @@ public: }; class MeshInstance3DEditorPlugin : public EditorPlugin { - GDCLASS(MeshInstance3DEditorPlugin, EditorPlugin); MeshInstance3DEditor *mesh_editor; diff --git a/editor/plugins/mesh_library_editor_plugin.cpp b/editor/plugins/mesh_library_editor_plugin.cpp index 1ca8be528f..7690beeee8 100644 --- a/editor/plugins/mesh_library_editor_plugin.cpp +++ b/editor/plugins/mesh_library_editor_plugin.cpp @@ -41,18 +41,15 @@ #include "scene/resources/packed_scene.h" void MeshLibraryEditor::edit(const Ref<MeshLibrary> &p_mesh_library) { - mesh_library = p_mesh_library; - if (mesh_library.is_valid()) + if (mesh_library.is_valid()) { menu->get_popup()->set_item_disabled(menu->get_popup()->get_item_index(MENU_OPTION_UPDATE_FROM_SCENE), !mesh_library->has_meta("_editor_source_scene")); + } } void MeshLibraryEditor::_menu_confirm() { - switch (option) { - case MENU_OPTION_REMOVE_ITEM: { - mesh_library->remove_item(to_erase); } break; case MENU_OPTION_UPDATE_FROM_SCENE: { @@ -67,14 +64,13 @@ void MeshLibraryEditor::_menu_confirm() { } void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library, bool p_merge) { - - if (!p_merge) + if (!p_merge) { p_library->clear(); + } Map<int, MeshInstance3D *> mesh_instances; for (int i = 0; i < p_scene->get_child_count(); i++) { - Node *child = p_scene->get_child(i); if (!Object::cast_to<MeshInstance3D>(child)) { @@ -84,14 +80,16 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library, continue; } - } else + } else { continue; + } } MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(child); Ref<Mesh> mesh = mi->get_mesh(); - if (mesh.is_null()) + if (mesh.is_null()) { continue; + } mesh = mesh->duplicate(); for (int j = 0; j < mesh->get_surface_count(); ++j) { @@ -104,7 +102,6 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library, int id = p_library->find_item_by_name(mi->get_name()); if (id < 0) { - id = p_library->get_last_unused_item_id(); p_library->create_item(id); p_library->set_item_name(id, mi->get_name()); @@ -116,28 +113,29 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library, Vector<MeshLibrary::ShapeData> collisions; for (int j = 0; j < mi->get_child_count(); j++) { - Node *child2 = mi->get_child(j); - if (!Object::cast_to<StaticBody3D>(child2)) + if (!Object::cast_to<StaticBody3D>(child2)) { continue; + } StaticBody3D *sb = Object::cast_to<StaticBody3D>(child2); List<uint32_t> shapes; sb->get_shape_owners(&shapes); for (List<uint32_t>::Element *E = shapes.front(); E; E = E->next()) { - if (sb->is_shape_owner_disabled(E->get())) + if (sb->is_shape_owner_disabled(E->get())) { continue; + } //Transform shape_transform = sb->shape_owner_get_transform(E->get()); //shape_transform.set_origin(shape_transform.get_origin() - phys_offset); for (int k = 0; k < sb->shape_owner_get_shape_count(E->get()); k++) { - Ref<Shape3D> collision = sb->shape_owner_get_shape(E->get(), k); - if (!collision.is_valid()) + if (!collision.is_valid()) { continue; + } MeshLibrary::ShapeData shape_data; shape_data.shape = collision; shape_data.local_transform = sb->get_transform() * sb->shape_owner_get_transform(E->get()); @@ -152,13 +150,15 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library, Transform navmesh_transform; for (int j = 0; j < mi->get_child_count(); j++) { Node *child2 = mi->get_child(j); - if (!Object::cast_to<NavigationRegion3D>(child2)) + if (!Object::cast_to<NavigationRegion3D>(child2)) { continue; + } NavigationRegion3D *sb = Object::cast_to<NavigationRegion3D>(child2); navmesh = sb->get_navigation_mesh(); navmesh_transform = sb->get_transform(); - if (!navmesh.is_null()) + if (!navmesh.is_null()) { break; + } } if (!navmesh.is_null()) { p_library->set_item_navmesh(id, navmesh); @@ -169,14 +169,11 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library, //generate previews! if (true) { - Vector<Ref<Mesh>> meshes; Vector<Transform> transforms; Vector<int> ids = p_library->get_item_list(); for (int i = 0; i < ids.size(); i++) { - if (mesh_instances.find(ids[i])) { - meshes.push_back(p_library->get_item_mesh(ids[i])); transforms.push_back(mesh_instances[ids[i]]->get_transform()); } @@ -185,9 +182,7 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library, Vector<Ref<Texture2D>> textures = EditorInterface::get_singleton()->make_mesh_previews(meshes, &transforms, EditorSettings::get_singleton()->get("editors/grid_map/preview_size")); int j = 0; for (int i = 0; i < ids.size(); i++) { - if (mesh_instances.find(ids[i])) { - p_library->set_item_preview(ids[i], textures[j]); j++; } @@ -196,7 +191,6 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library, } void MeshLibraryEditor::_import_scene_cbk(const String &p_str) { - Ref<PackedScene> ps = ResourceLoader::load(p_str, "PackedScene"); ERR_FAIL_COND(ps.is_null()); Node *scene = ps->instance(); @@ -211,36 +205,28 @@ void MeshLibraryEditor::_import_scene_cbk(const String &p_str) { } Error MeshLibraryEditor::update_library_file(Node *p_base_scene, Ref<MeshLibrary> ml, bool p_merge) { - _import_scene(p_base_scene, ml, p_merge); return OK; } void MeshLibraryEditor::_menu_cbk(int p_option) { - option = p_option; switch (p_option) { - case MENU_OPTION_ADD_ITEM: { - mesh_library->create_item(mesh_library->get_last_unused_item_id()); } break; case MENU_OPTION_REMOVE_ITEM: { - String p = editor->get_inspector()->get_selected_path(); if (p.begins_with("/MeshLibrary/item") && p.get_slice_count("/") >= 3) { - to_erase = p.get_slice("/", 3).to_int(); cd->set_text(vformat(TTR("Remove item %d?"), to_erase)); cd->popup_centered(Size2(300, 60)); } } break; case MENU_OPTION_IMPORT_FROM_SCENE: { - file->popup_centered_ratio(); } break; case MENU_OPTION_UPDATE_FROM_SCENE: { - cd->set_text(vformat(TTR("Update from existing scene?:\n%s"), String(mesh_library->get_meta("_editor_source_scene")))); cd->popup_centered(Size2(500, 60)); } break; @@ -251,7 +237,6 @@ void MeshLibraryEditor::_bind_methods() { } MeshLibraryEditor::MeshLibraryEditor(EditorNode *p_editor) { - file = memnew(EditorFileDialog); file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE); //not for now? @@ -260,7 +245,6 @@ MeshLibraryEditor::MeshLibraryEditor(EditorNode *p_editor) { file->clear_filters(); file->set_title(TTR("Import Scene")); for (int i = 0; i < extensions.size(); i++) { - file->add_filter("*." + extensions[i] + " ; " + extensions[i].to_upper()); } add_child(file); @@ -287,21 +271,19 @@ MeshLibraryEditor::MeshLibraryEditor(EditorNode *p_editor) { } void MeshLibraryEditorPlugin::edit(Object *p_node) { - if (Object::cast_to<MeshLibrary>(p_node)) { mesh_library_editor->edit(Object::cast_to<MeshLibrary>(p_node)); mesh_library_editor->show(); - } else + } else { mesh_library_editor->hide(); + } } bool MeshLibraryEditorPlugin::handles(Object *p_node) const { - return p_node->is_class("MeshLibrary"); } void MeshLibraryEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { mesh_library_editor->show(); mesh_library_editor->get_menu_button()->show(); @@ -312,7 +294,6 @@ void MeshLibraryEditorPlugin::make_visible(bool p_visible) { } MeshLibraryEditorPlugin::MeshLibraryEditorPlugin(EditorNode *p_node) { - EDITOR_DEF("editors/grid_map/preview_size", 64); mesh_library_editor = memnew(MeshLibraryEditor(p_node)); diff --git a/editor/plugins/mesh_library_editor_plugin.h b/editor/plugins/mesh_library_editor_plugin.h index 74b0a280e3..61ce5692bc 100644 --- a/editor/plugins/mesh_library_editor_plugin.h +++ b/editor/plugins/mesh_library_editor_plugin.h @@ -35,7 +35,6 @@ #include "scene/resources/mesh_library.h" class MeshLibraryEditor : public Control { - GDCLASS(MeshLibraryEditor, Control); Ref<MeshLibrary> mesh_library; @@ -74,7 +73,6 @@ public: }; class MeshLibraryEditorPlugin : public EditorPlugin { - GDCLASS(MeshLibraryEditorPlugin, EditorPlugin); MeshLibraryEditor *mesh_library_editor; diff --git a/editor/plugins/multimesh_editor_plugin.cpp b/editor/plugins/multimesh_editor_plugin.cpp index 4f482c2b43..3904389e09 100644 --- a/editor/plugins/multimesh_editor_plugin.cpp +++ b/editor/plugins/multimesh_editor_plugin.cpp @@ -35,7 +35,6 @@ #include "scene/gui/box_container.h" void MultiMeshEditor::_node_removed(Node *p_node) { - if (p_node == node) { node = nullptr; hide(); @@ -43,24 +42,21 @@ void MultiMeshEditor::_node_removed(Node *p_node) { } void MultiMeshEditor::_populate() { - - if (!node) + if (!node) { return; + } Ref<Mesh> mesh; if (mesh_source->get_text() == "") { - Ref<MultiMesh> multimesh; multimesh = node->get_multimesh(); if (multimesh.is_null()) { - err_dialog->set_text(TTR("No mesh source specified (and no MultiMesh set in node).")); err_dialog->popup_centered(); return; } if (multimesh->get_mesh().is_null()) { - err_dialog->set_text(TTR("No mesh source specified (and MultiMesh contains no Mesh).")); err_dialog->popup_centered(); return; @@ -68,11 +64,9 @@ void MultiMeshEditor::_populate() { mesh = multimesh->get_mesh(); } else { - Node *ms_node = node->get_node(mesh_source->get_text()); if (!ms_node) { - err_dialog->set_text(TTR("Mesh source is invalid (invalid path).")); err_dialog->popup_centered(); return; @@ -81,7 +75,6 @@ void MultiMeshEditor::_populate() { MeshInstance3D *ms_instance = Object::cast_to<MeshInstance3D>(ms_node); if (!ms_instance) { - err_dialog->set_text(TTR("Mesh source is invalid (not a MeshInstance3D).")); err_dialog->popup_centered(); return; @@ -90,7 +83,6 @@ void MultiMeshEditor::_populate() { mesh = ms_instance->get_mesh(); if (mesh.is_null()) { - err_dialog->set_text(TTR("Mesh source is invalid (contains no Mesh resource).")); err_dialog->popup_centered(); return; @@ -98,7 +90,6 @@ void MultiMeshEditor::_populate() { } if (surface_source->get_text() == "") { - err_dialog->set_text(TTR("No surface source specified.")); err_dialog->popup_centered(); return; @@ -107,7 +98,6 @@ void MultiMeshEditor::_populate() { Node *ss_node = node->get_node(surface_source->get_text()); if (!ss_node) { - err_dialog->set_text(TTR("Surface source is invalid (invalid path).")); err_dialog->popup_centered(); return; @@ -116,7 +106,6 @@ void MultiMeshEditor::_populate() { GeometryInstance3D *ss_instance = Object::cast_to<MeshInstance3D>(ss_node); if (!ss_instance) { - err_dialog->set_text(TTR("Surface source is invalid (no geometry).")); err_dialog->popup_centered(); return; @@ -127,7 +116,6 @@ void MultiMeshEditor::_populate() { Vector<Face3> geometry = ss_instance->get_faces(VisualInstance3D::FACES_SOLID); if (geometry.size() == 0) { - err_dialog->set_text(TTR("Surface source is invalid (no faces).")); err_dialog->popup_centered(); return; @@ -153,10 +141,10 @@ void MultiMeshEditor::_populate() { float area_accum = 0; Map<float, int> triangle_area_map; for (int i = 0; i < facecount; i++) { - float area = r[i].get_area(); - if (area < CMP_EPSILON) + if (area < CMP_EPSILON) { continue; + } triangle_area_map[area_accum] = i; area_accum += area; } @@ -188,7 +176,6 @@ void MultiMeshEditor::_populate() { } for (int i = 0; i < instance_count; i++) { - float areapos = Math::random(0.0f, area_accum); Map<float, int>::Element *E = triangle_area_map.find_closest(areapos); @@ -227,23 +214,19 @@ void MultiMeshEditor::_populate() { } void MultiMeshEditor::_browsed(const NodePath &p_path) { - NodePath path = node->get_path_to(get_node(p_path)); - if (browsing_source) + if (browsing_source) { mesh_source->set_text(path); - else + } else { surface_source->set_text(path); + } } void MultiMeshEditor::_menu_option(int p_option) { - switch (p_option) { - case MENU_OPTION_POPULATE: { - if (_last_pp_node != node) { - surface_source->set_text(".."); mesh_source->set_text(".."); populate_axis->select(1); @@ -262,26 +245,24 @@ void MultiMeshEditor::_menu_option(int p_option) { } void MultiMeshEditor::edit(MultiMeshInstance3D *p_multimesh) { - node = p_multimesh; } void MultiMeshEditor::_browse(bool p_source) { - browsing_source = p_source; std->get_scene_tree()->set_marked(node, false); std->popup_centered_ratio(); - if (p_source) + if (p_source) { std->set_title(TTR("Select a Source Mesh:")); - else + } else { std->set_title(TTR("Select a Target Surface:")); + } } void MultiMeshEditor::_bind_methods() { } MultiMeshEditor::MultiMeshEditor() { - options = memnew(MenuButton); options->set_switch_on_hover(true); Node3DEditor::get_singleton()->add_control_to_menu_panel(options); @@ -378,28 +359,23 @@ MultiMeshEditor::MultiMeshEditor() { } void MultiMeshEditorPlugin::edit(Object *p_object) { - multimesh_editor->edit(Object::cast_to<MultiMeshInstance3D>(p_object)); } bool MultiMeshEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("MultiMeshInstance3D"); } void MultiMeshEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { multimesh_editor->options->show(); } else { - multimesh_editor->options->hide(); multimesh_editor->edit(nullptr); } } MultiMeshEditorPlugin::MultiMeshEditorPlugin(EditorNode *p_node) { - editor = p_node; multimesh_editor = memnew(MultiMeshEditor); editor->get_viewport()->add_child(multimesh_editor); diff --git a/editor/plugins/multimesh_editor_plugin.h b/editor/plugins/multimesh_editor_plugin.h index 15c9b91fee..2b0a0c137f 100644 --- a/editor/plugins/multimesh_editor_plugin.h +++ b/editor/plugins/multimesh_editor_plugin.h @@ -37,7 +37,6 @@ #include "scene/gui/spin_box.h" class MultiMeshEditor : public Control { - GDCLASS(MultiMeshEditor, Control); friend class MultiMeshEditorPlugin; @@ -83,7 +82,6 @@ public: }; class MultiMeshEditorPlugin : public EditorPlugin { - GDCLASS(MultiMeshEditorPlugin, EditorPlugin); MultiMeshEditor *multimesh_editor; diff --git a/editor/plugins/navigation_polygon_editor_plugin.cpp b/editor/plugins/navigation_polygon_editor_plugin.cpp index e41b32ac86..8cf9f01fa0 100644 --- a/editor/plugins/navigation_polygon_editor_plugin.cpp +++ b/editor/plugins/navigation_polygon_editor_plugin.cpp @@ -31,10 +31,8 @@ #include "navigation_polygon_editor_plugin.h" Ref<NavigationPolygon> NavigationPolygonEditor::_ensure_navpoly() const { - Ref<NavigationPolygon> navpoly = node->get_navigation_polygon(); if (!navpoly.is_valid()) { - navpoly = Ref<NavigationPolygon>(memnew(NavigationPolygon)); node->set_navigation_polygon(navpoly); } @@ -42,42 +40,38 @@ Ref<NavigationPolygon> NavigationPolygonEditor::_ensure_navpoly() const { } Node2D *NavigationPolygonEditor::_get_node() const { - return node; } void NavigationPolygonEditor::_set_node(Node *p_polygon) { - node = Object::cast_to<NavigationRegion2D>(p_polygon); } int NavigationPolygonEditor::_get_polygon_count() const { - Ref<NavigationPolygon> navpoly = node->get_navigation_polygon(); - if (navpoly.is_valid()) + if (navpoly.is_valid()) { return navpoly->get_outline_count(); - else + } else { return 0; + } } Variant NavigationPolygonEditor::_get_polygon(int p_idx) const { - Ref<NavigationPolygon> navpoly = node->get_navigation_polygon(); - if (navpoly.is_valid()) + if (navpoly.is_valid()) { return navpoly->get_outline(p_idx); - else + } else { return Variant(Vector<Vector2>()); + } } void NavigationPolygonEditor::_set_polygon(int p_idx, const Variant &p_polygon) const { - Ref<NavigationPolygon> navpoly = _ensure_navpoly(); navpoly->set_outline(p_idx, p_polygon); navpoly->make_polygons_from_outlines(); } void NavigationPolygonEditor::_action_add_polygon(const Variant &p_polygon) { - Ref<NavigationPolygon> navpoly = _ensure_navpoly(); undo_redo->add_do_method(navpoly.ptr(), "add_outline", p_polygon); undo_redo->add_undo_method(navpoly.ptr(), "remove_outline", navpoly->get_outline_count()); @@ -86,7 +80,6 @@ void NavigationPolygonEditor::_action_add_polygon(const Variant &p_polygon) { } void NavigationPolygonEditor::_action_remove_polygon(int p_idx) { - Ref<NavigationPolygon> navpoly = _ensure_navpoly(); undo_redo->add_do_method(navpoly.ptr(), "remove_outline", p_idx); undo_redo->add_undo_method(navpoly.ptr(), "add_outline_at_index", navpoly->get_outline(p_idx), p_idx); @@ -95,7 +88,6 @@ void NavigationPolygonEditor::_action_remove_polygon(int p_idx) { } void NavigationPolygonEditor::_action_set_polygon(int p_idx, const Variant &p_previous, const Variant &p_polygon) { - Ref<NavigationPolygon> navpoly = _ensure_navpoly(); undo_redo->add_do_method(navpoly.ptr(), "set_outline", p_idx, p_polygon); undo_redo->add_undo_method(navpoly.ptr(), "set_outline", p_idx, p_previous); @@ -104,14 +96,13 @@ void NavigationPolygonEditor::_action_set_polygon(int p_idx, const Variant &p_pr } bool NavigationPolygonEditor::_has_resource() const { - return node && node->get_navigation_polygon().is_valid(); } void NavigationPolygonEditor::_create_resource() { - - if (!node) + if (!node) { return; + } undo_redo->create_action(TTR("Create Navigation Polygon")); undo_redo->add_do_method(node, "set_navigation_polygon", Ref<NavigationPolygon>(memnew(NavigationPolygon))); diff --git a/editor/plugins/navigation_polygon_editor_plugin.h b/editor/plugins/navigation_polygon_editor_plugin.h index 0bc35e2498..0767322c17 100644 --- a/editor/plugins/navigation_polygon_editor_plugin.h +++ b/editor/plugins/navigation_polygon_editor_plugin.h @@ -35,7 +35,6 @@ #include "scene/2d/navigation_region_2d.h" class NavigationPolygonEditor : public AbstractPolygon2DEditor { - GDCLASS(NavigationPolygonEditor, AbstractPolygon2DEditor); NavigationRegion2D *node; @@ -62,7 +61,6 @@ public: }; class NavigationPolygonEditorPlugin : public AbstractPolygon2DEditorPlugin { - GDCLASS(NavigationPolygonEditorPlugin, AbstractPolygon2DEditorPlugin); public: diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index 1614f3f073..3c12022854 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -77,7 +77,6 @@ #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); @@ -255,19 +254,16 @@ void ViewportRotationControl::_bind_methods() { } void Node3DEditorViewport::_update_camera(float p_interp_delta) { - bool is_orthogonal = camera->get_projection() == Camera3D::PROJECTION_ORTHOGONAL; Cursor old_camera_cursor = camera_cursor; camera_cursor = cursor; if (p_interp_delta > 0) { - //------- // Perform smoothing if (is_freelook_active()) { - // Higher inertia should increase "lag" (lerp with factor between 0 and 1) // Inertia of zero should produce instant movement (lerp with factor of 1) in this case it returns a really high value and gets clamped to 1. real_t inertia = EDITOR_GET("editors/3d/freelook/freelook_inertia"); @@ -294,7 +290,6 @@ void Node3DEditorViewport::_update_camera(float p_interp_delta) { camera_cursor.pos = camera_cursor.eye_pos + forward * camera_cursor.distance; } else { - //when not being manipulated, move softly float free_orbit_inertia = EDITOR_GET("editors/3d/navigation_feel/orbit_inertia"); float free_translation_inertia = EDITOR_GET("editors/3d/navigation_feel/translation_inertia"); @@ -348,7 +343,6 @@ void Node3DEditorViewport::_update_camera(float p_interp_delta) { } if (!equal || p_interp_delta == 0 || is_freelook_active() || is_orthogonal != orthogonal) { - camera->set_global_transform(to_camera_transform(camera_cursor)); if (orthogonal) { @@ -370,29 +364,30 @@ Transform Node3DEditorViewport::to_camera_transform(const Cursor &p_cursor) cons camera_transform.basis.rotate(Vector3(1, 0, 0), -p_cursor.x_rot); camera_transform.basis.rotate(Vector3(0, 1, 0), -p_cursor.y_rot); - if (orthogonal) + if (orthogonal) { camera_transform.translate(0, 0, (get_zfar() - get_znear()) / 2.0); - else + } else { camera_transform.translate(0, 0, p_cursor.distance); + } return camera_transform; } int Node3DEditorViewport::get_selected_count() const { - Map<Node *, Object *> &selection = editor_selection->get_selection(); int count = 0; for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->key()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp); - if (!se) + if (!se) { continue; + } count++; } @@ -401,62 +396,55 @@ int Node3DEditorViewport::get_selected_count() const { } float Node3DEditorViewport::get_znear() const { - return CLAMP(spatial_editor->get_znear(), MIN_Z, MAX_Z); } -float Node3DEditorViewport::get_zfar() const { +float Node3DEditorViewport::get_zfar() const { return CLAMP(spatial_editor->get_zfar(), MIN_Z, MAX_Z); } -float Node3DEditorViewport::get_fov() const { +float Node3DEditorViewport::get_fov() const { return CLAMP(spatial_editor->get_fov(), MIN_FOV, MAX_FOV); } Transform Node3DEditorViewport::_get_camera_transform() const { - return camera->get_global_transform(); } Vector3 Node3DEditorViewport::_get_camera_position() const { - return _get_camera_transform().origin; } Point2 Node3DEditorViewport::_point_to_screen(const Vector3 &p_point) { - return camera->unproject_position(p_point) * subviewport_container->get_stretch_shrink(); } Vector3 Node3DEditorViewport::_get_ray_pos(const Vector2 &p_pos) const { - return camera->project_ray_origin(p_pos / subviewport_container->get_stretch_shrink()); } Vector3 Node3DEditorViewport::_get_camera_normal() const { - return -_get_camera_transform().basis.get_axis(2); } Vector3 Node3DEditorViewport::_get_ray(const Vector2 &p_pos) const { - return camera->project_ray_normal(p_pos / subviewport_container->get_stretch_shrink()); } void Node3DEditorViewport::_clear_selected() { - editor_selection->clear(); } void Node3DEditorViewport::_select_clicked(bool p_append, bool p_single, bool p_allow_locked) { - - if (clicked.is_null()) + if (clicked.is_null()) { return; + } Node *node = Object::cast_to<Node>(ObjectDB::get_instance(clicked)); Node3D *selected = Object::cast_to<Node3D>(node); - if (!selected) + if (!selected) { return; + } if (!p_allow_locked) { // Replace the node by the group if grouped @@ -475,7 +463,6 @@ void Node3DEditorViewport::_select_clicked(bool p_append, bool p_single, bool p_ } void Node3DEditorViewport::_select(Node *p_node, bool p_append, bool p_single) { - if (!p_append) { editor_selection->clear(); } @@ -484,20 +471,20 @@ void Node3DEditorViewport::_select(Node *p_node, bool p_append, bool p_single) { //erase editor_selection->remove_node(p_node); } else { - editor_selection->add_node(p_node); } if (p_single) { - if (Engine::get_singleton()->is_editor_hint()) + if (Engine::get_singleton()->is_editor_hint()) { editor->call("edit_node", p_node); + } } } ObjectID Node3DEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, bool &r_includes_current, int *r_gizmo_handle, bool p_alt_select) { - - if (r_gizmo_handle) + if (r_gizmo_handle) { *r_gizmo_handle = -1; + } Vector3 ray = _get_ray(p_pos); Vector3 pos = _get_ray_pos(p_pos); @@ -513,11 +500,11 @@ ObjectID Node3DEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, b int selected_handle = -1; for (int i = 0; i < instances.size(); i++) { - Node3D *spat = Object::cast_to<Node3D>(ObjectDB::get_instance(instances[i])); - if (!spat) + if (!spat) { continue; + } Ref<EditorNode3DGizmo> seg = spat->get_gizmo(); @@ -532,16 +519,17 @@ ObjectID Node3DEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, b int handle = -1; bool inters = seg->intersect_ray(camera, shrinked_pos, point, normal, &handle, p_alt_select); - if (!inters) + if (!inters) { continue; + } float dist = pos.distance_to(point); - if (dist < 0) + if (dist < 0) { continue; + } if (dist < closest_dist) { - item = Object::cast_to<Node>(spat); while (item->get_owner() && item->get_owner() != edited_scene && !edited_scene->is_editable_instance(item->get_owner())) { item = item->get_owner(); @@ -553,20 +541,20 @@ ObjectID Node3DEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, b } } - if (!item) + if (!item) { return ObjectID(); + } if (!editor_selection->is_selected(item) || (r_gizmo_handle && selected_handle >= 0)) { - - if (r_gizmo_handle) + if (r_gizmo_handle) { *r_gizmo_handle = selected_handle; + } } return closest; } void Node3DEditorViewport::_find_items_at_pos(const Point2 &p_pos, bool &r_includes_current, Vector<_RayResult> &results, bool p_alt_select) { - Vector3 ray = _get_ray(p_pos); Vector3 pos = _get_ray_pos(p_pos); @@ -576,19 +564,21 @@ void Node3DEditorViewport::_find_items_at_pos(const Point2 &p_pos, bool &r_inclu r_includes_current = false; for (int i = 0; i < instances.size(); i++) { - Node3D *spat = Object::cast_to<Node3D>(ObjectDB::get_instance(instances[i])); - if (!spat) + if (!spat) { continue; + } Ref<EditorNode3DGizmo> seg = spat->get_gizmo(); - if (!seg.is_valid()) + if (!seg.is_valid()) { continue; + } - if (found_gizmos.has(seg)) + if (found_gizmos.has(seg)) { continue; + } found_gizmos.insert(seg); Vector3 point; @@ -597,16 +587,19 @@ void Node3DEditorViewport::_find_items_at_pos(const Point2 &p_pos, bool &r_inclu int handle = -1; bool inters = seg->intersect_ray(camera, p_pos, point, normal, nullptr, p_alt_select); - if (!inters) + if (!inters) { continue; + } float dist = pos.distance_to(point); - if (dist < 0) + if (dist < 0) { continue; + } - if (editor_selection->is_selected(spat)) + if (editor_selection->is_selected(spat)) { r_includes_current = true; + } _RayResult res; res.item = spat; @@ -615,14 +608,14 @@ void Node3DEditorViewport::_find_items_at_pos(const Point2 &p_pos, bool &r_inclu results.push_back(res); } - if (results.empty()) + if (results.empty()) { return; + } results.sort(); } Vector3 Node3DEditorViewport::_get_screen_to_space(const Vector3 &p_vector3) { - CameraMatrix cm; if (orthogonal) { cm.set_orthogonal(camera->get_size(), get_size().aspect(), get_znear() + p_vector3.z, get_zfar()); @@ -641,9 +634,9 @@ Vector3 Node3DEditorViewport::_get_screen_to_space(const Vector3 &p_vector3) { } void Node3DEditorViewport::_select_region() { - - if (cursor.region_begin == cursor.region_end) + if (cursor.region_begin == cursor.region_end) { return; //nothing really + } float z_offset = MAX(0.0, 5.0 - get_znear()); @@ -671,7 +664,6 @@ void Node3DEditorViewport::_select_region() { Vector3 cam_pos = _get_camera_position(); for (int i = 0; i < 4; i++) { - Vector3 a = _get_screen_to_space(box[i]); Vector3 b = _get_screen_to_space(box[(i + 1) % 4]); if (orthogonal) { @@ -695,10 +687,10 @@ void Node3DEditorViewport::_select_region() { Node *edited_scene = get_tree()->get_edited_scene_root(); for (int i = 0; i < instances.size(); i++) { - Node3D *sp = Object::cast_to<Node3D>(ObjectDB::get_instance(instances[i])); - if (!sp || _is_node_locked(sp)) + if (!sp || _is_node_locked(sp)) { continue; + } Node *item = Object::cast_to<Node>(sp); while (item->get_owner() && item->get_owner() != edited_scene && !edited_scene->is_editable_instance(item->get_owner())) { @@ -718,16 +710,19 @@ void Node3DEditorViewport::_select_region() { item = sel; } - if (selected.find(item) != -1) + if (selected.find(item) != -1) { continue; + } - if (_is_node_locked(item)) + if (_is_node_locked(item)) { continue; + } Ref<EditorNode3DGizmo> seg = sp->get_gizmo(); - if (!seg.is_valid()) + if (!seg.is_valid()) { continue; + } if (seg->intersect_frustum(camera, frustum)) { selected.push_back(item); @@ -741,23 +736,22 @@ void Node3DEditorViewport::_select_region() { } void Node3DEditorViewport::_update_name() { - String view_mode = orthogonal ? TTR("Orthogonal") : TTR("Perspective"); if (auto_orthogonal) { view_mode += " [auto]"; } - if (name != "") + if (name != "") { view_menu->set_text(name + " " + view_mode); - else + } else { view_menu->set_text(view_mode); + } view_menu->set_size(Vector2(0, 0)); // resets the button size } void Node3DEditorViewport::_compute_edit(const Point2 &p_point) { - _edit.click_ray = _get_ray(Vector2(p_point.x, p_point.y)); _edit.click_ray_pos = _get_ray_pos(Vector2(p_point.x, p_point.y)); _edit.plane = TRANSFORM_VIEW; @@ -767,14 +761,15 @@ void Node3DEditorViewport::_compute_edit(const Point2 &p_point) { List<Node *> &selection = editor_selection->get_selected_node_list(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp); - if (!se) + if (!se) { continue; + } se->original = se->sp->get_global_gizmo_transform(); se->original_local = se->sp->get_local_gizmo_transform(); @@ -782,9 +777,7 @@ void Node3DEditorViewport::_compute_edit(const Point2 &p_point) { } static int _get_key_modifier_setting(const String &p_property) { - switch (EditorSettings::get_singleton()->get(p_property).operator int()) { - case 0: return 0; case 1: @@ -800,24 +793,29 @@ static int _get_key_modifier_setting(const String &p_property) { } static int _get_key_modifier(Ref<InputEventWithModifiers> e) { - if (e->get_shift()) + if (e->get_shift()) { return KEY_SHIFT; - if (e->get_alt()) + } + if (e->get_alt()) { return KEY_ALT; - if (e->get_control()) + } + if (e->get_control()) { return KEY_CONTROL; - if (e->get_metakey()) + } + if (e->get_metakey()) { return KEY_META; + } return 0; } bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_highlight_only) { - - if (!spatial_editor->is_gizmo_visible()) + if (!spatial_editor->is_gizmo_visible()) { return false; + } if (get_selected_count() == 0) { - if (p_highlight_only) + if (p_highlight_only) { spatial_editor->select_gizmo_highlight_axis(-1); + } return false; } @@ -828,12 +826,10 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high float gs = gizmo_scale; if (spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_SELECT || spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_MOVE) { - int col_axis = -1; float col_d = 1e20; for (int i = 0; i < 3; i++) { - Vector3 grabber_pos = gt.origin + gt.basis.get_axis(i) * gs * (GIZMO_ARROW_OFFSET + (GIZMO_ARROW_SIZE * 0.5)); float grabber_radius = gs * GIZMO_ARROW_SIZE; @@ -854,7 +850,6 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high col_d = 1e20; for (int i = 0; i < 3; i++) { - Vector3 ivec2 = gt.basis.get_axis((i + 1) % 3).normalized(); Vector3 ivec3 = gt.basis.get_axis((i + 2) % 3).normalized(); @@ -864,10 +859,8 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high Plane plane(gt.origin, gt.basis.get_axis(i).normalized()); if (plane.intersects_ray(ray_pos, ray, &r)) { - float dist = r.distance_to(grabber_pos); if (dist < (gs * GIZMO_PLANE_SIZE)) { - float d = ray_pos.distance_to(r); if (d < col_d) { col_d = d; @@ -881,9 +874,7 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high } if (col_axis != -1) { - if (p_highlight_only) { - spatial_editor->select_gizmo_highlight_axis(col_axis + (is_plane_translate ? 6 : 0)); } else { @@ -897,21 +888,19 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high } if (spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_SELECT || spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_ROTATE) { - int col_axis = -1; float col_d = 1e20; for (int i = 0; i < 3; i++) { - Plane plane(gt.origin, gt.basis.get_axis(i).normalized()); Vector3 r; - if (!plane.intersects_ray(ray_pos, ray, &r)) + if (!plane.intersects_ray(ray_pos, ray, &r)) { continue; + } float dist = r.distance_to(gt.origin); if (dist > gs * (GIZMO_CIRCLE_SIZE - GIZMO_RING_HALF_WIDTH) && dist < gs * (GIZMO_CIRCLE_SIZE + GIZMO_RING_HALF_WIDTH)) { - float d = ray_pos.distance_to(r); if (d < col_d) { col_d = d; @@ -921,9 +910,7 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high } if (col_axis != -1) { - if (p_highlight_only) { - spatial_editor->select_gizmo_highlight_axis(col_axis + 3); } else { //handle rotate @@ -936,12 +923,10 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high } if (spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_SCALE) { - int col_axis = -1; float col_d = 1e20; for (int i = 0; i < 3; i++) { - Vector3 grabber_pos = gt.origin + gt.basis.get_axis(i) * gs * GIZMO_SCALE_OFFSET; float grabber_radius = gs * GIZMO_ARROW_SIZE; @@ -962,7 +947,6 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high col_d = 1e20; for (int i = 0; i < 3; i++) { - Vector3 ivec2 = gt.basis.get_axis((i + 1) % 3).normalized(); Vector3 ivec3 = gt.basis.get_axis((i + 2) % 3).normalized(); @@ -972,10 +956,8 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high Plane plane(gt.origin, gt.basis.get_axis(i).normalized()); if (plane.intersects_ray(ray_pos, ray, &r)) { - float dist = r.distance_to(grabber_pos); if (dist < (gs * GIZMO_PLANE_SIZE)) { - float d = ray_pos.distance_to(r); if (d < col_d) { col_d = d; @@ -989,9 +971,7 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high } if (col_axis != -1) { - if (p_highlight_only) { - spatial_editor->select_gizmo_highlight_axis(col_axis + (is_plane_scale ? 12 : 9)); } else { @@ -1004,37 +984,36 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high } } - if (p_highlight_only) + if (p_highlight_only) { spatial_editor->select_gizmo_highlight_axis(-1); + } return false; } void Node3DEditorViewport::_surface_mouse_enter() { - - if (!surface->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field())) + if (!surface->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field())) { surface->grab_focus(); + } } void Node3DEditorViewport::_surface_mouse_exit() { - _remove_preview(); } void Node3DEditorViewport::_surface_focus_enter() { - view_menu->set_disable_shortcuts(false); } void Node3DEditorViewport::_surface_focus_exit() { - view_menu->set_disable_shortcuts(true); } + bool Node3DEditorViewport ::_is_node_locked(const Node *p_node) { return p_node->has_meta("_edit_lock_") && p_node->get_meta("_edit_lock_"); } -void Node3DEditorViewport::_list_select(Ref<InputEventMouseButton> b) { +void Node3DEditorViewport::_list_select(Ref<InputEventMouseButton> b) { _find_items_at_pos(b->get_position(), clicked_includes_current, selection_results, b->get_shift()); Node *scene = editor->get_edited_scene(); @@ -1051,7 +1030,6 @@ void Node3DEditorViewport::_list_select(Ref<InputEventMouseButton> b) { clicked_wants_append = b->get_shift(); if (selection_results.size() == 1) { - clicked = selection_results[0].item->get_instance_id(); selection_results.clear(); @@ -1061,12 +1039,10 @@ void Node3DEditorViewport::_list_select(Ref<InputEventMouseButton> b) { } } else if (!selection_results.empty()) { - NodePath root_path = get_tree()->get_edited_scene_root()->get_path(); StringName root_name = root_path.get_name(root_path.get_name_count() - 1); for (int i = 0; i < selection_results.size(); i++) { - Node3D *spat = selection_results[i].item; Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(spat, "Node"); @@ -1107,17 +1083,18 @@ void Node3DEditorViewport::_list_select(Ref<InputEventMouseButton> b) { } void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { - - if (previewing) + if (previewing) { return; //do NONE + } { EditorNode *en = editor; EditorPluginList *force_input_forwarding_list = en->get_editor_plugins_force_input_forwarding(); if (!force_input_forwarding_list->empty()) { bool discard = force_input_forwarding_list->forward_spatial_gui_input(camera, p_event, true); - if (discard) + if (discard) { return; + } } } { @@ -1125,8 +1102,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { EditorPluginList *over_plugin_list = en->get_editor_plugins_over(); if (!over_plugin_list->empty()) { bool discard = over_plugin_list->forward_spatial_gui_input(camera, p_event, false); - if (discard) + if (discard) { return; + } } } @@ -1137,23 +1115,23 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { float zoom_factor = 1 + (ZOOM_MULTIPLIER - 1) * b->get_factor(); switch (b->get_button_index()) { - case BUTTON_WHEEL_UP: { - if (is_freelook_active()) + if (is_freelook_active()) { scale_freelook_speed(zoom_factor); - else + } else { scale_cursor_distance(1.0 / zoom_factor); + } } break; case BUTTON_WHEEL_DOWN: { - if (is_freelook_active()) + if (is_freelook_active()) { scale_freelook_speed(1.0 / zoom_factor); - else + } else { scale_cursor_distance(zoom_factor); + } } break; case BUTTON_RIGHT: { - NavigationScheme nav_scheme = (NavigationScheme)EditorSettings::get_singleton()->get("editors/3d/navigation/navigation_scheme").operator int(); if (b->is_pressed() && _edit.gizmo.is_valid()) { @@ -1163,11 +1141,10 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } if (_edit.mode == TRANSFORM_NONE && b->is_pressed()) { - if (b->get_alt()) { - - if (nav_scheme == NAVIGATION_MAYA) + if (nav_scheme == NAVIGATION_MAYA) { break; + } _list_select(b); return; @@ -1181,14 +1158,15 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { List<Node *> &selection = editor_selection->get_selected_node_list(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp); - if (!se) + if (!se) { continue; + } sp->set_global_transform(se->original); } @@ -1215,32 +1193,25 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } break; case BUTTON_MIDDLE: { - if (b->is_pressed() && _edit.mode != TRANSFORM_NONE) { - switch (_edit.plane) { - case TRANSFORM_VIEW: { - _edit.plane = TRANSFORM_X_AXIS; set_message(TTR("X-Axis Transform."), 2); name = ""; _update_name(); } break; case TRANSFORM_X_AXIS: { - _edit.plane = TRANSFORM_Y_AXIS; set_message(TTR("Y-Axis Transform."), 2); } break; case TRANSFORM_Y_AXIS: { - _edit.plane = TRANSFORM_Z_AXIS; set_message(TTR("Z-Axis Transform."), 2); } break; case TRANSFORM_Z_AXIS: { - _edit.plane = TRANSFORM_VIEW; set_message(TTR("View Plane Transform."), 2); @@ -1253,9 +1224,7 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } } break; case BUTTON_LEFT: { - if (b->is_pressed()) { - NavigationScheme nav_scheme = (NavigationScheme)EditorSettings::get_singleton()->get("editors/3d/navigation/navigation_scheme").operator int(); if ((nav_scheme == NAVIGATION_MAYA || nav_scheme == NAVIGATION_MODO) && b->get_alt()) { break; @@ -1280,7 +1249,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } if (can_select_gizmos && spatial_editor->get_selected()) { - Ref<EditorNode3DGizmo> seg = spatial_editor->get_selected()->get_gizmo(); if (seg.is_valid()) { int handle = -1; @@ -1288,7 +1256,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { Vector3 normal; bool inters = seg->intersect_ray(camera, _edit.mouse_pos, point, normal, &handle, b->get_shift()); if (inters && handle != -1) { - _edit.gizmo = seg; _edit.gizmo_handle = handle; _edit.gizmo_initial_value = seg->get_handle_value(handle); @@ -1297,17 +1264,18 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } } - if (_gizmo_select(_edit.mouse_pos)) + if (_gizmo_select(_edit.mouse_pos)) { break; + } clicked = ObjectID(); clicked_includes_current = false; if ((spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_SELECT && b->get_control()) || spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_ROTATE) { - /* HANDLE ROTATION */ - if (get_selected_count() == 0) + if (get_selected_count() == 0) { break; //bye + } //handle rotate _edit.mode = TRANSFORM_ROTATE; _compute_edit(b->get_position()); @@ -1315,9 +1283,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } if (spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_MOVE) { - - if (get_selected_count() == 0) + if (get_selected_count() == 0) { break; //bye + } //handle translate _edit.mode = TRANSFORM_TRANSLATE; _compute_edit(b->get_position()); @@ -1325,9 +1293,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } if (spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_SCALE) { - - if (get_selected_count() == 0) + if (get_selected_count() == 0) { break; //bye + } //handle scale _edit.mode = TRANSFORM_SCALE; _compute_edit(b->get_position()); @@ -1345,9 +1313,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { clicked_wants_append = b->get_shift(); if (clicked.is_null()) { - - if (!clicked_wants_append) + if (!clicked_wants_append) { _clear_selected(); + } //default to regionselect cursor.region_select = true; @@ -1356,13 +1324,10 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } if (clicked.is_valid() && gizmo_handle >= 0) { - Node3D *spa = Object::cast_to<Node3D>(ObjectDB::get_instance(clicked)); if (spa) { - Ref<EditorNode3DGizmo> seg = spa->get_gizmo(); if (seg.is_valid()) { - _edit.gizmo = seg; _edit.gizmo_handle = gizmo_handle; _edit.gizmo_initial_value = seg->get_handle_value(gizmo_handle); @@ -1373,9 +1338,7 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { surface->update(); } else { - if (_edit.gizmo.is_valid()) { - _edit.gizmo->commit_handle(_edit.gizmo_handle, _edit.gizmo_initial_value, false); _edit.gizmo = Ref<EditorNode3DGizmo>(); break; @@ -1387,9 +1350,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } if (cursor.region_select) { - - if (!clicked_wants_append) + if (!clicked_wants_append) { _clear_selected(); + } _select_region(); cursor.region_select = false; @@ -1397,21 +1360,21 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } if (_edit.mode != TRANSFORM_NONE) { - static const char *_transform_name[4] = { "None", "Rotate", "Translate", "Scale" }; undo_redo->create_action(_transform_name[_edit.mode]); List<Node *> &selection = editor_selection->get_selected_node_list(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp); - if (!se) + if (!se) { continue; + } undo_redo->add_do_method(sp, "set_global_transform", sp->get_global_gizmo_transform()); undo_redo->add_undo_method(sp, "set_global_transform", se->original); @@ -1431,14 +1394,11 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { Ref<InputEventMouseMotion> m = p_event; if (m.is_valid()) { - _edit.mouse_pos = m->get_position(); if (spatial_editor->get_selected()) { - Ref<EditorNode3DGizmo> seg = spatial_editor->get_selected()->get_gizmo(); if (seg.is_valid()) { - int selected_handle = -1; int handle = -1; @@ -1446,21 +1406,20 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { Vector3 normal; bool inters = seg->intersect_ray(camera, _edit.mouse_pos, point, normal, &handle, false); if (inters && handle != -1) { - selected_handle = handle; } if (selected_handle != spatial_editor->get_over_gizmo_handle()) { spatial_editor->set_over_gizmo_handle(selected_handle); spatial_editor->get_selected()->update_gizmo(); - if (selected_handle != -1) + if (selected_handle != -1) { spatial_editor->select_gizmo_highlight_axis(-1); + } } } } if (spatial_editor->get_over_gizmo_handle() == -1 && !(m->get_button_mask() & 1) && !_edit.gizmo.is_valid()) { - _gizmo_select(_edit.mouse_pos, true); } @@ -1468,14 +1427,12 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { NavigationMode nav_mode = NAVIGATION_NONE; if (_edit.gizmo.is_valid()) { - _edit.gizmo->set_handle(_edit.gizmo_handle, camera, m->get_position()); Variant v = _edit.gizmo->get_handle_value(_edit.gizmo_handle); String n = _edit.gizmo->get_handle_name(_edit.gizmo_handle); set_message(n + ": " + String(v)); } else if (m->get_button_mask() & BUTTON_MASK_LEFT) { - if (nav_scheme == NAVIGATION_MAYA && m->get_alt()) { nav_mode = NAVIGATION_ORBIT; } else if (nav_scheme == NAVIGATION_MODO && m->get_alt() && m->get_shift()) { @@ -1486,9 +1443,7 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { nav_mode = NAVIGATION_ORBIT; } else { if (clicked.is_valid()) { - if (!clicked_includes_current) { - _select_clicked(clicked_wants_append, true); // Processing was deferred. } @@ -1505,8 +1460,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { return; } - if (_edit.mode == TRANSFORM_NONE) + if (_edit.mode == TRANSFORM_NONE) { return; + } Vector3 ray_pos = _get_ray_pos(m->get_position()); Vector3 ray = _get_ray(m->get_position()); @@ -1514,9 +1470,7 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { int snap_step_decimals = Math::range_step_decimals(snap); switch (_edit.mode) { - case TRANSFORM_SCALE: { - Vector3 motion_mask; Plane plane; bool plane_mv = false; @@ -1556,22 +1510,21 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } Vector3 intersection; - if (!plane.intersects_ray(ray_pos, ray, &intersection)) + if (!plane.intersects_ray(ray_pos, ray, &intersection)) { break; + } Vector3 click; - if (!plane.intersects_ray(_edit.click_ray_pos, _edit.click_ray, &click)) + if (!plane.intersects_ray(_edit.click_ray_pos, _edit.click_ray, &click)) { break; + } Vector3 motion = intersection - click; if (_edit.plane != TRANSFORM_VIEW) { - if (!plane_mv) { - motion = motion_mask.dot(motion) * motion_mask; } else { - // Alternative planar scaling mode if (_get_key_modifier(m) != KEY_SHIFT) { motion = motion_mask.dot(motion) * motion_mask; @@ -1581,8 +1534,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } else { float center_click_dist = click.distance_to(_edit.center); float center_inters_dist = intersection.distance_to(_edit.center); - if (center_click_dist == 0) + if (center_click_dist == 0) { break; + } float scale = center_inters_dist - center_click_dist; motion = Vector3(scale, scale, scale); @@ -1603,7 +1557,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { String::num(motion_snapped.y, snap_step_decimals) + ", " + String::num(motion_snapped.z, snap_step_decimals) + ")"); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); if (!sp) { continue; @@ -1625,7 +1578,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { Vector3 local_scale; if (local_coords) { - Basis g = original.basis.orthonormalized(); Vector3 local_motion = g.inverse().xform(motion); @@ -1639,13 +1591,11 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { Basis check = original_local.basis; check.scale(local_scale); if (check.determinant() != 0) { - // Apply scale sp->set_scale(local_scale); } } else { - if (_edit.snap || spatial_editor->is_snap_enabled()) { motion.snap(Vector3(snap, snap, snap)); } @@ -1664,7 +1614,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } break; case TRANSFORM_TRANSLATE: { - Vector3 motion_mask; Plane plane; bool plane_mv = false; @@ -1700,12 +1649,14 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } Vector3 intersection; - if (!plane.intersects_ray(ray_pos, ray, &intersection)) + if (!plane.intersects_ray(ray_pos, ray, &intersection)) { break; + } Vector3 click; - if (!plane.intersects_ray(_edit.click_ray_pos, _edit.click_ray, &click)) + if (!plane.intersects_ray(_edit.click_ray_pos, _edit.click_ray, &click)) { break; + } Vector3 motion = intersection - click; if (_edit.plane != TRANSFORM_VIEW) { @@ -1728,7 +1679,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { String::num(motion_snapped.y, snap_step_decimals) + ", " + String::num(motion_snapped.z, snap_step_decimals) + ")"); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); if (!sp) { continue; @@ -1747,7 +1697,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { Transform t; if (local_coords) { - if (_edit.snap || spatial_editor->is_snap_enabled()) { Basis g = original.basis.orthonormalized(); Vector3 local_motion = g.inverse().xform(motion); @@ -1757,7 +1706,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } } else { - if (_edit.snap || spatial_editor->is_snap_enabled()) { motion.snap(Vector3(snap, snap, snap)); } @@ -1774,7 +1722,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } break; case TRANSFORM_ROTATE: { - Plane plane; Vector3 axis; @@ -1801,12 +1748,14 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } Vector3 intersection; - if (!plane.intersects_ray(ray_pos, ray, &intersection)) + if (!plane.intersects_ray(ray_pos, ray, &intersection)) { break; + } Vector3 click; - if (!plane.intersects_ray(_edit.click_ray_pos, _edit.click_ray, &click)) + if (!plane.intersects_ray(_edit.click_ray_pos, _edit.click_ray, &click)) { break; + } Vector3 y_axis = (click - _edit.center).normalized(); Vector3 x_axis = plane.normal.cross(y_axis).normalized(); @@ -1826,14 +1775,15 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { bool local_coords = (spatial_editor->are_local_coords_enabled() && _edit.plane != TRANSFORM_VIEW); // Disable local transformation for TRANSFORM_VIEW for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp); - if (!se) + if (!se) { continue; + } if (sp->has_meta("_edit_lock_")) { continue; @@ -1842,7 +1792,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { Transform t; if (local_coords) { - Transform original_local = se->original_local; Basis rot = Basis(axis, angle); @@ -1854,7 +1803,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { sp->set_scale(original_local.basis.get_scale()); // re-apply original scale } else { - Transform original = se->original; Transform r; Transform base = Transform(Basis(), _edit.center); @@ -1876,7 +1824,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } } else if ((m->get_button_mask() & BUTTON_MASK_RIGHT) || freelook_active) { - if (nav_scheme == NAVIGATION_MAYA && m->get_alt()) { nav_mode = NAVIGATION_ZOOM; } else if (freelook_active) { @@ -1886,9 +1833,7 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } } else if (m->get_button_mask() & BUTTON_MASK_MIDDLE) { - if (nav_scheme == NAVIGATION_GODOT) { - const int mod = _get_key_modifier(m); if (mod == _get_key_modifier_setting("editors/3d/navigation/pan_modifier")) { @@ -1901,8 +1846,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } } else if (nav_scheme == NAVIGATION_MAYA) { - if (m->get_alt()) + if (m->get_alt()) { nav_mode = NAVIGATION_PAN; + } } } else if (EditorSettings::get_singleton()->get("editors/3d/navigation/emulate_3_button_mouse")) { @@ -1949,21 +1895,19 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { Ref<InputEventMagnifyGesture> magnify_gesture = p_event; if (magnify_gesture.is_valid()) { - - if (is_freelook_active()) + if (is_freelook_active()) { scale_freelook_speed(magnify_gesture->get_factor()); - else + } else { scale_cursor_distance(1.0 / magnify_gesture->get_factor()); + } } Ref<InputEventPanGesture> pan_gesture = p_event; if (pan_gesture.is_valid()) { - NavigationScheme nav_scheme = (NavigationScheme)EditorSettings::get_singleton()->get("editors/3d/navigation/navigation_scheme").operator int(); NavigationMode nav_mode = NAVIGATION_NONE; if (nav_scheme == NAVIGATION_GODOT) { - const int mod = _get_key_modifier(pan_gesture); if (mod == _get_key_modifier_setting("editors/3d/navigation/pan_modifier")) { @@ -1976,8 +1920,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } } else if (nav_scheme == NAVIGATION_MAYA) { - if (pan_gesture->get_alt()) + if (pan_gesture->get_alt()) { nav_mode = NAVIGATION_PAN; + } } switch (nav_mode) { @@ -2009,8 +1954,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { Ref<InputEventKey> k = p_event; if (k.is_valid()) { - if (!k->is_pressed()) + if (!k->is_pressed()) { return; + } if (ED_IS_SHORTCUT("spatial_editor/snap", p_event)) { if (_edit.mode != TRANSFORM_NONE) { @@ -2053,8 +1999,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { _menu_option(VIEW_ALIGN_ROTATION_WITH_VIEW); } if (ED_IS_SHORTCUT("spatial_editor/insert_anim_key", p_event)) { - if (!get_selected_count() || _edit.mode != TRANSFORM_NONE) + if (!get_selected_count() || _edit.mode != TRANSFORM_NONE) { return; + } if (!AnimationPlayerEditor::singleton->get_track_editor()->has_keying()) { set_message(TTR("Keying is disabled (no key inserted).")); @@ -2064,10 +2011,10 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { List<Node *> &selection = editor_selection->get_selected_node_list(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); - if (!sp) + if (!sp) { continue; + } spatial_editor->emit_signal("transform_key_request", sp, "", sp->get_transform()); } @@ -2084,25 +2031,27 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } if (k->get_keycode() == KEY_SPACE) { - if (!k->is_pressed()) + if (!k->is_pressed()) { emit_signal("toggle_maximize_view", this); + } } } // freelook uses most of the useful shortcuts, like save, so its ok // to consider freelook active as end of the line for future events. - if (freelook_active) + if (freelook_active) { accept_event(); + } } void Node3DEditorViewport::_nav_pan(Ref<InputEventWithModifiers> p_event, const Vector2 &p_relative) { - const NavigationScheme nav_scheme = (NavigationScheme)EditorSettings::get_singleton()->get("editors/3d/navigation/navigation_scheme").operator int(); real_t pan_speed = 1 / 150.0; int pan_speed_modifier = 10; - if (nav_scheme == NAVIGATION_MAYA && p_event->get_shift()) + if (nav_scheme == NAVIGATION_MAYA && p_event->get_shift()) { pan_speed *= pan_speed_modifier; + } Transform camera_transform; @@ -2116,30 +2065,31 @@ void Node3DEditorViewport::_nav_pan(Ref<InputEventWithModifiers> p_event, const } void Node3DEditorViewport::_nav_zoom(Ref<InputEventWithModifiers> p_event, const Vector2 &p_relative) { - const NavigationScheme nav_scheme = (NavigationScheme)EditorSettings::get_singleton()->get("editors/3d/navigation/navigation_scheme").operator int(); real_t zoom_speed = 1 / 80.0; int zoom_speed_modifier = 10; - if (nav_scheme == NAVIGATION_MAYA && p_event->get_shift()) + if (nav_scheme == NAVIGATION_MAYA && p_event->get_shift()) { zoom_speed *= zoom_speed_modifier; + } NavigationZoomStyle zoom_style = (NavigationZoomStyle)EditorSettings::get_singleton()->get("editors/3d/navigation/zoom_style").operator int(); if (zoom_style == NAVIGATION_ZOOM_HORIZONTAL) { - if (p_relative.x > 0) + if (p_relative.x > 0) { scale_cursor_distance(1 - p_relative.x * zoom_speed); - else if (p_relative.x < 0) + } else if (p_relative.x < 0) { scale_cursor_distance(1.0 / (1 + p_relative.x * zoom_speed)); + } } else { - if (p_relative.y > 0) + if (p_relative.y > 0) { scale_cursor_distance(1 + p_relative.y * zoom_speed); - else if (p_relative.y < 0) + } else if (p_relative.y < 0) { scale_cursor_distance(1.0 / (1 - p_relative.y * zoom_speed)); + } } } void Node3DEditorViewport::_nav_orbit(Ref<InputEventWithModifiers> p_event, const Vector2 &p_relative) { - if (lock_rotation) { _nav_pan(p_event, p_relative); return; @@ -2159,16 +2109,17 @@ void Node3DEditorViewport::_nav_orbit(Ref<InputEventWithModifiers> p_event, cons cursor.x_rot += p_relative.y * radians_per_pixel; } cursor.y_rot += p_relative.x * radians_per_pixel; - if (cursor.x_rot > Math_PI / 2.0) + if (cursor.x_rot > Math_PI / 2.0) { cursor.x_rot = Math_PI / 2.0; - if (cursor.x_rot < -Math_PI / 2.0) + } + if (cursor.x_rot < -Math_PI / 2.0) { cursor.x_rot = -Math_PI / 2.0; + } name = ""; _update_name(); } void Node3DEditorViewport::_nav_look(Ref<InputEventWithModifiers> p_event, const Vector2 &p_relative) { - if (orthogonal) { _nav_pan(p_event, p_relative); return; @@ -2191,10 +2142,12 @@ void Node3DEditorViewport::_nav_look(Ref<InputEventWithModifiers> p_event, const cursor.x_rot += p_relative.y * radians_per_pixel; } cursor.y_rot += p_relative.x * radians_per_pixel; - if (cursor.x_rot > Math_PI / 2.0) + if (cursor.x_rot > Math_PI / 2.0) { cursor.x_rot = Math_PI / 2.0; - if (cursor.x_rot < -Math_PI / 2.0) + } + if (cursor.x_rot < -Math_PI / 2.0) { cursor.x_rot = -Math_PI / 2.0; + } // Look is like the opposite of Orbit: the focus point rotates around the camera Transform camera_transform = to_camera_transform(cursor); @@ -2208,7 +2161,6 @@ void Node3DEditorViewport::_nav_look(Ref<InputEventWithModifiers> p_event, const } void Node3DEditorViewport::set_freelook_active(bool active_now) { - if (!freelook_active && active_now) { // Sync camera cursor to cursor to "cut" interpolation jumps due to changing referential cursor = camera_cursor; @@ -2240,30 +2192,32 @@ void Node3DEditorViewport::set_freelook_active(bool active_now) { } void Node3DEditorViewport::scale_cursor_distance(real_t scale) { - // Prevents zero distance which would short-circuit any scaling - if (cursor.distance < ZOOM_MIN_DISTANCE) + if (cursor.distance < ZOOM_MIN_DISTANCE) { cursor.distance = ZOOM_MIN_DISTANCE; + } cursor.distance *= scale; - if (cursor.distance < ZOOM_MIN_DISTANCE) + if (cursor.distance < ZOOM_MIN_DISTANCE) { cursor.distance = ZOOM_MIN_DISTANCE; + } zoom_indicator_delay = ZOOM_INDICATOR_DELAY_S; surface->update(); } void Node3DEditorViewport::scale_freelook_speed(real_t scale) { - // Prevents zero distance which would short-circuit any scaling - if (freelook_speed < FREELOOK_MIN_SPEED) + if (freelook_speed < FREELOOK_MIN_SPEED) { freelook_speed = FREELOOK_MIN_SPEED; + } freelook_speed *= scale; - if (freelook_speed < FREELOOK_MIN_SPEED) + if (freelook_speed < FREELOOK_MIN_SPEED) { freelook_speed = FREELOOK_MIN_SPEED; + } zoom_indicator_delay = ZOOM_INDICATOR_DELAY_S; surface->update(); @@ -2294,7 +2248,6 @@ static bool is_shortcut_pressed(const String &p_path) { } void Node3DEditorViewport::_update_freelook(real_t delta) { - if (!is_freelook_active()) { return; } @@ -2357,7 +2310,6 @@ void Node3DEditorViewport::_update_freelook(real_t delta) { } void Node3DEditorViewport::set_message(String p_message, float p_time) { - message = p_message; message_time = p_time; } @@ -2372,9 +2324,7 @@ void Node3DEditorPlugin::edited_scene_changed() { } void Node3DEditorViewport::_notification(int p_what) { - if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { - bool visible = is_visible_in_tree(); set_process(visible); @@ -2391,7 +2341,6 @@ void Node3DEditorViewport::_notification(int p_what) { } if (p_what == NOTIFICATION_RESIZED) { - call_deferred("update_transform_gizmo_view"); } @@ -2403,7 +2352,6 @@ void Node3DEditorViewport::_notification(int p_what) { } if (p_what == NOTIFICATION_PROCESS) { - real_t delta = get_process_delta_time(); if (zoom_indicator_delay > 0) { @@ -2438,20 +2386,22 @@ void Node3DEditorViewport::_notification(int p_what) { bool exist = false; for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->key()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp); - if (!se) + if (!se) { continue; + } Transform t = sp->get_global_gizmo_transform(); exist = true; - if (se->last_xform == t && !se->last_xform_dirty) + if (se->last_xform == t && !se->last_xform_dirty) { continue; + } changed = true; se->last_xform_dirty = false; se->last_xform = t; @@ -2475,15 +2425,15 @@ void Node3DEditorViewport::_notification(int p_what) { } if (message_time > 0) { - if (message != last_message) { surface->update(); last_message = message; } message_time -= get_physics_process_delta_time(); - if (message_time < 0) + if (message_time < 0) { surface->update(); + } } //update shadow atlas if changed @@ -2561,7 +2511,6 @@ void Node3DEditorViewport::_notification(int p_what) { cpu_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; float cpu_time = 0.0; @@ -2600,7 +2549,6 @@ void Node3DEditorViewport::_notification(int p_what) { } 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)); @@ -2612,12 +2560,10 @@ void Node3DEditorViewport::_notification(int p_what) { } if (p_what == NOTIFICATION_EXIT_TREE) { - _finish_gizmo_instances(); } if (p_what == NOTIFICATION_THEME_CHANGED) { - view_menu->set_icon(get_theme_icon("GuiTabMenu", "EditorIcons")); preview_camera->set_icon(get_theme_icon("Camera3D", "EditorIcons")); @@ -2641,7 +2587,6 @@ void Node3DEditorViewport::_notification(int p_what) { } static void draw_indicator_bar(Control &surface, real_t fill, Ref<Texture2D> icon) { - // Adjust bar size from control height Vector2 surface_size = surface.get_size(); real_t h = surface_size.y / 2.0; @@ -2662,7 +2607,6 @@ static void draw_indicator_bar(Control &surface, real_t fill, Ref<Texture2D> ico } void Node3DEditorViewport::_draw() { - EditorPluginList *over_plugin_list = EditorNode::get_singleton()->get_editor_plugins_over(); if (!over_plugin_list->empty()) { over_plugin_list->forward_spatial_draw_over_viewport(surface); @@ -2704,7 +2648,6 @@ void Node3DEditorViewport::_draw() { } if (_edit.mode == TRANSFORM_ROTATE) { - Point2 center = _point_to_screen(_edit.center); RenderingServer::get_singleton()->canvas_item_add_line( ci, @@ -2714,7 +2657,6 @@ void Node3DEditorViewport::_draw() { Math::round(2 * EDSCALE)); } if (previewing) { - Size2 ss = Size2(ProjectSettings::get_singleton()->get("display/window/size/width"), ProjectSettings::get_singleton()->get("display/window/size/height")); float aspect = ss.aspect(); Size2 s = get_size(); @@ -2723,14 +2665,12 @@ void Node3DEditorViewport::_draw() { switch (previewing->get_keep_aspect_mode()) { case Camera3D::KEEP_WIDTH: { - draw_rect.size = Size2(s.width, s.width / aspect); draw_rect.position.x = 0; draw_rect.position.y = (s.height - draw_rect.size.y) * 0.5; } break; case Camera3D::KEEP_HEIGHT: { - draw_rect.size = Size2(s.height * aspect, s.height); draw_rect.position.y = 0; draw_rect.position.x = (s.width - draw_rect.size.x) * 0.5; @@ -2743,9 +2683,7 @@ void Node3DEditorViewport::_draw() { surface->draw_rect(draw_rect, Color(0.6, 0.6, 0.1, 0.5), false, Math::round(2 * EDSCALE)); } else { - if (zoom_indicator_delay > 0.0) { - if (is_freelook_active()) { // Show speed @@ -2758,8 +2696,9 @@ void Node3DEditorViewport::_draw() { // There is no real maximum speed so that factor can become negative, // Let's make it look asymptotic instead (will decrease slower and slower). - if (logscale_t < 0.25) + if (logscale_t < 0.25) { logscale_t = 0.25 * Math::exp(4.0 * logscale_t - 1.0); + } draw_indicator_bar(*surface, 1.0 - logscale_t, get_theme_icon("ViewportSpeed", "EditorIcons")); } @@ -2776,8 +2715,9 @@ void Node3DEditorViewport::_draw() { // There is no real maximum distance so that factor can become negative, // Let's make it look asymptotic instead (will decrease slower and slower). - if (logscale_t < 0.25) + if (logscale_t < 0.25) { logscale_t = 0.25 * Math::exp(4.0 * logscale_t - 1.0); + } draw_indicator_bar(*surface, logscale_t, get_theme_icon("ViewportZoom", "EditorIcons")); } @@ -2787,11 +2727,8 @@ void Node3DEditorViewport::_draw() { } void Node3DEditorViewport::_menu_option(int p_option) { - switch (p_option) { - case VIEW_TOP: { - cursor.y_rot = 0; cursor.x_rot = Math_PI / 2.0; set_message(TTR("Top View."), 2); @@ -2801,7 +2738,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_BOTTOM: { - cursor.y_rot = 0; cursor.x_rot = -Math_PI / 2.0; set_message(TTR("Bottom View."), 2); @@ -2811,7 +2747,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_LEFT: { - cursor.x_rot = 0; cursor.y_rot = Math_PI / 2.0; set_message(TTR("Left View."), 2); @@ -2821,7 +2756,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_RIGHT: { - cursor.x_rot = 0; cursor.y_rot = -Math_PI / 2.0; set_message(TTR("Right View."), 2); @@ -2831,7 +2765,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_FRONT: { - cursor.x_rot = 0; cursor.y_rot = 0; set_message(TTR("Front View."), 2); @@ -2841,7 +2774,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_REAR: { - cursor.x_rot = 0; cursor.y_rot = Math_PI; set_message(TTR("Rear View."), 2); @@ -2851,19 +2783,17 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_CENTER_TO_ORIGIN: { - cursor.pos = Vector3(0, 0, 0); } break; case VIEW_CENTER_TO_SELECTION: { - focus_selection(); } break; case VIEW_ALIGN_TRANSFORM_WITH_VIEW: { - - if (!get_selected_count()) + if (!get_selected_count()) { break; + } Transform camera_transform = camera->get_global_transform(); @@ -2872,14 +2802,15 @@ void Node3DEditorViewport::_menu_option(int p_option) { undo_redo->create_action(TTR("Align Transform with View")); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp); - if (!se) + if (!se) { continue; + } Transform xform; if (orthogonal) { @@ -2897,9 +2828,9 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_ALIGN_ROTATION_WITH_VIEW: { - - if (!get_selected_count()) + if (!get_selected_count()) { break; + } Transform camera_transform = camera->get_global_transform(); @@ -2907,14 +2838,15 @@ void Node3DEditorViewport::_menu_option(int p_option) { undo_redo->create_action(TTR("Align Rotation with View")); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp); - if (!se) + if (!se) { continue; + } undo_redo->add_do_method(sp, "set_rotation", camera_transform.basis.get_rotation()); undo_redo->add_undo_method(sp, "set_rotation", sp->get_rotation()); @@ -2923,15 +2855,12 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_ENVIRONMENT: { - int idx = view_menu->get_popup()->get_item_index(VIEW_ENVIRONMENT); bool current = view_menu->get_popup()->is_item_checked(idx); current = !current; if (current) { - camera->set_environment(RES()); } else { - camera->set_environment(Node3DEditor::get_singleton()->get_viewport_environment()); } @@ -2939,7 +2868,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_PERSPECTIVE: { - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_PERSPECTIVE), true); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_ORTHOGONAL), false); orthogonal = false; @@ -2949,7 +2877,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_ORTHOGONAL: { - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_PERSPECTIVE), false); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_ORTHOGONAL), true); orthogonal = true; @@ -2959,7 +2886,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_AUTO_ORTHOGONAL: { - int idx = view_menu->get_popup()->get_item_index(VIEW_AUTO_ORTHOGONAL); bool current = view_menu->get_popup()->is_item_checked(idx); current = !current; @@ -2970,7 +2896,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { } } break; case VIEW_LOCK_ROTATION: { - int idx = view_menu->get_popup()->get_item_index(VIEW_LOCK_ROTATION); bool current = view_menu->get_popup()->is_item_checked(idx); lock_rotation = !current; @@ -2983,7 +2908,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_AUDIO_LISTENER: { - int idx = view_menu->get_popup()->get_item_index(VIEW_AUDIO_LISTENER); bool current = view_menu->get_popup()->is_item_checked(idx); current = !current; @@ -2992,7 +2916,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_AUDIO_DOPPLER: { - int idx = view_menu->get_popup()->get_item_index(VIEW_AUDIO_DOPPLER); bool current = view_menu->get_popup()->is_item_checked(idx); current = !current; @@ -3001,7 +2924,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_CINEMATIC_PREVIEW: { - int idx = view_menu->get_popup()->get_item_index(VIEW_CINEMATIC_PREVIEW); bool current = view_menu->get_popup()->is_item_checked(idx); current = !current; @@ -3012,38 +2934,36 @@ void Node3DEditorViewport::_menu_option(int p_option) { if (current) { preview_camera->hide(); } else { - if (previewing != nullptr) + if (previewing != nullptr) { preview_camera->show(); + } } } break; case VIEW_GIZMOS: { - int idx = view_menu->get_popup()->get_item_index(VIEW_GIZMOS); bool current = view_menu->get_popup()->is_item_checked(idx); current = !current; - if (current) + if (current) { camera->set_cull_mask(((1 << 20) - 1) | (1 << (GIZMO_BASE_LAYER + index)) | (1 << GIZMO_EDIT_LAYER) | (1 << GIZMO_GRID_LAYER)); - else + } else { camera->set_cull_mask(((1 << 20) - 1) | (1 << (GIZMO_BASE_LAYER + index)) | (1 << GIZMO_GRID_LAYER)); + } view_menu->get_popup()->set_item_checked(idx, current); } break; case VIEW_HALF_RESOLUTION: { - int idx = view_menu->get_popup()->get_item_index(VIEW_HALF_RESOLUTION); bool current = view_menu->get_popup()->is_item_checked(idx); current = !current; view_menu->get_popup()->set_item_checked(idx, current); } break; case VIEW_INFORMATION: { - int idx = view_menu->get_popup()->get_item_index(VIEW_INFORMATION); bool current = view_menu->get_popup()->is_item_checked(idx); view_menu->get_popup()->set_item_checked(idx, !current); } break; case VIEW_FRAME_TIME: { - int idx = view_menu->get_popup()->get_item_index(VIEW_FRAME_TIME); bool current = view_menu->get_popup()->is_item_checked(idx); view_menu->get_popup()->set_item_checked(idx, !current); @@ -3065,7 +2985,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { case VIEW_DISPLAY_DEBUG_PSSM_SPLITS: case VIEW_DISPLAY_DEBUG_DECAL_ATLAS: case VIEW_DISPLAY_DEBUG_ROUGHNESS_LIMITER: { - static const int display_options[] = { VIEW_DISPLAY_NORMAL, VIEW_DISPLAY_WIREFRAME, @@ -3109,7 +3028,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { int idx = 0; while (display_options[idx] != VIEW_MAX) { - int id = display_options[idx]; int item_idx = view_menu->get_popup()->get_item_index(id); if (item_idx != -1) { @@ -3137,7 +3055,6 @@ void Node3DEditorViewport::_set_auto_orthogonal() { } void Node3DEditorViewport::_preview_exited_scene() { - preview_camera->disconnect("toggled", callable_mp(this, &Node3DEditorViewport::_toggle_camera_preview)); preview_camera->set_pressed(false); _toggle_camera_preview(false); @@ -3146,7 +3063,6 @@ void Node3DEditorViewport::_preview_exited_scene() { } void Node3DEditorViewport::_init_gizmo_instance(int p_idx) { - uint32_t layer = 1 << (GIZMO_BASE_LAYER + p_idx); for (int i = 0; i < 3; i++) { @@ -3188,7 +3104,6 @@ void Node3DEditorViewport::_init_gizmo_instance(int p_idx) { } void Node3DEditorViewport::_finish_gizmo_instances() { - for (int i = 0; i < 3; i++) { RS::get_singleton()->free(move_gizmo_instance[i]); RS::get_singleton()->free(move_plane_gizmo_instance[i]); @@ -3197,25 +3112,24 @@ void Node3DEditorViewport::_finish_gizmo_instances() { RS::get_singleton()->free(scale_plane_gizmo_instance[i]); } } -void Node3DEditorViewport::_toggle_camera_preview(bool p_activate) { +void Node3DEditorViewport::_toggle_camera_preview(bool p_activate) { ERR_FAIL_COND(p_activate && !preview); ERR_FAIL_COND(!p_activate && !previewing); rotation_control->set_visible(!p_activate); if (!p_activate) { - previewing->disconnect("tree_exiting", callable_mp(this, &Node3DEditorViewport::_preview_exited_scene)); previewing = nullptr; RS::get_singleton()->viewport_attach_camera(viewport->get_viewport_rid(), camera->get_camera()); //restore - if (!preview) + if (!preview) { preview_camera->hide(); + } view_menu->set_disabled(false); surface->update(); } else { - previewing = preview; previewing->connect("tree_exiting", callable_mp(this, &Node3DEditorViewport::_preview_exited_scene)); RS::get_singleton()->viewport_attach_camera(viewport->get_viewport_rid(), preview->get_camera()); //replace @@ -3227,8 +3141,9 @@ void Node3DEditorViewport::_toggle_camera_preview(bool p_activate) { void Node3DEditorViewport::_toggle_cinema_preview(bool p_activate) { previewing_cinema = p_activate; if (!previewing_cinema) { - if (previewing != nullptr) + if (previewing != nullptr) { previewing->disconnect("tree_exited", callable_mp(this, &Node3DEditorViewport::_preview_exited_scene)); + } previewing = nullptr; RS::get_singleton()->viewport_attach_camera(viewport->get_viewport_rid(), camera->get_camera()); //restore @@ -3244,9 +3159,9 @@ void Node3DEditorViewport::_toggle_cinema_preview(bool p_activate) { } void Node3DEditorViewport::_selection_result_pressed(int p_result) { - - if (selection_results.size() <= p_result) + if (selection_results.size() <= p_result) { return; + } clicked = selection_results[p_result].item->get_instance_id(); @@ -3257,24 +3172,23 @@ void Node3DEditorViewport::_selection_result_pressed(int p_result) { } void Node3DEditorViewport::_selection_menu_hide() { - selection_results.clear(); selection_menu->clear(); selection_menu->set_size(Vector2(0, 0)); } void Node3DEditorViewport::set_can_preview(Camera3D *p_preview) { - preview = p_preview; - if (!preview_camera->is_pressed() && !previewing_cinema) + if (!preview_camera->is_pressed() && !previewing_cinema) { preview_camera->set_visible(p_preview); + } } void Node3DEditorViewport::update_transform_gizmo_view() { - - if (!is_visible_in_tree()) + if (!is_visible_in_tree()) { return; + } Transform xform = spatial_editor->get_gizmo_transform(); @@ -3298,8 +3212,9 @@ void Node3DEditorViewport::update_transform_gizmo_view() { float d0 = camera->unproject_position(camera_xform.origin + camz * gizmo_d).y; float d1 = camera->unproject_position(camera_xform.origin + camz * gizmo_d + camy).y; float dd = Math::abs(d0 - d1); - if (dd == 0) + if (dd == 0) { dd = 0.0001; + } float gizmo_size = EditorSettings::get_singleton()->get("editors/3d/manipulator_gizmo_size"); // At low viewport heights, multiply the gizmo scale based on the viewport height. @@ -3328,23 +3243,27 @@ void Node3DEditorViewport::update_transform_gizmo_view() { } void Node3DEditorViewport::set_state(const Dictionary &p_state) { - - if (p_state.has("position")) + if (p_state.has("position")) { cursor.pos = p_state["position"]; - if (p_state.has("x_rotation")) + } + if (p_state.has("x_rotation")) { cursor.x_rot = p_state["x_rotation"]; - if (p_state.has("y_rotation")) + } + if (p_state.has("y_rotation")) { cursor.y_rot = p_state["y_rotation"]; - if (p_state.has("distance")) + } + if (p_state.has("distance")) { cursor.distance = p_state["distance"]; + } if (p_state.has("use_orthogonal")) { bool orth = p_state["use_orthogonal"]; - if (orth) + if (orth) { _menu_option(VIEW_ORTHOGONAL); - else + } else { _menu_option(VIEW_PERSPECTIVE); + } } if (p_state.has("view_name")) { name = p_state["view_name"]; @@ -3362,8 +3281,9 @@ void Node3DEditorViewport::set_state(const Dictionary &p_state) { int display = p_state["display_mode"]; int idx = view_menu->get_popup()->get_item_index(display); - if (!view_menu->get_popup()->is_item_checked(idx)) + if (!view_menu->get_popup()->is_item_checked(idx)) { _menu_option(display); + } } if (p_state.has("lock_rotation")) { lock_rotation = p_state["lock_rotation"]; @@ -3374,8 +3294,9 @@ void Node3DEditorViewport::set_state(const Dictionary &p_state) { if (p_state.has("use_environment")) { bool env = p_state["use_environment"]; - if (env != camera->get_environment().is_valid()) + if (env != camera->get_environment().is_valid()) { _menu_option(VIEW_ENVIRONMENT); + } } if (p_state.has("listener")) { bool listener = p_state["listener"]; @@ -3395,22 +3316,25 @@ void Node3DEditorViewport::set_state(const Dictionary &p_state) { bool gizmos = p_state["gizmos"]; int idx = view_menu->get_popup()->get_item_index(VIEW_GIZMOS); - if (view_menu->get_popup()->is_item_checked(idx) != gizmos) + if (view_menu->get_popup()->is_item_checked(idx) != gizmos) { _menu_option(VIEW_GIZMOS); + } } if (p_state.has("information")) { bool information = p_state["information"]; int idx = view_menu->get_popup()->get_item_index(VIEW_INFORMATION); - if (view_menu->get_popup()->is_item_checked(idx) != information) + if (view_menu->get_popup()->is_item_checked(idx) != information) { _menu_option(VIEW_INFORMATION); + } } if (p_state.has("frame_time")) { bool fps = p_state["frame_time"]; int idx = view_menu->get_popup()->get_item_index(VIEW_FRAME_TIME); - if (view_menu->get_popup()->is_item_checked(idx) != fps) + if (view_menu->get_popup()->is_item_checked(idx) != fps) { _menu_option(VIEW_FRAME_TIME); + } } if (p_state.has("half_res")) { bool half_res = p_state["half_res"]; @@ -3444,7 +3368,6 @@ void Node3DEditorViewport::set_state(const Dictionary &p_state) { } Dictionary Node3DEditorViewport::get_state() const { - Dictionary d; d["position"] = cursor.pos; d["x_rotation"] = cursor.x_rot; @@ -3455,14 +3378,15 @@ Dictionary Node3DEditorViewport::get_state() const { d["view_name"] = name; d["auto_orthogonal"] = auto_orthogonal; d["auto_orthogonal_enabled"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_AUTO_ORTHOGONAL)); - if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_NORMAL))) + if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_NORMAL))) { d["display_mode"] = VIEW_DISPLAY_NORMAL; - else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_WIREFRAME))) + } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_WIREFRAME))) { d["display_mode"] = VIEW_DISPLAY_WIREFRAME; - else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_OVERDRAW))) + } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_OVERDRAW))) { d["display_mode"] = VIEW_DISPLAY_OVERDRAW; - else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_SHADELESS))) + } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_SHADELESS))) { d["display_mode"] = VIEW_DISPLAY_SHADELESS; + } d["listener"] = viewport->is_audio_listener(); d["doppler"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_AUDIO_DOPPLER)); d["gizmos"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_GIZMOS)); @@ -3470,16 +3394,17 @@ Dictionary Node3DEditorViewport::get_state() const { d["frame_time"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_FRAME_TIME)); d["half_res"] = subviewport_container->get_stretch_shrink() > 1; d["cinematic_preview"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_CINEMATIC_PREVIEW)); - if (previewing) + if (previewing) { d["previewing"] = EditorNode::get_singleton()->get_edited_scene()->get_path_to(previewing); - if (lock_rotation) + } + if (lock_rotation) { d["lock_rotation"] = lock_rotation; + } return d; } void Node3DEditorViewport::_bind_methods() { - ClassDB::bind_method(D_METHOD("update_transform_gizmo_view"), &Node3DEditorViewport::update_transform_gizmo_view); // Used by call_deferred. ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &Node3DEditorViewport::can_drop_data_fw); ClassDB::bind_method(D_METHOD("drop_data_fw"), &Node3DEditorViewport::drop_data_fw); @@ -3489,7 +3414,6 @@ void Node3DEditorViewport::_bind_methods() { } void Node3DEditorViewport::reset() { - orthogonal = false; auto_orthogonal = false; lock_rotation = false; @@ -3507,8 +3431,9 @@ void Node3DEditorViewport::reset() { } void Node3DEditorViewport::focus_selection() { - if (!get_selected_count()) + if (!get_selected_count()) { return; + } Vector3 center; int count = 0; @@ -3516,14 +3441,15 @@ void Node3DEditorViewport::focus_selection() { List<Node *> &selection = editor_selection->get_selected_node_list(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp); - if (!se) + if (!se) { continue; + } center += sp->get_global_gizmo_transform().origin; count++; @@ -3557,11 +3483,11 @@ Vector3 Node3DEditorViewport::_get_instance_position(const Point2 &p_pos) const Vector3 normal = Vector3(0.0, 0.0, 0.0); for (int i = 0; i < instances.size(); i++) { - MeshInstance3D *mesh_instance = Object::cast_to<MeshInstance3D>(ObjectDB::get_instance(instances[i])); - if (!mesh_instance) + if (!mesh_instance) { continue; + } Ref<EditorNode3DGizmo> seg = mesh_instance->get_gizmo(); @@ -3575,13 +3501,15 @@ Vector3 Node3DEditorViewport::_get_instance_position(const Point2 &p_pos) const Vector3 hit_normal; bool inters = seg->intersect_ray(camera, p_pos, hit_point, hit_normal, nullptr, false); - if (!inters) + if (!inters) { continue; + } float dist = world_pos.distance_to(hit_point); - if (dist < 0) + if (dist < 0) { continue; + } if (dist < closest_dist) { closest_dist = dist; @@ -3591,10 +3519,11 @@ Vector3 Node3DEditorViewport::_get_instance_position(const Point2 &p_pos) const } Vector3 offset = Vector3(); for (int i = 0; i < 3; i++) { - if (normal[i] > 0.0) + if (normal[i] > 0.0) { offset[i] = (preview_bounds->get_size()[i] - (preview_bounds->get_size()[i] + preview_bounds->get_position()[i])); - else if (normal[i] < 0.0) + } else if (normal[i] < 0.0) { offset[i] = -(preview_bounds->get_size()[i] + preview_bounds->get_position()[i]); + } } return point + offset; } @@ -3734,8 +3663,9 @@ bool Node3DEditorViewport::_create_instance(Node *parent, String &path, const Po Transform global_transform; Node3D *parent_spatial = Object::cast_to<Node3D>(parent); - if (parent_spatial) + if (parent_spatial) { global_transform = parent_spatial->get_global_gizmo_transform(); + } global_transform.origin = spatial_editor->snap_point(_get_instance_position(p_point)); @@ -3781,7 +3711,6 @@ void Node3DEditorViewport::_perform_drop_data() { } bool Node3DEditorViewport::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { - bool can_instance = false; if (!preview_node->is_inside_tree()) { @@ -3838,8 +3767,9 @@ bool Node3DEditorViewport::can_drop_data_fw(const Point2 &p_point, const Variant } void Node3DEditorViewport::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { - if (!can_drop_data_fw(p_point, p_data, p_from)) + if (!can_drop_data_fw(p_point, p_data, p_from)) { return; + } bool is_shift = Input::get_singleton()->is_key_pressed(KEY_SHIFT); @@ -3878,7 +3808,6 @@ void Node3DEditorViewport::drop_data_fw(const Point2 &p_point, const Variant &p_ } Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, EditorNode *p_editor, int p_index) { - cpu_time_history_index = 0; gpu_time_history_index = 0; @@ -4132,11 +4061,9 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, Edito ////////////////////////////////////////////////////////////// void Node3DEditorViewportContainer::_gui_input(const Ref<InputEvent> &p_event) { - Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT) { - if (mb->is_pressed()) { Vector2 size = get_size(); @@ -4155,25 +4082,21 @@ void Node3DEditorViewportContainer::_gui_input(const Ref<InputEvent> &p_event) { switch (view) { case VIEW_USE_1_VIEWPORT: { - dragging_h = false; dragging_v = false; } break; case VIEW_USE_2_VIEWPORTS: { - dragging_h = false; } break; case VIEW_USE_2_VIEWPORTS_ALT: { - dragging_v = false; } break; case VIEW_USE_3_VIEWPORTS: case VIEW_USE_3_VIEWPORTS_ALT: case VIEW_USE_4_VIEWPORTS: { - // Do nothing. } break; @@ -4187,7 +4110,6 @@ void Node3DEditorViewportContainer::_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseMotion> mm = p_event; if (mm.is_valid()) { - if (view == VIEW_USE_3_VIEWPORTS || view == VIEW_USE_3_VIEWPORTS_ALT || view == VIEW_USE_4_VIEWPORTS) { Vector2 size = get_size(); @@ -4225,15 +4147,12 @@ 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(); } if (p_what == NOTIFICATION_DRAW && mouseover) { - Ref<Texture2D> h_grabber = get_theme_icon("grabber", "HSplitContainer"); Ref<Texture2D> v_grabber = get_theme_icon("grabber", "VSplitContainer"); @@ -4254,26 +4173,21 @@ void Node3DEditorViewportContainer::_notification(int p_what) { int size_bottom = size.height - mid_h - v_sep / 2; 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_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); @@ -4287,7 +4201,6 @@ void Node3DEditorViewportContainer::_notification(int p_what) { } 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); @@ -4301,7 +4214,6 @@ void Node3DEditorViewportContainer::_notification(int p_what) { } 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); @@ -4319,7 +4231,6 @@ void Node3DEditorViewportContainer::_notification(int p_what) { } if (p_what == NOTIFICATION_SORT_CHILDREN) { - Node3DEditorViewport *viewports[4]; int vc = 0; for (int i = 0; i < get_child_count(); i++) { @@ -4353,12 +4264,9 @@ void Node3DEditorViewportContainer::_notification(int p_what) { 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(); } @@ -4366,13 +4274,12 @@ void Node3DEditorViewportContainer::_notification(int p_what) { } break; case VIEW_USE_2_VIEWPORTS: { - for (int i = 0; i < 4; i++) { - - if (i == 1 || i == 3) + if (i == 1 || i == 3) { viewports[i]->hide(); - else + } else { viewports[i]->show(); + } } fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size.width, size_top))); @@ -4380,26 +4287,24 @@ void Node3DEditorViewportContainer::_notification(int p_what) { } break; case VIEW_USE_2_VIEWPORTS_ALT: { - for (int i = 0; i < 4; i++) { - - if (i == 1 || i == 3) + if (i == 1 || i == 3) { viewports[i]->hide(); - else + } 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))); } break; case VIEW_USE_3_VIEWPORTS: { - for (int i = 0; i < 4; i++) { - - if (i == 1) + if (i == 1) { viewports[i]->hide(); - else + } else { viewports[i]->show(); + } } fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size.width, size_top))); @@ -4408,13 +4313,12 @@ void Node3DEditorViewportContainer::_notification(int p_what) { } break; case VIEW_USE_3_VIEWPORTS_ALT: { - for (int i = 0; i < 4; i++) { - - if (i == 1) + if (i == 1) { viewports[i]->hide(); - else + } else { viewports[i]->show(); + } } fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size_left, size_top))); @@ -4423,9 +4327,7 @@ void Node3DEditorViewportContainer::_notification(int p_what) { } break; case VIEW_USE_4_VIEWPORTS: { - for (int i = 0; i < 4; i++) { - viewports[i]->show(); } @@ -4440,23 +4342,19 @@ void Node3DEditorViewportContainer::_notification(int p_what) { } void Node3DEditorViewportContainer::set_view(View p_view) { - view = p_view; queue_sort(); } Node3DEditorViewportContainer::View Node3DEditorViewportContainer::get_view() { - return view; } void Node3DEditorViewportContainer::_bind_methods() { - ClassDB::bind_method("_gui_input", &Node3DEditorViewportContainer::_gui_input); } Node3DEditorViewportContainer::Node3DEditorViewportContainer() { - set_clip_contents(true); view = VIEW_USE_1_VIEWPORT; mouseover = false; @@ -4473,15 +4371,13 @@ Node3DEditorViewportContainer::Node3DEditorViewportContainer() { Node3DEditor *Node3DEditor::singleton = nullptr; Node3DEditorSelectedItem::~Node3DEditorSelectedItem() { - - if (sbox_instance.is_valid()) + if (sbox_instance.is_valid()) { RenderingServer::get_singleton()->free(sbox_instance); + } } void Node3DEditor::select_gizmo_highlight_axis(int p_axis) { - for (int i = 0; i < 3; i++) { - move_gizmo[i]->surface_set_material(0, i == p_axis ? gizmo_color_hl[i] : gizmo_color[i]); move_plane_gizmo[i]->surface_set_material(0, (i + 6) == p_axis ? plane_gizmo_color_hl[i] : plane_gizmo_color[i]); rotate_gizmo[i]->surface_set_material(0, (i + 3) == p_axis ? gizmo_color_hl[i] : gizmo_color[i]); @@ -4491,7 +4387,6 @@ void Node3DEditor::select_gizmo_highlight_axis(int p_axis) { } void Node3DEditor::update_transform_gizmo() { - List<Node *> &selection = editor_selection->get_selected_node_list(); AABB center; bool first = true; @@ -4500,14 +4395,15 @@ void Node3DEditor::update_transform_gizmo() { bool local_gizmo_coords = are_local_coords_enabled(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp); - if (!se) + if (!se) { continue; + } Transform xf = se->sp->get_global_gizmo_transform(); @@ -4553,10 +4449,10 @@ void Node3DEditor::update_all_gizmos(Node *p_node) { } Object *Node3DEditor::_get_editor_data(Object *p_what) { - Node3D *sp = Object::cast_to<Node3D>(p_what); - if (!sp) + if (!sp) { return nullptr; + } Node3DEditorSelectedItem *si = memnew(Node3DEditorSelectedItem); @@ -4568,7 +4464,6 @@ Object *Node3DEditor::_get_editor_data(Object *p_what) { } void Node3DEditor::_generate_selection_box() { - AABB aabb(Vector3(), Vector3(1, 1, 1)); aabb.grow_by(aabb.get_longest_axis_size() / 20.0); @@ -4576,7 +4471,6 @@ void Node3DEditor::_generate_selection_box() { st->begin(Mesh::PRIMITIVE_LINES); for (int i = 0; i < 12; i++) { - Vector3 a, b; aabb.get_edge(i, a, b); @@ -4602,7 +4496,6 @@ void Node3DEditor::_generate_selection_box() { } Dictionary Node3DEditor::get_state() const { - Dictionary d; d["snap_enabled"] = snap_enabled; @@ -4613,18 +4506,19 @@ Dictionary Node3DEditor::get_state() const { d["local_coords"] = tool_option_button[TOOL_OPT_LOCAL_COORDS]->is_pressed(); int vc = 0; - if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT))) + if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT))) { vc = 1; - else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS))) + } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS))) { vc = 2; - else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS))) + } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS))) { vc = 3; - else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS))) + } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS))) { vc = 4; - else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT))) + } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT))) { vc = 5; - else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT))) + } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT))) { vc = 6; + } d["viewport_mode"] = vc; Array vpdata; @@ -4642,8 +4536,9 @@ Dictionary Node3DEditor::get_state() const { Dictionary gizmos_status; for (int i = 0; i < gizmo_plugins_by_name.size(); i++) { - if (!gizmo_plugins_by_name[i]->can_be_hidden()) + if (!gizmo_plugins_by_name[i]->can_be_hidden()) { continue; + } int state = gizmos_menu->get_item_state(gizmos_menu->get_item_index(i)); String name = gizmo_plugins_by_name[i]->get_name(); gizmos_status[name] = state; @@ -4653,8 +4548,8 @@ Dictionary Node3DEditor::get_state() const { return d; } -void Node3DEditor::set_state(const Dictionary &p_state) { +void Node3DEditor::set_state(const Dictionary &p_state) { Dictionary d = p_state; if (d.has("snap_enabled")) { @@ -4662,14 +4557,17 @@ void Node3DEditor::set_state(const Dictionary &p_state) { tool_option_button[TOOL_OPT_USE_SNAP]->set_pressed(d["snap_enabled"]); } - if (d.has("translate_snap")) + if (d.has("translate_snap")) { snap_translate_value = d["translate_snap"]; + } - if (d.has("rotate_snap")) + if (d.has("rotate_snap")) { snap_rotate_value = d["rotate_snap"]; + } - if (d.has("scale_snap")) + if (d.has("scale_snap")) { snap_scale_value = d["scale_snap"]; + } _snap_update(); @@ -4681,18 +4579,19 @@ void Node3DEditor::set_state(const Dictionary &p_state) { if (d.has("viewport_mode")) { int vc = d["viewport_mode"]; - if (vc == 1) + if (vc == 1) { _menu_item_pressed(MENU_VIEW_USE_1_VIEWPORT); - else if (vc == 2) + } else if (vc == 2) { _menu_item_pressed(MENU_VIEW_USE_2_VIEWPORTS); - else if (vc == 3) + } else if (vc == 3) { _menu_item_pressed(MENU_VIEW_USE_3_VIEWPORTS); - else if (vc == 4) + } else if (vc == 4) { _menu_item_pressed(MENU_VIEW_USE_4_VIEWPORTS); - else if (vc == 5) + } else if (vc == 5) { _menu_item_pressed(MENU_VIEW_USE_2_VIEWPORTS_ALT); - else if (vc == 6) + } else if (vc == 6) { _menu_item_pressed(MENU_VIEW_USE_3_VIEWPORTS_ALT); + } } if (d.has("viewports")) { @@ -4708,12 +4607,15 @@ void Node3DEditor::set_state(const Dictionary &p_state) { } } - if (d.has("zfar")) + if (d.has("zfar")) { settings_zfar->set_value(float(d["zfar"])); - if (d.has("znear")) + } + if (d.has("znear")) { settings_znear->set_value(float(d["znear"])); - if (d.has("fov")) + } + if (d.has("fov")) { settings_fov->set_value(float(d["fov"])); + } if (d.has("show_grid")) { bool use = d["show_grid"]; @@ -4737,8 +4639,9 @@ void Node3DEditor::set_state(const Dictionary &p_state) { gizmos_status.get_key_list(&keys); for (int j = 0; j < gizmo_plugins_by_name.size(); ++j) { - if (!gizmo_plugins_by_name[j]->can_be_hidden()) + if (!gizmo_plugins_by_name[j]->can_be_hidden()) { continue; + } int state = EditorNode3DGizmoPlugin::VISIBLE; for (int i = 0; i < keys.size(); i++) { if (gizmo_plugins_by_name.write[j]->get_name() == keys[i]) { @@ -4754,10 +4657,8 @@ void Node3DEditor::set_state(const Dictionary &p_state) { } void Node3DEditor::edit(Node3D *p_spatial) { - if (p_spatial != selected) { if (selected) { - Ref<EditorNode3DGizmo> seg = selected->get_gizmo(); if (seg.is_valid()) { seg->set_selected(false); @@ -4769,7 +4670,6 @@ void Node3DEditor::edit(Node3D *p_spatial) { over_gizmo_handle = -1; if (selected) { - Ref<EditorNode3DGizmo> seg = selected->get_gizmo(); if (seg.is_valid()) { seg->set_selected(true); @@ -4780,21 +4680,18 @@ void Node3DEditor::edit(Node3D *p_spatial) { } void Node3DEditor::_snap_changed() { - snap_translate_value = snap_translate->get_text().to_double(); snap_rotate_value = snap_rotate->get_text().to_double(); snap_scale_value = snap_scale->get_text().to_double(); } void Node3DEditor::_snap_update() { - snap_translate->set_text(String::num(snap_translate_value)); snap_rotate->set_text(String::num(snap_rotate_value)); snap_scale->set_text(String::num(snap_scale_value)); } void Node3DEditor::_xform_dialog_action() { - Transform t; //translation Vector3 scale; @@ -4816,22 +4713,22 @@ void Node3DEditor::_xform_dialog_action() { List<Node *> &selection = editor_selection->get_selected_node_list(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp); - if (!se) + if (!se) { continue; + } bool post = xform_type->get_selected() > 0; Transform tr = sp->get_global_gizmo_transform(); - if (post) + if (post) { tr = tr * t; - else { - + } else { tr.basis = t.basis * tr.basis; tr.origin += t.origin; } @@ -4843,10 +4740,8 @@ void Node3DEditor::_xform_dialog_action() { } void Node3DEditor::_menu_item_toggled(bool pressed, int p_option) { - switch (p_option) { case MENU_TOOL_LOCAL_COORDS: { - tool_option_button[TOOL_OPT_LOCAL_COORDS]->set_pressed(pressed); update_transform_gizmo(); } break; @@ -4861,7 +4756,6 @@ void Node3DEditor::_menu_item_toggled(bool pressed, int p_option) { using Override = EditorDebuggerNode::CameraOverride; if (pressed) { - debugger->set_camera_override((Override)(Override::OVERRIDE_3D_1 + camera_override_viewport_id)); } else { debugger->set_camera_override(Override::OVERRIDE_NONE); @@ -4872,7 +4766,6 @@ void Node3DEditor::_menu_item_toggled(bool pressed, int p_option) { } void Node3DEditor::_menu_gizmo_toggled(int p_option) { - const int idx = gizmos_menu->get_item_index(p_option); gizmos_menu->toggle_item_multistate(idx); @@ -4911,8 +4804,9 @@ void Node3DEditor::_update_camera_override_button(bool p_game_running) { void Node3DEditor::_update_camera_override_viewport(Object *p_viewport) { Node3DEditorViewport *current_viewport = Object::cast_to<Node3DEditorViewport>(p_viewport); - if (!current_viewport) + if (!current_viewport) { return; + } EditorDebuggerNode *const debugger = EditorDebuggerNode::get_singleton(); @@ -4925,29 +4819,24 @@ void Node3DEditor::_update_camera_override_viewport(Object *p_viewport) { } void Node3DEditor::_menu_item_pressed(int p_option) { - switch (p_option) { - case MENU_TOOL_SELECT: case MENU_TOOL_MOVE: case MENU_TOOL_ROTATE: case MENU_TOOL_SCALE: case MENU_TOOL_LIST_SELECT: { - - for (int i = 0; i < TOOL_MAX; i++) + for (int i = 0; i < TOOL_MAX; i++) { tool_button[i]->set_pressed(i == p_option); + } tool_mode = (ToolMode)p_option; update_transform_gizmo(); } break; case MENU_TRANSFORM_CONFIGURE_SNAP: { - snap_dialog->popup_centered(Size2(200, 180)); } break; case MENU_TRANSFORM_DIALOG: { - for (int i = 0; i < 3; i++) { - xform_translate[i]->set_text("0"); xform_rotate[i]->set_text("0"); xform_scale[i]->set_text("1"); @@ -4957,7 +4846,6 @@ void Node3DEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_USE_1_VIEWPORT: { - viewport_base->set_view(Node3DEditorViewportContainer::VIEW_USE_1_VIEWPORT); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), true); @@ -4969,7 +4857,6 @@ void Node3DEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_USE_2_VIEWPORTS: { - viewport_base->set_view(Node3DEditorViewportContainer::VIEW_USE_2_VIEWPORTS); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false); @@ -4981,7 +4868,6 @@ void Node3DEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_USE_2_VIEWPORTS_ALT: { - viewport_base->set_view(Node3DEditorViewportContainer::VIEW_USE_2_VIEWPORTS_ALT); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false); @@ -4993,7 +4879,6 @@ void Node3DEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_USE_3_VIEWPORTS: { - viewport_base->set_view(Node3DEditorViewportContainer::VIEW_USE_3_VIEWPORTS); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false); @@ -5005,7 +4890,6 @@ void Node3DEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_USE_3_VIEWPORTS_ALT: { - viewport_base->set_view(Node3DEditorViewportContainer::VIEW_USE_3_VIEWPORTS_ALT); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false); @@ -5017,7 +4901,6 @@ void Node3DEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_USE_4_VIEWPORTS: { - viewport_base->set_view(Node3DEditorViewportContainer::VIEW_USE_4_VIEWPORTS); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false); @@ -5029,7 +4912,6 @@ void Node3DEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_ORIGIN: { - bool is_checked = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(p_option)); origin_enabled = !is_checked; @@ -5041,7 +4923,6 @@ void Node3DEditor::_menu_item_pressed(int p_option) { view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(p_option), origin_enabled); } break; case MENU_VIEW_GRID: { - bool is_checked = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(p_option)); grid_enabled = !is_checked; @@ -5057,7 +4938,6 @@ void Node3DEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_CAMERA_SETTINGS: { - settings_dialog->popup_centered(settings_vbc->get_combined_minimum_size() + Size2(50, 50)); } break; case MENU_SNAP_TO_FLOOR: { @@ -5069,13 +4949,14 @@ void Node3DEditor::_menu_item_pressed(int p_option) { List<Node *> &selection = editor_selection->get_selected_node_list(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *spatial = Object::cast_to<Node3D>(E->get()); - if (!spatial || !spatial->is_visible_in_tree()) + if (!spatial || !spatial->is_visible_in_tree()) { continue; + } - if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root()) + if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root()) { continue; + } undo_redo->add_do_method(spatial, "set_meta", "_edit_lock_", true); undo_redo->add_undo_method(spatial, "remove_meta", "_edit_lock_"); @@ -5093,13 +4974,14 @@ void Node3DEditor::_menu_item_pressed(int p_option) { List<Node *> &selection = editor_selection->get_selected_node_list(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *spatial = Object::cast_to<Node3D>(E->get()); - if (!spatial || !spatial->is_visible_in_tree()) + if (!spatial || !spatial->is_visible_in_tree()) { continue; + } - if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root()) + if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root()) { continue; + } undo_redo->add_do_method(spatial, "remove_meta", "_edit_lock_"); undo_redo->add_undo_method(spatial, "set_meta", "_edit_lock_", true); @@ -5117,13 +4999,14 @@ void Node3DEditor::_menu_item_pressed(int p_option) { List<Node *> &selection = editor_selection->get_selected_node_list(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *spatial = Object::cast_to<Node3D>(E->get()); - if (!spatial || !spatial->is_visible_in_tree()) + if (!spatial || !spatial->is_visible_in_tree()) { continue; + } - if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root()) + if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root()) { continue; + } undo_redo->add_do_method(spatial, "set_meta", "_edit_group_", true); undo_redo->add_undo_method(spatial, "remove_meta", "_edit_group_"); @@ -5140,13 +5023,14 @@ void Node3DEditor::_menu_item_pressed(int p_option) { List<Node *> &selection = editor_selection->get_selected_node_list(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *spatial = Object::cast_to<Node3D>(E->get()); - if (!spatial || !spatial->is_visible_in_tree()) + if (!spatial || !spatial->is_visible_in_tree()) { continue; + } - if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root()) + if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root()) { continue; + } undo_redo->add_do_method(spatial, "remove_meta", "_edit_group_"); undo_redo->add_undo_method(spatial, "set_meta", "_edit_group_", true); @@ -5162,7 +5046,6 @@ void Node3DEditor::_menu_item_pressed(int p_option) { } void Node3DEditor::_init_indicators() { - { origin_enabled = true; grid_enabled = true; @@ -5224,11 +5107,9 @@ void Node3DEditor::_init_indicators() { } { - //move gizmo for (int i = 0; i < 3; i++) { - Color col; switch (i) { case 0: @@ -5276,7 +5157,6 @@ void Node3DEditor::_init_indicators() { //translate { - Ref<SurfaceTool> surftool = memnew(SurfaceTool); surftool->begin(Mesh::PRIMITIVE_TRIANGLES); @@ -5293,12 +5173,10 @@ void Node3DEditor::_init_indicators() { int arrow_sides = 16; for (int k = 0; k < arrow_sides; k++) { - Basis ma(ivec, Math_PI * 2 * float(k) / arrow_sides); Basis mb(ivec, Math_PI * 2 * float(k + 1) / arrow_sides); for (int j = 0; j < arrow_points - 1; j++) { - Vector3 points[4] = { ma.xform(arrow[j]), mb.xform(arrow[j]), @@ -5365,7 +5243,6 @@ void Node3DEditor::_init_indicators() { // Rotate { - Ref<SurfaceTool> surftool = memnew(SurfaceTool); surftool->begin(Mesh::PRIMITIVE_TRIANGLES); @@ -5378,12 +5255,10 @@ void Node3DEditor::_init_indicators() { }; for (int k = 0; k < 64; k++) { - Basis ma(ivec, Math_PI * 2 * float(k) / 64); Basis mb(ivec, Math_PI * 2 * float(k + 1) / 64); for (int j = 0; j < 4; j++) { - Vector3 points[4] = { ma.xform(circle[j]), mb.xform(circle[j]), @@ -5423,12 +5298,10 @@ void Node3DEditor::_init_indicators() { int arrow_sides = 4; for (int k = 0; k < 4; k++) { - Basis ma(ivec, Math_PI * 2 * float(k) / arrow_sides); Basis mb(ivec, Math_PI * 2 * float(k + 1) / arrow_sides); for (int j = 0; j < arrow_points - 1; j++) { - Vector3 points[4] = { ma.xform(arrow[j]), mb.xform(arrow[j]), @@ -5499,12 +5372,12 @@ void Node3DEditor::_init_indicators() { } void Node3DEditor::_update_gizmos_menu() { - gizmos_menu->clear(); for (int i = 0; i < gizmo_plugins_by_name.size(); ++i) { - if (!gizmo_plugins_by_name[i]->can_be_hidden()) + if (!gizmo_plugins_by_name[i]->can_be_hidden()) { continue; + } String plugin_name = gizmo_plugins_by_name[i]->get_name(); const int plugin_state = gizmo_plugins_by_name[i]->get_state(); gizmos_menu->add_multistate_item(TTR(plugin_name), 3, plugin_state, i); @@ -5525,8 +5398,9 @@ void Node3DEditor::_update_gizmos_menu() { void Node3DEditor::_update_gizmos_menu_theme() { for (int i = 0; i < gizmo_plugins_by_name.size(); ++i) { - if (!gizmo_plugins_by_name[i]->can_be_hidden()) + if (!gizmo_plugins_by_name[i]->can_be_hidden()) { continue; + } const int plugin_state = gizmo_plugins_by_name[i]->get_state(); const int idx = gizmos_menu->get_item_index(i); switch (plugin_state) { @@ -5544,7 +5418,6 @@ void Node3DEditor::_update_gizmos_menu_theme() { } void Node3DEditor::_init_grid() { - Vector<Color> grid_colors[3]; Vector<Vector3> grid_points[3]; @@ -5603,7 +5476,6 @@ void Node3DEditor::_init_grid() { } void Node3DEditor::_finish_indicators() { - RenderingServer::get_singleton()->free(origin_instance); RenderingServer::get_singleton()->free(origin); @@ -5619,14 +5491,14 @@ void Node3DEditor::_finish_grid() { bool Node3DEditor::is_any_freelook_active() const { for (unsigned int i = 0; i < VIEWPORTS_COUNT; ++i) { - if (viewports[i]->is_freelook_active()) + if (viewports[i]->is_freelook_active()) { return true; + } } return false; } void Node3DEditor::_refresh_menu_icons() { - bool all_locked = true; bool all_grouped = true; @@ -5798,16 +5670,15 @@ void Node3DEditor::snap_selected_nodes_to_floor() { } void Node3DEditor::_unhandled_key_input(Ref<InputEvent> p_event) { - - if (!is_visible_in_tree()) + if (!is_visible_in_tree()) { return; + } snap_key_enabled = Input::get_singleton()->is_key_pressed(KEY_CONTROL); } -void Node3DEditor::_notification(int p_what) { +void Node3DEditor::_notification(int p_what) { if (p_what == NOTIFICATION_READY) { - tool_button[Node3DEditor::TOOL_MODE_SELECT]->set_icon(get_theme_icon("ToolSelect", "EditorIcons")); tool_button[Node3DEditor::TOOL_MODE_MOVE]->set_icon(get_theme_icon("ToolMove", "EditorIcons")); tool_button[Node3DEditor::TOOL_MODE_ROTATE]->set_icon(get_theme_icon("ToolRotate", "EditorIcons")); @@ -5840,14 +5711,12 @@ void Node3DEditor::_notification(int p_what) { editor->connect("stop_pressed", callable_mp(this, &Node3DEditor::_update_camera_override_button), make_binds(false)); editor->connect("play_pressed", callable_mp(this, &Node3DEditor::_update_camera_override_button), make_binds(true)); } else if (p_what == NOTIFICATION_ENTER_TREE) { - _register_all_gizmos(); _update_gizmos_menu(); _init_indicators(); } else if (p_what == NOTIFICATION_THEME_CHANGED) { _update_gizmos_menu_theme(); } else if (p_what == NOTIFICATION_EXIT_TREE) { - _finish_indicators(); } else if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { tool_button[Node3DEditor::TOOL_MODE_SELECT]->set_icon(get_theme_icon("ToolSelect", "EditorIcons")); @@ -5884,39 +5753,33 @@ void Node3DEditor::_notification(int p_what) { } void Node3DEditor::add_control_to_menu_panel(Control *p_control) { - hbc_menu->add_child(p_control); } void Node3DEditor::remove_control_from_menu_panel(Control *p_control) { - hbc_menu->remove_child(p_control); } void Node3DEditor::set_can_preview(Camera3D *p_preview) { - for (int i = 0; i < 4; i++) { viewports[i]->set_can_preview(p_preview); } } VSplitContainer *Node3DEditor::get_shader_split() { - return shader_split; } HSplitContainer *Node3DEditor::get_palette_split() { - return palette_split; } void Node3DEditor::_request_gizmo(Object *p_obj) { - Node3D *sp = Object::cast_to<Node3D>(p_obj); - if (!sp) + if (!sp) { return; + } if (editor->get_edited_scene() && (sp == editor->get_edited_scene() || (sp->get_owner() && editor->get_edited_scene()->is_a_parent_of(sp)))) { - Ref<EditorNode3DGizmo> seg; for (int i = 0; i < gizmo_plugins_by_priority.size(); ++i) { @@ -5937,57 +5800,62 @@ void Node3DEditor::_request_gizmo(Object *p_obj) { } void Node3DEditor::_toggle_maximize_view(Object *p_viewport) { - if (!p_viewport) + if (!p_viewport) { return; + } Node3DEditorViewport *current_viewport = Object::cast_to<Node3DEditorViewport>(p_viewport); - if (!current_viewport) + if (!current_viewport) { return; + } int index = -1; bool maximized = false; for (int i = 0; i < 4; i++) { if (viewports[i] == current_viewport) { index = i; - if (current_viewport->get_global_rect() == viewport_base->get_global_rect()) + if (current_viewport->get_global_rect() == viewport_base->get_global_rect()) { maximized = true; + } break; } } - if (index == -1) + if (index == -1) { return; + } if (!maximized) { - for (uint32_t i = 0; i < VIEWPORTS_COUNT; i++) { - if (i == (uint32_t)index) + if (i == (uint32_t)index) { viewports[i]->set_anchors_and_margins_preset(Control::PRESET_WIDE); - else + } else { viewports[i]->hide(); + } } } else { - - for (uint32_t i = 0; i < VIEWPORTS_COUNT; i++) + for (uint32_t i = 0; i < VIEWPORTS_COUNT; i++) { viewports[i]->show(); + } - if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT))) + if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT))) { _menu_item_pressed(MENU_VIEW_USE_1_VIEWPORT); - else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS))) + } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS))) { _menu_item_pressed(MENU_VIEW_USE_2_VIEWPORTS); - else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT))) + } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT))) { _menu_item_pressed(MENU_VIEW_USE_2_VIEWPORTS_ALT); - else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS))) + } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS))) { _menu_item_pressed(MENU_VIEW_USE_3_VIEWPORTS); - else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT))) + } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT))) { _menu_item_pressed(MENU_VIEW_USE_3_VIEWPORTS_ALT); - else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS))) + } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS))) { _menu_item_pressed(MENU_VIEW_USE_4_VIEWPORTS); + } } } void Node3DEditor::_node_removed(Node *p_node) { - - if (p_node == selected) + if (p_node == selected) { selected = nullptr; + } } void Node3DEditor::_register_all_gizmos() { @@ -6018,7 +5886,6 @@ void Node3DEditor::_register_all_gizmos() { } void Node3DEditor::_bind_methods() { - ClassDB::bind_method("_unhandled_key_input", &Node3DEditor::_unhandled_key_input); ClassDB::bind_method("_get_editor_data", &Node3DEditor::_get_editor_data); ClassDB::bind_method("_request_gizmo", &Node3DEditor::_request_gizmo); @@ -6029,7 +5896,6 @@ void Node3DEditor::_bind_methods() { } void Node3DEditor::clear() { - settings_fov->set_value(EDITOR_DEF("editors/3d/default_fov", 70.0)); settings_znear->set_value(EDITOR_DEF("editors/3d/default_z_near", 0.05)); settings_zfar->set_value(EDITOR_DEF("editors/3d/default_z_far", 1500.0)); @@ -6048,7 +5914,6 @@ void Node3DEditor::clear() { } for (uint32_t i = 0; i < VIEWPORTS_COUNT; i++) { - viewports[i]->view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(Node3DEditorViewport::VIEW_AUDIO_LISTENER), i == 0); viewports[i]->viewport->set_as_audio_listener(i == 0); } @@ -6057,7 +5922,6 @@ void Node3DEditor::clear() { } Node3DEditor::Node3DEditor(EditorNode *p_editor) { - gizmo.visible = true; gizmo.scale = 1.0; @@ -6270,7 +6134,6 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) { shader_split->add_child(viewport_base); viewport_base->set_v_size_flags(SIZE_EXPAND_FILL); for (uint32_t i = 0; i < VIEWPORTS_COUNT; i++) { - viewports[i] = memnew(Node3DEditorViewport(this, editor, i)); viewports[i]->connect("toggle_maximize_view", callable_mp(this, &Node3DEditor::_toggle_maximize_view)); viewports[i]->connect("clicked", callable_mp(this, &Node3DEditor::_update_camera_override_viewport)); @@ -6355,7 +6218,6 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) { xform_vbc->add_child(xform_hbc); for (int i = 0; i < 3; i++) { - xform_translate[i] = memnew(LineEdit); xform_translate[i]->set_h_size_flags(SIZE_EXPAND_FILL); xform_hbc->add_child(xform_translate[i]); @@ -6420,25 +6282,21 @@ Node3DEditor::~Node3DEditor() { } void Node3DEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { - spatial_editor->show(); spatial_editor->set_process(true); } else { - spatial_editor->hide(); spatial_editor->set_process(false); } } -void Node3DEditorPlugin::edit(Object *p_object) { +void Node3DEditorPlugin::edit(Object *p_object) { spatial_editor->edit(Object::cast_to<Node3D>(p_object)); } bool Node3DEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("Node3D"); } @@ -6447,12 +6305,10 @@ Dictionary Node3DEditorPlugin::get_state() const { } void Node3DEditorPlugin::set_state(const Dictionary &p_state) { - spatial_editor->set_state(p_state); } void Node3DEditor::snap_cursor_to_plane(const Plane &p_plane) { - //cursor.pos=p_plane.project(cursor.pos); } @@ -6499,17 +6355,14 @@ float Node3DEditor::get_scale_snap() const { } void Node3DEditorPlugin::_bind_methods() { - ClassDB::bind_method("snap_cursor_to_plane", &Node3DEditorPlugin::snap_cursor_to_plane); } void Node3DEditorPlugin::snap_cursor_to_plane(const Plane &p_plane) { - spatial_editor->snap_cursor_to_plane(p_plane); } struct _GizmoPluginPriorityComparator { - bool operator()(const Ref<EditorNode3DGizmoPlugin> &p_a, const Ref<EditorNode3DGizmoPlugin> &p_b) const { if (p_a->get_priority() == p_b->get_priority()) { return p_a->get_name() < p_b->get_name(); @@ -6519,7 +6372,6 @@ struct _GizmoPluginPriorityComparator { }; struct _GizmoPluginNameComparator { - bool operator()(const Ref<EditorNode3DGizmoPlugin> &p_a, const Ref<EditorNode3DGizmoPlugin> &p_b) const { return p_a->get_name() < p_b->get_name(); } @@ -6545,7 +6397,6 @@ void Node3DEditor::remove_gizmo_plugin(Ref<EditorNode3DGizmoPlugin> p_plugin) { } Node3DEditorPlugin::Node3DEditorPlugin(EditorNode *p_node) { - editor = p_node; spatial_editor = memnew(Node3DEditor(p_node)); spatial_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL); @@ -6559,7 +6410,6 @@ Node3DEditorPlugin::~Node3DEditorPlugin() { } void EditorNode3DGizmoPlugin::create_material(const String &p_name, const Color &p_color, bool p_billboard, bool p_on_top, bool p_use_vertex_color) { - Color instanced_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/instanced", Color(0.7, 0.7, 0.7, 0.6)); Vector<Ref<StandardMaterial3D>> mats; @@ -6601,7 +6451,6 @@ void EditorNode3DGizmoPlugin::create_material(const String &p_name, const Color } void EditorNode3DGizmoPlugin::create_icon_material(const String &p_name, const Ref<Texture2D> &p_texture, bool p_on_top, const Color &p_albedo) { - Color instanced_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/instanced", Color(0.7, 0.7, 0.7, 0.6)); Vector<Ref<StandardMaterial3D>> icons; @@ -6672,8 +6521,9 @@ Ref<StandardMaterial3D> EditorNode3DGizmoPlugin::get_material(const String &p_na ERR_FAIL_COND_V(!materials.has(p_name), Ref<StandardMaterial3D>()); ERR_FAIL_COND_V(materials[p_name].size() == 0, Ref<StandardMaterial3D>()); - if (p_gizmo.is_null() || materials[p_name].size() == 1) + if (p_gizmo.is_null() || materials[p_name].size() == 1) { return materials[p_name][0]; + } int index = (p_gizmo->is_selected() ? 1 : 0) + (p_gizmo->is_editable() ? 2 : 0); @@ -6703,15 +6553,15 @@ int EditorNode3DGizmoPlugin::get_priority() const { } Ref<EditorNode3DGizmo> EditorNode3DGizmoPlugin::get_gizmo(Node3D *p_spatial) { - if (get_script_instance() && get_script_instance()->has_method("get_gizmo")) { return get_script_instance()->call("get_gizmo", p_spatial); } Ref<EditorNode3DGizmo> ref = create_gizmo(p_spatial); - if (ref.is_null()) + if (ref.is_null()) { return ref; + } ref->set_plugin(this); ref->set_spatial_node(p_spatial); @@ -6764,14 +6614,14 @@ bool EditorNode3DGizmoPlugin::has_gizmo(Node3D *p_spatial) { } Ref<EditorNode3DGizmo> EditorNode3DGizmoPlugin::create_gizmo(Node3D *p_spatial) { - if (get_script_instance() && get_script_instance()->has_method("create_gizmo")) { return get_script_instance()->call("create_gizmo", p_spatial); } Ref<EditorNode3DGizmo> ref; - if (has_gizmo(p_spatial)) + if (has_gizmo(p_spatial)) { ref.instance(); + } return ref; } diff --git a/editor/plugins/node_3d_editor_plugin.h b/editor/plugins/node_3d_editor_plugin.h index fdc0741651..3d92e7e7e1 100644 --- a/editor/plugins/node_3d_editor_plugin.h +++ b/editor/plugins/node_3d_editor_plugin.h @@ -46,7 +46,6 @@ class Node3DEditorViewport; class SubViewportContainer; class EditorNode3DGizmo : public Node3DGizmo { - GDCLASS(EditorNode3DGizmo, Node3DGizmo); bool selected; @@ -57,7 +56,6 @@ public: bool is_selected() const { return selected; } struct Instance { - RID instance; Ref<ArrayMesh> mesh; Ref<Material> material; @@ -68,7 +66,6 @@ public: bool can_intersect; bool extra_margin; Instance() { - billboard = false; unscaled = false; can_intersect = false; @@ -179,7 +176,6 @@ public: }; class Node3DEditorViewport : public Control { - GDCLASS(Node3DEditorViewport, Control); friend class Node3DEditor; friend class ViewportRotationControl; @@ -299,7 +295,6 @@ private: Label *fps_label; struct _RayResult { - Node3D *item; float depth; int handle; @@ -389,7 +384,6 @@ private: } _edit; struct Cursor { - Vector3 pos; float x_rot, y_rot, distance; Vector3 eye_pos; // Used in freelook mode @@ -490,7 +484,6 @@ public: }; class Node3DEditorSelectedItem : public Object { - GDCLASS(Node3DEditorSelectedItem, Object); public: @@ -510,7 +503,6 @@ public: }; class Node3DEditorViewportContainer : public Container { - GDCLASS(Node3DEditorViewportContainer, Container); public: @@ -551,7 +543,6 @@ public: }; class Node3DEditor : public VBoxContainer { - GDCLASS(Node3DEditor, VBoxContainer); public: @@ -629,7 +620,6 @@ private: AABB preview_bounds; struct Gizmo { - bool visible; float scale; Transform transform; @@ -819,7 +809,6 @@ public: }; class Node3DEditorPlugin : public EditorPlugin { - GDCLASS(Node3DEditorPlugin, EditorPlugin); Node3DEditor *spatial_editor; @@ -849,7 +838,6 @@ public: }; class EditorNode3DGizmoPlugin : public Resource { - GDCLASS(EditorNode3DGizmoPlugin, Resource); public: diff --git a/editor/plugins/path_2d_editor_plugin.cpp b/editor/plugins/path_2d_editor_plugin.cpp index 2edb337b1c..a3dab665b8 100644 --- a/editor/plugins/path_2d_editor_plugin.cpp +++ b/editor/plugins/path_2d_editor_plugin.cpp @@ -37,11 +37,8 @@ #include "editor/editor_settings.h" void Path2DEditor::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_READY: { - //button_create->set_icon( get_icon("Edit","EditorIcons")); //button_edit->set_icon( get_icon("MovePoint","EditorIcons")); //set_pressed_button(button_edit); @@ -49,12 +46,11 @@ void Path2DEditor::_notification(int p_what) { } break; case NOTIFICATION_PHYSICS_PROCESS: { - } break; } } -void Path2DEditor::_node_removed(Node *p_node) { +void Path2DEditor::_node_removed(Node *p_node) { if (p_node == node) { node = nullptr; hide(); @@ -62,31 +58,31 @@ void Path2DEditor::_node_removed(Node *p_node) { } bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { - if (!node) + if (!node) { return false; + } - if (!node->is_visible_in_tree()) + if (!node->is_visible_in_tree()) { return false; + } - if (!node->get_curve().is_valid()) + if (!node->get_curve().is_valid()) { return false; + } real_t grab_threshold = EDITOR_GET("editors/poly_editor/point_grab_radius"); Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid()) { - Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); Vector2 gpoint = mb->get_position(); Vector2 cpoint = node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(mb->get_position()))); if (mb->is_pressed() && action == ACTION_NONE) { - Ref<Curve2D> curve = node->get_curve(); for (int i = 0; i < curve->get_point_count(); i++) { - real_t dist_to_p = gpoint.distance_to(xform.xform(curve->get_point_position(i))); real_t dist_to_p_out = gpoint.distance_to(xform.xform(curve->get_point_position(i) + curve->get_point_out(i))); real_t dist_to_p_in = gpoint.distance_to(xform.xform(curve->get_point_position(i) + curve->get_point_in(i))); @@ -104,7 +100,6 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { } else if (mode == MODE_EDIT || mode == MODE_EDIT_CURVE) { // In/out controls can be moved in multiple modes. if (dist_to_p_out < grab_threshold && i < (curve->get_point_count() - 1)) { - action = ACTION_MOVING_OUT; action_point = i; moving_from = curve->get_point_out(i); @@ -112,7 +107,6 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { orig_in_length = curve->get_point_in(action_point).length(); return true; } else if (dist_to_p_in < grab_threshold && i > 0) { - action = ACTION_MOVING_IN; action_point = i; moving_from = curve->get_point_in(i); @@ -126,7 +120,6 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { // Check for point deletion. if ((mb->get_button_index() == BUTTON_RIGHT && mode == MODE_EDIT) || (mb->get_button_index() == BUTTON_LEFT && mode == MODE_DELETE)) { if (dist_to_p < grab_threshold) { - undo_redo->create_action(TTR("Remove Point from Curve")); undo_redo->add_do_method(curve.ptr(), "remove_point", i); undo_redo->add_undo_method(curve.ptr(), "add_point", curve->get_point_position(i), curve->get_point_in(i), curve->get_point_out(i), i); @@ -135,7 +128,6 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { undo_redo->commit_action(); return true; } else if (dist_to_p_out < grab_threshold) { - undo_redo->create_action(TTR("Remove Out-Control from Curve")); undo_redo->add_do_method(curve.ptr(), "set_point_out", i, Vector2()); undo_redo->add_undo_method(curve.ptr(), "set_point_out", i, curve->get_point_out(i)); @@ -144,7 +136,6 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { undo_redo->commit_action(); return true; } else if (dist_to_p_in < grab_threshold) { - undo_redo->create_action(TTR("Remove In-Control from Curve")); undo_redo->add_do_method(curve.ptr(), "set_point_in", i, Vector2()); undo_redo->add_undo_method(curve.ptr(), "set_point_in", i, curve->get_point_in(i)); @@ -159,7 +150,6 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { // Check for point creation. if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT && ((mb->get_command() && mode == MODE_EDIT) || mode == MODE_CREATE)) { - Ref<Curve2D> curve = node->get_curve(); undo_redo->create_action(TTR("Add Point to Curve")); @@ -189,11 +179,13 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { int len = curve->get_point_count(); for (int i = 0; i < len - 1; i++) { float compareLength = curve->get_closest_offset(curve->get_point_position(i + 1)); - if (mbLength >= curve->get_closest_offset(curve->get_point_position(i)) && mbLength <= compareLength) + if (mbLength >= curve->get_closest_offset(curve->get_point_position(i)) && mbLength <= compareLength) { insertion_point = i; + } } - if (insertion_point == -1) + if (insertion_point == -1) { insertion_point = curve->get_point_count() - 2; + } undo_redo->create_action(TTR("Split Curve")); undo_redo->add_do_method(curve.ptr(), "add_point", xform.affine_inverse().xform(gpoint2), Vector2(0, 0), Vector2(0, 0), insertion_point + 1); @@ -216,18 +208,15 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { // Check for point movement completion. if (!mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT && action != ACTION_NONE) { - Ref<Curve2D> curve = node->get_curve(); Vector2 new_pos = moving_from + xform.affine_inverse().basis_xform(gpoint - moving_screen_from); switch (action) { - case ACTION_NONE: // N/A, handled in above condition. break; case ACTION_MOVING_POINT: { - undo_redo->create_action(TTR("Move Point in Curve")); undo_redo->add_do_method(curve.ptr(), "set_point_position", action_point, cpoint); undo_redo->add_undo_method(curve.ptr(), "set_point_position", action_point, moving_from); @@ -238,7 +227,6 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { } break; case ACTION_MOVING_IN: { - undo_redo->create_action(TTR("Move In-Control in Curve")); undo_redo->add_do_method(curve.ptr(), "set_point_in", action_point, new_pos); undo_redo->add_undo_method(curve.ptr(), "set_point_in", action_point, moving_from); @@ -254,7 +242,6 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { } break; case ACTION_MOVING_OUT: { - undo_redo->create_action(TTR("Move Out-Control in Curve")); undo_redo->add_do_method(curve.ptr(), "set_point_out", action_point, new_pos); undo_redo->add_undo_method(curve.ptr(), "set_point_out", action_point, moving_from); @@ -279,7 +266,6 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseMotion> mm = p_event; if (mm.is_valid()) { - if (action == ACTION_NONE && mode == MODE_EDIT) { // Handle Edge Follow bool old_edge = on_edge; @@ -288,10 +274,12 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { Vector2 gpoint = mm->get_position(); Ref<Curve2D> curve = node->get_curve(); - if (curve == nullptr) + if (curve == nullptr) { return true; - if (curve->get_point_count() < 2) + } + if (curve->get_point_count() < 2) { return true; + } // Find edge edge_point = xform.xform(curve->get_closest_point(xform.affine_inverse().xform(mm->get_position()))); @@ -336,7 +324,6 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { Vector2 new_pos = moving_from + xform.affine_inverse().basis_xform(gpoint - moving_screen_from); switch (action) { - case ACTION_NONE: // N/A, handled in above condition. break; @@ -348,15 +335,17 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { case ACTION_MOVING_IN: { curve->set_point_in(action_point, new_pos); - if (mirror_handle_angle) + if (mirror_handle_angle) { curve->set_point_out(action_point, mirror_handle_length ? -new_pos : (-new_pos.normalized() * orig_out_length)); + } } break; case ACTION_MOVING_OUT: { curve->set_point_out(action_point, new_pos); - if (mirror_handle_angle) + if (mirror_handle_angle) { curve->set_point_in(action_point, mirror_handle_length ? -new_pos : (-new_pos.normalized() * orig_in_length)); + } } break; } @@ -369,9 +358,9 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { } void Path2DEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { - - if (!node || !node->is_visible_in_tree() || !node->get_curve().is_valid()) + if (!node || !node->is_visible_in_tree() || !node->get_curve().is_valid()) { return; + } Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); @@ -428,77 +417,73 @@ void Path2DEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { } void Path2DEditor::_node_visibility_changed() { - if (!node) + if (!node) { return; + } canvas_item_editor->update_viewport(); } void Path2DEditor::edit(Node *p_path2d) { - if (!canvas_item_editor) { canvas_item_editor = CanvasItemEditor::get_singleton(); } if (p_path2d) { - node = Object::cast_to<Path2D>(p_path2d); - if (!node->is_connected("visibility_changed", callable_mp(this, &Path2DEditor::_node_visibility_changed))) + if (!node->is_connected("visibility_changed", callable_mp(this, &Path2DEditor::_node_visibility_changed))) { node->connect("visibility_changed", callable_mp(this, &Path2DEditor::_node_visibility_changed)); + } } else { - // node may have been deleted at this point - if (node && node->is_connected("visibility_changed", callable_mp(this, &Path2DEditor::_node_visibility_changed))) + if (node && node->is_connected("visibility_changed", callable_mp(this, &Path2DEditor::_node_visibility_changed))) { node->disconnect("visibility_changed", callable_mp(this, &Path2DEditor::_node_visibility_changed)); + } node = nullptr; } } void Path2DEditor::_bind_methods() { - //ClassDB::bind_method(D_METHOD("_menu_option"),&Path2DEditor::_menu_option); } void Path2DEditor::_mode_selected(int p_mode) { - if (p_mode == MODE_CREATE) { - curve_create->set_pressed(true); curve_edit->set_pressed(false); curve_edit_curve->set_pressed(false); curve_del->set_pressed(false); } else if (p_mode == MODE_EDIT) { - curve_create->set_pressed(false); curve_edit->set_pressed(true); curve_edit_curve->set_pressed(false); curve_del->set_pressed(false); } else if (p_mode == MODE_EDIT_CURVE) { - curve_create->set_pressed(false); curve_edit->set_pressed(false); curve_edit_curve->set_pressed(true); curve_del->set_pressed(false); } else if (p_mode == MODE_DELETE) { - curve_create->set_pressed(false); curve_edit->set_pressed(false); curve_edit_curve->set_pressed(false); curve_del->set_pressed(true); } else if (p_mode == ACTION_CLOSE) { - //? - if (!node->get_curve().is_valid()) + if (!node->get_curve().is_valid()) { return; - if (node->get_curve()->get_point_count() < 3) + } + if (node->get_curve()->get_point_count() < 3) { return; + } Vector2 begin = node->get_curve()->get_point_position(0); Vector2 end = node->get_curve()->get_point_position(node->get_curve()->get_point_count() - 1); - if (begin.distance_to(end) < CMP_EPSILON) + if (begin.distance_to(end) < CMP_EPSILON) { return; + } undo_redo->create_action(TTR("Remove Point from Curve")); undo_redo->add_do_method(node->get_curve().ptr(), "add_point", begin); @@ -513,7 +498,6 @@ void Path2DEditor::_mode_selected(int p_mode) { } void Path2DEditor::_handle_option_pressed(int p_option) { - PopupMenu *pm; pm = handle_menu->get_popup(); @@ -533,7 +517,6 @@ void Path2DEditor::_handle_option_pressed(int p_option) { } Path2DEditor::Path2DEditor(EditorNode *p_editor) { - canvas_item_editor = nullptr; editor = p_editor; undo_redo = editor->get_undo_redo(); @@ -603,23 +586,19 @@ Path2DEditor::Path2DEditor(EditorNode *p_editor) { } void Path2DEditorPlugin::edit(Object *p_object) { - path2d_editor->edit(Object::cast_to<Node>(p_object)); } bool Path2DEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("Path2D"); } void Path2DEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { path2d_editor->show(); path2d_editor->base_hb->show(); } else { - path2d_editor->hide(); path2d_editor->base_hb->hide(); path2d_editor->edit(nullptr); @@ -627,7 +606,6 @@ void Path2DEditorPlugin::make_visible(bool p_visible) { } Path2DEditorPlugin::Path2DEditorPlugin(EditorNode *p_node) { - editor = p_node; path2d_editor = memnew(Path2DEditor(p_node)); CanvasItemEditor::get_singleton()->add_control_to_menu_panel(path2d_editor); diff --git a/editor/plugins/path_2d_editor_plugin.h b/editor/plugins/path_2d_editor_plugin.h index aae0e11c99..390dfdfdf7 100644 --- a/editor/plugins/path_2d_editor_plugin.h +++ b/editor/plugins/path_2d_editor_plugin.h @@ -39,7 +39,6 @@ class CanvasItemEditor; class Path2DEditor : public HBoxContainer { - GDCLASS(Path2DEditor, HBoxContainer); UndoRedo *undo_redo; @@ -112,7 +111,6 @@ public: }; class Path2DEditorPlugin : public EditorPlugin { - GDCLASS(Path2DEditorPlugin, EditorPlugin); Path2DEditor *path2d_editor; diff --git a/editor/plugins/path_3d_editor_plugin.cpp b/editor/plugins/path_3d_editor_plugin.cpp index 6c475d829f..a44fe69ff6 100644 --- a/editor/plugins/path_3d_editor_plugin.cpp +++ b/editor/plugins/path_3d_editor_plugin.cpp @@ -35,13 +35,12 @@ #include "scene/resources/curve.h" String Path3DGizmo::get_handle_name(int p_idx) const { - Ref<Curve3D> c = path->get_curve(); - if (c.is_null()) + if (c.is_null()) { return ""; + } if (p_idx < c->get_point_count()) { - return TTR("Curve Point #") + itos(p_idx); } @@ -50,21 +49,22 @@ String Path3DGizmo::get_handle_name(int p_idx) const { int idx = p_idx / 2; int t = p_idx % 2; String n = TTR("Curve Point #") + itos(idx); - if (t == 0) + if (t == 0) { n += " In"; - else + } else { n += " Out"; + } return n; } -Variant Path3DGizmo::get_handle_value(int p_idx) { +Variant Path3DGizmo::get_handle_value(int p_idx) { Ref<Curve3D> c = path->get_curve(); - if (c.is_null()) + if (c.is_null()) { return Variant(); + } if (p_idx < c->get_point_count()) { - original = c->get_point_position(p_idx); return original; } @@ -75,20 +75,22 @@ Variant Path3DGizmo::get_handle_value(int p_idx) { int t = p_idx % 2; Vector3 ofs; - if (t == 0) + if (t == 0) { ofs = c->get_point_in(idx); - else + } else { ofs = c->get_point_out(idx); + } original = ofs + c->get_point_position(idx); return ofs; } -void Path3DGizmo::set_handle(int p_idx, Camera3D *p_camera, const Point2 &p_point) { +void Path3DGizmo::set_handle(int p_idx, Camera3D *p_camera, const Point2 &p_point) { Ref<Curve3D> c = path->get_curve(); - if (c.is_null()) + if (c.is_null()) { return; + } Transform gt = path->get_global_transform(); Transform gi = gt.affine_inverse(); @@ -97,13 +99,11 @@ void Path3DGizmo::set_handle(int p_idx, Camera3D *p_camera, const Point2 &p_poin // Setting curve point positions if (p_idx < c->get_point_count()) { - Plane p(gt.xform(original), p_camera->get_transform().basis.get_axis(2)); Vector3 inters; if (p.intersects_ray(ray_from, ray_dir, &inters)) { - if (Node3DEditor::get_singleton()->is_snap_enabled()) { float snap = Node3DEditor::get_singleton()->get_translate_snap(); inters.snap(Vector3(snap, snap, snap)); @@ -129,7 +129,6 @@ void Path3DGizmo::set_handle(int p_idx, Camera3D *p_camera, const Point2 &p_poin // Setting curve in/out positions if (p.intersects_ray(ray_from, ray_dir, &inters)) { - if (!Path3DEditorPlugin::singleton->is_handle_clicked()) { orig_in_length = c->get_point_in(idx).length(); orig_out_length = c->get_point_out(idx).length(); @@ -144,28 +143,28 @@ void Path3DGizmo::set_handle(int p_idx, Camera3D *p_camera, const Point2 &p_poin if (t == 0) { c->set_point_in(idx, local); - if (Path3DEditorPlugin::singleton->mirror_angle_enabled()) + if (Path3DEditorPlugin::singleton->mirror_angle_enabled()) { c->set_point_out(idx, Path3DEditorPlugin::singleton->mirror_length_enabled() ? -local : (-local.normalized() * orig_out_length)); + } } else { c->set_point_out(idx, local); - if (Path3DEditorPlugin::singleton->mirror_angle_enabled()) + if (Path3DEditorPlugin::singleton->mirror_angle_enabled()) { c->set_point_in(idx, Path3DEditorPlugin::singleton->mirror_length_enabled() ? -local : (-local.normalized() * orig_in_length)); + } } } } void Path3DGizmo::commit_handle(int p_idx, const Variant &p_restore, bool p_cancel) { - Ref<Curve3D> c = path->get_curve(); - if (c.is_null()) + if (c.is_null()) { return; + } UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo(); if (p_idx < c->get_point_count()) { - if (p_cancel) { - c->set_point_position(p_idx, p_restore); return; } @@ -218,7 +217,6 @@ void Path3DGizmo::commit_handle(int p_idx, const Variant &p_restore, bool p_canc } void Path3DGizmo::redraw() { - clear(); Ref<StandardMaterial3D> path_material = gizmo_plugin->get_material("path_material", this); @@ -226,21 +224,22 @@ void Path3DGizmo::redraw() { Ref<StandardMaterial3D> handles_material = gizmo_plugin->get_material("handles"); Ref<Curve3D> c = path->get_curve(); - if (c.is_null()) + if (c.is_null()) { return; + } Vector<Vector3> v3a = c->tessellate(); //Vector<Vector3> v3a=c->get_baked_points(); int v3s = v3a.size(); - if (v3s == 0) + if (v3s == 0) { return; + } Vector<Vector3> v3p; const Vector3 *r = v3a.ptr(); // BUG: the following won't work when v3s, avoid drawing as a temporary workaround. for (int i = 0; i < v3s - 1; i++) { - v3p.push_back(r[i]); v3p.push_back(r[i + 1]); //v3p.push_back(r[i]); @@ -258,7 +257,6 @@ void Path3DGizmo::redraw() { Vector<Vector3> sec_handles; for (int i = 0; i < c->get_point_count(); i++) { - Vector3 p = c->get_point_position(i); handles.push_back(p); if (i > 0) { @@ -287,18 +285,18 @@ void Path3DGizmo::redraw() { } Path3DGizmo::Path3DGizmo(Path3D *p_path) { - path = p_path; set_spatial_node(p_path); } bool Path3DEditorPlugin::forward_spatial_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) { - - if (!path) + if (!path) { return false; + } Ref<Curve3D> c = path->get_curve(); - if (c.is_null()) + if (c.is_null()) { return false; + } Transform gt = path->get_global_transform(); Transform it = gt.affine_inverse(); @@ -307,11 +305,11 @@ bool Path3DEditorPlugin::forward_spatial_gui_input(Camera3D *p_camera, const Ref Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid()) { - Point2 mbpos(mb->get_position().x, mb->get_position().y); - if (!mb->is_pressed()) + if (!mb->is_pressed()) { set_handle_clicked(false); + } if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT && (curve_create->is_pressed() || (curve_edit->is_pressed() && mb->get_control()))) { //click into curve, break it down @@ -325,17 +323,18 @@ bool Path3DEditorPlugin::forward_spatial_gui_input(Camera3D *p_camera, const Ref if (rc >= 2) { const Vector3 *r = v3a.ptr(); - if (p_camera->unproject_position(gt.xform(c->get_point_position(0))).distance_to(mbpos) < click_dist) + if (p_camera->unproject_position(gt.xform(c->get_point_position(0))).distance_to(mbpos) < click_dist) { return false; //nope, existing + } for (int i = 0; i < c->get_point_count() - 1; i++) { //find the offset and point index of the place to break up int j = idx; - if (p_camera->unproject_position(gt.xform(c->get_point_position(i + 1))).distance_to(mbpos) < click_dist) + if (p_camera->unproject_position(gt.xform(c->get_point_position(i + 1))).distance_to(mbpos) < click_dist) { return false; //nope, existing + } while (j < rc && c->get_point_position(i + 1) != r[j]) { - Vector3 from = r[j]; Vector3 to = r[j + 1]; real_t cdist = from.distance_to(to); @@ -349,7 +348,6 @@ bool Path3DEditorPlugin::forward_spatial_gui_input(Camera3D *p_camera, const Ref float d = inters.distance_to(mbpos); if (d < 10 && d < closest_d) { - closest_d = d; closest_seg = i; Vector3 ray_from = p_camera->project_ray_origin(mbpos); @@ -363,13 +361,15 @@ bool Path3DEditorPlugin::forward_spatial_gui_input(Camera3D *p_camera, const Ref } j++; } - if (idx == j) + if (idx == j) { idx++; //force next - else + } else { idx = j; //swap + } - if (j == rc) + if (j == rc) { break; + } } } @@ -384,19 +384,18 @@ bool Path3DEditorPlugin::forward_spatial_gui_input(Camera3D *p_camera, const Ref return true; } else { - Vector3 org; - if (c->get_point_count() == 0) + if (c->get_point_count() == 0) { org = path->get_transform().get_origin(); - else + } else { org = gt.xform(c->get_point_position(c->get_point_count() - 1)); + } Plane p(org, p_camera->get_transform().basis.get_axis(2)); Vector3 ray_from = p_camera->project_ray_origin(mbpos); Vector3 ray_dir = p_camera->project_ray_normal(mbpos); Vector3 inters; if (p.intersects_ray(ray_from, ray_dir, &inters)) { - ur->create_action(TTR("Add Point to Curve")); ur->add_do_method(c.ptr(), "add_point", it.xform(inters), Vector3(), Vector3(), -1); ur->add_undo_method(c.ptr(), "remove_point", c->get_point_count()); @@ -408,7 +407,6 @@ bool Path3DEditorPlugin::forward_spatial_gui_input(Camera3D *p_camera, const Ref } } else if (mb->is_pressed() && ((mb->get_button_index() == BUTTON_LEFT && curve_del->is_pressed()) || (mb->get_button_index() == BUTTON_RIGHT && curve_edit->is_pressed()))) { - for (int i = 0; i < c->get_point_count(); i++) { real_t dist_to_p = p_camera->unproject_position(gt.xform(c->get_point_position(i))).distance_to(mbpos); real_t dist_to_p_out = p_camera->unproject_position(gt.xform(c->get_point_position(i) + c->get_point_out(i))).distance_to(mbpos); @@ -417,7 +415,6 @@ bool Path3DEditorPlugin::forward_spatial_gui_input(Camera3D *p_camera, const Ref // Find the offset and point index of the place to break up. // Also check for the control points. if (dist_to_p < click_dist) { - UndoRedo *ur = editor->get_undo_redo(); ur->create_action(TTR("Remove Path Point")); ur->add_do_method(c.ptr(), "remove_point", i); @@ -425,7 +422,6 @@ bool Path3DEditorPlugin::forward_spatial_gui_input(Camera3D *p_camera, const Ref ur->commit_action(); return true; } else if (dist_to_p_out < click_dist) { - UndoRedo *ur = editor->get_undo_redo(); ur->create_action(TTR("Remove Out-Control Point")); ur->add_do_method(c.ptr(), "set_point_out", i, Vector3()); @@ -433,7 +429,6 @@ bool Path3DEditorPlugin::forward_spatial_gui_input(Camera3D *p_camera, const Ref ur->commit_action(); return true; } else if (dist_to_p_in < click_dist) { - UndoRedo *ur = editor->get_undo_redo(); ur->create_action(TTR("Remove In-Control Point")); ur->add_do_method(c.ptr(), "set_point_in", i, Vector3()); @@ -449,11 +444,9 @@ bool Path3DEditorPlugin::forward_spatial_gui_input(Camera3D *p_camera, const Ref } void Path3DEditorPlugin::edit(Object *p_object) { - if (p_object) { path = Object::cast_to<Path3D>(p_object); if (path) { - if (path->get_curve().is_valid()) { path->get_curve()->emit_signal("changed"); } @@ -469,14 +462,11 @@ void Path3DEditorPlugin::edit(Object *p_object) { } bool Path3DEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("Path3D"); } void Path3DEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { - curve_create->show(); curve_edit->show(); curve_del->show(); @@ -484,7 +474,6 @@ void Path3DEditorPlugin::make_visible(bool p_visible) { handle_menu->show(); sep->show(); } else { - curve_create->hide(); curve_edit->hide(); curve_del->hide(); @@ -503,24 +492,23 @@ void Path3DEditorPlugin::make_visible(bool p_visible) { } void Path3DEditorPlugin::_mode_changed(int p_idx) { - curve_create->set_pressed(p_idx == 0); curve_edit->set_pressed(p_idx == 1); curve_del->set_pressed(p_idx == 2); } void Path3DEditorPlugin::_close_curve() { - Ref<Curve3D> c = path->get_curve(); - if (c.is_null()) + if (c.is_null()) { return; - if (c->get_point_count() < 2) + } + if (c->get_point_count() < 2) { return; + } c->add_point(c->get_point_position(0), c->get_point_in(0), c->get_point_out(0)); } void Path3DEditorPlugin::_handle_option_pressed(int p_option) { - PopupMenu *pm; pm = handle_menu->get_popup(); @@ -540,9 +528,7 @@ void Path3DEditorPlugin::_handle_option_pressed(int p_option) { } void Path3DEditorPlugin::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { - curve_create->connect("pressed", callable_mp(this, &Path3DEditorPlugin::_mode_changed), make_binds(0)); curve_edit->connect("pressed", callable_mp(this, &Path3DEditorPlugin::_mode_changed), make_binds(1)); curve_del->connect("pressed", callable_mp(this, &Path3DEditorPlugin::_mode_changed), make_binds(2)); @@ -556,7 +542,6 @@ void Path3DEditorPlugin::_bind_methods() { Path3DEditorPlugin *Path3DEditorPlugin::singleton = nullptr; Path3DEditorPlugin::Path3DEditorPlugin(EditorNode *p_node) { - path = nullptr; editor = p_node; singleton = this; @@ -631,8 +616,9 @@ Ref<EditorNode3DGizmo> Path3DGizmoPlugin::create_gizmo(Node3D *p_spatial) { Ref<Path3DGizmo> ref; Path3D *path = Object::cast_to<Path3D>(p_spatial); - if (path) + if (path) { ref = Ref<Path3DGizmo>(memnew(Path3DGizmo(path))); + } return ref; } @@ -646,7 +632,6 @@ int Path3DGizmoPlugin::get_priority() const { } Path3DGizmoPlugin::Path3DGizmoPlugin() { - Color path_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/path", Color(0.5, 0.5, 1.0, 0.8)); create_material("path_material", path_color); create_material("path_thin_material", Color(0.5, 0.5, 0.5)); diff --git a/editor/plugins/path_3d_editor_plugin.h b/editor/plugins/path_3d_editor_plugin.h index 3f18cadacd..8bec5df797 100644 --- a/editor/plugins/path_3d_editor_plugin.h +++ b/editor/plugins/path_3d_editor_plugin.h @@ -35,7 +35,6 @@ #include "scene/3d/path_3d.h" class Path3DGizmo : public EditorNode3DGizmo { - GDCLASS(Path3DGizmo, EditorNode3DGizmo); Path3D *path; @@ -54,7 +53,6 @@ public: }; class Path3DGizmoPlugin : public EditorNode3DGizmoPlugin { - GDCLASS(Path3DGizmoPlugin, EditorNode3DGizmoPlugin); protected: @@ -67,7 +65,6 @@ public: }; class Path3DEditorPlugin : public EditorPlugin { - GDCLASS(Path3DEditorPlugin, EditorPlugin); Separator *sep; diff --git a/editor/plugins/physical_bone_3d_editor_plugin.cpp b/editor/plugins/physical_bone_3d_editor_plugin.cpp index 567d58922f..bcbf88e7dc 100644 --- a/editor/plugins/physical_bone_3d_editor_plugin.cpp +++ b/editor/plugins/physical_bone_3d_editor_plugin.cpp @@ -37,7 +37,6 @@ void PhysicalBone3DEditor::_bind_methods() { } void PhysicalBone3DEditor::_on_toggle_button_transform_joint(bool p_is_pressed) { - _set_move_joint(); } @@ -49,7 +48,6 @@ void PhysicalBone3DEditor::_set_move_joint() { PhysicalBone3DEditor::PhysicalBone3DEditor(EditorNode *p_editor) : editor(p_editor) { - spatial_editor_hb = memnew(HBoxContainer); spatial_editor_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL); spatial_editor_hb->set_alignment(BoxContainer::ALIGN_BEGIN); @@ -69,7 +67,6 @@ PhysicalBone3DEditor::PhysicalBone3DEditor(EditorNode *p_editor) : } void PhysicalBone3DEditor::set_selected(PhysicalBone3D *p_pb) { - button_transform_joint->set_pressed(false); _set_move_joint(); @@ -91,10 +88,8 @@ PhysicalBone3DEditorPlugin::PhysicalBone3DEditorPlugin(EditorNode *p_editor) : void PhysicalBone3DEditorPlugin::make_visible(bool p_visible) { if (p_visible) { - physical_bone_editor.show(); } else { - physical_bone_editor.hide(); physical_bone_editor.set_selected(nullptr); selected = nullptr; diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp index e15d8556e4..7ee695b9fe 100644 --- a/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/editor/plugins/polygon_2d_editor_plugin.cpp @@ -39,23 +39,19 @@ #include "scene/2d/skeleton_2d.h" Node2D *Polygon2DEditor::_get_node() const { - return node; } void Polygon2DEditor::_set_node(Node *p_polygon) { - node = Object::cast_to<Polygon2D>(p_polygon); _update_polygon_editing_state(); } Vector2 Polygon2DEditor::_get_offset(int p_idx) const { - return node->get_offset(); } int Polygon2DEditor::_get_polygon_count() const { - if (node->get_internal_vertex_count() > 0) { return 0; //do not edit if internal vertices exist } else { @@ -64,17 +60,13 @@ int Polygon2DEditor::_get_polygon_count() const { } void Polygon2DEditor::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { - uv_edit_draw->add_theme_style_override("panel", get_theme_stylebox("bg", "Tree")); bone_scroll->add_theme_style_override("bg", get_theme_stylebox("bg", "Tree")); } break; case NOTIFICATION_READY: { - button_uv->set_icon(get_theme_icon("Uv", "EditorIcons")); uv_button[UV_MODE_CREATE]->set_icon(get_theme_icon("Edit", "EditorIcons")); @@ -97,7 +89,6 @@ void Polygon2DEditor::_notification(int p_what) { uv_hscroll->set_anchors_and_margins_preset(PRESET_BOTTOM_WIDE); } break; case NOTIFICATION_VISIBILITY_CHANGED: { - if (!is_visible()) { uv_edit->hide(); } @@ -106,7 +97,6 @@ void Polygon2DEditor::_notification(int p_what) { } void Polygon2DEditor::_sync_bones() { - Skeleton2D *skeleton = nullptr; if (!node->has_node(node->get_skeleton())) { error->set_text(TTR("The skeleton property of the Polygon2D does not point to a Skeleton2D node")); @@ -161,7 +151,6 @@ void Polygon2DEditor::_sync_bones() { } void Polygon2DEditor::_update_bone_list() { - NodePath selected; while (bone_scroll_vb->get_child_count()) { CheckBox *cb = Object::cast_to<CheckBox>(bone_scroll_vb->get_child(0)); @@ -189,8 +178,9 @@ void Polygon2DEditor::_update_bone_list() { cb->set_focus_mode(FOCUS_NONE); bone_scroll_vb->add_child(cb); - if (np == selected || bone_scroll_vb->get_child_count() < 2) + if (np == selected || bone_scroll_vb->get_child_count() < 2) { cb->set_pressed(true); + } cb->connect("pressed", callable_mp(this, &Polygon2DEditor::_bone_paint_selected), varray(i)); } @@ -203,7 +193,6 @@ void Polygon2DEditor::_bone_paint_selected(int p_index) { } void Polygon2DEditor::_uv_edit_mode_select(int p_mode) { - if (p_mode == 0) { //uv uv_button[UV_MODE_CREATE]->hide(); @@ -274,20 +263,15 @@ void Polygon2DEditor::_uv_edit_mode_select(int p_mode) { } void Polygon2DEditor::_uv_edit_popup_hide() { - EditorSettings::get_singleton()->set("interface/dialogs/uv_editor_bounds", Rect2(uv_edit->get_position(), uv_edit->get_size())); _cancel_editing(); } void Polygon2DEditor::_menu_option(int p_option) { - switch (p_option) { - case MODE_EDIT_UV: { - if (node->get_texture().is_null()) { - error->set_text(TTR("No texture in this polygon.\nSet a texture to be able to edit UV.")); error->popup_centered(); return; @@ -304,17 +288,18 @@ void Polygon2DEditor::_menu_option(int p_option) { undo_redo->commit_action(); } - if (EditorSettings::get_singleton()->has_setting("interface/dialogs/uv_editor_bounds")) + if (EditorSettings::get_singleton()->has_setting("interface/dialogs/uv_editor_bounds")) { uv_edit->popup(EditorSettings::get_singleton()->get("interface/dialogs/uv_editor_bounds")); - else + } else { uv_edit->popup_centered_ratio(0.85); + } _update_bone_list(); } break; case UVEDIT_POLYGON_TO_UV: { - Vector<Vector2> points = node->get_polygon(); - if (points.size() == 0) + if (points.size() == 0) { break; + } Vector<Vector2> uvs = node->get_uv(); undo_redo->create_action(TTR("Create UV Map")); undo_redo->add_do_method(node, "set_uv", points); @@ -324,11 +309,11 @@ void Polygon2DEditor::_menu_option(int p_option) { undo_redo->commit_action(); } break; case UVEDIT_UV_TO_POLYGON: { - Vector<Vector2> points = node->get_polygon(); Vector<Vector2> uvs = node->get_uv(); - if (uvs.size() == 0) + if (uvs.size() == 0) { break; + } undo_redo->create_action(TTR("Create Polygon")); undo_redo->add_do_method(node, "set_polygon", uvs); @@ -338,10 +323,10 @@ void Polygon2DEditor::_menu_option(int p_option) { undo_redo->commit_action(); } break; case UVEDIT_UV_CLEAR: { - Vector<Vector2> uvs = node->get_uv(); - if (uvs.size() == 0) + if (uvs.size() == 0) { break; + } undo_redo->create_action(TTR("Create UV Map")); undo_redo->add_do_method(node, "set_uv", Vector<Vector2>()); undo_redo->add_undo_method(node, "set_uv", uvs); @@ -350,18 +335,15 @@ void Polygon2DEditor::_menu_option(int p_option) { undo_redo->commit_action(); } break; case UVEDIT_GRID_SETTINGS: { - grid_settings->popup_centered(); } break; default: { - AbstractPolygon2DEditor::_menu_option(p_option); } break; } } void Polygon2DEditor::_cancel_editing() { - if (uv_create) { uv_drag = false; uv_create = false; @@ -386,18 +368,18 @@ void Polygon2DEditor::_cancel_editing() { } void Polygon2DEditor::_update_polygon_editing_state() { - - if (!_get_node()) + if (!_get_node()) { return; + } - if (node->get_internal_vertex_count() > 0) + if (node->get_internal_vertex_count() > 0) { disable_polygon_editing(true, TTR("Polygon 2D has internal vertices, so it can no longer be edited in the viewport.")); - else + } else { disable_polygon_editing(false, String()); + } } void Polygon2DEditor::_commit_action() { - // Makes that undo/redoing actions made outside of the UV editor still affect its polygon. undo_redo->add_do_method(uv_edit_draw, "update"); undo_redo->add_undo_method(uv_edit_draw, "update"); @@ -442,7 +424,6 @@ void Polygon2DEditor::_set_snap_step_y(float p_val) { } void Polygon2DEditor::_uv_mode(int p_mode) { - polygon_create.clear(); uv_drag = false; uv_create = false; @@ -454,9 +435,9 @@ void Polygon2DEditor::_uv_mode(int p_mode) { } void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { - - if (!_get_node()) + if (!_get_node()) { return; + } Transform2D mtx; mtx.elements[2] = -uv_draw_ofs; @@ -465,11 +446,8 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { Ref<InputEventMouseButton> mb = p_input; if (mb.is_valid()) { - if (mb->get_button_index() == BUTTON_LEFT) { - if (mb->is_pressed()) { - uv_drag_from = snap_point(Vector2(mb->get_position().x, mb->get_position().y)); uv_drag = true; points_prev = node->get_uv(); @@ -482,9 +460,7 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { uv_move_current = uv_mode; if (uv_move_current == UV_MODE_CREATE) { - if (!uv_create) { - points_prev.resize(0); Vector2 tuv = mtx.affine_inverse().xform(snap_point(Vector2(mb->get_position().x, mb->get_position().y))); points_prev.push_back(tuv); @@ -506,7 +482,6 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { uv_edit_draw->update(); } else { - Vector2 tuv = mtx.affine_inverse().xform(snap_point(Vector2(mb->get_position().x, mb->get_position().y))); if (points_prev.size() > 2 && tuv.distance_to(points_prev[0]) < 8) { @@ -544,7 +519,6 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { } if (uv_move_current == UV_MODE_CREATE_INTERNAL) { - uv_create_uv_prev = node->get_uv(); uv_create_poly_prev = node->get_polygon(); uv_create_colors_prev = node->get_vertex_colors(); @@ -582,21 +556,20 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { } if (uv_move_current == UV_MODE_REMOVE_INTERNAL) { - uv_create_uv_prev = node->get_uv(); uv_create_poly_prev = node->get_polygon(); uv_create_colors_prev = node->get_vertex_colors(); uv_create_bones_prev = node->call("_get_bones"); int internal_vertices = node->get_internal_vertex_count(); - if (internal_vertices <= 0) + if (internal_vertices <= 0) { return; + } int closest = -1; float closest_dist = 1e20; for (int i = points_prev.size() - internal_vertices; i < points_prev.size(); i++) { - Vector2 tuv = mtx.xform(uv_create_poly_prev[i]); float dist = tuv.distance_to(Vector2(mb->get_position().x, mb->get_position().y)); if (dist < 8 && dist < closest_dist) { @@ -605,8 +578,9 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { } } - if (closest == -1) + if (closest == -1) { return; + } uv_create_poly_prev.remove(closest); uv_create_uv_prev.remove(closest); @@ -637,20 +611,18 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { } if (uv_move_current == UV_MODE_EDIT_POINT) { - - if (mb->get_shift() && mb->get_command()) + if (mb->get_shift() && mb->get_command()) { uv_move_current = UV_MODE_SCALE; - else if (mb->get_shift()) + } else if (mb->get_shift()) { uv_move_current = UV_MODE_MOVE; - else if (mb->get_command()) + } else if (mb->get_command()) { uv_move_current = UV_MODE_ROTATE; + } } if (uv_move_current == UV_MODE_EDIT_POINT) { - point_drag_index = -1; for (int i = 0; i < points_prev.size(); i++) { - Vector2 tuv = mtx.xform(points_prev[i]); if (tuv.distance_to(Vector2(mb->get_position().x, mb->get_position().y)) < 8) { uv_drag_from = tuv; @@ -664,12 +636,10 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { } if (uv_move_current == UV_MODE_ADD_POLYGON) { - int closest = -1; float closest_dist = 1e20; for (int i = 0; i < points_prev.size(); i++) { - Vector2 tuv = mtx.xform(points_prev[i]); float dist = tuv.distance_to(Vector2(mb->get_position().x, mb->get_position().y)); if (dist < 8 && dist < closest_dist) { @@ -717,8 +687,9 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { polys.resize(points.size()); for (int j = 0; j < polys.size(); j++) { int idx = points[j]; - if (idx < 0 || idx >= points_prev.size()) + if (idx < 0 || idx >= points_prev.size()) { continue; + } polys.write[j] = mtx.xform(points_prev[idx]); } @@ -740,7 +711,6 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { } if (uv_move_current == UV_MODE_PAINT_WEIGHT || uv_move_current == UV_MODE_CLEAR_WEIGHT) { - int bone_selected = -1; for (int i = 0; i < bone_scroll_vb->get_child_count(); i++) { CheckBox *c = Object::cast_to<CheckBox>(bone_scroll_vb->get_child(i)); @@ -751,7 +721,6 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { } if (bone_selected != -1 && node->get_bone_weights(bone_selected).size() == points_prev.size()) { - prev_weights = node->get_bone_weights(bone_selected); bone_painting = true; bone_painting_bone = bone_selected; @@ -759,7 +728,6 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { } } else if (uv_drag && !uv_create) { - if (uv_edit_mode[0]->is_pressed()) { // Edit UV. undo_redo->create_action(TTR("Transform UV Map")); undo_redo->add_do_method(node, "set_uv", node->get_uv()); @@ -778,7 +746,6 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { uv_drag = false; } else if (bone_painting) { - undo_redo->create_action(TTR("Paint Bone Weights")); undo_redo->add_do_method(node, "set_bone_weights", bone_painting_bone, node->get_bone_weights(bone_painting_bone)); undo_redo->add_undo_method(node, "set_bone_weights", bone_painting_bone, prev_weights); @@ -789,19 +756,17 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { } } else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) { - _cancel_editing(); - if (bone_painting) + if (bone_painting) { node->set_bone_weights(bone_painting_bone, prev_weights); + } uv_edit_draw->update(); } else if (mb->get_button_index() == BUTTON_WHEEL_UP && mb->is_pressed()) { - uv_zoom->set_value(uv_zoom->get_value() / (1 - (0.1 * mb->get_factor()))); } else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && mb->is_pressed()) { - uv_zoom->set_value(uv_zoom->get_value() * (1 - (0.1 * mb->get_factor()))); } } @@ -809,29 +774,23 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { Ref<InputEventMouseMotion> mm = p_input; if (mm.is_valid()) { - if ((mm->get_button_mask() & BUTTON_MASK_MIDDLE) || Input::get_singleton()->is_key_pressed(KEY_SPACE)) { - Vector2 drag(mm->get_relative().x, mm->get_relative().y); uv_hscroll->set_value(uv_hscroll->get_value() - drag.x); uv_vscroll->set_value(uv_vscroll->get_value() - drag.y); } else if (uv_drag) { - Vector2 uv_drag_to = mm->get_position(); uv_drag_to = snap_point(uv_drag_to); // FIXME: Only works correctly with 'UV_MODE_EDIT_POINT', it's imprecise with the rest. Vector2 drag = mtx.affine_inverse().xform(uv_drag_to) - mtx.affine_inverse().xform(uv_drag_from); switch (uv_move_current) { - case UV_MODE_CREATE: { - if (uv_create) { uv_create_to = mtx.affine_inverse().xform(snap_point(Vector2(mm->get_position().x, mm->get_position().y))); } } break; case UV_MODE_EDIT_POINT: { - Vector<Vector2> uv_new = points_prev; uv_new.set(point_drag_index, uv_new[point_drag_index] + drag); @@ -842,10 +801,10 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { } } break; case UV_MODE_MOVE: { - Vector<Vector2> uv_new = points_prev; - for (int i = 0; i < uv_new.size(); i++) + for (int i = 0; i < uv_new.size(); i++) { uv_new.set(i, uv_new[i] + drag); + } if (uv_edit_mode[0]->is_pressed()) { //edit uv node->set_uv(uv_new); @@ -854,12 +813,12 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { } } break; case UV_MODE_ROTATE: { - Vector2 center; Vector<Vector2> uv_new = points_prev; - for (int i = 0; i < uv_new.size(); i++) + for (int i = 0; i < uv_new.size(); i++) { center += points_prev[i]; + } center /= uv_new.size(); float angle = (uv_drag_from - mtx.xform(center)).normalized().angle_to((uv_drag_to - mtx.xform(center)).normalized()); @@ -877,18 +836,19 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { } } break; case UV_MODE_SCALE: { - Vector2 center; Vector<Vector2> uv_new = points_prev; - for (int i = 0; i < uv_new.size(); i++) + for (int i = 0; i < uv_new.size(); i++) { center += points_prev[i]; + } center /= uv_new.size(); float from_dist = uv_drag_from.distance_to(mtx.xform(center)); float to_dist = uv_drag_to.distance_to(mtx.xform(center)); - if (from_dist < 2) + if (from_dist < 2) { break; + } float scale = to_dist / from_dist; @@ -906,7 +866,6 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { } break; case UV_MODE_PAINT_WEIGHT: case UV_MODE_CLEAR_WEIGHT: { - bone_paint_pos = Vector2(mm->get_position().x, mm->get_position().y); } break; default: { @@ -952,22 +911,20 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { Ref<InputEventMagnifyGesture> magnify_gesture = p_input; if (magnify_gesture.is_valid()) { - uv_zoom->set_value(uv_zoom->get_value() * magnify_gesture->get_factor()); } Ref<InputEventPanGesture> pan_gesture = p_input; if (pan_gesture.is_valid()) { - uv_hscroll->set_value(uv_hscroll->get_value() + uv_hscroll->get_page() * pan_gesture->get_delta().x / 8); uv_vscroll->set_value(uv_vscroll->get_value() + uv_vscroll->get_page() * pan_gesture->get_delta().y / 8); } } void Polygon2DEditor::_uv_scroll_changed(float) { - - if (updating_uv_scroll) + if (updating_uv_scroll) { return; + } uv_draw_ofs.x = uv_hscroll->get_value(); uv_draw_ofs.y = uv_vscroll->get_value(); @@ -976,13 +933,14 @@ void Polygon2DEditor::_uv_scroll_changed(float) { } void Polygon2DEditor::_uv_draw() { - - if (!uv_edit->is_visible() || !_get_node()) + if (!uv_edit->is_visible() || !_get_node()) { return; + } Ref<Texture2D> base_tex = node->get_texture(); - if (base_tex.is_null()) + if (base_tex.is_null()) { return; + } String warning; @@ -1002,10 +960,12 @@ void Polygon2DEditor::_uv_draw() { if (snap_step.x != 0) { for (int i = 0; i < s.width; i++) { int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(i, 0)).x - snap_offset.x) / snap_step.x)); - if (i == 0) + if (i == 0) { last_cell = cell; - if (last_cell != cell) + } + if (last_cell != cell) { uv_edit_draw->draw_line(Point2(i, 0), Point2(i, s.height), grid_color, Math::round(EDSCALE)); + } last_cell = cell; } } @@ -1013,10 +973,12 @@ void Polygon2DEditor::_uv_draw() { if (snap_step.y != 0) { for (int i = 0; i < s.height; i++) { int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(0, i)).y - snap_offset.y) / snap_step.y)); - if (i == 0) + if (i == 0) { last_cell = cell; - if (last_cell != cell) + } + if (last_cell != cell) { uv_edit_draw->draw_line(Point2(0, i), Point2(s.width, i), grid_color, Math::round(EDSCALE)); + } last_cell = cell; } } @@ -1073,7 +1035,6 @@ void Polygon2DEditor::_uv_draw() { } for (int i = 0; i < uvs.size(); i++) { - int next = uv_draw_max > 0 ? (i + 1) % uv_draw_max : 0; if (i < uv_draw_max && uv_drag && uv_move_current == UV_MODE_EDIT_POINT && EDITOR_DEF("editors/poly_editor/show_previous_outline", true)) { @@ -1092,7 +1053,6 @@ void Polygon2DEditor::_uv_draw() { } for (int i = 0; i < polygons.size(); i++) { - Vector<int> points = polygons[i]; Vector<Vector2> polypoints; for (int j = 0; j < points.size(); j++) { @@ -1100,12 +1060,14 @@ void Polygon2DEditor::_uv_draw() { int idx = points[j]; int idx_next = points[next]; - if (idx < 0 || idx >= uvs.size()) + if (idx < 0 || idx >= uvs.size()) { continue; + } polypoints.push_back(mtx.xform(uvs[idx])); - if (idx_next < 0 || idx_next >= uvs.size()) + if (idx_next < 0 || idx_next >= uvs.size()) { continue; + } uv_edit_draw->draw_line(mtx.xform(uvs[idx]), mtx.xform(uvs[idx_next]), polygon_line_color, Math::round(EDSCALE)); } if (points.size() >= 3) { @@ -1114,7 +1076,6 @@ void Polygon2DEditor::_uv_draw() { } for (int i = 0; i < uvs.size(); i++) { - if (weight_r) { Vector2 draw_pos = mtx.xform(uvs[i]); float weight = weight_r[i]; @@ -1138,7 +1099,6 @@ void Polygon2DEditor::_uv_draw() { } if (uv_mode == UV_MODE_PAINT_WEIGHT || uv_mode == UV_MODE_CLEAR_WEIGHT) { - NodePath bone_path; for (int i = 0; i < bone_scroll_vb->get_child_count(); i++) { CheckBox *c = Object::cast_to<CheckBox>(bone_scroll_vb->get_child(i)); @@ -1154,20 +1114,20 @@ void Polygon2DEditor::_uv_draw() { Skeleton2D *skeleton = Object::cast_to<Skeleton2D>(node->get_node(skeleton_path)); if (skeleton) { for (int i = 0; i < skeleton->get_bone_count(); i++) { - Bone2D *bone = skeleton->get_bone(i); - if (bone->get_rest() == Transform2D(0, 0, 0, 0, 0, 0)) + if (bone->get_rest() == Transform2D(0, 0, 0, 0, 0, 0)) { continue; //not set + } bool current = bone_path == skeleton->get_path_to(bone); bool found_child = false; for (int j = 0; j < bone->get_child_count(); j++) { - Bone2D *n = Object::cast_to<Bone2D>(bone->get_child(j)); - if (!n) + if (!n) { continue; + } found_child = true; @@ -1232,7 +1192,6 @@ void Polygon2DEditor::_uv_draw() { } void Polygon2DEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_update_bone_list"), &Polygon2DEditor::_update_bone_list); ClassDB::bind_method(D_METHOD("_update_polygon_editing_state"), &Polygon2DEditor::_update_polygon_editing_state); } @@ -1248,7 +1207,6 @@ Vector2 Polygon2DEditor::snap_point(Vector2 p_target) const { Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) : AbstractPolygon2DEditor(p_editor) { - node = nullptr; snap_offset = EditorSettings::get_singleton()->get_project_metadata("polygon_2d_uv_editor", "snap_offset", Vector2()); snap_step = EditorSettings::get_singleton()->get_project_metadata("polygon_2d_uv_editor", "snap_step", Vector2(10, 10)); @@ -1305,7 +1263,6 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) : uv_main_vb->add_child(uv_mode_hb); for (int i = 0; i < UV_MODE_MAX; i++) { - uv_button[i] = memnew(ToolButton); uv_button[i]->set_toggle_mode(true); uv_mode_hb->add_child(uv_button[i]); diff --git a/editor/plugins/polygon_2d_editor_plugin.h b/editor/plugins/polygon_2d_editor_plugin.h index 2b00b50e5c..b94ae53e2b 100644 --- a/editor/plugins/polygon_2d_editor_plugin.h +++ b/editor/plugins/polygon_2d_editor_plugin.h @@ -35,7 +35,6 @@ #include "scene/gui/scroll_container.h" class Polygon2DEditor : public AbstractPolygon2DEditor { - GDCLASS(Polygon2DEditor, AbstractPolygon2DEditor); enum Mode { @@ -165,7 +164,6 @@ public: }; class Polygon2DEditorPlugin : public AbstractPolygon2DEditorPlugin { - GDCLASS(Polygon2DEditorPlugin, AbstractPolygon2DEditorPlugin); public: diff --git a/editor/plugins/resource_preloader_editor_plugin.cpp b/editor/plugins/resource_preloader_editor_plugin.cpp index 852feeb675..75cb93ee76 100644 --- a/editor/plugins/resource_preloader_editor_plugin.cpp +++ b/editor/plugins/resource_preloader_editor_plugin.cpp @@ -39,13 +39,11 @@ void ResourcePreloaderEditor::_gui_input(Ref<InputEvent> p_event) { } void ResourcePreloaderEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { load->set_icon(get_theme_icon("Folder", "EditorIcons")); } if (p_what == NOTIFICATION_READY) { - //NodePath("/root")->connect("node_removed", this,"_node_removed",Vector<Variant>(),true); } @@ -54,9 +52,7 @@ void ResourcePreloaderEditor::_notification(int p_what) { } void ResourcePreloaderEditor::_files_load_request(const Vector<String> &p_paths) { - for (int i = 0; i < p_paths.size(); i++) { - String path = p_paths[i]; RES resource; @@ -89,14 +85,14 @@ void ResourcePreloaderEditor::_files_load_request(const Vector<String> &p_paths) } void ResourcePreloaderEditor::_load_pressed() { - loading_scene = false; file->clear_filters(); List<String> extensions; ResourceLoader::get_recognized_extensions_for_type("", &extensions); - for (int i = 0; i < extensions.size(); i++) + for (int i = 0; i < extensions.size(); i++) { file->add_filter("*." + extensions[i]); + } file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILES); @@ -104,9 +100,9 @@ void ResourcePreloaderEditor::_load_pressed() { } void ResourcePreloaderEditor::_item_edited() { - - if (!tree->get_selected()) + if (!tree->get_selected()) { return; + } TreeItem *s = tree->get_selected(); @@ -114,11 +110,11 @@ void ResourcePreloaderEditor::_item_edited() { // renamed String old_name = s->get_metadata(0); String new_name = s->get_text(0); - if (old_name == new_name) + if (old_name == new_name) { return; + } if (new_name == "" || new_name.find("\\") != -1 || new_name.find("/") != -1 || preloader->has_resource(new_name)) { - s->set_text(0, old_name); return; } @@ -136,7 +132,6 @@ void ResourcePreloaderEditor::_item_edited() { } void ResourcePreloaderEditor::_remove_resource(const String &p_to_remove) { - undo_redo->create_action(TTR("Delete Resource")); undo_redo->add_do_method(preloader, "remove_resource", p_to_remove); undo_redo->add_undo_method(preloader, "add_resource", p_to_remove, preloader->get_resource(p_to_remove)); @@ -146,7 +141,6 @@ void ResourcePreloaderEditor::_remove_resource(const String &p_to_remove) { } void ResourcePreloaderEditor::_paste_pressed() { - RES r = EditorSettings::get_singleton()->get_resource_clipboard(); if (!r.is_valid()) { dialog->set_text(TTR("Resource clipboard is empty!")); @@ -157,10 +151,12 @@ void ResourcePreloaderEditor::_paste_pressed() { } String name = r->get_name(); - if (name == "") + if (name == "") { name = r->get_path().get_file(); - if (name == "") + } + if (name == "") { name = r->get_class(); + } String basename = name; int counter = 1; @@ -178,7 +174,6 @@ void ResourcePreloaderEditor::_paste_pressed() { } void ResourcePreloaderEditor::_update_library() { - tree->clear(); tree->set_hide_root(true); TreeItem *root = tree->create_item(nullptr); @@ -194,7 +189,6 @@ void ResourcePreloaderEditor::_update_library() { names.sort(); for (List<String>::Element *E = names.front(); E; E = E->next()) { - TreeItem *ti = tree->create_item(root); ti->set_cell_mode(0, TreeItem::CELL_MODE_STRING); ti->set_editable(0, true); @@ -226,7 +220,6 @@ void ResourcePreloaderEditor::_update_library() { } void ResourcePreloaderEditor::_cell_button_pressed(Object *p_item, int p_column, int p_id) { - TreeItem *item = Object::cast_to<TreeItem>(p_item); ERR_FAIL_COND(!item); @@ -244,42 +237,42 @@ void ResourcePreloaderEditor::_cell_button_pressed(Object *p_item, int p_column, } void ResourcePreloaderEditor::edit(ResourcePreloader *p_preloader) { - preloader = p_preloader; if (p_preloader) { _update_library(); } else { - hide(); set_physics_process(false); } } Variant ResourcePreloaderEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) { - TreeItem *ti = tree->get_item_at_position(p_point); - if (!ti) + if (!ti) { return Variant(); + } String name = ti->get_metadata(0); RES res = preloader->get_resource(name); - if (!res.is_valid()) + if (!res.is_valid()) { return Variant(); + } return EditorNode::get_singleton()->drag_resource(res, p_from); } bool ResourcePreloaderEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { - Dictionary d = p_data; - if (!d.has("type")) + if (!d.has("type")) { return false; + } - if (d.has("from") && (Object *)(d["from"]) == tree) + if (d.has("from") && (Object *)(d["from"]) == tree) { return false; + } if (String(d["type"]) == "resource" && d.has("resource")) { RES r = d["resource"]; @@ -288,7 +281,6 @@ bool ResourcePreloaderEditor::can_drop_data_fw(const Point2 &p_point, const Vari } if (String(d["type"]) == "files") { - Vector<String> files = d["files"]; return files.size() != 0; @@ -297,20 +289,20 @@ bool ResourcePreloaderEditor::can_drop_data_fw(const Point2 &p_point, const Vari } void ResourcePreloaderEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { - - if (!can_drop_data_fw(p_point, p_data, p_from)) + if (!can_drop_data_fw(p_point, p_data, p_from)) { return; + } Dictionary d = p_data; - if (!d.has("type")) + if (!d.has("type")) { return; + } if (String(d["type"]) == "resource" && d.has("resource")) { RES r = d["resource"]; if (r.is_valid()) { - String basename; if (r->get_name() != "") { basename = r->get_name(); @@ -337,7 +329,6 @@ void ResourcePreloaderEditor::drop_data_fw(const Point2 &p_point, const Variant } if (String(d["type"]) == "files") { - Vector<String> files = d["files"]; _files_load_request(files); @@ -345,7 +336,6 @@ void ResourcePreloaderEditor::drop_data_fw(const Point2 &p_point, const Variant } void ResourcePreloaderEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_gui_input"), &ResourcePreloaderEditor::_gui_input); ClassDB::bind_method(D_METHOD("_update_library"), &ResourcePreloaderEditor::_update_library); ClassDB::bind_method(D_METHOD("_remove_resource", "to_remove"), &ResourcePreloaderEditor::_remove_resource); @@ -356,7 +346,6 @@ void ResourcePreloaderEditor::_bind_methods() { } ResourcePreloaderEditor::ResourcePreloaderEditor() { - //add_style_override("panel", EditorNode::get_singleton()->get_gui_base()->get_stylebox("panel","Panel")); VBoxContainer *vbc = memnew(VBoxContainer); @@ -399,31 +388,29 @@ ResourcePreloaderEditor::ResourcePreloaderEditor() { } void ResourcePreloaderEditorPlugin::edit(Object *p_object) { - preloader_editor->set_undo_redo(&get_undo_redo()); ResourcePreloader *s = Object::cast_to<ResourcePreloader>(p_object); - if (!s) + if (!s) { return; + } preloader_editor->edit(s); } bool ResourcePreloaderEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("ResourcePreloader"); } void ResourcePreloaderEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { //preloader_editor->show(); button->show(); editor->make_bottom_panel_item_visible(preloader_editor); //preloader_editor->set_process(true); } else { - - if (preloader_editor->is_visible_in_tree()) + if (preloader_editor->is_visible_in_tree()) { editor->hide_bottom_panel(); + } button->hide(); //preloader_editor->hide(); //preloader_editor->set_process(false); @@ -431,7 +418,6 @@ void ResourcePreloaderEditorPlugin::make_visible(bool p_visible) { } ResourcePreloaderEditorPlugin::ResourcePreloaderEditorPlugin(EditorNode *p_node) { - editor = p_node; preloader_editor = memnew(ResourcePreloaderEditor); preloader_editor->set_custom_minimum_size(Size2(0, 250) * EDSCALE); diff --git a/editor/plugins/resource_preloader_editor_plugin.h b/editor/plugins/resource_preloader_editor_plugin.h index 88e9cf4956..2d7a54eda5 100644 --- a/editor/plugins/resource_preloader_editor_plugin.h +++ b/editor/plugins/resource_preloader_editor_plugin.h @@ -39,7 +39,6 @@ #include "scene/main/resource_preloader.h" class ResourcePreloaderEditor : public PanelContainer { - GDCLASS(ResourcePreloaderEditor, PanelContainer); enum { @@ -87,7 +86,6 @@ public: }; class ResourcePreloaderEditorPlugin : public EditorPlugin { - GDCLASS(ResourcePreloaderEditorPlugin, EditorPlugin); ResourcePreloaderEditor *preloader_editor; diff --git a/editor/plugins/root_motion_editor_plugin.cpp b/editor/plugins/root_motion_editor_plugin.cpp index a7120c5d68..e107435373 100644 --- a/editor/plugins/root_motion_editor_plugin.cpp +++ b/editor/plugins/root_motion_editor_plugin.cpp @@ -33,10 +33,10 @@ #include "scene/main/window.h" void EditorPropertyRootMotion::_confirmed() { - TreeItem *ti = filters->get_selected(); - if (!ti) + if (!ti) { return; + } NodePath path = ti->get_metadata(0); emit_changed(get_edited_property(), path); @@ -45,7 +45,6 @@ void EditorPropertyRootMotion::_confirmed() { } void EditorPropertyRootMotion::_node_assign() { - NodePath current = get_edited_object()->get(get_edited_property()); AnimationTree *atree = Object::cast_to<AnimationTree>(get_edited_object()); @@ -72,7 +71,6 @@ void EditorPropertyRootMotion::_node_assign() { player->get_animation_list(&animations); for (List<StringName>::Element *E = animations.front(); E; E = E->next()) { - Ref<Animation> anim = player->get_animation(E->get()); for (int i = 0; i < anim->get_track_count(); i++) { paths.insert(anim->track_get_path(i)); @@ -86,7 +84,6 @@ void EditorPropertyRootMotion::_node_assign() { Map<String, TreeItem *> parenthood; for (Set<String>::Element *E = paths.front(); E; E = E->next()) { - NodePath path = E->get(); TreeItem *ti = nullptr; String accum; @@ -121,11 +118,11 @@ void EditorPropertyRootMotion::_node_assign() { if (base->has_node(accum)) { node = base->get_node(accum); } - if (!node) + if (!node) { continue; //no node, can't edit + } if (path.get_subname_count()) { - String concat = path.get_concatenated_subnames(); Skeleton3D *skeleton = Object::cast_to<Skeleton3D>(node); @@ -194,13 +191,11 @@ void EditorPropertyRootMotion::_node_assign() { } void EditorPropertyRootMotion::_node_clear() { - emit_changed(get_edited_property(), NodePath()); update_property(); } void EditorPropertyRootMotion::update_property() { - NodePath p = get_edited_object()->get(get_edited_property()); assign->set_tooltip(p); @@ -235,12 +230,10 @@ void EditorPropertyRootMotion::update_property() { } void EditorPropertyRootMotion::setup(const NodePath &p_base_hint) { - base_hint = 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("Clear", "EditorIcons"); clear->set_icon(t); @@ -251,7 +244,6 @@ void EditorPropertyRootMotion::_bind_methods() { } EditorPropertyRootMotion::EditorPropertyRootMotion() { - HBoxContainer *hbc = memnew(HBoxContainer); add_child(hbc); assign = memnew(Button); @@ -278,6 +270,7 @@ EditorPropertyRootMotion::EditorPropertyRootMotion() { filters->connect("item_activated", callable_mp(this, &EditorPropertyRootMotion::_confirmed)); //filters->connect("item_edited", this, "_filter_edited"); } + ////////////////////////// bool EditorInspectorRootMotionPlugin::can_handle(Object *p_object) { @@ -289,7 +282,6 @@ void EditorInspectorRootMotionPlugin::parse_begin(Object *p_object) { } bool EditorInspectorRootMotionPlugin::parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide) { - if (p_path == "root_motion_track" && p_object->is_class("AnimationTree") && p_type == Variant::NODE_PATH) { EditorPropertyRootMotion *editor = memnew(EditorPropertyRootMotion); if (p_hint == PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE && p_hint_text != String()) { diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index e6d3f17f12..8d6dac3907 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -54,7 +54,6 @@ /*** SCRIPT EDITOR ****/ void ScriptEditorBase::_bind_methods() { - ADD_SIGNAL(MethodInfo("name_changed")); ADD_SIGNAL(MethodInfo("edited_script_changed")); ADD_SIGNAL(MethodInfo("request_help", PropertyInfo(Variant::STRING, "topic"))); @@ -73,7 +72,6 @@ static bool _is_built_in_script(Script *p_script) { } class EditorScriptCodeCompletionCache : public ScriptCodeCompletionCache { - struct Cache { uint64_t time_loaded; RES cache; @@ -86,7 +84,6 @@ public: int max_cache_size; void cleanup() { - List<Map<String, Cache>::Element *> to_clean; Map<String, Cache>::Element *I = cached.front(); @@ -104,10 +101,8 @@ public: } virtual RES get_cached_resource(const String &p_path) { - Map<String, Cache>::Element *E = cached.find(p_path); if (!E) { - Cache c; c.cache = ResourceLoader::load(p_path); E = cached.insert(p_path, c); @@ -137,7 +132,6 @@ public: } EditorScriptCodeCompletionCache() { - max_cache_size = 128; max_time_cache = 5 * 60 * 1000; //minutes, five } @@ -146,50 +140,45 @@ public: }; void ScriptEditorQuickOpen::popup_dialog(const Vector<String> &p_functions, bool p_dontclear) { - popup_centered_ratio(0.6); - if (p_dontclear) + if (p_dontclear) { search_box->select_all(); - else + } else { search_box->clear(); + } search_box->grab_focus(); functions = p_functions; _update_search(); } void ScriptEditorQuickOpen::_text_changed(const String &p_newtext) { - _update_search(); } void ScriptEditorQuickOpen::_sbox_input(const Ref<InputEvent> &p_ie) { - Ref<InputEventKey> k = p_ie; if (k.is_valid() && (k->get_keycode() == KEY_UP || k->get_keycode() == KEY_DOWN || k->get_keycode() == KEY_PAGEUP || k->get_keycode() == KEY_PAGEDOWN)) { - search_options->call("_gui_input", k); search_box->accept_event(); } } void ScriptEditorQuickOpen::_update_search() { - search_options->clear(); TreeItem *root = search_options->create_item(); for (int i = 0; i < functions.size(); i++) { - String file = functions[i]; if ((search_box->get_text() == "" || file.findn(search_box->get_text()) != -1)) { - TreeItem *ti = search_options->create_item(root); ti->set_text(0, file); - if (root->get_children() == ti) + if (root->get_children() == ti) { ti->select(0); + } } } @@ -197,10 +186,10 @@ void ScriptEditorQuickOpen::_update_search() { } void ScriptEditorQuickOpen::_confirmed() { - TreeItem *ti = search_options->get_selected(); - if (!ti) + if (!ti) { return; + } int line = ti->get_text(0).get_slice(":", 1).to_int(); emit_signal("goto_line", line - 1); @@ -208,7 +197,6 @@ void ScriptEditorQuickOpen::_confirmed() { } void ScriptEditorQuickOpen::_notification(int p_what) { - switch (p_what) { case NOTIFICATION_ENTER_TREE: { connect("confirmed", callable_mp(this, &ScriptEditorQuickOpen::_confirmed)); @@ -226,12 +214,10 @@ void ScriptEditorQuickOpen::_notification(int p_what) { } void ScriptEditorQuickOpen::_bind_methods() { - ADD_SIGNAL(MethodInfo("goto_line", PropertyInfo(Variant::INT, "line"))); } ScriptEditorQuickOpen::ScriptEditorQuickOpen() { - VBoxContainer *vbc = memnew(VBoxContainer); add_child(vbc); search_box = memnew(LineEdit); @@ -257,24 +243,20 @@ ScriptEditor *ScriptEditor::script_editor = nullptr; /*** SCRIPT EDITOR ******/ String ScriptEditor::_get_debug_tooltip(const String &p_text, Node *_se) { - String val = EditorDebuggerNode::get_singleton()->get_var_value(p_text); if (val != String()) { return p_text + ": " + val; } else { - return String(); } } void ScriptEditor::_breaked(bool p_breaked, bool p_can_debug) { - if (bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor"))) { return; } for (int i = 0; i < tab_container->get_child_count(); i++) { - ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i)); if (!se) { continue; @@ -289,14 +271,13 @@ void ScriptEditor::_script_created(Ref<Script> p_script) { } void ScriptEditor::_goto_script_line2(int p_line) { - ScriptEditorBase *current = _get_current_editor(); - if (current) + if (current) { current->goto_line(p_line); + } } void ScriptEditor::_goto_script_line(REF p_script, int p_line) { - Ref<Script> script = Object::cast_to<Script>(*p_script); if (script.is_valid() && (script->has_source_code() || script->get_path().is_resource_file())) { if (edit(p_script, p_line, 0)) { @@ -316,10 +297,10 @@ void ScriptEditor::_set_execution(REF p_script, int p_line) { Ref<Script> script = Object::cast_to<Script>(*p_script); if (script.is_valid() && (script->has_source_code() || script->get_path().is_resource_file())) { for (int i = 0; i < tab_container->get_child_count(); i++) { - ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i)); - if (!se) + if (!se) { continue; + } if ((script != nullptr && se->get_edited_resource() == p_script) || se->get_edited_resource()->get_path() == script->get_path()) { se->set_executing_line(p_line); @@ -332,10 +313,10 @@ void ScriptEditor::_clear_execution(REF p_script) { Ref<Script> script = Object::cast_to<Script>(*p_script); if (script.is_valid() && (script->has_source_code() || script->get_path().is_resource_file())) { for (int i = 0; i < tab_container->get_child_count(); i++) { - ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i)); - if (!se) + if (!se) { continue; + } if ((script != nullptr && se->get_edited_resource() == p_script) || se->get_edited_resource()->get_path() == script->get_path()) { se->clear_executing_line(); @@ -345,32 +326,27 @@ void ScriptEditor::_clear_execution(REF p_script) { } ScriptEditorBase *ScriptEditor::_get_current_editor() const { - int selected = tab_container->get_current_tab(); - if (selected < 0 || selected >= tab_container->get_child_count()) + if (selected < 0 || selected >= tab_container->get_child_count()) { return nullptr; + } return Object::cast_to<ScriptEditorBase>(tab_container->get_child(selected)); } void ScriptEditor::_update_history_arrows() { - script_back->set_disabled(history_pos <= 0); script_forward->set_disabled(history_pos >= history.size() - 1); } void ScriptEditor::_save_history() { - if (history_pos >= 0 && history_pos < history.size() && history[history_pos].control == tab_container->get_current_tab_control()) { - Node *n = tab_container->get_current_tab_control(); if (Object::cast_to<ScriptEditorBase>(n)) { - history.write[history_pos].state = Object::cast_to<ScriptEditorBase>(n)->get_edit_state(); } if (Object::cast_to<EditorHelp>(n)) { - history.write[history_pos].state = Object::cast_to<EditorHelp>(n)->get_scroll(); } } @@ -387,29 +363,25 @@ void ScriptEditor::_save_history() { } void ScriptEditor::_go_to_tab(int p_idx) { - ScriptEditorBase *current = _get_current_editor(); if (current) { if (current->is_unsaved()) { - current->apply_code(); } } Control *c = Object::cast_to<Control>(tab_container->get_child(p_idx)); - if (!c) + if (!c) { return; + } if (history_pos >= 0 && history_pos < history.size() && history[history_pos].control == tab_container->get_current_tab_control()) { - Node *n = tab_container->get_current_tab_control(); if (Object::cast_to<ScriptEditorBase>(n)) { - history.write[history_pos].state = Object::cast_to<ScriptEditorBase>(n)->get_edit_state(); } if (Object::cast_to<EditorHelp>(n)) { - history.write[history_pos].state = Object::cast_to<EditorHelp>(n)->get_scroll(); } } @@ -427,11 +399,11 @@ void ScriptEditor::_go_to_tab(int p_idx) { c = tab_container->get_current_tab_control(); if (Object::cast_to<ScriptEditorBase>(c)) { - script_name_label->set_text(Object::cast_to<ScriptEditorBase>(c)->get_name()); script_icon->set_texture(Object::cast_to<ScriptEditorBase>(c)->get_theme_icon()); - if (is_visible_in_tree()) + if (is_visible_in_tree()) { Object::cast_to<ScriptEditorBase>(c)->ensure_focus(); + } Ref<Script> script = Object::cast_to<ScriptEditorBase>(c)->get_edited_resource(); if (script != nullptr) { @@ -441,11 +413,11 @@ void ScriptEditor::_go_to_tab(int p_idx) { Object::cast_to<ScriptEditorBase>(c)->validate(); } if (Object::cast_to<EditorHelp>(c)) { - script_name_label->set_text(Object::cast_to<EditorHelp>(c)->get_class()); script_icon->set_texture(get_theme_icon("Help", "EditorIcons")); - if (is_visible_in_tree()) + if (is_visible_in_tree()) { Object::cast_to<EditorHelp>(c)->set_focused(); + } } c->set_meta("__editor_pass", ++edit_pass); @@ -459,7 +431,6 @@ void ScriptEditor::_go_to_tab(int p_idx) { } void ScriptEditor::_add_recent_script(String p_path) { - if (p_path.empty()) { return; } @@ -478,13 +449,11 @@ void ScriptEditor::_add_recent_script(String p_path) { } void ScriptEditor::_update_recent_scripts() { - Array rc = EditorSettings::get_singleton()->get_project_metadata("recent_files", "scripts", Array()); recent_scripts->clear(); String path; for (int i = 0; i < rc.size(); i++) { - path = rc[i]; recent_scripts->add_item(path.replace("res://", "")); } @@ -496,7 +465,6 @@ void ScriptEditor::_update_recent_scripts() { } void ScriptEditor::_open_recent_script(int p_idx) { - // clear button if (p_idx == recent_scripts->get_item_count() - 1) { EditorSettings::get_singleton()->set_project_metadata("recent_files", "scripts", Array()); @@ -555,16 +523,15 @@ void ScriptEditor::_open_recent_script(int p_idx) { } void ScriptEditor::_show_error_dialog(String p_path) { - error_dialog->set_text(vformat(TTR("Can't open '%s'. The file could have been moved or deleted."), p_path)); error_dialog->popup_centered(); } void ScriptEditor::_close_tab(int p_idx, bool p_save, bool p_history_back) { - int selected = p_idx; - if (selected < 0 || selected >= tab_container->get_child_count()) + if (selected < 0 || selected >= tab_container->get_child_count()) { return; + } Node *tselected = tab_container->get_child(selected); @@ -606,10 +573,10 @@ void ScriptEditor::_close_tab(int p_idx, bool p_save, bool p_history_back) { current->clear_edit_menu(); } memdelete(tselected); - if (idx >= tab_container->get_child_count()) + if (idx >= tab_container->get_child_count()) { idx = tab_container->get_child_count() - 1; + } if (idx >= 0) { - if (history_pos >= 0) { idx = history[history_pos].control->get_index(); } @@ -627,7 +594,6 @@ void ScriptEditor::_close_tab(int p_idx, bool p_save, bool p_history_back) { } void ScriptEditor::_close_current_tab() { - _close_tab(tab_container->get_current_tab()); } @@ -637,10 +603,8 @@ void ScriptEditor::_close_discard_current_tab(const String &p_str) { } void ScriptEditor::_close_docs_tab() { - int child_count = tab_container->get_child_count(); for (int i = child_count - 1; i >= 0; i--) { - EditorHelp *se = Object::cast_to<EditorHelp>(tab_container->get_child(i)); if (se) { @@ -656,11 +620,9 @@ void ScriptEditor::_copy_script_path() { } void ScriptEditor::_close_other_tabs() { - int child_count = tab_container->get_child_count(); int current_idx = tab_container->get_current_tab(); for (int i = child_count - 1; i >= 0; i--) { - if (i == current_idx) { continue; } @@ -669,7 +631,6 @@ void ScriptEditor::_close_other_tabs() { ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i)); if (se) { - // Maybe there are unsaved changes if (se->is_unsaved()) { _ask_close_current_unsaved_tab(se); @@ -682,15 +643,12 @@ void ScriptEditor::_close_other_tabs() { } void ScriptEditor::_close_all_tabs() { - int child_count = tab_container->get_child_count(); for (int i = child_count - 1; i >= 0; i--) { - tab_container->set_current_tab(i); ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i)); if (se) { - // Maybe there are unsaved changes if (se->is_unsaved()) { _ask_close_current_unsaved_tab(se); @@ -708,19 +666,19 @@ void ScriptEditor::_ask_close_current_unsaved_tab(ScriptEditorBase *current) { } void ScriptEditor::_resave_scripts(const String &p_str) { - apply_scripts(); for (int i = 0; i < tab_container->get_child_count(); i++) { - ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i)); - if (!se) + if (!se) { continue; + } RES script = se->get_edited_resource(); - if (script->get_path() == "" || script->get_path().find("local://") != -1 || script->get_path().find("::") != -1) + if (script->get_path() == "" || script->get_path().find("local://") != -1 || script->get_path().find("::") != -1) { continue; //internal script, who cares + } if (trim_trailing_whitespace_on_save) { se->trim_trailing_whitespace(); @@ -751,19 +709,15 @@ void ScriptEditor::_resave_scripts(const String &p_str) { } void ScriptEditor::_reload_scripts() { - for (int i = 0; i < tab_container->get_child_count(); i++) { - ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i)); if (!se) { - continue; } RES edited_res = se->get_edited_resource(); if (edited_res->get_path() == "" || edited_res->get_path().find("local://") != -1 || edited_res->get_path().find("::") != -1) { - continue; //internal script, who cares } @@ -799,12 +753,9 @@ void ScriptEditor::_reload_scripts() { } void ScriptEditor::_res_saved_callback(const Ref<Resource> &p_res) { - for (int i = 0; i < tab_container->get_child_count(); i++) { - ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i)); if (!se) { - continue; } @@ -815,7 +766,6 @@ void ScriptEditor::_res_saved_callback(const Ref<Resource> &p_res) { } if (script == p_res) { - se->tag_saved_version(); } } @@ -834,7 +784,6 @@ void ScriptEditor::_live_auto_reload_running_scripts() { } bool ScriptEditor::_test_script_times_on_disk(RES p_for_script) { - disk_changed_list->clear(); TreeItem *r = disk_changed_list->create_item(); disk_changed_list->set_hide_root(true); @@ -844,22 +793,21 @@ bool ScriptEditor::_test_script_times_on_disk(RES p_for_script) { bool use_autoreload = bool(EDITOR_DEF("text_editor/files/auto_reload_scripts_on_external_change", false)); for (int i = 0; i < tab_container->get_child_count(); i++) { - ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i)); if (se) { - RES edited_res = se->get_edited_resource(); - if (p_for_script.is_valid() && edited_res.is_valid() && p_for_script != edited_res) + if (p_for_script.is_valid() && edited_res.is_valid() && p_for_script != edited_res) { continue; + } - if (edited_res->get_path() == "" || edited_res->get_path().find("local://") != -1 || edited_res->get_path().find("::") != -1) + if (edited_res->get_path() == "" || edited_res->get_path().find("local://") != -1 || edited_res->get_path().find("::") != -1) { continue; //internal script, who cares + } uint64_t last_date = edited_res->get_last_modified_time(); uint64_t date = FileAccess::get_modified_time(edited_res->get_path()); if (last_date != date) { - TreeItem *ti = disk_changed_list->create_item(r); ti->set_text(0, edited_res->get_path().get_file()); @@ -884,7 +832,6 @@ bool ScriptEditor::_test_script_times_on_disk(RES p_for_script) { } void ScriptEditor::_file_dialog_action(String p_file) { - switch (file_dialog_option) { case FILE_NEW_TEXTFILE: { Error err; @@ -899,7 +846,6 @@ void ScriptEditor::_file_dialog_action(String p_file) { [[fallthrough]]; } case FILE_OPEN: { - List<String> extensions; ResourceLoader::get_recognized_extensions_for_type("Script", &extensions); if (extensions.find(p_file.get_extension())) { @@ -956,7 +902,6 @@ void ScriptEditor::_file_dialog_action(String p_file) { } Ref<Script> ScriptEditor::_get_current_script() { - ScriptEditorBase *current = _get_current_editor(); if (current) { @@ -968,7 +913,6 @@ Ref<Script> ScriptEditor::_get_current_script() { } Array ScriptEditor::_get_open_scripts() const { - Array ret; Vector<Ref<Script>> scripts = get_open_scripts(); int scrits_amount = scripts.size(); @@ -988,7 +932,6 @@ bool ScriptEditor::is_scripts_panel_toggled() { } void ScriptEditor::_menu_option(int p_option) { - ScriptEditorBase *current = _get_current_editor(); switch (p_option) { case FILE_NEW: { @@ -1021,9 +964,9 @@ void ScriptEditor::_menu_option(int p_option) { return; } break; case FILE_REOPEN_CLOSED: { - - if (previous_scripts.empty()) + if (previous_scripts.empty()) { return; + } String path = previous_scripts.back()->get(); previous_scripts.pop_back(); @@ -1060,8 +1003,9 @@ void ScriptEditor::_menu_option(int p_option) { } else { Error error; Ref<TextFile> text_file = _load_text_file(path, &error); - if (error != OK) + if (error != OK) { editor->show_warning(TTR("Could not load file at:") + "\n\n" + path, TTR("Error!")); + } if (text_file.is_valid()) { edit(text_file); @@ -1071,34 +1015,28 @@ void ScriptEditor::_menu_option(int p_option) { } } break; case FILE_SAVE_ALL: { - - if (_test_script_times_on_disk()) + if (_test_script_times_on_disk()) { return; + } save_all_scripts(); } break; case SEARCH_IN_FILES: { - _on_find_in_files_requested(""); } break; case REPLACE_IN_FILES: { - _on_replace_in_files_requested(""); } break; case SEARCH_HELP: { - help_search_dialog->popup_dialog(); } break; case SEARCH_WEBSITE: { - OS::get_singleton()->shell_open("https://docs.godotengine.org/"); } break; case WINDOW_NEXT: { - _history_forward(); } break; case WINDOW_PREV: { - _history_back(); } break; case WINDOW_SORT: { @@ -1119,15 +1057,15 @@ void ScriptEditor::_menu_option(int p_option) { } if (current) { - switch (p_option) { case FILE_SAVE: { - - if (_test_script_times_on_disk()) + if (_test_script_times_on_disk()) { return; + } - if (trim_trailing_whitespace_on_save) + if (trim_trailing_whitespace_on_save) { current->trim_trailing_whitespace(); + } current->insert_final_newline(); @@ -1149,9 +1087,9 @@ void ScriptEditor::_menu_option(int p_option) { } break; case FILE_SAVE_AS: { - - if (trim_trailing_whitespace_on_save) + if (trim_trailing_whitespace_on_save) { current->trim_trailing_whitespace(); + } current->insert_final_newline(); @@ -1186,12 +1124,10 @@ void ScriptEditor::_menu_option(int p_option) { case FILE_TOOL_RELOAD: case FILE_TOOL_RELOAD_SOFT: { - current->reload(p_option == FILE_TOOL_RELOAD_SOFT); } break; case FILE_RUN: { - Ref<Script> scr = current->get_edited_resource(); if (scr == nullptr || scr.is_null()) { EditorNode::get_singleton()->show_warning(TTR("Can't obtain the script for running.")); @@ -1206,13 +1142,11 @@ void ScriptEditor::_menu_option(int p_option) { return; } if (!scr->is_tool()) { - EditorNode::get_singleton()->show_warning(TTR("Script is not in tool mode, will not be able to run.")); return; } if (!ClassDB::is_parent_class(scr->get_instance_base_type(), "EditorScript")) { - EditorNode::get_singleton()->show_warning(TTR("To run this script, it must inherit EditorScript and be set to tool mode.")); return; } @@ -1256,7 +1190,6 @@ void ScriptEditor::_menu_option(int p_option) { _close_all_tabs(); } break; case WINDOW_MOVE_UP: { - if (tab_container->get_current_tab() > 0) { tab_container->move_child(current, tab_container->get_current_tab() - 1); tab_container->set_current_tab(tab_container->get_current_tab() - 1); @@ -1264,7 +1197,6 @@ void ScriptEditor::_menu_option(int p_option) { } } break; case WINDOW_MOVE_DOWN: { - if (tab_container->get_current_tab() < tab_container->get_child_count() - 1) { tab_container->move_child(current, tab_container->get_current_tab() + 1); tab_container->set_current_tab(tab_container->get_current_tab() + 1); @@ -1272,19 +1204,15 @@ void ScriptEditor::_menu_option(int p_option) { } } break; default: { - if (p_option >= WINDOW_SELECT_BASE) { - tab_container->set_current_tab(p_option - WINDOW_SELECT_BASE); _update_script_names(); } } } } else { - EditorHelp *help = Object::cast_to<EditorHelp>(tab_container->get_current_tab_control()); if (help) { - switch (p_option) { case HELP_SEARCH_FIND: { help->popup_search(); @@ -1308,7 +1236,6 @@ void ScriptEditor::_menu_option(int p_option) { _close_all_tabs(); } break; case WINDOW_MOVE_UP: { - if (tab_container->get_current_tab() > 0) { tab_container->move_child(help, tab_container->get_current_tab() - 1); tab_container->set_current_tab(tab_container->get_current_tab() - 1); @@ -1316,7 +1243,6 @@ void ScriptEditor::_menu_option(int p_option) { } } break; case WINDOW_MOVE_DOWN: { - if (tab_container->get_current_tab() < tab_container->get_child_count() - 1) { tab_container->move_child(help, tab_container->get_current_tab() + 1); tab_container->set_current_tab(tab_container->get_current_tab() + 1); @@ -1367,16 +1293,12 @@ void ScriptEditor::_show_save_theme_as_dialog() { } void ScriptEditor::_tab_changed(int p_which) { - ensure_select_current(); } void ScriptEditor::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - editor->connect("stop_pressed", callable_mp(this, &ScriptEditor::_editor_stop)); editor->connect("script_add_function_request", callable_mp(this, &ScriptEditor::_add_callback)); editor->connect("resource_saved", callable_mp(this, &ScriptEditor::_res_saved_callback)); @@ -1390,7 +1312,6 @@ void ScriptEditor::_notification(int p_what) { [[fallthrough]]; } case NOTIFICATION_THEME_CHANGED: { - help_search->set_icon(get_theme_icon("HelpSearch", "EditorIcons")); site_search->set_icon(get_theme_icon("Instance", "EditorIcons")); @@ -1408,25 +1329,21 @@ void ScriptEditor::_notification(int p_what) { } break; case NOTIFICATION_READY: { - get_tree()->connect("tree_changed", callable_mp(this, &ScriptEditor::_tree_changed)); editor->get_inspector_dock()->connect("request_help", callable_mp(this, &ScriptEditor::_help_class_open)); editor->connect("request_help_search", callable_mp(this, &ScriptEditor::_help_search)); } break; case NOTIFICATION_EXIT_TREE: { - editor->disconnect("stop_pressed", callable_mp(this, &ScriptEditor::_editor_stop)); } break; case NOTIFICATION_WM_FOCUS_IN: { - _test_script_times_on_disk(); _update_modified_scripts_for_external_editor(); } break; case CanvasItem::NOTIFICATION_VISIBILITY_CHANGED: { - if (is_visible()) { find_in_files_button->show(); } else { @@ -1444,25 +1361,23 @@ void ScriptEditor::_notification(int p_what) { } bool ScriptEditor::can_take_away_focus() const { - ScriptEditorBase *current = _get_current_editor(); - if (current) + if (current) { return current->can_lose_focus_on_node_selection(); - else + } else { return true; + } } void ScriptEditor::close_builtin_scripts_from_scene(const String &p_scene) { - for (int i = 0; i < tab_container->get_child_count(); i++) { - ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i)); if (se) { - Ref<Script> script = se->get_edited_resource(); - if (script == nullptr || !script.is_valid()) + if (script == nullptr || !script.is_valid()) { continue; + } if (script->get_path().find("::") != -1 && script->get_path().begins_with(p_scene)) { //is an internal script and belongs to scene being closed _close_tab(i); @@ -1473,7 +1388,6 @@ void ScriptEditor::close_builtin_scripts_from_scene(const String &p_scene) { } void ScriptEditor::edited_scene_changed() { - _update_modified_scripts_for_external_editor(); } @@ -1486,12 +1400,11 @@ void ScriptEditor::notify_script_changed(const Ref<Script> &p_script) { } void ScriptEditor::get_breakpoints(List<String> *p_breakpoints) { - for (int i = 0; i < tab_container->get_child_count(); i++) { - ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i)); - if (!se) + if (!se) { continue; + } Ref<Script> script = se->get_edited_resource(); if (script == nullptr) { @@ -1504,20 +1417,20 @@ void ScriptEditor::get_breakpoints(List<String> *p_breakpoints) { ERR_CONTINUE(base.begins_with("local://") || base == ""); for (List<int>::Element *E = bpoints.front(); E; E = E->next()) { - p_breakpoints->push_back(base + ":" + itos(E->get() + 1)); } } } void ScriptEditor::ensure_focus_current() { - - if (!is_inside_tree()) + if (!is_inside_tree()) { return; + } ScriptEditorBase *current = _get_current_editor(); - if (current) + if (current) { current->ensure_focus(); + } } void ScriptEditor::_members_overview_selected(int p_idx) { @@ -1544,7 +1457,6 @@ void ScriptEditor::_help_overview_selected(int p_idx) { } void ScriptEditor::_script_selected(int p_idx) { - grab_focus_block = !Input::get_singleton()->is_mouse_button_pressed(1); //amazing hack, simply amazing _go_to_tab(script_list->get_item_metadata(p_idx)); @@ -1552,14 +1464,12 @@ void ScriptEditor::_script_selected(int p_idx) { } void ScriptEditor::ensure_select_current() { - if (tab_container->get_child_count() && tab_container->get_current_tab() >= 0) { - ScriptEditorBase *se = _get_current_editor(); if (se) { - - if (!grab_focus_block && is_visible_in_tree()) + if (!grab_focus_block && is_visible_in_tree()) { se->ensure_focus(); + } } } @@ -1567,13 +1477,15 @@ void ScriptEditor::ensure_select_current() { } void ScriptEditor::_find_scripts(Node *p_base, Node *p_current, Set<Ref<Script>> &used) { - if (p_current != p_base && p_current->get_owner() != p_base) + if (p_current != p_base && p_current->get_owner() != p_base) { return; + } if (p_current->get_script_instance()) { Ref<Script> scr = p_current->get_script(); - if (scr.is_valid()) + if (scr.is_valid()) { used.insert(scr); + } } for (int i = 0; i < p_current->get_child_count(); i++) { @@ -1582,7 +1494,6 @@ void ScriptEditor::_find_scripts(Node *p_base, Node *p_current, Set<Ref<Script>> } struct _ScriptEditorItemData { - String name; String sort_key; Ref<Texture2D> icon; @@ -1593,7 +1504,6 @@ struct _ScriptEditorItemData { Node *ref; bool operator<(const _ScriptEditorItemData &id) const { - if (category == id.category) { if (sort_key == id.sort_key) { return index < id.index; @@ -1607,7 +1517,6 @@ struct _ScriptEditorItemData { }; void ScriptEditor::_update_members_overview_visibility() { - ScriptEditorBase *se = _get_current_editor(); if (!se) { members_overview_alphabeta_sort_button->set_visible(false); @@ -1661,7 +1570,6 @@ void ScriptEditor::_update_members_overview() { } void ScriptEditor::_update_help_overview_visibility() { - int selected = tab_container->get_current_tab(); if (selected < 0 || selected >= tab_container->get_child_count()) { help_overview->set_visible(false); @@ -1690,8 +1598,9 @@ void ScriptEditor::_update_help_overview() { help_overview->clear(); int selected = tab_container->get_current_tab(); - if (selected < 0 || selected >= tab_container->get_child_count()) + if (selected < 0 || selected >= tab_container->get_child_count()) { return; + } Node *current = tab_container->get_child(tab_container->get_current_tab()); EditorHelp *se = Object::cast_to<EditorHelp>(current); @@ -1707,7 +1616,6 @@ void ScriptEditor::_update_help_overview() { } void ScriptEditor::_update_script_colors() { - bool script_temperature_enabled = EditorSettings::get_singleton()->get("text_editor/script_list/script_temperature_enabled"); bool highlight_current = EditorSettings::get_singleton()->get("text_editor/script_list/highlight_current_script"); @@ -1716,11 +1624,11 @@ void ScriptEditor::_update_script_colors() { Color cold_color = get_theme_color("font_color", "Editor"); for (int i = 0; i < script_list->get_item_count(); i++) { - int c = script_list->get_item_metadata(i); Node *n = tab_container->get_child(c); - if (!n) + if (!n) { continue; + } script_list->set_item_custom_bg_color(i, Color(0, 0, 0, 0)); @@ -1729,7 +1637,6 @@ void ScriptEditor::_update_script_colors() { script_list->set_item_custom_bg_color(i, EditorSettings::get_singleton()->get("text_editor/script_list/current_script_background_color")); } else if (script_temperature_enabled) { - if (!n->has_meta("__editor_pass")) { continue; } @@ -1748,9 +1655,9 @@ void ScriptEditor::_update_script_colors() { } void ScriptEditor::_update_script_names() { - - if (restoring_layout) + if (restoring_layout) { return; + } Set<Ref<Script>> used; Node *edited = EditorNode::get_singleton()->get_edited_scene(); @@ -1766,17 +1673,14 @@ void ScriptEditor::_update_script_names() { Vector<_ScriptEditorItemData> sedata; for (int i = 0; i < tab_container->get_child_count(); i++) { - ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i)); if (se) { - Ref<Texture2D> icon = se->get_theme_icon(); String path = se->get_edited_resource()->get_path(); bool built_in = !path.is_resource_file(); String name; if (built_in) { - name = path.get_file(); const String &resource_name = se->get_edited_resource()->get_name(); if (resource_name != "") { @@ -1785,7 +1689,6 @@ void ScriptEditor::_update_script_names() { name = vformat("%s (%s)", resource_name, name.substr(0, name.find("::", 0))); } } else { - name = se->get_name(); } @@ -1831,7 +1734,6 @@ void ScriptEditor::_update_script_names() { EditorHelp *eh = Object::cast_to<EditorHelp>(tab_container->get_child(i)); if (eh) { - String name = eh->get_class(); Ref<Texture2D> icon = get_theme_icon("Help", "EditorIcons"); String tooltip = vformat(TTR("%s Class Reference"), name); @@ -1978,9 +1880,9 @@ Error ScriptEditor::_save_text_file(Ref<TextFile> p_text_file, const String &p_p } bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_grab_focus) { - - if (p_resource.is_null()) + if (p_resource.is_null()) { return false; + } Ref<Script> script = p_resource; @@ -1995,8 +1897,9 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra if (script != nullptr && script->get_language()->overrides_external_editor()) { if (should_open) { Error err = script->get_language()->open_in_external_editor(script, p_line >= 0 ? p_line : 0, p_col); - if (err != OK) + if (err != OK) { ERR_PRINT("Couldn't open script in the overridden external text editor"); + } } return false; } @@ -2005,7 +1908,6 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra p_resource->get_path().is_resource_file() && p_resource->get_class_name() != StringName("VisualScript") && bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor"))) { - String path = EditorSettings::get_singleton()->get("text_editor/external/exec_path"); String flags = EditorSettings::get_singleton()->get("text_editor/external/exec_flags"); @@ -2025,16 +1927,13 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra bool inside_quotes = false; for (int i = 0; i < flags.size(); i++) { - if (flags[i] == '"' && (!i || flags[i - 1] != '\\')) { - if (!inside_quotes) { from++; } inside_quotes = !inside_quotes; } else if (flags[i] == '\0' || (!inside_quotes && flags[i] == ' ')) { - String arg = flags.substr(from, num_chars); if (arg.find("{file}") != -1) { has_file_flag = true; @@ -2059,26 +1958,27 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra } Error err = OS::get_singleton()->execute(path, args, false); - if (err == OK) + if (err == OK) { return false; + } WARN_PRINT("Couldn't open external text editor, using internal"); } for (int i = 0; i < tab_container->get_child_count(); i++) { - ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i)); - if (!se) + if (!se) { continue; + } if ((script != nullptr && se->get_edited_resource() == p_resource) || se->get_edited_resource()->get_path() == p_resource->get_path()) { - if (should_open) { if (tab_container->get_current_tab() != i) { _go_to_tab(i); _update_script_names(); } - if (is_visible_in_tree()) + if (is_visible_in_tree()) { se->ensure_focus(); + } if (p_line > 0) { se->goto_line(p_line - 1); @@ -2096,8 +1996,9 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra for (int i = script_editor_func_count - 1; i >= 0; i--) { se = script_editor_funcs[i](p_resource); - if (se) + if (se) { break; + } } ERR_FAIL_COND_V(!se, false); @@ -2157,12 +2058,11 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra } void ScriptEditor::save_all_scripts() { - for (int i = 0; i < tab_container->get_child_count(); i++) { - ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i)); - if (!se) + if (!se) { continue; + } if (convert_indent_on_save) { if (use_space_indentation) { @@ -2178,8 +2078,9 @@ void ScriptEditor::save_all_scripts() { se->insert_final_newline(); - if (!se->is_unsaved()) + if (!se->is_unsaved()) { continue; + } RES edited_res = se->get_edited_resource(); if (edited_res.is_valid()) { @@ -2201,12 +2102,11 @@ void ScriptEditor::save_all_scripts() { } void ScriptEditor::apply_scripts() const { - for (int i = 0; i < tab_container->get_child_count(); i++) { - ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i)); - if (!se) + if (!se) { continue; + } se->apply_code(); } } @@ -2218,10 +2118,8 @@ void ScriptEditor::open_script_create_dialog(const String &p_base_name, const St void ScriptEditor::_editor_stop() { for (int i = 0; i < tab_container->get_child_count(); i++) { - ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i)); if (!se) { - continue; } @@ -2230,7 +2128,6 @@ void ScriptEditor::_editor_stop() { } void ScriptEditor::_add_callback(Object *p_obj, const String &p_function, const PackedStringArray &p_args) { - ERR_FAIL_COND(!p_obj); Ref<Script> script = p_obj->get_script(); ERR_FAIL_COND(!script.is_valid()); @@ -2238,12 +2135,13 @@ void ScriptEditor::_add_callback(Object *p_obj, const String &p_function, const editor->push_item(script.ptr()); for (int i = 0; i < tab_container->get_child_count(); i++) { - ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i)); - if (!se) + if (!se) { continue; - if (se->get_edited_resource() != script) + } + if (se->get_edited_resource() != script) { continue; + } se->add_callback(p_function, p_args); @@ -2256,7 +2154,6 @@ void ScriptEditor::_add_callback(Object *p_obj, const String &p_function, const } void ScriptEditor::_save_layout() { - if (restoring_layout) { return; } @@ -2265,7 +2162,6 @@ void ScriptEditor::_save_layout() { } void ScriptEditor::_editor_settings_changed() { - trim_trailing_whitespace_on_save = EditorSettings::get_singleton()->get("text_editor/files/trim_trailing_whitespace_on_save"); convert_indent_on_save = EditorSettings::get_singleton()->get("text_editor/indent/convert_indent_on_save"); use_space_indentation = EditorSettings::get_singleton()->get("text_editor/indent/type"); @@ -2285,10 +2181,10 @@ void ScriptEditor::_editor_settings_changed() { } for (int i = 0; i < tab_container->get_child_count(); i++) { - ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i)); - if (!se) + if (!se) { continue; + } se->update_settings(); } @@ -2299,12 +2195,10 @@ void ScriptEditor::_editor_settings_changed() { } void ScriptEditor::_autosave_scripts() { - save_all_scripts(); } void ScriptEditor::_update_autosave_timer() { - if (!autosave_timer->is_inside_tree()) { return; } @@ -2319,9 +2213,9 @@ void ScriptEditor::_update_autosave_timer() { } void ScriptEditor::_tree_changed() { - - if (waiting_update_names) + if (waiting_update_names) { return; + } waiting_update_names = true; call_deferred("_update_script_names"); @@ -2329,14 +2223,13 @@ void ScriptEditor::_tree_changed() { } void ScriptEditor::_script_split_dragged(float) { - _save_layout(); } Variant ScriptEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) { - - if (tab_container->get_child_count() == 0) + if (tab_container->get_child_count() == 0) { return Variant(); + } Node *cur_node = tab_container->get_child(tab_container->get_current_tab()); @@ -2372,13 +2265,12 @@ Variant ScriptEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) { } bool ScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { - Dictionary d = p_data; - if (!d.has("type")) + if (!d.has("type")) { return false; + } if (String(d["type"]) == "script_list_element") { - Node *node = d["script_list_element"]; ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(node); @@ -2392,10 +2284,10 @@ bool ScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data } if (String(d["type"]) == "nodes") { - Array nodes = d["nodes"]; - if (nodes.size() == 0) + if (nodes.size() == 0) { return false; + } Node *node = get_node((nodes[0])); ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(node); @@ -2409,16 +2301,17 @@ bool ScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data } if (String(d["type"]) == "files") { - Vector<String> files = d["files"]; - if (files.size() == 0) + if (files.size() == 0) { return false; //weird + } for (int i = 0; i < files.size(); i++) { String file = files[i]; - if (file == "" || !FileAccess::exists(file)) + if (file == "" || !FileAccess::exists(file)) { continue; + } Ref<Script> scr = ResourceLoader::load(file); if (scr.is_valid()) { return true; @@ -2431,16 +2324,16 @@ bool ScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data } void ScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { - - if (!can_drop_data_fw(p_point, p_data, p_from)) + if (!can_drop_data_fw(p_point, p_data, p_from)) { return; + } Dictionary d = p_data; - if (!d.has("type")) + if (!d.has("type")) { return; + } if (String(d["type"]) == "script_list_element") { - Node *node = d["script_list_element"]; ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(node); @@ -2457,10 +2350,10 @@ void ScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Co } if (String(d["type"]) == "nodes") { - Array nodes = d["nodes"]; - if (nodes.size() == 0) + if (nodes.size() == 0) { return; + } Node *node = get_node(nodes[0]); ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(node); @@ -2477,7 +2370,6 @@ void ScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Co } if (String(d["type"]) == "files") { - Vector<String> files = d["files"]; int new_index = 0; @@ -2487,8 +2379,9 @@ void ScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Co int num_tabs_before = tab_container->get_child_count(); for (int i = 0; i < files.size(); i++) { String file = files[i]; - if (file == "" || !FileAccess::exists(file)) + if (file == "" || !FileAccess::exists(file)) { continue; + } Ref<Script> scr = ResourceLoader::load(file); if (scr.is_valid()) { edit(scr); @@ -2506,8 +2399,9 @@ void ScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Co } void ScriptEditor::_unhandled_input(const Ref<InputEvent> &p_event) { - if (!is_visible_in_tree() || !p_event->is_pressed() || p_event->is_echo()) + if (!is_visible_in_tree() || !p_event->is_pressed() || p_event->is_echo()) { return; + } if (ED_IS_SHORTCUT("script_editor/next_script", p_event)) { if (script_list->get_item_count() > 1) { int next_tab = script_list->get_current() + 1; @@ -2533,11 +2427,9 @@ void ScriptEditor::_unhandled_input(const Ref<InputEvent> &p_event) { } void ScriptEditor::_script_list_gui_input(const Ref<InputEvent> &ev) { - Ref<InputEventMouseButton> mb = ev; if (mb.is_valid() && mb->is_pressed()) { switch (mb->get_button_index()) { - case BUTTON_MIDDLE: { // Right-click selects automatically; middle-click does not. int idx = script_list->get_item_at_position(mb->get_position(), true); @@ -2556,12 +2448,12 @@ void ScriptEditor::_script_list_gui_input(const Ref<InputEvent> &ev) { } void ScriptEditor::_make_script_list_context_menu() { - context_menu->clear(); int selected = tab_container->get_current_tab(); - if (selected < 0 || selected >= tab_container->get_child_count()) + if (selected < 0 || selected >= tab_container->get_child_count()) { return; + } ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(selected)); if (se) { @@ -2597,18 +2489,19 @@ void ScriptEditor::_make_script_list_context_menu() { } void ScriptEditor::set_window_layout(Ref<ConfigFile> p_layout) { - if (!bool(EDITOR_DEF("text_editor/files/restore_scripts_on_load", true))) { return; } - if (!p_layout->has_section_key("ScriptEditor", "open_scripts") && !p_layout->has_section_key("ScriptEditor", "open_help")) + if (!p_layout->has_section_key("ScriptEditor", "open_scripts") && !p_layout->has_section_key("ScriptEditor", "open_help")) { return; + } Array scripts = p_layout->get_value("ScriptEditor", "open_scripts"); Array helps; - if (p_layout->has_section_key("ScriptEditor", "open_help")) + if (p_layout->has_section_key("ScriptEditor", "open_help")) { helps = p_layout->get_value("ScriptEditor", "open_help"); + } restoring_layout = true; @@ -2616,7 +2509,6 @@ void ScriptEditor::set_window_layout(Ref<ConfigFile> p_layout) { ResourceLoader::get_recognized_extensions_for_type("Script", &extensions); for (int i = 0; i < scripts.size(); i++) { - String path = scripts[i]; Dictionary script_info = scripts[i]; @@ -2624,8 +2516,9 @@ void ScriptEditor::set_window_layout(Ref<ConfigFile> p_layout) { path = script_info["path"]; } - if (!FileAccess::exists(path)) + if (!FileAccess::exists(path)) { continue; + } if (extensions.find(path.get_extension())) { Ref<Script> scr = ResourceLoader::load(path); @@ -2655,7 +2548,6 @@ void ScriptEditor::set_window_layout(Ref<ConfigFile> p_layout) { } for (int i = 0; i < helps.size(); i++) { - String path = helps[i]; if (path == "") { // invalid, skip continue; @@ -2677,18 +2569,16 @@ void ScriptEditor::set_window_layout(Ref<ConfigFile> p_layout) { } void ScriptEditor::get_window_layout(Ref<ConfigFile> p_layout) { - Array scripts; Array helps; for (int i = 0; i < tab_container->get_child_count(); i++) { - ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i)); if (se) { - String path = se->get_edited_resource()->get_path(); - if (!path.is_resource_file()) + if (!path.is_resource_file()) { continue; + } Dictionary script_info; script_info["path"] = path; @@ -2700,7 +2590,6 @@ void ScriptEditor::get_window_layout(Ref<ConfigFile> p_layout) { EditorHelp *eh = Object::cast_to<EditorHelp>(tab_container->get_child(i)); if (eh) { - helps.push_back(eh->get_class()); } } @@ -2711,16 +2600,14 @@ void ScriptEditor::get_window_layout(Ref<ConfigFile> p_layout) { } void ScriptEditor::_help_class_open(const String &p_class) { - - if (p_class == "") + if (p_class == "") { return; + } for (int i = 0; i < tab_container->get_child_count(); i++) { - EditorHelp *eh = Object::cast_to<EditorHelp>(tab_container->get_child(i)); if (eh && eh->get_class() == p_class) { - _go_to_tab(i); _update_script_names(); return; @@ -2741,15 +2628,12 @@ void ScriptEditor::_help_class_open(const String &p_class) { } void ScriptEditor::_help_class_goto(const String &p_desc) { - String cname = p_desc.get_slice(":", 1); for (int i = 0; i < tab_container->get_child_count(); i++) { - EditorHelp *eh = Object::cast_to<EditorHelp>(tab_container->get_child(i)); if (eh && eh->get_class() == cname) { - _go_to_tab(i); eh->go_to_help(p_desc); _update_script_names(); @@ -2771,25 +2655,22 @@ void ScriptEditor::_help_class_goto(const String &p_desc) { } void ScriptEditor::_update_selected_editor_menu() { - for (int i = 0; i < tab_container->get_child_count(); i++) { - bool current = tab_container->get_current_tab() == i; ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i)); if (se && se->get_edit_menu()) { - - if (current) + if (current) { se->get_edit_menu()->show(); - else + } else { se->get_edit_menu()->hide(); + } } } EditorHelp *eh = Object::cast_to<EditorHelp>(tab_container->get_current_tab_control()); script_search_menu->get_popup()->clear(); if (eh) { - script_search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find", TTR("Find..."), KEY_MASK_CMD | KEY_F), HELP_SEARCH_FIND); script_search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find_next", TTR("Find Next"), KEY_F3), HELP_SEARCH_FIND_NEXT); script_search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find_previous", TTR("Find Previous"), KEY_MASK_SHIFT | KEY_F3), HELP_SEARCH_FIND_PREVIOUS); @@ -2797,7 +2678,6 @@ void ScriptEditor::_update_selected_editor_menu() { script_search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find_in_files", TTR("Find in Files"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F), SEARCH_IN_FILES); script_search_menu->show(); } else { - if (tab_container->get_child_count() == 0) { script_search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find_in_files", TTR("Find in Files"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F), SEARCH_IN_FILES); script_search_menu->show(); @@ -2808,15 +2688,12 @@ void ScriptEditor::_update_selected_editor_menu() { } void ScriptEditor::_update_history_pos(int p_new_pos) { - Node *n = tab_container->get_current_tab_control(); if (Object::cast_to<ScriptEditorBase>(n)) { - history.write[history_pos].state = Object::cast_to<ScriptEditorBase>(n)->get_edit_state(); } if (Object::cast_to<EditorHelp>(n)) { - history.write[history_pos].state = Object::cast_to<EditorHelp>(n)->get_scroll(); } @@ -2826,7 +2703,6 @@ void ScriptEditor::_update_history_pos(int p_new_pos) { n = history[history_pos].control; if (Object::cast_to<ScriptEditorBase>(n)) { - Object::cast_to<ScriptEditorBase>(n)->set_edit_state(history[history_pos].state); Object::cast_to<ScriptEditorBase>(n)->ensure_focus(); @@ -2837,7 +2713,6 @@ void ScriptEditor::_update_history_pos(int p_new_pos) { } if (Object::cast_to<EditorHelp>(n)) { - Object::cast_to<EditorHelp>(n)->set_scroll(history[history_pos].state); Object::cast_to<EditorHelp>(n)->set_focused(); } @@ -2849,27 +2724,25 @@ void ScriptEditor::_update_history_pos(int p_new_pos) { } void ScriptEditor::_history_forward() { - if (history_pos < history.size() - 1) { _update_history_pos(history_pos + 1); } } void ScriptEditor::_history_back() { - if (history_pos > 0) { _update_history_pos(history_pos - 1); } } Vector<Ref<Script>> ScriptEditor::get_open_scripts() const { - Vector<Ref<Script>> out_scripts = Vector<Ref<Script>>(); for (int i = 0; i < tab_container->get_child_count(); i++) { ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i)); - if (!se) + if (!se) { continue; + } Ref<Script> script = se->get_edited_resource(); if (script != nullptr) { @@ -2881,11 +2754,11 @@ Vector<Ref<Script>> ScriptEditor::get_open_scripts() const { } void ScriptEditor::set_scene_root_script(Ref<Script> p_script) { - bool open_dominant = EditorSettings::get_singleton()->get("text_editor/files/open_dominant_script_on_scene_change"); - if (bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor"))) + if (bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor"))) { return; + } if (open_dominant && p_script.is_valid()) { edit(p_script); @@ -2893,17 +2766,16 @@ void ScriptEditor::set_scene_root_script(Ref<Script> p_script) { } bool ScriptEditor::script_goto_method(Ref<Script> p_script, const String &p_method) { - int line = p_script->get_member_line(p_method); - if (line == -1) + if (line == -1) { return false; + } return edit(p_script, line, 0); } void ScriptEditor::set_live_auto_reload_running_scripts(bool p_enabled) { - auto_reload_running_scripts = p_enabled; } @@ -2912,7 +2784,6 @@ void ScriptEditor::_help_search(String p_text) { } void ScriptEditor::_open_script_request(const String &p_path) { - Ref<Script> script = ResourceLoader::load(p_path); if (script.is_valid()) { script_editor->edit(script, false); @@ -2939,25 +2810,21 @@ int ScriptEditor::script_editor_func_count = 0; CreateScriptEditorFunc ScriptEditor::script_editor_funcs[ScriptEditor::SCRIPT_EDITOR_FUNC_MAX]; void ScriptEditor::register_create_script_editor_function(CreateScriptEditorFunc p_func) { - ERR_FAIL_COND(script_editor_func_count == SCRIPT_EDITOR_FUNC_MAX); script_editor_funcs[script_editor_func_count++] = p_func; } void ScriptEditor::_script_changed() { - NodeDock::singleton->update_lists(); } void ScriptEditor::_on_find_in_files_requested(String text) { - find_in_files_dialog->set_find_in_files_mode(FindInFilesDialog::SEARCH_MODE); find_in_files_dialog->set_search_text(text); find_in_files_dialog->popup_centered(); } void ScriptEditor::_on_replace_in_files_requested(String text) { - find_in_files_dialog->set_find_in_files_mode(FindInFilesDialog::REPLACE_MODE); find_in_files_dialog->set_search_text(text); find_in_files_dialog->set_replace_text(""); @@ -2965,7 +2832,6 @@ void ScriptEditor::_on_replace_in_files_requested(String text) { } void ScriptEditor::_on_find_in_files_result_selected(String fpath, int line_number, int begin, int end) { - if (ResourceLoader::exists(fpath)) { RES res = ResourceLoader::load(fpath); @@ -3003,7 +2869,6 @@ void ScriptEditor::_on_find_in_files_result_selected(String fpath, int line_numb } void ScriptEditor::_start_find_in_files(bool with_replace) { - FindInFiles *f = find_in_files->get_finder(); f->set_search_text(find_in_files_dialog->get_search_text()); @@ -3020,7 +2885,6 @@ void ScriptEditor::_start_find_in_files(bool with_replace) { } void ScriptEditor::_on_find_in_files_modified_files(PackedStringArray paths) { - _test_script_times_on_disk(); _update_modified_scripts_for_external_editor(); } @@ -3034,7 +2898,6 @@ void ScriptEditor::_filter_methods_text_changed(const String &p_newtext) { } void ScriptEditor::_bind_methods() { - ClassDB::bind_method("_close_docs_tab", &ScriptEditor::_close_docs_tab); ClassDB::bind_method("_close_all_tabs", &ScriptEditor::_close_all_tabs); ClassDB::bind_method("_close_other_tabs", &ScriptEditor::_close_other_tabs); @@ -3063,7 +2926,6 @@ void ScriptEditor::_bind_methods() { } ScriptEditor::ScriptEditor(EditorNode *p_editor) { - current_theme = ""; completion_cache = memnew(EditorScriptCodeCompletionCache); @@ -3364,14 +3226,11 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { } ScriptEditor::~ScriptEditor() { - memdelete(completion_cache); } void ScriptEditorPlugin::edit(Object *p_object) { - if (Object::cast_to<Script>(p_object)) { - Script *p_script = Object::cast_to<Script>(p_object); String res_path = p_script->get_path().get_slice("::", 0); @@ -3391,7 +3250,6 @@ void ScriptEditorPlugin::edit(Object *p_object) { } bool ScriptEditorPlugin::handles(Object *p_object) const { - if (Object::cast_to<TextFile>(p_object)) { return true; } @@ -3404,30 +3262,25 @@ bool ScriptEditorPlugin::handles(Object *p_object) const { } void ScriptEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { script_editor->show(); script_editor->set_process(true); script_editor->ensure_select_current(); } else { - script_editor->hide(); script_editor->set_process(false); } } void ScriptEditorPlugin::selected_notify() { - script_editor->ensure_select_current(); } void ScriptEditorPlugin::save_external_data() { - script_editor->save_all_scripts(); } void ScriptEditorPlugin::apply_changes() { - script_editor->apply_scripts(); } @@ -3438,27 +3291,22 @@ void ScriptEditorPlugin::save_global_state() { } void ScriptEditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) { - script_editor->set_window_layout(p_layout); } void ScriptEditorPlugin::get_window_layout(Ref<ConfigFile> p_layout) { - script_editor->get_window_layout(p_layout); } void ScriptEditorPlugin::get_breakpoints(List<String> *p_breakpoints) { - script_editor->get_breakpoints(p_breakpoints); } void ScriptEditorPlugin::edited_scene_changed() { - script_editor->edited_scene_changed(); } ScriptEditorPlugin::ScriptEditorPlugin(EditorNode *p_node) { - editor = p_node; script_editor = memnew(ScriptEditor(p_node)); editor->get_viewport()->add_child(script_editor); diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index e895867268..f7352be7e8 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -49,7 +49,6 @@ #include "scene/resources/text_file.h" class ScriptEditorQuickOpen : public ConfirmationDialog { - GDCLASS(ScriptEditorQuickOpen, ConfirmationDialog); LineEdit *search_box; @@ -76,7 +75,6 @@ public: class EditorDebuggerNode; class ScriptEditorBase : public VBoxContainer { - GDCLASS(ScriptEditorBase, VBoxContainer); protected: @@ -131,7 +129,6 @@ class FindInFilesDialog; class FindInFilesPanel; class ScriptEditor : public PanelContainer { - GDCLASS(ScriptEditor, PanelContainer); EditorNode *editor; @@ -250,7 +247,6 @@ class ScriptEditor : public PanelContainer { static CreateSyntaxHighlighterFunc syntax_highlighters_funcs[SYNTAX_HIGHLIGHTER_FUNC_MAX]; struct ScriptHistory { - Control *control; Variant state; }; @@ -454,7 +450,6 @@ public: }; class ScriptEditorPlugin : public EditorPlugin { - GDCLASS(ScriptEditorPlugin, EditorPlugin); ScriptEditor *script_editor; diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 109d83d838..e7f8a56e5e 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -109,7 +109,6 @@ ConnectionInfoDialog::ConnectionInfoDialog() { //////////////////////////////////////////////////////////////////////////////// Vector<String> ScriptTextEditor::get_functions() { - String errortxt; int line = -1, col; TextEdit *te = code_editor->get_text_edit(); @@ -117,11 +116,9 @@ Vector<String> ScriptTextEditor::get_functions() { List<String> fnc; if (script->get_language()->validate(text, line, col, errortxt, script->get_path(), &fnc)) { - //if valid rewrite functions to latest functions.clear(); for (List<String>::Element *E = fnc.front(); E; E = E->next()) { - functions.push_back(E->get()); } } @@ -130,9 +127,9 @@ Vector<String> ScriptTextEditor::get_functions() { } void ScriptTextEditor::apply_code() { - - if (script.is_null()) + if (script.is_null()) { return; + } script->set_source_code(code_editor->get_text_edit()->get_text()); script->update_exports(); _update_member_keywords(); @@ -165,17 +162,20 @@ void ScriptTextEditor::_update_member_keywords() { StringName instance_base = script->get_instance_base_type(); - if (instance_base == StringName()) + if (instance_base == StringName()) { return; + } List<PropertyInfo> plist; ClassDB::get_property_list(instance_base, &plist); for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { String name = E->get().name; - if (E->get().usage & PROPERTY_USAGE_CATEGORY || E->get().usage & PROPERTY_USAGE_GROUP || E->get().usage & PROPERTY_USAGE_SUBGROUP) + if (E->get().usage & PROPERTY_USAGE_CATEGORY || E->get().usage & PROPERTY_USAGE_GROUP || E->get().usage & PROPERTY_USAGE_SUBGROUP) { continue; - if (name.find("/") != -1) + } + if (name.find("/") != -1) { continue; + } code_editor->get_text_edit()->add_member_keyword(name, member_variable_color); } @@ -184,13 +184,11 @@ void ScriptTextEditor::_update_member_keywords() { ClassDB::get_integer_constant_list(instance_base, &clist); for (List<String>::Element *E = clist.front(); E; E = E->next()) { - code_editor->get_text_edit()->add_member_keyword(E->get(), member_variable_color); } } void ScriptTextEditor::_load_theme_settings() { - TextEdit *text_edit = code_editor->get_text_edit(); text_edit->clear_colors(); @@ -270,14 +268,15 @@ void ScriptTextEditor::_load_theme_settings() { colors_cache.string_color = string_color; theme_loaded = true; - if (!script.is_null()) + if (!script.is_null()) { _set_theme_for_script(); + } } void ScriptTextEditor::_set_theme_for_script() { - - if (!theme_loaded) + if (!theme_loaded) { return; + } TextEdit *text_edit = code_editor->get_text_edit(); @@ -285,7 +284,6 @@ void ScriptTextEditor::_set_theme_for_script() { script->get_language()->get_reserved_words(&keywords); for (List<String>::Element *E = keywords.front(); E; E = E->next()) { - text_edit->add_keyword_color(E->get(), colors_cache.keyword_color); } @@ -327,10 +325,10 @@ void ScriptTextEditor::_set_theme_for_script() { ClassDB::get_class_list(&types); for (List<StringName>::Element *E = types.front(); E; E = E->next()) { - String n = E->get(); - if (n.begins_with("_")) + if (n.begins_with("_")) { n = n.substr(1, n.length()); + } text_edit->add_keyword_color(n, colors_cache.type_color); } @@ -341,7 +339,6 @@ void ScriptTextEditor::_set_theme_for_script() { ScriptServer::get_global_class_list(&global_classes); for (List<StringName>::Element *E = global_classes.front(); E; E = E->next()) { - text_edit->add_keyword_color(E->get(), colors_cache.usertype_color); } @@ -364,7 +361,6 @@ void ScriptTextEditor::_set_theme_for_script() { script->get_language()->get_comment_delimiters(&comments); for (List<String>::Element *E = comments.front(); E; E = E->next()) { - String comment = E->get(); String beg = comment.get_slice(" ", 0); String end = comment.get_slice_count(" ") > 1 ? comment.get_slice(" ", 1) : String(); @@ -376,7 +372,6 @@ void ScriptTextEditor::_set_theme_for_script() { List<String> strings; script->get_language()->get_string_delimiters(&strings); for (List<String>::Element *E = strings.front(); E; E = E->next()) { - String string = E->get(); String beg = string.get_slice(" ", 0); String end = string.get_slice_count(" ") > 1 ? string.get_slice(" ", 1) : String(); @@ -403,7 +398,6 @@ void ScriptTextEditor::_warning_clicked(Variant p_line) { } void ScriptTextEditor::reload_text() { - ERR_FAIL_COND(script.is_null()); TextEdit *te = code_editor->get_text_edit(); @@ -424,7 +418,6 @@ void ScriptTextEditor::reload_text() { } void ScriptTextEditor::_notification(int p_what) { - switch (p_what) { case NOTIFICATION_READY: _load_theme_settings(); @@ -433,7 +426,6 @@ void ScriptTextEditor::_notification(int p_what) { } void ScriptTextEditor::add_callback(const String &p_function, PackedStringArray p_args) { - String code = code_editor->get_text_edit()->get_text(); int pos = script->get_language()->find_function(p_function, code); if (pos == -1) { @@ -455,22 +447,18 @@ bool ScriptTextEditor::show_members_overview() { } void ScriptTextEditor::update_settings() { - code_editor->update_editor_settings(); } bool ScriptTextEditor::is_unsaved() { - return code_editor->get_text_edit()->get_version() != code_editor->get_text_edit()->get_saved_version(); } Variant ScriptTextEditor::get_edit_state() { - return code_editor->get_edit_state(); } void ScriptTextEditor::set_edit_state(const Variant &p_state) { - code_editor->set_edit_state(p_state); Dictionary state = p_state; @@ -483,47 +471,38 @@ void ScriptTextEditor::set_edit_state(const Variant &p_state) { } void ScriptTextEditor::_convert_case(CodeTextEditor::CaseStyle p_case) { - code_editor->convert_case(p_case); } void ScriptTextEditor::trim_trailing_whitespace() { - code_editor->trim_trailing_whitespace(); } void ScriptTextEditor::insert_final_newline() { - code_editor->insert_final_newline(); } void ScriptTextEditor::convert_indent_to_spaces() { - code_editor->convert_indent_to_spaces(); } void ScriptTextEditor::convert_indent_to_tabs() { - code_editor->convert_indent_to_tabs(); } void ScriptTextEditor::tag_saved_version() { - code_editor->get_text_edit()->tag_saved_version(); } void ScriptTextEditor::goto_line(int p_line, bool p_with_error) { - code_editor->goto_line(p_line); } void ScriptTextEditor::goto_line_selection(int p_line, int p_begin, int p_end) { - code_editor->goto_line_selection(p_line, p_begin, p_end); } void ScriptTextEditor::goto_line_centered(int p_line) { - code_editor->goto_line_centered(p_line); } @@ -536,7 +515,6 @@ void ScriptTextEditor::clear_executing_line() { } void ScriptTextEditor::ensure_focus() { - code_editor->get_text_edit()->grab_focus(); } @@ -548,16 +526,16 @@ String ScriptTextEditor::get_name() { if (is_unsaved()) { name += "(*)"; } - } else if (script->get_name() != "") + } else if (script->get_name() != "") { name = script->get_name(); - else + } else { name = script->get_class() + "(" + itos(script->get_instance_id()) + ")"; + } return name; } Ref<Texture2D> ScriptTextEditor::get_theme_icon() { - if (get_parent_control() && get_parent_control()->has_theme_icon(script->get_class(), "EditorIcons")) { return get_parent_control()->get_theme_icon(script->get_class(), "EditorIcons"); } @@ -566,7 +544,6 @@ Ref<Texture2D> ScriptTextEditor::get_theme_icon() { } void ScriptTextEditor::_validate_script() { - String errortxt; int line = -1, col; TextEdit *te = code_editor->get_text_edit(); @@ -592,7 +569,6 @@ void ScriptTextEditor::_validate_script() { functions.clear(); for (List<String>::Element *E = fnc.front(); E; E = E->next()) { - functions.push_back(E->get()); } script_is_valid = true; @@ -682,7 +658,6 @@ void ScriptTextEditor::_validate_script() { } void ScriptTextEditor::_update_bookmark_list() { - bookmarks_menu->clear(); bookmarks_menu->set_size(Size2(1, 1)); @@ -714,7 +689,6 @@ void ScriptTextEditor::_update_bookmark_list() { } void ScriptTextEditor::_bookmark_item_pressed(int p_idx) { - if (p_idx < 4) { // Any item before the separator. _edit_option(bookmarks_menu->get_item_id(p_idx)); } else { @@ -724,7 +698,6 @@ void ScriptTextEditor::_bookmark_item_pressed(int p_idx) { } static Vector<Node *> _find_all_node_for_script(Node *p_base, Node *p_current, const Ref<Script> &p_script) { - Vector<Node *> nodes; if (p_current->get_owner() != p_base && p_base != p_current) { @@ -745,29 +718,32 @@ static Vector<Node *> _find_all_node_for_script(Node *p_base, Node *p_current, c } static Node *_find_node_for_script(Node *p_base, Node *p_current, const Ref<Script> &p_script) { - - if (p_current->get_owner() != p_base && p_base != p_current) + if (p_current->get_owner() != p_base && p_base != p_current) { return nullptr; + } Ref<Script> c = p_current->get_script(); - if (c == p_script) + if (c == p_script) { return p_current; + } for (int i = 0; i < p_current->get_child_count(); i++) { Node *found = _find_node_for_script(p_base, p_current->get_child(i), p_script); - if (found) + if (found) { return found; + } } return nullptr; } static void _find_changed_scripts_for_external_editor(Node *p_base, Node *p_current, Set<Ref<Script>> &r_scripts) { - - if (p_current->get_owner() != p_base && p_base != p_current) + if (p_current->get_owner() != p_base && p_base != p_current) { return; + } Ref<Script> c = p_current->get_script(); - if (c.is_valid()) + if (c.is_valid()) { r_scripts.insert(c); + } for (int i = 0; i < p_current->get_child_count(); i++) { _find_changed_scripts_for_external_editor(p_base, p_current->get_child(i), r_scripts); @@ -775,9 +751,9 @@ static void _find_changed_scripts_for_external_editor(Node *p_base, Node *p_curr } void ScriptEditor::_update_modified_scripts_for_external_editor(Ref<Script> p_for_script) { - - if (!bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor"))) + if (!bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor"))) { return; + } ERR_FAIL_COND(!get_tree()); @@ -789,14 +765,13 @@ void ScriptEditor::_update_modified_scripts_for_external_editor(Ref<Script> p_fo } for (Set<Ref<Script>>::Element *E = scripts.front(); E; E = E->next()) { - Ref<Script> script = E->get(); - if (p_for_script.is_valid() && p_for_script != script) + if (p_for_script.is_valid() && p_for_script != script) { continue; + } if (script->get_path() == "" || script->get_path().find("local://") != -1 || script->get_path().find("::") != -1) { - continue; //internal script, who cares, though weird } @@ -804,7 +779,6 @@ void ScriptEditor::_update_modified_scripts_for_external_editor(Ref<Script> p_fo uint64_t date = FileAccess::get_modified_time(script->get_path()); if (last_date != date) { - Ref<Script> rel_script = ResourceLoader::load(script->get_path(), script->get_class(), true); ERR_CONTINUE(!rel_script.is_valid()); script->set_source_code(rel_script->get_source_code()); @@ -815,15 +789,14 @@ void ScriptEditor::_update_modified_scripts_for_external_editor(Ref<Script> p_fo } void ScriptTextEditor::_code_complete_scripts(void *p_ud, const String &p_code, List<ScriptCodeCompletionOption> *r_options, bool &r_force) { - ScriptTextEditor *ste = (ScriptTextEditor *)p_ud; ste->_code_complete_script(p_code, r_options, r_force); } void ScriptTextEditor::_code_complete_script(const String &p_code, List<ScriptCodeCompletionOption> *r_options, bool &r_force) { - - if (color_panel->is_visible()) + if (color_panel->is_visible()) { return; + } Node *base = get_tree()->get_edited_scene_root(); if (base) { base = _find_node_for_script(base, base, script); @@ -836,7 +809,6 @@ void ScriptTextEditor::_code_complete_script(const String &p_code, List<ScriptCo } void ScriptTextEditor::_update_breakpoint_list() { - breakpoints_menu->clear(); breakpoints_menu->set_size(Size2(1, 1)); @@ -868,7 +840,6 @@ void ScriptTextEditor::_update_breakpoint_list() { } void ScriptTextEditor::_breakpoint_item_pressed(int p_idx) { - if (p_idx < 4) { // Any item before the separator. _edit_option(breakpoints_menu->get_item_id(p_idx)); } else { @@ -878,12 +849,10 @@ void ScriptTextEditor::_breakpoint_item_pressed(int p_idx) { } void ScriptTextEditor::_breakpoint_toggled(int p_row) { - EditorDebuggerNode::get_singleton()->set_breakpoint(script->get_path(), p_row + 1, code_editor->get_text_edit()->is_line_set_as_breakpoint(p_row)); } void ScriptTextEditor::_lookup_symbol(const String &p_symbol, int p_row, int p_column) { - Node *base = get_tree()->get_edited_scene_root(); if (base) { base = _find_node_for_script(base, base, script); @@ -903,14 +872,12 @@ void ScriptTextEditor::_lookup_symbol(const String &p_symbol, int p_row, int p_c } } else if (script->get_language()->lookup_code(code_editor->get_text_edit()->get_text_for_lookup_completion(), p_symbol, script->get_path(), base, result) == OK) { - _goto_line(p_row); result.class_name = result.class_name.trim_prefix("_"); switch (result.type) { case ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION: { - if (result.script.is_valid()) { emit_signal("request_open_script_at_line", result.script, result.location - 1); } else { @@ -922,7 +889,6 @@ void ScriptTextEditor::_lookup_symbol(const String &p_symbol, int p_row, int p_c emit_signal("go_to_help", "class_name:" + result.class_name); } break; case ScriptLanguage::LookupResult::RESULT_CLASS_CONSTANT: { - StringName cname = result.class_name; bool success; while (true) { @@ -943,7 +909,6 @@ void ScriptTextEditor::_lookup_symbol(const String &p_symbol, int p_row, int p_c } break; case ScriptLanguage::LookupResult::RESULT_CLASS_METHOD: { - StringName cname = result.class_name; while (true) { @@ -959,7 +924,6 @@ void ScriptTextEditor::_lookup_symbol(const String &p_symbol, int p_row, int p_c } break; case ScriptLanguage::LookupResult::RESULT_CLASS_ENUM: { - StringName cname = result.class_name; StringName success; while (true) { @@ -1003,7 +967,6 @@ void ScriptTextEditor::_lookup_symbol(const String &p_symbol, int p_row, int p_c } void ScriptTextEditor::_validate_symbol(const String &p_symbol) { - TextEdit *text_edit = code_editor->get_text_edit(); Node *base = get_tree()->get_edited_scene_root(); @@ -1015,7 +978,6 @@ void ScriptTextEditor::_validate_symbol(const String &p_symbol) { if (ScriptServer::is_global_class(p_symbol) || p_symbol.is_resource_file() || script->get_language()->lookup_code(code_editor->get_text_edit()->get_text_for_lookup_completion(), p_symbol, script->get_path(), base, result) == OK || ProjectSettings::get_singleton()->has_setting("autoload/" + p_symbol)) { text_edit->set_highlighted_word(p_symbol); } else if (p_symbol.is_rel_path()) { - String path = _get_absolute_path(p_symbol); if (FileAccess::exists(path)) { text_edit->set_highlighted_word(p_symbol); @@ -1124,101 +1086,85 @@ void ScriptTextEditor::_lookup_connections(int p_row, String p_method) { } void ScriptTextEditor::_edit_option(int p_op) { - TextEdit *tx = code_editor->get_text_edit(); switch (p_op) { case EDIT_UNDO: { - tx->undo(); tx->call_deferred("grab_focus"); } break; case EDIT_REDO: { - tx->redo(); tx->call_deferred("grab_focus"); } break; case EDIT_CUT: { - tx->cut(); tx->call_deferred("grab_focus"); } break; case EDIT_COPY: { - tx->copy(); tx->call_deferred("grab_focus"); } break; case EDIT_PASTE: { - tx->paste(); tx->call_deferred("grab_focus"); } break; case EDIT_SELECT_ALL: { - tx->select_all(); tx->call_deferred("grab_focus"); } break; case EDIT_MOVE_LINE_UP: { - code_editor->move_lines_up(); } break; case EDIT_MOVE_LINE_DOWN: { - code_editor->move_lines_down(); } break; case EDIT_INDENT_LEFT: { - Ref<Script> scr = script; - if (scr.is_null()) + if (scr.is_null()) { return; + } tx->indent_left(); } break; case EDIT_INDENT_RIGHT: { - Ref<Script> scr = script; - if (scr.is_null()) + if (scr.is_null()) { return; + } tx->indent_right(); } break; case EDIT_DELETE_LINE: { - code_editor->delete_lines(); } break; case EDIT_CLONE_DOWN: { - code_editor->clone_lines_down(); } break; case EDIT_TOGGLE_FOLD_LINE: { - tx->toggle_fold_line(tx->cursor_get_line()); tx->update(); } break; case EDIT_FOLD_ALL_LINES: { - tx->fold_all_lines(); tx->update(); } break; case EDIT_UNFOLD_ALL_LINES: { - tx->unhide_all_lines(); tx->update(); } break; case EDIT_TOGGLE_COMMENT: { - _edit_option_toggle_inline_comment(); } break; case EDIT_COMPLETE: { - tx->query_code_comple(); } break; case EDIT_AUTO_INDENT: { - String text = tx->get_text(); Ref<Script> scr = script; - if (scr.is_null()) + if (scr.is_null()) { return; + } tx->begin_complex_operation(); int begin, end; @@ -1242,35 +1188,27 @@ void ScriptTextEditor::_edit_option(int p_op) { tx->end_complex_operation(); } break; case EDIT_TRIM_TRAILING_WHITESAPCE: { - trim_trailing_whitespace(); } break; case EDIT_CONVERT_INDENT_TO_SPACES: { - convert_indent_to_spaces(); } break; case EDIT_CONVERT_INDENT_TO_TABS: { - convert_indent_to_tabs(); } break; case EDIT_PICK_COLOR: { - color_panel->popup(); } break; case EDIT_TO_UPPERCASE: { - _convert_case(CodeTextEditor::UPPER); } break; case EDIT_TO_LOWERCASE: { - _convert_case(CodeTextEditor::LOWER); } break; case EDIT_CAPITALIZE: { - _convert_case(CodeTextEditor::CAPITALIZE); } break; case EDIT_EVALUATE: { - Expression expression; Vector<String> lines = code_editor->get_text_edit()->get_selection_text().split("\n"); PackedStringArray results; @@ -1296,23 +1234,18 @@ void ScriptTextEditor::_edit_option(int p_op) { code_editor->get_text_edit()->end_complex_operation(); } break; case SEARCH_FIND: { - code_editor->get_find_replace_bar()->popup_search(); } break; case SEARCH_FIND_NEXT: { - code_editor->get_find_replace_bar()->search_next(); } break; case SEARCH_FIND_PREV: { - code_editor->get_find_replace_bar()->search_prev(); } break; case SEARCH_REPLACE: { - code_editor->get_find_replace_bar()->popup_replace(); } break; case SEARCH_IN_FILES: { - String selected_text = code_editor->get_text_edit()->get_selection_text(); // Yep, because it doesn't make sense to instance this dialog for every single script open... @@ -1320,45 +1253,36 @@ void ScriptTextEditor::_edit_option(int p_op) { emit_signal("search_in_files_requested", selected_text); } break; case REPLACE_IN_FILES: { - String selected_text = code_editor->get_text_edit()->get_selection_text(); emit_signal("replace_in_files_requested", selected_text); } break; case SEARCH_LOCATE_FUNCTION: { - quick_open->popup_dialog(get_functions()); quick_open->set_title(TTR("Go to Function")); } break; case SEARCH_GOTO_LINE: { - goto_line_dialog->popup_find_line(tx); } break; case BOOKMARK_TOGGLE: { - code_editor->toggle_bookmark(); } break; case BOOKMARK_GOTO_NEXT: { - code_editor->goto_next_bookmark(); } break; case BOOKMARK_GOTO_PREV: { - code_editor->goto_prev_bookmark(); } break; case BOOKMARK_REMOVE_ALL: { - code_editor->remove_all_bookmarks(); } break; case DEBUG_TOGGLE_BREAKPOINT: { - int line = tx->cursor_get_line(); bool dobreak = !tx->is_line_set_as_breakpoint(line); tx->set_line_as_breakpoint(line, dobreak); EditorDebuggerNode::get_singleton()->set_breakpoint(script->get_path(), line + 1, dobreak); } break; case DEBUG_REMOVE_ALL_BREAKPOINTS: { - List<int> bpoints; tx->get_breakpoints(&bpoints); @@ -1370,7 +1294,6 @@ void ScriptTextEditor::_edit_option(int p_op) { } } break; case DEBUG_GOTO_NEXT_BREAKPOINT: { - List<int> bpoints; tx->get_breakpoints(&bpoints); if (bpoints.size() <= 0) { @@ -1398,7 +1321,6 @@ void ScriptTextEditor::_edit_option(int p_op) { } break; case DEBUG_GOTO_PREV_BREAKPOINT: { - List<int> bpoints; tx->get_breakpoints(&bpoints); if (bpoints.size() <= 0) { @@ -1425,19 +1347,19 @@ void ScriptTextEditor::_edit_option(int p_op) { } break; case HELP_CONTEXTUAL: { - String text = tx->get_selection_text(); - if (text == "") + if (text == "") { text = tx->get_word_under_cursor(); + } if (text != "") { emit_signal("request_help", text); } } break; case LOOKUP_SYMBOL: { - String text = tx->get_word_under_cursor(); - if (text == "") + if (text == "") { text = tx->get_selection_text(); + } if (text != "") { _lookup_symbol(text, tx->cursor_get_line(), tx->cursor_get_column()); } @@ -1446,8 +1368,9 @@ void ScriptTextEditor::_edit_option(int p_op) { } void ScriptTextEditor::_edit_option_toggle_inline_comment() { - if (script.is_null()) + if (script.is_null()) { return; + } String delimiter = "#"; List<String> comment_delimiters; @@ -1472,10 +1395,11 @@ void ScriptTextEditor::add_syntax_highlighter(SyntaxHighlighter *p_highlighter) void ScriptTextEditor::set_syntax_highlighter(SyntaxHighlighter *p_highlighter) { TextEdit *te = code_editor->get_text_edit(); te->_set_syntax_highlighting(p_highlighter); - if (p_highlighter != nullptr) + if (p_highlighter != nullptr) { highlighter_menu->set_item_checked(highlighter_menu->get_item_idx_from_text(p_highlighter->get_name()), true); - else + } else { highlighter_menu->set_item_checked(highlighter_menu->get_item_idx_from_text(TTR("Standard")), true); + } } void ScriptTextEditor::_change_syntax_highlighter(int p_idx) { @@ -1489,7 +1413,6 @@ void ScriptTextEditor::_change_syntax_highlighter(int p_idx) { } void ScriptTextEditor::_bind_methods() { - ClassDB::bind_method("_update_connected_methods", &ScriptTextEditor::_update_connected_methods); ClassDB::bind_method("get_drag_data_fw", &ScriptTextEditor::get_drag_data_fw); @@ -1498,7 +1421,6 @@ void ScriptTextEditor::_bind_methods() { } Control *ScriptTextEditor::get_edit_menu() { - return edit_hb; } @@ -1507,11 +1429,11 @@ void ScriptTextEditor::clear_edit_menu() { } void ScriptTextEditor::reload(bool p_soft) { - TextEdit *te = code_editor->get_text_edit(); Ref<Script> scr = script; - if (scr.is_null()) + if (scr.is_null()) { return; + } scr->set_source_code(te->get_text()); bool soft = p_soft || scr->get_instance_base_type() == "EditorPlugin"; //always soft-reload editor plugins @@ -1519,12 +1441,10 @@ void ScriptTextEditor::reload(bool p_soft) { } void ScriptTextEditor::get_breakpoints(List<int> *p_breakpoints) { - code_editor->get_text_edit()->get_breakpoints(p_breakpoints); } void ScriptTextEditor::set_tooltip_request_func(String p_method, Object *p_obj) { - code_editor->get_text_edit()->set_tooltip_request_func(p_obj, p_method, this); } @@ -1532,18 +1452,15 @@ void ScriptTextEditor::set_debugger_active(bool p_active) { } Variant ScriptTextEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) { - return Variant(); } bool ScriptTextEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { - Dictionary d = p_data; if (d.has("type") && (String(d["type"]) == "resource" || String(d["type"]) == "files" || String(d["type"]) == "nodes" || String(d["type"]) == "files_and_dirs")) { - return true; } @@ -1551,26 +1468,27 @@ bool ScriptTextEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_ } static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) { - - if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) + if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) { return nullptr; + } Ref<Script> scr = p_current_node->get_script(); - if (scr.is_valid() && scr == script) + if (scr.is_valid() && scr == script) { return p_current_node; + } for (int i = 0; i < p_current_node->get_child_count(); i++) { Node *n = _find_script_node(p_edited_scene, p_current_node->get_child(i), script); - if (n) + if (n) { return n; + } } return nullptr; } void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { - Dictionary d = p_data; TextEdit *te = code_editor->get_text_edit(); @@ -1578,7 +1496,6 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data te->_get_mouse_pos(p_point, row, col); if (d.has("type") && String(d["type"]) == "resource") { - Ref<Resource> res = d["resource"]; if (!res.is_valid()) { return; @@ -1595,14 +1512,13 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data } if (d.has("type") && (String(d["type"]) == "files" || String(d["type"]) == "files_and_dirs")) { - Array files = d["files"]; String text_to_drop; for (int i = 0; i < files.size(); i++) { - - if (i > 0) + if (i > 0) { text_to_drop += ","; + } text_to_drop += "\"" + String(files[i]).c_escape() + "\""; } @@ -1612,7 +1528,6 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data } if (d.has("type") && String(d["type"]) == "nodes") { - Node *sn = _find_script_node(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root(), script); if (!sn) { @@ -1623,9 +1538,9 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data Array nodes = d["nodes"]; String text_to_drop; for (int i = 0; i < nodes.size(); i++) { - - if (i > 0) + if (i > 0) { text_to_drop += ","; + } NodePath np = nodes[i]; Node *node = get_node(np); @@ -1644,7 +1559,6 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data } void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { - Ref<InputEventMouseButton> mb = ev; Ref<InputEventKey> k = ev; Point2 local_pos; @@ -1683,10 +1597,12 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { } String word_at_pos = tx->get_word_at_pos(local_pos); - if (word_at_pos == "") + if (word_at_pos == "") { word_at_pos = tx->get_word_under_cursor(); - if (word_at_pos == "") + } + if (word_at_pos == "") { word_at_pos = tx->get_selection_text(); + } bool has_color = (word_at_pos == "Color"); bool foldable = tx->can_fold(row) || tx->is_folded(row); @@ -1763,7 +1679,6 @@ void ScriptTextEditor::_color_changed(const Color &p_color) { } void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color, bool p_foldable, bool p_open_docs, bool p_goto_definition, Vector2 p_pos) { - context_menu->clear(); context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO); context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO); @@ -1788,15 +1703,18 @@ void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color, bool p context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_to_lowercase"), EDIT_TO_LOWERCASE); context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/evaluate_selection"), EDIT_EVALUATE); } - if (p_foldable) + if (p_foldable) { context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_fold_line"), EDIT_TOGGLE_FOLD_LINE); + } if (p_color || p_open_docs || p_goto_definition) { context_menu->add_separator(); - if (p_open_docs) + if (p_open_docs) { context_menu->add_item(TTR("Lookup Symbol"), LOOKUP_SYMBOL); - if (p_color) + } + if (p_color) { context_menu->add_item(TTR("Pick Color"), EDIT_PICK_COLOR); + } } context_menu->set_position(get_global_transform().xform(p_pos)); @@ -1805,7 +1723,6 @@ void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color, bool p } ScriptTextEditor::ScriptTextEditor() { - theme_loaded = false; script_is_valid = false; @@ -1864,10 +1781,11 @@ ScriptTextEditor::ScriptTextEditor() { // get default color picker mode from editor settings int default_color_mode = EDITOR_GET("interface/inspector/default_color_picker_mode"); - if (default_color_mode == 1) + if (default_color_mode == 1) { color_picker->set_hsv_mode(true); - else if (default_color_mode == 2) + } else if (default_color_mode == 2) { color_picker->set_raw_mode(true); + } edit_hb = memnew(HBoxContainer); @@ -1988,7 +1906,6 @@ ScriptTextEditor::~ScriptTextEditor() { } static ScriptEditorBase *create_editor(const RES &p_resource) { - if (Object::cast_to<Script>(*p_resource)) { return memnew(ScriptTextEditor); } @@ -1996,7 +1913,6 @@ static ScriptEditorBase *create_editor(const RES &p_resource) { } void ScriptTextEditor::register_editor() { - ED_SHORTCUT("script_text_editor/undo", TTR("Undo"), KEY_MASK_CMD | KEY_Z); ED_SHORTCUT("script_text_editor/redo", TTR("Redo"), KEY_MASK_CMD | KEY_Y); ED_SHORTCUT("script_text_editor/cut", TTR("Cut"), KEY_MASK_CMD | KEY_X); diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h index a0dfba6cc8..adcd0218bc 100644 --- a/editor/plugins/script_text_editor.h +++ b/editor/plugins/script_text_editor.h @@ -37,7 +37,6 @@ #include "script_editor_plugin.h" class ConnectionInfoDialog : public AcceptDialog { - GDCLASS(ConnectionInfoDialog, AcceptDialog); Label *method; @@ -52,7 +51,6 @@ public: }; class ScriptTextEditor : public ScriptEditorBase { - GDCLASS(ScriptTextEditor, ScriptEditorBase); CodeTextEditor *code_editor; diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index 9ef8148241..0c3a44e4cd 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -44,11 +44,10 @@ /*** SHADER SCRIPT EDITOR ****/ Ref<Shader> ShaderTextEditor::get_edited_shader() const { - return shader; } -void ShaderTextEditor::set_edited_shader(const Ref<Shader> &p_shader) { +void ShaderTextEditor::set_edited_shader(const Ref<Shader> &p_shader) { if (shader == p_shader) { return; } @@ -84,7 +83,6 @@ void ShaderTextEditor::reload_text() { } void ShaderTextEditor::_load_theme_settings() { - get_text_edit()->clear_colors(); Color background_color = EDITOR_GET("text_editor/highlighting/background_color"); @@ -149,22 +147,18 @@ void ShaderTextEditor::_load_theme_settings() { ShaderLanguage::get_keyword_list(&keywords); if (shader.is_valid()) { - for (const Map<StringName, ShaderLanguage::FunctionInfo>::Element *E = ShaderTypes::get_singleton()->get_functions(RenderingServer::ShaderMode(shader->get_mode())).front(); E; E = E->next()) { - for (const Map<StringName, ShaderLanguage::BuiltInInfo>::Element *F = E->get().built_ins.front(); F; F = F->next()) { keywords.push_back(F->key()); } } for (int i = 0; i < ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(shader->get_mode())).size(); i++) { - keywords.push_back(ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(shader->get_mode()))[i]); } } for (List<String>::Element *E = keywords.front(); E; E = E->next()) { - get_text_edit()->add_keyword_color(E->get(), keyword_color); } @@ -174,7 +168,6 @@ void ShaderTextEditor::_load_theme_settings() { } void ShaderTextEditor::_check_shader_mode() { - String type = ShaderLanguage::get_shader_type(get_text_edit()->get_text()); Shader::Mode mode; @@ -194,13 +187,11 @@ void ShaderTextEditor::_check_shader_mode() { } static ShaderLanguage::DataType _get_global_variable_type(const StringName &p_variable) { - RS::GlobalVariableType gvt = RS::get_singleton()->global_variable_get_type(p_variable); return RS::global_variable_type_get_shader_datatype(gvt); } void ShaderTextEditor::_code_complete_script(const String &p_code, List<ScriptCodeCompletionOption> *r_options) { - _check_shader_mode(); ShaderLanguage sl; @@ -212,7 +203,6 @@ void ShaderTextEditor::_code_complete_script(const String &p_code, List<ScriptCo } void ShaderTextEditor::_validate_script() { - _check_shader_mode(); String code = get_text_edit()->get_text(); @@ -227,13 +217,15 @@ void ShaderTextEditor::_validate_script() { String error_text = "error(" + itos(sl.get_error_line()) + "): " + sl.get_error_text(); set_error(error_text); set_error_pos(sl.get_error_line() - 1, 0); - for (int i = 0; i < get_text_edit()->get_line_count(); i++) + for (int i = 0; i < get_text_edit()->get_line_count(); i++) { get_text_edit()->set_line_as_marked(i, false); + } get_text_edit()->set_line_as_marked(sl.get_error_line() - 1, true); } else { - for (int i = 0; i < get_text_edit()->get_line_count(); i++) + for (int i = 0; i < get_text_edit()->get_line_count(); i++) { get_text_edit()->set_line_as_marked(i, false); + } set_error(""); } @@ -249,7 +241,6 @@ ShaderTextEditor::ShaderTextEditor() { /*** SCRIPT EDITOR ******/ void ShaderEditor::_menu_option(int p_option) { - switch (p_option) { case EDIT_UNDO: { shader_editor->get_text_edit()->undo(); @@ -276,18 +267,18 @@ void ShaderEditor::_menu_option(int p_option) { shader_editor->move_lines_down(); } break; case EDIT_INDENT_LEFT: { - - if (shader.is_null()) + if (shader.is_null()) { return; + } TextEdit *tx = shader_editor->get_text_edit(); tx->indent_left(); } break; case EDIT_INDENT_RIGHT: { - - if (shader.is_null()) + if (shader.is_null()) { return; + } TextEdit *tx = shader_editor->get_text_edit(); tx->indent_right(); @@ -300,51 +291,41 @@ void ShaderEditor::_menu_option(int p_option) { shader_editor->clone_lines_down(); } break; case EDIT_TOGGLE_COMMENT: { - - if (shader.is_null()) + if (shader.is_null()) { return; + } shader_editor->toggle_inline_comment("//"); } break; case EDIT_COMPLETE: { - shader_editor->get_text_edit()->query_code_comple(); } break; case SEARCH_FIND: { - shader_editor->get_find_replace_bar()->popup_search(); } break; case SEARCH_FIND_NEXT: { - shader_editor->get_find_replace_bar()->search_next(); } break; case SEARCH_FIND_PREV: { - shader_editor->get_find_replace_bar()->search_prev(); } break; case SEARCH_REPLACE: { - shader_editor->get_find_replace_bar()->popup_replace(); } break; case SEARCH_GOTO_LINE: { - goto_line_dialog->popup_find_line(shader_editor->get_text_edit()); } break; case BOOKMARK_TOGGLE: { - shader_editor->toggle_bookmark(); } break; case BOOKMARK_GOTO_NEXT: { - shader_editor->goto_next_bookmark(); } break; case BOOKMARK_GOTO_PREV: { - shader_editor->goto_prev_bookmark(); } break; case BOOKMARK_REMOVE_ALL: { - shader_editor->remove_all_bookmarks(); } break; case HELP_DOCS: { @@ -357,19 +338,16 @@ void ShaderEditor::_menu_option(int p_option) { } void ShaderEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_WM_FOCUS_IN) { _check_for_external_edit(); } } void ShaderEditor::_params_changed() { - shader_editor->_validate_script(); } void ShaderEditor::_editor_settings_changed() { - shader_editor->get_text_edit()->set_auto_brace_completion(EditorSettings::get_singleton()->get("text_editor/completion/auto_brace_complete")); shader_editor->get_text_edit()->set_scroll_pass_end_of_file(EditorSettings::get_singleton()->get("text_editor/cursor/scroll_past_end_of_file")); shader_editor->get_text_edit()->set_indent_size(EditorSettings::get_singleton()->get("text_editor/indent/size")); @@ -396,12 +374,10 @@ void ShaderEditor::_editor_settings_changed() { } void ShaderEditor::_bind_methods() { - ClassDB::bind_method("_params_changed", &ShaderEditor::_params_changed); } void ShaderEditor::ensure_select_current() { - /* if (tab_container->get_child_count() && tab_container->get_current_tab()>=0) { @@ -414,12 +390,10 @@ void ShaderEditor::ensure_select_current() { } void ShaderEditor::goto_line_selection(int p_line, int p_begin, int p_end) { - shader_editor->goto_line_selection(p_line, p_begin, p_end); } void ShaderEditor::_check_for_external_edit() { - if (shader.is_null() || !shader.is_valid()) { return; } @@ -440,7 +414,6 @@ void ShaderEditor::_check_for_external_edit() { } void ShaderEditor::_reload_shader_from_disk() { - Ref<Shader> rel_shader = ResourceLoader::load(shader->get_path(), shader->get_class(), true); ERR_FAIL_COND(!rel_shader.is_valid()); @@ -450,12 +423,13 @@ void ShaderEditor::_reload_shader_from_disk() { } void ShaderEditor::edit(const Ref<Shader> &p_shader) { - - if (p_shader.is_null() || !p_shader->is_text_shader()) + if (p_shader.is_null() || !p_shader->is_text_shader()) { return; + } - if (shader == p_shader) + if (shader == p_shader) { return; + } shader = p_shader; @@ -466,7 +440,6 @@ void ShaderEditor::edit(const Ref<Shader> &p_shader) { } void ShaderEditor::save_external_data(const String &p_str) { - if (shader.is_null()) { disk_changed->hide(); return; @@ -482,7 +455,6 @@ void ShaderEditor::save_external_data(const String &p_str) { } void ShaderEditor::apply_shaders() { - if (shader.is_valid()) { String shader_code = shader->get_code(); String editor_code = shader_editor->get_text_edit()->get_text(); @@ -494,13 +466,10 @@ void ShaderEditor::apply_shaders() { } void ShaderEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { - Ref<InputEventMouseButton> mb = ev; if (mb.is_valid()) { - if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) { - int col, row; TextEdit *tx = shader_editor->get_text_edit(); tx->_get_mouse_pos(mb->get_global_position() - tx->get_global_position(), row, col); @@ -508,7 +477,6 @@ void ShaderEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { if (tx->is_right_click_moving_caret()) { if (tx->is_selection_active()) { - int from_line = tx->get_selection_from_line(); int to_line = tx->get_selection_to_line(); int from_column = tx->get_selection_from_column(); @@ -537,7 +505,6 @@ void ShaderEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { } void ShaderEditor::_update_bookmark_list() { - bookmarks_menu->clear(); bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE); @@ -565,7 +532,6 @@ void ShaderEditor::_update_bookmark_list() { } void ShaderEditor::_bookmark_item_pressed(int p_idx) { - if (p_idx < 4) { // Any item before the separator. _menu_option(bookmarks_menu->get_item_id(p_idx)); } else { @@ -574,7 +540,6 @@ void ShaderEditor::_bookmark_item_pressed(int p_idx) { } void ShaderEditor::_make_context_menu(bool p_selection, Vector2 p_position) { - context_menu->clear(); if (p_selection) { context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT); @@ -599,7 +564,6 @@ void ShaderEditor::_make_context_menu(bool p_selection, Vector2 p_position) { } ShaderEditor::ShaderEditor(EditorNode *p_node) { - shader_editor = memnew(ShaderTextEditor); shader_editor->set_v_size_flags(SIZE_EXPAND_FILL); shader_editor->add_theme_constant_override("separation", 0); @@ -714,49 +678,42 @@ ShaderEditor::ShaderEditor(EditorNode *p_node) { } void ShaderEditorPlugin::edit(Object *p_object) { - Shader *s = Object::cast_to<Shader>(p_object); shader_editor->edit(s); } bool ShaderEditorPlugin::handles(Object *p_object) const { - Shader *shader = Object::cast_to<Shader>(p_object); return shader != nullptr && shader->is_text_shader(); } void ShaderEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { button->show(); editor->make_bottom_panel_item_visible(shader_editor); } else { - button->hide(); - if (shader_editor->is_visible_in_tree()) + if (shader_editor->is_visible_in_tree()) { editor->hide_bottom_panel(); + } shader_editor->apply_shaders(); } } void ShaderEditorPlugin::selected_notify() { - shader_editor->ensure_select_current(); } void ShaderEditorPlugin::save_external_data() { - shader_editor->save_external_data(); } void ShaderEditorPlugin::apply_changes() { - shader_editor->apply_shaders(); } ShaderEditorPlugin::ShaderEditorPlugin(EditorNode *p_node) { - editor = p_node; shader_editor = memnew(ShaderEditor(p_node)); diff --git a/editor/plugins/shader_editor_plugin.h b/editor/plugins/shader_editor_plugin.h index f02ed590fc..0208b43e13 100644 --- a/editor/plugins/shader_editor_plugin.h +++ b/editor/plugins/shader_editor_plugin.h @@ -42,7 +42,6 @@ #include "servers/rendering/shader_language.h" class ShaderTextEditor : public CodeTextEditor { - GDCLASS(ShaderTextEditor, CodeTextEditor); Ref<Shader> shader; @@ -66,7 +65,6 @@ public: }; class ShaderEditor : public PanelContainer { - GDCLASS(ShaderEditor, PanelContainer); enum { @@ -143,7 +141,6 @@ public: }; class ShaderEditorPlugin : public EditorPlugin { - GDCLASS(ShaderEditorPlugin, EditorPlugin); bool _2d; diff --git a/editor/plugins/shader_file_editor_plugin.cpp b/editor/plugins/shader_file_editor_plugin.cpp index 9d5ffd6516..0ac29f68f6 100644 --- a/editor/plugins/shader_file_editor_plugin.cpp +++ b/editor/plugins/shader_file_editor_plugin.cpp @@ -49,7 +49,6 @@ void ShaderFileEditor::_update_version(const StringName &p_version_txt, const RD } void ShaderFileEditor::_version_selected(int p_option) { - int c = versions->get_current(); StringName version_txt = versions->get_item_metadata(c); @@ -106,7 +105,6 @@ void ShaderFileEditor::_version_selected(int p_option) { } void ShaderFileEditor::_update_options() { - ERR_FAIL_COND(shader_file.is_null()); if (shader_file->get_base_error() != String()) { @@ -202,7 +200,6 @@ void ShaderFileEditor::_update_options() { } void ShaderFileEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_WM_FOCUS_IN) { if (is_visible_in_tree() && shader_file.is_valid()) { _update_options(); @@ -211,7 +208,6 @@ void ShaderFileEditor::_notification(int p_what) { } void ShaderFileEditor::_editor_settings_changed() { - if (is_visible_in_tree() && shader_file.is_valid()) { _update_options(); } @@ -221,7 +217,6 @@ void ShaderFileEditor::_bind_methods() { } void ShaderFileEditor::edit(const Ref<RDShaderFile> &p_shader) { - if (p_shader.is_null()) { if (shader_file.is_valid()) { shader_file->disconnect("changed", callable_mp(this, &ShaderFileEditor::_shader_changed)); @@ -229,8 +224,9 @@ void ShaderFileEditor::edit(const Ref<RDShaderFile> &p_shader) { return; } - if (shader_file == p_shader) + if (shader_file == p_shader) { return; + } shader_file = p_shader; @@ -242,7 +238,6 @@ void ShaderFileEditor::edit(const Ref<RDShaderFile> &p_shader) { } void ShaderFileEditor::_shader_changed() { - if (is_visible_in_tree()) { _update_options(); } @@ -294,33 +289,29 @@ ShaderFileEditor::ShaderFileEditor(EditorNode *p_node) { } void ShaderFileEditorPlugin::edit(Object *p_object) { - RDShaderFile *s = Object::cast_to<RDShaderFile>(p_object); shader_editor->edit(s); } bool ShaderFileEditorPlugin::handles(Object *p_object) const { - RDShaderFile *shader = Object::cast_to<RDShaderFile>(p_object); return shader != nullptr; } void ShaderFileEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { button->show(); editor->make_bottom_panel_item_visible(shader_editor); } else { - button->hide(); - if (shader_editor->is_visible_in_tree()) + if (shader_editor->is_visible_in_tree()) { editor->hide_bottom_panel(); + } } } ShaderFileEditorPlugin::ShaderFileEditorPlugin(EditorNode *p_node) { - editor = p_node; shader_editor = memnew(ShaderFileEditor(p_node)); diff --git a/editor/plugins/shader_file_editor_plugin.h b/editor/plugins/shader_file_editor_plugin.h index 7df177a0d5..19617366b2 100644 --- a/editor/plugins/shader_file_editor_plugin.h +++ b/editor/plugins/shader_file_editor_plugin.h @@ -42,7 +42,6 @@ #include "servers/rendering/rendering_device_binds.h" class ShaderFileEditor : public PanelContainer { - GDCLASS(ShaderFileEditor, PanelContainer); Ref<RDShaderFile> shader_file; @@ -71,7 +70,6 @@ public: }; class ShaderFileEditorPlugin : public EditorPlugin { - GDCLASS(ShaderFileEditorPlugin, EditorPlugin); ShaderFileEditor *shader_editor; diff --git a/editor/plugins/skeleton_2d_editor_plugin.cpp b/editor/plugins/skeleton_2d_editor_plugin.cpp index c81d3f787e..a198e4ff8f 100644 --- a/editor/plugins/skeleton_2d_editor_plugin.cpp +++ b/editor/plugins/skeleton_2d_editor_plugin.cpp @@ -36,7 +36,6 @@ #include "thirdparty/misc/clipper.hpp" void Skeleton2DEditor::_node_removed(Node *p_node) { - if (p_node == node) { node = nullptr; options->hide(); @@ -44,19 +43,16 @@ void Skeleton2DEditor::_node_removed(Node *p_node) { } void Skeleton2DEditor::edit(Skeleton2D *p_sprite) { - node = p_sprite; } void Skeleton2DEditor::_menu_option(int p_option) { - if (!node) { return; } switch (p_option) { case MENU_OPTION_MAKE_REST: { - if (node->get_bone_count() == 0) { err_dialog->set_text(TTR("This skeleton has no bones, create some children Bone2D nodes.")); err_dialog->popup_centered(); @@ -95,7 +91,6 @@ void Skeleton2DEditor::_bind_methods() { } Skeleton2DEditor::Skeleton2DEditor() { - options = memnew(MenuButton); CanvasItemEditor::get_singleton()->add_control_to_menu_panel(options); @@ -115,28 +110,23 @@ Skeleton2DEditor::Skeleton2DEditor() { } void Skeleton2DEditorPlugin::edit(Object *p_object) { - sprite_editor->edit(Object::cast_to<Skeleton2D>(p_object)); } bool Skeleton2DEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("Skeleton2D"); } void Skeleton2DEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { sprite_editor->options->show(); } else { - sprite_editor->options->hide(); sprite_editor->edit(nullptr); } } Skeleton2DEditorPlugin::Skeleton2DEditorPlugin(EditorNode *p_node) { - editor = p_node; sprite_editor = memnew(Skeleton2DEditor); editor->get_viewport()->add_child(sprite_editor); diff --git a/editor/plugins/skeleton_2d_editor_plugin.h b/editor/plugins/skeleton_2d_editor_plugin.h index ebc6746b81..f1ba1a3612 100644 --- a/editor/plugins/skeleton_2d_editor_plugin.h +++ b/editor/plugins/skeleton_2d_editor_plugin.h @@ -37,7 +37,6 @@ #include "scene/gui/spin_box.h" class Skeleton2DEditor : public Control { - GDCLASS(Skeleton2DEditor, Control); enum Menu { @@ -65,7 +64,6 @@ public: }; class Skeleton2DEditorPlugin : public EditorPlugin { - GDCLASS(Skeleton2DEditorPlugin, EditorPlugin); Skeleton2DEditor *sprite_editor; diff --git a/editor/plugins/skeleton_3d_editor_plugin.cpp b/editor/plugins/skeleton_3d_editor_plugin.cpp index fac4cb19d8..c256acd17b 100644 --- a/editor/plugins/skeleton_3d_editor_plugin.cpp +++ b/editor/plugins/skeleton_3d_editor_plugin.cpp @@ -63,22 +63,18 @@ void Skeleton3DEditor::create_physical_skeleton() { bones_infos.resize(bc); for (int bone_id = 0; bc > bone_id; ++bone_id) { - const int parent = skeleton->get_bone_parent(bone_id); if (parent < 0) { - bones_infos.write[bone_id].relative_rest = skeleton->get_bone_rest(bone_id); } else { - const int parent_parent = skeleton->get_bone_parent(parent); bones_infos.write[bone_id].relative_rest = bones_infos[parent].relative_rest * skeleton->get_bone_rest(bone_id); /// create physical bone on parent if (!bones_infos[parent].physical_bone) { - bones_infos.write[parent].physical_bone = create_physical_bone(parent, bone_id, bones_infos); ur->create_action(TTR("Create physical bones")); @@ -93,7 +89,6 @@ void Skeleton3DEditor::create_physical_skeleton() { /// Create joint between parent of parent if (-1 != parent_parent) { - bones_infos[parent].physical_bone->set_joint_type(PhysicalBone3D::JOINT_TYPE_PIN); } } @@ -102,7 +97,6 @@ void Skeleton3DEditor::create_physical_skeleton() { } PhysicalBone3D *Skeleton3DEditor::create_physical_bone(int bone_id, int bone_child_id, const Vector<BoneInfo> &bones_infos) { - const Transform child_rest = skeleton->get_bone_rest(bone_child_id); const real_t half_height(child_rest.origin.length() * 0.5); @@ -131,7 +125,6 @@ PhysicalBone3D *Skeleton3DEditor::create_physical_bone(int bone_id, int bone_chi } void Skeleton3DEditor::edit(Skeleton3D *p_node) { - skeleton = p_node; } @@ -142,7 +135,6 @@ void Skeleton3DEditor::_notification(int p_what) { } void Skeleton3DEditor::_node_removed(Node *p_node) { - if (p_node == skeleton) { skeleton = nullptr; options->hide(); @@ -180,7 +172,6 @@ void Skeleton3DEditorPlugin::make_visible(bool p_visible) { if (p_visible) { skeleton_editor->options->show(); } else { - skeleton_editor->options->hide(); skeleton_editor->edit(nullptr); } diff --git a/editor/plugins/skeleton_3d_editor_plugin.h b/editor/plugins/skeleton_3d_editor_plugin.h index 1bcf27e2f2..af9ebb6246 100644 --- a/editor/plugins/skeleton_3d_editor_plugin.h +++ b/editor/plugins/skeleton_3d_editor_plugin.h @@ -75,7 +75,6 @@ public: }; class Skeleton3DEditorPlugin : public EditorPlugin { - GDCLASS(Skeleton3DEditorPlugin, EditorPlugin); EditorNode *editor; diff --git a/editor/plugins/skeleton_ik_3d_editor_plugin.cpp b/editor/plugins/skeleton_ik_3d_editor_plugin.cpp index a22534eac0..8fc789b94a 100644 --- a/editor/plugins/skeleton_ik_3d_editor_plugin.cpp +++ b/editor/plugins/skeleton_ik_3d_editor_plugin.cpp @@ -33,12 +33,13 @@ #include "scene/3d/skeleton_ik_3d.h" void SkeletonIK3DEditorPlugin::_play() { - - if (!skeleton_ik) + if (!skeleton_ik) { return; + } - if (!skeleton_ik->get_parent_skeleton()) + if (!skeleton_ik->get_parent_skeleton()) { return; + } if (play_btn->is_pressed()) { skeleton_ik->start(); @@ -49,7 +50,6 @@ void SkeletonIK3DEditorPlugin::_play() { } void SkeletonIK3DEditorPlugin::edit(Object *p_object) { - if (p_object != skeleton_ik) { if (skeleton_ik) { play_btn->set_pressed(false); @@ -58,30 +58,29 @@ void SkeletonIK3DEditorPlugin::edit(Object *p_object) { } SkeletonIK3D *s = Object::cast_to<SkeletonIK3D>(p_object); - if (!s) + if (!s) { return; + } skeleton_ik = s; } bool SkeletonIK3DEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("SkeletonIK3D"); } void SkeletonIK3DEditorPlugin::make_visible(bool p_visible) { - - if (p_visible) + if (p_visible) { play_btn->show(); - else + } else { play_btn->hide(); + } } void SkeletonIK3DEditorPlugin::_bind_methods() { } SkeletonIK3DEditorPlugin::SkeletonIK3DEditorPlugin(EditorNode *p_node) { - editor = p_node; play_btn = memnew(Button); play_btn->set_icon(editor->get_gui_base()->get_theme_icon("Play", "EditorIcons")); diff --git a/editor/plugins/skeleton_ik_3d_editor_plugin.h b/editor/plugins/skeleton_ik_3d_editor_plugin.h index 88472a2963..bd4c5ba93e 100644 --- a/editor/plugins/skeleton_ik_3d_editor_plugin.h +++ b/editor/plugins/skeleton_ik_3d_editor_plugin.h @@ -37,7 +37,6 @@ class SkeletonIK3D; class SkeletonIK3DEditorPlugin : public EditorPlugin { - GDCLASS(SkeletonIK3DEditorPlugin, EditorPlugin); SkeletonIK3D *skeleton_ik; diff --git a/editor/plugins/sprite_2d_editor_plugin.cpp b/editor/plugins/sprite_2d_editor_plugin.cpp index ab0f15d3d0..b21586a6b0 100644 --- a/editor/plugins/sprite_2d_editor_plugin.cpp +++ b/editor/plugins/sprite_2d_editor_plugin.cpp @@ -40,7 +40,6 @@ #include "thirdparty/misc/clipper.hpp" void Sprite2DEditor::_node_removed(Node *p_node) { - if (p_node == node) { node = nullptr; options->hide(); @@ -48,7 +47,6 @@ void Sprite2DEditor::_node_removed(Node *p_node) { } void Sprite2DEditor::edit(Sprite2D *p_sprite) { - node = p_sprite; } @@ -63,7 +61,6 @@ Vector<Vector2> expand(const Vector<Vector2> &points, const Rect2i &rect, float ClipperLib::PolyTree out; for (int i = 0; i < points.size(); i++) { - subj << ClipperLib::IntPoint(points[i].x * PRECISION, points[i].y * PRECISION); } ClipperLib::ClipperOffset co; @@ -104,7 +101,6 @@ Vector<Vector2> expand(const Vector<Vector2> &points, const Rect2i &rect, float int lasti = p2->Contour.size() - 1; Vector2 prev = Vector2(p2->Contour[lasti].X / PRECISION, p2->Contour[lasti].Y / PRECISION); for (uint64_t i = 0; i < p2->Contour.size(); i++) { - Vector2 cur = Vector2(p2->Contour[i].X / PRECISION, p2->Contour[i].Y / PRECISION); if (cur.distance_to(prev) > 0.5) { outPoints.push_back(cur); @@ -115,7 +111,6 @@ Vector<Vector2> expand(const Vector<Vector2> &points, const Rect2i &rect, float } void Sprite2DEditor::_menu_option(int p_option) { - if (!node) { return; } @@ -124,7 +119,6 @@ void Sprite2DEditor::_menu_option(int p_option) { switch (p_option) { case MENU_OPTION_CONVERT_TO_MESH_2D: { - debug_uv_dialog->get_ok()->set_text(TTR("Create Mesh2D")); debug_uv_dialog->set_title(TTR("Mesh2D Preview")); @@ -134,7 +128,6 @@ void Sprite2DEditor::_menu_option(int p_option) { } break; case MENU_OPTION_CONVERT_TO_POLYGON_2D: { - debug_uv_dialog->get_ok()->set_text(TTR("Create Polygon2D")); debug_uv_dialog->set_title(TTR("Polygon2D Preview")); @@ -143,7 +136,6 @@ void Sprite2DEditor::_menu_option(int p_option) { debug_uv->update(); } break; case MENU_OPTION_CREATE_COLLISION_POLY_2D: { - debug_uv_dialog->get_ok()->set_text(TTR("Create CollisionPolygon2D")); debug_uv_dialog->set_title(TTR("CollisionPolygon2D Preview")); @@ -153,7 +145,6 @@ void Sprite2DEditor::_menu_option(int p_option) { } break; case MENU_OPTION_CREATE_LIGHT_OCCLUDER_2D: { - debug_uv_dialog->get_ok()->set_text(TTR("Create LightOccluder2D")); debug_uv_dialog->set_title(TTR("LightOccluder2D Preview")); @@ -166,7 +157,6 @@ void Sprite2DEditor::_menu_option(int p_option) { } void Sprite2DEditor::_update_mesh_data() { - Ref<Texture2D> texture = node->get_texture(); if (texture.is_null()) { err_dialog->set_text(TTR("Sprite2D is empty!")); @@ -183,10 +173,11 @@ void Sprite2DEditor::_update_mesh_data() { Ref<Image> image = texture->get_data(); ERR_FAIL_COND(image.is_null()); Rect2 rect; - if (node->is_region()) + if (node->is_region()) { rect = node->get_region_rect(); - else + } else { rect.size = Size2(image->get_width(), image->get_height()); + } Ref<BitMap> bm; bm.instance(); @@ -218,7 +209,6 @@ void Sprite2DEditor::_update_mesh_data() { } if (selected_menu_item == MENU_OPTION_CONVERT_TO_MESH_2D) { - for (int j = 0; j < lines.size(); j++) { int index_ofs = computed_vertices.size(); @@ -229,13 +219,16 @@ void Sprite2DEditor::_update_mesh_data() { vtx -= rect.position; //offset by rect position //flip if flipped - if (node->is_flipped_h()) + if (node->is_flipped_h()) { vtx.x = rect.size.x - vtx.x - 1.0; - if (node->is_flipped_v()) + } + if (node->is_flipped_v()) { vtx.y = rect.size.y - vtx.y - 1.0; + } - if (node->is_centered()) + if (node->is_centered()) { vtx -= rect.size / 2.0; + } computed_vertices.push_back(vtx); } @@ -262,7 +255,6 @@ void Sprite2DEditor::_update_mesh_data() { outline_lines.resize(lines.size()); computed_outline_lines.resize(lines.size()); for (int pi = 0; pi < lines.size(); pi++) { - Vector<Vector2> ol; Vector<Vector2> col; @@ -277,13 +269,16 @@ void Sprite2DEditor::_update_mesh_data() { vtx -= rect.position; //offset by rect position //flip if flipped - if (node->is_flipped_h()) + if (node->is_flipped_h()) { vtx.x = rect.size.x - vtx.x - 1.0; - if (node->is_flipped_v()) + } + if (node->is_flipped_v()) { vtx.y = rect.size.y - vtx.y - 1.0; + } - if (node->is_centered()) + if (node->is_centered()) { vtx -= rect.size / 2.0; + } col.write[i] = vtx; } @@ -314,7 +309,6 @@ void Sprite2DEditor::_create_node() { } void Sprite2DEditor::_convert_to_mesh_2d_node() { - if (computed_vertices.size() < 3) { err_dialog->set_text(TTR("Invalid geometry, can't replace by mesh.")); err_dialog->popup_centered(); @@ -345,7 +339,6 @@ void Sprite2DEditor::_convert_to_mesh_2d_node() { } void Sprite2DEditor::_convert_to_polygon_2d_node() { - if (computed_outline_lines.empty()) { err_dialog->set_text(TTR("Invalid geometry, can't create polygon.")); err_dialog->popup_centered(); @@ -355,8 +348,9 @@ void Sprite2DEditor::_convert_to_polygon_2d_node() { Polygon2D *polygon_2d_instance = memnew(Polygon2D); int total_point_count = 0; - for (int i = 0; i < computed_outline_lines.size(); i++) + for (int i = 0; i < computed_outline_lines.size(); i++) { total_point_count += computed_outline_lines[i].size(); + } PackedVector2Array polygon; polygon.resize(total_point_count); @@ -372,7 +366,6 @@ void Sprite2DEditor::_convert_to_polygon_2d_node() { polys.resize(computed_outline_lines.size()); for (int i = 0; i < computed_outline_lines.size(); i++) { - Vector<Vector2> outline = computed_outline_lines[i]; Vector<Vector2> uv_outline = outline_lines[i]; @@ -404,7 +397,6 @@ void Sprite2DEditor::_convert_to_polygon_2d_node() { } void Sprite2DEditor::_create_collision_polygon_2d_node() { - if (computed_outline_lines.empty()) { err_dialog->set_text(TTR("Invalid geometry, can't create collision polygon.")); err_dialog->popup_centered(); @@ -412,7 +404,6 @@ void Sprite2DEditor::_create_collision_polygon_2d_node() { } for (int i = 0; i < computed_outline_lines.size(); i++) { - Vector<Vector2> outline = computed_outline_lines[i]; CollisionPolygon2D *collision_polygon_2d_instance = memnew(CollisionPolygon2D); @@ -428,7 +419,6 @@ void Sprite2DEditor::_create_collision_polygon_2d_node() { } void Sprite2DEditor::_create_light_occluder_2d_node() { - if (computed_outline_lines.empty()) { err_dialog->set_text(TTR("Invalid geometry, can't create light occluder.")); err_dialog->popup_centered(); @@ -436,7 +426,6 @@ void Sprite2DEditor::_create_light_occluder_2d_node() { } for (int i = 0; i < computed_outline_lines.size(); i++) { - Vector<Vector2> outline = computed_outline_lines[i]; Ref<OccluderPolygon2D> polygon; @@ -475,7 +464,6 @@ void Sprite2DEditor::_add_as_sibling_or_child(Node *p_own_node, Node *p_new_node } void Sprite2DEditor::_debug_uv_draw() { - Ref<Texture2D> tex = node->get_texture(); ERR_FAIL_COND(!tex.is_valid()); @@ -503,12 +491,10 @@ void Sprite2DEditor::_debug_uv_draw() { } void Sprite2DEditor::_bind_methods() { - ClassDB::bind_method("_add_as_sibling_or_child", &Sprite2DEditor::_add_as_sibling_or_child); } Sprite2DEditor::Sprite2DEditor() { - options = memnew(MenuButton); CanvasItemEditor::get_singleton()->add_control_to_menu_panel(options); @@ -577,28 +563,23 @@ Sprite2DEditor::Sprite2DEditor() { } void Sprite2DEditorPlugin::edit(Object *p_object) { - sprite_editor->edit(Object::cast_to<Sprite2D>(p_object)); } bool Sprite2DEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("Sprite2D"); } void Sprite2DEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { sprite_editor->options->show(); } else { - sprite_editor->options->hide(); sprite_editor->edit(nullptr); } } Sprite2DEditorPlugin::Sprite2DEditorPlugin(EditorNode *p_node) { - editor = p_node; sprite_editor = memnew(Sprite2DEditor); editor->get_viewport()->add_child(sprite_editor); diff --git a/editor/plugins/sprite_2d_editor_plugin.h b/editor/plugins/sprite_2d_editor_plugin.h index 0add77843b..c2b942fd82 100644 --- a/editor/plugins/sprite_2d_editor_plugin.h +++ b/editor/plugins/sprite_2d_editor_plugin.h @@ -37,7 +37,6 @@ #include "scene/gui/spin_box.h" class Sprite2DEditor : public Control { - GDCLASS(Sprite2DEditor, Control); enum Menu { @@ -97,7 +96,6 @@ public: }; class Sprite2DEditorPlugin : public EditorPlugin { - GDCLASS(Sprite2DEditorPlugin, EditorPlugin); Sprite2DEditor *sprite_editor; diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp index 34ff34d45b..859fec1628 100644 --- a/editor/plugins/sprite_frames_editor_plugin.cpp +++ b/editor/plugins/sprite_frames_editor_plugin.cpp @@ -41,7 +41,6 @@ void SpriteFramesEditor::_gui_input(Ref<InputEvent> p_event) { } void SpriteFramesEditor::_open_sprite_sheet() { - file_split_sheet->clear_filters(); List<String> extensions; ResourceLoader::get_recognized_extensions_for_type("Texture2D", &extensions); @@ -53,7 +52,6 @@ void SpriteFramesEditor::_open_sprite_sheet() { } void SpriteFramesEditor::_sheet_preview_draw() { - Size2i size = split_sheet_preview->get_size(); int h = split_sheet_h->get_value(); int v = split_sheet_v->get_value(); @@ -61,13 +59,11 @@ void SpriteFramesEditor::_sheet_preview_draw() { int height = size.height / v; const float a = 0.3; for (int i = 1; i < h; i++) { - int x = i * width; split_sheet_preview->draw_line(Point2(x, 0), Point2(x, size.height), Color(1, 1, 1, a)); split_sheet_preview->draw_line(Point2(x + 1, 0), Point2(x + 1, size.height), Color(0, 0, 0, a)); for (int j = 1; j < v; j++) { - int y = j * height; split_sheet_preview->draw_line(Point2(0, y), Point2(size.width, y), Color(1, 1, 1, a)); @@ -102,8 +98,8 @@ void SpriteFramesEditor::_sheet_preview_draw() { split_sheet_dialog->get_ok()->set_disabled(false); split_sheet_dialog->get_ok()->set_text(vformat(TTR("Add %d Frame(s)"), frames_selected.size())); } -void SpriteFramesEditor::_sheet_preview_input(const Ref<InputEvent> &p_event) { +void SpriteFramesEditor::_sheet_preview_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { @@ -145,7 +141,6 @@ void SpriteFramesEditor::_sheet_preview_input(const Ref<InputEvent> &p_event) { } void SpriteFramesEditor::_sheet_add_frames() { - Size2i size = split_sheet_preview->get_size(); int h = split_sheet_h->get_value(); int v = split_sheet_v->get_value(); @@ -158,8 +153,9 @@ void SpriteFramesEditor::_sheet_add_frames() { Rect2 region_rect = Rect2(); - if (atlas_source && atlas_source->get_atlas().is_valid()) + if (atlas_source && atlas_source->get_atlas().is_valid()) { region_rect = atlas_source->get_region(); + } for (Set<int>::Element *E = frames_selected.front(); E; E = E->next()) { int idx = E->get(); @@ -185,7 +181,6 @@ void SpriteFramesEditor::_sheet_add_frames() { } void SpriteFramesEditor::_sheet_select_clear_all_frames() { - bool should_clear = true; for (int i = 0; i < split_sheet_h->get_value() * split_sheet_v->get_value(); i++) { if (!frames_selected.has(i)) { @@ -201,14 +196,12 @@ void SpriteFramesEditor::_sheet_select_clear_all_frames() { } void SpriteFramesEditor::_sheet_spin_changed(double) { - frames_selected.clear(); last_frame_selected = -1; split_sheet_preview->update(); } void SpriteFramesEditor::_prepare_sprite_sheet(const String &p_file) { - Ref<Resource> texture = ResourceLoader::load(p_file); if (!texture.is_valid()) { EditorNode::get_singleton()->show_warning(TTR("Unable to load images")); @@ -227,7 +220,6 @@ void SpriteFramesEditor::_prepare_sprite_sheet(const String &p_file) { } void SpriteFramesEditor::_notification(int p_what) { - switch (p_what) { case NOTIFICATION_ENTER_TREE: { load->set_icon(get_theme_icon("Load", "EditorIcons")); @@ -253,13 +245,11 @@ void SpriteFramesEditor::_notification(int p_what) { } void SpriteFramesEditor::_file_load_request(const Vector<String> &p_path, int p_at_pos) { - ERR_FAIL_COND(!frames->has_animation(edited_anim)); List<Ref<Texture2D>> resources; for (int i = 0; i < p_path.size(); i++) { - Ref<Texture2D> resource; resource = ResourceLoader::load(p_path[i]); @@ -286,7 +276,6 @@ void SpriteFramesEditor::_file_load_request(const Vector<String> &p_path, int p_ int count = 0; for (List<Ref<Texture2D>>::Element *E = resources.front(); E; E = E->next()) { - undo_redo->add_do_method(frames, "add_frame", edited_anim, E->get(), p_at_pos == -1 ? -1 : p_at_pos + count); undo_redo->add_undo_method(frames, "remove_frame", edited_anim, p_at_pos == -1 ? fc : p_at_pos); count++; @@ -298,15 +287,15 @@ void SpriteFramesEditor::_file_load_request(const Vector<String> &p_path, int p_ } void SpriteFramesEditor::_load_pressed() { - ERR_FAIL_COND(!frames->has_animation(edited_anim)); loading_scene = false; file->clear_filters(); List<String> extensions; ResourceLoader::get_recognized_extensions_for_type("Texture2D", &extensions); - for (int i = 0; i < extensions.size(); i++) + for (int i = 0; i < extensions.size(); i++) { file->add_filter("*." + extensions[i]); + } file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILES); @@ -314,7 +303,6 @@ void SpriteFramesEditor::_load_pressed() { } void SpriteFramesEditor::_paste_pressed() { - ERR_FAIL_COND(!frames->has_animation(edited_anim)); Ref<Texture2D> r = EditorSettings::get_singleton()->get_resource_clipboard(); @@ -338,8 +326,9 @@ void SpriteFramesEditor::_paste_pressed() { void SpriteFramesEditor::_copy_pressed() { ERR_FAIL_COND(!frames->has_animation(edited_anim)); - if (tree->get_current() < 0) + if (tree->get_current() < 0) { return; + } Ref<Texture2D> r = frames->get_frame(edited_anim, tree->get_current()); if (!r.is_valid()) { return; @@ -349,13 +338,11 @@ void SpriteFramesEditor::_copy_pressed() { } void SpriteFramesEditor::_empty_pressed() { - ERR_FAIL_COND(!frames->has_animation(edited_anim)); int from = -1; if (tree->get_current() >= 0) { - from = tree->get_current(); sel = from; @@ -374,13 +361,11 @@ void SpriteFramesEditor::_empty_pressed() { } void SpriteFramesEditor::_empty2_pressed() { - ERR_FAIL_COND(!frames->has_animation(edited_anim)); int from = -1; if (tree->get_current() >= 0) { - from = tree->get_current(); sel = from; @@ -399,15 +384,16 @@ void SpriteFramesEditor::_empty2_pressed() { } void SpriteFramesEditor::_up_pressed() { - ERR_FAIL_COND(!frames->has_animation(edited_anim)); - if (tree->get_current() < 0) + if (tree->get_current() < 0) { return; + } int to_move = tree->get_current(); - if (to_move < 1) + if (to_move < 1) { return; + } sel = to_move; sel -= 1; @@ -423,15 +409,16 @@ void SpriteFramesEditor::_up_pressed() { } void SpriteFramesEditor::_down_pressed() { - ERR_FAIL_COND(!frames->has_animation(edited_anim)); - if (tree->get_current() < 0) + if (tree->get_current() < 0) { return; + } int to_move = tree->get_current(); - if (to_move < 0 || to_move >= frames->get_frame_count(edited_anim) - 1) + if (to_move < 0 || to_move >= frames->get_frame_count(edited_anim) - 1) { return; + } sel = to_move; sel += 1; @@ -447,11 +434,11 @@ void SpriteFramesEditor::_down_pressed() { } void SpriteFramesEditor::_delete_pressed() { - ERR_FAIL_COND(!frames->has_animation(edited_anim)); - if (tree->get_current() < 0) + if (tree->get_current() < 0) { return; + } int to_delete = tree->get_current(); if (to_delete < 0 || to_delete >= frames->get_frame_count(edited_anim)) { @@ -467,14 +454,15 @@ void SpriteFramesEditor::_delete_pressed() { } void SpriteFramesEditor::_animation_select() { - - if (updating) + if (updating) { return; + } if (frames->has_animation(edited_anim)) { double value = anim_speed->get_line_edit()->get_text().to_double(); - if (!Math::is_equal_approx(value, frames->get_animation_speed(edited_anim))) + if (!Math::is_equal_approx(value, frames->get_animation_speed(edited_anim))) { _animation_fps_changed(value); + } } TreeItem *selected = animations->get_selected(); @@ -484,12 +472,13 @@ void SpriteFramesEditor::_animation_select() { } static void _find_anim_sprites(Node *p_node, List<Node *> *r_nodes, Ref<SpriteFrames> p_sfames) { - Node *edited = EditorNode::get_singleton()->get_edited_scene(); - if (!edited) + if (!edited) { return; - if (p_node != edited && p_node->get_owner() != edited) + } + if (p_node != edited && p_node->get_owner() != edited) { return; + } { AnimatedSprite2D *as = Object::cast_to<AnimatedSprite2D>(p_node); @@ -511,21 +500,24 @@ static void _find_anim_sprites(Node *p_node, List<Node *> *r_nodes, Ref<SpriteFr } void SpriteFramesEditor::_animation_name_edited() { - - if (updating) + if (updating) { return; + } - if (!frames->has_animation(edited_anim)) + if (!frames->has_animation(edited_anim)) { return; + } TreeItem *edited = animations->get_edited(); - if (!edited) + if (!edited) { return; + } String new_name = edited->get_text(0); - if (new_name == String(edited_anim)) + if (new_name == String(edited_anim)) { return; + } new_name = new_name.replace("/", "_").replace(",", " "); @@ -544,7 +536,6 @@ void SpriteFramesEditor::_animation_name_edited() { undo_redo->add_undo_method(frames, "rename_animation", name, edited_anim); for (List<Node *>::Element *E = nodes.front(); E; E = E->next()) { - String current = E->get()->call("get_animation"); undo_redo->add_do_method(E->get(), "set_animation", name); undo_redo->add_undo_method(E->get(), "set_animation", edited_anim); @@ -559,7 +550,6 @@ void SpriteFramesEditor::_animation_name_edited() { } void SpriteFramesEditor::_animation_add() { - String name = "New Anim"; int counter = 0; while (frames->has_animation(name)) { @@ -577,7 +567,6 @@ void SpriteFramesEditor::_animation_add() { undo_redo->add_undo_method(this, "_update_library"); for (List<Node *>::Element *E = nodes.front(); E; E = E->next()) { - String current = E->get()->call("get_animation"); undo_redo->add_do_method(E->get(), "set_animation", name); undo_redo->add_undo_method(E->get(), "set_animation", current); @@ -590,19 +579,19 @@ void SpriteFramesEditor::_animation_add() { } void SpriteFramesEditor::_animation_remove() { - - if (updating) + if (updating) { return; + } - if (!frames->has_animation(edited_anim)) + if (!frames->has_animation(edited_anim)) { return; + } delete_dialog->set_text(TTR("Delete Animation?")); delete_dialog->popup_centered(); } void SpriteFramesEditor::_animation_remove_confirmed() { - undo_redo->create_action(TTR("Remove Animation")); undo_redo->add_do_method(frames, "remove_animation", edited_anim); undo_redo->add_undo_method(frames, "add_animation", edited_anim); @@ -622,9 +611,9 @@ void SpriteFramesEditor::_animation_remove_confirmed() { } void SpriteFramesEditor::_animation_loop_changed() { - - if (updating) + if (updating) { return; + } undo_redo->create_action(TTR("Change Animation Loop")); undo_redo->add_do_method(frames, "set_animation_loop", edited_anim, anim_loop->is_pressed()); @@ -635,9 +624,9 @@ void SpriteFramesEditor::_animation_loop_changed() { } void SpriteFramesEditor::_animation_fps_changed(double p_value) { - - if (updating) + if (updating) { return; + } undo_redo->create_action(TTR("Change Animation FPS"), UndoRedo::MERGE_ENDS); undo_redo->add_do_method(frames, "set_animation_speed", edited_anim, p_value); @@ -649,7 +638,6 @@ void SpriteFramesEditor::_animation_fps_changed(double p_value) { } void SpriteFramesEditor::_update_library(bool p_skip_selector) { - updating = true; if (!p_skip_selector) { @@ -664,7 +652,6 @@ void SpriteFramesEditor::_update_library(bool p_skip_selector) { anim_names.sort_custom<StringName::AlphCompare>(); for (List<StringName>::Element *E = anim_names.front(); E; E = E->next()) { - String name = E->get(); TreeItem *it = animations->create_item(anim_root); @@ -687,18 +674,17 @@ void SpriteFramesEditor::_update_library(bool p_skip_selector) { return; } - if (sel >= frames->get_frame_count(edited_anim)) + if (sel >= frames->get_frame_count(edited_anim)) { sel = frames->get_frame_count(edited_anim) - 1; - else if (sel < 0 && frames->get_frame_count(edited_anim)) + } else if (sel < 0 && frames->get_frame_count(edited_anim)) { sel = 0; + } for (int i = 0; i < frames->get_frame_count(edited_anim); i++) { - String name; Ref<Texture2D> icon; if (frames->get_frame(edited_anim, i).is_null()) { - name = itos(i) + ": " + TTR("(empty)"); } else { @@ -707,10 +693,12 @@ void SpriteFramesEditor::_update_library(bool p_skip_selector) { } tree->add_item(name, icon); - if (frames->get_frame(edited_anim, i).is_valid()) + if (frames->get_frame(edited_anim, i).is_valid()) { tree->set_item_tooltip(tree->get_item_count() - 1, frames->get_frame(edited_anim, i)->get_path()); - if (sel == i) + } + if (sel == i) { tree->select(tree->get_item_count() - 1); + } } anim_speed->set_value(frames->get_animation_speed(edited_anim)); @@ -721,16 +709,14 @@ void SpriteFramesEditor::_update_library(bool p_skip_selector) { } void SpriteFramesEditor::edit(SpriteFrames *p_frames) { - - if (frames == p_frames) + if (frames == p_frames) { return; + } frames = p_frames; if (p_frames) { - if (!p_frames->has_animation(edited_anim)) { - List<StringName> anim_names; frames->get_animation_list(&anim_names); anim_names.sort_custom<StringName::AlphCompare>(); @@ -743,25 +729,26 @@ void SpriteFramesEditor::edit(SpriteFrames *p_frames) { _update_library(); } else { - hide(); } } Variant SpriteFramesEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) { - - if (!frames->has_animation(edited_anim)) + if (!frames->has_animation(edited_anim)) { return false; + } int idx = tree->get_item_at_position(p_point, true); - if (idx < 0 || idx >= frames->get_frame_count(edited_anim)) + if (idx < 0 || idx >= frames->get_frame_count(edited_anim)) { return Variant(); + } RES frame = frames->get_frame(edited_anim, idx); - if (frame.is_null()) + if (frame.is_null()) { return Variant(); + } Dictionary drag_data = EditorNode::get_singleton()->drag_resource(frame, p_from); drag_data["frame"] = idx; // store the frame, in case we want to reorder frames inside 'drop_data_fw' @@ -769,15 +756,16 @@ Variant SpriteFramesEditor::get_drag_data_fw(const Point2 &p_point, Control *p_f } bool SpriteFramesEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { - Dictionary d = p_data; - if (!d.has("type")) + if (!d.has("type")) { return false; + } // reordering frames - if (d.has("from") && (Object *)(d["from"]) == tree) + if (d.has("from") && (Object *)(d["from"]) == tree) { return true; + } if (String(d["type"]) == "resource" && d.has("resource")) { RES r = d["resource"]; @@ -785,17 +773,16 @@ bool SpriteFramesEditor::can_drop_data_fw(const Point2 &p_point, const Variant & Ref<Texture2D> texture = r; if (texture.is_valid()) { - return true; } } if (String(d["type"]) == "files") { - Vector<String> files = d["files"]; - if (files.size() == 0) + if (files.size() == 0) { return false; + } for (int i = 0; i < files.size(); i++) { String file = files[i]; @@ -812,14 +799,15 @@ bool SpriteFramesEditor::can_drop_data_fw(const Point2 &p_point, const Variant & } void SpriteFramesEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { - - if (!can_drop_data_fw(p_point, p_data, p_from)) + if (!can_drop_data_fw(p_point, p_data, p_from)) { return; + } Dictionary d = p_data; - if (!d.has("type")) + if (!d.has("type")) { return; + } int at_pos = tree->get_item_at_position(p_point, true); @@ -830,13 +818,15 @@ void SpriteFramesEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da if (texture.is_valid()) { bool reorder = false; - if (d.has("from") && (Object *)(d["from"]) == tree) + if (d.has("from") && (Object *)(d["from"]) == tree) { reorder = true; + } if (reorder) { //drop is from reordering frames int from_frame = -1; - if (d.has("frame")) + if (d.has("frame")) { from_frame = d["frame"]; + } undo_redo->create_action(TTR("Move Frame")); undo_redo->add_do_method(frames, "remove_frame", edited_anim, from_frame == -1 ? frames->get_frame_count(edited_anim) : from_frame); @@ -858,7 +848,6 @@ void SpriteFramesEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } if (String(d["type"]) == "files") { - Vector<String> files = d["files"]; _file_load_request(files, at_pos); @@ -866,7 +855,6 @@ void SpriteFramesEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } void SpriteFramesEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_update_library", "skipsel"), &SpriteFramesEditor::_update_library, DEFVAL(false)); ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &SpriteFramesEditor::get_drag_data_fw); ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &SpriteFramesEditor::can_drop_data_fw); @@ -874,7 +862,6 @@ void SpriteFramesEditor::_bind_methods() { } SpriteFramesEditor::SpriteFramesEditor() { - VBoxContainer *vbc_animlist = memnew(VBoxContainer); add_child(vbc_animlist); vbc_animlist->set_custom_minimum_size(Size2(150, 0) * EDSCALE); @@ -1071,7 +1058,6 @@ SpriteFramesEditor::SpriteFramesEditor() { } void SpriteFramesEditorPlugin::edit(Object *p_object) { - frames_editor->set_undo_redo(&get_undo_redo()); SpriteFrames *s; @@ -1083,7 +1069,6 @@ void SpriteFramesEditorPlugin::edit(Object *p_object) { if (animated_sprite_3d) { s = *animated_sprite_3d->get_sprite_frames(); } else { - s = Object::cast_to<SpriteFrames>(p_object); } } @@ -1092,7 +1077,6 @@ void SpriteFramesEditorPlugin::edit(Object *p_object) { } bool SpriteFramesEditorPlugin::handles(Object *p_object) const { - AnimatedSprite2D *animated_sprite = Object::cast_to<AnimatedSprite2D>(p_object); AnimatedSprite3D *animated_sprite_3d = Object::cast_to<AnimatedSprite3D>(p_object); if (animated_sprite && *animated_sprite->get_sprite_frames()) { @@ -1105,20 +1089,18 @@ bool SpriteFramesEditorPlugin::handles(Object *p_object) const { } void SpriteFramesEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { button->show(); editor->make_bottom_panel_item_visible(frames_editor); } else { - button->hide(); - if (frames_editor->is_visible_in_tree()) + if (frames_editor->is_visible_in_tree()) { editor->hide_bottom_panel(); + } } } SpriteFramesEditorPlugin::SpriteFramesEditorPlugin(EditorNode *p_node) { - editor = p_node; frames_editor = memnew(SpriteFramesEditor); frames_editor->set_custom_minimum_size(Size2(0, 300) * EDSCALE); diff --git a/editor/plugins/sprite_frames_editor_plugin.h b/editor/plugins/sprite_frames_editor_plugin.h index 89d9bc6fd3..45646eb9e4 100644 --- a/editor/plugins/sprite_frames_editor_plugin.h +++ b/editor/plugins/sprite_frames_editor_plugin.h @@ -41,7 +41,6 @@ #include "scene/gui/tree.h" class SpriteFramesEditor : public HSplitContainer { - GDCLASS(SpriteFramesEditor, HSplitContainer); ToolButton *load; @@ -134,7 +133,6 @@ public: }; class SpriteFramesEditorPlugin : public EditorPlugin { - GDCLASS(SpriteFramesEditorPlugin, EditorPlugin); SpriteFramesEditor *frames_editor; diff --git a/editor/plugins/style_box_editor_plugin.cpp b/editor/plugins/style_box_editor_plugin.cpp index eb6e261305..3641052a4e 100644 --- a/editor/plugins/style_box_editor_plugin.cpp +++ b/editor/plugins/style_box_editor_plugin.cpp @@ -33,28 +33,28 @@ #include "editor/editor_scale.h" bool EditorInspectorPluginStyleBox::can_handle(Object *p_object) { - return Object::cast_to<StyleBox>(p_object) != nullptr; } void EditorInspectorPluginStyleBox::parse_begin(Object *p_object) { - Ref<StyleBox> sb = Ref<StyleBox>(Object::cast_to<StyleBox>(p_object)); StyleBoxPreview *preview = memnew(StyleBoxPreview); preview->edit(sb); add_custom_control(preview); } + bool EditorInspectorPluginStyleBox::parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide) { return false; //do not want } + void EditorInspectorPluginStyleBox::parse_end() { } void StyleBoxPreview::edit(const Ref<StyleBox> &p_stylebox) { - - if (stylebox.is_valid()) + if (stylebox.is_valid()) { stylebox->disconnect("changed", callable_mp(this, &StyleBoxPreview::_sb_changed)); + } stylebox = p_stylebox; if (p_stylebox.is_valid()) { preview->add_theme_style_override("panel", stylebox); @@ -64,7 +64,6 @@ void StyleBoxPreview::edit(const Ref<StyleBox> &p_stylebox) { } void StyleBoxPreview::_sb_changed() { - preview->update(); } @@ -93,7 +92,6 @@ StyleBoxPreview::StyleBoxPreview() { } StyleBoxEditorPlugin::StyleBoxEditorPlugin(EditorNode *p_node) { - Ref<EditorInspectorPluginStyleBox> inspector_plugin; inspector_plugin.instance(); add_inspector_plugin(inspector_plugin); diff --git a/editor/plugins/style_box_editor_plugin.h b/editor/plugins/style_box_editor_plugin.h index 1eea9260b2..d9958d42e6 100644 --- a/editor/plugins/style_box_editor_plugin.h +++ b/editor/plugins/style_box_editor_plugin.h @@ -38,7 +38,6 @@ #include "scene/resources/style_box.h" class StyleBoxPreview : public VBoxContainer { - GDCLASS(StyleBoxPreview, VBoxContainer); Control *preview; @@ -67,7 +66,6 @@ public: }; class StyleBoxEditorPlugin : public EditorPlugin { - GDCLASS(StyleBoxEditorPlugin, EditorPlugin); public: diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp index 2786a568ea..3ceb9bfd82 100644 --- a/editor/plugins/text_editor.cpp +++ b/editor/plugins/text_editor.cpp @@ -70,7 +70,6 @@ void TextEditor::_change_syntax_highlighter(int p_idx) { } void TextEditor::_load_theme_settings() { - TextEdit *text_edit = code_editor->get_text_edit(); text_edit->clear_colors(); @@ -164,7 +163,6 @@ String TextEditor::get_name() { } Ref<Texture2D> TextEditor::get_theme_icon() { - return EditorNode::get_singleton()->get_object_icon(text_file.operator->(), ""); } @@ -195,7 +193,6 @@ void TextEditor::get_breakpoints(List<int> *p_breakpoints) { } void TextEditor::reload_text() { - ERR_FAIL_COND(text_file.is_null()); TextEdit *te = code_editor->get_text_edit(); @@ -221,7 +218,6 @@ void TextEditor::_validate_script() { } void TextEditor::_update_bookmark_list() { - bookmarks_menu->clear(); bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE); @@ -249,7 +245,6 @@ void TextEditor::_update_bookmark_list() { } void TextEditor::_bookmark_item_pressed(int p_idx) { - if (p_idx < 4) { // Any item before the separator. _edit_option(bookmarks_menu->get_item_id(p_idx)); } else { @@ -262,17 +257,14 @@ void TextEditor::apply_code() { } bool TextEditor::is_unsaved() { - return code_editor->get_text_edit()->get_version() != code_editor->get_text_edit()->get_saved_version(); } Variant TextEditor::get_edit_state() { - return code_editor->get_edit_state(); } void TextEditor::set_edit_state(const Variant &p_state) { - code_editor->set_edit_state(p_state); Dictionary state = p_state; @@ -285,42 +277,34 @@ void TextEditor::set_edit_state(const Variant &p_state) { } void TextEditor::trim_trailing_whitespace() { - code_editor->trim_trailing_whitespace(); } void TextEditor::insert_final_newline() { - code_editor->insert_final_newline(); } void TextEditor::convert_indent_to_spaces() { - code_editor->convert_indent_to_spaces(); } void TextEditor::convert_indent_to_tabs() { - code_editor->convert_indent_to_tabs(); } void TextEditor::tag_saved_version() { - code_editor->get_text_edit()->tag_saved_version(); } void TextEditor::goto_line(int p_line, bool p_with_error) { - code_editor->goto_line(p_line); } void TextEditor::goto_line_selection(int p_line, int p_begin, int p_end) { - code_editor->goto_line_selection(p_line, p_begin, p_end); } void TextEditor::set_executing_line(int p_line) { - code_editor->set_executing_line(p_line); } @@ -329,12 +313,10 @@ void TextEditor::clear_executing_line() { } void TextEditor::ensure_focus() { - code_editor->get_text_edit()->grab_focus(); } Vector<String> TextEditor::get_functions() { - return Vector<String>(); } @@ -343,17 +325,14 @@ bool TextEditor::show_members_overview() { } void TextEditor::update_settings() { - code_editor->update_editor_settings(); } void TextEditor::set_tooltip_request_func(String p_method, Object *p_obj) { - code_editor->get_text_edit()->set_tooltip_request_func(p_obj, p_method, this); } Control *TextEditor::get_edit_menu() { - return edit_hb; } @@ -362,7 +341,6 @@ void TextEditor::clear_edit_menu() { } void TextEditor::_notification(int p_what) { - switch (p_what) { case NOTIFICATION_READY: _load_theme_settings(); @@ -375,116 +353,90 @@ void TextEditor::_edit_option(int p_op) { switch (p_op) { case EDIT_UNDO: { - tx->undo(); tx->call_deferred("grab_focus"); } break; case EDIT_REDO: { - tx->redo(); tx->call_deferred("grab_focus"); } break; case EDIT_CUT: { - tx->cut(); tx->call_deferred("grab_focus"); } break; case EDIT_COPY: { - tx->copy(); tx->call_deferred("grab_focus"); } break; case EDIT_PASTE: { - tx->paste(); tx->call_deferred("grab_focus"); } break; case EDIT_SELECT_ALL: { - tx->select_all(); tx->call_deferred("grab_focus"); } break; case EDIT_MOVE_LINE_UP: { - code_editor->move_lines_up(); } break; case EDIT_MOVE_LINE_DOWN: { - code_editor->move_lines_down(); } break; case EDIT_INDENT_LEFT: { - tx->indent_left(); } break; case EDIT_INDENT_RIGHT: { - tx->indent_right(); } break; case EDIT_DELETE_LINE: { - code_editor->delete_lines(); } break; case EDIT_CLONE_DOWN: { - code_editor->clone_lines_down(); } break; case EDIT_TOGGLE_FOLD_LINE: { - tx->toggle_fold_line(tx->cursor_get_line()); tx->update(); } break; case EDIT_FOLD_ALL_LINES: { - tx->fold_all_lines(); tx->update(); } break; case EDIT_UNFOLD_ALL_LINES: { - tx->unhide_all_lines(); tx->update(); } break; case EDIT_TRIM_TRAILING_WHITESAPCE: { - trim_trailing_whitespace(); } break; case EDIT_CONVERT_INDENT_TO_SPACES: { - convert_indent_to_spaces(); } break; case EDIT_CONVERT_INDENT_TO_TABS: { - convert_indent_to_tabs(); } break; case EDIT_TO_UPPERCASE: { - _convert_case(CodeTextEditor::UPPER); } break; case EDIT_TO_LOWERCASE: { - _convert_case(CodeTextEditor::LOWER); } break; case EDIT_CAPITALIZE: { - _convert_case(CodeTextEditor::CAPITALIZE); } break; case SEARCH_FIND: { - code_editor->get_find_replace_bar()->popup_search(); } break; case SEARCH_FIND_NEXT: { - code_editor->get_find_replace_bar()->search_next(); } break; case SEARCH_FIND_PREV: { - code_editor->get_find_replace_bar()->search_prev(); } break; case SEARCH_REPLACE: { - code_editor->get_find_replace_bar()->popup_replace(); } break; case SEARCH_IN_FILES: { - String selected_text = code_editor->get_text_edit()->get_selection_text(); // Yep, because it doesn't make sense to instance this dialog for every single script open... @@ -492,36 +444,29 @@ void TextEditor::_edit_option(int p_op) { emit_signal("search_in_files_requested", selected_text); } break; case REPLACE_IN_FILES: { - String selected_text = code_editor->get_text_edit()->get_selection_text(); emit_signal("replace_in_files_requested", selected_text); } break; case SEARCH_GOTO_LINE: { - goto_line_dialog->popup_find_line(tx); } break; case BOOKMARK_TOGGLE: { - code_editor->toggle_bookmark(); } break; case BOOKMARK_GOTO_NEXT: { - code_editor->goto_next_bookmark(); } break; case BOOKMARK_GOTO_PREV: { - code_editor->goto_prev_bookmark(); } break; case BOOKMARK_REMOVE_ALL: { - code_editor->remove_all_bookmarks(); } break; } } void TextEditor::_convert_case(CodeTextEditor::CaseStyle p_case) { - code_editor->convert_case(p_case); } @@ -529,7 +474,6 @@ void TextEditor::_bind_methods() { } static ScriptEditorBase *create_editor(const RES &p_resource) { - if (Object::cast_to<TextFile>(*p_resource)) { return memnew(TextEditor); } @@ -537,17 +481,14 @@ static ScriptEditorBase *create_editor(const RES &p_resource) { } void TextEditor::register_editor() { - ScriptEditor::register_create_script_editor_function(create_editor); } void TextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { - Ref<InputEventMouseButton> mb = ev; if (mb.is_valid()) { if (mb->get_button_index() == BUTTON_RIGHT) { - int col, row; TextEdit *tx = code_editor->get_text_edit(); tx->_get_mouse_pos(mb->get_global_position() - tx->get_global_position(), row, col); @@ -558,7 +499,6 @@ void TextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { if (tx->is_right_click_moving_caret()) { if (tx->is_selection_active()) { - int from_line = tx->get_selection_from_line(); int to_line = tx->get_selection_to_line(); int from_column = tx->get_selection_from_column(); @@ -591,7 +531,6 @@ void TextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { } void TextEditor::_make_context_menu(bool p_selection, bool p_can_fold, bool p_is_folded, Vector2 p_position) { - context_menu->clear(); if (p_selection) { context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT); @@ -613,8 +552,9 @@ void TextEditor::_make_context_menu(bool p_selection, bool p_can_fold, bool p_is context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_to_uppercase"), EDIT_TO_UPPERCASE); context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_to_lowercase"), EDIT_TO_LOWERCASE); } - if (p_can_fold || p_is_folded) + if (p_can_fold || p_is_folded) { context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_fold_line"), EDIT_TOGGLE_FOLD_LINE); + } context_menu->set_position(get_global_transform().xform(p_position)); context_menu->set_size(Vector2(1, 1)); diff --git a/editor/plugins/text_editor.h b/editor/plugins/text_editor.h index b41e11c3aa..9d9025a2c4 100644 --- a/editor/plugins/text_editor.h +++ b/editor/plugins/text_editor.h @@ -34,7 +34,6 @@ #include "script_editor_plugin.h" class TextEditor : public ScriptEditorBase { - GDCLASS(TextEditor, ScriptEditorBase); private: diff --git a/editor/plugins/texture_editor_plugin.cpp b/editor/plugins/texture_editor_plugin.cpp index 7a3e571f16..b728a6700c 100644 --- a/editor/plugins/texture_editor_plugin.cpp +++ b/editor/plugins/texture_editor_plugin.cpp @@ -38,14 +38,11 @@ void TextureEditor::_gui_input(Ref<InputEvent> p_event) { } void TextureEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_READY) { - //get_scene()->connect("node_removed",this,"_node_removed"); } if (p_what == NOTIFICATION_DRAW) { - Ref<Texture2D> checkerboard = get_theme_icon("Checkerboard", "EditorIcons"); Size2 size = get_size(); @@ -60,10 +57,12 @@ void TextureEditor::_notification(int p_what) { } // Prevent the texture from being unpreviewable after the rescale, so that we can still see something - if (tex_height <= 0) + if (tex_height <= 0) { tex_height = 1; - if (tex_width <= 0) + } + if (tex_width <= 0) { tex_width = 1; + } int ofs_x = (size.width - tex_width) / 2; int ofs_y = (size.height - tex_height) / 2; @@ -94,8 +93,9 @@ void TextureEditor::_notification(int p_what) { Size2 rect = font->get_string_size(text); Vector2 draw_from = size - rect + Size2(-2, font->get_ascent() - 2); - if (draw_from.x < 0) + if (draw_from.x < 0) { draw_from.x = 0; + } draw_string(font, draw_from + Vector2(2, 2), text, Color(0, 0, 0, 0.5), size.width); draw_string(font, draw_from - Vector2(2, 2), text, Color(0, 0, 0, 0.5), size.width); @@ -104,16 +104,16 @@ void TextureEditor::_notification(int p_what) { } void TextureEditor::_changed_callback(Object *p_changed, const char *p_prop) { - - if (!is_visible()) + if (!is_visible()) { return; + } update(); } void TextureEditor::edit(Ref<Texture2D> p_texture) { - - if (!texture.is_null()) + if (!texture.is_null()) { texture->remove_change_receptor(this); + } texture = p_texture; @@ -126,12 +126,10 @@ void TextureEditor::edit(Ref<Texture2D> p_texture) { } void TextureEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_gui_input"), &TextureEditor::_gui_input); } TextureEditor::TextureEditor() { - set_texture_repeat(TextureRepeat::TEXTURE_REPEAT_ENABLED); set_custom_minimum_size(Size2(1, 150)); } @@ -141,14 +139,13 @@ TextureEditor::~TextureEditor() { texture->remove_change_receptor(this); } } + // bool EditorInspectorPluginTexture::can_handle(Object *p_object) { - return Object::cast_to<ImageTexture>(p_object) != nullptr || Object::cast_to<AtlasTexture>(p_object) != nullptr || Object::cast_to<StreamTexture2D>(p_object) != nullptr || Object::cast_to<LargeTexture>(p_object) != nullptr || Object::cast_to<AnimatedTexture>(p_object) != nullptr; } void EditorInspectorPluginTexture::parse_begin(Object *p_object) { - Texture2D *texture = Object::cast_to<Texture2D>(p_object); if (!texture) { return; @@ -161,7 +158,6 @@ void EditorInspectorPluginTexture::parse_begin(Object *p_object) { } TextureEditorPlugin::TextureEditorPlugin(EditorNode *p_node) { - Ref<EditorInspectorPluginTexture> plugin; plugin.instance(); add_inspector_plugin(plugin); diff --git a/editor/plugins/texture_editor_plugin.h b/editor/plugins/texture_editor_plugin.h index 29ad0183dc..63eea2b767 100644 --- a/editor/plugins/texture_editor_plugin.h +++ b/editor/plugins/texture_editor_plugin.h @@ -36,7 +36,6 @@ #include "scene/resources/texture.h" class TextureEditor : public Control { - GDCLASS(TextureEditor, Control); Ref<Texture2D> texture; @@ -62,7 +61,6 @@ public: }; class TextureEditorPlugin : public EditorPlugin { - GDCLASS(TextureEditorPlugin, EditorPlugin); public: diff --git a/editor/plugins/texture_layered_editor_plugin.cpp b/editor/plugins/texture_layered_editor_plugin.cpp index 6d716951b3..59e87fb273 100644 --- a/editor/plugins/texture_layered_editor_plugin.cpp +++ b/editor/plugins/texture_layered_editor_plugin.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* texture_editor_plugin.cpp */ +/* texture_layered_editor_plugin.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -48,9 +48,7 @@ void TextureLayeredEditor::_texture_rect_draw() { } void TextureLayeredEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_READY) { - //get_scene()->connect("node_removed",this,"_node_removed"); } if (p_what == NOTIFICATION_RESIZED) { @@ -58,7 +56,6 @@ void TextureLayeredEditor::_notification(int p_what) { } if (p_what == NOTIFICATION_DRAW) { - Ref<Texture2D> checkerboard = get_theme_icon("Checkerboard", "EditorIcons"); Size2 size = get_size(); @@ -67,14 +64,13 @@ void TextureLayeredEditor::_notification(int p_what) { } void TextureLayeredEditor::_changed_callback(Object *p_changed, const char *p_prop) { - - if (!is_visible()) + if (!is_visible()) { return; + } update(); } void TextureLayeredEditor::_update_material() { - materials[0]->set_shader_param("layer", layer->get_value()); materials[2]->set_shader_param("layer", layer->get_value()); materials[texture->get_layered_type()]->set_shader_param("tex", texture->get_rid()); @@ -151,7 +147,6 @@ void TextureLayeredEditor::_make_shaders() { } void TextureLayeredEditor::_texture_rect_update_area() { - Size2 size = get_size(); int tex_width = texture->get_width() * size.height / texture->get_height(); int tex_height = size.height; @@ -162,10 +157,12 @@ void TextureLayeredEditor::_texture_rect_update_area() { } // Prevent the texture from being unpreviewable after the rescale, so that we can still see something - if (tex_height <= 0) + if (tex_height <= 0) { tex_height = 1; - if (tex_width <= 0) + } + if (tex_width <= 0) { tex_width = 1; + } int ofs_x = (size.width - tex_width) / 2; int ofs_y = (size.height - tex_height) / 2; @@ -175,14 +172,13 @@ void TextureLayeredEditor::_texture_rect_update_area() { } void TextureLayeredEditor::edit(Ref<TextureLayered> p_texture) { - - if (!texture.is_null()) + if (!texture.is_null()) { texture->remove_change_receptor(this); + } texture = p_texture; if (!texture.is_null()) { - if (shaders[0].is_null()) { _make_shaders(); } @@ -213,13 +209,11 @@ void TextureLayeredEditor::edit(Ref<TextureLayered> p_texture) { } void TextureLayeredEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_gui_input"), &TextureLayeredEditor::_gui_input); ClassDB::bind_method(D_METHOD("_layer_changed"), &TextureLayeredEditor::_layer_changed); } TextureLayeredEditor::TextureLayeredEditor() { - set_texture_repeat(TextureRepeat::TEXTURE_REPEAT_ENABLED); set_custom_minimum_size(Size2(1, 150)); texture_rect = memnew(Control); @@ -259,14 +253,13 @@ TextureLayeredEditor::~TextureLayeredEditor() { texture->remove_change_receptor(this); } } + // bool EditorInspectorPluginLayeredTexture::can_handle(Object *p_object) { - return Object::cast_to<TextureLayered>(p_object) != nullptr; } void EditorInspectorPluginLayeredTexture::parse_begin(Object *p_object) { - TextureLayered *texture = Object::cast_to<TextureLayered>(p_object); if (!texture) { return; @@ -279,7 +272,6 @@ void EditorInspectorPluginLayeredTexture::parse_begin(Object *p_object) { } TextureLayeredEditorPlugin::TextureLayeredEditorPlugin(EditorNode *p_node) { - Ref<EditorInspectorPluginLayeredTexture> plugin; plugin.instance(); add_inspector_plugin(plugin); diff --git a/editor/plugins/texture_layered_editor_plugin.h b/editor/plugins/texture_layered_editor_plugin.h index e8503e845e..4c5e06a5b8 100644 --- a/editor/plugins/texture_layered_editor_plugin.h +++ b/editor/plugins/texture_layered_editor_plugin.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* texture_editor_plugin.h */ +/* texture_layered_editor_plugin.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -35,8 +35,8 @@ #include "editor/editor_plugin.h" #include "scene/resources/shader.h" #include "scene/resources/texture.h" -class TextureLayeredEditor : public Control { +class TextureLayeredEditor : public Control { GDCLASS(TextureLayeredEditor, Control); SpinBox *layer; @@ -55,8 +55,9 @@ class TextureLayeredEditor : public Control { void _update_material(); bool setting; void _layer_changed(double) { - if (!setting) + if (!setting) { _update_material(); + } } void _texture_rect_update_area(); @@ -83,7 +84,6 @@ public: }; class TextureLayeredEditorPlugin : public EditorPlugin { - GDCLASS(TextureLayeredEditorPlugin, EditorPlugin); public: diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index 099c9ceb5d..9b8b111be5 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -50,19 +50,21 @@ void draw_margin_line(Control *edit_draw, Vector2 from, Vector2 to) { void TextureRegionEditor::_region_draw() { Ref<Texture2D> base_tex = nullptr; - if (node_sprite) + if (node_sprite) { base_tex = node_sprite->get_texture(); - else if (node_sprite_3d) + } else if (node_sprite_3d) { base_tex = node_sprite_3d->get_texture(); - else if (node_ninepatch) + } else if (node_ninepatch) { base_tex = node_ninepatch->get_texture(); - else if (obj_styleBox.is_valid()) + } else if (obj_styleBox.is_valid()) { base_tex = obj_styleBox->get_texture(); - else if (atlas_tex.is_valid()) + } else if (atlas_tex.is_valid()) { base_tex = atlas_tex->get_atlas(); + } - if (base_tex.is_null()) + if (base_tex.is_null()) { return; + } Transform2D mtx; mtx.elements[2] = -draw_ofs * draw_zoom; @@ -78,45 +80,55 @@ void TextureRegionEditor::_region_draw() { int last_cell = 0; if (snap_step.x != 0) { - if (snap_separation.x == 0) + if (snap_separation.x == 0) { for (int i = 0; i < s.width; i++) { int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(i, 0)).x - snap_offset.x) / snap_step.x)); - if (i == 0) + if (i == 0) { last_cell = cell; - if (last_cell != cell) + } + if (last_cell != cell) { edit_draw->draw_line(Point2(i, 0), Point2(i, s.height), grid_color); + } last_cell = cell; } - else + } else { for (int i = 0; i < s.width; i++) { int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(i, 0)).x - snap_offset.x) / (snap_step.x + snap_separation.x))); - if (i == 0) + if (i == 0) { last_cell = cell; - if (last_cell != cell) + } + if (last_cell != cell) { edit_draw->draw_rect(Rect2(i - snap_separation.x * draw_zoom, 0, snap_separation.x * draw_zoom, s.height), grid_color); + } last_cell = cell; } + } } if (snap_step.y != 0) { - if (snap_separation.y == 0) + if (snap_separation.y == 0) { for (int i = 0; i < s.height; i++) { int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(0, i)).y - snap_offset.y) / snap_step.y)); - if (i == 0) + if (i == 0) { last_cell = cell; - if (last_cell != cell) + } + if (last_cell != cell) { edit_draw->draw_line(Point2(0, i), Point2(s.width, i), grid_color); + } last_cell = cell; } - else + } else { for (int i = 0; i < s.height; i++) { int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(0, i)).y - snap_offset.y) / (snap_step.y + snap_separation.y))); - if (i == 0) + if (i == 0) { last_cell = cell; - if (last_cell != cell) + } + if (last_cell != cell) { edit_draw->draw_rect(Rect2(0, i - snap_separation.y * draw_zoom, s.width, snap_separation.y * draw_zoom), grid_color); + } last_cell = cell; } + } } } else if (snap_mode == SNAP_AUTOSLICE) { for (List<Rect2>::Element *E = autoslice_cache.front(); E; E = E->next()) { @@ -152,7 +164,6 @@ void TextureRegionEditor::_region_draw() { }; Color color = get_theme_color("mono_color", "Editor"); for (int i = 0; i < 4; i++) { - int prev = (i + 3) % 4; int next = (i + 1) % 4; @@ -161,14 +172,16 @@ void TextureRegionEditor::_region_draw() { edit_draw->draw_line(endpoints[i] - draw_ofs * draw_zoom, endpoints[next] - draw_ofs * draw_zoom, color, 2); - if (snap_mode != SNAP_AUTOSLICE) + if (snap_mode != SNAP_AUTOSLICE) { edit_draw->draw_texture(select_handle, (endpoints[i] + ofs - (select_handle->get_size() / 2)).floor() - draw_ofs * draw_zoom); + } ofs = (endpoints[next] - endpoints[i]) / 2; ofs += (endpoints[next] - endpoints[i]).tangent().normalized() * (select_handle->get_size().width / 2); - if (snap_mode != SNAP_AUTOSLICE) + if (snap_mode != SNAP_AUTOSLICE) { edit_draw->draw_texture(select_handle, (endpoints[i] + ofs - (select_handle->get_size() / 2)).floor() - draw_ofs * draw_zoom); + } scroll_rect.expand_to(raw_endpoints[i]); } @@ -259,9 +272,7 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { Ref<InputEventMouseButton> mb = p_input; if (mb.is_valid()) { - if (mb->get_button_index() == BUTTON_LEFT) { - if (mb->is_pressed()) { if (node_ninepatch || obj_styleBox.is_valid()) { edited_margin = -1; @@ -309,16 +320,17 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { rect = E->get(); if (Input::get_singleton()->is_key_pressed(KEY_CONTROL) && !(Input::get_singleton()->is_key_pressed(KEY_SHIFT | KEY_ALT))) { Rect2 r; - if (node_sprite) + if (node_sprite) { r = node_sprite->get_region_rect(); - else if (node_sprite_3d) + } else if (node_sprite_3d) { r = node_sprite_3d->get_region_rect(); - else if (node_ninepatch) + } else if (node_ninepatch) { r = node_ninepatch->get_region_rect(); - else if (obj_styleBox.is_valid()) + } else if (obj_styleBox.is_valid()) { r = obj_styleBox->get_region_rect(); - else if (atlas_tex.is_valid()) + } else if (atlas_tex.is_valid()) { r = atlas_tex->get_region(); + } rect.expand_to(r.position); rect.expand_to(r.position + r.size); } @@ -349,21 +361,23 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { } } else if (edited_margin < 0) { drag_from = mtx.affine_inverse().xform(Vector2(mb->get_position().x, mb->get_position().y)); - if (snap_mode == SNAP_PIXEL) + if (snap_mode == SNAP_PIXEL) { drag_from = drag_from.snapped(Vector2(1, 1)); - else if (snap_mode == SNAP_GRID) + } else if (snap_mode == SNAP_GRID) { drag_from = snap_point(drag_from); + } drag = true; - if (node_sprite) + if (node_sprite) { rect_prev = node_sprite->get_region_rect(); - else if (node_sprite_3d) + } else if (node_sprite_3d) { rect_prev = node_sprite_3d->get_region_rect(); - else if (node_ninepatch) + } else if (node_ninepatch) { rect_prev = node_ninepatch->get_region_rect(); - else if (obj_styleBox.is_valid()) + } else if (obj_styleBox.is_valid()) { rect_prev = obj_styleBox->get_region_rect(); - else if (atlas_tex.is_valid()) + } else if (atlas_tex.is_valid()) { rect_prev = atlas_tex->get_region(); + } for (int i = 0; i < 8; i++) { Vector2 tuv = endpoints[i]; @@ -421,15 +435,16 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { } } else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) { - if (drag) { drag = false; if (edited_margin >= 0) { static Margin m[4] = { MARGIN_TOP, MARGIN_BOTTOM, MARGIN_LEFT, MARGIN_RIGHT }; - if (node_ninepatch) + if (node_ninepatch) { node_ninepatch->set_patch_margin(m[edited_margin], prev_margin); - if (obj_styleBox.is_valid()) + } + if (obj_styleBox.is_valid()) { obj_styleBox->set_margin_size(m[edited_margin], prev_margin); + } edited_margin = -1; } else { apply_rect(rect_prev); @@ -448,41 +463,43 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { Ref<InputEventMouseMotion> mm = p_input; if (mm.is_valid()) { - if (mm->get_button_mask() & BUTTON_MASK_MIDDLE || Input::get_singleton()->is_key_pressed(KEY_SPACE)) { - Vector2 dragged(mm->get_relative().x / draw_zoom, mm->get_relative().y / draw_zoom); hscroll->set_value(hscroll->get_value() - dragged.x); vscroll->set_value(vscroll->get_value() - dragged.y); } else if (drag) { - if (edited_margin >= 0) { float new_margin = 0; - if (edited_margin == 0) + if (edited_margin == 0) { new_margin = prev_margin + (mm->get_position().y - drag_from.y) / draw_zoom; - else if (edited_margin == 1) + } else if (edited_margin == 1) { new_margin = prev_margin - (mm->get_position().y - drag_from.y) / draw_zoom; - else if (edited_margin == 2) + } else if (edited_margin == 2) { new_margin = prev_margin + (mm->get_position().x - drag_from.x) / draw_zoom; - else if (edited_margin == 3) + } else if (edited_margin == 3) { new_margin = prev_margin - (mm->get_position().x - drag_from.x) / draw_zoom; - else + } else { ERR_PRINT("Unexpected edited_margin"); + } - if (new_margin < 0) + if (new_margin < 0) { new_margin = 0; + } static Margin m[4] = { MARGIN_TOP, MARGIN_BOTTOM, MARGIN_LEFT, MARGIN_RIGHT }; - if (node_ninepatch) + if (node_ninepatch) { node_ninepatch->set_patch_margin(m[edited_margin], new_margin); - if (obj_styleBox.is_valid()) + } + if (obj_styleBox.is_valid()) { obj_styleBox->set_margin_size(m[edited_margin], new_margin); + } } else { Vector2 new_pos = mtx.affine_inverse().xform(mm->get_position()); - if (snap_mode == SNAP_PIXEL) + if (snap_mode == SNAP_PIXEL) { new_pos = new_pos.snapped(Vector2(1, 1)); - else if (snap_mode == SNAP_GRID) + } else if (snap_mode == SNAP_GRID) { new_pos = snap_point(new_pos); + } if (creating) { rect = Rect2(drag_from, Size2()); @@ -560,8 +577,9 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { } void TextureRegionEditor::_scroll_changed(float) { - if (updating_scroll) + if (updating_scroll) { return; + } draw_ofs.x = hscroll->get_value(); draw_ofs.y = vscroll->get_value(); @@ -571,10 +589,11 @@ void TextureRegionEditor::_scroll_changed(float) { void TextureRegionEditor::_set_snap_mode(int p_mode) { snap_mode = p_mode; - if (snap_mode == SNAP_GRID) + if (snap_mode == SNAP_GRID) { hb_grid->show(); - else + } else { hb_grid->hide(); + } if (snap_mode == SNAP_AUTOSLICE && is_visible() && autoslice_is_dirty) { _update_autoslice(); @@ -614,8 +633,9 @@ void TextureRegionEditor::_set_snap_sep_y(float p_val) { } void TextureRegionEditor::_zoom_on_position(float p_zoom, Point2 p_position) { - if (p_zoom < 0.25 || p_zoom > 8) + if (p_zoom < 0.25 || p_zoom > 8) { return; + } float prev_zoom = draw_zoom; draw_zoom = p_zoom; @@ -640,32 +660,34 @@ void TextureRegionEditor::_zoom_out() { } void TextureRegionEditor::apply_rect(const Rect2 &p_rect) { - if (node_sprite) + if (node_sprite) { node_sprite->set_region_rect(p_rect); - else if (node_sprite_3d) + } else if (node_sprite_3d) { node_sprite_3d->set_region_rect(p_rect); - else if (node_ninepatch) + } else if (node_ninepatch) { node_ninepatch->set_region_rect(p_rect); - else if (obj_styleBox.is_valid()) + } else if (obj_styleBox.is_valid()) { obj_styleBox->set_region_rect(p_rect); - else if (atlas_tex.is_valid()) + } else if (atlas_tex.is_valid()) { atlas_tex->set_region(p_rect); + } } void TextureRegionEditor::_update_rect() { - if (node_sprite) + if (node_sprite) { rect = node_sprite->get_region_rect(); - else if (node_sprite_3d) + } else if (node_sprite_3d) { rect = node_sprite_3d->get_region_rect(); - else if (node_ninepatch) { + } else if (node_ninepatch) { rect = node_ninepatch->get_region_rect(); if (rect == Rect2()) { rect = Rect2(Vector2(), node_ninepatch->get_texture()->get_size()); } - } else if (obj_styleBox.is_valid()) + } else if (obj_styleBox.is_valid()) { rect = obj_styleBox->get_region_rect(); - else if (atlas_tex.is_valid()) + } else if (atlas_tex.is_valid()) { rect = atlas_tex->get_region(); + } } void TextureRegionEditor::_update_autoslice() { @@ -673,16 +695,17 @@ void TextureRegionEditor::_update_autoslice() { autoslice_cache.clear(); Ref<Texture2D> texture = nullptr; - if (node_sprite) + if (node_sprite) { texture = node_sprite->get_texture(); - else if (node_sprite_3d) + } else if (node_sprite_3d) { texture = node_sprite_3d->get_texture(); - else if (node_ninepatch) + } else if (node_ninepatch) { texture = node_ninepatch->get_texture(); - else if (obj_styleBox.is_valid()) + } else if (obj_styleBox.is_valid()) { texture = obj_styleBox->get_texture(); - else if (atlas_tex.is_valid()) + } else if (atlas_tex.is_valid()) { texture = atlas_tex->get_atlas(); + } if (texture.is_null()) { return; @@ -707,8 +730,9 @@ void TextureRegionEditor::_update_autoslice() { autoslice_cache.erase(F->prev()); queue_erase = false; } - if (F == E) + if (F == E) { continue; + } if (E->get().grow(1).intersects(F->get())) { E->get().expand_to(F->get().position); E->get().expand_to(F->get().position + F->get().size); @@ -788,7 +812,6 @@ bool TextureRegionEditor::is_stylebox() { } bool TextureRegionEditor::is_atlas_texture() { - return atlas_tex.is_valid(); } @@ -805,24 +828,31 @@ Sprite2D *TextureRegionEditor::get_sprite() { } void TextureRegionEditor::edit(Object *p_obj) { - if (node_sprite) + if (node_sprite) { node_sprite->remove_change_receptor(this); - if (node_sprite_3d) + } + if (node_sprite_3d) { node_sprite_3d->remove_change_receptor(this); - if (node_ninepatch) + } + if (node_ninepatch) { node_ninepatch->remove_change_receptor(this); - if (obj_styleBox.is_valid()) + } + if (obj_styleBox.is_valid()) { obj_styleBox->remove_change_receptor(this); - if (atlas_tex.is_valid()) + } + if (atlas_tex.is_valid()) { atlas_tex->remove_change_receptor(this); + } if (p_obj) { node_sprite = Object::cast_to<Sprite2D>(p_obj); node_sprite_3d = Object::cast_to<Sprite3D>(p_obj); node_ninepatch = Object::cast_to<NinePatchRect>(p_obj); - if (Object::cast_to<StyleBoxTexture>(p_obj)) + if (Object::cast_to<StyleBoxTexture>(p_obj)) { obj_styleBox = Ref<StyleBoxTexture>(Object::cast_to<StyleBoxTexture>(p_obj)); - if (Object::cast_to<AtlasTexture>(p_obj)) + } + if (Object::cast_to<AtlasTexture>(p_obj)) { atlas_tex = Ref<AtlasTexture>(Object::cast_to<AtlasTexture>(p_obj)); + } p_obj->add_change_receptor(this); _edit_region(); } else { @@ -842,25 +872,27 @@ void TextureRegionEditor::edit(Object *p_obj) { } void TextureRegionEditor::_changed_callback(Object *p_changed, const char *p_prop) { - - if (!is_visible()) + if (!is_visible()) { return; - if (p_prop == StringName("atlas") || p_prop == StringName("texture")) + } + if (p_prop == StringName("atlas") || p_prop == StringName("texture")) { _edit_region(); + } } void TextureRegionEditor::_edit_region() { Ref<Texture2D> texture = nullptr; - if (node_sprite) + if (node_sprite) { texture = node_sprite->get_texture(); - else if (node_sprite_3d) + } else if (node_sprite_3d) { texture = node_sprite_3d->get_texture(); - else if (node_ninepatch) + } else if (node_ninepatch) { texture = node_ninepatch->get_texture(); - else if (obj_styleBox.is_valid()) + } else if (obj_styleBox.is_valid()) { texture = obj_styleBox->get_texture(); - else if (atlas_tex.is_valid()) + } else if (atlas_tex.is_valid()) { texture = atlas_tex->get_atlas(); + } if (texture.is_null()) { _zoom_reset(); @@ -1063,7 +1095,6 @@ void TextureRegionEditorPlugin::make_visible(bool p_visible) { } Dictionary TextureRegionEditorPlugin::get_state() const { - Dictionary state; state["snap_offset"] = region_editor->snap_offset; state["snap_step"] = region_editor->snap_step; @@ -1073,7 +1104,6 @@ Dictionary TextureRegionEditorPlugin::get_state() const { } void TextureRegionEditorPlugin::set_state(const Dictionary &p_state) { - Dictionary state = p_state; if (state.has("snap_step")) { Vector2 s = state["snap_step"]; diff --git a/editor/plugins/texture_region_editor_plugin.h b/editor/plugins/texture_region_editor_plugin.h index c6cd648842..93da23fd50 100644 --- a/editor/plugins/texture_region_editor_plugin.h +++ b/editor/plugins/texture_region_editor_plugin.h @@ -45,7 +45,6 @@ */ class TextureRegionEditor : public VBoxContainer { - GDCLASS(TextureRegionEditor, VBoxContainer); enum SnapMode { diff --git a/editor/plugins/theme_editor_plugin.cpp b/editor/plugins/theme_editor_plugin.cpp index d9be2e32cb..eb028659fd 100644 --- a/editor/plugins/theme_editor_plugin.cpp +++ b/editor/plugins/theme_editor_plugin.cpp @@ -36,44 +36,38 @@ #include "scene/gui/progress_bar.h" void ThemeEditor::edit(const Ref<Theme> &p_theme) { - theme = p_theme; main_panel->set_theme(p_theme); main_container->set_theme(p_theme); } void ThemeEditor::_propagate_redraw(Control *p_at) { - p_at->notification(NOTIFICATION_THEME_CHANGED); p_at->minimum_size_changed(); p_at->update(); for (int i = 0; i < p_at->get_child_count(); i++) { Control *a = Object::cast_to<Control>(p_at->get_child(i)); - if (a) + if (a) { _propagate_redraw(a); + } } } void ThemeEditor::_refresh_interval() { - _propagate_redraw(main_panel); _propagate_redraw(main_container); } void ThemeEditor::_type_menu_cbk(int p_option) { - type_edit->set_text(type_menu->get_popup()->get_item_text(p_option)); } void ThemeEditor::_name_menu_about_to_show() { - String fromtype = type_edit->get_text(); List<StringName> names; if (popup_mode == POPUP_ADD) { - switch (type_select->get_selected()) { - case 0: Theme::get_default()->get_icon_list(fromtype, &names); break; @@ -91,7 +85,6 @@ void ThemeEditor::_name_menu_about_to_show() { break; } } else if (popup_mode == POPUP_REMOVE) { - theme->get_icon_list(fromtype, &names); theme->get_stylebox_list(fromtype, &names); theme->get_font_list(fromtype, &names); @@ -102,21 +95,17 @@ void ThemeEditor::_name_menu_about_to_show() { name_menu->get_popup()->clear(); name_menu->get_popup()->set_size(Size2()); for (List<StringName>::Element *E = names.front(); E; E = E->next()) { - name_menu->get_popup()->add_item(E->get()); } } void ThemeEditor::_name_menu_cbk(int p_option) { - name_edit->set_text(name_menu->get_popup()->get_item_text(p_option)); } struct _TECategory { - template <class T> struct RefItem { - Ref<T> item; StringName name; bool operator<(const RefItem<T> &p) const { return item->get_instance_id() < p.item->get_instance_id(); } @@ -124,7 +113,6 @@ struct _TECategory { template <class T> struct Item { - T item; String name; bool operator<(const Item<T> &p) const { return name < p.name; } @@ -139,7 +127,6 @@ struct _TECategory { }; void ThemeEditor::_save_template_cbk(String fname) { - String filename = file_dialog->get_current_path(); Map<String, _TECategory> categories; @@ -153,7 +140,6 @@ void ThemeEditor::_save_template_cbk(String fname) { // Fill default theme. for (Map<String, _TECategory>::Element *E = categories.front(); E; E = E->next()) { - _TECategory &tc = E->get(); List<StringName> stylebox_list; @@ -270,55 +256,55 @@ void ThemeEditor::_save_template_cbk(String fname) { // Write default theme. for (Map<String, _TECategory>::Element *E = categories.front(); E; E = E->next()) { - _TECategory &tc = E->get(); String underline = "; "; - for (int i = 0; i < E->key().length(); i++) + for (int i = 0; i < E->key().length(); i++) { underline += "*"; + } file->store_line(""); file->store_line(underline); file->store_line("; " + E->key()); file->store_line(underline); - if (tc.stylebox_items.size()) + if (tc.stylebox_items.size()) { file->store_line("\n; StyleBox Items:\n"); + } for (Set<_TECategory::RefItem<StyleBox>>::Element *F = tc.stylebox_items.front(); F; F = F->next()) { - file->store_line(E->key() + "." + F->get().name + " = default"); } - if (tc.font_items.size()) + if (tc.font_items.size()) { file->store_line("\n; Font Items:\n"); + } for (Set<_TECategory::RefItem<Font>>::Element *F = tc.font_items.front(); F; F = F->next()) { - file->store_line(E->key() + "." + F->get().name + " = default"); } - if (tc.icon_items.size()) + if (tc.icon_items.size()) { file->store_line("\n; Icon Items:\n"); + } for (Set<_TECategory::RefItem<Texture2D>>::Element *F = tc.icon_items.front(); F; F = F->next()) { - file->store_line(E->key() + "." + F->get().name + " = default"); } - if (tc.color_items.size()) + if (tc.color_items.size()) { file->store_line("\n; Color Items:\n"); + } for (Set<_TECategory::Item<Color>>::Element *F = tc.color_items.front(); F; F = F->next()) { - file->store_line(E->key() + "." + F->get().name + " = default"); } - if (tc.constant_items.size()) + if (tc.constant_items.size()) { file->store_line("\n; Constant Items:\n"); + } for (Set<_TECategory::Item<int>>::Element *F = tc.constant_items.front(); F; F = F->next()) { - file->store_line(E->key() + "." + F->get().name + " = default"); } } @@ -328,12 +314,9 @@ void ThemeEditor::_save_template_cbk(String fname) { } void ThemeEditor::_dialog_cbk() { - switch (popup_mode) { case POPUP_ADD: { - switch (type_select->get_selected()) { - case 0: theme->set_icon(name_edit->get_text(), type_edit->get_text(), Ref<Texture2D>()); break; @@ -353,7 +336,6 @@ void ThemeEditor::_dialog_cbk() { } break; case POPUP_CLASS_ADD: { - StringName fromtype = type_edit->get_text(); List<StringName> names; @@ -395,7 +377,6 @@ void ThemeEditor::_dialog_cbk() { } break; case POPUP_REMOVE: { switch (type_select->get_selected()) { - case 0: theme->clear_icon(name_edit->get_text(), type_edit->get_text()); break; @@ -459,9 +440,7 @@ void ThemeEditor::_dialog_cbk() { } void ThemeEditor::_theme_menu_cbk(int p_option) { - if (p_option == POPUP_CREATE_EMPTY || p_option == POPUP_CREATE_EDITOR_EMPTY || p_option == POPUP_IMPORT_EDITOR_THEME) { - bool import = (p_option == POPUP_IMPORT_EDITOR_THEME); Ref<Theme> base_theme; @@ -473,7 +452,6 @@ void ThemeEditor::_theme_menu_cbk(int p_option) { } { - List<StringName> types; base_theme->get_type_list(&types); @@ -555,7 +533,6 @@ void ThemeEditor::_theme_menu_cbk(int p_option) { type_select->hide(); } else if (p_option == POPUP_REMOVE) { - add_del_dialog->set_title(TTR("Remove Item")); add_del_dialog->get_ok()->set_text(TTR("Remove")); add_del_dialog->popup_centered(Size2(490, 85) * EDSCALE); @@ -563,7 +540,6 @@ void ThemeEditor::_theme_menu_cbk(int p_option) { base_theme = theme; } else if (p_option == POPUP_CLASS_REMOVE) { - add_del_dialog->set_title(TTR("Remove All Items")); add_del_dialog->get_ok()->set_text(TTR("Remove All")); add_del_dialog->popup_centered(Size2(240, 85) * EDSCALE); @@ -589,30 +565,27 @@ void ThemeEditor::_theme_menu_cbk(int p_option) { List<StringName> new_types; theme->get_type_list(&new_types); for (List<StringName>::Element *F = new_types.front(); F; F = F->next()) { - bool found = false; for (List<StringName>::Element *E = types.front(); E; E = E->next()) { - if (E->get() == F->get()) { found = true; break; } } - if (!found) + if (!found) { types.push_back(F->get()); + } } } types.sort_custom<StringName::AlphCompare>(); for (List<StringName>::Element *E = types.front(); E; E = E->next()) { - type_menu->get_popup()->add_item(E->get()); } } void ThemeEditor::_notification(int p_what) { - switch (p_what) { case NOTIFICATION_PROCESS: { time_left -= get_process_delta_time(); @@ -631,7 +604,6 @@ void ThemeEditor::_bind_methods() { } ThemeEditor::ThemeEditor() { - time_left = 0; HBoxContainer *top_menu = memnew(HBoxContainer); @@ -901,7 +873,6 @@ ThemeEditor::ThemeEditor() { } void ThemeEditorPlugin::edit(Object *p_node) { - if (Object::cast_to<Theme>(p_node)) { theme_editor->edit(Object::cast_to<Theme>(p_node)); } else { @@ -910,27 +881,25 @@ void ThemeEditorPlugin::edit(Object *p_node) { } bool ThemeEditorPlugin::handles(Object *p_node) const { - return p_node->is_class("Theme"); } void ThemeEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { theme_editor->set_process(true); button->show(); editor->make_bottom_panel_item_visible(theme_editor); } else { theme_editor->set_process(false); - if (theme_editor->is_visible_in_tree()) + if (theme_editor->is_visible_in_tree()) { editor->hide_bottom_panel(); + } button->hide(); } } ThemeEditorPlugin::ThemeEditorPlugin(EditorNode *p_node) { - editor = p_node; theme_editor = memnew(ThemeEditor); theme_editor->set_custom_minimum_size(Size2(0, 200) * EDSCALE); diff --git a/editor/plugins/theme_editor_plugin.h b/editor/plugins/theme_editor_plugin.h index c51583593d..983bfb6b50 100644 --- a/editor/plugins/theme_editor_plugin.h +++ b/editor/plugins/theme_editor_plugin.h @@ -42,7 +42,6 @@ #include "editor/editor_node.h" class ThemeEditor : public VBoxContainer { - GDCLASS(ThemeEditor, VBoxContainer); Panel *main_panel; @@ -99,7 +98,6 @@ public: }; class ThemeEditorPlugin : public EditorPlugin { - GDCLASS(ThemeEditorPlugin, EditorPlugin); ThemeEditor *theme_editor; diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp index e22e0cc052..3010d72d81 100644 --- a/editor/plugins/tile_map_editor_plugin.cpp +++ b/editor/plugins/tile_map_editor_plugin.cpp @@ -39,18 +39,14 @@ #include "scene/gui/split_container.h" void TileMapEditor::_node_removed(Node *p_node) { - if (p_node == node) { node = nullptr; } } void TileMapEditor::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_PROCESS: { - if (bucket_queue.size()) { CanvasItemEditor::get_singleton()->update_viewport(); } @@ -58,13 +54,11 @@ void TileMapEditor::_notification(int p_what) { } break; case NOTIFICATION_ENTER_TREE: { - get_tree()->connect("node_removed", callable_mp(this, &TileMapEditor::_node_removed)); [[fallthrough]]; } case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { - if (is_visible_in_tree()) { _update_palette(); } @@ -97,7 +91,6 @@ void TileMapEditor::_notification(int p_what) { } void TileMapEditor::_update_button_tool() { - ToolButton *tb[4] = { paint_button, bucket_fill_button, picker_button, select_button }; // Unpress all buttons for (int i = 0; i < 4; i++) { @@ -123,8 +116,9 @@ void TileMapEditor::_update_button_tool() { break; } - if (tool != TOOL_PICKING) + if (tool != TOOL_PICKING) { last_tool = tool; + } } void TileMapEditor::_button_tool_select(int p_tool) { @@ -132,7 +126,6 @@ void TileMapEditor::_button_tool_select(int p_tool) { _update_button_tool(); switch (tool) { case TOOL_SELECTING: { - selection_active = false; } break; default: @@ -142,10 +135,8 @@ void TileMapEditor::_button_tool_select(int p_tool) { } void TileMapEditor::_menu_option(int p_option) { - switch (p_option) { case OPTION_COPY: { - _update_copydata(); if (selection_active) { @@ -155,9 +146,9 @@ void TileMapEditor::_menu_option(int p_option) { } } break; case OPTION_ERASE_SELECTION: { - - if (!selection_active) + if (!selection_active) { return; + } _start_undo(TTR("Erase Selection")); _erase_selection(); @@ -169,7 +160,6 @@ void TileMapEditor::_menu_option(int p_option) { CanvasItemEditor::get_singleton()->update_viewport(); } break; case OPTION_FIX_INVALID: { - undo_redo->create_action(TTR("Fix Invalid Tiles")); undo_redo->add_undo_method(node, "set", "tile_data", node->get("tile_data")); node->fix_invalid_tiles(); @@ -178,7 +168,6 @@ void TileMapEditor::_menu_option(int p_option) { } break; case OPTION_CUT: { - if (selection_active) { _update_copydata(); @@ -206,19 +195,16 @@ void TileMapEditor::_palette_multi_selected(int index, bool selected) { } void TileMapEditor::_canvas_mouse_enter() { - mouse_over = true; CanvasItemEditor::get_singleton()->update_viewport(); } void TileMapEditor::_canvas_mouse_exit() { - mouse_over = false; CanvasItemEditor::get_singleton()->update_viewport(); } Vector<int> TileMapEditor::get_selected_tiles() const { - Vector<int> items = palette->get_selected_items(); if (items.size() == 0) { @@ -233,7 +219,6 @@ Vector<int> TileMapEditor::get_selected_tiles() const { } void TileMapEditor::set_selected_tiles(Vector<int> p_tiles) { - palette->unselect_all(); for (int i = p_tiles.size() - 1; i >= 0; i--) { @@ -248,7 +233,6 @@ void TileMapEditor::set_selected_tiles(Vector<int> p_tiles) { } Dictionary TileMapEditor::_create_cell_dictionary(int tile, bool flip_x, bool flip_y, bool transpose, Vector2 autotile_coord) { - Dictionary cell; cell["id"] = tile; @@ -261,7 +245,6 @@ Dictionary TileMapEditor::_create_cell_dictionary(int tile, bool flip_x, bool fl } void TileMapEditor::_create_set_cell_undo_redo(const Vector2 &p_vec, const CellOp &p_cell_old, const CellOp &p_cell_new) { - Dictionary cell_old = _create_cell_dictionary(p_cell_old.idx, p_cell_old.xf, p_cell_old.yf, p_cell_old.tr, p_cell_old.ac); Dictionary cell_new = _create_cell_dictionary(p_cell_new.idx, p_cell_new.xf, p_cell_new.yf, p_cell_new.tr, p_cell_new.ac); @@ -270,13 +253,11 @@ void TileMapEditor::_create_set_cell_undo_redo(const Vector2 &p_vec, const CellO } void TileMapEditor::_start_undo(const String &p_action) { - undo_data.clear(); undo_redo->create_action(p_action); } void TileMapEditor::_finish_undo() { - if (undo_data.size()) { for (Map<Point2i, CellOp>::Element *E = undo_data.front(); E; E = E->next()) { _create_set_cell_undo_redo(E->key(), E->get(), _get_op_from_cell(E->key())); @@ -289,11 +270,11 @@ void TileMapEditor::_finish_undo() { } void TileMapEditor::_set_cell(const Point2i &p_pos, Vector<int> p_values, bool p_flip_h, bool p_flip_v, bool p_transpose, const Point2i &p_autotile_coord) { - ERR_FAIL_COND(!node); - if (p_values.size() == 0) + if (p_values.size() == 0) { return; + } int p_value = p_values[Math::rand() % p_values.size()]; int prev_val = node->get_cell(p_pos.x, p_pos.y); @@ -319,8 +300,9 @@ void TileMapEditor::_set_cell(const Point2i &p_pos, Vector<int> p_values, bool p position = prev_position; } - if (p_value == prev_val && p_flip_h == prev_flip_h && p_flip_v == prev_flip_v && p_transpose == prev_transpose && prev_position == position) + if (p_value == prev_val && p_flip_h == prev_flip_h && p_flip_v == prev_flip_v && p_transpose == prev_transpose && prev_position == position) { return; // Check that it's actually different. + } for (int y = p_pos.y - 1; y <= p_pos.y + 1; y++) { for (int x = p_pos.x - 1; x <= p_pos.x + 1; x++) { @@ -333,8 +315,9 @@ void TileMapEditor::_set_cell(const Point2i &p_pos, Vector<int> p_values, bool p node->_set_celld(p_pos, _create_cell_dictionary(p_value, p_flip_h, p_flip_v, p_transpose, p_autotile_coord)); - if (tool == TOOL_PASTING) + if (tool == TOOL_PASTING) { return; + } if (manual_autotile || (p_value != -1 && node->get_tileset()->tile_get_tile_mode(p_value) == TileSet::ATLAS_TILE)) { if (current != -1) { @@ -360,7 +343,6 @@ void TileMapEditor::_priority_toggled(bool p_enabled) { } void TileMapEditor::_text_entered(const String &p_text) { - canvas_item_editor_viewport->grab_focus(); } @@ -369,14 +351,12 @@ void TileMapEditor::_text_changed(const String &p_text) { } void TileMapEditor::_sbox_input(const Ref<InputEvent> &p_ie) { - Ref<InputEventKey> k = p_ie; if (k.is_valid() && (k->get_keycode() == KEY_UP || k->get_keycode() == KEY_DOWN || k->get_keycode() == KEY_PAGEUP || k->get_keycode() == KEY_PAGEDOWN)) { - palette->call("_gui_input", k); search_box->accept_event(); } @@ -396,9 +376,9 @@ struct _PaletteEntry { } // namespace void TileMapEditor::_update_palette() { - - if (!node) + if (!node) { return; + } // Update the clear button. clear_transform_button->set_disabled(!flip_h && !flip_v && !transpose); @@ -424,8 +404,9 @@ void TileMapEditor::_update_palette() { List<int> tiles; tileset->get_tile_list(&tiles); - if (tiles.empty()) + if (tiles.empty()) { return; + } float min_size = EDITOR_DEF("editors/tile_map/preview_size", 64); min_size *= EDSCALE; @@ -447,7 +428,6 @@ void TileMapEditor::_update_palette() { Vector<_PaletteEntry> entries; for (List<int>::Element *E = tiles.front(); E; E = E->next()) { - String name = tileset->tile_get_name(E->get()); if (name != "") { @@ -462,8 +442,9 @@ void TileMapEditor::_update_palette() { name = "#" + itos(E->get()); } - if (filter != "" && !filter.is_subsequence_ofi(name)) + if (filter != "" && !filter.is_subsequence_ofi(name)) { continue; + } const _PaletteEntry entry = { E->get(), name }; entries.push_back(entry); @@ -474,7 +455,6 @@ void TileMapEditor::_update_palette() { } for (int i = 0; i < entries.size(); i++) { - if (show_tile_names) { palette->add_item(entries[i].name); } else { @@ -502,8 +482,9 @@ void TileMapEditor::_update_palette() { } // Set region. - if (region.size != Size2()) + if (region.size != Size2()) { palette->set_item_icon_region(palette->get_item_count() - 1, region); + } // Set icon. palette->set_item_icon(palette->get_item_count() - 1, tex); @@ -526,7 +507,6 @@ void TileMapEditor::_update_palette() { } if (sel_tile != TileMap::INVALID_CELL && ((manual_autotile && tileset->tile_get_tile_mode(sel_tile) == TileSet::AUTO_TILE) || (!priority_atlastile && tileset->tile_get_tile_mode(sel_tile) == TileSet::ATLAS_TILE))) { - const Map<Vector2, uint32_t> &tiles2 = tileset->autotile_get_bitmask_map(sel_tile); Vector<Vector2> entries2; @@ -544,18 +524,17 @@ void TileMapEditor::_update_palette() { Ref<Texture2D> tex = tileset->tile_get_texture(sel_tile); for (int i = 0; i < entries2.size(); i++) { - manual_palette->add_item(String()); if (tex.is_valid()) { - Rect2 region = tileset->tile_get_region(sel_tile); int spacing = tileset->autotile_get_spacing(sel_tile); region.size = tileset->autotile_get_size(sel_tile); // !! region.position += (region.size + Vector2(spacing, spacing)) * entries2[i]; - if (!region.has_no_area()) + if (!region.has_no_area()) { manual_palette->set_item_icon_region(manual_palette->get_item_count() - 1, region); + } manual_palette->set_item_icon(manual_palette->get_item_count() - 1, tex); } @@ -566,10 +545,12 @@ void TileMapEditor::_update_palette() { if (manual_palette->get_item_count() > 0) { // Only show the manual palette if at least tile exists in it. - if (selected_manual == -1 || selected_single != palette->get_current()) + if (selected_manual == -1 || selected_single != palette->get_current()) { selected_manual = 0; - if (selected_manual < manual_palette->get_item_count()) + } + if (selected_manual < manual_palette->get_item_count()) { manual_palette->set_current(selected_manual); + } manual_palette->show(); } @@ -583,11 +564,11 @@ void TileMapEditor::_update_palette() { } void TileMapEditor::_pick_tile(const Point2 &p_pos) { - int id = node->get_cell(p_pos.x, p_pos.y); - if (id == TileMap::INVALID_CELL) + if (id == TileMap::INVALID_CELL) { return; + } if (search_box->get_text() != "") { search_box->set_text(""); @@ -612,15 +593,15 @@ void TileMapEditor::_pick_tile(const Point2 &p_pos) { } Vector<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool erase, bool preview) { - int prev_id = node->get_cell(p_start.x, p_start.y); Vector<int> ids; ids.push_back(TileMap::INVALID_CELL); if (!erase) { ids = get_selected_tiles(); - if (ids.size() == 0 || ids[0] == TileMap::INVALID_CELL) + if (ids.size() == 0 || ids[0] == TileMap::INVALID_CELL) { return Vector<Vector2>(); + } } else if (prev_id == TileMap::INVALID_CELL) { return Vector<Vector2>(); } @@ -637,8 +618,9 @@ Vector<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool erase, // Test if we can re-use the result from preview bucket fill bool invalidate_cache = false; // Area changed - if (r != bucket_cache_rect) + if (r != bucket_cache_rect) { _clear_bucket_cache(); + } // Cache grid is not initialized if (bucket_cache_visited == nullptr) { bucket_cache_visited = new bool[area]; @@ -651,8 +633,9 @@ Vector<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool erase, invalidate_cache = true; } if (invalidate_cache) { - for (int i = 0; i < area; ++i) + for (int i = 0; i < area; ++i) { bucket_cache_visited[i] = false; + } bucket_cache = Vector<Vector2>(); bucket_cache_tile = prev_id; bucket_cache_rect = r; @@ -674,24 +657,25 @@ Vector<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool erase, bucket_queue.push_back(p_start); while (bucket_queue.size()) { - Point2i n = bucket_queue.front()->get(); bucket_queue.pop_front(); - if (!r.has_point(n)) + if (!r.has_point(n)) { continue; + } if (node->get_cell(n.x, n.y) == prev_id) { - if (preview) { int loc = (n.x - r.position.x) + (n.y - r.position.y) * r.get_size().x; - if (bucket_cache_visited[loc]) + if (bucket_cache_visited[loc]) { continue; + } bucket_cache_visited[loc] = true; bucket_cache.push_back(n); } else { - if (non_preview_cache.find(n) >= 0) + if (non_preview_cache.find(n) >= 0) { continue; + } points.push_back(n); non_preview_cache.push_back(n); } @@ -712,7 +696,6 @@ Vector<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool erase, } void TileMapEditor::_fill_points(const Vector<Vector2> &p_points, const Dictionary &p_op) { - int len = p_points.size(); const Vector2 *pr = p_points.ptr(); @@ -725,32 +708,28 @@ void TileMapEditor::_fill_points(const Vector<Vector2> &p_points, const Dictiona _set_cell(pr[i], ids, xf, yf, tr); node->make_bitmask_area_dirty(pr[i]); } - if (!manual_autotile) + if (!manual_autotile) { node->update_dirty_bitmask(); + } } void TileMapEditor::_erase_points(const Vector<Vector2> &p_points) { - int len = p_points.size(); const Vector2 *pr = p_points.ptr(); for (int i = 0; i < len; i++) { - _set_cell(pr[i], invalid_cell); } } void TileMapEditor::_select(const Point2i &p_from, const Point2i &p_to) { - Point2i begin = p_from; Point2i end = p_to; if (begin.x > end.x) { - SWAP(begin.x, end.x); } if (begin.y > end.y) { - SWAP(begin.y, end.y); } @@ -761,23 +740,23 @@ void TileMapEditor::_select(const Point2i &p_from, const Point2i &p_to) { } void TileMapEditor::_erase_selection() { - if (!selection_active) + if (!selection_active) { return; + } for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) { for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) { - _set_cell(Point2i(j, i), invalid_cell, false, false, false); } } } void TileMapEditor::_draw_cell(Control *p_viewport, int p_cell, const Point2i &p_point, bool p_flip_h, bool p_flip_v, bool p_transpose, const Point2i &p_autotile_coord, const Transform2D &p_xform) { - Ref<Texture2D> t = node->get_tileset()->tile_get_texture(p_cell); - if (t.is_null()) + if (t.is_null()) { return; + } Vector2 tile_ofs = node->get_tileset()->tile_get_texture_offset(p_cell); @@ -814,11 +793,13 @@ void TileMapEditor::_draw_cell(Control *p_viewport, int p_cell, const Point2i &p if (compatibility_mode_enabled && !centered_texture) { if (rect.size.y > rect.size.x) { - if ((p_flip_h && (p_flip_v || p_transpose)) || (p_flip_v && !p_transpose)) + if ((p_flip_h && (p_flip_v || p_transpose)) || (p_flip_v && !p_transpose)) { tile_ofs.y += rect.size.y - rect.size.x; + } } else if (rect.size.y < rect.size.x) { - if ((p_flip_v && (p_flip_h || p_transpose)) || (p_flip_h && !p_transpose)) + if ((p_flip_v && (p_flip_h || p_transpose)) || (p_flip_h && !p_transpose)) { tile_ofs.x += rect.size.x - rect.size.y; + } } } @@ -844,37 +825,38 @@ void TileMapEditor::_draw_cell(Control *p_viewport, int p_cell, const Point2i &p if (compatibility_mode_enabled && !centered_texture) { if (node->get_tile_origin() == TileMap::TILE_ORIGIN_TOP_LEFT) { - rect.position += tile_ofs; } else if (node->get_tile_origin() == TileMap::TILE_ORIGIN_BOTTOM_LEFT) { - rect.position += tile_ofs; if (p_transpose) { - if (p_flip_h) + if (p_flip_h) { rect.position.x -= cell_size.x; - else + } else { rect.position.x += cell_size.x; + } } else { - if (p_flip_v) + if (p_flip_v) { rect.position.y -= cell_size.y; - else + } else { rect.position.y += cell_size.y; + } } } else if (node->get_tile_origin() == TileMap::TILE_ORIGIN_CENTER) { - rect.position += tile_ofs; - if (p_flip_h) + if (p_flip_h) { rect.position.x -= cell_size.x / 2; - else + } else { rect.position.x += cell_size.x / 2; + } - if (p_flip_v) + if (p_flip_v) { rect.position.y -= cell_size.y / 2; - else + } else { rect.position.y += cell_size.y / 2; + } } } else { rect.position += tile_ofs; @@ -894,7 +876,6 @@ void TileMapEditor::_draw_cell(Control *p_viewport, int p_cell, const Point2i &p } void TileMapEditor::_draw_fill_preview(Control *p_viewport, int p_cell, const Point2i &p_point, bool p_flip_h, bool p_flip_v, bool p_transpose, const Point2i &p_autotile_coord, const Transform2D &p_xform) { - Vector<Vector2> points = _bucket_fill(p_point, false, true); const Vector2 *pr = points.ptr(); int len = points.size(); @@ -912,16 +893,14 @@ void TileMapEditor::_clear_bucket_cache() { } void TileMapEditor::_update_copydata() { - copydata.clear(); - if (!selection_active) + if (!selection_active) { return; + } for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) { - for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) { - TileData tcd; tcd.cell = node->get_cell(j, i); @@ -939,7 +918,6 @@ void TileMapEditor::_update_copydata() { } static inline Vector<Point2i> line(int x0, int x1, int y0, int y1) { - Vector<Point2i> points; float dx = ABS(x1 - x0); @@ -983,9 +961,9 @@ static inline Vector<Point2i> line(int x0, int x1, int y0, int y1) { } bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { - - if (!node || !node->get_tileset().is_valid() || !node->is_visible_in_tree() || CanvasItemEditor::get_singleton()->get_current_tool() != CanvasItemEditor::TOOL_SELECT) + if (!node || !node->get_tileset().is_valid() || !node->is_visible_in_tree() || CanvasItemEditor::get_singleton()->get_current_tool() != CanvasItemEditor::TOOL_SELECT) { return false; + } Transform2D xform = CanvasItemEditor::get_singleton()->get_canvas_transform() * node->get_global_transform(); Transform2D xform_inv = xform.affine_inverse(); @@ -994,20 +972,18 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { if (mb.is_valid()) { if (mb->get_button_index() == BUTTON_LEFT) { - if (mb->is_pressed()) { - - if (Input::get_singleton()->is_key_pressed(KEY_SPACE)) + if (Input::get_singleton()->is_key_pressed(KEY_SPACE)) { return false; // Drag. + } if (tool == TOOL_NONE) { - if (mb->get_shift()) { - - if (mb->get_command()) + if (mb->get_command()) { tool = TOOL_RECTANGLE_PAINT; - else + } else { tool = TOOL_LINE_PAINT; + } selection_active = false; rectangle_begin = over_tile; @@ -1029,20 +1005,16 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { } if (tool == TOOL_PAINTING) { - Vector<int> ids = get_selected_tiles(); if (ids.size() > 0 && ids[0] != TileMap::INVALID_CELL) { - tool = TOOL_PAINTING; _start_undo(TTR("Paint TileMap")); } } else if (tool == TOOL_PICKING) { - _pick_tile(over_tile); } else if (tool == TOOL_SELECTING) { - selection_active = true; rectangle_begin = over_tile; } @@ -1053,27 +1025,21 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { } else { // Mousebutton was released. if (tool != TOOL_NONE) { - if (tool == TOOL_PAINTING) { - Vector<int> ids = get_selected_tiles(); if (ids.size() > 0 && ids[0] != TileMap::INVALID_CELL) { - _set_cell(over_tile, ids, flip_h, flip_v, transpose); _finish_undo(); paint_undo.clear(); } } else if (tool == TOOL_LINE_PAINT) { - Vector<int> ids = get_selected_tiles(); if (ids.size() > 0 && ids[0] != TileMap::INVALID_CELL) { - _start_undo(TTR("Line Draw")); for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) { - _set_cell(E->key(), ids, flip_h, flip_v, transpose); } _finish_undo(); @@ -1083,15 +1049,12 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { CanvasItemEditor::get_singleton()->update_viewport(); } } else if (tool == TOOL_RECTANGLE_PAINT) { - Vector<int> ids = get_selected_tiles(); if (ids.size() > 0 && ids[0] != TileMap::INVALID_CELL) { - _start_undo(TTR("Rectangle Paint")); for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) { for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) { - _set_cell(Point2i(j, i), ids, flip_h, flip_v, transpose); } } @@ -1100,14 +1063,12 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { CanvasItemEditor::get_singleton()->update_viewport(); } } else if (tool == TOOL_PASTING) { - Point2 ofs = over_tile - rectangle.position; Vector<int> ids; _start_undo(TTR("Paste")); ids.push_back(0); for (List<TileData>::Element *E = copydata.front(); E; E = E->next()) { - ids.write[0] = E->get().cell; _set_cell(E->get().pos + ofs, ids, E->get().flip_h, E->get().flip_v, E->get().transpose, E->get().autotile_coord); } @@ -1117,15 +1078,14 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { return true; // We want to keep the Pasting tool. } else if (tool == TOOL_SELECTING) { - CanvasItemEditor::get_singleton()->update_viewport(); } else if (tool == TOOL_BUCKET) { - Vector<Vector2> points = _bucket_fill(over_tile); - if (points.size() == 0) + if (points.size() == 0) { return false; + } _start_undo(TTR("Bucket Fill")); @@ -1153,11 +1113,8 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { } } } else if (mb->get_button_index() == BUTTON_RIGHT) { - if (mb->is_pressed()) { - if (tool == TOOL_SELECTING || selection_active) { - tool = TOOL_NONE; selection_active = false; @@ -1168,7 +1125,6 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { } if (tool == TOOL_PASTING) { - tool = TOOL_NONE; copydata.clear(); @@ -1179,7 +1135,6 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { } if (tool == TOOL_NONE) { - paint_undo.clear(); Point2 local = node->world_to_map(xform_inv.xform(mb->get_position())); @@ -1187,15 +1142,15 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { _start_undo(TTR("Erase TileMap")); if (mb->get_shift()) { - if (mb->get_command()) + if (mb->get_command()) { tool = TOOL_RECTANGLE_ERASE; - else + } else { tool = TOOL_LINE_ERASE; + } selection_active = false; rectangle_begin = local; } else { - tool = TOOL_ERASING; _set_cell(local, invalid_cell); @@ -1207,7 +1162,6 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { } else { if (tool == TOOL_ERASING || tool == TOOL_RECTANGLE_ERASE || tool == TOOL_LINE_ERASE) { - _finish_undo(); if (tool == TOOL_RECTANGLE_ERASE || tool == TOOL_LINE_ERASE) { @@ -1220,7 +1174,6 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { return true; } else if (tool == TOOL_BUCKET) { - Vector<int> ids; ids.push_back(node->get_cell(over_tile.x, over_tile.y)); Dictionary pop; @@ -1231,8 +1184,9 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { Vector<Vector2> points = _bucket_fill(over_tile, true); - if (points.size() == 0) + if (points.size() == 0) { return false; + } undo_redo->create_action(TTR("Bucket Fill")); @@ -1248,12 +1202,10 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseMotion> mm = p_event; if (mm.is_valid()) { - Point2i new_over_tile = node->world_to_map(xform_inv.xform(mm->get_position())); Point2i old_over_tile = over_tile; if (new_over_tile != over_tile) { - over_tile = new_over_tile; CanvasItemEditor::get_singleton()->update_viewport(); } @@ -1261,20 +1213,19 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { int tile_under = node->get_cell(over_tile.x, over_tile.y); String tile_name = "none"; - if (node->get_tileset()->has_tile(tile_under)) + if (node->get_tileset()->has_tile(tile_under)) { tile_name = node->get_tileset()->tile_get_name(tile_under); + } tile_info->show(); tile_info->set_text(String::num(over_tile.x) + ", " + String::num(over_tile.y) + " [" + tile_name + "]"); if (tool == TOOL_PAINTING) { - // Paint using bresenham line to prevent holes in painting if the user moves fast. Vector<Point2i> points = line(old_over_tile.x, over_tile.x, old_over_tile.y, over_tile.y); Vector<int> ids = get_selected_tiles(); for (int i = 0; i < points.size(); ++i) { - Point2i pos = points[i]; if (!paint_undo.has(pos)) { @@ -1288,13 +1239,11 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { } if (tool == TOOL_ERASING) { - // Erase using bresenham line to prevent holes in painting if the user moves fast. Vector<Point2i> points = line(old_over_tile.x, over_tile.x, old_over_tile.y, over_tile.y); for (int i = 0; i < points.size(); ++i) { - Point2i pos = points[i]; _set_cell(pos, invalid_cell); @@ -1304,23 +1253,19 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { } if (tool == TOOL_SELECTING) { - _select(rectangle_begin, over_tile); return true; } if (tool == TOOL_LINE_PAINT || tool == TOOL_LINE_ERASE) { - Vector<int> ids = get_selected_tiles(); Vector<int> tmp_cell; bool erasing = (tool == TOOL_LINE_ERASE); tmp_cell.push_back(0); if (erasing && paint_undo.size()) { - for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) { - tmp_cell.write[0] = E->get().idx; _set_cell(E->key(), tmp_cell, E->get().xf, E->get().yf, E->get().tr); } @@ -1329,15 +1274,14 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { paint_undo.clear(); if (ids.size() > 0 && ids[0] != TileMap::INVALID_CELL) { - Vector<Point2i> points = line(rectangle_begin.x, over_tile.x, rectangle_begin.y, over_tile.y); for (int i = 0; i < points.size(); i++) { - paint_undo[points[i]] = _get_op_from_cell(points[i]); - if (erasing) + if (erasing) { _set_cell(points[i], invalid_cell); + } } CanvasItemEditor::get_singleton()->update_viewport(); @@ -1346,18 +1290,14 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { return true; } if (tool == TOOL_RECTANGLE_PAINT || tool == TOOL_RECTANGLE_ERASE) { - Vector<int> tmp_cell; tmp_cell.push_back(0); _select(rectangle_begin, over_tile); if (tool == TOOL_RECTANGLE_ERASE) { - if (paint_undo.size()) { - for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) { - tmp_cell.write[0] = E->get().idx; _set_cell(E->key(), tmp_cell, E->get().xf, E->get().yf, E->get().tr); } @@ -1367,7 +1307,6 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) { for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) { - Point2i tile = Point2i(j, i); paint_undo[tile] = _get_op_from_cell(tile); @@ -1379,7 +1318,6 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { return true; } if (tool == TOOL_PICKING && Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) { - _pick_tile(over_tile); return true; @@ -1389,7 +1327,6 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventKey> k = p_event; if (k.is_valid() && k->is_pressed()) { - if (last_tool == TOOL_NONE && tool == TOOL_PICKING && k->get_keycode() == KEY_SHIFT && k->get_command()) { // trying to draw a rectangle with the painting tool, so change to the correct tool tool = last_tool; @@ -1399,11 +1336,11 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { } if (k->get_keycode() == KEY_ESCAPE) { - - if (tool == TOOL_PASTING) + if (tool == TOOL_PASTING) { copydata.clear(); - else if (tool == TOOL_SELECTING || selection_active) + } else if (tool == TOOL_SELECTING || selection_active) { selection_active = false; + } tool = TOOL_NONE; @@ -1518,14 +1455,11 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { } else if (k.is_valid()) { // Release event. if (tool == TOOL_NONE) { - if (k->get_keycode() == KEY_SHIFT && k->get_command()) { - tool = TOOL_PICKING; _update_button_tool(); } } else if (tool == TOOL_PICKING) { - #ifdef APPLE_STYLE_KEYS if (k->get_keycode() == KEY_META) { #else @@ -1543,9 +1477,9 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { } void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { - - if (!node || CanvasItemEditor::get_singleton()->get_current_tool() != CanvasItemEditor::TOOL_SELECT) + if (!node || CanvasItemEditor::get_singleton()->get_current_tool() != CanvasItemEditor::TOOL_SELECT) { return; + } Transform2D cell_xf = node->get_cell_transform(); Transform2D xform = CanvasItemEditor::get_singleton()->get_canvas_transform() * node->get_global_transform(); @@ -1561,27 +1495,23 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { Rect2i si = aabb.grow(1.0); if (node->get_half_offset() != TileMap::HALF_OFFSET_X && node->get_half_offset() != TileMap::HALF_OFFSET_NEGATIVE_X) { - int max_lines = 2000; //avoid crash if size too small for (int i = (si.position.x) - 1; i <= (si.position.x + si.size.x); i++) { - Vector2 from = xform.xform(node->map_to_world(Vector2(i, si.position.y))); Vector2 to = xform.xform(node->map_to_world(Vector2(i, si.position.y + si.size.y + 1))); Color col = i == 0 ? Color(1, 0.8, 0.2, 0.5) : Color(1, 0.3, 0.1, 0.2); p_overlay->draw_line(from, to, col, 1); - if (max_lines-- == 0) + if (max_lines-- == 0) { break; + } } } else { - int max_lines = 10000; //avoid crash if size too small for (int i = (si.position.x) - 1; i <= (si.position.x + si.size.x); i++) { - for (int j = (si.position.y) - 1; j <= (si.position.y + si.size.y); j++) { - Vector2 ofs; if (ABS(j) & 1) { ofs = cell_xf[0] * (node->get_half_offset() == TileMap::HALF_OFFSET_X ? 0.5 : -0.5); @@ -1593,35 +1523,33 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { Color col = i == 0 ? Color(1, 0.8, 0.2, 0.5) : Color(1, 0.3, 0.1, 0.2); p_overlay->draw_line(from, to, col, 1); - if (--max_lines == 0) + if (--max_lines == 0) { break; + } } - if (max_lines == 0) + if (max_lines == 0) { break; + } } } int max_lines = 10000; //avoid crash if size too small if (node->get_half_offset() != TileMap::HALF_OFFSET_Y && node->get_half_offset() != TileMap::HALF_OFFSET_NEGATIVE_Y) { - for (int i = (si.position.y) - 1; i <= (si.position.y + si.size.y); i++) { - Vector2 from = xform.xform(node->map_to_world(Vector2(si.position.x, i))); Vector2 to = xform.xform(node->map_to_world(Vector2(si.position.x + si.size.x + 1, i))); Color col = i == 0 ? Color(1, 0.8, 0.2, 0.5) : Color(1, 0.3, 0.1, 0.2); p_overlay->draw_line(from, to, col, 1); - if (max_lines-- == 0) + if (max_lines-- == 0) { break; + } } } else { - for (int i = (si.position.y) - 1; i <= (si.position.y + si.size.y); i++) { - for (int j = (si.position.x) - 1; j <= (si.position.x + si.size.x); j++) { - Vector2 ofs; if (ABS(j) & 1) { ofs = cell_xf[1] * (node->get_half_offset() == TileMap::HALF_OFFSET_Y ? 0.5 : -0.5); @@ -1633,17 +1561,18 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { Color col = i == 0 ? Color(1, 0.8, 0.2, 0.5) : Color(1, 0.3, 0.1, 0.2); p_overlay->draw_line(from, to, col, 1); - if (--max_lines == 0) + if (--max_lines == 0) { break; + } } - if (max_lines == 0) + if (max_lines == 0) { break; + } } } } if (selection_active) { - Vector<Vector2> points; points.push_back(xform.xform(node->map_to_world((rectangle.position)))); points.push_back(xform.xform(node->map_to_world((rectangle.position + Point2(rectangle.size.x + 1, 0))))); @@ -1654,7 +1583,6 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { } if (mouse_over && node->get_tileset().is_valid()) { - Vector2 endpoints[4] = { node->map_to_world(over_tile, true), node->map_to_world((over_tile + Point2(1, 0)), true), @@ -1663,24 +1591,30 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { }; for (int i = 0; i < 4; i++) { - if (node->get_half_offset() == TileMap::HALF_OFFSET_X && ABS(over_tile.y) & 1) + if (node->get_half_offset() == TileMap::HALF_OFFSET_X && ABS(over_tile.y) & 1) { endpoints[i] += cell_xf[0] * 0.5; - if (node->get_half_offset() == TileMap::HALF_OFFSET_NEGATIVE_X && ABS(over_tile.y) & 1) + } + if (node->get_half_offset() == TileMap::HALF_OFFSET_NEGATIVE_X && ABS(over_tile.y) & 1) { endpoints[i] += cell_xf[0] * -0.5; - if (node->get_half_offset() == TileMap::HALF_OFFSET_Y && ABS(over_tile.x) & 1) + } + if (node->get_half_offset() == TileMap::HALF_OFFSET_Y && ABS(over_tile.x) & 1) { endpoints[i] += cell_xf[1] * 0.5; - if (node->get_half_offset() == TileMap::HALF_OFFSET_NEGATIVE_Y && ABS(over_tile.x) & 1) + } + if (node->get_half_offset() == TileMap::HALF_OFFSET_NEGATIVE_Y && ABS(over_tile.x) & 1) { endpoints[i] += cell_xf[1] * -0.5; + } endpoints[i] = xform.xform(endpoints[i]); } Color col; - if (node->get_cell(over_tile.x, over_tile.y) != TileMap::INVALID_CELL) + if (node->get_cell(over_tile.x, over_tile.y) != TileMap::INVALID_CELL) { col = Color(0.2, 0.8, 1.0, 0.8); - else + } else { col = Color(1.0, 0.4, 0.2, 0.8); + } - for (int i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) { p_overlay->draw_line(endpoints[i], endpoints[(i + 1) % 4], col, 2); + } bool bucket_preview = EditorSettings::get_singleton()->get("editors/tile_map/bucket_fill_preview"); if (tool == TOOL_SELECTING || tool == TOOL_PICKING || !bucket_preview) { @@ -1688,49 +1622,49 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { } if (tool == TOOL_LINE_PAINT) { - - if (paint_undo.empty()) + if (paint_undo.empty()) { return; + } Vector<int> ids = get_selected_tiles(); - if (ids.size() == 1 && ids[0] == TileMap::INVALID_CELL) + if (ids.size() == 1 && ids[0] == TileMap::INVALID_CELL) { return; + } for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) { - _draw_cell(p_overlay, ids[0], E->key(), flip_h, flip_v, transpose, autotile_coord, xform); } } else if (tool == TOOL_RECTANGLE_PAINT) { - Vector<int> ids = get_selected_tiles(); - if (ids.size() == 1 && ids[0] == TileMap::INVALID_CELL) + if (ids.size() == 1 && ids[0] == TileMap::INVALID_CELL) { return; + } for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) { for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) { - _draw_cell(p_overlay, ids[0], Point2i(j, i), flip_h, flip_v, transpose, autotile_coord, xform); } } } else if (tool == TOOL_PASTING) { - - if (copydata.empty()) + if (copydata.empty()) { return; + } Ref<TileSet> ts = node->get_tileset(); - if (ts.is_null()) + if (ts.is_null()) { return; + } Point2 ofs = over_tile - rectangle.position; for (List<TileData>::Element *E = copydata.front(); E; E = E->next()) { - - if (!ts->has_tile(E->get().cell)) + if (!ts->has_tile(E->get().cell)) { continue; + } TileData tcd = E->get(); @@ -1749,16 +1683,15 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { p_overlay->draw_colored_polygon(points, Color(0.2, 1.0, 0.8, 0.2)); } else if (tool == TOOL_BUCKET) { - Vector<int> tiles = get_selected_tiles(); _draw_fill_preview(p_overlay, tiles[0], over_tile, flip_h, flip_v, transpose, autotile_coord, xform); } else { - Vector<int> st = get_selected_tiles(); - if (st.size() == 1 && st[0] == TileMap::INVALID_CELL) + if (st.size() == 1 && st[0] == TileMap::INVALID_CELL) { return; + } _draw_cell(p_overlay, st[0], over_tile, flip_h, flip_v, transpose, autotile_coord, xform); } @@ -1766,44 +1699,47 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { } void TileMapEditor::edit(Node *p_tile_map) { - search_box->set_text(""); if (!canvas_item_editor_viewport) { canvas_item_editor_viewport = CanvasItemEditor::get_singleton()->get_viewport_control(); } - if (node) + if (node) { node->disconnect("settings_changed", callable_mp(this, &TileMapEditor::_tileset_settings_changed)); + } if (p_tile_map) { - node = Object::cast_to<TileMap>(p_tile_map); - if (!canvas_item_editor_viewport->is_connected("mouse_entered", callable_mp(this, &TileMapEditor::_canvas_mouse_enter))) + if (!canvas_item_editor_viewport->is_connected("mouse_entered", callable_mp(this, &TileMapEditor::_canvas_mouse_enter))) { canvas_item_editor_viewport->connect("mouse_entered", callable_mp(this, &TileMapEditor::_canvas_mouse_enter)); - if (!canvas_item_editor_viewport->is_connected("mouse_exited", callable_mp(this, &TileMapEditor::_canvas_mouse_exit))) + } + if (!canvas_item_editor_viewport->is_connected("mouse_exited", callable_mp(this, &TileMapEditor::_canvas_mouse_exit))) { canvas_item_editor_viewport->connect("mouse_exited", callable_mp(this, &TileMapEditor::_canvas_mouse_exit)); + } _update_palette(); } else { node = nullptr; - if (canvas_item_editor_viewport->is_connected("mouse_entered", callable_mp(this, &TileMapEditor::_canvas_mouse_enter))) + if (canvas_item_editor_viewport->is_connected("mouse_entered", callable_mp(this, &TileMapEditor::_canvas_mouse_enter))) { canvas_item_editor_viewport->disconnect("mouse_entered", callable_mp(this, &TileMapEditor::_canvas_mouse_enter)); - if (canvas_item_editor_viewport->is_connected("mouse_exited", callable_mp(this, &TileMapEditor::_canvas_mouse_exit))) + } + if (canvas_item_editor_viewport->is_connected("mouse_exited", callable_mp(this, &TileMapEditor::_canvas_mouse_exit))) { canvas_item_editor_viewport->disconnect("mouse_exited", callable_mp(this, &TileMapEditor::_canvas_mouse_exit)); + } _update_palette(); } - if (node) + if (node) { node->connect("settings_changed", callable_mp(this, &TileMapEditor::_tileset_settings_changed)); + } _clear_bucket_cache(); } void TileMapEditor::_tileset_settings_changed() { - _update_palette(); CanvasItemEditor::get_singleton()->update_viewport(); } @@ -1817,7 +1753,6 @@ void TileMapEditor::_icon_size_changed(float p_value) { } void TileMapEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_fill_points"), &TileMapEditor::_fill_points); ClassDB::bind_method(D_METHOD("_erase_points"), &TileMapEditor::_erase_points); } @@ -1826,12 +1761,15 @@ TileMapEditor::CellOp TileMapEditor::_get_op_from_cell(const Point2i &p_pos) { CellOp op; op.idx = node->get_cell(p_pos.x, p_pos.y); if (op.idx != TileMap::INVALID_CELL) { - if (node->is_cell_x_flipped(p_pos.x, p_pos.y)) + if (node->is_cell_x_flipped(p_pos.x, p_pos.y)) { op.xf = true; - if (node->is_cell_y_flipped(p_pos.x, p_pos.y)) + } + if (node->is_cell_y_flipped(p_pos.x, p_pos.y)) { op.yf = true; - if (node->is_cell_transposed(p_pos.x, p_pos.y)) + } + if (node->is_cell_transposed(p_pos.x, p_pos.y)) { op.tr = true; + } op.ac = node->get_cell_autotile_coord(p_pos.x, p_pos.y); } return op; @@ -1901,7 +1839,6 @@ void TileMapEditor::_clear_transform() { } TileMapEditor::TileMapEditor(EditorNode *p_editor) { - node = nullptr; manual_autotile = false; priority_atlastile = false; @@ -2112,9 +2049,7 @@ TileMapEditor::~TileMapEditor() { /////////////////////////////////////////////////////////////// void TileMapEditorPlugin::_notification(int p_what) { - if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { - switch ((int)EditorSettings::get_singleton()->get("editors/tile_map/editor_side")) { case 0: { // Left. CanvasItemEditor::get_singleton()->get_palette_split()->move_child(tile_map_editor, 0); @@ -2127,19 +2062,15 @@ void TileMapEditorPlugin::_notification(int p_what) { } void TileMapEditorPlugin::edit(Object *p_object) { - tile_map_editor->edit(Object::cast_to<Node>(p_object)); } bool TileMapEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("TileMap"); } void TileMapEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { - tile_map_editor->show(); tile_map_editor->get_toolbar()->show(); tile_map_editor->get_toolbar_right()->show(); @@ -2150,7 +2081,6 @@ void TileMapEditorPlugin::make_visible(bool p_visible) { // Change to TOOL_SELECT when TileMap node is selected, to prevent accidental movement. CanvasItemEditor::get_singleton()->set_current_tool(CanvasItemEditor::TOOL_SELECT); } else { - tile_map_editor->hide(); tile_map_editor->get_toolbar()->hide(); tile_map_editor->get_toolbar_right()->hide(); @@ -2160,7 +2090,6 @@ void TileMapEditorPlugin::make_visible(bool p_visible) { } TileMapEditorPlugin::TileMapEditorPlugin(EditorNode *p_node) { - EDITOR_DEF("editors/tile_map/preview_size", 64); EDITOR_DEF("editors/tile_map/palette_item_hseparation", 8); EDITOR_DEF("editors/tile_map/show_tile_names", true); diff --git a/editor/plugins/tile_map_editor_plugin.h b/editor/plugins/tile_map_editor_plugin.h index 28b0e9b6db..5f82d7bfb8 100644 --- a/editor/plugins/tile_map_editor_plugin.h +++ b/editor/plugins/tile_map_editor_plugin.h @@ -41,7 +41,6 @@ #include "scene/gui/tool_button.h" class TileMapEditor : public VBoxContainer { - GDCLASS(TileMapEditor, VBoxContainer); enum Tool { @@ -221,7 +220,6 @@ public: }; class TileMapEditorPlugin : public EditorPlugin { - GDCLASS(TileMapEditorPlugin, EditorPlugin); TileMapEditor *tile_map_editor; diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp index b0d325efc1..644facd5bd 100644 --- a/editor/plugins/tile_set_editor_plugin.cpp +++ b/editor/plugins/tile_set_editor_plugin.cpp @@ -38,7 +38,6 @@ #include "scene/2d/sprite_2d.h" void TileSetEditor::edit(const Ref<TileSet> &p_tileset) { - tileset = p_tileset; tileset->add_change_receptor(this); @@ -48,9 +47,7 @@ void TileSetEditor::edit(const Ref<TileSet> &p_tileset) { } void TileSetEditor::_import_node(Node *p_node, Ref<TileSet> p_library) { - for (int i = 0; i < p_node->get_child_count(); i++) { - Node *child = p_node->get_child(i); if (!Object::cast_to<Sprite2D>(child)) { @@ -66,12 +63,12 @@ void TileSetEditor::_import_node(Node *p_node, Ref<TileSet> p_library) { Ref<Texture2D> normal_map = mi->get_normal_map(); Ref<ShaderMaterial> material = mi->get_material(); - if (texture.is_null()) + if (texture.is_null()) { continue; + } int id = p_library->find_tile_by_name(mi->get_name()); if (id < 0) { - id = p_library->get_last_unused_tile_id(); p_library->create_tile(id); p_library->tile_set_name(id, mi->get_name()); @@ -106,17 +103,19 @@ void TileSetEditor::_import_node(Node *p_node, Ref<TileSet> p_library) { bool found_collisions = false; for (int j = 0; j < mi->get_child_count(); j++) { - Node *child2 = mi->get_child(j); - if (Object::cast_to<NavigationRegion2D>(child2)) + if (Object::cast_to<NavigationRegion2D>(child2)) { nav_poly = Object::cast_to<NavigationRegion2D>(child2)->get_navigation_polygon(); + } - if (Object::cast_to<LightOccluder2D>(child2)) + if (Object::cast_to<LightOccluder2D>(child2)) { occluder = Object::cast_to<LightOccluder2D>(child2)->get_occluder_polygon(); + } - if (!Object::cast_to<StaticBody2D>(child2)) + if (!Object::cast_to<StaticBody2D>(child2)) { continue; + } found_collisions = true; @@ -126,8 +125,9 @@ void TileSetEditor::_import_node(Node *p_node, Ref<TileSet> p_library) { sb->get_shape_owners(&shapes); for (List<uint32_t>::Element *E = shapes.front(); E; E = E->next()) { - if (sb->is_shape_owner_disabled(E->get())) + if (sb->is_shape_owner_disabled(E->get())) { continue; + } Transform2D shape_transform = sb->get_transform() * sb->shape_owner_get_transform(E->get()); bool one_way = sb->is_shape_owner_one_way_collision_enabled(E->get()); @@ -135,7 +135,6 @@ void TileSetEditor::_import_node(Node *p_node, Ref<TileSet> p_library) { shape_transform[2] -= phys_offset; for (int k = 0; k < sb->shape_owner_get_shape_count(E->get()); k++) { - Ref<Shape2D> shape = sb->shape_owner_get_shape(E->get(), k); TileSet::ShapeData shape_data; shape_data.shape = shape; @@ -160,38 +159,36 @@ void TileSetEditor::_import_node(Node *p_node, Ref<TileSet> p_library) { } void TileSetEditor::_import_scene(Node *p_scene, Ref<TileSet> p_library, bool p_merge) { - - if (!p_merge) + if (!p_merge) { p_library->clear(); + } _import_node(p_scene, p_library); } void TileSetEditor::_undo_redo_import_scene(Node *p_scene, bool p_merge) { - _import_scene(p_scene, tileset, p_merge); } Error TileSetEditor::update_library_file(Node *p_base_scene, Ref<TileSet> ml, bool p_merge) { - _import_scene(p_base_scene, ml, p_merge); return OK; } Variant TileSetEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) { - return false; } bool TileSetEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { - Dictionary d = p_data; - if (!d.has("type")) + if (!d.has("type")) { return false; + } - if (d.has("from") && (Object *)(d["from"]) == texture_list) + if (d.has("from") && (Object *)(d["from"]) == texture_list) { return false; + } if (String(d["type"]) == "resource" && d.has("resource")) { RES r = d["resource"]; @@ -199,17 +196,16 @@ bool TileSetEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_dat Ref<Texture2D> texture = r; if (texture.is_valid()) { - return true; } } if (String(d["type"]) == "files") { - Vector<String> files = d["files"]; - if (files.size() == 0) + if (files.size() == 0) { return false; + } for (int i = 0; i < files.size(); i++) { String file = files[i]; @@ -226,22 +222,24 @@ bool TileSetEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_dat } void TileSetEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { - - if (!can_drop_data_fw(p_point, p_data, p_from)) + if (!can_drop_data_fw(p_point, p_data, p_from)) { return; + } Dictionary d = p_data; - if (!d.has("type")) + if (!d.has("type")) { return; + } if (String(d["type"]) == "resource" && d.has("resource")) { RES r = d["resource"]; Ref<Texture2D> texture = r; - if (texture.is_valid()) + if (texture.is_valid()) { add_texture(texture); + } if (texture_list->get_item_count() > 0) { update_texture_list_icon(); @@ -251,7 +249,6 @@ void TileSetEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, C } if (String(d["type"]) == "files") { - Vector<String> files = d["files"]; _on_textures_added(files); @@ -259,7 +256,6 @@ void TileSetEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, C } void TileSetEditor::_bind_methods() { - ClassDB::bind_method("_undo_redo_import_scene", &TileSetEditor::_undo_redo_import_scene); ClassDB::bind_method("_on_workspace_process", &TileSetEditor::_on_workspace_process); // Still used by some connect_compat. ClassDB::bind_method("_set_snap_step", &TileSetEditor::_set_snap_step); @@ -281,15 +277,12 @@ void TileSetEditor::_bind_methods() { } void TileSetEditor::_notification(int p_what) { - switch (p_what) { case NOTIFICATION_READY: { - add_theme_constant_override("autohide", 1); // Fixes the dragger always showing up. } break; case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { - tileset_toolbar_buttons[TOOL_TILESET_ADD_TEXTURE]->set_icon(get_theme_icon("ToolAddNode", "EditorIcons")); tileset_toolbar_buttons[TOOL_TILESET_REMOVE_TEXTURE]->set_icon(get_theme_icon("Remove", "EditorIcons")); tileset_toolbar_tools->set_icon(get_theme_icon("Tools", "EditorIcons")); @@ -331,7 +324,6 @@ void TileSetEditor::_notification(int p_what) { } TileSetEditor::TileSetEditor(EditorNode *p_editor) { - editor = p_editor; undo_redo = EditorNode::get_undo_redo(); current_tile = -1; @@ -626,7 +618,6 @@ TileSetEditor::TileSetEditor(EditorNode *p_editor) { ResourceLoader::get_recognized_extensions_for_type("Texture2D", &extensions); for (List<String>::Element *E = extensions.front(); E; E = E->next()) { - texture_dialog->add_filter("*." + E->get() + " ; " + E->get().to_upper()); } add_child(texture_dialog); @@ -643,8 +634,9 @@ TileSetEditor::TileSetEditor(EditorNode *p_editor) { } TileSetEditor::~TileSetEditor() { - if (helper) + if (helper) { memdelete(helper); + } } void TileSetEditor::_on_tileset_toolbar_button_pressed(int p_index) { @@ -663,12 +655,10 @@ void TileSetEditor::_on_tileset_toolbar_button_pressed(int p_index) { } } break; case TOOL_TILESET_CREATE_SCENE: { - cd->set_text(TTR("Create from scene? This will overwrite all current tiles.")); cd->popup_centered(Size2(300, 60)); } break; case TOOL_TILESET_MERGE_SCENE: { - cd->set_text(TTR("Merge from scene?")); cd->popup_centered(Size2(300, 60)); } break; @@ -696,11 +686,11 @@ void TileSetEditor::_on_tileset_toolbar_confirm() { } break; case TOOL_TILESET_MERGE_SCENE: case TOOL_TILESET_CREATE_SCENE: { - EditorNode *en = editor; Node *scene = en->get_edited_scene(); - if (!scene) + if (!scene) { break; + } List<int> ids; tileset->get_tile_list(&ids); @@ -895,9 +885,9 @@ void TileSetEditor::_on_workspace_mode_changed(int p_workspace_mode) { } void TileSetEditor::_on_workspace_draw() { - - if (tileset.is_null() || !get_current_texture().is_valid()) + if (tileset.is_null() || !get_current_texture().is_valid()) { return; + } const Color COLOR_AUTOTILE = Color(0.3, 0.6, 1); const Color COLOR_SINGLE = Color(1, 1, 0.3); @@ -1056,12 +1046,13 @@ void TileSetEditor::_on_workspace_draw() { Rect2i region = tileset->tile_get_region(t_id); region.position += WORKSPACE_MARGIN; Color c; - if (tileset->tile_get_tile_mode(t_id) == TileSet::SINGLE_TILE) + if (tileset->tile_get_tile_mode(t_id) == TileSet::SINGLE_TILE) { c = COLOR_SINGLE; - else if (tileset->tile_get_tile_mode(t_id) == TileSet::AUTO_TILE) + } else if (tileset->tile_get_tile_mode(t_id) == TileSet::AUTO_TILE) { c = COLOR_AUTOTILE; - else if (tileset->tile_get_tile_mode(t_id) == TileSet::ATLAS_TILE) + } else if (tileset->tile_get_tile_mode(t_id) == TileSet::ATLAS_TILE) { c = COLOR_ATLAS; + } draw_tile_subdivision(t_id, COLOR_SUBDIVISION); workspace->draw_rect(region, c, false); } @@ -1072,39 +1063,43 @@ void TileSetEditor::_on_workspace_draw() { if (workspace_mode != WORKSPACE_EDIT) { Rect2i region = edited_region; Color c; - if (workspace_mode == WORKSPACE_CREATE_SINGLE) + if (workspace_mode == WORKSPACE_CREATE_SINGLE) { c = COLOR_SINGLE; - else if (workspace_mode == WORKSPACE_CREATE_AUTOTILE) + } else if (workspace_mode == WORKSPACE_CREATE_AUTOTILE) { c = COLOR_AUTOTILE; - else if (workspace_mode == WORKSPACE_CREATE_ATLAS) + } else if (workspace_mode == WORKSPACE_CREATE_ATLAS) { c = COLOR_ATLAS; + } workspace->draw_rect(region, c, false); draw_edited_region_subdivision(); } else { int t_id = get_current_tile(); - if (t_id < 0) + if (t_id < 0) { return; + } Rect2i region; - if (draw_edited_region) + if (draw_edited_region) { region = edited_region; - else { + } else { region = tileset->tile_get_region(t_id); region.position += WORKSPACE_MARGIN; } - if (draw_edited_region) + if (draw_edited_region) { draw_edited_region_subdivision(); - else + } else { draw_tile_subdivision(t_id, COLOR_SUBDIVISION); + } Color c; - if (tileset->tile_get_tile_mode(t_id) == TileSet::SINGLE_TILE) + if (tileset->tile_get_tile_mode(t_id) == TileSet::SINGLE_TILE) { c = COLOR_SINGLE; - else if (tileset->tile_get_tile_mode(t_id) == TileSet::AUTO_TILE) + } else if (tileset->tile_get_tile_mode(t_id) == TileSet::AUTO_TILE) { c = COLOR_AUTOTILE; - else if (tileset->tile_get_tile_mode(t_id) == TileSet::ATLAS_TILE) + } else if (tileset->tile_get_tile_mode(t_id) == TileSet::ATLAS_TILE) { c = COLOR_ATLAS; + } workspace->draw_rect(region, c, false); } } @@ -1113,7 +1108,6 @@ void TileSetEditor::_on_workspace_draw() { } void TileSetEditor::_on_workspace_process() { - if (Input::get_singleton()->is_key_pressed(KEY_ALT) || tools[VISIBLE_INFO]->is_pressed()) { if (!tile_names_visible) { tile_names_visible = true; @@ -1126,9 +1120,9 @@ void TileSetEditor::_on_workspace_process() { } void TileSetEditor::_on_workspace_overlay_draw() { - - if (!tileset.is_valid() || !get_current_texture().is_valid()) + if (!tileset.is_valid() || !get_current_texture().is_valid()) { return; + } const Color COLOR_AUTOTILE = Color(0.266373, 0.565288, 0.988281); const Color COLOR_SINGLE = Color(0.988281, 0.909323, 0.266373); @@ -1140,19 +1134,21 @@ void TileSetEditor::_on_workspace_overlay_draw() { tileset->get_tile_list(tiles); for (List<int>::Element *E = tiles->front(); E; E = E->next()) { int t_id = E->get(); - if (tileset->tile_get_texture(t_id)->get_rid() != current_texture_rid) + if (tileset->tile_get_texture(t_id)->get_rid() != current_texture_rid) { continue; + } Rect2 region = tileset->tile_get_region(t_id); region.position += WORKSPACE_MARGIN; region.position *= workspace->get_scale().x; Color c; - if (tileset->tile_get_tile_mode(t_id) == TileSet::SINGLE_TILE) + if (tileset->tile_get_tile_mode(t_id) == TileSet::SINGLE_TILE) { c = COLOR_SINGLE; - else if (tileset->tile_get_tile_mode(t_id) == TileSet::AUTO_TILE) + } else if (tileset->tile_get_tile_mode(t_id) == TileSet::AUTO_TILE) { c = COLOR_AUTOTILE; - else if (tileset->tile_get_tile_mode(t_id) == TileSet::ATLAS_TILE) + } else if (tileset->tile_get_tile_mode(t_id) == TileSet::ATLAS_TILE) { c = COLOR_ATLAS; + } String tile_id_name = String::num(t_id, 0) + ": " + tileset->tile_get_name(t_id); Ref<Font> font = get_theme_font("font", "Label"); region.set_size(font->get_string_size(tile_id_name)); @@ -1165,8 +1161,9 @@ void TileSetEditor::_on_workspace_overlay_draw() { } int t_id = get_current_tile(); - if (t_id < 0) + if (t_id < 0) { return; + } Ref<Texture2D> handle = get_theme_icon("EditorHandle", "EditorIcons"); if (draw_handles) { @@ -1202,9 +1199,9 @@ bool TileSetEditor::is_within_grabbing_distance_of_first_point(const Vector2 &p_ } void TileSetEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) { - - if (tileset.is_null() || !get_current_texture().is_valid()) + if (tileset.is_null() || !get_current_texture().is_valid()) { return; + } static bool dragging; static bool erasing; @@ -1658,7 +1655,6 @@ void TileSetEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) { pos = snap_point(pos); if (creating_shape) { if (current_shape.size() > 2) { - if (is_within_grabbing_distance_of_first_point(mb->get_position(), grab_threshold)) { close_shape(shape_anchor); workspace->update(); @@ -1708,7 +1704,6 @@ void TileSetEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) { } } else if (!mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { if (creating_shape) { - // if the first two corners are within grabbing distance of one another, expand the rect to fill the tile if (is_within_grabbing_distance_of_first_point(current_shape[1], grab_threshold)) { current_shape.set(0, snap_point(shape_anchor)); @@ -1909,8 +1904,9 @@ void TileSetEditor::_on_tool_clicked(int p_tool) { } void TileSetEditor::_on_priority_changed(float val) { - if ((int)val == tileset->autotile_get_subtile_priority(get_current_tile(), edited_shape_coord)) + if ((int)val == tileset->autotile_get_subtile_priority(get_current_tile(), edited_shape_coord)) { return; + } undo_redo->create_action(TTR("Edit Tile Priority")); undo_redo->add_do_method(tileset.ptr(), "autotile_set_subtile_priority", get_current_tile(), edited_shape_coord, (int)val); @@ -1921,8 +1917,9 @@ void TileSetEditor::_on_priority_changed(float val) { } void TileSetEditor::_on_z_index_changed(float val) { - if ((int)val == tileset->autotile_get_z_index(get_current_tile(), edited_shape_coord)) + if ((int)val == tileset->autotile_get_z_index(get_current_tile(), edited_shape_coord)) { return; + } undo_redo->create_action(TTR("Edit Tile Z Index")); undo_redo->add_do_method(tileset.ptr(), "autotile_set_z_index", get_current_tile(), edited_shape_coord, (int)val); @@ -1978,8 +1975,9 @@ void TileSetEditor::_set_edited_shape_points(const Vector<Vector2> &points) { void TileSetEditor::_update_tile_data() { current_tile_data.clear(); - if (get_current_tile() < 0) + if (get_current_tile() < 0) { return; + } Vector<TileSet::ShapeData> sd = tileset->tile_get_shapes(get_current_tile()); if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::SINGLE_TILE) { @@ -2323,8 +2321,9 @@ void TileSetEditor::_set_snap_sep(Vector2 p_val) { } void TileSetEditor::_validate_current_tile_id() { - if (get_current_tile() >= 0 && !tileset->has_tile(get_current_tile())) + if (get_current_tile() >= 0 && !tileset->has_tile(get_current_tile())) { set_current_tile(-1); + } } void TileSetEditor::_select_edited_shape_coord() { @@ -2388,6 +2387,7 @@ void TileSetEditor::_zoom_in() { workspace_overlay->set_custom_minimum_size(workspace->get_rect().size * scale); } } + void TileSetEditor::_zoom_out() { float scale = workspace->get_scale().x; if (scale > min_scale) { @@ -2397,6 +2397,7 @@ void TileSetEditor::_zoom_out() { workspace_overlay->set_custom_minimum_size(workspace->get_rect().size * scale); } } + void TileSetEditor::_zoom_reset() { workspace->set_scale(Vector2(1, 1)); workspace_container->set_custom_minimum_size(workspace->get_rect().size); @@ -2404,7 +2405,6 @@ void TileSetEditor::_zoom_reset() { } void TileSetEditor::draw_highlight_current_tile() { - Color shadow_color = Color(0.3, 0.3, 0.3, 0.3); if ((workspace_mode == WORKSPACE_EDIT && get_current_tile() >= 0) || !edited_region.has_no_area()) { Rect2 region; @@ -2415,21 +2415,24 @@ void TileSetEditor::draw_highlight_current_tile() { region = edited_region; } - if (region.position.y >= 0) + if (region.position.y >= 0) { workspace->draw_rect(Rect2(0, 0, workspace->get_rect().size.x, region.position.y), shadow_color); - if (region.position.x >= 0) + } + if (region.position.x >= 0) { workspace->draw_rect(Rect2(0, MAX(0, region.position.y), region.position.x, MIN(workspace->get_rect().size.y - region.position.y, MIN(region.size.y, region.position.y + region.size.y))), shadow_color); - if (region.position.x + region.size.x <= workspace->get_rect().size.x) + } + if (region.position.x + region.size.x <= workspace->get_rect().size.x) { workspace->draw_rect(Rect2(region.position.x + region.size.x, MAX(0, region.position.y), workspace->get_rect().size.x - region.position.x - region.size.x, MIN(workspace->get_rect().size.y - region.position.y, MIN(region.size.y, region.position.y + region.size.y))), shadow_color); - if (region.position.y + region.size.y <= workspace->get_rect().size.y) + } + if (region.position.y + region.size.y <= workspace->get_rect().size.y) { workspace->draw_rect(Rect2(0, region.position.y + region.size.y, workspace->get_rect().size.x, workspace->get_rect().size.y - region.size.y - region.position.y), shadow_color); + } } else { workspace->draw_rect(Rect2(Point2(0, 0), workspace->get_rect().size), shadow_color); } } void TileSetEditor::draw_highlight_subtile(Vector2 coord, const Vector<Vector2> &other_highlighted) { - Color shadow_color = Color(0.3, 0.3, 0.3, 0.3); Vector2 size = tileset->autotile_get_size(get_current_tile()); int spacing = tileset->autotile_get_spacing(get_current_tile()); @@ -2439,14 +2442,18 @@ void TileSetEditor::draw_highlight_subtile(Vector2 coord, const Vector<Vector2> coord += region.position; coord += WORKSPACE_MARGIN; - if (coord.y >= 0) + if (coord.y >= 0) { workspace->draw_rect(Rect2(0, 0, workspace->get_rect().size.x, coord.y), shadow_color); - if (coord.x >= 0) + } + if (coord.x >= 0) { workspace->draw_rect(Rect2(0, MAX(0, coord.y), coord.x, MIN(workspace->get_rect().size.y - coord.y, MIN(size.y, coord.y + size.y))), shadow_color); - if (coord.x + size.x <= workspace->get_rect().size.x) + } + if (coord.x + size.x <= workspace->get_rect().size.x) { workspace->draw_rect(Rect2(coord.x + size.x, MAX(0, coord.y), workspace->get_rect().size.x - coord.x - size.x, MIN(workspace->get_rect().size.y - coord.y, MIN(size.y, coord.y + size.y))), shadow_color); - if (coord.y + size.y <= workspace->get_rect().size.y) + } + if (coord.y + size.y <= workspace->get_rect().size.y) { workspace->draw_rect(Rect2(0, coord.y + size.y, workspace->get_rect().size.x, workspace->get_rect().size.y - size.y - coord.y), shadow_color); + } coord += Vector2(1, 1) / workspace->get_scale().x; workspace->draw_rect(Rect2(coord, size - Vector2(2, 2) / workspace->get_scale().x), Color(1, 0, 0), false); @@ -2579,10 +2586,10 @@ void TileSetEditor::draw_grid_snap() { } void TileSetEditor::draw_polygon_shapes() { - int t_id = get_current_tile(); - if (t_id < 0) + if (t_id < 0) { return; + } switch (edit_mode) { case EDITMODE_COLLISION: { @@ -2638,8 +2645,9 @@ void TileSetEditor::draw_polygon_shapes() { } } - if (polygon.size() < 3) + if (polygon.size() < 3) { continue; + } workspace->draw_polygon(polygon, colors); @@ -2848,7 +2856,6 @@ void TileSetEditor::draw_polygon_shapes() { } void TileSetEditor::close_shape(const Vector2 &shape_anchor) { - creating_shape = false; if (edit_mode == EDITMODE_COLLISION) { @@ -2861,14 +2868,16 @@ void TileSetEditor::close_shape(const Vector2 &shape_anchor) { for (int i = 0; i < current_shape.size(); i++) { points.push_back(current_shape[i] - shape_anchor); - if (i != current_shape.size() - 1) + if (i != current_shape.size() - 1) { p_total += ((current_shape[i + 1].x - current_shape[i].x) * (-current_shape[i + 1].y + (-current_shape[i].y))); - else + } else { p_total += ((current_shape[0].x - current_shape[i].x) * (-current_shape[0].y + (-current_shape[i].y))); + } } - if (p_total < 0) + if (p_total < 0) { points.invert(); + } shape->set_points(points); @@ -2883,10 +2892,11 @@ void TileSetEditor::close_shape(const Vector2 &shape_anchor) { } } undo_redo->add_do_method(tileset.ptr(), "tile_set_shapes", get_current_tile(), sd); - if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::AUTO_TILE || tileset->tile_get_tile_mode(get_current_tile()) == TileSet::ATLAS_TILE) + if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::AUTO_TILE || tileset->tile_get_tile_mode(get_current_tile()) == TileSet::ATLAS_TILE) { undo_redo->add_do_method(tileset.ptr(), "tile_add_shape", get_current_tile(), shape, Transform2D(), false, edited_shape_coord); - else + } else { undo_redo->add_do_method(tileset.ptr(), "tile_add_shape", get_current_tile(), shape, Transform2D()); + } tools[TOOL_SELECT]->set_pressed(true); undo_redo->add_do_method(this, "_select_edited_shape_coord"); undo_redo->add_undo_method(this, "_select_edited_shape_coord"); @@ -2955,17 +2965,21 @@ void TileSetEditor::close_shape(const Vector2 &shape_anchor) { void TileSetEditor::select_coord(const Vector2 &coord) { _update_tile_data(); current_shape = PackedVector2Array(); - if (get_current_tile() == -1) + if (get_current_tile() == -1) { return; + } Rect2 current_tile_region = tileset->tile_get_region(get_current_tile()); current_tile_region.position += WORKSPACE_MARGIN; if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::SINGLE_TILE) { - if (edited_collision_shape != tileset->tile_get_shape(get_current_tile(), 0)) + if (edited_collision_shape != tileset->tile_get_shape(get_current_tile(), 0)) { _set_edited_collision_shape(tileset->tile_get_shape(get_current_tile(), 0)); - if (edited_occlusion_shape != tileset->tile_get_light_occluder(get_current_tile())) + } + if (edited_occlusion_shape != tileset->tile_get_light_occluder(get_current_tile())) { edited_occlusion_shape = tileset->tile_get_light_occluder(get_current_tile()); - if (edited_navigation_shape != tileset->tile_get_navigation_polygon(get_current_tile())) + } + if (edited_navigation_shape != tileset->tile_get_navigation_polygon(get_current_tile())) { edited_navigation_shape = tileset->tile_get_navigation_polygon(get_current_tile()); + } if (edit_mode == EDITMODE_COLLISION) { current_shape.resize(0); @@ -2997,18 +3011,22 @@ void TileSetEditor::select_coord(const Vector2 &coord) { bool found_collision_shape = false; for (int i = 0; i < sd.size(); i++) { if (sd[i].autotile_coord == coord) { - if (edited_collision_shape != sd[i].shape) + if (edited_collision_shape != sd[i].shape) { _set_edited_collision_shape(sd[i].shape); + } found_collision_shape = true; break; } } - if (!found_collision_shape) + if (!found_collision_shape) { _set_edited_collision_shape(Ref<ConvexPolygonShape2D>(nullptr)); - if (edited_occlusion_shape != tileset->autotile_get_light_occluder(get_current_tile(), coord)) + } + if (edited_occlusion_shape != tileset->autotile_get_light_occluder(get_current_tile(), coord)) { edited_occlusion_shape = tileset->autotile_get_light_occluder(get_current_tile(), coord); - if (edited_navigation_shape != tileset->autotile_get_navigation_polygon(get_current_tile(), coord)) + } + if (edited_navigation_shape != tileset->autotile_get_navigation_polygon(get_current_tile(), coord)) { edited_navigation_shape = tileset->autotile_get_navigation_polygon(get_current_tile(), coord); + } int spacing = tileset->autotile_get_spacing(get_current_tile()); Vector2 size = tileset->autotile_get_size(get_current_tile()); @@ -3068,14 +3086,18 @@ Vector2 TileSetEditor::snap_point(const Vector2 &point) { p.y = Math::snap_scalar_separation(snap_offset.y, snap_step.y, p.y, snap_separation.y); } if (tools[SHAPE_KEEP_INSIDE_TILE]->is_pressed()) { - if (p.x < region.position.x) + if (p.x < region.position.x) { p.x = region.position.x; - if (p.y < region.position.y) + } + if (p.y < region.position.y) { p.y = region.position.y; - if (p.x > region.position.x + region.size.x) + } + if (p.x > region.position.x + region.size.x) { p.x = region.position.x + region.size.x; - if (p.y > region.position.y + region.size.y) + } + if (p.y > region.position.y + region.size.y) { p.y = region.position.y + region.size.y; + } } return p; } @@ -3123,8 +3145,9 @@ void TileSetEditor::update_texture_list() { if (texture_list->get_item_count() > 0 && selected_texture.is_valid()) { texture_list->select(texture_list->find_metadata(selected_texture->get_rid())); - if (texture_list->get_selected_items().size() > 0) + if (texture_list->get_selected_items().size() > 0) { _on_texture_list_selected(texture_list->get_selected_items()[0]); + } } else if (get_current_texture().is_valid()) { _on_texture_list_selected(texture_list->find_metadata(get_current_texture()->get_rid())); } else { @@ -3137,7 +3160,6 @@ void TileSetEditor::update_texture_list() { } void TileSetEditor::update_texture_list_icon() { - for (int current_idx = 0; current_idx < texture_list->get_item_count(); current_idx++) { RID rid = texture_list->get_item_metadata(current_idx); texture_list->set_item_icon(current_idx, texture_map[rid]); @@ -3148,7 +3170,6 @@ void TileSetEditor::update_texture_list_icon() { } void TileSetEditor::update_workspace_tile_mode() { - if (!get_current_texture().is_valid()) { tool_workspacemode[WORKSPACE_EDIT]->set_pressed(true); workspace_mode = WORKSPACE_EDIT; @@ -3224,19 +3245,21 @@ void TileSetEditor::update_workspace_tile_mode() { tool_editmode[EDITMODE_PRIORITY]->hide(); tool_editmode[EDITMODE_Z_INDEX]->hide(); } else if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::AUTO_TILE) { - if (edit_mode == EDITMODE_ICON) + if (edit_mode == EDITMODE_ICON) { select_coord(tileset->autotile_get_icon_coordinate(get_current_tile())); - else + } else { _select_edited_shape_coord(); + } } else if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::ATLAS_TILE) { if (tool_editmode[EDITMODE_PRIORITY]->is_pressed() || tool_editmode[EDITMODE_BITMASK]->is_pressed()) { tool_editmode[EDITMODE_COLLISION]->set_pressed(true); edit_mode = EDITMODE_COLLISION; } - if (edit_mode == EDITMODE_ICON) + if (edit_mode == EDITMODE_ICON) { select_coord(tileset->autotile_get_icon_coordinate(get_current_tile())); - else + } else { _select_edited_shape_coord(); + } tool_editmode[EDITMODE_BITMASK]->hide(); } @@ -3309,14 +3332,14 @@ void TileSetEditor::set_current_tile(int p_id) { } Ref<Texture2D> TileSetEditor::get_current_texture() { - if (texture_list->get_selected_items().size() == 0) + if (texture_list->get_selected_items().size() == 0) { return Ref<Texture2D>(); - else + } else { return texture_map[texture_list->get_item_metadata(texture_list->get_selected_items()[0])]; + } } void TilesetEditorContext::set_tileset(const Ref<TileSet> &p_tileset) { - tileset = p_tileset; } @@ -3326,7 +3349,6 @@ void TilesetEditorContext::set_snap_options_visible(bool p_visible) { } bool TilesetEditorContext::_set(const StringName &p_name, const Variant &p_value) { - String name = p_name.operator String(); if (name == "options_offset") { @@ -3345,8 +3367,9 @@ bool TilesetEditorContext::_set(const StringName &p_name, const Variant &p_value String name2 = p_name.operator String().right(5); bool v = false; - if (tileset_editor->get_current_tile() < 0 || tileset.is_null()) + if (tileset_editor->get_current_tile() < 0 || tileset.is_null()) { return false; + } if (name2 == "autotile_bitmask_mode") { tileset->set(String::num(tileset_editor->get_current_tile(), 0) + "/autotile/bitmask_mode", p_value, &v); @@ -3392,7 +3415,6 @@ bool TilesetEditorContext::_set(const StringName &p_name, const Variant &p_value } bool TilesetEditorContext::_get(const StringName &p_name, Variant &r_ret) const { - String name = p_name.operator String(); bool v = false; @@ -3408,10 +3430,12 @@ bool TilesetEditorContext::_get(const StringName &p_name, Variant &r_ret) const } else if (name.left(5) == "tile_") { name = name.right(5); - if (tileset_editor->get_current_tile() < 0 || tileset.is_null()) + if (tileset_editor->get_current_tile() < 0 || tileset.is_null()) { return false; - if (!tileset->has_tile(tileset_editor->get_current_tile())) + } + if (!tileset->has_tile(tileset_editor->get_current_tile())) { return false; + } if (name == "autotile_bitmask_mode") { r_ret = tileset->get(String::num(tileset_editor->get_current_tile(), 0) + "/autotile/bitmask_mode", &v); @@ -3458,7 +3482,6 @@ bool TilesetEditorContext::_get(const StringName &p_name, Variant &r_ret) const } void TilesetEditorContext::_get_property_list(List<PropertyInfo> *p_list) const { - if (snap_options_visible) { p_list->push_back(PropertyInfo(Variant::NIL, "Snap Options", PROPERTY_HINT_NONE, "options_", PROPERTY_USAGE_GROUP)); p_list->push_back(PropertyInfo(Variant::VECTOR2, "options_offset")); @@ -3507,25 +3530,21 @@ void TilesetEditorContext::_get_property_list(List<PropertyInfo> *p_list) const } void TilesetEditorContext::_bind_methods() { - ClassDB::bind_method("_hide_script_from_inspector", &TilesetEditorContext::_hide_script_from_inspector); } TilesetEditorContext::TilesetEditorContext(TileSetEditor *p_tileset_editor) { - tileset_editor = p_tileset_editor; snap_options_visible = false; } void TileSetEditorPlugin::edit(Object *p_node) { - if (Object::cast_to<TileSet>(p_node)) { tileset_editor->edit(Object::cast_to<TileSet>(p_node)); } } bool TileSetEditorPlugin::handles(Object *p_node) const { - return p_node->is_class("TileSet") || p_node->is_class("TilesetEditorContext"); } @@ -3542,7 +3561,6 @@ void TileSetEditorPlugin::make_visible(bool p_visible) { } Dictionary TileSetEditorPlugin::get_state() const { - Dictionary state; state["snap_offset"] = tileset_editor->snap_offset; state["snap_step"] = tileset_editor->snap_step; @@ -3554,7 +3572,6 @@ Dictionary TileSetEditorPlugin::get_state() const { } void TileSetEditorPlugin::set_state(const Dictionary &p_state) { - Dictionary state = p_state; if (state.has("snap_step")) { tileset_editor->_set_snap_step(state["snap_step"]); diff --git a/editor/plugins/tile_set_editor_plugin.h b/editor/plugins/tile_set_editor_plugin.h index 53f8e8c4d6..827325cfd7 100644 --- a/editor/plugins/tile_set_editor_plugin.h +++ b/editor/plugins/tile_set_editor_plugin.h @@ -41,7 +41,6 @@ class TilesetEditorContext; class TileSetEditor : public HSplitContainer { - friend class TileSetEditorPlugin; friend class TilesetEditorContext; @@ -252,7 +251,6 @@ private: }; class TilesetEditorContext : public Object { - friend class TileSetEditor; GDCLASS(TilesetEditorContext, Object); @@ -278,7 +276,6 @@ public: }; class TileSetEditorPlugin : public EditorPlugin { - GDCLASS(TileSetEditorPlugin, EditorPlugin); TileSetEditor *tileset_editor; diff --git a/editor/plugins/version_control_editor_plugin.cpp b/editor/plugins/version_control_editor_plugin.cpp index fe8392593b..a1436e123d 100644 --- a/editor/plugins/version_control_editor_plugin.cpp +++ b/editor/plugins/version_control_editor_plugin.cpp @@ -38,7 +38,6 @@ VersionControlEditorPlugin *VersionControlEditorPlugin::singleton = nullptr; void VersionControlEditorPlugin::_bind_methods() { - ClassDB::bind_method(D_METHOD("popup_vcs_set_up_dialog"), &VersionControlEditorPlugin::popup_vcs_set_up_dialog); // Used to track the status of files in the staging area @@ -50,20 +49,16 @@ void VersionControlEditorPlugin::_bind_methods() { } void VersionControlEditorPlugin::_selected_a_vcs(int p_id) { - List<StringName> available_addons = get_available_vcs_names(); const StringName selected_vcs = set_up_choice->get_item_text(p_id); } void VersionControlEditorPlugin::_populate_available_vcs_names() { - static bool called = false; if (!called) { - List<StringName> available_addons = get_available_vcs_names(); for (int i = 0; i < available_addons.size(); i++) { - set_up_choice->add_item(available_addons[i]); } @@ -72,16 +67,13 @@ void VersionControlEditorPlugin::_populate_available_vcs_names() { } VersionControlEditorPlugin *VersionControlEditorPlugin::get_singleton() { - return singleton ? singleton : memnew(VersionControlEditorPlugin); } void VersionControlEditorPlugin::popup_vcs_set_up_dialog(const Control *p_gui_base) { - fetch_available_vcs_addon_names(); List<StringName> available_addons = get_available_vcs_names(); if (available_addons.size() >= 1) { - Size2 popup_size = Size2(400, 100); Size2 window_size = p_gui_base->get_viewport_rect().size; popup_size.x = MIN(window_size.x * 0.5, popup_size.x); @@ -91,13 +83,11 @@ void VersionControlEditorPlugin::popup_vcs_set_up_dialog(const Control *p_gui_ba set_up_dialog->popup_centered_clamped(popup_size * EDSCALE); } else { - EditorNode::get_singleton()->show_warning(TTR("No VCS addons are available."), TTR("Error")); } } void VersionControlEditorPlugin::_initialize_vcs() { - register_editor(); ERR_FAIL_COND_MSG(EditorVCSInterface::get_singleton(), EditorVCSInterface::get_singleton()->get_vcs_name() + " is already active"); @@ -129,18 +119,14 @@ void VersionControlEditorPlugin::_initialize_vcs() { } void VersionControlEditorPlugin::_send_commit_msg() { - String msg = commit_message->get_text(); if (msg == "") { - commit_status->set_text(TTR("No commit message was provided")); return; } if (EditorVCSInterface::get_singleton()) { - if (staged_files_count == 0) { - commit_status->set_text(TTR("No files added to stage")); return; } @@ -150,7 +136,6 @@ void VersionControlEditorPlugin::_send_commit_msg() { commit_message->set_text(""); version_control_dock_button->set_pressed(false); } else { - WARN_PRINT("No VCS addon is initialized. Select a Version Control Addon from Project menu"); } @@ -160,20 +145,16 @@ void VersionControlEditorPlugin::_send_commit_msg() { } void VersionControlEditorPlugin::_refresh_stage_area() { - if (EditorVCSInterface::get_singleton()) { - staged_files_count = 0; clear_stage_area(); Dictionary modified_file_paths = EditorVCSInterface::get_singleton()->get_modified_files_data(); String file_path; for (int i = 0; i < modified_file_paths.size(); i++) { - file_path = modified_file_paths.get_key_at_index(i); TreeItem *found = stage_files->search_item_text(file_path, nullptr, true); if (!found) { - ChangeType change_index = (ChangeType)(int)modified_file_paths.get_value_at_index(i); String change_text = file_path + " (" + change_type_to_strings[change_index] + ")"; Color &change_color = change_type_to_color[change_index]; @@ -185,24 +166,19 @@ void VersionControlEditorPlugin::_refresh_stage_area() { new_item->set_checked(0, true); new_item->set_editable(0, true); } else { - if (found->get_metadata(0) == diff_file_name->get_text()) { - _refresh_file_diff(); } } commit_status->set_text("New changes detected"); } } else { - WARN_PRINT("No VCS addon is initialized. Select a Version Control Addon from Project menu."); } } void VersionControlEditorPlugin::_stage_selected() { - if (!EditorVCSInterface::get_singleton()) { - WARN_PRINT("No VCS addon is initialized. Select a Version Control Addon from Project menu"); return; } @@ -210,17 +186,13 @@ void VersionControlEditorPlugin::_stage_selected() { staged_files_count = 0; TreeItem *root = stage_files->get_root(); if (root) { - TreeItem *file_entry = root->get_children(); while (file_entry) { - if (file_entry->is_checked(0)) { - EditorVCSInterface::get_singleton()->stage_file(file_entry->get_metadata(0)); file_entry->set_icon_modulate(0, EditorNode::get_singleton()->get_gui_base()->get_theme_color("success_color", "Editor")); staged_files_count++; } else { - EditorVCSInterface::get_singleton()->unstage_file(file_entry->get_metadata(0)); file_entry->set_icon_modulate(0, EditorNode::get_singleton()->get_gui_base()->get_theme_color("error_color", "Editor")); } @@ -233,9 +205,7 @@ void VersionControlEditorPlugin::_stage_selected() { } void VersionControlEditorPlugin::_stage_all() { - if (!EditorVCSInterface::get_singleton()) { - WARN_PRINT("No VCS addon is initialized. Select a Version Control Addon from Project menu"); return; } @@ -243,10 +213,8 @@ void VersionControlEditorPlugin::_stage_all() { staged_files_count = 0; TreeItem *root = stage_files->get_root(); if (root) { - TreeItem *file_entry = root->get_children(); while (file_entry) { - EditorVCSInterface::get_singleton()->stage_file(file_entry->get_metadata(0)); file_entry->set_icon_modulate(0, EditorNode::get_singleton()->get_gui_base()->get_theme_color("success_color", "Editor")); file_entry->set_checked(0, true); @@ -260,7 +228,6 @@ void VersionControlEditorPlugin::_stage_all() { } void VersionControlEditorPlugin::_view_file_diff() { - version_control_dock_button->set_pressed(true); String file_path = stage_files->get_selected()->get_metadata(0); @@ -269,7 +236,6 @@ void VersionControlEditorPlugin::_view_file_diff() { } void VersionControlEditorPlugin::_display_file_diff(String p_file_path) { - Array diff_content = EditorVCSInterface::get_singleton()->get_file_diff(p_file_path); diff_file_name->set_text(p_file_path); @@ -277,17 +243,13 @@ void VersionControlEditorPlugin::_display_file_diff(String p_file_path) { diff->clear(); diff->push_font(EditorNode::get_singleton()->get_gui_base()->get_theme_font("source", "EditorFonts")); for (int i = 0; i < diff_content.size(); i++) { - Dictionary line_result = diff_content[i]; if (line_result["status"] == "+") { - diff->push_color(EditorNode::get_singleton()->get_gui_base()->get_theme_color("success_color", "Editor")); } else if (line_result["status"] == "-") { - diff->push_color(EditorNode::get_singleton()->get_gui_base()->get_theme_color("error_color", "Editor")); } else { - diff->push_color(EditorNode::get_singleton()->get_gui_base()->get_theme_color("font_color", "Label")); } @@ -299,42 +261,33 @@ void VersionControlEditorPlugin::_display_file_diff(String p_file_path) { } void VersionControlEditorPlugin::_refresh_file_diff() { - String open_file = diff_file_name->get_text(); if (open_file != "") { - _display_file_diff(diff_file_name->get_text()); } } void VersionControlEditorPlugin::_clear_file_diff() { - diff->clear(); diff_file_name->set_text(""); version_control_dock_button->set_pressed(false); } void VersionControlEditorPlugin::_update_stage_status() { - String status; if (staged_files_count == 1) { - status = "Stage contains 1 file"; } else { - status = "Stage contains " + String::num_int64(staged_files_count) + " files"; } commit_status->set_text(status); } void VersionControlEditorPlugin::_update_commit_status() { - String status; if (staged_files_count == 1) { - status = "Committed 1 file"; } else { - status = "Committed " + String::num_int64(staged_files_count) + " files "; } commit_status->set_text(status); @@ -342,9 +295,7 @@ void VersionControlEditorPlugin::_update_commit_status() { } void VersionControlEditorPlugin::register_editor() { - if (!EditorVCSInterface::get_singleton()) { - EditorNode::get_singleton()->add_control_to_dock(EditorNode::DOCK_SLOT_RIGHT_UL, version_commit_dock); TabContainer *dock_vbc = (TabContainer *)version_commit_dock->get_parent_control(); dock_vbc->set_tab_title(version_commit_dock->get_index(), TTR("Commit")); @@ -355,30 +306,25 @@ void VersionControlEditorPlugin::register_editor() { } void VersionControlEditorPlugin::fetch_available_vcs_addon_names() { - List<StringName> global_classes; ScriptServer::get_global_class_list(&global_classes); for (int i = 0; i != global_classes.size(); i++) { - String path = ScriptServer::get_global_class_path(global_classes[i]); Ref<Script> script = ResourceLoader::load(path); ERR_FAIL_COND(script.is_null()); if (script->get_instance_base_type() == "EditorVCSInterface") { - available_addons.push_back(global_classes[i]); } } } void VersionControlEditorPlugin::clear_stage_area() { - stage_files->get_root()->clear_children(); } void VersionControlEditorPlugin::shut_down() { - if (EditorVCSInterface::get_singleton()) { if (EditorFileSystem::get_singleton()->is_connected("filesystem_changed", callable_mp(this, &VersionControlEditorPlugin::_refresh_stage_area))) { EditorFileSystem::get_singleton()->disconnect("filesystem_changed", callable_mp(this, &VersionControlEditorPlugin::_refresh_stage_area)); @@ -393,17 +339,14 @@ void VersionControlEditorPlugin::shut_down() { } bool VersionControlEditorPlugin::is_vcs_initialized() const { - return EditorVCSInterface::get_singleton() ? EditorVCSInterface::get_singleton()->is_vcs_initialized() : false; } const String VersionControlEditorPlugin::get_vcs_name() const { - return EditorVCSInterface::get_singleton() ? EditorVCSInterface::get_singleton()->get_vcs_name() : ""; } VersionControlEditorPlugin::VersionControlEditorPlugin() { - singleton = this; staged_files_count = 0; @@ -570,7 +513,6 @@ VersionControlEditorPlugin::VersionControlEditorPlugin() { } VersionControlEditorPlugin::~VersionControlEditorPlugin() { - shut_down(); memdelete(version_control_dock); memdelete(version_commit_dock); diff --git a/editor/plugins/version_control_editor_plugin.h b/editor/plugins/version_control_editor_plugin.h index 4a98c8580e..664e38d65f 100644 --- a/editor/plugins/version_control_editor_plugin.h +++ b/editor/plugins/version_control_editor_plugin.h @@ -39,7 +39,6 @@ #include "scene/gui/tree.h" class VersionControlEditorPlugin : public EditorPlugin { - GDCLASS(VersionControlEditorPlugin, EditorPlugin) public: diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 07251ad7ad..92bdba93e7 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -48,7 +48,6 @@ #include "servers/rendering/shader_types.h" Control *VisualShaderNodePlugin::create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node) { - if (get_script_instance()) { return get_script_instance()->call("create_editor", p_parent_resource, p_node); } @@ -56,14 +55,12 @@ Control *VisualShaderNodePlugin::create_editor(const Ref<Resource> &p_parent_res } void VisualShaderNodePlugin::_bind_methods() { - BIND_VMETHOD(MethodInfo(Variant::OBJECT, "create_editor", PropertyInfo(Variant::OBJECT, "parent_resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"), PropertyInfo(Variant::OBJECT, "for_node", PROPERTY_HINT_RESOURCE_TYPE, "VisualShaderNode"))); } /////////////////// void VisualShaderEditor::edit(VisualShader *p_visual_shader) { - bool changed = false; if (p_visual_shader) { if (visual_shader.is_null()) { @@ -106,8 +103,9 @@ void VisualShaderEditor::edit(VisualShader *p_visual_shader) { } void VisualShaderEditor::add_plugin(const Ref<VisualShaderNodePlugin> &p_plugin) { - if (plugins.find(p_plugin) != -1) + if (plugins.find(p_plugin) != -1) { return; + } plugins.push_back(p_plugin); } @@ -125,14 +123,14 @@ void VisualShaderEditor::clear_custom_types() { } void VisualShaderEditor::add_custom_type(const String &p_name, const Ref<Script> &p_script, const String &p_description, int p_return_icon_type, const String &p_category, bool p_highend) { - ERR_FAIL_COND(!p_name.is_valid_identifier()); ERR_FAIL_COND(!p_script.is_valid()); for (int i = 0; i < add_options.size(); i++) { if (add_options[i].is_custom) { - if (add_options[i].script == p_script) + if (add_options[i].script == p_script) { return; + } } } @@ -166,11 +164,9 @@ void VisualShaderEditor::add_custom_type(const String &p_name, const Ref<Script> } bool VisualShaderEditor::_is_available(int p_mode) { - int current_mode = edit_type->get_selected(); if (p_mode != -1) { - switch (current_mode) { case VisualShader::TYPE_VERTEX: current_mode = 1; @@ -215,7 +211,6 @@ void VisualShaderEditor::update_custom_nodes() { Dictionary added; for (int i = 0; i < class_list.size(); i++) { if (ScriptServer::get_global_class_native_base(class_list[i]) == "VisualShaderNodeCustom") { - String script_path = ScriptServer::get_global_class_path(class_list[i]); Ref<Resource> res = ResourceLoader::load(script_path); ERR_FAIL_COND(res.is_null()); @@ -285,7 +280,6 @@ void VisualShaderEditor::update_custom_nodes() { keys.sort(); for (int i = 0; i < keys.size(); i++) { - const Variant &key = keys.get(i); const Dictionary &value = (Dictionary)added[key]; @@ -301,7 +295,6 @@ String VisualShaderEditor::_get_description(int p_idx) { } void VisualShaderEditor::_update_options_menu() { - node_desc->set_text(""); members_dialog->get_ok()->set_disabled(true); @@ -374,10 +367,11 @@ void VisualShaderEditor::_update_options_menu() { } TreeItem *item = members->create_item(category); - if (options[i].highend && low_driver) + if (options[i].highend && low_driver) { item->set_custom_color(0, unsupported_color); - else if (options[i].highend) + } else if (options[i].highend) { item->set_custom_color(0, supported_color); + } item->set_text(0, options[i].name); if (is_first_item && use_filter) { item->select(0); @@ -411,15 +405,14 @@ void VisualShaderEditor::_update_options_menu() { } Size2 VisualShaderEditor::get_minimum_size() const { - return Size2(10, 200); } void VisualShaderEditor::_draw_color_over_button(Object *obj, Color p_color) { - Button *button = Object::cast_to<Button>(obj); - if (!button) + if (!button) { return; + } Ref<StyleBox> normal = get_theme_stylebox("normal", "Button"); button->draw_rect(Rect2(normal->get_offset(), button->get_size() - normal->get_minimum_size()), p_color); @@ -435,7 +428,6 @@ static Ref<StyleBoxEmpty> make_empty_stylebox(float p_margin_left = -1, float p_ } void VisualShaderEditor::_update_created_node(GraphNode *node) { - if (EditorSettings::get_singleton()->get("interface/theme/use_graph_node_headers")) { Ref<StyleBoxFlat> sb = node->get_theme_stylebox("frame", "GraphNode"); Color c = sb->get_border_color(); @@ -459,12 +451,13 @@ void VisualShaderEditor::_update_created_node(GraphNode *node) { } void VisualShaderEditor::_update_graph() { - - if (updating) + if (updating) { return; + } - if (visual_shader.is_null()) + if (visual_shader.is_null()) { return; + } graph->set_scroll_ofs(visual_shader->get_graph_offset() * EDSCALE); @@ -472,7 +465,6 @@ void VisualShaderEditor::_update_graph() { graph->clear_connections(); //erase all nodes for (int i = 0; i < graph->get_child_count(); i++) { - if (Object::cast_to<GraphNode>(graph->get_child(i))) { Node *node = graph->get_child(i); graph->remove_child(node); @@ -500,7 +492,6 @@ void VisualShaderEditor::_update_graph() { Control *offset; for (int n_i = 0; n_i < nodes.size(); n_i++) { - Vector2 position = visual_shader->get_node_position(type, nodes[n_i]); Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, nodes[n_i]); @@ -592,7 +583,6 @@ void VisualShaderEditor::_update_graph() { if (custom_editor && !float_uniform.is_valid() && !int_uniform.is_valid() && !vec3_uniform.is_valid() && !bool_uniform.is_valid() && !transform_uniform.is_valid() && vsnode->get_output_port_count() > 0 && vsnode->get_output_port_name(0) == "" && (vsnode->get_input_port_count() == 0 || vsnode->get_input_port_name(0) == "")) { //will be embedded in first port } else if (custom_editor) { - port_offset++; node->add_child(custom_editor); if (color_uniform.is_valid()) { @@ -606,7 +596,6 @@ void VisualShaderEditor::_update_graph() { } if (is_group) { - offset = memnew(Control); offset->set_custom_minimum_size(Size2(0, 6 * EDSCALE)); node->add_child(offset); @@ -631,7 +620,6 @@ void VisualShaderEditor::_update_graph() { } for (int i = 0; i < MAX(vsnode->get_input_port_count(), vsnode->get_output_port_count()); i++) { - if (vsnode->is_port_separator(i)) { node->add_child(memnew(HSeparator)); port_offset++; @@ -674,7 +662,6 @@ void VisualShaderEditor::_update_graph() { button->connect("pressed", callable_mp(this, &VisualShaderEditor::_edit_port_default_input), varray(button, nodes[n_i], i)); switch (default_value.get_type()) { - case Variant::COLOR: { button->set_custom_minimum_size(Size2(30, 0) * EDSCALE); button->connect("draw", callable_mp(this, &VisualShaderEditor::_draw_color_over_button), varray(button, default_value)); @@ -699,9 +686,7 @@ void VisualShaderEditor::_update_graph() { hb->add_child(custom_editor); custom_editor->set_h_size_flags(SIZE_EXPAND_FILL); } else { - if (valid_left) { - if (is_group) { OptionButton *type_box = memnew(OptionButton); hb->add_child(type_box); @@ -729,14 +714,12 @@ void VisualShaderEditor::_update_graph() { remove_btn->connect("pressed", callable_mp(this, &VisualShaderEditor::_remove_input_port), varray(nodes[n_i], i), CONNECT_DEFERRED); hb->add_child(remove_btn); } else { - Label *label = memnew(Label); label->set_text(name_left); label->add_theme_style_override("normal", label_style); //more compact hb->add_child(label); if (vsnode->get_input_port_default_hint(i) != "" && !port_left_used) { - Label *hint_label = memnew(Label); hint_label->set_text("[" + vsnode->get_input_port_default_hint(i) + "]"); hint_label->add_theme_color_override("font_color", get_theme_color("font_color_readonly", "TextEdit")); @@ -840,7 +823,6 @@ void VisualShaderEditor::_update_graph() { } if (is_expression) { - TextEdit *expression_box = memnew(TextEdit); expression_node->set_control(expression_box, 0); node->add_child(expression_box); @@ -855,7 +837,6 @@ void VisualShaderEditor::_update_graph() { expression_box->add_theme_color_override("background_color", background_color); for (List<String>::Element *E = keyword_list.front(); E; E = E->next()) { - expression_box->add_keyword_color(E->get(), keyword_color); } @@ -875,13 +856,13 @@ void VisualShaderEditor::_update_graph() { if (!uniform.is_valid()) { graph->add_child(node); _update_created_node(node); - if (is_group) + if (is_group) { call_deferred("_set_node_size", (int)type, nodes[n_i], size); + } } } for (List<VisualShader::Connection>::Element *E = connections.front(); E; E = E->next()) { - int from = E->get().from_node; int from_idx = E->get().from_port; int to = E->get().to_node; @@ -892,7 +873,6 @@ void VisualShaderEditor::_update_graph() { } void VisualShaderEditor::_add_input_port(int p_node, int p_port, int p_port_type, const String &p_name) { - VisualShader::Type type = VisualShader::Type(edit_type->get_selected()); Ref<VisualShaderNodeExpression> node = visual_shader->get_node(type, p_node); if (node.is_null()) { @@ -910,7 +890,6 @@ void VisualShaderEditor::_add_input_port(int p_node, int p_port, int p_port_type } void VisualShaderEditor::_add_output_port(int p_node, int p_port, int p_port_type, const String &p_name) { - VisualShader::Type type = VisualShader::Type(edit_type->get_selected()); Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node); if (node.is_null()) { @@ -928,7 +907,6 @@ void VisualShaderEditor::_add_output_port(int p_node, int p_port, int p_port_typ } void VisualShaderEditor::_change_input_port_type(int p_type, int p_node, int p_port) { - VisualShader::Type type = VisualShader::Type(edit_type->get_selected()); Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node); if (node.is_null()) { @@ -946,7 +924,6 @@ void VisualShaderEditor::_change_input_port_type(int p_type, int p_node, int p_p } void VisualShaderEditor::_change_output_port_type(int p_type, int p_node, int p_port) { - VisualShader::Type type = VisualShader::Type(edit_type->get_selected()); Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node); if (node.is_null()) { @@ -964,7 +941,6 @@ void VisualShaderEditor::_change_output_port_type(int p_type, int p_node, int p_ } void VisualShaderEditor::_change_input_port_name(const String &p_text, Object *line_edit, int p_node_id, int p_port_id) { - VisualShader::Type type = VisualShader::Type(edit_type->get_selected()); Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node_id); @@ -979,7 +955,6 @@ void VisualShaderEditor::_change_input_port_name(const String &p_text, Object *l } void VisualShaderEditor::_change_output_port_name(const String &p_text, Object *line_edit, int p_node_id, int p_port_id) { - VisualShader::Type type = VisualShader::Type(edit_type->get_selected()); Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node_id); @@ -994,7 +969,6 @@ void VisualShaderEditor::_change_output_port_name(const String &p_text, Object * } void VisualShaderEditor::_remove_input_port(int p_node, int p_port) { - VisualShader::Type type = VisualShader::Type(edit_type->get_selected()); Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node); if (node.is_null()) { @@ -1006,7 +980,6 @@ void VisualShaderEditor::_remove_input_port(int p_node, int p_port) { List<VisualShader::Connection> conns; visual_shader->get_node_connections(type, &conns); for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) { - int from_node = E->get().from_node; int from_port = E->get().from_port; int to_node = E->get().to_node; @@ -1039,7 +1012,6 @@ void VisualShaderEditor::_remove_input_port(int p_node, int p_port) { } void VisualShaderEditor::_remove_output_port(int p_node, int p_port) { - VisualShader::Type type = VisualShader::Type(edit_type->get_selected()); Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node); if (node.is_null()) { @@ -1051,7 +1023,6 @@ void VisualShaderEditor::_remove_output_port(int p_node, int p_port) { List<VisualShader::Connection> conns; visual_shader->get_node_connections(type, &conns); for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) { - int from_node = E->get().from_node; int from_port = E->get().from_port; int to_node = E->get().to_node; @@ -1084,7 +1055,6 @@ void VisualShaderEditor::_remove_output_port(int p_node, int p_port) { } void VisualShaderEditor::_expression_focus_out(Object *text_edit, int p_node) { - VisualShader::Type type = VisualShader::Type(edit_type->get_selected()); Ref<VisualShaderNodeExpression> node = visual_shader->get_node(type, p_node); if (node.is_null()) { @@ -1093,8 +1063,9 @@ void VisualShaderEditor::_expression_focus_out(Object *text_edit, int p_node) { TextEdit *expression_box = Object::cast_to<TextEdit>(text_edit); - if (node->get_expression() == expression_box->get_text()) + if (node->get_expression() == expression_box->get_text()) { return; + } undo_redo->create_action(TTR("Set expression")); undo_redo->add_do_method(node.ptr(), "set_expression", expression_box->get_text()); @@ -1112,7 +1083,6 @@ void VisualShaderEditor::_rebuild() { } void VisualShaderEditor::_set_node_size(int p_type, int p_node, const Vector2 &p_size) { - VisualShader::Type type = VisualShader::Type(p_type); Ref<VisualShaderNode> node = visual_shader->get_node(type, p_node); if (node.is_null()) { @@ -1133,8 +1103,9 @@ void VisualShaderEditor::_set_node_size(int p_type, int p_node, const Vector2 &p if (edit_type->get_selected() == p_type) { // check - otherwise the error will be emitted Node *node2 = graph->get_node(itos(p_node)); gn = Object::cast_to<GraphNode>(node2); - if (!gn) + if (!gn) { return; + } gn->set_custom_minimum_size(size); gn->set_size(Size2(1, 1)); @@ -1159,7 +1130,6 @@ void VisualShaderEditor::_set_node_size(int p_type, int p_node, const Vector2 &p } void VisualShaderEditor::_node_resized(const Vector2 &p_new_size, int p_type, int p_node) { - VisualShader::Type type = VisualShader::Type(p_type); Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node); if (node.is_null()) { @@ -1173,7 +1143,6 @@ void VisualShaderEditor::_node_resized(const Vector2 &p_new_size, int p_type, in } void VisualShaderEditor::_preview_select_port(int p_node, int p_port) { - VisualShader::Type type = VisualShader::Type(edit_type->get_selected()); Ref<VisualShaderNode> node = visual_shader->get_node(type, p_node); if (node.is_null()) { @@ -1192,7 +1161,6 @@ void VisualShaderEditor::_preview_select_port(int p_node, int p_port) { } void VisualShaderEditor::_line_edit_changed(const String &p_text, Object *line_edit, int p_node_id) { - VisualShader::Type type = VisualShader::Type(edit_type->get_selected()); Ref<VisualShaderNodeUniform> node = visual_shader->get_node(type, p_node_id); @@ -1213,13 +1181,11 @@ void VisualShaderEditor::_line_edit_changed(const String &p_text, Object *line_e } void VisualShaderEditor::_line_edit_focus_out(Object *line_edit, int p_node_id) { - String text = Object::cast_to<LineEdit>(line_edit)->get_text(); _line_edit_changed(text, line_edit, p_node_id); } void VisualShaderEditor::_port_name_focus_out(Object *line_edit, int p_node_id, int p_port_id, bool p_output) { - VisualShader::Type type = VisualShader::Type(edit_type->get_selected()); Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node_id); @@ -1228,24 +1194,28 @@ void VisualShaderEditor::_port_name_focus_out(Object *line_edit, int p_node_id, String text = Object::cast_to<LineEdit>(line_edit)->get_text(); if (!p_output) { - if (node->get_input_port_name(p_port_id) == text) + if (node->get_input_port_name(p_port_id) == text) { return; + } } else { - if (node->get_output_port_name(p_port_id) == text) + if (node->get_output_port_name(p_port_id) == text) { return; + } } List<String> input_names; List<String> output_names; for (int i = 0; i < node->get_input_port_count(); i++) { - if (!p_output && i == p_port_id) + if (!p_output && i == p_port_id) { continue; + } input_names.push_back(node->get_input_port_name(i)); } for (int i = 0; i < node->get_output_port_count(); i++) { - if (p_output && i == p_port_id) + if (p_output && i == p_port_id) { continue; + } output_names.push_back(node->get_output_port_name(i)); } @@ -1267,7 +1237,6 @@ void VisualShaderEditor::_port_name_focus_out(Object *line_edit, int p_node_id, } void VisualShaderEditor::_port_edited() { - VisualShader::Type type = VisualShader::Type(edit_type->get_selected()); Variant value = property_editor->get_variant(); @@ -1285,7 +1254,6 @@ void VisualShaderEditor::_port_edited() { } void VisualShaderEditor::_edit_port_default_input(Object *p_button, int p_node, int p_port) { - VisualShader::Type type = VisualShader::Type(edit_type->get_selected()); Ref<VisualShaderNode> vsn = visual_shader->get_node(type, p_node); @@ -1301,7 +1269,6 @@ void VisualShaderEditor::_edit_port_default_input(Object *p_button, int p_node, } void VisualShaderEditor::_add_custom_node(const String &p_path) { - int idx = -1; for (int i = custom_node_option_idx; i < add_options.size(); i++) { @@ -1323,7 +1290,6 @@ void VisualShaderEditor::_add_texture_node(const String &p_path) { } VisualShaderNode *VisualShaderEditor::_add_node(int p_idx, int p_op_idx) { - ERR_FAIL_INDEX_V(p_idx, add_options.size(), nullptr); Ref<VisualShaderNode> vsnode; @@ -1337,12 +1303,12 @@ VisualShaderNode *VisualShaderEditor::_add_node(int p_idx, int p_op_idx) { VisualShaderNodeFloatConstant *constant = Object::cast_to<VisualShaderNodeFloatConstant>(vsn); if (constant) { - if ((int)add_options[p_idx].value != -1) + if ((int)add_options[p_idx].value != -1) { constant->set_constant(add_options[p_idx].value); + } } if (p_op_idx != -1) { - VisualShaderNodeInput *input = Object::cast_to<VisualShaderNodeInput>(vsn); if (input) { @@ -1463,7 +1429,6 @@ VisualShaderNode *VisualShaderEditor::_add_node(int p_idx, int p_op_idx) { if (to_node != -1 && to_slot != -1) { if (vsnode->get_output_port_count() > 0) { - int _from_node = id_to_use; int _from_slot = 0; @@ -1474,7 +1439,6 @@ VisualShaderNode *VisualShaderEditor::_add_node(int p_idx, int p_op_idx) { } } else if (from_node != -1 && from_slot != -1) { if (vsnode->get_input_port_count() > 0) { - int _to_node = id_to_use; int _to_slot = 0; @@ -1492,7 +1456,6 @@ VisualShaderNode *VisualShaderEditor::_add_node(int p_idx, int p_op_idx) { } void VisualShaderEditor::_node_dragged(const Vector2 &p_from, const Vector2 &p_to, int p_node) { - VisualShader::Type type = VisualShader::Type(edit_type->get_selected()); updating = true; @@ -1506,7 +1469,6 @@ void VisualShaderEditor::_node_dragged(const Vector2 &p_from, const Vector2 &p_t } void VisualShaderEditor::_connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index) { - VisualShader::Type type = VisualShader::Type(edit_type->get_selected()); int from = p_from.to_int(); @@ -1536,7 +1498,6 @@ void VisualShaderEditor::_connection_request(const String &p_from, int p_from_in } void VisualShaderEditor::_disconnection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index) { - graph->disconnect_node(p_from, p_from_index, p_to, p_to_index); VisualShader::Type type = VisualShader::Type(edit_type->get_selected()); @@ -1567,7 +1528,6 @@ void VisualShaderEditor::_connection_from_empty(const String &p_to, int p_to_slo } void VisualShaderEditor::_delete_request(int which) { - VisualShader::Type type = VisualShader::Type(edit_type->get_selected()); Ref<VisualShaderNode> node = Ref<VisualShaderNode>(visual_shader->get_node(type, which)); @@ -1607,7 +1567,6 @@ void VisualShaderEditor::_delete_request(int which) { } void VisualShaderEditor::_node_selected(Object *p_node) { - VisualShader::Type type = VisualShader::Type(edit_type->get_selected()); GraphNode *gn = Object::cast_to<GraphNode>(p_node); @@ -1623,7 +1582,6 @@ void VisualShaderEditor::_node_selected(Object *p_node) { } void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) { - Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_RIGHT) { @@ -1652,7 +1610,6 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) { } void VisualShaderEditor::_show_members_dialog(bool at_mouse_pos) { - if (at_mouse_pos) { saved_node_pos_dirty = true; saved_node_pos = graph->get_local_mouse_position(); @@ -1688,7 +1645,6 @@ void VisualShaderEditor::_sbox_input(const Ref<InputEvent> &p_ie) { ie->get_keycode() == KEY_DOWN || ie->get_keycode() == KEY_ENTER || ie->get_keycode() == KEY_KP_ENTER)) { - members->call("_gui_input", ie); node_filter->accept_event(); } @@ -1696,7 +1652,6 @@ void VisualShaderEditor::_sbox_input(const Ref<InputEvent> &p_ie) { void VisualShaderEditor::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { - node_filter->set_clear_button_enabled(true); // collapse tree by default @@ -1723,7 +1678,6 @@ void VisualShaderEditor::_notification(int p_what) { } if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { - highend_label->set_modulate(get_theme_color("vulkan_color", "Editor")); error_panel->add_theme_style_override("panel", get_theme_stylebox("bg", "Tree")); @@ -1743,7 +1697,6 @@ void VisualShaderEditor::_notification(int p_what) { preview_text->add_theme_color_override("background_color", background_color); for (List<String>::Element *E = keyword_list.front(); E; E = E->next()) { - preview_text->add_keyword_color(E->get(), keyword_color); } @@ -1759,22 +1712,25 @@ void VisualShaderEditor::_notification(int p_what) { tools->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon("Tools", "EditorIcons")); - if (p_what == NOTIFICATION_THEME_CHANGED && is_visible_in_tree()) + if (p_what == NOTIFICATION_THEME_CHANGED && is_visible_in_tree()) { _update_graph(); + } } } void VisualShaderEditor::_scroll_changed(const Vector2 &p_scroll) { - if (updating) + if (updating) { return; + } updating = true; visual_shader->set_graph_offset(p_scroll / EDSCALE); updating = false; } void VisualShaderEditor::_node_changed(int p_id) { - if (updating) + if (updating) { return; + } if (is_visible_in_tree()) { _update_graph(); @@ -1786,7 +1742,6 @@ void VisualShaderEditor::_dup_update_excluded(int p_type, Set<int> &r_excluded) VisualShader::Type type = (VisualShader::Type)p_type; for (int i = 0; i < graph->get_child_count(); i++) { - GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i)); if (gn) { int id = String(gn->get_name()).to_int(); @@ -1802,14 +1757,12 @@ void VisualShaderEditor::_dup_update_excluded(int p_type, Set<int> &r_excluded) } void VisualShaderEditor::_dup_copy_nodes(int p_type, List<int> &r_nodes, Set<int> &r_excluded) { - VisualShader::Type type = (VisualShader::Type)p_type; selection_center.x = 0.0f; selection_center.y = 0.0f; for (int i = 0; i < graph->get_child_count(); i++) { - GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i)); if (gn) { int id = String(gn->get_name()).to_int(); @@ -1832,7 +1785,6 @@ void VisualShaderEditor::_dup_copy_nodes(int p_type, List<int> &r_nodes, Set<int } void VisualShaderEditor::_dup_paste_nodes(int p_type, int p_pasted_type, List<int> &r_nodes, Set<int> &r_excluded, const Vector2 &p_offset, bool p_select) { - VisualShader::Type type = (VisualShader::Type)p_type; VisualShader::Type pasted_type = (VisualShader::Type)p_pasted_type; @@ -1842,7 +1794,6 @@ void VisualShaderEditor::_dup_paste_nodes(int p_type, int p_pasted_type, List<in Set<int> unsupported_set; for (List<int>::Element *E = r_nodes.front(); E; E = E->next()) { - connection_remap[E->get()] = id_from; Ref<VisualShaderNode> node = visual_shader->get_node(pasted_type, E->get()); @@ -1900,7 +1851,6 @@ void VisualShaderEditor::_dup_paste_nodes(int p_type, int p_pasted_type, List<in if (p_select) { // reselect duplicated nodes by excluding the other ones for (int i = 0; i < graph->get_child_count(); i++) { - GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i)); if (gn) { int id = String(gn->get_name()).to_int(); @@ -1915,13 +1865,11 @@ void VisualShaderEditor::_dup_paste_nodes(int p_type, int p_pasted_type, List<in } void VisualShaderEditor::_clear_buffer() { - copy_nodes_buffer.clear(); copy_nodes_excluded_buffer.clear(); } void VisualShaderEditor::_duplicate_nodes() { - int type = edit_type->get_selected(); List<int> nodes; @@ -1929,8 +1877,9 @@ void VisualShaderEditor::_duplicate_nodes() { _dup_copy_nodes(type, nodes, excluded); - if (nodes.empty()) + if (nodes.empty()) { return; + } undo_redo->create_action(TTR("Duplicate Nodes")); @@ -1938,7 +1887,6 @@ void VisualShaderEditor::_duplicate_nodes() { } void VisualShaderEditor::_copy_nodes() { - copy_type = edit_type->get_selected(); _clear_buffer(); @@ -1947,9 +1895,9 @@ void VisualShaderEditor::_copy_nodes() { } void VisualShaderEditor::_paste_nodes(bool p_use_custom_position, const Vector2 &p_custom_position) { - - if (copy_nodes_buffer.empty()) + if (copy_nodes_buffer.empty()) { return; + } int type = edit_type->get_selected(); @@ -1970,7 +1918,6 @@ void VisualShaderEditor::_paste_nodes(bool p_use_custom_position, const Vector2 } void VisualShaderEditor::_delete_nodes() { - VisualShader::Type type = VisualShader::Type(edit_type->get_selected()); List<int> to_erase; @@ -1983,13 +1930,13 @@ void VisualShaderEditor::_delete_nodes() { } } - if (to_erase.empty()) + if (to_erase.empty()) { return; + } undo_redo->create_action(TTR("Delete Nodes")); for (List<int>::Element *F = to_erase.front(); F; F = F->next()) { - Ref<VisualShaderNode> node = visual_shader->get_node(type, F->get()); undo_redo->add_do_method(visual_shader.ptr(), "remove_node", type, F->get()); @@ -2020,7 +1967,6 @@ void VisualShaderEditor::_delete_nodes() { for (List<int>::Element *F = to_erase.front(); F; F = F->next()) { for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) { if (E->get().from_node == F->get() || E->get().to_node == F->get()) { - bool cancel = false; for (List<VisualShader::Connection>::Element *R = used_conns.front(); R; R = R->next()) { if (R->get().from_node == E->get().from_node && R->get().from_port == E->get().from_port && R->get().to_node == E->get().to_node && R->get().to_port == E->get().to_port) { @@ -2042,17 +1988,16 @@ void VisualShaderEditor::_delete_nodes() { } void VisualShaderEditor::_mode_selected(int p_id) { - _update_options_menu(); _update_graph(); } void VisualShaderEditor::_input_select_item(Ref<VisualShaderNodeInput> input, String name) { - String prev_name = input->get_input_name(); - if (name == prev_name) + if (name == prev_name) { return; + } bool type_changed = input->get_input_type_by_name(name) != input->get_input_type_by_name(prev_name); @@ -2119,7 +2064,6 @@ void VisualShaderEditor::_member_cancel() { } void VisualShaderEditor::_tools_menu_option(int p_idx) { - TreeItem *category = members->get_root()->get_children(); switch (p_idx) { @@ -2176,13 +2120,14 @@ void VisualShaderEditor::_node_menu_id_pressed(int p_idx) { } Variant VisualShaderEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) { - if (p_from == members) { TreeItem *it = members->get_item_at_position(p_point); - if (!it) + if (!it) { return Variant(); - if (!it->has_meta("id")) + } + if (!it->has_meta("id")) { return Variant(); + } int id = it->get_meta("id"); AddOption op = add_options[id]; @@ -2204,9 +2149,7 @@ Variant VisualShaderEditor::get_drag_data_fw(const Point2 &p_point, Control *p_f } bool VisualShaderEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { - if (p_from == graph) { - Dictionary d = p_data; if (d.has("id")) { @@ -2221,9 +2164,7 @@ bool VisualShaderEditor::can_drop_data_fw(const Point2 &p_point, const Variant & } void VisualShaderEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { - if (p_from == graph) { - Dictionary d = p_data; if (d.has("id")) { @@ -2233,11 +2174,9 @@ void VisualShaderEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da _add_node(idx, add_options[idx].sub_func); } else if (d.has("files")) { if (d["files"].get_type() == Variant::PACKED_STRING_ARRAY) { - int j = 0; PackedStringArray arr = d["files"]; for (int i = 0; i < arr.size(); i++) { - String type = ResourceLoader::get_resource_type(arr[i]); if (type == "GDScript") { Ref<Script> script = ResourceLoader::load(arr[i]); @@ -2271,13 +2210,11 @@ void VisualShaderEditor::_show_preview_text() { } static ShaderLanguage::DataType _get_global_variable_type(const StringName &p_variable) { - RS::GlobalVariableType gvt = RS::get_singleton()->global_variable_get_type(p_variable); return RS::global_variable_type_get_shader_datatype(gvt); } void VisualShaderEditor::_update_preview() { - if (!preview_showed) { pending_update_preview = true; return; @@ -2327,7 +2264,6 @@ void VisualShaderEditor::_bind_methods() { VisualShaderEditor *VisualShaderEditor::singleton = nullptr; VisualShaderEditor::VisualShaderEditor() { - singleton = this; updating = false; saved_node_pos_dirty = false; @@ -2945,17 +2881,14 @@ VisualShaderEditor::VisualShaderEditor() { } void VisualShaderEditorPlugin::edit(Object *p_object) { - visual_shader_editor->edit(Object::cast_to<VisualShader>(p_object)); } bool VisualShaderEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("VisualShader"); } void VisualShaderEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { //editor->hide_animation_player_editors(); //editor->animation_panel_make_visible(true); @@ -2965,9 +2898,9 @@ void VisualShaderEditorPlugin::make_visible(bool p_visible) { visual_shader_editor->set_process_input(true); //visual_shader_editor->set_process(true); } else { - - if (visual_shader_editor->is_visible_in_tree()) + if (visual_shader_editor->is_visible_in_tree()) { editor->hide_bottom_panel(); + } button->hide(); visual_shader_editor->set_process_input(false); //visual_shader_editor->set_process(false); @@ -2975,7 +2908,6 @@ void VisualShaderEditorPlugin::make_visible(bool p_visible) { } VisualShaderEditorPlugin::VisualShaderEditorPlugin(EditorNode *p_node) { - editor = p_node; visual_shader_editor = memnew(VisualShaderEditor); visual_shader_editor->set_custom_minimum_size(Size2(0, 300) * EDSCALE); @@ -3037,9 +2969,9 @@ class VisualShaderNodePluginDefaultEditor : public VBoxContainer { public: void _property_changed(const String &p_property, const Variant &p_value, const String &p_field = "", bool p_changing = false) { - - if (p_changing) + if (p_changing) { return; + } UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo(); @@ -3049,7 +2981,6 @@ public: undo_redo->add_undo_property(node.ptr(), p_property, node->get(p_property)); if (p_value.get_type() == Variant::OBJECT) { - RES prev_res = node->get(p_property); RES curr_res = p_value; @@ -3072,8 +3003,9 @@ public: } void _node_changed() { - if (updating) + if (updating) { return; + } for (int i = 0; i < properties.size(); i++) { properties[i]->update_property(); } @@ -3109,7 +3041,6 @@ public: properties = p_properties; for (int i = 0; i < p_properties.size(); i++) { - HBoxContainer *hbox = memnew(HBoxContainer); hbox->set_h_size_flags(SIZE_EXPAND_FILL); add_child(hbox); @@ -3147,7 +3078,6 @@ public: }; Control *VisualShaderNodePluginDefault::create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node) { - if (p_node->is_class("VisualShaderNodeInput")) { //create input VisualShaderNodePluginInputEditor *input_editor = memnew(VisualShaderNodePluginInputEditor); @@ -3166,7 +3096,6 @@ Control *VisualShaderNodePluginDefault::create_editor(const Ref<Resource> &p_par Vector<PropertyInfo> pinfo; for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - for (int i = 0; i < properties.size(); i++) { if (E->get().name == String(properties[i])) { pinfo.push_back(E->get()); @@ -3174,8 +3103,9 @@ Control *VisualShaderNodePluginDefault::create_editor(const Ref<Resource> &p_par } } - if (pinfo.size() == 0) + if (pinfo.size() == 0) { return nullptr; + } properties.clear(); @@ -3183,10 +3113,10 @@ Control *VisualShaderNodePluginDefault::create_editor(const Ref<Resource> &p_par Vector<EditorProperty *> editors; for (int i = 0; i < pinfo.size(); i++) { - EditorProperty *prop = EditorInspector::instantiate_property_editor(node.ptr(), pinfo[i].type, pinfo[i].name, pinfo[i].hint, pinfo[i].hint_string, pinfo[i].usage); - if (!prop) + if (!prop) { return nullptr; + } if (Object::cast_to<EditorPropertyResource>(prop)) { Object::cast_to<EditorPropertyResource>(prop)->set_use_sub_inspector(false); @@ -3209,14 +3139,14 @@ Control *VisualShaderNodePluginDefault::create_editor(const Ref<Resource> &p_par } void EditorPropertyShaderMode::_option_selected(int p_which) { - //will not use this, instead will do all the logic setting manually //emit_signal("property_changed", get_edited_property(), p_which); Ref<VisualShader> visual_shader(Object::cast_to<VisualShader>(get_edited_object())); - if (visual_shader->get_mode() == p_which) + if (visual_shader->get_mode() == p_which) { return; + } UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo(); undo_redo->create_action(TTR("Visual Shader Mode Changed")); @@ -3227,7 +3157,6 @@ void EditorPropertyShaderMode::_option_selected(int p_which) { //1. restore connections to output for (int i = 0; i < VisualShader::TYPE_MAX; i++) { - VisualShader::Type type = VisualShader::Type(i); List<VisualShader::Connection> conns; visual_shader->get_node_connections(type, &conns); @@ -3239,7 +3168,6 @@ void EditorPropertyShaderMode::_option_selected(int p_which) { } //2. restore input indices for (int i = 0; i < VisualShader::TYPE_MAX; i++) { - VisualShader::Type type = VisualShader::Type(i); Vector<int> nodes = visual_shader->get_node_list(type); for (int j = 0; j < nodes.size(); j++) { @@ -3257,7 +3185,6 @@ void EditorPropertyShaderMode::_option_selected(int p_which) { visual_shader->get_property_list(&props); for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - if (E->get().name.begins_with("flags/") || E->get().name.begins_with("modes/")) { undo_redo->add_undo_property(visual_shader.ptr(), E->get().name, visual_shader->get(E->get().name)); } @@ -3274,7 +3201,6 @@ void EditorPropertyShaderMode::_option_selected(int p_which) { } void EditorPropertyShaderMode::update_property() { - int which = get_edited_object()->get(get_edited_property()); options->select(which); } @@ -3309,9 +3235,7 @@ void EditorInspectorShaderModePlugin::parse_begin(Object *p_object) { } bool EditorInspectorShaderModePlugin::parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide) { - if (p_path == "mode" && p_object->is_class("VisualShader") && p_type == Variant::INT) { - EditorPropertyShaderMode *editor = memnew(EditorPropertyShaderMode); Vector<String> options = p_hint_text.split(","); editor->setup(options); @@ -3326,6 +3250,7 @@ bool EditorInspectorShaderModePlugin::parse_property(Object *p_object, Variant:: void EditorInspectorShaderModePlugin::parse_end() { //do none } + ////////////////////////////////// void VisualShaderNodePortPreview::_shader_changed() { @@ -3351,11 +3276,11 @@ void VisualShaderNodePortPreview::_shader_changed() { for (int i = EditorNode::get_singleton()->get_editor_history()->get_path_size() - 1; i >= 0; i--) { Object *object = ObjectDB::get_instance(EditorNode::get_singleton()->get_editor_history()->get_path_object(i)); - if (!object) + if (!object) { continue; + } ShaderMaterial *src_mat = Object::cast_to<ShaderMaterial>(object); if (src_mat && src_mat->get_shader().is_valid()) { - List<PropertyInfo> params; src_mat->get_shader()->get_param_list(¶ms); for (List<PropertyInfo>::Element *E = params.front(); E; E = E->next()) { @@ -3368,7 +3293,6 @@ void VisualShaderNodePortPreview::_shader_changed() { } void VisualShaderNodePortPreview::setup(const Ref<VisualShader> &p_shader, VisualShader::Type p_type, int p_node, int p_port) { - shader = p_shader; shader->connect("changed", callable_mp(this, &VisualShaderNodePortPreview::_shader_changed)); type = p_type; @@ -3413,18 +3337,15 @@ VisualShaderNodePortPreview::VisualShaderNodePortPreview() { ////////////////////////////////// String VisualShaderConversionPlugin::converts_to() const { - return "Shader"; } bool VisualShaderConversionPlugin::handles(const Ref<Resource> &p_resource) const { - Ref<VisualShader> vshader = p_resource; return vshader.is_valid(); } Ref<Resource> VisualShaderConversionPlugin::convert(const Ref<Resource> &p_resource) const { - Ref<VisualShader> vshader = p_resource; ERR_FAIL_COND_V(!vshader.is_valid(), Ref<Resource>()); diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h index a495b09b5c..d2f10d9407 100644 --- a/editor/plugins/visual_shader_editor_plugin.h +++ b/editor/plugins/visual_shader_editor_plugin.h @@ -41,7 +41,6 @@ #include "scene/resources/visual_shader.h" class VisualShaderNodePlugin : public Reference { - GDCLASS(VisualShaderNodePlugin, Reference); protected: @@ -52,7 +51,6 @@ public: }; class VisualShaderEditor : public VBoxContainer { - GDCLASS(VisualShaderEditor, VBoxContainer); CustomPropertyEditor *property_editor; @@ -157,7 +155,6 @@ class VisualShaderEditor : public VBoxContainer { } }; struct _OptionComparator { - _FORCE_INLINE_ bool operator()(const AddOption &a, const AddOption &b) const { return a.category.count("/") > b.category.count("/") || (a.category + "/" + a.name).naturalnocasecmp_to(b.category + "/" + b.name) < 0; } @@ -290,7 +287,6 @@ public: }; class VisualShaderEditorPlugin : public EditorPlugin { - GDCLASS(VisualShaderEditorPlugin, EditorPlugin); VisualShaderEditor *visual_shader_editor; @@ -309,7 +305,6 @@ public: }; class VisualShaderNodePluginDefault : public VisualShaderNodePlugin { - GDCLASS(VisualShaderNodePluginDefault, VisualShaderNodePlugin); public: |