Skip to content

Commit

Permalink
Merge pull request #22715 from groud/fix_tilemap_editor
Browse files Browse the repository at this point in the history
Fixes tilemap editor offset tile selection
  • Loading branch information
akien-mga committed Oct 4, 2018
2 parents 10718b0 + c7725aa commit 8068d02
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 47 deletions.
92 changes: 46 additions & 46 deletions editor/plugins/tile_map_editor_plugin.cpp
Expand Up @@ -43,8 +43,8 @@ void TileMapEditor::_notification(int p_what) {

case NOTIFICATION_PROCESS: {

if (bucket_queue.size() && canvas_item_editor) {
canvas_item_editor->update();
if (bucket_queue.size() && canvas_item_editor_viewport) {
canvas_item_editor_viewport->update();
}

} break;
Expand Down Expand Up @@ -97,27 +97,27 @@ void TileMapEditor::_menu_option(int p_option) {
// immediately without pressing the left mouse button first
tool = TOOL_NONE;

canvas_item_editor->update();
canvas_item_editor_viewport->update();

} break;
case OPTION_BUCKET: {

tool = TOOL_BUCKET;

canvas_item_editor->update();
canvas_item_editor_viewport->update();
} break;
case OPTION_PICK_TILE: {

tool = TOOL_PICKING;

canvas_item_editor->update();
canvas_item_editor_viewport->update();
} break;
case OPTION_SELECT: {

tool = TOOL_SELECTING;
selection_active = false;

canvas_item_editor->update();
canvas_item_editor_viewport->update();
} break;
case OPTION_COPY: {

Expand All @@ -126,7 +126,7 @@ void TileMapEditor::_menu_option(int p_option) {
if (selection_active) {
tool = TOOL_PASTING;

canvas_item_editor->update();
canvas_item_editor_viewport->update();
}
} break;
case OPTION_ERASE_SELECTION: {
Expand All @@ -141,7 +141,7 @@ void TileMapEditor::_menu_option(int p_option) {
selection_active = false;
copydata.clear();

canvas_item_editor->update();
canvas_item_editor_viewport->update();
} break;
case OPTION_FIX_INVALID: {

Expand All @@ -165,7 +165,7 @@ void TileMapEditor::_menu_option(int p_option) {

tool = TOOL_PASTING;

canvas_item_editor->update();
canvas_item_editor_viewport->update();
}
} break;
}
Expand All @@ -182,13 +182,13 @@ void TileMapEditor::_palette_multi_selected(int index, bool selected) {
void TileMapEditor::_canvas_mouse_enter() {

mouse_over = true;
canvas_item_editor->update();
canvas_item_editor_viewport->update();
}

void TileMapEditor::_canvas_mouse_exit() {

mouse_over = false;
canvas_item_editor->update();
canvas_item_editor_viewport->update();
}

Vector<int> TileMapEditor::get_selected_tiles() const {
Expand Down Expand Up @@ -318,7 +318,7 @@ void TileMapEditor::_manual_toggled(bool p_enabled) {

void TileMapEditor::_text_entered(const String &p_text) {

canvas_item_editor->grab_focus();
canvas_item_editor_viewport->grab_focus();
}

void TileMapEditor::_text_changed(const String &p_text) {
Expand Down Expand Up @@ -524,7 +524,7 @@ void TileMapEditor::_pick_tile(const Point2 &p_pos) {
transp->set_pressed(node->is_cell_transposed(p_pos.x, p_pos.y));

_update_transform_buttons();
canvas_item_editor->update();
canvas_item_editor_viewport->update();
}

PoolVector<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool erase, bool preview) {
Expand Down Expand Up @@ -671,7 +671,7 @@ void TileMapEditor::_select(const Point2i &p_from, const Point2i &p_to) {
rectangle.position = begin;
rectangle.size = end - begin;

canvas_item_editor->update();
canvas_item_editor_viewport->update();
}

void TileMapEditor::_erase_selection() {
Expand Down Expand Up @@ -882,7 +882,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
if (!node || !node->get_tileset().is_valid() || !node->is_visible_in_tree())
return false;

Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
Transform2D xform = CanvasItemEditor::get_singleton()->get_canvas_transform() * node->get_global_transform();
Transform2D xform_inv = xform.affine_inverse();

Ref<InputEventMouseButton> mb = p_event;
Expand Down Expand Up @@ -978,7 +978,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {

paint_undo.clear();

canvas_item_editor->update();
canvas_item_editor_viewport->update();
}
} else if (tool == TOOL_RECTANGLE_PAINT) {

Expand All @@ -995,7 +995,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
}
_finish_undo();

canvas_item_editor->update();
canvas_item_editor_viewport->update();
}
} else if (tool == TOOL_PASTING) {

Expand All @@ -1011,12 +1011,12 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
}
_finish_undo();

canvas_item_editor->update();
canvas_item_editor_viewport->update();

return true; // We want to keep the Pasting tool
} else if (tool == TOOL_SELECTING) {

canvas_item_editor->update();
canvas_item_editor_viewport->update();

} else if (tool == TOOL_BUCKET) {

Expand Down Expand Up @@ -1055,7 +1055,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
tool = TOOL_NONE;
selection_active = false;

canvas_item_editor->update();
canvas_item_editor_viewport->update();

return true;
}
Expand All @@ -1065,7 +1065,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
tool = TOOL_NONE;
copydata.clear();

canvas_item_editor->update();
canvas_item_editor_viewport->update();

return true;
}
Expand Down Expand Up @@ -1106,7 +1106,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
_finish_undo();

if (tool == TOOL_RECTANGLE_ERASE || tool == TOOL_LINE_ERASE) {
canvas_item_editor->update();
canvas_item_editor_viewport->update();
}

tool = TOOL_NONE;
Expand Down Expand Up @@ -1149,7 +1149,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
if (new_over_tile != over_tile) {

over_tile = new_over_tile;
canvas_item_editor->update();
canvas_item_editor_viewport->update();
}

if (show_tile_info) {
Expand Down Expand Up @@ -1235,7 +1235,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
_set_cell(points[i], invalid_cell);
}

canvas_item_editor->update();
canvas_item_editor_viewport->update();
}

return true;
Expand Down Expand Up @@ -1294,7 +1294,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {

tool = TOOL_NONE;

canvas_item_editor->update();
canvas_item_editor_viewport->update();

return true;
}
Expand All @@ -1308,13 +1308,13 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
// NOTE: We do not set tool = TOOL_PAINTING as this begins painting
// immediately without pressing the left mouse button first
tool = TOOL_NONE;
canvas_item_editor->update();
canvas_item_editor_viewport->update();

return true;
}
if (ED_IS_SHORTCUT("tile_map_editor/bucket_fill", p_event)) {
tool = TOOL_BUCKET;
canvas_item_editor->update();
canvas_item_editor_viewport->update();

return true;
}
Expand All @@ -1327,7 +1327,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
tool = TOOL_SELECTING;
selection_active = false;

canvas_item_editor->update();
canvas_item_editor_viewport->update();

return true;
}
Expand All @@ -1337,7 +1337,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
if (selection_active) {
tool = TOOL_PASTING;

canvas_item_editor->update();
canvas_item_editor_viewport->update();

return true;
}
Expand All @@ -1354,7 +1354,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {

tool = TOOL_PASTING;

canvas_item_editor->update();
canvas_item_editor_viewport->update();
return true;
}
}
Expand All @@ -1368,21 +1368,21 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
flip_h = !flip_h;
mirror_x->set_pressed(flip_h);
_update_transform_buttons();
canvas_item_editor->update();
canvas_item_editor_viewport->update();
return true;
}
if (ED_IS_SHORTCUT("tile_map_editor/mirror_y", p_event)) {
flip_v = !flip_v;
mirror_y->set_pressed(flip_v);
_update_transform_buttons();
canvas_item_editor->update();
canvas_item_editor_viewport->update();
return true;
}
if (ED_IS_SHORTCUT("tile_map_editor/transpose", p_event)) {
transpose = !transpose;
transp->set_pressed(transpose);
_update_transform_buttons();
canvas_item_editor->update();
canvas_item_editor_viewport->update();
return true;
}
}
Expand Down Expand Up @@ -1607,29 +1607,29 @@ void TileMapEditor::edit(Node *p_tile_map) {

search_box->set_text("");

if (!canvas_item_editor) {
canvas_item_editor = CanvasItemEditor::get_singleton()->get_viewport_control();
if (!canvas_item_editor_viewport) {
canvas_item_editor_viewport = CanvasItemEditor::get_singleton()->get_viewport_control();
}

if (node)
node->disconnect("settings_changed", this, "_tileset_settings_changed");
if (p_tile_map) {

node = Object::cast_to<TileMap>(p_tile_map);
if (!canvas_item_editor->is_connected("mouse_entered", this, "_canvas_mouse_enter"))
canvas_item_editor->connect("mouse_entered", this, "_canvas_mouse_enter");
if (!canvas_item_editor->is_connected("mouse_exited", this, "_canvas_mouse_exit"))
canvas_item_editor->connect("mouse_exited", this, "_canvas_mouse_exit");
if (!canvas_item_editor_viewport->is_connected("mouse_entered", this, "_canvas_mouse_enter"))
canvas_item_editor_viewport->connect("mouse_entered", this, "_canvas_mouse_enter");
if (!canvas_item_editor_viewport->is_connected("mouse_exited", this, "_canvas_mouse_exit"))
canvas_item_editor_viewport->connect("mouse_exited", this, "_canvas_mouse_exit");

_update_palette();

} else {
node = NULL;

if (canvas_item_editor->is_connected("mouse_entered", this, "_canvas_mouse_enter"))
canvas_item_editor->disconnect("mouse_entered", this, "_canvas_mouse_enter");
if (canvas_item_editor->is_connected("mouse_exited", this, "_canvas_mouse_exit"))
canvas_item_editor->disconnect("mouse_exited", this, "_canvas_mouse_exit");
if (canvas_item_editor_viewport->is_connected("mouse_entered", this, "_canvas_mouse_enter"))
canvas_item_editor_viewport->disconnect("mouse_entered", this, "_canvas_mouse_enter");
if (canvas_item_editor_viewport->is_connected("mouse_exited", this, "_canvas_mouse_exit"))
canvas_item_editor_viewport->disconnect("mouse_exited", this, "_canvas_mouse_exit");

_update_palette();
}
Expand All @@ -1644,8 +1644,8 @@ void TileMapEditor::_tileset_settings_changed() {

_update_palette();

if (canvas_item_editor)
canvas_item_editor->update();
if (canvas_item_editor_viewport)
canvas_item_editor_viewport->update();
}

void TileMapEditor::_icon_size_changed(float p_value) {
Expand Down Expand Up @@ -1729,7 +1729,7 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) {
node = NULL;
manual_autotile = false;
manual_position = Vector2(0, 0);
canvas_item_editor = NULL;
canvas_item_editor_viewport = NULL;
editor = p_editor;
undo_redo = editor->get_undo_redo();

Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/tile_map_editor_plugin.h
Expand Up @@ -82,7 +82,7 @@ class TileMapEditor : public VBoxContainer {

EditorNode *editor;
UndoRedo *undo_redo;
Control *canvas_item_editor;
Control *canvas_item_editor_viewport;

LineEdit *search_box;
HSlider *size_slider;
Expand Down

0 comments on commit 8068d02

Please sign in to comment.