diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2018-08-24 15:18:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-24 15:18:06 +0200 |
commit | cd945e28def309222abdb2fdc057a0913abde4b8 (patch) | |
tree | 598b43ce7cbd9057ecc3cc82032fb9355bc67be7 | |
parent | 1ae7a78d8b7566c8421dda4a061e10c8278f7760 (diff) | |
parent | 3f1b9772639dcaac807aee95e8226094f32dfac7 (diff) |
Merge pull request #21272 from paulloz/tilemap-tools-enhancements
tilemap_editor: change move and duplicate tools
-rw-r--r-- | editor/plugins/tile_map_editor_plugin.cpp | 109 | ||||
-rw-r--r-- | editor/plugins/tile_map_editor_plugin.h | 8 |
2 files changed, 53 insertions, 64 deletions
diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp index 0a421bdffe..34dd36692c 100644 --- a/editor/plugins/tile_map_editor_plugin.cpp +++ b/editor/plugins/tile_map_editor_plugin.cpp @@ -79,9 +79,9 @@ void TileMapEditor::_notification(int p_what) { PopupMenu *p = options->get_popup(); p->set_item_icon(p->get_item_index(OPTION_PAINTING), get_icon("Edit", "EditorIcons")); p->set_item_icon(p->get_item_index(OPTION_PICK_TILE), get_icon("ColorPick", "EditorIcons")); - p->set_item_icon(p->get_item_index(OPTION_SELECT), get_icon("ToolSelect", "EditorIcons")); - p->set_item_icon(p->get_item_index(OPTION_MOVE), get_icon("ToolMove", "EditorIcons")); - p->set_item_icon(p->get_item_index(OPTION_DUPLICATE), get_icon("Duplicate", "EditorIcons")); + p->set_item_icon(p->get_item_index(OPTION_SELECT), get_icon("ActionCopy", "EditorIcons")); + p->set_item_icon(p->get_item_index(OPTION_CUT), get_icon("ActionCut", "EditorIcons")); + p->set_item_icon(p->get_item_index(OPTION_COPY), get_icon("Duplicate", "EditorIcons")); p->set_item_icon(p->get_item_index(OPTION_ERASE_SELECTION), get_icon("Remove", "EditorIcons")); } break; @@ -119,12 +119,12 @@ void TileMapEditor::_menu_option(int p_option) { canvas_item_editor->update(); } break; - case OPTION_DUPLICATE: { + case OPTION_COPY: { _update_copydata(); if (selection_active) { - tool = TOOL_DUPLICATING; + tool = TOOL_PASTING; canvas_item_editor->update(); } @@ -135,12 +135,7 @@ void TileMapEditor::_menu_option(int p_option) { return; _start_undo(TTR("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); - } - } + _erase_selection(); _finish_undo(); selection_active = false; @@ -157,11 +152,19 @@ void TileMapEditor::_menu_option(int p_option) { undo_redo->commit_action(); } break; - case OPTION_MOVE: { + case OPTION_CUT: { if (selection_active) { _update_copydata(); - tool = TOOL_MOVING; + + _start_undo(TTR("Cut Selection")); + _erase_selection(); + _finish_undo(); + + selection_active = false; + + tool = TOOL_PASTING; + canvas_item_editor->update(); } } break; @@ -669,6 +672,18 @@ void TileMapEditor::_select(const Point2i &p_from, const Point2i &p_to) { canvas_item_editor->update(); } +void TileMapEditor::_erase_selection() { + 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++) { + + _set_cell(Point2i(j, i), invalid_cell, false, false, false); + } + } +} + void TileMapEditor::_draw_cell(int p_cell, const Point2i &p_point, bool p_flip_h, bool p_flip_v, bool p_transpose, const Transform2D &p_xform) { Ref<Texture> t = node->get_tileset()->tile_get_texture(p_cell); @@ -980,12 +995,12 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { canvas_item_editor->update(); } - } else if (tool == TOOL_DUPLICATING) { + } else if (tool == TOOL_PASTING) { Point2 ofs = over_tile - rectangle.position; Vector<int> ids; - _start_undo(TTR("Duplicate")); + _start_undo(TTR("Paste")); ids.push_back(0); for (List<TileData>::Element *E = copydata.front(); E; E = E->next()) { @@ -994,34 +1009,9 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { } _finish_undo(); - copydata.clear(); - - canvas_item_editor->update(); - } else if (tool == TOOL_MOVING) { - - Point2 ofs = over_tile - rectangle.position; - Vector<int> ids; - - _start_undo(TTR("Move")); - ids.push_back(TileMap::INVALID_CELL); - 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, false, false, false); - } - } - 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); - } - _finish_undo(); - - copydata.clear(); - selection_active = false; - canvas_item_editor->update(); + return true; // We want to keep the Pasting tool } else if (tool == TOOL_SELECTING) { canvas_item_editor->update(); @@ -1068,17 +1058,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { return true; } - if (tool == TOOL_DUPLICATING) { - - tool = TOOL_NONE; - copydata.clear(); - - canvas_item_editor->update(); - - return true; - } - - if (tool == TOOL_MOVING) { + if (tool == TOOL_PASTING) { tool = TOOL_NONE; copydata.clear(); @@ -1305,7 +1285,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { if (k->get_scancode() == KEY_ESCAPE) { - if (tool == TOOL_DUPLICATING || tool == TOOL_MOVING) + if (tool == TOOL_PASTING) copydata.clear(); else if (tool == TOOL_SELECTING || selection_active) selection_active = false; @@ -1349,21 +1329,29 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { return true; } - if (ED_IS_SHORTCUT("tile_map_editor/duplicate_selection", p_event)) { + if (ED_IS_SHORTCUT("tile_map_editor/copy_selection", p_event)) { _update_copydata(); if (selection_active) { - tool = TOOL_DUPLICATING; + tool = TOOL_PASTING; canvas_item_editor->update(); return true; } } - if (ED_IS_SHORTCUT("tile_map_editor/move_selection", p_event)) { + if (ED_IS_SHORTCUT("tile_map_editor/cut_selection", p_event)) { if (selection_active) { _update_copydata(); - tool = TOOL_MOVING; + + _start_undo(TTR("Cut Selection")); + _erase_selection(); + _finish_undo(); + + selection_active = false; + + tool = TOOL_PASTING; + canvas_item_editor->update(); return true; } @@ -1564,7 +1552,7 @@ void TileMapEditor::forward_draw_over_viewport(Control *p_overlay) { _draw_cell(ids[0], Point2i(j, i), flip_h, flip_v, transpose, xform); } } - } else if (tool == TOOL_DUPLICATING || tool == TOOL_MOVING) { + } else if (tool == TOOL_PASTING) { if (copydata.empty()) return; @@ -1844,8 +1832,8 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { p->add_item(TTR("Pick Tile"), OPTION_PICK_TILE, KEY_CONTROL); p->add_separator(); p->add_shortcut(ED_SHORTCUT("tile_map_editor/select", TTR("Select"), KEY_MASK_CMD + KEY_B), OPTION_SELECT); - p->add_shortcut(ED_SHORTCUT("tile_map_editor/move_selection", TTR("Move Selection"), KEY_MASK_CMD + KEY_M), OPTION_MOVE); - p->add_shortcut(ED_SHORTCUT("tile_map_editor/duplicate_selection", TTR("Duplicate Selection"), KEY_MASK_CMD + KEY_D), OPTION_DUPLICATE); + p->add_shortcut(ED_SHORTCUT("tile_map_editor/cut_selection", TTR("Cut Selection"), KEY_MASK_CMD + KEY_X), OPTION_CUT); + p->add_shortcut(ED_SHORTCUT("tile_map_editor/copy_selection", TTR("Copy Selection"), KEY_MASK_CMD + KEY_C), OPTION_COPY); p->add_shortcut(ED_GET_SHORTCUT("tile_map_editor/erase_selection"), OPTION_ERASE_SELECTION); p->add_separator(); p->add_item(TTR("Fix Invalid Tiles"), OPTION_FIX_INVALID); @@ -1903,6 +1891,7 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { TileMapEditor::~TileMapEditor() { _clear_bucket_cache(); + copydata.clear(); } /////////////////////////////////////////////////////////////// diff --git a/editor/plugins/tile_map_editor_plugin.h b/editor/plugins/tile_map_editor_plugin.h index d72224263a..c824824d56 100644 --- a/editor/plugins/tile_map_editor_plugin.h +++ b/editor/plugins/tile_map_editor_plugin.h @@ -61,8 +61,7 @@ class TileMapEditor : public VBoxContainer { TOOL_SELECTING, TOOL_BUCKET, TOOL_PICKING, - TOOL_DUPLICATING, - TOOL_MOVING + TOOL_PASTING }; enum Options { @@ -70,11 +69,11 @@ class TileMapEditor : public VBoxContainer { OPTION_BUCKET, OPTION_PICK_TILE, OPTION_SELECT, - OPTION_DUPLICATE, + OPTION_COPY, OPTION_ERASE_SELECTION, OPTION_PAINTING, OPTION_FIX_INVALID, - OPTION_MOVE + OPTION_CUT }; TileMap *node; @@ -167,6 +166,7 @@ class TileMapEditor : public VBoxContainer { void _erase_points(const PoolVector<Vector2> p_points); void _select(const Point2i &p_from, const Point2i &p_to); + void _erase_selection(); void _draw_cell(int p_cell, const Point2i &p_point, bool p_flip_h, bool p_flip_v, bool p_transpose, const Transform2D &p_xform); void _draw_fill_preview(int p_cell, const Point2i &p_point, bool p_flip_h, bool p_flip_v, bool p_transpose, const Transform2D &p_xform); |