summaryrefslogtreecommitdiff
path: root/editor/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'editor/plugins')
-rw-r--r--editor/plugins/abstract_polygon_2d_editor.cpp11
-rw-r--r--editor/plugins/animation_state_machine_editor.cpp23
-rw-r--r--editor/plugins/animation_state_machine_editor.h1
-rw-r--r--editor/plugins/theme_editor_plugin.cpp221
-rw-r--r--editor/plugins/theme_editor_plugin.h7
-rw-r--r--editor/plugins/tile_map_editor_plugin.cpp135
-rw-r--r--editor/plugins/tile_map_editor_plugin.h12
-rw-r--r--editor/plugins/tile_set_editor_plugin.cpp39
8 files changed, 300 insertions, 149 deletions
diff --git a/editor/plugins/abstract_polygon_2d_editor.cpp b/editor/plugins/abstract_polygon_2d_editor.cpp
index 4a4e7f25b8..1afd7df049 100644
--- a/editor/plugins/abstract_polygon_2d_editor.cpp
+++ b/editor/plugins/abstract_polygon_2d_editor.cpp
@@ -481,6 +481,17 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event)
if (edited_point.valid() && (wip_active || (mm->get_button_mask() & BUTTON_MASK_LEFT))) {
Vector2 cpoint = _get_node()->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint)));
+
+ //Move the point in a single axis. Should only work when editing a polygon and while holding shift.
+ if (mode == MODE_EDIT && mm->get_shift()) {
+ Vector2 old_point = pre_move_edit.get(selected_point.vertex);
+ if (ABS(cpoint.x - old_point.x) > ABS(cpoint.y - old_point.y)) {
+ cpoint.y = old_point.y;
+ } else {
+ cpoint.x = old_point.x;
+ }
+ }
+
edited_point = PosVertex(edited_point, cpoint);
if (!wip_active) {
diff --git a/editor/plugins/animation_state_machine_editor.cpp b/editor/plugins/animation_state_machine_editor.cpp
index cb3e5a8129..567c336eff 100644
--- a/editor/plugins/animation_state_machine_editor.cpp
+++ b/editor/plugins/animation_state_machine_editor.cpp
@@ -876,7 +876,7 @@ void AnimationNodeStateMachineEditor::_state_machine_pos_draw() {
float len = MAX(0.0001, playback->get_current_length());
- float pos = CLAMP(playback->get_current_play_pos(), 0, len);
+ float pos = CLAMP(play_pos, 0, len);
float c = pos / len;
Color fg = get_color("font_color", "Label");
Color bg = fg;
@@ -1011,7 +1011,7 @@ void AnimationNodeStateMachineEditor::_notification(int p_what) {
bool is_playing = false;
StringName current_node;
StringName blend_from_node;
- float play_pos = 0;
+ play_pos = 0;
if (playback.is_valid()) {
tp = playback->get_travel_path();
@@ -1046,6 +1046,25 @@ void AnimationNodeStateMachineEditor::_notification(int p_what) {
state_machine_play_pos->update();
}
+ {
+ if (current_node != StringName() && state_machine->has_node(current_node)) {
+
+ String next = current_node;
+ Ref<AnimationNodeStateMachine> anodesm = state_machine->get_node(next);
+ Ref<AnimationNodeStateMachinePlayback> current_node_playback;
+
+ while (anodesm.is_valid()) {
+ current_node_playback = AnimationTreeEditor::get_singleton()->get_tree()->get(AnimationTreeEditor::get_singleton()->get_base_path() + next + "/playback");
+ next += "/" + current_node_playback->get_current_node();
+ anodesm = anodesm->get_node(current_node_playback->get_current_node());
+ }
+
+ // when current_node is a state machine, use playback of current_node to set play_pos
+ if (current_node_playback.is_valid())
+ play_pos = current_node_playback->get_current_play_pos();
+ }
+ }
+
if (last_play_pos != play_pos) {
last_play_pos = play_pos;
diff --git a/editor/plugins/animation_state_machine_editor.h b/editor/plugins/animation_state_machine_editor.h
index 1c4c06090a..135aff9027 100644
--- a/editor/plugins/animation_state_machine_editor.h
+++ b/editor/plugins/animation_state_machine_editor.h
@@ -160,6 +160,7 @@ class AnimationNodeStateMachineEditor : public AnimationTreeNodeEditorPlugin {
StringName last_current_node;
Vector<StringName> last_travel_path;
float last_play_pos;
+ float play_pos;
float error_time;
String error_text;
diff --git a/editor/plugins/theme_editor_plugin.cpp b/editor/plugins/theme_editor_plugin.cpp
index e9b9c03c1e..0bbffc8a0b 100644
--- a/editor/plugins/theme_editor_plugin.cpp
+++ b/editor/plugins/theme_editor_plugin.cpp
@@ -36,7 +36,7 @@
void ThemeEditor::edit(const Ref<Theme> &p_theme) {
theme = p_theme;
- main_vb->set_theme(p_theme);
+ main_container->set_theme(p_theme);
}
void ThemeEditor::_propagate_redraw(Control *p_at) {
@@ -53,7 +53,7 @@ void ThemeEditor::_propagate_redraw(Control *p_at) {
void ThemeEditor::_refresh_interval() {
- _propagate_redraw(main_vb);
+ _propagate_redraw(main_container);
}
void ThemeEditor::_type_menu_cbk(int p_option) {
@@ -574,7 +574,6 @@ void ThemeEditor::_theme_menu_cbk(int p_option) {
}
}
- //types.sort();
types.sort_custom<StringName::AlphCompare>();
for (List<StringName>::Element *E = types.front(); E; E = E->next()) {
@@ -610,30 +609,14 @@ ThemeEditor::ThemeEditor() {
time_left = 0;
- scroll = memnew(ScrollContainer);
- add_child(scroll);
- scroll->set_anchors_and_margins_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 3);
- scroll->set_margin(MARGIN_TOP, 30 * EDSCALE);
- //scroll->set_enable_h_scroll(true);
- scroll->set_enable_v_scroll(true);
- scroll->set_enable_h_scroll(false);
-
- Panel *panel = memnew(Panel);
- scroll->add_child(panel);
- panel->set_custom_minimum_size(Size2(500, 800) * EDSCALE);
- panel->set_theme(Theme::get_default());
- panel->set_h_size_flags(SIZE_EXPAND_FILL);
-
- main_vb = memnew(VBoxContainer);
- panel->add_child(main_vb);
- main_vb->set_anchors_and_margins_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 4 * EDSCALE);
+ HBoxContainer *top_menu = memnew(HBoxContainer);
+ add_child(top_menu);
- HBoxContainer *hb_menu = memnew(HBoxContainer);
- main_vb->add_child(hb_menu);
+ top_menu->add_child(memnew(Label(TTR("Preview:"))));
+ top_menu->add_spacer(false);
theme_menu = memnew(MenuButton);
- theme_menu->set_text(TTR("Edit theme..."));
- theme_menu->set_flat(false);
+ theme_menu->set_text(TTR("Edit Theme"));
theme_menu->set_tooltip(TTR("Theme editing menu."));
theme_menu->get_popup()->add_item(TTR("Add Item"), POPUP_ADD);
theme_menu->get_popup()->add_item(TTR("Add Class Items"), POPUP_CLASS_ADD);
@@ -643,51 +626,73 @@ ThemeEditor::ThemeEditor() {
theme_menu->get_popup()->add_item(TTR("Create Empty Template"), POPUP_CREATE_EMPTY);
theme_menu->get_popup()->add_item(TTR("Create Empty Editor Template"), POPUP_CREATE_EDITOR_EMPTY);
theme_menu->get_popup()->add_item(TTR("Create From Current Editor Theme"), POPUP_IMPORT_EDITOR_THEME);
- add_child(theme_menu);
- theme_menu->set_position(Vector2(3, 3) * EDSCALE);
+ top_menu->add_child(theme_menu);
theme_menu->get_popup()->connect("id_pressed", this, "_theme_menu_cbk");
+ scroll = memnew(ScrollContainer);
+ add_child(scroll);
+ scroll->set_enable_v_scroll(true);
+ scroll->set_enable_h_scroll(false);
+ scroll->set_v_size_flags(SIZE_EXPAND_FILL);
+
+ main_container = memnew(MarginContainer);
+ scroll->add_child(main_container);
+ main_container->set_clip_contents(true);
+ main_container->set_custom_minimum_size(Size2(700, 0) * EDSCALE);
+ main_container->set_v_size_flags(SIZE_EXPAND_FILL);
+ main_container->set_h_size_flags(SIZE_EXPAND_FILL);
+
+ //// Preview Controls ////
+
+ Panel *panel = memnew(Panel);
+ main_container->add_child(panel);
+ panel->set_theme(Theme::get_default());
+
+ MarginContainer *mc = memnew(MarginContainer);
+ main_container->add_child(mc);
+ mc->set_theme(Theme::get_default());
+ mc->add_constant_override("margin_right", 4 * EDSCALE);
+ mc->add_constant_override("margin_top", 4 * EDSCALE);
+ mc->add_constant_override("margin_left", 4 * EDSCALE);
+ mc->add_constant_override("margin_bottom", 4 * EDSCALE);
+
HBoxContainer *main_hb = memnew(HBoxContainer);
- main_vb->add_child(main_hb);
+ mc->add_child(main_hb);
VBoxContainer *first_vb = memnew(VBoxContainer);
- first_vb->set_h_size_flags(SIZE_EXPAND_FILL);
main_hb->add_child(first_vb);
-
- //main_panel->add_child(panel);
- //panel->set_anchors_and_margins_preset(Control::PRESET_WIDE);
- //panel->set_margin( MARGIN_TOP,20 );
+ first_vb->set_h_size_flags(SIZE_EXPAND_FILL);
+ first_vb->add_constant_override("separation", 10 * EDSCALE);
first_vb->add_child(memnew(Label("Label")));
first_vb->add_child(memnew(Button("Button")));
+ Button *bt = memnew(Button);
+ bt->set_text(TTR("Toggle Button"));
+ bt->set_toggle_mode(true);
+ bt->set_pressed(true);
+ first_vb->add_child(bt);
+ bt = memnew(Button);
+ bt->set_text(TTR("Disabled Button"));
+ bt->set_disabled(true);
+ first_vb->add_child(bt);
ToolButton *tb = memnew(ToolButton);
tb->set_text("ToolButton");
first_vb->add_child(tb);
+
CheckButton *cb = memnew(CheckButton);
cb->set_text("CheckButton");
first_vb->add_child(cb);
+ cb = memnew(CheckButton);
CheckBox *cbx = memnew(CheckBox);
cbx->set_text("CheckBox");
first_vb->add_child(cbx);
- VBoxContainer *bg = memnew(VBoxContainer);
- bg->set_v_size_flags(SIZE_EXPAND_FILL);
- VBoxContainer *gbvb = memnew(VBoxContainer);
- gbvb->set_v_size_flags(SIZE_EXPAND_FILL);
- CheckBox *rbx1 = memnew(CheckBox);
- rbx1->set_text(TTR("CheckBox Radio1"));
- rbx1->set_pressed(true);
- gbvb->add_child(rbx1);
- CheckBox *rbx2 = memnew(CheckBox);
- rbx2->set_text(TTR("CheckBox Radio2"));
- gbvb->add_child(rbx2);
- bg->add_child(gbvb);
- first_vb->add_child(bg);
-
MenuButton *test_menu_button = memnew(MenuButton);
test_menu_button->set_text("MenuButton");
test_menu_button->get_popup()->add_item(TTR("Item"));
+ test_menu_button->get_popup()->add_item(TTR("Disabled Item"));
+ test_menu_button->get_popup()->set_item_disabled(1, true);
test_menu_button->get_popup()->add_separator();
test_menu_button->get_popup()->add_check_item(TTR("Check Item"));
test_menu_button->get_popup()->add_check_item(TTR("Checked Item"));
@@ -696,6 +701,14 @@ ThemeEditor::ThemeEditor() {
test_menu_button->get_popup()->add_radio_check_item(TTR("Radio Item"));
test_menu_button->get_popup()->add_radio_check_item(TTR("Checked Radio Item"));
test_menu_button->get_popup()->set_item_checked(6, true);
+ test_menu_button->get_popup()->add_separator(TTR("Named Sep."));
+
+ PopupMenu *test_submenu = memnew(PopupMenu);
+ test_menu_button->get_popup()->add_child(test_submenu);
+ test_submenu->set_name("submenu");
+ test_menu_button->get_popup()->add_submenu_item(TTR("Submenu"), "submenu");
+ test_submenu->add_item(TTR("Item 1"));
+ test_submenu->add_item(TTR("Item 2"));
first_vb->add_child(test_menu_button);
OptionButton *test_option_button = memnew(OptionButton);
@@ -705,21 +718,7 @@ ThemeEditor::ThemeEditor() {
test_option_button->add_item(TTR("Many"));
test_option_button->add_item(TTR("Options"));
first_vb->add_child(test_option_button);
-
- ColorPickerButton *cpb = memnew(ColorPickerButton);
- first_vb->add_child(cpb);
-
- first_vb->add_child(memnew(HSeparator));
- first_vb->add_child(memnew(HSlider));
- first_vb->add_child(memnew(HScrollBar));
- first_vb->add_child(memnew(SpinBox));
- ProgressBar *pb = memnew(ProgressBar);
- pb->set_value(50);
- first_vb->add_child(pb);
- Panel *pn = memnew(Panel);
- pn->set_custom_minimum_size(Size2(40, 40) * EDSCALE);
- first_vb->add_child(pn);
- first_vb->add_constant_override("separation", 10 * EDSCALE);
+ first_vb->add_child(memnew(ColorPickerButton));
VBoxContainer *second_vb = memnew(VBoxContainer);
second_vb->set_h_size_flags(SIZE_EXPAND_FILL);
@@ -728,50 +727,48 @@ ThemeEditor::ThemeEditor() {
LineEdit *le = memnew(LineEdit);
le->set_text("LineEdit");
second_vb->add_child(le);
+ le = memnew(LineEdit);
+ le->set_text(TTR("Disabled LineEdit"));
+ le->set_editable(false);
+ second_vb->add_child(le);
TextEdit *te = memnew(TextEdit);
te->set_text("TextEdit");
- //te->set_v_size_flags(SIZE_EXPAND_FILL);
- te->set_custom_minimum_size(Size2(0, 160) * EDSCALE);
+ te->set_custom_minimum_size(Size2(0, 100) * EDSCALE);
second_vb->add_child(te);
+ second_vb->add_child(memnew(SpinBox));
- Tree *test_tree = memnew(Tree);
- second_vb->add_child(test_tree);
- test_tree->set_custom_minimum_size(Size2(0, 160) * EDSCALE);
-
- TreeItem *item = test_tree->create_item();
- item->set_editable(0, true);
- item->set_text(0, "Tree");
- item = test_tree->create_item(test_tree->get_root());
- item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
- item->set_editable(0, true);
- item->set_text(0, "Check");
- item = test_tree->create_item(test_tree->get_root());
- item->set_cell_mode(0, TreeItem::CELL_MODE_RANGE);
- item->set_editable(0, true);
- item->set_range_config(0, 0, 20, 0.1);
- item->set_range(0, 2);
- item = test_tree->create_item(test_tree->get_root());
- item->set_cell_mode(0, TreeItem::CELL_MODE_RANGE);
- item->set_editable(0, true);
- item->set_text(0, TTR("Has,Many,Options"));
- item->set_range(0, 2);
+ HBoxContainer *vhb = memnew(HBoxContainer);
+ second_vb->add_child(vhb);
+ vhb->set_custom_minimum_size(Size2(0, 100) * EDSCALE);
+ vhb->add_child(memnew(VSlider));
+ VScrollBar *vsb = memnew(VScrollBar);
+ vsb->set_page(25);
+ vhb->add_child(vsb);
+ vhb->add_child(memnew(VSeparator));
+ VBoxContainer *hvb = memnew(VBoxContainer);
+ vhb->add_child(hvb);
+ hvb->set_alignment(ALIGN_CENTER);
+ hvb->set_h_size_flags(SIZE_EXPAND_FILL);
+ hvb->add_child(memnew(HSlider));
+ HScrollBar *hsb = memnew(HScrollBar);
+ hsb->set_page(25);
+ hvb->add_child(hsb);
+ HSlider *hs = memnew(HSlider);
+ hs->set_editable(false);
+ hvb->add_child(hs);
+ hvb->add_child(memnew(HSeparator));
+ ProgressBar *pb = memnew(ProgressBar);
+ pb->set_value(50);
+ hvb->add_child(pb);
VBoxContainer *third_vb = memnew(VBoxContainer);
third_vb->set_h_size_flags(SIZE_EXPAND_FILL);
- third_vb->add_constant_override("separation", 10);
-
+ third_vb->add_constant_override("separation", 10 * EDSCALE);
main_hb->add_child(third_vb);
- HBoxContainer *vhb = memnew(HBoxContainer);
- vhb->set_custom_minimum_size(Size2(0, 160) * EDSCALE);
- vhb->add_child(memnew(VSeparator));
- vhb->add_child(memnew(VSlider));
- vhb->add_child(memnew(VScrollBar));
- third_vb->add_child(vhb);
-
TabContainer *tc = memnew(TabContainer);
third_vb->add_child(tc);
- tc->set_custom_minimum_size(Size2(0, 160) * EDSCALE);
+ tc->set_custom_minimum_size(Size2(0, 135) * EDSCALE);
Control *tcc = memnew(Control);
tcc->set_name(TTR("Tab 1"));
tc->add_child(tcc);
@@ -781,9 +778,41 @@ ThemeEditor::ThemeEditor() {
tcc = memnew(Control);
tcc->set_name(TTR("Tab 3"));
tc->add_child(tcc);
+ tc->set_tab_disabled(2, true);
+
+ Tree *test_tree = memnew(Tree);
+ third_vb->add_child(test_tree);
+ test_tree->set_custom_minimum_size(Size2(0, 175) * EDSCALE);
+ test_tree->add_constant_override("draw_relationship_lines", 1);
+
+ TreeItem *item = test_tree->create_item();
+ item->set_text(0, "Tree");
+ item = test_tree->create_item(test_tree->get_root());
+ item->set_text(0, "Item");
+ item = test_tree->create_item(test_tree->get_root());
+ item->set_editable(0, true);
+ item->set_text(0, TTR("Editable Item"));
+ TreeItem *sub_tree = test_tree->create_item(test_tree->get_root());
+ sub_tree->set_text(0, TTR("Subtree"));
+ item = test_tree->create_item(sub_tree);
+ item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
+ item->set_editable(0, true);
+ item->set_text(0, "Check Item");
+ item = test_tree->create_item(sub_tree);
+ item->set_cell_mode(0, TreeItem::CELL_MODE_RANGE);
+ item->set_editable(0, true);
+ item->set_range_config(0, 0, 20, 0.1);
+ item->set_range(0, 2);
+ item = test_tree->create_item(sub_tree);
+ item->set_cell_mode(0, TreeItem::CELL_MODE_RANGE);
+ item->set_editable(0, true);
+ item->set_text(0, TTR("Has,Many,Options"));
+ item->set_range(0, 2);
main_hb->add_constant_override("separation", 20 * EDSCALE);
+ ////////
+
add_del_dialog = memnew(ConfirmationDialog);
add_del_dialog->hide();
add_child(add_del_dialog);
@@ -844,9 +873,6 @@ ThemeEditor::ThemeEditor() {
file_dialog->add_filter("*.theme ; Theme File");
add_child(file_dialog);
file_dialog->connect("file_selected", this, "_save_template_cbk");
-
- //MenuButton *name_menu;
- //LineEdit *name_edit;
}
void ThemeEditorPlugin::edit(Object *p_node) {
@@ -886,7 +912,6 @@ ThemeEditorPlugin::ThemeEditorPlugin(EditorNode *p_node) {
theme_editor = memnew(ThemeEditor);
theme_editor->set_custom_minimum_size(Size2(0, 200));
- //p_node->get_viewport()->add_child(theme_editor);
button = editor->add_bottom_panel_item(TTR("Theme"), theme_editor);
button->hide();
}
diff --git a/editor/plugins/theme_editor_plugin.h b/editor/plugins/theme_editor_plugin.h
index 352988d69e..cc236907a9 100644
--- a/editor/plugins/theme_editor_plugin.h
+++ b/editor/plugins/theme_editor_plugin.h
@@ -33,6 +33,7 @@
#include "scene/gui/check_box.h"
#include "scene/gui/file_dialog.h"
+#include "scene/gui/margin_container.h"
#include "scene/gui/option_button.h"
#include "scene/gui/scroll_container.h"
#include "scene/gui/texture_rect.h"
@@ -40,12 +41,12 @@
#include "editor/editor_node.h"
-class ThemeEditor : public Control {
+class ThemeEditor : public VBoxContainer {
- GDCLASS(ThemeEditor, Control);
+ GDCLASS(ThemeEditor, VBoxContainer);
ScrollContainer *scroll;
- VBoxContainer *main_vb;
+ MarginContainer *main_container;
Ref<Theme> theme;
EditorFileDialog *file_dialog;
diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp
index 33e4bb2336..467b83f4f8 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) {
@@ -944,6 +961,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
@@ -953,11 +971,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) {
@@ -979,6 +999,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
rectangle_begin = over_tile;
}
+ _update_button_tool();
return true;
} else {
@@ -1075,6 +1096,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
}
tool = TOOL_NONE;
+ _update_button_tool();
return true;
}
@@ -1090,6 +1112,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
CanvasItemEditor::get_singleton()->update_viewport();
+ _update_button_tool();
return true;
}
@@ -1100,6 +1123,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
CanvasItemEditor::get_singleton()->update_viewport();
+ _update_button_tool();
return true;
}
@@ -1130,6 +1154,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
_set_cell(local, invalid_cell);
}
+ _update_button_tool();
return true;
}
@@ -1144,6 +1169,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
tool = TOOL_NONE;
+ _update_button_tool();
return true;
} else if (tool == TOOL_BUCKET) {
@@ -1329,6 +1355,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
CanvasItemEditor::get_singleton()->update_viewport();
+ _update_button_tool();
return true;
}
@@ -1343,17 +1370,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)) {
@@ -1362,6 +1392,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)) {
@@ -1372,6 +1403,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
CanvasItemEditor::get_singleton()->update_viewport();
+ _update_button_tool();
return true;
}
}
@@ -1388,6 +1420,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
tool = TOOL_PASTING;
CanvasItemEditor::get_singleton()->update_viewport();
+ _update_button_tool();
return true;
}
}
@@ -1700,6 +1733,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);
@@ -1880,37 +1914,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);
diff --git a/editor/plugins/tile_map_editor_plugin.h b/editor/plugins/tile_map_editor_plugin.h
index b30426eabe..296e861949 100644
--- a/editor/plugins/tile_map_editor_plugin.h
+++ b/editor/plugins/tile_map_editor_plugin.h
@@ -66,12 +66,8 @@ class TileMapEditor : public VBoxContainer {
enum Options {
- OPTION_BUCKET,
- OPTION_PICK_TILE,
- OPTION_SELECT,
OPTION_COPY,
OPTION_ERASE_SELECTION,
- OPTION_PAINTING,
OPTION_FIX_INVALID,
OPTION_CUT
};
@@ -90,10 +86,16 @@ class TileMapEditor : public VBoxContainer {
ItemList *manual_palette;
HBoxContainer *toolbar;
+ HBoxContainer *toolbar_right;
Label *tile_info;
MenuButton *options;
+ ToolButton *paint_button;
+ ToolButton *bucket_fill_button;
+ ToolButton *picker_button;
+ ToolButton *select_button;
+
ToolButton *flip_horizontal_button;
ToolButton *flip_vertical_button;
ToolButton *rotate_left_button;
@@ -184,6 +186,8 @@ class TileMapEditor : public VBoxContainer {
void _text_changed(const String &p_text);
void _sbox_input(const Ref<InputEvent> &p_ie);
void _update_palette();
+ void _update_button_tool();
+ void _button_tool_select(int p_tool);
void _menu_option(int p_option);
void _palette_selected(int index);
void _palette_multi_selected(int index, bool selected);
diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp
index 8cf00cf67d..21470d81ed 100644
--- a/editor/plugins/tile_set_editor_plugin.cpp
+++ b/editor/plugins/tile_set_editor_plugin.cpp
@@ -1561,13 +1561,42 @@ void TileSetEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) {
if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
_set_edited_collision_shape(Ref<ConvexPolygonShape2D>());
current_shape.resize(0);
- current_shape.push_back(snap_point(shape_anchor));
- current_shape.push_back(snap_point(shape_anchor + Vector2(current_tile_region.size.x, 0)));
- current_shape.push_back(snap_point(shape_anchor + current_tile_region.size));
- current_shape.push_back(snap_point(shape_anchor + Vector2(0, current_tile_region.size.y)));
- close_shape(shape_anchor);
+ Vector2 pos = mb->get_position();
+ pos = snap_point(pos);
+ current_shape.push_back(pos);
+ current_shape.push_back(pos);
+ current_shape.push_back(pos);
+ current_shape.push_back(pos);
+ creating_shape = true;
workspace->update();
+ return;
} else if (mb->is_pressed() && mb->get_button_index() == BUTTON_RIGHT) {
+ if (creating_shape) {
+ creating_shape = false;
+ _select_edited_shape_coord();
+ workspace->update();
+ }
+ } else if (!mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
+ if (creating_shape) {
+ if ((current_shape[0] - current_shape[1]).length_squared() <= grab_threshold) {
+ current_shape.set(0, snap_point(shape_anchor));
+ current_shape.set(1, snap_point(shape_anchor + Vector2(current_tile_region.size.x, 0)));
+ current_shape.set(2, snap_point(shape_anchor + current_tile_region.size));
+ current_shape.set(3, snap_point(shape_anchor + Vector2(0, current_tile_region.size.y)));
+ }
+ close_shape(shape_anchor);
+ workspace->update();
+ return;
+ }
+ }
+ } else if (mm.is_valid()) {
+ if (creating_shape) {
+ Vector2 pos = mm->get_position();
+ pos = snap_point(pos);
+ Vector2 p = current_shape[2];
+ current_shape.set(3, snap_point(Vector2(pos.x, p.y)));
+ current_shape.set(0, snap_point(pos));
+ current_shape.set(1, snap_point(Vector2(p.x, pos.y)));
workspace->update();
}
}