summaryrefslogtreecommitdiff
path: root/tools/editor
diff options
context:
space:
mode:
Diffstat (limited to 'tools/editor')
-rw-r--r--tools/editor/icons/icon_rotate_0.pngbin0 -> 207 bytes
-rw-r--r--tools/editor/icons/icon_rotate_180.pngbin0 -> 303 bytes
-rw-r--r--tools/editor/icons/icon_rotate_270.pngbin0 -> 343 bytes
-rw-r--r--tools/editor/icons/icon_rotate_90.pngbin0 -> 256 bytes
-rw-r--r--tools/editor/icons/icon_transpose.pngbin0 -> 244 bytes
-rw-r--r--tools/editor/plugins/tile_map_editor_plugin.cpp145
-rw-r--r--tools/editor/plugins/tile_map_editor_plugin.h13
7 files changed, 136 insertions, 22 deletions
diff --git a/tools/editor/icons/icon_rotate_0.png b/tools/editor/icons/icon_rotate_0.png
new file mode 100644
index 0000000000..85a4b4c420
--- /dev/null
+++ b/tools/editor/icons/icon_rotate_0.png
Binary files differ
diff --git a/tools/editor/icons/icon_rotate_180.png b/tools/editor/icons/icon_rotate_180.png
new file mode 100644
index 0000000000..c4c516cff5
--- /dev/null
+++ b/tools/editor/icons/icon_rotate_180.png
Binary files differ
diff --git a/tools/editor/icons/icon_rotate_270.png b/tools/editor/icons/icon_rotate_270.png
new file mode 100644
index 0000000000..6e0f2e62b8
--- /dev/null
+++ b/tools/editor/icons/icon_rotate_270.png
Binary files differ
diff --git a/tools/editor/icons/icon_rotate_90.png b/tools/editor/icons/icon_rotate_90.png
new file mode 100644
index 0000000000..f25b0e99a3
--- /dev/null
+++ b/tools/editor/icons/icon_rotate_90.png
Binary files differ
diff --git a/tools/editor/icons/icon_transpose.png b/tools/editor/icons/icon_transpose.png
new file mode 100644
index 0000000000..f9b78bc0fd
--- /dev/null
+++ b/tools/editor/icons/icon_transpose.png
Binary files differ
diff --git a/tools/editor/plugins/tile_map_editor_plugin.cpp b/tools/editor/plugins/tile_map_editor_plugin.cpp
index ce5ea58124..1dcf948505 100644
--- a/tools/editor/plugins/tile_map_editor_plugin.cpp
+++ b/tools/editor/plugins/tile_map_editor_plugin.cpp
@@ -34,7 +34,7 @@
#include "os/file_access.h"
#include "tools/editor/editor_settings.h"
#include "os/input.h"
-
+#include "method_bind_ext.inc"
void TileMapEditor::_notification(int p_what) {
@@ -44,6 +44,11 @@ void TileMapEditor::_notification(int p_what) {
mirror_x->set_icon( get_icon("MirrorX","EditorIcons"));
mirror_y->set_icon( get_icon("MirrorY","EditorIcons"));
+ transpose->set_icon( get_icon("Transpose","EditorIcons"));
+ rotate_0->set_icon( get_icon("Rotate0","EditorIcons"));
+ rotate_90->set_icon( get_icon("Rotate90","EditorIcons"));
+ rotate_180->set_icon( get_icon("Rotate180","EditorIcons"));
+ rotate_270->set_icon( get_icon("Rotate270","EditorIcons"));
} break;
}
@@ -85,24 +90,30 @@ void TileMapEditor::set_selected_tile(int p_tile) {
}
}
-void TileMapEditor::_set_cell(const Point2i& p_pos,int p_value,bool p_flip_h, bool p_flip_v,bool p_with_undo) {
+void TileMapEditor::_set_cell_shortened(const Point2& p_pos,int p_value,bool p_flip_h, bool p_flip_v, bool p_transpose) {
+ ERR_FAIL_COND(!node);
+ node->set_cell(floor(p_pos.x), floor(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,bool p_with_undo) {
ERR_FAIL_COND(!node);
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);
int prev_val=node->get_cell(p_pos.x,p_pos.y);
- if (p_value==prev_val && p_flip_h==prev_flip_h && p_flip_v==prev_flip_v)
+ 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
if (p_with_undo) {
- undo_redo->add_do_method(node,"set_cell",p_pos.x,p_pos.y,p_value,p_flip_h,p_flip_v);
- undo_redo->add_undo_method(node,"set_cell",p_pos.x,p_pos.y,prev_val,prev_flip_h,prev_flip_v);
+ undo_redo->add_do_method(this,"_set_cell_shortened",Point2(p_pos),p_value,p_flip_h,p_flip_v,p_transpose);
+ undo_redo->add_undo_method(this,"_set_cell_shortened",Point2(p_pos),prev_val,prev_flip_h,prev_flip_v,prev_transpose);
} else {
- node->set_cell(p_pos.x,p_pos.y,p_value,p_flip_h,p_flip_v);
+ node->set_cell(p_pos.x,p_pos.y,p_value,p_flip_h,p_flip_v,p_transpose);
}
@@ -168,6 +179,7 @@ struct _TileMapEditorCopyData {
int cell;
bool flip_h;
bool flip_v;
+ bool transpose;
};
bool TileMapEditor::forward_input_event(const InputEvent& p_event) {
@@ -204,6 +216,7 @@ bool TileMapEditor::forward_input_event(const InputEvent& p_event) {
tcd.cell=node->get_cell(j,i);
tcd.flip_h=node->is_cell_x_flipped(j,i);
tcd.flip_v=node->is_cell_y_flipped(j,i);
+ tcd.transpose=node->is_cell_transposed(j,i);
dupdata.push_back(tcd);
@@ -214,7 +227,7 @@ bool TileMapEditor::forward_input_event(const InputEvent& p_event) {
for (List<_TileMapEditorCopyData>::Element *E=dupdata.front();E;E=E->next()) {
- _set_cell(E->get().pos+ofs,E->get().cell,E->get().flip_h,E->get().flip_v,true);
+ _set_cell(E->get().pos+ofs,E->get().cell,E->get().flip_h,E->get().flip_v,E->get().transpose,true);
}
undo_redo->commit_action();
@@ -239,6 +252,10 @@ bool TileMapEditor::forward_input_event(const InputEvent& p_event) {
} else if (mb.mod.control) {
tool=TOOL_PICKING;
set_selected_tile(node->get_cell(over_tile.x, over_tile.y));
+ mirror_x->set_pressed(node->is_cell_x_flipped(over_tile.x, over_tile.y));
+ mirror_y->set_pressed(node->is_cell_y_flipped(over_tile.x, over_tile.y));
+ transpose->set_pressed(node->is_cell_transposed(over_tile.x, over_tile.y));
+ _update_transform_buttons();
canvas_item_editor->update();
return true;
} else {
@@ -248,7 +265,7 @@ bool TileMapEditor::forward_input_event(const InputEvent& p_event) {
Point2i local =node->world_to_map((xform_inv.xform(Point2(mb.x,mb.y))));
paint_undo.clear();
paint_undo[local]=_get_op_from_cell(local);
- node->set_cell(local.x,local.y,id,mirror_x->is_pressed(),mirror_y->is_pressed());
+ node->set_cell(local.x,local.y,id,mirror_x->is_pressed(),mirror_y->is_pressed(),transpose->is_pressed());
return true;
}
}
@@ -263,8 +280,8 @@ bool TileMapEditor::forward_input_event(const InputEvent& p_event) {
for(Map<Point2i,CellOp>::Element *E=paint_undo.front();E;E=E->next()) {
Point2i p=E->key();
- undo_redo->add_do_method(node,"set_cell",p.x,p.y,node->get_cell(p.x,p.y),node->is_cell_x_flipped(p.x,p.y),node->is_cell_y_flipped(p.x,p.y));
- undo_redo->add_undo_method(node,"set_cell",p.x,p.y,E->get().idx,E->get().xf,E->get().yf);
+ undo_redo->add_do_method(this,"_set_cell_shortened",Point2(p),node->get_cell(p.x,p.y),node->is_cell_x_flipped(p.x,p.y),node->is_cell_y_flipped(p.x,p.y),node->is_cell_transposed(p.x,p.y));
+ undo_redo->add_undo_method(this,"_set_cell_shortened",Point2(p),E->get().idx,E->get().xf,E->get().yf,E->get().tr);
}
undo_redo->commit_action();
@@ -289,7 +306,7 @@ bool TileMapEditor::forward_input_event(const InputEvent& p_event) {
Point2i local =node->world_to_map(xform_inv.xform(Point2(mb.x,mb.y)));
paint_undo.clear();
paint_undo[local]=_get_op_from_cell(local);
- //node->set_cell(local.x,local.y,id,mirror_x->is_pressed(),mirror_y->is_pressed());
+ //node->set_cell(local.x,local.y,id,mirror_x->is_pressed(),mirror_y->is_pressed(),transpose->is_pressed());
//return true;
_set_cell(local,TileMap::INVALID_CELL);
return true;
@@ -302,9 +319,9 @@ bool TileMapEditor::forward_input_event(const InputEvent& p_event) {
for(Map<Point2i,CellOp>::Element *E=paint_undo.front();E;E=E->next()) {
Point2i p=E->key();
- //undo_redo->add_do_method(node,"set_cell",p.x,p.y,node->get_cell(p.x,p.y),node->is_cell_x_flipped(p.x,p.y),node->is_cell_y_flipped(p.x,p.y));
- _set_cell(p,TileMap::INVALID_CELL,false,false,true);
- undo_redo->add_undo_method(node,"set_cell",p.x,p.y,E->get().idx,E->get().xf,E->get().yf);
+ //undo_redo->add_do_method(node,"set_cell",p.x,p.y,node->get_cell(p.x,p.y),node->is_cell_x_flipped(p.x,p.y),node->is_cell_y_flipped(p.x,p.y),node->is_cell_transposed(p.x,p.y));
+ _set_cell(p,TileMap::INVALID_CELL,false,false,false,true);
+ undo_redo->add_undo_method(this,"_set_cell_shortened",Point2(p),E->get().idx,E->get().xf,E->get().yf,E->get().tr);
}
undo_redo->commit_action();
@@ -340,7 +357,7 @@ bool TileMapEditor::forward_input_event(const InputEvent& p_event) {
paint_undo[over_tile]=_get_op_from_cell(over_tile);
}
- node->set_cell(over_tile.x,over_tile.y,id,mirror_x->is_pressed(),mirror_y->is_pressed());
+ node->set_cell(over_tile.x,over_tile.y,id,mirror_x->is_pressed(),mirror_y->is_pressed(),transpose->is_pressed());
return true;
}
@@ -373,13 +390,17 @@ bool TileMapEditor::forward_input_event(const InputEvent& p_event) {
if (!paint_undo.has(over_tile)) {
paint_undo[over_tile]=_get_op_from_cell(over_tile);
}
- //node->set_cell(over_tile.x,over_tile.y,id,mirror_x->is_pressed(),mirror_y->is_pressed());
+ //node->set_cell(over_tile.x,over_tile.y,id,mirror_x->is_pressed(),mirror_y->is_pressed(),transpose->is_pressed());
_set_cell(local,TileMap::INVALID_CELL);
return true;
}
if (tool==TOOL_PICKING) {
set_selected_tile(node->get_cell(over_tile.x, over_tile.y));
+ mirror_x->set_pressed(node->is_cell_x_flipped(over_tile.x, over_tile.y));
+ mirror_y->set_pressed(node->is_cell_y_flipped(over_tile.x, over_tile.y));
+ transpose->set_pressed(node->is_cell_transposed(over_tile.x, over_tile.y));
+ _update_transform_buttons();
canvas_item_editor->update();
return true;
}
@@ -627,10 +648,10 @@ void TileMapEditor::_canvas_draw() {
sc.y*=-1.0;
if (r==Rect2()) {
- canvas_item_editor->draw_texture_rect(t,Rect2(from,t->get_size()*sc),false,Color(1,1,1,0.5));
+ canvas_item_editor->draw_texture_rect(t,Rect2(from,t->get_size()*sc),false,Color(1,1,1,0.5),transpose->is_pressed());
} else {
- canvas_item_editor->draw_texture_rect_region(t,Rect2(from,r.get_size()*sc),r,Color(1,1,1,0.5));
+ canvas_item_editor->draw_texture_rect_region(t,Rect2(from,r.get_size()*sc),r,Color(1,1,1,0.5),transpose->is_pressed());
}
}
}
@@ -697,6 +718,8 @@ void TileMapEditor::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_canvas_mouse_enter"),&TileMapEditor::_canvas_mouse_enter);
ObjectTypeDB::bind_method(_MD("_canvas_mouse_exit"),&TileMapEditor::_canvas_mouse_exit);
ObjectTypeDB::bind_method(_MD("_tileset_settings_changed"),&TileMapEditor::_tileset_settings_changed);
+ ObjectTypeDB::bind_method(_MD("_update_transform_buttons"),&TileMapEditor::_update_transform_buttons);
+ ObjectTypeDB::bind_method(_MD("_set_cell_shortened","pos","tile","flip_x","flip_y","transpose"),&TileMapEditor::_set_cell_shortened,DEFVAL(false),DEFVAL(false),DEFVAL(false));
}
@@ -709,10 +732,60 @@ TileMapEditor::CellOp TileMapEditor::_get_op_from_cell(const Point2i& p_pos)
op.xf=true;
if (node->is_cell_y_flipped(p_pos.x,p_pos.y))
op.yf=true;
+ if (node->is_cell_transposed(p_pos.x,p_pos.y))
+ op.tr=true;
}
return op;
}
+void TileMapEditor::_update_transform_buttons(Object *p_button) {
+ //ERR_FAIL_NULL(p_button);
+ ToolButton *b=p_button->cast_to<ToolButton>();
+ //ERR_FAIL_COND(!b);
+
+ mirror_x->set_block_signals(true);
+ mirror_y->set_block_signals(true);
+ transpose->set_block_signals(true);
+ rotate_0->set_block_signals(true);
+ rotate_90->set_block_signals(true);
+ rotate_180->set_block_signals(true);
+ rotate_270->set_block_signals(true);
+
+ if (b == rotate_0) {
+ mirror_x->set_pressed(false);
+ mirror_y->set_pressed(false);
+ transpose->set_pressed(false);
+ }
+ else if (b == rotate_90) {
+ mirror_x->set_pressed(false);
+ mirror_y->set_pressed(true);
+ transpose->set_pressed(true);
+ }
+ else if (b == rotate_180) {
+ mirror_x->set_pressed(true);
+ mirror_y->set_pressed(true);
+ transpose->set_pressed(false);
+ }
+ else if (b == rotate_270) {
+ mirror_x->set_pressed(true);
+ mirror_y->set_pressed(false);
+ transpose->set_pressed(true);
+ }
+
+ rotate_0->set_pressed(!mirror_x->is_pressed() && !mirror_y->is_pressed() && !transpose->is_pressed());
+ rotate_90->set_pressed(!mirror_x->is_pressed() && mirror_y->is_pressed() && transpose->is_pressed());
+ rotate_180->set_pressed(mirror_x->is_pressed() && mirror_y->is_pressed() && !transpose->is_pressed());
+ rotate_270->set_pressed(mirror_x->is_pressed() && !mirror_y->is_pressed() && transpose->is_pressed());
+
+ mirror_x->set_block_signals(false);
+ mirror_y->set_block_signals(false);
+ transpose->set_block_signals(false);
+ rotate_0->set_block_signals(false);
+ rotate_90->set_block_signals(false);
+ rotate_180->set_block_signals(false);
+ rotate_270->set_block_signals(false);
+}
+
TileMapEditor::TileMapEditor(EditorNode *p_editor) {
node=NULL;
@@ -738,14 +811,48 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) {
mirror_x->set_toggle_mode(true);
mirror_x->set_tooltip("Mirror X (A)");
mirror_x->set_focus_mode(FOCUS_NONE);
+ mirror_x->connect("pressed", this, "_update_transform_buttons", make_binds(mirror_x));
canvas_item_editor_hb->add_child(mirror_x);
mirror_y = memnew( ToolButton );
mirror_y->set_toggle_mode(true);
mirror_y->set_tooltip("Mirror Y (S)");
mirror_y->set_focus_mode(FOCUS_NONE);
+ mirror_y->connect("pressed", this, "_update_transform_buttons", make_binds(mirror_y));
canvas_item_editor_hb->add_child(mirror_y);
+ transpose = memnew( ToolButton );
+ transpose->set_toggle_mode(true);
+ transpose->set_tooltip("Transpose");
+ transpose->set_focus_mode(FOCUS_NONE);
+ transpose->connect("pressed", this, "_update_transform_buttons", make_binds(transpose));
+ canvas_item_editor_hb->add_child(transpose);
+ canvas_item_editor_hb->add_child(memnew(VSeparator));
+ rotate_0 = memnew( ToolButton );
+ rotate_0->set_toggle_mode(true);
+ rotate_0->set_tooltip("Rotate 0 degrees");
+ rotate_0->set_focus_mode(FOCUS_NONE);
+ rotate_0->connect("pressed", this, "_update_transform_buttons", make_binds(rotate_0));
+ canvas_item_editor_hb->add_child(rotate_0);
+ rotate_90 = memnew( ToolButton );
+ rotate_90->set_toggle_mode(true);
+ rotate_90->set_tooltip("Rotate 90 degrees");
+ rotate_90->set_focus_mode(FOCUS_NONE);
+ rotate_90->connect("pressed", this, "_update_transform_buttons", make_binds(rotate_90));
+ canvas_item_editor_hb->add_child(rotate_90);
+ rotate_180 = memnew( ToolButton );
+ rotate_180->set_toggle_mode(true);
+ rotate_180->set_tooltip("Rotate 180 degrees");
+ rotate_180->set_focus_mode(FOCUS_NONE);
+ rotate_180->connect("pressed", this, "_update_transform_buttons", make_binds(rotate_180));
+ canvas_item_editor_hb->add_child(rotate_180);
+ rotate_270 = memnew( ToolButton );
+ rotate_270->set_toggle_mode(true);
+ rotate_270->set_tooltip("Rotate 270 degrees");
+ rotate_270->set_focus_mode(FOCUS_NONE);
+ rotate_270->connect("pressed", this, "_update_transform_buttons", make_binds(rotate_270));
+ canvas_item_editor_hb->add_child(rotate_270);
canvas_item_editor_hb->hide();
-
+
+ rotate_0->set_pressed(true);
tool=TOOL_NONE;
selection_active=false;
mouse_over=false;
diff --git a/tools/editor/plugins/tile_map_editor_plugin.h b/tools/editor/plugins/tile_map_editor_plugin.h
index f3c590e228..525315a8f1 100644
--- a/tools/editor/plugins/tile_map_editor_plugin.h
+++ b/tools/editor/plugins/tile_map_editor_plugin.h
@@ -73,6 +73,11 @@ class TileMapEditor : public VBoxContainer {
Label *mirror_label;
ToolButton *mirror_x;
ToolButton *mirror_y;
+ ToolButton *transpose;
+ ToolButton *rotate_0;
+ ToolButton *rotate_90;
+ ToolButton *rotate_180;
+ ToolButton *rotate_270;
HBoxContainer *canvas_item_editor_hb;
@@ -81,8 +86,8 @@ class TileMapEditor : public VBoxContainer {
int idx;
bool xf;
bool yf;
- CellOp() { idx=-1; xf=false; yf=false; }
- CellOp(const CellOp& p_other) : idx(p_other.idx), xf(p_other.xf), yf(p_other.yf) {}
+ bool tr;
+ CellOp() { idx=-1; xf=false; yf=false; tr=false; }
};
Map<Point2i,CellOp> paint_undo;
@@ -94,7 +99,8 @@ class TileMapEditor : public VBoxContainer {
void _canvas_draw();
void _menu_option(int p_option);
- void _set_cell(const Point2i& p_pos, int p_value, bool p_flip_h=false, bool p_flip_v=false, bool p_with_undo=false);
+ void _set_cell(const Point2i& p_pos, int p_value, bool p_flip_h=false, bool p_flip_v=false, bool p_transpose=false, bool p_with_undo=false);
+ void _set_cell_shortened(const Point2& p_pos, int p_value, bool p_flip_h=false, bool p_flip_v=false, bool p_transpose=false);
void _canvas_mouse_enter();
void _canvas_mouse_exit();
@@ -106,6 +112,7 @@ protected:
void _node_removed(Node *p_node);
static void _bind_methods();
CellOp _get_op_from_cell(const Point2i& p_pos);
+ void _update_transform_buttons(Object *p_button=0);
public:
HBoxContainer *get_canvas_item_editor_hb() const { return canvas_item_editor_hb; }