You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-07 12:30:27 +00:00
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.
This commit is contained in:
@@ -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<int> TileMapEditor::get_selected_tiles() const {
|
||||
|
||||
Vector<int> items = palette->get_selected_items();
|
||||
|
||||
if (items.size() == 0) {
|
||||
@@ -233,7 +217,6 @@ Vector<int> TileMapEditor::get_selected_tiles() const {
|
||||
}
|
||||
|
||||
void TileMapEditor::set_selected_tiles(Vector<int> p_tiles) {
|
||||
|
||||
palette->unselect_all();
|
||||
|
||||
for (int i = p_tiles.size() - 1; i >= 0; i--) {
|
||||
@@ -248,7 +231,6 @@ void TileMapEditor::set_selected_tiles(Vector<int> p_tiles) {
|
||||
}
|
||||
|
||||
Dictionary TileMapEditor::_create_cell_dictionary(int tile, bool flip_x, bool flip_y, bool transpose, Vector2 autotile_coord) {
|
||||
|
||||
Dictionary cell;
|
||||
|
||||
cell["id"] = tile;
|
||||
@@ -261,7 +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<Point2i, CellOp>::Element *E = undo_data.front(); E; E = E->next()) {
|
||||
_create_set_cell_undo_redo(E->key(), E->get(), _get_op_from_cell(E->key()));
|
||||
@@ -289,7 +268,6 @@ 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)
|
||||
@@ -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<InputEvent> &p_ie) {
|
||||
|
||||
Ref<InputEventKey> k = p_ie;
|
||||
|
||||
if (k.is_valid() && (k->get_keycode() == KEY_UP ||
|
||||
k->get_keycode() == KEY_DOWN ||
|
||||
k->get_keycode() == KEY_PAGEUP ||
|
||||
k->get_keycode() == KEY_PAGEDOWN)) {
|
||||
|
||||
palette->call("_gui_input", k);
|
||||
search_box->accept_event();
|
||||
}
|
||||
@@ -396,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<int>::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<Vector2, uint32_t> &tiles2 = tileset->autotile_get_bitmask_map(sel_tile);
|
||||
|
||||
Vector<Vector2> entries2;
|
||||
@@ -544,11 +515,9 @@ void TileMapEditor::_update_palette() {
|
||||
Ref<Texture2D> tex = tileset->tile_get_texture(sel_tile);
|
||||
|
||||
for (int i = 0; i < entries2.size(); i++) {
|
||||
|
||||
manual_palette->add_item(String());
|
||||
|
||||
if (tex.is_valid()) {
|
||||
|
||||
Rect2 region = tileset->tile_get_region(sel_tile);
|
||||
int spacing = tileset->autotile_get_spacing(sel_tile);
|
||||
region.size = tileset->autotile_get_size(sel_tile); // !!
|
||||
@@ -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<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool erase, bool preview) {
|
||||
|
||||
int prev_id = node->get_cell(p_start.x, p_start.y);
|
||||
Vector<int> ids;
|
||||
ids.push_back(TileMap::INVALID_CELL);
|
||||
@@ -674,7 +641,6 @@ Vector<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool erase,
|
||||
bucket_queue.push_back(p_start);
|
||||
|
||||
while (bucket_queue.size()) {
|
||||
|
||||
Point2i n = bucket_queue.front()->get();
|
||||
bucket_queue.pop_front();
|
||||
|
||||
@@ -682,7 +648,6 @@ Vector<Vector2> 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<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool erase,
|
||||
}
|
||||
|
||||
void TileMapEditor::_fill_points(const Vector<Vector2> &p_points, const Dictionary &p_op) {
|
||||
|
||||
int len = p_points.size();
|
||||
const Vector2 *pr = p_points.ptr();
|
||||
|
||||
@@ -730,27 +694,22 @@ void TileMapEditor::_fill_points(const Vector<Vector2> &p_points, const Dictiona
|
||||
}
|
||||
|
||||
void TileMapEditor::_erase_points(const Vector<Vector2> &p_points) {
|
||||
|
||||
int len = p_points.size();
|
||||
const Vector2 *pr = p_points.ptr();
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
|
||||
_set_cell(pr[i], invalid_cell);
|
||||
}
|
||||
}
|
||||
|
||||
void TileMapEditor::_select(const Point2i &p_from, const Point2i &p_to) {
|
||||
|
||||
Point2i begin = p_from;
|
||||
Point2i end = p_to;
|
||||
|
||||
if (begin.x > end.x) {
|
||||
|
||||
SWAP(begin.x, end.x);
|
||||
}
|
||||
if (begin.y > end.y) {
|
||||
|
||||
SWAP(begin.y, end.y);
|
||||
}
|
||||
|
||||
@@ -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<Texture2D> 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<Vector2> 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<Point2i> line(int x0, int x1, int y0, int y1) {
|
||||
|
||||
Vector<Point2i> points;
|
||||
|
||||
float dx = ABS(x1 - x0);
|
||||
@@ -983,7 +932,6 @@ 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)
|
||||
return false;
|
||||
|
||||
@@ -994,16 +942,12 @@ 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))
|
||||
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<InputEvent> &p_event) {
|
||||
}
|
||||
|
||||
if (tool == TOOL_PAINTING) {
|
||||
|
||||
Vector<int> ids = get_selected_tiles();
|
||||
|
||||
if (ids.size() > 0 && ids[0] != TileMap::INVALID_CELL) {
|
||||
|
||||
tool = TOOL_PAINTING;
|
||||
|
||||
_start_undo(TTR("Paint TileMap"));
|
||||
}
|
||||
} else if (tool == TOOL_PICKING) {
|
||||
|
||||
_pick_tile(over_tile);
|
||||
} else if (tool == TOOL_SELECTING) {
|
||||
|
||||
selection_active = true;
|
||||
rectangle_begin = over_tile;
|
||||
}
|
||||
@@ -1053,27 +993,21 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
||||
} else {
|
||||
// Mousebutton was released.
|
||||
if (tool != TOOL_NONE) {
|
||||
|
||||
if (tool == TOOL_PAINTING) {
|
||||
|
||||
Vector<int> ids = get_selected_tiles();
|
||||
|
||||
if (ids.size() > 0 && ids[0] != TileMap::INVALID_CELL) {
|
||||
|
||||
_set_cell(over_tile, ids, flip_h, flip_v, transpose);
|
||||
_finish_undo();
|
||||
|
||||
paint_undo.clear();
|
||||
}
|
||||
} else if (tool == TOOL_LINE_PAINT) {
|
||||
|
||||
Vector<int> ids = get_selected_tiles();
|
||||
|
||||
if (ids.size() > 0 && ids[0] != TileMap::INVALID_CELL) {
|
||||
|
||||
_start_undo(TTR("Line Draw"));
|
||||
for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) {
|
||||
|
||||
_set_cell(E->key(), ids, flip_h, flip_v, transpose);
|
||||
}
|
||||
_finish_undo();
|
||||
@@ -1083,15 +1017,12 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
||||
CanvasItemEditor::get_singleton()->update_viewport();
|
||||
}
|
||||
} else if (tool == TOOL_RECTANGLE_PAINT) {
|
||||
|
||||
Vector<int> ids = get_selected_tiles();
|
||||
|
||||
if (ids.size() > 0 && ids[0] != TileMap::INVALID_CELL) {
|
||||
|
||||
_start_undo(TTR("Rectangle Paint"));
|
||||
for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) {
|
||||
for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) {
|
||||
|
||||
_set_cell(Point2i(j, i), ids, flip_h, flip_v, transpose);
|
||||
}
|
||||
}
|
||||
@@ -1100,14 +1031,12 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
||||
CanvasItemEditor::get_singleton()->update_viewport();
|
||||
}
|
||||
} else if (tool == TOOL_PASTING) {
|
||||
|
||||
Point2 ofs = over_tile - rectangle.position;
|
||||
Vector<int> ids;
|
||||
|
||||
_start_undo(TTR("Paste"));
|
||||
ids.push_back(0);
|
||||
for (List<TileData>::Element *E = copydata.front(); E; E = E->next()) {
|
||||
|
||||
ids.write[0] = E->get().cell;
|
||||
_set_cell(E->get().pos + ofs, ids, E->get().flip_h, E->get().flip_v, E->get().transpose, E->get().autotile_coord);
|
||||
}
|
||||
@@ -1117,11 +1046,9 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
||||
|
||||
return true; // We want to keep the Pasting tool.
|
||||
} else if (tool == TOOL_SELECTING) {
|
||||
|
||||
CanvasItemEditor::get_singleton()->update_viewport();
|
||||
|
||||
} else if (tool == TOOL_BUCKET) {
|
||||
|
||||
Vector<Vector2> points = _bucket_fill(over_tile);
|
||||
|
||||
if (points.size() == 0)
|
||||
@@ -1153,11 +1080,8 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
||||
}
|
||||
}
|
||||
} else if (mb->get_button_index() == BUTTON_RIGHT) {
|
||||
|
||||
if (mb->is_pressed()) {
|
||||
|
||||
if (tool == TOOL_SELECTING || selection_active) {
|
||||
|
||||
tool = TOOL_NONE;
|
||||
selection_active = false;
|
||||
|
||||
@@ -1168,7 +1092,6 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
||||
}
|
||||
|
||||
if (tool == TOOL_PASTING) {
|
||||
|
||||
tool = TOOL_NONE;
|
||||
copydata.clear();
|
||||
|
||||
@@ -1179,7 +1102,6 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
||||
}
|
||||
|
||||
if (tool == TOOL_NONE) {
|
||||
|
||||
paint_undo.clear();
|
||||
|
||||
Point2 local = node->world_to_map(xform_inv.xform(mb->get_position()));
|
||||
@@ -1195,7 +1117,6 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &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<InputEvent> &p_event) {
|
||||
|
||||
} else {
|
||||
if (tool == TOOL_ERASING || tool == TOOL_RECTANGLE_ERASE || tool == TOOL_LINE_ERASE) {
|
||||
|
||||
_finish_undo();
|
||||
|
||||
if (tool == TOOL_RECTANGLE_ERASE || tool == TOOL_LINE_ERASE) {
|
||||
@@ -1220,7 +1140,6 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
||||
return true;
|
||||
|
||||
} else if (tool == TOOL_BUCKET) {
|
||||
|
||||
Vector<int> ids;
|
||||
ids.push_back(node->get_cell(over_tile.x, over_tile.y));
|
||||
Dictionary pop;
|
||||
@@ -1248,12 +1167,10 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
||||
Ref<InputEventMouseMotion> mm = p_event;
|
||||
|
||||
if (mm.is_valid()) {
|
||||
|
||||
Point2i new_over_tile = node->world_to_map(xform_inv.xform(mm->get_position()));
|
||||
Point2i old_over_tile = over_tile;
|
||||
|
||||
if (new_over_tile != over_tile) {
|
||||
|
||||
over_tile = new_over_tile;
|
||||
CanvasItemEditor::get_singleton()->update_viewport();
|
||||
}
|
||||
@@ -1267,14 +1184,12 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &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<Point2i> points = line(old_over_tile.x, over_tile.x, old_over_tile.y, over_tile.y);
|
||||
Vector<int> ids = get_selected_tiles();
|
||||
|
||||
for (int i = 0; i < points.size(); ++i) {
|
||||
|
||||
Point2i pos = points[i];
|
||||
|
||||
if (!paint_undo.has(pos)) {
|
||||
@@ -1288,13 +1203,11 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
||||
}
|
||||
|
||||
if (tool == TOOL_ERASING) {
|
||||
|
||||
// Erase using bresenham line to prevent holes in painting if the user moves fast.
|
||||
|
||||
Vector<Point2i> points = line(old_over_tile.x, over_tile.x, old_over_tile.y, over_tile.y);
|
||||
|
||||
for (int i = 0; i < points.size(); ++i) {
|
||||
|
||||
Point2i pos = points[i];
|
||||
|
||||
_set_cell(pos, invalid_cell);
|
||||
@@ -1304,23 +1217,19 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
||||
}
|
||||
|
||||
if (tool == TOOL_SELECTING) {
|
||||
|
||||
_select(rectangle_begin, over_tile);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (tool == TOOL_LINE_PAINT || tool == TOOL_LINE_ERASE) {
|
||||
|
||||
Vector<int> ids = get_selected_tiles();
|
||||
Vector<int> tmp_cell;
|
||||
bool erasing = (tool == TOOL_LINE_ERASE);
|
||||
|
||||
tmp_cell.push_back(0);
|
||||
if (erasing && paint_undo.size()) {
|
||||
|
||||
for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) {
|
||||
|
||||
tmp_cell.write[0] = E->get().idx;
|
||||
_set_cell(E->key(), tmp_cell, E->get().xf, E->get().yf, E->get().tr);
|
||||
}
|
||||
@@ -1329,11 +1238,9 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
||||
paint_undo.clear();
|
||||
|
||||
if (ids.size() > 0 && ids[0] != TileMap::INVALID_CELL) {
|
||||
|
||||
Vector<Point2i> points = line(rectangle_begin.x, over_tile.x, rectangle_begin.y, over_tile.y);
|
||||
|
||||
for (int i = 0; i < points.size(); i++) {
|
||||
|
||||
paint_undo[points[i]] = _get_op_from_cell(points[i]);
|
||||
|
||||
if (erasing)
|
||||
@@ -1346,18 +1253,14 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
||||
return true;
|
||||
}
|
||||
if (tool == TOOL_RECTANGLE_PAINT || tool == TOOL_RECTANGLE_ERASE) {
|
||||
|
||||
Vector<int> tmp_cell;
|
||||
tmp_cell.push_back(0);
|
||||
|
||||
_select(rectangle_begin, over_tile);
|
||||
|
||||
if (tool == TOOL_RECTANGLE_ERASE) {
|
||||
|
||||
if (paint_undo.size()) {
|
||||
|
||||
for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) {
|
||||
|
||||
tmp_cell.write[0] = E->get().idx;
|
||||
_set_cell(E->key(), tmp_cell, E->get().xf, E->get().yf, E->get().tr);
|
||||
}
|
||||
@@ -1367,7 +1270,6 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
||||
|
||||
for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) {
|
||||
for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) {
|
||||
|
||||
Point2i tile = Point2i(j, i);
|
||||
paint_undo[tile] = _get_op_from_cell(tile);
|
||||
|
||||
@@ -1379,7 +1281,6 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
||||
return true;
|
||||
}
|
||||
if (tool == TOOL_PICKING && Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) {
|
||||
|
||||
_pick_tile(over_tile);
|
||||
|
||||
return true;
|
||||
@@ -1389,7 +1290,6 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
||||
Ref<InputEventKey> k = p_event;
|
||||
|
||||
if (k.is_valid() && k->is_pressed()) {
|
||||
|
||||
if (last_tool == TOOL_NONE && tool == TOOL_PICKING && k->get_keycode() == KEY_SHIFT && k->get_command()) {
|
||||
// trying to draw a rectangle with the painting tool, so change to the correct tool
|
||||
tool = last_tool;
|
||||
@@ -1399,7 +1299,6 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &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<InputEvent> &p_event) {
|
||||
} else if (k.is_valid()) { // Release event.
|
||||
|
||||
if (tool == TOOL_NONE) {
|
||||
|
||||
if (k->get_keycode() == KEY_SHIFT && k->get_command()) {
|
||||
|
||||
tool = TOOL_PICKING;
|
||||
_update_button_tool();
|
||||
}
|
||||
} else if (tool == TOOL_PICKING) {
|
||||
|
||||
#ifdef APPLE_STYLE_KEYS
|
||||
if (k->get_keycode() == KEY_META) {
|
||||
#else
|
||||
@@ -1543,7 +1439,6 @@ 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)
|
||||
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<Vector2> points;
|
||||
points.push_back(xform.xform(node->map_to_world((rectangle.position))));
|
||||
points.push_back(xform.xform(node->map_to_world((rectangle.position + Point2(rectangle.size.x + 1, 0)))));
|
||||
@@ -1654,7 +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<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) {
|
||||
|
||||
_draw_cell(p_overlay, ids[0], E->key(), flip_h, flip_v, transpose, autotile_coord, xform);
|
||||
}
|
||||
|
||||
} else if (tool == TOOL_RECTANGLE_PAINT) {
|
||||
|
||||
Vector<int> ids = get_selected_tiles();
|
||||
|
||||
if (ids.size() == 1 && ids[0] == TileMap::INVALID_CELL)
|
||||
@@ -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<TileData>::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<int> tiles = get_selected_tiles();
|
||||
_draw_fill_preview(p_overlay, tiles[0], over_tile, flip_h, flip_v, transpose, autotile_coord, xform);
|
||||
|
||||
} else {
|
||||
|
||||
Vector<int> st = get_selected_tiles();
|
||||
|
||||
if (st.size() == 1 && st[0] == TileMap::INVALID_CELL)
|
||||
@@ -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<TileMap>(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<Node>(p_object));
|
||||
}
|
||||
|
||||
bool TileMapEditorPlugin::handles(Object *p_object) const {
|
||||
|
||||
return p_object->is_class("TileMap");
|
||||
}
|
||||
|
||||
void TileMapEditorPlugin::make_visible(bool p_visible) {
|
||||
|
||||
if (p_visible) {
|
||||
|
||||
tile_map_editor->show();
|
||||
tile_map_editor->get_toolbar()->show();
|
||||
tile_map_editor->get_toolbar_right()->show();
|
||||
@@ -2150,7 +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);
|
||||
|
||||
Reference in New Issue
Block a user