From 0be6d925dc3c6413bce7a3ccb49631b8e4a6e67a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 13:23:58 +0200 Subject: Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks Which means that reduz' beloved style which we all became used to will now be changed automatically to remove the first empty line. This makes us lean closer to 1TBS (the one true brace style) instead of hybridating it with some Allman-inspired spacing. There's still the case of braces around single-statement blocks that needs to be addressed (but clang-format can't help with that, but clang-tidy may if we agree about it). Part of #33027. --- editor/plugins/tile_map_editor_plugin.cpp | 138 ------------------------------ 1 file changed, 138 deletions(-) (limited to 'editor/plugins/tile_map_editor_plugin.cpp') diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp index e22e0cc052..61eea6c15e 100644 --- a/editor/plugins/tile_map_editor_plugin.cpp +++ b/editor/plugins/tile_map_editor_plugin.cpp @@ -39,18 +39,14 @@ #include "scene/gui/split_container.h" void TileMapEditor::_node_removed(Node *p_node) { - if (p_node == node) { node = nullptr; } } void TileMapEditor::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_PROCESS: { - if (bucket_queue.size()) { CanvasItemEditor::get_singleton()->update_viewport(); } @@ -58,13 +54,11 @@ void TileMapEditor::_notification(int p_what) { } break; case NOTIFICATION_ENTER_TREE: { - get_tree()->connect("node_removed", callable_mp(this, &TileMapEditor::_node_removed)); [[fallthrough]]; } case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { - if (is_visible_in_tree()) { _update_palette(); } @@ -97,7 +91,6 @@ void TileMapEditor::_notification(int p_what) { } void TileMapEditor::_update_button_tool() { - ToolButton *tb[4] = { paint_button, bucket_fill_button, picker_button, select_button }; // Unpress all buttons for (int i = 0; i < 4; i++) { @@ -132,7 +125,6 @@ void TileMapEditor::_button_tool_select(int p_tool) { _update_button_tool(); switch (tool) { case TOOL_SELECTING: { - selection_active = false; } break; default: @@ -142,10 +134,8 @@ void TileMapEditor::_button_tool_select(int p_tool) { } void TileMapEditor::_menu_option(int p_option) { - switch (p_option) { case OPTION_COPY: { - _update_copydata(); if (selection_active) { @@ -155,7 +145,6 @@ void TileMapEditor::_menu_option(int p_option) { } } break; case OPTION_ERASE_SELECTION: { - if (!selection_active) return; @@ -169,7 +158,6 @@ void TileMapEditor::_menu_option(int p_option) { CanvasItemEditor::get_singleton()->update_viewport(); } break; case OPTION_FIX_INVALID: { - undo_redo->create_action(TTR("Fix Invalid Tiles")); undo_redo->add_undo_method(node, "set", "tile_data", node->get("tile_data")); node->fix_invalid_tiles(); @@ -178,7 +166,6 @@ void TileMapEditor::_menu_option(int p_option) { } break; case OPTION_CUT: { - if (selection_active) { _update_copydata(); @@ -206,19 +193,16 @@ void TileMapEditor::_palette_multi_selected(int index, bool selected) { } void TileMapEditor::_canvas_mouse_enter() { - mouse_over = true; CanvasItemEditor::get_singleton()->update_viewport(); } void TileMapEditor::_canvas_mouse_exit() { - mouse_over = false; CanvasItemEditor::get_singleton()->update_viewport(); } Vector TileMapEditor::get_selected_tiles() const { - Vector items = palette->get_selected_items(); if (items.size() == 0) { @@ -233,7 +217,6 @@ Vector TileMapEditor::get_selected_tiles() const { } void TileMapEditor::set_selected_tiles(Vector p_tiles) { - palette->unselect_all(); for (int i = p_tiles.size() - 1; i >= 0; i--) { @@ -248,7 +231,6 @@ void TileMapEditor::set_selected_tiles(Vector p_tiles) { } Dictionary TileMapEditor::_create_cell_dictionary(int tile, bool flip_x, bool flip_y, bool transpose, Vector2 autotile_coord) { - Dictionary cell; cell["id"] = tile; @@ -261,7 +243,6 @@ Dictionary TileMapEditor::_create_cell_dictionary(int tile, bool flip_x, bool fl } void TileMapEditor::_create_set_cell_undo_redo(const Vector2 &p_vec, const CellOp &p_cell_old, const CellOp &p_cell_new) { - Dictionary cell_old = _create_cell_dictionary(p_cell_old.idx, p_cell_old.xf, p_cell_old.yf, p_cell_old.tr, p_cell_old.ac); Dictionary cell_new = _create_cell_dictionary(p_cell_new.idx, p_cell_new.xf, p_cell_new.yf, p_cell_new.tr, p_cell_new.ac); @@ -270,13 +251,11 @@ void TileMapEditor::_create_set_cell_undo_redo(const Vector2 &p_vec, const CellO } void TileMapEditor::_start_undo(const String &p_action) { - undo_data.clear(); undo_redo->create_action(p_action); } void TileMapEditor::_finish_undo() { - if (undo_data.size()) { for (Map::Element *E = undo_data.front(); E; E = E->next()) { _create_set_cell_undo_redo(E->key(), E->get(), _get_op_from_cell(E->key())); @@ -289,7 +268,6 @@ void TileMapEditor::_finish_undo() { } void TileMapEditor::_set_cell(const Point2i &p_pos, Vector 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) @@ -360,7 +338,6 @@ void TileMapEditor::_priority_toggled(bool p_enabled) { } void TileMapEditor::_text_entered(const String &p_text) { - canvas_item_editor_viewport->grab_focus(); } @@ -369,14 +346,12 @@ void TileMapEditor::_text_changed(const String &p_text) { } void TileMapEditor::_sbox_input(const Ref &p_ie) { - Ref k = p_ie; if (k.is_valid() && (k->get_keycode() == KEY_UP || k->get_keycode() == KEY_DOWN || k->get_keycode() == KEY_PAGEUP || k->get_keycode() == KEY_PAGEDOWN)) { - palette->call("_gui_input", k); search_box->accept_event(); } @@ -396,7 +371,6 @@ struct _PaletteEntry { } // namespace void TileMapEditor::_update_palette() { - if (!node) return; @@ -447,7 +421,6 @@ void TileMapEditor::_update_palette() { Vector<_PaletteEntry> entries; for (List::Element *E = tiles.front(); E; E = E->next()) { - String name = tileset->tile_get_name(E->get()); if (name != "") { @@ -474,7 +447,6 @@ void TileMapEditor::_update_palette() { } for (int i = 0; i < entries.size(); i++) { - if (show_tile_names) { palette->add_item(entries[i].name); } else { @@ -526,7 +498,6 @@ void TileMapEditor::_update_palette() { } if (sel_tile != TileMap::INVALID_CELL && ((manual_autotile && tileset->tile_get_tile_mode(sel_tile) == TileSet::AUTO_TILE) || (!priority_atlastile && tileset->tile_get_tile_mode(sel_tile) == TileSet::ATLAS_TILE))) { - const Map &tiles2 = tileset->autotile_get_bitmask_map(sel_tile); Vector entries2; @@ -544,11 +515,9 @@ void TileMapEditor::_update_palette() { Ref tex = tileset->tile_get_texture(sel_tile); for (int i = 0; i < entries2.size(); i++) { - manual_palette->add_item(String()); if (tex.is_valid()) { - Rect2 region = tileset->tile_get_region(sel_tile); int spacing = tileset->autotile_get_spacing(sel_tile); region.size = tileset->autotile_get_size(sel_tile); // !! @@ -583,7 +552,6 @@ 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) @@ -612,7 +580,6 @@ void TileMapEditor::_pick_tile(const Point2 &p_pos) { } Vector TileMapEditor::_bucket_fill(const Point2i &p_start, bool erase, bool preview) { - int prev_id = node->get_cell(p_start.x, p_start.y); Vector ids; ids.push_back(TileMap::INVALID_CELL); @@ -674,7 +641,6 @@ Vector TileMapEditor::_bucket_fill(const Point2i &p_start, bool erase, bucket_queue.push_back(p_start); while (bucket_queue.size()) { - Point2i n = bucket_queue.front()->get(); bucket_queue.pop_front(); @@ -682,7 +648,6 @@ Vector TileMapEditor::_bucket_fill(const Point2i &p_start, bool erase, 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]) @@ -712,7 +677,6 @@ Vector TileMapEditor::_bucket_fill(const Point2i &p_start, bool erase, } void TileMapEditor::_fill_points(const Vector &p_points, const Dictionary &p_op) { - int len = p_points.size(); const Vector2 *pr = p_points.ptr(); @@ -730,27 +694,22 @@ void TileMapEditor::_fill_points(const Vector &p_points, const Dictiona } void TileMapEditor::_erase_points(const Vector &p_points) { - int len = p_points.size(); const Vector2 *pr = p_points.ptr(); for (int i = 0; i < len; i++) { - _set_cell(pr[i], invalid_cell); } } void TileMapEditor::_select(const Point2i &p_from, const Point2i &p_to) { - Point2i begin = p_from; Point2i end = p_to; if (begin.x > end.x) { - SWAP(begin.x, end.x); } if (begin.y > end.y) { - SWAP(begin.y, end.y); } @@ -766,14 +725,12 @@ void TileMapEditor::_erase_selection() { for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) { for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) { - _set_cell(Point2i(j, i), invalid_cell, false, false, false); } } } void TileMapEditor::_draw_cell(Control *p_viewport, int p_cell, const Point2i &p_point, bool p_flip_h, bool p_flip_v, bool p_transpose, const Point2i &p_autotile_coord, const Transform2D &p_xform) { - Ref t = node->get_tileset()->tile_get_texture(p_cell); if (t.is_null()) @@ -844,10 +801,8 @@ void TileMapEditor::_draw_cell(Control *p_viewport, int p_cell, const Point2i &p if (compatibility_mode_enabled && !centered_texture) { if (node->get_tile_origin() == TileMap::TILE_ORIGIN_TOP_LEFT) { - rect.position += tile_ofs; } else if (node->get_tile_origin() == TileMap::TILE_ORIGIN_BOTTOM_LEFT) { - rect.position += tile_ofs; if (p_transpose) { @@ -863,7 +818,6 @@ void TileMapEditor::_draw_cell(Control *p_viewport, int p_cell, const Point2i &p } } else if (node->get_tile_origin() == TileMap::TILE_ORIGIN_CENTER) { - rect.position += tile_ofs; if (p_flip_h) @@ -894,7 +848,6 @@ void TileMapEditor::_draw_cell(Control *p_viewport, int p_cell, const Point2i &p } void TileMapEditor::_draw_fill_preview(Control *p_viewport, int p_cell, const Point2i &p_point, bool p_flip_h, bool p_flip_v, bool p_transpose, const Point2i &p_autotile_coord, const Transform2D &p_xform) { - Vector points = _bucket_fill(p_point, false, true); const Vector2 *pr = points.ptr(); int len = points.size(); @@ -912,16 +865,13 @@ void TileMapEditor::_clear_bucket_cache() { } void TileMapEditor::_update_copydata() { - copydata.clear(); if (!selection_active) return; for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) { - for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) { - TileData tcd; tcd.cell = node->get_cell(j, i); @@ -939,7 +889,6 @@ void TileMapEditor::_update_copydata() { } static inline Vector line(int x0, int x1, int y0, int y1) { - Vector points; float dx = ABS(x1 - x0); @@ -983,7 +932,6 @@ static inline Vector line(int x0, int x1, int y0, int y1) { } bool TileMapEditor::forward_gui_input(const Ref &p_event) { - if (!node || !node->get_tileset().is_valid() || !node->is_visible_in_tree() || CanvasItemEditor::get_singleton()->get_current_tool() != CanvasItemEditor::TOOL_SELECT) return false; @@ -994,16 +942,12 @@ bool TileMapEditor::forward_gui_input(const Ref &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)) return false; // Drag. if (tool == TOOL_NONE) { - if (mb->get_shift()) { - if (mb->get_command()) tool = TOOL_RECTANGLE_PAINT; else @@ -1029,20 +973,16 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { } if (tool == TOOL_PAINTING) { - Vector ids = get_selected_tiles(); if (ids.size() > 0 && ids[0] != TileMap::INVALID_CELL) { - tool = TOOL_PAINTING; _start_undo(TTR("Paint TileMap")); } } else if (tool == TOOL_PICKING) { - _pick_tile(over_tile); } else if (tool == TOOL_SELECTING) { - selection_active = true; rectangle_begin = over_tile; } @@ -1053,27 +993,21 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { } else { // Mousebutton was released. if (tool != TOOL_NONE) { - if (tool == TOOL_PAINTING) { - Vector ids = get_selected_tiles(); if (ids.size() > 0 && ids[0] != TileMap::INVALID_CELL) { - _set_cell(over_tile, ids, flip_h, flip_v, transpose); _finish_undo(); paint_undo.clear(); } } else if (tool == TOOL_LINE_PAINT) { - Vector ids = get_selected_tiles(); if (ids.size() > 0 && ids[0] != TileMap::INVALID_CELL) { - _start_undo(TTR("Line Draw")); for (Map::Element *E = paint_undo.front(); E; E = E->next()) { - _set_cell(E->key(), ids, flip_h, flip_v, transpose); } _finish_undo(); @@ -1083,15 +1017,12 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { CanvasItemEditor::get_singleton()->update_viewport(); } } else if (tool == TOOL_RECTANGLE_PAINT) { - Vector ids = get_selected_tiles(); if (ids.size() > 0 && ids[0] != TileMap::INVALID_CELL) { - _start_undo(TTR("Rectangle Paint")); for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) { for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) { - _set_cell(Point2i(j, i), ids, flip_h, flip_v, transpose); } } @@ -1100,14 +1031,12 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { CanvasItemEditor::get_singleton()->update_viewport(); } } else if (tool == TOOL_PASTING) { - Point2 ofs = over_tile - rectangle.position; Vector ids; _start_undo(TTR("Paste")); ids.push_back(0); for (List::Element *E = copydata.front(); E; E = E->next()) { - ids.write[0] = E->get().cell; _set_cell(E->get().pos + ofs, ids, E->get().flip_h, E->get().flip_v, E->get().transpose, E->get().autotile_coord); } @@ -1117,11 +1046,9 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { return true; // We want to keep the Pasting tool. } else if (tool == TOOL_SELECTING) { - CanvasItemEditor::get_singleton()->update_viewport(); } else if (tool == TOOL_BUCKET) { - Vector points = _bucket_fill(over_tile); if (points.size() == 0) @@ -1153,11 +1080,8 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { } } } else if (mb->get_button_index() == BUTTON_RIGHT) { - if (mb->is_pressed()) { - if (tool == TOOL_SELECTING || selection_active) { - tool = TOOL_NONE; selection_active = false; @@ -1168,7 +1092,6 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { } if (tool == TOOL_PASTING) { - tool = TOOL_NONE; copydata.clear(); @@ -1179,7 +1102,6 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { } if (tool == TOOL_NONE) { - paint_undo.clear(); Point2 local = node->world_to_map(xform_inv.xform(mb->get_position())); @@ -1195,7 +1117,6 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { selection_active = false; rectangle_begin = local; } else { - tool = TOOL_ERASING; _set_cell(local, invalid_cell); @@ -1207,7 +1128,6 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { } else { if (tool == TOOL_ERASING || tool == TOOL_RECTANGLE_ERASE || tool == TOOL_LINE_ERASE) { - _finish_undo(); if (tool == TOOL_RECTANGLE_ERASE || tool == TOOL_LINE_ERASE) { @@ -1220,7 +1140,6 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { return true; } else if (tool == TOOL_BUCKET) { - Vector ids; ids.push_back(node->get_cell(over_tile.x, over_tile.y)); Dictionary pop; @@ -1248,12 +1167,10 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { Ref mm = p_event; if (mm.is_valid()) { - Point2i new_over_tile = node->world_to_map(xform_inv.xform(mm->get_position())); Point2i old_over_tile = over_tile; if (new_over_tile != over_tile) { - over_tile = new_over_tile; CanvasItemEditor::get_singleton()->update_viewport(); } @@ -1267,14 +1184,12 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { tile_info->set_text(String::num(over_tile.x) + ", " + String::num(over_tile.y) + " [" + tile_name + "]"); if (tool == TOOL_PAINTING) { - // Paint using bresenham line to prevent holes in painting if the user moves fast. Vector points = line(old_over_tile.x, over_tile.x, old_over_tile.y, over_tile.y); Vector ids = get_selected_tiles(); for (int i = 0; i < points.size(); ++i) { - Point2i pos = points[i]; if (!paint_undo.has(pos)) { @@ -1288,13 +1203,11 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { } if (tool == TOOL_ERASING) { - // Erase using bresenham line to prevent holes in painting if the user moves fast. Vector points = line(old_over_tile.x, over_tile.x, old_over_tile.y, over_tile.y); for (int i = 0; i < points.size(); ++i) { - Point2i pos = points[i]; _set_cell(pos, invalid_cell); @@ -1304,23 +1217,19 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { } if (tool == TOOL_SELECTING) { - _select(rectangle_begin, over_tile); return true; } if (tool == TOOL_LINE_PAINT || tool == TOOL_LINE_ERASE) { - Vector ids = get_selected_tiles(); Vector tmp_cell; bool erasing = (tool == TOOL_LINE_ERASE); tmp_cell.push_back(0); if (erasing && paint_undo.size()) { - for (Map::Element *E = paint_undo.front(); E; E = E->next()) { - tmp_cell.write[0] = E->get().idx; _set_cell(E->key(), tmp_cell, E->get().xf, E->get().yf, E->get().tr); } @@ -1329,11 +1238,9 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { paint_undo.clear(); if (ids.size() > 0 && ids[0] != TileMap::INVALID_CELL) { - Vector points = line(rectangle_begin.x, over_tile.x, rectangle_begin.y, over_tile.y); for (int i = 0; i < points.size(); i++) { - paint_undo[points[i]] = _get_op_from_cell(points[i]); if (erasing) @@ -1346,18 +1253,14 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { return true; } if (tool == TOOL_RECTANGLE_PAINT || tool == TOOL_RECTANGLE_ERASE) { - Vector tmp_cell; tmp_cell.push_back(0); _select(rectangle_begin, over_tile); if (tool == TOOL_RECTANGLE_ERASE) { - if (paint_undo.size()) { - for (Map::Element *E = paint_undo.front(); E; E = E->next()) { - tmp_cell.write[0] = E->get().idx; _set_cell(E->key(), tmp_cell, E->get().xf, E->get().yf, E->get().tr); } @@ -1367,7 +1270,6 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) { for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) { - Point2i tile = Point2i(j, i); paint_undo[tile] = _get_op_from_cell(tile); @@ -1379,7 +1281,6 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { return true; } if (tool == TOOL_PICKING && Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) { - _pick_tile(over_tile); return true; @@ -1389,7 +1290,6 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { Ref k = p_event; if (k.is_valid() && k->is_pressed()) { - if (last_tool == TOOL_NONE && tool == TOOL_PICKING && k->get_keycode() == KEY_SHIFT && k->get_command()) { // trying to draw a rectangle with the painting tool, so change to the correct tool tool = last_tool; @@ -1399,7 +1299,6 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { } if (k->get_keycode() == KEY_ESCAPE) { - if (tool == TOOL_PASTING) copydata.clear(); else if (tool == TOOL_SELECTING || selection_active) @@ -1518,14 +1417,11 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { } else if (k.is_valid()) { // Release event. if (tool == TOOL_NONE) { - if (k->get_keycode() == KEY_SHIFT && k->get_command()) { - tool = TOOL_PICKING; _update_button_tool(); } } else if (tool == TOOL_PICKING) { - #ifdef APPLE_STYLE_KEYS if (k->get_keycode() == KEY_META) { #else @@ -1543,7 +1439,6 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { } void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { - if (!node || CanvasItemEditor::get_singleton()->get_current_tool() != CanvasItemEditor::TOOL_SELECT) return; @@ -1561,11 +1456,9 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { Rect2i si = aabb.grow(1.0); if (node->get_half_offset() != TileMap::HALF_OFFSET_X && node->get_half_offset() != TileMap::HALF_OFFSET_NEGATIVE_X) { - int max_lines = 2000; //avoid crash if size too small for (int i = (si.position.x) - 1; i <= (si.position.x + si.size.x); i++) { - Vector2 from = xform.xform(node->map_to_world(Vector2(i, si.position.y))); Vector2 to = xform.xform(node->map_to_world(Vector2(i, si.position.y + si.size.y + 1))); @@ -1575,13 +1468,10 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { break; } } else { - int max_lines = 10000; //avoid crash if size too small for (int i = (si.position.x) - 1; i <= (si.position.x + si.size.x); i++) { - for (int j = (si.position.y) - 1; j <= (si.position.y + si.size.y); j++) { - Vector2 ofs; if (ABS(j) & 1) { ofs = cell_xf[0] * (node->get_half_offset() == TileMap::HALF_OFFSET_X ? 0.5 : -0.5); @@ -1604,9 +1494,7 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { int max_lines = 10000; //avoid crash if size too small if (node->get_half_offset() != TileMap::HALF_OFFSET_Y && node->get_half_offset() != TileMap::HALF_OFFSET_NEGATIVE_Y) { - for (int i = (si.position.y) - 1; i <= (si.position.y + si.size.y); i++) { - Vector2 from = xform.xform(node->map_to_world(Vector2(si.position.x, i))); Vector2 to = xform.xform(node->map_to_world(Vector2(si.position.x + si.size.x + 1, i))); @@ -1617,11 +1505,8 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { break; } } else { - for (int i = (si.position.y) - 1; i <= (si.position.y + si.size.y); i++) { - for (int j = (si.position.x) - 1; j <= (si.position.x + si.size.x); j++) { - Vector2 ofs; if (ABS(j) & 1) { ofs = cell_xf[1] * (node->get_half_offset() == TileMap::HALF_OFFSET_Y ? 0.5 : -0.5); @@ -1643,7 +1528,6 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { } if (selection_active) { - Vector points; points.push_back(xform.xform(node->map_to_world((rectangle.position)))); points.push_back(xform.xform(node->map_to_world((rectangle.position + Point2(rectangle.size.x + 1, 0))))); @@ -1654,7 +1538,6 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { } if (mouse_over && node->get_tileset().is_valid()) { - Vector2 endpoints[4] = { node->map_to_world(over_tile, true), node->map_to_world((over_tile + Point2(1, 0)), true), @@ -1688,7 +1571,6 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { } if (tool == TOOL_LINE_PAINT) { - if (paint_undo.empty()) return; @@ -1698,12 +1580,10 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { return; for (Map::Element *E = paint_undo.front(); E; E = E->next()) { - _draw_cell(p_overlay, ids[0], E->key(), flip_h, flip_v, transpose, autotile_coord, xform); } } else if (tool == TOOL_RECTANGLE_PAINT) { - Vector ids = get_selected_tiles(); if (ids.size() == 1 && ids[0] == TileMap::INVALID_CELL) @@ -1711,12 +1591,10 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) { for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) { - _draw_cell(p_overlay, ids[0], Point2i(j, i), flip_h, flip_v, transpose, autotile_coord, xform); } } } else if (tool == TOOL_PASTING) { - if (copydata.empty()) return; @@ -1728,7 +1606,6 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { Point2 ofs = over_tile - rectangle.position; for (List::Element *E = copydata.front(); E; E = E->next()) { - if (!ts->has_tile(E->get().cell)) continue; @@ -1749,12 +1626,10 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { p_overlay->draw_colored_polygon(points, Color(0.2, 1.0, 0.8, 0.2)); } else if (tool == TOOL_BUCKET) { - Vector tiles = get_selected_tiles(); _draw_fill_preview(p_overlay, tiles[0], over_tile, flip_h, flip_v, transpose, autotile_coord, xform); } else { - Vector st = get_selected_tiles(); if (st.size() == 1 && st[0] == TileMap::INVALID_CELL) @@ -1766,7 +1641,6 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { } void TileMapEditor::edit(Node *p_tile_map) { - search_box->set_text(""); if (!canvas_item_editor_viewport) { @@ -1776,7 +1650,6 @@ void TileMapEditor::edit(Node *p_tile_map) { if (node) node->disconnect("settings_changed", callable_mp(this, &TileMapEditor::_tileset_settings_changed)); if (p_tile_map) { - node = Object::cast_to(p_tile_map); 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)); @@ -1803,7 +1676,6 @@ void TileMapEditor::edit(Node *p_tile_map) { } void TileMapEditor::_tileset_settings_changed() { - _update_palette(); CanvasItemEditor::get_singleton()->update_viewport(); } @@ -1817,7 +1689,6 @@ void TileMapEditor::_icon_size_changed(float p_value) { } void TileMapEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_fill_points"), &TileMapEditor::_fill_points); ClassDB::bind_method(D_METHOD("_erase_points"), &TileMapEditor::_erase_points); } @@ -1901,7 +1772,6 @@ void TileMapEditor::_clear_transform() { } TileMapEditor::TileMapEditor(EditorNode *p_editor) { - node = nullptr; manual_autotile = false; priority_atlastile = false; @@ -2112,9 +1982,7 @@ TileMapEditor::~TileMapEditor() { /////////////////////////////////////////////////////////////// void TileMapEditorPlugin::_notification(int p_what) { - if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { - switch ((int)EditorSettings::get_singleton()->get("editors/tile_map/editor_side")) { case 0: { // Left. CanvasItemEditor::get_singleton()->get_palette_split()->move_child(tile_map_editor, 0); @@ -2127,19 +1995,15 @@ void TileMapEditorPlugin::_notification(int p_what) { } void TileMapEditorPlugin::edit(Object *p_object) { - tile_map_editor->edit(Object::cast_to(p_object)); } bool TileMapEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("TileMap"); } void TileMapEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { - tile_map_editor->show(); tile_map_editor->get_toolbar()->show(); tile_map_editor->get_toolbar_right()->show(); @@ -2150,7 +2014,6 @@ void TileMapEditorPlugin::make_visible(bool p_visible) { // Change to TOOL_SELECT when TileMap node is selected, to prevent accidental movement. CanvasItemEditor::get_singleton()->set_current_tool(CanvasItemEditor::TOOL_SELECT); } else { - tile_map_editor->hide(); tile_map_editor->get_toolbar()->hide(); tile_map_editor->get_toolbar_right()->hide(); @@ -2160,7 +2023,6 @@ void TileMapEditorPlugin::make_visible(bool p_visible) { } TileMapEditorPlugin::TileMapEditorPlugin(EditorNode *p_node) { - EDITOR_DEF("editors/tile_map/preview_size", 64); EDITOR_DEF("editors/tile_map/palette_item_hseparation", 8); EDITOR_DEF("editors/tile_map/show_tile_names", true); -- cgit v1.2.3 From 0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 16:41:43 +0200 Subject: Style: Enforce braces around if blocks and loops Using clang-tidy's `readability-braces-around-statements`. https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html --- editor/plugins/tile_map_editor_plugin.cpp | 217 +++++++++++++++++++----------- 1 file changed, 142 insertions(+), 75 deletions(-) (limited to 'editor/plugins/tile_map_editor_plugin.cpp') 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 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 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 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 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 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(); + } } else if (prev_id == TileMap::INVALID_CELL) { return Vector(); } @@ -604,8 +618,9 @@ Vector 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 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(); bucket_cache_tile = prev_id; bucket_cache_rect = r; @@ -644,19 +660,22 @@ Vector 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 &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 &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 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 line(int x0, int x1, int y0, int y1) { } bool TileMapEditor::forward_gui_input(const Ref &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 &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 &p_event) { } else if (tool == TOOL_BUCKET) { Vector 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 &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 &p_event) { Vector 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 &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 &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 &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 &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 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::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 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 ts = node->get_tileset(); - if (ts.is_null()) + if (ts.is_null()) { return; + } Point2 ofs = over_tile - rectangle.position; for (List::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 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(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; -- cgit v1.2.3