You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-06 12:20:30 +00:00
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
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user