Skip to content

Commit

Permalink
Fix polygon editor not initializing toolbar correctly
Browse files Browse the repository at this point in the history
Robystify mode changing logic and use it to initialize the toolbar upon entering the editor.
  • Loading branch information
aXu-AP committed Nov 19, 2024
1 parent d9966f9 commit 8b64dbb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 55 deletions.
78 changes: 23 additions & 55 deletions editor/plugins/polygon_2d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ void Polygon2DEditor::_set_node(Node *p_polygon) {
EditorNode::get_bottom_panel()->make_item_visible(polygon_edit);
_update_bone_list();
_update_available_modes();
if (current_mode == MODE_MAX) {
_select_mode(MODE_POINTS); // Initialize when opening the first time.
}
get_tree()->connect("process_frame", callable_mp(this, &Polygon2DEditor::_center_view), CONNECT_ONE_SHOT);
// Whenever polygon gets redrawn, there's possible changes for the editor as well.
node->connect("draw", callable_mp(draw, &CanvasItem::queue_redraw));
Expand Down Expand Up @@ -243,67 +246,45 @@ void Polygon2DEditor::_bone_paint_selected(int p_index) {
void Polygon2DEditor::_select_mode(int p_mode) {
current_mode = Mode(p_mode);
mode_buttons[current_mode]->set_pressed(true);
for (int i = 0; i < ACTION_MAX; i++) {
action_buttons[i]->hide();
}
bone_scroll_main_vb->hide();
bone_paint_strength->hide();
bone_paint_radius->hide();
bone_paint_radius_label->hide();
switch (current_mode) {
case MODE_POINTS: {
for (int i = 0; i <= ACTION_SCALE; i++) {
action_buttons[i]->show();
}
action_buttons[ACTION_ADD_POLYGON]->hide();
action_buttons[ACTION_REMOVE_POLYGON]->hide();
action_buttons[ACTION_PAINT_WEIGHT]->hide();
action_buttons[ACTION_CLEAR_WEIGHT]->hide();
action_buttons[ACTION_CREATE]->show();
action_buttons[ACTION_CREATE_INTERNAL]->show();
action_buttons[ACTION_REMOVE_INTERNAL]->show();
action_buttons[ACTION_EDIT_POINT]->show();
action_buttons[ACTION_MOVE]->show();
action_buttons[ACTION_ROTATE]->show();
action_buttons[ACTION_SCALE]->show();

if (node->get_polygon().is_empty()) {
_set_action(ACTION_CREATE);
} else {
_set_action(ACTION_EDIT_POINT);
}

bone_scroll_main_vb->hide();
bone_paint_strength->hide();
bone_paint_radius->hide();
bone_paint_radius_label->hide();
} break;
case MODE_POLYGONS: {
for (int i = 0; i <= ACTION_SCALE; i++) {
action_buttons[i]->hide();
}
action_buttons[ACTION_ADD_POLYGON]->show();
action_buttons[ACTION_REMOVE_POLYGON]->show();
action_buttons[ACTION_PAINT_WEIGHT]->hide();
action_buttons[ACTION_CLEAR_WEIGHT]->hide();
_set_action(ACTION_ADD_POLYGON);

bone_scroll_main_vb->hide();
bone_paint_strength->hide();
bone_paint_radius->hide();
bone_paint_radius_label->hide();
} break;
case MODE_UV: {
if (node->get_uv().size() != node->get_polygon().size()) {
_edit_menu_option(MENU_POLYGON_TO_UV);
}

action_buttons[ACTION_CREATE]->hide();
action_buttons[ACTION_CREATE_INTERNAL]->hide();
action_buttons[ACTION_REMOVE_INTERNAL]->hide();
for (int i = ACTION_EDIT_POINT; i <= ACTION_SCALE; i++) {
action_buttons[i]->show();
}
action_buttons[ACTION_ADD_POLYGON]->hide();
action_buttons[ACTION_REMOVE_POLYGON]->hide();
action_buttons[ACTION_PAINT_WEIGHT]->hide();
action_buttons[ACTION_CLEAR_WEIGHT]->hide();
action_buttons[ACTION_EDIT_POINT]->show();
action_buttons[ACTION_MOVE]->show();
action_buttons[ACTION_ROTATE]->show();
action_buttons[ACTION_SCALE]->show();
_set_action(ACTION_EDIT_POINT);

bone_scroll_main_vb->hide();
bone_paint_strength->hide();
bone_paint_radius->hide();
bone_paint_radius_label->hide();
} break;
case MODE_WEIGHTS: {
for (int i = 0; i <= ACTION_REMOVE_POLYGON; i++) {
action_buttons[i]->hide();
}
action_buttons[ACTION_PAINT_WEIGHT]->show();
action_buttons[ACTION_CLEAR_WEIGHT]->show();
_set_action(ACTION_PAINT_WEIGHT);
Expand Down Expand Up @@ -1280,7 +1261,6 @@ Polygon2DEditor::Polygon2DEditor() {
polygon_edit = memnew(VBoxContainer);
HBoxContainer *uv_mode_hb = memnew(HBoxContainer);

Ref<ButtonGroup> mode_button_group;
mode_button_group.instantiate();
for (int i = 0; i < MODE_MAX; i++) {
mode_buttons[i] = memnew(Button);
Expand Down Expand Up @@ -1321,15 +1301,6 @@ Polygon2DEditor::Polygon2DEditor() {
action_buttons[ACTION_PAINT_WEIGHT]->set_tooltip_text(TTR("Paint weights with specified intensity."));
action_buttons[ACTION_CLEAR_WEIGHT]->set_tooltip_text(TTR("Unpaint weights with specified intensity."));

action_buttons[ACTION_CREATE]->hide();
action_buttons[ACTION_CREATE_INTERNAL]->hide();
action_buttons[ACTION_REMOVE_INTERNAL]->hide();
action_buttons[ACTION_ADD_POLYGON]->hide();
action_buttons[ACTION_REMOVE_POLYGON]->hide();
action_buttons[ACTION_PAINT_WEIGHT]->hide();
action_buttons[ACTION_CLEAR_WEIGHT]->hide();
action_buttons[ACTION_EDIT_POINT]->set_pressed(true);

bone_paint_strength = memnew(HSlider);
uv_mode_hb->add_child(bone_paint_strength);
bone_paint_strength->set_custom_minimum_size(Size2(75 * EDSCALE, 0));
Expand All @@ -1344,9 +1315,6 @@ Polygon2DEditor::Polygon2DEditor() {
bone_paint_radius = memnew(SpinBox);
uv_mode_hb->add_child(bone_paint_radius);

bone_paint_strength->hide();
bone_paint_radius->hide();
bone_paint_radius_label->hide();
bone_paint_radius->set_min(1);
bone_paint_radius->set_max(100);
bone_paint_radius->set_step(1);
Expand Down Expand Up @@ -1466,7 +1434,6 @@ Polygon2DEditor::Polygon2DEditor() {
hscroll->connect(SceneStringName(value_changed), callable_mp(this, &Polygon2DEditor::_update_zoom_and_pan).unbind(1).bind(false));

bone_scroll_main_vb = memnew(VBoxContainer);
bone_scroll_main_vb->hide();
bone_scroll_main_vb->set_custom_minimum_size(Size2(150 * EDSCALE, 0));
sync_bones = memnew(Button(TTR("Sync Bones to Polygon")));
bone_scroll_main_vb->add_child(sync_bones);
Expand All @@ -1493,6 +1460,7 @@ Polygon2DEditor::Polygon2DEditor() {
is_dragging = false;
is_creating = false;
bone_painting = false;
current_mode = MODE_MAX; // Uninitialized.

error = memnew(AcceptDialog);
add_child(error);
Expand Down
1 change: 1 addition & 0 deletions editor/plugins/polygon_2d_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class Polygon2DEditor : public AbstractPolygon2DEditor {
VBoxContainer *polygon_edit = nullptr;
Mode current_mode;
Button *mode_buttons[MODE_MAX];
Ref<ButtonGroup> mode_button_group;
Action selected_action;
Button *action_buttons[ACTION_MAX];
Button *b_snap_enable = nullptr;
Expand Down

0 comments on commit 8b64dbb

Please sign in to comment.