Grid/Tile map editor new item palette

This commit is contained in:
Franklin Sobrinho 2015-06-22 10:05:03 -03:00
parent e9bbb97acc
commit d68a33b473
4 changed files with 180 additions and 91 deletions

View File

@ -706,9 +706,40 @@ struct _CGMEItemSort {
}; };
void GridMapEditor::_set_display_mode(int p_mode) {
if (display_mode==p_mode) {
return;
}
if (p_mode == DISPLAY_LIST) {
mode_list->set_pressed(true);
mode_thumbnail->set_pressed(false);
} else if (p_mode == DISPLAY_THUMBNAIL) {
mode_list->set_pressed(false);
mode_thumbnail->set_pressed(true);
}
display_mode=p_mode;
update_pallete();
}
void GridMapEditor::update_pallete() { void GridMapEditor::update_pallete() {
int selected = theme_pallete->get_current();
theme_pallete->clear(); theme_pallete->clear();
if (display_mode == DISPLAY_THUMBNAIL) {
theme_pallete->set_max_columns(0);
theme_pallete->set_icon_mode(ItemList::ICON_MODE_TOP);
} else if (display_mode == DISPLAY_LIST){
theme_pallete->set_max_columns(1);
theme_pallete->set_icon_mode(ItemList::ICON_MODE_LEFT);
}
float min_size = EDITOR_DEF("grid_map/preview_size",64);
theme_pallete->set_min_icon_size(Size2(min_size, min_size));
theme_pallete->set_fixed_column_width(min_size + 4);
theme_pallete->set_max_text_lines(2);
Ref<MeshLibrary> theme = node->get_theme(); Ref<MeshLibrary> theme = node->get_theme();
@ -720,10 +751,6 @@ void GridMapEditor::update_pallete() {
Vector<int> ids; Vector<int> ids;
ids = theme->get_item_list(); ids = theme->get_item_list();
TreeItem *root = theme_pallete->create_item(NULL);
theme_pallete->set_hide_root(true);
TreeItem *selected=NULL;
List<_CGMEItemSort> il; List<_CGMEItemSort> il;
for(int i=0;i<ids.size();i++) { for(int i=0;i<ids.size();i++) {
@ -734,46 +761,32 @@ void GridMapEditor::update_pallete() {
} }
il.sort(); il.sort();
int col=0; int item = 0;
TreeItem *ti=NULL;
int selected_col=0;
for(List<_CGMEItemSort>::Element *E=il.front();E;E=E->next()) { for(List<_CGMEItemSort>::Element *E=il.front();E;E=E->next()) {
int id = E->get().id; int id = E->get().id;
if (col==0) { theme_pallete->add_item("");
ti = theme_pallete->create_item(root);
}
String name=theme->get_item_name(id); String name=theme->get_item_name(id);
Ref<Texture> preview = theme->get_item_preview(id); Ref<Texture> preview = theme->get_item_preview(id);
if (!preview.is_null()) { if (!preview.is_null()) {
theme_pallete->set_item_icon(item, preview);
ti->set_cell_mode(col,TreeItem::CELL_MODE_ICON); theme_pallete->set_item_tooltip(item, name);
ti->set_icon(col,preview);
ti->set_tooltip(col,name);
} else {
ti->set_text(col,name);
} }
ti->set_metadata(col,id); if (name!="") {
theme_pallete->set_item_text(item,name);
}
theme_pallete->set_item_metadata(item, id);
if (selected_pallete==id) { item++;
selected=ti;
selected_col=col;
} }
col++; if (selected!=-1) {
if (col==theme_pallete->get_columns()) theme_pallete->select(selected);
col=0;
} }
if (selected)
selected->select(selected_col);
last_theme=theme.operator->(); last_theme=theme.operator->();
} }
@ -842,6 +855,9 @@ void GridMapEditor::edit(GridMap *p_gridmap) {
VisualServer::get_singleton()->instance_geometry_set_flag(grid_instance[i],VS::INSTANCE_FLAG_VISIBLE,false); VisualServer::get_singleton()->instance_geometry_set_flag(grid_instance[i],VS::INSTANCE_FLAG_VISIBLE,false);
} }
VisualServer::get_singleton()->instance_geometry_set_flag(cursor_instance, VS::INSTANCE_FLAG_VISIBLE,false);
_clear_areas(); _clear_areas();
return; return;
@ -951,7 +967,7 @@ void GridMapEditor::update_grid() {
grid_xform.origin.x-=1; //force update in hackish way.. what do i care grid_xform.origin.x-=1; //force update in hackish way.. what do i care
VS *vs = VS::get_singleton(); //VS *vs = VS::get_singleton();
grid_ofs[edit_axis]=edit_floor[edit_axis]*node->get_cell_size(); grid_ofs[edit_axis]=edit_floor[edit_axis]*node->get_cell_size();
@ -976,7 +992,7 @@ void GridMapEditor::_notification(int p_what) {
if (p_what==NOTIFICATION_ENTER_TREE) { if (p_what==NOTIFICATION_ENTER_TREE) {
theme_pallete->connect("cell_selected", this,"_item_selected_cbk"); theme_pallete->connect("item_selected", this,"_item_selected_cbk");
edit_mode->connect("item_selected", this,"_edit_mode_changed"); edit_mode->connect("item_selected", this,"_edit_mode_changed");
area_list->connect("item_edited", this,"_area_renamed"); area_list->connect("item_edited", this,"_area_renamed");
area_list->connect("item_selected", this,"_area_selected"); area_list->connect("item_selected", this,"_area_selected");
@ -1063,18 +1079,8 @@ void GridMapEditor::_update_cursor_instance() {
} }
void GridMapEditor::_item_selected_cbk() { void GridMapEditor::_item_selected_cbk(int idx) {
selected_pallete=theme_pallete->get_item_metadata(idx);
TreeItem *it = theme_pallete->get_selected();
if (it) {
selected_pallete=it->get_metadata(theme_pallete->get_selected_column());
} else {
selected_pallete=-1;
}
_update_cursor_instance(); _update_cursor_instance();
@ -1179,7 +1185,7 @@ void GridMapEditor::_bind_methods() {
ObjectTypeDB::bind_method("_area_selected",&GridMapEditor::_area_selected); ObjectTypeDB::bind_method("_area_selected",&GridMapEditor::_area_selected);
ObjectTypeDB::bind_method("_floor_changed",&GridMapEditor::_floor_changed); ObjectTypeDB::bind_method("_floor_changed",&GridMapEditor::_floor_changed);
ObjectTypeDB::bind_method(_MD("_set_display_mode","mode"), &GridMapEditor::_set_display_mode);
} }
@ -1240,6 +1246,9 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
clip_mode=CLIP_DISABLED; clip_mode=CLIP_DISABLED;
options->get_popup()->connect("item_pressed", this,"_menu_option"); options->get_popup()->connect("item_pressed", this,"_menu_option");
HBoxContainer *hb = memnew( HBoxContainer );
add_child(hb);
hb->set_h_size_flags(SIZE_EXPAND_FILL);
edit_mode = memnew(OptionButton); edit_mode = memnew(OptionButton);
edit_mode->set_area_as_parent_rect(); edit_mode->set_area_as_parent_rect();
@ -1247,13 +1256,27 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
edit_mode->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,14);; edit_mode->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,14);;
edit_mode->add_item("Tiles"); edit_mode->add_item("Tiles");
edit_mode->add_item("Areas"); edit_mode->add_item("Areas");
add_child(edit_mode); hb->add_child(edit_mode);
edit_mode->set_h_size_flags(SIZE_EXPAND_FILL);
mode_thumbnail = memnew( ToolButton );
mode_thumbnail->set_toggle_mode(true);
mode_thumbnail->set_pressed(true);
mode_thumbnail->set_icon(p_editor->get_gui_base()->get_icon("FileThumbnail","EditorIcons"));
hb->add_child(mode_thumbnail);
mode_thumbnail->connect("pressed", this, "_set_display_mode", varray(DISPLAY_THUMBNAIL));
mode_list = memnew( ToolButton );
mode_list->set_toggle_mode(true);
mode_list->set_pressed(false);
mode_list->set_icon(p_editor->get_gui_base()->get_icon("FileList", "EditorIcons"));
hb->add_child(mode_list);
mode_list->connect("pressed", this, "_set_display_mode", varray(DISPLAY_LIST));
display_mode = DISPLAY_THUMBNAIL;
selected_area=-1; selected_area=-1;
theme_pallete = memnew( ItemList );
theme_pallete = memnew( Tree );
theme_pallete->set_columns(3);
add_child(theme_pallete); add_child(theme_pallete);
theme_pallete->set_v_size_flags(SIZE_EXPAND_FILL); theme_pallete->set_v_size_flags(SIZE_EXPAND_FILL);

View File

@ -40,10 +40,8 @@
class SpatialEditorPlugin; class SpatialEditorPlugin;
class GridMapEditor : public VBoxContainer { class GridMapEditor : public VBoxContainer {
OBJ_TYPE(GridMapEditor, VBoxContainer ); OBJ_TYPE(GridMapEditor, VBoxContainer );
enum { enum {
GRID_CURSOR_SIZE=50 GRID_CURSOR_SIZE=50
@ -66,6 +64,10 @@ class GridMapEditor : public VBoxContainer {
CLIP_BELOW CLIP_BELOW
}; };
enum DisplayMode {
DISPLAY_THUMBNAIL,
DISPLAY_LIST
};
UndoRedo *undo_redo; UndoRedo *undo_redo;
InputAction input_action; InputAction input_action;
@ -73,6 +75,8 @@ class GridMapEditor : public VBoxContainer {
MenuButton * options; MenuButton * options;
SpinBox *floor; SpinBox *floor;
OptionButton *edit_mode; OptionButton *edit_mode;
ToolButton *mode_thumbnail;
ToolButton *mode_list;
HBoxContainer *spatial_editor_hb; HBoxContainer *spatial_editor_hb;
struct SetItem { struct SetItem {
@ -132,6 +136,7 @@ class GridMapEditor : public VBoxContainer {
Vector3 cursor_origin; Vector3 cursor_origin;
Vector3 last_mouseover; Vector3 last_mouseover;
int display_mode;
int selected_pallete; int selected_pallete;
int selected_area; int selected_area;
int cursor_rot; int cursor_rot;
@ -183,9 +188,10 @@ class GridMapEditor : public VBoxContainer {
void _configure(); void _configure();
void _menu_option(int); void _menu_option(int);
void update_pallete(); void update_pallete();
Tree *theme_pallete; void _set_display_mode(int p_mode);
ItemList *theme_pallete;
Tree *area_list; Tree *area_list;
void _item_selected_cbk(); void _item_selected_cbk(int idx);
void _update_cursor_transform(); void _update_cursor_transform();
void _update_cursor_instance(); void _update_cursor_instance();
void _update_clip(); void _update_clip();

View File

@ -71,22 +71,19 @@ void TileMapEditor::_canvas_mouse_exit() {
} }
int TileMapEditor::get_selected_tile() const { int TileMapEditor::get_selected_tile() const {
int item = palette->get_current();
TreeItem *item = palette->get_selected(); if (item==-1)
if (!item)
return TileMap::INVALID_CELL; return TileMap::INVALID_CELL;
return item->get_metadata(0); return palette->get_item_metadata(item);
} }
void TileMapEditor::set_selected_tile(int p_tile) { void TileMapEditor::set_selected_tile(int p_tile) {
TreeItem *item = palette->get_root()->get_children(); for (int i = 0; i < palette->get_item_count(); i++) {
while (item) { if (palette->get_item_metadata(i).operator int() == p_tile) {
if ((int)item->get_metadata(0) == p_tile) { palette->select(i,true);
item->select(0); palette->ensure_current_is_visible();
palette->ensure_cursor_is_visible();
break; break;
} }
item = item->get_next();
} }
} }
@ -120,42 +117,77 @@ void TileMapEditor::_set_cell(const Point2i& p_pos,int p_value,bool p_flip_h, bo
} }
void TileMapEditor::_set_display_mode(int p_mode) {
if (display_mode == p_mode) {
return;
}
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;
}
display_mode = p_mode;
_update_palette();
}
void TileMapEditor::_update_palette() { void TileMapEditor::_update_palette() {
if (!node) if (!node)
return; return;
palette->clear();; palette->clear();
Ref<TileSet> tileset=node->get_tileset(); Ref<TileSet> tileset=node->get_tileset();
if (!tileset.is_valid()) if (!tileset.is_valid())
return; return;
TreeItem *root = palette->create_item();
palette->set_hide_root(true);
List<int> tiles; List<int> tiles;
tileset->get_tile_list(&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);
}
palette->set_max_text_lines(2);
for(List<int>::Element *E=tiles.front();E;E=E->next()) { for(List<int>::Element *E=tiles.front();E;E=E->next()) {
palette->add_item("");
TreeItem *tile = palette->create_item(root);
tile->set_icon_max_width(0,64);
Ref<Texture> tex = tileset->tile_get_texture(E->get()); Ref<Texture> tex = tileset->tile_get_texture(E->get());
if (tex.is_valid()) { if (tex.is_valid()) {
tile->set_icon(0,tex);
Rect2 region = tileset->tile_get_region(E->get()); Rect2 region = tileset->tile_get_region(E->get());
if (region!=Rect2())
tile->set_icon_region(0,region);
} else if (tileset->tile_get_name(E->get())!="") if (region==Rect2()) {
tile->set_text(0,tileset->tile_get_name(E->get())); continue;
else }
tile->set_text(0,"#"+itos(E->get()));
tile->set_metadata(0,E->get()); Image data = VS::get_singleton()->texture_get_data(tex->get_rid());
Ref<ImageTexture> img = memnew( ImageTexture );
img->create_from_image(data.get_rect(region));
palette->set_item_icon(palette->get_item_count()-1, img);
}
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());
} }
} }
@ -755,7 +787,7 @@ void TileMapEditor::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_tileset_settings_changed"),&TileMapEditor::_tileset_settings_changed); 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("_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_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) TileMapEditor::CellOp TileMapEditor::_get_op_from_cell(const Point2i& p_pos)
@ -833,8 +865,27 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) {
ec->set_custom_minimum_size(Size2(mw,0)); ec->set_custom_minimum_size(Size2(mw,0));
add_child(ec); 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));
// Add tile palette // Add tile palette
palette = memnew( Tree ); palette = memnew( ItemList );
palette->set_v_size_flags(SIZE_EXPAND_FILL); palette->set_v_size_flags(SIZE_EXPAND_FILL);
add_child(palette); add_child(palette);

View File

@ -55,10 +55,18 @@ class TileMapEditor : public VBoxContainer {
TOOL_PICKING TOOL_PICKING
}; };
enum DisplayMode {
DISPLAY_THUMBNAIL,
DISPLAY_LIST
};
Tool tool; Tool tool;
Control *canvas_item_editor; Control *canvas_item_editor;
Tree *palette; int display_mode;
ItemList *palette;
ToolButton *button_thumbnail;
ToolButton *button_list;
EditorNode *editor; EditorNode *editor;
Panel *panel; Panel *panel;
TileMap *node; TileMap *node;
@ -95,6 +103,7 @@ class TileMapEditor : public VBoxContainer {
int get_selected_tile() const; int get_selected_tile() const;
void set_selected_tile(int p_tile); void set_selected_tile(int p_tile);
void _set_display_mode(int p_mode);
void _update_palette(); void _update_palette();
void _canvas_draw(); void _canvas_draw();
void _menu_option(int p_option); void _menu_option(int p_option);