diff options
Diffstat (limited to 'editor')
140 files changed, 5920 insertions, 3140 deletions
diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp index dededfb617..f880ece88b 100644 --- a/editor/animation_bezier_editor.cpp +++ b/editor/animation_bezier_editor.cpp @@ -70,8 +70,9 @@ void AnimationBezierTrackEdit::_draw_track(int p_track, const Color &p_color) { for (Map<float, int>::Element *E = key_order.front(); E; E = E->next()) { int i = E->get(); - if (!E->next()) + if (!E->next()) { break; + } int i_n = E->next()->get(); @@ -111,11 +112,13 @@ void AnimationBezierTrackEdit::_draw_track(int p_track, const Color &p_color) { int to_x = (offset_n - timeline->get_value()) * scale + limit; int point_end = to_x; - if (from_x > right_limit) //not visible + if (from_x > right_limit) { //not visible continue; + } - if (to_x < limit) //not visible + if (to_x < limit) { //not visible continue; + } from_x = MAX(from_x, limit); to_x = MIN(to_x, right_limit); @@ -182,17 +185,20 @@ void AnimationBezierTrackEdit::_draw_line_clipped(const Vector2 &p_from, const V Vector2 from = p_from; Vector2 to = p_to; - if (from.x == to.x) + if (from.x == to.x) { return; + } if (to.x < from.x) { SWAP(to, from); } - if (to.x < p_clip_left) + if (to.x < p_clip_left) { return; + } - if (from.x > p_clip_right) + if (from.x > p_clip_right) { return; + } if (to.x > p_clip_right) { float c = (p_clip_right - from.x) / (to.x - from.x); @@ -227,8 +233,9 @@ void AnimationBezierTrackEdit::_notification(int p_what) { handle_mode_option->set_size(Vector2(timeline->get_buttons_width() - hsep * 2, handle_mode_option->get_combined_minimum_size().height)); } if (p_what == NOTIFICATION_DRAW) { - if (animation.is_null()) + if (animation.is_null()) { return; + } int limit = timeline->get_name_limit(); @@ -309,11 +316,13 @@ void AnimationBezierTrackEdit::_notification(int p_what) { subtracks.clear(); for (int i = 0; i < animation->get_track_count(); i++) { - if (animation->track_get_type(i) != Animation::TYPE_BEZIER) + if (animation->track_get_type(i) != Animation::TYPE_BEZIER) { continue; + } String path = animation->track_get_path(i); - if (!path.begins_with(base_path)) + if (!path.begins_with(base_path)) { continue; //another node + } path = path.replace_first(base_path, ""); Color cc = color; @@ -363,8 +372,9 @@ void AnimationBezierTrackEdit::_notification(int p_what) { ofs += v_scroll; int iv = int(ofs / scale); - if (ofs < 0) + if (ofs < 0) { iv -= 1; + } if (!first && iv != prev_iv) { Color lc = linecolor; lc.a *= 0.5; @@ -488,10 +498,12 @@ Ref<Animation> AnimationBezierTrackEdit::get_animation() const { void AnimationBezierTrackEdit::set_animation_and_track(const Ref<Animation> &p_animation, int p_track) { animation = p_animation; track = p_track; - if (is_connected_compat("select_key", editor, "_key_selected")) + if (is_connected_compat("select_key", editor, "_key_selected")) { disconnect_compat("select_key", editor, "_key_selected"); - if (is_connected_compat("deselect_key", editor, "_key_deselected")) + } + if (is_connected_compat("deselect_key", editor, "_key_deselected")) { disconnect_compat("deselect_key", editor, "_key_deselected"); + } connect_compat("select_key", editor, "_key_selected", varray(p_track), CONNECT_DEFERRED); connect_compat("deselect_key", editor, "_key_deselected", varray(p_track), CONNECT_DEFERRED); update(); @@ -516,8 +528,9 @@ void AnimationBezierTrackEdit::set_editor(AnimationTrackEditor *p_editor) { } void AnimationBezierTrackEdit::_play_position_draw() { - if (!animation.is_valid() || play_position_pos < 0) + if (!animation.is_valid() || play_position_pos < 0) { return; + } float scale = timeline->get_zoom_scale(); int h = get_size().height; @@ -558,15 +571,17 @@ void AnimationBezierTrackEdit::_clear_selection() { } void AnimationBezierTrackEdit::_clear_selection_for_anim(const Ref<Animation> &p_anim) { - if (!(animation == p_anim)) + if (!(animation == p_anim)) { return; + } //selection.clear(); _clear_selection(); } void AnimationBezierTrackEdit::_select_at_anim(const Ref<Animation> &p_anim, int p_track, float p_pos) { - if (!(animation == p_anim)) + if (!(animation == p_anim)) { return; + } int idx = animation->track_find_key(p_track, p_pos, true); ERR_FAIL_COND(idx < 0); @@ -822,11 +837,13 @@ void AnimationBezierTrackEdit::_gui_input(const Ref<InputEvent> &p_event) { float newtime = editor->snap_time(animation->track_get_key_time(track, E->get()) + moving_selection_offset.x); int idx = animation->track_find_key(track, newtime, true); - if (idx == -1) + if (idx == -1) { continue; + } - if (selection.has(idx)) + if (selection.has(idx)) { continue; //already in selection, don't save + } undo_redo->add_do_method(animation.ptr(), "track_remove_key_at_position", track, newtime); AnimMoveRestore amr; @@ -902,10 +919,12 @@ void AnimationBezierTrackEdit::_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseMotion> mm = p_event; if (mm.is_valid() && mm->get_button_mask() & BUTTON_MASK_MIDDLE) { v_scroll += mm->get_relative().y * v_zoom; - if (v_scroll > 100000) + if (v_scroll > 100000) { v_scroll = 100000; - if (v_scroll < -100000) + } + if (v_scroll < -100000) { v_scroll = -100000; + } int x = mm->get_position().x - timeline->get_name_limit(); float ofs = x / timeline->get_zoom_scale(); @@ -1021,14 +1040,16 @@ void AnimationBezierTrackEdit::_menu_selected(int p_index) { } void AnimationBezierTrackEdit::duplicate_selection() { - if (selection.size() == 0) + if (selection.size() == 0) { return; + } float top_time = 1e10; for (Set<int>::Element *E = selection.back(); E; E = E->prev()) { float t = animation->track_get_key_time(track, E->get()); - if (t < top_time) + if (t < top_time) { top_time = t; + } } undo_redo->create_action(TTR("Anim Duplicate Keys")); @@ -1064,8 +1085,9 @@ void AnimationBezierTrackEdit::duplicate_selection() { int existing_idx = animation->track_find_key(track, time, true); - if (existing_idx == -1) + if (existing_idx == -1) { continue; + } selection.insert(existing_idx); } diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 0808946b16..2a8e0d856e 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -65,8 +65,9 @@ public: void _fix_node_path(Variant &value) { NodePath np = value; - if (np == NodePath()) + if (np == NodePath()) { return; + } Node *root = EditorNode::get_singleton()->get_tree()->get_root(); @@ -80,20 +81,23 @@ public: } void _update_obj(const Ref<Animation> &p_anim) { - if (setting || animation != p_anim) + if (setting || animation != p_anim) { return; + } notify_change(); } void _key_ofs_changed(const Ref<Animation> &p_anim, float from, float to) { - if (animation != p_anim || from != key_ofs) + if (animation != p_anim || from != key_ofs) { return; + } key_ofs = to; - if (setting) + if (setting) { return; + } notify_change(); } @@ -114,8 +118,9 @@ public: new_time /= fps; } - if (new_time == key_ofs) + if (new_time == key_ofs) { return true; + } int existing = animation->track_find_key(track, new_time, true); @@ -242,10 +247,11 @@ public: } } - if (mergeable) + if (mergeable) { undo_redo->create_action(TTR("Anim Change Call"), UndoRedo::MERGE_ENDS); - else + } else { undo_redo->create_action(TTR("Anim Change Call")); + } setting = true; undo_redo->add_do_method(animation.ptr(), "track_set_key_value", track, key, d_new); @@ -255,8 +261,9 @@ public: undo_redo->commit_action(); setting = false; - if (change_notify_deserved) + if (change_notify_deserved) { notify_change(); + } return true; } break; case Animation::TYPE_BEZIER: { @@ -499,8 +506,9 @@ public: return false; } void _get_property_list(List<PropertyInfo> *p_list) const { - if (animation.is_null()) + if (animation.is_null()) { return; + } ERR_FAIL_INDEX(track, animation->get_track_count()); int key = animation->track_find_key(track, key_ofs, true); @@ -540,8 +548,9 @@ public: } } - if (v.get_type() != Variant::NIL) + if (v.get_type() != Variant::NIL) { p_list->push_back(PropertyInfo(v.get_type(), "value", hint, hint_string)); + } } } break; @@ -554,15 +563,17 @@ public: Vector<Variant> args = d["args"]; String vtypes; for (int i = 0; i < Variant::VARIANT_MAX; i++) { - if (i > 0) + if (i > 0) { vtypes += ","; + } vtypes += Variant::get_type_name(Variant::Type(i)); } for (int i = 0; i < args.size(); i++) { p_list->push_back(PropertyInfo(Variant::INT, "args/" + itos(i) + "/type", PROPERTY_HINT_ENUM, vtypes)); - if (args[i].get_type() != Variant::NIL) + if (args[i].get_type() != Variant::NIL) { p_list->push_back(PropertyInfo(args[i].get_type(), "args/" + itos(i) + "/value")); + } } } break; @@ -668,8 +679,9 @@ public: void _fix_node_path(Variant &value, NodePath &base) { NodePath np = value; - if (np == NodePath()) + if (np == NodePath()) { return; + } Node *root = EditorNode::get_singleton()->get_tree()->get_root(); @@ -683,15 +695,17 @@ public: } void _update_obj(const Ref<Animation> &p_anim) { - if (setting || animation != p_anim) + if (setting || animation != p_anim) { return; + } notify_change(); } void _key_ofs_changed(const Ref<Animation> &p_anim, float from, float to) { - if (animation != p_anim) + if (animation != p_anim) { return; + } for (Map<int, List<float>>::Element *E = key_ofs_map.front(); E; E = E->next()) { int key = 0; @@ -705,8 +719,9 @@ public: int track = E->key(); key_ofs_map[track][key] = to; - if (setting) + if (setting) { return; + } notify_change(); @@ -853,10 +868,11 @@ public: Variant prev = animation->track_get_key_value(track, key); if (!setting) { - if (mergeable) + if (mergeable) { undo_redo->create_action(TTR("Anim Multi Change Call"), UndoRedo::MERGE_ENDS); - else + } else { undo_redo->create_action(TTR("Anim Multi Change Call")); + } setting = true; } @@ -964,8 +980,9 @@ public: undo_redo->commit_action(); setting = false; - if (change_notify_deserved) + if (change_notify_deserved) { notify_change(); + } return true; } @@ -1099,8 +1116,9 @@ public: return false; } void _get_property_list(List<PropertyInfo> *p_list) const { - if (animation.is_null()) + if (animation.is_null()) { return; + } int first_track = -1; float first_key = -1.0; @@ -1112,11 +1130,13 @@ public: int track = E->key(); ERR_FAIL_INDEX(track, animation->get_track_count()); - if (first_track < 0) + if (first_track < 0) { first_track = track; + } - if (show_time && E->value().size() > 1) + if (show_time && E->value().size() > 1) { show_time = false; + } if (same_track_type) { if (animation->track_get_type(first_track) != animation->track_get_type(track)) { @@ -1127,11 +1147,13 @@ public: for (List<float>::Element *F = E->value().front(); F; F = F->next()) { int key = animation->track_find_key(track, F->get(), true); ERR_FAIL_COND(key == -1); - if (first_key < 0) + if (first_key < 0) { first_key = key; + } - if (animation->track_get_key_value(first_track, first_key).get_type() != animation->track_get_key_value(track, key).get_type()) + if (animation->track_get_key_value(first_track, first_key).get_type() != animation->track_get_key_value(track, key).get_type()) { same_key_type = false; + } } } } @@ -1153,8 +1175,9 @@ public: p_list->push_back(PropertyInfo(Variant::VECTOR3, "scale")); } break; case Animation::TYPE_VALUE: { - if (!same_key_type) + if (!same_key_type) { break; + } Variant v = animation->track_get_key_value(first_track, first_key); @@ -1175,8 +1198,9 @@ public: } } - if (v.get_type() != Variant::NIL) + if (v.get_type() != Variant::NIL) { p_list->push_back(PropertyInfo(v.get_type(), "value", hint, hint_string)); + } } p_list->push_back(PropertyInfo(Variant::FLOAT, "easing", PROPERTY_HINT_EXP_EASING)); @@ -1190,15 +1214,17 @@ public: Vector<Variant> args = d["args"]; String vtypes; for (int i = 0; i < Variant::VARIANT_MAX; i++) { - if (i > 0) + if (i > 0) { vtypes += ","; + } vtypes += Variant::get_type_name(Variant::Type(i)); } for (int i = 0; i < args.size(); i++) { p_list->push_back(PropertyInfo(Variant::INT, "args/" + itos(i) + "/type", PROPERTY_HINT_ENUM, vtypes)); - if (args[i].get_type() != Variant::NIL) + if (args[i].get_type() != Variant::NIL) { p_list->push_back(PropertyInfo(args[i].get_type(), "args/" + itos(i) + "/value")); + } } } break; case Animation::TYPE_BEZIER: { @@ -1212,8 +1238,9 @@ public: p_list->push_back(PropertyInfo(Variant::FLOAT, "end_offset", PROPERTY_HINT_RANGE, "0,3600,0.01,or_greater")); } break; case Animation::TYPE_ANIMATION: { - if (key_ofs_map.size() > 1) + if (key_ofs_map.size() > 1) { break; + } String animations; @@ -1292,8 +1319,9 @@ float AnimationTimelineEdit::get_zoom_scale() const { } void AnimationTimelineEdit::_anim_length_changed(double p_new_len) { - if (editing) + if (editing) { return; + } p_new_len = MAX(0.001, p_new_len); if (use_fps && animation->get_step() > 0) { @@ -1364,8 +1392,9 @@ void AnimationTimelineEdit::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { int key_range = get_size().width - get_buttons_width() - get_name_limit(); - if (!animation.is_valid()) + if (!animation.is_valid()) { return; + } Ref<Font> font = get_theme_font("font", "Label"); Color color = get_theme_color("font_color", "Label"); @@ -1375,8 +1404,9 @@ void AnimationTimelineEdit::_notification(int p_what) { int h = get_size().height; float l = animation->get_length(); - if (l <= 0) + if (l <= 0) { l = 0.001; //avoid crashor + } Ref<Texture2D> hsize_icon = get_theme_icon("Hsize", "EditorIcons"); hsize_rect = Rect2(get_name_limit() - hsize_icon->get_width() - 2 * EDSCALE, (get_size().height - hsize_icon->get_height()) / 2, hsize_icon->get_width(), hsize_icon->get_height()); @@ -1392,16 +1422,18 @@ void AnimationTimelineEdit::_notification(int p_what) { beg += animation->bezier_track_get_key_in_handle(i, 0).x; }* not worth it since they have no use */ - if (beg < time_min) + if (beg < time_min) { time_min = beg; + } float end = animation->track_get_key_time(i, animation->track_get_key_count(i) - 1); /*if (animation->track_get_type(i) == Animation::TYPE_BEZIER) { end += animation->bezier_track_get_key_out_handle(i, animation->track_get_key_count(i) - 1).x; } not worth it since they have no use */ - if (end > time_max) + if (end > time_max) { time_max = end; + } } } @@ -1435,10 +1467,12 @@ void AnimationTimelineEdit::_notification(int p_what) { draw_rect(Rect2(Point2(get_name_limit(), 0), Point2(zoomw - 1, h)), notimecol); if (begin_px < zoomw && end_px > 0) { - if (begin_px < 0) + if (begin_px < 0) { begin_px = 0; - if (end_px > zoomw) + } + if (end_px > zoomw) { end_px = zoomw; + } draw_rect(Rect2(Point2(get_name_limit() + begin_px, 0), Point2(end_px - begin_px - 1, h)), timecolor); } @@ -1465,8 +1499,9 @@ void AnimationTimelineEdit::_notification(int p_what) { while (!step_found) { min = max_sc_width; - if (decimals > 0) + if (decimals > 0) { min += period_width + max_digit_width * decimals; + } static const int _multp[3] = { 1, 2, 5 }; for (int i = 0; i < 3; i++) { @@ -1476,12 +1511,14 @@ void AnimationTimelineEdit::_notification(int p_what) { break; } } - if (step_found) + if (step_found) { break; + } dec *= 10; decimals--; - if (decimals < 0) + if (decimals < 0) { decimals = 0; + } } if (use_fps) { @@ -1574,8 +1611,9 @@ void AnimationTimelineEdit::update_play_position() { } void AnimationTimelineEdit::update_values() { - if (!animation.is_valid() || editing) + if (!animation.is_valid() || editing) { return; + } editing = true; if (use_fps && animation->get_step() > 0) { @@ -1594,8 +1632,9 @@ void AnimationTimelineEdit::update_values() { } void AnimationTimelineEdit::_play_position_draw() { - if (!animation.is_valid() || play_position_pos < 0) + if (!animation.is_valid() || play_position_pos < 0) { return; + } float scale = get_zoom_scale(); int h = play_position->get_size().height; @@ -1764,8 +1803,9 @@ AnimationTimelineEdit::AnimationTimelineEdit() { void AnimationTrackEdit::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { - if (animation.is_null()) + if (animation.is_null()) { return; + } ERR_FAIL_INDEX(track, animation->get_track_count()); int limit = timeline->get_name_limit(); @@ -2062,15 +2102,17 @@ void AnimationTrackEdit::_notification(int p_what) { } int AnimationTrackEdit::get_key_height() const { - if (!animation.is_valid()) + if (!animation.is_valid()) { return 0; + } return type_icon->get_height(); } Rect2 AnimationTrackEdit::get_key_rect(int p_index, float p_pixels_sec) { - if (!animation.is_valid()) + if (!animation.is_valid()) { return Rect2(); + } Rect2 rect = Rect2(-type_icon->get_width() / 2, 0, type_icon->get_width(), get_size().height); //make it a big easier to click @@ -2084,15 +2126,18 @@ bool AnimationTrackEdit::is_key_selectable_by_distance() const { } void AnimationTrackEdit::draw_key_link(int p_index, float p_pixels_sec, int p_x, int p_next_x, int p_clip_left, int p_clip_right) { - if (p_next_x < p_clip_left) + if (p_next_x < p_clip_left) { return; - if (p_x > p_clip_right) + } + if (p_x > p_clip_right) { return; + } Variant current = animation->track_get_key_value(get_track(), p_index); Variant next = animation->track_get_key_value(get_track(), p_index + 1); - if (current != next) + if (current != next) { return; + } Color color = get_theme_color("font_color", "Label"); color.a = 0.5; @@ -2104,11 +2149,13 @@ void AnimationTrackEdit::draw_key_link(int p_index, float p_pixels_sec, int p_x, } void AnimationTrackEdit::draw_key(int p_index, float p_pixels_sec, int p_x, bool p_selected, int p_clip_left, int p_clip_right) { - if (!animation.is_valid()) + if (!animation.is_valid()) { return; + } - if (p_x < p_clip_left || p_x > p_clip_right) + if (p_x < p_clip_left || p_x > p_clip_right) { return; + } Ref<Texture2D> icon_to_draw = p_selected ? selected_icon : type_icon; @@ -2131,15 +2178,18 @@ void AnimationTrackEdit::draw_key(int p_index, float p_pixels_sec, int p_x, bool Dictionary d = animation->track_get_key_value(track, p_index); String text; - if (d.has("method")) + if (d.has("method")) { text += String(d["method"]); + } text += "("; Vector<Variant> args; - if (d.has("args")) + if (d.has("args")) { args = d["args"]; + } for (int i = 0; i < args.size(); i++) { - if (i > 0) + if (i > 0) { text += ", "; + } text += String(args[i]); } text += ")"; @@ -2158,10 +2208,12 @@ void AnimationTrackEdit::draw_rect_clipped(const Rect2 &p_rect, const Color &p_c int clip_left = timeline->get_name_limit(); int clip_right = get_size().width - timeline->get_buttons_width(); - if (p_rect.position.x > clip_right) + if (p_rect.position.x > clip_right) { return; - if (p_rect.position.x + p_rect.size.x < clip_left) + } + if (p_rect.position.x + p_rect.size.x < clip_left) { return; + } Rect2 clip = Rect2(clip_left, 0, clip_right - clip_left, get_size().height); draw_rect(clip.clip(p_rect), p_color, p_filled); } @@ -2181,10 +2233,12 @@ void AnimationTrackEdit::draw_texture_region_clipped(const Ref<Texture2D> &p_tex int clip_right = get_size().width - timeline->get_buttons_width(); //clip left and right - if (clip_left > p_rect.position.x + p_rect.size.x) + if (clip_left > p_rect.position.x + p_rect.size.x) { return; - if (clip_right < p_rect.position.x) + } + if (clip_right < p_rect.position.x) { return; + } Rect2 rect = p_rect; Rect2 region = p_region; @@ -2270,8 +2324,9 @@ void AnimationTrackEdit::set_editor(AnimationTrackEditor *p_editor) { } void AnimationTrackEdit::_play_position_draw() { - if (!animation.is_valid() || play_position_pos < 0) + if (!animation.is_valid() || play_position_pos < 0) { return; + } float scale = timeline->get_zoom_scale(); int h = get_size().height; @@ -2311,8 +2366,9 @@ void AnimationTrackEdit::_path_entered(const String &p_text) { } bool AnimationTrackEdit::_is_value_key_valid(const Variant &p_key_value, Variant::Type &r_valid_type) const { - if (root == nullptr) + if (root == nullptr) { return false; + } RES res; Vector<StringName> leftover_path; @@ -2394,12 +2450,15 @@ String AnimationTrackEdit::get_tooltip(const Point2 &p_pos) const { switch (animation->track_get_type(track)) { case Animation::TYPE_TRANSFORM: { Dictionary d = animation->track_get_key_value(track, key_idx); - if (d.has("location")) + if (d.has("location")) { text += "Pos: " + String(d["location"]) + "\n"; - if (d.has("rotation")) + } + if (d.has("rotation")) { text += "Rot: " + String(d["rotation"]) + "\n"; - if (d.has("scale")) + } + if (d.has("scale")) { text += "Scale: " + String(d["scale"]) + "\n"; + } } break; case Animation::TYPE_VALUE: { const Variant &v = animation->track_get_key_value(track, key_idx); @@ -2415,15 +2474,18 @@ String AnimationTrackEdit::get_tooltip(const Point2 &p_pos) const { } break; case Animation::TYPE_METHOD: { Dictionary d = animation->track_get_key_value(track, key_idx); - if (d.has("method")) + if (d.has("method")) { text += String(d["method"]); + } text += "("; Vector<Variant> args; - if (d.has("args")) + if (d.has("args")) { args = d["args"]; + } for (int i = 0; i < args.size(); i++) { - if (i > 0) + if (i > 0) { text += ", "; + } text += String(args[i]); } text += ")\n"; @@ -2713,8 +2775,9 @@ void AnimationTrackEdit::_gui_input(const Ref<InputEvent> &p_event) { } Variant AnimationTrackEdit::get_drag_data(const Point2 &p_point) { - if (!clicking_on_name) + if (!clicking_on_name) { return Variant(); + } Dictionary drag_data; drag_data["type"] = "animation_track"; @@ -2868,10 +2931,11 @@ void AnimationTrackEdit::append_to_selection(const Rect2 &p_box, bool p_deselect rect.position.x += offset; if (select_rect.intersects(rect)) { - if (p_deselection) + if (p_deselection) { emit_signal("deselect_key", i); - else + } else { emit_signal("select_key", i, false); + } } } } @@ -3044,8 +3108,9 @@ AnimationTrackEditGroup::AnimationTrackEditGroup() { ////////////////////////////////////// void AnimationTrackEditor::add_track_edit_plugin(const Ref<AnimationTrackEditPlugin> &p_plugin) { - if (track_edit_plugins.find(p_plugin) != -1) + if (track_edit_plugins.find(p_plugin) != -1) { return; + } track_edit_plugins.push_back(p_plugin); } @@ -3129,8 +3194,9 @@ Node *AnimationTrackEditor::get_root() const { void AnimationTrackEditor::update_keying() { bool keying_enabled = is_visible_in_tree() && animation.is_valid(); - if (keying_enabled == keying) + if (keying_enabled == keying) { return; + } keying = keying_enabled; //_update_menu(); @@ -3224,8 +3290,9 @@ void AnimationTrackEditor::_track_remove_request(int p_track) { void AnimationTrackEditor::_track_grab_focus(int p_track) { // Don't steal focus if not working with the track editor. - if (Object::cast_to<AnimationTrackEdit>(get_focus_owner())) + if (Object::cast_to<AnimationTrackEdit>(get_focus_owner())) { track_edits[p_track]->grab_focus(); + } } void AnimationTrackEditor::set_anim_pos(float p_pos) { @@ -3242,8 +3309,9 @@ void AnimationTrackEditor::set_anim_pos(float p_pos) { void AnimationTrackEditor::_query_insert(const InsertData &p_id) { if (insert_frame != Engine::get_singleton()->get_frames_drawn()) { //clear insert list for the frame if frame changed - if (insert_confirm->is_visible()) + if (insert_confirm->is_visible()) { return; //do nothing + } insert_data.clear(); insert_query = false; } @@ -3251,8 +3319,9 @@ void AnimationTrackEditor::_query_insert(const InsertData &p_id) { for (List<InsertData>::Element *E = insert_data.front(); E; E = E->next()) { //prevent insertion of multiple tracks - if (E->get().path == p_id.path) + if (E->get().path == p_id.path) { return; //already inserted a track for this on this frame + } } insert_data.push_back(p_id); @@ -3263,14 +3332,17 @@ void AnimationTrackEditor::_query_insert(const InsertData &p_id) { int num_tracks = 0; bool all_bezier = true; for (int i = 0; i < insert_data.size(); i++) { - if (insert_data[i].type != Animation::TYPE_VALUE && insert_data[i].type != Animation::TYPE_BEZIER) + if (insert_data[i].type != Animation::TYPE_VALUE && insert_data[i].type != Animation::TYPE_BEZIER) { all_bezier = false; + } - if (insert_data[i].track_idx == -1) + if (insert_data[i].track_idx == -1) { ++num_tracks; + } - if (insert_data[i].type != Animation::TYPE_VALUE) + if (insert_data[i].type != Animation::TYPE_VALUE) { continue; + } switch (insert_data[i].value.get_type()) { case Variant::INT: @@ -3288,10 +3360,11 @@ void AnimationTrackEditor::_query_insert(const InsertData &p_id) { } } - if (num_tracks == 1) + if (num_tracks == 1) { insert_confirm_text->set_text(vformat(TTR("Create NEW track for %s and insert key?"), p_id.query)); - else + } else { insert_confirm_text->set_text(vformat(TTR("Create %d NEW tracks and insert keys?"), num_tracks)); + } insert_confirm_bezier->set_visible(all_bezier); insert_confirm->get_ok()->set_text(TTR("Create")); @@ -3322,8 +3395,9 @@ void AnimationTrackEditor::_insert_delay() { int last_track = animation->get_track_count(); bool advance = false; while (insert_data.size()) { - if (insert_data.front()->get().advance) + if (insert_data.front()->get().advance) { advance = true; + } last_track = _confirm_insert(insert_data.front()->get(), last_track); insert_data.pop_front(); } @@ -3332,14 +3406,16 @@ void AnimationTrackEditor::_insert_delay() { if (advance) { float step = animation->get_step(); - if (step == 0) + if (step == 0) { step = 1; + } float pos = timeline->get_play_position(); pos = Math::stepify(pos + step, step); - if (pos > animation->get_length()) + if (pos > animation->get_length()) { pos = animation->get_length(); + } set_anim_pos(pos); emit_signal("timeline_changed", pos, true); } @@ -3347,26 +3423,31 @@ void AnimationTrackEditor::_insert_delay() { } void AnimationTrackEditor::insert_transform_key(Node3D *p_node, const String &p_sub, const Transform &p_xform) { - if (!keying) + if (!keying) { return; - if (!animation.is_valid()) + } + if (!animation.is_valid()) { return; + } ERR_FAIL_COND(!root); //let's build a node path String path = root->get_path_to(p_node); - if (p_sub != "") + if (p_sub != "") { path += ":" + p_sub; + } NodePath np = path; int track_idx = -1; for (int i = 0; i < animation->get_track_count(); i++) { - if (animation->track_get_type(i) != Animation::TYPE_TRANSFORM) + if (animation->track_get_type(i) != Animation::TYPE_TRANSFORM) { continue; - if (animation->track_get_path(i) != np) + } + if (animation->track_get_path(i) != np) { continue; + } track_idx = i; break; @@ -3454,8 +3535,9 @@ void AnimationTrackEditor::insert_node_value_key(Node *p_node, const String &p_p for (int i = 0; i < animation->get_track_count(); i++) { if (animation->track_get_type(i) == Animation::TYPE_VALUE) { - if (animation->track_get_path(i) != np) + if (animation->track_get_path(i) != np) { continue; + } InsertData id; id.path = np; @@ -3479,10 +3561,12 @@ void AnimationTrackEditor::insert_node_value_key(Node *p_node, const String &p_p if (base_path == np) { String value_name = track_path.substr(sep + 1); value = p_value.get(value_name); - } else + } else { continue; - } else + } + } else { continue; + } } InsertData id; @@ -3498,8 +3582,9 @@ void AnimationTrackEditor::insert_node_value_key(Node *p_node, const String &p_p } } - if (inserted || p_only_if_exists) + if (inserted || p_only_if_exists) { return; + } InsertData id; id.path = np; id.track_idx = -1; @@ -3549,8 +3634,9 @@ void AnimationTrackEditor::insert_value_key(const String &p_property, const Vari for (int i = 0; i < animation->get_track_count(); i++) { if (animation->track_get_type(i) == Animation::TYPE_VALUE) { - if (animation->track_get_path(i) != np) + if (animation->track_get_path(i) != np) { continue; + } InsertData id; id.path = np; @@ -3728,8 +3814,9 @@ static Vector<String> _get_bezier_subindices_for_type(Variant::Type p_type, bool } int AnimationTrackEditor::_confirm_insert(InsertData p_id, int p_last_track, bool p_create_beziers) { - if (p_last_track == -1) + if (p_last_track == -1) { p_last_track = animation->get_track_count(); + } bool created = false; if (p_id.track_idx < 0) { @@ -3786,8 +3873,9 @@ int AnimationTrackEditor::_confirm_insert(InsertData p_id, int p_last_track, boo undo_redo->add_do_method(animation.ptr(), "add_track", p_id.type); undo_redo->add_do_method(animation.ptr(), "track_set_path", p_id.track_idx, p_id.path); - if (p_id.type == Animation::TYPE_VALUE) + if (p_id.type == Animation::TYPE_VALUE) { undo_redo->add_do_method(animation.ptr(), "value_track_set_update_mode", p_id.track_idx, update_mode); + } } else { undo_redo->create_action(TTR("Anim Insert Key")); @@ -3879,8 +3967,9 @@ void AnimationTrackEditor::_update_tracks() { track_edits.clear(); groups.clear(); - if (animation.is_null()) + if (animation.is_null()) { return; + } Map<String, VBoxContainer *> group_sort; @@ -4044,10 +4133,11 @@ void AnimationTrackEditor::_animation_changed() { if (key_edit && key_edit->setting) { //if editing a key, just update the edited track, makes refresh less costly if (key_edit->track < track_edits.size()) { - if (animation->track_get_type(key_edit->track) == Animation::TYPE_BEZIER) + if (animation->track_get_type(key_edit->track) == Animation::TYPE_BEZIER) { bezier_edit->update(); - else + } else { track_edits[key_edit->track]->update(); + } } return; } @@ -4363,8 +4453,9 @@ void AnimationTrackEditor::_timeline_value_changed(double) { int AnimationTrackEditor::_get_track_selected() { for (int i = 0; i < track_edits.size(); i++) { - if (track_edits[i]->has_focus()) + if (track_edits[i]->has_focus()) { return i; + } } return -1; @@ -4608,8 +4699,9 @@ void AnimationTrackEditor::_clear_selection(bool p_update) { void AnimationTrackEditor::_update_key_edit() { _clear_key_edit(); - if (!animation.is_valid()) + if (!animation.is_valid()) { return; + } if (selection.size() == 1) { key_edit = memnew(AnimationTrackKeyEdit); @@ -4636,8 +4728,9 @@ void AnimationTrackEditor::_update_key_edit() { int first_track = -1; for (Map<SelectedKey, KeyInfo>::Element *E = selection.front(); E; E = E->next()) { int track = E->key().track; - if (first_track < 0) + if (first_track < 0) { first_track = track; + } if (!key_ofs_map.has(track)) { key_ofs_map[track] = List<float>(); @@ -4661,15 +4754,17 @@ void AnimationTrackEditor::_update_key_edit() { } void AnimationTrackEditor::_clear_selection_for_anim(const Ref<Animation> &p_anim) { - if (animation != p_anim) + if (animation != p_anim) { return; + } _clear_selection(); } void AnimationTrackEditor::_select_at_anim(const Ref<Animation> &p_anim, int p_track, float p_pos) { - if (animation != p_anim) + if (animation != p_anim) { return; + } int idx = animation->track_find_key(p_track, p_pos, true); ERR_FAIL_COND(idx < 0); @@ -4697,13 +4792,15 @@ void AnimationTrackEditor::_move_selection_commit() { for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) { float newtime = snap_time(E->get().pos + motion); int idx = animation->track_find_key(E->key().track, newtime, true); - if (idx == -1) + if (idx == -1) { continue; + } SelectedKey sk; sk.key = idx; sk.track = E->key().track; - if (selection.has(sk)) + if (selection.has(sk)) { continue; //already in selection, don't save + } undo_redo->add_do_method(animation.ptr(), "track_remove_key_at_position", E->key().track, newtime); _AnimMoveRestore amr; @@ -4891,10 +4988,12 @@ void AnimationTrackEditor::_anim_duplicate_keys(bool transpose) { const SelectedKey &sk = E->key(); float t = animation->track_get_key_time(sk.track, sk.key); - if (t < top_time) + if (t < top_time) { top_time = t; - if (sk.track < top_track) + } + if (sk.track < top_track) { top_track = sk.track; + } } ERR_FAIL_COND(top_track == 0x7FFFFFFF || top_time == 1e10); @@ -4914,11 +5013,13 @@ void AnimationTrackEditor::_anim_duplicate_keys(bool transpose) { float dst_time = t + (timeline->get_play_position() - top_time); int dst_track = sk.track + (start_track - top_track); - if (dst_track < 0 || dst_track >= animation->get_track_count()) + if (dst_track < 0 || dst_track >= animation->get_track_count()) { continue; + } - if (animation->track_get_type(dst_track) != animation->track_get_type(sk.track)) + if (animation->track_get_type(dst_track) != animation->track_get_type(sk.track)) { continue; + } int existing_idx = animation->track_find_key(dst_track, dst_time, true); @@ -4946,8 +5047,9 @@ void AnimationTrackEditor::_anim_duplicate_keys(bool transpose) { int existing_idx = animation->track_find_key(track, time, true); - if (existing_idx == -1) + if (existing_idx == -1) { continue; + } SelectedKey sk2; sk2.track = track; sk2.key = existing_idx; @@ -5111,8 +5213,9 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) { scale_dialog->popup_centered(Size2(200, 100) * EDSCALE); } break; case EDIT_SCALE_CONFIRM: { - if (selection.empty()) + if (selection.empty()) { return; + } float from_t = 1e20; float to_t = -1e20; @@ -5121,10 +5224,12 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) { for (Map<SelectedKey, KeyInfo>::Element *E = selection.front(); E; E = E->next()) { float t = animation->track_get_key_time(E->key().track, E->key().key); - if (t < from_t) + if (t < from_t) { from_t = t; - if (t > to_t) + } + if (t > to_t) { to_t = t; + } } len = to_t - from_t; @@ -5152,13 +5257,15 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) { for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) { float newtime = (E->get().pos - from_t) * s + from_t; int idx = animation->track_find_key(E->key().track, newtime, true); - if (idx == -1) + if (idx == -1) { continue; + } SelectedKey sk; sk.key = idx; sk.track = E->key().track; - if (selection.has(sk)) + if (selection.has(sk)) { continue; //already in selection, don't save + } undo_redo->add_do_method(animation.ptr(), "track_remove_key_at_position", E->key().track, newtime); _AnimMoveRestore amr; @@ -5202,8 +5309,9 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) { for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) { float oldpos = E->get().pos; float newpos = _NEW_POS(oldpos); - if (newpos >= 0) + if (newpos >= 0) { undo_redo->add_do_method(this, "_select_at_anim", animation, E->key().track, newpos); + } undo_redo->add_undo_method(this, "_select_at_anim", animation, E->key().track, oldpos); } #undef _NEW_POS @@ -5243,33 +5351,39 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) { } } break; case EDIT_GOTO_NEXT_STEP: { - if (animation.is_null()) + if (animation.is_null()) { break; + } float step = animation->get_step(); - if (step == 0) + if (step == 0) { step = 1; + } float pos = timeline->get_play_position(); pos = Math::stepify(pos + step, step); - if (pos > animation->get_length()) + if (pos > animation->get_length()) { pos = animation->get_length(); + } set_anim_pos(pos); emit_signal("timeline_changed", pos, true); } break; case EDIT_GOTO_PREV_STEP: { - if (animation.is_null()) + if (animation.is_null()) { break; + } float step = animation->get_step(); - if (step == 0) + if (step == 0) { step = 1; + } float pos = timeline->get_play_position(); pos = Math::stepify(pos - step, step); - if (pos < 0) + if (pos < 0) { pos = 0; + } set_anim_pos(pos); emit_signal("timeline_changed", pos, true); @@ -5330,8 +5444,9 @@ void AnimationTrackEditor::_cleanup_animation(Ref<Animation> p_animation) { continue; } - if (!prop_exists || p_animation->track_get_type(i) != Animation::TYPE_VALUE || !cleanup_keys->is_pressed()) + if (!prop_exists || p_animation->track_get_type(i) != Animation::TYPE_VALUE || !cleanup_keys->is_pressed()) { continue; + } for (int j = 0; j < p_animation->track_get_key_count(i); j++) { Variant v = p_animation->track_get_key_value(i, j); @@ -5382,10 +5497,11 @@ void AnimationTrackEditor::_selection_changed() { float AnimationTrackEditor::snap_time(float p_value, bool p_relative) { if (is_snap_enabled()) { double snap_increment; - if (timeline->is_using_fps() && step->get_value() > 0) + if (timeline->is_using_fps() && step->get_value() > 0) { snap_increment = 1.0 / step->get_value(); - else + } else { snap_increment = step->get_value(); + } if (p_relative) { double rel = Math::fmod(timeline->get_value(), snap_increment); @@ -5406,13 +5522,15 @@ void AnimationTrackEditor::_show_imported_anim_warning() { void AnimationTrackEditor::_select_all_tracks_for_copy() { TreeItem *track = track_copy_select->get_root()->get_children(); - if (!track) + if (!track) { return; + } bool all_selected = true; while (track) { - if (!track->is_checked(0)) + if (!track->is_checked(0)) { all_selected = false; + } track = track->get_next(); } diff --git a/editor/animation_track_editor_plugins.cpp b/editor/animation_track_editor_plugins.cpp index ed64fb2415..9fc67000f9 100644 --- a/editor/animation_track_editor_plugins.cpp +++ b/editor/animation_track_editor_plugins.cpp @@ -60,11 +60,13 @@ void AnimationTrackEditBool::draw_key(int p_index, float p_pixels_sec, int p_x, Vector2 ofs(p_x - icon->get_width() / 2, int(get_size().height - icon->get_height()) / 2); - if (ofs.x + icon->get_width() / 2 < p_clip_left) + if (ofs.x + icon->get_width() / 2 < p_clip_left) { return; + } - if (ofs.x + icon->get_width() / 2 > p_clip_right) + if (ofs.x + icon->get_width() / 2 > p_clip_right) { return; + } draw_texture(icon, ofs); @@ -99,8 +101,9 @@ void AnimationTrackEditColor::draw_key_link(int p_index, float p_pixels_sec, int int x_to = p_next_x - fh / 2 + 1; fh /= 3; - if (x_from > p_clip_right || x_to < p_clip_left) + if (x_from > p_clip_right || x_to < p_clip_left) { return; + } Color color = get_animation()->track_get_key_value(get_track(), p_index); Color color_next = get_animation()->track_get_key_value(get_track(), p_index + 1); @@ -162,8 +165,9 @@ void AnimationTrackEditColor::draw_key(int p_index, float p_pixels_sec, int p_x, void AnimationTrackEditAudio::_preview_changed(ObjectID p_which) { Object *object = ObjectDB::get_instance(id); - if (!object) + if (!object) { return; + } Ref<AudioStream> stream = object->call("get_stream"); @@ -251,11 +255,13 @@ void AnimationTrackEditAudio::draw_key(int p_index, float p_pixels_sec, int p_x, int pixel_begin = p_x; int pixel_end = p_x + pixel_len; - if (pixel_end < p_clip_left) + if (pixel_end < p_clip_left) { return; + } - if (pixel_begin > p_clip_right) + if (pixel_begin > p_clip_right) { return; + } int from_x = MAX(pixel_begin, p_clip_left); int to_x = MIN(pixel_end, p_clip_right); @@ -266,8 +272,9 @@ void AnimationTrackEditAudio::draw_key(int p_index, float p_pixels_sec, int p_x, to_x = MIN(limit_x, to_x); } - if (to_x <= from_x) + if (to_x <= from_x) { return; + } Ref<Font> font = get_theme_font("font", "Label"); float fh = int(font->get_height() * 1.5); @@ -495,11 +502,13 @@ void AnimationTrackEditSpriteFrame::draw_key(int p_index, float p_pixels_sec, in Rect2 rect(p_x, int(get_size().height - height) / 2, width, height); - if (rect.position.x + rect.size.x < p_clip_left) + if (rect.position.x + rect.size.x < p_clip_left) { return; + } - if (rect.position.x > p_clip_right) + if (rect.position.x > p_clip_right) { return; + } Color accent = get_theme_color("accent_color", "Editor"); Color bg = accent; @@ -596,17 +605,20 @@ void AnimationTrackEditSubAnim::draw_key(int p_index, float p_pixels_sec, int p_ int pixel_begin = p_x; int pixel_end = p_x + pixel_len; - if (pixel_end < p_clip_left) + if (pixel_end < p_clip_left) { return; + } - if (pixel_begin > p_clip_right) + if (pixel_begin > p_clip_right) { return; + } int from_x = MAX(pixel_begin, p_clip_left); int to_x = MIN(pixel_end, p_clip_right); - if (to_x <= from_x) + if (to_x <= from_x) { return; + } Ref<Font> font = get_theme_font("font", "Label"); int fh = font->get_height() * 1.5; @@ -634,8 +646,9 @@ void AnimationTrackEditSubAnim::draw_key(int p_index, float p_pixels_sec, int p_ float ofs = animation->track_get_key_time(i, j); int x = p_x + ofs * p_pixels_sec + 2; - if (x < from_x || x >= (to_x - 4)) + if (x < from_x || x >= (to_x - 4)) { continue; + } lines.push_back(Point2(x, y)); lines.push_back(Point2(x + 1, y)); @@ -705,8 +718,9 @@ void AnimationTrackEditVolumeDB::draw_fg(int p_clip_left, int p_clip_right) { } void AnimationTrackEditVolumeDB::draw_key_link(int p_index, float p_pixels_sec, int p_x, int p_next_x, int p_clip_left, int p_clip_right) { - if (p_x > p_clip_right || p_next_x < p_clip_left) + if (p_x > p_clip_right || p_next_x < p_clip_left) { return; + } float db = get_animation()->track_get_key_value(get_track(), p_index); float db_n = get_animation()->track_get_key_value(get_track(), p_index + 1); @@ -809,12 +823,14 @@ void AnimationTrackEditTypeAudio::draw_key(int p_index, float p_pixels_sec, int float ofs_local = -len_resizing_rel / get_timeline()->get_zoom_scale(); if (len_resizing_start) { start_ofs += ofs_local; - if (start_ofs < 0) + if (start_ofs < 0) { start_ofs = 0; + } } else { end_ofs += ofs_local; - if (end_ofs < 0) + if (end_ofs < 0) { end_ofs = 0; + } } } @@ -845,11 +861,13 @@ void AnimationTrackEditTypeAudio::draw_key(int p_index, float p_pixels_sec, int int pixel_begin = p_x; int pixel_end = p_x + pixel_len; - if (pixel_end < p_clip_left) + if (pixel_end < p_clip_left) { return; + } - if (pixel_begin > p_clip_right) + if (pixel_begin > p_clip_right) { return; + } int from_x = MAX(pixel_begin, p_clip_left); int to_x = MIN(pixel_end, p_clip_right); @@ -1152,17 +1170,20 @@ void AnimationTrackEditTypeAnimation::draw_key(int p_index, float p_pixels_sec, int pixel_begin = p_x; int pixel_end = p_x + pixel_len; - if (pixel_end < p_clip_left) + if (pixel_end < p_clip_left) { return; + } - if (pixel_begin > p_clip_right) + if (pixel_begin > p_clip_right) { return; + } int from_x = MAX(pixel_begin, p_clip_left); int to_x = MIN(pixel_end, p_clip_right); - if (to_x <= from_x) + if (to_x <= from_x) { return; + } Ref<Font> font = get_theme_font("font", "Label"); int fh = font->get_height() * 1.5; @@ -1190,8 +1211,9 @@ void AnimationTrackEditTypeAnimation::draw_key(int p_index, float p_pixels_sec, float ofs = animation->track_get_key_time(i, j); int x = p_x + ofs * p_pixels_sec + 2; - if (x < from_x || x >= (to_x - 4)) + if (x < from_x || x >= (to_x - 4)) { continue; + } lines.push_back(Point2(x, y)); lines.push_back(Point2(x + 1, y)); diff --git a/editor/array_property_edit.cpp b/editor/array_property_edit.cpp index 3832a93360..20f947e707 100644 --- a/editor/array_property_edit.cpp +++ b/editor/array_property_edit.cpp @@ -37,8 +37,9 @@ Variant ArrayPropertyEdit::get_array() const { Object *o = ObjectDB::get_instance(obj); - if (!o) + if (!o) { return Array(); + } Variant arr = o->get(property); if (!arr.is_array()) { Callable::CallError ce; @@ -59,8 +60,9 @@ void ArrayPropertyEdit::_set_size(int p_size) { Variant arr = get_array(); arr.call("resize", p_size); Object *o = ObjectDB::get_instance(obj); - if (!o) + if (!o) { return; + } o->set(property, arr); } @@ -69,8 +71,9 @@ void ArrayPropertyEdit::_set_value(int p_idx, const Variant &p_value) { Variant arr = get_array(); arr.set(p_idx, p_value); Object *o = ObjectDB::get_instance(obj); - if (!o) + if (!o) { return; + } o->set(property, arr); } @@ -84,8 +87,9 @@ bool ArrayPropertyEdit::_set(const StringName &p_name, const Variant &p_value) { int size = arr.call("size"); int newsize = p_value; - if (newsize == size) + if (newsize == size) { return true; + } UndoRedo *ur = EditorNode::get_undo_redo(); ur->create_action(TTR("Resize Array")); @@ -184,8 +188,9 @@ bool ArrayPropertyEdit::_get(const StringName &p_name, Variant &r_ret) const { int idx = pn.get_slicec('/', 1).get_slicec('_', 0).to_int(); bool valid; r_ret = arr.get(idx, &valid); - if (valid) + if (valid) { r_ret = r_ret.get_type(); + } return valid; } else { @@ -210,8 +215,9 @@ void ArrayPropertyEdit::_get_property_list(List<PropertyInfo> *p_list) const { p_list->push_back(PropertyInfo(Variant::INT, "array/size", PROPERTY_HINT_RANGE, "0,100000,1")); int pages = size / ITEMS_PER_PAGE; - if (pages > 0) + if (pages > 0) { p_list->push_back(PropertyInfo(Variant::INT, "array/page", PROPERTY_HINT_RANGE, "0," + itos(pages) + ",1")); + } int offset = page * ITEMS_PER_PAGE; @@ -288,8 +294,9 @@ void ArrayPropertyEdit::_bind_methods() { ArrayPropertyEdit::ArrayPropertyEdit() { page = 0; for (int i = 0; i < Variant::VARIANT_MAX; i++) { - if (i > 0) + if (i > 0) { vtypes += ","; + } vtypes += Variant::get_type_name(Variant::Type(i)); } default_type = Variant::NIL; diff --git a/editor/audio_stream_preview.cpp b/editor/audio_stream_preview.cpp index e0d5184aac..9e4e157c96 100644 --- a/editor/audio_stream_preview.cpp +++ b/editor/audio_stream_preview.cpp @@ -37,8 +37,9 @@ float AudioStreamPreview::get_length() const { } float AudioStreamPreview::get_max(float p_time, float p_time_next) const { - if (length == 0) + if (length == 0) { return 0; + } int max = preview.size() / 2; int time_from = p_time / length * max; @@ -63,8 +64,9 @@ float AudioStreamPreview::get_max(float p_time, float p_time_next) const { } float AudioStreamPreview::get_min(float p_time, float p_time_next) const { - if (length == 0) + if (length == 0) { return 0; + } int max = preview.size() / 2; int time_from = p_time / length * max; @@ -194,8 +196,9 @@ Ref<AudioStreamPreview> AudioStreamPreviewGenerator::generate_preview(const Ref< preview->preview->preview = maxmin; preview->preview->length = len_s; - if (preview->playback.is_valid()) + if (preview->playback.is_valid()) { preview->thread = Thread::create(_preview_thread, preview); + } return preview->preview; } diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 381e3f8dfb..3ea970a0f0 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -54,8 +54,9 @@ int GotoLineDialog::get_line() const { } void GotoLineDialog::ok_pressed() { - if (get_line() < 1 || get_line() > text_editor->get_line_count()) + if (get_line() < 1 || get_line() > text_editor->get_line_count()) { return; + } text_editor->unfold_line(get_line() - 1); text_editor->cursor_set_line(get_line() - 1); hide(); @@ -285,14 +286,16 @@ void FindReplaceBar::_get_search_from(int &r_line, int &r_col) { } void FindReplaceBar::_update_results_count() { - if (results_count != -1) + if (results_count != -1) { return; + } results_count = 0; String searched = get_search_text(); - if (searched.empty()) + if (searched.empty()) { return; + } String full_text = text_edit->get_text(); @@ -300,15 +303,18 @@ void FindReplaceBar::_update_results_count() { while (true) { int pos = is_case_sensitive() ? full_text.find(searched, from_pos) : full_text.findn(searched, from_pos); - if (pos == -1) + if (pos == -1) { break; + } if (is_whole_words()) { from_pos++; // Making sure we won't hit the same match next time, if we get out via a continue. - if (pos > 0 && !is_symbol(full_text[pos - 1])) + if (pos > 0 && !is_symbol(full_text[pos - 1])) { continue; - if (pos + searched.length() < full_text.length() && !is_symbol(full_text[pos + searched.length()])) + } + if (pos + searched.length() < full_text.length() && !is_symbol(full_text[pos + searched.length()])) { continue; + } } results_count++; @@ -330,10 +336,12 @@ void FindReplaceBar::_update_matches_label() { bool FindReplaceBar::search_current() { uint32_t flags = 0; - if (is_whole_words()) + if (is_whole_words()) { flags |= TextEdit::SEARCH_WHOLE_WORDS; - if (is_case_sensitive()) + } + if (is_case_sensitive()) { flags |= TextEdit::SEARCH_MATCH_CASE; + } int line, col; _get_search_from(line, col); @@ -342,29 +350,34 @@ bool FindReplaceBar::search_current() { } bool FindReplaceBar::search_prev() { - if (!is_visible()) + if (!is_visible()) { popup_search(true); + } uint32_t flags = 0; String text = get_search_text(); - if (is_whole_words()) + if (is_whole_words()) { flags |= TextEdit::SEARCH_WHOLE_WORDS; - if (is_case_sensitive()) + } + if (is_case_sensitive()) { flags |= TextEdit::SEARCH_MATCH_CASE; + } flags |= TextEdit::SEARCH_BACKWARDS; int line, col; _get_search_from(line, col); - if (text_edit->is_selection_active()) + if (text_edit->is_selection_active()) { col--; // Skip currently selected word. + } col -= text.length(); if (col < 0) { line -= 1; - if (line < 0) + if (line < 0) { line = text_edit->get_line_count() - 1; + } col = text_edit->get_line(line).length(); } @@ -372,20 +385,24 @@ bool FindReplaceBar::search_prev() { } bool FindReplaceBar::search_next() { - if (!is_visible()) + if (!is_visible()) { popup_search(true); + } uint32_t flags = 0; String text; - if (replace_all_mode) + if (replace_all_mode) { text = get_replace_text(); - else + } else { text = get_search_text(); + } - if (is_whole_words()) + if (is_whole_words()) { flags |= TextEdit::SEARCH_WHOLE_WORDS; - if (is_case_sensitive()) + } + if (is_case_sensitive()) { flags |= TextEdit::SEARCH_MATCH_CASE; + } int line, col; _get_search_from(line, col); @@ -394,8 +411,9 @@ bool FindReplaceBar::search_next() { col += text.length(); if (col > text_edit->get_line(line).length()) { line += 1; - if (line >= text_edit->get_line_count()) + if (line >= text_edit->get_line_count()) { line = 0; + } col = 0; } } @@ -404,8 +422,9 @@ bool FindReplaceBar::search_next() { } void FindReplaceBar::_hide_bar() { - if (replace_text->has_focus() || search_text->has_focus()) + if (replace_text->has_focus() || search_text->has_focus()) { text_edit->grab_focus(); + } text_edit->set_search_text(""); result_line = -1; @@ -415,8 +434,9 @@ void FindReplaceBar::_hide_bar() { void FindReplaceBar::_show_search(bool p_focus_replace, bool p_show_only) { show(); - if (p_show_only) + if (p_show_only) { return; + } if (p_focus_replace) { search_text->deselect(); @@ -637,8 +657,9 @@ FindReplaceBar::FindReplaceBar() { // be handled too late if they weren't handled here. void CodeTextEditor::_input(const Ref<InputEvent> &event) { const Ref<InputEventKey> key_event = event; - if (!key_event.is_valid() || !key_event->is_pressed()) + if (!key_event.is_valid() || !key_event->is_pressed()) { return; + } if (ED_IS_SHORTCUT("script_text_editor/move_up", key_event)) { move_lines_up(); @@ -719,8 +740,9 @@ void CodeTextEditor::_zoom_out() { } void CodeTextEditor::_zoom_changed() { - if (font_resize_timer->get_time_left() == 0) + if (font_resize_timer->get_time_left() == 0) { font_resize_timer->start(); + } } void CodeTextEditor::_reset_zoom() { @@ -763,8 +785,9 @@ void CodeTextEditor::_text_changed() { } void CodeTextEditor::_code_complete_timer_timeout() { - if (!is_visible_in_tree()) + if (!is_visible_in_tree()) { return; + } text_editor->query_code_comple(); } @@ -776,8 +799,9 @@ void CodeTextEditor::_complete_request() { if (code_complete_func) { code_complete_func(code_complete_ud, ctext, &entries, forced); } - if (entries.size() == 0) + if (entries.size() == 0) { return; + } for (List<ScriptCodeCompletionOption>::Element *E = entries.front(); E; E = E->next()) { E->get().icon = _get_completion_icon(E->get()); @@ -1035,10 +1059,12 @@ void CodeTextEditor::convert_case(CaseStyle p_case) { for (int i = begin; i <= end; i++) { int len = text_editor->get_line(i).length(); - if (i == end) + if (i == end) { len = end_col; - if (i == begin) + } + if (i == begin) { len -= begin_col; + } String new_line = text_editor->get_line(i).substr(i == begin ? begin_col : 0, len); switch (p_case) { @@ -1076,8 +1102,9 @@ void CodeTextEditor::move_lines_up() { int line_id = i; int next_id = i - 1; - if (line_id == 0 || next_id < 0) + if (line_id == 0 || next_id < 0) { return; + } text_editor->unfold_line(line_id); text_editor->unfold_line(next_id); @@ -1092,8 +1119,9 @@ void CodeTextEditor::move_lines_up() { int line_id = text_editor->cursor_get_line(); int next_id = line_id - 1; - if (line_id == 0 || next_id < 0) + if (line_id == 0 || next_id < 0) { return; + } text_editor->unfold_line(line_id); text_editor->unfold_line(next_id); @@ -1117,8 +1145,9 @@ void CodeTextEditor::move_lines_down() { int line_id = i; int next_id = i + 1; - if (line_id == text_editor->get_line_count() - 1 || next_id > text_editor->get_line_count()) + if (line_id == text_editor->get_line_count() - 1 || next_id > text_editor->get_line_count()) { return; + } text_editor->unfold_line(line_id); text_editor->unfold_line(next_id); @@ -1133,8 +1162,9 @@ void CodeTextEditor::move_lines_down() { int line_id = text_editor->cursor_get_line(); int next_id = line_id + 1; - if (line_id == text_editor->get_line_count() - 1 || next_id > text_editor->get_line_count()) + if (line_id == text_editor->get_line_count() - 1 || next_id > text_editor->get_line_count()) { return; + } text_editor->unfold_line(line_id); text_editor->unfold_line(next_id); @@ -1228,8 +1258,9 @@ void CodeTextEditor::toggle_inline_comment(const String &delimiter) { int end = text_editor->get_selection_to_line(); // End of selection ends on the first column of the last line, ignore it. - if (text_editor->get_selection_to_column() == 0) + if (text_editor->get_selection_to_column() == 0) { end -= 1; + } int col_to = text_editor->get_selection_to_column(); int cursor_pos = text_editor->cursor_get_column(); @@ -1261,14 +1292,17 @@ void CodeTextEditor::toggle_inline_comment(const String &delimiter) { int offset = (is_commented ? -1 : 1) * delimiter.length(); int col_from = text_editor->get_selection_from_column() > 0 ? text_editor->get_selection_from_column() + offset : 0; - if (is_commented && text_editor->cursor_get_column() == text_editor->get_line(text_editor->cursor_get_line()).length() + 1) + if (is_commented && text_editor->cursor_get_column() == text_editor->get_line(text_editor->cursor_get_line()).length() + 1) { cursor_pos += 1; + } - if (text_editor->get_selection_to_column() != 0 && col_to != text_editor->get_line(text_editor->get_selection_to_line()).length() + 1) + if (text_editor->get_selection_to_column() != 0 && col_to != text_editor->get_line(text_editor->get_selection_to_line()).length() + 1) { col_to += offset; + } - if (text_editor->cursor_get_column() != 0) + if (text_editor->cursor_get_column() != 0) { cursor_pos += offset; + } text_editor->select(begin, col_from, text_editor->get_selection_to_line(), col_to); text_editor->cursor_set_column(cursor_pos); @@ -1419,8 +1453,9 @@ void CodeTextEditor::_update_font() { int count = status_bar->get_child_count(); for (int i = 0; i < count; i++) { Control *n = Object::cast_to<Control>(status_bar->get_child(i)); - if (n) + if (n) { n->add_theme_font_override("font", status_bar_font); + } } } @@ -1511,8 +1546,9 @@ void CodeTextEditor::set_warning_nb(int p_warning_nb) { warning_count_label->set_text(itos(p_warning_nb)); warning_count_label->set_visible(p_warning_nb > 0); warning_button->set_visible(p_warning_nb > 0); - if (!p_warning_nb) + if (!p_warning_nb) { _set_show_warnings_panel(false); + } } void CodeTextEditor::toggle_bookmark() { diff --git a/editor/connections_dialog.cpp b/editor/connections_dialog.cpp index 2e47be32ca..62b5911ac1 100644 --- a/editor/connections_dialog.cpp +++ b/editor/connections_dialog.cpp @@ -69,8 +69,9 @@ public: int which = name.get_slice("/", 1).to_int() - 1; ERR_FAIL_INDEX_V(which, params.size(), false); params.write[which] = p_value; - } else + } else { return false; + } return true; } @@ -82,8 +83,9 @@ public: int which = name.get_slice("/", 1).to_int() - 1; ERR_FAIL_INDEX_V(which, params.size(), false); r_ret = params[which]; - } else + } else { return false; + } return true; } @@ -144,8 +146,9 @@ void ConnectDialog::_text_entered(const String &p_text) { void ConnectDialog::_tree_node_selected() { Node *current = tree->get_selected(); - if (!current) + if (!current) { return; + } dst_path = source->get_path_to(current); _update_ok_enabled(); @@ -155,8 +158,9 @@ void ConnectDialog::_tree_node_selected() { * Adds a new parameter bind to connection. */ void ConnectDialog::_add_bind() { - if (cdbinds->params.size() >= VARIANT_ARG_MAX) + if (cdbinds->params.size() >= VARIANT_ARG_MAX) { return; + } Variant::Type vt = (Variant::Type)type_list->get_item_id(type_list->get_selected()); Variant value; @@ -220,8 +224,9 @@ void ConnectDialog::_add_bind() { */ void ConnectDialog::_remove_bind() { String st = bind_editor->get_selected_path(); - if (st == "") + if (st == "") { return; + } int idx = st.get_slice("/", 1).to_int() - 1; ERR_FAIL_INDEX(idx, cdbinds->params.size()); @@ -280,8 +285,9 @@ void ConnectDialog::set_dst_node(Node *p_node) { StringName ConnectDialog::get_dst_method_name() const { String txt = dst_method->get_text(); - if (txt.find("(") != -1) + if (txt.find("(") != -1) { txt = txt.left(txt.find("(")).strip_edges(); + } return txt; } @@ -345,8 +351,9 @@ void ConnectDialog::init(ConnectionData c, bool bEdit) { void ConnectDialog::popup_dialog(const String &p_for_signal) { from_signal->set_text(p_for_signal); error_label->add_theme_color_override("font_color", error_label->get_theme_color("error_color", "Editor")); - if (!advanced->is_pressed()) + if (!advanced->is_pressed()) { error_label->set_visible(!_find_first_script(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root())); + } popup_centered(); } @@ -588,8 +595,9 @@ void ConnectionsDock::_connect(ConnectDialog::ConnectionData cToMake) { Node *source = static_cast<Node *>(cToMake.source); Node *target = static_cast<Node *>(cToMake.target); - if (!source || !target) + if (!source || !target) { return; + } undo_redo->create_action(vformat(TTR("Connect '%s' to '%s'"), String(cToMake.signal), String(cToMake.method))); @@ -633,8 +641,9 @@ void ConnectionsDock::_disconnect(TreeItem &item) { void ConnectionsDock::_disconnect_all() { TreeItem *item = tree->get_selected(); - if (!_is_item_signal(*item)) + if (!_is_item_signal(*item)) { return; + } TreeItem *child = item->get_children(); String signalName = item->get_metadata(0).operator Dictionary()["name"]; @@ -674,8 +683,9 @@ void ConnectionsDock::_tree_item_activated() { // "Activation" on double-click. TreeItem *item = tree->get_selected(); - if (!item) + if (!item) { return; + } if (_is_item_signal(*item)) { _open_connection_dialog(*item); @@ -746,20 +756,23 @@ void ConnectionsDock::_open_connection_dialog(ConnectDialog::ConnectionData cToE * Open slot method location in script editor. */ void ConnectionsDock::_go_to_script(TreeItem &item) { - if (_is_item_signal(item)) + if (_is_item_signal(item)) { return; + } Connection cd = item.get_metadata(0); ConnectDialog::ConnectionData c = cd; ERR_FAIL_COND(c.source != selectedNode); //shouldn't happen but...bugcheck - if (!c.target) + if (!c.target) { return; + } Ref<Script> script = c.target->get_script(); - if (script.is_null()) + if (script.is_null()) { return; + } if (script.is_valid() && ScriptEditor::get_singleton()->script_goto_method(script, c.method)) { editor->call("_editor_select", EditorNode::EDITOR_SCRIPT); @@ -769,8 +782,9 @@ void ConnectionsDock::_go_to_script(TreeItem &item) { void ConnectionsDock::_handle_signal_menu_option(int option) { TreeItem *item = tree->get_selected(); - if (!item) + if (!item) { return; + } switch (option) { case CONNECT: { @@ -787,8 +801,9 @@ void ConnectionsDock::_handle_signal_menu_option(int option) { void ConnectionsDock::_handle_slot_menu_option(int option) { TreeItem *item = tree->get_selected(); - if (!item) + if (!item) { return; + } switch (option) { case EDIT: { @@ -808,8 +823,9 @@ void ConnectionsDock::_handle_slot_menu_option(int option) { void ConnectionsDock::_rmb_pressed(Vector2 position) { TreeItem *item = tree->get_selected(); - if (!item) + if (!item) { return; + } Vector2 global_position = tree->get_global_position() + position; @@ -859,8 +875,9 @@ void ConnectionsDock::set_node(Node *p_node) { void ConnectionsDock::update_tree() { tree->clear(); - if (!selectedNode) + if (!selectedNode) { return; + } TreeItem *root = tree->create_item(); @@ -880,10 +897,11 @@ void ConnectionsDock::update_tree() { Ref<Script> scr = selectedNode->get_script(); if (scr.is_valid()) { scr->get_script_signal_list(&node_signals2); - if (scr->get_path().is_resource_file()) + if (scr->get_path().is_resource_file()) { name = scr->get_path().get_file(); - else + } else { name = scr->get_class(); + } if (has_theme_icon(scr->get_class(), "EditorIcons")) { icon = get_theme_icon(scr->get_class(), "EditorIcons"); @@ -923,8 +941,9 @@ void ConnectionsDock::update_tree() { for (int i = 0; i < mi.arguments.size(); i++) { PropertyInfo &pi = mi.arguments[i]; - if (i > 0) + if (i > 0) { signaldesc += ", "; + } String tname = "var"; if (pi.type == Variant::OBJECT && pi.class_name != StringName()) { tname = pi.class_name.operator String(); @@ -988,24 +1007,29 @@ void ConnectionsDock::update_tree() { for (List<Object::Connection>::Element *F = connections.front(); F; F = F->next()) { Connection cn = F->get(); - if (!(cn.flags & CONNECT_PERSIST)) + if (!(cn.flags & CONNECT_PERSIST)) { continue; + } ConnectDialog::ConnectionData c = cn; Node *target = Object::cast_to<Node>(c.target); - if (!target) + if (!target) { continue; + } String path = String(selectedNode->get_path_to(target)) + " :: " + c.method + "()"; - if (c.flags & CONNECT_DEFERRED) + if (c.flags & CONNECT_DEFERRED) { path += " (deferred)"; - if (c.flags & CONNECT_ONESHOT) + } + if (c.flags & CONNECT_ONESHOT) { path += " (oneshot)"; + } if (c.binds.size()) { path += " binds("; for (int i = 0; i < c.binds.size(); i++) { - if (i > 0) + if (i > 0) { path += ", "; + } path += c.binds[i].operator String(); } path += ")"; diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index 5f693fdbb6..75fff03297 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -132,30 +132,35 @@ void CreateDialog::_sbox_input(const Ref<InputEvent> &p_ie) { } void CreateDialog::add_type(const String &p_type, HashMap<String, TreeItem *> &p_types, TreeItem *p_root, TreeItem **to_select) { - if (p_types.has(p_type)) + if (p_types.has(p_type)) { return; + } bool cpp_type = ClassDB::class_exists(p_type); EditorData &ed = EditorNode::get_editor_data(); - if (p_type == base_type) + if (p_type == base_type) { return; + } if (cpp_type) { - if (!ClassDB::is_parent_class(p_type, base_type)) + if (!ClassDB::is_parent_class(p_type, base_type)) { return; + } } else { if (!search_loaded_scripts.has(p_type)) { search_loaded_scripts[p_type] = ed.script_class_load_script(p_type); } - if (!ScriptServer::is_global_class(p_type) || !ed.script_class_is_parent(p_type, base_type)) + if (!ScriptServer::is_global_class(p_type) || !ed.script_class_is_parent(p_type, base_type)) { return; + } String script_path = ScriptServer::get_global_class_path(p_type); if (script_path.find("res://addons/", 0) != -1) { - if (!EditorNode::get_singleton()->is_addon_plugin_enabled(script_path.get_slicec('/', 3))) + if (!EditorNode::get_singleton()->is_addon_plugin_enabled(script_path.get_slicec('/', 3))) { return; + } } } @@ -168,10 +173,11 @@ void CreateDialog::add_type(const String &p_type, HashMap<String, TreeItem *> &p add_type(inherits, p_types, p_root, to_select); } - if (p_types.has(inherits)) + if (p_types.has(inherits)) { parent = p_types[inherits]; - else if (ScriptServer::is_global_class(inherits)) + } else if (ScriptServer::is_global_class(inherits)) { return; + } } bool can_instance = (cpp_type && ClassDB::can_instance(p_type)) || ScriptServer::is_global_class(p_type); @@ -313,21 +319,25 @@ void CreateDialog::_update_search() { } bool cpp_type = ClassDB::class_exists(type); - if (base_type == "Node" && type.begins_with("Editor")) + if (base_type == "Node" && type.begins_with("Editor")) { continue; // do not show editor nodes + } - if (cpp_type && !ClassDB::can_instance(type)) + if (cpp_type && !ClassDB::can_instance(type)) { continue; // can't create what can't be instanced + } if (cpp_type) { bool skip = false; for (Set<StringName>::Element *E = type_blacklist.front(); E && !skip; E = E->next()) { - if (ClassDB::is_parent_class(type, E->get())) + if (ClassDB::is_parent_class(type, E->get())) { skip = true; + } } - if (skip) + if (skip) { continue; + } } if (search_box->get_text() == "") { @@ -365,17 +375,20 @@ void CreateDialog::_update_search() { for (int i = 0; i < ct.size(); i++) { bool show = search_box->get_text().is_subsequence_ofi(ct[i].name); - if (!show) + if (!show) { continue; + } - if (!search_options_types.has(type)) + if (!search_options_types.has(type)) { add_type(type, search_options_types, root, &to_select); + } TreeItem *ti; - if (search_options_types.has(type)) + if (search_options_types.has(type)) { ti = search_options_types[type]; - else + } else { ti = search_options->get_root(); + } TreeItem *item = search_options->create_item(ti); item->set_metadata(0, type); @@ -407,16 +420,18 @@ void CreateDialog::_update_search() { void CreateDialog::_confirmed() { TreeItem *ti = search_options->get_selected(); - if (!ti) + if (!ti) { return; + } FileAccess *f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("create_recent." + base_type), FileAccess::WRITE); if (f) { f->store_line(get_selected_type()); TreeItem *t = recent->get_root(); - if (t) + if (t) { t = t->get_children(); + } int count = 0; while (t) { if (t->get_text(0) != get_selected_type()) { @@ -463,10 +478,11 @@ void CreateDialog::_notification(int p_what) { void CreateDialog::set_base_type(const String &p_base) { base_type = p_base; - if (is_replace_mode) + if (is_replace_mode) { set_title(vformat(TTR("Change %s Type"), p_base)); - else + } else { set_title(vformat(TTR("Create New %s"), p_base)); + } _update_search(); } @@ -485,10 +501,11 @@ String CreateDialog::get_preferred_search_result_type() { String CreateDialog::get_selected_type() { TreeItem *selected = search_options->get_selected(); - if (selected) + if (selected) { return selected->get_text(0); - else + } else { return String(); + } } Object *CreateDialog::instance_selected() { @@ -498,15 +515,17 @@ Object *CreateDialog::instance_selected() { Variant md = selected->get_metadata(0); String custom; - if (md.get_type() != Variant::NIL) + if (md.get_type() != Variant::NIL) { custom = md; + } if (custom != String()) { if (ScriptServer::is_global_class(custom)) { Object *obj = EditorNode::get_editor_data().script_class_instance(custom); Node *n = Object::cast_to<Node>(obj); - if (n) + if (n) { n->set_name(custom); + } return obj; } return EditorNode::get_editor_data().instance_custom_type(selected->get_text(0), custom); @@ -520,16 +539,18 @@ Object *CreateDialog::instance_selected() { void CreateDialog::_item_selected() { TreeItem *item = search_options->get_selected(); - if (!item) + if (!item) { return; + } String name = item->get_text(0); favorite->set_disabled(false); favorite->set_pressed(favorite_list.find(name) != -1); - if (!EditorHelp::get_doc_data()->class_list.has(name)) + if (!EditorHelp::get_doc_data()->class_list.has(name)) { return; + } help_bit->set_text(DTR(EditorHelp::get_doc_data()->class_list[name].brief_description)); @@ -542,8 +563,9 @@ void CreateDialog::_hide_requested() { void CreateDialog::_favorite_toggled() { TreeItem *item = search_options->get_selected(); - if (!item) + if (!item) { return; + } String name = item->get_text(0); @@ -565,8 +587,9 @@ void CreateDialog::_save_favorite_list() { for (int i = 0; i < favorite_list.size(); i++) { String l = favorite_list[i]; String name = l.split(" ")[0]; - if (!(ClassDB::class_exists(name) || ScriptServer::is_global_class(name))) + if (!(ClassDB::class_exists(name) || ScriptServer::is_global_class(name))) { continue; + } f->store_line(l); } memdelete(f); @@ -579,8 +602,9 @@ void CreateDialog::_update_favorite_list() { for (int i = 0; i < favorite_list.size(); i++) { String l = favorite_list[i]; String name = l.split(" ")[0]; - if (!((ClassDB::class_exists(name) || ScriptServer::is_global_class(name)) && !_is_class_disabled_by_feature_profile(name))) + if (!((ClassDB::class_exists(name) || ScriptServer::is_global_class(name)) && !_is_class_disabled_by_feature_profile(name))) { continue; + } TreeItem *ti = favorites->create_item(root); ti->set_text(0, l); ti->set_icon(0, EditorNode::get_singleton()->get_class_icon(l, base_type)); @@ -590,8 +614,9 @@ void CreateDialog::_update_favorite_list() { void CreateDialog::_history_selected() { TreeItem *item = recent->get_selected(); - if (!item) + if (!item) { return; + } search_box->set_text(item->get_text(0).get_slicec(' ', 0)); favorites->deselect_all(); @@ -600,8 +625,9 @@ void CreateDialog::_history_selected() { void CreateDialog::_favorite_selected() { TreeItem *item = favorites->get_selected(); - if (!item) + if (!item) { return; + } search_box->set_text(item->get_text(0).get_slicec(' ', 0)); recent->deselect_all(); @@ -650,21 +676,24 @@ void CreateDialog::drop_data_fw(const Point2 &p_point, const Variant &p_data, Co Dictionary d = p_data; TreeItem *ti = favorites->get_item_at_position(p_point); - if (!ti) + if (!ti) { return; + } String drop_at = ti->get_text(0); int ds = favorites->get_drop_section_at_position(p_point); int drop_idx = favorite_list.find(drop_at); - if (drop_idx < 0) + if (drop_idx < 0) { return; + } String type = d["class"]; int from_idx = favorite_list.find(type); - if (from_idx < 0) + if (from_idx < 0) { return; + } if (drop_idx == from_idx) { ds = -1; //cause it will be gone diff --git a/editor/debugger/editor_debugger_inspector.cpp b/editor/debugger/editor_debugger_inspector.cpp index 0c5fce91a6..125439d09b 100644 --- a/editor/debugger/editor_debugger_inspector.cpp +++ b/editor/debugger/editor_debugger_inspector.cpp @@ -36,8 +36,9 @@ #include "scene/debugger/scene_debugger.h" bool EditorDebuggerRemoteObject::_set(const StringName &p_name, const Variant &p_value) { - if (!editable || !prop_values.has(p_name) || String(p_name).begins_with("Constants/")) + if (!editable || !prop_values.has(p_name) || String(p_name).begins_with("Constants/")) { return false; + } prop_values[p_name] = p_value; emit_signal("value_edited", remote_object_id, p_name, p_value); @@ -45,8 +46,9 @@ bool EditorDebuggerRemoteObject::_set(const StringName &p_name, const Variant &p } bool EditorDebuggerRemoteObject::_get(const StringName &p_name, Variant &r_ret) const { - if (!prop_values.has(p_name)) + if (!prop_values.has(p_name)) { return false; + } r_ret = prop_values[p_name]; return true; @@ -60,10 +62,11 @@ void EditorDebuggerRemoteObject::_get_property_list(List<PropertyInfo> *p_list) } String EditorDebuggerRemoteObject::get_title() { - if (remote_object_id.is_valid()) + if (remote_object_id.is_valid()) { return TTR("Remote ") + String(type_name) + ": " + itos(remote_object_id); - else + } else { return "<null>"; + } } Variant EditorDebuggerRemoteObject::get_variant(const StringName &p_name) { @@ -211,8 +214,9 @@ void EditorDebuggerInspector::clear_cache() { } Object *EditorDebuggerInspector::get_object(ObjectID p_id) { - if (remote_objects.has(p_id)) + if (remote_objects.has(p_id)) { return remote_objects[p_id]; + } return nullptr; } diff --git a/editor/debugger/editor_debugger_node.cpp b/editor/debugger/editor_debugger_node.cpp index 76d1701372..a9c18138d8 100644 --- a/editor/debugger/editor_debugger_node.cpp +++ b/editor/debugger/editor_debugger_node.cpp @@ -50,8 +50,9 @@ void _for_all(TabContainer *p_node, const Func &p_func) { EditorDebuggerNode *EditorDebuggerNode::singleton = nullptr; EditorDebuggerNode::EditorDebuggerNode() { - if (!singleton) + if (!singleton) { singleton = this; + } add_theme_constant_override("margin_left", -EditorNode::get_singleton()->get_gui_base()->get_theme_stylebox("BottomPanelDebuggerOverride", "EditorStyles")->get_margin(MARGIN_LEFT)); add_theme_constant_override("margin_right", -EditorNode::get_singleton()->get_gui_base()->get_theme_stylebox("BottomPanelDebuggerOverride", "EditorStyles")->get_margin(MARGIN_RIGHT)); @@ -119,8 +120,9 @@ ScriptEditorDebugger *EditorDebuggerNode::_add_debugger() { void EditorDebuggerNode::_stack_frame_selected(int p_debugger) { const ScriptEditorDebugger *dbg = get_debugger(p_debugger); ERR_FAIL_COND(!dbg); - if (dbg != get_current_debugger()) + if (dbg != get_current_debugger()) { return; + } _text_editor_stack_goto(dbg); } @@ -131,8 +133,9 @@ void EditorDebuggerNode::_error_selected(const String &p_file, int p_line, int p void EditorDebuggerNode::_text_editor_stack_goto(const ScriptEditorDebugger *p_debugger) { const String file = p_debugger->get_stack_script_file(); - if (file.empty()) + if (file.empty()) { return; + } stack_script = ResourceLoader::load(file); const int line = p_debugger->get_stack_script_line() - 1; emit_signal("goto_script_line", stack_script, line); @@ -198,13 +201,15 @@ void EditorDebuggerNode::stop() { } // Also close all debugging sessions. _for_all(tabs, [&](ScriptEditorDebugger *dbg) { - if (dbg->is_session_active()) + if (dbg->is_session_active()) { dbg->stop(); + } }); _break_state_changed(); if (hide_on_stop) { - if (is_visible_in_tree()) + if (is_visible_in_tree()) { EditorNode::get_singleton()->hide_bottom_panel(); + } } breakpoints.clear(); set_process(false); @@ -224,8 +229,9 @@ void EditorDebuggerNode::_notification(int p_what) { break; } - if (p_what != NOTIFICATION_PROCESS || !server.is_valid()) + if (p_what != NOTIFICATION_PROCESS || !server.is_valid()) { return; + } if (!server.is_valid() || !server->is_active()) { stop(); @@ -285,8 +291,9 @@ void EditorDebuggerNode::_notification(int p_what) { if (server->is_connection_available()) { ScriptEditorDebugger *debugger = nullptr; _for_all(tabs, [&](ScriptEditorDebugger *dbg) { - if (debugger || dbg->is_session_active()) + if (debugger || dbg->is_session_active()) { return; + } debugger = dbg; }); if (debugger == nullptr) { @@ -325,8 +332,9 @@ void EditorDebuggerNode::_debugger_stopped(int p_id) { bool found = false; _for_all(tabs, [&](ScriptEditorDebugger *p_debugger) { - if (p_debugger->is_session_active()) + if (p_debugger->is_session_active()) { found = true; + } }); if (!found) { EditorNode::get_singleton()->get_pause_button()->set_pressed(false); @@ -340,8 +348,9 @@ void EditorDebuggerNode::_debugger_stopped(int p_id) { void EditorDebuggerNode::_debugger_wants_stop(int p_id) { // Ask editor to kill PID. int pid = get_debugger(p_id)->get_remote_pid(); - if (pid) + if (pid) { EditorNode::get_singleton()->call_deferred("stop_child_process", pid); + } } void EditorDebuggerNode::_debugger_changed(int p_tab) { @@ -380,12 +389,14 @@ void EditorDebuggerNode::set_script_debug_button(MenuButton *p_button) { void EditorDebuggerNode::_break_state_changed() { const bool breaked = get_current_debugger()->is_breaked(); const bool can_debug = get_current_debugger()->is_debuggable(); - if (breaked) // Show debugger. + if (breaked) { // Show debugger. EditorNode::get_singleton()->make_bottom_panel_item_visible(this); + } // Update script menu. - if (!script_menu) + if (!script_menu) { return; + } PopupMenu *p = script_menu->get_popup(); p->set_item_disabled(p->get_item_index(DEBUG_NEXT), !(breaked && can_debug)); p->set_item_disabled(p->get_item_index(DEBUG_STEP), !(breaked && can_debug)); @@ -434,8 +445,9 @@ void EditorDebuggerNode::_paused() { void EditorDebuggerNode::_breaked(bool p_breaked, bool p_can_debug, int p_debugger) { if (get_current_debugger() != get_debugger(p_debugger)) { - if (!p_breaked) + if (!p_breaked) { return; + } tabs->set_current_tab(p_debugger); } _break_state_changed(); @@ -486,58 +498,67 @@ void EditorDebuggerNode::request_remote_tree() { } void EditorDebuggerNode::_remote_tree_updated(int p_debugger) { - if (p_debugger != tabs->get_current_tab()) + if (p_debugger != tabs->get_current_tab()) { return; + } remote_scene_tree->clear(); remote_scene_tree->update_scene_tree(get_current_debugger()->get_remote_tree(), p_debugger); } void EditorDebuggerNode::_remote_object_updated(ObjectID p_id, int p_debugger) { - if (p_debugger != tabs->get_current_tab()) + if (p_debugger != tabs->get_current_tab()) { return; + } if (EditorDebuggerRemoteObject *obj = get_inspected_remote_object()) { - if (obj->remote_object_id == p_id) + if (obj->remote_object_id == p_id) { return; // Already being edited + } } EditorNode::get_singleton()->push_item(get_current_debugger()->get_remote_object(p_id)); } void EditorDebuggerNode::_remote_object_property_updated(ObjectID p_id, const String &p_property, int p_debugger) { - if (p_debugger != tabs->get_current_tab()) + if (p_debugger != tabs->get_current_tab()) { return; + } if (EditorDebuggerRemoteObject *obj = get_inspected_remote_object()) { - if (obj->remote_object_id != p_id) + if (obj->remote_object_id != p_id) { return; + } EditorNode::get_singleton()->get_inspector()->update_property(p_property); } } void EditorDebuggerNode::_remote_object_requested(ObjectID p_id, int p_debugger) { - if (p_debugger != tabs->get_current_tab()) + if (p_debugger != tabs->get_current_tab()) { return; + } inspect_edited_object_timeout = 0.7; // Temporarily disable timeout to avoid multiple requests. get_current_debugger()->request_remote_object(p_id); } void EditorDebuggerNode::_save_node_requested(ObjectID p_id, const String &p_file, int p_debugger) { - if (p_debugger != tabs->get_current_tab()) + if (p_debugger != tabs->get_current_tab()) { return; + } get_current_debugger()->save_node(p_id, p_file); } // Remote inspector/edit. void EditorDebuggerNode::_method_changeds(void *p_ud, Object *p_base, const StringName &p_name, VARIANT_ARG_DECLARE) { - if (!singleton) + if (!singleton) { return; + } _for_all(singleton->tabs, [&](ScriptEditorDebugger *dbg) { dbg->_method_changed(p_base, p_name, VARIANT_ARG_PASS); }); } void EditorDebuggerNode::_property_changeds(void *p_ud, Object *p_base, const StringName &p_property, const Variant &p_value) { - if (!singleton) + if (!singleton) { return; + } _for_all(singleton->tabs, [&](ScriptEditorDebugger *dbg) { dbg->_property_changed(p_base, p_property, p_value); }); diff --git a/editor/debugger/editor_debugger_node.h b/editor/debugger/editor_debugger_node.h index 9138651147..ff9601c026 100644 --- a/editor/debugger/editor_debugger_node.h +++ b/editor/debugger/editor_debugger_node.h @@ -70,8 +70,9 @@ private: int line = 0; bool operator<(const Breakpoint &p_b) const { - if (line == p_b.line) + if (line == p_b.line) { return source < p_b.source; + } return line < p_b.line; } diff --git a/editor/debugger/editor_debugger_tree.cpp b/editor/debugger/editor_debugger_tree.cpp index ecffa0f05d..0b5f865a98 100644 --- a/editor/debugger/editor_debugger_tree.cpp +++ b/editor/debugger/editor_debugger_tree.cpp @@ -84,8 +84,9 @@ void EditorDebuggerTree::_scene_tree_folded(Object *p_obj) { } TreeItem *item = Object::cast_to<TreeItem>(p_obj); - if (!item) + if (!item) { return; + } ObjectID id = ObjectID(uint64_t(item->get_metadata(0))); if (unfold_cache.has(id)) { @@ -97,8 +98,9 @@ void EditorDebuggerTree::_scene_tree_folded(Object *p_obj) { void EditorDebuggerTree::_scene_tree_rmb_selected(const Vector2 &p_position) { TreeItem *item = get_item_at_position(p_position); - if (!item) + if (!item) { return; + } item->select(0); @@ -176,12 +178,14 @@ void EditorDebuggerTree::update_scene_tree(const SceneDebuggerTree *p_tree, int // Apply filters. while (parent) { const bool had_siblings = item->get_prev() || item->get_next(); - if (filter.is_subsequence_ofi(item->get_text(0))) + if (filter.is_subsequence_ofi(item->get_text(0))) { break; // Filter matches, must survive. + } parent->remove_child(item); memdelete(item); - if (had_siblings) + if (had_siblings) { break; // Parent must survive. + } item = parent; parent = item->get_parent(); // Check if parent expects more children. @@ -199,8 +203,9 @@ void EditorDebuggerTree::update_scene_tree(const SceneDebuggerTree *p_tree, int } String EditorDebuggerTree::get_selected_path() { - if (!get_selected()) + if (!get_selected()) { return ""; + } return _get_path(get_selected()); } @@ -256,7 +261,8 @@ void EditorDebuggerTree::_item_menu_id_pressed(int p_option) { } void EditorDebuggerTree::_file_selected(const String &p_file) { - if (inspected_object_id.is_null()) + if (inspected_object_id.is_null()) { return; + } emit_signal("save_node", inspected_object_id, p_file, debugger_id); } diff --git a/editor/debugger/editor_profiler.cpp b/editor/debugger/editor_profiler.cpp index 0b10602c54..8bd21fff5c 100644 --- a/editor/debugger/editor_profiler.cpp +++ b/editor/debugger/editor_profiler.cpp @@ -45,8 +45,9 @@ void EditorProfiler::_make_metric_ptrs(Metric &m) { void EditorProfiler::add_frame_metric(const Metric &p_metric, bool p_final) { ++last_metric; - if (last_metric >= frame_metrics.size()) + if (last_metric >= frame_metrics.size()) { last_metric = 0; + } frame_metrics.write[last_metric] = p_metric; _make_metric_ptrs(frame_metrics.write[last_metric]); @@ -134,19 +135,22 @@ Color EditorProfiler::_get_color_from_signature(const StringName &p_signature) c } void EditorProfiler::_item_edited() { - if (updating_frame) + if (updating_frame) { return; + } TreeItem *item = variables->get_edited(); - if (!item) + if (!item) { return; + } StringName signature = item->get_metadata(0); bool checked = item->is_checked(0); - if (checked) + if (checked) { plot_sigs.insert(signature); - else + } else { plot_sigs.erase(signature); + } if (!frame_delay->is_processing()) { frame_delay->set_wait_time(0.1); @@ -185,8 +189,9 @@ void EditorProfiler::_update_plot() { for (int i = 0; i < frame_metrics.size(); i++) { const Metric &m = frame_metrics[i]; - if (!m.valid) + if (!m.valid) { continue; + } for (Set<StringName>::Element *E = plot_sigs.front(); E; E = E->next()) { const Map<StringName, Metric::Category *>::Element *F = m.category_ptrs.find(E->get()); @@ -228,8 +233,9 @@ void EditorProfiler::_update_plot() { if (next > frame_metrics.size()) { next = frame_metrics.size(); } - if (next == current) + if (next == current) { next = current + 1; //just because for loop must work + } for (Set<StringName>::Element *E = plot_sigs.front(); E; E = E->next()) { int plot_pos = -1; @@ -243,8 +249,9 @@ void EditorProfiler::_update_plot() { //get const Metric &m = frame_metrics[idx]; - if (!m.valid) + if (!m.valid) { continue; //skip because invalid + } float value = 0; @@ -423,13 +430,15 @@ void EditorProfiler::_notification(int p_what) { } void EditorProfiler::_graph_tex_draw() { - if (last_metric < 0) + if (last_metric < 0) { return; + } if (seeking) { int max_frames = frame_metrics.size(); int frame = cursor_metric_edit->get_value() - (frame_metrics[last_metric].frame_number - max_frames + 1); - if (frame < 0) + if (frame < 0) { frame = 0; + } int cur_x = frame * graph->get_size().x / max_frames; @@ -439,8 +448,9 @@ void EditorProfiler::_graph_tex_draw() { if (hover_metric != -1 && frame_metrics[hover_metric].valid) { int max_frames = frame_metrics.size(); int frame = frame_metrics[hover_metric].frame_number - (frame_metrics[last_metric].frame_number - max_frames + 1); - if (frame < 0) + if (frame < 0) { frame = 0; + } int cur_x = frame * graph->get_size().x / max_frames; @@ -454,16 +464,18 @@ void EditorProfiler::_graph_tex_mouse_exit() { } void EditorProfiler::_cursor_metric_changed(double) { - if (updating_frame) + if (updating_frame) { return; + } graph->update(); _update_frame(); } void EditorProfiler::_graph_tex_input(const Ref<InputEvent> &p_ev) { - if (last_metric < 0) + if (last_metric < 0) { return; + } Ref<InputEventMouse> me = p_ev; Ref<InputEventMouseButton> mb = p_ev; @@ -511,12 +523,14 @@ void EditorProfiler::_graph_tex_input(const Ref<InputEvent> &p_ev) { } metric++; - if (metric >= frame_metrics.size()) + if (metric >= frame_metrics.size()) { metric = 0; + } } - if (valid) + if (valid) { cursor_metric_edit->set_value(frame_metrics[metric].frame_number); + } updating_frame = false; @@ -539,10 +553,12 @@ void EditorProfiler::_graph_tex_input(const Ref<InputEvent> &p_ev) { } int EditorProfiler::_get_cursor_index() const { - if (last_metric < 0) + if (last_metric < 0) { return 0; - if (!frame_metrics[last_metric].valid) + } + if (!frame_metrics[last_metric].valid) { return 0; + } int diff = (frame_metrics[last_metric].frame_number - cursor_metric_edit->get_value()); diff --git a/editor/debugger/editor_visual_profiler.cpp b/editor/debugger/editor_visual_profiler.cpp index e1bd00f6f6..81b42da08e 100644 --- a/editor/debugger/editor_visual_profiler.cpp +++ b/editor/debugger/editor_visual_profiler.cpp @@ -36,8 +36,9 @@ void EditorVisualProfiler::add_frame_metric(const Metric &p_metric) { ++last_metric; - if (last_metric >= frame_metrics.size()) + if (last_metric >= frame_metrics.size()) { last_metric = 0; + } frame_metrics.write[last_metric] = p_metric; // _make_metric_ptrs(frame_metrics.write[last_metric]); @@ -130,12 +131,14 @@ Color EditorVisualProfiler::_get_color_from_signature(const StringName &p_signat } void EditorVisualProfiler::_item_selected() { - if (updating_frame) + if (updating_frame) { return; + } TreeItem *item = variables->get_selected(); - if (!item) + if (!item) { return; + } selected_area = item->get_metadata(0); _update_plot(); } @@ -170,8 +173,9 @@ void EditorVisualProfiler::_update_plot() { for (int i = 0; i < frame_metrics.size(); i++) { const Metric &m = frame_metrics[i]; - if (!m.valid) + if (!m.valid) { continue; + } if (m.areas.size()) { highest_cpu = MAX(highest_cpu, m.areas[m.areas.size() - 1].cpu_time); @@ -216,8 +220,9 @@ void EditorVisualProfiler::_update_plot() { if (next > frame_metrics.size()) { next = frame_metrics.size(); } - if (next == current) + if (next == current) { next = current + 1; //just because for loop must work + } for (int j = current; j < next; j++) { //wrap @@ -425,14 +430,16 @@ void EditorVisualProfiler::_notification(int p_what) { } void EditorVisualProfiler::_graph_tex_draw() { - if (last_metric < 0) + if (last_metric < 0) { return; + } Ref<Font> font = get_theme_font("font", "Label"); if (seeking) { int max_frames = frame_metrics.size(); int frame = cursor_metric_edit->get_value() - (frame_metrics[last_metric].frame_number - max_frames + 1); - if (frame < 0) + if (frame < 0) { frame = 0; + } int half_width = graph->get_size().x / 2; int cur_x = frame * half_width / max_frames; @@ -488,16 +495,18 @@ void EditorVisualProfiler::_graph_tex_mouse_exit() { } void EditorVisualProfiler::_cursor_metric_changed(double) { - if (updating_frame) + if (updating_frame) { return; + } graph->update(); _update_frame(); } void EditorVisualProfiler::_graph_tex_input(const Ref<InputEvent> &p_ev) { - if (last_metric < 0) + if (last_metric < 0) { return; + } Ref<InputEventMouse> me = p_ev; Ref<InputEventMouseButton> mb = p_ev; @@ -549,8 +558,9 @@ void EditorVisualProfiler::_graph_tex_input(const Ref<InputEvent> &p_ev) { } metric++; - if (metric >= frame_metrics.size()) + if (metric >= frame_metrics.size()) { metric = 0; + } } if (!valid) { @@ -610,10 +620,12 @@ void EditorVisualProfiler::_graph_tex_input(const Ref<InputEvent> &p_ev) { } int EditorVisualProfiler::_get_cursor_index() const { - if (last_metric < 0) + if (last_metric < 0) { return 0; - if (!frame_metrics[last_metric].valid) + } + if (!frame_metrics[last_metric].valid) { return 0; + } int diff = (frame_metrics[last_metric].frame_number - cursor_metric_edit->get_value()); diff --git a/editor/debugger/script_editor_debugger.cpp b/editor/debugger/script_editor_debugger.cpp index 867eef1c93..49137f76fa 100644 --- a/editor/debugger/script_editor_debugger.cpp +++ b/editor/debugger/script_editor_debugger.cpp @@ -74,17 +74,19 @@ void ScriptEditorDebugger::_put_msg(String p_message, Array p_data) { void ScriptEditorDebugger::debug_copy() { String msg = reason->get_text(); - if (msg == "") + if (msg == "") { return; + } DisplayServer::get_singleton()->clipboard_set(msg); } void ScriptEditorDebugger::debug_skip_breakpoints() { skip_breakpoints_value = !skip_breakpoints_value; - if (skip_breakpoints_value) + if (skip_breakpoints_value) { skip_breakpoints->set_icon(get_theme_icon("DebugSkipBreakpointsOn", "EditorIcons")); - else + } else { skip_breakpoints->set_icon(get_theme_icon("DebugSkipBreakpointsOff", "EditorIcons")); + } Array msg; msg.push_back(skip_breakpoints_value); @@ -115,8 +117,9 @@ void ScriptEditorDebugger::debug_continue() { ERR_FAIL_COND(!breaked); // Allow focus stealing only if we actually run this client for security. - if (remote_pid && EditorNode::get_singleton()->has_child_process(remote_pid)) + if (remote_pid && EditorNode::get_singleton()->has_child_process(remote_pid)) { DisplayServer::get_singleton()->enable_for_stealing_focus(remote_pid); + } _clear_execution(); _put_msg("continue", Array()); @@ -318,8 +321,9 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da _update_buttons_state(); } else if (p_msg == "scene:inspect_object") { ObjectID id = inspector->add_object(p_data); - if (id.is_valid()) + if (id.is_valid()) { emit_signal("remote_object_updated", id); + } } else if (p_msg == "memory:usage") { vmem_tree->clear(); TreeItem *root = vmem_tree->create_item(); @@ -338,8 +342,9 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da it->set_text(3, String::humanize_size(bytes)); total += bytes; - if (has_theme_icon(type, "EditorIcons")) + if (has_theme_icon(type, "EditorIcons")) { it->set_icon(0, get_theme_icon(type, "EditorIcons")); + } } vmem_total->set_tooltip(TTR("Bytes:") + " " + itos(total)); @@ -365,8 +370,9 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da String line = itos(i) + " - " + String(d["file"]) + ":" + itos(d["line"]) + " - at function: " + d["function"]; s->set_text(0, line); - if (i == 0) + if (i == 0) { s->select(0); + } } } else if (p_msg == "stack_frame_vars") { inspector->clear_stack_variables(); @@ -427,8 +433,9 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da perf_items[i]->set_text(1, label); perf_items[i]->set_tooltip(1, tooltip); - if (p[i] > perf_max[i]) + if (p[i] > perf_max[i]) { perf_max.write[i] = p[i]; + } } } perf_history.push_front(p); @@ -493,8 +500,9 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da String error_title; // Include method name, when given, in error title. - if (!oe.source_func.empty()) + if (!oe.source_func.empty()) { error_title += oe.source_func + ": "; + } // If we have a (custom) error message, use it as title, and add a C++ Error // item with the original error condition. error_title += oe.error_descr.empty() ? oe.error : oe.error_descr; @@ -508,16 +516,18 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da cpp_cond->set_text(1, oe.error); cpp_cond->set_text_align(0, TreeItem::ALIGN_LEFT); tooltip += TTR("C++ Error:") + " " + oe.error + "\n"; - if (source_is_project_file) + if (source_is_project_file) { cpp_cond->set_metadata(0, source_meta); + } } Vector<uint8_t> v; v.resize(100); // Source of the error. String source_txt = (source_is_project_file ? oe.source_file.get_file() : oe.source_file) + ":" + itos(oe.source_line); - if (!oe.source_func.empty()) + if (!oe.source_func.empty()) { source_txt += " @ " + oe.source_func + "()"; + } TreeItem *cpp_source = error_tree->create_item(error); cpp_source->set_text(0, "<" + (source_is_project_file ? TTR("Source") : TTR("C++ Source")) + ">"); @@ -554,10 +564,11 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da stack_trace->set_text(1, infos[i].file.get_file() + ":" + itos(infos[i].line) + " @ " + infos[i].func + "()"); } - if (oe.warning) + if (oe.warning) { warning_count++; - else + } else { error_count++; + } } else if (p_msg == "servers:function_signature") { // Cache a profiler signature. @@ -672,10 +683,11 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da metric.categories.push_back(funcs); - if (p_msg == "servers:profile_frame") + if (p_msg == "servers:profile_frame") { profiler->add_frame_metric(metric, false); - else + } else { profiler->add_frame_metric(metric, true); + } } else if (p_msg == "network:profile_frame") { DebuggerMarshalls::NetworkProfilerFrame frame; @@ -719,8 +731,9 @@ void ScriptEditorDebugger::_performance_select() { void ScriptEditorDebugger::_performance_draw() { Vector<int> which; for (int i = 0; i < perf_items.size(); i++) { - if (perf_items[i]->is_checked(0)) + if (perf_items[i]->is_checked(0)) { which.push_back(i); + } } if (which.empty()) { @@ -735,8 +748,9 @@ void ScriptEditorDebugger::_performance_draw() { int cols = Math::ceil(Math::sqrt((float)which.size())); int rows = Math::ceil((float)which.size() / cols); - if (which.size() == 1) + if (which.size() == 1) { rows = 1; + } int margin = 3; int point_sep = 5; @@ -768,13 +782,15 @@ void ScriptEditorDebugger::_performance_draw() { float prev = -1; while (from >= 0 && E) { float m = perf_max[pi]; - if (m == 0) + if (m == 0) { m = 0.00001; + } float h2 = E->get()[pi] / m; h2 = (1.0 - h2) * r.size.y; - if (E != perf_history.front()) + if (E != perf_history.front()) { perf_draw->draw_line(r.position + Point2(from, h2), r.position + Point2(from + spacing, prev), c, Math::round(EDSCALE)); + } prev = h2; E = E->next(); from -= spacing; @@ -851,8 +867,9 @@ void ScriptEditorDebugger::_notification(int p_what) { } _parse_message(arr[0], arr[1]); - if (OS::get_singleton()->get_ticks_msec() > until) + if (OS::get_singleton()->get_ticks_msec() > until) { break; + } } if (!is_session_active()) { _stop_and_notify(); @@ -877,8 +894,9 @@ void ScriptEditorDebugger::_notification(int p_what) { void ScriptEditorDebugger::_clear_execution() { TreeItem *ti = stack_dump->get_selected(); - if (!ti) + if (!ti) { return; + } Dictionary d = ti->get_metadata(0); @@ -983,8 +1001,9 @@ void ScriptEditorDebugger::_profiler_activate(bool p_enable, int p_type) { } void ScriptEditorDebugger::_profiler_seeked() { - if (breaked) + if (breaked) { return; + } debug_break(); } @@ -1010,15 +1029,17 @@ void ScriptEditorDebugger::_export_csv() { } String ScriptEditorDebugger::get_var_value(const String &p_var) const { - if (!breaked) + if (!breaked) { return String(); + } return inspector->get_stack_variable(p_var); } int ScriptEditorDebugger::_get_node_path_cache(const NodePath &p_path) { const int *r = node_path_cache.getptr(p_path); - if (r) + if (r) { return *r; + } last_path_id++; @@ -1034,8 +1055,9 @@ int ScriptEditorDebugger::_get_node_path_cache(const NodePath &p_path) { int ScriptEditorDebugger::_get_res_path_cache(const String &p_path) { Map<String, int>::Element *E = res_path_cache.find(p_path); - if (E) + if (E) { return E->get(); + } last_path_id++; @@ -1049,8 +1071,9 @@ int ScriptEditorDebugger::_get_res_path_cache(const String &p_path) { } void ScriptEditorDebugger::_method_changed(Object *p_base, const StringName &p_name, VARIANT_ARG_DECLARE) { - if (!p_base || !live_debug || !is_session_active() || !editor->get_edited_scene()) + if (!p_base || !live_debug || !is_session_active() || !editor->get_edited_scene()) { return; + } Node *node = Object::cast_to<Node>(p_base); @@ -1058,8 +1081,9 @@ void ScriptEditorDebugger::_method_changed(Object *p_base, const StringName &p_n for (int i = 0; i < VARIANT_ARG_MAX; i++) { //no pointers, sorry - if (argptr[i] && (argptr[i]->get_type() == Variant::OBJECT || argptr[i]->get_type() == Variant::_RID)) + if (argptr[i] && (argptr[i]->get_type() == Variant::OBJECT || argptr[i]->get_type() == Variant::_RID)) { return; + } } if (node) { @@ -1098,8 +1122,9 @@ void ScriptEditorDebugger::_method_changed(Object *p_base, const StringName &p_n } void ScriptEditorDebugger::_property_changed(Object *p_base, const StringName &p_property, const Variant &p_value) { - if (!p_base || !live_debug || !editor->get_edited_scene()) + if (!p_base || !live_debug || !editor->get_edited_scene()) { return; + } Node *node = Object::cast_to<Node>(p_base); @@ -1156,24 +1181,27 @@ void ScriptEditorDebugger::_property_changed(Object *p_base, const StringName &p String ScriptEditorDebugger::get_stack_script_file() const { TreeItem *ti = stack_dump->get_selected(); - if (!ti) + if (!ti) { return ""; + } Dictionary d = ti->get_metadata(0); return d["file"]; } int ScriptEditorDebugger::get_stack_script_line() const { TreeItem *ti = stack_dump->get_selected(); - if (!ti) + if (!ti) { return -1; + } Dictionary d = ti->get_metadata(0); return d["line"]; } int ScriptEditorDebugger::get_stack_script_frame() const { TreeItem *ti = stack_dump->get_selected(); - if (!ti) + if (!ti) { return -1; + } Dictionary d = ti->get_metadata(0); return d["frame"]; } @@ -1183,12 +1211,14 @@ void ScriptEditorDebugger::set_live_debugging(bool p_enable) { } void ScriptEditorDebugger::_live_edit_set() { - if (!is_session_active() || !editor_remote_tree) + if (!is_session_active() || !editor_remote_tree) { return; + } TreeItem *ti = editor_remote_tree->get_selected(); - if (!ti) + if (!ti) { return; + } String path; @@ -1217,10 +1247,11 @@ void ScriptEditorDebugger::update_live_edit_root() { Array msg; msg.push_back(np); - if (editor->get_edited_scene()) + if (editor->get_edited_scene()) { msg.push_back(editor->get_edited_scene()->get_filename()); - else + } else { msg.push_back(""); + } _put_msg("scene:live_set_root", msg); live_edit_root->set_text(np); } @@ -1355,8 +1386,9 @@ void ScriptEditorDebugger::_error_selected() { void ScriptEditorDebugger::_expand_errors_list() { TreeItem *root = error_tree->get_root(); - if (!root) + if (!root) { return; + } TreeItem *item = root->get_children(); while (item) { @@ -1367,8 +1399,9 @@ void ScriptEditorDebugger::_expand_errors_list() { void ScriptEditorDebugger::_collapse_errors_list() { TreeItem *root = error_tree->get_root(); - if (!root) + if (!root) { return; + } TreeItem *item = root->get_children(); while (item) { @@ -1400,8 +1433,9 @@ void ScriptEditorDebugger::_error_tree_item_rmb_selected(const Vector2 &p_pos) { void ScriptEditorDebugger::_item_menu_id_pressed(int p_option) { TreeItem *ti = error_tree->get_selected(); - while (ti->get_parent() != error_tree->get_root()) + while (ti->get_parent() != error_tree->get_root()) { ti = ti->get_parent(); + } String type; diff --git a/editor/dependency_editor.cpp b/editor/dependency_editor.cpp index 9c8a7eaef0..c6977779bd 100644 --- a/editor/dependency_editor.cpp +++ b/editor/dependency_editor.cpp @@ -68,8 +68,9 @@ void DependencyEditor::_fix_and_find(EditorFileSystemDirectory *efsd, Map<String for (int i = 0; i < efsd->get_file_count(); i++) { String file = efsd->get_file(i); - if (!candidates.has(file)) + if (!candidates.has(file)) { continue; + } String path = efsd->get_file_path(i); @@ -113,8 +114,9 @@ void DependencyEditor::_fix_and_find(EditorFileSystemDirectory *efsd, Map<String } void DependencyEditor::_fix_all() { - if (!EditorFileSystem::get_singleton()->get_filesystem()) + if (!EditorFileSystem::get_singleton()->get_filesystem()) { return; + } Map<String, Map<String, String>> candidates; @@ -278,8 +280,9 @@ void DependencyEditorOwners::_file_option(int p_option) { switch (p_option) { case FILE_OPEN: { int idx = owners->get_current(); - if (idx < 0 || idx >= owners->get_item_count()) + if (idx < 0 || idx >= owners->get_item_count()) { break; + } _select_file(idx); } break; } @@ -289,8 +292,9 @@ void DependencyEditorOwners::_bind_methods() { } void DependencyEditorOwners::_fill_owners(EditorFileSystemDirectory *efsd) { - if (!efsd) + if (!efsd) { return; + } for (int i = 0; i < efsd->get_subdir_count(); i++) { _fill_owners(efsd->get_subdir(i)); @@ -305,8 +309,9 @@ void DependencyEditorOwners::_fill_owners(EditorFileSystemDirectory *efsd) { break; } } - if (!found) + if (!found) { continue; + } Ref<Texture2D> icon = EditorNode::get_singleton()->get_class_icon(efsd->get_file_type(i)); @@ -341,8 +346,9 @@ DependencyEditorOwners::DependencyEditorOwners(EditorNode *p_editor) { /////////////////////// void DependencyRemoveDialog::_find_files_in_removed_folder(EditorFileSystemDirectory *efsd, const String &p_folder) { - if (!efsd) + if (!efsd) { return; + } for (int i = 0; i < efsd->get_subdir_count(); ++i) { _find_files_in_removed_folder(efsd->get_subdir(i), p_folder); @@ -355,8 +361,9 @@ void DependencyRemoveDialog::_find_files_in_removed_folder(EditorFileSystemDirec } void DependencyRemoveDialog::_find_all_removed_dependencies(EditorFileSystemDirectory *efsd, Vector<RemovedDependency> &p_removed) { - if (!efsd) + if (!efsd) { return; + } for (int i = 0; i < efsd->get_subdir_count(); i++) { _find_all_removed_dependencies(efsd->get_subdir(i), p_removed); @@ -366,8 +373,9 @@ void DependencyRemoveDialog::_find_all_removed_dependencies(EditorFileSystemDire const String path = efsd->get_file_path(i); //It doesn't matter if a file we are about to delete will have some of its dependencies removed too - if (all_remove_files.has(path)) + if (all_remove_files.has(path)) { continue; + } Vector<String> all_deps = efsd->get_file_deps(i); for (int j = 0; j < all_deps.size(); ++j) { @@ -500,8 +508,9 @@ void DependencyRemoveDialog::ok_pressed() { if (dirs_to_delete.size() == 0) { // If we only deleted files we should only need to tell the file system about the files we touched. - for (int i = 0; i < files_to_delete.size(); ++i) + for (int i = 0; i < files_to_delete.size(); ++i) { EditorFileSystem::get_singleton()->update_file(files_to_delete[i]); + } } else { for (int i = 0; i < dirs_to_delete.size(); ++i) { String path = OS::get_singleton()->get_resource_dir() + dirs_to_delete[i].replace_first("res://", "/"); @@ -523,11 +532,13 @@ void DependencyRemoveDialog::ok_pressed() { for (int i = 0; i < previous_favorites.size(); ++i) { if (previous_favorites[i].ends_with("/")) { - if (dirs_to_delete.find(previous_favorites[i]) < 0) + if (dirs_to_delete.find(previous_favorites[i]) < 0) { new_favorites.push_back(previous_favorites[i]); + } } else { - if (files_to_delete.find(previous_favorites[i]) < 0) + if (files_to_delete.find(previous_favorites[i]) < 0) { new_favorites.push_back(previous_favorites[i]); + } } } @@ -569,8 +580,9 @@ void DependencyErrorDialog::show(Mode p_mode, const String &p_for_file, const Ve String dep; String type = "Object"; dep = report[i].get_slice("::", 0); - if (report[i].get_slice_count("::") > 0) + if (report[i].get_slice_count("::") > 0) { type = report[i].get_slice("::", 1); + } Ref<Texture2D> icon = EditorNode::get_singleton()->get_class_icon(type); @@ -625,16 +637,18 @@ void OrphanResourcesDialog::ok_pressed() { paths.clear(); _find_to_delete(files->get_root(), paths); - if (paths.empty()) + if (paths.empty()) { return; + } delete_confirm->set_text(vformat(TTR("Permanently delete %d item(s)? (No undo!)"), paths.size())); delete_confirm->popup_centered(); } bool OrphanResourcesDialog::_fill_owners(EditorFileSystemDirectory *efsd, HashMap<String, int> &refs, TreeItem *p_parent) { - if (!efsd) + if (!efsd) { return false; + } bool has_children = false; diff --git a/editor/dictionary_property_edit.cpp b/editor/dictionary_property_edit.cpp index c92f62cf58..276cd12ded 100644 --- a/editor/dictionary_property_edit.cpp +++ b/editor/dictionary_property_edit.cpp @@ -47,19 +47,22 @@ void DictionaryPropertyEdit::_set_value(const Variant &p_key, const Variant &p_v Dictionary dict = get_dictionary(); dict[p_key] = p_value; Object *o = ObjectDB::get_instance(obj); - if (!o) + if (!o) { return; + } o->set(property, dict); } Variant DictionaryPropertyEdit::get_dictionary() const { Object *o = ObjectDB::get_instance(obj); - if (!o) + if (!o) { return Dictionary(); + } Variant dict = o->get(property); - if (dict.get_type() != Variant::DICTIONARY) + if (dict.get_type() != Variant::DICTIONARY) { return Dictionary(); + } return dict; } @@ -89,8 +92,9 @@ void DictionaryPropertyEdit::edit(Object *p_obj, const StringName &p_prop) { Node *DictionaryPropertyEdit::get_node() { Object *o = ObjectDB::get_instance(obj); - if (!o) + if (!o) { return nullptr; + } return cast_to<Node>(o); } diff --git a/editor/doc_data.cpp b/editor/doc_data.cpp index d45c9f5ff5..53641da0e9 100644 --- a/editor/doc_data.cpp +++ b/editor/doc_data.cpp @@ -47,8 +47,9 @@ void DocData::merge_from(const DocData &p_data) { for (Map<String, ClassDoc>::Element *E = class_list.front(); E; E = E->next()) { ClassDoc &c = E->get(); - if (!p_data.class_list.has(c.name)) + if (!p_data.class_list.has(c.name)) { continue; + } const ClassDoc &cf = p_data.class_list[c.name]; @@ -60,32 +61,39 @@ void DocData::merge_from(const DocData &p_data) { MethodDoc &m = c.methods.write[i]; for (int j = 0; j < cf.methods.size(); j++) { - if (cf.methods[j].name != m.name) + if (cf.methods[j].name != m.name) { continue; - if (cf.methods[j].arguments.size() != m.arguments.size()) + } + if (cf.methods[j].arguments.size() != m.arguments.size()) { continue; + } // since polymorphic functions are allowed we need to check the type of // the arguments so we make sure they are different. int arg_count = cf.methods[j].arguments.size(); Vector<bool> arg_used; arg_used.resize(arg_count); - for (int l = 0; l < arg_count; ++l) + for (int l = 0; l < arg_count; ++l) { arg_used.write[l] = false; + } // also there is no guarantee that argument ordering will match, so we // have to check one by one so we make sure we have an exact match for (int k = 0; k < arg_count; ++k) { - for (int l = 0; l < arg_count; ++l) + for (int l = 0; l < arg_count; ++l) { if (cf.methods[j].arguments[k].type == m.arguments[l].type && !arg_used[l]) { arg_used.write[l] = true; break; } + } } bool not_the_same = false; - for (int l = 0; l < arg_count; ++l) - if (!arg_used[l]) // at least one of the arguments was different + for (int l = 0; l < arg_count; ++l) { + if (!arg_used[l]) { // at least one of the arguments was different not_the_same = true; - if (not_the_same) + } + } + if (not_the_same) { continue; + } const MethodDoc &mf = cf.methods[j]; @@ -98,8 +106,9 @@ void DocData::merge_from(const DocData &p_data) { MethodDoc &m = c.signals.write[i]; for (int j = 0; j < cf.signals.size(); j++) { - if (cf.signals[j].name != m.name) + if (cf.signals[j].name != m.name) { continue; + } const MethodDoc &mf = cf.signals[j]; m.description = mf.description; @@ -111,8 +120,9 @@ void DocData::merge_from(const DocData &p_data) { ConstantDoc &m = c.constants.write[i]; for (int j = 0; j < cf.constants.size(); j++) { - if (cf.constants[j].name != m.name) + if (cf.constants[j].name != m.name) { continue; + } const ConstantDoc &mf = cf.constants[j]; m.description = mf.description; @@ -124,8 +134,9 @@ void DocData::merge_from(const DocData &p_data) { PropertyDoc &p = c.properties.write[i]; for (int j = 0; j < cf.properties.size(); j++) { - if (cf.properties[j].name != p.name) + if (cf.properties[j].name != p.name) { continue; + } const PropertyDoc &pf = cf.properties[j]; p.description = pf.description; @@ -137,8 +148,9 @@ void DocData::merge_from(const DocData &p_data) { PropertyDoc &p = c.theme_properties.write[i]; for (int j = 0; j < cf.theme_properties.size(); j++) { - if (cf.theme_properties[j].name != p.name) + if (cf.theme_properties[j].name != p.name) { continue; + } const PropertyDoc &pf = cf.theme_properties[j]; p.description = pf.description; @@ -167,16 +179,18 @@ void DocData::merge_from(const DocData &p_data) { void DocData::remove_from(const DocData &p_data) { for (Map<String, ClassDoc>::Element *E = p_data.class_list.front(); E; E = E->next()) { - if (class_list.has(E->key())) + if (class_list.has(E->key())) { class_list.erase(E->key()); + } } } static void return_doc_from_retinfo(DocData::MethodDoc &p_method, const PropertyInfo &p_retinfo) { if (p_retinfo.type == Variant::INT && p_retinfo.usage & PROPERTY_USAGE_CLASS_IS_ENUM) { p_method.return_enum = p_retinfo.class_name; - if (p_method.return_enum.begins_with("_")) //proxy class + if (p_method.return_enum.begins_with("_")) { //proxy class p_method.return_enum = p_method.return_enum.substr(1, p_method.return_enum.length()); + } p_method.return_type = "int"; } else if (p_retinfo.class_name != StringName()) { p_method.return_type = p_retinfo.class_name; @@ -198,8 +212,9 @@ static void argument_doc_from_arginfo(DocData::ArgumentDoc &p_argument, const Pr if (p_arginfo.type == Variant::INT && p_arginfo.usage & PROPERTY_USAGE_CLASS_IS_ENUM) { p_argument.enumeration = p_arginfo.class_name; - if (p_argument.enumeration.begins_with("_")) //proxy class + if (p_argument.enumeration.begins_with("_")) { //proxy class p_argument.enumeration = p_argument.enumeration.substr(1, p_argument.enumeration.length()); + } p_argument.type = "int"; } else if (p_arginfo.class_name != StringName()) { p_argument.type = p_arginfo.class_name; @@ -228,8 +243,9 @@ static Variant get_documentation_default_value(const StringName &p_class_name, c for (List<StringName>::Element *E2 = inheriting_classes.front(); E2; E2 = E2->next()) { if (ClassDB::can_instance(E2->get())) { default_value = ClassDB::class_get_default_property_value(E2->get(), p_property_name, &r_default_value_valid); - if (r_default_value_valid) + if (r_default_value_valid) { break; + } } } } @@ -257,8 +273,9 @@ void DocData::generate(bool p_basic_types) { } String cname = name; - if (cname.begins_with("_")) //proxy class + if (cname.begins_with("_")) { //proxy class cname = cname.substr(1, name.length()); + } class_list[cname] = ClassDoc(); ClassDoc &c = class_list[cname]; @@ -284,8 +301,9 @@ void DocData::generate(bool p_basic_types) { EO = EO->next(); } - if (E->get().usage & PROPERTY_USAGE_GROUP || E->get().usage & PROPERTY_USAGE_SUBGROUP || E->get().usage & PROPERTY_USAGE_CATEGORY || E->get().usage & PROPERTY_USAGE_INTERNAL) + if (E->get().usage & PROPERTY_USAGE_GROUP || E->get().usage & PROPERTY_USAGE_SUBGROUP || E->get().usage & PROPERTY_USAGE_CATEGORY || E->get().usage & PROPERTY_USAGE_INTERNAL) { continue; + } PropertyDoc prop; @@ -312,8 +330,9 @@ void DocData::generate(bool p_basic_types) { if (inherited) { bool base_default_value_valid = false; Variant base_default_value = get_documentation_default_value(ClassDB::get_parent_class(name), E->get().name, base_default_value_valid); - if (!default_value_valid || !base_default_value_valid || default_value == base_default_value) + if (!default_value_valid || !base_default_value_valid || default_value == base_default_value) { continue; + } } } @@ -362,10 +381,11 @@ void DocData::generate(bool p_basic_types) { } if (!found_type) { - if (E->get().type == Variant::OBJECT && E->get().hint == PROPERTY_HINT_RESOURCE_TYPE) + if (E->get().type == Variant::OBJECT && E->get().hint == PROPERTY_HINT_RESOURCE_TYPE) { prop.type = E->get().hint_string; - else + } else { prop.type = Variant::get_type_name(E->get().type); + } } c.properties.push_back(prop); @@ -376,8 +396,9 @@ void DocData::generate(bool p_basic_types) { method_list.sort(); for (List<MethodInfo>::Element *E = method_list.front(); E; E = E->next()) { - if (E->get().name == "" || (E->get().name[0] == '_' && !(E->get().flags & METHOD_FLAG_VIRTUAL))) + if (E->get().name == "" || (E->get().name[0] == '_' && !(E->get().flags & METHOD_FLAG_VIRTUAL))) { continue; //hidden, don't count + } if (skip_setter_getter_methods && setters_getters.has(E->get().name)) { // Don't skip parametric setters and getters, i.e. method which require @@ -392,16 +413,19 @@ void DocData::generate(bool p_basic_types) { method.name = E->get().name; - if (E->get().flags & METHOD_FLAG_VIRTUAL) + if (E->get().flags & METHOD_FLAG_VIRTUAL) { method.qualifiers = "virtual"; + } if (E->get().flags & METHOD_FLAG_CONST) { - if (method.qualifiers != "") + if (method.qualifiers != "") { method.qualifiers += " "; + } method.qualifiers += "const"; } else if (E->get().flags & METHOD_FLAG_VARARG) { - if (method.qualifiers != "") + if (method.qualifiers != "") { method.qualifiers += " "; + } method.qualifiers += "vararg"; } @@ -516,15 +540,18 @@ void DocData::generate(bool p_basic_types) { class_list["Variant"].name = "Variant"; } - if (!p_basic_types) + if (!p_basic_types) { return; + } // Add Variant types. for (int i = 0; i < Variant::VARIANT_MAX; i++) { - if (i == Variant::NIL) + if (i == Variant::NIL) { continue; // Not exposed outside of 'null', should not be in class list. - if (i == Variant::OBJECT) + } + if (i == Variant::OBJECT) { continue; // Use the core type instead. + } String cname = Variant::get_type_name(Variant::Type(i)); @@ -564,8 +591,9 @@ void DocData::generate(bool p_basic_types) { return_doc_from_retinfo(method, mi.return_val); if (mi.flags & METHOD_FLAG_VARARG) { - if (method.qualifiers != "") + if (method.qualifiers != "") { method.qualifiers += " "; + } method.qualifiers += "vararg"; } @@ -624,10 +652,12 @@ void DocData::generate(bool p_basic_types) { } pd.name = s.name; pd.type = s.ptr->get_class(); - while (String(ClassDB::get_parent_class(pd.type)) != "Object") + while (String(ClassDB::get_parent_class(pd.type)) != "Object") { pd.type = ClassDB::get_parent_class(pd.type); - if (pd.type.begins_with("_")) + } + if (pd.type.begins_with("_")) { pd.type = pd.type.substr(1, pd.type.length()); + } c.properties.push_back(pd); } } @@ -652,8 +682,9 @@ void DocData::generate(bool p_basic_types) { md.name = mi.name; if (mi.flags & METHOD_FLAG_VARARG) { - if (md.qualifiers != "") + if (md.qualifiers != "") { md.qualifiers += " "; + } md.qualifiers += "vararg"; } @@ -698,8 +729,9 @@ static Error _parse_methods(Ref<XMLParser> &parser, Vector<DocData::MethodDoc> & DocData::MethodDoc method; ERR_FAIL_COND_V(!parser->has_attribute("name"), ERR_FILE_CORRUPT); method.name = parser->get_attribute_value("name"); - if (parser->has_attribute("qualifiers")) + if (parser->has_attribute("qualifiers")) { method.qualifiers = parser->get_attribute_value("qualifiers"); + } while (parser->read() == OK) { if (parser->get_node_type() == XMLParser::NODE_ELEMENT) { @@ -724,12 +756,14 @@ static Error _parse_methods(Ref<XMLParser> &parser, Vector<DocData::MethodDoc> & } else if (name == "description") { parser->read(); - if (parser->get_node_type() == XMLParser::NODE_TEXT) + if (parser->get_node_type() == XMLParser::NODE_TEXT) { method.description = parser->get_node_data(); + } } - } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == element) + } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == element) { break; + } } methods.push_back(method); @@ -738,8 +772,9 @@ static Error _parse_methods(Ref<XMLParser> &parser, Vector<DocData::MethodDoc> & ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + parser->get_node_name() + "."); } - } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == section) + } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == section) { break; + } } return OK; @@ -759,8 +794,9 @@ Error DocData::load_classes(const String &p_dir) { if (!da->current_is_dir() && path.ends_with("xml")) { Ref<XMLParser> parser = memnew(XMLParser); Error err2 = parser->open(p_dir.plus_file(path)); - if (err2) + if (err2) { return err2; + } _load(parser); } @@ -808,8 +844,9 @@ Error DocData::_load(Ref<XMLParser> parser) { parser->skip_section(); } - if (parser->get_node_type() != XMLParser::NODE_ELEMENT) + if (parser->get_node_type() != XMLParser::NODE_ELEMENT) { continue; //no idea what this may be, but skipping anyway + } ERR_FAIL_COND_V(parser->get_node_name() != "class", ERR_FILE_CORRUPT); @@ -819,8 +856,9 @@ Error DocData::_load(Ref<XMLParser> parser) { ClassDoc &c = class_list[name]; c.name = name; - if (parser->has_attribute("inherits")) + if (parser->has_attribute("inherits")) { c.inherits = parser->get_attribute_value("inherits"); + } while (parser->read() == OK) { if (parser->get_node_type() == XMLParser::NODE_ELEMENT) { @@ -828,13 +866,15 @@ Error DocData::_load(Ref<XMLParser> parser) { if (name2 == "brief_description") { parser->read(); - if (parser->get_node_type() == XMLParser::NODE_TEXT) + if (parser->get_node_type() == XMLParser::NODE_TEXT) { c.brief_description = parser->get_node_data(); + } } else if (name2 == "description") { parser->read(); - if (parser->get_node_type() == XMLParser::NODE_TEXT) + if (parser->get_node_type() == XMLParser::NODE_TEXT) { c.description = parser->get_node_data(); + } } else if (name2 == "tutorials") { while (parser->read() == OK) { if (parser->get_node_type() == XMLParser::NODE_ELEMENT) { @@ -842,13 +882,15 @@ Error DocData::_load(Ref<XMLParser> parser) { if (name3 == "link") { parser->read(); - if (parser->get_node_type() == XMLParser::NODE_TEXT) + if (parser->get_node_type() == XMLParser::NODE_TEXT) { c.tutorials.push_back(parser->get_node_data().strip_edges()); + } } else { ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + "."); } - } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "tutorials") + } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "tutorials") { break; // End of <tutorials>. + } } } else if (name2 == "methods") { Error err2 = _parse_methods(parser, c.methods); @@ -869,24 +911,29 @@ Error DocData::_load(Ref<XMLParser> parser) { prop2.name = parser->get_attribute_value("name"); ERR_FAIL_COND_V(!parser->has_attribute("type"), ERR_FILE_CORRUPT); prop2.type = parser->get_attribute_value("type"); - if (parser->has_attribute("setter")) + if (parser->has_attribute("setter")) { prop2.setter = parser->get_attribute_value("setter"); - if (parser->has_attribute("getter")) + } + if (parser->has_attribute("getter")) { prop2.getter = parser->get_attribute_value("getter"); - if (parser->has_attribute("enum")) + } + if (parser->has_attribute("enum")) { prop2.enumeration = parser->get_attribute_value("enum"); + } if (!parser->is_empty()) { parser->read(); - if (parser->get_node_type() == XMLParser::NODE_TEXT) + if (parser->get_node_type() == XMLParser::NODE_TEXT) { prop2.description = parser->get_node_data(); + } } c.properties.push_back(prop2); } else { ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + "."); } - } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "members") + } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "members") { break; // End of <members>. + } } } else if (name2 == "theme_items") { @@ -903,16 +950,18 @@ Error DocData::_load(Ref<XMLParser> parser) { prop2.type = parser->get_attribute_value("type"); if (!parser->is_empty()) { parser->read(); - if (parser->get_node_type() == XMLParser::NODE_TEXT) + if (parser->get_node_type() == XMLParser::NODE_TEXT) { prop2.description = parser->get_node_data(); + } } c.theme_properties.push_back(prop2); } else { ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + "."); } - } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "theme_items") + } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "theme_items") { break; // End of <theme_items>. + } } } else if (name2 == "constants") { @@ -931,24 +980,27 @@ Error DocData::_load(Ref<XMLParser> parser) { } if (!parser->is_empty()) { parser->read(); - if (parser->get_node_type() == XMLParser::NODE_TEXT) + if (parser->get_node_type() == XMLParser::NODE_TEXT) { constant2.description = parser->get_node_data(); + } } c.constants.push_back(constant2); } else { ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + "."); } - } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "constants") + } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "constants") { break; // End of <constants>. + } } } else { ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name2 + "."); } - } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "class") + } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "class") { break; // End of <class>. + } } } @@ -956,11 +1008,13 @@ Error DocData::_load(Ref<XMLParser> parser) { } static void _write_string(FileAccess *f, int p_tablevel, const String &p_string) { - if (p_string == "") + if (p_string == "") { return; + } String tab; - for (int i = 0; i < p_tablevel; i++) + for (int i = 0; i < p_tablevel; i++) { tab += "\t"; + } f->store_string(tab + p_string + "\n"); } @@ -984,8 +1038,9 @@ Error DocData::save_classes(const String &p_default_path, const Map<String, Stri _write_string(f, 0, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); String header = "<class name=\"" + c.name + "\""; - if (c.inherits != "") + if (c.inherits != "") { header += " inherits=\"" + c.inherits + "\""; + } header += String(" version=\"") + VERSION_BRANCH + "\""; header += ">"; _write_string(f, 0, header); @@ -1012,8 +1067,9 @@ Error DocData::save_classes(const String &p_default_path, const Map<String, Stri const MethodDoc &m = c.methods[i]; String qualifiers; - if (m.qualifiers != "") + if (m.qualifiers != "") { qualifiers += " qualifiers=\"" + m.qualifiers.xml_escape() + "\""; + } _write_string(f, 2, "<method name=\"" + m.name + "\"" + qualifiers + ">"); @@ -1034,10 +1090,11 @@ Error DocData::save_classes(const String &p_default_path, const Map<String, Stri enum_text = " enum=\"" + a.enumeration + "\""; } - if (a.default_value != "") + if (a.default_value != "") { _write_string(f, 3, "<argument index=\"" + itos(j) + "\" name=\"" + a.name.xml_escape() + "\" type=\"" + a.type.xml_escape() + "\"" + enum_text + " default=\"" + a.default_value.xml_escape(true) + "\">"); - else + } else { _write_string(f, 3, "<argument index=\"" + itos(j) + "\" name=\"" + a.name.xml_escape() + "\" type=\"" + a.type.xml_escape() + "\"" + enum_text + ">"); + } _write_string(f, 3, "</argument>"); } @@ -1123,10 +1180,11 @@ Error DocData::save_classes(const String &p_default_path, const Map<String, Stri for (int i = 0; i < c.theme_properties.size(); i++) { const PropertyDoc &p = c.theme_properties[i]; - if (p.default_value != "") + if (p.default_value != "") { _write_string(f, 2, "<theme_item name=\"" + p.name + "\" type=\"" + p.type + "\" default=\"" + p.default_value.xml_escape(true) + "\">"); - else + } else { _write_string(f, 2, "<theme_item name=\"" + p.name + "\" type=\"" + p.type + "\">"); + } _write_string(f, 3, p.description.strip_edges().xml_escape()); @@ -1149,8 +1207,9 @@ Error DocData::load_compressed(const uint8_t *p_data, int p_compressed_size, int Ref<XMLParser> parser = memnew(XMLParser); Error err = parser->open_buffer(data); - if (err) + if (err) { return err; + } _load(parser); diff --git a/editor/editor_about.cpp b/editor/editor_about.cpp index a41444a27f..d99726c57c 100644 --- a/editor/editor_about.cpp +++ b/editor/editor_about.cpp @@ -123,8 +123,9 @@ EditorAbout::EditorAbout() { hbc->add_child(_logo); String hash = String(VERSION_HASH); - if (hash.length() != 0) + if (hash.length() != 0) { hash = "." + hash.left(9); + } Label *about_text = memnew(Label); about_text->set_v_size_flags(Control::SIZE_SHRINK_CENTER); diff --git a/editor/editor_asset_installer.cpp b/editor/editor_asset_installer.cpp index 9b05826e92..b43ee0e245 100644 --- a/editor/editor_asset_installer.cpp +++ b/editor/editor_asset_installer.cpp @@ -55,12 +55,14 @@ void EditorAssetInstaller::_update_subitems(TreeItem *p_item, bool p_check, bool } void EditorAssetInstaller::_item_edited() { - if (updating) + if (updating) { return; + } TreeItem *item = tree->get_edited(); - if (!item) + if (!item) { return; + } String path = item->get_metadata(0); @@ -145,8 +147,9 @@ void EditorAssetInstaller::open(const String &p_path, int p_depth) { depth--; } - if (skip || path == String()) + if (skip || path == String()) { continue; + } bool isdir = false; @@ -285,11 +288,13 @@ void EditorAssetInstaller::ok_pressed() { } msg += failed_files[i]; } - if (EditorNode::get_singleton() != nullptr) + if (EditorNode::get_singleton() != nullptr) { EditorNode::get_singleton()->show_warning(msg); + } } else { - if (EditorNode::get_singleton() != nullptr) + if (EditorNode::get_singleton() != nullptr) { EditorNode::get_singleton()->show_warning(TTR("Package installed successfully!"), TTR("Success!")); + } } EditorFileSystem::get_singleton()->scan_changes(); } diff --git a/editor/editor_atlas_packer.cpp b/editor/editor_atlas_packer.cpp index 469a6c6de1..68abeb2cda 100644 --- a/editor/editor_atlas_packer.cpp +++ b/editor/editor_atlas_packer.cpp @@ -73,10 +73,11 @@ void EditorAtlasPacker::_plot_triangle(Ref<BitMap> p_bitmap, Vector2i *vertices) } } xf += dx_far; - if (yi < y[1]) + if (yi < y[1]) { xt += dx_upper; - else + } else { xt += dx_low; + } } } @@ -158,11 +159,13 @@ void EditorAtlasPacker::chart_pack(Vector<Chart> &charts, int &r_width, int &r_h for (int lx = x - 1; lx < x + 2 && !found_pixel; lx++) { for (int ly = y - 1; ly < y + 2 && !found_pixel; ly++) { int px = lx - 1; - if (px < 0 || px >= w) + if (px < 0 || px >= w) { continue; + } int py = ly - 1; - if (py < 0 || py >= h) + if (py < 0 || py >= h) { continue; + } if (src_bitmap->get_bit(Vector2(px, py))) { found_pixel = true; diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp index 1114ae9bb5..f8dec13a5c 100644 --- a/editor/editor_audio_buses.cpp +++ b/editor/editor_audio_buses.cpp @@ -207,8 +207,9 @@ void EditorAudioBus::update_send() { } void EditorAudioBus::update_bus() { - if (updating_bus) + if (updating_bus) { return; + } updating_bus = true; @@ -217,8 +218,9 @@ void EditorAudioBus::update_bus() { float db_value = AudioServer::get_singleton()->get_bus_volume_db(index); slider->set_value(_scaled_db_to_normalized_volume(db_value)); track_name->set_text(AudioServer::get_singleton()->get_bus_name(index)); - if (is_master) + if (is_master) { track_name->set_editable(false); + } solo->set_pressed(AudioServer::get_singleton()->is_bus_solo(index)); mute->set_pressed(AudioServer::get_singleton()->is_bus_mute(index)); @@ -250,8 +252,9 @@ void EditorAudioBus::update_bus() { } void EditorAudioBus::_name_changed(const String &p_new_name) { - if (p_new_name == AudioServer::get_singleton()->get_bus_name(get_index())) + if (p_new_name == AudioServer::get_singleton()->get_bus_name(get_index())) { return; + } String attempt = p_new_name; int attempts = 1; @@ -301,8 +304,9 @@ void EditorAudioBus::_name_changed(const String &p_new_name) { } void EditorAudioBus::_volume_changed(float p_normalized) { - if (updating_bus) + if (updating_bus) { return; + } updating_bus = true; @@ -454,8 +458,9 @@ void EditorAudioBus::_send_selected(int p_which) { void EditorAudioBus::_effect_selected() { TreeItem *effect = effects->get_selected(); - if (!effect) + if (!effect) { return; + } updating_bus = true; if (effect->get_metadata(0) != Variant()) { @@ -470,12 +475,14 @@ void EditorAudioBus::_effect_selected() { } void EditorAudioBus::_effect_edited() { - if (updating_bus) + if (updating_bus) { return; + } TreeItem *effect = effects->get_edited(); - if (!effect) + if (!effect) { return; + } if (effect->get_metadata(0) == Variant()) { Rect2 area = effects->get_item_rect(effect); @@ -500,8 +507,9 @@ void EditorAudioBus::_effect_edited() { } void EditorAudioBus::_effect_add(int p_which) { - if (updating_bus) + if (updating_bus) { return; + } StringName name = effect_options->get_item_metadata(p_which); @@ -617,12 +625,14 @@ Variant EditorAudioBus::get_drag_data_fw(const Point2 &p_point, Control *p_from) bool EditorAudioBus::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"]) != "audio_bus_effect") + if (!d.has("type") || String(d["type"]) != "audio_bus_effect") { return false; + } TreeItem *item = effects->get_item_at_position(p_point); - if (!item) + if (!item) { return false; + } effects->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN); @@ -633,8 +643,9 @@ void EditorAudioBus::drop_data_fw(const Point2 &p_point, const Variant &p_data, Dictionary d = p_data; TreeItem *item = effects->get_item_at_position(p_point); - if (!item) + if (!item) { return; + } int pos = effects->get_drop_section_at_position(p_point); Variant md = item->get_metadata(0); @@ -644,8 +655,9 @@ void EditorAudioBus::drop_data_fw(const Point2 &p_point, const Variant &p_data, if (md.get_type() == Variant::INT) { paste_at = md; - if (pos > 0) + if (pos > 0) { paste_at++; + } if (bus == get_index() && paste_at > effect) { paste_at--; @@ -688,11 +700,13 @@ void EditorAudioBus::drop_data_fw(const Point2 &p_point, const Variant &p_data, void EditorAudioBus::_delete_effect_pressed(int p_option) { TreeItem *item = effects->get_selected(); - if (!item) + if (!item) { return; + } - if (item->get_metadata(0).get_type() != Variant::INT) + if (item->get_metadata(0).get_type() != Variant::INT) { return; + } int index = item->get_metadata(0); @@ -708,11 +722,13 @@ void EditorAudioBus::_delete_effect_pressed(int p_option) { void EditorAudioBus::_effect_rmb(const Vector2 &p_pos) { TreeItem *item = effects->get_selected(); - if (!item) + if (!item) { return; + } - if (item->get_metadata(0).get_type() != Variant::INT) + if (item->get_metadata(0).get_type() != Variant::INT) { return; + } delete_effect_popup->set_position(get_global_mouse_position()); delete_effect_popup->popup(); @@ -889,8 +905,9 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) { ClassDB::get_inheriters_from_class("AudioEffect", &effects); effects.sort_custom<StringName::AlphCompare>(); for (List<StringName>::Element *E = effects.front(); E; E = E->next()) { - if (!ClassDB::can_instance(E->get())) + if (!ClassDB::can_instance(E->get())) { continue; + } Ref<Texture2D> icon = EditorNode::get_singleton()->get_class_icon(E->get()); String name = E->get().operator String().replace("AudioEffect", ""); @@ -1031,8 +1048,9 @@ void EditorAudioBuses::_add_bus() { } void EditorAudioBuses::_update_bus(int p_index) { - if (p_index >= bus_hb->get_child_count()) + if (p_index >= bus_hb->get_child_count()) { return; + } bus_hb->get_child(p_index)->call("update_bus"); } diff --git a/editor/editor_autoload_settings.cpp b/editor/editor_autoload_settings.cpp index 1132cda415..200ae7045f 100644 --- a/editor/editor_autoload_settings.cpp +++ b/editor/editor_autoload_settings.cpp @@ -64,23 +64,26 @@ void EditorAutoloadSettings::_notification(int p_what) { bool EditorAutoloadSettings::_autoload_name_is_valid(const String &p_name, String *r_error) { if (!p_name.is_valid_identifier()) { - if (r_error) + if (r_error) { *r_error = TTR("Invalid name.") + "\n" + TTR("Valid characters:") + " a-z, A-Z, 0-9 or _"; + } return false; } if (ClassDB::class_exists(p_name)) { - if (r_error) + if (r_error) { *r_error = TTR("Invalid name.") + "\n" + TTR("Must not collide with an existing engine class name."); + } return false; } for (int i = 0; i < Variant::VARIANT_MAX; i++) { if (Variant::get_type_name(Variant::Type(i)) == p_name) { - if (r_error) + if (r_error) { *r_error = TTR("Invalid name.") + "\n" + TTR("Must not collide with an existing built-in type name."); + } return false; } @@ -88,8 +91,9 @@ bool EditorAutoloadSettings::_autoload_name_is_valid(const String &p_name, Strin for (int i = 0; i < GlobalConstants::get_global_constant_count(); i++) { if (GlobalConstants::get_global_constant_name(i) == p_name) { - if (r_error) + if (r_error) { *r_error = TTR("Invalid name.") + "\n" + TTR("Must not collide with an existing global constant name."); + } return false; } @@ -100,8 +104,9 @@ bool EditorAutoloadSettings::_autoload_name_is_valid(const String &p_name, Strin ScriptServer::get_language(i)->get_reserved_words(&keywords); for (List<String>::Element *E = keywords.front(); E; E = E->next()) { if (E->get() == p_name) { - if (r_error) + if (r_error) { *r_error = TTR("Invalid name.") + "\n" + TTR("Keyword cannot be used as an autoload name."); + } return false; } @@ -112,8 +117,9 @@ bool EditorAutoloadSettings::_autoload_name_is_valid(const String &p_name, Strin } void EditorAutoloadSettings::_autoload_add() { - if (autoload_add(autoload_add_name->get_text(), autoload_add_path->get_text())) + if (autoload_add(autoload_add_name->get_text(), autoload_add_path->get_text())) { autoload_add_path->set_text(""); + } autoload_add_name->set_text(""); add_autoload->set_disabled(true); @@ -122,15 +128,17 @@ void EditorAutoloadSettings::_autoload_add() { void EditorAutoloadSettings::_autoload_selected() { TreeItem *ti = tree->get_selected(); - if (!ti) + if (!ti) { return; + } selected_autoload = "autoload/" + ti->get_text(0); } void EditorAutoloadSettings::_autoload_edited() { - if (updating_autoload) + if (updating_autoload) { return; + } TreeItem *ti = tree->get_edited(); int column = tree->get_edited_column(); @@ -141,8 +149,9 @@ void EditorAutoloadSettings::_autoload_edited() { String name = ti->get_text(0); String old_name = selected_autoload.get_slice("/", 1); - if (name == old_name) + if (name == old_name) { return; + } String error; if (!_autoload_name_is_valid(name, &error)) { @@ -192,12 +201,14 @@ void EditorAutoloadSettings::_autoload_edited() { int order = ProjectSettings::get_singleton()->get_order(base); String path = ProjectSettings::get_singleton()->get(base); - if (path.begins_with("*")) + if (path.begins_with("*")) { path = path.substr(1, path.length()); + } // Singleton autoloads are represented with a leading "*" in their path. - if (checked) + if (checked) { path = "*" + path; + } undo_redo->create_action(TTR("Toggle AutoLoad Globals")); @@ -240,8 +251,9 @@ void EditorAutoloadSettings::_autoload_button_pressed(Object *p_item, int p_colu swap = ti->get_next(); } - if (!swap) + if (!swap) { return; + } String swap_name = "autoload/" + swap->get_text(0); @@ -288,8 +300,9 @@ void EditorAutoloadSettings::_autoload_button_pressed(Object *p_item, int p_colu void EditorAutoloadSettings::_autoload_activated() { TreeItem *ti = tree->get_selected(); - if (!ti) + if (!ti) { return; + } _autoload_open(ti->get_text(1)); } @@ -357,8 +370,9 @@ Node *EditorAutoloadSettings::_create_autoload(const String &p_path) { } void EditorAutoloadSettings::update_autoload() { - if (updating_autoload) + if (updating_autoload) { return; + } updating_autoload = true; @@ -381,14 +395,16 @@ void EditorAutoloadSettings::update_autoload() { for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { const PropertyInfo &pi = E->get(); - if (!pi.name.begins_with("autoload/")) + if (!pi.name.begins_with("autoload/")) { continue; + } String name = pi.name.get_slice("/", 1); String path = ProjectSettings::get_singleton()->get(pi.name); - if (name.empty()) + if (name.empty()) { continue; + } AutoLoadInfo info; info.is_singleton = path.begins_with("*"); @@ -502,8 +518,9 @@ void EditorAutoloadSettings::update_autoload() { } Variant EditorAutoloadSettings::get_drag_data_fw(const Point2 &p_point, Control *p_control) { - if (autoload_cache.size() <= 1) + if (autoload_cache.size() <= 1) { return false; + } PackedStringArray autoloads; @@ -514,8 +531,9 @@ Variant EditorAutoloadSettings::get_drag_data_fw(const Point2 &p_point, Control next = tree->get_next_selected(next); } - if (autoloads.size() == 0 || autoloads.size() == autoload_cache.size()) + if (autoloads.size() == 0 || autoloads.size() == autoload_cache.size()) { return Variant(); + } VBoxContainer *preview = memnew(VBoxContainer); @@ -539,19 +557,22 @@ Variant EditorAutoloadSettings::get_drag_data_fw(const Point2 &p_point, Control } bool EditorAutoloadSettings::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_control) const { - if (updating_autoload) + if (updating_autoload) { return false; + } Dictionary drop_data = p_data; - if (!drop_data.has("type")) + if (!drop_data.has("type")) { return false; + } if (drop_data.has("type")) { TreeItem *ti = tree->get_item_at_position(p_point); - if (!ti) + if (!ti) { return false; + } int section = tree->get_drop_section_at_position(p_point); @@ -564,13 +585,15 @@ bool EditorAutoloadSettings::can_drop_data_fw(const Point2 &p_point, const Varia void EditorAutoloadSettings::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_control) { TreeItem *ti = tree->get_item_at_position(p_point); - if (!ti) + if (!ti) { return; + } int section = tree->get_drop_section_at_position(p_point); - if (section < -1) + if (section < -1) { return; + } String name; bool move_to_back = false; @@ -736,14 +759,16 @@ EditorAutoloadSettings::EditorAutoloadSettings() { for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { const PropertyInfo &pi = E->get(); - if (!pi.name.begins_with("autoload/")) + if (!pi.name.begins_with("autoload/")) { continue; + } String name = pi.name.get_slice("/", 1); String path = ProjectSettings::get_singleton()->get(pi.name); - if (name.empty()) + if (name.empty()) { continue; + } AutoLoadInfo info; info.is_singleton = path.begins_with("*"); diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp index 45c44a3a2b..130c330f5a 100644 --- a/editor/editor_data.cpp +++ b/editor/editor_data.cpp @@ -43,16 +43,19 @@ void EditorHistory::cleanup_history() { bool fail = false; for (int j = 0; j < history[i].path.size(); j++) { - if (!history[i].path[j].ref.is_null()) + if (!history[i].path[j].ref.is_null()) { continue; + } Object *obj = ObjectDB::get_instance(history[i].path[j].object); if (obj) { Node *n = Object::cast_to<Node>(obj); - if (n && n->is_inside_tree()) + if (n && n->is_inside_tree()) { continue; - if (!n) // Possibly still alive + } + if (!n) { // Possibly still alive continue; + } } if (j <= history[i].level) { @@ -72,8 +75,9 @@ void EditorHistory::cleanup_history() { } } - if (current >= history.size()) + if (current >= history.size()) { current = history.size() - 1; + } } void EditorHistory::_add_object(ObjectID p_object, const String &p_property, int p_level_change, bool p_inspector_only) { @@ -81,8 +85,9 @@ void EditorHistory::_add_object(ObjectID p_object, const String &p_property, int ERR_FAIL_COND(!obj); Reference *r = Object::cast_to<Reference>(obj); Obj o; - if (r) + if (r) { o.ref = REF(r); + } o.object = p_object; o.property = p_property; o.inspector_only = p_inspector_only; @@ -165,10 +170,11 @@ bool EditorHistory::is_at_end() const { bool EditorHistory::next() { cleanup_history(); - if ((current + 1) < history.size()) + if ((current + 1) < history.size()) { current++; - else + } else { return false; + } return true; } @@ -176,60 +182,68 @@ bool EditorHistory::next() { bool EditorHistory::previous() { cleanup_history(); - if (current > 0) + if (current > 0) { current--; - else + } else { return false; + } return true; } bool EditorHistory::is_current_inspector_only() const { - if (current < 0 || current >= history.size()) + if (current < 0 || current >= history.size()) { return false; + } const History &h = history[current]; return h.path[h.level].inspector_only; } ObjectID EditorHistory::get_current() { - if (current < 0 || current >= history.size()) + if (current < 0 || current >= history.size()) { return ObjectID(); + } History &h = history.write[current]; Object *obj = ObjectDB::get_instance(h.path[h.level].object); - if (!obj) + if (!obj) { return ObjectID(); + } return obj->get_instance_id(); } int EditorHistory::get_path_size() const { - if (current < 0 || current >= history.size()) + if (current < 0 || current >= history.size()) { return 0; + } const History &h = history[current]; return h.path.size(); } ObjectID EditorHistory::get_path_object(int p_index) const { - if (current < 0 || current >= history.size()) + if (current < 0 || current >= history.size()) { return ObjectID(); + } const History &h = history[current]; ERR_FAIL_INDEX_V(p_index, h.path.size(), ObjectID()); Object *obj = ObjectDB::get_instance(h.path[p_index].object); - if (!obj) + if (!obj) { return ObjectID(); + } return obj->get_instance_id(); } String EditorHistory::get_path_property(int p_index) const { - if (current < 0 || current >= history.size()) + if (current < 0 || current >= history.size()) { return ""; + } const History &h = history[current]; @@ -249,8 +263,9 @@ EditorHistory::EditorHistory() { EditorPlugin *EditorData::get_editor(Object *p_object) { for (int i = 0; i < editor_plugins.size(); i++) { - if (editor_plugins[i]->has_main_screen() && editor_plugins[i]->handles(p_object)) + if (editor_plugins[i]->has_main_screen() && editor_plugins[i]->handles(p_object)) { return editor_plugins[i]; + } } return nullptr; @@ -258,8 +273,9 @@ EditorPlugin *EditorData::get_editor(Object *p_object) { EditorPlugin *EditorData::get_subeditor(Object *p_object) { for (int i = 0; i < editor_plugins.size(); i++) { - if (!editor_plugins[i]->has_main_screen() && editor_plugins[i]->handles(p_object)) + if (!editor_plugins[i]->has_main_screen() && editor_plugins[i]->handles(p_object)) { return editor_plugins[i]; + } } return nullptr; @@ -277,8 +293,9 @@ Vector<EditorPlugin *> EditorData::get_subeditors(Object *p_object) { EditorPlugin *EditorData::get_editor(String p_name) { for (int i = 0; i < editor_plugins.size(); i++) { - if (editor_plugins[i]->get_name() == p_name) + if (editor_plugins[i]->get_name() == p_name) { return editor_plugins[i]; + } } return nullptr; @@ -291,8 +308,9 @@ void EditorData::copy_object_params(Object *p_object) { p_object->get_property_list(&pinfo); for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_EDITOR) || E->get().name == "script" || E->get().name == "scripts") + if (!(E->get().usage & PROPERTY_USAGE_EDITOR) || E->get().name == "script" || E->get().name == "scripts") { continue; + } PropertyData pd; pd.name = E->get().name; @@ -311,8 +329,9 @@ Dictionary EditorData::get_editor_states() const { Dictionary metadata; for (int i = 0; i < editor_plugins.size(); i++) { Dictionary state = editor_plugins[i]->get_state(); - if (state.empty()) + if (state.empty()) { continue; + } metadata[editor_plugins[i]->get_name()] = state; } @@ -340,8 +359,9 @@ void EditorData::set_editor_states(const Dictionary &p_states) { } } - if (idx == -1) + if (idx == -1) { continue; + } editor_plugins[idx]->set_state(p_states[name]); } } @@ -481,8 +501,9 @@ void EditorData::remove_custom_type(const String &p_type) { } int EditorData::add_edited_scene(int p_at_pos) { - if (p_at_pos < 0) + if (p_at_pos < 0) { p_at_pos = edited_scene.size(); + } EditedScene es; es.root = nullptr; es.path = String(); @@ -490,13 +511,15 @@ int EditorData::add_edited_scene(int p_at_pos) { es.version = 0; es.live_edit_root = NodePath(String("/root")); - if (p_at_pos == edited_scene.size()) + if (p_at_pos == edited_scene.size()) { edited_scene.push_back(es); - else + } else { edited_scene.insert(p_at_pos, es); + } - if (current_edited_scene < 0) + if (current_edited_scene < 0) { current_edited_scene = 0; + } return p_at_pos; } @@ -516,9 +539,9 @@ void EditorData::remove_scene(int p_idx) { memdelete(edited_scene[p_idx].root); } - if (current_edited_scene > p_idx) + if (current_edited_scene > p_idx) { current_edited_scene--; - else if (current_edited_scene == p_idx && current_edited_scene > 0) { + } else if (current_edited_scene == p_idx && current_edited_scene > 0) { current_edited_scene--; } @@ -554,8 +577,9 @@ bool EditorData::_find_updated_instances(Node *p_root, Node *p_node, Set<String> for (int i = 0; i < p_node->get_child_count(); i++) { bool found = _find_updated_instances(p_root, p_node->get_child(i), checked_paths); - if (found) + if (found) { return true; + } } return false; @@ -563,8 +587,9 @@ bool EditorData::_find_updated_instances(Node *p_root, Node *p_node, Set<String> bool EditorData::check_and_update_scene(int p_idx) { ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), false); - if (!edited_scene[p_idx].root) + if (!edited_scene[p_idx].root) { return false; + } Set<String> checked_scenes; @@ -588,16 +613,18 @@ bool EditorData::check_and_update_scene(int p_idx) { for (List<Node *>::Element *E = edited_scene.write[p_idx].selection.front(); E; E = E->next()) { NodePath p = edited_scene[p_idx].root->get_path_to(E->get()); Node *new_node = new_scene->get_node(p); - if (new_node) + if (new_node) { new_selection.push_back(new_node); + } } new_scene->set_filename(edited_scene[p_idx].root->get_filename()); memdelete(edited_scene[p_idx].root); edited_scene.write[p_idx].root = new_scene; - if (new_scene->get_filename() != "") + if (new_scene->get_filename() != "") { edited_scene.write[p_idx].path = new_scene->get_filename(); + } edited_scene.write[p_idx].selection = new_selection; return true; @@ -630,10 +657,11 @@ void EditorData::set_edited_scene_root(Node *p_root) { ERR_FAIL_INDEX(current_edited_scene, edited_scene.size()); edited_scene.write[current_edited_scene].root = p_root; if (p_root) { - if (p_root->get_filename() != "") + if (p_root->get_filename() != "") { edited_scene.write[current_edited_scene].path = p_root->get_filename(); - else + } else { p_root->set_filename(edited_scene[current_edited_scene].path); + } } } @@ -673,8 +701,9 @@ uint64_t EditorData::get_scene_version(int p_idx) const { String EditorData::get_scene_type(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), String()); - if (!edited_scene[p_idx].root) + if (!edited_scene[p_idx].root) { return ""; + } return edited_scene[p_idx].root->get_class(); } @@ -690,8 +719,9 @@ void EditorData::move_edited_scene_to_index(int p_idx) { Ref<Script> EditorData::get_scene_root_script(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), Ref<Script>()); - if (!edited_scene[p_idx].root) + if (!edited_scene[p_idx].root) { return Ref<Script>(); + } Ref<Script> s = edited_scene[p_idx].root->get_script(); if (!s.is_valid() && edited_scene[p_idx].root->get_child_count()) { Node *n = edited_scene[p_idx].root->get_child(0); @@ -705,10 +735,12 @@ Ref<Script> EditorData::get_scene_root_script(int p_idx) const { String EditorData::get_scene_title(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), String()); - if (!edited_scene[p_idx].root) + if (!edited_scene[p_idx].root) { return TTR("[empty]"); - if (edited_scene[p_idx].root->get_filename() == "") + } + if (edited_scene[p_idx].root->get_filename() == "") { return TTR("[unsaved]"); + } bool show_ext = EDITOR_DEF("interface/scene_tabs/show_extension", false); String name = edited_scene[p_idx].root->get_filename().get_file(); if (!show_ext) { @@ -721,8 +753,9 @@ void EditorData::set_scene_path(int p_idx, const String &p_path) { ERR_FAIL_INDEX(p_idx, edited_scene.size()); edited_scene.write[p_idx].path = p_path; - if (!edited_scene[p_idx].root) + if (!edited_scene[p_idx].root) { return; + } edited_scene[p_idx].root->set_filename(p_path); } @@ -730,10 +763,11 @@ String EditorData::get_scene_path(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), String()); if (edited_scene[p_idx].root) { - if (edited_scene[p_idx].root->get_filename() == "") + if (edited_scene[p_idx].root->get_filename() == "") { edited_scene[p_idx].root->set_filename(edited_scene[p_idx].path); - else + } else { return edited_scene[p_idx].root->get_filename(); + } } return edited_scene[p_idx].path; @@ -801,8 +835,9 @@ void EditorData::get_plugin_window_layout(Ref<ConfigFile> p_layout) { } bool EditorData::script_class_is_parent(const String &p_class, const String &p_inherits) { - if (!ScriptServer::is_global_class(p_class)) + if (!ScriptServer::is_global_class(p_class)) { return false; + } String base = script_class_get_base(p_class); Ref<Script> script = script_class_load_script(p_class); Ref<Script> base_script = script->get_base_script(); @@ -823,8 +858,9 @@ bool EditorData::script_class_is_parent(const String &p_class, const String &p_i StringName EditorData::script_class_get_base(const String &p_class) const { Ref<Script> script = script_class_load_script(p_class); - if (script.is_null()) + if (script.is_null()) { return StringName(); + } Ref<Script> base_script = script->get_base_script(); if (base_script.is_null()) { @@ -839,8 +875,9 @@ Object *EditorData::script_class_instance(const String &p_class) { Object *obj = ClassDB::instance(ScriptServer::get_global_class_native_base(p_class)); if (obj) { Ref<Script> script = script_class_load_script(p_class); - if (script.is_valid()) + if (script.is_valid()) { obj->set_script(script); + } return obj; } } @@ -848,8 +885,9 @@ Object *EditorData::script_class_instance(const String &p_class) { } Ref<Script> EditorData::script_class_load_script(const String &p_class) const { - if (!ScriptServer::is_global_class(p_class)) + if (!ScriptServer::is_global_class(p_class)) { return Ref<Script>(); + } String path = ScriptServer::get_global_class_path(p_class); return ResourceLoader::load(path, "Script"); @@ -860,15 +898,17 @@ void EditorData::script_class_set_icon_path(const String &p_class, const String } String EditorData::script_class_get_icon_path(const String &p_class) const { - if (!ScriptServer::is_global_class(p_class)) + if (!ScriptServer::is_global_class(p_class)) { return String(); + } String current = p_class; String ret = _script_class_icon_paths[current]; while (ret.empty()) { current = script_class_get_base(current); - if (!ScriptServer::is_global_class(current)) + if (!ScriptServer::is_global_class(current)) { return String(); + } ret = _script_class_icon_paths.has(current) ? _script_class_icon_paths[current] : String(); } @@ -889,8 +929,9 @@ void EditorData::script_class_save_icon_paths() { Dictionary d; for (List<StringName>::Element *E = keys.front(); E; E = E->next()) { - if (ScriptServer::is_global_class(E->get())) + if (ScriptServer::is_global_class(E->get())) { d[E->get()] = _script_class_icon_paths[E->get()]; + } } ProjectSettings::get_singleton()->set("_global_script_class_icons", d); @@ -924,12 +965,14 @@ EditorData::EditorData() { /////////// void EditorSelection::_node_removed(Node *p_node) { - if (!selection.has(p_node)) + if (!selection.has(p_node)) { return; + } Object *meta = selection[p_node]; - if (meta) + if (meta) { memdelete(meta); + } selection.erase(p_node); changed = true; nl_changed = true; @@ -938,8 +981,9 @@ void EditorSelection::_node_removed(Node *p_node) { void EditorSelection::add_node(Node *p_node) { ERR_FAIL_NULL(p_node); ERR_FAIL_COND(!p_node->is_inside_tree()); - if (selection.has(p_node)) + if (selection.has(p_node)) { return; + } changed = true; nl_changed = true; @@ -960,14 +1004,16 @@ void EditorSelection::add_node(Node *p_node) { void EditorSelection::remove_node(Node *p_node) { ERR_FAIL_NULL(p_node); - if (!selection.has(p_node)) + if (!selection.has(p_node)) { return; + } changed = true; nl_changed = true; Object *meta = selection[p_node]; - if (meta) + if (meta) { memdelete(meta); + } selection.erase(p_node); p_node->disconnect("tree_exiting", callable_mp(this, &EditorSelection::_node_removed)); //emit_signal("selection_changed"); @@ -1012,8 +1058,9 @@ void EditorSelection::add_editor_plugin(Object *p_object) { } void EditorSelection::_update_nl() { - if (!nl_changed) + if (!nl_changed) { return; + } selected_node_list.clear(); @@ -1029,8 +1076,9 @@ void EditorSelection::_update_nl() { parent = parent->get_parent(); } - if (skip) + if (skip) { continue; + } selected_node_list.push_back(E->key()); } @@ -1040,8 +1088,9 @@ void EditorSelection::_update_nl() { void EditorSelection::update() { _update_nl(); - if (!changed) + if (!changed) { return; + } changed = false; if (!emitted) { emitted = true; @@ -1055,10 +1104,11 @@ void EditorSelection::_emit_change() { } List<Node *> &EditorSelection::get_selected_node_list() { - if (changed) + if (changed) { update(); - else + } else { _update_nl(); + } return selected_node_list; } diff --git a/editor/editor_data.h b/editor/editor_data.h index 1dd2214e53..8083dde09c 100644 --- a/editor/editor_data.h +++ b/editor/editor_data.h @@ -256,8 +256,9 @@ public: template <class T> T *get_node_editor_data(Node *p_node) { - if (!selection.has(p_node)) + if (!selection.has(p_node)) { return nullptr; + } return Object::cast_to<T>(selection[p_node]); } diff --git a/editor/editor_dir_dialog.cpp b/editor/editor_dir_dialog.cpp index 3039c3adb5..3c1c3c8a86 100644 --- a/editor/editor_dir_dialog.cpp +++ b/editor/editor_dir_dialog.cpp @@ -107,13 +107,15 @@ void EditorDirDialog::_notification(int p_what) { void EditorDirDialog::_item_collapsed(Object *p_item) { TreeItem *item = Object::cast_to<TreeItem>(p_item); - if (updating) + if (updating) { return; + } - if (item->is_collapsed()) + if (item->is_collapsed()) { opened_paths.erase(item->get_metadata(0)); - else + } else { opened_paths.insert(item->get_metadata(0)); + } } void EditorDirDialog::_item_activated() { @@ -122,8 +124,9 @@ void EditorDirDialog::_item_activated() { void EditorDirDialog::ok_pressed() { TreeItem *ti = tree->get_selected(); - if (!ti) + if (!ti) { return; + } String dir = ti->get_metadata(0); emit_signal("dir_selected", dir); @@ -144,8 +147,9 @@ void EditorDirDialog::_make_dir() { void EditorDirDialog::_make_dir_confirm() { TreeItem *ti = tree->get_selected(); - if (!ti) + if (!ti) { return; + } String dir = ti->get_metadata(0); diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp index 46740a0f6d..87ca499413 100644 --- a/editor/editor_export.cpp +++ b/editor/editor_export.cpp @@ -173,10 +173,11 @@ bool EditorExportPreset::has_export_file(const String &p_path) { } void EditorExportPreset::add_patch(const String &p_path, int p_at_pos) { - if (p_at_pos < 0) + if (p_at_pos < 0) { patches.push_back(p_path); - else + } else { patches.insert(p_at_pos, p_path); + } EditorExport::singleton->save_presets(); } @@ -233,8 +234,9 @@ void EditorExportPlatform::gen_debug_flags(Vector<String> &r_flags, int p_flags) String host = EditorSettings::get_singleton()->get("network/debug/remote_host"); int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port"); - if (p_flags & DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST) + if (p_flags & DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST) { host = "localhost"; + } if (p_flags & DEBUG_FLAG_DUMB_CLIENT) { int port = EditorSettings::get_singleton()->get("filesystem/file_server/port"); @@ -260,8 +262,9 @@ void EditorExportPlatform::gen_debug_flags(Vector<String> &r_flags, int p_flags) String bpoints; for (const List<String>::Element *E = breakpoints.front(); E; E = E->next()) { bpoints += E->get().replace(" ", "%20"); - if (E->next()) + if (E->next()) { bpoints += ","; + } } r_flags.push_back(bpoints); @@ -389,16 +392,18 @@ void EditorExportPlatform::_export_find_resources(EditorFileSystemDirectory *p_d } void EditorExportPlatform::_export_find_dependencies(const String &p_path, Set<String> &p_paths) { - if (p_paths.has(p_path)) + if (p_paths.has(p_path)) { return; + } p_paths.insert(p_path); EditorFileSystemDirectory *dir; int file_idx; dir = EditorFileSystem::get_singleton()->find_file(p_path, &file_idx); - if (!dir) + if (!dir) { return; + } Vector<String> deps = dir->get_file_deps(file_idx); @@ -410,16 +415,17 @@ void EditorExportPlatform::_export_find_dependencies(const String &p_path, Set<S void EditorExportPlatform::_edit_files_with_filter(DirAccess *da, const Vector<String> &p_filters, Set<String> &r_list, bool exclude) { da->list_dir_begin(); String cur_dir = da->get_current_dir().replace("\\", "/"); - if (!cur_dir.ends_with("/")) + if (!cur_dir.ends_with("/")) { cur_dir += "/"; + } String cur_dir_no_prefix = cur_dir.replace("res://", ""); Vector<String> dirs; String f; while ((f = da->get_next()) != "") { - if (da->current_is_dir()) + if (da->current_is_dir()) { dirs.push_back(f); - else { + } else { String fullpath = cur_dir + f; // Test also against path without res:// so that filters like `file.txt` can work. String fullpath_no_prefix = cur_dir_no_prefix + f; @@ -439,8 +445,9 @@ void EditorExportPlatform::_edit_files_with_filter(DirAccess *da, const Vector<S for (int i = 0; i < dirs.size(); ++i) { String dir = dirs[i]; - if (dir.begins_with(".")) + if (dir.begins_with(".")) { continue; + } da->change_dir(dir); _edit_files_with_filter(da, p_filters, r_list, exclude); da->change_dir(".."); @@ -448,14 +455,16 @@ void EditorExportPlatform::_edit_files_with_filter(DirAccess *da, const Vector<S } void EditorExportPlatform::_edit_filter_list(Set<String> &r_list, const String &p_filter, bool exclude) { - if (p_filter == "") + if (p_filter == "") { return; + } Vector<String> split = p_filter.split(","); Vector<String> filters; for (int i = 0; i < split.size(); i++) { String f = split[i].strip_edges(); - if (f.empty()) + if (f.empty()) { continue; + } filters.push_back(f); } @@ -649,8 +658,9 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> & Vector<String> files = p_preset->get_files_to_export(); for (int i = 0; i < files.size(); i++) { - if (scenes_only && ResourceLoader::get_resource_type(files[i]) != "PackedScene") + if (scenes_only && ResourceLoader::get_resource_type(files[i]) != "PackedScene") { continue; + } _export_find_dependencies(files[i], paths); } @@ -777,8 +787,9 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> & } export_plugins.write[i]->_clear(); - if (!do_export) + if (!do_export) { break; //apologies, not exporting + } } //just store it as it comes if (do_export) { @@ -976,8 +987,9 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, c while (true) { int got = ftmp->get_buffer(buf, bufsize); - if (got <= 0) + if (got <= 0) { break; + } f->store_buffer(buf, got); } @@ -1018,8 +1030,9 @@ Error EditorExportPlatform::save_zip(const Ref<EditorExportPreset> &p_preset, co zd.zip = zip; Error err = export_project_files(p_preset, _save_zip_file, &zd); - if (err != OK && err != ERR_SKIP) + if (err != OK && err != ERR_SKIP) { ERR_PRINT("Failed to export project files"); + } zipClose(zip, nullptr); @@ -1040,8 +1053,9 @@ void EditorExportPlatform::gen_export_flags(Vector<String> &r_flags, int p_flags String host = EditorSettings::get_singleton()->get("network/debug/remote_host"); int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port"); - if (p_flags & DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST) + if (p_flags & DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST) { host = "localhost"; + } if (p_flags & DEBUG_FLAG_DUMB_CLIENT) { int port = EditorSettings::get_singleton()->get("filesystem/file_server/port"); @@ -1067,8 +1081,9 @@ void EditorExportPlatform::gen_export_flags(Vector<String> &r_flags, int p_flags String bpoints; for (const List<String>::Element *E = breakpoints.front(); E; E = E->next()) { bpoints += E->get().replace(" ", "%20"); - if (E->next()) + if (E->next()) { bpoints += ","; + } } r_flags.push_back(bpoints); @@ -1140,8 +1155,9 @@ void EditorExport::_save() { } void EditorExport::save_presets() { - if (block_save) + if (block_save) { return; + } save_timer->start(); } @@ -1163,10 +1179,11 @@ Ref<EditorExportPlatform> EditorExport::get_export_platform(int p_idx) { } void EditorExport::add_export_preset(const Ref<EditorExportPreset> &p_preset, int p_at_pos) { - if (p_at_pos < 0) + if (p_at_pos < 0) { export_presets.push_back(p_preset); - else + } else { export_presets.insert(p_at_pos, p_preset); + } } String EditorExportPlatform::test_etc2() const { @@ -1221,16 +1238,18 @@ void EditorExport::load_config() { Ref<ConfigFile> config; config.instance(); Error err = config->load("res://export_presets.cfg"); - if (err != OK) + if (err != OK) { return; + } block_save = true; int index = 0; while (true) { String section = "preset." + itos(index); - if (!config->has_section(section)) + if (!config->has_section(section)) { break; + } String platform = config->get_value(section, "platform"); @@ -1408,8 +1427,9 @@ bool EditorExportPlatformPC::can_export(const Ref<EditorExportPreset> &p_preset, valid = dvalid || rvalid; r_missing_templates = !valid; - if (!err.empty()) + if (!err.empty()) { r_error = err; + } return valid; } @@ -1597,8 +1617,9 @@ void EditorExportTextSceneToBinaryPlugin::_export_file(const String &p_path, con } bool convert = GLOBAL_GET("editor/convert_text_resources_to_binary_on_export"); - if (!convert) + if (!convert) { return; + } String tmp_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpfile.res"); Error err = ResourceFormatLoaderText::convert_file_to_binary(p_path, tmp_path); if (err != OK) { diff --git a/editor/editor_feature_profile.cpp b/editor/editor_feature_profile.cpp index f8c1c490d5..d3749477cc 100644 --- a/editor/editor_feature_profile.cpp +++ b/editor/editor_feature_profile.cpp @@ -504,8 +504,9 @@ void EditorFeatureProfileManager::_fill_classes_from(TreeItem *p_parent, const S } void EditorFeatureProfileManager::_class_list_item_selected() { - if (updating_features) + if (updating_features) { return; + } property_list->clear(); @@ -549,8 +550,9 @@ void EditorFeatureProfileManager::_class_list_item_selected() { for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { String name = E->get().name; - if (!(E->get().usage & PROPERTY_USAGE_EDITOR)) + if (!(E->get().usage & PROPERTY_USAGE_EDITOR)) { continue; + } TreeItem *property = property_list->create_item(properties); property->set_cell_mode(0, TreeItem::CELL_MODE_CHECK); property->set_editable(0, true); @@ -566,8 +568,9 @@ void EditorFeatureProfileManager::_class_list_item_selected() { } void EditorFeatureProfileManager::_class_list_item_edited() { - if (updating_features) + if (updating_features) { return; + } TreeItem *item = class_list->get_edited(); if (!item) { @@ -590,8 +593,9 @@ void EditorFeatureProfileManager::_class_list_item_edited() { } void EditorFeatureProfileManager::_property_item_edited() { - if (updating_features) + if (updating_features) { return; + } TreeItem *class_item = class_list->get_selected(); if (!class_item) { diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp index 3b1c4d380a..5ae5d1cb31 100644 --- a/editor/editor_file_dialog.cpp +++ b/editor/editor_file_dialog.cpp @@ -74,8 +74,9 @@ void EditorFileDialog::_notification(int p_what) { preview_wheel_timeout -= get_process_delta_time(); if (preview_wheel_timeout <= 0) { preview_wheel_index++; - if (preview_wheel_index >= 8) + if (preview_wheel_index >= 8) { preview_wheel_index = 0; + } Ref<Texture2D> frame = item_list->get_theme_icon("Progress" + itos(preview_wheel_index + 1), "EditorIcons"); preview->set_texture(frame); preview_wheel_timeout = 0.1; @@ -84,8 +85,9 @@ void EditorFileDialog::_notification(int p_what) { } else if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { bool is_showing_hidden = EditorSettings::get_singleton()->get("filesystem/file_dialog/show_hidden_files"); - if (show_hidden_files != is_showing_hidden) + if (show_hidden_files != is_showing_hidden) { set_show_hidden_files(is_showing_hidden); + } set_display_mode((DisplayMode)EditorSettings::get_singleton()->get("filesystem/file_dialog/display_mode").operator int()); // update icons @@ -184,8 +186,9 @@ void EditorFileDialog::set_enable_multiple_selection(bool p_enable) { Vector<String> EditorFileDialog::get_selected_files() const { Vector<String> list; for (int i = 0; i < item_list->get_item_count(); i++) { - if (item_list->is_selected(i)) + if (item_list->is_selected(i)) { list.push_back(item_list->get_item_text(i)); + } } return list; }; @@ -238,10 +241,11 @@ void EditorFileDialog::_post_popup() { update_file_list(); invalidated = false; } - if (mode == FILE_MODE_SAVE_FILE) + if (mode == FILE_MODE_SAVE_FILE) { file->grab_focus(); - else + } else { item_list->grab_focus(); + } if (mode == FILE_MODE_OPEN_DIR) { file_box->set_visible(false); @@ -249,8 +253,9 @@ void EditorFileDialog::_post_popup() { file_box->set_visible(true); } - if (is_visible() && get_current_file() != "") + if (is_visible() && get_current_file() != "") { _request_single_thumbnail(get_current_dir().plus_file(get_current_file())); + } if (is_visible()) { Ref<Texture2D> folder = item_list->get_theme_icon("folder", "FileDialog"); @@ -261,8 +266,9 @@ void EditorFileDialog::_post_popup() { Vector<String> recentd = EditorSettings::get_singleton()->get_recent_dirs(); for (int i = 0; i < recentd.size(); i++) { bool cres = recentd[i].begins_with("res://"); - if (cres != res) + if (cres != res) { continue; + } String name = recentd[i]; if (res && name == "res://") { name = "/"; @@ -286,8 +292,9 @@ void EditorFileDialog::_post_popup() { } void EditorFileDialog::_thumbnail_result(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata) { - if (display_mode == DISPLAY_LIST || p_preview.is_null()) + if (display_mode == DISPLAY_LIST || p_preview.is_null()) { return; + } for (int i = 0; i < item_list->get_item_count(); i++) { Dictionary d = item_list->get_item_metadata(i); @@ -318,8 +325,9 @@ void EditorFileDialog::_thumbnail_done(const String &p_path, const Ref<Texture2D } void EditorFileDialog::_request_single_thumbnail(const String &p_path) { - if (!FileAccess::exists(p_path)) + if (!FileAccess::exists(p_path)) { return; + } set_process(true); preview_waiting = true; @@ -333,8 +341,9 @@ void EditorFileDialog::_action_pressed() { Vector<String> files; for (int i = 0; i < item_list->get_item_count(); i++) { - if (item_list->is_selected(i)) + if (item_list->is_selected(i)) { files.push_back(fbase.plus_file(item_list->get_item_text(i))); + } } if (files.size()) { @@ -389,13 +398,15 @@ void EditorFileDialog::_action_pressed() { break; } } - if (valid) + if (valid) { break; + } } } else { int idx = filter->get_selected(); - if (filters.size() > 1) + if (filters.size() > 1) { idx--; + } if (idx >= 0 && idx < filters.size()) { String flt = filters[idx].get_slice(";", 0); int filterSliceCount = flt.get_slice_count(","); @@ -443,8 +454,9 @@ void EditorFileDialog::_cancel_pressed() { void EditorFileDialog::_item_selected(int p_item) { int current = p_item; - if (current < 0 || current >= item_list->get_item_count()) + if (current < 0 || current >= item_list->get_item_count()) { return; + } Dictionary d = item_list->get_item_metadata(current); @@ -460,8 +472,9 @@ void EditorFileDialog::_item_selected(int p_item) { void EditorFileDialog::_multi_selected(int p_item, bool p_selected) { int current = p_item; - if (current < 0 || current >= item_list->get_item_count()) + if (current < 0 || current >= item_list->get_item_count()) { return; + } Dictionary d = item_list->get_item_metadata(current); @@ -509,8 +522,9 @@ void EditorFileDialog::_push_history() { void EditorFileDialog::_item_dc_selected(int p_item) { int current = p_item; - if (current < 0 || current >= item_list->get_item_count()) + if (current < 0 || current >= item_list->get_item_count()) { return; + } Dictionary d = item_list->get_item_metadata(current); @@ -625,18 +639,21 @@ void EditorFileDialog::_item_menu_id_pressed(int p_option) { } bool EditorFileDialog::_is_open_should_be_disabled() { - if (mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_SAVE_FILE) + if (mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_SAVE_FILE) { return false; + } Vector<int> items = item_list->get_selected_items(); - if (items.size() == 0) + if (items.size() == 0) { return mode != FILE_MODE_OPEN_DIR; // In "Open folder" mode, having nothing selected picks the current folder. + } for (int i = 0; i < items.size(); i++) { Dictionary d = item_list->get_item_metadata(items.get(i)); - if (((mode == FILE_MODE_OPEN_FILE || mode == FILE_MODE_OPEN_FILES) && d["dir"]) || (mode == FILE_MODE_OPEN_DIR && !d["dir"])) + if (((mode == FILE_MODE_OPEN_FILE || mode == FILE_MODE_OPEN_FILES) && d["dir"]) || (mode == FILE_MODE_OPEN_DIR && !d["dir"])) { return true; + } } return false; @@ -645,8 +662,9 @@ bool EditorFileDialog::_is_open_should_be_disabled() { void EditorFileDialog::update_file_name() { int idx = filter->get_selected() - 1; if ((idx == -1 && filter->get_item_count() == 2) || (filter->get_item_count() > 2 && idx >= 0 && idx < filter->get_item_count() - 2)) { - if (idx == -1) + if (idx == -1) { idx += 1; + } String filter_str = filters[idx]; String file_str = file->get_text(); String base_name = file_str.get_basename(); @@ -695,8 +713,9 @@ void EditorFileDialog::update_file_list() { item_list->set_max_text_lines(1); item_list->set_fixed_column_width(0); item_list->set_fixed_icon_size(Size2()); - if (preview->get_texture().is_valid()) + if (preview->get_texture().is_valid()) { preview_vb->show(); + } } String cdir = dir_access->get_current_dir(); @@ -711,14 +730,16 @@ void EditorFileDialog::update_file_list() { String item; while ((item = dir_access->get_next()) != "") { - if (item == "." || item == "..") + if (item == "." || item == "..") { continue; + } if (show_hidden_files || !dir_access->current_is_hidden()) { - if (!dir_access->current_is_dir()) + if (!dir_access->current_is_dir()) { files.push_back(item); - else + } else { dirs.push_back(item); + } } } @@ -761,8 +782,9 @@ void EditorFileDialog::update_file_list() { } } else { int idx = filter->get_selected(); - if (filters.size() > 1) + if (filters.size() > 1) { idx--; + } if (idx >= 0 && idx < filters.size()) { String f = filters[idx].get_slice(";", 0); @@ -806,8 +828,9 @@ void EditorFileDialog::update_file_list() { EditorResourcePreview::get_singleton()->queue_resource_preview(fullpath, this, "_thumbnail_result", fullpath); } - if (file->get_text() == files.front()->get()) + if (file->get_text() == files.front()->get()) { item_list->set_current(item_list->get_item_count() - 1); + } } files.pop_front(); @@ -851,23 +874,26 @@ void EditorFileDialog::update_filters() { for (int i = 0; i < MIN(max_filters, filters.size()); i++) { String flt = filters[i].get_slice(";", 0).strip_edges(); - if (i > 0) + if (i > 0) { all_filters += ", "; + } all_filters += flt; } - if (max_filters < filters.size()) + if (max_filters < filters.size()) { all_filters += ", ..."; + } filter->add_item(TTR("All Recognized") + " (" + all_filters + ")"); } for (int i = 0; i < filters.size(); i++) { String flt = filters[i].get_slice(";", 0).strip_edges(); String desc = filters[i].get_slice(";", 1).strip_edges(); - if (desc.length()) + if (desc.length()) { filter->add_item(desc + " (" + flt + ")"); - else + } else { filter->add_item("(" + flt + ")"); + } } filter->add_item(TTR("All Files (*)")); @@ -898,8 +924,9 @@ String EditorFileDialog::get_current_path() const { } void EditorFileDialog::set_current_dir(const String &p_dir) { - if (p_dir.is_rel_path()) + if (p_dir.is_rel_path()) { dir_access->change_dir(OS::get_singleton()->get_resource_dir()); + } dir_access->change_dir(p_dir); update_dir(); invalidate(); @@ -915,13 +942,15 @@ void EditorFileDialog::set_current_file(const String &p_file) { file->grab_focus(); } - if (is_visible()) + if (is_visible()) { _request_single_thumbnail(get_current_dir().plus_file(get_current_file())); + } } void EditorFileDialog::set_current_path(const String &p_path) { - if (!p_path.size()) + if (!p_path.size()) { return; + } int pos = MAX(p_path.find_last("/"), p_path.find_last("\\")); if (pos == -1) { set_current_file(p_path); @@ -982,8 +1011,9 @@ EditorFileDialog::FileMode EditorFileDialog::get_file_mode() const { void EditorFileDialog::set_access(Access p_access) { ERR_FAIL_INDEX(p_access, 3); - if (access == p_access) + if (access == p_access) { return; + } memdelete(dir_access); switch (p_access) { case ACCESS_FILESYSTEM: { @@ -1107,8 +1137,9 @@ void EditorFileDialog::_favorite_move_up() { int a_idx = favorited.find(String(favorites->get_item_metadata(current - 1))); int b_idx = favorited.find(String(favorites->get_item_metadata(current))); - if (a_idx == -1 || b_idx == -1) + if (a_idx == -1 || b_idx == -1) { return; + } SWAP(favorited.write[a_idx], favorited.write[b_idx]); EditorSettings::get_singleton()->set_favorites(favorited); @@ -1127,8 +1158,9 @@ void EditorFileDialog::_favorite_move_down() { int a_idx = favorited.find(String(favorites->get_item_metadata(current + 1))); int b_idx = favorited.find(String(favorites->get_item_metadata(current))); - if (a_idx == -1 || b_idx == -1) + if (a_idx == -1 || b_idx == -1) { return; + } SWAP(favorited.write[a_idx], favorited.write[b_idx]); EditorSettings::get_singleton()->set_favorites(favorited); @@ -1151,20 +1183,23 @@ void EditorFileDialog::_update_favorites() { Vector<String> favorited = EditorSettings::get_singleton()->get_favorites(); for (int i = 0; i < favorited.size(); i++) { bool cres = favorited[i].begins_with("res://"); - if (cres != res) + if (cres != res) { continue; + } String name = favorited[i]; bool setthis = false; if (res && name == "res://") { - if (name == current) + if (name == current) { setthis = true; + } name = "/"; favorites->add_item(name, folder_icon); } else if (name.ends_with("/")) { - if (name == current || name == current + "/") + if (name == current || name == current + "/") { setthis = true; + } name = name.substr(0, name.length() - 1); name = name.get_file(); @@ -1188,16 +1223,18 @@ void EditorFileDialog::_favorite_pressed() { bool res = access == ACCESS_RESOURCES; String cd = get_current_dir(); - if (!cd.ends_with("/")) + if (!cd.ends_with("/")) { cd += "/"; + } Vector<String> favorited = EditorSettings::get_singleton()->get_favorites(); bool found = false; for (int i = 0; i < favorited.size(); i++) { bool cres = favorited[i].begins_with("res://"); - if (cres != res) + if (cres != res) { continue; + } if (favorited[i] == cd) { found = true; @@ -1205,10 +1242,11 @@ void EditorFileDialog::_favorite_pressed() { } } - if (found) + if (found) { favorited.erase(cd); - else + } else { favorited.push_back(cd); + } EditorSettings::get_singleton()->set_favorites(favorited); @@ -1265,8 +1303,9 @@ bool EditorFileDialog::default_show_hidden_files = false; EditorFileDialog::DisplayMode EditorFileDialog::default_display_mode = DISPLAY_THUMBNAILS; void EditorFileDialog::set_display_mode(DisplayMode p_mode) { - if (display_mode == p_mode) + if (display_mode == p_mode) { return; + } if (p_mode == DISPLAY_THUMBNAILS) { mode_list->set_pressed(false); mode_thumbnails->set_pressed(true); @@ -1625,8 +1664,9 @@ EditorFileDialog::EditorFileDialog() { vbox = vbc; invalidated = true; - if (register_func) + if (register_func) { register_func(this); + } preview_wheel_timeout = 0; preview_wheel_index = 0; @@ -1634,7 +1674,8 @@ EditorFileDialog::EditorFileDialog() { } EditorFileDialog::~EditorFileDialog() { - if (unregister_func) + if (unregister_func) { unregister_func(this); + } memdelete(dir_access); } diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index 77ba5b3f1d..d88c61d7b2 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -51,16 +51,18 @@ void EditorFileSystemDirectory::sort_files() { int EditorFileSystemDirectory::find_file_index(const String &p_file) const { for (int i = 0; i < files.size(); i++) { - if (files[i]->file == p_file) + if (files[i]->file == p_file) { return i; + } } return -1; } int EditorFileSystemDirectory::find_dir_index(const String &p_dir) const { for (int i = 0; i < subdirs.size(); i++) { - if (subdirs[i]->name == p_dir) + if (subdirs[i]->name == p_dir) { return i; + } } return -1; @@ -209,8 +211,9 @@ void EditorFileSystem::_scan_filesystem() { first = false; continue; } - if (l == String()) + if (l == String()) { continue; + } if (l.begins_with("::")) { Vector<String> split = l.split("::"); @@ -317,8 +320,9 @@ void EditorFileSystem::_thread_func(void *_userdata) { } bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_imported_files) { - if (!reimport_on_missing_imported_files && p_only_imported_files) + if (!reimport_on_missing_imported_files && p_only_imported_files) { return false; + } if (!FileAccess::exists(p_path + ".import")) { return true; @@ -476,8 +480,9 @@ bool EditorFileSystem::_update_scan_actions() { case ItemAction::ACTION_DIR_ADD: { int idx = 0; for (int i = 0; i < ia.dir->subdirs.size(); i++) { - if (ia.new_dir->name < ia.dir->subdirs[i]->name) + if (ia.new_dir->name < ia.dir->subdirs[i]->name) { break; + } idx++; } if (idx == ia.dir->subdirs.size()) { @@ -497,8 +502,9 @@ bool EditorFileSystem::_update_scan_actions() { case ItemAction::ACTION_FILE_ADD: { int idx = 0; for (int i = 0; i < ia.dir->files.size(); i++) { - if (ia.new_file->file < ia.dir->files[i]->file) + if (ia.new_file->file < ia.dir->files[i]->file) { break; + } idx++; } if (idx == ia.dir->files.size()) { @@ -567,11 +573,13 @@ bool EditorFileSystem::_update_scan_actions() { } void EditorFileSystem::scan() { - if (false /*&& bool(Globals::get_singleton()->get("debug/disable_scan"))*/) + if (false /*&& bool(Globals::get_singleton()->get("debug/disable_scan"))*/) { return; + } - if (scanning || scanning_changes || thread) + if (scanning || scanning_changes || thread) { return; + } _update_extensions(); @@ -580,8 +588,9 @@ void EditorFileSystem::scan() { scanning = true; scan_total = 0; _scan_filesystem(); - if (filesystem) + if (filesystem) { memdelete(filesystem); + } //file_type_cache.clear(); filesystem = new_filesystem; new_filesystem = nullptr; @@ -629,20 +638,25 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess da->list_dir_begin(); while (true) { String f = da->get_next(); - if (f == "") + if (f == "") { break; + } - if (da->current_is_hidden()) + if (da->current_is_hidden()) { continue; + } if (da->current_is_dir()) { - if (f.begins_with(".")) // Ignore special and . / .. + if (f.begins_with(".")) { // Ignore special and . / .. continue; + } - if (FileAccess::exists(cd.plus_file(f).plus_file("project.godot"))) // skip if another project inside this + if (FileAccess::exists(cd.plus_file(f).plus_file("project.godot"))) { // skip if another project inside this continue; - if (FileAccess::exists(cd.plus_file(f).plus_file(".gdignore"))) // skip if another project inside this + } + if (FileAccess::exists(cd.plus_file(f).plus_file(".gdignore"))) { // skip if another project inside this continue; + } dirs.push_back(f); @@ -675,8 +689,9 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess int idx2 = 0; for (int i = 0; i < p_dir->subdirs.size(); i++) { - if (efd->name < p_dir->subdirs[i]->name) + if (efd->name < p_dir->subdirs[i]->name) { break; + } idx2++; } if (idx2 == p_dir->subdirs.size()) { @@ -812,22 +827,27 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const da->list_dir_begin(); while (true) { String f = da->get_next(); - if (f == "") + if (f == "") { break; + } - if (da->current_is_hidden()) + if (da->current_is_hidden()) { continue; + } if (da->current_is_dir()) { - if (f.begins_with(".")) // Ignore special and . / .. + if (f.begins_with(".")) { // Ignore special and . / .. continue; + } int idx = p_dir->find_dir_index(f); if (idx == -1) { - if (FileAccess::exists(cd.plus_file(f).plus_file("project.godot"))) // skip if another project inside this + if (FileAccess::exists(cd.plus_file(f).plus_file("project.godot"))) { // skip if another project inside this continue; - if (FileAccess::exists(cd.plus_file(f).plus_file(".gdignore"))) // skip if another project inside this + } + if (FileAccess::exists(cd.plus_file(f).plus_file(".gdignore"))) { // skip if another project inside this continue; + } EditorFileSystemDirectory *efd = memnew(EditorFileSystemDirectory); @@ -850,8 +870,9 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const } else { String ext = f.get_extension().to_lower(); - if (!valid_extensions.has(ext)) + if (!valid_extensions.has(ext)) { continue; //invalid + } int idx = p_dir->find_file_index(f); @@ -1019,8 +1040,9 @@ void EditorFileSystem::scan_changes() { sp.low = 0; scan_total = 0; _scan_fs_changes(filesystem, sp); - if (_update_scan_actions()) + if (_update_scan_actions()) { emit_signal("filesystem_changed"); + } } scanning_changes = false; scanning_changes_done = true; @@ -1057,10 +1079,12 @@ void EditorFileSystem::_notification(int p_what) { set_process(false); } - if (filesystem) + if (filesystem) { memdelete(filesystem); - if (new_filesystem) + } + if (new_filesystem) { memdelete(new_filesystem); + } filesystem = nullptr; new_filesystem = nullptr; @@ -1076,8 +1100,9 @@ void EditorFileSystem::_notification(int p_what) { Thread::wait_to_finish(thread_sources); memdelete(thread_sources); thread_sources = nullptr; - if (_update_scan_actions()) + if (_update_scan_actions()) { emit_signal("filesystem_changed"); + } emit_signal("sources_changed", sources_changed.size() > 0); _queue_update_script_classes(); first_scan = false; @@ -1085,8 +1110,9 @@ void EditorFileSystem::_notification(int p_what) { } else if (!scanning) { set_process(false); - if (filesystem) + if (filesystem) { memdelete(filesystem); + } filesystem = new_filesystem; new_filesystem = nullptr; Thread::wait_to_finish(thread); @@ -1121,8 +1147,9 @@ EditorFileSystemDirectory *EditorFileSystem::get_filesystem() { } void EditorFileSystem::_save_filesystem_cache(EditorFileSystemDirectory *p_dir, FileAccess *p_file) { - if (!p_dir) + if (!p_dir) { return; //none + } p_file->store_line("::" + p_dir->get_path() + "::" + String::num(p_dir->modified_time)); for (int i = 0; i < p_dir->files.size(); i++) { @@ -1132,8 +1159,9 @@ void EditorFileSystem::_save_filesystem_cache(EditorFileSystemDirectory *p_dir, String s = p_dir->files[i]->file + "::" + p_dir->files[i]->type + "::" + itos(p_dir->files[i]->modified_time) + "::" + itos(p_dir->files[i]->import_modified_time) + "::" + itos(p_dir->files[i]->import_valid) + "::" + p_dir->files[i]->import_group_file + "::" + p_dir->files[i]->script_class_name + "<>" + p_dir->files[i]->script_class_extends + "<>" + p_dir->files[i]->script_class_icon_path; s += "::"; for (int j = 0; j < p_dir->files[i]->deps.size(); j++) { - if (j > 0) + if (j > 0) { s += "<>"; + } s += p_dir->files[i]->deps[j]; } @@ -1148,28 +1176,32 @@ void EditorFileSystem::_save_filesystem_cache(EditorFileSystemDirectory *p_dir, bool EditorFileSystem::_find_file(const String &p_file, EditorFileSystemDirectory **r_d, int &r_file_pos) const { //todo make faster - if (!filesystem || scanning) + if (!filesystem || scanning) { return false; + } String f = ProjectSettings::get_singleton()->localize_path(p_file); - if (!f.begins_with("res://")) + if (!f.begins_with("res://")) { return false; + } f = f.substr(6, f.length()); f = f.replace("\\", "/"); Vector<String> path = f.split("/"); - if (path.size() == 0) + if (path.size() == 0) { return false; + } String file = path[path.size() - 1]; path.resize(path.size() - 1); EditorFileSystemDirectory *fs = filesystem; for (int i = 0; i < path.size(); i++) { - if (path[i].begins_with(".")) + if (path[i].begins_with(".")) { return false; + } int idx = -1; for (int j = 0; j < fs->get_subdir_count(); j++) { @@ -1188,15 +1220,17 @@ bool EditorFileSystem::_find_file(const String &p_file, EditorFileSystemDirector int idx2 = 0; for (int j = 0; j < fs->get_subdir_count(); j++) { - if (efsd->name < fs->get_subdir(j)->get_name()) + if (efsd->name < fs->get_subdir(j)->get_name()) { break; + } idx2++; } - if (idx2 == fs->get_subdir_count()) + if (idx2 == fs->get_subdir_count()) { fs->subdirs.push_back(efsd); - else + } else { fs->subdirs.insert(idx2, efsd); + } fs = efsd; } else { fs = fs->get_subdir(idx); @@ -1229,8 +1263,9 @@ String EditorFileSystem::get_file_type(const String &p_file) const { } EditorFileSystemDirectory *EditorFileSystem::find_file(const String &p_file, int *r_index) const { - if (!filesystem || scanning) + if (!filesystem || scanning) { return nullptr; + } EditorFileSystemDirectory *fs = nullptr; int cpos = -1; @@ -1238,33 +1273,39 @@ EditorFileSystemDirectory *EditorFileSystem::find_file(const String &p_file, int return nullptr; } - if (r_index) + if (r_index) { *r_index = cpos; + } return fs; } EditorFileSystemDirectory *EditorFileSystem::get_filesystem_path(const String &p_path) { - if (!filesystem || scanning) + if (!filesystem || scanning) { return nullptr; + } String f = ProjectSettings::get_singleton()->localize_path(p_path); - if (!f.begins_with("res://")) + if (!f.begins_with("res://")) { return nullptr; + } f = f.substr(6, f.length()); f = f.replace("\\", "/"); - if (f == String()) + if (f == String()) { return filesystem; + } - if (f.ends_with("/")) + if (f.ends_with("/")) { f = f.substr(0, f.length() - 1); + } Vector<String> path = f.split("/"); - if (path.size() == 0) + if (path.size() == 0) { return nullptr; + } EditorFileSystemDirectory *fs = filesystem; @@ -1351,8 +1392,9 @@ void EditorFileSystem::_scan_script_classes(EditorFileSystemDirectory *p_dir) { } void EditorFileSystem::update_script_classes() { - if (!update_script_classes_queued) + if (!update_script_classes_queued) { return; + } update_script_classes_queued = false; ScriptServer::global_classes_clear(); @@ -1386,8 +1428,9 @@ void EditorFileSystem::update_file(const String &p_file) { int cpos = -1; if (!_find_file(p_file, &fs, cpos)) { - if (!fs) + if (!fs) { return; + } } if (!FileAccess::exists(p_file)) { @@ -1412,8 +1455,9 @@ void EditorFileSystem::update_file(const String &p_file) { int idx = 0; for (int i = 0; i < fs->files.size(); i++) { - if (p_file < fs->files[i]->file) + if (p_file < fs->files[i]->file) { break; + } idx++; } diff --git a/editor/editor_folding.cpp b/editor/editor_folding.cpp index a1d65ac739..f0e6e3a799 100644 --- a/editor/editor_folding.cpp +++ b/editor/editor_folding.cpp @@ -132,8 +132,9 @@ void EditorFolding::save_scene_folding(const Node *p_scene, const String &p_path ERR_FAIL_NULL(p_scene); FileAccessRef file_check = FileAccess::create(FileAccess::ACCESS_RESOURCES); - if (!file_check->file_exists(p_path)) //This can happen when creating scene from FilesystemDock. It has path, but no file. + if (!file_check->file_exists(p_path)) { //This can happen when creating scene from FilesystemDock. It has path, but no file. return; + } Ref<ConfigFile> config; config.instance(); diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index 16e49ad4e1..30cf7d1e7a 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -57,8 +57,9 @@ void EditorHelp::_init_colors() { } void EditorHelp::_unhandled_key_input(const Ref<InputEvent> &p_ev) { - if (!is_visible_in_tree()) + if (!is_visible_in_tree()) { return; + } Ref<InputEventKey> k = p_ev; @@ -69,10 +70,11 @@ void EditorHelp::_unhandled_key_input(const Ref<InputEvent> &p_ev) { } void EditorHelp::_search(bool p_search_previous) { - if (p_search_previous) + if (p_search_previous) { find_bar->search_prev(); - else + } else { find_bar->search_next(); + } } void EditorHelp::_class_list_select(const String &p_select) { @@ -177,8 +179,9 @@ void EditorHelp::_class_desc_resized() { void EditorHelp::_add_type(const String &p_type, const String &p_enum) { String t = p_type; - if (t.empty()) + if (t.empty()) { t = "void"; + } bool can_ref = (t != "void") || !p_enum.empty(); if (!p_enum.empty()) { @@ -270,8 +273,9 @@ void EditorHelp::_add_method(const DocData::MethodDoc &p_method, bool p_overview for (int j = 0; j < p_method.arguments.size(); j++) { class_desc->push_color(text_color); - if (j > 0) + if (j > 0) { class_desc->add_text(", "); + } _add_text(p_method.arguments[j].name); class_desc->add_text(": "); @@ -290,8 +294,9 @@ void EditorHelp::_add_method(const DocData::MethodDoc &p_method, bool p_overview if (is_vararg) { class_desc->push_color(text_color); - if (p_method.arguments.size()) + if (p_method.arguments.size()) { class_desc->add_text(", "); + } class_desc->push_color(symbol_color); class_desc->add_text("..."); class_desc->pop(); @@ -308,13 +313,15 @@ void EditorHelp::_add_method(const DocData::MethodDoc &p_method, bool p_overview class_desc->pop(); } - if (p_overview) + if (p_overview) { class_desc->pop(); //cell + } } Error EditorHelp::_goto_desc(const String &p_class, int p_vscr) { - if (!doc->class_list.has(p_class)) + if (!doc->class_list.has(p_class)) { return ERR_DOES_NOT_EXIST; + } select_locked = true; @@ -322,8 +329,9 @@ Error EditorHelp::_goto_desc(const String &p_class, int p_vscr) { description_line = 0; - if (p_class == edited_class) + if (p_class == edited_class) { return OK; //already there + } edited_class = p_class; _update_doc(); @@ -331,8 +339,9 @@ Error EditorHelp::_goto_desc(const String &p_class, int p_vscr) { } void EditorHelp::_update_doc() { - if (!doc->class_list.has(edited_class)) + if (!doc->class_list.has(edited_class)) { return; + } scroll_locked = true; @@ -594,8 +603,9 @@ void EditorHelp::_update_doc() { } if (methods.size()) { - if (sort_methods) + if (sort_methods) { methods.sort(); + } section_line.push_back(Pair<String, int>(TTR("Methods"), class_desc->get_line_count() - 2)); class_desc->push_color(title_color); @@ -755,8 +765,9 @@ void EditorHelp::_update_doc() { class_desc->pop(); for (int j = 0; j < cd.signals[i].arguments.size(); j++) { class_desc->push_color(text_color); - if (j > 0) + if (j > 0) { class_desc->add_text(", "); + } _add_text(cd.signals[i].arguments[j].name); class_desc->add_text(": "); @@ -849,8 +860,9 @@ void EditorHelp::_update_doc() { int enumStartingLine = enum_line[E->key()]; for (int i = 0; i < enum_list.size(); i++) { - if (cd.name == "@GlobalScope") + if (cd.name == "@GlobalScope") { enumValuesContainer[enum_list[i].name] = enumStartingLine; + } // Add the enum constant line to the constant_line map so we can locate it as a constant constant_line[enum_list[i].name] = class_desc->get_line_count() - 2; @@ -881,8 +893,9 @@ void EditorHelp::_update_doc() { class_desc->add_newline(); } - if (cd.name == "@GlobalScope") + if (cd.name == "@GlobalScope") { enum_values_line[E->key()] = enumValuesContainer; + } class_desc->pop(); @@ -963,8 +976,9 @@ void EditorHelp::_update_doc() { class_desc->add_newline(); for (int i = 0; i < cd.properties.size(); i++) { - if (cd.properties[i].overridden) + if (cd.properties[i].overridden) { continue; + } property_line[cd.properties[i].name] = class_desc->get_line_count() - 2; @@ -1128,8 +1142,9 @@ void EditorHelp::_help_callback(const String &p_topic) { String what = p_topic.get_slice(":", 0); String clss = p_topic.get_slice(":", 1); String name; - if (p_topic.get_slice_count(":") == 3) + if (p_topic.get_slice_count(":") == 3) { name = p_topic.get_slice(":", 2); + } _request_help(clss); //first go to class @@ -1138,36 +1153,43 @@ void EditorHelp::_help_callback(const String &p_topic) { if (what == "class_desc") { line = description_line; } else if (what == "class_signal") { - if (signal_line.has(name)) + if (signal_line.has(name)) { line = signal_line[name]; + } } else if (what == "class_method" || what == "class_method_desc") { - if (method_line.has(name)) + if (method_line.has(name)) { line = method_line[name]; + } } else if (what == "class_property") { - if (property_line.has(name)) + if (property_line.has(name)) { line = property_line[name]; + } } else if (what == "class_enum") { - if (enum_line.has(name)) + if (enum_line.has(name)) { line = enum_line[name]; + } } else if (what == "class_theme_item") { - if (theme_property_line.has(name)) + if (theme_property_line.has(name)) { line = theme_property_line[name]; + } } else if (what == "class_constant") { - if (constant_line.has(name)) + if (constant_line.has(name)) { line = constant_line[name]; + } } else if (what == "class_global") { - if (constant_line.has(name)) + if (constant_line.has(name)) { line = constant_line[name]; - else { + } else { Map<String, Map<String, int>>::Element *iter = enum_values_line.front(); while (true) { if (iter->value().has(name)) { line = iter->value()[name]; break; - } else if (iter == enum_values_line.back()) + } else if (iter == enum_values_line.back()) { break; - else + } else { iter = iter->next(); + } } } } @@ -1204,25 +1226,29 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) { while (pos < bbcode.length()) { int brk_pos = bbcode.find("[", pos); - if (brk_pos < 0) + if (brk_pos < 0) { brk_pos = bbcode.length(); + } if (brk_pos > pos) { String text = bbcode.substr(pos, brk_pos - pos); - if (!code_tag) + if (!code_tag) { text = text.replace("\n", "\n\n"); + } p_rt->add_text(text); } - if (brk_pos == bbcode.length()) + if (brk_pos == bbcode.length()) { break; //nothing else to add + } int brk_end = bbcode.find("]", brk_pos + 1); if (brk_end == -1) { String text = bbcode.substr(brk_pos, bbcode.length() - brk_pos); - if (!code_tag) + if (!code_tag) { text = text.replace("\n", "\n\n"); + } p_rt->add_text(text); break; @@ -1320,8 +1346,9 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) { } else if (tag == "url") { int end = bbcode.find("[", brk_end); - if (end == -1) + if (end == -1) { end = bbcode.length(); + } String url = bbcode.substr(brk_end + 1, end - brk_end - 1); p_rt->push_meta(url); @@ -1334,13 +1361,15 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) { tag_stack.push_front("url"); } else if (tag == "img") { int end = bbcode.find("[", brk_end); - if (end == -1) + if (end == -1) { end = bbcode.length(); + } String image = bbcode.substr(brk_end + 1, end - brk_end - 1); Ref<Texture2D> texture = ResourceLoader::load(base_path.plus_file(image), "Texture2D"); - if (texture.is_valid()) + if (texture.is_valid()) { p_rt->add_image(texture); + } pos = end; tag_stack.push_front(tag); @@ -1348,42 +1377,43 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) { String col = tag.substr(6, tag.length()); Color color; - if (col.begins_with("#")) + if (col.begins_with("#")) { color = Color::html(col); - else if (col == "aqua") + } else if (col == "aqua") { color = Color(0, 1, 1); - else if (col == "black") + } else if (col == "black") { color = Color(0, 0, 0); - else if (col == "blue") + } else if (col == "blue") { color = Color(0, 0, 1); - else if (col == "fuchsia") + } else if (col == "fuchsia") { color = Color(1, 0, 1); - else if (col == "gray" || col == "grey") + } else if (col == "gray" || col == "grey") { color = Color(0.5, 0.5, 0.5); - else if (col == "green") + } else if (col == "green") { color = Color(0, 0.5, 0); - else if (col == "lime") + } else if (col == "lime") { color = Color(0, 1, 0); - else if (col == "maroon") + } else if (col == "maroon") { color = Color(0.5, 0, 0); - else if (col == "navy") + } else if (col == "navy") { color = Color(0, 0, 0.5); - else if (col == "olive") + } else if (col == "olive") { color = Color(0.5, 0.5, 0); - else if (col == "purple") + } else if (col == "purple") { color = Color(0.5, 0, 0.5); - else if (col == "red") + } else if (col == "red") { color = Color(1, 0, 0); - else if (col == "silver") + } else if (col == "silver") { color = Color(0.75, 0.75, 0.75); - else if (col == "teal") + } else if (col == "teal") { color = Color(0, 0.5, 0.5); - else if (col == "white") + } else if (col == "white") { color = Color(1, 1, 1); - else if (col == "yellow") + } else if (col == "yellow") { color = Color(1, 1, 0); - else + } else { color = Color(0, 0, 0); //base_color; + } p_rt->push_color(color); pos = brk_end + 1; @@ -1393,9 +1423,9 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) { String fnt = tag.substr(5, tag.length()); Ref<Font> font = ResourceLoader::load(base_path.plus_file(fnt), "Font"); - if (font.is_valid()) + if (font.is_valid()) { p_rt->push_font(font); - else { + } else { p_rt->push_font(doc_font); } @@ -1544,8 +1574,9 @@ void EditorHelpBit::_meta_clicked(String p_select) { } else if (p_select.begins_with("@")) { String m = p_select.substr(1, p_select.length()); - if (m.find(".") != -1) + if (m.find(".") != -1) { _go_to_help("class_method:" + m.get_slice(".", 0) + ":" + m.get_slice(".", 0)); //must go somewhere else + } } } @@ -1696,8 +1727,9 @@ void FindBar::_update_results_count() { results_count = 0; String searched = search_text->get_text(); - if (searched.empty()) + if (searched.empty()) { return; + } String full_text = rich_text_label->get_text(); @@ -1705,8 +1737,9 @@ void FindBar::_update_results_count() { while (true) { int pos = full_text.find(searched, from_pos); - if (pos == -1) + if (pos == -1) { break; + } results_count++; from_pos = pos + searched.length(); @@ -1725,8 +1758,9 @@ void FindBar::_update_matches_label() { } void FindBar::_hide_bar() { - if (search_text->has_focus()) + if (search_text->has_focus()) { rich_text_label->grab_focus(); + } hide(); } diff --git a/editor/editor_help_search.cpp b/editor/editor_help_search.cpp index 936288b176..5bfcbf06fc 100644 --- a/editor/editor_help_search.cpp +++ b/editor/editor_help_search.cpp @@ -42,18 +42,21 @@ void EditorHelpSearch::_update_icons() { case_sensitive_button->set_icon(results_tree->get_theme_icon("MatchCase", "EditorIcons")); hierarchy_button->set_icon(results_tree->get_theme_icon("ClassList", "EditorIcons")); - if (is_visible()) + if (is_visible()) { _update_results(); + } } void EditorHelpSearch::_update_results() { String term = search_box->get_text(); int search_flags = filter_combo->get_selected_id(); - if (case_sensitive_button->is_pressed()) + if (case_sensitive_button->is_pressed()) { search_flags |= SEARCH_CASE_SENSITIVE; - if (hierarchy_button->is_pressed()) + } + if (hierarchy_button->is_pressed()) { search_flags |= SEARCH_SHOW_HIERARCHY; + } search = Ref<Runner>(memnew(Runner(results_tree, results_tree, term, search_flags))); set_process(true); @@ -85,8 +88,9 @@ void EditorHelpSearch::_filter_combo_item_selected(int p_option) { void EditorHelpSearch::_confirmed() { TreeItem *item = results_tree->get_selected(); - if (!item) + if (!item) { return; + } // Activate the script editor and emit the signal with the documentation link to display. EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT); @@ -120,10 +124,11 @@ void EditorHelpSearch::_notification(int p_what) { // Search done. // Only point to the perfect match if it's a new search, and not just reopening a old one. - if (!old_search) + if (!old_search) { results_tree->ensure_cursor_is_visible(); - else + } else { old_search = false; + } get_ok()->set_disabled(!results_tree->get_selected()); @@ -148,18 +153,20 @@ void EditorHelpSearch::popup_dialog() { void EditorHelpSearch::popup_dialog(const String &p_term) { // Restore valid window bounds or pop up at default size. Rect2 saved_size = EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "search_help", Rect2()); - if (saved_size != Rect2()) + if (saved_size != Rect2()) { popup(saved_size); - else + } else { popup_centered_ratio(0.5F); + } if (p_term == "") { search_box->clear(); } else { - if (old_term == p_term) + if (old_term == p_term) { old_search = true; - else + } else { old_term = p_term; + } search_box->set_text(p_term); search_box->select_all(); @@ -291,8 +298,9 @@ bool EditorHelpSearch::Runner::_slice() { return true; }; - if (phase_done) + if (phase_done) { phase++; + } return false; } @@ -313,41 +321,58 @@ bool EditorHelpSearch::Runner::_phase_match_classes() { match.doc = &class_doc; // Match class name. - if (search_flags & SEARCH_CLASSES) + if (search_flags & SEARCH_CLASSES) { match.name = term == "" || _match_string(term, class_doc.name); + } // Match members if the term is long enough. if (term.length() > 1) { - if (search_flags & SEARCH_METHODS) + if (search_flags & SEARCH_METHODS) { for (int i = 0; i < class_doc.methods.size(); i++) { String method_name = (search_flags & SEARCH_CASE_SENSITIVE) ? class_doc.methods[i].name : class_doc.methods[i].name.to_lower(); String aux_term = (search_flags & SEARCH_CASE_SENSITIVE) ? term : term.to_lower(); - if (aux_term.begins_with(".")) + if (aux_term.begins_with(".")) { aux_term = aux_term.right(1); + } - if (aux_term.ends_with("(")) + if (aux_term.ends_with("(")) { aux_term = aux_term.left(aux_term.length() - 1).strip_edges(); + } - if (aux_term.is_subsequence_of(method_name)) + if (aux_term.is_subsequence_of(method_name)) { match.methods.push_back(const_cast<DocData::MethodDoc *>(&class_doc.methods[i])); + } } - if (search_flags & SEARCH_SIGNALS) - for (int i = 0; i < class_doc.signals.size(); i++) - if (_match_string(term, class_doc.signals[i].name)) + } + if (search_flags & SEARCH_SIGNALS) { + for (int i = 0; i < class_doc.signals.size(); i++) { + if (_match_string(term, class_doc.signals[i].name)) { match.signals.push_back(const_cast<DocData::MethodDoc *>(&class_doc.signals[i])); - if (search_flags & SEARCH_CONSTANTS) - for (int i = 0; i < class_doc.constants.size(); i++) - if (_match_string(term, class_doc.constants[i].name)) + } + } + } + if (search_flags & SEARCH_CONSTANTS) { + for (int i = 0; i < class_doc.constants.size(); i++) { + if (_match_string(term, class_doc.constants[i].name)) { match.constants.push_back(const_cast<DocData::ConstantDoc *>(&class_doc.constants[i])); - if (search_flags & SEARCH_PROPERTIES) - for (int i = 0; i < class_doc.properties.size(); i++) - if (_match_string(term, class_doc.properties[i].name) || _match_string(term, class_doc.properties[i].getter) || _match_string(term, class_doc.properties[i].setter)) + } + } + } + if (search_flags & SEARCH_PROPERTIES) { + for (int i = 0; i < class_doc.properties.size(); i++) { + if (_match_string(term, class_doc.properties[i].name) || _match_string(term, class_doc.properties[i].getter) || _match_string(term, class_doc.properties[i].setter)) { match.properties.push_back(const_cast<DocData::PropertyDoc *>(&class_doc.properties[i])); - if (search_flags & SEARCH_THEME_ITEMS) - for (int i = 0; i < class_doc.theme_properties.size(); i++) - if (_match_string(term, class_doc.theme_properties[i].name)) + } + } + } + if (search_flags & SEARCH_THEME_ITEMS) { + for (int i = 0; i < class_doc.theme_properties.size(); i++) { + if (_match_string(term, class_doc.theme_properties[i].name)) { match.theme_properties.push_back(const_cast<DocData::PropertyDoc *>(&class_doc.theme_properties[i])); + } + } + } } } @@ -369,11 +394,13 @@ bool EditorHelpSearch::Runner::_phase_class_items() { ClassMatch &match = iterator_match->value(); if (search_flags & SEARCH_SHOW_HIERARCHY) { - if (match.required()) + if (match.required()) { _create_class_hierarchy(match); + } } else { - if (match.name) + if (match.name) { _create_class_item(root_item, match.doc, false); + } } iterator_match = iterator_match->next(); @@ -390,49 +417,59 @@ bool EditorHelpSearch::Runner::_phase_member_items() { ClassMatch &match = iterator_match->value(); TreeItem *parent = (search_flags & SEARCH_SHOW_HIERARCHY) ? class_items[match.doc->name] : root_item; - for (int i = 0; i < match.methods.size(); i++) + for (int i = 0; i < match.methods.size(); i++) { _create_method_item(parent, match.doc, match.methods[i]); - for (int i = 0; i < match.signals.size(); i++) + } + for (int i = 0; i < match.signals.size(); i++) { _create_signal_item(parent, match.doc, match.signals[i]); - for (int i = 0; i < match.constants.size(); i++) + } + for (int i = 0; i < match.constants.size(); i++) { _create_constant_item(parent, match.doc, match.constants[i]); - for (int i = 0; i < match.properties.size(); i++) + } + for (int i = 0; i < match.properties.size(); i++) { _create_property_item(parent, match.doc, match.properties[i]); - for (int i = 0; i < match.theme_properties.size(); i++) + } + for (int i = 0; i < match.theme_properties.size(); i++) { _create_theme_property_item(parent, match.doc, match.theme_properties[i]); + } iterator_match = iterator_match->next(); return !iterator_match; } bool EditorHelpSearch::Runner::_phase_select_match() { - if (matched_item) + if (matched_item) { matched_item->select(0); + } return true; } bool EditorHelpSearch::Runner::_match_string(const String &p_term, const String &p_string) const { - if (search_flags & SEARCH_CASE_SENSITIVE) + if (search_flags & SEARCH_CASE_SENSITIVE) { return p_term.is_subsequence_of(p_string); - else + } else { return p_term.is_subsequence_ofi(p_string); + } } void EditorHelpSearch::Runner::_match_item(TreeItem *p_item, const String &p_text) { if (!matched_item) { if (search_flags & SEARCH_CASE_SENSITIVE) { - if (p_text.casecmp_to(term) == 0) + if (p_text.casecmp_to(term) == 0) { matched_item = p_item; + } } else { - if (p_text.nocasecmp_to(term) == 0) + if (p_text.nocasecmp_to(term) == 0) { matched_item = p_item; + } } } } TreeItem *EditorHelpSearch::Runner::_create_class_hierarchy(const ClassMatch &p_match) { - if (class_items.has(p_match.doc->name)) + if (class_items.has(p_match.doc->name)) { return class_items[p_match.doc->name]; + } // Ensure parent nodes are created first. TreeItem *parent = root_item; @@ -452,10 +489,11 @@ TreeItem *EditorHelpSearch::Runner::_create_class_hierarchy(const ClassMatch &p_ TreeItem *EditorHelpSearch::Runner::_create_class_item(TreeItem *p_parent, const DocData::ClassDoc *p_doc, bool p_gray) { Ref<Texture2D> icon = empty_icon; - if (ui_service->has_theme_icon(p_doc->name, "EditorIcons")) + if (ui_service->has_theme_icon(p_doc->name, "EditorIcons")) { icon = ui_service->get_theme_icon(p_doc->name, "EditorIcons"); - else if (ClassDB::class_exists(p_doc->name) && ClassDB::is_parent_class(p_doc->name, "Object")) + } else if (ClassDB::class_exists(p_doc->name) && ClassDB::is_parent_class(p_doc->name, "Object")) { icon = ui_service->get_theme_icon("Object", "EditorIcons"); + } String tooltip = p_doc->brief_description.strip_edges(); TreeItem *item = results_tree->create_item(p_parent); @@ -480,10 +518,12 @@ TreeItem *EditorHelpSearch::Runner::_create_method_item(TreeItem *p_parent, cons for (int i = 0; i < p_doc->arguments.size(); i++) { const DocData::ArgumentDoc &arg = p_doc->arguments[i]; tooltip += arg.type + " " + arg.name; - if (arg.default_value != "") + if (arg.default_value != "") { tooltip += " = " + arg.default_value; - if (i < p_doc->arguments.size() - 1) + } + if (i < p_doc->arguments.size() - 1) { tooltip += ", "; + } } tooltip += ")"; return _create_member_item(p_parent, p_class_doc->name, "MemberMethod", p_doc->name, TTRC("Method"), "method", tooltip); @@ -494,10 +534,12 @@ TreeItem *EditorHelpSearch::Runner::_create_signal_item(TreeItem *p_parent, cons for (int i = 0; i < p_doc->arguments.size(); i++) { const DocData::ArgumentDoc &arg = p_doc->arguments[i]; tooltip += arg.type + " " + arg.name; - if (arg.default_value != "") + if (arg.default_value != "") { tooltip += " = " + arg.default_value; - if (i < p_doc->arguments.size() - 1) + } + if (i < p_doc->arguments.size() - 1) { tooltip += ", "; + } } tooltip += ")"; return _create_member_item(p_parent, p_class_doc->name, "MemberSignal", p_doc->name, TTRC("Signal"), "signal", tooltip); @@ -529,10 +571,10 @@ TreeItem *EditorHelpSearch::Runner::_create_member_item(TreeItem *p_parent, cons } else { icon = ui_service->get_theme_icon(p_icon, "EditorIcons"); /*// In flat mode, show the class icon. - if (ui_service->has_icon(p_class_name, "EditorIcons")) - icon = ui_service->get_icon(p_class_name, "EditorIcons"); - else if (ClassDB::is_parent_class(p_class_name, "Object")) - icon = ui_service->get_icon("Object", "EditorIcons");*/ +if (ui_service->has_icon(p_class_name, "EditorIcons")) +icon = ui_service->get_icon(p_class_name, "EditorIcons"); +else if (ClassDB::is_parent_class(p_class_name, "Object")) +icon = ui_service->get_icon("Object", "EditorIcons");*/ text = p_class_name + "." + p_name; } @@ -552,9 +594,11 @@ TreeItem *EditorHelpSearch::Runner::_create_member_item(TreeItem *p_parent, cons bool EditorHelpSearch::Runner::work(uint64_t slot) { // Return true when the search has been completed, otherwise false. const uint64_t until = OS::get_singleton()->get_ticks_usec() + slot; - while (!_slice()) - if (OS::get_singleton()->get_ticks_usec() > until) + while (!_slice()) { + if (OS::get_singleton()->get_ticks_usec() > until) { return false; + } + } return true; } diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 0e39d0f2ab..1b423f69b7 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -45,14 +45,18 @@ Size2 EditorProperty::get_minimum_size() const { for (int i = 0; i < get_child_count(); i++) { Control *c = Object::cast_to<Control>(get_child(i)); - if (!c) + if (!c) { continue; - if (c->is_set_as_toplevel()) + } + if (c->is_set_as_toplevel()) { continue; - if (!c->is_visible()) + } + if (!c->is_visible()) { continue; - if (c == bottom_editor) + } + if (c == bottom_editor) { continue; + } Size2 minsize = c->get_combined_minimum_size(); ms.width = MAX(ms.width, minsize.width); @@ -110,12 +114,15 @@ void EditorProperty::_notification(int p_what) { //compute room needed for (int i = 0; i < get_child_count(); i++) { Control *c = Object::cast_to<Control>(get_child(i)); - if (!c) + if (!c) { continue; - if (c->is_set_as_toplevel()) + } + if (c->is_set_as_toplevel()) { continue; - if (c == bottom_editor) + } + if (c == bottom_editor) { continue; + } Size2 minsize = c->get_combined_minimum_size(); child_room = MAX(child_room, minsize.width); @@ -169,12 +176,15 @@ void EditorProperty::_notification(int p_what) { //set children for (int i = 0; i < get_child_count(); i++) { Control *c = Object::cast_to<Control>(get_child(i)); - if (!c) + if (!c) { continue; - if (c->is_set_as_toplevel()) + } + if (c->is_set_as_toplevel()) { continue; - if (c == bottom_editor) + } + if (c == bottom_editor) { continue; + } fit_child_in_rect(c, rect); right_child_rect = rect; @@ -226,10 +236,11 @@ void EditorProperty::_notification(int p_what) { if (checkable) { Ref<Texture2D> checkbox; - if (checked) + if (checked) { checkbox = get_theme_icon("GuiChecked", "EditorIcons"); - else + } else { checkbox = get_theme_icon("GuiUnchecked", "EditorIcons"); + } Color color2(1, 1, 1); if (check_hover) { @@ -327,8 +338,9 @@ StringName EditorProperty::get_edited_property() { } void EditorProperty::update_property() { - if (get_script_instance()) + if (get_script_instance()) { get_script_instance()->call("update_property"); + } } void EditorProperty::set_read_only(bool p_read_only) { @@ -421,8 +433,9 @@ bool EditorPropertyRevert::is_node_property_different(Node *p_node, const Varian //make sure there is an actual state { Node *node = p_node; - if (!node) + if (!node) { return false; + } Node *edited_scene = EditorNode::get_singleton()->get_edited_scene(); bool found_state = false; @@ -447,8 +460,9 @@ bool EditorPropertyRevert::is_node_property_different(Node *p_node, const Varian node = node->get_owner(); } - if (!found_state) + if (!found_state) { return false; //pointless to check if we are not comparing against anything. + } } if (p_current.get_type() == Variant::FLOAT && p_orig.get_type() == Variant::FLOAT) { @@ -507,8 +521,9 @@ bool EditorPropertyRevert::can_property_revert(Object *p_object, const StringNam } void EditorProperty::update_reload_status() { - if (property == StringName()) + if (property == StringName()) { return; //no property, so nothing to do + } bool has_reload = EditorPropertyRevert::can_property_revert(object, property); @@ -582,8 +597,9 @@ bool EditorProperty::is_draw_red() const { } void EditorProperty::_focusable_focused(int p_index) { - if (!selectable) + if (!selectable) { return; + } bool already_selected = selected; selected = true; selected_focusable = p_index; @@ -625,8 +641,9 @@ bool EditorProperty::is_selected() const { } void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) { - if (property == StringName()) + if (property == StringName()) { return; + } Ref<InputEventMouse> me = p_event; @@ -744,8 +761,9 @@ void EditorProperty::set_bottom_editor(Control *p_control) { } Variant EditorProperty::get_drag_data(const Point2 &p_point) { - if (property == StringName()) + if (property == StringName()) { return Variant(); + } Dictionary dp; dp["type"] = "obj_property"; @@ -1112,12 +1130,15 @@ void EditorInspectorSection::_notification(int p_what) { //set children for (int i = 0; i < get_child_count(); i++) { Control *c = Object::cast_to<Control>(get_child(i)); - if (!c) + if (!c) { continue; - if (c->is_set_as_toplevel()) + } + if (c->is_set_as_toplevel()) { continue; - if (!c->is_visible_in_tree()) + } + if (!c->is_visible_in_tree()) { continue; + } fit_child_in_rect(c, rect); } @@ -1160,12 +1181,15 @@ Size2 EditorInspectorSection::get_minimum_size() const { Size2 ms; for (int i = 0; i < get_child_count(); i++) { Control *c = Object::cast_to<Control>(get_child(i)); - if (!c) + if (!c) { continue; - if (c->is_set_as_toplevel()) + } + if (c->is_set_as_toplevel()) { continue; - if (!c->is_visible()) + } + if (!c->is_visible()) { continue; + } Size2 minsize = c->get_combined_minimum_size(); ms.width = MAX(ms.width, minsize.width); ms.height = MAX(ms.height, minsize.height); @@ -1201,8 +1225,9 @@ void EditorInspectorSection::setup(const String &p_section, const String &p_labe } void EditorInspectorSection::_gui_input(const Ref<InputEvent> &p_event) { - if (!foldable) + if (!foldable) { return; + } Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { @@ -1228,8 +1253,9 @@ VBoxContainer *EditorInspectorSection::get_vbox() { } void EditorInspectorSection::unfold() { - if (!foldable) + if (!foldable) { return; + } _test_unfold(); @@ -1239,11 +1265,13 @@ void EditorInspectorSection::unfold() { } void EditorInspectorSection::fold() { - if (!foldable) + if (!foldable) { return; + } - if (!vbox_added) + if (!vbox_added) { return; //kinda pointless + } object->editor_set_section_unfold(section, false); vbox->hide(); @@ -1302,8 +1330,9 @@ void EditorInspector::add_inspector_plugin(const Ref<EditorInspectorPlugin> &p_p ERR_FAIL_COND(inspector_plugin_count == MAX_PLUGINS); for (int i = 0; i < inspector_plugin_count; i++) { - if (inspector_plugins[i] == p_plugin) + if (inspector_plugins[i] == p_plugin) { return; //already exists + } } inspector_plugins[inspector_plugin_count++] = p_plugin; } @@ -1324,8 +1353,9 @@ void EditorInspector::remove_inspector_plugin(const Ref<EditorInspectorPlugin> & inspector_plugins[i] = inspector_plugins[i + 1]; } - if (idx == inspector_plugin_count - 1) + if (idx == inspector_plugin_count - 1) { inspector_plugins[idx] = Ref<EditorInspectorPlugin>(); + } inspector_plugin_count--; } @@ -1442,14 +1472,16 @@ void EditorInspector::update_tree() { _clear(); - if (!object) + if (!object) { return; + } List<Ref<EditorInspectorPlugin>> valid_plugins; for (int i = inspector_plugin_count - 1; i >= 0; i--) { //start by last, so lastly added can override newly added - if (!inspector_plugins[i]->can_handle(object)) + if (!inspector_plugins[i]->can_handle(object)) { continue; + } valid_plugins.push_back(inspector_plugins[i]); } @@ -1514,23 +1546,26 @@ void EditorInspector::update_tree() { subgroup = ""; subgroup_base = ""; - if (!show_categories) + if (!show_categories) { continue; + } List<PropertyInfo>::Element *N = I->next(); bool valid = true; //if no properties in category, skip while (N) { - if (N->get().usage & PROPERTY_USAGE_EDITOR) + if (N->get().usage & PROPERTY_USAGE_EDITOR) { break; + } if (N->get().usage & PROPERTY_USAGE_CATEGORY) { valid = false; break; } N = N->next(); } - if (!valid) + if (!valid) { continue; //empty, ignore + } EditorInspectorCategory *category = memnew(EditorInspectorCategory); main_vbox->add_child(category); @@ -1564,11 +1599,13 @@ void EditorInspector::update_tree() { continue; - } else if (!(p.usage & PROPERTY_USAGE_EDITOR) || _is_property_disabled_by_feature_profile(p.name)) + } else if (!(p.usage & PROPERTY_USAGE_EDITOR) || _is_property_disabled_by_feature_profile(p.name)) { continue; + } - if (p.usage & PROPERTY_USAGE_HIGH_END_GFX && RS::get_singleton()->is_low_end()) + if (p.usage & PROPERTY_USAGE_HIGH_END_GFX && RS::get_singleton()->is_low_end()) { continue; //do not show this property in low end gfx + } if (p.name == "script" && (hide_script || bool(object->call("_hide_script_from_inspector")))) { continue; @@ -1626,11 +1663,13 @@ void EditorInspector::update_tree() { if (use_filter && filter != "") { String cat = path; - if (capitalize_paths) + if (capitalize_paths) { cat = cat.capitalize(); + } - if (!filter.is_subsequence_ofi(cat) && !filter.is_subsequence_ofi(name) && property_prefix.to_lower().find(filter.to_lower()) == -1) + if (!filter.is_subsequence_ofi(cat) && !filter.is_subsequence_ofi(name) && property_prefix.to_lower().find(filter.to_lower()) == -1) { continue; + } } if (category_vbox == nullptr) { @@ -1645,16 +1684,18 @@ void EditorInspector::update_tree() { int level = 1; for (int i = 0; i < path.get_slice_count("/"); i++) { String path_name = path.get_slice("/", i); - if (i > 0) + if (i > 0) { acc_path += "/"; + } acc_path += path_name; if (!item_path.has(acc_path)) { EditorInspectorSection *section = memnew(EditorInspectorSection); current_vbox->add_child(section); sections.push_back(section); - if (capitalize_paths) + if (capitalize_paths) { path_name = path_name.capitalize(); + } Color c = sscolor; c.a /= level; @@ -1834,8 +1875,9 @@ void EditorInspector::update_tree() { } void EditorInspector::update_property(const String &p_prop) { - if (!editor_property_map.has(p_prop)) + if (!editor_property_map.has(p_prop)) { return; + } for (List<EditorProperty *>::Element *E = editor_property_map[p_prop].front(); E; E = E->next()) { E->get()->update_property(); @@ -1856,8 +1898,9 @@ void EditorInspector::_clear() { } void EditorInspector::refresh() { - if (refresh_countdown > 0 || changing) + if (refresh_countdown > 0 || changing) { return; + } refresh_countdown = EditorSettings::get_singleton()->get("docks/property_editor/auto_refresh_interval"); } @@ -1866,8 +1909,9 @@ Object *EditorInspector::get_edited_object() { } void EditorInspector::edit(Object *p_object) { - if (object == p_object) + if (object == p_object) { return; + } if (object) { _clear(); object->remove_change_receptor(this); @@ -1886,8 +1930,9 @@ void EditorInspector::edit(Object *p_object) { } void EditorInspector::set_keying(bool p_active) { - if (keying == p_active) + if (keying == p_active) { return; + } keying = p_active; update_tree(); } @@ -1932,8 +1977,9 @@ void EditorInspector::set_use_filter(bool p_use) { void EditorInspector::register_text_enter(Node *p_line_edit) { search_box = Object::cast_to<LineEdit>(p_line_edit); - if (search_box) + if (search_box) { search_box->connect("text_changed", callable_mp(this, &EditorInspector::_filter_changed)); + } } void EditorInspector::_filter_changed(const String &p_text) { @@ -1987,8 +2033,9 @@ void EditorInspector::set_use_wide_editors(bool p_enable) { void EditorInspector::set_sub_inspector(bool p_enable) { sub_inspector = p_enable; - if (!is_inside_tree()) + if (!is_inside_tree()) { return; + } if (sub_inspector) { add_theme_style_override("bg", get_theme_stylebox("sub_inspector_bg", "Editor")); @@ -2002,15 +2049,17 @@ void EditorInspector::set_use_deletable_properties(bool p_enabled) { } void EditorInspector::_edit_request_change(Object *p_object, const String &p_property) { - if (object != p_object) //may be undoing/redoing for a non edited object, so ignore + if (object != p_object) { //may be undoing/redoing for a non edited object, so ignore return; + } - if (changing) + if (changing) { return; + } - if (p_property == String()) + if (p_property == String()) { update_tree_pending = true; - else { + } else { pending.insert(p_property); } } @@ -2026,10 +2075,11 @@ void EditorInspector::_edit_set(const String &p_name, const Variant &p_value, bo if (!undo_redo || bool(object->call("_dont_undo_redo"))) { object->set(p_name, p_value); - if (p_refresh_all) + if (p_refresh_all) { _edit_request_change(object, ""); - else + } else { _edit_request_change(object, p_name); + } emit_signal(_prop_edited, p_name); @@ -2078,13 +2128,15 @@ void EditorInspector::_edit_set(const String &p_name, const Variant &p_value, bo void EditorInspector::_property_changed(const String &p_path, const Variant &p_value, const String &p_name, bool p_changing) { // The "changing" variable must be true for properties that trigger events as typing occurs, // like "text_changed" signal. E.g. text property of Label, Button, RichTextLabel, etc. - if (p_changing) + if (p_changing) { this->changing++; + } _edit_set(p_path, p_value, false, p_name); - if (p_changing) + if (p_changing) { this->changing--; + } if (restart_request_props.has(p_path)) { emit_signal("restart_requested"); @@ -2100,8 +2152,9 @@ void EditorInspector::_multiple_properties_changed(Vector<String> p_paths, Array ERR_FAIL_COND(p_paths.size() != p_values.size()); String names; for (int i = 0; i < p_paths.size(); i++) { - if (i > 0) + if (i > 0) { names += ","; + } names += p_paths[i]; } undo_redo->create_action(TTR("Set Multiple:") + " " + names, UndoRedo::MERGE_ENDS); @@ -2117,30 +2170,34 @@ void EditorInspector::_multiple_properties_changed(Vector<String> p_paths, Array } void EditorInspector::_property_keyed(const String &p_path, bool p_advance) { - if (!object) + if (!object) { return; + } emit_signal("property_keyed", p_path, object->get(p_path), p_advance); //second param is deprecated } void EditorInspector::_property_deleted(const String &p_path) { print_line("deleted pressed?"); - if (!object) + if (!object) { return; + } emit_signal("property_deleted", p_path); //second param is deprecated } void EditorInspector::_property_keyed_with_value(const String &p_path, const Variant &p_value, bool p_advance) { - if (!object) + if (!object) { return; + } emit_signal("property_keyed", p_path, p_value, p_advance); //second param is deprecated } void EditorInspector::_property_checked(const String &p_path, bool p_checked) { - if (!object) + if (!object) { return; + } //property checked if (autoclear) { @@ -2177,11 +2234,13 @@ void EditorInspector::_property_selected(const String &p_path, int p_focusable) property_focusable = p_focusable; //deselect the others for (Map<StringName, List<EditorProperty *>>::Element *F = editor_property_map.front(); F; F = F->next()) { - if (F->key() == property_selected) + if (F->key() == property_selected) { continue; + } for (List<EditorProperty *>::Element *E = F->get().front(); E; E = E->next()) { - if (E->get()->is_selected()) + if (E->get()->is_selected()) { E->get()->deselect(); + } } } @@ -2282,8 +2341,9 @@ void EditorInspector::_changed_callback(Object *p_changed, const char *p_prop) { } void EditorInspector::_vscroll_changed(double p_offset) { - if (update_scroll_request >= 0) //waiting, do nothing + if (update_scroll_request >= 0) { //waiting, do nothing return; + } if (object) { scroll_cache[object->get_instance_id()] = p_offset; diff --git a/editor/editor_layouts_dialog.cpp b/editor/editor_layouts_dialog.cpp index 4f48c5091b..14478b1386 100644 --- a/editor/editor_layouts_dialog.cpp +++ b/editor/editor_layouts_dialog.cpp @@ -41,14 +41,16 @@ void EditorLayoutsDialog::_line_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventKey> k = p_event; if (k.is_valid()) { - if (!k->is_pressed()) + if (!k->is_pressed()) { return; + } switch (k->get_keycode()) { case KEY_KP_ENTER: case KEY_ENTER: { - if (get_hide_on_ok()) + if (get_hide_on_ok()) { hide(); + } ok_pressed(); set_input_as_handled(); } break; diff --git a/editor/editor_log.cpp b/editor/editor_log.cpp index 7adde6f114..ea5f73acd1 100644 --- a/editor/editor_log.cpp +++ b/editor/editor_log.cpp @@ -39,8 +39,9 @@ void EditorLog::_error_handler(void *p_self, const char *p_func, const char *p_file, int p_line, const char *p_error, const char *p_errorexp, ErrorHandlerType p_type) { EditorLog *self = (EditorLog *)p_self; - if (self->current != Thread::get_caller_id()) + if (self->current != Thread::get_caller_id()) { return; + } String err_str; if (p_errorexp && p_errorexp[0]) { @@ -118,8 +119,9 @@ void EditorLog::add_message(const String &p_msg, MessageType p_type) { log->add_text(p_msg); - if (restore) + if (restore) { log->pop(); + } } void EditorLog::set_tool_button(ToolButton *p_tool_button) { diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index c8f07f4b8d..ca0e486259 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -230,8 +230,9 @@ void EditorNode::_update_scene_tabs() { scene_tabs->add_child(scene_tab_add); } Rect2 last_tab = Rect2(); - if (scene_tabs->get_tab_count() != 0) + if (scene_tabs->get_tab_count() != 0) { last_tab = scene_tabs->get_tab_rect(scene_tabs->get_tab_count() - 1); + } scene_tab_add->set_position(Point2(last_tab.get_position().x + last_tab.get_size().x + 3, last_tab.get_position().y)); } } @@ -251,10 +252,12 @@ void EditorNode::_update_title() { String appname = ProjectSettings::get_singleton()->get("application/config/name"); String title = appname.empty() ? String(VERSION_FULL_NAME) : String(VERSION_NAME + String(" - ") + appname); String edited = editor_data.get_edited_scene_root() ? editor_data.get_edited_scene_root()->get_filename() : String(); - if (!edited.empty()) + if (!edited.empty()) { title += " - " + String(edited.get_file()); - if (unsaved_cache) + } + if (unsaved_cache) { title += " (*)"; + } DisplayServer::get_singleton()->window_set_title(title); } @@ -303,8 +306,9 @@ void EditorNode::_unhandled_input(const Ref<InputEvent> &p_event) { void EditorNode::_notification(int p_what) { switch (p_what) { case NOTIFICATION_PROCESS: { - if (opening_prev && !confirmation->is_visible()) + if (opening_prev && !confirmation->is_visible()) { opening_prev = false; + } if (unsaved_cache != (saved_version != editor_data.get_undo_redo().get_version())) { unsaved_cache = (saved_version != editor_data.get_undo_redo().get_version()); @@ -322,8 +326,9 @@ void EditorNode::_notification(int p_what) { if (frame != update_spinner_step_frame && (tick - update_spinner_step_msec) > (1000 / 8)) { update_spinner_step++; - if (update_spinner_step >= 8) + if (update_spinner_step >= 8) { update_spinner_step = 0; + } update_spinner_step_msec = tick; update_spinner_step_frame = frame + 1; @@ -474,8 +479,9 @@ void EditorNode::_notification(int p_what) { recent_scenes->set_as_minsize(); // debugger area - if (EditorDebuggerNode::get_singleton()->is_visible()) + if (EditorDebuggerNode::get_singleton()->is_visible()) { bottom_panel->add_theme_style_override("panel", gui_base->get_theme_stylebox("BottomPanelDebuggerOverride", "EditorStyles")); + } // update_icons for (int i = 0; i < singleton->main_editor_buttons.size(); i++) { @@ -540,8 +546,9 @@ void EditorNode::_update_update_spinner() { void EditorNode::_on_plugin_ready(Object *p_script, const String &p_activate_name) { Ref<Script> script = Object::cast_to<Script>(p_script); - if (script.is_null()) + if (script.is_null()) { return; + } if (p_activate_name.length()) { set_addon_plugin_enabled(p_activate_name, true); } @@ -560,12 +567,15 @@ void EditorNode::_resources_changed(const Vector<String> &p_resources) { continue; } - if (!res->editor_can_reload_from_file()) + if (!res->editor_can_reload_from_file()) { continue; - if (!res->get_path().is_resource_file() && !res->get_path().is_abs_path()) + } + if (!res->get_path().is_resource_file() && !res->get_path().is_abs_path()) { continue; - if (!FileAccess::exists(res->get_path())) + } + if (!FileAccess::exists(res->get_path())) { continue; + } if (res->get_import_path() != String()) { //this is an imported resource, will be reloaded if reimported via the _resources_reimported() callback @@ -711,8 +721,9 @@ void EditorNode::_vp_resized() { } void EditorNode::_node_renamed() { - if (get_inspector()) + if (get_inspector()) { get_inspector()->update_tree(); + } } void EditorNode::_editor_select_next() { @@ -773,8 +784,9 @@ void EditorNode::edit_node(Node *p_node) { void EditorNode::save_resource_in_path(const Ref<Resource> &p_resource, const String &p_path) { editor_data.apply_changes_in_editors(); 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); @@ -912,8 +924,9 @@ void EditorNode::_dialog_display_load_error(String p_file, Error p_error) { void EditorNode::_get_scene_metadata(const String &p_file) { Node *scene = editor_data.get_edited_scene_root(); - if (!scene) + if (!scene) { return; + } String path = EditorSettings::get_singleton()->get_project_settings_dir().plus_file(p_file.get_file() + "-editstate-" + p_file.md5_text() + ".cfg"); @@ -921,8 +934,9 @@ void EditorNode::_get_scene_metadata(const String &p_file) { cf.instance(); Error err = cf->load(path); - if (err != OK || !cf->has_section("editor_states")) + if (err != OK || !cf->has_section("editor_states")) { return; //must not exist + } List<String> esl; cf->get_section_keys("editor_states", &esl); @@ -941,8 +955,9 @@ void EditorNode::_get_scene_metadata(const String &p_file) { void EditorNode::_set_scene_metadata(const String &p_file, int p_idx) { Node *scene = editor_data.get_edited_scene_root(p_idx); - if (!scene) + if (!scene) { return; + } scene->set_meta("__editor_run_settings__", Variant()); //clear it (no point in keeping it) scene->set_meta("__editor_plugin_states__", Variant()); @@ -972,8 +987,9 @@ void EditorNode::_set_scene_metadata(const String &p_file, int p_idx) { } bool EditorNode::_find_and_save_resource(RES p_res, Map<RES, bool> &processed, int32_t flags) { - if (p_res.is_null()) + if (p_res.is_null()) { return false; + } if (processed.has(p_res)) { return processed[p_res]; @@ -1002,15 +1018,17 @@ bool EditorNode::_find_and_save_edited_subresources(Object *obj, Map<RES, bool> List<PropertyInfo> pi; obj->get_property_list(&pi); for (List<PropertyInfo>::Element *E = pi.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { continue; + } switch (E->get().type) { case Variant::OBJECT: { RES res = obj->get(E->get().name); - if (_find_and_save_resource(res, processed, flags)) + if (_find_and_save_resource(res, processed, flags)) { ret_changed = true; + } } break; case Variant::ARRAY: { @@ -1019,8 +1037,9 @@ bool EditorNode::_find_and_save_edited_subresources(Object *obj, Map<RES, bool> for (int i = 0; i < len; i++) { const Variant &v = varray.get(i); RES res = v; - if (_find_and_save_resource(res, processed, flags)) + if (_find_and_save_resource(res, processed, flags)) { ret_changed = true; + } } } break; @@ -1031,8 +1050,9 @@ bool EditorNode::_find_and_save_edited_subresources(Object *obj, Map<RES, bool> for (List<Variant>::Element *F = keys.front(); F; F = F->next()) { Variant v = d[F->get()]; RES res = v; - if (_find_and_save_resource(res, processed, flags)) + if (_find_and_save_resource(res, processed, flags)) { ret_changed = true; + } } } break; default: { @@ -1048,23 +1068,27 @@ void EditorNode::_save_edited_subresources(Node *scene, Map<RES, bool> &processe for (int i = 0; i < scene->get_child_count(); i++) { Node *n = scene->get_child(i); - if (n->get_owner() != editor_data.get_edited_scene_root()) + if (n->get_owner() != editor_data.get_edited_scene_root()) { continue; + } _save_edited_subresources(n, processed, flags); } } void EditorNode::_find_node_types(Node *p_node, int &count_2d, int &count_3d) { - if (p_node->is_class("Viewport") || (p_node != editor_data.get_edited_scene_root() && p_node->get_owner() != editor_data.get_edited_scene_root())) + if (p_node->is_class("Viewport") || (p_node != editor_data.get_edited_scene_root() && p_node->get_owner() != editor_data.get_edited_scene_root())) { return; + } - if (p_node->is_class("CanvasItem")) + if (p_node->is_class("CanvasItem")) { count_2d++; - else if (p_node->is_class("Node3D")) + } else if (p_node->is_class("Node3D")) { count_3d++; + } - for (int i = 0; i < p_node->get_child_count(); i++) + for (int i = 0; i < p_node->get_child_count(); i++) { _find_node_types(p_node->get_child(i), count_2d, count_3d); + } } void EditorNode::_save_scene_with_preview(String p_file, int p_idx) { @@ -1192,8 +1216,9 @@ int EditorNode::_save_external_resources() { //save external resources and its subresources if any was modified 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; + } flg |= ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS; Set<Ref<Resource>> edited_subresources; @@ -1202,8 +1227,9 @@ int EditorNode::_save_external_resources() { ResourceCache::get_cached_resources(&cached); for (List<Ref<Resource>>::Element *E = cached.front(); E; E = E->next()) { Ref<Resource> res = E->get(); - if (!res->get_path().is_resource_file()) + if (!res->get_path().is_resource_file()) { continue; + } //not only check if this resourec is edited, check contained subresources too if (_find_edited_resources(res, edited_subresources)) { ResourceSaver::save(res->get_path(), res, flg); @@ -1248,10 +1274,11 @@ void EditorNode::_save_scene(String p_file, int idx) { // old version still work for referencing changes in instanced or inherited scenes sdata = Ref<PackedScene>(Object::cast_to<PackedScene>(ResourceCache::get(p_file))); - if (sdata.is_valid()) + if (sdata.is_valid()) { sdata->recreate_state(); - else + } else { sdata.instance(); + } } else { sdata.instance(); } @@ -1272,8 +1299,9 @@ void EditorNode::_save_scene(String p_file, int idx) { memdelete(dummy_scene); 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; + } flg |= ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS; err = ResourceSaver::save(p_file, sdata, flg); @@ -1283,10 +1311,11 @@ void EditorNode::_save_scene(String p_file, int idx) { editor_data.save_editor_external_data(); if (err == OK) { scene->set_filename(ProjectSettings::get_singleton()->localize_path(p_file)); - if (idx < 0 || idx == editor_data.get_edited_scene()) + if (idx < 0 || idx == editor_data.get_edited_scene()) { set_current_version(editor_data.get_undo_redo().get_version()); - else + } else { editor_data.set_edited_scene_version(0, idx); + } editor_folding.save_scene_folding(scene, p_file); @@ -1337,10 +1366,11 @@ void EditorNode::_save_all_scenes() { for (int i = 0; i < editor_data.get_edited_scene_count(); i++) { Node *scene = editor_data.get_edited_scene_root(i); if (scene && scene->get_filename() != "") { - if (i != editor_data.get_edited_scene()) + if (i != editor_data.get_edited_scene()) { _save_scene(scene->get_filename(), i); - else + } else { _save_scene_with_preview(scene->get_filename()); + } } // else: ignore new scenes } @@ -1350,15 +1380,17 @@ void EditorNode::_save_all_scenes() { void EditorNode::_mark_unsaved_scenes() { for (int i = 0; i < editor_data.get_edited_scene_count(); i++) { Node *node = editor_data.get_edited_scene_root(i); - if (!node) + if (!node) { continue; + } String path = node->get_filename(); if (!(path == String() || FileAccess::exists(path))) { - if (i == editor_data.get_edited_scene()) + if (i == editor_data.get_edited_scene()) { set_current_version(-1); - else + } else { editor_data.set_edited_scene_version(-1, i); + } } } @@ -1371,8 +1403,9 @@ void EditorNode::_dialog_action(String p_file) { case FILE_NEW_INHERITED_SCENE: { Node *scene = editor_data.get_edited_scene_root(); // If the previous scene is rootless, just close it in favor of the new one. - if (!scene) + if (!scene) { _menu_option_confirm(FILE_CLOSE, true); + } load_scene(p_file, false, true); } break; @@ -1401,8 +1434,9 @@ void EditorNode::_dialog_action(String p_file) { if (file->get_file_mode() == EditorFileDialog::FILE_MODE_SAVE_FILE) { bool same_open_scene = false; for (int i = 0; i < editor_data.get_edited_scene_count(); i++) { - if (editor_data.get_scene_path(i) == p_file && i != scene_idx) + if (editor_data.get_scene_path(i) == p_file && i != scene_idx) { same_open_scene = true; + } } if (same_open_scene) { @@ -1415,8 +1449,9 @@ void EditorNode::_dialog_action(String p_file) { _add_to_recent_scenes(p_file); save_layout(); - if (scene_idx != -1) + if (scene_idx != -1) { _discard_changes(); + } } } break; @@ -1487,8 +1522,9 @@ void EditorNode::_dialog_action(String p_file) { current_obj->_change_notify(); } break; case SETTINGS_LAYOUT_SAVE: { - if (p_file.empty()) + if (p_file.empty()) { return; + } Ref<ConfigFile> config; config.instance(); @@ -1514,8 +1550,9 @@ void EditorNode::_dialog_action(String p_file) { } break; case SETTINGS_LAYOUT_DELETE: { - if (p_file.empty()) + if (p_file.empty()) { return; + } Ref<ConfigFile> config; config.instance(); @@ -1631,10 +1668,11 @@ void EditorNode::push_item(Object *p_object, const String &p_property, bool p_in if (id != editor_history.get_current()) { if (p_inspector_only) { editor_history.add_object_inspector_only(id); - } else if (p_property == "") + } else if (p_property == "") { editor_history.add_object(id); - else + } else { editor_history.add_object(id, p_property); + } } _edit_current(); @@ -1671,8 +1709,9 @@ void EditorNode::_set_editing_top_editors(Object *p_current_object) { static bool overrides_external_editor(Object *p_object) { Script *script = Object::cast_to<Script>(p_object); - if (!script) + if (!script) { return false; + } return script->get_language()->overrides_external_editor(); } @@ -1814,16 +1853,18 @@ void EditorNode::_edit_current() { if (main_plugin) { // special case if use of external editor is true if (main_plugin->get_name() == "Script" && current_obj->get_class_name() != StringName("VisualScript") && (bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor")) || overrides_external_editor(current_obj))) { - if (!changing_scene) + if (!changing_scene) { main_plugin->edit(current_obj); + } } else if (main_plugin != editor_plugin_screen && (!ScriptEditor::get_singleton() || !ScriptEditor::get_singleton()->is_visible_in_tree() || ScriptEditor::get_singleton()->can_take_away_focus())) { // update screen main_plugin if (!changing_scene) { - if (editor_plugin_screen) + if (editor_plugin_screen) { editor_plugin_screen->make_visible(false); + } editor_plugin_screen = main_plugin; editor_plugin_screen->edit(current_obj); @@ -1928,8 +1969,9 @@ void EditorNode::_run(bool p_current, const String &p_custom) { editor_data.save_editor_external_data(); } - if (!call_build()) + if (!call_build()) { return; + } if (bool(EDITOR_GET("run/output/always_clear_output_on_play"))) { log->clear(); @@ -1978,8 +2020,9 @@ void EditorNode::_run_native(const Ref<EditorExportPreset> &p_preset) { if (run_native->is_deploy_debug_remote_enabled()) { _menu_option_confirm(RUN_STOP, true); - if (!call_build()) + if (!call_build()) { return; // build failed + } EditorDebuggerNode::get_singleton()->start(p_preset->get_platform()->get_debug_protocol()); emit_signal("play_pressed"); @@ -1988,8 +2031,9 @@ void EditorNode::_run_native(const Ref<EditorExportPreset> &p_preset) { } void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { - if (!p_confirmed) //this may be a hack.. + if (!p_confirmed) { //this may be a hack.. current_option = (MenuOptions)p_option; + } switch (p_option) { case FILE_NEW_SCENE: { @@ -2030,8 +2074,9 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } break; case FILE_OPEN_PREV: { - if (previous_scenes.empty()) + if (previous_scenes.empty()) { break; + } opening_prev = true; open_request(previous_scenes.back()->get()); previous_scenes.pop_back(); @@ -2045,14 +2090,16 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { next_tab %= editor_data.get_edited_scene_count(); _scene_tab_closed(next_tab, current_option); } else { - if (current_option != FILE_CLOSE_ALL) + if (current_option != FILE_CLOSE_ALL) { current_option = -1; - else + } else { _scene_tab_closed(editor_data.get_edited_scene()); + } } - if (p_confirmed) + if (p_confirmed) { _menu_option_confirm(SCENE_TAB_CLOSE, true); + } } break; case FILE_CLOSE_ALL_AND_QUIT: @@ -2085,13 +2132,15 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { Node *scene = editor_data.get_edited_scene_root(scene_idx); if (scene && scene->get_filename() != "") { - if (scene_idx != editor_data.get_edited_scene()) + if (scene_idx != editor_data.get_edited_scene()) { _save_scene_with_preview(scene->get_filename(), scene_idx); - else + } else { _save_scene_with_preview(scene->get_filename()); + } - if (scene_idx != -1) + if (scene_idx != -1) { _discard_changes(); + } save_layout(); break; @@ -2261,8 +2310,9 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { case EDIT_RELOAD_SAVED_SCENE: { Node *scene = get_edited_scene(); - if (!scene) + if (!scene) { break; + } String filename = scene->get_filename(); @@ -2282,8 +2332,9 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { int cur_idx = editor_data.get_edited_scene(); _remove_edited_scene(); Error err = load_scene(filename); - if (err != OK) + if (err != OK) { ERR_PRINT("Failed to load scene"); + } editor_data.move_edited_scene_to_index(cur_idx); get_undo_redo()->clear_history(false); scene_tabs->set_current_tab(cur_idx); @@ -2308,8 +2359,9 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } break; case RUN_STOP: { - if (editor_run.get_status() == EditorRun::STATUS_STOP) + if (editor_run.get_status() == EditorRun::STATUS_STOP) { break; + } editor_run.stop(); run_custom_filename.clear(); @@ -2550,14 +2602,16 @@ void EditorNode::_tool_menu_option(int p_idx) { int EditorNode::_next_unsaved_scene(bool p_valid_filename, int p_start) { for (int i = p_start; i < editor_data.get_edited_scene_count(); i++) { - if (!editor_data.get_edited_scene_root(i)) + if (!editor_data.get_edited_scene_root(i)) { continue; + } int current = editor_data.get_edited_scene(); bool unsaved = (i == current) ? saved_version != editor_data.get_undo_redo().get_version() : editor_data.get_scene_version(i) != 0; if (unsaved) { String scene_filename = editor_data.get_edited_scene_root(i)->get_filename(); - if (p_valid_filename && scene_filename.length() == 0) + if (p_valid_filename && scene_filename.length() == 0) { continue; + } return i; } } @@ -2658,13 +2712,15 @@ Control *EditorNode::get_viewport() { void EditorNode::_editor_select(int p_which) { static bool selecting = false; - if (selecting || changing_scene) + if (selecting || changing_scene) { return; + } ERR_FAIL_INDEX(p_which, editor_table.size()); - if (!main_editor_buttons[p_which]->is_visible()) //button hidden, no editor + if (!main_editor_buttons[p_which]->is_visible()) { //button hidden, no editor return; + } selecting = true; @@ -2677,8 +2733,9 @@ void EditorNode::_editor_select(int p_which) { EditorPlugin *new_editor = editor_table[p_which]; ERR_FAIL_COND(!new_editor); - if (editor_plugin_screen == new_editor) + if (editor_plugin_screen == new_editor) { return; + } if (editor_plugin_screen) { editor_plugin_screen->make_visible(false); @@ -2738,8 +2795,9 @@ void EditorNode::add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed } singleton->editor_data.add_editor_plugin(p_editor); singleton->add_child(p_editor); - if (p_config_changed) + if (p_config_changed) { p_editor->enable_plugin(); + } } void EditorNode::remove_editor_plugin(EditorPlugin *p_editor, bool p_config_changed) { @@ -2761,8 +2819,9 @@ void EditorNode::remove_editor_plugin(EditorPlugin *p_editor, bool p_config_chan } p_editor->make_visible(false); p_editor->clear(); - if (p_config_changed) + if (p_config_changed) { p_editor->disable_plugin(); + } singleton->editor_plugins_over->get_plugins_list().erase(p_editor); singleton->remove_child(p_editor); singleton->editor_data.remove_editor_plugin(p_editor); @@ -2770,8 +2829,9 @@ void EditorNode::remove_editor_plugin(EditorPlugin *p_editor, bool p_config_chan } void EditorNode::_update_addon_config() { - if (_initializing_addons) + if (_initializing_addons) { return; + } Vector<String> enabled_addons; @@ -2889,8 +2949,9 @@ void EditorNode::_remove_edited_scene(bool p_change_tab) { ScriptEditor::get_singleton()->close_builtin_scripts_from_scene(editor_data.get_scene_path(old_index)); } - if (p_change_tab) + if (p_change_tab) { _scene_tab_changed(new_index); + } editor_data.remove_scene(old_index); editor_data.get_undo_redo().clear_history(false); _update_title(); @@ -2909,27 +2970,32 @@ void EditorNode::_remove_scene(int index, bool p_change_tab) { void EditorNode::set_edited_scene(Node *p_scene) { if (get_editor_data().get_edited_scene_root()) { - if (get_editor_data().get_edited_scene_root()->get_parent() == scene_root) + if (get_editor_data().get_edited_scene_root()->get_parent() == scene_root) { scene_root->remove_child(get_editor_data().get_edited_scene_root()); + } } get_editor_data().set_edited_scene_root(p_scene); - if (Object::cast_to<Popup>(p_scene)) + if (Object::cast_to<Popup>(p_scene)) { Object::cast_to<Popup>(p_scene)->show(); //show popups + } scene_tree_dock->set_edited_scene(p_scene); - if (get_tree()) + if (get_tree()) { get_tree()->set_edited_scene_root(p_scene); + } if (p_scene) { - if (p_scene->get_parent() != scene_root) + if (p_scene->get_parent() != scene_root) { scene_root->add_child(p_scene); + } } } int EditorNode::_get_current_main_editor() { for (int i = 0; i < editor_table.size(); i++) { - if (editor_table[i] == editor_plugin_screen) + if (editor_table[i] == editor_plugin_screen) { return i; + } } return 0; @@ -2946,8 +3012,9 @@ Dictionary EditorNode::_get_main_scene_state() { } void EditorNode::_set_main_scene_state(Dictionary p_state, Node *p_for_scene) { - if (get_edited_scene() != p_for_scene && p_for_scene != nullptr) + if (get_edited_scene() != p_for_scene && p_for_scene != nullptr) { return; //not for this scene + } changing_scene = false; @@ -2981,13 +3048,16 @@ void EditorNode::_set_main_scene_state(Dictionary p_state, Node *p_for_scene) { } } - if (p_state.has("scene_tree_offset")) + if (p_state.has("scene_tree_offset")) { scene_tree_dock->get_tree_editor()->get_scene_tree()->get_vscroll_bar()->set_value(p_state["scene_tree_offset"]); - if (p_state.has("property_edit_offset")) + } + if (p_state.has("property_edit_offset")) { get_inspector()->set_scroll_offset(p_state["property_edit_offset"]); + } - if (p_state.has("node_filter")) + if (p_state.has("node_filter")) { scene_tree_dock->set_filter(p_state["node_filter"]); + } //this should only happen at the very end @@ -3011,12 +3081,14 @@ void EditorNode::_clear_undo_history() { void EditorNode::set_current_scene(int p_idx) { //Save the folding in case the scene gets reloaded. - if (editor_data.get_scene_path(p_idx) != "" && editor_data.get_edited_scene_root(p_idx)) + if (editor_data.get_scene_path(p_idx) != "" && editor_data.get_edited_scene_root(p_idx)) { editor_folding.save_scene_folding(editor_data.get_edited_scene_root(p_idx), editor_data.get_scene_path(p_idx)); + } if (editor_data.check_and_update_scene(p_idx)) { - if (editor_data.get_scene_path(p_idx) != "") + if (editor_data.get_scene_path(p_idx) != "") { editor_folding.load_scene_folding(editor_data.get_edited_scene_root(p_idx), editor_data.get_scene_path(p_idx)); + } call_deferred("_clear_undo_history"); } @@ -3025,8 +3097,9 @@ void EditorNode::set_current_scene(int p_idx) { editor_data.save_edited_scene_state(editor_selection, &editor_history, _get_main_scene_state()); if (get_editor_data().get_edited_scene_root()) { - if (get_editor_data().get_edited_scene_root()->get_parent() == scene_root) + if (get_editor_data().get_edited_scene_root()->get_parent() == scene_root) { scene_root->remove_child(get_editor_data().get_edited_scene_root()); + } } editor_selection->clear(); @@ -3034,16 +3107,19 @@ void EditorNode::set_current_scene(int p_idx) { Node *new_scene = editor_data.get_edited_scene_root(); - if (Object::cast_to<Popup>(new_scene)) + if (Object::cast_to<Popup>(new_scene)) { Object::cast_to<Popup>(new_scene)->show(); //show popups + } scene_tree_dock->set_edited_scene(new_scene); - if (get_tree()) + if (get_tree()) { get_tree()->set_edited_scene_root(new_scene); + } if (new_scene) { - if (new_scene->get_parent() != scene_root) + if (new_scene->get_parent() != scene_root) { scene_root->add_child(new_scene); + } } Dictionary state = editor_data.restore_edited_scene_state(editor_selection, &editor_history); @@ -3056,8 +3132,9 @@ void EditorNode::set_current_scene(int p_idx) { bool EditorNode::is_scene_open(const String &p_path) { for (int i = 0; i < editor_data.get_edited_scene_count(); i++) { - if (editor_data.get_scene_path(i) == p_path) + if (editor_data.get_scene_path(i) == p_path) { return true; + } } return false; @@ -3098,8 +3175,9 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b } } - if (p_clear_errors) + if (p_clear_errors) { load_errors->clear(); + } String lpath = ProjectSettings::get_singleton()->localize_path(p_scene); @@ -3279,11 +3357,13 @@ void EditorNode::_show_messages() { void EditorNode::_add_to_recent_scenes(const String &p_scene) { Array rc = EditorSettings::get_singleton()->get_project_metadata("recent_files", "scenes", Array()); - if (rc.find(p_scene) != -1) + if (rc.find(p_scene) != -1) { rc.erase(p_scene); + } rc.push_front(p_scene); - if (rc.size() > 10) + if (rc.size() > 10) { rc.resize(10); + } EditorSettings::get_singleton()->set_project_metadata("recent_files", "scenes", rc); _update_recent_scenes(); @@ -3371,8 +3451,9 @@ bool EditorNode::_find_scene_in_use(Node *p_node, const String &p_path) const { bool EditorNode::is_scene_in_use(const String &p_path) { Node *es = get_edited_scene(); - if (es) + if (es) { return _find_scene_in_use(es, p_path); + } return false; } @@ -3419,8 +3500,9 @@ void EditorNode::unregister_editor_types() { void EditorNode::stop_child_process(OS::ProcessID p_pid) { if (has_child_process(p_pid)) { editor_run.stop_child_process(p_pid); - if (!editor_run.get_child_process_count()) // All children stopped. Closing. + if (!editor_run.get_child_process_count()) { // All children stopped. Closing. _menu_option_confirm(RUN_STOP, false); + } } } @@ -3467,8 +3549,9 @@ StringName EditorNode::get_object_custom_type_name(const Object *p_object) const Ref<Script> base_script = script; while (base_script.is_valid()) { StringName name = EditorNode::get_editor_data().script_class_get_name(base_script->get_path()); - if (name != StringName()) + if (name != StringName()) { return name; + } // should probably be deprecated in 4.x StringName base = base_script->get_instance_base_type(); @@ -3534,14 +3617,17 @@ Ref<Texture2D> EditorNode::get_object_icon(const Object *p_object, const String } // should probably be deprecated in 4.x - if (p_object->has_meta("_editor_icon")) + if (p_object->has_meta("_editor_icon")) { return p_object->get_meta("_editor_icon"); + } - if (gui_base->has_theme_icon(p_object->get_class(), "EditorIcons")) + if (gui_base->has_theme_icon(p_object->get_class(), "EditorIcons")) { return gui_base->get_theme_icon(p_object->get_class(), "EditorIcons"); + } - if (p_fallback.length()) + if (p_fallback.length()) { return gui_base->get_theme_icon(p_fallback, "EditorIcons"); + } return nullptr; } @@ -3591,8 +3677,9 @@ Ref<Texture2D> EditorNode::get_class_icon(const String &p_class, const String &p } } - if (p_fallback.length() && gui_base->has_theme_icon(p_fallback, "EditorIcons")) + if (p_fallback.length() && gui_base->has_theme_icon(p_fallback, "EditorIcons")) { return gui_base->get_theme_icon(p_fallback, "EditorIcons"); + } return nullptr; } @@ -3659,8 +3746,9 @@ void EditorNode::_build_icon_type_cache() { StringName ei = "EditorIcons"; theme_base->get_theme()->get_icon_list(ei, &tl); for (List<StringName>::Element *E = tl.front(); E; E = E->next()) { - if (!ClassDB::class_exists(E->get())) + if (!ClassDB::class_exists(E->get())) { continue; + } icon_type_cache[E->get()] = theme_base->get_theme()->get_icon(E->get(), ei); } } @@ -3784,16 +3872,18 @@ void EditorNode::_update_dock_containers() { } for (int i = 0; i < vsplits.size(); i++) { bool in_use = dock_slot[i * 2 + 0]->get_tab_count() || dock_slot[i * 2 + 1]->get_tab_count(); - if (in_use) + if (in_use) { vsplits[i]->show(); - else + } else { vsplits[i]->hide(); + } } - if (right_l_vsplit->is_visible() || right_r_vsplit->is_visible()) + if (right_l_vsplit->is_visible() || right_r_vsplit->is_visible()) { right_hsplit->show(); - else + } else { right_hsplit->hide(); + } } void EditorNode::_dock_select_input(const Ref<InputEvent> &p_input) { @@ -3815,8 +3905,9 @@ void EditorNode::_dock_select_input(const Ref<InputEvent> &p_input) { dock_select_rect_over = nrect; } - if (nrect == -1) + if (nrect == -1) { return; + } Ref<InputEventMouseButton> mb = me; @@ -3856,12 +3947,14 @@ void EditorNode::_dock_pre_popup(int p_which) { } void EditorNode::_dock_move_left() { - if (dock_popup_selected < 0 || dock_popup_selected >= DOCK_SLOT_MAX) + if (dock_popup_selected < 0 || dock_popup_selected >= DOCK_SLOT_MAX) { return; + } Control *current = dock_slot[dock_popup_selected]->get_tab_control(dock_slot[dock_popup_selected]->get_current_tab()); Control *prev = dock_slot[dock_popup_selected]->get_tab_control(dock_slot[dock_popup_selected]->get_current_tab() - 1); - if (!current || !prev) + if (!current || !prev) { return; + } dock_slot[dock_popup_selected]->move_child(current, prev->get_index()); dock_slot[dock_popup_selected]->set_current_tab(dock_slot[dock_popup_selected]->get_current_tab() - 1); dock_select->update(); @@ -3872,8 +3965,9 @@ void EditorNode::_dock_move_left() { void EditorNode::_dock_move_right() { Control *current = dock_slot[dock_popup_selected]->get_tab_control(dock_slot[dock_popup_selected]->get_current_tab()); Control *next = dock_slot[dock_popup_selected]->get_tab_control(dock_slot[dock_popup_selected]->get_current_tab() + 1); - if (!current || !next) + if (!current || !next) { return; + } dock_slot[dock_popup_selected]->move_child(next, current->get_index()); dock_slot[dock_popup_selected]->set_current_tab(dock_slot[dock_popup_selected]->get_current_tab() + 1); dock_select->update(); @@ -3959,8 +4053,9 @@ void EditorNode::_dock_select_draw() { for (int j = 0; j < MIN(3, dock_slot[i]->get_child_count()); j++) { int xofs = (r.size.width / 3) * j; Color c = used; - if (i == dock_popup_selected && (dock_slot[i]->get_current_tab() > 3 || dock_slot[i]->get_current_tab() == j)) + if (i == dock_popup_selected && (dock_slot[i]->get_current_tab() > 3 || dock_slot[i]->get_current_tab() == j)) { c = tab_selected; + } dock_select->draw_rect(Rect2(2 + ofs.x + xofs, ofs.y, r.size.width / 3 - 1, 3), c); } } @@ -3985,8 +4080,9 @@ void EditorNode::_save_docks_to_config(Ref<ConfigFile> p_layout, const String &p String names; for (int j = 0; j < dock_slot[i]->get_tab_count(); j++) { String name = dock_slot[i]->get_tab_control(j)->get_name(); - if (names != "") + if (names != "") { names += ","; + } names += name; } @@ -4068,18 +4164,20 @@ void EditorNode::_update_dock_slots_visibility() { tabs_visible++; } } - if (tabs_visible) + if (tabs_visible) { dock_slot[i]->show(); - else + } else { dock_slot[i]->hide(); + } } for (int i = 0; i < vsplits.size(); i++) { bool in_use = dock_slot[i * 2 + 0]->get_tab_count() || dock_slot[i * 2 + 1]->get_tab_count(); - if (in_use) + if (in_use) { vsplits[i]->show(); - else + } else { vsplits[i]->hide(); + } } for (int i = 0; i < DOCK_SLOT_MAX; i++) { @@ -4089,10 +4187,11 @@ void EditorNode::_update_dock_slots_visibility() { } bottom_panel->show(); - if (right_l_vsplit->is_visible() || right_r_vsplit->is_visible()) + if (right_l_vsplit->is_visible() || right_r_vsplit->is_visible()) { right_hsplit->show(); - else + } else { right_hsplit->hide(); + } } } @@ -4112,32 +4211,36 @@ void EditorNode::_dock_tab_changed(int p_tab) { bottom_panel->hide(); } else { for (int i = 0; i < DOCK_SLOT_MAX; i++) { - if (dock_slot[i]->get_tab_count()) + if (dock_slot[i]->get_tab_count()) { dock_slot[i]->show(); - else + } else { dock_slot[i]->hide(); + } } for (int i = 0; i < vsplits.size(); i++) { bool in_use = dock_slot[i * 2 + 0]->get_tab_count() || dock_slot[i * 2 + 1]->get_tab_count(); - if (in_use) + if (in_use) { vsplits[i]->show(); - else + } else { vsplits[i]->hide(); + } } bottom_panel->show(); - if (right_l_vsplit->is_visible() || right_r_vsplit->is_visible()) + if (right_l_vsplit->is_visible() || right_r_vsplit->is_visible()) { right_hsplit->show(); - else + } else { right_hsplit->hide(); + } } } void EditorNode::_load_docks_from_config(Ref<ConfigFile> p_layout, const String &p_section) { for (int i = 0; i < DOCK_SLOT_MAX; i++) { - if (!p_layout->has_section_key(p_section, "dock_" + itos(i + 1))) + if (!p_layout->has_section_key(p_section, "dock_" + itos(i + 1))) { continue; + } Vector<String> names = String(p_layout->get_value(p_section, "dock_" + itos(i + 1))).split(","); @@ -4147,16 +4250,19 @@ void EditorNode::_load_docks_from_config(Ref<ConfigFile> p_layout, const String int atidx = -1; Control *node = nullptr; for (int k = 0; k < DOCK_SLOT_MAX; k++) { - if (!dock_slot[k]->has_node(name)) + if (!dock_slot[k]->has_node(name)) { continue; + } node = Object::cast_to<Control>(dock_slot[k]->get_node(name)); - if (!node) + if (!node) { continue; + } atidx = k; break; } - if (atidx == -1) //well, it's not anywhere + if (atidx == -1) { //well, it's not anywhere continue; + } if (atidx == i) { node->raise(); @@ -4189,32 +4295,36 @@ void EditorNode::_load_docks_from_config(Ref<ConfigFile> p_layout, const String } for (int i = 0; i < vsplits.size(); i++) { - if (!p_layout->has_section_key(p_section, "dock_split_" + itos(i + 1))) + if (!p_layout->has_section_key(p_section, "dock_split_" + itos(i + 1))) { continue; + } int ofs = p_layout->get_value(p_section, "dock_split_" + itos(i + 1)); vsplits[i]->set_split_offset(ofs); } for (int i = 0; i < hsplits.size(); i++) { - if (!p_layout->has_section_key(p_section, "dock_hsplit_" + itos(i + 1))) + if (!p_layout->has_section_key(p_section, "dock_hsplit_" + itos(i + 1))) { continue; + } int ofs = p_layout->get_value(p_section, "dock_hsplit_" + itos(i + 1)); hsplits[i]->set_split_offset(ofs); } for (int i = 0; i < vsplits.size(); i++) { bool in_use = dock_slot[i * 2 + 0]->get_tab_count() || dock_slot[i * 2 + 1]->get_tab_count(); - if (in_use) + if (in_use) { vsplits[i]->show(); - else + } else { vsplits[i]->hide(); + } } - if (right_l_vsplit->is_visible() || right_r_vsplit->is_visible()) + if (right_l_vsplit->is_visible() || right_r_vsplit->is_visible()) { right_hsplit->show(); - else + } else { right_hsplit->hide(); + } for (int i = 0; i < DOCK_SLOT_MAX; i++) { if (dock_slot[i]->is_visible() && dock_slot[i]->get_tab_count()) { @@ -4373,8 +4483,9 @@ void EditorNode::_layout_menu_option(int p_id) { void EditorNode::_scene_tab_script_edited(int p_tab) { Ref<Script> script = editor_data.get_scene_root_script(p_tab); - if (script.is_valid()) + if (script.is_valid()) { inspector_dock->edit_resource(script); + } } void EditorNode::_scene_tab_closed(int p_tab, int option) { @@ -4491,8 +4602,9 @@ void EditorNode::_scene_tab_changed(int p_tab) { bool unsaved = (saved_version != editor_data.get_undo_redo().get_version()); - if (p_tab == editor_data.get_edited_scene()) + if (p_tab == editor_data.get_edited_scene()) { return; //pointless + } uint64_t next_scene_version = editor_data.get_scene_version(p_tab); @@ -4529,8 +4641,9 @@ ToolButton *EditorNode::add_bottom_panel_item(String p_text, Control *p_item) { bool EditorNode::are_bottom_panels_hidden() const { for (int i = 0; i < bottom_panel_items.size(); i++) { - if (bottom_panel_items[i].button->is_pressed()) + if (bottom_panel_items[i].button->is_pressed()) { return false; + } } return true; @@ -4810,8 +4923,9 @@ void EditorNode::add_tool_submenu_item(const String &p_name, PopupMenu *p_submen void EditorNode::remove_tool_menu_item(const String &p_name) { for (int i = 0; i < tool_menu->get_item_count(); i++) { - if (tool_menu->get_item_id(i) != TOOLS_CUSTOM) + if (tool_menu->get_item_id(i) != TOOLS_CUSTOM) { continue; + } if (tool_menu->get_item_text(i) == p_name) { if (tool_menu->get_item_submenu(i) != "") { @@ -5087,8 +5201,9 @@ void EditorNode::_feature_profile_changed() { main_editor_buttons[EDITOR_3D]->set_visible(!profile->is_feature_disabled(EditorFeatureProfile::FEATURE_3D)); main_editor_buttons[EDITOR_SCRIPT]->set_visible(!profile->is_feature_disabled(EditorFeatureProfile::FEATURE_SCRIPT)); - if (StreamPeerSSL::is_available()) + if (StreamPeerSSL::is_available()) { main_editor_buttons[EDITOR_ASSETLIB]->set_visible(!profile->is_feature_disabled(EditorFeatureProfile::FEATURE_ASSET_LIB)); + } if ((profile->is_feature_disabled(EditorFeatureProfile::FEATURE_3D) && singleton->main_editor_buttons[EDITOR_3D]->is_pressed()) || (profile->is_feature_disabled(EditorFeatureProfile::FEATURE_SCRIPT) && singleton->main_editor_buttons[EDITOR_SCRIPT]->is_pressed()) || (StreamPeerSSL::is_available() && profile->is_feature_disabled(EditorFeatureProfile::FEATURE_ASSET_LIB) && singleton->main_editor_buttons[EDITOR_ASSETLIB]->is_pressed())) { @@ -5103,8 +5218,9 @@ void EditorNode::_feature_profile_changed() { filesystem_dock->set_visible(true); main_editor_buttons[EDITOR_3D]->set_visible(true); main_editor_buttons[EDITOR_SCRIPT]->set_visible(true); - if (StreamPeerSSL::is_available()) + if (StreamPeerSSL::is_available()) { main_editor_buttons[EDITOR_ASSETLIB]->set_visible(true); + } } _update_dock_slots_visibility(); @@ -5269,8 +5385,9 @@ EditorNode::EditorNode() { TranslationServer::get_singleton()->set_enabled(false); // load settings - if (!EditorSettings::get_singleton()) + if (!EditorSettings::get_singleton()) { EditorSettings::create(); + } FileAccess::set_backup_save(EDITOR_GET("filesystem/on_save/safe_save_on_backup_then_rename")); @@ -6142,8 +6259,9 @@ EditorNode::EditorNode() { default_layout->set_value(docks_section, "dock_4", "FileSystem"); default_layout->set_value(docks_section, "dock_5", "Inspector,Node"); - for (int i = 0; i < vsplits.size(); i++) + for (int i = 0; i < vsplits.size(); i++) { default_layout->set_value(docks_section, "dock_split_" + itos(i + 1), 0); + } default_layout->set_value(docks_section, "dock_hsplit_1", 0); default_layout->set_value(docks_section, "dock_hsplit_2", 70 * EDSCALE); default_layout->set_value(docks_section, "dock_hsplit_3", -70 * EDSCALE); @@ -6344,8 +6462,9 @@ EditorNode::EditorNode() { add_editor_plugin(memnew(MeshEditorPlugin(this))); add_editor_plugin(memnew(MaterialEditorPlugin(this))); - for (int i = 0; i < EditorPlugins::get_plugin_count(); i++) + for (int i = 0; i < EditorPlugins::get_plugin_count(); i++) { add_editor_plugin(EditorPlugins::create(i, this)); + } for (int i = 0; i < plugin_init_callback_count; i++) { plugin_init_callbacks[i](); @@ -6465,8 +6584,9 @@ EditorNode::EditorNode() { pick_main_scene->get_ok()->set_text(TTR("Select")); pick_main_scene->connect("confirmed", callable_mp(this, &EditorNode::_menu_option), varray(SETTINGS_PICK_MAIN_SCENE)); - for (int i = 0; i < _init_callbacks.size(); i++) + for (int i = 0; i < _init_callbacks.size(); i++) { _init_callbacks[i](); + } editor_data.add_edited_scene(-1); editor_data.set_edited_scene(0); diff --git a/editor/editor_node.h b/editor/editor_node.h index a0f4d7db7c..dfe3d91c07 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -547,8 +547,9 @@ private: static void _dependency_error_report(void *ud, const String &p_path, const String &p_dep, const String &p_type) { EditorNode *en = (EditorNode *)ud; - if (!en->dependency_errors.has(p_path)) + if (!en->dependency_errors.has(p_path)) { en->dependency_errors[p_path] = Set<String>(); + } en->dependency_errors[p_path].insert(p_dep + "::" + p_type); } @@ -801,10 +802,11 @@ public: static void progress_end_task_bg(const String &p_task); void save_scene_to_path(String p_file, bool p_with_preview = true) { - if (p_with_preview) + if (p_with_preview) { _save_scene_with_preview(p_file); - else + } else { _save_scene(p_file); + } } bool is_scene_in_use(const String &p_path); diff --git a/editor/editor_path.cpp b/editor/editor_path.cpp index 8d71dc6ca0..c249974f99 100644 --- a/editor/editor_path.cpp +++ b/editor/editor_path.cpp @@ -34,23 +34,28 @@ #include "editor_scale.h" void EditorPath::_add_children_to_popup(Object *p_obj, int p_depth) { - if (p_depth > 8) + if (p_depth > 8) { return; + } List<PropertyInfo> pinfo; p_obj->get_property_list(&pinfo); for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_EDITOR)) + if (!(E->get().usage & PROPERTY_USAGE_EDITOR)) { continue; - if (E->get().hint != PROPERTY_HINT_RESOURCE_TYPE) + } + if (E->get().hint != PROPERTY_HINT_RESOURCE_TYPE) { continue; + } Variant value = p_obj->get(E->get().name); - if (value.get_type() != Variant::OBJECT) + if (value.get_type() != Variant::OBJECT) { continue; + } Object *obj = value; - if (!obj) + if (!obj) { continue; + } Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(obj); @@ -65,8 +70,9 @@ void EditorPath::_add_children_to_popup(Object *p_obj, int p_depth) { void EditorPath::_about_to_show() { Object *obj = ObjectDB::get_instance(history->get_path_object(history->get_path_size() - 1)); - if (!obj) + if (!obj) { return; + } objects.clear(); get_popup()->clear(); @@ -82,32 +88,37 @@ void EditorPath::_about_to_show() { void EditorPath::update_path() { for (int i = 0; i < history->get_path_size(); i++) { Object *obj = ObjectDB::get_instance(history->get_path_object(i)); - if (!obj) + if (!obj) { continue; + } Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(obj); - if (icon.is_valid()) + if (icon.is_valid()) { set_icon(icon); + } if (i == history->get_path_size() - 1) { String name; if (Object::cast_to<Resource>(obj)) { Resource *r = Object::cast_to<Resource>(obj); - if (r->get_path().is_resource_file()) + if (r->get_path().is_resource_file()) { name = r->get_path().get_file(); - else + } else { name = r->get_name(); + } - if (name == "") + if (name == "") { name = r->get_class(); - } else if (obj->is_class("EditorDebuggerRemoteObject")) + } + } else if (obj->is_class("EditorDebuggerRemoteObject")) { name = obj->call("get_title"); - else if (Object::cast_to<Node>(obj)) + } else if (Object::cast_to<Node>(obj)) { name = Object::cast_to<Node>(obj)->get_name(); - else if (Object::cast_to<Resource>(obj) && Object::cast_to<Resource>(obj)->get_name() != "") + } else if (Object::cast_to<Resource>(obj) && Object::cast_to<Resource>(obj)->get_name() != "") { name = Object::cast_to<Resource>(obj)->get_name(); - else + } else { name = obj->get_class(); + } set_text(" " + name); // An extra space so the text is not too close of the icon. set_tooltip(obj->get_class()); @@ -119,8 +130,9 @@ void EditorPath::_id_pressed(int p_idx) { ERR_FAIL_INDEX(p_idx, objects.size()); Object *obj = ObjectDB::get_instance(objects[p_idx]); - if (!obj) + if (!obj) { return; + } EditorNode::get_singleton()->push_item(obj); } diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp index f731a87cef..2365090f03 100644 --- a/editor/editor_plugin.cpp +++ b/editor/editor_plugin.cpp @@ -186,8 +186,9 @@ Array EditorInterface::get_open_scenes() const { int scns_amount = scenes.size(); for (int idx_scn = 0; idx_scn < scns_amount; idx_scn++) { - if (scenes[idx_scn].root == nullptr) + if (scenes[idx_scn].root == nullptr) { continue; + } ret.push_back(scenes[idx_scn].root->get_filename()); } return ret; @@ -250,10 +251,12 @@ EditorInspector *EditorInterface::get_inspector() const { } Error EditorInterface::save_scene() { - if (!get_edited_scene_root()) + if (!get_edited_scene_root()) { return ERR_CANT_CREATE; - if (get_edited_scene_root()->get_filename() == String()) + } + if (get_edited_scene_root()->get_filename() == String()) { return ERR_CANT_CREATE; + } save_scene_as(get_edited_scene_root()->get_filename()); return OK; @@ -481,8 +484,9 @@ void EditorPlugin::notify_scene_changed(const Node *scn_root) { } void EditorPlugin::notify_main_screen_changed(const String &screen_name) { - if (screen_name == last_main_screen_name) + if (screen_name == last_main_screen_name) { return; + } emit_signal("main_screen_changed", screen_name); last_main_screen_name = screen_name; @@ -639,8 +643,9 @@ void EditorPlugin::apply_changes() { void EditorPlugin::get_breakpoints(List<String> *p_breakpoints) { if (get_script_instance() && get_script_instance()->has_method("get_breakpoints")) { PackedStringArray arr = get_script_instance()->call("get_breakpoints"); - for (int i = 0; i < arr.size(); i++) + for (int i = 0; i < arr.size(); i++) { p_breakpoints->push_back(arr[i]); + } } } diff --git a/editor/editor_plugin_settings.cpp b/editor/editor_plugin_settings.cpp index 764d1af451..b5f1133a9e 100644 --- a/editor/editor_plugin_settings.cpp +++ b/editor/editor_plugin_settings.cpp @@ -146,8 +146,9 @@ void EditorPluginSettings::update_plugins() { } void EditorPluginSettings::_plugin_activity_changed() { - if (updating) + if (updating) { return; + } TreeItem *ti = plugin_list->get_edited(); ERR_FAIL_COND(!ti); @@ -172,8 +173,9 @@ void EditorPluginSettings::_create_clicked() { void EditorPluginSettings::_cell_button_pressed(Object *p_item, int p_column, int p_id) { TreeItem *item = Object::cast_to<TreeItem>(p_item); - if (!item) + if (!item) { return; + } if (p_id == BUTTON_PLUGIN_EDIT) { if (p_column == 4) { String dir = item->get_metadata(0); diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index e5ca5d95e8..81c4e48974 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -51,8 +51,9 @@ EditorPropertyNil::EditorPropertyNil() { ///////////////////// TEXT ///////////////////////// void EditorPropertyText::_text_entered(const String &p_string) { - if (updating) + if (updating) { return; + } if (text->has_focus()) { text->release_focus(); @@ -61,8 +62,9 @@ void EditorPropertyText::_text_entered(const String &p_string) { } void EditorPropertyText::_text_changed(const String &p_string) { - if (updating) + if (updating) { return; + } if (string_name) { emit_changed(get_edited_property(), StringName(p_string), "", true); @@ -366,16 +368,18 @@ void EditorPropertyMember::_property_select() { type = Variant::Type(i); } } - if (type != Variant::NIL) + if (type != Variant::NIL) { selector->select_method_from_basic_type(type, current); + } } else if (hint == MEMBER_METHOD_OF_BASE_TYPE) { selector->select_method_from_base_type(hint_text, current); } else if (hint == MEMBER_METHOD_OF_INSTANCE) { Object *instance = ObjectDB::get_instance(ObjectID(hint_text.to_int64())); - if (instance) + if (instance) { selector->select_method_from_instance(instance, current); + } } else if (hint == MEMBER_METHOD_OF_SCRIPT) { Object *obj = ObjectDB::get_instance(ObjectID(hint_text.to_int64())); @@ -386,24 +390,27 @@ void EditorPropertyMember::_property_select() { } else if (hint == MEMBER_PROPERTY_OF_VARIANT_TYPE) { Variant::Type type = Variant::NIL; String tname = hint_text; - if (tname.find(".") != -1) + if (tname.find(".") != -1) { tname = tname.get_slice(".", 0); + } for (int i = 0; i < Variant::VARIANT_MAX; i++) { if (tname == Variant::get_type_name(Variant::Type(i))) { type = Variant::Type(Variant::Type(i)); } } - if (type != Variant::NIL) + if (type != Variant::NIL) { selector->select_property_from_basic_type(type, current); + } } else if (hint == MEMBER_PROPERTY_OF_BASE_TYPE) { selector->select_property_from_base_type(hint_text, current); } else if (hint == MEMBER_PROPERTY_OF_INSTANCE) { Object *instance = ObjectDB::get_instance(ObjectID(hint_text.to_int64())); - if (instance) + if (instance) { selector->select_property_from_instance(instance, current); + } } else if (hint == MEMBER_PROPERTY_OF_SCRIPT) { Object *obj = ObjectDB::get_instance(ObjectID(hint_text.to_int64())); @@ -479,8 +486,9 @@ void EditorPropertyEnum::setup(const Vector<String> &p_options) { int64_t current_val = 0; for (int i = 0; i < p_options.size(); i++) { Vector<String> text_split = p_options[i].split(":"); - if (text_split.size() != 1) + if (text_split.size() != 1) { current_val = text_split[1].to_int64(); + } options->add_item(text_split[0]); options->set_item_metadata(i, current_val); current_val += 1; @@ -619,14 +627,16 @@ public: Color color = get_theme_color("highlight_color", "Editor"); for (int i = 0; i < 2; i++) { Point2 ofs(4, vofs); - if (i == 1) + if (i == 1) { ofs.y += bsize + 1; + } ofs += rect.position; for (int j = 0; j < 10; j++) { Point2 o = ofs + Point2(j * (bsize + 1), 0); - if (j >= 5) + if (j >= 5) { o.x += 1; + } uint32_t idx = i * 10 + j; bool on = value & (1 << idx); @@ -756,8 +766,9 @@ EditorPropertyLayers::EditorPropertyLayers() { ///////////////////// INT ///////////////////////// void EditorPropertyInteger::_value_changed(int64_t val) { - if (setting) + if (setting) { return; + } emit_changed(get_edited_property(), val); } @@ -802,8 +813,9 @@ void EditorPropertyObjectID::_edit_pressed() { void EditorPropertyObjectID::update_property() { String type = base_type; - if (type == "") + if (type == "") { type = "Object"; + } ObjectID id = get_edited_object()->get(get_edited_property()); if (id.is_valid()) { @@ -834,8 +846,9 @@ EditorPropertyObjectID::EditorPropertyObjectID() { ///////////////////// FLOAT ///////////////////////// void EditorPropertyFloat::_value_changed(double val) { - if (setting) + if (setting) { return; + } emit_changed(get_edited_property(), val); } @@ -898,15 +911,18 @@ void EditorPropertyEasing::_drag_easing(const Ref<InputEvent> &p_ev) { if (mm.is_valid() && mm->get_button_mask() & BUTTON_MASK_LEFT) { float rel = mm->get_relative().x; - if (rel == 0) + if (rel == 0) { return; + } - if (flip) + if (flip) { rel = -rel; + } float val = get_edited_object()->get(get_edited_property()); - if (val == 0) + if (val == 0) { return; + } bool sg = val < 0; val = Math::absf(val); @@ -915,8 +931,9 @@ void EditorPropertyEasing::_drag_easing(const Ref<InputEvent> &p_ev) { val += rel * 0.05; val = Math::pow(2.0f, val); - if (sg) + if (sg) { val = -val; + } emit_changed(get_edited_property(), val); easing_draw->update(); @@ -983,8 +1000,9 @@ void EditorPropertyEasing::_setup_spin() { } void EditorPropertyEasing::_spin_value_changed(double p_value) { - if (setting) + if (setting) { return; + } // 0 is a singularity, but both positive and negative values // are otherwise allowed. Enforce 0+ as workaround. @@ -1060,8 +1078,9 @@ EditorPropertyEasing::EditorPropertyEasing() { ///////////////////// VECTOR2 ///////////////////////// void EditorPropertyVector2::_value_changed(double val, const String &p_name) { - if (setting) + if (setting) { return; + } Vector2 v2; v2.x = spin[0]->get_value(); @@ -1141,8 +1160,9 @@ EditorPropertyVector2::EditorPropertyVector2(bool p_force_wide) { ///////////////////// RECT2 ///////////////////////// void EditorPropertyRect2::_value_changed(double val, const String &p_name) { - if (setting) + if (setting) { return; + } Rect2 r2; r2.position.x = spin[0]->get_value(); @@ -1226,8 +1246,9 @@ EditorPropertyRect2::EditorPropertyRect2(bool p_force_wide) { ///////////////////// VECTOR3 ///////////////////////// void EditorPropertyVector3::_value_changed(double val, const String &p_name) { - if (setting) + if (setting) { return; + } Vector3 v3; v3.x = spin[0]->get_value(); @@ -1309,8 +1330,9 @@ EditorPropertyVector3::EditorPropertyVector3(bool p_force_wide) { ///////////////////// VECTOR2i ///////////////////////// void EditorPropertyVector2i::_value_changed(double val, const String &p_name) { - if (setting) + if (setting) { return; + } Vector2i v2; v2.x = spin[0]->get_value(); @@ -1390,8 +1412,9 @@ EditorPropertyVector2i::EditorPropertyVector2i(bool p_force_wide) { ///////////////////// RECT2 ///////////////////////// void EditorPropertyRect2i::_value_changed(double val, const String &p_name) { - if (setting) + if (setting) { return; + } Rect2i r2; r2.position.x = spin[0]->get_value(); @@ -1475,8 +1498,9 @@ EditorPropertyRect2i::EditorPropertyRect2i(bool p_force_wide) { ///////////////////// VECTOR3 ///////////////////////// void EditorPropertyVector3i::_value_changed(double val, const String &p_name) { - if (setting) + if (setting) { return; + } Vector3i v3; v3.x = spin[0]->get_value(); @@ -1557,8 +1581,9 @@ EditorPropertyVector3i::EditorPropertyVector3i(bool p_force_wide) { ///////////////////// PLANE ///////////////////////// void EditorPropertyPlane::_value_changed(double val, const String &p_name) { - if (setting) + if (setting) { return; + } Plane p; p.normal.x = spin[0]->get_value(); @@ -1642,8 +1667,9 @@ EditorPropertyPlane::EditorPropertyPlane(bool p_force_wide) { ///////////////////// QUAT ///////////////////////// void EditorPropertyQuat::_value_changed(double val, const String &p_name) { - if (setting) + if (setting) { return; + } Quat p; p.x = spin[0]->get_value(); @@ -1724,8 +1750,9 @@ EditorPropertyQuat::EditorPropertyQuat() { ///////////////////// AABB ///////////////////////// void EditorPropertyAABB::_value_changed(double val, const String &p_name) { - if (setting) + if (setting) { return; + } AABB p; p.position.x = spin[0]->get_value(); @@ -1799,8 +1826,9 @@ EditorPropertyAABB::EditorPropertyAABB() { ///////////////////// TRANSFORM2D ///////////////////////// void EditorPropertyTransform2D::_value_changed(double val, const String &p_name) { - if (setting) + if (setting) { return; + } Transform2D p; p[0][0] = spin[0]->get_value(); @@ -1873,8 +1901,9 @@ EditorPropertyTransform2D::EditorPropertyTransform2D() { ///////////////////// BASIS ///////////////////////// void EditorPropertyBasis::_value_changed(double val, const String &p_name) { - if (setting) + if (setting) { return; + } Basis p; p[0][0] = spin[0]->get_value(); @@ -1953,8 +1982,9 @@ EditorPropertyBasis::EditorPropertyBasis() { ///////////////////// TRANSFORM ///////////////////////// void EditorPropertyTransform::_value_changed(double val, const String &p_name) { - if (setting) + if (setting) { return; + } Transform p; p.basis[0][0] = spin[0]->get_value(); @@ -2049,10 +2079,11 @@ void EditorPropertyColor::_popup_closed() { void EditorPropertyColor::_picker_created() { // 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) { picker->get_picker()->set_hsv_mode(true); - else if (default_color_mode == 2) + } else if (default_color_mode == 2) { picker->get_picker()->set_raw_mode(true); + } } void EditorPropertyColor::_bind_methods() { @@ -2263,8 +2294,9 @@ void EditorPropertyResource::_file_selected(const String &p_path) { } } - if (!any_type_matches) + if (!any_type_matches) { EditorNode::get_singleton()->show_warning(vformat(TTR("The selected resource (%s) does not match any type expected for this property (%s)."), res->get_class(), property_types)); + } } emit_changed(get_edited_property(), res); @@ -2316,8 +2348,9 @@ void EditorPropertyResource::_menu_option(int p_which) { case OBJ_MENU_MAKE_UNIQUE: { RES res_orig = get_edited_object()->get(get_edited_property()); - if (res_orig.is_null()) + if (res_orig.is_null()) { return; + } List<PropertyInfo> property_list; res_orig->get_property_list(&property_list); @@ -2354,8 +2387,9 @@ void EditorPropertyResource::_menu_option(int p_which) { case OBJ_MENU_SAVE: { RES res = get_edited_object()->get(get_edited_property()); - if (res.is_null()) + if (res.is_null()) { return; + } EditorNode::get_singleton()->save_resource(res); } break; @@ -2556,20 +2590,23 @@ void EditorPropertyResource::_update_menu_items() { for (int j = 0; j < custom_resources.size(); j++) { if (custom_resources[j].name == t) { is_custom_resource = true; - if (custom_resources[j].icon.is_valid()) + if (custom_resources[j].icon.is_valid()) { icon = custom_resources[j].icon; + } break; } } } - if (!is_custom_resource && !(ScriptServer::is_global_class(t) || ClassDB::can_instance(t))) + if (!is_custom_resource && !(ScriptServer::is_global_class(t) || ClassDB::can_instance(t))) { continue; + } inheritors_array.push_back(t); - if (!icon.is_valid()) + if (!icon.is_valid()) { icon = get_theme_icon(has_theme_icon(t, "EditorIcons") ? t : "Object", "EditorIcons"); + } int id = TYPE_BASE_ID + idx; menu->add_icon_item(icon, vformat(TTR("New %s"), t), id); @@ -2578,8 +2615,9 @@ void EditorPropertyResource::_update_menu_items() { } } - if (menu->get_item_count()) + if (menu->get_item_count()) { menu->add_separator(); + } } menu->add_icon_item(get_theme_icon("Load", "EditorIcons"), TTR("Load"), OBJ_MENU_LOAD); @@ -2599,14 +2637,16 @@ void EditorPropertyResource::_update_menu_items() { RES cb = EditorSettings::get_singleton()->get_resource_clipboard(); bool paste_valid = false; if (cb.is_valid()) { - if (base_type == "") + if (base_type == "") { paste_valid = true; - else - for (int i = 0; i < base_type.get_slice_count(","); i++) + } else { + for (int i = 0; i < base_type.get_slice_count(","); i++) { if (ClassDB::is_parent_class(cb->get_class(), base_type.get_slice(",", i))) { paste_valid = true; break; } + } + } } if (!res.is_null() || paste_valid) { @@ -2691,8 +2731,9 @@ void EditorPropertyResource::_fold_other_editors(Object *p_self) { RES res = get_edited_object()->get(get_edited_property()); - if (!res.is_valid()) + if (!res.is_valid()) { return; + } bool use_editor = false; for (int i = 0; i < EditorNode::get_editor_data().get_editor_plugin_count(); i++) { EditorPlugin *ep = EditorNode::get_editor_data().get_editor_plugin(i); @@ -2701,8 +2742,9 @@ void EditorPropertyResource::_fold_other_editors(Object *p_self) { } } - if (!use_editor) + if (!use_editor) { return; + } bool unfolded = get_edited_object()->editor_is_section_unfolded(get_edited_property()); opened_editor = false; diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp index cf2104bc08..51fac6acec 100644 --- a/editor/editor_properties_array_dict.cpp +++ b/editor/editor_properties_array_dict.cpp @@ -501,15 +501,17 @@ void EditorPropertyArray::_edit_pressed() { } void EditorPropertyArray::_page_changed(double p_page) { - if (updating) + if (updating) { return; + } page_idx = p_page; update_property(); } void EditorPropertyArray::_length_changed(double p_page) { - if (updating) + if (updating) { return; + } Variant array = object->get_array(); int previous_size = array.call("size"); @@ -1051,8 +1053,9 @@ void EditorPropertyDictionary::_edit_pressed() { } void EditorPropertyDictionary::_page_changed(double p_page) { - if (updating) + if (updating) { return; + } page_idx = p_page; update_property(); } diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp index d389a076b7..7ac8fae156 100644 --- a/editor/editor_resource_preview.cpp +++ b/editor/editor_resource_preview.cpp @@ -61,8 +61,9 @@ Ref<Texture2D> EditorResourcePreviewGenerator::generate_from_path(const String & } RES res = ResourceLoader::load(p_path); - if (!res.is_valid()) + if (!res.is_valid()) { return res; + } return generate(res, p_size); } @@ -131,10 +132,11 @@ void EditorResourcePreview::_preview_ready(const String &p_str, const Ref<Textur void EditorResourcePreview::_generate_preview(Ref<ImageTexture> &r_texture, Ref<ImageTexture> &r_small_texture, const QueueItem &p_item, const String &cache_base) { String type; - if (p_item.resource.is_valid()) + if (p_item.resource.is_valid()) { type = p_item.resource->get_class(); - else + } else { type = ResourceLoader::get_resource_type(p_item.path); + } if (type == "") { r_texture = Ref<ImageTexture>(); @@ -149,8 +151,9 @@ void EditorResourcePreview::_generate_preview(Ref<ImageTexture> &r_texture, Ref< r_small_texture = Ref<ImageTexture>(); for (int i = 0; i < preview_generators.size(); i++) { - if (!preview_generators[i]->handles(type)) + if (!preview_generators[i]->handles(type)) { continue; + } Ref<Texture2D> generated; if (p_item.resource.is_valid()) { diff --git a/editor/editor_run.cpp b/editor/editor_run.cpp index 00befb89f2..1148a6c7ec 100644 --- a/editor/editor_run.cpp +++ b/editor/editor_run.cpp @@ -156,8 +156,9 @@ Error EditorRun::run(const String &p_scene, const String &p_custom_args, const L String bpoints; for (const List<String>::Element *E = p_breakpoints.front(); E; E = E->next()) { bpoints += E->get().replace(" ", "%20"); - if (E->next()) + if (E->next()) { bpoints += ","; + } } args.push_back(bpoints); @@ -201,8 +202,9 @@ Error EditorRun::run(const String &p_scene, const String &p_custom_args, const L bool EditorRun::has_child_process(OS::ProcessID p_pid) const { for (const List<OS::ProcessID>::Element *E = pids.front(); E; E = E->next()) { - if (E->get() == p_pid) + if (E->get() == p_pid) { return true; + } } return false; } diff --git a/editor/editor_run_native.cpp b/editor/editor_run_native.cpp index 16b8d6d110..9a834977fd 100644 --- a/editor/editor_run_native.cpp +++ b/editor/editor_run_native.cpp @@ -38,8 +38,9 @@ void EditorRunNative::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { for (int i = 0; i < EditorExport::get_singleton()->get_export_platform_count(); i++) { Ref<EditorExportPlatform> eep = EditorExport::get_singleton()->get_export_platform(i); - if (eep.is_null()) + if (eep.is_null()) { continue; + } Ref<ImageTexture> icon = eep->get_run_icon(); if (!icon.is_null()) { Ref<Image> im = icon->get_data(); @@ -133,14 +134,18 @@ void EditorRunNative::_run_native(int p_idx, int p_platform) { bool debug_collisions = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_collisons", false); bool debug_navigation = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_navigation", false); - if (deploy_debug_remote) + if (deploy_debug_remote) { flags |= EditorExportPlatform::DEBUG_FLAG_REMOTE_DEBUG; - if (deploy_dumb) + } + if (deploy_dumb) { flags |= EditorExportPlatform::DEBUG_FLAG_DUMB_CLIENT; - if (debug_collisions) + } + if (debug_collisions) { flags |= EditorExportPlatform::DEBUG_FLAG_VIEW_COLLISONS; - if (debug_navigation) + } + if (debug_navigation) { flags |= EditorExportPlatform::DEBUG_FLAG_VIEW_NAVIGATION; + } eep->run(preset, p_idx, flags); } diff --git a/editor/editor_sectioned_inspector.cpp b/editor/editor_sectioned_inspector.cpp index c5e0c091e8..eabbf6b0d8 100644 --- a/editor/editor_sectioned_inspector.cpp +++ b/editor/editor_sectioned_inspector.cpp @@ -40,8 +40,9 @@ class SectionedInspectorFilter : public Object { bool allow_sub; bool _set(const StringName &p_name, const Variant &p_value) { - if (!edited) + if (!edited) { return false; + } String name = p_name; if (section != "") { @@ -54,8 +55,9 @@ class SectionedInspectorFilter : public Object { } bool _get(const StringName &p_name, Variant &r_ret) const { - if (!edited) + if (!edited) { return false; + } String name = p_name; if (section != "") { @@ -68,8 +70,9 @@ class SectionedInspectorFilter : public Object { return valid; } void _get_property_list(List<PropertyInfo> *p_list) const { - if (!edited) + if (!edited) { return; + } List<PropertyInfo> pinfo; edited->get_property_list(&pinfo); @@ -77,8 +80,9 @@ class SectionedInspectorFilter : public Object { PropertyInfo pi = E->get(); int sp = pi.name.find("/"); - if (pi.name == "resource_path" || pi.name == "resource_name" || pi.name == "resource_local_to_scene" || pi.name.begins_with("script/") || pi.name.begins_with("_global_script")) //skip resource stuff + if (pi.name == "resource_path" || pi.name == "resource_name" || pi.name == "resource_local_to_scene" || pi.name.begins_with("script/") || pi.name.begins_with("_global_script")) { //skip resource stuff continue; + } if (sp == -1) { pi.name = "global/" + pi.name; @@ -86,8 +90,9 @@ class SectionedInspectorFilter : public Object { if (pi.name.begins_with(section + "/")) { pi.name = pi.name.replace_first(section + "/", ""); - if (!allow_sub && pi.name.find("/") != -1) + if (!allow_sub && pi.name.find("/") != -1) { continue; + } p_list->push_back(pi); } } @@ -129,8 +134,9 @@ void SectionedInspector::_bind_methods() { } void SectionedInspector::_section_selected() { - if (!sections->get_selected()) + if (!sections->get_selected()) { return; + } selected_category = sections->get_selected()->get_metadata(0); filter->set_section(selected_category, sections->get_selected()->get_children() == nullptr); @@ -144,19 +150,21 @@ void SectionedInspector::set_current_section(const String &p_section) { } String SectionedInspector::get_current_section() const { - if (sections->get_selected()) + if (sections->get_selected()) { return sections->get_selected()->get_metadata(0); - else + } else { return ""; + } } String SectionedInspector::get_full_item_path(const String &p_item) { String base = get_current_section(); - if (base != "") + if (base != "") { return base + "/" + p_item; - else + } else { return p_item; + } } void SectionedInspector::edit(Object *p_object) { @@ -183,8 +191,9 @@ void SectionedInspector::edit(Object *p_object) { TreeItem *first_item = sections->get_root(); if (first_item) { - while (first_item->get_children()) + while (first_item->get_children()) { first_item = first_item->get_children(); + } first_item->select(0); selected_category = first_item->get_metadata(0); @@ -199,8 +208,9 @@ void SectionedInspector::update_category_list() { Object *o = ObjectDB::get_instance(obj); - if (!o) + if (!o) { return; + } List<PropertyInfo> pinfo; o->get_property_list(&pinfo); @@ -211,26 +221,31 @@ void SectionedInspector::update_category_list() { section_map[""] = root; String filter; - if (search_box) + if (search_box) { filter = search_box->get_text(); + } for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { PropertyInfo pi = E->get(); - if (pi.usage & PROPERTY_USAGE_CATEGORY) + if (pi.usage & PROPERTY_USAGE_CATEGORY) { continue; - else if (!(pi.usage & PROPERTY_USAGE_EDITOR)) + } else if (!(pi.usage & PROPERTY_USAGE_EDITOR)) { continue; + } - if (pi.name.find(":") != -1 || pi.name == "script" || pi.name == "resource_name" || pi.name == "resource_path" || pi.name == "resource_local_to_scene" || pi.name.begins_with("_global_script")) + if (pi.name.find(":") != -1 || pi.name == "script" || pi.name == "resource_name" || pi.name == "resource_path" || pi.name == "resource_local_to_scene" || pi.name.begins_with("_global_script")) { continue; + } - if (!filter.empty() && !filter.is_subsequence_ofi(pi.name) && !filter.is_subsequence_ofi(pi.name.replace("/", " ").capitalize())) + if (!filter.empty() && !filter.is_subsequence_ofi(pi.name) && !filter.is_subsequence_ofi(pi.name.replace("/", " ").capitalize())) { continue; + } int sp = pi.name.find("/"); - if (sp == -1) + if (sp == -1) { pi.name = "global/" + pi.name; + } Vector<String> sectionarr = pi.name.split("/"); String metasection; diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index bbb4881d14..a16605ab44 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -129,8 +129,9 @@ bool EditorSettings::_get(const StringName &p_name, Variant &r_ret) const { } Ref<InputEvent> original = sc->get_meta("original"); - if (sc->is_shortcut(original) || (original.is_null() && sc->get_shortcut().is_null())) + if (sc->is_shortcut(original) || (original.is_null() && sc->get_shortcut().is_null())) { continue; //not changed from default, don't save + } } arr.push_back(E->key()); @@ -174,8 +175,9 @@ void EditorSettings::_get_property_list(List<PropertyInfo> *p_list) const { while ((k = props.next(k))) { const VariantContainer *v = props.getptr(*k); - if (v->hide_from_editor) + if (v->hide_from_editor) { continue; + } _EVCSort vc; vc.name = *k; @@ -206,8 +208,9 @@ void EditorSettings::_get_property_list(List<PropertyInfo> *p_list) const { PropertyInfo pi(E->get().type, E->get().name); pi.usage = pinfo; - if (hints.has(E->get().name)) + if (hints.has(E->get().name)) { pi = hints[E->get().name]; + } if (E->get().restart_if_changed) { pi.usage |= PROPERTY_USAGE_RESTART_IF_CHANGED; @@ -229,10 +232,12 @@ void EditorSettings::_add_property_info_bind(const Dictionary &p_info) { pinfo.type = Variant::Type(p_info["type"].operator int()); ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX); - if (p_info.has("hint")) + if (p_info.has("hint")) { pinfo.hint = PropertyHint(p_info["hint"].operator int()); - if (p_info.has("hint_string")) + } + if (p_info.has("hint_string")) { pinfo.hint_string = p_info["hint_string"]; + } add_property_hint(pinfo); } @@ -241,8 +246,9 @@ void EditorSettings::_add_property_info_bind(const Dictionary &p_info) { bool EditorSettings::has_default_value(const String &p_setting) const { _THREAD_SAFE_METHOD_ - if (!props.has(p_setting)) + if (!props.has(p_setting)) { return false; + } return props[p_setting].has_default_value; } @@ -757,8 +763,9 @@ EditorSettings *EditorSettings::get_singleton() { } void EditorSettings::create() { - if (singleton.ptr()) + if (singleton.ptr()) { return; //pointless + } DirAccess *dir = nullptr; @@ -889,8 +896,9 @@ void EditorSettings::create() { dir->change_dir("projects"); String project_config_dir = ProjectSettings::get_singleton()->get_resource_path(); - if (project_config_dir.ends_with("/")) + if (project_config_dir.ends_with("/")) { project_config_dir = config_path.substr(0, project_config_dir.size() - 1); + } project_config_dir = project_config_dir.get_file() + "-" + project_config_dir.md5_text(); if (dir->change_dir(project_config_dir) != OK) { @@ -959,8 +967,9 @@ fail: void EditorSettings::setup_language() { String lang = get("interface/editor/editor_language"); - if (lang == "en") + if (lang == "en") { return; // Default, nothing to do. + } // Load editor translation for configured/detected locale. EditorTranslationList *etl = _editor_translations; @@ -1021,16 +1030,20 @@ void EditorSettings::setup_network() { String ip = E->get(); // link-local IPv6 addresses don't work, skipping them - if (ip.begins_with("fe80:0:0:0:")) // fe80::/64 + if (ip.begins_with("fe80:0:0:0:")) { // fe80::/64 continue; + } // Same goes for IPv4 link-local (APIPA) addresses. - if (ip.begins_with("169.254.")) // 169.254.0.0/16 + if (ip.begins_with("169.254.")) { // 169.254.0.0/16 continue; + } // Select current IP (found) - if (ip == current) + if (ip == current) { selected = ip; - if (hint != "") + } + if (hint != "") { hint += ","; + } hint += ip; } @@ -1043,8 +1056,9 @@ void EditorSettings::setup_network() { void EditorSettings::save() { //_THREAD_SAFE_METHOD_ - if (!singleton.ptr()) + if (!singleton.ptr()) { return; + } if (singleton->config_file_path == "") { ERR_PRINT("Cannot save EditorSettings config, no valid path"); @@ -1061,8 +1075,9 @@ void EditorSettings::save() { } void EditorSettings::destroy() { - if (!singleton.ptr()) + if (!singleton.ptr()) { return; + } save(); singleton = Ref<EditorSettings>(); } @@ -1105,16 +1120,18 @@ void EditorSettings::raise_order(const String &p_setting) { void EditorSettings::set_restart_if_changed(const StringName &p_setting, bool p_restart) { _THREAD_SAFE_METHOD_ - if (!props.has(p_setting)) + if (!props.has(p_setting)) { return; + } props[p_setting].restart_if_changed = p_restart; } void EditorSettings::set_initial_value(const StringName &p_setting, const Variant &p_value, bool p_update_current) { _THREAD_SAFE_METHOD_ - if (!props.has(p_setting)) + if (!props.has(p_setting)) { return; + } props[p_setting].initial = p_value; props[p_setting].has_default_value = true; if (p_update_current) { @@ -1144,18 +1161,21 @@ Variant _EDITOR_GET(const String &p_setting) { } bool EditorSettings::property_can_revert(const String &p_setting) { - if (!props.has(p_setting)) + if (!props.has(p_setting)) { return false; + } - if (!props[p_setting].has_default_value) + if (!props[p_setting].has_default_value) { return false; + } return props[p_setting].initial != props[p_setting].variant; } Variant EditorSettings::property_get_revert(const String &p_setting) { - if (!props.has(p_setting) || !props[p_setting].has_default_value) + if (!props.has(p_setting) || !props[p_setting].has_default_value) { return Variant(); + } return props[p_setting].initial; } @@ -1235,8 +1255,9 @@ void EditorSettings::set_favorites(const Vector<String> &p_favorites) { favorites = p_favorites; FileAccess *f = FileAccess::open(get_project_settings_dir().plus_file("favorites"), FileAccess::WRITE); if (f) { - for (int i = 0; i < favorites.size(); i++) + for (int i = 0; i < favorites.size(); i++) { f->store_line(favorites[i]); + } memdelete(f); } } @@ -1249,8 +1270,9 @@ void EditorSettings::set_recent_dirs(const Vector<String> &p_recent_dirs) { recent_dirs = p_recent_dirs; FileAccess *f = FileAccess::open(get_project_settings_dir().plus_file("recent_dirs"), FileAccess::WRITE); if (f) { - for (int i = 0; i < recent_dirs.size(); i++) + for (int i = 0; i < recent_dirs.size(); i++) { f->store_line(recent_dirs[i]); + } memdelete(f); } } @@ -1448,8 +1470,9 @@ bool EditorSettings::is_shortcut(const String &p_name, const Ref<InputEvent> &p_ Ref<ShortCut> EditorSettings::get_shortcut(const String &p_name) const { const Map<String, Ref<ShortCut>>::Element *E = shortcuts.find(p_name); - if (!E) + if (!E) { return Ref<ShortCut>(); + } return E->get(); } diff --git a/editor/editor_settings.h b/editor/editor_settings.h index 755d46f11b..13aebb7ea6 100644 --- a/editor/editor_settings.h +++ b/editor/editor_settings.h @@ -138,10 +138,11 @@ public: void set_initial_value(const StringName &p_setting, const Variant &p_value, bool p_update_current = false); void set_restart_if_changed(const StringName &p_setting, bool p_restart); void set_manually(const StringName &p_setting, const Variant &p_value, bool p_emit_signal = false) { - if (p_emit_signal) + if (p_emit_signal) { _set(p_setting, p_value); - else + } else { _set_only(p_setting, p_value); + } } bool property_can_revert(const String &p_setting); Variant property_get_revert(const String &p_setting); diff --git a/editor/editor_spin_slider.cpp b/editor/editor_spin_slider.cpp index e19fcfd55c..39e6746797 100644 --- a/editor/editor_spin_slider.cpp +++ b/editor/editor_spin_slider.cpp @@ -47,8 +47,9 @@ String EditorSpinSlider::get_text_value() const { } void EditorSpinSlider::_gui_input(const Ref<InputEvent> &p_event) { - if (read_only) + if (read_only) { return; + } Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid()) { @@ -84,8 +85,9 @@ void EditorSpinSlider::_gui_input(const Ref<InputEvent> &p_event) { } } } else if (mb->get_button_index() == BUTTON_WHEEL_UP || mb->get_button_index() == BUTTON_WHEEL_DOWN) { - if (grabber->is_visible()) + if (grabber->is_visible()) { call_deferred("update"); + } } } @@ -169,8 +171,9 @@ void EditorSpinSlider::_grabber_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseMotion> mm = p_event; if (mm.is_valid() && grabbing_grabber) { - if (mousewheel_over_grabber) + if (mousewheel_over_grabber) { return; + } float grabbing_ofs = (grabber->get_transform().xform(mm->get_position()).x - grabbing_from) / float(grabber_range); set_as_ratio(grabbing_ratio + grabbing_ofs); @@ -361,8 +364,9 @@ void EditorSpinSlider::_evaluate_input_text() { } Variant v = expr->execute(Array(), nullptr, false); - if (v.get_type() == Variant::NIL) + if (v.get_type() == Variant::NIL) { return; + } set_value(v); } @@ -381,8 +385,9 @@ void EditorSpinSlider::_value_input_closed() { //focus_exited signal void EditorSpinSlider::_value_focus_exited() { // discontinue because the focus_exit was caused by right-click context menu - if (value_input->get_menu()->is_visible()) + if (value_input->get_menu()->is_visible()) { return; + } _evaluate_input_text(); // focus is not on the same element after the vlalue_input was exited diff --git a/editor/editor_sub_scene.cpp b/editor/editor_sub_scene.cpp index 2170fd6380..a9b1a28092 100644 --- a/editor/editor_sub_scene.cpp +++ b/editor/editor_sub_scene.cpp @@ -47,17 +47,20 @@ void EditorSubScene::_path_changed(const String &p_path) { scene = nullptr; } - if (p_path == "") + if (p_path == "") { return; + } Ref<PackedScene> ps = ResourceLoader::load(p_path, "PackedScene"); - if (ps.is_null()) + if (ps.is_null()) { return; + } scene = ps->instance(); - if (!scene) + if (!scene) { return; + } _fill_tree(scene, nullptr); } @@ -84,8 +87,9 @@ void EditorSubScene::_fill_tree(Node *p_node, TreeItem *p_parent) { for (int i = 0; i < p_node->get_child_count(); i++) { Node *c = p_node->get_child(i); - if (c->get_owner() != scene) + if (c->get_owner() != scene) { continue; + } _fill_tree(c, it); } } @@ -108,8 +112,9 @@ void EditorSubScene::_item_multi_selected(Object *p_object, int p_cell, bool p_s Node *n = item->get_metadata(0); - if (!n) + if (!n) { return; + } if (p_selected) { if (n == scene) { is_root = true; @@ -119,8 +124,9 @@ void EditorSubScene::_item_multi_selected(Object *p_object, int p_cell, bool p_s } else { List<Node *>::Element *E = selection.find(n); - if (E) + if (E) { selection.erase(E); + } } } } diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index a6ba624b64..4fdc3dc080 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -63,8 +63,9 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory // Create a tree item for the subdirectory. TreeItem *subdirectory_item = tree->create_item(p_parent); String dname = p_dir->get_name(); - if (dname == "") + if (dname == "") { dname = "res://"; + } subdirectory_item->set_text(0, dname); subdirectory_item->set_icon(0, get_theme_icon("Folder", "EditorIcons")); @@ -86,8 +87,9 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory } // Create items for all subdirectories. - for (int i = 0; i < p_dir->get_subdir_count(); i++) + for (int i = 0; i < p_dir->get_subdir_count(); i++) { parent_should_expand = (_create_tree(subdirectory_item, p_dir->get_subdir(i), uncollapsed_paths, p_select_in_favorites, p_unfold_path) || parent_should_expand); + } // Create all items for the files in the subdirectory. if (display_mode == DISPLAY_MODE_TREE_ONLY) { @@ -195,8 +197,9 @@ void FileSystemDock::_update_tree(const Vector<String> &p_uncollapsed_paths, boo Vector<String> favorite_paths = EditorSettings::get_singleton()->get_favorites(); for (int i = 0; i < favorite_paths.size(); i++) { String fave = favorite_paths[i]; - if (!fave.begins_with("res://")) + if (!fave.begins_with("res://")) { continue; + } Ref<Texture2D> folder_icon = get_theme_icon("Folder", "EditorIcons"); const Color folder_color = get_theme_color("folder_icon_modulate", "FileDialog"); @@ -297,8 +300,9 @@ void FileSystemDock::_update_display_mode(bool p_force) { void FileSystemDock::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { - if (initialized) + if (initialized) { return; + } initialized = true; EditorFeatureProfileManager::get_singleton()->connect("current_feature_profile_changed", callable_mp(this, &FileSystemDock::_feature_profile_changed)); @@ -349,8 +353,9 @@ void FileSystemDock::_notification(int p_what) { Dictionary dd = get_viewport()->gui_get_drag_data(); if (tree->is_visible_in_tree() && dd.has("type")) { if (dd.has("favorite")) { - if ((String(dd["favorite"]) == "all")) + if ((String(dd["favorite"]) == "all")) { tree->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN); + } } else if ((String(dd["type"]) == "files") || (String(dd["type"]) == "files_and_dirs") || (String(dd["type"]) == "resource")) { tree->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM | Tree::DROP_MODE_INBETWEEN); } @@ -404,13 +409,15 @@ void FileSystemDock::_tree_multi_selected(Object *p_item, int p_column, bool p_s call_deferred("_update_import_dock"); // Return if we don't select something new. - if (!p_selected) + if (!p_selected) { return; + } // Tree item selected. TreeItem *selected = tree->get_selected(); - if (!selected) + if (!selected) { return; + } TreeItem *favorites_item = tree->get_root()->get_children(); if (selected->get_parent() == favorites_item && !String(selected->get_metadata(0)).ends_with("/")) { @@ -432,10 +439,11 @@ void FileSystemDock::_tree_multi_selected(Object *p_item, int p_column, bool p_s } String FileSystemDock::get_selected_path() const { - if (path.ends_with("/")) + if (path.ends_with("/")) { return path; - else + } else { return path.get_base_dir(); + } } String FileSystemDock::get_current_path() const { @@ -504,8 +512,9 @@ void FileSystemDock::_file_list_thumbnail_done(const String &p_path, const Ref<T String file = uarr[1]; if (idx < files->get_item_count() && files->get_item_text(idx) == file && files->get_item_metadata(idx) == p_path) { if (file_list_display_mode == FILE_LIST_DISPLAY_LIST) { - if (p_small_preview.is_valid()) + if (p_small_preview.is_valid()) { files->set_item_icon(idx, p_small_preview); + } } else { files->set_item_icon(idx, p_preview); } @@ -563,8 +572,9 @@ bool FileSystemDock::_is_file_type_disabled_by_feature_profile(const StringName } void FileSystemDock::_search(EditorFileSystemDirectory *p_path, List<FileInfo> *matches, int p_max_items) { - if (matches->size() > p_max_items) + if (matches->size() > p_max_items) { return; + } for (int i = 0; i < p_path->get_subdir_count(); i++) { _search(p_path->get_subdir(i), matches, p_max_items); @@ -586,8 +596,9 @@ void FileSystemDock::_search(EditorFileSystemDirectory *p_path, List<FileInfo> * } matches->push_back(fi); - if (matches->size() > p_max_items) + if (matches->size() > p_max_items) { return; + } } } } @@ -597,8 +608,9 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { Set<String> cselection; if (p_keep_selection) { for (int i = 0; i < files->get_item_count(); i++) { - if (files->is_selected(i)) + if (files->is_selected(i)) { cselection.insert(files->get_item_text(i)); + } } } @@ -701,8 +713,9 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { file = path.get_file(); efd = EditorFileSystem::get_singleton()->get_filesystem_path(directory); } - if (!efd) + if (!efd) { return; + } if (searched_string.length() > 0) { // Display the search results. @@ -714,8 +727,9 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { files->add_item("..", folder_icon, true); String bd = directory.get_base_dir(); - if (bd != "res://" && !bd.ends_with("/")) + if (bd != "res://" && !bd.ends_with("/")) { bd += "/"; + } files->set_item_metadata(files->get_item_count() - 1, bd); files->set_item_selectable(files->get_item_count() - 1, false); @@ -801,8 +815,9 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { } // Select the items. - if (cselection.has(fname)) + if (cselection.has(fname)) { files->select(item_index, false); + } if (!p_keep_selection && file != "" && fname == file) { files->select(item_index, true); @@ -902,15 +917,17 @@ void FileSystemDock::_set_scanning_mode() { } void FileSystemDock::_fw_history() { - if (history_pos < history.size() - 1) + if (history_pos < history.size() - 1) { history_pos++; + } _update_history(); } void FileSystemDock::_bw_history() { - if (history_pos > 0) + if (history_pos > 0) { history_pos--; + } _update_history(); } @@ -950,8 +967,9 @@ void FileSystemDock::_push_to_history() { } void FileSystemDock::_get_all_items_in_dir(EditorFileSystemDirectory *efsd, Vector<String> &files, Vector<String> &folders) const { - if (efsd == nullptr) + if (efsd == nullptr) { return; + } for (int i = 0; i < efsd->get_subdir_count(); i++) { folders.push_back(efsd->get_subdir(i)->get_path()); @@ -1106,8 +1124,9 @@ void FileSystemDock::_update_resource_paths_after_move(const Map<String, String> for (int i = 0; i < EditorNode::get_editor_data().get_edited_scene_count(); i++) { String path; if (i == EditorNode::get_editor_data().get_edited_scene()) { - if (!get_tree()->get_edited_scene_root()) + if (!get_tree()->get_edited_scene_root()) { continue; + } path = get_tree()->get_edited_scene_root()->get_filename(); } else { @@ -1138,8 +1157,9 @@ void FileSystemDock::_update_dependencies_after_move(const Map<String, String> & print_verbose("Remapping dependencies for: " + file); Error err = ResourceLoader::rename_dependencies(file, p_renames); if (err == OK) { - if (ResourceLoader::get_resource_type(file) == "PackedScene") + if (ResourceLoader::get_resource_type(file) == "PackedScene") { editor->reload_scene(file); + } } else { EditorNode::get_singleton()->add_io_error(TTR("Unable to update dependencies:") + "\n" + remaps[i] + "\n"); } @@ -1267,8 +1287,9 @@ void FileSystemDock::_make_scene_confirm() { break; } } - if (!extension_correct) + if (!extension_correct) { scene_name = scene_name.get_basename() + ".tscn"; + } scene_name = directory.plus_file(scene_name); @@ -1621,8 +1642,9 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } EditorSettings::get_singleton()->set_favorites(favorites); _update_tree(_compute_uncollapsed_paths()); - if (path == "Favorites") + if (path == "Favorites") { _update_file_list(true); + } } break; case FILE_DEPENDENCIES: { @@ -1807,10 +1829,11 @@ void FileSystemDock::_search_changed(const String &p_text, const Control *p_from searched_string = p_text.to_lower(); - if (p_from == tree_search_box) + if (p_from == tree_search_box) { file_list_search_box->set_text(searched_string); - else // File_list_search_box. + } else { // File_list_search_box. tree_search_box->set_text(searched_string); + } bool unfold_path = (p_text == String() && path != String()); switch (display_mode) { @@ -1843,8 +1866,9 @@ void FileSystemDock::focus_on_filter() { } void FileSystemDock::set_file_list_display_mode(FileListDisplayMode p_mode) { - if (p_mode == file_list_display_mode) + if (p_mode == file_list_display_mode) { return; + } _toggle_file_display(); } @@ -1885,8 +1909,9 @@ Variant FileSystemDock::get_drag_data_fw(const Point2 &p_point, Control *p_from) all_not_favorites = true; } - if (paths.empty()) + if (paths.empty()) { return Variant(); + } Dictionary drag_data = EditorNode::get_singleton()->drag_files_and_dirs(paths, p_from); if (!all_not_favorites) { @@ -1905,8 +1930,9 @@ bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_da // Moving favorite around. TreeItem *ti = tree->get_item_at_position(p_point); - if (!ti) + if (!ti) { return false; + } int drop_section = tree->get_drop_section_at_position(p_point); TreeItem *favorites_item = tree->get_root()->get_children(); @@ -1940,19 +1966,22 @@ bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_da bool favorite; _get_drag_target_folder(to_dir, favorite, p_point, p_from); - if (favorite) + if (favorite) { return true; + } - if (to_dir.empty()) + if (to_dir.empty()) { return false; + } // Attempting to move a folder into itself will fail later, // rather than bring up a message don't try to do it in the first place. to_dir = to_dir.ends_with("/") ? to_dir : (to_dir + "/"); Vector<String> fnames = drag_data["files"]; for (int i = 0; i < fnames.size(); ++i) { - if (fnames[i].ends_with("/") && to_dir.begins_with(fnames[i])) + if (fnames[i].ends_with("/") && to_dir.begins_with(fnames[i])) { return false; + } } return true; @@ -1962,8 +1991,9 @@ bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_da } void FileSystemDock::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 drag_data = p_data; Vector<String> dirs = EditorSettings::get_singleton()->get_favorites(); @@ -1974,8 +2004,9 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data, } // Moving favorite around. TreeItem *ti = tree->get_item_at_position(p_point); - if (!ti) + if (!ti) { return; + } int drop_section = tree->get_drop_section_at_position(p_point); int drop_position; @@ -2022,8 +2053,9 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data, EditorSettings::get_singleton()->set_favorites(dirs); _update_tree(_compute_uncollapsed_paths()); - if (display_mode == DISPLAY_MODE_SPLIT && path == "Favorites") + if (display_mode == DISPLAY_MODE_SPLIT && path == "Favorites") { _update_file_list(true); + } return; } @@ -2282,8 +2314,9 @@ void FileSystemDock::_file_list_rmb_select(int p_item, const Vector2 &p_pos) { // Right click is pressed in the file list. Vector<String> paths; for (int i = 0; i < files->get_item_count(); i++) { - if (!files->is_selected(i)) + if (!files->is_selected(i)) { continue; + } if (files->get_item_text(p_item) == "..") { files->unselect(i); continue; @@ -2303,8 +2336,9 @@ void FileSystemDock::_file_list_rmb_select(int p_item, const Vector2 &p_pos) { void FileSystemDock::_file_list_rmb_pressed(const Vector2 &p_pos) { // Right click on empty space for file list. - if (searched_string.length() > 0) + if (searched_string.length() > 0) { return; + } file_list_popup->clear(); file_list_popup->set_size(Size2(1, 1)); @@ -2372,8 +2406,9 @@ void FileSystemDock::_file_list_gui_input(Ref<InputEvent> p_event) { } void FileSystemDock::_update_import_dock() { - if (!import_dock_needs_update) + if (!import_dock_needs_update) { return; + } // List selected. Vector<String> selected; @@ -2384,8 +2419,9 @@ void FileSystemDock::_update_import_dock() { } else { // Use the file list. for (int i = 0; i < files->get_item_count(); i++) { - if (!files->is_selected(i)) + if (!files->is_selected(i)) { continue; + } selected.push_back(files->get_item_metadata(i)); } diff --git a/editor/find_in_files.cpp b/editor/find_in_files.cpp index b2a8f7dba4..1bc0de1ab0 100644 --- a/editor/find_in_files.cpp +++ b/editor/find_in_files.cpp @@ -64,8 +64,9 @@ static bool find_next(const String &line, String pattern, int from, bool match_c while (true) { int begin = match_case ? line.find(pattern, end) : line.findn(pattern, end); - if (begin == -1) + if (begin == -1) { return false; + } end = begin + pattern.length(); out_begin = begin; @@ -156,8 +157,9 @@ void FindInFiles::_process() { while (is_processing()) { _iterate(); float elapsed = (os.get_ticks_msec() - time_before); - if (elapsed > 1000.0 / 120.0) + if (elapsed > 1000.0 / 120.0) { break; + } } } @@ -227,19 +229,22 @@ void FindInFiles::_scan_dir(String path, PackedStringArray &out_folders) { for (int i = 0; i < 1000; ++i) { String file = dir->get_next(); - if (file == "") + if (file == "") { break; + } // Ignore special dirs (such as .git and .import) - if (file == "." || file == ".." || file.begins_with(".")) + if (file == "." || file == ".." || file.begins_with(".")) { continue; - if (dir->current_is_hidden()) + } + if (dir->current_is_hidden()) { continue; + } - if (dir->current_is_dir()) + if (dir->current_is_dir()) { out_folders.push_back(file); - else { + } else { String file_ext = file.get_extension(); if (_extension_filter.has(file_ext)) { _files_to_scan.push_back(path.plus_file(file)); @@ -399,8 +404,9 @@ void FindInFilesDialog::set_replace_text(String text) { } void FindInFilesDialog::set_find_in_files_mode(FindInFilesMode p_mode) { - if (_mode == p_mode) + if (_mode == p_mode) { return; + } _mode = p_mode; @@ -528,8 +534,9 @@ void FindInFilesDialog::_on_replace_text_entered(String text) { void FindInFilesDialog::_on_folder_selected(String path) { int i = path.find("://"); - if (i != -1) + if (i != -1) { path = path.right(i + 3); + } _folder_line_edit->set_text(path); } @@ -739,12 +746,14 @@ void FindInFilesPanel::_on_result_found(String fpath, int line_number, int begin void FindInFilesPanel::draw_result_text(Object *item_obj, Rect2 rect) { TreeItem *item = Object::cast_to<TreeItem>(item_obj); - if (!item) + if (!item) { return; + } Map<TreeItem *, Result>::Element *E = _result_items.find(item); - if (!E) + if (!E) { return; + } Result r = E->value(); Rect2 match_rect = rect; @@ -791,8 +800,9 @@ void FindInFilesPanel::_on_result_selected() { TreeItem *item = _results_display->get_selected(); Map<TreeItem *, Result>::Element *E = _result_items.find(item); - if (E == nullptr) + if (E == nullptr) { return; + } Result r = E->value(); TreeItem *file_item = item->get_parent(); @@ -816,8 +826,9 @@ void FindInFilesPanel::_on_replace_all_clicked() { Vector<Result> locations; for (TreeItem *item = file_item->get_children(); item; item = item->get_next()) { - if (!item->is_checked(0)) + if (!item->is_checked(0)) { continue; + } Map<TreeItem *, Result>::Element *F = _result_items.find(item); ERR_FAIL_COND(F == nullptr); diff --git a/editor/groups_editor.cpp b/editor/groups_editor.cpp index 692b41e921..98b216acda 100644 --- a/editor/groups_editor.cpp +++ b/editor/groups_editor.cpp @@ -300,8 +300,9 @@ void GroupDialog::_load_groups(Node *p_current) { void GroupDialog::_delete_group_pressed(Object *p_item, int p_column, int p_id) { TreeItem *ti = Object::cast_to<TreeItem>(p_item); - if (!ti) + if (!ti) { return; + } String name = ti->get_text(0); @@ -536,15 +537,18 @@ GroupDialog::GroupDialog() { //////////////////////////////////////////////////////////////////////////////// void GroupsEditor::_add_group(const String &p_group) { - if (!node) + if (!node) { return; + } const String name = group_name->get_text().strip_edges(); - if (name.empty()) + if (name.empty()) { return; + } - if (node->is_in_group(name)) + if (node->is_in_group(name)) { return; + } undo_redo->create_action(TTR("Add to Group")); @@ -563,12 +567,14 @@ void GroupsEditor::_add_group(const String &p_group) { } void GroupsEditor::_remove_group(Object *p_item, int p_column, int p_id) { - if (!node) + if (!node) { return; + } TreeItem *ti = Object::cast_to<TreeItem>(p_item); - if (!ti) + if (!ti) { return; + } String name = ti->get_text(0); @@ -595,8 +601,9 @@ struct _GroupInfoComparator { void GroupsEditor::update_tree() { tree->clear(); - if (!node) + if (!node) { return; + } List<Node::GroupInfo> groups; node->get_groups(&groups); @@ -606,8 +613,9 @@ void GroupsEditor::update_tree() { for (List<GroupInfo>::Element *E = groups.front(); E; E = E->next()) { Node::GroupInfo gi = E->get(); - if (!gi.persistent) + if (!gi.persistent) { continue; + } Node *n = node; bool can_be_deleted = true; diff --git a/editor/import/collada.cpp b/editor/import/collada.cpp index e82e1bb098..41e71248a9 100644 --- a/editor/import/collada.cpp +++ b/editor/import/collada.cpp @@ -65,10 +65,11 @@ void Collada::Vertex::fix_unit_scale(Collada &state) { } static String _uri_to_id(const String &p_uri) { - if (p_uri.begins_with("#")) + if (p_uri.begins_with("#")) { return p_uri.substr(1, p_uri.size() - 1); - else + } else { return p_uri; + } } /** HELPER FUNCTIONS **/ @@ -79,10 +80,12 @@ Transform Collada::fix_transform(const Transform &p_transform) { #ifndef NO_UP_AXIS_SWAP if (state.up_axis != Vector3::AXIS_Y) { - for (int i = 0; i < 3; i++) + for (int i = 0; i < 3; i++) { SWAP(tr.basis[1][i], tr.basis[state.up_axis][i]); - for (int i = 0; i < 3; i++) + } + for (int i = 0; i < 3; i++) { SWAP(tr.basis[i][1], tr.basis[i][state.up_axis]); + } SWAP(tr.origin[1], tr.origin[state.up_axis]); @@ -167,10 +170,11 @@ Transform Collada::Node::get_transform() const { } Transform Collada::Node::get_global_transform() const { - if (parent) + if (parent) { return parent->get_global_transform() * default_transform; - else + } else { return default_transform; + } } Vector<float> Collada::AnimationTrack::get_value_at_time(float p_time) const { @@ -178,14 +182,17 @@ Vector<float> Collada::AnimationTrack::get_value_at_time(float p_time) const { int i = 0; for (i = 0; i < keys.size(); i++) { - if (keys[i].time > p_time) + if (keys[i].time > p_time) { break; + } } - if (i == 0) + if (i == 0) { return keys[0].data; - if (i == keys.size()) + } + if (i == keys.size()) { return keys[keys.size() - 1].data; + } switch (keys[i].interp_type) { case INTERP_BEZIER: //wait for bezier @@ -243,12 +250,15 @@ void Collada::_parse_asset(XMLParser &parser) { if (name == "up_axis") { parser.read(); - if (parser.get_node_data() == "X_UP") + if (parser.get_node_data() == "X_UP") { state.up_axis = Vector3::AXIS_X; - if (parser.get_node_data() == "Y_UP") + } + if (parser.get_node_data() == "Y_UP") { state.up_axis = Vector3::AXIS_Y; - if (parser.get_node_data() == "Z_UP") + } + if (parser.get_node_data() == "Z_UP") { state.up_axis = Vector3::AXIS_Z; + } COLLADA_PRINT("up axis: " + parser.get_node_data()); } else if (name == "unit") { @@ -256,8 +266,9 @@ void Collada::_parse_asset(XMLParser &parser) { COLLADA_PRINT("unit scale: " + rtos(state.unit_scale)); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "asset") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "asset") { break; //end of <asset> + } } } @@ -265,8 +276,9 @@ void Collada::_parse_image(XMLParser &parser) { String id = parser.get_attribute_value("id"); if (!(state.import_flags & IMPORT_FLAG_SCENE)) { - if (!parser.is_empty()) + if (!parser.is_empty()) { parser.skip_section(); + } return; } @@ -302,11 +314,13 @@ void Collada::_parse_image(XMLParser &parser) { } else if (name == "data") { ERR_PRINT("COLLADA Embedded image data not supported!"); - } else if (name == "extra" && !parser.is_empty()) + } else if (name == "extra" && !parser.is_empty()) { parser.skip_section(); + } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "image") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "image") { break; //end of <asset> + } } } @@ -315,16 +329,18 @@ void Collada::_parse_image(XMLParser &parser) { void Collada::_parse_material(XMLParser &parser) { if (!(state.import_flags & IMPORT_FLAG_SCENE)) { - if (!parser.is_empty()) + if (!parser.is_empty()) { parser.skip_section(); + } return; } Material material; String id = parser.get_attribute_value("id"); - if (parser.has_attribute("name")) + if (parser.has_attribute("name")) { material.name = parser.get_attribute_value("name"); + } if (state.version < State::Version(1, 4, 0)) { /* <1.4 */ @@ -333,8 +349,9 @@ void Collada::_parse_material(XMLParser &parser) { while (parser.read() == OK) { if (parser.get_node_type() == XMLParser::NODE_ELEMENT && parser.get_node_name() == "instance_effect") { material.instance_effect = _uri_to_id(parser.get_attribute_value("url")); - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "material") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "material") { break; //end of <asset> + } } } @@ -343,8 +360,9 @@ void Collada::_parse_material(XMLParser &parser) { //! reads floats from inside of xml element until end of xml element Vector<float> Collada::_read_float_array(XMLParser &parser) { - if (parser.is_empty()) + if (parser.is_empty()) { return Vector<float>(); + } Vector<String> splitters; splitters.push_back(" "); @@ -362,16 +380,18 @@ Vector<float> Collada::_read_float_array(XMLParser &parser) { String str = parser.get_node_data(); array = str.split_floats_mk(splitters, false); //array=str.split_floats(" ",false); - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END) + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END) { break; // end parsing text + } } return array; } Vector<String> Collada::_read_string_array(XMLParser &parser) { - if (parser.is_empty()) + if (parser.is_empty()) { return Vector<String>(); + } Vector<String> array; while (parser.read() == OK) { @@ -382,16 +402,18 @@ Vector<String> Collada::_read_string_array(XMLParser &parser) { // parse String data String str = parser.get_node_data(); array = str.split_spaces(); - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END) + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END) { break; // end parsing text + } } return array; } Transform Collada::_read_transform(XMLParser &parser) { - if (parser.is_empty()) + if (parser.is_empty()) { return Transform(); + } Vector<String> array; while (parser.read() == OK) { @@ -402,8 +424,9 @@ Transform Collada::_read_transform(XMLParser &parser) { // parse float data String str = parser.get_node_data(); array = str.split_spaces(); - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END) + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END) { break; // end parsing text + } } ERR_FAIL_COND_V(array.size() != 16, Transform()); @@ -419,21 +442,24 @@ Transform Collada::_read_transform(XMLParser &parser) { String Collada::_read_empty_draw_type(XMLParser &parser) { String empty_draw_type = ""; - if (parser.is_empty()) + if (parser.is_empty()) { return empty_draw_type; + } while (parser.read() == OK) { if (parser.get_node_type() == XMLParser::NODE_TEXT) { empty_draw_type = parser.get_node_data(); - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END) + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END) { break; // end parsing text + } } return empty_draw_type; } Variant Collada::_parse_param(XMLParser &parser) { - if (parser.is_empty()) + if (parser.is_empty()) { return Variant(); + } String from = parser.get_node_name(); Variant data; @@ -473,8 +499,9 @@ Variant Collada::_parse_param(XMLParser &parser) { data = parser.get_node_data(); } } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "sampler2D") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "sampler2D") { break; + } } } else if (parser.get_node_name() == "surface") { while (parser.read() == OK) { @@ -486,13 +513,15 @@ Variant Collada::_parse_param(XMLParser &parser) { data = parser.get_node_data(); } } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "surface") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "surface") { break; + } } } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == from) + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == from) { break; + } } COLLADA_PRINT("newparam ending " + parser.get_node_name()); @@ -501,8 +530,9 @@ Variant Collada::_parse_param(XMLParser &parser) { void Collada::_parse_effect_material(XMLParser &parser, Effect &effect, String &id) { if (!(state.import_flags & IMPORT_FLAG_SCENE)) { - if (!parser.is_empty()) + if (!parser.is_empty()) { parser.skip_section(); + } return; } @@ -544,12 +574,15 @@ void Collada::_parse_effect_material(XMLParser &parser, Effect &effect, String & if (colorarr.size() >= 3) { // alpha strangely not alright? maybe it needs to be multiplied by value as a channel intensity Color color(colorarr[0], colorarr[1], colorarr[2], 1.0); - if (what == "diffuse") + if (what == "diffuse") { effect.diffuse.color = color; - if (what == "specular") + } + if (what == "specular") { effect.specular.color = color; - if (what == "emission") + } + if (what == "emission") { effect.emission.color = color; + } COLLADA_PRINT(what + " color: " + color); } @@ -583,11 +616,13 @@ void Collada::_parse_effect_material(XMLParser &parser, Effect &effect, String & COLLADA_PRINT(what + " texture: " + uri); } } - } else if (!parser.is_empty()) + } else if (!parser.is_empty()) { parser.skip_section(); + } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == what) + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == what) { break; + } } } else if (what == "shininess") { @@ -596,8 +631,9 @@ void Collada::_parse_effect_material(XMLParser &parser, Effect &effect, String & } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && (parser.get_node_name() == "constant" || parser.get_node_name() == "lambert" || parser.get_node_name() == "phong" || - parser.get_node_name() == "blinn")) + parser.get_node_name() == "blinn")) { break; + } } } else if (parser.get_node_name() == "double_sided" || parser.get_node_name() == "show_double_sided") { // colladamax / google earth @@ -633,36 +669,42 @@ void Collada::_parse_effect_material(XMLParser &parser, Effect &effect, String & COLLADA_PRINT(" bump: " + uri); } } - } else if (!parser.is_empty()) + } else if (!parser.is_empty()) { parser.skip_section(); + } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "bump") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "bump") { break; + } } - } else if (!parser.is_empty()) + } else if (!parser.is_empty()) { parser.skip_section(); + } } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && (parser.get_node_name() == "effect" || parser.get_node_name() == "profile_COMMON" || parser.get_node_name() == "technique" || - parser.get_node_name() == "extra")) + parser.get_node_name() == "extra")) { break; + } } } void Collada::_parse_effect(XMLParser &parser) { if (!(state.import_flags & IMPORT_FLAG_SCENE)) { - if (!parser.is_empty()) + if (!parser.is_empty()) { parser.skip_section(); + } return; } String id = parser.get_attribute_value("id"); Effect effect; - if (parser.has_attribute("name")) + if (parser.has_attribute("name")) { effect.name = parser.get_attribute_value("name"); + } _parse_effect_material(parser, effect, id); state.effect_map[id] = effect; @@ -672,8 +714,9 @@ void Collada::_parse_effect(XMLParser &parser) { void Collada::_parse_camera(XMLParser &parser) { if (!(state.import_flags & IMPORT_FLAG_SCENE)) { - if (!parser.is_empty()) + if (!parser.is_empty()) { parser.skip_section(); + } return; } @@ -717,8 +760,9 @@ void Collada::_parse_camera(XMLParser &parser) { camera.z_far = parser.get_node_data().to_double(); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "camera") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "camera") { break; //end of <asset> + } } COLLADA_PRINT("Camera ID:" + id); @@ -726,8 +770,9 @@ void Collada::_parse_camera(XMLParser &parser) { void Collada::_parse_light(XMLParser &parser) { if (!(state.import_flags & IMPORT_FLAG_SCENE)) { - if (!parser.is_empty()) + if (!parser.is_empty()) { parser.skip_section(); + } return; } @@ -777,8 +822,9 @@ void Collada::_parse_light(XMLParser &parser) { light.spot_exp = parser.get_node_data().to_double(); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "light") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "light") { break; //end of <asset> + } } COLLADA_PRINT("Light ID:" + id); @@ -786,8 +832,9 @@ void Collada::_parse_light(XMLParser &parser) { void Collada::_parse_curve_geometry(XMLParser &parser, String p_id, String p_name) { if (!(state.import_flags & IMPORT_FLAG_SCENE)) { - if (!parser.is_empty()) + if (!parser.is_empty()) { parser.skip_section(); + } return; } @@ -849,22 +896,25 @@ void Collada::_parse_curve_geometry(XMLParser &parser, String p_id, String p_nam COLLADA_PRINT(section + " input semantic: " + semantic + " source: " + source); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) { break; + } } } else if (!parser.is_empty()) { parser.skip_section(); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "spline") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "spline") { break; + } } } void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name) { if (!(state.import_flags & IMPORT_FLAG_SCENE)) { - if (!parser.is_empty()) + if (!parser.is_empty()) { parser.skip_section(); + } return; } @@ -922,8 +972,9 @@ void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name COLLADA_PRINT(section + " input semantic: " + semantic + " source: " + source); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) { break; + } } meshdata.vertices[id] = vert; @@ -935,8 +986,9 @@ void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name } MeshData::Primitives prim; - if (parser.has_attribute("material")) + if (parser.has_attribute("material")) { prim.material = parser.get_attribute_value("material"); + } prim.count = parser.get_attribute_value("count").to_int(); prim.vertex_size = 0; int last_ref = 0; @@ -973,8 +1025,9 @@ void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name prim.polygons.push_back(values.size() / prim.vertex_size); int from = prim.indices.size(); prim.indices.resize(from + values.size()); - for (int i = 0; i < values.size(); i++) + for (int i = 0; i < values.size(); i++) { prim.indices.write[from + i] = values[i]; + } } else if (prim.vertex_size > 0) { prim.indices = values; @@ -988,8 +1041,9 @@ void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name prim.polygons = values; COLLADA_PRINT("read " + itos(values.size()) + " polygon values"); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) { break; + } } meshdata.primitives.push_back(prim); @@ -1004,8 +1058,9 @@ void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name } else if (!parser.is_empty()) { parser.skip_section(); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "mesh") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "mesh") { break; + } } } @@ -1044,14 +1099,16 @@ void Collada::_parse_skin_controller(XMLParser &parser, String p_id) { } else if (section == "Name_array" || section == "IDREF_array") { // create a new array and read it. - if (section == "IDREF_array") + if (section == "IDREF_array") { skindata.use_idrefs = true; + } if (skindata.sources.has(current_source)) { skindata.sources[current_source].sarray = _read_string_array(parser); if (section == "IDREF_array") { Vector<String> sa = skindata.sources[current_source].sarray; - for (int i = 0; i < sa.size(); i++) + for (int i = 0; i < sa.size(); i++) { state.idref_joints.insert(sa[i]); + } } COLLADA_PRINT("section: " + current_source + " read " + itos(skindata.sources[current_source].array.size()) + " values."); } @@ -1061,8 +1118,9 @@ void Collada::_parse_skin_controller(XMLParser &parser, String p_id) { if (skindata.sources.has(current_source)) { int stride = 1; - if (parser.has_attribute("stride")) + if (parser.has_attribute("stride")) { stride = parser.get_attribute_value("stride").to_int(); + } skindata.sources[current_source].stride = stride; COLLADA_PRINT("section: " + current_source + " stride " + itos(skindata.sources[current_source].stride)); @@ -1081,8 +1139,9 @@ void Collada::_parse_skin_controller(XMLParser &parser, String p_id) { COLLADA_PRINT(section + " input semantic: " + semantic + " source: " + source); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) { break; + } } skindata.joints = joint; @@ -1119,8 +1178,9 @@ void Collada::_parse_skin_controller(XMLParser &parser, String p_id) { weights.sets = values; COLLADA_PRINT("read " + itos(values.size()) + " polygon values"); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) { break; + } } skindata.weights = weights; @@ -1130,8 +1190,9 @@ void Collada::_parse_skin_controller(XMLParser &parser, String p_id) { parser.skip_section(); */ - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "skin") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "skin") { break; + } } /* STORE REST MATRICES */ @@ -1209,8 +1270,9 @@ void Collada::_parse_morph_controller(XMLParser &parser, String p_id) { if (morphdata.sources.has(current_source)) { int stride = 1; - if (parser.has_attribute("stride")) + if (parser.has_attribute("stride")) { stride = parser.get_attribute_value("stride").to_int(); + } morphdata.sources[current_source].stride = stride; COLLADA_PRINT("section: " + current_source + " stride " + itos(morphdata.sources[current_source].stride)); @@ -1227,8 +1289,9 @@ void Collada::_parse_morph_controller(XMLParser &parser, String p_id) { COLLADA_PRINT(section + " input semantic: " + semantic + " source: " + source); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) { break; + } } } /* @@ -1236,8 +1299,9 @@ void Collada::_parse_morph_controller(XMLParser &parser, String p_id) { parser.skip_section(); */ - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "morph") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "morph") { break; + } } if (morphdata.targets.has("MORPH_WEIGHT")) { @@ -1261,8 +1325,9 @@ void Collada::_parse_controller(XMLParser &parser) { } else if (section == "morph") { _parse_morph_controller(parser, id); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "controller") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "controller") { break; + } } } @@ -1272,8 +1337,9 @@ Collada::Node *Collada::_parse_visual_instance_geometry(XMLParser &parser) { geom->controller = type == "instance_controller"; geom->source = _uri_to_id(parser.get_attribute_value_safe("url")); - if (parser.is_empty()) //nothing else to parse... + if (parser.is_empty()) { //nothing else to parse... return geom; + } // try to find also many materials and skeletons! while (parser.read() == OK) { if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { @@ -1293,8 +1359,9 @@ Collada::Node *Collada::_parse_visual_instance_geometry(XMLParser &parser) { } } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == type) + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == type) { break; + } } if (geom->controller) { @@ -1320,15 +1387,18 @@ Collada::Node *Collada::_parse_visual_instance_camera(XMLParser &parser) { NodeCamera *cam = memnew(NodeCamera); cam->camera = _uri_to_id(parser.get_attribute_value_safe("url")); - if (state.up_axis == Vector3::AXIS_Z) //collada weirdness + if (state.up_axis == Vector3::AXIS_Z) { //collada weirdness cam->post_transform.basis.rotate(Vector3(1, 0, 0), -Math_PI * 0.5); + } - if (parser.is_empty()) //nothing else to parse... + if (parser.is_empty()) { //nothing else to parse... return cam; + } while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "instance_camera") + if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "instance_camera") { break; + } } return cam; @@ -1338,15 +1408,18 @@ Collada::Node *Collada::_parse_visual_instance_light(XMLParser &parser) { NodeLight *cam = memnew(NodeLight); cam->light = _uri_to_id(parser.get_attribute_value_safe("url")); - if (state.up_axis == Vector3::AXIS_Z) //collada weirdness + if (state.up_axis == Vector3::AXIS_Z) { //collada weirdness cam->post_transform.basis.rotate(Vector3(1, 0, 0), -Math_PI * 0.5); + } - if (parser.is_empty()) //nothing else to parse... + if (parser.is_empty()) { //nothing else to parse... return cam; + } while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "instance_light") + if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "instance_light") { break; + } } return cam; @@ -1363,12 +1436,14 @@ Collada::Node *Collada::_parse_visual_node_instance_data(XMLParser &parser) { return _parse_visual_instance_light(parser); } - if (parser.is_empty()) //nothing else to parse... + if (parser.is_empty()) { //nothing else to parse... return nullptr; + } while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == instance_type) + if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == instance_type) { break; + } } return nullptr; @@ -1475,8 +1550,9 @@ Collada::Node *Collada::_parse_visual_scene_node(XMLParser &parser) { xf.data = matrix; String mtx; - for (int i = 0; i < matrix.size(); i++) + for (int i = 0; i < matrix.size(); i++) { mtx += " " + rtos(matrix[i]); + } xform_list.push_back(xf); @@ -1514,8 +1590,9 @@ Collada::Node *Collada::_parse_visual_scene_node(XMLParser &parser) { children.push_back(child); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "node") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "node") { break; + } } if (!node) { @@ -1556,8 +1633,9 @@ void Collada::_parse_visual_scene(XMLParser &parser) { state.visual_scene_map[id] = VisualScene(); VisualScene &vscene = state.visual_scene_map[id]; - if (parser.has_attribute("name")) + if (parser.has_attribute("name")) { vscene.name = parser.get_attribute_value("name"); + } while (parser.read() == OK) { if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { @@ -1567,8 +1645,9 @@ void Collada::_parse_visual_scene(XMLParser &parser) { vscene.root_nodes.push_back(_parse_visual_scene_node(parser)); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "visual_scene") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "visual_scene") { break; + } } COLLADA_PRINT("Scene ID:" + id); @@ -1576,8 +1655,9 @@ void Collada::_parse_visual_scene(XMLParser &parser) { void Collada::_parse_animation(XMLParser &parser) { if (!(state.import_flags & IMPORT_FLAG_ANIMATION)) { - if (!parser.is_empty()) + if (!parser.is_empty()) { parser.skip_section(); + } return; } @@ -1590,8 +1670,9 @@ void Collada::_parse_animation(XMLParser &parser) { Map<String, Vector<String>> source_param_types; String id = ""; - if (parser.has_attribute("id")) + if (parser.has_attribute("id")) { id = parser.get_attribute_value("id"); + } String current_source; String current_sampler; @@ -1623,15 +1704,17 @@ void Collada::_parse_animation(XMLParser &parser) { current_sampler = parser.get_attribute_value("id"); samplers[current_sampler] = Map<String, String>(); } else if (name == "param") { - if (parser.has_attribute("name")) + if (parser.has_attribute("name")) { source_param_names[current_source].push_back(parser.get_attribute_value("name")); - else + } else { source_param_names[current_source].push_back(""); + } - if (parser.has_attribute("type")) + if (parser.has_attribute("type")) { source_param_types[current_source].push_back(parser.get_attribute_value("type")); - else + } else { source_param_types[current_source].push_back(""); + } } else if (name == "input") { if (current_sampler != "") { @@ -1643,8 +1726,9 @@ void Collada::_parse_animation(XMLParser &parser) { channel_targets.push_back(parser.get_attribute_value("target")); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "animation") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "animation") { break; //end of <asset> + } } for (int i = 0; i < channel_sources.size(); i++) { @@ -1686,8 +1770,9 @@ void Collada::_parse_animation(XMLParser &parser) { int stride = 1; - if (source_strides.has(output_id)) + if (source_strides.has(output_id)) { stride = source_strides[output_id]; + } int output_len = stride / names.size(); ERR_CONTINUE(output_len == 0); @@ -1699,8 +1784,9 @@ void Collada::_parse_animation(XMLParser &parser) { for (int j = 0; j < key_count; j++) { track.keys.write[j].data.resize(output_len); - for (int k = 0; k < output_len; k++) + for (int k = 0; k < output_len; k++) { track.keys.write[j].data.write[k] = output[l + j * stride + k]; //super weird but should work: + } } if (sampler.has("INTERPOLATION")) { @@ -1710,10 +1796,11 @@ void Collada::_parse_animation(XMLParser &parser) { ERR_CONTINUE(interps.size() != key_count); for (int j = 0; j < key_count; j++) { - if (interps[j] == "BEZIER") + if (interps[j] == "BEZIER") { track.keys.write[j].interp_type = AnimationTrack::INTERP_BEZIER; - else + } else { track.keys.write[j].interp_type = AnimationTrack::INTERP_LINEAR; + } } } @@ -1739,8 +1826,9 @@ void Collada::_parse_animation(XMLParser &parser) { if (target.find("/") != -1) { //transform component track.target = target.get_slicec('/', 0); track.param = target.get_slicec('/', 1); - if (track.param.find(".") != -1) + if (track.param.find(".") != -1) { track.component = track.param.get_slice(".", 1).to_upper(); + } track.param = track.param.get_slice(".", 0); if (names.size() > 1 && track.component == "") { //this is a guess because the collada spec is ambiguous here... @@ -1753,14 +1841,16 @@ void Collada::_parse_animation(XMLParser &parser) { state.animation_tracks.push_back(track); - if (!state.referenced_tracks.has(target)) + if (!state.referenced_tracks.has(target)) { state.referenced_tracks[target] = Vector<int>(); + } state.referenced_tracks[target].push_back(state.animation_tracks.size() - 1); if (id != "") { - if (!state.by_id_tracks.has(id)) + if (!state.by_id_tracks.has(id)) { state.by_id_tracks[id] = Vector<int>(); + } state.by_id_tracks[id].push_back(state.animation_tracks.size() - 1); } @@ -1772,22 +1862,26 @@ void Collada::_parse_animation(XMLParser &parser) { void Collada::_parse_animation_clip(XMLParser &parser) { if (!(state.import_flags & IMPORT_FLAG_ANIMATION)) { - if (!parser.is_empty()) + if (!parser.is_empty()) { parser.skip_section(); + } return; } AnimationClip clip; - if (parser.has_attribute("name")) + if (parser.has_attribute("name")) { clip.name = parser.get_attribute_value("name"); - else if (parser.has_attribute("id")) + } else if (parser.has_attribute("id")) { clip.name = parser.get_attribute_value("id"); - if (parser.has_attribute("start")) + } + if (parser.has_attribute("start")) { clip.begin = parser.get_attribute_value("start").to_double(); - if (parser.has_attribute("end")) + } + if (parser.has_attribute("end")) { clip.end = parser.get_attribute_value("end").to_double(); + } while (parser.read() == OK) { if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { @@ -1797,8 +1891,9 @@ void Collada::_parse_animation_clip(XMLParser &parser) { clip.tracks.push_back(url); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "animation_clip") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "animation_clip") { break; //end of <asset> + } } state.animation_clips.push_back(clip); @@ -1819,8 +1914,9 @@ void Collada::_parse_scene(XMLParser &parser) { state.root_physics_scene = _uri_to_id(parser.get_attribute_value("url")); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "scene") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "scene") { break; //end of <asset> + } } } @@ -1854,10 +1950,12 @@ void Collada::_parse_library(XMLParser &parser) { } else if (parser.get_node_name() == "spline") { state.mesh_name_map[id] = (name2 != "") ? name2 : id; _parse_curve_geometry(parser, id, name2); - } else if (!parser.is_empty()) + } else if (!parser.is_empty()) { parser.skip_section(); - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "geometry") + } + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "geometry") { break; + } } } else if (name == "controller") { @@ -1869,11 +1967,13 @@ void Collada::_parse_library(XMLParser &parser) { } else if (name == "visual_scene") { COLLADA_PRINT("visual scene"); _parse_visual_scene(parser); - } else if (!parser.is_empty()) + } else if (!parser.is_empty()) { parser.skip_section(); + } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name().begins_with("library_")) + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name().begins_with("library_")) { break; //end of <asset> + } } } @@ -1919,8 +2019,9 @@ bool Collada::_remove_node(Node *p_parent, Node *p_node) { p_parent->children.remove(i); return true; } - if (_remove_node(p_parent->children[i], p_node)) + if (_remove_node(p_parent->children[i], p_node)) { return true; + } } return false; @@ -1932,8 +2033,9 @@ void Collada::_remove_node(VisualScene *p_vscene, Node *p_node) { p_vscene->root_nodes.remove(i); return; } - if (_remove_node(p_vscene->root_nodes[i], p_node)) + if (_remove_node(p_vscene->root_nodes[i], p_node)) { return; + } } ERR_PRINT("ERROR: Not found node to remove?"); @@ -2090,8 +2192,9 @@ bool Collada::_optimize_skeletons(VisualScene *p_vscene, Node *p_node) { } for (int i = 0; i < node->children.size(); i++) { - if (_optimize_skeletons(p_vscene, node->children[i])) + if (_optimize_skeletons(p_vscene, node->children[i])) { return false; //stop processing, go up + } } return false; @@ -2103,8 +2206,9 @@ bool Collada::_move_geometry_to_skeletons(VisualScene *p_vscene, Node *p_node, L if (p_node->type == Node::TYPE_GEOMETRY) { NodeGeometry *ng = static_cast<NodeGeometry *>(p_node); - if (ng->ignore_anim) + if (ng->ignore_anim) { return false; //already made child of skeleton and processeg + } if (ng->controller && ng->skeletons.size()) { String nodeid = ng->skeletons[0]; @@ -2253,8 +2357,9 @@ Error Collada::load(const String &p_path, int p_flags) { if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { if (parser.get_node_name() == "COLLADA") { break; - } else if (!parser.is_empty()) + } else if (!parser.is_empty()) { parser.skip_section(); // unknown section, likely headers + } } } @@ -2274,8 +2379,9 @@ Error Collada::load(const String &p_path, int p_flags) { while ((err = parser.read()) == OK) { /* Read all the main sections.. */ - if (parser.get_node_type() != XMLParser::NODE_ELEMENT) + if (parser.get_node_type() != XMLParser::NODE_ELEMENT) { continue; //no idea what this may be, but skipping anyway + } String section = parser.get_node_name(); diff --git a/editor/import/collada.h b/editor/import/collada.h index 02c3277911..90c6c47e0b 100644 --- a/editor/import/collada.h +++ b/editor/import/collada.h @@ -255,11 +255,14 @@ public: //cap to 4 and make weights add up 1 weights.resize(4); float total = 0; - for (int i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) { total += weights[i].weight; - if (total) - for (int i = 0; i < 4; i++) + } + if (total) { + for (int i = 0; i < 4; i++) { weights.write[i].weight /= total; + } + } } } @@ -274,11 +277,13 @@ public: if (!weights.empty() || !p_vert.weights.empty()) { if (weights.size() == p_vert.weights.size()) { for (int i = 0; i < weights.size(); i++) { - if (weights[i].bone_idx != p_vert.weights[i].bone_idx) + if (weights[i].bone_idx != p_vert.weights[i].bone_idx) { return weights[i].bone_idx < p_vert.weights[i].bone_idx; + } - if (weights[i].weight != p_vert.weights[i].weight) + if (weights[i].weight != p_vert.weights[i].weight) { return weights[i].weight < p_vert.weights[i].weight; + } } } else { return weights.size() < p_vert.weights.size(); @@ -286,16 +291,21 @@ public: } return (color < p_vert.color); - } else + } else { return (uv2 < p_vert.uv2); - } else + } + } else { return (uv < p_vert.uv); - } else + } + } else { return (normal < p_vert.normal); - } else + } + } else { return vertex < p_vert.vertex; - } else + } + } else { return uid < p_vert.uid; + } } Vertex() {} @@ -347,8 +357,9 @@ public: Node() {} virtual ~Node() { - for (int i = 0; i < children.size(); i++) + for (int i = 0; i < children.size(); i++) { memdelete(children[i]); + } }; }; @@ -395,8 +406,9 @@ public: Vector<Node *> root_nodes; ~VisualScene() { - for (int i = 0; i < root_nodes.size(); i++) + for (int i = 0; i < root_nodes.size(); i++) { memdelete(root_nodes[i]); + } } }; diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp index 54b4dc2972..12cbaaa885 100644 --- a/editor/import/editor_import_collada.cpp +++ b/editor/import/editor_import_collada.cpp @@ -109,14 +109,16 @@ struct ColladaImport { }; Error ColladaImport::_populate_skeleton(Skeleton3D *p_skeleton, Collada::Node *p_node, int &r_bone, int p_parent) { - if (p_node->type != Collada::Node::TYPE_JOINT) + if (p_node->type != Collada::Node::TYPE_JOINT) { return OK; + } Collada::NodeJoint *joint = static_cast<Collada::NodeJoint *>(p_node); p_skeleton->add_bone(p_node->name); - if (p_parent >= 0) + if (p_parent >= 0) { p_skeleton->set_bone_parent(r_bone, p_parent); + } NodeMap nm; nm.node = p_skeleton; @@ -136,8 +138,9 @@ Error ColladaImport::_populate_skeleton(Skeleton3D *p_skeleton, Collada::Node *p int id = r_bone++; for (int i = 0; i < p_node->children.size(); i++) { Error err = _populate_skeleton(p_skeleton, p_node->children[i], r_bone, id); - if (err) + if (err) { return err; + } } return OK; @@ -158,8 +161,9 @@ void ColladaImport::_pre_process_lights(Collada::Node *p_node) { } } - for (int i = 0; i < p_node->children.size(); i++) + for (int i = 0; i < p_node->children.size(); i++) { _pre_process_lights(p_node->children[i]); + } } Error ColladaImport::_create_scene_skeletons(Collada::Node *p_node) { @@ -175,8 +179,9 @@ Error ColladaImport::_create_scene_skeletons(Collada::Node *p_node) { for (int i = 0; i < p_node->children.size(); i++) { Error err = _create_scene_skeletons(p_node->children[i]); - if (err) + if (err) { return err; + } } return OK; } @@ -198,11 +203,13 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Node3D *p_parent) { Collada::LightData &ld = collada.state.light_data_map[light->light]; if (ld.mode == Collada::LightData::MODE_AMBIENT) { - if (found_directional) + if (found_directional) { return OK; //do nothing not needed + } - if (!bool(GLOBAL_DEF("collada/use_ambient", false))) + if (!bool(GLOBAL_DEF("collada/use_ambient", false))) { return OK; + } //well, it's an ambient light.. Light3D *l = memnew(DirectionalLight3D); //l->set_color(Light::COLOR_AMBIENT,ld.color); @@ -224,9 +231,9 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Node3D *p_parent) { } else { Light3D *l; - if (ld.mode == Collada::LightData::MODE_OMNI) + if (ld.mode == Collada::LightData::MODE_OMNI) { l = memnew(OmniLight3D); - else { + } else { l = memnew(SpotLight3D); //l->set_parameter(Light::PARAM_SPOT_ANGLE,ld.spot_angle); //l->set_parameter(Light::PARAM_SPOT_ATTENUATION,ld.spot_exp); @@ -295,8 +302,9 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Node3D *p_parent) { } break; } - if (p_node->name != "") + if (p_node->name != "") { node->set_name(p_node->name); + } NodeMap nm; nm.node = node; node_map[p_node->id] = nm; @@ -314,8 +322,9 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Node3D *p_parent) { for (int i = 0; i < p_node->children.size(); i++) { Error err = _create_scene(p_node->children[i], node); - if (err) + if (err) { return err; + } } return OK; } @@ -329,10 +338,11 @@ Error ColladaImport::_create_material(const String &p_target) { Ref<StandardMaterial3D> material = memnew(StandardMaterial3D); - if (src_mat.name != "") + if (src_mat.name != "") { material->set_name(src_mat.name); - else if (effect.name != "") + } else if (effect.name != "") { material->set_name(effect.name); + } // DIFFUSE @@ -459,10 +469,11 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me p_mesh->add_blend_shape(name); } - if (p_morph_data->mode == "RELATIVE") + if (p_morph_data->mode == "RELATIVE") { p_mesh->set_blend_shape_mode(Mesh::BLEND_SHAPE_MODE_RELATIVE); - else if (p_morph_data->mode == "NORMALIZED") + } else if (p_morph_data->mode == "NORMALIZED") { p_mesh->set_blend_shape_mode(Mesh::BLEND_SHAPE_MODE_NORMALIZED); + } } int surface = 0; @@ -594,8 +605,9 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me w.weight = weight_src->array[weight_index]; int bone_index = p_skin_controller->weights.indices[read_from + joint_ofs]; - if (bone_index == -1) + if (bone_index == -1) { continue; //ignore this weight (refers to bind shape) + } ERR_FAIL_INDEX_V(bone_index, bone_remap.size(), ERR_INVALID_DATA); w.bone_idx = bone_remap[bone_index]; @@ -614,11 +626,14 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me //make sure weights always add up to 1 float total = 0; - for (int i = 0; i < weights.size(); i++) + for (int i = 0; i < weights.size(); i++) { total += weights[i].weight; - if (total) - for (int i = 0; i < weights.size(); i++) + } + if (total) { + for (int i = 0; i < weights.size(); i++) { weights.write[i].weight /= total; + } + } if (weights.size() == 0 || total == 0) { //if nothing, add a weight to bone 0 //no weights assigned @@ -672,8 +687,9 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me ERR_FAIL_INDEX_V(src, p.indices.size(), ERR_INVALID_DATA); Collada::Vertex vertex; - if (!p_optimize) + if (!p_optimize) { vertex.uid = vertidx++; + } int vertex_index = p.indices[src + vertex_ofs]; //used for index field (later used by controllers) int vertex_pos = (vertex_src->stride ? vertex_src->stride : 3) * vertex_index; @@ -752,8 +768,9 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me } //build triangles if needed - if (j == 0) + if (j == 0) { prev2[0] = index; + } if (j >= 2) { //insert indices in reverse order (collada uses CCW as frontface) @@ -809,10 +826,12 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me if (!material_cache.has(target)) { Error err = _create_material(target); - if (!err) + if (!err) { material = material_cache[target]; - } else + } + } else { material = material_cache[target]; + } } else if (p.material != "") { WARN_PRINT("Collada: Unreferenced material in geometry instance: " + p.material); @@ -961,8 +980,9 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres ERR_FAIL_COND_V(interps.stride != 1, ERR_INVALID_DATA); const Collada::CurveData::Source *tilts = nullptr; - if (cd.control_vertices.has("TILT") && cd.sources.has(cd.control_vertices["TILT"])) + if (cd.control_vertices.has("TILT") && cd.sources.has(cd.control_vertices["TILT"])) { tilts = &cd.sources[cd.control_vertices["TILT"]]; + } int pc = vertices.array.size() / 3; for (int i = 0; i < pc; i++) { @@ -985,8 +1005,9 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres out *= collada.state.unit_scale; c->add_point(pos, in - pos, out - pos); - if (tilts) + if (tilts) { c->set_point_tilt(i, tilts->array[i]); + } } curve_cache[ng->source] = c; @@ -1088,8 +1109,9 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres } } - if (!valid) + if (!valid) { morphs.clear(); + } ngsource = ""; } } @@ -1134,10 +1156,12 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres Ref<Material> material; if (!material_cache.has(target)) { Error err = _create_material(target); - if (!err) + if (!err) { material = material_cache[target]; - } else + } + } else { material = material_cache[target]; + } mi->set_surface_material(i, material); } else if (matname != "") { @@ -1151,8 +1175,9 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres for (int i = 0; i < p_node->children.size(); i++) { Error err = _create_resources(p_node->children[i], p_use_compression); - if (err) + if (err) { return err; + } } return OK; } @@ -1274,8 +1299,9 @@ void ColladaImport::_fix_param_animation_tracks() { void ColladaImport::create_animations(bool p_make_tracks_in_all_bones, bool p_import_value_tracks) { _fix_param_animation_tracks(); for (int i = 0; i < collada.state.animation_clips.size(); i++) { - for (int j = 0; j < collada.state.animation_clips[i].tracks.size(); j++) + for (int j = 0; j < collada.state.animation_clips[i].tracks.size(); j++) { tracks_in_clips.insert(collada.state.animation_clips[i].tracks[j]); + } } for (int i = 0; i < collada.state.animation_tracks.size(); i++) { @@ -1304,8 +1330,9 @@ void ColladaImport::create_animations(bool p_make_tracks_in_all_bones, bool p_im } create_animation(-1, p_make_tracks_in_all_bones, p_import_value_tracks); - for (int i = 0; i < collada.state.animation_clips.size(); i++) + for (int i = 0; i < collada.state.animation_clips.size(); i++) { create_animation(i, p_make_tracks_in_all_bones, p_import_value_tracks); + } } void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones, bool p_import_value_tracks) { @@ -1318,8 +1345,9 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones } for (Map<String, NodeMap>::Element *E = node_map.front(); E; E = E->next()) { - if (E->get().bone < 0) + if (E->get().bone < 0) { continue; + } bones_with_animation[E->key()] = false; } //store and validate tracks @@ -1365,8 +1393,9 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones float snapshot_interval = 1.0 / bake_fps; //should be customizable somewhere... float anim_length = collada.state.animation_length; - if (p_clip >= 0 && collada.state.animation_clips[p_clip].end) + if (p_clip >= 0 && collada.state.animation_clips[p_clip].end) { anim_length = collada.state.animation_clips[p_clip].end; + } while (f < anim_length) { base_snapshots.push_back(f); @@ -1416,8 +1445,9 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones //use snapshot keys from anim track instead, because this was most likely exported baked const Collada::AnimationTrack &at = collada.state.animation_tracks[nm.anim_tracks.front()->get()]; snapshots.clear(); - for (int i = 0; i < at.keys.size(); i++) + for (int i = 0; i < at.keys.size(); i++) { snapshots.push_back(at.keys[i].time); + } } for (int i = 0; i < snapshots.size(); i++) { @@ -1429,8 +1459,9 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones continue; } } else { - if (!track_filter.has(ET->get())) + if (!track_filter.has(ET->get())) { continue; + } } found_anim = true; @@ -1494,13 +1525,14 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones } if (nm.bone >= 0) { - if (found_anim) + if (found_anim) { bones_with_animation[E->get()] = true; + } } - if (found_anim) + if (found_anim) { tracks_found = true; - else { + } else { animation->remove_track(track); } } @@ -1508,8 +1540,9 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones if (p_make_tracks_in_all_bones) { //some bones may lack animation, but since we don't store pose as a property, we must add keyframes! for (Map<String, bool>::Element *E = bones_with_animation.front(); E; E = E->next()) { - if (E->get()) + if (E->get()) { continue; + } NodeMap &nm = node_map[E->key()]; String path = scene->get_path_to(nm.node); @@ -1550,18 +1583,21 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones int ti = valid_animated_properties[i]; if (p_clip == -1) { - if (track_filter.has(ti)) + if (track_filter.has(ti)) { continue; + } } else { - if (!track_filter.has(ti)) + if (!track_filter.has(ti)) { continue; + } } const Collada::AnimationTrack &at = collada.state.animation_tracks[ti]; // take snapshots - if (!collada.state.scene_map.has(at.target)) + if (!collada.state.scene_map.has(at.target)) { continue; + } NodeMap &nm = node_map[at.target]; String path = scene->get_path_to(nm.node); @@ -1615,8 +1651,9 @@ void EditorSceneImporterCollada::get_extensions(List<String> *r_extensions) cons Node *EditorSceneImporterCollada::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List<String> *r_missing_deps, Error *r_err) { ColladaImport state; uint32_t flags = Collada::IMPORT_FLAG_SCENE; - if (p_flags & IMPORT_ANIMATION) + if (p_flags & IMPORT_ANIMATION) { flags |= Collada::IMPORT_FLAG_ANIMATION; + } state.use_mesh_builtin_materials = !(p_flags & IMPORT_MATERIALS_IN_INSTANCES); state.bake_fps = p_bake_fps; @@ -1627,10 +1664,10 @@ Node *EditorSceneImporterCollada::import_scene(const String &p_path, uint32_t p_ if (state.missing_textures.size()) { /* - for(int i=0;i<state.missing_textures.size();i++) { - EditorNode::add_io_error("Texture Not Found: "+state.missing_textures[i]); - } - */ + for(int i=0;i<state.missing_textures.size();i++) { + EditorNode::add_io_error("Texture Not Found: "+state.missing_textures[i]); + } + */ if (r_missing_deps) { for (int i = 0; i < state.missing_textures.size(); i++) { @@ -1645,10 +1682,11 @@ Node *EditorSceneImporterCollada::import_scene(const String &p_path, uint32_t p_ AnimationPlayer *ap = memnew(AnimationPlayer); for (int i = 0; i < state.animations.size(); i++) { String name; - if (state.animations[i]->get_name() == "") + if (state.animations[i]->get_name() == "") { name = "default"; - else + } else { name = state.animations[i]->get_name(); + } if (p_flags & IMPORT_ANIMATION_DETECT_LOOP) { if (name.begins_with("loop") || name.ends_with("loop") || name.begins_with("cycle") || name.ends_with("cycle")) { @@ -1674,11 +1712,13 @@ Ref<Animation> EditorSceneImporterCollada::import_animation(const String &p_path ERR_FAIL_COND_V_MSG(err != OK, RES(), "Cannot load animation from file '" + p_path + "'."); state.create_animations(p_flags & EditorSceneImporter::IMPORT_ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS, p_flags & EditorSceneImporter::IMPORT_ANIMATION_KEEP_VALUE_TRACKS); - if (state.scene) + if (state.scene) { memdelete(state.scene); + } - if (state.animations.size() == 0) + if (state.animations.size() == 0) { return Ref<Animation>(); + } Ref<Animation> anim = state.animations[0]; String base = p_path.get_basename().to_lower(); if (p_flags & IMPORT_ANIMATION_DETECT_LOOP) { diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp index 3c9f04322e..6ffff09ce5 100644 --- a/editor/import/editor_scene_importer_gltf.cpp +++ b/editor/import/editor_scene_importer_gltf.cpp @@ -355,8 +355,9 @@ static Vector<uint8_t> _parse_base64_uri(const String &uri) { } Error EditorSceneImporterGLTF::_parse_buffers(GLTFState &state, const String &p_base_path) { - if (!state.json.has("buffers")) + if (!state.json.has("buffers")) { return OK; + } const Array &buffers = state.json["buffers"]; for (GLTFBufferIndex i = 0; i < buffers.size(); i++) { @@ -426,22 +427,29 @@ Error EditorSceneImporterGLTF::_parse_buffer_views(GLTFState &state) { } EditorSceneImporterGLTF::GLTFType EditorSceneImporterGLTF::_get_type_from_str(const String &p_string) { - if (p_string == "SCALAR") + if (p_string == "SCALAR") { return TYPE_SCALAR; + } - if (p_string == "VEC2") + if (p_string == "VEC2") { return TYPE_VEC2; - if (p_string == "VEC3") + } + if (p_string == "VEC3") { return TYPE_VEC3; - if (p_string == "VEC4") + } + if (p_string == "VEC4") { return TYPE_VEC4; + } - if (p_string == "MAT2") + if (p_string == "MAT2") { return TYPE_MAT2; - if (p_string == "MAT3") + } + if (p_string == "MAT3") { return TYPE_MAT3; - if (p_string == "MAT4") + } + if (p_string == "MAT4") { return TYPE_MAT4; + } ERR_FAIL_V(TYPE_SCALAR); } @@ -714,8 +722,9 @@ Vector<double> EditorSceneImporterGLTF::_decode_accessor(GLTFState &state, const ERR_FAIL_INDEX_V(a.buffer_view, state.buffer_views.size(), Vector<double>()); const Error err = _decode_buffer_view(state, dst, a.buffer_view, skip_every, skip_bytes, element_size, a.count, a.type, component_count, a.component_type, component_size, a.normalized, a.byte_offset, p_for_vertex); - if (err != OK) + if (err != OK) { return Vector<double>(); + } } else { //fill with zeros, as bufferview is not defined. @@ -731,14 +740,16 @@ Vector<double> EditorSceneImporterGLTF::_decode_accessor(GLTFState &state, const const int indices_component_size = _get_component_type_size(a.sparse_indices_component_type); Error err = _decode_buffer_view(state, indices.ptrw(), a.sparse_indices_buffer_view, 0, 0, indices_component_size, a.sparse_count, TYPE_SCALAR, 1, a.sparse_indices_component_type, indices_component_size, false, a.sparse_indices_byte_offset, false); - if (err != OK) + if (err != OK) { return Vector<double>(); + } Vector<double> data; data.resize(component_count * a.sparse_count); err = _decode_buffer_view(state, data.ptrw(), a.sparse_values_buffer_view, skip_every, skip_bytes, element_size, a.sparse_count, a.type, component_count, a.component_type, component_size, a.normalized, a.sparse_values_byte_offset, p_for_vertex); - if (err != OK) + if (err != OK) { return Vector<double>(); + } for (int i = 0; i < indices.size(); i++) { const int write_offset = int(indices[i]) * component_count; @@ -756,8 +767,9 @@ Vector<int> EditorSceneImporterGLTF::_decode_accessor_as_ints(GLTFState &state, const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector<int> ret; - if (attribs.size() == 0) + if (attribs.size() == 0) { return ret; + } const double *attribs_ptr = attribs.ptr(); const int ret_size = attribs.size(); @@ -775,8 +787,9 @@ Vector<float> EditorSceneImporterGLTF::_decode_accessor_as_floats(GLTFState &sta const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector<float> ret; - if (attribs.size() == 0) + if (attribs.size() == 0) { return ret; + } const double *attribs_ptr = attribs.ptr(); const int ret_size = attribs.size(); @@ -794,8 +807,9 @@ Vector<Vector2> EditorSceneImporterGLTF::_decode_accessor_as_vec2(GLTFState &sta const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector<Vector2> ret; - if (attribs.size() == 0) + if (attribs.size() == 0) { return ret; + } ERR_FAIL_COND_V(attribs.size() % 2 != 0, ret); const double *attribs_ptr = attribs.ptr(); @@ -814,8 +828,9 @@ Vector<Vector3> EditorSceneImporterGLTF::_decode_accessor_as_vec3(GLTFState &sta const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector<Vector3> ret; - if (attribs.size() == 0) + if (attribs.size() == 0) { return ret; + } ERR_FAIL_COND_V(attribs.size() % 3 != 0, ret); const double *attribs_ptr = attribs.ptr(); @@ -834,8 +849,9 @@ Vector<Color> EditorSceneImporterGLTF::_decode_accessor_as_color(GLTFState &stat const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector<Color> ret; - if (attribs.size() == 0) + if (attribs.size() == 0) { return ret; + } const int type = state.accessors[p_accessor].type; ERR_FAIL_COND_V(!(type == TYPE_VEC3 || type == TYPE_VEC4), ret); @@ -861,8 +877,9 @@ Vector<Quat> EditorSceneImporterGLTF::_decode_accessor_as_quat(GLTFState &state, const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector<Quat> ret; - if (attribs.size() == 0) + if (attribs.size() == 0) { return ret; + } ERR_FAIL_COND_V(attribs.size() % 4 != 0, ret); const double *attribs_ptr = attribs.ptr(); @@ -880,8 +897,9 @@ Vector<Transform2D> EditorSceneImporterGLTF::_decode_accessor_as_xform2d(GLTFSta const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector<Transform2D> ret; - if (attribs.size() == 0) + if (attribs.size() == 0) { return ret; + } ERR_FAIL_COND_V(attribs.size() % 4 != 0, ret); ret.resize(attribs.size() / 4); @@ -896,8 +914,9 @@ Vector<Basis> EditorSceneImporterGLTF::_decode_accessor_as_basis(GLTFState &stat const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector<Basis> ret; - if (attribs.size() == 0) + if (attribs.size() == 0) { return ret; + } ERR_FAIL_COND_V(attribs.size() % 9 != 0, ret); ret.resize(attribs.size() / 9); @@ -913,8 +932,9 @@ Vector<Transform> EditorSceneImporterGLTF::_decode_accessor_as_xform(GLTFState & const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector<Transform> ret; - if (attribs.size() == 0) + if (attribs.size() == 0) { return ret; + } ERR_FAIL_COND_V(attribs.size() % 16 != 0, ret); ret.resize(attribs.size() / 16); @@ -928,8 +948,9 @@ Vector<Transform> EditorSceneImporterGLTF::_decode_accessor_as_xform(GLTFState & } Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) { - if (!state.json.has("meshes")) + if (!state.json.has("meshes")) { return OK; + } Array meshes = state.json["meshes"]; for (GLTFMeshIndex i = 0; i < meshes.size(); i++) { @@ -1214,8 +1235,9 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) { } Error EditorSceneImporterGLTF::_parse_images(GLTFState &state, const String &p_base_path) { - if (!state.json.has("images")) + if (!state.json.has("images")) { return OK; + } const Array &images = state.json["images"]; for (int i = 0; i < images.size(); i++) { @@ -1307,8 +1329,9 @@ Error EditorSceneImporterGLTF::_parse_images(GLTFState &state, const String &p_b } Error EditorSceneImporterGLTF::_parse_textures(GLTFState &state) { - if (!state.json.has("textures")) + if (!state.json.has("textures")) { return OK; + } const Array &textures = state.json["textures"]; for (GLTFTextureIndex i = 0; i < textures.size(); i++) { @@ -1334,8 +1357,9 @@ Ref<Texture2D> EditorSceneImporterGLTF::_get_texture(GLTFState &state, const GLT } Error EditorSceneImporterGLTF::_parse_materials(GLTFState &state) { - if (!state.json.has("materials")) + if (!state.json.has("materials")) { return OK; + } const Array &materials = state.json["materials"]; for (GLTFMaterialIndex i = 0; i < materials.size(); i++) { @@ -1694,8 +1718,9 @@ Error EditorSceneImporterGLTF::_verify_skin(GLTFState &state, GLTFSkin &skin) { } Error EditorSceneImporterGLTF::_parse_skins(GLTFState &state) { - if (!state.json.has("skins")) + if (!state.json.has("skins")) { return OK; + } const Array &skins = state.json["skins"]; @@ -1940,8 +1965,9 @@ Error EditorSceneImporterGLTF::_reparent_to_fake_joint(GLTFState &state, GLTFSke state.nodes.push_back(fake_joint); // We better not be a joint, or we messed up in our logic - if (node->joint) + if (node->joint) { return FAILED; + } fake_joint->translation = node->translation; fake_joint->rotation = node->rotation; @@ -2217,8 +2243,9 @@ void EditorSceneImporterGLTF::_remove_duplicate_skins(GLTFState &state) { } Error EditorSceneImporterGLTF::_parse_cameras(GLTFState &state) { - if (!state.json.has("cameras")) + if (!state.json.has("cameras")) { return OK; + } const Array &cameras = state.json["cameras"]; @@ -2263,8 +2290,9 @@ Error EditorSceneImporterGLTF::_parse_cameras(GLTFState &state) { } Error EditorSceneImporterGLTF::_parse_animations(GLTFState &state) { - if (!state.json.has("animations")) + if (!state.json.has("animations")) { return OK; + } const Array &animations = state.json["animations"]; @@ -2273,8 +2301,9 @@ Error EditorSceneImporterGLTF::_parse_animations(GLTFState &state) { GLTFAnimation animation; - if (!d.has("channels") || !d.has("samplers")) + if (!d.has("channels") || !d.has("samplers")) { continue; + } Array channels = d["channels"]; Array samplers = d["samplers"]; @@ -2289,8 +2318,9 @@ Error EditorSceneImporterGLTF::_parse_animations(GLTFState &state) { for (int j = 0; j < channels.size(); j++) { const Dictionary &c = channels[j]; - if (!c.has("target")) + if (!c.has("target")) { continue; + } const Dictionary &t = c["target"]; if (!t.has("node") || !t.has("path")) { @@ -2401,8 +2431,9 @@ void EditorSceneImporterGLTF::_assign_scene_names(GLTFState &state) { GLTFNode *n = state.nodes[i]; // Any joints get unique names generated when the skeleton is made, unique to the skeleton - if (n->skeleton >= 0) + if (n->skeleton >= 0) { continue; + } if (n->name.empty()) { if (n->mesh >= 0) { @@ -2599,8 +2630,9 @@ T EditorSceneImporterGLTF::_interpolate_track(const Vector<float> &p_times, cons //could use binary search, worth it? int idx = -1; for (int i = 0; i < p_times.size(); i++) { - if (p_times[i] > p_time) + if (p_times[i] > p_time) { break; + } idx++; } @@ -2900,13 +2932,15 @@ Node *EditorSceneImporterGLTF::import_scene(const String &p_path, uint32_t p_fla //binary file //text file Error err = _parse_glb(p_path, state); - if (err) + if (err) { return nullptr; + } } else { //text file Error err = _parse_json(p_path, state); - if (err) + if (err) { return nullptr; + } } ERR_FAIL_COND_V(!state.json.has("asset"), nullptr); @@ -2923,78 +2957,93 @@ Node *EditorSceneImporterGLTF::import_scene(const String &p_path, uint32_t p_fla /* STEP 0 PARSE SCENE */ Error err = _parse_scenes(state); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 1 PARSE NODES */ err = _parse_nodes(state); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 2 PARSE BUFFERS */ err = _parse_buffers(state, p_path.get_base_dir()); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 3 PARSE BUFFER VIEWS */ err = _parse_buffer_views(state); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 4 PARSE ACCESSORS */ err = _parse_accessors(state); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 5 PARSE IMAGES */ err = _parse_images(state, p_path.get_base_dir()); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 6 PARSE TEXTURES */ err = _parse_textures(state); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 7 PARSE TEXTURES */ err = _parse_materials(state); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 9 PARSE SKINS */ err = _parse_skins(state); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 10 DETERMINE SKELETONS */ err = _determine_skeletons(state); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 11 CREATE SKELETONS */ err = _create_skeletons(state); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 12 CREATE SKINS */ err = _create_skins(state); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 13 PARSE MESHES (we have enough info now) */ err = _parse_meshes(state); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 14 PARSE CAMERAS */ err = _parse_cameras(state); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 15 PARSE ANIMATIONS */ err = _parse_animations(state); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 16 ASSIGN SCENE NAMES */ _assign_scene_names(state); diff --git a/editor/import/resource_importer_bitmask.cpp b/editor/import/resource_importer_bitmask.cpp index 5e52a95e4e..da2d1c9bdf 100644 --- a/editor/import/resource_importer_bitmask.cpp +++ b/editor/import/resource_importer_bitmask.cpp @@ -80,8 +80,9 @@ Error ResourceImporterBitMap::import(const String &p_source_file, const String & Ref<Image> image; image.instance(); Error err = ImageLoader::load_image(p_source_file, image); - if (err != OK) + if (err != OK) { return err; + } int w = image->get_width(); int h = image->get_height(); diff --git a/editor/import/resource_importer_layered_texture.cpp b/editor/import/resource_importer_layered_texture.cpp index 2c9e7dcd3b..1f39a12c25 100644 --- a/editor/import/resource_importer_layered_texture.cpp +++ b/editor/import/resource_importer_layered_texture.cpp @@ -239,8 +239,9 @@ Error ResourceImporterLayeredTexture::import(const String &p_source_file, const Ref<Image> image; image.instance(); Error err = ImageLoader::load_image(p_source_file, image, nullptr, false, 1.0); - if (err != OK) + if (err != OK) { return err; + } if (compress_mode == COMPRESS_BASIS_UNIVERSAL && image->get_format() >= Image::FORMAT_RF) { //basis universal does not support float formats, fall back diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp index 4316a9b512..49b47bf4be 100644 --- a/editor/import/resource_importer_obj.cpp +++ b/editor/import/resource_importer_obj.cpp @@ -290,23 +290,26 @@ static Error _parse_obj(const String &p_path, List<Ref<Mesh>> &r_meshes, bool p_ if (face[idx].size() == 3) { int norm = face[idx][2].to_int() - 1; - if (norm < 0) + if (norm < 0) { norm += normals.size() + 1; + } ERR_FAIL_INDEX_V(norm, normals.size(), ERR_FILE_CORRUPT); surf_tool->add_normal(normals[norm]); } if (face[idx].size() >= 2 && face[idx][1] != String()) { int uv = face[idx][1].to_int() - 1; - if (uv < 0) + if (uv < 0) { uv += uvs.size() + 1; + } ERR_FAIL_INDEX_V(uv, uvs.size(), ERR_FILE_CORRUPT); surf_tool->add_uv(uvs[uv]); } int vtx = face[idx][0].to_int() - 1; - if (vtx < 0) + if (vtx < 0) { vtx += vertices.size() + 1; + } ERR_FAIL_INDEX_V(vtx, vertices.size(), ERR_FILE_CORRUPT); Vector3 vertex = vertices[vtx]; @@ -319,10 +322,11 @@ static Error _parse_obj(const String &p_path, List<Ref<Mesh>> &r_meshes, bool p_ } } else if (l.begins_with("s ")) { //smoothing String what = l.substr(2, l.length()).strip_edges(); - if (what == "off") + if (what == "off") { surf_tool->add_smooth_group(false); - else + } else { surf_tool->add_smooth_group(true); + } } else if (/*l.begins_with("g ") ||*/ l.begins_with("usemtl ") || (l.begins_with("o ") || f->eof_reached())) { //commit group to mesh //groups are too annoying if (surf_tool->get_vertex_array().size()) { diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index f4fb0f9f0c..ec82f78e75 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -127,8 +127,9 @@ void EditorScenePostImport::_bind_methods() { } Node *EditorScenePostImport::post_import(Node *p_scene) { - if (get_script_instance()) + if (get_script_instance()) { return get_script_instance()->call("post_import", p_scene); + } return p_scene; } @@ -173,20 +174,24 @@ String ResourceImporterScene::get_resource_type() const { bool ResourceImporterScene::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const { if (p_option.begins_with("animation/")) { - if (p_option != "animation/import" && !bool(p_options["animation/import"])) + if (p_option != "animation/import" && !bool(p_options["animation/import"])) { return false; + } - if (p_option == "animation/keep_custom_tracks" && int(p_options["animation/storage"]) == 0) + if (p_option == "animation/keep_custom_tracks" && int(p_options["animation/storage"]) == 0) { return false; + } - if (p_option.begins_with("animation/optimizer/") && p_option != "animation/optimizer/enabled" && !bool(p_options["animation/optimizer/enabled"])) + if (p_option.begins_with("animation/optimizer/") && p_option != "animation/optimizer/enabled" && !bool(p_options["animation/optimizer/enabled"])) { return false; + } if (p_option.begins_with("animation/clip_")) { int max_clip = p_options["animation/clips/amount"]; int clip = p_option.get_slice("/", 1).get_slice("_", 1).to_int() - 1; - if (clip >= max_clip) + if (clip >= max_clip) { return false; + } } } @@ -240,12 +245,15 @@ static bool _teststr(const String &p_what, const String &p_str) { what = what.substr(0, what.length() - 1); } - if (what.findn("$" + p_str) != -1) //blender and other stuff + if (what.findn("$" + p_str) != -1) { //blender and other stuff return true; - if (what.to_lower().ends_with("-" + p_str)) //collada only supports "_" and "-" besides letters + } + if (what.to_lower().ends_with("-" + p_str)) { //collada only supports "_" and "-" besides letters return true; - if (what.to_lower().ends_with("_" + p_str)) //collada only supports "_" and "-" besides letters + } + if (what.to_lower().ends_with("_" + p_str)) { //collada only supports "_" and "-" besides letters return true; + } return false; } @@ -259,12 +267,15 @@ static String _fixstr(const String &p_what, const String &p_str) { String end = p_what.substr(what.length(), p_what.length() - what.length()); - if (what.findn("$" + p_str) != -1) //blender and other stuff + if (what.findn("$" + p_str) != -1) { //blender and other stuff return what.replace("$" + p_str, "") + end; - if (what.to_lower().ends_with("-" + p_str)) //collada only supports "_" and "-" besides letters + } + if (what.to_lower().ends_with("-" + p_str)) { //collada only supports "_" and "-" besides letters return what.substr(0, what.length() - (p_str.length() + 1)) + end; - if (what.to_lower().ends_with("_" + p_str)) //collada only supports "_" and "-" besides letters + } + if (what.to_lower().ends_with("_" + p_str)) { //collada only supports "_" and "-" besides letters return what.substr(0, what.length() - (p_str.length() + 1)) + end; + } return what; } @@ -308,8 +319,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> if (m.is_valid()) { for (int i = 0; i < m->get_surface_count(); i++) { Ref<StandardMaterial3D> mat = m->surface_get_material(i); - if (!mat.is_valid()) + if (!mat.is_valid()) { continue; + } if (_teststr(mat->get_name(), "alpha")) { mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); @@ -353,8 +365,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> } if (_teststr(name, "colonly") || _teststr(name, "convcolonly")) { - if (isroot) + if (isroot) { return p_node; + } MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_node); if (mi) { Ref<Mesh> mesh = mi->get_mesh(); @@ -436,8 +449,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> } } else if (_teststr(name, "rigid") && Object::cast_to<MeshInstance3D>(p_node)) { - if (isroot) + if (isroot) { return p_node; + } MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_node); Ref<Mesh> mesh = mi->get_mesh(); @@ -523,8 +537,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> } } else if (_teststr(name, "navmesh") && Object::cast_to<MeshInstance3D>(p_node)) { - if (isroot) + if (isroot) { return p_node; + } MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_node); @@ -541,8 +556,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> memdelete(p_node); p_node = nmi; } else if (_teststr(name, "vehicle")) { - if (isroot) + if (isroot) { return p_node; + } Node *owner = p_node->get_owner(); Node3D *s = Object::cast_to<Node3D>(p_node); @@ -560,8 +576,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> p_node = bv; } else if (_teststr(name, "wheel")) { - if (isroot) + if (isroot) { return p_node; + } Node *owner = p_node->get_owner(); Node3D *s = Object::cast_to<Node3D>(p_node); @@ -622,16 +639,18 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> } void ResourceImporterScene::_create_clips(Node *scene, const Array &p_clips, bool p_bake_all) { - if (!scene->has_node(String("AnimationPlayer"))) + if (!scene->has_node(String("AnimationPlayer"))) { return; + } Node *n = scene->get_node(String("AnimationPlayer")); ERR_FAIL_COND(!n); AnimationPlayer *anim = Object::cast_to<AnimationPlayer>(n); ERR_FAIL_COND(!anim); - if (!anim->has_animation("default")) + if (!anim->has_animation("default")) { return; + } Ref<Animation> default_anim = anim->get_animation("default"); @@ -640,8 +659,9 @@ void ResourceImporterScene::_create_clips(Node *scene, const Array &p_clips, boo float from = p_clips[i + 1]; float to = p_clips[i + 2]; bool loop = p_clips[i + 3]; - if (from >= to) + if (from >= to) { continue; + } Ref<Animation> new_anim = memnew(Animation); @@ -746,8 +766,9 @@ void ResourceImporterScene::_filter_anim_tracks(Ref<Animation> anim, Set<String> } void ResourceImporterScene::_filter_tracks(Node *scene, const String &p_text) { - if (!scene->has_node(String("AnimationPlayer"))) + if (!scene->has_node(String("AnimationPlayer"))) { return; + } Node *n = scene->get_node(String("AnimationPlayer")); ERR_FAIL_COND(!n); AnimationPlayer *anim = Object::cast_to<AnimationPlayer>(n); @@ -779,55 +800,63 @@ void ResourceImporterScene::_filter_tracks(Node *scene, const String &p_text) { Vector<String> filters = strings[i].substr(1, strings[i].length()).split(","); for (int j = 0; j < filters.size(); j++) { String fname = filters[j].strip_edges(); - if (fname == "") + if (fname == "") { continue; + } int fc = fname[0]; bool plus; - if (fc == '+') + if (fc == '+') { plus = true; - else if (fc == '-') + } else if (fc == '-') { plus = false; - else + } else { continue; + } String filter = fname.substr(1, fname.length()).strip_edges(); - if (!name.matchn(filter)) + if (!name.matchn(filter)) { continue; + } valid_for_this = plus; } - if (valid_for_this) + if (valid_for_this) { valid = true; + } } else if (valid_for_this) { Ref<Animation> a = anim->get_animation(name); - if (!a.is_valid()) + if (!a.is_valid()) { continue; + } for (int j = 0; j < a->get_track_count(); j++) { String path = a->track_get_path(j); String tname = strings[i]; - if (tname == "") + if (tname == "") { continue; + } int fc = tname[0]; bool plus; - if (fc == '+') + if (fc == '+') { plus = true; - else if (fc == '-') + } else if (fc == '-') { plus = false; - else + } else { continue; + } String filter = tname.substr(1, tname.length()).strip_edges(); - if (!path.matchn(filter)) + if (!path.matchn(filter)) { continue; + } - if (plus) + if (plus) { keep_local.insert(path); - else if (!keep.has(path)) { + } else if (!keep.has(path)) { keep_local.erase(path); } } @@ -844,8 +873,9 @@ void ResourceImporterScene::_filter_tracks(Node *scene, const String &p_text) { } void ResourceImporterScene::_optimize_animations(Node *scene, float p_max_lin_error, float p_max_ang_error, float p_max_angle) { - if (!scene->has_node(String("AnimationPlayer"))) + if (!scene->has_node(String("AnimationPlayer"))) { return; + } Node *n = scene->get_node(String("AnimationPlayer")); ERR_FAIL_COND(!n); AnimationPlayer *anim = Object::cast_to<AnimationPlayer>(n); @@ -1005,10 +1035,12 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String for (int i = 0; i < mesh->get_surface_count(); i++) { mat = mesh->surface_get_material(i); - if (!mat.is_valid()) + if (!mat.is_valid()) { continue; - if (mat->get_name() == "") + } + if (mat->get_name() == "") { continue; + } if (!p_materials.has(mat)) { String ext_name; @@ -1072,8 +1104,9 @@ void ResourceImporterScene::get_import_options(List<ImportOption> *r_options, in String script_ext_hint; for (List<String>::Element *E = script_extentions.front(); E; E = E->next()) { - if (script_ext_hint != "") + if (script_ext_hint != "") { script_ext_hint += ","; + } script_ext_hint += "*." + E->get(); } @@ -1130,8 +1163,9 @@ Node *ResourceImporterScene::import_scene_from_other_importer(EditorSceneImporte String ext = p_path.get_extension().to_lower(); for (Set<Ref<EditorSceneImporter>>::Element *E = importers.front(); E; E = E->next()) { - if (E->get().ptr() == p_exception) + if (E->get().ptr() == p_exception) { continue; + } List<String> extensions; E->get()->get_extensions(&extensions); @@ -1142,8 +1176,9 @@ Node *ResourceImporterScene::import_scene_from_other_importer(EditorSceneImporte } } - if (importer.is_valid()) + if (importer.is_valid()) { break; + } } ERR_FAIL_COND_V(!importer.is_valid(), nullptr); @@ -1158,8 +1193,9 @@ Ref<Animation> ResourceImporterScene::import_animation_from_other_importer(Edito String ext = p_path.get_extension().to_lower(); for (Set<Ref<EditorSceneImporter>>::Element *E = importers.front(); E; E = E->next()) { - if (E->get().ptr() == p_exception) + if (E->get().ptr() == p_exception) { continue; + } List<String> extensions; E->get()->get_extensions(&extensions); @@ -1170,8 +1206,9 @@ Ref<Animation> ResourceImporterScene::import_animation_from_other_importer(Edito } } - if (importer.is_valid()) + if (importer.is_valid()) { break; + } } ERR_FAIL_COND_V(!importer.is_valid(), nullptr); @@ -1199,8 +1236,9 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p } } - if (importer.is_valid()) + if (importer.is_valid()) { break; + } } ERR_FAIL_COND_V(!importer.is_valid(), ERR_FILE_UNRECOGNIZED); @@ -1208,23 +1246,29 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p float fps = p_options["animation/fps"]; int import_flags = EditorSceneImporter::IMPORT_ANIMATION_DETECT_LOOP; - if (!bool(p_options["animation/optimizer/remove_unused_tracks"])) + if (!bool(p_options["animation/optimizer/remove_unused_tracks"])) { import_flags |= EditorSceneImporter::IMPORT_ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS; + } - if (bool(p_options["animation/import"])) + if (bool(p_options["animation/import"])) { import_flags |= EditorSceneImporter::IMPORT_ANIMATION; + } - if (int(p_options["meshes/compress"])) + if (int(p_options["meshes/compress"])) { import_flags |= EditorSceneImporter::IMPORT_USE_COMPRESSION; + } - if (bool(p_options["meshes/ensure_tangents"])) + if (bool(p_options["meshes/ensure_tangents"])) { import_flags |= EditorSceneImporter::IMPORT_GENERATE_TANGENT_ARRAYS; + } - if (int(p_options["materials/location"]) == 0) + if (int(p_options["materials/location"]) == 0) { import_flags |= EditorSceneImporter::IMPORT_MATERIALS_IN_INSTANCES; + } - if (bool(p_options["skins/use_named_skins"])) + if (bool(p_options["skins/use_named_skins"])) { import_flags |= EditorSceneImporter::IMPORT_USE_NAMED_SKIN_BINDS; + } Error err = OK; List<String> missing_deps; // for now, not much will be done with this @@ -1262,10 +1306,11 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p Object::cast_to<Node3D>(scene)->scale(Vector3(root_scale, root_scale, root_scale)); } - if (p_options["nodes/root_name"] != "Scene Root") + if (p_options["nodes/root_name"] != "Scene Root") { scene->set_name(p_options["nodes/root_name"]); - else + } else { scene->set_name(p_save_path.get_file().get_basename()); + } err = OK; @@ -1345,8 +1390,9 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p FileAccess *file = FileAccess::open(cache_file_path, FileAccess::READ, &err2); if (err2) { - if (file) + if (file) { memdelete(file); + } } else { int cache_size = file->get_len(); cache_data.resize(cache_size); @@ -1405,8 +1451,9 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p FileAccess *file = FileAccess::open(cache_file_path, FileAccess::WRITE, &err2); if (err2) { - if (file) + if (file) { memdelete(file); + } } else { // Store number of entries file->store_32(used_unwraps.size()); @@ -1486,8 +1533,9 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p //save sub-scenes as instances! for (int i = 0; i < scene->get_child_count(); i++) { Node *child = scene->get_child(i); - if (child->get_owner() != scene) + if (child->get_owner() != scene) { continue; //not a real child probably created by scene type (ig, a scrollbar) + } _replace_owner(child, scene, child); String cn = String(child->get_name()).strip_edges().replace(".", "_").replace(":", "_"); diff --git a/editor/import/resource_importer_texture.cpp b/editor/import/resource_importer_texture.cpp index ab23ab6db6..a13324f0fc 100644 --- a/editor/import/resource_importer_texture.cpp +++ b/editor/import/resource_importer_texture.cpp @@ -314,16 +314,21 @@ void ResourceImporterTexture::_save_stex(const Ref<Image> &p_image, const String f->store_32(p_image->get_height()); uint32_t flags = 0; - if (p_streamable) + if (p_streamable) { flags |= StreamTexture2D::FORMAT_BIT_STREAM; - if (p_mipmaps) + } + if (p_mipmaps) { flags |= StreamTexture2D::FORMAT_BIT_HAS_MIPMAPS; //mipmaps bit - if (p_detect_3d) + } + if (p_detect_3d) { flags |= StreamTexture2D::FORMAT_BIT_DETECT_3D; - if (p_detect_roughness) + } + if (p_detect_roughness) { flags |= StreamTexture2D::FORMAT_BIT_DETECT_ROUGNESS; - if (p_detect_normal) + } + if (p_detect_normal) { flags |= StreamTexture2D::FORMAT_BIT_DETECT_NORMAL; + } f->store_32(flags); f->store_32(p_limit_mipmap); @@ -407,8 +412,9 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String Ref<Image> image; image.instance(); Error err = ImageLoader::load_image(p_source_file, image, nullptr, hdr_as_srgb, scale); - if (err != OK) + if (err != OK) { return err; + } Array formats_imported; diff --git a/editor/import/resource_importer_texture_atlas.cpp b/editor/import/resource_importer_texture_atlas.cpp index 0ef5d84eca..0818655c4c 100644 --- a/editor/import/resource_importer_texture_atlas.cpp +++ b/editor/import/resource_importer_texture_atlas.cpp @@ -176,10 +176,11 @@ static void _plot_triangle(Vector2 *vertices, const Vector2 &p_offset, bool p_tr } } xf += dx_far; - if (yi < y[1]) + if (yi < y[1]) { xt += dx_upper; - else + } else { xt += dx_low; + } } } diff --git a/editor/import/resource_importer_wav.cpp b/editor/import/resource_importer_wav.cpp index eace84400a..cb669b4c89 100644 --- a/editor/import/resource_importer_wav.cpp +++ b/editor/import/resource_importer_wav.cpp @@ -260,8 +260,9 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s * 22:38 06.07.2017 GMT **/ - for (int i = 0; i < 10; i++) + for (int i = 0; i < 10; i++) { file->get_32(); // i wish to know why should i do this... no doc! + } // only read 0x00 (loop forward), 0x01 (loop ping-pong) and 0x02 (loop backward) // Skip anything else because it's not supported, reserved for future uses or sampler specific @@ -361,8 +362,9 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s float max = 0; for (int i = 0; i < data.size(); i++) { float amp = Math::abs(data[i]); - if (amp > max) + if (amp > max) { max = amp; + } } if (max > 0) { diff --git a/editor/import/resource_importer_wav.h b/editor/import/resource_importer_wav.h index b48c5f4c32..3ff3aea9f4 100644 --- a/editor/import/resource_importer_wav.h +++ b/editor/import/resource_importer_wav.h @@ -72,8 +72,9 @@ public: int datalen = p_data.size(); int datamax = datalen; - if (datalen & 1) + if (datalen & 1) { datalen++; + } dst_data.resize(datalen / 2 + 4); uint8_t *w = dst_data.ptrw(); @@ -96,9 +97,9 @@ public: uint8_t nibble; int16_t xm_sample; - if (i >= datamax) + if (i >= datamax) { xm_sample = 0; - else { + } else { xm_sample = CLAMP(in[i] * 32767.0, -32768, 32767); /* if (xm_sample==32767 || xm_sample==-32768) @@ -130,10 +131,11 @@ public: mask >>= 1; }; - if (nibble & 8) + if (nibble & 8) { prev -= vpdiff; - else + } else { prev += vpdiff; + } if (prev > 32767) { //printf("%i,xms %i, prev %i,diff %i, vpdiff %i, clip up %i\n",i,xm_sample,prev,diff,vpdiff,prev); @@ -144,10 +146,11 @@ public: } step_idx += _ima_adpcm_index_table[nibble]; - if (step_idx < 0) + if (step_idx < 0) { step_idx = 0; - else if (step_idx > 88) + } else if (step_idx > 88) { step_idx = 88; + } if (i & 1) { *out |= nibble << 4; diff --git a/editor/import_dock.cpp b/editor/import_dock.cpp index 4a3011086f..1128b72c5a 100644 --- a/editor/import_dock.cpp +++ b/editor/import_dock.cpp @@ -66,8 +66,9 @@ public: } void _get_property_list(List<PropertyInfo> *p_list) const { for (const List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) { - if (!importer->get_option_visibility(E->get().name, values)) + if (!importer->get_option_visibility(E->get().name, values)) { continue; + } PropertyInfo pi = E->get(); if (checking) { pi.usage |= PROPERTY_USAGE_CHECKABLE; @@ -367,8 +368,9 @@ void ImportDock::clear() { } static bool _find_owners(EditorFileSystemDirectory *efsd, const String &p_path) { - if (!efsd) + if (!efsd) { return false; + } for (int i = 0; i < efsd->get_subdir_count(); i++) { if (_find_owners(efsd->get_subdir(i), p_path)) { @@ -378,8 +380,9 @@ static bool _find_owners(EditorFileSystemDirectory *efsd, const String &p_path) for (int i = 0; i < efsd->get_file_count(); i++) { Vector<String> deps = efsd->get_file_deps(i); - if (deps.find(p_path) != -1) + if (deps.find(p_path) != -1) { return true; + } } return false; diff --git a/editor/inspector_dock.cpp b/editor/inspector_dock.cpp index 8ada7e9ba5..2b26851140 100644 --- a/editor/inspector_dock.cpp +++ b/editor/inspector_dock.cpp @@ -68,14 +68,16 @@ void InspectorDock::_menu_option(int p_option) { case OBJECT_COPY_PARAMS: { editor_data->apply_changes_in_editors(); - if (current) + if (current) { editor_data->copy_object_params(current); + } } break; case OBJECT_PASTE_PARAMS: { editor_data->apply_changes_in_editors(); - if (current) + if (current) { editor_data->paste_object_params(current); + } } break; case OBJECT_UNIQUE_RESOURCES: { @@ -85,8 +87,9 @@ void InspectorDock::_menu_option(int p_option) { current->get_property_list(&props); Map<RES, RES> duplicates; for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { continue; + } Variant v = current->get(E->get().name); if (v.is_ref()) { @@ -169,10 +172,11 @@ void InspectorDock::_save_resource(bool save_as) const { RES current_res = RES(Object::cast_to<Resource>(current_obj)); - if (save_as) + if (save_as) { editor->save_resource_as(current_res); - else + } else { editor->save_resource(current_res); + } } void InspectorDock::_unref_resource() const { @@ -233,9 +237,9 @@ void InspectorDock::_prepare_history() { String text; if (Object::cast_to<Resource>(obj)) { Resource *r = Object::cast_to<Resource>(obj); - if (r->get_path().is_resource_file()) + if (r->get_path().is_resource_file()) { text = r->get_path().get_file(); - else if (r->get_name() != String()) { + } else if (r->get_name() != String()) { text = r->get_name(); } else { text = r->get_class(); @@ -259,8 +263,9 @@ void InspectorDock::_select_history(int p_idx) { //push it to the top, it is not correct, but it's more useful ObjectID id = EditorNode::get_singleton()->get_editor_history()->get_history_obj(p_idx); Object *obj = ObjectDB::get_instance(id); - if (!obj) + if (!obj) { return; + } editor->push_item(obj); } @@ -276,22 +281,25 @@ void InspectorDock::_resource_created() { } void InspectorDock::_resource_selected(const RES &p_res, const String &p_property) { - if (p_res.is_null()) + if (p_res.is_null()) { return; + } RES r = p_res; editor->push_item(r.operator->(), p_property); } void InspectorDock::_edit_forward() { - if (EditorNode::get_singleton()->get_editor_history()->next()) + if (EditorNode::get_singleton()->get_editor_history()->next()) { editor->edit_current(); + } } void InspectorDock::_edit_back() { EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history(); - if ((current && editor_history->previous()) || editor_history->get_path_size() == 1) + if ((current && editor_history->previous()) || editor_history->get_path_size() == 1) { editor->edit_current(); + } } void InspectorDock::_menu_collapseall() { @@ -308,8 +316,9 @@ void InspectorDock::_property_keyed(const String &p_keyed, const Variant &p_valu void InspectorDock::_transform_keyed(Object *sp, const String &p_sub, const Transform &p_key) { Node3D *s = Object::cast_to<Node3D>(sp); - if (!s) + if (!s) { return; + } AnimationPlayerEditor::singleton->get_track_editor()->insert_transform_key(s, p_sub, p_key); } diff --git a/editor/multi_node_edit.cpp b/editor/multi_node_edit.cpp index 0d795cc163..1077aca7b3 100644 --- a/editor/multi_node_edit.cpp +++ b/editor/multi_node_edit.cpp @@ -39,8 +39,9 @@ bool MultiNodeEdit::_set(const StringName &p_name, const Variant &p_value) { bool MultiNodeEdit::_set_impl(const StringName &p_name, const Variant &p_value, const String &p_field) { Node *es = EditorNode::get_singleton()->get_edited_scene(); - if (!es) + if (!es) { return false; + } String name = p_name; @@ -52,12 +53,14 @@ bool MultiNodeEdit::_set_impl(const StringName &p_name, const Variant &p_value, ur->create_action(TTR("MultiNode Set") + " " + String(name), UndoRedo::MERGE_ENDS); for (const List<NodePath>::Element *E = nodes.front(); E; E = E->next()) { - if (!es->has_node(E->get())) + if (!es->has_node(E->get())) { continue; + } Node *n = es->get_node(E->get()); - if (!n) + if (!n) { continue; + } if (p_value.get_type() == Variant::NODE_PATH) { Node *tonode = n->get_node(p_value); @@ -86,8 +89,9 @@ bool MultiNodeEdit::_set_impl(const StringName &p_name, const Variant &p_value, bool MultiNodeEdit::_get(const StringName &p_name, Variant &r_ret) const { Node *es = EditorNode::get_singleton()->get_edited_scene(); - if (!es) + if (!es) { return false; + } String name = p_name; if (name == "scripts") { // script set is intercepted at object level (check Variant Object::get() ) ,so use a different name @@ -95,17 +99,20 @@ bool MultiNodeEdit::_get(const StringName &p_name, Variant &r_ret) const { } for (const List<NodePath>::Element *E = nodes.front(); E; E = E->next()) { - if (!es->has_node(E->get())) + if (!es->has_node(E->get())) { continue; + } const Node *n = es->get_node(E->get()); - if (!n) + if (!n) { continue; + } bool found; r_ret = n->get(name, &found); - if (found) + if (found) { return true; + } } return false; @@ -115,27 +122,31 @@ void MultiNodeEdit::_get_property_list(List<PropertyInfo> *p_list) const { HashMap<String, PLData> usage; Node *es = EditorNode::get_singleton()->get_edited_scene(); - if (!es) + if (!es) { return; + } int nc = 0; List<PLData *> data_list; for (const List<NodePath>::Element *E = nodes.front(); E; E = E->next()) { - if (!es->has_node(E->get())) + if (!es->has_node(E->get())) { continue; + } Node *n = es->get_node(E->get()); - if (!n) + if (!n) { continue; + } List<PropertyInfo> plist; n->get_property_list(&plist, true); for (List<PropertyInfo>::Element *F = plist.front(); F; F = F->next()) { - if (F->get().name == "script") + if (F->get().name == "script") { continue; //added later manually, since this is intercepted before being set (check Variant Object::get() ) + } if (!usage.has(F->get().name)) { PLData pld; pld.uses = 0; @@ -145,8 +156,9 @@ void MultiNodeEdit::_get_property_list(List<PropertyInfo> *p_list) const { } // Make sure only properties with the same exact PropertyInfo data will appear - if (usage[F->get().name].info == F->get()) + if (usage[F->get().name].info == F->get()) { usage[F->get().name].uses++; + } } nc++; diff --git a/editor/node_3d_editor_gizmos.cpp b/editor/node_3d_editor_gizmos.cpp index 20b84f9358..0eb4e6036a 100644 --- a/editor/node_3d_editor_gizmos.cpp +++ b/editor/node_3d_editor_gizmos.cpp @@ -71,21 +71,25 @@ bool EditorNode3DGizmo::is_editable() const { ERR_FAIL_COND_V(!spatial_node, false); Node *edited_root = spatial_node->get_tree()->get_edited_scene_root(); - if (spatial_node == edited_root) + if (spatial_node == edited_root) { return true; - if (spatial_node->get_owner() == edited_root) + } + if (spatial_node->get_owner() == edited_root) { return true; + } - if (edited_root->is_editable_instance(spatial_node->get_owner())) + if (edited_root->is_editable_instance(spatial_node->get_owner())) { return true; + } return false; } void EditorNode3DGizmo::clear() { for (int i = 0; i < instances.size(); i++) { - if (instances[i].instance.is_valid()) + if (instances[i].instance.is_valid()) { RS::get_singleton()->free(instances[i].instance); + } } billboard_handle = false; @@ -164,8 +168,9 @@ void EditorNode3DGizmo::Instance::create_instance(Node3D *p_base, bool p_hidden) if (skin_reference.is_valid()) { RS::get_singleton()->instance_attach_skeleton(instance, skin_reference->get_skeleton()); } - if (extra_margin) + if (extra_margin) { RS::get_singleton()->instance_set_extra_visibility_margin(instance, 1); + } RS::get_singleton()->instance_geometry_set_cast_shadows_setting(instance, RS::SHADOW_CASTING_SETTING_OFF); int layer = p_hidden ? 0 : 1 << Node3DEditorViewport::GIZMO_EDIT_LAYER; RS::get_singleton()->instance_set_layer_mask(instance, layer); //gizmos are 26 @@ -209,10 +214,11 @@ void EditorNode3DGizmo::add_lines(const Vector<Vector3> &p_lines, const Ref<Mate { Color *w = color.ptrw(); for (int i = 0; i < p_lines.size(); i++) { - if (is_selected()) + if (is_selected()) { w[i] = Color(1, 1, 1, 0.8) * p_modulate; - else + } else { w[i] = Color(1, 1, 1, 0.2) * p_modulate; + } } } @@ -320,8 +326,9 @@ void EditorNode3DGizmo::add_collision_segments(const Vector<Vector3> &p_lines) { void EditorNode3DGizmo::add_handles(const Vector<Vector3> &p_handles, const Ref<Material> &p_material, bool p_billboard, bool p_secondary) { billboard_handle = p_billboard; - if (!is_selected() || !is_editable()) + if (!is_selected() || !is_editable()) { return; + } ERR_FAIL_COND(!spatial_node); @@ -338,11 +345,13 @@ void EditorNode3DGizmo::add_handles(const Vector<Vector3> &p_handles, const Ref< Color *w = colors.ptrw(); for (int i = 0; i < p_handles.size(); i++) { Color col(1, 1, 1, 1); - if (is_handle_highlighted(i)) + if (is_handle_highlighted(i)) { col = Color(0, 0, 1, 0.9); + } - if (Node3DEditor::get_singleton()->get_over_gizmo_handle() != i) + if (Node3DEditor::get_singleton()->get_over_gizmo_handle() != i) { col.a = 0.8; + } w[i] = col; } @@ -410,8 +419,9 @@ bool EditorNode3DGizmo::intersect_frustum(const Camera3D *p_camera, const Vector ERR_FAIL_COND_V(!spatial_node, false); ERR_FAIL_COND_V(!valid, false); - if (hidden && !gizmo_plugin->is_selectable_when_hidden()) + if (hidden && !gizmo_plugin->is_selectable_when_hidden()) { return false; + } if (selectable_icon_size > 0.0f) { Vector3 origin = spatial_node->get_global_transform().get_origin(); @@ -448,12 +458,14 @@ bool EditorNode3DGizmo::intersect_frustum(const Camera3D *p_camera, const Vector break; } } - if (any_out) + if (any_out) { break; + } } - if (!any_out) + if (!any_out) { return true; + } } if (collision_mesh.is_valid()) { @@ -483,8 +495,9 @@ bool EditorNode3DGizmo::intersect_ray(Camera3D *p_camera, const Point2 &p_point, ERR_FAIL_COND_V(!spatial_node, false); ERR_FAIL_COND_V(!valid, false); - if (hidden && !gizmo_plugin->is_selectable_when_hidden()) + if (hidden && !gizmo_plugin->is_selectable_when_hidden()) { return false; + } if (r_gizmo_handle && !hidden) { Transform t = spatial_node->get_global_transform(); @@ -618,8 +631,9 @@ bool EditorNode3DGizmo::intersect_ray(Camera3D *p_camera, const Point2 &p_point, tcp = a; } - if (camp.distance_to(tcp) < p_camera->get_znear()) + if (camp.distance_to(tcp) < p_camera->get_znear()) { continue; + } cp = tcp; cpd = pd; } @@ -681,8 +695,9 @@ void EditorNode3DGizmo::free() { ERR_FAIL_COND(!valid); for (int i = 0; i < instances.size(); i++) { - if (instances[i].instance.is_valid()) + if (instances[i].instance.is_valid()) { RS::get_singleton()->free(instances[i].instance); + } instances.write[i].instance = RID(); } @@ -743,8 +758,9 @@ EditorNode3DGizmo::EditorNode3DGizmo() { } EditorNode3DGizmo::~EditorNode3DGizmo() { - if (gizmo_plugin != nullptr) + if (gizmo_plugin != nullptr) { gizmo_plugin->unregister_gizmo(this); + } clear(); } @@ -783,18 +799,21 @@ int Light3DGizmoPlugin::get_priority() const { } String Light3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const { - if (p_idx == 0) + if (p_idx == 0) { return "Radius"; - else + } else { return "Aperture"; + } } Variant Light3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const { Light3D *light = Object::cast_to<Light3D>(p_gizmo->get_spatial_node()); - if (p_idx == 0) + if (p_idx == 0) { return light->get_param(Light3D::PARAM_RANGE); - if (p_idx == 1) + } + if (p_idx == 1) { return light->get_param(Light3D::PARAM_SPOT_ANGLE); + } return Variant(); } @@ -845,8 +864,9 @@ void Light3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camer d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap()); } - if (d <= 0) // Equal is here for negative zero. + if (d <= 0) { // Equal is here for negative zero. d = 0; + } light->set_param(Light3D::PARAM_RANGE, d); } else if (Object::cast_to<OmniLight3D>(light)) { @@ -1429,8 +1449,9 @@ void MeshInstance3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { Ref<Mesh> m = mesh->get_mesh(); - if (!m.is_valid()) + if (!m.is_valid()) { return; //none + } Ref<TriangleMesh> tm = m->generate_triangle_mesh(); if (tm.is_valid()) { @@ -1591,8 +1612,9 @@ void Skeleton3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { for (int j = 0; j < 3; j++) { float dp = Math::abs(grests[parent].basis[j].normalized().dot(d)); - if (j == 0 || dp > closest_d) + if (j == 0 || dp > closest_d) { closest = j; + } } //find closest other @@ -1610,8 +1632,9 @@ void Skeleton3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { surface_tool->add_color(rootcolor); surface_tool->add_vertex(v0 + grests[parent].basis[j].normalized() * dist * 0.05); - if (j == closest) + if (j == closest) { continue; + } Vector3 axis; if (first == Vector3()) { @@ -1622,8 +1645,9 @@ void Skeleton3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { } for (int k = 0; k < 2; k++) { - if (k == 1) + if (k == 1) { axis = -axis; + } Vector3 point = v0 + d * dist * 0.2; point += axis * dist * 0.1; @@ -1747,20 +1771,24 @@ void PhysicalBone3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { PhysicalBone3D *physical_bone = Object::cast_to<PhysicalBone3D>(p_gizmo->get_spatial_node()); - if (!physical_bone) + if (!physical_bone) { return; + } Skeleton3D *sk(physical_bone->find_skeleton_parent()); - if (!sk) + if (!sk) { return; + } PhysicalBone3D *pb(sk->get_physical_bone(physical_bone->get_bone_id())); - if (!pb) + if (!pb) { return; + } PhysicalBone3D *pbp(sk->get_physical_bone_parent(physical_bone->get_bone_id())); - if (!pbp) + if (!pbp) { return; + } Vector<Vector3> points; @@ -2160,8 +2188,9 @@ void VisibilityNotifier3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap()); } - if (d < 0.001) + if (d < 0.001) { d = 0.001; + } //resize aabb.position[p_idx] = (aabb.position[p_idx] + aabb.size[p_idx] * 0.5) - d; aabb.size[p_idx] = d * 2; @@ -2350,8 +2379,9 @@ void GPUParticles3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap()); } - if (d < 0.001) + if (d < 0.001) { d = 0.001; + } //resize aabb.position[p_idx] = (aabb.position[p_idx] + aabb.size[p_idx] * 0.5) - d; aabb.size[p_idx] = d * 2; @@ -2499,8 +2529,9 @@ void ReflectionProbeGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_id d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap()); } - if (d < 0.001) + if (d < 0.001) { d = 0.001; + } extents[p_idx] = d; probe->set_extents(extents); @@ -2676,8 +2707,9 @@ void DecalGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3 d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap()); } - if (d < 0.001) + if (d < 0.001) { d = 0.001; + } extents[p_idx] = d; decal->set_extents(extents); @@ -2816,8 +2848,9 @@ void GIProbeGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camer d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap()); } - if (d < 0.001) + if (d < 0.001) { d = 0.001; + } extents[p_idx] = d; probe->set_extents(extents); @@ -3239,8 +3272,9 @@ String CollisionShape3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_g const CollisionShape3D *cs = Object::cast_to<CollisionShape3D>(p_gizmo->get_spatial_node()); Ref<Shape3D> s = cs->get_shape(); - if (s.is_null()) + if (s.is_null()) { return ""; + } if (Object::cast_to<SphereShape3D>(*s)) { return "Radius"; @@ -3269,8 +3303,9 @@ Variant CollisionShape3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo CollisionShape3D *cs = Object::cast_to<CollisionShape3D>(p_gizmo->get_spatial_node()); Ref<Shape3D> s = cs->get_shape(); - if (s.is_null()) + if (s.is_null()) { return Variant(); + } if (Object::cast_to<SphereShape3D>(*s)) { Ref<SphereShape3D> ss = s; @@ -3304,8 +3339,9 @@ void CollisionShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_i CollisionShape3D *cs = Object::cast_to<CollisionShape3D>(p_gizmo->get_spatial_node()); Ref<Shape3D> s = cs->get_shape(); - if (s.is_null()) + if (s.is_null()) { return; + } Transform gt = cs->get_global_transform(); Transform gi = gt.affine_inverse(); @@ -3324,8 +3360,9 @@ void CollisionShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_i d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap()); } - if (d < 0.001) + if (d < 0.001) { d = 0.001; + } ss->set_radius(d); } @@ -3339,8 +3376,9 @@ void CollisionShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_i d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap()); } - if (d < 0.001) + if (d < 0.001) { d = 0.001; + } rs->set_length(d); } @@ -3356,8 +3394,9 @@ void CollisionShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_i d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap()); } - if (d < 0.001) + if (d < 0.001) { d = 0.001; + } Vector3 he = bs->get_extents(); he[p_idx] = d; @@ -3371,20 +3410,23 @@ void CollisionShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_i Vector3 ra, rb; Geometry::get_closest_points_between_segments(Vector3(), axis * 4096, sg[0], sg[1], ra, rb); float d = axis.dot(ra); - if (p_idx == 1) + if (p_idx == 1) { d -= cs2->get_radius(); + } if (Node3DEditor::get_singleton()->is_snap_enabled()) { d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap()); } - if (d < 0.001) + if (d < 0.001) { d = 0.001; + } - if (p_idx == 0) + if (p_idx == 0) { cs2->set_radius(d); - else if (p_idx == 1) + } else if (p_idx == 1) { cs2->set_height(d * 2.0); + } } if (Object::cast_to<CylinderShape3D>(*s)) { @@ -3398,13 +3440,15 @@ void CollisionShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_i d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap()); } - if (d < 0.001) + if (d < 0.001) { d = 0.001; + } - if (p_idx == 0) + if (p_idx == 0) { cs2->set_radius(d); - else if (p_idx == 1) + } else if (p_idx == 1) { cs2->set_height(d * 2.0); + } } } @@ -3412,8 +3456,9 @@ void CollisionShape3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int CollisionShape3D *cs = Object::cast_to<CollisionShape3D>(p_gizmo->get_spatial_node()); Ref<Shape3D> s = cs->get_shape(); - if (s.is_null()) + if (s.is_null()) { return; + } if (Object::cast_to<SphereShape3D>(*s)) { Ref<SphereShape3D> ss = s; @@ -3446,10 +3491,11 @@ void CollisionShape3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int if (Object::cast_to<CapsuleShape3D>(*s)) { Ref<CapsuleShape3D> ss = s; if (p_cancel) { - if (p_idx == 0) + if (p_idx == 0) { ss->set_radius(p_restore); - else + } else { ss->set_height(p_restore); + } return; } @@ -3470,10 +3516,11 @@ void CollisionShape3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int if (Object::cast_to<CylinderShape3D>(*s)) { Ref<CylinderShape3D> ss = s; if (p_cancel) { - if (p_idx == 0) + if (p_idx == 0) { ss->set_radius(p_restore); - else + } else { ss->set_height(p_restore); + } return; } @@ -3516,8 +3563,9 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { p_gizmo->clear(); Ref<Shape3D> s = cs->get_shape(); - if (s.is_null()) + if (s.is_null()) { return; + } const Ref<Material> material = get_material(!cs->is_disabled() ? "shape_material" : "shape_material_disabled", p_gizmo); @@ -3877,8 +3925,9 @@ void NavigationRegion3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { p_gizmo->clear(); Ref<NavigationMesh> navmeshie = navmesh->get_navigation_mesh(); - if (navmeshie.is_null()) + if (navmeshie.is_null()) { return; + } Vector<Vector3> vertices = navmeshie->get_vertices(); const Vector3 *vr = vertices.ptr(); @@ -3896,8 +3945,9 @@ void NavigationRegion3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { } } - if (faces.empty()) + if (faces.empty()) { return; + } Map<_EdgeKey, bool> edge_map; Vector<Vector3> tmeshfaces; @@ -3915,8 +3965,9 @@ void NavigationRegion3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { _EdgeKey ek; ek.from = f.vertex[j].snapped(Vector3(CMP_EPSILON, CMP_EPSILON, CMP_EPSILON)); ek.to = f.vertex[(j + 1) % 3].snapped(Vector3(CMP_EPSILON, CMP_EPSILON, CMP_EPSILON)); - if (ek.from < ek.to) + if (ek.from < ek.to) { SWAP(ek.from, ek.to); + } Map<_EdgeKey, bool>::Element *F = edge_map.find(ek); @@ -3941,8 +3992,9 @@ void NavigationRegion3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { Ref<TriangleMesh> tmesh = memnew(TriangleMesh); tmesh->create(tmeshfaces); - if (lines.size()) + if (lines.size()) { p_gizmo->add_lines(lines, navmesh->is_enabled() ? edge_material : edge_material_disabled); + } p_gizmo->add_collision_triangles(tmesh); Ref<ArrayMesh> m = memnew(ArrayMesh); Array a; @@ -4446,7 +4498,7 @@ void Joint3DGizmoPlugin::CreateSliderJointGizmo(const Transform &p_offset, const r_points.push_back(p_offset.translated(Vector3(-cs * 2, 0, 0)).origin); } - if (r_body_a_points) + if (r_body_a_points) { JointGizmosDrawer::draw_circle( Vector3::AXIS_X, BODY_A_RADIUS, @@ -4455,8 +4507,9 @@ void Joint3DGizmoPlugin::CreateSliderJointGizmo(const Transform &p_offset, const p_angular_limit_lower, p_angular_limit_upper, *r_body_a_points); + } - if (r_body_b_points) + if (r_body_b_points) { JointGizmosDrawer::draw_circle( Vector3::AXIS_X, BODY_B_RADIUS, @@ -4466,24 +4519,27 @@ void Joint3DGizmoPlugin::CreateSliderJointGizmo(const Transform &p_offset, const p_angular_limit_upper, *r_body_b_points, true); + } } void Joint3DGizmoPlugin::CreateConeTwistJointGizmo(const Transform &p_offset, const Transform &p_trs_joint, const Transform &p_trs_body_a, const Transform &p_trs_body_b, real_t p_swing, real_t p_twist, Vector<Vector3> *r_body_a_points, Vector<Vector3> *r_body_b_points) { - if (r_body_a_points) + if (r_body_a_points) { JointGizmosDrawer::draw_cone( p_offset, JointGizmosDrawer::look_body(p_trs_joint, p_trs_body_a), p_swing, p_twist, *r_body_a_points); + } - if (r_body_b_points) + if (r_body_b_points) { JointGizmosDrawer::draw_cone( p_offset, JointGizmosDrawer::look_body(p_trs_joint, p_trs_body_b), p_swing, p_twist, *r_body_b_points); + } } void Joint3DGizmoPlugin::CreateGeneric6DOFJointGizmo( @@ -4603,7 +4659,7 @@ void Joint3DGizmoPlugin::CreateGeneric6DOFJointGizmo( ul = -1; } - if (r_body_a_points) + if (r_body_a_points) { JointGizmosDrawer::draw_circle( static_cast<Vector3::Axis>(ax), BODY_A_RADIUS, @@ -4613,8 +4669,9 @@ void Joint3DGizmoPlugin::CreateGeneric6DOFJointGizmo( ul, *r_body_a_points, true); + } - if (r_body_b_points) + if (r_body_b_points) { JointGizmosDrawer::draw_circle( static_cast<Vector3::Axis>(ax), BODY_B_RADIUS, @@ -4623,6 +4680,7 @@ void Joint3DGizmoPlugin::CreateGeneric6DOFJointGizmo( ll, ul, *r_body_b_points); + } } #undef ADD_VTX diff --git a/editor/node_dock.cpp b/editor/node_dock.cpp index aa3ebe5ce7..9b9cfad9eb 100644 --- a/editor/node_dock.cpp +++ b/editor/node_dock.cpp @@ -68,10 +68,11 @@ void NodeDock::set_node(Node *p_node) { groups->set_current(p_node); if (p_node) { - if (connections_button->is_pressed()) + if (connections_button->is_pressed()) { connections->show(); - else + } else { groups->show(); + } mode_hb->show(); select_a_node->hide(); diff --git a/editor/pane_drag.cpp b/editor/pane_drag.cpp index 8cadc3925e..09f2b90b90 100644 --- a/editor/pane_drag.cpp +++ b/editor/pane_drag.cpp @@ -41,8 +41,9 @@ void PaneDrag::_notification(int p_what) { switch (p_what) { case NOTIFICATION_DRAW: { Ref<Texture2D> icon = mouse_over ? get_theme_icon("PaneDragHover", "EditorIcons") : get_theme_icon("PaneDrag", "EditorIcons"); - if (!icon.is_null()) + if (!icon.is_null()) { icon->draw(get_canvas_item(), Point2(0, 0)); + } } break; case NOTIFICATION_MOUSE_ENTER: @@ -58,8 +59,9 @@ void PaneDrag::_notification(int p_what) { Size2 PaneDrag::get_minimum_size() const { Ref<Texture2D> icon = get_theme_icon("PaneDrag", "EditorIcons"); - if (!icon.is_null()) + if (!icon.is_null()) { return icon->get_size(); + } return Size2(); } diff --git a/editor/plugin_config_dialog.cpp b/editor/plugin_config_dialog.cpp index ac8f4a1ad5..3ad6938498 100644 --- a/editor/plugin_config_dialog.cpp +++ b/editor/plugin_config_dialog.cpp @@ -56,8 +56,9 @@ void PluginConfigDialog::_on_confirmed() { if (!_edit_mode) { DirAccess *d = DirAccess::create(DirAccess::ACCESS_RESOURCES); - if (!d || d->make_dir_recursive(path) != OK) + if (!d || d->make_dir_recursive(path) != OK) { return; + } } Ref<ConfigFile> cf = memnew(ConfigFile); diff --git a/editor/plugins/abstract_polygon_2d_editor.cpp b/editor/plugins/abstract_polygon_2d_editor.cpp index d3e4c20e50..1abba45f9e 100644 --- a/editor/plugins/abstract_polygon_2d_editor.cpp +++ b/editor/plugins/abstract_polygon_2d_editor.cpp @@ -47,16 +47,18 @@ bool AbstractPolygon2DEditor::Vertex::valid() const { } 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; @@ -185,8 +187,9 @@ void AbstractPolygon2DEditor::_wip_cancel() { } void AbstractPolygon2DEditor::_wip_close() { - if (!wip_active) + if (!wip_active) { return; + } if (_is_line()) { _set_polygon(0, wip); @@ -234,8 +237,9 @@ 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; @@ -248,8 +252,9 @@ 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(); @@ -260,8 +265,9 @@ 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); @@ -464,8 +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 @@ -476,8 +483,9 @@ 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; @@ -486,8 +494,9 @@ void AbstractPolygon2DEditor::forward_canvas_draw_over_viewport(Control *p_overl points = Variant(wip); offset = Vector2(0, 0); } else { - if (j == -1) + if (j == -1) { continue; + } points = _get_polygon(j); offset = _get_offset(j); } @@ -519,10 +528,11 @@ void AbstractPolygon2DEditor::forward_canvas_draw_over_viewport(Control *p_overl 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)); @@ -554,17 +564,19 @@ void AbstractPolygon2DEditor::forward_canvas_draw_over_viewport(Control *p_overl } 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; @@ -596,12 +608,14 @@ void AbstractPolygon2DEditor::remove_point(const Vertex &p_vertex) { _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 { @@ -659,8 +673,9 @@ AbstractPolygon2DEditor::PosVertex AbstractPolygon2DEditor::closest_edge_point(c 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) { diff --git a/editor/plugins/animation_blend_space_1d_editor.cpp b/editor/plugins/animation_blend_space_1d_editor.cpp index 64e5df084b..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); @@ -300,8 +301,9 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_draw() { } void AnimationNodeBlendSpace1DEditor::_update_space() { - if (updating) + if (updating) { return; + } updating = true; @@ -318,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")); @@ -338,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); @@ -438,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); @@ -495,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")); diff --git a/editor/plugins/animation_blend_space_2d_editor.cpp b/editor/plugins/animation_blend_space_2d_editor.cpp index a308b5dddb..df67482dfb 100644 --- a/editor/plugins/animation_blend_space_2d_editor.cpp +++ b/editor/plugins/animation_blend_space_2d_editor.cpp @@ -105,8 +105,9 @@ 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()); @@ -179,8 +180,9 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven 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); @@ -578,8 +580,9 @@ void AnimationNodeBlendSpace2DEditor::_snap_toggled() { } void AnimationNodeBlendSpace2DEditor::_update_space() { - if (updating) + if (updating) { return; + } updating = true; @@ -611,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")); @@ -633,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); @@ -687,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); @@ -707,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())); diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp index 3363e1b804..82d942821f 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.cpp +++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp @@ -99,8 +99,9 @@ void AnimationNodeBlendTreeEditor::_property_changed(const StringName &p_propert } void AnimationNodeBlendTreeEditor::_update_graph() { - if (updating) + if (updating) { return; + } visible_properties.clear(); @@ -415,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)")); @@ -482,8 +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(); @@ -582,8 +585,9 @@ 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(); @@ -670,8 +674,9 @@ void AnimationNodeBlendTreeEditor::_edit_filters(const String &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); } @@ -687,8 +692,9 @@ void AnimationNodeBlendTreeEditor::_notification(int p_what) { 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) { @@ -754,8 +760,9 @@ 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; diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index 28d0e113d4..1e0a9535e2 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -59,8 +59,9 @@ 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; @@ -139,8 +140,9 @@ void AnimationPlayerEditor::_notification(int p_what) { } void AnimationPlayerEditor::_autoplay_pressed() { - if (updating) + if (updating) { return; + } if (animation->get_item_count() == 0) { return; } @@ -173,8 +175,9 @@ void AnimationPlayerEditor::_play_pressed() { } 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); } @@ -210,8 +213,9 @@ void AnimationPlayerEditor::_play_bw_pressed() { } 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); } @@ -227,8 +231,9 @@ void AnimationPlayerEditor::_play_bw_from_pressed() { 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); @@ -249,8 +254,9 @@ 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; @@ -291,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; @@ -308,8 +315,9 @@ void AnimationPlayerEditor::_animation_new() { } void AnimationPlayerEditor::_animation_rename() { - if (animation->get_item_count() == 0) + if (animation->get_item_count() == 0) { return; + } int selected = animation->get_selected(); String selected_name = animation->get_item_text(selected); @@ -338,8 +346,9 @@ 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); @@ -397,8 +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()); @@ -516,8 +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()); @@ -530,13 +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()); @@ -584,17 +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); @@ -611,8 +627,9 @@ 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(); } @@ -701,8 +718,9 @@ void AnimationPlayerEditor::_dialog_action(String p_file) { 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); @@ -765,8 +783,9 @@ void AnimationPlayerEditor::_update_animation() { void AnimationPlayerEditor::_update_player() { updating = true; List<StringName> animlist; - if (player) + if (player) { player->get_animation_list(&animlist); + } animation->clear(); @@ -801,13 +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; @@ -838,36 +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(); @@ -910,13 +936,15 @@ 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; @@ -989,14 +1017,16 @@ 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) { @@ -1006,17 +1036,21 @@ void AnimationPlayerEditor::_animation_key_editor_anim_len_changed(float 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())); @@ -1130,10 +1164,11 @@ void AnimationPlayerEditor::_onion_skinning_menu(int 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: { @@ -1175,19 +1210,21 @@ void AnimationPlayerEditor::_unhandled_key_input(const Ref<InputEvent> &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; } } @@ -1247,8 +1284,9 @@ 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(); @@ -1261,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"); @@ -1274,11 +1313,13 @@ 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; @@ -1351,8 +1392,9 @@ void AnimationPlayerEditor::_prepare_onion_layers_2() { 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; } @@ -1702,8 +1744,9 @@ void AnimationPlayerEditorPlugin::_notification(int p_what) { 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)); } diff --git a/editor/plugins/animation_state_machine_editor.cpp b/editor/plugins/animation_state_machine_editor.cpp index bcd393957c..652754a146 100644 --- a/editor/plugins/animation_state_machine_editor.cpp +++ b/editor/plugins/animation_state_machine_editor.cpp @@ -61,8 +61,9 @@ 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()) { @@ -101,8 +102,9 @@ 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()); @@ -317,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); @@ -520,8 +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(); @@ -531,8 +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(); @@ -811,8 +816,9 @@ 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++) { @@ -822,8 +828,9 @@ void AnimationNodeStateMachineEditor::_state_machine_pos_draw() { } } - if (idx == -1) + if (idx == -1) { return; + } const NodeRect &nr = node_rects[idx]; @@ -855,8 +862,9 @@ void AnimationNodeStateMachineEditor::_state_machine_pos_draw() { } void AnimationNodeStateMachineEditor::_update_graph() { - if (updating) + if (updating) { return; + } updating = true; @@ -1071,15 +1079,17 @@ 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(); diff --git a/editor/plugins/animation_tree_editor_plugin.cpp b/editor/plugins/animation_tree_editor_plugin.cpp index 2512dbdfb2..ec3e25f999 100644 --- a/editor/plugins/animation_tree_editor_plugin.cpp +++ b/editor/plugins/animation_tree_editor_plugin.cpp @@ -48,8 +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; @@ -204,13 +205,15 @@ Vector<String> AnimationTreeEditor::get_animation_list() { } 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); @@ -261,8 +264,9 @@ 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); } diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp index ad2164b719..da170cd498 100644 --- a/editor/plugins/asset_library_editor_plugin.cpp +++ b/editor/plugins/asset_library_editor_plugin.cpp @@ -374,8 +374,9 @@ void EditorAssetLibraryItemDownload::configure(const String &p_title, int p_asse 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(); @@ -597,8 +598,9 @@ void EditorAssetLibrary::_install_asset() { 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; } } @@ -643,8 +645,9 @@ void EditorAssetLibrary::_select_author(int p_id) { 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); @@ -914,16 +917,19 @@ void EditorAssetLibrary::_search_text_entered(const String &p_text) { 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); @@ -1072,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); @@ -1297,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...")); diff --git a/editor/plugins/audio_stream_editor_plugin.cpp b/editor/plugins/audio_stream_editor_plugin.cpp index 44238323ea..3b7a9320f0 100644 --- a/editor/plugins/audio_stream_editor_plugin.cpp +++ b/editor/plugins/audio_stream_editor_plugin.cpp @@ -97,8 +97,9 @@ void AudioStreamEditor::_preview_changed(ObjectID p_which) { } void AudioStreamEditor::_changed_callback(Object *p_changed, const char *p_prop) { - if (!is_visible()) + if (!is_visible()) { return; + } update(); } @@ -170,8 +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); @@ -242,8 +244,9 @@ 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)); } diff --git a/editor/plugins/baked_lightmap_editor_plugin.cpp b/editor/plugins/baked_lightmap_editor_plugin.cpp index 4f1b794c0c..8fbe1646f7 100644 --- a/editor/plugins/baked_lightmap_editor_plugin.cpp +++ b/editor/plugins/baked_lightmap_editor_plugin.cpp @@ -75,8 +75,9 @@ void BakedLightmapEditorPlugin::_bake() { void BakedLightmapEditorPlugin::edit(Object *p_object) { BakedLightmap *s = Object::cast_to<BakedLightmap>(p_object); - if (!s) + if (!s) { return; + } lightmap = s; } diff --git a/editor/plugins/camera_3d_editor_plugin.cpp b/editor/plugins/camera_3d_editor_plugin.cpp index 58ea5e45bb..48f9f208a5 100644 --- a/editor/plugins/camera_3d_editor_plugin.cpp +++ b/editor/plugins/camera_3d_editor_plugin.cpp @@ -55,10 +55,11 @@ void Camera3DEditor::edit(Node *p_camera) { 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); + } } } diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 2d7198bec8..744c7907af 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -472,8 +472,9 @@ 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(); @@ -487,8 +488,9 @@ 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(); } } @@ -496,17 +498,19 @@ void CanvasItemEditor::_unhandled_key_input(const Ref<InputEvent> &p_ev) { 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) { @@ -532,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); @@ -571,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); @@ -659,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)) { @@ -672,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; @@ -692,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; @@ -734,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(); @@ -852,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_")) { @@ -881,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; } } @@ -956,13 +976,15 @@ 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() { @@ -1262,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; @@ -1350,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)); @@ -1462,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; @@ -1611,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) { @@ -1710,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) { @@ -2141,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) { @@ -2293,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; @@ -2362,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()) { @@ -2402,15 +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()) { @@ -2446,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(); @@ -2516,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); @@ -2569,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); @@ -2633,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)); } @@ -2643,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)); } @@ -2844,8 +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"); @@ -3463,12 +3512,14 @@ void CanvasItemEditor::_draw_bones() { 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_")) { @@ -3511,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; @@ -3578,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; @@ -3743,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(); @@ -3993,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_")) { @@ -4024,8 +4083,9 @@ 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; @@ -4180,8 +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(); @@ -4273,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; @@ -4360,21 +4422,26 @@ void CanvasItemEditor::_insert_animation_keys(bool p_location, bool p_rotation, 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 @@ -4390,19 +4457,23 @@ void CanvasItemEditor::_insert_animation_keys(bool p_location, bool p_rotation, 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); + } } } } @@ -4410,12 +4481,15 @@ void CanvasItemEditor::_insert_animation_keys(bool p_location, bool p_rotation, } 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); + } } } } @@ -4424,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); } @@ -4564,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_"); @@ -4584,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); @@ -4604,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_"); @@ -4624,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); @@ -4762,11 +4845,13 @@ void CanvasItemEditor::_popup_callback(int p_op) { 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); @@ -4781,14 +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); @@ -4804,26 +4891,32 @@ void CanvasItemEditor::_popup_callback(int p_op) { 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()); @@ -4872,14 +4965,18 @@ void CanvasItemEditor::_popup_callback(int p_op) { 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_"); @@ -4897,12 +4994,15 @@ void CanvasItemEditor::_popup_callback(int p_op) { 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_")); @@ -4920,12 +5020,15 @@ void CanvasItemEditor::_popup_callback(int p_op) { 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_"); @@ -4941,12 +5044,15 @@ void CanvasItemEditor::_popup_callback(int p_op) { 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_")); @@ -4967,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; @@ -4996,8 +5104,9 @@ 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; @@ -5794,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(); @@ -5835,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() { @@ -6010,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); } @@ -6127,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 a4ef84f5f3..a686c98f65 100644 --- a/editor/plugins/canvas_item_editor_plugin.h +++ b/editor/plugins/canvas_item_editor_plugin.h @@ -318,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; + } } }; diff --git a/editor/plugins/collision_polygon_3d_editor_plugin.cpp b/editor/plugins/collision_polygon_3d_editor_plugin.cpp index 920a7f195a..c61d410d38 100644 --- a/editor/plugins/collision_polygon_3d_editor_plugin.cpp +++ b/editor/plugins/collision_polygon_3d_editor_plugin.cpp @@ -64,8 +64,9 @@ void CollisionPolygon3DEditor::_notification(int p_what) { 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); } @@ -102,8 +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(); @@ -120,8 +122,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); @@ -194,8 +197,9 @@ bool CollisionPolygon3DEditor::forward_spatial_gui_input(Camera3D *p_camera, con }; 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) { @@ -304,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); @@ -330,22 +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; @@ -358,15 +366,17 @@ void CollisionPolygon3DEditor::_polygon_draw() { 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); @@ -431,8 +441,9 @@ void CollisionPolygon3DEditor::_polygon_draw() { m->clear_surfaces(); - if (poly.size() == 0) + if (poly.size() == 0) { return; + } Array a; a.resize(Mesh::ARRAY_MAX); @@ -471,8 +482,9 @@ 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); } diff --git a/editor/plugins/cpu_particles_2d_editor_plugin.cpp b/editor/plugins/cpu_particles_2d_editor_plugin.cpp index a601c1440d..008de7cfb4 100644 --- a/editor/plugins/cpu_particles_2d_editor_plugin.cpp +++ b/editor/plugins/cpu_particles_2d_editor_plugin.cpp @@ -134,8 +134,9 @@ void CPUParticles2DEditorPlugin::_generate_emission_mask() { } } - if (on_border) + if (on_border) { break; + } } if (on_border) { @@ -145,8 +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(); diff --git a/editor/plugins/curve_editor_plugin.cpp b/editor/plugins/curve_editor_plugin.cpp index 94059ea39d..539ab03f5b 100644 --- a/editor/plugins/curve_editor_plugin.cpp +++ b/editor/plugins/curve_editor_plugin.cpp @@ -65,8 +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)); @@ -95,8 +96,9 @@ 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) { @@ -108,8 +110,9 @@ void CurveEditor::on_gui_input(const Ref<InputEvent> &p_event) { 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: @@ -182,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); @@ -198,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); @@ -209,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); + } } } } @@ -231,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); + } } } } @@ -351,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); @@ -377,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; @@ -394,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); @@ -421,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); @@ -447,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(); } @@ -462,8 +476,9 @@ 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; @@ -530,10 +545,11 @@ 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); @@ -605,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(); diff --git a/editor/plugins/debugger_editor_plugin.cpp b/editor/plugins/debugger_editor_plugin.cpp index da060c3093..0ca479555d 100644 --- a/editor/plugins/debugger_editor_plugin.cpp +++ b/editor/plugins/debugger_editor_plugin.cpp @@ -164,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() { @@ -177,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/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp index 0c0f014af6..9cb167b41c 100644 --- a/editor/plugins/editor_preview_plugins.cpp +++ b/editor/plugins/editor_preview_plugins.cpp @@ -43,8 +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(); @@ -105,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); } @@ -146,15 +149,17 @@ bool EditorImagePreviewPlugin::handles(const String &p_type) const { 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); } @@ -220,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); } @@ -269,8 +275,9 @@ 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(); @@ -468,12 +475,14 @@ bool EditorScriptPreviewPlugin::handles(const String &p_type) const { 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); @@ -496,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++) { @@ -530,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; @@ -554,8 +566,9 @@ Ref<Texture2D> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size if (c == '\n') { col = x0; line++; - if (line >= available_height / 2) + if (line >= available_height / 2) { break; + } } else if (c == '\t') { col += 3; } @@ -686,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)); diff --git a/editor/plugins/gi_probe_editor_plugin.cpp b/editor/plugins/gi_probe_editor_plugin.cpp index 9669853f1b..94f771e643 100644 --- a/editor/plugins/gi_probe_editor_plugin.cpp +++ b/editor/plugins/gi_probe_editor_plugin.cpp @@ -50,8 +50,9 @@ 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; } diff --git a/editor/plugins/gpu_particles_2d_editor_plugin.cpp b/editor/plugins/gpu_particles_2d_editor_plugin.cpp index fa97e3dcca..01420dac3e 100644 --- a/editor/plugins/gpu_particles_2d_editor_plugin.cpp +++ b/editor/plugins/gpu_particles_2d_editor_plugin.cpp @@ -61,10 +61,11 @@ 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: { @@ -118,10 +119,11 @@ void GPUParticles2DEditorPlugin::_generate_visibility_rect() { 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; } @@ -204,8 +206,9 @@ void GPUParticles2DEditorPlugin::_generate_emission_mask() { } } - if (on_border) + if (on_border) { break; + } } if (on_border) { @@ -215,8 +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(); diff --git a/editor/plugins/gpu_particles_3d_editor_plugin.cpp b/editor/plugins/gpu_particles_3d_editor_plugin.cpp index da1bc89e33..fa507dd3d7 100644 --- a/editor/plugins/gpu_particles_3d_editor_plugin.cpp +++ b/editor/plugins/gpu_particles_3d_editor_plugin.cpp @@ -44,8 +44,9 @@ bool GPUParticles3DEditorBase::_generate(Vector<Vector3> &points, Vector<Vector3 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; } @@ -92,10 +93,11 @@ bool GPUParticles3DEditorBase::_generate(Vector<Vector3> &points, Vector<Vector3 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]); + } } } @@ -125,15 +127,18 @@ bool GPUParticles3DEditorBase::_generate(Vector<Vector3> &points, Vector<Vector3 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(); @@ -150,8 +155,9 @@ 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())); @@ -234,10 +240,11 @@ void GPUParticles3DEditor::_menu_option(int 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: { @@ -295,10 +302,11 @@ void GPUParticles3DEditor::_generate_aabb() { 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; } diff --git a/editor/plugins/gradient_editor_plugin.cpp b/editor/plugins/gradient_editor_plugin.cpp index 1ccfeccf7a..13b5c8cef5 100644 --- a/editor/plugins/gradient_editor_plugin.cpp +++ b/editor/plugins/gradient_editor_plugin.cpp @@ -39,8 +39,9 @@ Size2 GradientEditor::get_minimum_size() const { } void GradientEditor::_gradient_changed() { - if (editing) + if (editing) { return; + } editing = true; Vector<Gradient::Point> points = gradient->get_points(); diff --git a/editor/plugins/item_list_editor_plugin.cpp b/editor/plugins/item_list_editor_plugin.cpp index 2829b9bd5b..7402baad57 100644 --- a/editor/plugins/item_list_editor_plugin.cpp +++ b/editor/plugins/item_list_editor_plugin.cpp @@ -38,11 +38,11 @@ bool ItemListPlugin::_set(const StringName &p_name, const Variant &p_value) { 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: @@ -53,16 +53,17 @@ 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; } @@ -72,27 +73,28 @@ bool ItemListPlugin::_get(const StringName &p_name, Variant &r_ret) const { 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; } @@ -111,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")); + } } } @@ -159,10 +164,11 @@ ItemListOptionButtonPlugin::ItemListOptionButtonPlugin() { /////////////////////////////////////////////////////////////// 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 { @@ -245,20 +251,23 @@ void ItemListEditor::_notification(int p_notification) { } 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. @@ -351,8 +360,9 @@ 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) { diff --git a/editor/plugins/light_occluder_2d_editor_plugin.cpp b/editor/plugins/light_occluder_2d_editor_plugin.cpp index 0cbb3f5d9d..e422140efa 100644 --- a/editor/plugins/light_occluder_2d_editor_plugin.cpp +++ b/editor/plugins/light_occluder_2d_editor_plugin.cpp @@ -49,26 +49,29 @@ void LightOccluder2DEditor::_set_node(Node *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 { @@ -87,8 +90,9 @@ bool LightOccluder2DEditor::_has_resource() const { } 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))); diff --git a/editor/plugins/material_editor_plugin.cpp b/editor/plugins/material_editor_plugin.cpp index 992f080cec..e49cfd51f7 100644 --- a/editor/plugins/material_editor_plugin.cpp +++ b/editor/plugins/material_editor_plugin.cpp @@ -203,8 +203,9 @@ 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; } diff --git a/editor/plugins/mesh_editor_plugin.cpp b/editor/plugins/mesh_editor_plugin.cpp index 7ac44cf53a..9d396467c3 100644 --- a/editor/plugins/mesh_editor_plugin.cpp +++ b/editor/plugins/mesh_editor_plugin.cpp @@ -37,9 +37,9 @@ void MeshEditor::_gui_input(Ref<InputEvent> 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(); diff --git a/editor/plugins/mesh_instance_3d_editor_plugin.cpp b/editor/plugins/mesh_instance_3d_editor_plugin.cpp index 3c1554de27..1b65987af0 100644 --- a/editor/plugins/mesh_instance_3d_editor_plugin.cpp +++ b/editor/plugins/mesh_instance_3d_editor_plugin.cpp @@ -92,16 +92,19 @@ void MeshInstance3DEditor::_menu_option(int p_option) { 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); @@ -129,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); @@ -219,8 +223,9 @@ void MeshInstance3DEditor::_menu_option(int p_option) { 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); @@ -284,10 +289,11 @@ struct MeshInstance3DEditorEdgeSort { 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() {} @@ -309,8 +315,9 @@ void MeshInstance3DEditor::_create_uv_lines(int p_layer) { 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]; @@ -345,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); @@ -359,8 +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)); diff --git a/editor/plugins/mesh_library_editor_plugin.cpp b/editor/plugins/mesh_library_editor_plugin.cpp index 30ffba0db4..7690beeee8 100644 --- a/editor/plugins/mesh_library_editor_plugin.cpp +++ b/editor/plugins/mesh_library_editor_plugin.cpp @@ -42,8 +42,9 @@ 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() { @@ -63,8 +64,9 @@ 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; @@ -78,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) { @@ -110,16 +114,18 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library, 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()); @@ -127,8 +133,9 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library, 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()); @@ -143,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); @@ -265,8 +274,9 @@ 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 { diff --git a/editor/plugins/multimesh_editor_plugin.cpp b/editor/plugins/multimesh_editor_plugin.cpp index 9d4442174c..3904389e09 100644 --- a/editor/plugins/multimesh_editor_plugin.cpp +++ b/editor/plugins/multimesh_editor_plugin.cpp @@ -42,8 +42,9 @@ void MultiMeshEditor::_node_removed(Node *p_node) { } void MultiMeshEditor::_populate() { - if (!node) + if (!node) { return; + } Ref<Mesh> mesh; @@ -141,8 +142,9 @@ void MultiMeshEditor::_populate() { 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; } @@ -214,10 +216,11 @@ 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) { @@ -249,10 +252,11 @@ 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() { diff --git a/editor/plugins/navigation_polygon_editor_plugin.cpp b/editor/plugins/navigation_polygon_editor_plugin.cpp index d4cc96b7df..8cf9f01fa0 100644 --- a/editor/plugins/navigation_polygon_editor_plugin.cpp +++ b/editor/plugins/navigation_polygon_editor_plugin.cpp @@ -49,18 +49,20 @@ void NavigationPolygonEditor::_set_node(Node *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 { @@ -98,8 +100,9 @@ bool NavigationPolygonEditor::_has_resource() const { } 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/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index bfdd148e3f..3c12022854 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -364,10 +364,11 @@ 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; } @@ -379,12 +380,14 @@ int Node3DEditorViewport::get_selected_count() const { 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++; } @@ -433,13 +436,15 @@ void Node3DEditorViewport::_clear_selected() { } 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 @@ -470,14 +475,16 @@ void Node3DEditorViewport::_select(Node *p_node, bool p_append, bool p_single) { } 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); @@ -495,8 +502,9 @@ ObjectID Node3DEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, b 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(); @@ -511,13 +519,15 @@ 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); @@ -531,12 +541,14 @@ 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; @@ -554,16 +566,19 @@ void Node3DEditorViewport::_find_items_at_pos(const Point2 &p_pos, bool &r_inclu 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; @@ -572,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; @@ -590,8 +608,9 @@ 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(); } @@ -615,8 +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()); @@ -668,8 +688,9 @@ void Node3DEditorViewport::_select_region() { 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())) { @@ -689,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); @@ -718,10 +742,11 @@ void Node3DEditorViewport::_update_name() { 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 } @@ -737,12 +762,14 @@ void Node3DEditorViewport::_compute_edit(const Point2 &p_point) { 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(); @@ -766,23 +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; } @@ -861,8 +894,9 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high 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); @@ -950,15 +984,17 @@ 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() { @@ -1047,16 +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; + } } } { @@ -1064,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; + } } } @@ -1077,17 +1116,19 @@ 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: { @@ -1101,8 +1142,9 @@ 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; @@ -1117,12 +1159,14 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { 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); } @@ -1220,16 +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()); @@ -1237,8 +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()); @@ -1246,8 +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()); @@ -1265,8 +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; @@ -1301,8 +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; @@ -1317,12 +1367,14 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { 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); @@ -1360,8 +1412,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { 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); + } } } } @@ -1407,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()); @@ -1456,12 +1510,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) { @@ -1478,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); @@ -1592,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) { @@ -1689,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(); @@ -1715,12 +1776,14 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { 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; @@ -1783,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")) { @@ -1831,10 +1895,11 @@ 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; @@ -1855,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) { @@ -1888,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) { @@ -1932,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).")); @@ -1944,8 +2012,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { 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()); } @@ -1962,15 +2031,17 @@ 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) { @@ -1978,8 +2049,9 @@ void Node3DEditorViewport::_nav_pan(Ref<InputEventWithModifiers> p_event, const 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; @@ -1997,20 +2069,23 @@ void Node3DEditorViewport::_nav_zoom(Ref<InputEventWithModifiers> p_event, const 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)); + } } } @@ -2034,10 +2109,12 @@ 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(); } @@ -2065,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); @@ -2114,13 +2193,15 @@ 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(); @@ -2128,13 +2209,15 @@ void Node3DEditorViewport::scale_cursor_distance(real_t scale) { 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(); @@ -2304,18 +2387,21 @@ void Node3DEditorViewport::_notification(int p_what) { 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; @@ -2345,8 +2431,9 @@ void Node3DEditorViewport::_notification(int p_what) { } message_time -= get_physics_process_delta_time(); - if (message_time < 0) + if (message_time < 0) { surface->update(); + } } //update shadow atlas if changed @@ -2609,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")); } @@ -2627,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")); } @@ -2702,8 +2791,9 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_ALIGN_TRANSFORM_WITH_VIEW: { - if (!get_selected_count()) + if (!get_selected_count()) { break; + } Transform camera_transform = camera->get_global_transform(); @@ -2713,12 +2803,14 @@ void Node3DEditorViewport::_menu_option(int p_option) { 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) { @@ -2736,8 +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(); @@ -2746,12 +2839,14 @@ 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()); @@ -2839,18 +2934,20 @@ 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; @@ -3026,8 +3123,9 @@ void Node3DEditorViewport::_toggle_camera_preview(bool 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(); @@ -3043,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 @@ -3060,8 +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(); @@ -3080,13 +3180,15 @@ void Node3DEditorViewport::_selection_menu_hide() { 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(); @@ -3110,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. @@ -3140,22 +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"]; @@ -3173,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"]; @@ -3185,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"]; @@ -3206,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"]; @@ -3265,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)); @@ -3280,10 +3394,12 @@ 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; } @@ -3315,8 +3431,9 @@ void Node3DEditorViewport::reset() { } void Node3DEditorViewport::focus_selection() { - if (!get_selected_count()) + if (!get_selected_count()) { return; + } Vector3 center; int count = 0; @@ -3325,12 +3442,14 @@ void Node3DEditorViewport::focus_selection() { 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++; @@ -3366,8 +3485,9 @@ Vector3 Node3DEditorViewport::_get_instance_position(const Point2 &p_pos) const 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(); @@ -3381,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; @@ -3397,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; } @@ -3540,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)); @@ -3643,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); @@ -4150,10 +4275,11 @@ 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))); @@ -4162,10 +4288,11 @@ 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))); @@ -4173,10 +4300,11 @@ void Node3DEditorViewportContainer::_notification(int p_what) { } 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))); @@ -4186,10 +4314,11 @@ 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))); @@ -4242,8 +4371,9 @@ 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) { @@ -4266,12 +4396,14 @@ void Node3DEditor::update_transform_gizmo() { 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(); @@ -4318,8 +4450,9 @@ 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); @@ -4373,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; @@ -4402,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; @@ -4422,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(); @@ -4441,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")) { @@ -4468,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"]; @@ -4497,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]) { @@ -4571,19 +4714,21 @@ void Node3DEditor::_xform_dialog_action() { 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; } @@ -4659,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(); @@ -4679,8 +4825,9 @@ void Node3DEditor::_menu_item_pressed(int p_option) { 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(); @@ -4803,11 +4950,13 @@ void Node3DEditor::_menu_item_pressed(int p_option) { 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_"); @@ -4826,11 +4975,13 @@ void Node3DEditor::_menu_item_pressed(int p_option) { 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); @@ -4849,11 +5000,13 @@ void Node3DEditor::_menu_item_pressed(int p_option) { 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_"); @@ -4871,11 +5024,13 @@ void Node3DEditor::_menu_item_pressed(int p_option) { 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); @@ -5220,8 +5375,9 @@ 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); @@ -5242,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) { @@ -5334,8 +5491,9 @@ 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; } @@ -5512,8 +5670,9 @@ 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); } @@ -5617,8 +5776,9 @@ HSplitContainer *Node3DEditor::get_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; @@ -5640,54 +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() { @@ -6353,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); @@ -6390,8 +6559,9 @@ Ref<EditorNode3DGizmo> EditorNode3DGizmoPlugin::get_gizmo(Node3D *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); @@ -6449,8 +6619,9 @@ Ref<EditorNode3DGizmo> EditorNode3DGizmoPlugin::create_gizmo(Node3D *p_spatial) } Ref<EditorNode3DGizmo> ref; - if (has_gizmo(p_spatial)) + if (has_gizmo(p_spatial)) { ref.instance(); + } return ref; } diff --git a/editor/plugins/path_2d_editor_plugin.cpp b/editor/plugins/path_2d_editor_plugin.cpp index d4f49100d6..a3dab665b8 100644 --- a/editor/plugins/path_2d_editor_plugin.cpp +++ b/editor/plugins/path_2d_editor_plugin.cpp @@ -58,14 +58,17 @@ 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"); @@ -176,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); @@ -269,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()))); @@ -328,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; } @@ -349,8 +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(); @@ -407,8 +417,9 @@ 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(); } @@ -420,13 +431,15 @@ void Path2DEditor::edit(Node *p_path2d) { 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; } } @@ -459,15 +472,18 @@ void Path2DEditor::_mode_selected(int p_mode) { } 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); diff --git a/editor/plugins/path_3d_editor_plugin.cpp b/editor/plugins/path_3d_editor_plugin.cpp index 0aee064c41..a44fe69ff6 100644 --- a/editor/plugins/path_3d_editor_plugin.cpp +++ b/editor/plugins/path_3d_editor_plugin.cpp @@ -36,8 +36,9 @@ 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); @@ -48,18 +49,20 @@ 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) { 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); @@ -72,10 +75,11 @@ 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); @@ -84,8 +88,9 @@ Variant Path3DGizmo::get_handle_value(int p_idx) { 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(); @@ -138,20 +143,23 @@ 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(); @@ -216,15 +224,17 @@ 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(); @@ -280,11 +290,13 @@ Path3DGizmo::Path3DGizmo(Path3D *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(); @@ -295,8 +307,9 @@ bool Path3DEditorPlugin::forward_spatial_gui_input(Camera3D *p_camera, const Ref 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 @@ -310,14 +323,16 @@ 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]; @@ -346,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; + } } } @@ -368,10 +385,11 @@ bool Path3DEditorPlugin::forward_spatial_gui_input(Camera3D *p_camera, const Ref } 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); @@ -481,10 +499,12 @@ void Path3DEditorPlugin::_mode_changed(int p_idx) { 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)); } @@ -596,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; } diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp index 3fcf3131b0..7ee695b9fe 100644 --- a/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/editor/plugins/polygon_2d_editor_plugin.cpp @@ -178,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)); } @@ -287,16 +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); @@ -308,8 +311,9 @@ void Polygon2DEditor::_menu_option(int p_option) { 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); @@ -320,8 +324,9 @@ void Polygon2DEditor::_menu_option(int p_option) { } 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); @@ -363,13 +368,15 @@ 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() { @@ -428,8 +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; @@ -554,8 +562,9 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { 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; @@ -569,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); @@ -601,12 +611,13 @@ 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) { @@ -676,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]); } @@ -746,8 +758,9 @@ 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(); @@ -789,8 +802,9 @@ 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); @@ -802,8 +816,9 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { 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()); @@ -824,14 +839,16 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { 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; @@ -905,8 +922,9 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { } 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(); @@ -915,12 +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; @@ -940,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; } } @@ -951,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; } } @@ -1036,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) { @@ -1089,8 +1115,9 @@ void Polygon2DEditor::_uv_draw() { 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); @@ -1098,8 +1125,9 @@ void Polygon2DEditor::_uv_draw() { 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; diff --git a/editor/plugins/resource_preloader_editor_plugin.cpp b/editor/plugins/resource_preloader_editor_plugin.cpp index 0d4ee492ee..75cb93ee76 100644 --- a/editor/plugins/resource_preloader_editor_plugin.cpp +++ b/editor/plugins/resource_preloader_editor_plugin.cpp @@ -90,8 +90,9 @@ void ResourcePreloaderEditor::_load_pressed() { 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); @@ -99,8 +100,9 @@ void ResourcePreloaderEditor::_load_pressed() { } void ResourcePreloaderEditor::_item_edited() { - if (!tree->get_selected()) + if (!tree->get_selected()) { return; + } TreeItem *s = tree->get_selected(); @@ -108,8 +110,9 @@ 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); @@ -148,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; @@ -244,14 +249,16 @@ void ResourcePreloaderEditor::edit(ResourcePreloader *p_preloader) { 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); } @@ -259,11 +266,13 @@ Variant ResourcePreloaderEditor::get_drag_data_fw(const Point2 &p_point, Control 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"]; @@ -280,13 +289,15 @@ 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"]; @@ -379,8 +390,9 @@ 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); } @@ -396,8 +408,9 @@ void ResourcePreloaderEditorPlugin::make_visible(bool p_visible) { 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); diff --git a/editor/plugins/root_motion_editor_plugin.cpp b/editor/plugins/root_motion_editor_plugin.cpp index 37e779fbbb..e107435373 100644 --- a/editor/plugins/root_motion_editor_plugin.cpp +++ b/editor/plugins/root_motion_editor_plugin.cpp @@ -34,8 +34,9 @@ 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); @@ -117,8 +118,9 @@ 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(); diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index dbeb6e339b..8d6dac3907 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -141,10 +141,11 @@ 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(); @@ -175,8 +176,9 @@ void ScriptEditorQuickOpen::_update_search() { 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); + } } } @@ -185,8 +187,9 @@ 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); @@ -269,8 +272,9 @@ 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) { @@ -294,8 +298,9 @@ void ScriptEditor::_set_execution(REF p_script, int p_line) { 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); @@ -309,8 +314,9 @@ void ScriptEditor::_clear_execution(REF 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(); @@ -321,8 +327,9 @@ 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)); } @@ -364,8 +371,9 @@ void ScriptEditor::_go_to_tab(int p_idx) { } 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(); @@ -393,8 +401,9 @@ void ScriptEditor::_go_to_tab(int p_idx) { 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) { @@ -406,8 +415,9 @@ void ScriptEditor::_go_to_tab(int p_idx) { 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); @@ -519,8 +529,9 @@ void ScriptEditor::_show_error_dialog(String p_path) { 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); @@ -562,8 +573,9 @@ 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(); @@ -658,13 +670,15 @@ void ScriptEditor::_resave_scripts(const String &p_str) { 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(); @@ -782,11 +796,13 @@ bool ScriptEditor::_test_script_times_on_disk(RES p_for_script) { 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()); @@ -948,8 +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(); @@ -986,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); @@ -997,8 +1015,9 @@ 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; @@ -1040,11 +1059,13 @@ 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(); @@ -1066,8 +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(); @@ -1340,10 +1362,11 @@ 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) { @@ -1352,8 +1375,9 @@ void ScriptEditor::close_builtin_scripts_from_scene(const String &p_scene) { 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); @@ -1378,8 +1402,9 @@ 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) { @@ -1398,12 +1423,14 @@ void ScriptEditor::get_breakpoints(List<String> *p_breakpoints) { } 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) { @@ -1440,8 +1467,9 @@ 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(); + } } } @@ -1449,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++) { @@ -1568,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); @@ -1595,8 +1626,9 @@ void ScriptEditor::_update_script_colors() { 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)); @@ -1623,8 +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(); @@ -1847,8 +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; @@ -1863,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; } @@ -1923,15 +1958,17 @@ 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) { @@ -1939,8 +1976,9 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra _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); @@ -1958,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); @@ -2021,8 +2060,9 @@ 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) { @@ -2038,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()) { @@ -2063,8 +2104,9 @@ 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(); } } @@ -2094,10 +2136,12 @@ void ScriptEditor::_add_callback(Object *p_obj, const String &p_function, 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; - if (se->get_edited_resource() != script) + } + if (se->get_edited_resource() != script) { continue; + } se->add_callback(p_function, p_args); @@ -2138,8 +2182,9 @@ 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(); } @@ -2168,8 +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"); @@ -2181,8 +2227,9 @@ void ScriptEditor::_script_split_dragged(float) { } 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()); @@ -2219,8 +2266,9 @@ 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"]; @@ -2237,8 +2285,9 @@ 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); @@ -2254,13 +2303,15 @@ 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; @@ -2273,12 +2324,14 @@ 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"]; @@ -2298,8 +2351,9 @@ 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); @@ -2325,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); @@ -2344,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; @@ -2395,8 +2451,9 @@ 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) { @@ -2436,13 +2493,15 @@ void ScriptEditor::set_window_layout(Ref<ConfigFile> p_layout) { 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; @@ -2457,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); @@ -2516,8 +2576,9 @@ void ScriptEditor::get_window_layout(Ref<ConfigFile> p_layout) { 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; @@ -2539,8 +2600,9 @@ 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)); @@ -2598,10 +2660,11 @@ void ScriptEditor::_update_selected_editor_menu() { 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(); + } } } @@ -2677,8 +2740,9 @@ Vector<Ref<Script>> ScriptEditor::get_open_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; + } Ref<Script> script = se->get_edited_resource(); if (script != nullptr) { @@ -2692,8 +2756,9 @@ 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); @@ -2703,8 +2768,9 @@ 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); } diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 1f916fb3ba..e7f8a56e5e 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -127,8 +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(); @@ -161,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); } @@ -264,13 +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(); @@ -320,8 +326,9 @@ void ScriptTextEditor::_set_theme_for_script() { 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); } @@ -519,10 +526,11 @@ 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; } @@ -710,27 +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); @@ -738,8 +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()); @@ -753,8 +767,9 @@ 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 @@ -779,8 +794,9 @@ void ScriptTextEditor::_code_complete_scripts(void *p_ud, const String &p_code, } 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); @@ -1105,15 +1121,17 @@ void ScriptTextEditor::_edit_option(int p_op) { } 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; @@ -1144,8 +1162,9 @@ void ScriptTextEditor::_edit_option(int p_op) { 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; @@ -1329,16 +1348,18 @@ 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()); } @@ -1347,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; @@ -1373,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) { @@ -1408,8 +1431,9 @@ 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 @@ -1444,18 +1468,21 @@ 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; @@ -1489,8 +1516,9 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data 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() + "\""; } @@ -1510,8 +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); @@ -1568,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); @@ -1672,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)); @@ -1747,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); diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index e0748f5237..0c3a44e4cd 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -217,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(""); } @@ -265,16 +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(); @@ -287,8 +291,9 @@ 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("//"); @@ -418,11 +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; @@ -687,8 +694,9 @@ void ShaderEditorPlugin::make_visible(bool p_visible) { } 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(); } } diff --git a/editor/plugins/shader_file_editor_plugin.cpp b/editor/plugins/shader_file_editor_plugin.cpp index 2f9b00ee56..0ac29f68f6 100644 --- a/editor/plugins/shader_file_editor_plugin.cpp +++ b/editor/plugins/shader_file_editor_plugin.cpp @@ -224,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; @@ -304,8 +305,9 @@ void ShaderFileEditorPlugin::make_visible(bool p_visible) { } else { button->hide(); - if (shader_editor->is_visible_in_tree()) + if (shader_editor->is_visible_in_tree()) { editor->hide_bottom_panel(); + } } } diff --git a/editor/plugins/skeleton_ik_3d_editor_plugin.cpp b/editor/plugins/skeleton_ik_3d_editor_plugin.cpp index 170a777523..8fc789b94a 100644 --- a/editor/plugins/skeleton_ik_3d_editor_plugin.cpp +++ b/editor/plugins/skeleton_ik_3d_editor_plugin.cpp @@ -33,11 +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(); @@ -56,8 +58,9 @@ void SkeletonIK3DEditorPlugin::edit(Object *p_object) { } SkeletonIK3D *s = Object::cast_to<SkeletonIK3D>(p_object); - if (!s) + if (!s) { return; + } skeleton_ik = s; } @@ -67,10 +70,11 @@ bool SkeletonIK3DEditorPlugin::handles(Object *p_object) const { } 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() { diff --git a/editor/plugins/sprite_2d_editor_plugin.cpp b/editor/plugins/sprite_2d_editor_plugin.cpp index f09e4cb456..b21586a6b0 100644 --- a/editor/plugins/sprite_2d_editor_plugin.cpp +++ b/editor/plugins/sprite_2d_editor_plugin.cpp @@ -173,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,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); } @@ -265,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; } @@ -341,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); diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp index d869f9fcbc..859fec1628 100644 --- a/editor/plugins/sprite_frames_editor_plugin.cpp +++ b/editor/plugins/sprite_frames_editor_plugin.cpp @@ -153,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(); @@ -292,8 +293,9 @@ void SpriteFramesEditor::_load_pressed() { 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); @@ -324,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; @@ -383,12 +386,14 @@ 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; @@ -406,12 +411,14 @@ 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; @@ -429,8 +436,9 @@ 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)) { @@ -446,13 +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(); @@ -463,10 +473,12 @@ 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); @@ -488,20 +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(",", " "); @@ -563,11 +579,13 @@ 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(); @@ -593,8 +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()); @@ -605,8 +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); @@ -654,10 +674,11 @@ 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; @@ -672,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)); @@ -686,8 +709,9 @@ 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; @@ -710,18 +734,21 @@ void SpriteFramesEditor::edit(SpriteFrames *p_frames) { } 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' @@ -731,12 +758,14 @@ 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"]; @@ -751,8 +780,9 @@ bool SpriteFramesEditor::can_drop_data_fw(const Point2 &p_point, const Variant & 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]; @@ -769,13 +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); @@ -786,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); @@ -1060,8 +1094,9 @@ void SpriteFramesEditorPlugin::make_visible(bool p_visible) { 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(); + } } } diff --git a/editor/plugins/style_box_editor_plugin.cpp b/editor/plugins/style_box_editor_plugin.cpp index 0d957bb101..3641052a4e 100644 --- a/editor/plugins/style_box_editor_plugin.cpp +++ b/editor/plugins/style_box_editor_plugin.cpp @@ -52,8 +52,9 @@ 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); diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp index f6603d268c..3ceb9bfd82 100644 --- a/editor/plugins/text_editor.cpp +++ b/editor/plugins/text_editor.cpp @@ -552,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/texture_editor_plugin.cpp b/editor/plugins/texture_editor_plugin.cpp index bc4b97d40a..b728a6700c 100644 --- a/editor/plugins/texture_editor_plugin.cpp +++ b/editor/plugins/texture_editor_plugin.cpp @@ -57,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; @@ -91,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); @@ -101,14 +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; diff --git a/editor/plugins/texture_layered_editor_plugin.cpp b/editor/plugins/texture_layered_editor_plugin.cpp index e0e5bdb407..59e87fb273 100644 --- a/editor/plugins/texture_layered_editor_plugin.cpp +++ b/editor/plugins/texture_layered_editor_plugin.cpp @@ -64,8 +64,9 @@ 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(); } @@ -156,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; @@ -169,8 +172,9 @@ 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; diff --git a/editor/plugins/texture_layered_editor_plugin.h b/editor/plugins/texture_layered_editor_plugin.h index a620b1443c..4c5e06a5b8 100644 --- a/editor/plugins/texture_layered_editor_plugin.h +++ b/editor/plugins/texture_layered_editor_plugin.h @@ -35,6 +35,7 @@ #include "editor/editor_plugin.h" #include "scene/resources/shader.h" #include "scene/resources/texture.h" + class TextureLayeredEditor : public Control { GDCLASS(TextureLayeredEditor, Control); @@ -54,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(); diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index 7176e4aa19..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()) { @@ -160,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]); } @@ -306,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); } @@ -346,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]; @@ -422,10 +439,12 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { 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); @@ -452,30 +471,35 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { } 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()); @@ -553,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(); @@ -564,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(); @@ -607,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; @@ -633,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() { @@ -666,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; @@ -700,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); @@ -797,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 { @@ -834,24 +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(); diff --git a/editor/plugins/theme_editor_plugin.cpp b/editor/plugins/theme_editor_plugin.cpp index 90ef1e1507..eb028659fd 100644 --- a/editor/plugins/theme_editor_plugin.cpp +++ b/editor/plugins/theme_editor_plugin.cpp @@ -47,8 +47,9 @@ void ThemeEditor::_propagate_redraw(Control *p_at) { 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); + } } } @@ -258,44 +259,50 @@ void ThemeEditor::_save_template_cbk(String fname) { _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"); @@ -566,8 +573,9 @@ void ThemeEditor::_theme_menu_cbk(int p_option) { } } - if (!found) + if (!found) { types.push_back(F->get()); + } } } @@ -883,8 +891,9 @@ void ThemeEditorPlugin::make_visible(bool p_visible) { 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(); } diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp index 61eea6c15e..3010d72d81 100644 --- a/editor/plugins/tile_map_editor_plugin.cpp +++ b/editor/plugins/tile_map_editor_plugin.cpp @@ -116,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) { @@ -145,8 +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(); @@ -270,8 +272,9 @@ 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); @@ -297,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++) { @@ -311,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) { @@ -371,8 +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); @@ -398,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; @@ -435,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,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); @@ -523,8 +532,9 @@ void TileMapEditor::_update_palette() { 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); } @@ -535,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(); } @@ -554,8 +566,9 @@ 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(""); @@ -586,8 +599,9 @@ Vector<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool erase, 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>(); } @@ -604,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]; @@ -618,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; @@ -644,19 +660,22 @@ Vector<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool erase, 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); } @@ -689,8 +708,9 @@ 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) { @@ -720,8 +740,9 @@ 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++) { @@ -733,8 +754,9 @@ void TileMapEditor::_erase_selection() { 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); @@ -771,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; + } } } @@ -806,29 +830,33 @@ void TileMapEditor::_draw_cell(Control *p_viewport, int p_cell, const Point2i &p 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; @@ -867,8 +895,9 @@ 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++) { @@ -932,8 +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(); @@ -943,15 +973,17 @@ 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; @@ -1051,8 +1083,9 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { } 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")); @@ -1109,10 +1142,11 @@ 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; @@ -1150,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")); @@ -1178,8 +1213,9 @@ 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 + "]"); @@ -1243,8 +1279,9 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { 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(); @@ -1299,10 +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; @@ -1439,8 +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(); @@ -1464,8 +1503,9 @@ 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; + } } } else { int max_lines = 10000; //avoid crash if size too small @@ -1483,11 +1523,13 @@ 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; + } } } @@ -1501,8 +1543,9 @@ 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; + } } } else { for (int i = (si.position.y) - 1; i <= (si.position.y + si.size.y); i++) { @@ -1518,11 +1561,13 @@ 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; + } } } } @@ -1546,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) { @@ -1571,13 +1622,15 @@ 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); @@ -1586,8 +1639,9 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { } 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++) { @@ -1595,19 +1649,22 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { } } } 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(); @@ -1632,8 +1689,9 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { } 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); } @@ -1647,30 +1705,36 @@ void TileMapEditor::edit(Node *p_tile_map) { 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(); } @@ -1697,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; diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp index 9ab7e7ae8a..644facd5bd 100644 --- a/editor/plugins/tile_set_editor_plugin.cpp +++ b/editor/plugins/tile_set_editor_plugin.cpp @@ -63,8 +63,9 @@ 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) { @@ -104,14 +105,17 @@ void TileSetEditor::_import_node(Node *p_node, Ref<TileSet> p_library) { 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; @@ -121,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()); @@ -154,8 +159,9 @@ 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); } @@ -176,11 +182,13 @@ Variant TileSetEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) 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"]; @@ -195,8 +203,9 @@ bool TileSetEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_dat 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]; @@ -213,21 +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(); @@ -622,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) { @@ -675,8 +688,9 @@ void TileSetEditor::_on_tileset_toolbar_confirm() { 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); @@ -871,8 +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); @@ -1031,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); } @@ -1047,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); } } @@ -1100,8 +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); @@ -1113,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)); @@ -1138,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) { @@ -1175,8 +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; @@ -1879,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); @@ -1891,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); @@ -1948,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) { @@ -2293,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() { @@ -2386,14 +2415,18 @@ 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); } @@ -2409,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); @@ -2550,8 +2587,9 @@ 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: { @@ -2607,8 +2645,9 @@ void TileSetEditor::draw_polygon_shapes() { } } - if (polygon.size() < 3) + if (polygon.size() < 3) { continue; + } workspace->draw_polygon(polygon, colors); @@ -2829,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); @@ -2851,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"); @@ -2923,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); @@ -2965,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()); @@ -3036,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; } @@ -3091,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 { @@ -3190,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(); } @@ -3275,10 +3332,11 @@ 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) { @@ -3309,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); @@ -3371,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); diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 223cc249e1..92bdba93e7 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -103,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); } @@ -127,8 +128,9 @@ void VisualShaderEditor::add_custom_type(const String &p_name, const Ref<Script> 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; + } } } @@ -365,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); @@ -407,8 +410,9 @@ Size2 VisualShaderEditor::get_minimum_size() const { 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); @@ -447,11 +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); @@ -850,8 +856,9 @@ 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); + } } } @@ -1056,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()); @@ -1095,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)); @@ -1185,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)); } @@ -1290,8 +1303,9 @@ 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) { @@ -1698,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(); @@ -1860,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")); @@ -1877,8 +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(); @@ -1911,8 +1930,9 @@ void VisualShaderEditor::_delete_nodes() { } } - if (to_erase.empty()) + if (to_erase.empty()) { return; + } undo_redo->create_action(TTR("Delete Nodes")); @@ -1975,8 +1995,9 @@ void VisualShaderEditor::_mode_selected(int p_id) { 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); @@ -2101,10 +2122,12 @@ 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]; @@ -2875,8 +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); @@ -2945,8 +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(); @@ -2978,8 +3003,9 @@ public: } void _node_changed() { - if (updating) + if (updating) { return; + } for (int i = 0; i < properties.size(); i++) { properties[i]->update_property(); } @@ -3077,8 +3103,9 @@ Control *VisualShaderNodePluginDefault::create_editor(const Ref<Resource> &p_par } } - if (pinfo.size() == 0) + if (pinfo.size() == 0) { return nullptr; + } properties.clear(); @@ -3087,8 +3114,9 @@ Control *VisualShaderNodePluginDefault::create_editor(const Ref<Resource> &p_par 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); @@ -3116,8 +3144,9 @@ void EditorPropertyShaderMode::_option_selected(int 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")); @@ -3247,8 +3276,9 @@ 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; diff --git a/editor/progress_dialog.cpp b/editor/progress_dialog.cpp index 8487a3d1d2..541cba836b 100644 --- a/editor/progress_dialog.cpp +++ b/editor/progress_dialog.cpp @@ -78,10 +78,11 @@ void BackgroundProgress::_task_step(const String &p_task, int p_step) { ERR_FAIL_COND(!tasks.has(p_task)); Task &t = tasks[p_task]; - if (p_step < 0) + if (p_step < 0) { t.progress->set_value(t.progress->get_value() + 1); - else + } else { t.progress->set_value(p_step); + } } void BackgroundProgress::_end_task(const String &p_task) { @@ -113,8 +114,9 @@ void BackgroundProgress::task_step(const String &p_task, int p_step) { no_updates = updates.empty(); } - if (no_updates) + if (no_updates) { MessageQueue::get_singleton()->push_call(this, "_update"); + } { _THREAD_SAFE_METHOD_ @@ -187,15 +189,17 @@ bool ProgressDialog::task_step(const String &p_task, const String &p_state, int if (!p_force_redraw) { uint64_t tus = OS::get_singleton()->get_ticks_usec(); - if (tus - last_progress_tick < 200000) //200ms + if (tus - last_progress_tick < 200000) { //200ms return cancelled; + } } Task &t = tasks[p_task]; - if (p_step < 0) + if (p_step < 0) { t.progress->set_value(t.progress->get_value() + 1); - else + } else { t.progress->set_value(p_step); + } t.state->set_text(p_state); last_progress_tick = OS::get_singleton()->get_ticks_usec(); @@ -214,10 +218,11 @@ void ProgressDialog::end_task(const String &p_task) { memdelete(t.vb); tasks.erase(p_task); - if (tasks.empty()) + if (tasks.empty()) { hide(); - else + } else { _popup(); + } } void ProgressDialog::_cancel_pressed() { diff --git a/editor/project_export.cpp b/editor/project_export.cpp index bc4a1ee118..32a1cf2fa1 100644 --- a/editor/project_export.cpp +++ b/editor/project_export.cpp @@ -52,8 +52,9 @@ void ProjectExportDialog::_theme_changed() { duplicate_preset->set_icon(presets->get_theme_icon("Duplicate", "EditorIcons")); delete_preset->set_icon(presets->get_theme_icon("Remove", "EditorIcons")); Control *panel = custom_feature_display->get_parent_control(); - if (panel) + if (panel) { panel->add_theme_style_override("panel", patches->get_theme_stylebox("bg", "Tree")); + } } void ProjectExportDialog::_notification(int p_what) { @@ -115,16 +116,18 @@ void ProjectExportDialog::_add_preset(int p_platform) { } } - if (valid) + if (valid) { break; + } attempt++; name = EditorExport::get_singleton()->get_export_platform(p_platform)->get_name() + " " + itos(attempt); } preset->set_name(name); - if (make_runnable) + if (make_runnable) { preset->set_runnable(make_runnable); + } EditorExport::get_singleton()->add_export_preset(preset); _update_presets(); _edit_preset(EditorExport::get_singleton()->get_export_preset_count() - 1); @@ -138,8 +141,9 @@ void ProjectExportDialog::_update_presets() { updating = true; Ref<EditorExportPreset> current; - if (presets->get_current() >= 0 && presets->get_current() < presets->get_item_count()) + if (presets->get_current() >= 0 && presets->get_current() < presets->get_item_count()) { current = get_current_preset(); + } int current_idx = -1; presets->clear(); @@ -150,8 +154,9 @@ void ProjectExportDialog::_update_presets() { } String name = preset->get_name(); - if (preset->is_runnable()) + if (preset->is_runnable()) { name += " (" + TTR("Runnable") + ")"; + } presets->add_item(name, preset->get_platform()->get_logo()); } @@ -238,8 +243,9 @@ void ProjectExportDialog::_edit_preset(int p_index) { String file = patchlist[i].get_file(); patch->set_editable(0, true); patch->set_text(0, file.get_file().replace("*", "")); - if (file.ends_with("*")) + if (file.ends_with("*")) { patch->set_checked(0, true); + } patch->set_tooltip(0, patchlist[i]); patch->set_metadata(0, i); patch->add_button(0, presets->get_theme_icon("Remove", "EditorIcons"), 0); @@ -248,10 +254,11 @@ void ProjectExportDialog::_edit_preset(int p_index) { TreeItem *patch_add = patches->create_item(patch_root); patch_add->set_metadata(0, patchlist.size()); - if (patchlist.size() == 0) + if (patchlist.size() == 0) { patch_add->set_text(0, TTR("Add initial export...")); - else + } else { patch_add->set_text(0, TTR("Add previous patches...")); + } patch_add->add_button(0, presets->get_theme_icon("folder", "FileDialog"), 1); @@ -264,8 +271,9 @@ void ProjectExportDialog::_edit_preset(int p_index) { Vector<String> items = error.split("\n", false); error = ""; for (int i = 0; i < items.size(); i++) { - if (i > 0) + if (i > 0) { error += "\n"; + } error += " - " + items[i]; } @@ -274,10 +282,11 @@ void ProjectExportDialog::_edit_preset(int p_index) { } else { export_error->hide(); } - if (needs_templates) + if (needs_templates) { export_templates_error->show(); - else + } else { export_templates_error->hide(); + } export_button->set_disabled(true); get_ok()->set_disabled(true); @@ -352,8 +361,9 @@ void ProjectExportDialog::_update_feature_list() { } void ProjectExportDialog::_custom_features_changed(const String &p_text) { - if (updating) + if (updating) { return; + } Ref<EditorExportPreset> current = get_current_preset(); ERR_FAIL_COND(current.is_null()); @@ -386,8 +396,9 @@ void ProjectExportDialog::_patch_button_pressed(Object *p_item, int p_column, in void ProjectExportDialog::_patch_edited() { TreeItem *item = patches->get_edited(); - if (!item) + if (!item) { return; + } int index = item->get_metadata(0); Ref<EditorExportPreset> current = get_current_preset(); @@ -438,8 +449,9 @@ void ProjectExportDialog::_update_parameters(const String &p_edited_property) { } void ProjectExportDialog::_runnable_pressed() { - if (updating) + if (updating) { return; + } Ref<EditorExportPreset> current = get_current_preset(); ERR_FAIL_COND(current.is_null()); @@ -459,8 +471,9 @@ void ProjectExportDialog::_runnable_pressed() { } void ProjectExportDialog::_name_changed(const String &p_string) { - if (updating) + if (updating) { return; + } Ref<EditorExportPreset> current = get_current_preset(); ERR_FAIL_COND(current.is_null()); @@ -488,8 +501,9 @@ Ref<EditorExportPreset> ProjectExportDialog::get_current_preset() const { } void ProjectExportDialog::_export_path_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing) { - if (updating) + if (updating) { return; + } Ref<EditorExportPreset> current = get_current_preset(); ERR_FAIL_COND(current.is_null()); @@ -499,8 +513,9 @@ void ProjectExportDialog::_export_path_changed(const StringName &p_property, con } void ProjectExportDialog::_script_export_mode_changed(int p_mode) { - if (updating) + if (updating) { return; + } Ref<EditorExportPreset> current = get_current_preset(); ERR_FAIL_COND(current.is_null()); @@ -511,8 +526,9 @@ void ProjectExportDialog::_script_export_mode_changed(int p_mode) { } void ProjectExportDialog::_script_encryption_key_changed(const String &p_key) { - if (updating) + if (updating) { return; + } Ref<EditorExportPreset> current = get_current_preset(); ERR_FAIL_COND(current.is_null()); @@ -535,8 +551,9 @@ bool ProjectExportDialog::_validate_script_encryption_key(const String &p_key) { void ProjectExportDialog::_duplicate_preset() { Ref<EditorExportPreset> current = get_current_preset(); - if (current.is_null()) + if (current.is_null()) { return; + } Ref<EditorExportPreset> preset = current->get_platform()->create_preset(); ERR_FAIL_COND(!preset.is_valid()); @@ -557,15 +574,17 @@ void ProjectExportDialog::_duplicate_preset() { } } - if (valid) + if (valid) { break; + } name += " (copy)"; } preset->set_name(name); - if (make_runnable) + if (make_runnable) { preset->set_runnable(make_runnable); + } preset->set_export_filter(current->get_export_filter()); preset->set_include_filter(current->get_include_filter()); preset->set_exclude_filter(current->get_exclude_filter()); @@ -586,8 +605,9 @@ void ProjectExportDialog::_duplicate_preset() { void ProjectExportDialog::_delete_preset() { Ref<EditorExportPreset> current = get_current_preset(); - if (current.is_null()) + if (current.is_null()) { return; + } delete_confirm->set_text(vformat(TTR("Delete preset '%s'?"), current->get_name())); delete_confirm->popup_centered(); @@ -646,15 +666,18 @@ Variant ProjectExportDialog::get_drag_data_fw(const Point2 &p_point, Control *p_ bool ProjectExportDialog::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { if (p_from == presets) { Dictionary d = p_data; - if (!d.has("type") || String(d["type"]) != "export_preset") + if (!d.has("type") || String(d["type"]) != "export_preset") { return false; + } - if (presets->get_item_at_position(p_point, true) < 0 && !presets->is_pos_at_end_of_items(p_point)) + if (presets->get_item_at_position(p_point, true) < 0 && !presets->is_pos_at_end_of_items(p_point)) { return false; + } } else if (p_from == patches) { Dictionary d = p_data; - if (!d.has("type") || String(d["type"]) != "export_patch") + if (!d.has("type") || String(d["type"]) != "export_patch") { return false; + } patches->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM); @@ -679,12 +702,13 @@ void ProjectExportDialog::drop_data_fw(const Point2 &p_point, const Variant &p_d to_pos = presets->get_item_at_position(p_point, true); } - if (to_pos == -1 && !presets->is_pos_at_end_of_items(p_point)) + if (to_pos == -1 && !presets->is_pos_at_end_of_items(p_point)) { return; + } - if (to_pos == from_pos) + if (to_pos == from_pos) { return; - else if (to_pos > from_pos) { + } else if (to_pos > from_pos) { to_pos--; } @@ -693,26 +717,29 @@ void ProjectExportDialog::drop_data_fw(const Point2 &p_point, const Variant &p_d EditorExport::get_singleton()->add_export_preset(preset, to_pos); _update_presets(); - if (to_pos >= 0) + if (to_pos >= 0) { _edit_preset(to_pos); - else + } else { _edit_preset(presets->get_item_count() - 1); + } } else if (p_from == patches) { Dictionary d = p_data; - if (!d.has("type") || String(d["type"]) != "export_patch") + if (!d.has("type") || String(d["type"]) != "export_patch") { return; + } int from_pos = d["patch"]; TreeItem *item = patches->get_item_at_position(p_point); - if (!item) + if (!item) { return; + } int to_pos = item->get_cell_mode(0) == TreeItem::CELL_MODE_CHECK ? int(item->get_metadata(0)) : -1; - if (to_pos == from_pos) + if (to_pos == from_pos) { return; - else if (to_pos > from_pos) { + } else if (to_pos > from_pos) { to_pos--; } @@ -726,12 +753,14 @@ void ProjectExportDialog::drop_data_fw(const Point2 &p_point, const Variant &p_d } void ProjectExportDialog::_export_type_changed(int p_which) { - if (updating) + if (updating) { return; + } Ref<EditorExportPreset> current = get_current_preset(); - if (current.is_null()) + if (current.is_null()) { return; + } current->set_export_filter(EditorExportPreset::ExportFilter(p_which)); updating = true; @@ -740,12 +769,14 @@ void ProjectExportDialog::_export_type_changed(int p_which) { } void ProjectExportDialog::_filter_changed(const String &p_filter) { - if (updating) + if (updating) { return; + } Ref<EditorExportPreset> current = get_current_preset(); - if (current.is_null()) + if (current.is_null()) { return; + } current->set_include_filter(include_filters->get_text()); current->set_exclude_filter(exclude_filters->get_text()); @@ -757,8 +788,9 @@ void ProjectExportDialog::_fill_resource_tree() { include_margin->hide(); Ref<EditorExportPreset> current = get_current_preset(); - if (current.is_null()) + if (current.is_null()) { return; + } EditorExportPreset::ExportFilter f = current->get_export_filter(); @@ -790,8 +822,9 @@ bool ProjectExportDialog::_fill_tree(EditorFileSystemDirectory *p_dir, TreeItem for (int i = 0; i < p_dir->get_file_count(); i++) { String type = p_dir->get_file_type(i); - if (p_only_scenes && type != "PackedScene") + if (p_only_scenes && type != "PackedScene") { continue; + } TreeItem *file = include_files->create_item(p_item); file->set_cell_mode(0, TreeItem::CELL_MODE_CHECK); @@ -811,16 +844,19 @@ bool ProjectExportDialog::_fill_tree(EditorFileSystemDirectory *p_dir, TreeItem } void ProjectExportDialog::_tree_changed() { - if (updating) + if (updating) { return; + } Ref<EditorExportPreset> current = get_current_preset(); - if (current.is_null()) + if (current.is_null()) { return; + } TreeItem *item = include_files->get_edited(); - if (!item) + if (!item) { return; + } String path = item->get_metadata(0); bool added = item->is_checked(0); @@ -859,10 +895,12 @@ void ProjectExportDialog::_validate_export_path(const String &p_path) { bool invalid_path = (p_path.get_file().get_basename() == ""); // Check if state change before needlessly messing with signals - if (invalid_path && export_project->get_ok()->is_disabled()) + if (invalid_path && export_project->get_ok()->is_disabled()) { return; - if (!invalid_path && !export_project->get_ok()->is_disabled()) + } + if (!invalid_path && !export_project->get_ok()->is_disabled()) { return; + } if (invalid_path) { export_project->get_ok()->set_disabled(true); diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index 1e04b4e467..dc5ff6a5eb 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -300,8 +300,9 @@ private: if (lidx != -1) { sp = sp.substr(lidx + 1, sp.length()).capitalize(); } - if (sp == "" && mode == MODE_IMPORT) + if (sp == "" && mode == MODE_IMPORT) { sp = TTR("Imported Project"); + } project_name->set_text(sp); _text_changed(sp); @@ -404,13 +405,15 @@ private: } void _text_changed(const String &p_text) { - if (mode != MODE_NEW) + if (mode != MODE_NEW) { return; + } _test_path(); - if (p_text == "") + if (p_text == "") { set_message(TTR("It would be a good idea to name your project."), MESSAGE_WARNING); + } } void ok_pressed() { @@ -578,8 +581,9 @@ private: } dir = dir.replace("\\", "/"); - if (dir.ends_with("/")) + if (dir.ends_with("/")) { dir = dir.substr(0, dir.length() - 1); + } String proj = get_project_key_from_path(dir); EditorSettings::get_singleton()->set("projects/" + proj, dir); EditorSettings::get_singleton()->save(); @@ -608,16 +612,19 @@ private: project_name->clear(); _text_changed(""); - if (status_rect->get_texture() == msg->get_theme_icon("StatusError", "EditorIcons")) + if (status_rect->get_texture() == msg->get_theme_icon("StatusError", "EditorIcons")) { msg->show(); + } - if (install_status_rect->get_texture() == msg->get_theme_icon("StatusError", "EditorIcons")) + if (install_status_rect->get_texture() == msg->get_theme_icon("StatusError", "EditorIcons")) { msg->show(); + } } void _notification(int p_what) { - if (p_what == NOTIFICATION_WM_CLOSE_REQUEST) + if (p_what == NOTIFICATION_WM_CLOSE_REQUEST) { _remove_created_folder(); + } } protected: @@ -1137,8 +1144,9 @@ void ProjectList::load_project_data(const String &p_property_key, Item &p_item, String project_name = TTR("Unnamed Project"); if (cf_err == OK) { String cf_project_name = static_cast<String>(cf->get_value("application", "config/name", "")); - if (cf_project_name != "") + if (cf_project_name != "") { project_name = cf_project_name.xml_unescape(); + } config_version = (int)cf->get_value("", "config_version", 0); } @@ -1161,8 +1169,9 @@ void ProjectList::load_project_data(const String &p_property_key, Item &p_item, String fscache = path.plus_file(".fscache"); if (FileAccess::exists(fscache)) { uint64_t cache_modified = FileAccess::get_modified_time(fscache); - if (cache_modified > last_edited) + if (cache_modified > last_edited) { last_edited = cache_modified; + } } } else { grayed = true; @@ -1208,8 +1217,9 @@ void ProjectList::load_projects() { for (List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) { // This is actually something like "projects/C:::Documents::Godot::Projects::MyGame" String property_key = E->get().name; - if (!property_key.begins_with("projects/")) + if (!property_key.begins_with("projects/")) { continue; + } String project_key = property_key.get_slice("/", 1); bool favorite = favorites.has("favorite_projects/" + project_key); @@ -1327,8 +1337,9 @@ void ProjectList::create_project_item_control(int p_index) { hb->icon = tf; VBoxContainer *vb = memnew(VBoxContainer); - if (item.grayed) + if (item.grayed) { vb->set_modulate(Color(1, 1, 1, 0.5)); + } vb->set_h_size_flags(Control::SIZE_EXPAND_FILL); hb->add_child(vb); Control *ec = memnew(Control); @@ -1792,8 +1803,9 @@ void ProjectManager::_notification(int p_what) { } } break; case NOTIFICATION_READY: { - if (_project_list->get_project_count() == 0 && StreamPeerSSL::is_available()) + if (_project_list->get_project_count() == 0 && StreamPeerSSL::is_available()) { open_templates->popup_centered(); + } if (_project_list->get_project_count() >= 1) { // Focus on the search box immediately to allow the user @@ -1859,8 +1871,9 @@ void ProjectManager::_unhandled_input(const Ref<InputEvent> &p_ev) { } #endif - if (tabs->get_current_tab() != 0) + if (tabs->get_current_tab() != 0) { return; + } bool keycode_handled = true; @@ -1886,8 +1899,9 @@ void ProjectManager::_unhandled_input(const Ref<InputEvent> &p_ev) { } break; case KEY_UP: { - if (k->get_shift()) + if (k->get_shift()) { break; + } int index = _project_list->get_single_selected_index(); if (index > 0) { @@ -1899,8 +1913,9 @@ void ProjectManager::_unhandled_input(const Ref<InputEvent> &p_ev) { break; } case KEY_DOWN: { - if (k->get_shift()) + if (k->get_shift()) { break; + } int index = _project_list->get_single_selected_index(); if (index + 1 < _project_list->get_project_count()) { @@ -1911,10 +1926,11 @@ void ProjectManager::_unhandled_input(const Ref<InputEvent> &p_ev) { } break; case KEY_F: { - if (k->get_command()) + if (k->get_command()) { this->project_filter->search_box->grab_focus(); - else + } else { keycode_handled = false; + } } break; default: { keycode_handled = false; @@ -2176,8 +2192,9 @@ void ProjectManager::_erase_missing_projects_confirm() { void ProjectManager::_erase_project() { const Set<String> &selected_list = _project_list->get_selected_project_keys(); - if (selected_list.size() == 0) + if (selected_list.size() == 0) { return; + } String confirm_message; if (selected_list.size() >= 2) { @@ -2305,8 +2322,9 @@ void ProjectManager::_open_asset_library() { ProjectManager::ProjectManager() { // load settings - if (!EditorSettings::get_singleton()) + if (!EditorSettings::get_singleton()) { EditorSettings::create(); + } EditorSettings::get_singleton()->set_optimize_save(false); //just write settings as they came @@ -2626,14 +2644,16 @@ ProjectManager::ProjectManager() { } ProjectManager::~ProjectManager() { - if (EditorSettings::get_singleton()) + if (EditorSettings::get_singleton()) { EditorSettings::destroy(); + } } void ProjectListFilter::_setup_filters(Vector<String> options) { filter_option->clear(); - for (int i = 0; i < options.size(); i++) + for (int i = 0; i < options.size(); i++) { filter_option->add_item(options[i]); + } } void ProjectListFilter::_search_text_changed(const String &p_newtext) { @@ -2657,8 +2677,9 @@ void ProjectListFilter::_filter_option_selected(int p_idx) { FilterOption selected = (FilterOption)(filter_option->get_selected()); if (_current_filter != selected) { _current_filter = selected; - if (is_inside_tree()) + if (is_inside_tree()) { emit_signal("filter_changed"); + } } } diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp index 4f9c6c2cf3..a7c260c0f8 100644 --- a/editor/project_settings_editor.cpp +++ b/editor/project_settings_editor.cpp @@ -163,17 +163,20 @@ void ProjectSettingsEditor::_notification(int p_what) { static bool _validate_action_name(const String &p_name) { const CharType *cstr = p_name.c_str(); - for (int i = 0; cstr[i]; i++) + for (int i = 0; cstr[i]; i++) { if (cstr[i] == '/' || cstr[i] == ':' || cstr[i] == '"' || - cstr[i] == '=' || cstr[i] == '\\' || cstr[i] < 32) + cstr[i] == '=' || cstr[i] == '\\' || cstr[i] < 32) { return false; + } + } return true; } void ProjectSettingsEditor::_action_selected() { TreeItem *ti = input_editor->get_selected(); - if (!ti || !ti->is_editable(0)) + if (!ti || !ti->is_editable(0)) { return; + } add_at = "input/" + ti->get_text(0); edit_idx = -1; @@ -181,15 +184,17 @@ void ProjectSettingsEditor::_action_selected() { void ProjectSettingsEditor::_action_edited() { TreeItem *ti = input_editor->get_selected(); - if (!ti) + if (!ti) { return; + } if (input_editor->get_selected_column() == 0) { String new_name = ti->get_text(0); String old_name = add_at.substr(add_at.find("/") + 1, add_at.length()); - if (new_name == old_name) + if (new_name == old_name) { return; + } if (new_name == "" || !_validate_action_name(new_name)) { ti->set_text(0, old_name); @@ -262,8 +267,9 @@ void ProjectSettingsEditor::_device_input_add() { for (int i = 0; i < events.size(); i++) { Ref<InputEventMouseButton> aie = events[i]; - if (aie.is_null()) + if (aie.is_null()) { continue; + } if (aie->get_device() == mb->get_device() && aie->get_button_index() == mb->get_button_index()) { return; } @@ -281,8 +287,9 @@ void ProjectSettingsEditor::_device_input_add() { for (int i = 0; i < events.size(); i++) { Ref<InputEventJoypadMotion> aie = events[i]; - if (aie.is_null()) + if (aie.is_null()) { continue; + } if (aie->get_device() == jm->get_device() && aie->get_axis() == jm->get_axis() && aie->get_axis_value() == jm->get_axis_value()) { return; @@ -301,8 +308,9 @@ void ProjectSettingsEditor::_device_input_add() { for (int i = 0; i < events.size(); i++) { Ref<InputEventJoypadButton> aie = events[i]; - if (aie.is_null()) + if (aie.is_null()) { continue; + } if (aie->get_device() == jb->get_device() && aie->get_button_index() == jb->get_button_index()) { return; } @@ -342,14 +350,16 @@ int ProjectSettingsEditor::_get_current_device() { } String ProjectSettingsEditor::_get_device_string(int i_device) { - if (i_device == InputMap::ALL_DEVICES) + if (i_device == InputMap::ALL_DEVICES) { return TTR("All Devices"); + } return TTR("Device") + " " + itos(i_device); } void ProjectSettingsEditor::_press_a_key_confirm() { - if (last_wait_for_key.is_null()) + if (last_wait_for_key.is_null()) { return; + } Ref<InputEventKey> ie; ie.instance(); @@ -374,8 +384,9 @@ void ProjectSettingsEditor::_press_a_key_confirm() { for (int i = 0; i < events.size(); i++) { Ref<InputEventKey> aie = events[i]; - if (aie.is_null()) + if (aie.is_null()) { continue; + } if (!press_a_key_physical) { if (aie->get_keycode_with_modifiers() == ie->get_keycode_with_modifiers()) { return; @@ -411,11 +422,13 @@ void ProjectSettingsEditor::_show_last_added(const Ref<InputEvent> &p_event, con String name = p_name; name.erase(0, 6); - if (!r) + if (!r) { return; + } r = r->get_children(); - if (!r) + if (!r) { return; + } bool found = false; while (r) { if (r->get_text(0) != name) { @@ -433,13 +446,15 @@ void ProjectSettingsEditor::_show_last_added(const Ref<InputEvent> &p_event, con } child = child->get_next(); } - if (found) + if (found) { break; + } r = r->get_next(); } - if (found) + if (found) { input_editor->ensure_cursor_is_visible(); + } } void ProjectSettingsEditor::_wait_for_key(const Ref<InputEvent> &p_event) { @@ -528,8 +543,9 @@ void ProjectSettingsEditor::_add_item(int p_item, Ref<InputEvent> p_exiting_even device_index->clear(); for (int i = 0; i < JOY_BUTTON_MAX; i++) { String desc = TTR("Button") + " " + itos(i); - if (i < JOY_SDL_BUTTONS) + if (i < JOY_SDL_BUTTONS) { desc += " (" + TTR(_button_descriptions[i]) + ")"; + } device_index->add_item(desc); } device_input->popup_centered(Size2(350, 95) * EDSCALE); @@ -579,8 +595,9 @@ void ProjectSettingsEditor::_edit_item(Ref<InputEvent> p_exiting_event) { void ProjectSettingsEditor::_action_activated() { TreeItem *ti = input_editor->get_selected(); - if (!ti || ti->get_parent() == input_editor->get_root()) + if (!ti || ti->get_parent() == input_editor->get_root()) { return; + } String name = "input/" + ti->get_parent()->get_text(0); int idx = ti->get_metadata(0); @@ -589,8 +606,9 @@ void ProjectSettingsEditor::_action_activated() { ERR_FAIL_INDEX(idx, events.size()); Ref<InputEvent> event = events[idx]; - if (event.is_null()) + if (event.is_null()) { return; + } add_at = name; edit_idx = idx; @@ -673,8 +691,9 @@ void ProjectSettingsEditor::_action_button_pressed(Object *p_obj, int p_column, Ref<InputEvent> event = events[idx]; - if (event.is_null()) + if (event.is_null()) { return; + } ti->set_as_cursor(0); add_at = name; @@ -685,8 +704,9 @@ void ProjectSettingsEditor::_action_button_pressed(Object *p_obj, int p_column, } void ProjectSettingsEditor::_update_actions() { - if (setting) + if (setting) { return; + } Map<String, bool> collapsed; @@ -705,12 +725,14 @@ void ProjectSettingsEditor::_update_actions() { for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { const PropertyInfo &pi = E->get(); - if (!pi.name.begins_with("input/")) + if (!pi.name.begins_with("input/")) { continue; + } String name = pi.name.get_slice("/", 1); - if (name == "") + if (name == "") { continue; + } Dictionary action = ProjectSettings::get_singleton()->get(pi.name); Array events = action["events"]; @@ -718,8 +740,9 @@ void ProjectSettingsEditor::_update_actions() { TreeItem *item = input_editor->create_item(root); item->set_text(0, name); item->set_custom_bg_color(0, input_editor->get_theme_color("prop_subsection", "Editor")); - if (collapsed.has(name)) + if (collapsed.has(name)) { item->set_collapsed(collapsed[name]); + } item->set_editable(1, true); item->set_cell_mode(1, TreeItem::CELL_MODE_RANGE); @@ -744,8 +767,9 @@ void ProjectSettingsEditor::_update_actions() { for (int i = 0; i < events.size(); i++) { Ref<InputEvent> event = events[i]; - if (event.is_null()) + if (event.is_null()) { continue; + } TreeItem *action2 = input_editor->create_item(item); @@ -850,8 +874,9 @@ void ProjectSettingsEditor::update_plugins() { void ProjectSettingsEditor::_item_selected(const String &p_path) { const String &selected_path = p_path; - if (selected_path == String()) + if (selected_path == String()) { return; + } category->set_text(globals_editor->get_current_section()); property->set_text(selected_path); popup_copy_to_feature->set_disabled(false); @@ -985,13 +1010,16 @@ void ProjectSettingsEditor::_action_add() { TreeItem *r = input_editor->get_root(); - if (!r) + if (!r) { return; + } r = r->get_children(); - if (!r) + if (!r) { return; - while (r->get_next()) + } + while (r->get_next()) { r = r->get_next(); + } r->select(0); input_editor->ensure_cursor_is_visible(); @@ -1072,8 +1100,9 @@ void ProjectSettingsEditor::_copy_to_platform_about_to_show() { Variant ProjectSettingsEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) { TreeItem *selected = input_editor->get_selected(); - if (!selected || selected->get_parent() != input_editor->get_root()) + if (!selected || selected->get_parent() != input_editor->get_root()) { return Variant(); + } String name = selected->get_text(0); VBoxContainer *vb = memnew(VBoxContainer); @@ -1094,25 +1123,29 @@ Variant ProjectSettingsEditor::get_drag_data_fw(const Point2 &p_point, Control * bool ProjectSettingsEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { Dictionary d = p_data; - if (!d.has("type") || d["type"] != "nodes") + if (!d.has("type") || d["type"] != "nodes") { return false; + } TreeItem *selected = input_editor->get_selected(); TreeItem *item = input_editor->get_item_at_position(p_point); - if (!selected || !item || item == selected || item->get_parent() == selected) + if (!selected || !item || item == selected || item->get_parent() == selected) { return false; + } return true; } void ProjectSettingsEditor::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; + } TreeItem *selected = input_editor->get_selected(); TreeItem *item = input_editor->get_item_at_position(p_point); - if (!item) + if (!item) { return; + } TreeItem *target = item->get_parent() == input_editor->get_root() ? item : item->get_parent(); String selected_name = "input/" + selected->get_text(0); @@ -1188,8 +1221,9 @@ void ProjectSettingsEditor::_translation_add(const String &p_path) { PackedStringArray translations = ProjectSettings::get_singleton()->get("locale/translations"); for (int i = 0; i < translations.size(); i++) { - if (translations[i] == p_path) + if (translations[i] == p_path) { return; //exists + } } translations.push_back(p_path); @@ -1242,8 +1276,9 @@ void ProjectSettingsEditor::_translation_res_add(const String &p_path) { prev = remaps; } - if (remaps.has(p_path)) + if (remaps.has(p_path)) { return; //pointless already has it + } remaps[p_path] = PackedStringArray(); @@ -1287,18 +1322,21 @@ void ProjectSettingsEditor::_translation_res_option_add(const String &p_path) { } void ProjectSettingsEditor::_translation_res_select() { - if (updating_translations) + if (updating_translations) { return; + } call_deferred("_update_translations"); } void ProjectSettingsEditor::_translation_res_option_changed() { - if (updating_translations) + if (updating_translations) { return; + } - if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) + if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) { return; + } Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps"); @@ -1339,11 +1377,13 @@ void ProjectSettingsEditor::_translation_res_option_changed() { } void ProjectSettingsEditor::_translation_res_delete(Object *p_item, int p_column, int p_button) { - if (updating_translations) + if (updating_translations) { return; + } - if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) + if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) { return; + } Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps"); @@ -1365,11 +1405,13 @@ void ProjectSettingsEditor::_translation_res_delete(Object *p_item, int p_column } void ProjectSettingsEditor::_translation_res_option_delete(Object *p_item, int p_column, int p_button) { - if (updating_translations) + if (updating_translations) { return; + } - if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) + if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) { return; + } Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps"); @@ -1480,8 +1522,9 @@ void ProjectSettingsEditor::_translation_filter_mode_changed(int p_mode) { void ProjectSettingsEditor::_update_translations() { //update translations - if (updating_translations) + if (updating_translations) { return; + } updating_translations = true; @@ -1539,8 +1582,9 @@ void ProjectSettingsEditor::_update_translations() { String n = names[i]; String l = langs[i]; bool is_checked = l_filter.has(l); - if (filter_mode == SHOW_ONLY_SELECTED_LOCALES && !is_checked) + if (filter_mode == SHOW_ONLY_SELECTED_LOCALES && !is_checked) { continue; + } TreeItem *t = translation_filter->create_item(root); t->set_cell_mode(0, TreeItem::CELL_MODE_CHECK); @@ -1582,16 +1626,18 @@ void ProjectSettingsEditor::_update_translations() { if (filter_mode == SHOW_ONLY_SELECTED_LOCALES && fl_idx_count != 0) { if (l_filter.size() > 0) { if (l_filter.find(langs[i]) != -1) { - if (langnames.length() > 0) + if (langnames.length() > 0) { langnames += ","; + } langnames += names[i]; translation_locales_idxs_remap.write[l_idx] = i; l_idx++; } } } else { - if (i > 0) + if (i > 0) { langnames += ","; + } langnames += names[i]; } } @@ -1635,8 +1681,9 @@ void ProjectSettingsEditor::_update_translations() { t2->set_editable(1, true); t2->set_metadata(1, path); int idx = langs.find(locale); - if (idx < 0) + if (idx < 0) { idx = 0; + } int f_idx = translation_locales_idxs_remap.find(idx); if (f_idx != -1 && fl_idx_count > 0 && filter_mode == SHOW_ONLY_SELECTED_LOCALES) { @@ -1926,8 +1973,9 @@ ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) { vbc_left->add_child(l); device_id = memnew(OptionButton); - for (int i = -1; i < 8; i++) + for (int i = -1; i < 8; i++) { device_id->add_item(_get_device_string(i)); + } _set_current_device(0); vbc_left->add_child(device_id); diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp index e14d842b98..c6efcc944b 100644 --- a/editor/property_editor.cpp +++ b/editor/property_editor.cpp @@ -77,22 +77,25 @@ void EditorResourceConversionPlugin::_bind_methods() { } String EditorResourceConversionPlugin::converts_to() const { - if (get_script_instance()) + if (get_script_instance()) { return get_script_instance()->call("_converts_to"); + } return ""; } bool EditorResourceConversionPlugin::handles(const Ref<Resource> &p_resource) const { - if (get_script_instance()) + if (get_script_instance()) { return get_script_instance()->call("_handles", p_resource); + } return false; } Ref<Resource> EditorResourceConversionPlugin::convert(const Ref<Resource> &p_resource) const { - if (get_script_instance()) + if (get_script_instance()) { return get_script_instance()->call("_convert", p_resource); + } return Ref<Resource>(); } @@ -168,8 +171,9 @@ void CustomPropertyEditor::_menu_option(int p_which) { case OBJ_MENU_MAKE_UNIQUE: { Ref<Resource> res_orig = v; - if (res_orig.is_null()) + if (res_orig.is_null()) { return; + } List<PropertyInfo> property_list; res_orig->get_property_list(&property_list); @@ -214,13 +218,15 @@ void CustomPropertyEditor::_menu_option(int p_which) { } break; case OBJ_MENU_NEW_SCRIPT: { - if (Object::cast_to<Node>(owner)) + if (Object::cast_to<Node>(owner)) { EditorNode::get_singleton()->get_scene_tree_dock()->open_script_dialog(Object::cast_to<Node>(owner), false); + } } break; case OBJ_MENU_EXTEND_SCRIPT: { - if (Object::cast_to<Node>(owner)) + if (Object::cast_to<Node>(owner)) { EditorNode::get_singleton()->get_scene_tree_dock()->open_script_dialog(Object::cast_to<Node>(owner), true); + } } break; case OBJ_MENU_SHOW_IN_FILE_SYSTEM: { @@ -307,8 +313,9 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: hint = p_hint; hint_text = p_hint_text; type_button->hide(); - if (color_picker) + if (color_picker) { color_picker->hide(); + } texture_preview->hide(); inheritors_array.clear(); text_edit->hide(); @@ -321,8 +328,9 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: for (int i = 0; i < MAX_VALUE_EDITORS; i++) { value_editor[i]->hide(); value_label[i]->hide(); - if (i < 4) + if (i < 4) { scroll[i]->hide(); + } } for (int i = 0; i < MAX_ACTION_BUTTONS; i++) { @@ -330,8 +338,9 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: } checks20gc->hide(); - for (int i = 0; i < 20; i++) + for (int i = 0; i < 20; i++) { checks20[i]->hide(); + } type = (p_variant.get_type() != Variant::NIL && p_variant.get_type() != Variant::_RID && p_type != Variant::OBJECT) ? p_variant.get_type() : p_type; @@ -355,17 +364,20 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: int c = hint_text.get_slice_count(","); float min = 0, max = 100, step = type == Variant::FLOAT ? .01 : 1; if (c >= 1) { - if (!hint_text.get_slice(",", 0).empty()) + if (!hint_text.get_slice(",", 0).empty()) { min = hint_text.get_slice(",", 0).to_double(); + } } if (c >= 2) { - if (!hint_text.get_slice(",", 1).empty()) + if (!hint_text.get_slice(",", 1).empty()) { max = hint_text.get_slice(",", 1).to_double(); + } } if (c >= 3) { - if (!hint_text.get_slice(",", 2).empty()) + if (!hint_text.get_slice(",", 2).empty()) { step = hint_text.get_slice(",", 2).to_double(); + } } if (c >= 4 && hint_text.get_slice(",", 3) == "slider") { @@ -389,8 +401,9 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: int current_val = 0; for (int i = 0; i < options.size(); i++) { Vector<String> text_split = options[i].split(":"); - if (text_split.size() != 1) + if (text_split.size() != 1) { current_val = text_split[1].to_int(); + } menu->add_item(text_split[0]); menu->set_item_metadata(i, current_val); current_val += 1; @@ -466,12 +479,14 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: Vector<String> flags = hint_text.split(","); for (int i = 0; i < flags.size(); i++) { String flag = flags[i]; - if (flag == "") + if (flag == "") { continue; + } menu->add_check_item(flag, i); int f = v; - if (f & (1 << i)) + if (f & (1 << i)) { menu->set_item_checked(menu->get_item_index(i), true); + } } menu->set_position(get_position()); menu->popup(); @@ -562,8 +577,9 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: type = Variant::Type(i); } } - if (type != Variant::NIL) + if (type != Variant::NIL) { property_select->select_method_from_basic_type(type, v); + } updating = false; return false; @@ -579,8 +595,9 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: MAKE_PROPSELECT Object *instance = ObjectDB::get_instance(ObjectID(hint_text.to_int64())); - if (instance) + if (instance) { property_select->select_method_from_instance(instance, v); + } updating = false; return false; @@ -599,16 +616,18 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: MAKE_PROPSELECT Variant::Type type = Variant::NIL; String tname = hint_text; - if (tname.find(".") != -1) + if (tname.find(".") != -1) { tname = tname.get_slice(".", 0); + } for (int i = 0; i < Variant::VARIANT_MAX; i++) { if (tname == Variant::get_type_name(Variant::Type(i))) { type = Variant::Type(Variant::Type(i)); } } - if (type != Variant::NIL) + if (type != Variant::NIL) { property_select->select_property_from_basic_type(type, v); + } updating = false; return false; @@ -625,8 +644,9 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: MAKE_PROPSELECT Object *instance = ObjectDB::get_instance(ObjectID(hint_text.to_int64())); - if (instance) + if (instance) { property_select->select_property_from_instance(instance, v); + } updating = false; return false; @@ -793,10 +813,11 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: // 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); + } } color_picker->show(); @@ -811,15 +832,17 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: names.push_back(TTR("Assign")); names.push_back(TTR("Clear")); - if (owner && owner->is_class("Node") && (v.get_type() == Variant::NODE_PATH) && Object::cast_to<Node>(owner)->has_node(v)) + if (owner && owner->is_class("Node") && (v.get_type() == Variant::NODE_PATH) && Object::cast_to<Node>(owner)->has_node(v)) { names.push_back(TTR("Select Node")); + } config_action_buttons(names); } break; case Variant::OBJECT: { - if (hint != PROPERTY_HINT_RESOURCE_TYPE) + if (hint != PROPERTY_HINT_RESOURCE_TYPE) { break; + } if (p_name == "script" && hint_text == "Script" && Object::cast_to<Node>(owner)) { menu->add_item(TTR("New Script"), OBJ_MENU_NEW_SCRIPT); @@ -860,15 +883,17 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: for (int k = 0; k < custom_resources.size(); k++) { if (custom_resources[k].name == t) { is_custom_resource = true; - if (custom_resources[k].icon.is_valid()) + if (custom_resources[k].icon.is_valid()) { icon = custom_resources[k].icon; + } break; } } } - if (!is_custom_resource && !ClassDB::can_instance(t)) + if (!is_custom_resource && !ClassDB::can_instance(t)) { continue; + } inheritors_array.push_back(t); @@ -880,8 +905,9 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: } } - if (menu->get_item_count()) + if (menu->get_item_count()) { menu->add_separator(); + } } menu->add_item(TTR("Load"), OBJ_MENU_LOAD); @@ -901,14 +927,16 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: RES cb = EditorSettings::get_singleton()->get_resource_clipboard(); bool paste_valid = false; if (cb.is_valid()) { - if (hint_text == "") + if (hint_text == "") { paste_valid = true; - else - for (int i = 0; i < hint_text.get_slice_count(","); i++) + } else { + for (int i = 0; i < hint_text.get_slice_count(","); i++) { if (ClassDB::is_parent_class(cb->get_class(), hint_text.get_slice(",", i))) { paste_valid = true; break; } + } + } } if (!RES(v).is_null() || paste_valid) { @@ -939,7 +967,6 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: hide(); updating = false; return false; - } break; case Variant::DICTIONARY: { } break; @@ -1089,12 +1116,13 @@ void CustomPropertyEditor::_node_path_selected(NodePath p_path) { } else if (owner) { Node *node = nullptr; - if (owner->is_class("Node")) + if (owner->is_class("Node")) { node = Object::cast_to<Node>(owner); - else if (owner->is_class("ArrayPropertyEdit")) + } else if (owner->is_class("ArrayPropertyEdit")) { node = Object::cast_to<ArrayPropertyEdit>(owner)->get_node(); - else if (owner->is_class("DictionaryPropertyEdit")) + } else if (owner->is_class("DictionaryPropertyEdit")) { node = Object::cast_to<DictionaryPropertyEdit>(owner)->get_node(); + } if (!node) { v = p_path; emit_signal("variant_changed"); @@ -1114,8 +1142,9 @@ void CustomPropertyEditor::_node_path_selected(NodePath p_path) { } void CustomPropertyEditor::_action_pressed(int p_which) { - if (updating) + if (updating) { return; + } switch (type) { case Variant::BOOL: { @@ -1125,10 +1154,11 @@ void CustomPropertyEditor::_action_pressed(int p_which) { case Variant::INT: { if (hint == PROPERTY_HINT_LAYERS_2D_PHYSICS || hint == PROPERTY_HINT_LAYERS_2D_RENDER || hint == PROPERTY_HINT_LAYERS_3D_PHYSICS || hint == PROPERTY_HINT_LAYERS_3D_RENDER) { uint32_t f = v; - if (checks20[p_which]->is_pressed()) + if (checks20[p_which]->is_pressed()) { f |= (1 << p_which); - else + } else { f &= ~(1 << p_which); + } v = f; emit_signal("variant_changed"); @@ -1141,10 +1171,11 @@ void CustomPropertyEditor::_action_pressed(int p_which) { } else if (hint == PROPERTY_HINT_FILE || hint == PROPERTY_HINT_GLOBAL_FILE) { if (p_which == 0) { - if (hint == PROPERTY_HINT_FILE) + if (hint == PROPERTY_HINT_FILE) { file->set_access(EditorFileDialog::ACCESS_RESOURCES); - else + } else { file->set_access(EditorFileDialog::ACCESS_FILESYSTEM); + } file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE); file->clear_filters(); @@ -1155,10 +1186,11 @@ void CustomPropertyEditor::_action_pressed(int p_which) { Vector<String> extensions = hint_text.split(","); for (int i = 0; i < extensions.size(); i++) { String filter = extensions[i]; - if (filter.begins_with(".")) + if (filter.begins_with(".")) { filter = "*" + extensions[i]; - else if (!filter.begins_with("*")) + } else if (!filter.begins_with("*")) { filter = "*." + extensions[i]; + } file->add_filter(filter + " ; " + extensions[i].to_upper()); } @@ -1172,10 +1204,11 @@ void CustomPropertyEditor::_action_pressed(int p_which) { } else if (hint == PROPERTY_HINT_DIR || hint == PROPERTY_HINT_GLOBAL_DIR) { if (p_which == 0) { - if (hint == PROPERTY_HINT_DIR) + if (hint == PROPERTY_HINT_DIR) { file->set_access(EditorFileDialog::ACCESS_RESOURCES); - else + } else { file->set_access(EditorFileDialog::ACCESS_FILESYSTEM); + } file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_DIR); file->clear_filters(); file->popup_centered_ratio(); @@ -1261,8 +1294,9 @@ void CustomPropertyEditor::_action_pressed(int p_which) { hide(); } else if (p_which == 4) { Ref<Resource> res_orig = v; - if (res_orig.is_null()) + if (res_orig.is_null()) { return; + } List<PropertyInfo> property_list; res_orig->get_property_list(&property_list); @@ -1305,17 +1339,20 @@ void CustomPropertyEditor::_drag_easing(const Ref<InputEvent> &p_ev) { if (mm.is_valid() && mm->get_button_mask() & BUTTON_MASK_LEFT) { float rel = mm->get_relative().x; - if (rel == 0) + if (rel == 0) { return; + } bool flip = hint_text == "attenuation"; - if (flip) + if (flip) { rel = -rel; + } float val = v; - if (val == 0) + if (val == 0) { return; + } bool sg = val < 0; val = Math::absf(val); @@ -1324,8 +1361,9 @@ void CustomPropertyEditor::_drag_easing(const Ref<InputEvent> &p_ev) { val += rel * 0.05; val = Math::pow(2.0f, val); - if (sg) + if (sg) { val = -val; + } v = val; easing_draw->update(); @@ -1384,8 +1422,9 @@ void CustomPropertyEditor::_create_selected_property(const String &p_prop) { } void CustomPropertyEditor::_modified(String p_string) { - if (updating) + if (updating) { return; + } updating = true; switch (type) { @@ -1632,8 +1671,9 @@ void CustomPropertyEditor::config_action_buttons(const List<String> &p_strings) action_buttons[i]->set_text(p_strings[i]); Size2 btn_m_size = action_buttons[i]->get_minimum_size(); - if (btn_m_size.width > max_width) + if (btn_m_size.width > max_width) { max_width = btn_m_size.width; + } } else { action_buttons[i]->hide(); diff --git a/editor/property_selector.cpp b/editor/property_selector.cpp index 870bf52a91..6888ebdc71 100644 --- a/editor/property_selector.cpp +++ b/editor/property_selector.cpp @@ -51,8 +51,9 @@ void PropertySelector::_sbox_input(const Ref<InputEvent> &p_ie) { search_box->accept_event(); TreeItem *root = search_options->get_root(); - if (!root->get_children()) + if (!root->get_children()) { break; + } TreeItem *current = search_options->get_selected(); @@ -70,12 +71,13 @@ void PropertySelector::_sbox_input(const Ref<InputEvent> &p_ie) { } void PropertySelector::_update_search() { - if (properties) + if (properties) { set_title(TTR("Select Property")); - else if (virtuals_only) + } else if (virtuals_only) { set_title(TTR("Select Virtual Method")); - else + } else { set_title(TTR("Select Method")); + } search_options->clear(); help_bit->set_text(""); @@ -161,14 +163,17 @@ void PropertySelector::_update_search() { continue; } - if (!(E->get().usage & PROPERTY_USAGE_EDITOR) && !(E->get().usage & PROPERTY_USAGE_SCRIPT_VARIABLE)) + if (!(E->get().usage & PROPERTY_USAGE_EDITOR) && !(E->get().usage & PROPERTY_USAGE_SCRIPT_VARIABLE)) { continue; + } - if (search_box->get_text() != String() && E->get().name.find(search_box->get_text()) == -1) + if (search_box->get_text() != String() && E->get().name.find(search_box->get_text()) == -1) { continue; + } - if (type_filter.size() && type_filter.find(E->get().type) == -1) + if (type_filter.size() && type_filter.find(E->get().type) == -1) { continue; + } TreeItem *item = search_options->create_item(category ? category : root); item->set_text(0, E->get().name); @@ -238,17 +243,21 @@ void PropertySelector::_update_search() { } String name = E->get().name.get_slice(":", 0); - if (!script_methods && name.begins_with("_") && !(E->get().flags & METHOD_FLAG_VIRTUAL)) + if (!script_methods && name.begins_with("_") && !(E->get().flags & METHOD_FLAG_VIRTUAL)) { continue; + } - if (virtuals_only && !(E->get().flags & METHOD_FLAG_VIRTUAL)) + if (virtuals_only && !(E->get().flags & METHOD_FLAG_VIRTUAL)) { continue; + } - if (!virtuals_only && (E->get().flags & METHOD_FLAG_VIRTUAL)) + if (!virtuals_only && (E->get().flags & METHOD_FLAG_VIRTUAL)) { continue; + } - if (search_box->get_text() != String() && name.find(search_box->get_text()) == -1) + if (search_box->get_text() != String() && name.find(search_box->get_text()) == -1) { continue; + } TreeItem *item = search_options->create_item(category ? category : root); @@ -258,35 +267,40 @@ void PropertySelector::_update_search() { if (mi.name.find(":") != -1) { desc = mi.name.get_slice(":", 1) + " "; mi.name = mi.name.get_slice(":", 0); - } else if (mi.return_val.type != Variant::NIL) + } else if (mi.return_val.type != Variant::NIL) { desc = Variant::get_type_name(mi.return_val.type); - else + } else { desc = "void "; + } desc += " " + mi.name + " ( "; for (int i = 0; i < mi.arguments.size(); i++) { - if (i > 0) + if (i > 0) { desc += ", "; + } - if (mi.arguments[i].type == Variant::NIL) + if (mi.arguments[i].type == Variant::NIL) { desc += "var "; - else if (mi.arguments[i].name.find(":") != -1) { + } else if (mi.arguments[i].name.find(":") != -1) { desc += mi.arguments[i].name.get_slice(":", 1) + " "; mi.arguments[i].name = mi.arguments[i].name.get_slice(":", 0); - } else + } else { desc += Variant::get_type_name(mi.arguments[i].type) + " "; + } desc += mi.arguments[i].name; } desc += " )"; - if (E->get().flags & METHOD_FLAG_CONST) + if (E->get().flags & METHOD_FLAG_CONST) { desc += " const"; + } - if (E->get().flags & METHOD_FLAG_VIRTUAL) + if (E->get().flags & METHOD_FLAG_VIRTUAL) { desc += " virtual"; + } item->set_text(0, desc); item->set_metadata(0, name); @@ -308,8 +322,9 @@ void PropertySelector::_update_search() { void PropertySelector::_confirmed() { TreeItem *ti = search_options->get_selected(); - if (!ti) + if (!ti) { return; + } emit_signal("selected", ti->get_metadata(0)); hide(); } @@ -318,8 +333,9 @@ void PropertySelector::_item_selected() { help_bit->set_text(""); TreeItem *item = search_options->get_selected(); - if (!item) + if (!item) { return; + } String name = item->get_metadata(0); String class_type; @@ -365,8 +381,9 @@ void PropertySelector::_item_selected() { } } - if (text == String()) + if (text == String()) { return; + } help_bit->set_text(text); } @@ -437,8 +454,9 @@ void PropertySelector::select_method_from_instance(Object *p_instance, const Str script = ObjectID(); { Ref<Script> scr = p_instance->get_script(); - if (scr.is_valid()) + if (scr.is_valid()) { script = scr->get_instance_id(); + } } properties = false; instance = nullptr; diff --git a/editor/pvrtc_compress.cpp b/editor/pvrtc_compress.cpp index 8532ed23be..23bcf9540e 100644 --- a/editor/pvrtc_compress.cpp +++ b/editor/pvrtc_compress.cpp @@ -47,14 +47,16 @@ static void _compress_image(Image::CompressMode p_mode, Image *p_image) { if (ttpath.strip_edges() == "" || !FileAccess::exists(ttpath)) { switch (p_mode) { case Image::COMPRESS_PVRTC2: - if (_base_image_compress_pvrtc2_func) + if (_base_image_compress_pvrtc2_func) { _base_image_compress_pvrtc2_func(p_image); - else if (_base_image_compress_pvrtc4_func) + } else if (_base_image_compress_pvrtc4_func) { _base_image_compress_pvrtc4_func(p_image); + } break; case Image::COMPRESS_PVRTC4: - if (_base_image_compress_pvrtc4_func) + if (_base_image_compress_pvrtc4_func) { _base_image_compress_pvrtc4_func(p_image); + } break; default: ERR_FAIL_MSG("Unsupported Image compress mode used in PVRTC module."); diff --git a/editor/quick_open.cpp b/editor/quick_open.cpp index e16b1f61fb..bcef29dfa6 100644 --- a/editor/quick_open.cpp +++ b/editor/quick_open.cpp @@ -35,14 +35,16 @@ void EditorQuickOpen::popup_dialog(const StringName &p_base, bool p_enable_multi, bool p_add_dirs, bool p_dontclear) { add_directories = p_add_dirs; popup_centered_ratio(0.6); - if (p_dontclear) + if (p_dontclear) { search_box->select_all(); - else + } else { search_box->clear(); - if (p_enable_multi) + } + if (p_enable_multi) { search_options->set_select_mode(Tree::SELECT_MULTI); - else + } else { search_options->set_select_mode(Tree::SELECT_SINGLE); + } search_box->grab_focus(); base_type = p_base; _update_search(); @@ -50,8 +52,9 @@ void EditorQuickOpen::popup_dialog(const StringName &p_base, bool p_enable_multi String EditorQuickOpen::get_selected() const { TreeItem *ti = search_options->get_selected(); - if (!ti) + if (!ti) { return String(); + } return "res://" + ti->get_text(0); } @@ -85,8 +88,9 @@ void EditorQuickOpen::_sbox_input(const Ref<InputEvent> &p_ie) { search_box->accept_event(); TreeItem *root = search_options->get_root(); - if (!root->get_children()) + if (!root->get_children()) { break; + } TreeItem *current = search_options->get_selected(); @@ -130,8 +134,9 @@ void EditorQuickOpen::_parse_fs(EditorFileSystemDirectory *efsd, Vector<Pair<Str if (add_directories) { String path = efsd->get_path(); - if (!path.ends_with("/")) + if (!path.ends_with("/")) { path += "/"; + } if (path != "res://") { path = path.substr(6, path.length()); if (search_text.is_subsequence_ofi(path)) { @@ -180,13 +185,15 @@ Vector<Pair<String, Ref<Texture2D>>> EditorQuickOpen::_sort_fs(Vector<Pair<Strin String search_text = search_box->get_text(); Vector<Pair<String, Ref<Texture2D>>> sorted_list; - if (search_text == String() || list.size() == 0) + if (search_text == String() || list.size() == 0) { return list; + } Vector<float> scores; scores.resize(list.size()); - for (int i = 0; i < list.size(); i++) + for (int i = 0; i < list.size(); i++) { scores.write[i] = _path_cmp(search_text, list[i].first); + } while (list.size() > 0) { float best_score = 0.0f; @@ -235,8 +242,9 @@ void EditorQuickOpen::_update_search() { void EditorQuickOpen::_confirmed() { TreeItem *ti = search_options->get_selected(); - if (!ti) + if (!ti) { return; + } emit_signal("quick_open"); hide(); } diff --git a/editor/rename_dialog.cpp b/editor/rename_dialog.cpp index fa44efda29..6a54894f40 100644 --- a/editor/rename_dialog.cpp +++ b/editor/rename_dialog.cpp @@ -381,8 +381,9 @@ void RenameDialog::_update_preview_int(int new_value) { } void RenameDialog::_update_preview(String new_text) { - if (lock_preview_update || preview_node == nullptr) + if (lock_preview_update || preview_node == nullptr) { return; + } has_errors = false; add_error_handler(&eh); @@ -469,8 +470,9 @@ void RenameDialog::_error_handler(void *p_self, const char *p_func, const char * String source_file(p_file); // Only show first error that is related to "regex" - if (self->has_errors || source_file.find("regex") < 0) + if (self->has_errors || source_file.find("regex") < 0) { return; + } String err_str; if (p_errorexp && p_errorexp[0]) { @@ -538,8 +540,9 @@ String RenameDialog::_postprocess(const String &subject) { } void RenameDialog::_iterate_scene(const Node *node, const Array &selection, int *counter) { - if (!node) + if (!node) { return; + } if (selection.has(node)) { String new_name = _apply_rename(node, *counter); diff --git a/editor/run_settings_dialog.cpp b/editor/run_settings_dialog.cpp index e8c3c2065c..b6dda4c5bb 100644 --- a/editor/run_settings_dialog.cpp +++ b/editor/run_settings_dialog.cpp @@ -47,10 +47,11 @@ void RunSettingsDialog::_bind_methods() { } void RunSettingsDialog::_run_mode_changed(int idx) { - if (idx == 0) + if (idx == 0) { arguments->set_editable(false); - else + } else { arguments->set_editable(true); + } } int RunSettingsDialog::get_run_mode() const { diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index c385405a01..e73c52047b 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -72,11 +72,13 @@ void SceneTreeDock::_input(Ref<InputEvent> p_event) { } void SceneTreeDock::_unhandled_key_input(Ref<InputEvent> p_event) { - if (get_focus_owner() && get_focus_owner()->is_text_field()) + if (get_focus_owner() && get_focus_owner()->is_text_field()) { return; + } - if (!p_event->is_pressed() || p_event->is_echo()) + if (!p_event->is_pressed() || p_event->is_echo()) { return; + } if (ED_IS_SHORTCUT("scene_tree/batch_rename", p_event)) { _tool_selected(TOOL_BATCH_RENAME); @@ -304,13 +306,16 @@ bool SceneTreeDock::_track_inherit(const String &p_target_scene_path, Node *p_de Ref<PackedScene> data = ResourceLoader::load(path); if (data.is_valid()) { p = data->instance(PackedScene::GEN_EDIT_STATE_INSTANCE); - if (!p) + if (!p) { continue; + } instances.push_back(p); - } else + } else { break; - } else + } + } else { break; + } } for (int i = 0; i < instances.size(); i++) { memdelete(instances[i]); @@ -349,10 +354,11 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { Node *current_edited_scene_root = EditorNode::get_singleton()->get_edited_scene(); if (current_edited_scene_root) { - if (ClassDB::is_parent_class(current_edited_scene_root->get_class_name(), "Node2D")) + if (ClassDB::is_parent_class(current_edited_scene_root->get_class_name(), "Node2D")) { preferred = "Node2D"; - else if (ClassDB::is_parent_class(current_edited_scene_root->get_class_name(), "Node3D")) + } else if (ClassDB::is_parent_class(current_edited_scene_root->get_class_name(), "Node3D")) { preferred = "Node3D"; + } } create_dialog->set_preferred_search_result_type(preferred); create_dialog->popup_create(true); @@ -373,14 +379,16 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } break; case TOOL_EXPAND_COLLAPSE: { - if (!scene_tree->get_selected()) + if (!scene_tree->get_selected()) { break; + } Tree *tree = scene_tree->get_scene_tree(); TreeItem *selected_item = tree->get_selected(); - if (!selected_item) + if (!selected_item) { selected_item = tree->get_root(); + } bool collapsed = _is_collapsed_recursive(selected_item); _set_collapsed_recursive(selected_item, !collapsed); @@ -394,11 +402,13 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } Node *selected = scene_tree->get_selected(); - if (!selected && !editor_selection->get_selected_node_list().empty()) + if (!selected && !editor_selection->get_selected_node_list().empty()) { selected = editor_selection->get_selected_node_list().front()->get(); + } - if (selected) + if (selected) { create_dialog->popup_create(false, true, selected->get_class()); + } } break; case TOOL_EXTEND_SCRIPT: { @@ -414,8 +424,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { Array selection = editor_selection->get_selected_nodes(); - if (selection.empty()) + if (selection.empty()) { return; + } editor_data->get_undo_redo().create_action(TTR("Detach Script")); editor_data->get_undo_redo().add_do_method(editor, "push_item", (Script *)nullptr); @@ -441,8 +452,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { break; } - if (!scene_tree->get_selected()) + if (!scene_tree->get_selected()) { break; + } if (scene_tree->get_selected() == edited_scene) { current_option = -1; @@ -451,8 +463,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { break; } - if (!_validate_no_foreign()) + if (!_validate_no_foreign()) { break; + } bool MOVING_DOWN = (p_tool == TOOL_MOVE_DOWN); bool MOVING_UP = !MOVING_DOWN; @@ -460,30 +473,37 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { Node *common_parent = scene_tree->get_selected()->get_parent(); List<Node *> selection = editor_selection->get_selected_node_list(); selection.sort_custom<Node::Comparator>(); // sort by index - if (MOVING_DOWN) + if (MOVING_DOWN) { selection.invert(); + } int lowest_id = common_parent->get_child_count() - 1; int highest_id = 0; for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { int index = E->get()->get_index(); - if (index > highest_id) + if (index > highest_id) { highest_id = index; - if (index < lowest_id) + } + if (index < lowest_id) { lowest_id = index; + } - if (E->get()->get_parent() != common_parent) + if (E->get()->get_parent() != common_parent) { common_parent = nullptr; + } } - if (!common_parent || (MOVING_DOWN && highest_id >= common_parent->get_child_count() - MOVING_DOWN) || (MOVING_UP && lowest_id == 0)) + if (!common_parent || (MOVING_DOWN && highest_id >= common_parent->get_child_count() - MOVING_DOWN) || (MOVING_UP && lowest_id == 0)) { break; // one or more nodes can not be moved + } - if (selection.size() == 1) + if (selection.size() == 1) { editor_data->get_undo_redo().create_action(TTR("Move Node In Parent")); - if (selection.size() > 1) + } + if (selection.size() > 1) { editor_data->get_undo_redo().create_action(TTR("Move Nodes In Parent")); + } for (int i = 0; i < selection.size(); i++) { Node *top_node = selection[i]; @@ -507,8 +527,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { break; } - if (!edited_scene) + if (!edited_scene) { break; + } if (editor_selection->is_selected(edited_scene)) { current_option = -1; @@ -517,12 +538,14 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { break; } - if (!_validate_no_foreign()) + if (!_validate_no_foreign()) { break; + } List<Node *> selection = editor_selection->get_selected_node_list(); - if (selection.size() == 0) + if (selection.size() == 0) { break; + } editor_data->get_undo_redo().create_action(TTR("Duplicate Node(s)")); editor_data->get_undo_redo().add_do_method(editor_selection, "clear"); @@ -544,13 +567,15 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { Map<const Node *, Node *> duplimap; Node *dup = node->duplicate_from_editor(duplimap); - if (EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(node)) + if (EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(node)) { editable_children.push_back(dup); + } ERR_CONTINUE(!dup); - if (selection.size() == 1) + if (selection.size() == 1) { dupsingle = dup; + } dup->set_name(parent->validate_child_name(dup)); @@ -576,11 +601,13 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { editor_data->get_undo_redo().commit_action(); - if (dupsingle) + if (dupsingle) { editor->push_item(dupsingle); + } - for (List<Node *>::Element *E = editable_children.back(); E; E = E->prev()) + for (List<Node *>::Element *E = editable_children.back(); E; E = E->prev()) { _toggle_editable_children(E->get()); + } } break; case TOOL_REPARENT: { @@ -588,8 +615,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { break; } - if (!scene_tree->get_selected()) + if (!scene_tree->get_selected()) { break; + } if (editor_selection->is_selected(edited_scene)) { current_option = -1; @@ -598,8 +626,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { break; } - if (!_validate_no_foreign()) + if (!_validate_no_foreign()) { break; + } List<Node *> nodes = editor_selection->get_selected_node_list(); Set<Node *> nodeset; @@ -621,8 +650,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { Node *node = nodes.front()->get(); Node *root = get_tree()->get_edited_scene_root(); - if (node == root) + if (node == root) { return; + } //check that from node to root, all owners are right @@ -674,8 +704,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } Node *root = EditorNode::get_singleton()->get_edited_scene(); - if (!root) + if (!root) { break; + } Ref<MultiNodeEdit> mne = memnew(MultiNodeEdit); for (const Map<Node *, Object *>::Element *E = EditorNode::get_singleton()->get_editor_selection()->get_selection().front(); E; E = E->next()) { mne->add_node(root->get_path_to(E->key())); @@ -692,11 +723,13 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { List<Node *> remove_list = editor_selection->get_selected_node_list(); - if (remove_list.empty()) + if (remove_list.empty()) { return; + } - if (!_validate_no_foreign()) + if (!_validate_no_foreign()) { break; + } if (p_confirm_override) { _delete_confirm(); @@ -845,8 +878,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { placeholder = !placeholder; - if (placeholder) + if (placeholder) { EditorNode::get_singleton()->get_edited_scene()->set_editable_instance(node, false); + } node->set_scene_instance_load_placeholder(placeholder); scene_tree->update_tree(); @@ -865,8 +899,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { if (node) { Node *root = EditorNode::get_singleton()->get_edited_scene(); UndoRedo *undo_redo = &editor_data->get_undo_redo(); - if (!root) + if (!root) { break; + } ERR_FAIL_COND(node->get_filename() == String()); undo_redo->create_action(TTR("Make Local")); @@ -992,8 +1027,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { void SceneTreeDock::_node_collapsed(Object *p_obj) { TreeItem *ti = Object::cast_to<TreeItem>(p_obj); - if (!ti) + if (!ti) { return; + } if (Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { _set_collapsed_recursive(ti, ti->is_collapsed()); @@ -1003,8 +1039,9 @@ void SceneTreeDock::_node_collapsed(Object *p_obj) { void SceneTreeDock::_notification(int p_what) { switch (p_what) { case NOTIFICATION_READY: { - if (!first_enter) + if (!first_enter) { break; + } first_enter = false; EditorFeatureProfileManager::get_singleton()->connect("current_feature_profile_changed", callable_mp(this, &SceneTreeDock::_feature_profile_changed)); @@ -1177,21 +1214,24 @@ void SceneTreeDock::_node_renamed() { void SceneTreeDock::_set_owners(Node *p_owner, const Array &p_nodes) { for (int i = 0; i < p_nodes.size(); i++) { Node *n = Object::cast_to<Node>(p_nodes[i]); - if (!n) + if (!n) { continue; + } n->set_owner(p_owner); } } void SceneTreeDock::_fill_path_renames(Vector<StringName> base_path, Vector<StringName> new_base_path, Node *p_node, List<Pair<NodePath, NodePath>> *p_renames) { base_path.push_back(p_node->get_name()); - if (new_base_path.size()) + if (new_base_path.size()) { new_base_path.push_back(p_node->get_name()); + } NodePath from(base_path, true); NodePath to; - if (new_base_path.size()) + if (new_base_path.size()) { to = NodePath(new_base_path, true); + } Pair<NodePath, NodePath> npp; npp.first = from; @@ -1205,8 +1245,9 @@ void SceneTreeDock::_fill_path_renames(Vector<StringName> base_path, Vector<Stri } void SceneTreeDock::fill_path_renames(Node *p_node, Node *p_new_parent, List<Pair<NodePath, NodePath>> *p_renames) { - if (!bool(EDITOR_DEF("editors/animation/autorename_animation_tracks", true))) + if (!bool(EDITOR_DEF("editors/animation/autorename_animation_tracks", true))) { return; + } Vector<StringName> base_path; Node *n = p_node->get_parent(); @@ -1233,15 +1274,17 @@ void SceneTreeDock::fill_path_renames(Node *p_node, Node *p_new_parent, List<Pai void SceneTreeDock::perform_node_renames(Node *p_base, List<Pair<NodePath, NodePath>> *p_renames, Map<Ref<Animation>, Set<int>> *r_rem_anims) { Map<Ref<Animation>, Set<int>> rem_anims; - if (!r_rem_anims) + if (!r_rem_anims) { r_rem_anims = &rem_anims; + } if (!p_base) { p_base = edited_scene; } - if (!p_base) + if (!p_base) { return; + } // Renaming node paths used in script instances if (p_base->get_script_instance()) { @@ -1309,14 +1352,16 @@ void SceneTreeDock::perform_node_renames(Node *p_base, List<Pair<NodePath, NodeP if (!r_rem_anims->has(anim)) { r_rem_anims->insert(anim, Set<int>()); Set<int> &ran = r_rem_anims->find(anim)->get(); - for (int i = 0; i < anim->get_track_count(); i++) + for (int i = 0; i < anim->get_track_count(); i++) { ran.insert(i); + } } Set<int> &ran = r_rem_anims->find(anim)->get(); - if (anim.is_null()) + if (anim.is_null()) { continue; + } for (int i = 0; i < anim->get_track_count(); i++) { NodePath track_np = anim->track_get_path(i); @@ -1327,8 +1372,9 @@ void SceneTreeDock::perform_node_renames(Node *p_base, List<Pair<NodePath, NodeP NodePath old_np = n->get_path(); - if (!ran.has(i)) + if (!ran.has(i)) { continue; //channel was removed + } for (List<Pair<NodePath, NodePath>>::Element *F = p_renames->front(); F; F = F->next()) { if (F->get().first == old_np) { @@ -1359,8 +1405,9 @@ void SceneTreeDock::perform_node_renames(Node *p_base, List<Pair<NodePath, NodeP NodePath rel_path = new_root_path.rel_path_to(F->get().second); NodePath new_path = NodePath(rel_path.get_names(), track_np.get_subnames(), false); - if (new_path == track_np) + if (new_path == track_np) { continue; //bleh + } editor_data->get_undo_redo().add_do_method(anim.ptr(), "track_set_path", i, new_path); editor_data->get_undo_redo().add_undo_method(anim.ptr(), "track_set_path", i, track_np); } @@ -1372,8 +1419,9 @@ void SceneTreeDock::perform_node_renames(Node *p_base, List<Pair<NodePath, NodeP } } - for (int i = 0; i < p_base->get_child_count(); i++) + for (int i = 0; i < p_base->get_child_count(); i++) { perform_node_renames(p_base->get_child(i), p_renames, r_rem_anims); + } } void SceneTreeDock::_node_prerenamed(Node *p_node, const String &p_new_name) { @@ -1397,8 +1445,9 @@ void SceneTreeDock::_node_prerenamed(Node *p_node, const String &p_new_name) { npp.second = NodePath(new_base_path, true); path_renames.push_back(npp); - for (int i = 0; i < p_node->get_child_count(); i++) + for (int i = 0; i < p_node->get_child_count(); i++) { _fill_path_renames(base_path, new_base_path, p_node->get_child(i), &path_renames); + } perform_node_renames(nullptr, &path_renames); } @@ -1436,8 +1485,9 @@ void SceneTreeDock::_node_reparent(NodePath p_path, bool p_keep_global_xform) { List<Node *> selection = editor_selection->get_selected_node_list(); - if (selection.empty()) + if (selection.empty()) { return; // Nothing to reparent. + } Vector<Node *> nodes; @@ -1452,22 +1502,26 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V Node *new_parent = p_new_parent; ERR_FAIL_COND(!new_parent); - if (p_nodes.size() == 0) + if (p_nodes.size() == 0) { return; // Nothing to reparent. + } p_nodes.sort_custom<Node::Comparator>(); //Makes result reliable. bool no_change = true; for (int ni = 0; ni < p_nodes.size(); ni++) { - if (p_nodes[ni] == p_new_parent) + if (p_nodes[ni] == p_new_parent) { return; // Attempt to reparent to itself. + } - if (p_nodes[ni]->get_parent() != p_new_parent || p_position_in_parent + ni != p_nodes[ni]->get_index()) + if (p_nodes[ni]->get_parent() != p_new_parent || p_position_in_parent + ni != p_nodes[ni]->get_index()) { no_change = false; + } } - if (no_change) + if (no_change) { return; // Position and parent didn't change. + } Node *validate = new_parent; while (validate) { @@ -1499,14 +1553,16 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V owners.push_back(E->get()); } - if (new_parent == node->get_parent() && node->get_index() < p_position_in_parent + ni) + if (new_parent == node->get_parent() && node->get_index() < p_position_in_parent + ni) { inc--; // If the child will generate a gap when moved, adjust. + } editor_data->get_undo_redo().add_do_method(node->get_parent(), "remove_child", node); editor_data->get_undo_redo().add_do_method(new_parent, "add_child", node); - if (p_position_in_parent >= 0) + if (p_position_in_parent >= 0) { editor_data->get_undo_redo().add_do_method(new_parent, "move_child", node, p_position_in_parent + inc); + } EditorDebuggerNode *ed = EditorDebuggerNode::get_singleton(); String old_name = former_names[ni]; @@ -1536,18 +1592,22 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V editor_data->get_undo_redo().add_undo_method(ed, "live_debug_reparent_node", NodePath(String(edited_scene->get_path_to(new_parent)).plus_file(new_name)), edited_scene->get_path_to(node->get_parent()), node->get_name(), node->get_index()); if (p_keep_global_xform) { - if (Object::cast_to<Node2D>(node)) + if (Object::cast_to<Node2D>(node)) { editor_data->get_undo_redo().add_do_method(node, "set_global_transform", Object::cast_to<Node2D>(node)->get_global_transform()); - if (Object::cast_to<Node3D>(node)) + } + if (Object::cast_to<Node3D>(node)) { editor_data->get_undo_redo().add_do_method(node, "set_global_transform", Object::cast_to<Node3D>(node)->get_global_transform()); - if (Object::cast_to<Control>(node)) + } + if (Object::cast_to<Control>(node)) { editor_data->get_undo_redo().add_do_method(node, "set_global_position", Object::cast_to<Control>(node)->get_global_position()); + } } editor_data->get_undo_redo().add_do_method(this, "_set_owners", edited_scene, owners); - if (AnimationPlayerEditor::singleton->get_track_editor()->get_root() == node) + if (AnimationPlayerEditor::singleton->get_track_editor()->get_root() == node) { editor_data->get_undo_redo().add_do_method(AnimationPlayerEditor::singleton->get_track_editor(), "set_root", node); + } editor_data->get_undo_redo().add_undo_method(new_parent, "remove_child", node); editor_data->get_undo_redo().add_undo_method(node, "set_name", former_names[ni]); @@ -1571,16 +1631,20 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V editor_data->get_undo_redo().add_undo_method(node->get_parent(), "add_child", node); editor_data->get_undo_redo().add_undo_method(node->get_parent(), "move_child", node, child_pos); editor_data->get_undo_redo().add_undo_method(this, "_set_owners", edited_scene, owners); - if (AnimationPlayerEditor::singleton->get_track_editor()->get_root() == node) + if (AnimationPlayerEditor::singleton->get_track_editor()->get_root() == node) { editor_data->get_undo_redo().add_undo_method(AnimationPlayerEditor::singleton->get_track_editor(), "set_root", node); + } if (p_keep_global_xform) { - if (Object::cast_to<Node2D>(node)) + if (Object::cast_to<Node2D>(node)) { editor_data->get_undo_redo().add_undo_method(node, "set_transform", Object::cast_to<Node2D>(node)->get_transform()); - if (Object::cast_to<Node3D>(node)) + } + if (Object::cast_to<Node3D>(node)) { editor_data->get_undo_redo().add_undo_method(node, "set_transform", Object::cast_to<Node3D>(node)->get_transform()); - if (Object::cast_to<Control>(node)) + } + if (Object::cast_to<Control>(node)) { editor_data->get_undo_redo().add_undo_method(node, "set_position", Object::cast_to<Control>(node)->get_position()); + } } } @@ -1634,8 +1698,9 @@ void SceneTreeDock::_set_collapsed_recursive(TreeItem *p_item, bool p_collapsed) void SceneTreeDock::_script_created(Ref<Script> p_script) { List<Node *> selected = editor_selection->get_selected_node_list(); - if (selected.empty()) + if (selected.empty()) { return; + } editor_data->get_undo_redo().create_action(TTR("Attach Script")); for (List<Node *>::Element *E = selected.front(); E; E = E->next()) { @@ -1687,8 +1752,9 @@ void SceneTreeDock::_toggle_editable_children(Node *p_node) { if (p_node) { bool editable = !EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(p_node); EditorNode::get_singleton()->get_edited_scene()->set_editable_instance(p_node, editable); - if (editable) + if (editable) { p_node->set_scene_instance_load_placeholder(false); + } Node3DEditor::get_singleton()->update_all_gizmos(p_node); @@ -1699,8 +1765,9 @@ void SceneTreeDock::_toggle_editable_children(Node *p_node) { void SceneTreeDock::_delete_confirm() { List<Node *> remove_list = editor_selection->get_selected_node_list(); - if (remove_list.empty()) + if (remove_list.empty()) { return; + } editor->get_editor_plugins_over()->make_visible(false); @@ -1728,8 +1795,9 @@ void SceneTreeDock::_delete_confirm() { //delete from animation for (List<Node *>::Element *E = remove_list.front(); E; E = E->next()) { Node *n = E->get(); - if (!n->is_inside_tree() || !n->get_parent()) + if (!n->is_inside_tree() || !n->get_parent()) { continue; + } fill_path_renames(n, nullptr, &path_renames); } @@ -1738,8 +1806,9 @@ void SceneTreeDock::_delete_confirm() { //delete for read for (List<Node *>::Element *E = remove_list.front(); E; E = E->next()) { Node *n = E->get(); - if (!n->is_inside_tree() || !n->get_parent()) + if (!n->is_inside_tree() || !n->get_parent()) { continue; + } List<Node *> owned; n->get_owned_by(n->get_owner(), &owned); @@ -1751,8 +1820,9 @@ void SceneTreeDock::_delete_confirm() { editor_data->get_undo_redo().add_do_method(n->get_parent(), "remove_child", n); editor_data->get_undo_redo().add_undo_method(n->get_parent(), "add_child", n); editor_data->get_undo_redo().add_undo_method(n->get_parent(), "move_child", n, n->get_index()); - if (AnimationPlayerEditor::singleton->get_track_editor()->get_root() == n) + if (AnimationPlayerEditor::singleton->get_track_editor()->get_root() == n) { editor_data->get_undo_redo().add_undo_method(AnimationPlayerEditor::singleton->get_track_editor(), "set_root", n); + } editor_data->get_undo_redo().add_undo_method(this, "_set_owners", edited_scene, owners); editor_data->get_undo_redo().add_undo_reference(n); @@ -1764,8 +1834,9 @@ void SceneTreeDock::_delete_confirm() { editor_data->get_undo_redo().commit_action(); // hack, force 2d editor viewport to refresh after deletion - if (CanvasItemEditor *editor = CanvasItemEditor::get_singleton()) + if (CanvasItemEditor *editor = CanvasItemEditor::get_singleton()) { editor->get_viewport_control()->update(); + } editor->push_item(nullptr); @@ -1825,10 +1896,11 @@ Node *SceneTreeDock::_get_selection_group_tail(Node *p_node, List<Node *> p_list for (int i = p_node->get_index(); i < parent->get_child_count(); i++) { Node *sibling = parent->get_child(i); - if (p_list.find(sibling)) + if (p_list.find(sibling)) { tail = sibling; - else + } else { break; + } } return tail; @@ -1872,10 +1944,12 @@ void SceneTreeDock::_do_create(Node *p_parent) { Control *ct = Object::cast_to<Control>(c); Size2 ms = ct->get_minimum_size(); - if (ms.width < 4) + if (ms.width < 4) { ms.width = 40; - if (ms.height < 4) + } + if (ms.height < 4) { ms.height = 40; + } ct->set_size(ms); } } @@ -1887,8 +1961,9 @@ void SceneTreeDock::_create() { if (edited_scene) { // If root exists in edited scene parent = scene_tree->get_selected(); - if (!parent) + if (!parent) { parent = edited_scene; + } } else { // If no root exist in edited scene @@ -1946,17 +2021,19 @@ void SceneTreeDock::_create() { smaller_path_to_top = path_length; only_one_top_node = true; } else if (smaller_path_to_top == path_length) { - if (only_one_top_node && top_node->get_parent() != n->get_parent()) + if (only_one_top_node && top_node->get_parent() != n->get_parent()) { only_one_top_node = false; + } } } } Node *parent = nullptr; - if (only_one_top_node) + if (only_one_top_node) { parent = top_node->get_parent(); - else + } else { parent = top_node->get_parent()->get_parent(); + } _do_create(parent); @@ -1983,10 +2060,12 @@ void SceneTreeDock::replace_node(Node *p_node, Node *p_by_node, bool p_keep_prop n->get_property_list(&pinfo); for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { continue; - if (E->get().name == "__meta__") + } + if (E->get().name == "__meta__") { continue; + } if (default_oldnode->get(E->get().name) != n->get(E->get().name)) { newnode->set(E->get().name, n->get(E->get().name)); } @@ -2007,8 +2086,9 @@ void SceneTreeDock::replace_node(Node *p_node, Node *p_by_node, bool p_keep_prop for (List<Object::Connection>::Element *F = cl.front(); F; F = F->next()) { Object::Connection &c = F->get(); - if (!(c.flags & Object::CONNECT_PERSIST)) + if (!(c.flags & Object::CONNECT_PERSIST)) { continue; + } newnode->connect(c.signal.get_name(), c.callable, c.binds, Object::CONNECT_PERSIST); } } @@ -2035,8 +2115,9 @@ void SceneTreeDock::replace_node(Node *p_node, Node *p_by_node, bool p_keep_prop c->call("set_transform", c->call("get_transform")); } //p_remove_old was added to support undo - if (p_remove_old) + if (p_remove_old) { editor_data->get_undo_redo().clear_history(); + } newnode->set_name(newname); editor->push_item(newnode); @@ -2106,8 +2187,9 @@ void SceneTreeDock::_new_scene_from(String p_file) { } 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; + } err = ResourceSaver::save(p_file, sdata, flg); if (err != OK) { @@ -2124,23 +2206,27 @@ void SceneTreeDock::_new_scene_from(String p_file) { } static bool _is_node_visible(Node *p_node) { - if (!p_node->get_owner()) + if (!p_node->get_owner()) { return false; - if (p_node->get_owner() != EditorNode::get_singleton()->get_edited_scene() && !EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(p_node->get_owner())) + } + if (p_node->get_owner() != EditorNode::get_singleton()->get_edited_scene() && !EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(p_node->get_owner())) { return false; + } return true; } static bool _has_visible_children(Node *p_node) { bool collapsed = p_node->is_displayed_folded(); - if (collapsed) + if (collapsed) { return false; + } for (int i = 0; i < p_node->get_child_count(); i++) { Node *child = p_node->get_child(i); - if (!_is_node_visible(child)) + if (!_is_node_visible(child)) { continue; + } return true; } @@ -2216,12 +2302,14 @@ void SceneTreeDock::_script_dropped(String p_file, NodePath p_to) { void SceneTreeDock::_nodes_dragged(Array p_nodes, NodePath p_to, int p_type) { List<Node *> selection = editor_selection->get_selected_node_list(); - if (selection.empty()) + if (selection.empty()) { return; //nothing to reparent + } Node *to_node = get_node(p_to); - if (!to_node) + if (!to_node) { return; + } Vector<Node *> nodes; for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { @@ -2235,23 +2323,28 @@ void SceneTreeDock::_nodes_dragged(Array p_nodes, NodePath p_to, int p_type) { } void SceneTreeDock::_add_children_to_popup(Object *p_obj, int p_depth) { - if (p_depth > 8) + if (p_depth > 8) { return; + } List<PropertyInfo> pinfo; p_obj->get_property_list(&pinfo); for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_EDITOR)) + if (!(E->get().usage & PROPERTY_USAGE_EDITOR)) { continue; - if (E->get().hint != PROPERTY_HINT_RESOURCE_TYPE) + } + if (E->get().hint != PROPERTY_HINT_RESOURCE_TYPE) { continue; + } Variant value = p_obj->get(E->get().name); - if (value.get_type() != Variant::OBJECT) + if (value.get_type() != Variant::OBJECT) { continue; + } Object *obj = value; - if (!obj) + if (!obj) { continue; + } Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(obj); @@ -2284,8 +2377,9 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { List<Node *> selection = editor_selection->get_selected_node_list(); List<Node *> full_selection = editor_selection->get_full_selected_node_list(); // Above method only returns nodes with common parent. - if (selection.size() == 0) + if (selection.size() == 0) { return; + } menu->clear(); @@ -2299,8 +2393,9 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { menu_subresources->clear(); menu_subresources->set_size(Size2(1, 1)); _add_children_to_popup(selection.front()->get(), 0); - if (menu->get_item_count() > 0) + if (menu->get_item_count() > 0) { menu->add_separator(); + } menu->add_icon_shortcut(get_theme_icon("Add", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/add_child_node"), TOOL_NEW); menu->add_icon_shortcut(get_theme_icon("Instance", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/instance_scene"), TOOL_INSTANCE); @@ -2454,12 +2549,14 @@ void SceneTreeDock::attach_script_to_selected(bool p_extend) { } List<Node *> selection = editor_selection->get_selected_node_list(); - if (selection.empty()) + if (selection.empty()) { return; + } Node *selected = scene_tree->get_selected(); - if (!selected) + if (!selected) { selected = selection.front()->get(); + } Ref<Script> existing = selected->get_script(); @@ -2533,8 +2630,9 @@ void SceneTreeDock::hide_tab_buttons() { void SceneTreeDock::_remote_tree_selected() { scene_tree->hide(); create_root_dialog->hide(); - if (remote_tree) + if (remote_tree) { remote_tree->show(); + } edit_remote->set_pressed(true); edit_local->set_pressed(false); @@ -2543,8 +2641,9 @@ void SceneTreeDock::_remote_tree_selected() { void SceneTreeDock::_local_tree_selected() { scene_tree->show(); - if (remote_tree) + if (remote_tree) { remote_tree->hide(); + } edit_remote->set_pressed(false); edit_local->set_pressed(true); } @@ -2553,14 +2652,16 @@ void SceneTreeDock::_update_create_root_dialog() { BaseButton *toggle = Object::cast_to<BaseButton>(create_root_dialog->get_node(String("NodeShortcutsTopRow/NodeShortcutsToggle"))); Node *node_shortcuts = create_root_dialog->get_node(String("NodeShortcuts")); - if (!toggle || !node_shortcuts) + if (!toggle || !node_shortcuts) { return; + } Control *beginner_nodes = Object::cast_to<Control>(node_shortcuts->get_node(String("BeginnerNodeShortcuts"))); Control *favorite_nodes = Object::cast_to<Control>(node_shortcuts->get_node(String("FavoriteNodeShortcuts"))); - if (!beginner_nodes || !favorite_nodes) + if (!beginner_nodes || !favorite_nodes) { return; + } EditorSettings::get_singleton()->set_setting("_use_favorites_root_selection", toggle->is_pressed()); EditorSettings::get_singleton()->save(); @@ -2580,8 +2681,9 @@ void SceneTreeDock::_update_create_root_dialog() { favorite_nodes->add_child(button); button->set_text(TTR(l)); String name = l.get_slicec(' ', 0); - if (ScriptServer::is_global_class(name)) + if (ScriptServer::is_global_class(name)) { name = ScriptServer::get_global_class_native_base(name); + } button->set_icon(EditorNode::get_singleton()->get_class_icon(name)); button->connect("pressed", callable_mp(this, &SceneTreeDock::_favorite_root_selected), make_binds(l)); } diff --git a/editor/scene_tree_editor.cpp b/editor/scene_tree_editor.cpp index 757dff2552..1b818036e1 100644 --- a/editor/scene_tree_editor.cpp +++ b/editor/scene_tree_editor.cpp @@ -69,8 +69,9 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_i } } else if (p_id == BUTTON_SCRIPT) { Ref<Script> script_typed = n->get_script(); - if (!script_typed.is_null()) + if (!script_typed.is_null()) { emit_signal("open_script", script_typed); + } } else if (p_id == BUTTON_VISIBILITY) { undo_redo->create_action(TTR("Toggle Visible")); @@ -119,8 +120,9 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_i undo_redo->commit_action(); } else if (p_id == BUTTON_WARNING) { String config_err = n->get_configuration_warning(); - if (config_err == String()) + if (config_err == String()) { return; + } config_err = config_err.word_wrap(80); warning->set_text(config_err); warning->popup_centered(); @@ -154,8 +156,9 @@ void SceneTreeEditor::_toggle_visible(Node *p_node) { } bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { - if (!p_node) + if (!p_node) { return false; + } // only owned nodes are editable, since nodes can create their own (manually owned) child nodes, // which the editor needs not to know about. @@ -176,14 +179,16 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { TreeItem *item = tree->create_item(p_parent); item->set_text(0, p_node->get_name()); - if (can_rename && !part_of_subscene) + if (can_rename && !part_of_subscene) { item->set_editable(0, true); + } item->set_selectable(0, true); if (can_rename) { bool collapsed = p_node->is_displayed_folded(); - if (collapsed) + if (collapsed) { item->set_collapsed(true); + } } Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(p_node, "Node"); @@ -310,8 +315,9 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { if (can_open_instance && undo_redo) { //Show buttons only when necessary(SceneTreeDock) to avoid crashes - if (!p_node->is_connected("script_changed", callable_mp(this, &SceneTreeEditor::_node_script_changed))) + if (!p_node->is_connected("script_changed", callable_mp(this, &SceneTreeEditor::_node_script_changed))) { p_node->connect("script_changed", callable_mp(this, &SceneTreeEditor::_node_script_changed), varray(p_node)); + } Ref<Script> script = p_node->get_script(); if (!script.is_null()) { @@ -323,40 +329,48 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { if (p_node->is_class("CanvasItem")) { bool is_locked = p_node->has_meta("_edit_lock_"); //_edit_group_ - if (is_locked) + if (is_locked) { item->add_button(0, get_theme_icon("Lock", "EditorIcons"), BUTTON_LOCK, false, TTR("Node is locked.\nClick to unlock it.")); + } bool is_grouped = p_node->has_meta("_edit_group_"); - if (is_grouped) + if (is_grouped) { item->add_button(0, get_theme_icon("Group", "EditorIcons"), BUTTON_GROUP, false, TTR("Children are not selectable.\nClick to make selectable.")); + } bool v = p_node->call("is_visible"); - if (v) + if (v) { item->add_button(0, get_theme_icon("GuiVisibilityVisible", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility")); - else + } else { item->add_button(0, get_theme_icon("GuiVisibilityHidden", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility")); + } - if (!p_node->is_connected("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed))) + if (!p_node->is_connected("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed))) { p_node->connect("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed), varray(p_node)); + } _update_visibility_color(p_node, item); } else if (p_node->is_class("Node3D")) { bool is_locked = p_node->has_meta("_edit_lock_"); - if (is_locked) + if (is_locked) { item->add_button(0, get_theme_icon("Lock", "EditorIcons"), BUTTON_LOCK, false, TTR("Node is locked.\nClick to unlock it.")); + } bool is_grouped = p_node->has_meta("_edit_group_"); - if (is_grouped) + if (is_grouped) { item->add_button(0, get_theme_icon("Group", "EditorIcons"), BUTTON_GROUP, false, TTR("Children are not selectable.\nClick to make selectable.")); + } bool v = p_node->call("is_visible"); - if (v) + if (v) { item->add_button(0, get_theme_icon("GuiVisibilityVisible", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility")); - else + } else { item->add_button(0, get_theme_icon("GuiVisibilityHidden", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility")); + } - if (!p_node->is_connected("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed))) + if (!p_node->is_connected("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed))) { p_node->connect("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed), varray(p_node)); + } _update_visibility_color(p_node, item); } else if (p_node->is_class("AnimationPlayer")) { @@ -375,8 +389,9 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { } if (selected == p_node) { - if (!editor_selection) + if (!editor_selection) { item->select(0); + } item->set_as_cursor(0); } @@ -441,10 +456,11 @@ void SceneTreeEditor::_node_visibility_changed(Node *p_node) { visible = p_node->call("is_visible"); } - if (visible) + if (visible) { item->set_button(0, idx, get_theme_icon("GuiVisibilityVisible", "EditorIcons")); - else + } else { item->set_button(0, idx, get_theme_icon("GuiVisibilityHidden", "EditorIcons")); + } _update_visibility_color(p_node, item); } @@ -462,23 +478,27 @@ void SceneTreeEditor::_update_visibility_color(Node *p_node, TreeItem *p_item) { } void SceneTreeEditor::_node_script_changed(Node *p_node) { - if (tree_dirty) + if (tree_dirty) { return; + } MessageQueue::get_singleton()->push_call(this, "_update_tree"); tree_dirty = true; } void SceneTreeEditor::_node_removed(Node *p_node) { - if (EditorNode::get_singleton()->is_exiting()) + if (EditorNode::get_singleton()->is_exiting()) { return; //speed up exit + } - if (p_node->is_connected("script_changed", callable_mp(this, &SceneTreeEditor::_node_script_changed))) + if (p_node->is_connected("script_changed", callable_mp(this, &SceneTreeEditor::_node_script_changed))) { p_node->disconnect("script_changed", callable_mp(this, &SceneTreeEditor::_node_script_changed)); + } if (p_node->is_class("Node3D") || p_node->is_class("CanvasItem")) { - if (p_node->is_connected("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed))) + if (p_node->is_connected("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed))) { p_node->disconnect("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed)); + } } if (p_node == selected) { @@ -516,8 +536,9 @@ void SceneTreeEditor::_update_tree() { void SceneTreeEditor::_compute_hash(Node *p_node, uint64_t &hash) { hash = hash_djb2_one_64(p_node->get_instance_id(), hash); - if (p_node->get_parent()) + if (p_node->get_parent()) { hash = hash_djb2_one_64(p_node->get_parent()->get_instance_id(), hash); //so a reparent still produces a different hash + } for (int i = 0; i < p_node->get_child_count(); i++) { _compute_hash(p_node->get_child(i), hash); @@ -527,30 +548,37 @@ void SceneTreeEditor::_compute_hash(Node *p_node, uint64_t &hash) { void SceneTreeEditor::_test_update_tree() { pending_test_update = false; - if (!is_inside_tree()) + if (!is_inside_tree()) { return; + } - if (tree_dirty) + if (tree_dirty) { return; // don't even bother + } uint64_t hash = hash_djb2_one_64(0); - if (get_scene_node()) + if (get_scene_node()) { _compute_hash(get_scene_node(), hash); + } //test hash - if (hash == last_hash) + if (hash == last_hash) { return; // did not change + } MessageQueue::get_singleton()->push_call(this, "_update_tree"); tree_dirty = true; } void SceneTreeEditor::_tree_changed() { - if (EditorNode::get_singleton()->is_exiting()) + if (EditorNode::get_singleton()->is_exiting()) { return; //speed up exit - if (pending_test_update) + } + if (pending_test_update) { return; - if (tree_dirty) + } + if (tree_dirty) { return; + } MessageQueue::get_singleton()->push_call(this, "_test_update_tree"); pending_test_update = true; @@ -563,8 +591,9 @@ void SceneTreeEditor::_selected_changed() { Node *n = get_node(np); - if (n == selected) + if (n == selected) { return; + } selected = get_node(np); @@ -589,11 +618,13 @@ void SceneTreeEditor::_cell_multi_selected(Object *p_object, int p_cell, bool p_ Node *n = get_node(np); - if (!n) + if (!n) { return; + } - if (!editor_selection) + if (!editor_selection) { return; + } if (p_selected) { editor_selection->add_node(n); @@ -630,18 +661,21 @@ void SceneTreeEditor::_notification(int p_what) { } TreeItem *SceneTreeEditor::_find(TreeItem *p_node, const NodePath &p_path) { - if (!p_node) + if (!p_node) { return nullptr; + } NodePath np = p_node->get_metadata(0); - if (np == p_path) + if (np == p_path) { return p_node; + } TreeItem *children = p_node->get_children(); while (children) { TreeItem *n = _find(children, p_path); - if (n) + if (n) { return n; + } children = children->get_next(); } @@ -651,13 +685,16 @@ TreeItem *SceneTreeEditor::_find(TreeItem *p_node, const NodePath &p_path) { void SceneTreeEditor::set_selected(Node *p_node, bool p_emit_selected) { ERR_FAIL_COND(blocked > 0); - if (pending_test_update) + if (pending_test_update) { _test_update_tree(); - if (tree_dirty) + } + if (tree_dirty) { _update_tree(); + } - if (selected == p_node) + if (selected == p_node) { return; + } TreeItem *item = p_node ? _find(tree->get_root(), p_node->get_path()) : nullptr; @@ -674,8 +711,9 @@ void SceneTreeEditor::set_selected(Node *p_node, bool p_emit_selected) { tree->ensure_cursor_is_visible(); } else { - if (!p_node) + if (!p_node) { selected = nullptr; + } _update_tree(); selected = p_node; } @@ -726,8 +764,9 @@ void SceneTreeEditor::_renamed() { which->set_text(0, new_name); } - if (new_name == n->get_name()) + if (new_name == n->get_name()) { return; + } if (!undo_redo) { n->set_name(new_name); @@ -747,8 +786,9 @@ Node *SceneTreeEditor::get_selected() { } void SceneTreeEditor::set_marked(const Set<Node *> &p_marked, bool p_selectable, bool p_children_selectable) { - if (tree_dirty) + if (tree_dirty) { _update_tree(); + } marked = p_marked; marked_selectable = p_selectable; marked_children_selectable = p_children_selectable; @@ -757,8 +797,9 @@ void SceneTreeEditor::set_marked(const Set<Node *> &p_marked, bool p_selectable, void SceneTreeEditor::set_marked(Node *p_marked, bool p_selectable, bool p_children_selectable) { Set<Node *> s; - if (p_marked) + if (p_marked) { s.insert(p_marked); + } set_marked(s, p_selectable, p_children_selectable); } @@ -796,18 +837,21 @@ void SceneTreeEditor::_update_selection(TreeItem *item) { NodePath np = item->get_metadata(0); - if (!has_node(np)) + if (!has_node(np)) { return; + } Node *n = get_node(np); - if (!n) + if (!n) { return; + } - if (editor_selection->is_selected(n)) + if (editor_selection->is_selected(n)) { item->select(0); - else + } else { item->deselect(0); + } TreeItem *c = item->get_children(); @@ -818,25 +862,30 @@ void SceneTreeEditor::_update_selection(TreeItem *item) { } void SceneTreeEditor::_selection_changed() { - if (!editor_selection) + if (!editor_selection) { return; + } TreeItem *root = tree->get_root(); - if (!root) + if (!root) { return; + } _update_selection(root); } void SceneTreeEditor::_cell_collapsed(Object *p_obj) { - if (updating_tree) + if (updating_tree) { return; - if (!can_rename) + } + if (!can_rename) { return; + } TreeItem *ti = Object::cast_to<TreeItem>(p_obj); - if (!ti) + if (!ti) { return; + } bool collapsed = ti->is_collapsed(); @@ -849,8 +898,9 @@ void SceneTreeEditor::_cell_collapsed(Object *p_obj) { } Variant SceneTreeEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) { - if (!can_rename) + if (!can_rename) { return Variant(); //not editable tree + } Vector<Node *> selected; Vector<Ref<Texture2D>> icons; @@ -869,8 +919,9 @@ Variant SceneTreeEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from next = tree->get_next_selected(next); } - if (selected.empty()) + if (selected.empty()) { return Variant(); + } VBoxContainer *vb = memnew(VBoxContainer); Array objs; @@ -910,28 +961,34 @@ bool SceneTreeEditor::_is_script_type(const StringName &p_type) const { } bool SceneTreeEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { - if (!can_rename) + if (!can_rename) { return false; //not editable tree - if (filter != String()) + } + if (filter != String()) { return false; //can't rearrange tree with filter turned on + } Dictionary d = p_data; - if (!d.has("type")) + if (!d.has("type")) { return false; + } TreeItem *item = tree->get_item_at_position(p_point); - if (!item) + if (!item) { return false; + } int section = tree->get_drop_section_at_position(p_point); - if (section < -1 || (section == -1 && !item->get_parent())) + if (section < -1 || (section == -1 && !item->get_parent())) { return false; + } if (String(d["type"]) == "files") { Vector<String> files = d["files"]; - if (files.size() == 0) + if (files.size() == 0) { return false; //weird + } if (_is_script_type(EditorFileSystem::get_singleton()->get_file_type(files[0]))) { tree->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM); @@ -941,8 +998,9 @@ bool SceneTreeEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_d for (int i = 0; i < files.size(); i++) { String file = files[i]; String ftype = EditorFileSystem::get_singleton()->get_file_type(file); - if (ftype != "PackedScene") + if (ftype != "PackedScene") { return false; + } } tree->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN | Tree::DROP_MODE_ON_ITEM); //so it works.. @@ -965,20 +1023,24 @@ bool SceneTreeEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_d } void SceneTreeEditor::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; + } TreeItem *item = tree->get_item_at_position(p_point); - if (!item) + if (!item) { return; + } int section = tree->get_drop_section_at_position(p_point); - if (section < -1) + if (section < -1) { return; + } NodePath np = item->get_metadata(0); Node *n = get_node(np); - if (!n) + if (!n) { return; + } Dictionary d = p_data; @@ -1131,8 +1193,9 @@ SceneTreeEditor::~SceneTreeEditor() { void SceneTreeDialog::_notification(int p_what) { switch (p_what) { case NOTIFICATION_VISIBILITY_CHANGED: { - if (is_visible()) + if (is_visible()) { tree->update_tree(); + } } break; case NOTIFICATION_ENTER_TREE: { connect("confirmed", callable_mp(this, &SceneTreeDialog::_select)); diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp index d0346a6c3e..04fbfdff9d 100644 --- a/editor/script_create_dialog.cpp +++ b/editor/script_create_dialog.cpp @@ -127,32 +127,37 @@ void ScriptCreateDialog::set_inheritance_base_type(const String &p_base) { } bool ScriptCreateDialog::_validate_parent(const String &p_string) { - if (p_string.length() == 0) + if (p_string.length() == 0) { return false; + } if (can_inherit_from_file && p_string.is_quoted()) { String p = p_string.substr(1, p_string.length() - 2); - if (_validate_path(p, true) == "") + if (_validate_path(p, true) == "") { return true; + } } return ClassDB::class_exists(p_string) || ScriptServer::is_global_class(p_string); } bool ScriptCreateDialog::_validate_class(const String &p_string) { - if (p_string.length() == 0) + if (p_string.length() == 0) { return false; + } for (int i = 0; i < p_string.length(); i++) { if (i == 0) { - if (p_string[0] >= '0' && p_string[0] <= '9') + if (p_string[0] >= '0' && p_string[0] <= '9') { return false; // no start with number plz + } } bool valid_char = (p_string[i] >= '0' && p_string[i] <= '9') || (p_string[i] >= 'a' && p_string[i] <= 'z') || (p_string[i] >= 'A' && p_string[i] <= 'Z') || p_string[i] == '_' || p_string[i] == '.'; - if (!valid_char) + if (!valid_char) { return false; + } } return true; @@ -161,14 +166,17 @@ bool ScriptCreateDialog::_validate_class(const String &p_string) { String ScriptCreateDialog::_validate_path(const String &p_path, bool p_file_must_exist) { String p = p_path.strip_edges(); - if (p == "") + if (p == "") { return TTR("Path is empty."); - if (p.get_file().get_basename() == "") + } + if (p.get_file().get_basename() == "") { return TTR("Filename is empty."); + } p = ProjectSettings::get_singleton()->localize_path(p); - if (!p.begins_with("res://")) + if (!p.begins_with("res://")) { return TTR("Path is not local."); + } DirAccess *d = DirAccess::create(DirAccess::ACCESS_RESOURCES); if (d->change_dir(p.get_base_dir()) != OK) { @@ -213,15 +221,18 @@ String ScriptCreateDialog::_validate_path(const String &p_path, bool p_file_must index++; } - if (!found) + if (!found) { return TTR("Invalid extension."); - if (!match) + } + if (!match) { return TTR("Wrong extension chosen."); + } /* Let ScriptLanguage do custom validation */ String path_error = ScriptServer::get_language(language_menu->get_selected())->validate_path(p); - if (path_error != "") + if (path_error != "") { return path_error; + } /* All checks passed */ return ""; @@ -300,8 +311,9 @@ void ScriptCreateDialog::_create_new() { if (has_named_classes) { String cname = class_name->get_text(); - if (cname.length()) + if (cname.length()) { scr->set_name(cname); + } } if (!is_built_in) { @@ -338,8 +350,9 @@ void ScriptCreateDialog::_lang_changed(int l) { has_named_classes = language->has_named_classes(); can_inherit_from_file = language->can_inherit_from_file(); supports_built_in = language->supports_builtin_mode(); - if (!supports_built_in) + if (!supports_built_in) { is_built_in = false; + } String selected_ext = "." + language->get_extension(); String path = file_path->get_text(); diff --git a/editor/settings_config_dialog.cpp b/editor/settings_config_dialog.cpp index b86db7d073..c461bf0410 100644 --- a/editor/settings_config_dialog.cpp +++ b/editor/settings_config_dialog.cpp @@ -41,8 +41,9 @@ #include "scene/gui/margin_container.h" void EditorSettingsDialog::ok_pressed() { - if (!EditorSettings::get_singleton()) + if (!EditorSettings::get_singleton()) { return; + } _settings_save(); timer->stop(); @@ -68,15 +69,17 @@ void EditorSettingsDialog::_settings_save() { } void EditorSettingsDialog::cancel_pressed() { - if (!EditorSettings::get_singleton()) + if (!EditorSettings::get_singleton()) { return; + } EditorSettings::get_singleton()->notify_changes(); } void EditorSettingsDialog::popup_edit_settings() { - if (!EditorSettings::get_singleton()) + if (!EditorSettings::get_singleton()) { return; + } EditorSettings::get_singleton()->list_text_editor_themes(); // make sure we have an up to date list of themes @@ -142,8 +145,9 @@ void EditorSettingsDialog::_unhandled_input(const Ref<InputEvent> &p_event) { if (ED_IS_SHORTCUT("editor/undo", p_event)) { String action = undo_redo->get_current_action_name(); - if (action != "") + if (action != "") { EditorNode::get_log()->add_message("Undo: " + action, EditorLog::MSG_TYPE_EDITOR); + } undo_redo->undo(); handled = true; } @@ -151,8 +155,9 @@ void EditorSettingsDialog::_unhandled_input(const Ref<InputEvent> &p_event) { if (ED_IS_SHORTCUT("editor/redo", p_event)) { undo_redo->redo(); String action = undo_redo->get_current_action_name(); - if (action != "") + if (action != "") { EditorNode::get_log()->add_message("Redo: " + action, EditorLog::MSG_TYPE_EDITOR); + } handled = true; } @@ -198,8 +203,9 @@ void EditorSettingsDialog::_update_shortcuts() { for (List<String>::Element *E = slist.front(); E; E = E->next()) { Ref<ShortCut> sc = EditorSettings::get_singleton()->get_shortcut(E->get()); - if (!sc->has_meta("original")) + if (!sc->has_meta("original")) { continue; + } Ref<InputEvent> original = sc->get_meta("original"); @@ -274,8 +280,9 @@ void EditorSettingsDialog::_shortcut_button_pressed(Object *p_item, int p_column shortcut_configured = item; } else if (p_idx == 1) { //erase - if (!sc.is_valid()) + if (!sc.is_valid()) { return; //pointless, there is nothing + } undo_redo->create_action(TTR("Erase Shortcut")); undo_redo->add_do_method(sc.ptr(), "set_shortcut", Ref<InputEvent>()); @@ -286,8 +293,9 @@ void EditorSettingsDialog::_shortcut_button_pressed(Object *p_item, int p_column undo_redo->add_undo_method(this, "_settings_changed"); undo_redo->commit_action(); } else if (p_idx == 2) { //revert to original - if (!sc.is_valid()) + if (!sc.is_valid()) { return; //pointless, there is nothing + } Ref<InputEvent> original = sc->get_meta("original"); @@ -315,8 +323,9 @@ void EditorSettingsDialog::_wait_for_key(const Ref<InputEvent> &p_event) { } void EditorSettingsDialog::_press_a_key_confirm() { - if (last_wait_for_key.is_null()) + if (last_wait_for_key.is_null()) { return; + } Ref<InputEventKey> ie; ie.instance(); @@ -345,10 +354,11 @@ void EditorSettingsDialog::_tabs_tab_changed(int p_tab) { void EditorSettingsDialog::_focus_current_search_box() { Control *tab = tabs->get_current_tab_control(); LineEdit *current_search_box = nullptr; - if (tab == tab_general) + if (tab == tab_general) { current_search_box = search_box; - else if (tab == tab_shortcuts) + } else if (tab == tab_shortcuts) { current_search_box = shortcut_search_box; + } if (current_search_box) { current_search_box->grab_focus(); |