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
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 = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
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", this, "_node_removed");
|
||||
FALLTHROUGH;
|
||||
}
|
||||
|
||||
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
|
||||
|
||||
if (is_visible_in_tree()) {
|
||||
_update_palette();
|
||||
}
|
||||
@@ -116,7 +110,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++) {
|
||||
@@ -151,7 +144,6 @@ void TileMapEditor::_button_tool_select(int p_tool) {
|
||||
_update_button_tool();
|
||||
switch (tool) {
|
||||
case TOOL_SELECTING: {
|
||||
|
||||
selection_active = false;
|
||||
} break;
|
||||
default:
|
||||
@@ -161,10 +153,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) {
|
||||
@@ -174,7 +164,6 @@ void TileMapEditor::_menu_option(int p_option) {
|
||||
}
|
||||
} break;
|
||||
case OPTION_ERASE_SELECTION: {
|
||||
|
||||
if (!selection_active)
|
||||
return;
|
||||
|
||||
@@ -188,7 +177,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();
|
||||
@@ -197,7 +185,6 @@ void TileMapEditor::_menu_option(int p_option) {
|
||||
|
||||
} break;
|
||||
case OPTION_CUT: {
|
||||
|
||||
if (selection_active) {
|
||||
_update_copydata();
|
||||
|
||||
@@ -240,19 +227,16 @@ void TileMapEditor::_palette_input(const Ref<InputEvent> &p_event) {
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -267,7 +251,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--) {
|
||||
@@ -282,7 +265,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;
|
||||
@@ -295,7 +277,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);
|
||||
|
||||
@@ -304,13 +285,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()));
|
||||
@@ -323,7 +302,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)
|
||||
@@ -394,7 +372,6 @@ void TileMapEditor::_priority_toggled(bool p_enabled) {
|
||||
}
|
||||
|
||||
void TileMapEditor::_text_entered(const String &p_text) {
|
||||
|
||||
canvas_item_editor_viewport->grab_focus();
|
||||
}
|
||||
|
||||
@@ -403,14 +380,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_scancode() == KEY_UP ||
|
||||
k->get_scancode() == KEY_DOWN ||
|
||||
k->get_scancode() == KEY_PAGEUP ||
|
||||
k->get_scancode() == KEY_PAGEDOWN)) {
|
||||
|
||||
palette->call("_gui_input", k);
|
||||
search_box->accept_event();
|
||||
}
|
||||
@@ -432,7 +407,6 @@ struct _PaletteEntry {
|
||||
} // namespace
|
||||
|
||||
void TileMapEditor::_update_palette() {
|
||||
|
||||
if (!node)
|
||||
return;
|
||||
|
||||
@@ -483,7 +457,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 != "") {
|
||||
@@ -510,7 +483,6 @@ void TileMapEditor::_update_palette() {
|
||||
}
|
||||
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
|
||||
if (show_tile_names) {
|
||||
palette->add_item(entries[i].name);
|
||||
} else {
|
||||
@@ -562,7 +534,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;
|
||||
@@ -581,11 +552,9 @@ void TileMapEditor::_update_palette() {
|
||||
Color modulate = tileset->tile_get_modulate(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); // !!
|
||||
@@ -621,7 +590,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)
|
||||
@@ -650,7 +618,6 @@ void TileMapEditor::_pick_tile(const Point2 &p_pos) {
|
||||
}
|
||||
|
||||
PoolVector<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);
|
||||
@@ -722,7 +689,6 @@ PoolVector<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool era
|
||||
bucket_queue.push_back(p_start);
|
||||
|
||||
while (bucket_queue.size()) {
|
||||
|
||||
Point2i n = bucket_queue.front()->get();
|
||||
bucket_queue.pop_front();
|
||||
|
||||
@@ -730,7 +696,6 @@ PoolVector<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool era
|
||||
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])
|
||||
@@ -760,7 +725,6 @@ PoolVector<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool era
|
||||
}
|
||||
|
||||
void TileMapEditor::_fill_points(const PoolVector<Vector2> &p_points, const Dictionary &p_op) {
|
||||
|
||||
int len = p_points.size();
|
||||
PoolVector<Vector2>::Read pr = p_points.read();
|
||||
|
||||
@@ -778,27 +742,22 @@ void TileMapEditor::_fill_points(const PoolVector<Vector2> &p_points, const Dict
|
||||
}
|
||||
|
||||
void TileMapEditor::_erase_points(const PoolVector<Vector2> &p_points) {
|
||||
|
||||
int len = p_points.size();
|
||||
PoolVector<Vector2>::Read pr = p_points.read();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -814,14 +773,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<Texture> t = node->get_tileset()->tile_get_texture(p_cell);
|
||||
|
||||
if (t.is_null())
|
||||
@@ -891,10 +848,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) {
|
||||
@@ -910,7 +865,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)
|
||||
@@ -941,7 +895,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) {
|
||||
|
||||
PoolVector<Vector2> points = _bucket_fill(p_point, false, true);
|
||||
PoolVector<Vector2>::Read pr = points.read();
|
||||
int len = points.size();
|
||||
@@ -959,16 +912,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);
|
||||
@@ -986,7 +936,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);
|
||||
@@ -1030,7 +979,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;
|
||||
|
||||
@@ -1041,16 +989,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
|
||||
@@ -1076,20 +1020,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;
|
||||
}
|
||||
@@ -1100,27 +1040,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();
|
||||
@@ -1130,15 +1064,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);
|
||||
}
|
||||
}
|
||||
@@ -1147,14 +1078,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);
|
||||
}
|
||||
@@ -1164,11 +1093,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) {
|
||||
|
||||
PoolVector<Vector2> points = _bucket_fill(over_tile);
|
||||
|
||||
if (points.size() == 0)
|
||||
@@ -1200,11 +1127,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;
|
||||
|
||||
@@ -1215,7 +1139,6 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
||||
}
|
||||
|
||||
if (tool == TOOL_PASTING) {
|
||||
|
||||
tool = TOOL_NONE;
|
||||
copydata.clear();
|
||||
|
||||
@@ -1226,7 +1149,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()));
|
||||
@@ -1242,7 +1164,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);
|
||||
@@ -1254,7 +1175,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) {
|
||||
@@ -1267,7 +1187,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;
|
||||
@@ -1295,12 +1214,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();
|
||||
}
|
||||
@@ -1320,14 +1237,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)) {
|
||||
@@ -1341,13 +1256,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);
|
||||
@@ -1357,23 +1270,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);
|
||||
}
|
||||
@@ -1382,11 +1291,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)
|
||||
@@ -1399,18 +1306,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);
|
||||
}
|
||||
@@ -1420,7 +1323,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);
|
||||
|
||||
@@ -1432,7 +1334,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;
|
||||
@@ -1442,7 +1343,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_scancode() == KEY_SHIFT && k->get_command()) {
|
||||
// trying to draw a rectangle with the painting tool, so change to the correct tool
|
||||
tool = last_tool;
|
||||
@@ -1452,7 +1352,6 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
||||
}
|
||||
|
||||
if (k->get_scancode() == KEY_ESCAPE) {
|
||||
|
||||
if (tool == TOOL_PASTING)
|
||||
copydata.clear();
|
||||
else if (tool == TOOL_SELECTING || selection_active)
|
||||
@@ -1571,14 +1470,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_scancode() == KEY_SHIFT && k->get_command()) {
|
||||
|
||||
tool = TOOL_PICKING;
|
||||
_update_button_tool();
|
||||
}
|
||||
} else if (tool == TOOL_PICKING) {
|
||||
|
||||
#ifdef APPLE_STYLE_KEYS
|
||||
if (k->get_scancode() == KEY_META) {
|
||||
#else
|
||||
@@ -1596,7 +1492,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;
|
||||
|
||||
@@ -1614,11 +1509,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)));
|
||||
|
||||
@@ -1628,13 +1521,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);
|
||||
@@ -1657,9 +1547,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)));
|
||||
|
||||
@@ -1670,11 +1558,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);
|
||||
@@ -1696,7 +1581,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)))));
|
||||
@@ -1707,7 +1591,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),
|
||||
@@ -1741,7 +1624,6 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) {
|
||||
}
|
||||
|
||||
if (tool == TOOL_LINE_PAINT) {
|
||||
|
||||
if (paint_undo.empty())
|
||||
return;
|
||||
|
||||
@@ -1751,12 +1633,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)
|
||||
@@ -1764,12 +1644,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;
|
||||
|
||||
@@ -1781,7 +1659,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;
|
||||
|
||||
@@ -1802,12 +1679,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)
|
||||
@@ -1819,7 +1694,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) {
|
||||
@@ -1831,7 +1705,6 @@ void TileMapEditor::edit(Node *p_tile_map) {
|
||||
}
|
||||
|
||||
if (p_tile_map) {
|
||||
|
||||
node = Object::cast_to<TileMap>(p_tile_map);
|
||||
if (!canvas_item_editor_viewport->is_connected("mouse_entered", this, "_canvas_mouse_enter"))
|
||||
canvas_item_editor_viewport->connect("mouse_entered", this, "_canvas_mouse_enter");
|
||||
@@ -1859,7 +1732,6 @@ void TileMapEditor::edit(Node *p_tile_map) {
|
||||
}
|
||||
|
||||
void TileMapEditor::_tileset_settings_changed() {
|
||||
|
||||
_update_palette();
|
||||
CanvasItemEditor::get_singleton()->update_viewport();
|
||||
}
|
||||
@@ -1873,7 +1745,6 @@ void TileMapEditor::_icon_size_changed(float p_value) {
|
||||
}
|
||||
|
||||
void TileMapEditor::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_manual_toggled"), &TileMapEditor::_manual_toggled);
|
||||
ClassDB::bind_method(D_METHOD("_priority_toggled"), &TileMapEditor::_priority_toggled);
|
||||
ClassDB::bind_method(D_METHOD("_text_entered"), &TileMapEditor::_text_entered);
|
||||
@@ -1978,7 +1849,6 @@ void TileMapEditor::_clear_transform() {
|
||||
}
|
||||
|
||||
TileMapEditor::TileMapEditor(EditorNode *p_editor) {
|
||||
|
||||
node = NULL;
|
||||
manual_autotile = false;
|
||||
priority_atlastile = false;
|
||||
@@ -2194,9 +2064,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);
|
||||
@@ -2209,19 +2077,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();
|
||||
@@ -2232,7 +2096,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();
|
||||
@@ -2242,7 +2105,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