summaryrefslogtreecommitdiff
path: root/editor/plugins/tile_map_editor_plugin.cpp
diff options
context:
space:
mode:
authorGilles Roudiere <gilles.roudiere@gmail.com>2019-01-29 19:55:52 +0100
committerGilles Roudière <gilles.roudiere@gmail.com>2019-01-30 16:06:40 +0100
commit96f25c8b67417d3367dad16e67786092b28e55bb (patch)
treed63396792877f300f695d2394dd93edc25fd57f9 /editor/plugins/tile_map_editor_plugin.cpp
parentc21ca98e4c6e6228adefcc696b3ff6a1104c678e (diff)
Move some tilemap options to the toolbar
Diffstat (limited to 'editor/plugins/tile_map_editor_plugin.cpp')
-rw-r--r--editor/plugins/tile_map_editor_plugin.cpp135
1 files changed, 98 insertions, 37 deletions
diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp
index a967374eb9..8cd9921b11 100644
--- a/editor/plugins/tile_map_editor_plugin.cpp
+++ b/editor/plugins/tile_map_editor_plugin.cpp
@@ -66,6 +66,11 @@ void TileMapEditor::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: {
+ paint_button->set_icon(get_icon("Edit", "EditorIcons"));
+ bucket_fill_button->set_icon(get_icon("Bucket", "EditorIcons"));
+ picker_button->set_icon(get_icon("ColorPick", "EditorIcons"));
+ select_button->set_icon(get_icon("ActionCopy", "EditorIcons"));
+
rotate_left_button->set_icon(get_icon("Rotate270", "EditorIcons"));
rotate_right_button->set_icon(get_icon("Rotate90", "EditorIcons"));
flip_horizontal_button->set_icon(get_icon("MirrorX", "EditorIcons"));
@@ -76,9 +81,6 @@ void TileMapEditor::_notification(int p_what) {
search_box->set_clear_button_enabled(true);
PopupMenu *p = options->get_popup();
- p->set_item_icon(p->get_item_index(OPTION_PAINTING), get_icon("Edit", "EditorIcons"));
- p->set_item_icon(p->get_item_index(OPTION_PICK_TILE), get_icon("ColorPick", "EditorIcons"));
- p->set_item_icon(p->get_item_index(OPTION_SELECT), get_icon("ActionCopy", "EditorIcons"));
p->set_item_icon(p->get_item_index(OPTION_CUT), get_icon("ActionCut", "EditorIcons"));
p->set_item_icon(p->get_item_index(OPTION_COPY), get_icon("Duplicate", "EditorIcons"));
p->set_item_icon(p->get_item_index(OPTION_ERASE_SELECTION), get_icon("Remove", "EditorIcons"));
@@ -87,37 +89,51 @@ void TileMapEditor::_notification(int p_what) {
}
}
-void TileMapEditor::_menu_option(int p_option) {
+void TileMapEditor::_update_button_tool() {
- switch (p_option) {
-
- case OPTION_PAINTING: {
- // NOTE: We do not set tool = TOOL_PAINTING as this begins painting
- // immediately without pressing the left mouse button first
- tool = TOOL_NONE;
-
- CanvasItemEditor::get_singleton()->update_viewport();
+ ToolButton *tb[4] = { paint_button, bucket_fill_button, picker_button, select_button };
+ // Unpress all buttons
+ for (int i = 0; i < 4; i++) {
+ tb[i]->set_pressed(false);
+ }
+ // Press the good button
+ switch (tool) {
+ case TOOL_NONE:
+ case TOOL_PAINTING: {
+ paint_button->set_pressed(true);
} break;
- case OPTION_BUCKET: {
-
- tool = TOOL_BUCKET;
-
- CanvasItemEditor::get_singleton()->update_viewport();
+ case TOOL_BUCKET: {
+ bucket_fill_button->set_pressed(true);
} break;
- case OPTION_PICK_TILE: {
+ case TOOL_PICKING: {
+ picker_button->set_pressed(true);
+ } break;
+ case TOOL_SELECTING: {
+ select_button->set_pressed(true);
+ } break;
+ default:
+ break;
+ }
+}
- tool = TOOL_PICKING;
+void TileMapEditor::_button_tool_select(int p_tool) {
+ tool = (Tool)p_tool;
+ _update_button_tool();
+ switch (tool) {
+ case TOOL_SELECTING: {
- CanvasItemEditor::get_singleton()->update_viewport();
+ selection_active = false;
} break;
- case OPTION_SELECT: {
+ default:
+ break;
+ }
+ CanvasItemEditor::get_singleton()->update_viewport();
+}
- tool = TOOL_SELECTING;
- selection_active = false;
+void TileMapEditor::_menu_option(int p_option) {
- CanvasItemEditor::get_singleton()->update_viewport();
- } break;
+ switch (p_option) {
case OPTION_COPY: {
_update_copydata();
@@ -168,6 +184,7 @@ void TileMapEditor::_menu_option(int p_option) {
}
} break;
}
+ _update_button_tool();
}
void TileMapEditor::_palette_selected(int index) {
@@ -940,6 +957,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
selection_active = false;
rectangle_begin = over_tile;
+ _update_button_tool();
return true;
}
#ifdef APPLE_STYLE_KEYS
@@ -949,11 +967,13 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
#endif
tool = TOOL_PICKING;
_pick_tile(over_tile);
+ _update_button_tool();
return true;
}
tool = TOOL_PAINTING;
+ _update_button_tool();
}
if (tool == TOOL_PAINTING) {
@@ -975,6 +995,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
rectangle_begin = over_tile;
}
+ _update_button_tool();
return true;
} else {
@@ -1071,6 +1092,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
}
tool = TOOL_NONE;
+ _update_button_tool();
return true;
}
@@ -1086,6 +1108,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
CanvasItemEditor::get_singleton()->update_viewport();
+ _update_button_tool();
return true;
}
@@ -1096,6 +1119,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
CanvasItemEditor::get_singleton()->update_viewport();
+ _update_button_tool();
return true;
}
@@ -1126,6 +1150,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
_set_cell(local, invalid_cell);
}
+ _update_button_tool();
return true;
}
@@ -1140,6 +1165,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
tool = TOOL_NONE;
+ _update_button_tool();
return true;
} else if (tool == TOOL_BUCKET) {
@@ -1325,6 +1351,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
CanvasItemEditor::get_singleton()->update_viewport();
+ _update_button_tool();
return true;
}
@@ -1339,17 +1366,20 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
tool = TOOL_NONE;
CanvasItemEditor::get_singleton()->update_viewport();
+ _update_button_tool();
return true;
}
if (ED_IS_SHORTCUT("tile_map_editor/bucket_fill", p_event)) {
tool = TOOL_BUCKET;
CanvasItemEditor::get_singleton()->update_viewport();
+ _update_button_tool();
return true;
}
if (ED_IS_SHORTCUT("tile_map_editor/erase_selection", p_event)) {
_menu_option(OPTION_ERASE_SELECTION);
+ _update_button_tool();
return true;
}
if (ED_IS_SHORTCUT("tile_map_editor/select", p_event)) {
@@ -1358,6 +1388,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
CanvasItemEditor::get_singleton()->update_viewport();
+ _update_button_tool();
return true;
}
if (ED_IS_SHORTCUT("tile_map_editor/copy_selection", p_event)) {
@@ -1368,6 +1399,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
CanvasItemEditor::get_singleton()->update_viewport();
+ _update_button_tool();
return true;
}
}
@@ -1384,6 +1416,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
tool = TOOL_PASTING;
CanvasItemEditor::get_singleton()->update_viewport();
+ _update_button_tool();
return true;
}
}
@@ -1686,6 +1719,7 @@ void TileMapEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("_text_entered"), &TileMapEditor::_text_entered);
ClassDB::bind_method(D_METHOD("_text_changed"), &TileMapEditor::_text_changed);
ClassDB::bind_method(D_METHOD("_sbox_input"), &TileMapEditor::_sbox_input);
+ ClassDB::bind_method(D_METHOD("_button_tool_select"), &TileMapEditor::_button_tool_select);
ClassDB::bind_method(D_METHOD("_menu_option"), &TileMapEditor::_menu_option);
ClassDB::bind_method(D_METHOD("_canvas_mouse_enter"), &TileMapEditor::_canvas_mouse_enter);
ClassDB::bind_method(D_METHOD("_canvas_mouse_exit"), &TileMapEditor::_canvas_mouse_exit);
@@ -1866,37 +1900,64 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) {
// Add menu items
toolbar = memnew(HBoxContainer);
- toolbar->set_h_size_flags(SIZE_EXPAND_FILL);
- toolbar->set_alignment(BoxContainer::ALIGN_END);
toolbar->hide();
CanvasItemEditor::get_singleton()->add_control_to_menu_panel(toolbar);
+ // Separator
+ toolbar->add_child(memnew(VSeparator));
+
+ // Tools
+ paint_button = memnew(ToolButton);
+ paint_button->set_shortcut(ED_SHORTCUT("tile_map_editor/paint_tile", TTR("Paint Tile"), KEY_P));
+ paint_button->connect("pressed", this, "_button_tool_select", make_binds(TOOL_NONE));
+ paint_button->set_toggle_mode(true);
+ toolbar->add_child(paint_button);
+
+ bucket_fill_button = memnew(ToolButton);
+ bucket_fill_button->set_shortcut(ED_SHORTCUT("tile_map_editor/bucket_fill", TTR("Bucket Fill"), KEY_G));
+ bucket_fill_button->connect("pressed", this, "_button_tool_select", make_binds(TOOL_BUCKET));
+ bucket_fill_button->set_toggle_mode(true);
+ toolbar->add_child(bucket_fill_button);
+
+ picker_button = memnew(ToolButton);
+ picker_button->set_shortcut(ED_SHORTCUT("tile_map_editor/pîck_tile", TTR("Pick Tile"), KEY_CONTROL));
+ picker_button->connect("pressed", this, "_button_tool_select", make_binds(TOOL_PICKING));
+ picker_button->set_toggle_mode(true);
+ toolbar->add_child(picker_button);
+
+ select_button = memnew(ToolButton);
+ select_button->set_shortcut(ED_SHORTCUT("tile_map_editor/pîck_tile", TTR("Select"), KEY_MASK_CMD + KEY_B));
+ select_button->connect("pressed", this, "_button_tool_select", make_binds(TOOL_SELECTING));
+ select_button->set_toggle_mode(true);
+ toolbar->add_child(select_button);
+
+ _update_button_tool();
+
+ // Container to the right of the toolbar
+ toolbar_right = memnew(HBoxContainer);
+ toolbar_right->set_h_size_flags(SIZE_EXPAND_FILL);
+ toolbar_right->set_alignment(BoxContainer::ALIGN_END);
+ CanvasItemEditor::get_singleton()->add_control_to_menu_panel(toolbar_right);
+
// Tile position
tile_info = memnew(Label);
- toolbar->add_child(tile_info);
+ toolbar_right->add_child(tile_info);
+ // Menu
options = memnew(MenuButton);
options->set_text("TileMap");
options->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("TileMap", "EditorIcons"));
options->set_process_unhandled_key_input(false);
+ toolbar_right->add_child(options);
PopupMenu *p = options->get_popup();
-
- p->add_shortcut(ED_SHORTCUT("tile_map_editor/paint_tile", TTR("Paint Tile"), KEY_P), OPTION_PAINTING);
- p->add_shortcut(ED_SHORTCUT("tile_map_editor/bucket_fill", TTR("Bucket Fill"), KEY_G), OPTION_BUCKET);
- p->add_separator();
- p->add_item(TTR("Pick Tile"), OPTION_PICK_TILE, KEY_CONTROL);
- p->add_separator();
- p->add_shortcut(ED_SHORTCUT("tile_map_editor/select", TTR("Select"), KEY_MASK_CMD + KEY_B), OPTION_SELECT);
p->add_shortcut(ED_SHORTCUT("tile_map_editor/cut_selection", TTR("Cut Selection"), KEY_MASK_CMD + KEY_X), OPTION_CUT);
p->add_shortcut(ED_SHORTCUT("tile_map_editor/copy_selection", TTR("Copy Selection"), KEY_MASK_CMD + KEY_C), OPTION_COPY);
p->add_shortcut(ED_GET_SHORTCUT("tile_map_editor/erase_selection"), OPTION_ERASE_SELECTION);
p->add_separator();
p->add_item(TTR("Fix Invalid Tiles"), OPTION_FIX_INVALID);
-
p->connect("id_pressed", this, "_menu_option");
- toolbar->add_child(options);
rotate_left_button = memnew(ToolButton);
rotate_left_button->set_tooltip(TTR("Rotate left"));
rotate_left_button->set_focus_mode(FOCUS_NONE);