Merge pull request #19127 from marcelofg55/set_cell_undo
Improve TileMap undo operations
This commit is contained in:
commit
5e04dcd616
2 changed files with 11 additions and 16 deletions
|
@ -133,14 +133,12 @@ void TileMapEditor::_menu_option(int p_option) {
|
|||
return;
|
||||
|
||||
undo_redo->create_action(TTR("Erase Selection"));
|
||||
undo_redo->add_undo_method(node, "set", "tile_data", node->get("tile_data"));
|
||||
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), TileMap::INVALID_CELL, false, false, false);
|
||||
}
|
||||
}
|
||||
undo_redo->add_do_method(node, "set", "tile_data", node->get("tile_data"));
|
||||
undo_redo->commit_action();
|
||||
|
||||
selection_active = false;
|
||||
|
@ -200,6 +198,15 @@ void TileMapEditor::set_selected_tile(int p_tile) {
|
|||
}
|
||||
}
|
||||
|
||||
void TileMapEditor::_create_set_cell_undo(const Point2i &p_pos, int p_value, bool p_flip_h, bool p_flip_v, bool p_transpose) {
|
||||
int prev_id = node->get_cell(p_pos.x, p_pos.y);
|
||||
bool prev_flip_h = node->is_cell_x_flipped(p_pos.x, p_pos.y);
|
||||
bool prev_flip_v = node->is_cell_y_flipped(p_pos.x, p_pos.y);
|
||||
bool prev_transpose = node->is_cell_transposed(p_pos.x, p_pos.y);
|
||||
undo_redo->add_undo_method(node, "set_cellv", Vector2(p_pos.x, p_pos.y), prev_id, prev_flip_h, prev_flip_v, prev_transpose);
|
||||
undo_redo->add_do_method(node, "set_cellv", Vector2(p_pos.x, p_pos.y), p_value, p_flip_h, p_flip_v, p_transpose);
|
||||
}
|
||||
|
||||
void TileMapEditor::_set_cell(const Point2i &p_pos, int p_value, bool p_flip_h, bool p_flip_v, bool p_transpose) {
|
||||
|
||||
ERR_FAIL_COND(!node);
|
||||
|
@ -213,6 +220,7 @@ void TileMapEditor::_set_cell(const Point2i &p_pos, int p_value, bool p_flip_h,
|
|||
if (p_value == prev_val && p_flip_h == prev_flip_h && p_flip_v == prev_flip_v && p_transpose == prev_transpose)
|
||||
return; //check that it's actually different
|
||||
|
||||
_create_set_cell_undo(p_pos, p_value, p_flip_h, p_flip_v, p_transpose);
|
||||
node->set_cell(p_pos.x, p_pos.y, p_value, p_flip_h, p_flip_v, p_transpose);
|
||||
node->update_bitmask_area(Point2(p_pos));
|
||||
}
|
||||
|
@ -761,7 +769,6 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
|||
tool = TOOL_PAINTING;
|
||||
|
||||
undo_redo->create_action(TTR("Paint TileMap"));
|
||||
undo_redo->add_undo_method(node, "set", "tile_data", node->get("tile_data"));
|
||||
}
|
||||
} else if (tool == TOOL_PICKING) {
|
||||
|
||||
|
@ -785,7 +792,6 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
|||
if (id != TileMap::INVALID_CELL) {
|
||||
|
||||
_set_cell(over_tile, id, flip_h, flip_v, transpose);
|
||||
undo_redo->add_do_method(node, "set", "tile_data", node->get("tile_data"));
|
||||
undo_redo->commit_action();
|
||||
|
||||
paint_undo.clear();
|
||||
|
@ -797,12 +803,10 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
|||
if (id != TileMap::INVALID_CELL) {
|
||||
|
||||
undo_redo->create_action(TTR("Line Draw"));
|
||||
undo_redo->add_undo_method(node, "set", "tile_data", node->get("tile_data"));
|
||||
for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) {
|
||||
|
||||
_set_cell(E->key(), id, flip_h, flip_v, transpose);
|
||||
}
|
||||
undo_redo->add_do_method(node, "set", "tile_data", node->get("tile_data"));
|
||||
undo_redo->commit_action();
|
||||
|
||||
paint_undo.clear();
|
||||
|
@ -816,14 +820,12 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
|||
if (id != TileMap::INVALID_CELL) {
|
||||
|
||||
undo_redo->create_action(TTR("Rectangle Paint"));
|
||||
undo_redo->add_undo_method(node, "set", "tile_data", node->get("tile_data"));
|
||||
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), id, flip_h, flip_v, transpose);
|
||||
}
|
||||
}
|
||||
undo_redo->add_do_method(node, "set", "tile_data", node->get("tile_data"));
|
||||
undo_redo->commit_action();
|
||||
|
||||
canvas_item_editor->update();
|
||||
|
@ -833,12 +835,10 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
|||
Point2 ofs = over_tile - rectangle.position;
|
||||
|
||||
undo_redo->create_action(TTR("Duplicate"));
|
||||
undo_redo->add_undo_method(node, "set", "tile_data", node->get("tile_data"));
|
||||
for (List<TileData>::Element *E = copydata.front(); E; E = E->next()) {
|
||||
|
||||
_set_cell(E->get().pos + ofs, E->get().cell, E->get().flip_h, E->get().flip_v, E->get().transpose);
|
||||
}
|
||||
undo_redo->add_do_method(node, "set", "tile_data", node->get("tile_data"));
|
||||
undo_redo->commit_action();
|
||||
|
||||
copydata.clear();
|
||||
|
@ -849,7 +849,6 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
|||
Point2 ofs = over_tile - rectangle.position;
|
||||
|
||||
undo_redo->create_action(TTR("Move"));
|
||||
undo_redo->add_undo_method(node, "set", "tile_data", node->get("tile_data"));
|
||||
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++) {
|
||||
|
||||
|
@ -860,7 +859,6 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
|||
|
||||
_set_cell(E->get().pos + ofs, E->get().cell, E->get().flip_h, E->get().flip_v, E->get().transpose);
|
||||
}
|
||||
undo_redo->add_do_method(node, "set", "tile_data", node->get("tile_data"));
|
||||
undo_redo->commit_action();
|
||||
|
||||
copydata.clear();
|
||||
|
@ -880,7 +878,6 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
|||
return false;
|
||||
|
||||
undo_redo->create_action(TTR("Bucket Fill"));
|
||||
undo_redo->add_undo_method(node, "set", "tile_data", node->get("tile_data"));
|
||||
|
||||
Dictionary op;
|
||||
op["id"] = get_selected_tile();
|
||||
|
@ -890,7 +887,6 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
|||
|
||||
_fill_points(points, op);
|
||||
|
||||
undo_redo->add_do_method(node, "set", "tile_data", node->get("tile_data"));
|
||||
undo_redo->commit_action();
|
||||
|
||||
// We want to keep the bucket-tool active
|
||||
|
@ -943,7 +939,6 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
|||
Point2 local = node->world_to_map(xform_inv.xform(mb->get_position()));
|
||||
|
||||
undo_redo->create_action(TTR("Erase TileMap"));
|
||||
undo_redo->add_undo_method(node, "set", "tile_data", node->get("tile_data"));
|
||||
|
||||
if (mb->get_shift()) {
|
||||
#ifdef APPLE_STYLE_KEYS
|
||||
|
@ -970,7 +965,6 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
|
|||
} else {
|
||||
if (tool == TOOL_ERASING || tool == TOOL_RECTANGLE_ERASE || tool == TOOL_LINE_ERASE) {
|
||||
|
||||
undo_redo->add_do_method(node, "set", "tile_data", node->get("tile_data"));
|
||||
undo_redo->commit_action();
|
||||
|
||||
if (tool == TOOL_RECTANGLE_ERASE || tool == TOOL_LINE_ERASE) {
|
||||
|
|
|
@ -174,6 +174,7 @@ class TileMapEditor : public VBoxContainer {
|
|||
void _update_palette();
|
||||
void _menu_option(int p_option);
|
||||
|
||||
void _create_set_cell_undo(const Point2i &p_pos, int p_value, bool p_flip_h, bool p_flip_v, bool p_transpose);
|
||||
void _set_cell(const Point2i &p_pos, int p_value, bool p_flip_h = false, bool p_flip_v = false, bool p_transpose = false);
|
||||
|
||||
void _canvas_mouse_enter();
|
||||
|
|
Loading…
Reference in a new issue