summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/editor/plugins/tile_map_editor_plugin.cpp953
-rw-r--r--tools/editor/plugins/tile_map_editor_plugin.h91
2 files changed, 626 insertions, 418 deletions
diff --git a/tools/editor/plugins/tile_map_editor_plugin.cpp b/tools/editor/plugins/tile_map_editor_plugin.cpp
index acacd37f66..a765bc6fe2 100644
--- a/tools/editor/plugins/tile_map_editor_plugin.cpp
+++ b/tools/editor/plugins/tile_map_editor_plugin.cpp
@@ -42,7 +42,7 @@ void TileMapEditor::_notification(int p_what) {
case NOTIFICATION_READY: {
- transpose->set_icon( get_icon("Transpose","EditorIcons"));
+ transp->set_icon( get_icon("Transpose","EditorIcons"));
mirror_x->set_icon( get_icon("MirrorX","EditorIcons"));
mirror_y->set_icon( get_icon("MirrorY","EditorIcons"));
rotate_0->set_icon( get_icon("Rotate0","EditorIcons"));
@@ -52,45 +52,87 @@ void TileMapEditor::_notification(int p_what) {
} break;
}
+}
+
+void TileMapEditor::_menu_option(int p_option) {
+
+ switch(p_option) {
+
+ case OPTION_PICK_TILE: {
+
+ tool=TOOL_PICKING;
+
+ canvas_item_editor->update();
+ } break;
+ case OPTION_SELECT: {
+
+ tool=TOOL_SELECTING;
+ selection_active=false;
+
+ canvas_item_editor->update();
+ } break;
+ case OPTION_DUPLICATE: {
+
+ _update_copydata();
+
+ if (selection_active) {
+ tool=TOOL_DUPLICATING;
+
+ canvas_item_editor->update();
+ }
+ }
+ case OPTION_ERASE_SELECTION: {
+
+ if (!selection_active)
+ return;
+
+ undo_redo->create_action("Erase Selection");
+ for(int i=rectangle.pos.y;i<=rectangle.pos.y+rectangle.size.y;i++) {
+ for(int j=rectangle.pos.x;j<=rectangle.pos.x+rectangle.size.x;j++) {
+
+ _set_cell(Point2i(j, i), TileMap::INVALID_CELL, false, false, false, true);
+ }
+ }
+ undo_redo->commit_action();
+
+ selection_active=false;
+ copydata.clear();
+ canvas_item_editor->update();
+ }
+ }
}
void TileMapEditor::_canvas_mouse_enter() {
mouse_over=true;
canvas_item_editor->update();
-
-
}
void TileMapEditor::_canvas_mouse_exit() {
mouse_over=false;
canvas_item_editor->update();
-
}
int TileMapEditor::get_selected_tile() const {
+
int item = palette->get_current();
+
if (item==-1)
return TileMap::INVALID_CELL;
+
return palette->get_item_metadata(item);
}
void TileMapEditor::set_selected_tile(int p_tile) {
- for (int i = 0; i < palette->get_item_count(); i++) {
- if (palette->get_item_metadata(i).operator int() == p_tile) {
- palette->select(i,true);
- palette->ensure_current_is_visible();
- break;
- }
- }
-}
-// Wrapper to workaround five arg limit of undo/redo methods
-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);
+ int idx = palette->find_metadata(p_tile);
+
+ if (idx >= 0) {
+ palette->select(idx, true);
+ palette->ensure_current_is_visible();
+ }
}
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) {
@@ -105,65 +147,78 @@ void TileMapEditor::_set_cell(const Point2i& p_pos,int p_value,bool p_flip_h, bo
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_cellv",Point2(p_pos),p_value,p_flip_h,p_flip_v,p_transpose);
undo_redo->add_undo_method(node,"set_cellv",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,p_transpose);
-
}
}
-void TileMapEditor::_set_display_mode(int p_mode) {
- if (display_mode == p_mode) {
- return;
- }
+void TileMapEditor::_text_entered(const String& p_text) {
- switch (p_mode) {
- case DISPLAY_THUMBNAIL: {
- button_thumbnail->set_pressed(true);
- button_list->set_pressed(false);
- } break;
- case DISPLAY_LIST: {
- button_thumbnail->set_pressed(false);
- button_list->set_pressed(true);
- } break;
- }
+ canvas_item_editor->grab_focus();
+}
- display_mode = p_mode;
+void TileMapEditor::_text_changed(const String& p_text) {
_update_palette();
}
+void TileMapEditor::_sbox_input(const InputEvent& p_ie) {
+
+ if (p_ie.type==InputEvent::KEY && (
+ p_ie.key.scancode == KEY_UP ||
+ p_ie.key.scancode == KEY_DOWN ||
+ p_ie.key.scancode == KEY_PAGEUP ||
+ p_ie.key.scancode == KEY_PAGEDOWN ) ) {
+
+ palette->call("_input_event", p_ie);
+ search_box->accept_event();
+ }
+}
+
void TileMapEditor::_update_palette() {
if (!node)
return;
+ int selected = get_selected_tile();
palette->clear();
Ref<TileSet> tileset=node->get_tileset();
- if (!tileset.is_valid())
+ if (tileset.is_null())
return;
List<int> tiles;
tileset->get_tile_list(&tiles);
- if (display_mode == DISPLAY_THUMBNAIL) {
- palette->set_max_columns(0);
- palette->set_icon_mode(ItemList::ICON_MODE_TOP);
- } else if (display_mode == DISPLAY_LIST) {
- palette->set_max_columns(1);
- palette->set_icon_mode(ItemList::ICON_MODE_LEFT);
- }
+ if (tiles.empty())
+ return;
+ palette->set_max_columns(0);
+ palette->set_icon_mode(ItemList::ICON_MODE_TOP);
palette->set_max_text_lines(2);
+ String filter = search_box->get_text().strip_edges();
+
for(List<int>::Element *E=tiles.front();E;E=E->next()) {
- palette->add_item("");
+
+ String name;
+
+ if (tileset->tile_get_name(E->get())!="") {
+ name = tileset->tile_get_name(E->get());
+ } else {
+ name = "#"+itos(E->get());
+ }
+
+ if (filter != "" && name.findn(filter) == -1)
+ continue;
+
+ palette->add_item(name);
Ref<Texture> tex = tileset->tile_get_texture(E->get());
@@ -182,50 +237,163 @@ void TileMapEditor::_update_palette() {
}
}
- if (tileset->tile_get_name(E->get())!="") {
- palette->set_item_text(palette->get_item_count()-1, tileset->tile_get_name(E->get()));
- } else {
- palette->set_item_text(palette->get_item_count()-1, "#"+itos(E->get()));
- }
-
palette->set_item_metadata(palette->get_item_count()-1, E->get());
}
+
+ if (selected != -1)
+ set_selected_tile(selected);
+ else
+ palette->select(0, true);
}
-void TileMapEditor::_node_removed(Node *p_node) {
+void TileMapEditor::_pick_tile(const Point2& p_pos) {
- if(p_node==node) {
- node=NULL;
- hide();
+ int id = node->get_cell(p_pos.x, p_pos.y);
+
+ if (id==TileMap::INVALID_CELL)
+ return;
+
+ if (search_box->get_text().strip_edges() != "") {
+
+ search_box->set_text("");
+ _update_palette();
}
+ set_selected_tile(id);
+
+ mirror_x->set_pressed(node->is_cell_x_flipped(p_pos.x, p_pos.y));
+ mirror_y->set_pressed(node->is_cell_y_flipped(p_pos.x, p_pos.y));
+ transp->set_pressed(node->is_cell_transposed(p_pos.x, p_pos.y));
+
+ _update_transform_buttons();
+ canvas_item_editor->update();
}
-void TileMapEditor::_menu_option(int p_option) {
- switch(p_option) {
+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);
}
+
+ rectangle.pos=begin;
+ rectangle.size=end-begin;
+
+ canvas_item_editor->update();
}
-struct _TileMapEditorCopyData {
- Point2i pos;
- int cell;
- bool flip_h;
- bool flip_v;
- bool transpose;
-};
+void TileMapEditor::_draw_cell(int p_cell, const Point2i& p_point, bool p_flip_h, bool p_flip_v, bool p_transpose, const Matrix32& p_xform) {
-bool TileMapEditor::forward_input_event(const InputEvent& p_event) {
+ Ref<Texture> t = node->get_tileset()->tile_get_texture(p_cell);
+
+ if (t.is_null())
+ return;
+
+ Vector2 from = node->map_to_world(p_point)+node->get_cell_draw_offset();
+ Vector2 tile_ofs = node->get_tileset()->tile_get_texture_offset(p_cell);
+
+ Rect2 r = node->get_tileset()->tile_get_region(p_cell);
+ Size2 sc = p_xform.get_scale();
+
+ Rect2 rect;
+
+ if (r==Rect2()) {
+ rect=Rect2(from,t->get_size());
+ } else {
+ rect=Rect2(from,r.get_size());
+ }
+
+ if (rect.size.y > rect.size.x) {
+ if ((p_flip_h && (p_flip_v || p_transpose)) || (p_flip_v && !p_transpose))
+ tile_ofs.y += rect.size.y - rect.size.x;
+ } else if (rect.size.y < rect.size.x) {
+ if ((p_flip_v && (p_flip_h || p_transpose)) || (p_flip_h && !p_transpose))
+ tile_ofs.x += rect.size.x - rect.size.y;
+ }
+
+ if (p_transpose) {
+ SWAP(tile_ofs.x, tile_ofs.y);
+ }
+ if (p_flip_h) {
+ sc.x*=-1.0;
+ tile_ofs.x*=-1.0;
+ }
+ if (p_flip_v) {
+ sc.y*=-1.0;
+ tile_ofs.y*=-1.0;
+ }
+
+ if (node->get_tile_origin()==TileMap::TILE_ORIGIN_TOP_LEFT) {
+ rect.pos+=tile_ofs;
+
+ } else if (node->get_tile_origin()==TileMap::TILE_ORIGIN_CENTER) {
+ rect.pos+=node->get_cell_size()/2;
+ Vector2 s = r.size;
+
+ Vector2 center = (s/2) - tile_ofs;
+
+
+ if (p_flip_h)
+ rect.pos.x-=s.x-center.x;
+ else
+ rect.pos.x-=center.x;
+
+ if (p_flip_v)
+ rect.pos.y-=s.y-center.y;
+ else
+ rect.pos.y-=center.y;
+ }
+ rect.pos=p_xform.xform(rect.pos);
+ rect.size*=sc;
+
+ if (r==Rect2())
+ canvas_item_editor->draw_texture_rect(t,rect,false,Color(1,1,1,0.5),p_transpose);
+ else
+ canvas_item_editor->draw_texture_rect_region(t,rect,r,Color(1,1,1,0.5),p_transpose);
+}
+
+void TileMapEditor::_update_copydata() {
+
+ copydata.clear();
+
+ if (!selection_active)
+ return;
+
+ for(int i=rectangle.pos.y;i<=rectangle.pos.y+rectangle.size.y;i++) {
+
+ for(int j=rectangle.pos.x;j<=rectangle.pos.x+rectangle.size.x;j++) {
+
+ TileData tcd;
+
+ tcd.cell=node->get_cell(j, i);
+
+ if (tcd.cell!=TileMap::INVALID_CELL) {
+ tcd.pos=Point2i(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);
+ }
+
+ copydata.push_back(tcd);
+ }
+ }
+}
+
+bool TileMapEditor::forward_input_event(const InputEvent& p_event) {
if (!node || !node->get_tileset().is_valid() || !node->is_visible())
return false;
Matrix32 xform = CanvasItemEditor::get_singleton()->get_canvas_transform() * node->get_global_transform();
Matrix32 xform_inv = xform.affine_inverse();
- Vector2 snap = node->get_cell_size();
-
switch(p_event.type) {
@@ -235,165 +403,222 @@ bool TileMapEditor::forward_input_event(const InputEvent& p_event) {
if (mb.button_index==BUTTON_LEFT) {
+ if (mb.pressed) {
- if (mb.pressed && tool==TOOL_DUPLICATING) {
-
+ if (Input::get_singleton()->is_key_pressed(KEY_SPACE))
+ return false; //drag
- List<_TileMapEditorCopyData> dupdata;
- Point2 ofs = over_tile-selection.pos;
+ if (tool==TOOL_NONE) {
+ if (mb.mod.shift) {
- for(int i=selection.pos.y;i<=selection.pos.y+selection.size.y;i++) {
+ tool=TOOL_RECTANGLE_PAINT;
+ selection_active=false;
+ rectangle_begin=node->world_to_map(xform_inv.xform(Point2(mb.x,mb.y)));
- for(int j=selection.pos.x;j<=selection.pos.x+selection.size.x;j++) {
+ return true;
+ }
+ if (mb.mod.control) {
- _TileMapEditorCopyData tcd;
- tcd.pos=Point2i(j,i);
- 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);
+ tool=TOOL_PICKING;
+ _pick_tile(over_tile);
+ return true;
}
+
+ tool=TOOL_PAINTING;
}
- undo_redo->create_action("Duplicate");
- for (List<_TileMapEditorCopyData>::Element *E=dupdata.front();E;E=E->next()) {
+ if (tool==TOOL_PAINTING) {
+ int id = get_selected_tile();
+
+ if (id!=TileMap::INVALID_CELL) {
+
+ tool=TOOL_PAINTING;
+
+ paint_undo.clear();
+ paint_undo[over_tile]=_get_op_from_cell(over_tile);
+ _set_cell(over_tile, id, flip_h, flip_v, transpose);
- _set_cell(E->get().pos+ofs,E->get().cell,E->get().flip_h,E->get().flip_v,E->get().transpose,true);
+ return true;
+ }
}
- undo_redo->commit_action();
- tool=TOOL_NONE;
- canvas_item_editor->update();
- selection.pos=over_tile;
+ if (tool==TOOL_PICKING) {
- } else if (mb.pressed && tool==TOOL_NONE) {
+ _pick_tile(over_tile);
- if (Input::get_singleton()->is_key_pressed(KEY_SPACE))
- return false; //drag
- if (mb.mod.shift) {
+ return true;
+ }
+
+ if (tool==TOOL_SELECTING) {
- tool=TOOL_SELECTING;
- selection_begin =node->world_to_map(xform_inv.xform(Point2(mb.x,mb.y)));
- selection.pos=selection_begin;
- selection.size=Point2(0,0);
selection_active=true;
- canvas_item_editor->update();
+ rectangle_begin=node->world_to_map(xform_inv.xform(Point2(mb.x,mb.y)));
+
return true;
+ }
+
+ if (tool==TOOL_DUPLICATING) {
+
+ Point2 ofs = over_tile-rectangle.pos;
+
+ undo_redo->create_action("Duplicate");
+ 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,true);
+ }
+ undo_redo->commit_action();
+
+ tool=TOOL_NONE;
+ copydata.clear();
- } 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 {
- int id = get_selected_tile();
- if (id!=TileMap::INVALID_CELL) {
- tool=TOOL_PAINTING;
- 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(),transpose->is_pressed());
- return true;
- }
}
} else {
- if (tool==TOOL_PAINTING || tool == TOOL_SELECTING || tool == TOOL_PICKING) {
+ if (tool!=TOOL_NONE) {
if (tool==TOOL_PAINTING) {
- if (paint_undo.size()) {
+ int id=get_selected_tile();
+
+ if (id!=TileMap::INVALID_CELL && paint_undo.size()) {
undo_redo->create_action("Paint TileMap");
for(Map<Point2i,CellOp>::Element *E=paint_undo.front();E;E=E->next()) {
Point2i p=E->key();
- undo_redo->add_do_method(node,"set_cellv",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_do_method(node,"set_cellv",Point2(p),id,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(node,"set_cellv",Point2(p),E->get().idx,E->get().xf,E->get().yf,E->get().tr);
}
undo_redo->commit_action();
paint_undo.clear();
}
+ } else if (tool==TOOL_RECTANGLE_PAINT) {
+
+ int id=get_selected_tile();
+
+ if (id!=TileMap::INVALID_CELL) {
+
+ undo_redo->create_action("Rectangle Paint");
+ for(int i=rectangle.pos.y;i<=rectangle.pos.y+rectangle.size.y;i++) {
+ for(int j=rectangle.pos.x;j<=rectangle.pos.x+rectangle.size.x;j++) {
+
+ _set_cell(Point2(j, i), id, flip_h, flip_v, transpose, true);
+ }
+ }
+ undo_redo->commit_action();
+
+ canvas_item_editor->update();
+ }
+ } else if (tool==TOOL_SELECTING) {
+
+ canvas_item_editor->update();
}
+
tool=TOOL_NONE;
+
return true;
}
}
- }
+ } else if (mb.button_index==BUTTON_RIGHT) {
- if (mb.button_index==BUTTON_RIGHT) {
+ if (mb.pressed) {
- if (mb.pressed && tool==TOOL_DUPLICATING) {
+ if (tool==TOOL_SELECTING) {
- tool=TOOL_NONE;
- canvas_item_editor->update();
- } else if (mb.pressed && tool==TOOL_NONE) {
-
- tool=TOOL_ERASING;
- 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(),transpose->is_pressed());
- //return true;
- _set_cell(local,TileMap::INVALID_CELL);
- return true;
- } else if (!mb.pressed) {
+ tool=TOOL_NONE;
+ selection_active=false;
+
+ canvas_item_editor->update();
+
+ return true;
+ }
+
+ if (tool==TOOL_DUPLICATING) {
+
+ tool=TOOL_NONE;
+ copydata.clear();
+
+ canvas_item_editor->update();
+
+ return true;
+ }
+
+ if (tool==TOOL_NONE) {
+
+ if (mb.mod.shift) {
+
+ tool=TOOL_RECTANGLE_ERASE;
+
+ selection_active=false;
+ rectangle_begin=node->world_to_map(xform_inv.xform(Point2(mb.x,mb.y)));
+ paint_undo.clear();
+
+ } else {
+ tool=TOOL_ERASING;
+
+ 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);
- if (tool==TOOL_ERASING) {
+ _set_cell(local, TileMap::INVALID_CELL);
+ }
+
+ return true;
+ }
+
+ } else {
+ if (tool==TOOL_ERASING || tool==TOOL_RECTANGLE_ERASE) {
if (paint_undo.size()) {
undo_redo->create_action("Erase TileMap");
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,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_do_method(node,"set_cellv",Point2(p),TileMap::INVALID_CELL,false,false,false);
undo_redo->add_undo_method(node,"set_cellv",Point2(p),E->get().idx,E->get().xf,E->get().yf,E->get().tr);
}
undo_redo->commit_action();
paint_undo.clear();
+ }
+ if (tool==TOOL_RECTANGLE_ERASE) {
+ canvas_item_editor->update();
}
tool=TOOL_NONE;
+
return true;
}
}
}
-
} break;
case InputEvent::MOUSE_MOTION: {
const InputEventMouseMotion &mm=p_event.mouse_motion;
- Point2i new_over_tile = node->world_to_map(xform_inv.xform(Point2(mm.x,mm.y)));//(xform_inv.xform(Point2(mm.x,mm.y))/snap).floor();
+ Point2i new_over_tile = node->world_to_map(xform_inv.xform(Point2(mm.x,mm.y)));
+
if (new_over_tile!=over_tile) {
over_tile=new_over_tile;
canvas_item_editor->update();
}
-
-
if (tool==TOOL_PAINTING) {
int id = get_selected_tile();
if (id!=TileMap::INVALID_CELL) {
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(),transpose->is_pressed());
+ _set_cell(over_tile, id, flip_h, flip_v, transpose);
return true;
}
@@ -401,110 +626,130 @@ bool TileMapEditor::forward_input_event(const InputEvent& p_event) {
if (tool==TOOL_SELECTING) {
- Point2i begin=selection_begin;
- Point2i end =over_tile;
+ _select(rectangle_begin, over_tile);
- if (begin.x > end.x) {
+ return true;
+ }
+ if (tool==TOOL_RECTANGLE_PAINT || tool==TOOL_RECTANGLE_ERASE) {
- SWAP( begin.x, end.x);
- }
- if (begin.y > end.y) {
+ _select(rectangle_begin, over_tile);
- SWAP( begin.y, end.y);
- }
+ if (tool==TOOL_RECTANGLE_ERASE) {
- selection.pos=begin;
- selection.size=end-begin;
- canvas_item_editor->update();
+ if (paint_undo.size()) {
- return true;
+ for (Map<Point2i, CellOp>::Element *E=paint_undo.front();E;E=E->next()) {
- }
+ _set_cell(E->key(), E->get().idx, E->get().xf, E->get().yf, E->get().tr);
+ }
+
+ paint_undo.clear();
+ }
+
+ for(int i=rectangle.pos.y;i<=rectangle.pos.y+rectangle.size.y;i++) {
+ for(int j=rectangle.pos.x;j<=rectangle.pos.x+rectangle.size.x;j++) {
+
+ Point2i tile = Point2i(j, i);
+ if (!paint_undo.has(tile))
+ paint_undo[tile]=_get_op_from_cell(tile);
+
+ _set_cell(tile, TileMap::INVALID_CELL);
+ }
+ }
+ }
+
+ return true;
+ }
if (tool==TOOL_ERASING) {
- Point2i local =over_tile;
+
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(),transpose->is_pressed());
- _set_cell(local,TileMap::INVALID_CELL);
+
+ _set_cell(over_tile, TileMap::INVALID_CELL);
+
return true;
}
+ if (tool==TOOL_PICKING && Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) {
+
+ _pick_tile(over_tile);
- 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;
}
-
} break;
case InputEvent::KEY: {
const InputEventKey &k = p_event.key;
- if (!node)
- break;
- if (k.pressed && k.scancode==KEY_DELETE && selection_active && tool==TOOL_NONE) {
+ if (!k.pressed)
+ break;
- undo_redo->create_action("Delete");
- for(int i=selection.pos.y;i<=selection.pos.y+selection.size.y;i++) {
+ if (k.scancode==KEY_ESCAPE) {
- for(int j=selection.pos.x;j<=selection.pos.x+selection.size.x;j++) {
+ if (tool==TOOL_DUPLICATING)
+ copydata.clear();
+ else if (tool==TOOL_SELECTING || selection_active)
+ selection_active=false;
+ tool=TOOL_NONE;
- _set_cell(Point2i(j,i),TileMap::INVALID_CELL);
- }
- }
- undo_redo->commit_action();
-
- selection_active=false;
canvas_item_editor->update();
+
return true;
}
- if (mouse_over && k.pressed && k.scancode==KEY_A && tool==TOOL_NONE && !k.mod.command) {
+ if (tool!=TOOL_NONE)
+ return false;
- /*int cell = node->get_cell(over_tile.x,over_tile.y);
- if (cell!=TileMap::INVALID_CELL) {
- bool flip_h = node->is_cell_x_flipped(over_tile.x,over_tile.y);
- bool flip_v = node->is_cell_y_flipped(over_tile.x,over_tile.y);
- _set_cell(over_tile,cell,!flip_h,flip_v);
- }*/
+ if (k.scancode==KEY_DELETE) {
+
+ _menu_option(OPTION_ERASE_SELECTION);
- mirror_x->set_pressed( ! mirror_x->is_pressed() );
- canvas_item_editor->update();
return true;
}
- if (mouse_over && k.pressed && k.scancode==KEY_S && tool==TOOL_NONE && !k.mod.command) {
+ if (mouse_over && k.scancode==KEY_A && !k.mod.command) {
+ flip_h=!flip_h;
+ mirror_x->set_pressed(flip_h);
+ canvas_item_editor->update();
+ return true;
+ }
+ if (mouse_over && k.scancode==KEY_S && !k.mod.command) {
- /*
- int cell = node->get_cell(over_tile.x,over_tile.y);
- if (cell!=TileMap::INVALID_CELL) {
+ flip_v=!flip_v;
+ mirror_y->set_pressed(flip_v);
+ canvas_item_editor->update();
+ return true;
+ }
+ if (mouse_over && k.scancode==KEY_F && k.mod.command) {
- bool flip_h = node->is_cell_x_flipped(over_tile.x,over_tile.y);
- bool flip_v = node->is_cell_y_flipped(over_tile.x,over_tile.y);
- _set_cell(over_tile,cell,flip_h,!flip_v);
- }*/
+ search_box->select_all();
+ search_box->grab_focus();
- mirror_y->set_pressed( ! mirror_y->is_pressed() );
- canvas_item_editor->update();
return true;
}
+ if (mouse_over && k.scancode==KEY_B && k.mod.command) {
- if (mouse_over && selection_active && k.pressed && k.mod.command && k.scancode==KEY_D && tool==TOOL_NONE) {
+ tool=TOOL_SELECTING;
+ selection_active=false;
- tool=TOOL_DUPLICATING;
canvas_item_editor->update();
+
return true;
}
+ if (mouse_over && k.scancode==KEY_D && k.mod.command) {
+ _update_copydata();
+ if (selection_active) {
+ tool=TOOL_DUPLICATING;
+ canvas_item_editor->update();
+
+ return true;
+ }
+ }
} break;
}
@@ -515,7 +760,6 @@ void TileMapEditor::_canvas_draw() {
if (!node)
return;
- Size2 cell_size=node->get_cell_size();
Matrix32 cell_xf = node->get_cell_transform();
Matrix32 xform = CanvasItemEditor::get_singleton()->get_canvas_transform() * node->get_global_transform();
@@ -608,43 +852,29 @@ void TileMapEditor::_canvas_draw() {
break;
}
-
}
-
-
-
}
-/*
- for(int i=(si.pos.y/cell_size.y)-1;i<=(si.pos.y+si.size.y)/cell_size.y;i++) {
-
- int ofs = i*cell_size.y;
- Color col=i==0?Color(1,0.8,0.2,0.5):Color(1,0.3,0.1,0.2);
- canvas_item_editor->draw_line(xform.xform(Point2(si.pos.x,ofs)),xform.xform(Point2(si.pos.x+si.size.x,ofs)),col,1);*/
}
-
if (selection_active) {
Vector<Vector2> points;
- points.push_back( xform.xform( node->map_to_world(( selection.pos ) )));
- points.push_back( xform.xform( node->map_to_world((selection.pos+Point2(selection.size.x+1,0)) ) ));
- points.push_back( xform.xform( node->map_to_world((selection.pos+Point2(selection.size.x+1,selection.size.y+1)) ) ));
- points.push_back( xform.xform( node->map_to_world((selection.pos+Point2(0,selection.size.y+1)) ) ));
- Color col=Color(0.2,0.8,1,0.4);
+ points.push_back( xform.xform( node->map_to_world(( rectangle.pos ) )));
+ points.push_back( xform.xform( node->map_to_world((rectangle.pos+Point2(rectangle.size.x+1,0)) ) ));
+ points.push_back( xform.xform( node->map_to_world((rectangle.pos+Point2(rectangle.size.x+1,rectangle.size.y+1)) ) ));
+ points.push_back( xform.xform( node->map_to_world((rectangle.pos+Point2(0,rectangle.size.y+1)) ) ));
- canvas_item_editor->draw_colored_polygon(points,col);
+ canvas_item_editor->draw_colored_polygon(points, Color(0.2,0.8,1,0.4));
}
if (mouse_over){
Vector2 endpoints[4]={
-
- ( node->map_to_world(over_tile,true) ) ,
- ( node->map_to_world((over_tile+Point2(1,0)),true ) ),
- ( node->map_to_world((over_tile+Point2(1,1)),true ) ),
- ( node->map_to_world((over_tile+Point2(0,1)),true ) )
-
+ node->map_to_world(over_tile, true),
+ node->map_to_world((over_tile+Point2(1,0)), true),
+ node->map_to_world((over_tile+Point2(1,1)), true),
+ node->map_to_world((over_tile+Point2(0,1)), true)
};
for(int i=0;i<4;i++) {
@@ -664,118 +894,75 @@ void TileMapEditor::_canvas_draw() {
canvas_item_editor->draw_line(endpoints[i],endpoints[(i+1)%4],col,2);
+ if (tool==TOOL_SELECTING || tool==TOOL_PICKING) {
- if (tool==TOOL_DUPLICATING) {
+ return;
- Rect2i duplicate=selection;
- duplicate.pos=over_tile;
+ } else if (tool==TOOL_RECTANGLE_PAINT) {
+ int id = get_selected_tile();
- Vector<Vector2> points;
- points.push_back( xform.xform( node->map_to_world(duplicate.pos ) ));
- points.push_back( xform.xform( node->map_to_world((duplicate.pos+Point2(duplicate.size.x+1,0)) ) ));
- points.push_back( xform.xform( node->map_to_world((duplicate.pos+Point2(duplicate.size.x+1,duplicate.size.y+1))) ));
- points.push_back( xform.xform( node->map_to_world((duplicate.pos+Point2(0,duplicate.size.y+1))) ));
- Color col=Color(0.2,1.0,0.8,0.4);
+ if (id==TileMap::INVALID_CELL)
+ return;
- canvas_item_editor->draw_colored_polygon(points,col);
+ for(int i=rectangle.pos.y;i<=rectangle.pos.y+rectangle.size.y;i++) {
+ for(int j=rectangle.pos.x;j<=rectangle.pos.x+rectangle.size.x;j++) {
- } else {
-
- Ref<TileSet> ts = node->get_tileset();
-
-
- if (ts.is_valid()) {
-
- int st = get_selected_tile();
- if (ts->has_tile(st)) {
-
- Ref<Texture> t = ts->tile_get_texture(st);
- if (t.is_valid()) {
- Vector2 from = node->map_to_world(over_tile)+node->get_cell_draw_offset();
- Vector2 tile_ofs = ts->tile_get_texture_offset(st);
- Rect2 r = ts->tile_get_region(st);
- Size2 sc = xform.get_scale();
-
- Rect2 rect;
- if (r==Rect2()) {
- rect=Rect2(from,t->get_size());
- } else {
-
- rect=Rect2(from,r.get_size());
- }
+ _draw_cell(id, Point2(j, i), flip_h, flip_v, transpose, xform);
+ }
+ }
+ } else if (tool==TOOL_DUPLICATING) {
- bool transp = transpose->is_pressed();
- bool flip_h = mirror_x->is_pressed();
- bool flip_v = mirror_y->is_pressed();
+ if (copydata.empty())
+ return;
- if (rect.size.y > rect.size.x) {
- if ((flip_h && (flip_v || transp)) || (flip_v && !transp))
- tile_ofs.y += rect.size.y - rect.size.x;
- } else if (rect.size.y < rect.size.x) {
- if ((flip_v && (flip_h || transp)) || (flip_h && !transp))
- tile_ofs.x += rect.size.x - rect.size.y;
- }
+ Ref<TileSet> ts = node->get_tileset();
- if (transp) {
- SWAP(tile_ofs.x, tile_ofs.y);
- }
+ if (ts.is_null())
+ return;
- if (flip_h) {
- sc.x*=-1.0;
- tile_ofs.x*=-1.0;
- }
- if (flip_v) {
- sc.y*=-1.0;
- tile_ofs.y*=-1.0;
- }
+ Point2 ofs = over_tile-rectangle.pos;
- if (node->get_tile_origin()==TileMap::TILE_ORIGIN_TOP_LEFT) {
- rect.pos+=tile_ofs;
+ for (List<TileData>::Element *E=copydata.front();E;E=E->next()) {
- } else if (node->get_tile_origin()==TileMap::TILE_ORIGIN_CENTER) {
- rect.pos+=node->get_cell_size()/2;
- Vector2 s = r.size;
+ if (!ts->has_tile(E->get().cell))
+ continue;
- Vector2 center = (s/2) - tile_ofs;
+ TileData tcd = E->get();
+ _draw_cell(tcd.cell, tcd.pos+ofs, tcd.flip_h, tcd.flip_v, tcd.transpose, xform);
+ }
- if (flip_h)
- rect.pos.x-=s.x-center.x;
- else
- rect.pos.x-=center.x;
+ Rect2i duplicate=rectangle;
+ duplicate.pos=over_tile;
- if (flip_v)
- rect.pos.y-=s.y-center.y;
- else
- rect.pos.y-=center.y;
- }
+ Vector<Vector2> points;
+ points.push_back( xform.xform( node->map_to_world(duplicate.pos ) ));
+ points.push_back( xform.xform( node->map_to_world((duplicate.pos+Point2(duplicate.size.x+1,0)) ) ));
+ points.push_back( xform.xform( node->map_to_world((duplicate.pos+Point2(duplicate.size.x+1,duplicate.size.y+1))) ));
+ points.push_back( xform.xform( node->map_to_world((duplicate.pos+Point2(0,duplicate.size.y+1))) ));
- rect.pos=xform.xform(rect.pos);
- rect.size*=sc;
+ canvas_item_editor->draw_colored_polygon(points, Color(0.2,1.0,0.8,0.2));
- if (r==Rect2()) {
+ } else {
- canvas_item_editor->draw_texture_rect(t,rect,false,Color(1,1,1,0.5),transp);
- } else {
+ int st = get_selected_tile();
- canvas_item_editor->draw_texture_rect_region(t,rect,r,Color(1,1,1,0.5),transp);
- }
- }
- }
- }
+ if (st==TileMap::INVALID_CELL)
+ return;
+ _draw_cell(st, over_tile, flip_h, flip_v, transpose, xform);
}
}
-
-
}
void TileMapEditor::edit(Node *p_tile_map) {
+ search_box->set_text("");
+
if (!canvas_item_editor) {
canvas_item_editor=CanvasItemEditor::get_singleton()->get_viewport_control();
}
@@ -815,27 +1002,29 @@ void TileMapEditor::edit(Node *p_tile_map) {
void TileMapEditor::_tileset_settings_changed() {
_update_palette();
+
if (canvas_item_editor)
canvas_item_editor->update();
}
void TileMapEditor::_bind_methods() {
+ ObjectTypeDB::bind_method(_MD("_text_entered"),&TileMapEditor::_text_entered);
+ ObjectTypeDB::bind_method(_MD("_text_changed"),&TileMapEditor::_text_changed);
+ ObjectTypeDB::bind_method(_MD("_sbox_input"),&TileMapEditor::_sbox_input);
ObjectTypeDB::bind_method(_MD("_menu_option"),&TileMapEditor::_menu_option);
ObjectTypeDB::bind_method(_MD("_canvas_draw"),&TileMapEditor::_canvas_draw);
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));
- ObjectTypeDB::bind_method(_MD("_set_display_mode","mode"),&TileMapEditor::_set_display_mode);
}
TileMapEditor::CellOp TileMapEditor::_get_op_from_cell(const Point2i& p_pos)
{
CellOp op;
op.idx = node->get_cell(p_pos.x,p_pos.y);
- if (op.idx>=0) {
+ if (op.idx!=TileMap::INVALID_CELL) {
if (node->is_cell_x_flipped(p_pos.x,p_pos.y))
op.xf=true;
if (node->is_cell_y_flipped(p_pos.x,p_pos.y))
@@ -851,47 +1040,35 @@ void TileMapEditor::_update_transform_buttons(Object *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);
+ transp->set_pressed(false);
}
else if (b == rotate_90) {
mirror_x->set_pressed(true);
mirror_y->set_pressed(false);
- transpose->set_pressed(true);
+ transp->set_pressed(true);
}
else if (b == rotate_180) {
mirror_x->set_pressed(true);
mirror_y->set_pressed(true);
- transpose->set_pressed(false);
+ transp->set_pressed(false);
}
else if (b == rotate_270) {
mirror_x->set_pressed(false);
mirror_y->set_pressed(true);
- transpose->set_pressed(true);
+ transp->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);
+ flip_h=mirror_x->is_pressed();
+ flip_v=mirror_y->is_pressed();
+ transpose=transp->is_pressed();
+
+ rotate_0->set_pressed(!flip_h && !flip_v && !transpose);
+ rotate_90->set_pressed(flip_h && !flip_v && transpose);
+ rotate_180->set_pressed(flip_h && flip_v && !transpose);
+ rotate_270->set_pressed(!flip_h && flip_v && transpose);
}
TileMapEditor::TileMapEditor(EditorNode *p_editor) {
@@ -899,92 +1076,105 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) {
node=NULL;
canvas_item_editor=NULL;
editor=p_editor;
- undo_redo = editor->get_undo_redo();
-
- int mw = EDITOR_DEF("tile_map/palette_min_width",80);
- Control *ec = memnew( Control);
- ec->set_custom_minimum_size(Size2(mw,0));
- add_child(ec);
-
- HBoxContainer *hb = memnew( HBoxContainer );
- add_child(hb);
- hb->set_h_size_flags(SIZE_EXPAND_FILL);
- hb->add_spacer(true);
-
- button_thumbnail = memnew( ToolButton );
- button_thumbnail->set_toggle_mode(true);
- button_thumbnail->set_pressed(true);
- button_thumbnail->set_icon(p_editor->get_gui_base()->get_icon("FileThumbnail","EditorIcons"));
- hb->add_child(button_thumbnail);
- button_thumbnail->connect("pressed", this, "_set_display_mode", varray(DISPLAY_THUMBNAIL));
-
- button_list = memnew( ToolButton );
- button_list->set_toggle_mode(true);
- button_list->set_pressed(false);
- button_list->set_icon(p_editor->get_gui_base()->get_icon("FileList","EditorIcons"));
- hb->add_child(button_list);
- button_list->connect("pressed", this, "_set_display_mode", varray(DISPLAY_LIST));
+ undo_redo=editor->get_undo_redo();
+
+ tool=TOOL_NONE;
+ selection_active=false;
+ mouse_over=false;
+
+ flip_h=false;
+ flip_v=false;
+ transpose=false;
+
+ search_box = memnew( LineEdit );
+ search_box->set_h_size_flags(SIZE_EXPAND_FILL);
+ search_box->connect("text_entered", this, "_text_entered");
+ search_box->connect("text_changed", this, "_text_changed");
+ search_box->connect("input_event", this, "_sbox_input");
+ add_child(search_box);
+
+ int mw = EDITOR_DEF("tile_map/palette_min_width", 80);
// Add tile palette
palette = memnew( ItemList );
palette->set_v_size_flags(SIZE_EXPAND_FILL);
+ palette->set_custom_minimum_size(Size2(mw,0));
add_child(palette);
// Add menu items
- canvas_item_editor_hb = memnew( HBoxContainer );
- CanvasItemEditor::get_singleton()->add_control_to_menu_panel(canvas_item_editor_hb);
- canvas_item_editor_hb->add_child( memnew( VSeparator ));
- 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);
+ toolbar = memnew( HBoxContainer );
+ CanvasItemEditor::get_singleton()->add_control_to_menu_panel(toolbar);
+
+ options = memnew( MenuButton );
+ options->set_text("Tile Map");
+ options->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("TileMap", "EditorIcons"));
+
+ PopupMenu *p = options->get_popup();
+
+ p->add_item("Pick Tile", OPTION_PICK_TILE);
+ p->add_separator();
+ p->add_item("Select", OPTION_SELECT);
+ p->add_item("Duplicate Selection", OPTION_DUPLICATE);
+ p->add_separator();
+ p->add_item("Erase Selection", OPTION_ERASE_SELECTION);
+
+ p->connect("item_pressed", this, "_menu_option");
+
+ toolbar->add_child(options);
+
+ toolbar->add_child( memnew( VSeparator ) );
+
+ transp = memnew( ToolButton );
+ transp->set_toggle_mode(true);
+ transp->set_tooltip("Transpose");
+ transp->set_focus_mode(FOCUS_NONE);
+ transp->connect("pressed", this, "_update_transform_buttons", make_binds(transp));
+ toolbar->add_child(transp);
mirror_x = memnew( ToolButton );
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);
+ toolbar->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);
- canvas_item_editor_hb->add_child(memnew(VSeparator));
+ toolbar->add_child(mirror_y);
+ toolbar->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);
+ toolbar->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);
+ toolbar->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);
+ toolbar->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();
+ toolbar->add_child(rotate_270);
+ toolbar->hide();
rotate_0->set_pressed(true);
- tool=TOOL_NONE;
- selection_active=false;
- mouse_over=false;
}
+///////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////
void TileMapEditorPlugin::edit(Object *p_object) {
@@ -999,33 +1189,24 @@ bool TileMapEditorPlugin::handles(Object *p_object) const {
void TileMapEditorPlugin::make_visible(bool p_visible) {
if (p_visible) {
- tile_map_editor->show();
- tile_map_editor->get_canvas_item_editor_hb()->show();
+ tile_map_editor->show();
+ tile_map_editor->get_toolbar()->show();
} else {
tile_map_editor->hide();
- tile_map_editor->get_canvas_item_editor_hb()->hide();
+ tile_map_editor->get_toolbar()->hide();
tile_map_editor->edit(NULL);
}
-
}
TileMapEditorPlugin::TileMapEditorPlugin(EditorNode *p_node) {
- editor=p_node;
tile_map_editor = memnew( TileMapEditor(p_node) );
- CanvasItemEditor::get_singleton()->get_palette_split()->add_child(tile_map_editor);
- CanvasItemEditor::get_singleton()->get_palette_split()->move_child(tile_map_editor,0);
-
+ add_control_to_container(CONTAINER_CANVAS_EDITOR_SIDE, tile_map_editor);
tile_map_editor->hide();
-
-
-
-
}
-
TileMapEditorPlugin::~TileMapEditorPlugin()
{
}
diff --git a/tools/editor/plugins/tile_map_editor_plugin.h b/tools/editor/plugins/tile_map_editor_plugin.h
index 3cbf5ff68d..b95f267de3 100644
--- a/tools/editor/plugins/tile_map_editor_plugin.h
+++ b/tools/editor/plugins/tile_map_editor_plugin.h
@@ -32,8 +32,10 @@
#include "tools/editor/editor_plugin.h"
#include "tools/editor/editor_node.h"
#include "scene/2d/tile_map.h"
+#include "scene/gui/line_edit.h"
#include "scene/gui/tool_button.h"
-#include "scene/gui/button_group.h"
+#include "scene/gui/menu_button.h"
+
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
@@ -43,43 +45,39 @@ class TileMapEditor : public VBoxContainer {
OBJ_TYPE(TileMapEditor, VBoxContainer );
- UndoRedo *undo_redo;
-
enum Tool {
TOOL_NONE,
TOOL_PAINTING,
- TOOL_SELECTING,
TOOL_ERASING,
+ TOOL_RECTANGLE_PAINT,
+ TOOL_RECTANGLE_ERASE,
+ TOOL_SELECTING,
TOOL_DUPLICATING,
TOOL_PICKING
};
- enum DisplayMode {
- DISPLAY_THUMBNAIL,
- DISPLAY_LIST
+ enum Options {
+
+ OPTION_PICK_TILE,
+ OPTION_SELECT,
+ OPTION_DUPLICATE,
+ OPTION_ERASE_SELECTION
};
- Tool tool;
+ TileMap *node;
+
+ EditorNode *editor;
+ UndoRedo *undo_redo;
Control *canvas_item_editor;
- int display_mode;
+ LineEdit *search_box;
ItemList *palette;
- ToolButton *button_thumbnail;
- ToolButton *button_list;
- EditorNode *editor;
- Panel *panel;
- TileMap *node;
- MenuButton *options;
- bool selection_active;
- Point2i selection_begin;
- Rect2i selection;
- Point2i over_tile;
- bool mouse_over;
+ HBoxContainer *toolbar;
- Label *mirror_label;
- ToolButton *transpose;
+ MenuButton *options;
+ ToolButton *transp;
ToolButton *mirror_x;
ToolButton *mirror_y;
ToolButton *rotate_0;
@@ -87,46 +85,77 @@ class TileMapEditor : public VBoxContainer {
ToolButton *rotate_180;
ToolButton *rotate_270;
- HBoxContainer *canvas_item_editor_hb;
+ Tool tool;
+
+ bool selection_active;
+ bool mouse_over;
+
+ bool flip_h;
+ bool flip_v;
+ bool transpose;
+
+ Point2i rectangle_begin;
+ Rect2i rectangle;
+ Point2i over_tile;
struct CellOp {
int idx;
bool xf;
bool yf;
bool tr;
+
CellOp() { idx=-1; xf=false; yf=false; tr=false; }
};
- Map<Point2i,CellOp> paint_undo;
+ Map<Point2i, CellOp> paint_undo;
+
+ struct TileData {
+ Point2i pos;
+ int cell;
+ bool flip_h;
+ bool flip_v;
+ bool transpose;
+ };
+
+ List<TileData> copydata;
+
+ void _pick_tile(const Point2& p_pos);
+ void _select(const Point2i& p_from, const Point2i& p_to);
+
+ void _draw_cell(int p_cell, const Point2i& p_point, bool p_flip_h, bool p_flip_v, bool p_transpose, const Matrix32& p_xform);
+ void _update_copydata();
int get_selected_tile() const;
void set_selected_tile(int p_tile);
- void _set_display_mode(int p_mode);
+ void _text_entered(const String& p_text);
+ void _text_changed(const String& p_text);
+ void _sbox_input(const InputEvent& p_ie);
void _update_palette();
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_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();
void _tileset_settings_changed();
-
protected:
+
void _notification(int p_what);
- 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);
+ void _update_transform_buttons(Object *p_button=NULL);
+
public:
- HBoxContainer *get_canvas_item_editor_hb() const { return canvas_item_editor_hb; }
+ HBoxContainer *get_toolbar() const { return toolbar; }
+
bool forward_input_event(const InputEvent& p_event);
void edit(Node *p_tile_map);
+
TileMapEditor(EditorNode *p_editor);
};
@@ -135,8 +164,6 @@ class TileMapEditorPlugin : public EditorPlugin {
OBJ_TYPE( TileMapEditorPlugin, EditorPlugin );
TileMapEditor *tile_map_editor;
- EditorNode *editor;
-
public: