diff options
Diffstat (limited to 'editor/plugins')
47 files changed, 1796 insertions, 1529 deletions
diff --git a/editor/plugins/abstract_polygon_2d_editor.cpp b/editor/plugins/abstract_polygon_2d_editor.cpp index f7e59e2beb..dfdf56a2ef 100644 --- a/editor/plugins/abstract_polygon_2d_editor.cpp +++ b/editor/plugins/abstract_polygon_2d_editor.cpp @@ -103,6 +103,11 @@ bool AbstractPolygon2DEditor::_is_line() const { return false; } +bool AbstractPolygon2DEditor::_has_uv() const { + + return false; +} + int AbstractPolygon2DEditor::_get_polygon_count() const { return 1; @@ -132,8 +137,8 @@ Vector2 AbstractPolygon2DEditor::_get_offset(int p_idx) const { void AbstractPolygon2DEditor::_commit_action() { - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_do_method(canvas_item_editor, "update_viewport"); + undo_redo->add_undo_method(canvas_item_editor, "update_viewport"); undo_redo->commit_action(); } @@ -202,12 +207,7 @@ void AbstractPolygon2DEditor::_notification(int p_what) { button_edit->set_pressed(true); get_tree()->connect("node_removed", this, "_node_removed"); - create_resource->connect("confirmed", this, "_create_resource"); - - } break; - case NOTIFICATION_PHYSICS_PROCESS: { - } break; } } @@ -218,7 +218,7 @@ void AbstractPolygon2DEditor::_node_removed(Node *p_node) { edit(NULL); hide(); - canvas_item_editor->get_viewport_control()->update(); + canvas_item_editor->update_viewport(); } } @@ -229,6 +229,18 @@ void AbstractPolygon2DEditor::_wip_changed() { } } +void AbstractPolygon2DEditor::_wip_cancel() { + + wip.clear(); + wip_active = false; + + edited_point = PosVertex(); + hover_point = Vertex(); + selected_point = Vertex(); + + canvas_item_editor->update_viewport(); +} + void AbstractPolygon2DEditor::_wip_close() { if (!wip_active) return; @@ -238,8 +250,12 @@ void AbstractPolygon2DEditor::_wip_close() { _set_polygon(0, wip); } else if (wip.size() >= (_is_line() ? 2 : 3)) { - undo_redo->create_action(TTR("Create Poly")); + undo_redo->create_action(TTR("Create Polygon")); _action_add_polygon(wip); + if (_has_uv()) { + undo_redo->add_do_method(_get_node(), "set_uv", PoolVector<Vector2>()); + undo_redo->add_undo_method(_get_node(), "set_uv", _get_node()->get("uv")); + } _commit_action(); } else { @@ -301,7 +317,7 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) if (vertices.size() < (_is_line() ? 2 : 3)) { vertices.push_back(cpoint); - undo_redo->create_action(TTR("Edit Poly")); + undo_redo->create_action(TTR("Edit Polygon")); selected_point = Vertex(insert.polygon, vertices.size()); _action_set_polygon(insert.polygon, vertices); _commit_action(); @@ -319,7 +335,6 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) undo_redo->create_action(TTR("Insert Point")); _action_set_polygon(insert.polygon, vertices); _commit_action(); - return true; } } else { @@ -334,7 +349,7 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) edited_point = PosVertex(closest, xform.affine_inverse().xform(closest.pos)); selected_point = closest; edge_point = PosVertex(); - canvas_item_editor->get_viewport_control()->update(); + canvas_item_editor->update_viewport(); return true; } else { @@ -351,7 +366,7 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) ERR_FAIL_INDEX_V(edited_point.vertex, vertices.size(), false); vertices.write[edited_point.vertex] = edited_point.pos - _get_offset(edited_point.polygon); - undo_redo->create_action(TTR("Edit Poly")); + undo_redo->create_action(TTR("Edit Polygon")); _action_set_polygon(edited_point.polygon, pre_move_edit, vertices); _commit_action(); @@ -403,14 +418,14 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) wip_active = true; _wip_changed(); edited_point = PosVertex(-1, 1, cpoint); - canvas_item_editor->get_viewport_control()->update(); + canvas_item_editor->update_viewport(); hover_point = Vertex(); selected_point = Vertex(0); edge_point = PosVertex(); return true; } else { - const real_t grab_threshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8); + const real_t grab_threshold = EDITOR_GET("editors/poly_editor/point_grab_radius"); if (!_is_line() && wip.size() > 1 && xform.xform(wip[0]).distance_to(gpoint) < grab_threshold) { //wip closed @@ -424,12 +439,12 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) _wip_changed(); edited_point = PosVertex(-1, wip.size(), cpoint); selected_point = Vertex(wip.size() - 1); - canvas_item_editor->get_viewport_control()->update(); + canvas_item_editor->update_viewport(); return true; } } } else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed() && wip_active) { - _wip_close(); + _wip_cancel(); } } } @@ -453,7 +468,7 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) _set_polygon(edited_point.polygon, vertices); } - canvas_item_editor->get_viewport_control()->update(); + canvas_item_editor->update_viewport(); } else if (mode == MODE_EDIT || (_is_line() && mode == MODE_CREATE)) { const PosVertex onEdgeVertex = closest_edge_point(gpoint); @@ -462,20 +477,20 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) hover_point = Vertex(); edge_point = onEdgeVertex; - canvas_item_editor->get_viewport_control()->update(); + canvas_item_editor->update_viewport(); } else { if (edge_point.valid()) { edge_point = PosVertex(); - canvas_item_editor->get_viewport_control()->update(); + canvas_item_editor->update_viewport(); } const PosVertex new_hover_point = closest_point(gpoint); if (hover_point != new_hover_point) { hover_point = new_hover_point; - canvas_item_editor->get_viewport_control()->update(); + canvas_item_editor->update_viewport(); } } } @@ -494,7 +509,7 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) wip.remove(selected_point.vertex); _wip_changed(); selected_point = wip.size() - 1; - canvas_item_editor->get_viewport_control()->update(); + canvas_item_editor->update_viewport(); return true; } } else { @@ -510,6 +525,8 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) } else if (wip_active && k->get_scancode() == KEY_ENTER) { _wip_close(); + } else if (wip_active && k->get_scancode() == KEY_ESCAPE) { + _wip_cancel(); } } @@ -517,6 +534,7 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) } void AbstractPolygon2DEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { + if (!_get_node()) return; @@ -547,7 +565,7 @@ void AbstractPolygon2DEditor::forward_canvas_draw_over_viewport(Control *p_overl offset = _get_offset(j); } - if (!wip_active && j == edited_point.polygon && EDITOR_DEF("editors/poly_editor/show_previous_outline", true)) { + if (!wip_active && j == edited_point.polygon && EDITOR_GET("editors/poly_editor/show_previous_outline")) { const Color col = Color(0.5, 0.5, 0.5); // FIXME polygon->get_outline_color(); const int n = pre_move_edit.size(); @@ -617,9 +635,11 @@ void AbstractPolygon2DEditor::edit(Node *p_polygon) { _set_node(p_polygon); - //Enable the pencil tool if the polygon is empty + // Enable the pencil tool if the polygon is empty. if (_is_empty()) _menu_option(MODE_CREATE); + else + _menu_option(MODE_EDIT); wip.clear(); wip_active = false; @@ -627,7 +647,7 @@ void AbstractPolygon2DEditor::edit(Node *p_polygon) { hover_point = Vertex(); selected_point = Vertex(); - canvas_item_editor->get_viewport_control()->update(); + canvas_item_editor->update_viewport(); } else { @@ -650,12 +670,12 @@ void AbstractPolygon2DEditor::remove_point(const Vertex &p_vertex) { vertices.remove(p_vertex.vertex); - undo_redo->create_action(TTR("Edit Poly (Remove Point)")); + undo_redo->create_action(TTR("Edit Polygon (Remove Point)")); _action_set_polygon(p_vertex.polygon, vertices); _commit_action(); } else { - undo_redo->create_action(TTR("Remove Poly And Point")); + undo_redo->create_action(TTR("Remove Polygon And Point")); _action_remove_polygon(p_vertex.polygon); _commit_action(); } @@ -675,7 +695,7 @@ AbstractPolygon2DEditor::Vertex AbstractPolygon2DEditor::get_active_point() cons AbstractPolygon2DEditor::PosVertex AbstractPolygon2DEditor::closest_point(const Vector2 &p_pos) const { - const real_t grab_threshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8); + const real_t grab_threshold = EDITOR_GET("editors/poly_editor/point_grab_radius"); const int n_polygons = _get_polygon_count(); const Transform2D xform = canvas_item_editor->get_canvas_transform() * _get_node()->get_global_transform(); @@ -706,7 +726,7 @@ AbstractPolygon2DEditor::PosVertex AbstractPolygon2DEditor::closest_point(const AbstractPolygon2DEditor::PosVertex AbstractPolygon2DEditor::closest_edge_point(const Vector2 &p_pos) const { - const real_t grab_threshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8); + const real_t grab_threshold = EDITOR_GET("editors/poly_editor/point_grab_radius"); const real_t eps = grab_threshold * 2; const real_t eps2 = eps * eps; @@ -763,19 +783,19 @@ AbstractPolygon2DEditor::AbstractPolygon2DEditor(EditorNode *p_editor, bool p_wi add_child(button_create); button_create->connect("pressed", this, "_menu_option", varray(MODE_CREATE)); button_create->set_toggle_mode(true); - button_create->set_tooltip(TTR("Create a new polygon from scratch")); + button_create->set_tooltip(TTR("Create points.")); button_edit = memnew(ToolButton); add_child(button_edit); button_edit->connect("pressed", this, "_menu_option", varray(MODE_EDIT)); button_edit->set_toggle_mode(true); - button_edit->set_tooltip(TTR("Edit existing polygon:\nLMB: Move Point.\nCtrl+LMB: Split Segment.\nRMB: Erase Point.")); + button_edit->set_tooltip(TTR("Edit points.\nLMB: Move Point\nRMB: Erase Point")); button_delete = memnew(ToolButton); add_child(button_delete); button_delete->connect("pressed", this, "_menu_option", varray(MODE_DELETE)); button_delete->set_toggle_mode(true); - button_delete->set_tooltip(TTR("Delete points")); + button_delete->set_tooltip(TTR("Erase points.")); create_resource = memnew(ConfirmationDialog); add_child(create_resource); @@ -806,13 +826,11 @@ void AbstractPolygon2DEditorPlugin::make_visible(bool p_visible) { } } -AbstractPolygon2DEditorPlugin::AbstractPolygon2DEditorPlugin(EditorNode *p_node, AbstractPolygon2DEditor *p_polygon_editor, String p_class) { - - editor = p_node; - polygon_editor = p_polygon_editor; - klass = p_class; +AbstractPolygon2DEditorPlugin::AbstractPolygon2DEditorPlugin(EditorNode *p_node, AbstractPolygon2DEditor *p_polygon_editor, String p_class) : + polygon_editor(p_polygon_editor), + editor(p_node), + klass(p_class) { CanvasItemEditor::get_singleton()->add_control_to_menu_panel(polygon_editor); - polygon_editor->hide(); } diff --git a/editor/plugins/abstract_polygon_2d_editor.h b/editor/plugins/abstract_polygon_2d_editor.h index 00634ba5b8..046e8540e7 100644 --- a/editor/plugins/abstract_polygon_2d_editor.h +++ b/editor/plugins/abstract_polygon_2d_editor.h @@ -88,12 +88,10 @@ class AbstractPolygon2DEditor : public HBoxContainer { protected: enum { - MODE_CREATE, MODE_EDIT, MODE_DELETE, MODE_CONT, - }; int mode; @@ -103,6 +101,7 @@ protected: virtual void _menu_option(int p_option); void _wip_changed(); void _wip_close(); + void _wip_cancel(); bool _delete_point(const Vector2 &p_gpoint); void _notification(int p_what); @@ -115,13 +114,12 @@ protected: PosVertex closest_edge_point(const Vector2 &p_pos) const; bool _is_empty() const; - void _commit_action(); -protected: virtual Node2D *_get_node() const = 0; virtual void _set_node(Node *p_polygon) = 0; virtual bool _is_line() const; + virtual bool _has_uv() const; virtual int _get_polygon_count() const; virtual Vector2 _get_offset(int p_idx) const; virtual Variant _get_polygon(int p_idx) const; @@ -131,6 +129,7 @@ protected: virtual void _action_remove_polygon(int p_idx); virtual void _action_set_polygon(int p_idx, const Variant &p_polygon); virtual void _action_set_polygon(int p_idx, const Variant &p_previous, const Variant &p_polygon); + virtual void _commit_action(); virtual bool _has_resource() const; virtual void _create_resource(); diff --git a/editor/plugins/animation_blend_space_2d_editor.cpp b/editor/plugins/animation_blend_space_2d_editor.cpp index 394b888d0e..e2fe9a91d8 100644 --- a/editor/plugins/animation_blend_space_2d_editor.cpp +++ b/editor/plugins/animation_blend_space_2d_editor.cpp @@ -607,6 +607,8 @@ void AnimationNodeBlendSpace2DEditor::_update_space() { auto_triangles->set_pressed(blend_space->get_auto_triangles()); + interpolation->select(blend_space->get_blend_mode()); + max_x_value->set_value(blend_space->get_max_space().x); max_y_value->set_value(blend_space->get_max_space().y); @@ -636,6 +638,8 @@ void AnimationNodeBlendSpace2DEditor::_config_changed(double) { undo_redo->add_undo_method(blend_space.ptr(), "set_min_space", blend_space->get_min_space()); undo_redo->add_do_method(blend_space.ptr(), "set_snap", Vector2(snap_x->get_value(), snap_y->get_value())); undo_redo->add_undo_method(blend_space.ptr(), "set_snap", blend_space->get_snap()); + undo_redo->add_do_method(blend_space.ptr(), "set_blend_mode", interpolation->get_selected()); + undo_redo->add_undo_method(blend_space.ptr(), "set_blend_mode", blend_space->get_blend_mode()); undo_redo->add_do_method(this, "_update_space"); undo_redo->add_undo_method(this, "_update_space"); undo_redo->commit_action(); @@ -752,6 +756,10 @@ void AnimationNodeBlendSpace2DEditor::_notification(int p_what) { snap->set_icon(get_icon("SnapGrid", "EditorIcons")); open_editor->set_icon(get_icon("Edit", "EditorIcons")); auto_triangles->set_icon(get_icon("AutoTriangle", "EditorIcons")); + interpolation->clear(); + interpolation->add_icon_item(get_icon("TrackContinuous", "EditorIcons"), "", 0); + interpolation->add_icon_item(get_icon("TrackDiscrete", "EditorIcons"), "", 1); + interpolation->add_icon_item(get_icon("TrackCapture", "EditorIcons"), "", 2); } if (p_what == NOTIFICATION_PROCESS) { @@ -914,6 +922,13 @@ AnimationNodeBlendSpace2DEditor::AnimationNodeBlendSpace2DEditor() { snap_y->set_step(0.01); snap_y->set_max(1000); + top_hb->add_child(memnew(VSeparator)); + + top_hb->add_child(memnew(Label(TTR("Blend:")))); + interpolation = memnew(OptionButton); + top_hb->add_child(interpolation); + interpolation->connect("item_selected", this, "_config_changed"); + edit_hb = memnew(HBoxContainer); top_hb->add_child(edit_hb); edit_hb->add_child(memnew(VSeparator)); diff --git a/editor/plugins/animation_blend_space_2d_editor.h b/editor/plugins/animation_blend_space_2d_editor.h index 613289e4d8..603fa1cd19 100644 --- a/editor/plugins/animation_blend_space_2d_editor.h +++ b/editor/plugins/animation_blend_space_2d_editor.h @@ -60,6 +60,7 @@ class AnimationNodeBlendSpace2DEditor : public AnimationTreeNodeEditorPlugin { ToolButton *snap; SpinBox *snap_x; SpinBox *snap_y; + OptionButton *interpolation; ToolButton *auto_triangles; diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp index 205458fb1d..eb3c432ee7 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.cpp +++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp @@ -692,7 +692,9 @@ void AnimationNodeBlendTreeEditor::_notification(int p_what) { Ref<Animation> anim = player->get_animation(an->get_animation()); if (anim.is_valid()) { E->get()->set_max(anim->get_length()); - E->get()->set_value(an->get_playback_time()); + //StringName path = AnimationTreeEditor::get_singleton()->get_base_path() + E->get().input_node; + StringName time_path = AnimationTreeEditor::get_singleton()->get_base_path() + String(E->key()) + "/time"; + E->get()->set_value(AnimationTreeEditor::get_singleton()->get_tree()->get(time_path)); } } } @@ -833,8 +835,6 @@ void AnimationNodeBlendTreeEditor::edit(const Ref<AnimationNode> &p_node) { if (p_node.is_valid()) { blend_tree = p_node; - } else { - blend_tree.unref(); } if (blend_tree.is_null()) { diff --git a/editor/plugins/animation_blend_tree_editor_plugin.h b/editor/plugins/animation_blend_tree_editor_plugin.h index e2daefdec6..e7934ea3a0 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.h +++ b/editor/plugins/animation_blend_tree_editor_plugin.h @@ -70,9 +70,9 @@ class AnimationNodeBlendTreeEditor : public AnimationTreeNodeEditorPlugin { String name; String type; Ref<Script> script; - AddOption(const String &p_name = String(), const String &p_type = String()) { - name = p_name; - type = p_type; + AddOption(const String &p_name = String(), const String &p_type = String()) : + name(p_name), + type(p_type) { } }; diff --git a/editor/plugins/animation_state_machine_editor.cpp b/editor/plugins/animation_state_machine_editor.cpp index e83773257b..990c77430f 100644 --- a/editor/plugins/animation_state_machine_editor.cpp +++ b/editor/plugins/animation_state_machine_editor.cpp @@ -849,7 +849,7 @@ void AnimationNodeStateMachineEditor::_state_machine_pos_draw() { return; int idx = -1; - for (int i = 0; node_rects.size(); i++) { + for (int i = 0; i < node_rects.size(); i++) { if (node_rects[i].node_name == playback->get_current_node()) { idx = i; break; diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp index 66770d98e5..138b8a491c 100644 --- a/editor/plugins/asset_library_editor_plugin.cpp +++ b/editor/plugins/asset_library_editor_plugin.cpp @@ -962,6 +962,9 @@ HBoxContainer *EditorAssetLibrary::_make_pages(int p_page, int p_page_count, int HBoxContainer *hbc = memnew(HBoxContainer); + if (p_page_count < 2) + return hbc; + //do the mario int from = p_page - 5; if (from < 0) diff --git a/editor/plugins/baked_lightmap_editor_plugin.cpp b/editor/plugins/baked_lightmap_editor_plugin.cpp index e65a697857..40e3bb5be2 100644 --- a/editor/plugins/baked_lightmap_editor_plugin.cpp +++ b/editor/plugins/baked_lightmap_editor_plugin.cpp @@ -108,7 +108,7 @@ void BakedLightmapEditorPlugin::_bind_methods() { BakedLightmapEditorPlugin::BakedLightmapEditorPlugin(EditorNode *p_node) { editor = p_node; - bake = memnew(Button); + bake = memnew(ToolButton); bake->set_icon(editor->get_gui_base()->get_icon("Bake", "EditorIcons")); bake->set_text(TTR("Bake Lightmaps")); bake->hide(); diff --git a/editor/plugins/baked_lightmap_editor_plugin.h b/editor/plugins/baked_lightmap_editor_plugin.h index a32b573851..8d3b5b1dd6 100644 --- a/editor/plugins/baked_lightmap_editor_plugin.h +++ b/editor/plugins/baked_lightmap_editor_plugin.h @@ -42,7 +42,7 @@ class BakedLightmapEditorPlugin : public EditorPlugin { BakedLightmap *lightmap; - Button *bake; + ToolButton *bake; EditorNode *editor; static EditorProgress *tmp_progress; diff --git a/editor/plugins/camera_editor_plugin.cpp b/editor/plugins/camera_editor_plugin.cpp index 37fbb54c30..3d8b24ccc7 100644 --- a/editor/plugins/camera_editor_plugin.cpp +++ b/editor/plugins/camera_editor_plugin.cpp @@ -32,18 +32,6 @@ #include "spatial_editor_plugin.h" -void CameraEditor::_notification(int p_what) { - - switch (p_what) { - - /* case NOTIFICATION_PROCESS: { - - if (preview->is_pressed() && node) - node->call("make_current"); - - } break;*/ - } -} void CameraEditor::_node_removed(Node *p_node) { if (p_node == node) { diff --git a/editor/plugins/camera_editor_plugin.h b/editor/plugins/camera_editor_plugin.h index 275624beeb..0340808c9a 100644 --- a/editor/plugins/camera_editor_plugin.h +++ b/editor/plugins/camera_editor_plugin.h @@ -50,7 +50,6 @@ class CameraEditor : public Control { void _pressed(); protected: - void _notification(int p_what); void _node_removed(Node *p_node); static void _bind_methods(); diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index e8f00ce0ba..c272f8d756 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -179,8 +179,21 @@ void CanvasItemEditor::_snap_if_closer_float(float p_value, float p_target_snap, } } -bool CanvasItemEditor::_is_node_editable(const Node *p_node) { - return (!(p_node->has_meta("_edit_lock_") && p_node->get_meta("_edit_lock_")) && !(ClassDB::is_parent_class(p_node->get_parent()->get_class_name(), "Container") && ClassDB::is_parent_class(p_node->get_class_name(), "Control"))); +bool CanvasItemEditor::_is_node_locked(const Node *p_node) { + return p_node->has_meta("_edit_lock_") && p_node->get_meta("_edit_lock_"); +} + +bool CanvasItemEditor::_is_node_movable(const Node *p_node, bool p_popup_warning) { + if (_is_node_locked(p_node)) { + return false; + } + if (Object::cast_to<Control>(p_node) && Object::cast_to<Container>(p_node->get_parent())) { + if (p_popup_warning) { + _popup_warning_temporarily(warning_child_of_container, 3.0); + } + return false; + } + return true; } void CanvasItemEditor::_snap_if_closer_point(Point2 p_value, Point2 p_target_snap, Point2 &r_current_snap, bool (&r_snapped)[2], real_t rotation, float p_radius) { @@ -415,7 +428,7 @@ void CanvasItemEditor::_expand_encompassing_rect_using_children(Rect2 &r_rect, c } } - if (canvas_item && canvas_item->is_visible_in_tree() && (include_locked_nodes || !_is_node_editable(canvas_item))) { + if (canvas_item && canvas_item->is_visible_in_tree() && (include_locked_nodes || !_is_node_locked(canvas_item))) { Transform2D xform = p_parent_xform * p_canvas_xform * canvas_item->get_transform(); Rect2 rect = canvas_item->_edit_get_rect(); if (r_first) { @@ -437,28 +450,26 @@ Rect2 CanvasItemEditor::_get_encompassing_rect(const Node *p_node) { return rect; } -void CanvasItemEditor::_find_canvas_items_at_pos(const Point2 &p_pos, Node *p_node, Vector<_SelectResult> &r_items, int p_limit, const Transform2D &p_parent_xform, const Transform2D &p_canvas_xform) { +void CanvasItemEditor::_find_canvas_items_at_pos(const Point2 &p_pos, Node *p_node, Vector<_SelectResult> &r_items, const Transform2D &p_parent_xform, const Transform2D &p_canvas_xform) { if (!p_node) return; if (Object::cast_to<Viewport>(p_node)) return; - const real_t grab_distance = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8); + const real_t grab_distance = EDITOR_GET("editors/poly_editor/point_grab_radius"); CanvasItem *canvas_item = Object::cast_to<CanvasItem>(p_node); for (int i = p_node->get_child_count() - 1; i >= 0; i--) { if (canvas_item) { if (!canvas_item->is_set_as_toplevel()) { - _find_canvas_items_at_pos(p_pos, p_node->get_child(i), r_items, p_limit, p_parent_xform * canvas_item->get_transform(), p_canvas_xform); + _find_canvas_items_at_pos(p_pos, p_node->get_child(i), r_items, p_parent_xform * canvas_item->get_transform(), p_canvas_xform); } else { - _find_canvas_items_at_pos(p_pos, p_node->get_child(i), r_items, p_limit, canvas_item->get_transform(), p_canvas_xform); + _find_canvas_items_at_pos(p_pos, p_node->get_child(i), r_items, canvas_item->get_transform(), p_canvas_xform); } } else { CanvasLayer *cl = Object::cast_to<CanvasLayer>(p_node); - _find_canvas_items_at_pos(p_pos, p_node->get_child(i), r_items, p_limit, Transform2D(), cl ? cl->get_transform() : p_canvas_xform); + _find_canvas_items_at_pos(p_pos, p_node->get_child(i), r_items, Transform2D(), cl ? cl->get_transform() : p_canvas_xform); } - if (p_limit != 0 && r_items.size() >= p_limit) - return; } if (canvas_item && canvas_item->is_visible_in_tree()) { @@ -478,11 +489,11 @@ void CanvasItemEditor::_find_canvas_items_at_pos(const Point2 &p_pos, Node *p_no return; } -void CanvasItemEditor::_get_canvas_items_at_pos(const Point2 &p_pos, Vector<_SelectResult> &r_items, int p_limit) { +void CanvasItemEditor::_get_canvas_items_at_pos(const Point2 &p_pos, Vector<_SelectResult> &r_items) { Node *scene = editor->get_edited_scene(); - _find_canvas_items_at_pos(p_pos, scene, r_items, p_limit); + _find_canvas_items_at_pos(p_pos, scene, r_items); //Remove invalid results for (int i = 0; i < r_items.size(); i++) { @@ -513,7 +524,7 @@ void CanvasItemEditor::_get_canvas_items_at_pos(const Point2 &p_pos, Vector<_Sel } //Remove the item if invalid - if (!canvas_item || duplicate || (canvas_item != scene && canvas_item->get_owner() != scene && !scene->is_editable_instance(canvas_item->get_owner())) || !_is_node_editable(canvas_item)) { + if (!canvas_item || duplicate || (canvas_item != scene && canvas_item->get_owner() != scene && !scene->is_editable_instance(canvas_item->get_owner())) || _is_node_locked(canvas_item)) { r_items.remove(i); i--; } else { @@ -614,7 +625,7 @@ void CanvasItemEditor::_find_canvas_items_in_rect(const Rect2 &p_rect, Node *p_n bool editable = p_node == scene || p_node->get_owner() == scene || scene->is_editable_instance(p_node->get_owner()); bool lock_children = p_node->has_meta("_edit_group_") && p_node->get_meta("_edit_group_"); - bool locked = !_is_node_editable(p_node); + bool locked = _is_node_locked(p_node); if (!lock_children || !editable) { for (int i = p_node->get_child_count() - 1; i >= 0; i--) { @@ -681,7 +692,7 @@ List<CanvasItem *> CanvasItemEditor::_get_edited_canvas_items(bool retreive_lock List<CanvasItem *> selection; for (Map<Node *, Object *>::Element *E = editor_selection->get_selection().front(); E; E = E->next()) { CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key()); - if (canvas_item && canvas_item->is_visible_in_tree() && canvas_item->get_viewport() == EditorNode::get_singleton()->get_scene_root() && (retreive_locked || _is_node_editable(canvas_item))) { + if (canvas_item && canvas_item->is_visible_in_tree() && canvas_item->get_viewport() == EditorNode::get_singleton()->get_scene_root() && (retreive_locked || !_is_node_locked(canvas_item))) { CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item); if (se) { selection.push_back(canvas_item); @@ -1025,8 +1036,7 @@ bool CanvasItemEditor::_gui_input_zoom_or_pan(const Ref<InputEvent> &p_event) { // Scroll or pan down if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) { view_offset.y += int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor(); - _update_scrollbars(); - viewport->update(); + update_viewport(); } else { _zoom_on_position(zoom * (1 - (0.05 * b->get_factor())), b->get_position()); } @@ -1037,8 +1047,7 @@ bool CanvasItemEditor::_gui_input_zoom_or_pan(const Ref<InputEvent> &p_event) { // Scroll or pan up if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) { view_offset.y -= int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor(); - _update_scrollbars(); - viewport->update(); + update_viewport(); } else { _zoom_on_position(zoom * ((0.95 + (0.05 * b->get_factor())) / 0.95), b->get_position()); } @@ -1049,8 +1058,7 @@ bool CanvasItemEditor::_gui_input_zoom_or_pan(const Ref<InputEvent> &p_event) { // Pan left if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) { view_offset.x -= int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor(); - _update_scrollbars(); - viewport->update(); + update_viewport(); return true; } } @@ -1059,8 +1067,7 @@ bool CanvasItemEditor::_gui_input_zoom_or_pan(const Ref<InputEvent> &p_event) { // Pan right if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) { view_offset.x += int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor(); - _update_scrollbars(); - viewport->update(); + update_viewport(); return true; } } @@ -1112,8 +1119,7 @@ bool CanvasItemEditor::_gui_input_zoom_or_pan(const Ref<InputEvent> &p_event) { } view_offset.x -= relative.x / zoom; view_offset.y -= relative.y / zoom; - _update_scrollbars(); - viewport->update(); + update_viewport(); return true; } } @@ -1131,8 +1137,7 @@ bool CanvasItemEditor::_gui_input_zoom_or_pan(const Ref<InputEvent> &p_event) { const Vector2 delta = (int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom) * pan_gesture->get_delta(); view_offset.x += delta.x; view_offset.y += delta.y; - _update_scrollbars(); - viewport->update(); + update_viewport(); return true; } @@ -1293,18 +1298,28 @@ bool CanvasItemEditor::_gui_input_rotate(const Ref<InputEvent> &p_event) { // Start rotation if (drag_type == DRAG_NONE) { if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && b->is_pressed()) { - drag_selection = _get_edited_canvas_items(); - if (drag_selection.size() > 0 && ((b->get_control() && !b->get_alt() && tool == TOOL_SELECT) || tool == TOOL_ROTATE)) { - drag_type = DRAG_ROTATE; - drag_from = transform.affine_inverse().xform(b->get_position()); - CanvasItem *canvas_item = drag_selection[0]; - if (canvas_item->_edit_use_pivot()) { - drag_rotation_center = canvas_item->get_global_transform_with_canvas().xform(canvas_item->_edit_get_pivot()); - } else { - drag_rotation_center = canvas_item->get_global_transform_with_canvas().get_origin(); + if ((b->get_control() && !b->get_alt() && tool == TOOL_SELECT) || tool == TOOL_ROTATE) { + List<CanvasItem *> selection = _get_edited_canvas_items(); + + // Remove not movable nodes + for (List<CanvasItem *>::Element *E = selection.front(); E; E = E->next()) { + if (!_is_node_movable(E->get(), true)) + selection.erase(E); + } + + drag_selection = selection; + if (drag_selection.size() > 0) { + drag_type = DRAG_ROTATE; + drag_from = transform.affine_inverse().xform(b->get_position()); + CanvasItem *canvas_item = drag_selection[0]; + if (canvas_item->_edit_use_pivot()) { + drag_rotation_center = canvas_item->get_global_transform_with_canvas().xform(canvas_item->_edit_get_pivot()); + } else { + drag_rotation_center = canvas_item->get_global_transform_with_canvas().get_origin(); + } + _save_canvas_item_state(drag_selection); + return true; } - _save_canvas_item_state(drag_selection); - return true; } } } @@ -1367,7 +1382,7 @@ bool CanvasItemEditor::_gui_input_anchors(const Ref<InputEvent> &p_event) { List<CanvasItem *> selection = _get_edited_canvas_items(); if (selection.size() == 1) { Control *control = Object::cast_to<Control>(selection[0]); - if (control && !Object::cast_to<Container>(control->get_parent())) { + if (control && _is_node_movable(control)) { Vector2 anchor_pos[4]; anchor_pos[0] = Vector2(control->get_anchor(MARGIN_LEFT), control->get_anchor(MARGIN_TOP)); anchor_pos[1] = Vector2(control->get_anchor(MARGIN_RIGHT), control->get_anchor(MARGIN_TOP)); @@ -1486,7 +1501,7 @@ bool CanvasItemEditor::_gui_input_resize(const Ref<InputEvent> &p_event) { List<CanvasItem *> selection = _get_edited_canvas_items(); if (selection.size() == 1) { CanvasItem *canvas_item = selection[0]; - if (canvas_item->_edit_use_rect()) { + if (canvas_item->_edit_use_rect() && _is_node_movable(canvas_item)) { Rect2 rect = canvas_item->_edit_get_rect(); Transform2D xform = transform * canvas_item->get_global_transform_with_canvas(); @@ -1654,27 +1669,30 @@ bool CanvasItemEditor::_gui_input_scale(const Ref<InputEvent> &p_event) { if (selection.size() == 1) { CanvasItem *canvas_item = selection[0]; - Transform2D xform = transform * canvas_item->get_global_transform_with_canvas(); - Transform2D unscaled_transform = (xform * canvas_item->get_transform().affine_inverse() * Transform2D(canvas_item->_edit_get_rotation(), canvas_item->_edit_get_position())).orthonormalized(); - Transform2D simple_xform = viewport->get_transform() * unscaled_transform; + if (_is_node_movable(canvas_item)) { - drag_type = DRAG_SCALE_BOTH; + Transform2D xform = transform * canvas_item->get_global_transform_with_canvas(); + Transform2D unscaled_transform = (xform * canvas_item->get_transform().affine_inverse() * Transform2D(canvas_item->_edit_get_rotation(), canvas_item->_edit_get_position())).orthonormalized(); + Transform2D simple_xform = viewport->get_transform() * unscaled_transform; - Size2 scale_factor = Size2(SCALE_HANDLE_DISTANCE, SCALE_HANDLE_DISTANCE); - Rect2 x_handle_rect = Rect2(scale_factor.x * EDSCALE, -5 * EDSCALE, 10 * EDSCALE, 10 * EDSCALE); - if (x_handle_rect.has_point(simple_xform.affine_inverse().xform(b->get_position()))) { - drag_type = DRAG_SCALE_X; - } - Rect2 y_handle_rect = Rect2(-5 * EDSCALE, -(scale_factor.y + 10) * EDSCALE, 10 * EDSCALE, 10 * EDSCALE); - if (y_handle_rect.has_point(simple_xform.affine_inverse().xform(b->get_position()))) { - drag_type = DRAG_SCALE_Y; - } + drag_type = DRAG_SCALE_BOTH; - drag_from = transform.affine_inverse().xform(b->get_position()); - drag_selection = List<CanvasItem *>(); - drag_selection.push_back(canvas_item); - _save_canvas_item_state(drag_selection); - return true; + Size2 scale_factor = Size2(SCALE_HANDLE_DISTANCE, SCALE_HANDLE_DISTANCE); + Rect2 x_handle_rect = Rect2(scale_factor.x * EDSCALE, -5 * EDSCALE, 10 * EDSCALE, 10 * EDSCALE); + if (x_handle_rect.has_point(simple_xform.affine_inverse().xform(b->get_position()))) { + drag_type = DRAG_SCALE_X; + } + Rect2 y_handle_rect = Rect2(-5 * EDSCALE, -(scale_factor.y + 10) * EDSCALE, 10 * EDSCALE, 10 * EDSCALE); + if (y_handle_rect.has_point(simple_xform.affine_inverse().xform(b->get_position()))) { + drag_type = DRAG_SCALE_Y; + } + + drag_from = transform.affine_inverse().xform(b->get_position()); + drag_selection = List<CanvasItem *>(); + drag_selection.push_back(canvas_item); + _save_canvas_item_state(drag_selection); + return true; + } } } } @@ -1702,13 +1720,7 @@ bool CanvasItemEditor::_gui_input_scale(const Ref<InputEvent> &p_event) { if (drag_type == DRAG_SCALE_BOTH) { Size2 scale_factor = drag_to_local / drag_from_local; if (uniform) { - if (ABS(offset.x) > ABS(offset.y)) { - scale.x *= scale_factor.x; - scale.y = scale.x * ratio; - } else { - scale.y *= scale_factor.y; - scale.x = scale.y / ratio; - } + scale *= (scale_factor.x + scale_factor.y) / 2.0; } else { scale *= scale_factor; } @@ -1759,12 +1771,22 @@ bool CanvasItemEditor::_gui_input_move(const Ref<InputEvent> &p_event) { if (drag_type == DRAG_NONE) { //Start moving the nodes if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && b->is_pressed()) { - List<CanvasItem *> selection = _get_edited_canvas_items(); - if (((b->get_alt() && !b->get_control()) || tool == TOOL_MOVE) && selection.size() > 0) { - drag_type = DRAG_MOVE; - drag_from = transform.affine_inverse().xform(b->get_position()); - drag_selection = selection; - _save_canvas_item_state(drag_selection); + if ((b->get_alt() && !b->get_control()) || tool == TOOL_MOVE) { + List<CanvasItem *> selection = _get_edited_canvas_items(); + + // Remove not movable nodes + for (int i = 0; i < selection.size(); i++) { + if (!_is_node_movable(selection[i], true)) { + selection.erase(selection[i]); + } + } + + if (selection.size() > 0) { + drag_type = DRAG_MOVE; + drag_from = transform.affine_inverse().xform(b->get_position()); + drag_selection = selection; + _save_canvas_item_state(drag_selection); + } return true; } } @@ -2014,7 +2036,7 @@ bool CanvasItemEditor::_gui_input_select(const Ref<InputEvent> &p_event) { Vector<_SelectResult> selection; // Retrieve the items - _get_canvas_items_at_pos(click, selection, editor_selection->get_selection().empty() ? 1 : 0); + _get_canvas_items_at_pos(click, selection); // Retrieve the bones _get_bones_at_pos(click, selection); @@ -2042,10 +2064,19 @@ bool CanvasItemEditor::_gui_input_select(const Ref<InputEvent> &p_event) { // Drag the node(s) if requested List<CanvasItem *> selection = _get_edited_canvas_items(); - drag_type = DRAG_MOVE; - drag_selection = selection; - drag_from = click; - _save_canvas_item_state(drag_selection); + // Remove not movable nodes + for (int i = 0; i < selection.size(); i++) { + if (!_is_node_movable(selection[i], true)) { + selection.erase(selection[i]); + } + } + + if (selection.size() > 0) { + drag_type = DRAG_MOVE; + drag_selection = selection; + drag_from = click; + _save_canvas_item_state(drag_selection); + } } // Select the item return true; @@ -2178,6 +2209,8 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) { //printf("Zoom or pan\n"); } else if ((accepted = _gui_input_select(p_event))) { //printf("Selection\n"); + } else { + //printf("Not accepted\n"); } if (accepted) @@ -2708,12 +2741,12 @@ void CanvasItemEditor::_draw_selection() { // Draw control-related helpers Control *control = Object::cast_to<Control>(canvas_item); - if (control) { + if (control && _is_node_movable(control)) { _draw_control_helpers(control); } // Draw the resize handles - if (tool == TOOL_SELECT && canvas_item->_edit_use_rect()) { + if (tool == TOOL_SELECT && canvas_item->_edit_use_rect() && _is_node_movable(canvas_item)) { Rect2 rect = canvas_item->_edit_get_rect(); Vector2 endpoints[4] = { xform.xform(rect.position), @@ -2741,40 +2774,41 @@ void CanvasItemEditor::_draw_selection() { bool is_ctrl = Input::get_singleton()->is_key_pressed(KEY_CONTROL); bool is_alt = Input::get_singleton()->is_key_pressed(KEY_ALT); if ((is_alt && is_ctrl) || tool == TOOL_SCALE || drag_type == DRAG_SCALE_X || drag_type == DRAG_SCALE_Y) { - - Transform2D unscaled_transform = (xform * canvas_item->get_transform().affine_inverse() * Transform2D(canvas_item->_edit_get_rotation(), canvas_item->_edit_get_position())).orthonormalized(); - Transform2D simple_xform = viewport->get_transform() * unscaled_transform; - - Size2 scale_factor = Size2(SCALE_HANDLE_DISTANCE, SCALE_HANDLE_DISTANCE); - bool uniform = Input::get_singleton()->is_key_pressed(KEY_SHIFT); - Point2 offset = (simple_xform.affine_inverse().xform(drag_to) - simple_xform.affine_inverse().xform(drag_from)) * zoom; - - if (drag_type == DRAG_SCALE_X) { - scale_factor.x += offset.x; - if (uniform) { - scale_factor.y += offset.x; - } - } else if (drag_type == DRAG_SCALE_Y) { - scale_factor.y -= offset.y; - if (uniform) { - scale_factor.x -= offset.y; + if (_is_node_movable(canvas_item)) { + Transform2D unscaled_transform = (xform * canvas_item->get_transform().affine_inverse() * Transform2D(canvas_item->_edit_get_rotation(), canvas_item->_edit_get_position())).orthonormalized(); + Transform2D simple_xform = viewport->get_transform() * unscaled_transform; + + Size2 scale_factor = Size2(SCALE_HANDLE_DISTANCE, SCALE_HANDLE_DISTANCE); + bool uniform = Input::get_singleton()->is_key_pressed(KEY_SHIFT); + Point2 offset = (simple_xform.affine_inverse().xform(drag_to) - simple_xform.affine_inverse().xform(drag_from)) * zoom; + + if (drag_type == DRAG_SCALE_X) { + scale_factor.x += offset.x; + if (uniform) { + scale_factor.y += offset.x; + } + } else if (drag_type == DRAG_SCALE_Y) { + scale_factor.y -= offset.y; + if (uniform) { + scale_factor.x -= offset.y; + } } - } - //scale_factor *= zoom; + //scale_factor *= zoom; - viewport->draw_set_transform_matrix(simple_xform); - Rect2 x_handle_rect = Rect2(scale_factor.x * EDSCALE, -5 * EDSCALE, 10 * EDSCALE, 10 * EDSCALE); - Color x_axis_color(1.0, 0.4, 0.4, 0.6); - viewport->draw_rect(x_handle_rect, x_axis_color); - viewport->draw_line(Point2(), Point2(scale_factor.x * EDSCALE, 0), x_axis_color); + viewport->draw_set_transform_matrix(simple_xform); + Rect2 x_handle_rect = Rect2(scale_factor.x * EDSCALE, -5 * EDSCALE, 10 * EDSCALE, 10 * EDSCALE); + Color x_axis_color(1.0, 0.4, 0.4, 0.6); + viewport->draw_rect(x_handle_rect, x_axis_color); + viewport->draw_line(Point2(), Point2(scale_factor.x * EDSCALE, 0), x_axis_color); - Rect2 y_handle_rect = Rect2(-5 * EDSCALE, -(scale_factor.y + 10) * EDSCALE, 10 * EDSCALE, 10 * EDSCALE); - Color y_axis_color(0.4, 1.0, 0.4, 0.6); - viewport->draw_rect(y_handle_rect, y_axis_color); - viewport->draw_line(Point2(), Point2(0, -scale_factor.y * EDSCALE), y_axis_color); + Rect2 y_handle_rect = Rect2(-5 * EDSCALE, -(scale_factor.y + 10) * EDSCALE, 10 * EDSCALE, 10 * EDSCALE); + Color y_axis_color(0.4, 1.0, 0.4, 0.6); + viewport->draw_rect(y_handle_rect, y_axis_color); + viewport->draw_line(Point2(), Point2(0, -scale_factor.y * EDSCALE), y_axis_color); - viewport->draw_set_transform_matrix(viewport->get_transform()); + viewport->draw_set_transform_matrix(viewport->get_transform()); + } } } } @@ -2950,7 +2984,7 @@ void CanvasItemEditor::_draw_invisible_nodes_positions(Node *p_node, const Trans _draw_invisible_nodes_positions(p_node->get_child(i), parent_xform, canvas_xform); } - if (canvas_item && !canvas_item->_edit_use_rect() && (!editor_selection->is_selected(canvas_item) || !_is_node_editable(canvas_item))) { + if (canvas_item && !canvas_item->_edit_use_rect() && (!editor_selection->is_selected(canvas_item) || _is_node_locked(canvas_item))) { Transform2D xform = transform * canvas_xform * parent_xform; // Draw the node's position @@ -3139,6 +3173,8 @@ void CanvasItemEditor::_draw_viewport() { group_button->set_disabled(selection.empty()); ungroup_button->set_visible(all_group); + info_overlay->set_margin(MARGIN_LEFT, (show_rulers ? RULER_WIDTH : 0) + 10); + _draw_grid(); _draw_selection(); _draw_axis(); @@ -3168,6 +3204,11 @@ void CanvasItemEditor::_draw_viewport() { _draw_hover(); } +void CanvasItemEditor::update_viewport() { + _update_scrollbars(); + viewport->update(); +} + void CanvasItemEditor::_notification(int p_what) { if (p_what == NOTIFICATION_PHYSICS_PROCESS) { @@ -3362,11 +3403,14 @@ void CanvasItemEditor::_notification(int p_what) { void CanvasItemEditor::edit(CanvasItem *p_canvas_item) { - drag_type = DRAG_NONE; + Array selection = editor_selection->get_selected_nodes(); + if (selection.size() != 1 || (Node *)selection[0] != p_canvas_item) { + drag_type = DRAG_NONE; - // Clear the selection - editor_selection->clear(); //_clear_canvas_items(); - editor_selection->add_node(p_canvas_item); + // Clear the selection + editor_selection->clear(); //_clear_canvas_items(); + editor_selection->add_node(p_canvas_item); + } } void CanvasItemEditor::_queue_update_bone_list() { @@ -3498,6 +3542,35 @@ void CanvasItemEditor::_update_scrollbars() { updating_scroll = false; } +void CanvasItemEditor::_popup_warning_depop(Control *p_control) { + ERR_FAIL_COND(!popup_temporarily_timers.has(p_control)); + + Timer *timer = popup_temporarily_timers[p_control]; + p_control->hide(); + remove_child(timer); + popup_temporarily_timers.erase(p_control); + memdelete(timer); + info_overlay->set_margin(MARGIN_LEFT, (show_rulers ? RULER_WIDTH : 0) + 10); +} + +void CanvasItemEditor::_popup_warning_temporarily(Control *p_control, const float p_duration) { + Timer *timer; + if (!popup_temporarily_timers.has(p_control)) { + timer = memnew(Timer); + timer->connect("timeout", this, "_popup_warning_depop", varray(p_control)); + timer->set_one_shot(true); + add_child(timer); + + popup_temporarily_timers[p_control] = timer; + } else { + timer = popup_temporarily_timers[p_control]; + } + + timer->start(p_duration); + p_control->show(); + info_overlay->set_margin(MARGIN_LEFT, (show_rulers ? RULER_WIDTH : 0) + 10); +} + void CanvasItemEditor::_update_scroll(float) { if (updating_scroll) @@ -3574,8 +3647,7 @@ void CanvasItemEditor::_zoom_on_position(float p_zoom, Point2 p_position) { view_offset.x = Math::round(view_offset.x + ofs.x); view_offset.y = Math::round(view_offset.y + ofs.y); - _update_scrollbars(); - viewport->update(); + update_viewport(); } void CanvasItemEditor::_button_zoom_minus() { @@ -4172,8 +4244,7 @@ void CanvasItemEditor::_focus_selection(int p_op) { Vector2 offset = viewport->get_size() / 2 - editor->get_scene_root()->get_global_canvas_transform().xform(center); view_offset.x -= offset.x / zoom; view_offset.y -= offset.y / zoom; - _update_scrollbars(); - viewport->update(); + update_viewport(); } else { // VIEW_FRAME_TO_SELECTION @@ -4206,10 +4277,11 @@ void CanvasItemEditor::_bind_methods() { ClassDB::bind_method("_snap_changed", &CanvasItemEditor::_snap_changed); ClassDB::bind_method("_update_bone_list", &CanvasItemEditor::_update_bone_list); ClassDB::bind_method("_tree_changed", &CanvasItemEditor::_tree_changed); - + ClassDB::bind_method("_popup_warning_depop", &CanvasItemEditor::_popup_warning_depop); ClassDB::bind_method(D_METHOD("_selection_result_pressed"), &CanvasItemEditor::_selection_result_pressed); ClassDB::bind_method(D_METHOD("_selection_menu_hide"), &CanvasItemEditor::_selection_menu_hide); ClassDB::bind_method(D_METHOD("set_state"), &CanvasItemEditor::set_state); + ClassDB::bind_method(D_METHOD("update_viewport"), &CanvasItemEditor::update_viewport); ADD_SIGNAL(MethodInfo("item_lock_status_changed")); ADD_SIGNAL(MethodInfo("item_group_status_changed")); @@ -4391,7 +4463,22 @@ void CanvasItemEditor::set_state(const Dictionary &p_state) { viewport->update(); } +void CanvasItemEditor::add_control_to_info_overlay(Control *p_control) { + ERR_FAIL_COND(!p_control); + + p_control->set_h_size_flags(p_control->get_h_size_flags() & ~Control::SIZE_EXPAND_FILL); + info_overlay->add_child(p_control); + info_overlay->set_margin(MARGIN_LEFT, (show_rulers ? RULER_WIDTH : 0) + 10); +} + +void CanvasItemEditor::remove_control_from_info_overlay(Control *p_control) { + + info_overlay->remove_child(p_control); + info_overlay->set_margin(MARGIN_LEFT, (show_rulers ? RULER_WIDTH : 0) + 10); +} + void CanvasItemEditor::add_control_to_menu_panel(Control *p_control) { + ERR_FAIL_COND(!p_control); hb->add_child(p_control); } @@ -4417,6 +4504,46 @@ void CanvasItemEditor::focus_selection() { CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { + key_pos = true; + key_rot = true; + key_scale = false; + + show_grid = false; + show_origin = true; + show_viewport = true; + show_helpers = false; + show_rulers = true; + show_guides = true; + show_edit_locks = true; + zoom = 1; + view_offset = Point2(-150 - RULER_WIDTH, -95 - RULER_WIDTH); + previous_update_view_offset = view_offset; // Moves the view a little bit to the left so that (0,0) is visible. The values a relative to a 16/10 screen + grid_offset = Point2(); + grid_step = Point2(10, 10); + grid_step_multiplier = 0; + snap_rotation_offset = 0; + snap_rotation_step = 15 / (180 / Math_PI); + snap_active = false; + snap_node_parent = true; + snap_node_anchors = true; + snap_node_sides = true; + snap_node_center = true; + snap_other_nodes = true; + snap_grid = true; + snap_guides = true; + snap_rotation = false; + snap_pixel = false; + + skeleton_show_bones = true; + + drag_type = DRAG_NONE; + drag_from = Vector2(); + drag_to = Vector2(); + dragged_guide_pos = Point2(); + dragged_guide_index = -1; + + bone_last_frame = 0; + bone_list_dirty = false; tool = TOOL_SELECT; undo_redo = p_editor->get_undo_redo(); @@ -4460,6 +4587,28 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { viewport->connect("draw", this, "_draw_viewport"); viewport->connect("gui_input", this, "_gui_input_viewport"); + info_overlay = memnew(VBoxContainer); + info_overlay->set_anchors_and_margins_preset(Control::PRESET_BOTTOM_LEFT); + info_overlay->set_margin(MARGIN_LEFT, 10); + info_overlay->set_margin(MARGIN_BOTTOM, -15); + info_overlay->set_v_grow_direction(Control::GROW_DIRECTION_BEGIN); + info_overlay->add_constant_override("separation", 10); + viewport_scrollable->add_child(info_overlay); + + Theme *info_overlay_theme = memnew(Theme); + info_overlay_theme->copy_default_theme(); + info_overlay->set_theme(info_overlay_theme); + + StyleBoxFlat *info_overlay_label_stylebox = memnew(StyleBoxFlat); + info_overlay_label_stylebox->set_bg_color(Color(0.0, 0.0, 0.0, 0.2)); + info_overlay_label_stylebox->set_expand_margin_size_all(4); + info_overlay_theme->set_stylebox("normal", "Label", info_overlay_label_stylebox); + + warning_child_of_container = memnew(Label); + warning_child_of_container->hide(); + warning_child_of_container->set_text(TTR("Warning: Children of a container get their position and size determined only by their parent")); + add_control_to_info_overlay(warning_child_of_container); + h_scroll = memnew(HScrollBar); viewport->add_child(h_scroll); h_scroll->connect("value_changed", this, "_update_scroll"); @@ -4477,19 +4626,19 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { zoom_minus = memnew(ToolButton); zoom_hb->add_child(zoom_minus); zoom_minus->connect("pressed", this, "_button_zoom_minus"); - zoom_minus->set_shortcut(ED_SHORTCUT("canvas_item_editor/zoom_minus", TTR("Zoom out"), KEY_MASK_CMD | KEY_MINUS)); + zoom_minus->set_shortcut(ED_SHORTCUT("canvas_item_editor/zoom_minus", TTR("Zoom Out"), KEY_MASK_CMD | KEY_MINUS)); zoom_minus->set_focus_mode(FOCUS_NONE); zoom_reset = memnew(ToolButton); zoom_hb->add_child(zoom_reset); zoom_reset->connect("pressed", this, "_button_zoom_reset"); - zoom_reset->set_shortcut(ED_SHORTCUT("canvas_item_editor/zoom_reset", TTR("Zoom reset"), KEY_MASK_CMD | KEY_0)); + zoom_reset->set_shortcut(ED_SHORTCUT("canvas_item_editor/zoom_reset", TTR("Zoom Reset"), KEY_MASK_CMD | KEY_0)); zoom_reset->set_focus_mode(FOCUS_NONE); zoom_plus = memnew(ToolButton); zoom_hb->add_child(zoom_plus); zoom_plus->connect("pressed", this, "_button_zoom_plus"); - zoom_plus->set_shortcut(ED_SHORTCUT("canvas_item_editor/zoom_plus", TTR("Zoom in"), KEY_MASK_CMD | KEY_EQUAL)); // Usually direct access key for PLUS + zoom_plus->set_shortcut(ED_SHORTCUT("canvas_item_editor/zoom_plus", TTR("Zoom In"), KEY_MASK_CMD | KEY_EQUAL)); // Usually direct access key for PLUS zoom_plus->set_focus_mode(FOCUS_NONE); updating_scroll = false; @@ -4608,6 +4757,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { skeleton_menu = memnew(MenuButton); hb->add_child(skeleton_menu); + skeleton_menu->set_tooltip(TTR("Skeleton Options")); p = skeleton_menu->get_popup(); p->set_hide_on_checkable_item_selection(false); @@ -4716,49 +4866,11 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { multiply_grid_step_shortcut = ED_SHORTCUT("canvas_item_editor/multiply_grid_step", TTR("Multiply grid step by 2"), KEY_KP_MULTIPLY); divide_grid_step_shortcut = ED_SHORTCUT("canvas_item_editor/divide_grid_step", TTR("Divide grid step by 2"), KEY_KP_DIVIDE); - key_pos = true; - key_rot = true; - key_scale = false; - - show_grid = false; - show_origin = true; - show_viewport = true; - show_helpers = false; - show_rulers = true; - show_guides = true; - show_edit_locks = true; - zoom = 1; - view_offset = Point2(-150 - RULER_WIDTH, -95 - RULER_WIDTH); - previous_update_view_offset = view_offset; // Moves the view a little bit to the left so that (0,0) is visible. The values a relative to a 16/10 screen - grid_offset = Point2(); - grid_step = Point2(10, 10); - grid_step_multiplier = 0; - snap_rotation_offset = 0; - snap_rotation_step = 15 / (180 / Math_PI); - snap_active = false; - snap_node_parent = true; - snap_node_anchors = true; - snap_node_sides = true; - snap_node_center = true; - snap_other_nodes = true; - snap_grid = true; - snap_guides = true; - snap_rotation = false; - snap_pixel = false; - skeleton_show_bones = true; skeleton_menu->get_popup()->set_item_checked(skeleton_menu->get_popup()->get_item_index(SKELETON_SHOW_BONES), true); singleton = this; set_process_unhandled_key_input(true); - drag_type = DRAG_NONE; - drag_from = Vector2(); - drag_to = Vector2(); - dragged_guide_pos = Point2(); - dragged_guide_index = -1; - - bone_last_frame = 0; - // Update the menus' checkboxes call_deferred("set_state", get_state()); } @@ -4958,19 +5070,13 @@ void CanvasItemEditorViewport::_create_nodes(Node *parent, Node *child, String & editor_data->get_undo_redo().add_do_property(child, "polygon", list); } - // locate at preview position - Point2 pos = Point2(0, 0); - if (parent && parent->has_method("get_global_position")) { - pos = parent->call("get_global_position"); - } - Transform2D trans = canvas->get_canvas_transform(); - Point2 target_position = (p_point - trans.get_origin()) / trans.get_scale().x - pos; - if (default_type == "Polygon2D" || default_type == "TouchScreenButton" || default_type == "TextureRect" || default_type == "NinePatchRect") { - target_position -= texture_size / 2; - } + // Compute the global position + Transform2D xform = canvas_item_editor->get_canvas_transform(); + Point2 target_position = xform.affine_inverse().xform(p_point); + // there's nothing to be used as source position so snapping will work as absolute if enabled - target_position = canvas->snap_point(target_position); - editor_data->get_undo_redo().add_do_method(child, "set_position", target_position); + target_position = canvas_item_editor->snap_point(target_position); + editor_data->get_undo_redo().add_do_method(child, "set_global_position", target_position); } bool CanvasItemEditorViewport::_create_instance(Node *parent, String &path, const Point2 &p_point) { @@ -5005,8 +5111,8 @@ bool CanvasItemEditorViewport::_create_instance(Node *parent, String &path, cons CanvasItem *parent_ci = Object::cast_to<CanvasItem>(parent); if (parent_ci) { - Vector2 target_pos = canvas->get_canvas_transform().affine_inverse().xform(p_point); - target_pos = canvas->snap_point(target_pos); + Vector2 target_pos = canvas_item_editor->get_canvas_transform().affine_inverse().xform(p_point); + target_pos = canvas_item_editor->snap_point(target_pos); target_pos = parent_ci->get_global_transform_with_canvas().affine_inverse().xform(target_pos); editor_data->get_undo_redo().add_do_method(instanced_scene, "set_position", target_pos); } @@ -5113,7 +5219,7 @@ bool CanvasItemEditorViewport::can_drop_data(const Point2 &p_point, const Varian type == "AtlasTexture" || type == "LargeTexture") { Ref<Texture> texture = Ref<Texture>(Object::cast_to<Texture>(*res)); - if (texture.is_valid() == false) { + if (!texture.is_valid()) { continue; } } else { @@ -5126,7 +5232,7 @@ bool CanvasItemEditorViewport::can_drop_data(const Point2 &p_point, const Varian if (!preview_node->get_parent()) { // create preview only once _create_preview(files); } - Transform2D trans = canvas->get_canvas_transform(); + Transform2D trans = canvas_item_editor->get_canvas_transform(); preview_node->set_position((p_point - trans.get_origin()) / trans.get_scale().x); label->set_text(vformat(TTR("Adding %s..."), default_type)); } @@ -5221,7 +5327,7 @@ void CanvasItemEditorViewport::_bind_methods() { ClassDB::bind_method(D_METHOD("_on_mouse_exit"), &CanvasItemEditorViewport::_on_mouse_exit); } -CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasItemEditor *p_canvas) { +CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasItemEditor *p_canvas_item_editor) { default_type = "Sprite"; // Node2D types.push_back("Sprite"); @@ -5236,7 +5342,7 @@ CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasIte target_node = NULL; editor = p_node; editor_data = editor->get_scene_tree_dock()->get_editor_data(); - canvas = p_canvas; + canvas_item_editor = p_canvas_item_editor; preview_node = memnew(Node2D); accept = memnew(AcceptDialog); diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h index 4f8cc6ab5e..207e57dbe2 100644 --- a/editor/plugins/canvas_item_editor_plugin.h +++ b/editor/plugins/canvas_item_editor_plugin.h @@ -64,7 +64,10 @@ public: Dictionary undo_state; - CanvasItemEditorSelectedItem() { prev_rot = 0; } + CanvasItemEditorSelectedItem() : + prev_anchors() { + prev_rot = 0; + } }; class CanvasItemEditor : public VBoxContainer { @@ -220,6 +223,11 @@ private: ToolButton *zoom_reset; ToolButton *zoom_plus; + Map<Control *, Timer *> popup_temporarily_timers; + + Label *warning_child_of_container; + VBoxContainer *info_overlay; + Transform2D transform; bool show_grid; bool show_rulers; @@ -369,9 +377,10 @@ private: Ref<ShortCut> multiply_grid_step_shortcut; Ref<ShortCut> divide_grid_step_shortcut; - bool _is_node_editable(const Node *p_node); - void _find_canvas_items_at_pos(const Point2 &p_pos, Node *p_node, Vector<_SelectResult> &r_items, int p_limit = 0, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D()); - void _get_canvas_items_at_pos(const Point2 &p_pos, Vector<_SelectResult> &r_items, int p_limit = 0); + bool _is_node_locked(const Node *p_node); + bool _is_node_movable(const Node *p_node, bool p_popup_warning = false); + void _find_canvas_items_at_pos(const Point2 &p_pos, Node *p_node, Vector<_SelectResult> &r_items, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D()); + void _get_canvas_items_at_pos(const Point2 &p_pos, Vector<_SelectResult> &r_items); void _get_bones_at_pos(const Point2 &p_pos, Vector<_SelectResult> &r_items); void _find_canvas_items_in_rect(const Rect2 &p_rect, Node *p_node, List<CanvasItem *> *r_items, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D()); @@ -477,6 +486,9 @@ private: void _update_bone_list(); void _tree_changed(Node *); + void _popup_warning_temporarily(Control *p_control, const float p_duration); + void _popup_warning_depop(Control *p_control); + friend class CanvasItemEditorPlugin; protected: @@ -542,11 +554,16 @@ public: void add_control_to_menu_panel(Control *p_control); void remove_control_from_menu_panel(Control *p_control); + void add_control_to_info_overlay(Control *p_control); + void remove_control_from_info_overlay(Control *p_control); + HSplitContainer *get_palette_split(); VSplitContainer *get_bottom_split(); Control *get_viewport_control() { return viewport; } + void update_viewport(); + Tool get_current_tool() { return tool; } void set_undo_redo(UndoRedo *p_undo_redo) { undo_redo = p_undo_redo; } @@ -591,7 +608,7 @@ class CanvasItemEditorViewport : public Control { EditorNode *editor; EditorData *editor_data; - CanvasItemEditor *canvas; + CanvasItemEditor *canvas_item_editor; Node2D *preview_node; AcceptDialog *accept; WindowDialog *selector; @@ -625,7 +642,7 @@ public: virtual bool can_drop_data(const Point2 &p_point, const Variant &p_data) const; virtual void drop_data(const Point2 &p_point, const Variant &p_data); - CanvasItemEditorViewport(EditorNode *p_node, CanvasItemEditor *p_canvas); + CanvasItemEditorViewport(EditorNode *p_node, CanvasItemEditor *p_canvas_item_editor); ~CanvasItemEditorViewport(); }; diff --git a/editor/plugins/collision_polygon_editor_plugin.cpp b/editor/plugins/collision_polygon_editor_plugin.cpp index 805a7d3835..9b31f2e24d 100644 --- a/editor/plugins/collision_polygon_editor_plugin.cpp +++ b/editor/plugins/collision_polygon_editor_plugin.cpp @@ -95,7 +95,7 @@ void Polygon3DEditor::_menu_option(int p_option) { void Polygon3DEditor::_wip_close() { - undo_redo->create_action(TTR("Create Poly3D")); + undo_redo->create_action(TTR("Create Polygon3D")); undo_redo->add_undo_method(node, "set_polygon", node->call("get_polygon")); undo_redo->add_do_method(node, "set_polygon", wip); undo_redo->add_do_method(this, "_polygon_draw"); @@ -144,7 +144,7 @@ bool Polygon3DEditor::forward_spatial_gui_input(Camera *p_camera, const Ref<Inpu Vector<Vector2> poly = node->call("get_polygon"); //first check if a point is to be added (segment split) - real_t grab_threshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8); + real_t grab_threshold = EDITOR_GET("editors/poly_editor/point_grab_radius"); switch (mode) { diff --git a/editor/plugins/collision_shape_2d_editor_plugin.cpp b/editor/plugins/collision_shape_2d_editor_plugin.cpp index d1a94f5b49..313ba1ee6b 100644 --- a/editor/plugins/collision_shape_2d_editor_plugin.cpp +++ b/editor/plugins/collision_shape_2d_editor_plugin.cpp @@ -129,7 +129,7 @@ void CollisionShape2DEditor::set_handle(int idx, Point2 &p_point) { capsule->set_height(parameter * 2 - capsule->get_radius() * 2); } - canvas_item_editor->get_viewport_control()->update(); + canvas_item_editor->update_viewport(); } } break; @@ -138,7 +138,7 @@ void CollisionShape2DEditor::set_handle(int idx, Point2 &p_point) { Ref<CircleShape2D> circle = node->get_shape(); circle->set_radius(p_point.length()); - canvas_item_editor->get_viewport_control()->update(); + canvas_item_editor->update_viewport(); } break; @@ -160,7 +160,7 @@ void CollisionShape2DEditor::set_handle(int idx, Point2 &p_point) { line->set_normal(p_point.normalized()); } - canvas_item_editor->get_viewport_control()->update(); + canvas_item_editor->update_viewport(); } } break; @@ -170,7 +170,7 @@ void CollisionShape2DEditor::set_handle(int idx, Point2 &p_point) { ray->set_length(Math::abs(p_point.y)); - canvas_item_editor->get_viewport_control()->update(); + canvas_item_editor->update_viewport(); } break; @@ -183,7 +183,7 @@ void CollisionShape2DEditor::set_handle(int idx, Point2 &p_point) { rect->set_extents(extents.abs()); - canvas_item_editor->get_viewport_control()->update(); + canvas_item_editor->update_viewport(); } } break; @@ -198,16 +198,16 @@ void CollisionShape2DEditor::set_handle(int idx, Point2 &p_point) { seg->set_b(p_point); } - canvas_item_editor->get_viewport_control()->update(); + canvas_item_editor->update_viewport(); } } break; } + node->get_shape()->_change_notify(); } void CollisionShape2DEditor::commit_handle(int idx, Variant &p_org) { - Control *c = canvas_item_editor->get_viewport_control(); undo_redo->create_action(TTR("Set Handle")); switch (shape_type) { @@ -216,14 +216,14 @@ void CollisionShape2DEditor::commit_handle(int idx, Variant &p_org) { if (idx == 0) { undo_redo->add_do_method(capsule.ptr(), "set_radius", capsule->get_radius()); - undo_redo->add_do_method(c, "update"); + undo_redo->add_do_method(canvas_item_editor, "update_viewport"); undo_redo->add_undo_method(capsule.ptr(), "set_radius", p_org); - undo_redo->add_do_method(c, "update"); + undo_redo->add_do_method(canvas_item_editor, "update_viewport"); } else if (idx == 1) { undo_redo->add_do_method(capsule.ptr(), "set_height", capsule->get_height()); - undo_redo->add_do_method(c, "update"); + undo_redo->add_do_method(canvas_item_editor, "update_viewport"); undo_redo->add_undo_method(capsule.ptr(), "set_height", p_org); - undo_redo->add_undo_method(c, "update"); + undo_redo->add_undo_method(canvas_item_editor, "update_viewport"); } } break; @@ -232,9 +232,9 @@ void CollisionShape2DEditor::commit_handle(int idx, Variant &p_org) { Ref<CircleShape2D> circle = node->get_shape(); undo_redo->add_do_method(circle.ptr(), "set_radius", circle->get_radius()); - undo_redo->add_do_method(c, "update"); + undo_redo->add_do_method(canvas_item_editor, "update_viewport"); undo_redo->add_undo_method(circle.ptr(), "set_radius", p_org); - undo_redo->add_undo_method(c, "update"); + undo_redo->add_undo_method(canvas_item_editor, "update_viewport"); } break; @@ -251,14 +251,14 @@ void CollisionShape2DEditor::commit_handle(int idx, Variant &p_org) { if (idx == 0) { undo_redo->add_do_method(line.ptr(), "set_d", line->get_d()); - undo_redo->add_do_method(c, "update"); + undo_redo->add_do_method(canvas_item_editor, "update_viewport"); undo_redo->add_undo_method(line.ptr(), "set_d", p_org); - undo_redo->add_undo_method(c, "update"); + undo_redo->add_undo_method(canvas_item_editor, "update_viewport"); } else { undo_redo->add_do_method(line.ptr(), "set_normal", line->get_normal()); - undo_redo->add_do_method(c, "update"); + undo_redo->add_do_method(canvas_item_editor, "update_viewport"); undo_redo->add_undo_method(line.ptr(), "set_normal", p_org); - undo_redo->add_undo_method(c, "update"); + undo_redo->add_undo_method(canvas_item_editor, "update_viewport"); } } break; @@ -267,9 +267,9 @@ void CollisionShape2DEditor::commit_handle(int idx, Variant &p_org) { Ref<RayShape2D> ray = node->get_shape(); undo_redo->add_do_method(ray.ptr(), "set_length", ray->get_length()); - undo_redo->add_do_method(c, "update"); + undo_redo->add_do_method(canvas_item_editor, "update_viewport"); undo_redo->add_undo_method(ray.ptr(), "set_length", p_org); - undo_redo->add_undo_method(c, "update"); + undo_redo->add_undo_method(canvas_item_editor, "update_viewport"); } break; @@ -277,9 +277,9 @@ void CollisionShape2DEditor::commit_handle(int idx, Variant &p_org) { Ref<RectangleShape2D> rect = node->get_shape(); undo_redo->add_do_method(rect.ptr(), "set_extents", rect->get_extents()); - undo_redo->add_do_method(c, "update"); + undo_redo->add_do_method(canvas_item_editor, "update_viewport"); undo_redo->add_undo_method(rect.ptr(), "set_extents", p_org); - undo_redo->add_undo_method(c, "update"); + undo_redo->add_undo_method(canvas_item_editor, "update_viewport"); } break; @@ -287,14 +287,14 @@ void CollisionShape2DEditor::commit_handle(int idx, Variant &p_org) { Ref<SegmentShape2D> seg = node->get_shape(); if (idx == 0) { undo_redo->add_do_method(seg.ptr(), "set_a", seg->get_a()); - undo_redo->add_do_method(c, "update"); + undo_redo->add_do_method(canvas_item_editor, "update_viewport"); undo_redo->add_undo_method(seg.ptr(), "set_a", p_org); - undo_redo->add_undo_method(c, "update"); + undo_redo->add_undo_method(canvas_item_editor, "update_viewport"); } else if (idx == 1) { undo_redo->add_do_method(seg.ptr(), "set_b", seg->get_b()); - undo_redo->add_do_method(c, "update"); + undo_redo->add_do_method(canvas_item_editor, "update_viewport"); undo_redo->add_undo_method(seg.ptr(), "set_b", p_org); - undo_redo->add_undo_method(c, "update"); + undo_redo->add_undo_method(canvas_item_editor, "update_viewport"); } } break; @@ -411,7 +411,7 @@ void CollisionShape2DEditor::_get_current_shape_type() { shape_type = -1; } - canvas_item_editor->get_viewport_control()->update(); + canvas_item_editor->update_viewport(); } void CollisionShape2DEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { @@ -538,7 +538,7 @@ void CollisionShape2DEditor::edit(Node *p_node) { node = NULL; } - canvas_item_editor->get_viewport_control()->update(); + canvas_item_editor->update_viewport(); } void CollisionShape2DEditor::_bind_methods() { diff --git a/editor/plugins/gi_probe_editor_plugin.cpp b/editor/plugins/gi_probe_editor_plugin.cpp index 06da64b181..5fc5cad1ef 100644 --- a/editor/plugins/gi_probe_editor_plugin.cpp +++ b/editor/plugins/gi_probe_editor_plugin.cpp @@ -90,7 +90,7 @@ void GIProbeEditorPlugin::_bind_methods() { GIProbeEditorPlugin::GIProbeEditorPlugin(EditorNode *p_node) { editor = p_node; - bake = memnew(Button); + bake = memnew(ToolButton); bake->set_icon(editor->get_gui_base()->get_icon("Bake", "EditorIcons")); bake->set_text(TTR("Bake GI Probe")); bake->hide(); diff --git a/editor/plugins/gi_probe_editor_plugin.h b/editor/plugins/gi_probe_editor_plugin.h index 017e9bd743..1b3b63f227 100644 --- a/editor/plugins/gi_probe_editor_plugin.h +++ b/editor/plugins/gi_probe_editor_plugin.h @@ -42,7 +42,7 @@ class GIProbeEditorPlugin : public EditorPlugin { GIProbe *gi_probe; - Button *bake; + ToolButton *bake; EditorNode *editor; static EditorProgress *tmp_progress; diff --git a/editor/plugins/item_list_editor_plugin.cpp b/editor/plugins/item_list_editor_plugin.cpp index 186e66f980..a32f42cc56 100644 --- a/editor/plugins/item_list_editor_plugin.cpp +++ b/editor/plugins/item_list_editor_plugin.cpp @@ -265,6 +265,9 @@ void ItemListEditor::_notification(int p_notification) { add_button->set_icon(get_icon("Add", "EditorIcons")); del_button->set_icon(get_icon("Remove", "EditorIcons")); + } else if (p_notification == NOTIFICATION_READY) { + + get_tree()->connect("node_removed", this, "_node_removed"); } } @@ -341,6 +344,7 @@ bool ItemListEditor::handles(Object *p_object) const { void ItemListEditor::_bind_methods() { + ClassDB::bind_method("_node_removed", &ItemListEditor::_node_removed); ClassDB::bind_method("_edit_items", &ItemListEditor::_edit_items); ClassDB::bind_method("_add_button", &ItemListEditor::_add_pressed); ClassDB::bind_method("_delete_button", &ItemListEditor::_delete_pressed); @@ -350,8 +354,6 @@ ItemListEditor::ItemListEditor() { selected_idx = -1; - add_child(memnew(VSeparator)); - toolbar_button = memnew(ToolButton); toolbar_button->set_text(TTR("Items")); add_child(toolbar_button); diff --git a/editor/plugins/light_occluder_2d_editor_plugin.cpp b/editor/plugins/light_occluder_2d_editor_plugin.cpp index 2f2e1dae81..646883fbda 100644 --- a/editor/plugins/light_occluder_2d_editor_plugin.cpp +++ b/editor/plugins/light_occluder_2d_editor_plugin.cpp @@ -30,425 +30,91 @@ #include "light_occluder_2d_editor_plugin.h" -#include "canvas_item_editor_plugin.h" -#include "core/os/file_access.h" -#include "editor/editor_settings.h" +Ref<OccluderPolygon2D> LightOccluder2DEditor::_ensure_occluder() const { -void LightOccluder2DEditor::_notification(int p_what) { + Ref<OccluderPolygon2D> occluder = node->get_occluder_polygon(); + if (!occluder.is_valid()) { - switch (p_what) { - - case NOTIFICATION_READY: { - - button_create->set_icon(get_icon("Edit", "EditorIcons")); - button_edit->set_icon(get_icon("MovePoint", "EditorIcons")); - button_edit->set_pressed(true); - get_tree()->connect("node_removed", this, "_node_removed"); - create_poly->connect("confirmed", this, "_create_poly"); - - } break; - case NOTIFICATION_PHYSICS_PROCESS: { - - } break; - } -} -void LightOccluder2DEditor::_node_removed(Node *p_node) { - - if (p_node == node) { - node = NULL; - hide(); - canvas_item_editor->get_viewport_control()->update(); + occluder = Ref<OccluderPolygon2D>(memnew(OccluderPolygon2D)); + node->set_occluder_polygon(occluder); } + return occluder; } -void LightOccluder2DEditor::_menu_option(int p_option) { +Node2D *LightOccluder2DEditor::_get_node() const { - switch (p_option) { - - case MODE_CREATE: { - - mode = MODE_CREATE; - button_create->set_pressed(true); - button_edit->set_pressed(false); - } break; - case MODE_EDIT: { - - mode = MODE_EDIT; - button_create->set_pressed(false); - button_edit->set_pressed(true); - } break; - } + return node; } -void LightOccluder2DEditor::_wip_close(bool p_closed) { - - undo_redo->create_action(TTR("Create Poly")); - undo_redo->add_undo_method(node->get_occluder_polygon().ptr(), "set_polygon", node->get_occluder_polygon()->get_polygon()); - undo_redo->add_do_method(node->get_occluder_polygon().ptr(), "set_polygon", wip); - undo_redo->add_undo_method(node->get_occluder_polygon().ptr(), "set_closed", node->get_occluder_polygon()->is_closed()); - undo_redo->add_do_method(node->get_occluder_polygon().ptr(), "set_closed", p_closed); +void LightOccluder2DEditor::_set_node(Node *p_polygon) { - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->commit_action(); - wip.clear(); - wip_active = false; - mode = MODE_EDIT; - button_edit->set_pressed(true); - button_create->set_pressed(false); - edited_point = -1; + node = Object::cast_to<LightOccluder2D>(p_polygon); } -bool LightOccluder2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { +bool LightOccluder2DEditor::_is_line() const { - if (!node) + Ref<OccluderPolygon2D> occluder = node->get_occluder_polygon(); + if (occluder.is_valid()) + return !occluder->is_closed(); + else return false; - - if (node->get_occluder_polygon().is_null()) { - Ref<InputEventMouseButton> mb = p_event; - if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed()) { - create_poly->set_text(TTR("No OccluderPolygon2D resource on this node.\nCreate and assign one?")); - create_poly->popup_centered_minsize(); - } - return (mb.is_valid() && mb->get_button_index() == 1); - } - - Ref<InputEventMouseButton> mb = p_event; - - if (mb.is_valid()) { - - Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - - Vector2 gpoint = mb->get_position(); - Vector2 cpoint = node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(mb->get_position()))); - - Vector<Vector2> poly = Variant(node->get_occluder_polygon()->get_polygon()); - - //first check if a point is to be added (segment split) - real_t grab_threshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8); - - switch (mode) { - - case MODE_CREATE: { - - if (mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) { - - if (!wip_active) { - - wip.clear(); - wip.push_back(cpoint); - wip_active = true; - edited_point_pos = cpoint; - canvas_item_editor->get_viewport_control()->update(); - edited_point = 1; - return true; - } else { - - if (wip.size() > 1 && xform.xform(wip[0]).distance_to(gpoint) < grab_threshold) { - //wip closed - _wip_close(true); - - return true; - } else if (wip.size() > 1 && xform.xform(wip[wip.size() - 1]).distance_to(gpoint) < grab_threshold) { - //wip closed - _wip_close(false); - return true; - - } else { - - wip.push_back(cpoint); - edited_point = wip.size(); - canvas_item_editor->get_viewport_control()->update(); - return true; - - //add wip point - } - } - } else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed() && wip_active) { - _wip_close(true); - } - - } break; - - case MODE_EDIT: { - - if (mb->get_button_index() == BUTTON_LEFT) { - if (mb->is_pressed()) { - - if (mb->get_control()) { - - if (poly.size() < 3) { - - undo_redo->create_action(TTR("Edit Poly")); - undo_redo->add_undo_method(node->get_occluder_polygon().ptr(), "set_polygon", poly); - poly.push_back(cpoint); - undo_redo->add_do_method(node->get_occluder_polygon().ptr(), "set_polygon", poly); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->commit_action(); - return true; - } - - //search edges - int closest_idx = -1; - Vector2 closest_pos; - real_t closest_dist = 1e10; - for (int i = 0; i < poly.size(); i++) { - - Vector2 points[2] = { xform.xform(poly[i]), - xform.xform(poly[(i + 1) % poly.size()]) }; - - Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint, points); - if (cp.distance_squared_to(points[0]) < CMP_EPSILON2 || cp.distance_squared_to(points[1]) < CMP_EPSILON2) - continue; //not valid to reuse point - - real_t d = cp.distance_to(gpoint); - if (d < closest_dist && d < grab_threshold) { - closest_dist = d; - closest_pos = cp; - closest_idx = i; - } - } - - if (closest_idx >= 0) { - - pre_move_edit = poly; - poly.insert(closest_idx + 1, xform.affine_inverse().xform(closest_pos)); - edited_point = closest_idx + 1; - edited_point_pos = xform.affine_inverse().xform(closest_pos); - node->get_occluder_polygon()->set_polygon(Variant(poly)); - canvas_item_editor->get_viewport_control()->update(); - return true; - } - } else { - - //look for points to move - - int closest_idx = -1; - Vector2 closest_pos; - real_t closest_dist = 1e10; - for (int i = 0; i < poly.size(); i++) { - - Vector2 cp = xform.xform(poly[i]); - - real_t d = cp.distance_to(gpoint); - if (d < closest_dist && d < grab_threshold) { - closest_dist = d; - closest_pos = cp; - closest_idx = i; - } - } - - if (closest_idx >= 0) { - - pre_move_edit = poly; - edited_point = closest_idx; - edited_point_pos = xform.affine_inverse().xform(closest_pos); - canvas_item_editor->get_viewport_control()->update(); - return true; - } - } - } else { - - if (edited_point != -1) { - - //apply - - ERR_FAIL_INDEX_V(edited_point, poly.size(), false); - poly.write[edited_point] = edited_point_pos; - undo_redo->create_action(TTR("Edit Poly")); - undo_redo->add_do_method(node->get_occluder_polygon().ptr(), "set_polygon", poly); - undo_redo->add_undo_method(node->get_occluder_polygon().ptr(), "set_polygon", pre_move_edit); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->commit_action(); - - edited_point = -1; - return true; - } - } - } else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed() && edited_point == -1) { - - int closest_idx = -1; - Vector2 closest_pos; - real_t closest_dist = 1e10; - for (int i = 0; i < poly.size(); i++) { - - Vector2 cp = xform.xform(poly[i]); - - real_t d = cp.distance_to(gpoint); - if (d < closest_dist && d < grab_threshold) { - closest_dist = d; - closest_pos = cp; - closest_idx = i; - } - } - - if (closest_idx >= 0) { - - undo_redo->create_action(TTR("Edit Poly (Remove Point)")); - undo_redo->add_undo_method(node->get_occluder_polygon().ptr(), "set_polygon", poly); - poly.remove(closest_idx); - undo_redo->add_do_method(node->get_occluder_polygon().ptr(), "set_polygon", poly); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->commit_action(); - return true; - } - } - - } break; - } - } - - Ref<InputEventMouseMotion> mm = p_event; - - if (mm.is_valid()) { - - if (edited_point != -1 && (wip_active || mm->get_button_mask() & BUTTON_MASK_LEFT)) { - - Vector2 gpoint = mm->get_position(); - Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); - cpoint = canvas_item_editor->snap_point(cpoint); - edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint); - - canvas_item_editor->get_viewport_control()->update(); - } - } - - return false; } -void LightOccluder2DEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { - - if (!node || !node->get_occluder_polygon().is_valid()) - return; - - Vector<Vector2> poly; +int LightOccluder2DEditor::_get_polygon_count() const { - if (wip_active) - poly = wip; + Ref<OccluderPolygon2D> occluder = node->get_occluder_polygon(); + if (occluder.is_valid()) + return occluder->get_polygon().size(); else - poly = Variant(node->get_occluder_polygon()->get_polygon()); - - Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Ref<Texture> handle = get_icon("EditorHandle", "EditorIcons"); - - for (int i = 0; i < poly.size(); i++) { - - Vector2 p, p2; - p = i == edited_point ? edited_point_pos : poly[i]; - if ((wip_active && i == poly.size() - 1) || (((i + 1) % poly.size()) == edited_point)) - p2 = edited_point_pos; - else - p2 = poly[(i + 1) % poly.size()]; + return 0; +} - Vector2 point = xform.xform(p); - Vector2 next_point = xform.xform(p2); +Variant LightOccluder2DEditor::_get_polygon(int p_idx) const { - Color col = Color(1, 0.3, 0.1, 0.8); + Ref<OccluderPolygon2D> occluder = node->get_occluder_polygon(); + if (occluder.is_valid()) + return occluder->get_polygon(); + else + return Variant(Vector<Vector2>()); +} - if (i == poly.size() - 1 && (!node->get_occluder_polygon()->is_closed() || wip_active)) { +void LightOccluder2DEditor::_set_polygon(int p_idx, const Variant &p_polygon) const { - } else { - p_overlay->draw_line(point, next_point, col, 2); - } - p_overlay->draw_texture(handle, point - handle->get_size() * 0.5); - } + Ref<OccluderPolygon2D> occluder = _ensure_occluder(); + occluder->set_polygon(p_polygon); } -void LightOccluder2DEditor::edit(Node *p_collision_polygon) { +void LightOccluder2DEditor::_action_set_polygon(int p_idx, const Variant &p_previous, const Variant &p_polygon) { - if (!canvas_item_editor) { - canvas_item_editor = CanvasItemEditor::get_singleton(); - } + Ref<OccluderPolygon2D> occluder = _ensure_occluder(); + undo_redo->add_do_method(occluder.ptr(), "set_polygon", p_polygon); + undo_redo->add_undo_method(occluder.ptr(), "set_polygon", p_previous); +} - if (p_collision_polygon) { +bool LightOccluder2DEditor::_has_resource() const { - node = Object::cast_to<LightOccluder2D>(p_collision_polygon); - wip.clear(); - wip_active = false; - edited_point = -1; - canvas_item_editor->get_viewport_control()->update(); - } else { - node = NULL; - } + return node && node->get_occluder_polygon().is_valid(); } -void LightOccluder2DEditor::_create_poly() { +void LightOccluder2DEditor::_create_resource() { if (!node) return; + undo_redo->create_action(TTR("Create Occluder Polygon")); undo_redo->add_do_method(node, "set_occluder_polygon", Ref<OccluderPolygon2D>(memnew(OccluderPolygon2D))); undo_redo->add_undo_method(node, "set_occluder_polygon", Variant(REF())); undo_redo->commit_action(); -} - -void LightOccluder2DEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_menu_option"), &LightOccluder2DEditor::_menu_option); - ClassDB::bind_method(D_METHOD("_node_removed"), &LightOccluder2DEditor::_node_removed); - ClassDB::bind_method(D_METHOD("_create_poly"), &LightOccluder2DEditor::_create_poly); + _menu_option(MODE_CREATE); } -LightOccluder2DEditor::LightOccluder2DEditor(EditorNode *p_editor) { +LightOccluder2DEditor::LightOccluder2DEditor(EditorNode *p_editor) : + AbstractPolygon2DEditor(p_editor) { node = NULL; - canvas_item_editor = NULL; - editor = p_editor; - undo_redo = editor->get_undo_redo(); - - add_child(memnew(VSeparator)); - button_create = memnew(ToolButton); - add_child(button_create); - button_create->connect("pressed", this, "_menu_option", varray(MODE_CREATE)); - button_create->set_toggle_mode(true); - button_create->set_tooltip(TTR("Create a new polygon from scratch.")); - - button_edit = memnew(ToolButton); - add_child(button_edit); - button_edit->connect("pressed", this, "_menu_option", varray(MODE_EDIT)); - button_edit->set_toggle_mode(true); - button_edit->set_tooltip(TTR("Edit existing polygon:") + "\n" + TTR("LMB: Move Point.") + "\n" + TTR("Ctrl+LMB: Split Segment.") + "\n" + TTR("RMB: Erase Point.")); - - create_poly = memnew(ConfirmationDialog); - add_child(create_poly); - create_poly->get_ok()->set_text(TTR("Create")); - - mode = MODE_EDIT; - wip_active = false; -} - -void LightOccluder2DEditorPlugin::edit(Object *p_object) { - - light_occluder_editor->edit(Object::cast_to<Node>(p_object)); -} - -bool LightOccluder2DEditorPlugin::handles(Object *p_object) const { - - return p_object->is_class("LightOccluder2D"); -} - -void LightOccluder2DEditorPlugin::make_visible(bool p_visible) { - - if (p_visible) { - light_occluder_editor->show(); - } else { - - light_occluder_editor->hide(); - light_occluder_editor->edit(NULL); - } -} - -LightOccluder2DEditorPlugin::LightOccluder2DEditorPlugin(EditorNode *p_node) { - - editor = p_node; - light_occluder_editor = memnew(LightOccluder2DEditor(p_node)); - CanvasItemEditor::get_singleton()->add_control_to_menu_panel(light_occluder_editor); - - light_occluder_editor->hide(); } -LightOccluder2DEditorPlugin::~LightOccluder2DEditorPlugin() { +LightOccluder2DEditorPlugin::LightOccluder2DEditorPlugin(EditorNode *p_node) : + AbstractPolygon2DEditorPlugin(p_node, memnew(LightOccluder2DEditor(p_node)), "LightOccluder2D") { } diff --git a/editor/plugins/light_occluder_2d_editor_plugin.h b/editor/plugins/light_occluder_2d_editor_plugin.h index a1962892ee..6117d50e89 100644 --- a/editor/plugins/light_occluder_2d_editor_plugin.h +++ b/editor/plugins/light_occluder_2d_editor_plugin.h @@ -31,83 +31,44 @@ #ifndef LIGHT_OCCLUDER_2D_EDITOR_PLUGIN_H #define LIGHT_OCCLUDER_2D_EDITOR_PLUGIN_H -#include "editor/editor_node.h" -#include "editor/editor_plugin.h" +#include "editor/plugins/abstract_polygon_2d_editor.h" #include "scene/2d/light_occluder_2d.h" -#include "scene/gui/tool_button.h" /** @author Juan Linietsky <reduzio@gmail.com> */ -class CanvasItemEditor; +class LightOccluder2DEditor : public AbstractPolygon2DEditor { -class LightOccluder2DEditor : public HBoxContainer { + GDCLASS(LightOccluder2DEditor, AbstractPolygon2DEditor); - GDCLASS(LightOccluder2DEditor, HBoxContainer); - - UndoRedo *undo_redo; - enum Mode { - - MODE_CREATE, - MODE_EDIT, - - }; - - Mode mode; - - ToolButton *button_create; - ToolButton *button_edit; - - CanvasItemEditor *canvas_item_editor; - EditorNode *editor; - Panel *panel; LightOccluder2D *node; - MenuButton *options; - int edited_point; - Vector2 edited_point_pos; - Vector<Vector2> pre_move_edit; - Vector<Vector2> wip; - bool wip_active; + Ref<OccluderPolygon2D> _ensure_occluder() const; - ConfirmationDialog *create_poly; +protected: + virtual Node2D *_get_node() const; + virtual void _set_node(Node *p_polygon); - void _wip_close(bool p_closed); - void _menu_option(int p_option); - void _create_poly(); + virtual bool _is_line() const; + virtual int _get_polygon_count() const; + virtual Variant _get_polygon(int p_idx) const; + virtual void _set_polygon(int p_idx, const Variant &p_polygon) const; -protected: - void _notification(int p_what); - void _node_removed(Node *p_node); - static void _bind_methods(); + virtual void _action_set_polygon(int p_idx, const Variant &p_previous, const Variant &p_polygon); + + virtual bool _has_resource() const; + virtual void _create_resource(); public: - Vector2 snap_point(const Vector2 &p_point) const; - void forward_canvas_draw_over_viewport(Control *p_overlay); - bool forward_gui_input(const Ref<InputEvent> &p_event); - void edit(Node *p_collision_polygon); LightOccluder2DEditor(EditorNode *p_editor); }; -class LightOccluder2DEditorPlugin : public EditorPlugin { +class LightOccluder2DEditorPlugin : public AbstractPolygon2DEditorPlugin { - GDCLASS(LightOccluder2DEditorPlugin, EditorPlugin); - - LightOccluder2DEditor *light_occluder_editor; - EditorNode *editor; + GDCLASS(LightOccluder2DEditorPlugin, AbstractPolygon2DEditorPlugin); public: - virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event) { return light_occluder_editor->forward_gui_input(p_event); } - virtual void forward_canvas_draw_over_viewport(Control *p_overlay) { return light_occluder_editor->forward_canvas_draw_over_viewport(p_overlay); } - - virtual String get_name() const { return "LightOccluder2D"; } - bool has_main_screen() const { return false; } - virtual void edit(Object *p_object); - virtual bool handles(Object *p_object) const; - virtual void make_visible(bool p_visible); - LightOccluder2DEditorPlugin(EditorNode *p_node); - ~LightOccluder2DEditorPlugin(); }; #endif // LIGHT_OCCLUDER_2D_EDITOR_PLUGIN_H diff --git a/editor/plugins/particles_2d_editor_plugin.cpp b/editor/plugins/particles_2d_editor_plugin.cpp index 5dcbca2ed6..ab94258c44 100644 --- a/editor/plugins/particles_2d_editor_plugin.cpp +++ b/editor/plugins/particles_2d_editor_plugin.cpp @@ -32,6 +32,7 @@ #include "canvas_item_editor_plugin.h" #include "core/io/image_loader.h" +#include "scene/2d/cpu_particles_2d.h" #include "scene/gui/separator.h" #include "scene/resources/particles_material.h" @@ -82,6 +83,25 @@ void Particles2DEditorPlugin::_menu_callback(int p_idx) { emission_mask->popup_centered_minsize(); } break; + case MENU_OPTION_CONVERT_TO_CPU_PARTICLES: { + + UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo(); + + CPUParticles2D *cpu_particles = memnew(CPUParticles2D); + cpu_particles->convert_from_particles(particles); + cpu_particles->set_name(particles->get_name()); + cpu_particles->set_transform(particles->get_transform()); + cpu_particles->set_visible(particles->is_visible()); + cpu_particles->set_pause_mode(particles->get_pause_mode()); + + undo_redo->create_action("Replace Particles by CPUParticles"); + undo_redo->add_do_method(particles, "replace_by", cpu_particles); + undo_redo->add_undo_method(cpu_particles, "replace_by", particles); + undo_redo->add_do_reference(cpu_particles); + undo_redo->add_undo_reference(particles); + undo_redo->commit_action(); + + } break; } } @@ -355,6 +375,8 @@ Particles2DEditorPlugin::Particles2DEditorPlugin(EditorNode *p_node) { menu->get_popup()->add_separator(); menu->get_popup()->add_item(TTR("Load Emission Mask"), MENU_LOAD_EMISSION_MASK); // menu->get_popup()->add_item(TTR("Clear Emission Mask"), MENU_CLEAR_EMISSION_MASK); + menu->get_popup()->add_separator(); + menu->get_popup()->add_item(TTR("Convert to CPUParticles"), MENU_OPTION_CONVERT_TO_CPU_PARTICLES); menu->set_text(TTR("Particles")); toolbar->add_child(menu); diff --git a/editor/plugins/particles_2d_editor_plugin.h b/editor/plugins/particles_2d_editor_plugin.h index 71ca8ef499..eaa96d84e9 100644 --- a/editor/plugins/particles_2d_editor_plugin.h +++ b/editor/plugins/particles_2d_editor_plugin.h @@ -46,7 +46,8 @@ class Particles2DEditorPlugin : public EditorPlugin { MENU_GENERATE_VISIBILITY_RECT, MENU_LOAD_EMISSION_MASK, - MENU_CLEAR_EMISSION_MASK + MENU_CLEAR_EMISSION_MASK, + MENU_OPTION_CONVERT_TO_CPU_PARTICLES }; enum EmissionMode { diff --git a/editor/plugins/particles_editor_plugin.cpp b/editor/plugins/particles_editor_plugin.cpp index 6b41946918..f2dfae7a9f 100644 --- a/editor/plugins/particles_editor_plugin.cpp +++ b/editor/plugins/particles_editor_plugin.cpp @@ -453,6 +453,7 @@ void ParticlesEditor::_bind_methods() { ParticlesEditor::ParticlesEditor() { + node = NULL; particles_editor_hb = memnew(HBoxContainer); SpatialEditor::get_singleton()->add_control_to_menu_panel(particles_editor_hb); options = memnew(MenuButton); diff --git a/editor/plugins/path_2d_editor_plugin.cpp b/editor/plugins/path_2d_editor_plugin.cpp index 88b3194490..3d4816b17b 100644 --- a/editor/plugins/path_2d_editor_plugin.cpp +++ b/editor/plugins/path_2d_editor_plugin.cpp @@ -70,8 +70,9 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { if (!node->get_curve().is_valid()) return false; - Ref<InputEventMouseButton> mb = p_event; + real_t grab_threshold = EDITOR_GET("editors/poly_editor/point_grab_radius"); + Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid()) { Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); @@ -79,8 +80,6 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { Vector2 gpoint = mb->get_position(); Vector2 cpoint = node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(mb->get_position()))); - real_t grab_threshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8); - if (mb->is_pressed() && action == ACTION_NONE) { Ref<Curve2D> curve = node->get_curve(); @@ -130,8 +129,8 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { undo_redo->create_action(TTR("Remove Point from Curve")); undo_redo->add_do_method(curve.ptr(), "remove_point", i); undo_redo->add_undo_method(curve.ptr(), "add_point", curve->get_point_position(i), curve->get_point_in(i), curve->get_point_out(i), i); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_do_method(canvas_item_editor, "update_viewport"); + undo_redo->add_undo_method(canvas_item_editor, "update_viewport"); undo_redo->commit_action(); return true; } else if (dist_to_p_out < grab_threshold) { @@ -139,8 +138,8 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { undo_redo->create_action(TTR("Remove Out-Control from Curve")); undo_redo->add_do_method(curve.ptr(), "set_point_out", i, Vector2()); undo_redo->add_undo_method(curve.ptr(), "set_point_out", i, curve->get_point_out(i)); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_do_method(canvas_item_editor, "update_viewport"); + undo_redo->add_undo_method(canvas_item_editor, "update_viewport"); undo_redo->commit_action(); return true; } else if (dist_to_p_in < grab_threshold) { @@ -148,8 +147,8 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { undo_redo->create_action(TTR("Remove In-Control from Curve")); undo_redo->add_do_method(curve.ptr(), "set_point_in", i, Vector2()); undo_redo->add_undo_method(curve.ptr(), "set_point_in", i, curve->get_point_in(i)); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_do_method(canvas_item_editor, "update_viewport"); + undo_redo->add_undo_method(canvas_item_editor, "update_viewport"); undo_redo->commit_action(); return true; } @@ -165,8 +164,8 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { undo_redo->create_action(TTR("Add Point to Curve")); undo_redo->add_do_method(curve.ptr(), "add_point", cpoint); undo_redo->add_undo_method(curve.ptr(), "remove_point", curve->get_point_count()); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_do_method(canvas_item_editor, "update_viewport"); + undo_redo->add_undo_method(canvas_item_editor, "update_viewport"); undo_redo->commit_action(); action = ACTION_MOVING_POINT; @@ -174,7 +173,42 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { moving_from = curve->get_point_position(action_point); moving_screen_from = gpoint; - canvas_item_editor->get_viewport_control()->update(); + canvas_item_editor->update_viewport(); + + return true; + } + + // Check for segment split. + if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT && mode == MODE_EDIT && on_edge == true) { + Vector2 gpoint = mb->get_position(); + Ref<Curve2D> curve = node->get_curve(); + + int insertion_point = -1; + float mbLength = curve->get_closest_offset(xform.affine_inverse().xform(gpoint)); + int len = curve->get_point_count(); + for (int i = 0; i < len - 1; i++) { + float compareLength = curve->get_closest_offset(curve->get_point_position(i + 1)); + if (mbLength >= curve->get_closest_offset(curve->get_point_position(i)) && mbLength <= compareLength) + insertion_point = i; + } + if (insertion_point == -1) + insertion_point = curve->get_point_count() - 2; + + undo_redo->create_action(TTR("Split Curve")); + undo_redo->add_do_method(curve.ptr(), "add_point", xform.affine_inverse().xform(gpoint), Vector2(0, 0), Vector2(0, 0), insertion_point + 1); + undo_redo->add_undo_method(curve.ptr(), "remove_point", insertion_point + 1); + undo_redo->add_do_method(canvas_item_editor, "update_viewport"); + undo_redo->add_undo_method(canvas_item_editor, "update_viewport"); + undo_redo->commit_action(); + + action = ACTION_MOVING_POINT; + action_point = insertion_point + 1; + moving_from = curve->get_point_position(action_point); + moving_screen_from = gpoint; + + canvas_item_editor->update_viewport(); + + on_edge = false; return true; } @@ -196,8 +230,8 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { undo_redo->create_action(TTR("Move Point in Curve")); undo_redo->add_do_method(curve.ptr(), "set_point_position", action_point, cpoint); undo_redo->add_undo_method(curve.ptr(), "set_point_position", action_point, moving_from); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_do_method(canvas_item_editor, "update_viewport"); + undo_redo->add_undo_method(canvas_item_editor, "update_viewport"); undo_redo->commit_action(); } break; @@ -212,8 +246,8 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { undo_redo->add_do_method(curve.ptr(), "set_point_out", action_point, mirror_handle_length ? -new_pos : (-new_pos.normalized() * orig_out_length)); undo_redo->add_undo_method(curve.ptr(), "set_point_out", action_point, mirror_handle_length ? -moving_from : (-moving_from.normalized() * orig_out_length)); } - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_do_method(canvas_item_editor, "update_viewport"); + undo_redo->add_undo_method(canvas_item_editor, "update_viewport"); undo_redo->commit_action(); } break; @@ -228,8 +262,8 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { undo_redo->add_do_method(curve.ptr(), "set_point_in", action_point, mirror_handle_length ? -new_pos : (-new_pos.normalized() * orig_in_length)); undo_redo->add_undo_method(curve.ptr(), "set_point_in", action_point, mirror_handle_length ? -moving_from : (-moving_from.normalized() * orig_in_length)); } - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_do_method(canvas_item_editor, "update_viewport"); + undo_redo->add_undo_method(canvas_item_editor, "update_viewport"); undo_redo->commit_action(); } break; @@ -245,6 +279,49 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { if (mm.is_valid()) { + if (action == ACTION_NONE && mode == MODE_EDIT) { + // Handle Edge Follow + bool old_edge = on_edge; + + Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); + Vector2 gpoint = mm->get_position(); + + Ref<Curve2D> curve = node->get_curve(); + if (curve == NULL) return true; + if (curve->get_point_count() < 2) return true; + + // Find edge + edge_point = xform.xform(curve->get_closest_point(xform.affine_inverse().xform(mm->get_position()))); + on_edge = false; + if (edge_point.distance_to(gpoint) <= grab_threshold) { + on_edge = true; + } + // However, if near a control point or its in-out handles then not on edge + int len = curve->get_point_count(); + for (int i = 0; i < len; i++) { + Vector2 pp = curve->get_point_position(i); + Vector2 p = xform.xform(pp); + if (p.distance_to(gpoint) <= grab_threshold) { + on_edge = false; + break; + } + p = xform.xform(pp + curve->get_point_in(i)); + if (p.distance_to(gpoint) <= grab_threshold) { + on_edge = false; + break; + } + p = xform.xform(pp + curve->get_point_out(i)); + if (p.distance_to(gpoint) <= grab_threshold) { + on_edge = false; + break; + } + } + if (on_edge || old_edge != on_edge) { + canvas_item_editor->update_viewport(); + return true; + } + } + if (action != ACTION_NONE) { // Handle point/control movement. Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); @@ -280,7 +357,7 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { } break; } - canvas_item_editor->get_viewport_control()->update(); + canvas_item_editor->update_viewport(); return true; } } @@ -309,7 +386,6 @@ void Path2DEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { Control *vpc = canvas_item_editor->get_viewport_control(); for (int i = 0; i < len; i++) { - Vector2 point = xform.xform(curve->get_point_position(i)); vpc->draw_texture_rect(handle, Rect2(point - handle_size * 0.5, handle_size), false, Color(1, 1, 1, 1)); @@ -325,13 +401,18 @@ void Path2DEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { vpc->draw_texture_rect(handle, Rect2(pointin - handle_size * 0.5, handle_size), false, Color(1, 0.5, 1, 0.3)); } } + + if (on_edge) { + Ref<Texture> add_handle = get_icon("EditorHandleAdd", "EditorIcons"); + p_overlay->draw_texture(add_handle, edge_point - add_handle->get_size() * 0.5); + } } void Path2DEditor::_node_visibility_changed() { if (!node) return; - canvas_item_editor->get_viewport_control()->update(); + canvas_item_editor->update_viewport(); } void Path2DEditor::edit(Node *p_path2d) { @@ -406,8 +487,8 @@ void Path2DEditor::_mode_selected(int p_mode) { undo_redo->create_action(TTR("Remove Point from Curve")); undo_redo->add_do_method(node->get_curve().ptr(), "add_point", begin); undo_redo->add_undo_method(node->get_curve().ptr(), "remove_point", node->get_curve()->get_point_count()); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_do_method(canvas_item_editor, "update_viewport"); + undo_redo->add_undo_method(canvas_item_editor, "update_viewport"); undo_redo->commit_action(); return; } @@ -442,6 +523,7 @@ Path2DEditor::Path2DEditor(EditorNode *p_editor) { undo_redo = editor->get_undo_redo(); mirror_handle_angle = true; mirror_handle_length = true; + on_edge = false; mode = MODE_EDIT; action = ACTION_NONE; @@ -455,7 +537,7 @@ Path2DEditor::Path2DEditor(EditorNode *p_editor) { curve_edit->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveEdit", "EditorIcons")); curve_edit->set_toggle_mode(true); curve_edit->set_focus_mode(Control::FOCUS_NONE); - curve_edit->set_tooltip(TTR("Select Points") + "\n" + TTR("Shift+Drag: Select Control Points") + "\n" + keycode_get_string(KEY_MASK_CMD) + TTR("Click: Add Point") + "\n" + TTR("Right Click: Delete Point")); + curve_edit->set_tooltip(TTR("Select Points") + "\n" + TTR("Shift+Drag: Select Control Points") + "\n" + keycode_get_string(KEY_MASK_CMD) + TTR("Click: Add Point") + "\n" + TTR("Left Click: Split Segment (in curve)") + "\n" + TTR("Right Click: Delete Point")); curve_edit->connect("pressed", this, "_mode_selected", varray(MODE_EDIT)); base_hb->add_child(curve_edit); curve_edit_curve = memnew(ToolButton); @@ -469,7 +551,7 @@ Path2DEditor::Path2DEditor(EditorNode *p_editor) { curve_create->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveCreate", "EditorIcons")); curve_create->set_toggle_mode(true); curve_create->set_focus_mode(Control::FOCUS_NONE); - curve_create->set_tooltip(TTR("Add Point (in empty space)") + "\n" + TTR("Split Segment (in curve)")); + curve_create->set_tooltip(TTR("Add Point (in empty space)")); curve_create->connect("pressed", this, "_mode_selected", varray(MODE_CREATE)); base_hb->add_child(curve_create); curve_del = memnew(ToolButton); diff --git a/editor/plugins/path_2d_editor_plugin.h b/editor/plugins/path_2d_editor_plugin.h index 3a78657746..34952b473a 100644 --- a/editor/plugins/path_2d_editor_plugin.h +++ b/editor/plugins/path_2d_editor_plugin.h @@ -73,6 +73,7 @@ class Path2DEditor : public HBoxContainer { bool mirror_handle_angle; bool mirror_handle_length; + bool on_edge; enum HandleOption { HANDLE_OPTION_ANGLE, @@ -93,6 +94,7 @@ class Path2DEditor : public HBoxContainer { Point2 moving_screen_from; float orig_in_length; float orig_out_length; + Vector2 edge_point; void _mode_selected(int p_mode); void _handle_option_pressed(int p_option); diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp index f937744d45..97448f3f88 100644 --- a/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/editor/plugins/polygon_2d_editor_plugin.cpp @@ -56,6 +56,12 @@ void Polygon2DEditor::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: + case NOTIFICATION_THEME_CHANGED: { + + uv_edit_draw->add_style_override("panel", get_stylebox("bg", "Tree")); + bone_scroll->add_style_override("bg", get_stylebox("bg", "Tree")); + } break; case NOTIFICATION_READY: { button_uv->set_icon(get_icon("Uv", "EditorIcons")); @@ -73,66 +79,68 @@ void Polygon2DEditor::_notification(int p_what) { b_snap_grid->set_icon(get_icon("Grid", "EditorIcons")); b_snap_enable->set_icon(get_icon("SnapGrid", "EditorIcons")); uv_icon_zoom->set_texture(get_icon("Zoom", "EditorIcons")); - } break; - case NOTIFICATION_PHYSICS_PROCESS: { + case NOTIFICATION_VISIBILITY_CHANGED: { + if (!is_visible()) { + uv_edit->hide(); + } } break; } } void Polygon2DEditor::_sync_bones() { + Skeleton2D *skeleton; if (!node->has_node(node->get_skeleton())) { error->set_text(TTR("The skeleton property of the Polygon2D does not point to a Skeleton2D node")); error->popup_centered_minsize(); - return; + } else { + Node *sn = node->get_node(node->get_skeleton()); + skeleton = Object::cast_to<Skeleton2D>(sn); } - Node *sn = node->get_node(node->get_skeleton()); - Skeleton2D *skeleton = Object::cast_to<Skeleton2D>(sn); + Array prev_bones = node->call("_get_bones"); + node->clear_bones(); if (!skeleton) { error->set_text(TTR("The skeleton property of the Polygon2D does not point to a Skeleton2D node")); error->popup_centered_minsize(); - return; - } - - Array prev_bones = node->call("_get_bones"); - node->clear_bones(); - - for (int i = 0; i < skeleton->get_bone_count(); i++) { - NodePath path = skeleton->get_path_to(skeleton->get_bone(i)); - PoolVector<float> weights; - int wc = node->get_polygon().size(); - - for (int j = 0; j < prev_bones.size(); j += 2) { - NodePath pvp = prev_bones[j]; - PoolVector<float> pv = prev_bones[j + 1]; - if (pvp == path && pv.size() == wc) { - weights = pv; + } else { + for (int i = 0; i < skeleton->get_bone_count(); i++) { + NodePath path = skeleton->get_path_to(skeleton->get_bone(i)); + PoolVector<float> weights; + int wc = node->get_polygon().size(); + + for (int j = 0; j < prev_bones.size(); j += 2) { + NodePath pvp = prev_bones[j]; + PoolVector<float> pv = prev_bones[j + 1]; + if (pvp == path && pv.size() == wc) { + weights = pv; + } } - } - if (weights.size() == 0) { //create them - weights.resize(node->get_polygon().size()); - PoolVector<float>::Write w = weights.write(); - for (int j = 0; j < wc; j++) { - w[j] = 0.0; + if (weights.size() == 0) { //create them + weights.resize(node->get_polygon().size()); + PoolVector<float>::Write w = weights.write(); + for (int j = 0; j < wc; j++) { + w[j] = 0.0; + } } - } - node->add_bone(path, weights); + node->add_bone(path, weights); + } } + Array new_bones = node->call("_get_bones"); - undo_redo->create_action(TTR("Sync bones")); + undo_redo->create_action(TTR("Sync Bones")); undo_redo->add_do_method(node, "_set_bones", new_bones); undo_redo->add_undo_method(node, "_set_bones", prev_bones); - undo_redo->add_do_method(uv_edit_draw, "update"); - undo_redo->add_undo_method(uv_edit_draw, "update"); undo_redo->add_do_method(this, "_update_bone_list"); undo_redo->add_undo_method(this, "_update_bone_list"); + undo_redo->add_do_method(uv_edit_draw, "update"); + undo_redo->add_undo_method(uv_edit_draw, "update"); undo_redo->commit_action(); } @@ -162,9 +170,10 @@ void Polygon2DEditor::_update_bone_list() { cb->set_text(name); cb->set_button_group(bg); cb->set_meta("bone_path", np); + cb->set_focus_mode(FOCUS_NONE); bone_scroll_vb->add_child(cb); - if (np == selected) + if (np == selected || bone_scroll_vb->get_child_count() < 2) cb->set_pressed(true); cb->connect("pressed", this, "_bone_paint_selected", varray(i)); @@ -180,6 +189,7 @@ void Polygon2DEditor::_bone_paint_selected(int p_index) { void Polygon2DEditor::_uv_edit_mode_select(int p_mode) { if (p_mode == 0) { //uv + uv_button[UV_MODE_CREATE]->hide(); for (int i = UV_MODE_MOVE; i <= UV_MODE_SCALE; i++) { uv_button[i]->show(); @@ -194,8 +204,8 @@ void Polygon2DEditor::_uv_edit_mode_select(int p_mode) { bone_paint_strength->hide(); bone_paint_radius->hide(); bone_paint_radius_label->hide(); - } else if (p_mode == 1) { //poly + for (int i = 0; i <= UV_MODE_SCALE; i++) { uv_button[i]->show(); } @@ -209,8 +219,8 @@ void Polygon2DEditor::_uv_edit_mode_select(int p_mode) { bone_paint_strength->hide(); bone_paint_radius->hide(); bone_paint_radius_label->hide(); - } else if (p_mode == 2) { //splits + for (int i = 0; i <= UV_MODE_SCALE; i++) { uv_button[i]->hide(); } @@ -224,8 +234,8 @@ void Polygon2DEditor::_uv_edit_mode_select(int p_mode) { bone_paint_strength->hide(); bone_paint_radius->hide(); bone_paint_radius_label->hide(); - } else if (p_mode == 3) { //bones´ + for (int i = 0; i <= UV_MODE_REMOVE_SPLIT; i++) { uv_button[i]->hide(); } @@ -241,9 +251,17 @@ void Polygon2DEditor::_uv_edit_mode_select(int p_mode) { bone_paint_pos = Vector2(-100000, -100000); //send brush away when switching } + uv_edit->set_size(uv_edit->get_size()); // Necessary readjustment of the popup window. uv_edit_draw->update(); } +void Polygon2DEditor::_uv_edit_popup_hide() { + + EditorSettings::get_singleton()->set("interface/dialogs/uv_editor_bounds", uv_edit->get_rect()); + + _cancel_editing(); +} + void Polygon2DEditor::_menu_option(int p_option) { switch (p_option) { @@ -252,7 +270,7 @@ void Polygon2DEditor::_menu_option(int p_option) { if (node->get_texture().is_null()) { - error->set_text("No texture in this polygon.\nSet a texture to be able to edit UV."); + error->set_text(TTR("No texture in this polygon.\nSet a texture to be able to edit UV.")); error->popup_centered_minsize(); return; } @@ -268,7 +286,10 @@ void Polygon2DEditor::_menu_option(int p_option) { undo_redo->commit_action(); } - uv_edit->popup_centered_ratio(0.85); + if (EditorSettings::get_singleton()->has_setting("interface/dialogs/uv_editor_bounds")) + uv_edit->popup(EditorSettings::get_singleton()->get("interface/dialogs/uv_editor_bounds")); + else + uv_edit->popup_centered_ratio(0.85); } break; case UVEDIT_POLYGON_TO_UV: { @@ -282,7 +303,6 @@ void Polygon2DEditor::_menu_option(int p_option) { undo_redo->add_do_method(uv_edit_draw, "update"); undo_redo->add_undo_method(uv_edit_draw, "update"); undo_redo->commit_action(); - } break; case UVEDIT_UV_TO_POLYGON: { @@ -291,13 +311,12 @@ void Polygon2DEditor::_menu_option(int p_option) { if (uvs.size() == 0) break; - undo_redo->create_action(TTR("Create UV Map")); + undo_redo->create_action(TTR("Create Polygon")); undo_redo->add_do_method(node, "set_polygon", uvs); undo_redo->add_undo_method(node, "set_polygon", points); undo_redo->add_do_method(uv_edit_draw, "update"); undo_redo->add_undo_method(uv_edit_draw, "update"); undo_redo->commit_action(); - } break; case UVEDIT_UV_CLEAR: { @@ -310,43 +329,81 @@ void Polygon2DEditor::_menu_option(int p_option) { undo_redo->add_do_method(uv_edit_draw, "update"); undo_redo->add_undo_method(uv_edit_draw, "update"); undo_redo->commit_action(); - } break; case UVEDIT_GRID_SETTINGS: { + grid_settings->popup_centered_minsize(); } break; default: { + AbstractPolygon2DEditor::_menu_option(p_option); } break; } } +void Polygon2DEditor::_cancel_editing() { + + if (uv_create) { + uv_drag = false; + uv_create = false; + node->set_uv(uv_create_uv_prev); + node->set_polygon(uv_create_poly_prev); + node->call("_set_bones", uv_create_bones_prev); + node->set_splits(splits_prev); + } else if (uv_drag) { + uv_drag = false; + if (uv_edit_mode[0]->is_pressed()) { // Edit UV. + node->set_uv(points_prev); + } else if (uv_edit_mode[1]->is_pressed()) { // Edit polygon. + node->set_polygon(points_prev); + } + } else if (split_create) { + split_create = false; + } +} + +void Polygon2DEditor::_commit_action() { + + // Makes that undo/redoing actions made outside of the UV editor still affects its polygon. + undo_redo->add_do_method(uv_edit_draw, "update"); + undo_redo->add_undo_method(uv_edit_draw, "update"); + undo_redo->add_do_method(CanvasItemEditor::get_singleton(), "update_viewport"); + undo_redo->add_undo_method(CanvasItemEditor::get_singleton(), "update_viewport"); + undo_redo->commit_action(); +} + void Polygon2DEditor::_set_use_snap(bool p_use) { use_snap = p_use; + EditorSettings::get_singleton()->set_project_metadata("polygon_2d_uv_editor", "snap_enabled", p_use); } void Polygon2DEditor::_set_show_grid(bool p_show) { snap_show_grid = p_show; + EditorSettings::get_singleton()->set_project_metadata("polygon_2d_uv_editor", "show_grid", p_show); uv_edit_draw->update(); } void Polygon2DEditor::_set_snap_off_x(float p_val) { snap_offset.x = p_val; + EditorSettings::get_singleton()->set_project_metadata("polygon_2d_uv_editor", "snap_offset", snap_offset); uv_edit_draw->update(); } void Polygon2DEditor::_set_snap_off_y(float p_val) { snap_offset.y = p_val; + EditorSettings::get_singleton()->set_project_metadata("polygon_2d_uv_editor", "snap_offset", snap_offset); uv_edit_draw->update(); } void Polygon2DEditor::_set_snap_step_x(float p_val) { snap_step.x = p_val; + EditorSettings::get_singleton()->set_project_metadata("polygon_2d_uv_editor", "snap_step", snap_step); uv_edit_draw->update(); } void Polygon2DEditor::_set_snap_step_y(float p_val) { snap_step.y = p_val; + EditorSettings::get_singleton()->set_project_metadata("polygon_2d_uv_editor", "snap_step", snap_step); uv_edit_draw->update(); } @@ -364,6 +421,9 @@ void Polygon2DEditor::_uv_mode(int p_mode) { void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { + if (!_get_node()) + return; + Transform2D mtx; mtx.elements[2] = -uv_draw_ofs; mtx.scale_basis(Vector2(uv_draw_zoom, uv_draw_zoom)); @@ -376,7 +436,7 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { if (mb->is_pressed()) { - uv_drag_from = Vector2(mb->get_position().x, mb->get_position().y); + uv_drag_from = snap_point(Vector2(mb->get_position().x, mb->get_position().y)); uv_drag = true; points_prev = node->get_uv(); @@ -390,8 +450,9 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { if (uv_move_current == UV_MODE_CREATE) { if (!uv_create) { + points_prev.resize(0); - Vector2 tuv = mtx.affine_inverse().xform(Vector2(mb->get_position().x, mb->get_position().y)); + Vector2 tuv = mtx.affine_inverse().xform(snap_point(Vector2(mb->get_position().x, mb->get_position().y))); points_prev.push_back(tuv); uv_create_to = tuv; point_drag_index = 0; @@ -405,23 +466,27 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { node->set_polygon(points_prev); node->set_uv(points_prev); + uv_edit_draw->update(); } else { - Vector2 tuv = mtx.affine_inverse().xform(Vector2(mb->get_position().x, mb->get_position().y)); - if (points_prev.size() > 3 && tuv.distance_to(points_prev[0]) < 8) { + Vector2 tuv = mtx.affine_inverse().xform(snap_point(Vector2(mb->get_position().x, mb->get_position().y))); + + if (points_prev.size() > 2 && tuv.distance_to(points_prev[0]) < 8) { undo_redo->create_action(TTR("Create Polygon & UV")); undo_redo->add_do_method(node, "set_uv", node->get_uv()); - undo_redo->add_undo_method(node, "set_uv", points_prev); + undo_redo->add_undo_method(node, "set_uv", uv_create_uv_prev); undo_redo->add_do_method(node, "set_polygon", node->get_polygon()); - undo_redo->add_undo_method(node, "set_polygon", points_prev); + undo_redo->add_undo_method(node, "set_polygon", uv_create_poly_prev); undo_redo->add_do_method(node, "clear_bones"); - undo_redo->add_undo_method(node, "_set_bones", node->call("_get_bones")); + undo_redo->add_undo_method(node, "_set_bones", uv_create_bones_prev); undo_redo->add_do_method(uv_edit_draw, "update"); undo_redo->add_undo_method(uv_edit_draw, "update"); undo_redo->commit_action(); uv_drag = false; uv_create = false; + _uv_mode(UV_MODE_EDIT_POINT); + _menu_option(MODE_EDIT); } else { points_prev.push_back(tuv); point_drag_index = points_prev.size() - 1; @@ -430,6 +495,8 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { node->set_polygon(points_prev); node->set_uv(points_prev); } + + CanvasItemEditor::get_singleton()->update_viewport(); } if (uv_move_current == UV_MODE_EDIT_POINT) { @@ -540,7 +607,6 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { splits_prev.push_back(split_to_index); undo_redo->create_action(TTR("Add Split")); - undo_redo->add_do_method(node, "set_splits", splits_prev); undo_redo->add_undo_method(node, "set_splits", node->get_splits()); undo_redo->add_do_method(uv_edit_draw, "update"); @@ -575,13 +641,11 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { splits_prev.remove(i); undo_redo->create_action(TTR("Remove Split")); - undo_redo->add_do_method(node, "set_splits", splits_prev); undo_redo->add_undo_method(node, "set_splits", node->get_splits()); undo_redo->add_do_method(uv_edit_draw, "update"); undo_redo->add_undo_method(uv_edit_draw, "update"); undo_redo->commit_action(); - break; } } @@ -608,12 +672,12 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { } else if (uv_drag && !uv_create) { - undo_redo->create_action(TTR("Transform UV Map")); - if (uv_edit_mode[0]->is_pressed()) { //edit uv + undo_redo->create_action(TTR("Transform UV Map")); undo_redo->add_do_method(node, "set_uv", node->get_uv()); undo_redo->add_undo_method(node, "set_uv", points_prev); } else if (uv_edit_mode[1]->is_pressed()) { //edit polygon + undo_redo->create_action(TTR("Transform Polygon")); undo_redo->add_do_method(node, "set_polygon", node->get_polygon()); undo_redo->add_undo_method(node, "set_polygon", points_prev); } @@ -624,7 +688,7 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { uv_drag = false; } else if (bone_painting) { - undo_redo->create_action(TTR("Paint bone weights")); + undo_redo->create_action(TTR("Paint Bone Weights")); undo_redo->add_do_method(node, "set_bone_weights", bone_painting_bone, node->get_bone_weights(bone_painting_bone)); undo_redo->add_undo_method(node, "set_bone_weights", bone_painting_bone, prev_weights); undo_redo->add_do_method(uv_edit_draw, "update"); @@ -635,30 +699,12 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { } else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) { - if (uv_create) { + _cancel_editing(); - uv_drag = false; - uv_create = false; - node->set_uv(uv_create_uv_prev); - node->set_polygon(uv_create_poly_prev); - node->call("_set_bones", uv_create_bones_prev); - node->set_splits(splits_prev); - uv_edit_draw->update(); - } else if (uv_drag) { - - uv_drag = false; - if (uv_edit_mode[0]->is_pressed()) { //edit uv - node->set_uv(points_prev); - } else if (uv_edit_mode[1]->is_pressed()) { //edit polygon - node->set_polygon(points_prev); - } - uv_edit_draw->update(); - } else if (split_create) { - split_create = false; - uv_edit_draw->update(); - } else if (bone_painting) { + if (bone_painting) node->set_bone_weights(bone_painting_bone, prev_weights); - } + + uv_edit_draw->update(); } else if (mb->get_button_index() == BUTTON_WHEEL_UP && mb->is_pressed()) { @@ -682,13 +728,15 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { } else if (uv_drag) { Vector2 uv_drag_to = mm->get_position(); + uv_drag_to = snap_point(uv_drag_to); // FIXME: Only works correctly with 'UV_MODE_EDIT_POINT', it's imprecise with the rest. Vector2 drag = mtx.affine_inverse().xform(uv_drag_to) - mtx.affine_inverse().xform(uv_drag_from); switch (uv_move_current) { case UV_MODE_CREATE: { + if (uv_create) { - uv_create_to = mtx.affine_inverse().xform(Vector2(mm->get_position().x, mm->get_position().y)); + uv_create_to = mtx.affine_inverse().xform(snap_point(Vector2(mm->get_position().x, mm->get_position().y))); } } break; case UV_MODE_EDIT_POINT: { @@ -713,7 +761,6 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { } else if (uv_edit_mode[1]->is_pressed()) { //edit polygon node->set_polygon(uv_new); } - } break; case UV_MODE_ROTATE: { @@ -737,7 +784,6 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { } else if (uv_edit_mode[1]->is_pressed()) { //edit polygon node->set_polygon(uv_new); } - } break; case UV_MODE_SCALE: { @@ -767,11 +813,15 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { node->set_polygon(uv_new); } } break; + case UV_MODE_PAINT_WEIGHT: + case UV_MODE_CLEAR_WEIGHT: { + + bone_paint_pos = Vector2(mm->get_position().x, mm->get_position().y); + } break; default: {} } if (bone_painting) { - bone_paint_pos = Vector2(mm->get_position().x, mm->get_position().y); PoolVector<float> painted_weights = node->get_bone_weights(bone_painting_bone); { @@ -796,7 +846,9 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { node->set_bone_weights(bone_painting_bone, painted_weights); } + uv_edit_draw->update(); + CanvasItemEditor::get_singleton()->update_viewport(); } else if (split_create) { uv_create_to = mtx.affine_inverse().xform(Vector2(mm->get_position().x, mm->get_position().y)); uv_edit_draw->update(); @@ -833,6 +885,9 @@ void Polygon2DEditor::_uv_scroll_changed(float) { void Polygon2DEditor::_uv_draw() { + if (!uv_edit->is_visible() || !_get_node()) + return; + Ref<Texture> base_tex = node->get_texture(); if (base_tex.is_null()) return; @@ -848,6 +903,7 @@ void Polygon2DEditor::_uv_draw() { VS::get_singleton()->canvas_item_add_set_transform(uv_edit_draw->get_canvas_item(), Transform2D()); if (snap_show_grid) { + Color grid_color = Color(1.0, 1.0, 1.0, 0.15); Size2 s = uv_edit_draw->get_size(); int last_cell = 0; @@ -857,7 +913,7 @@ void Polygon2DEditor::_uv_draw() { if (i == 0) last_cell = cell; if (last_cell != cell) - uv_edit_draw->draw_line(Point2(i, 0), Point2(i, s.height), Color(0.3, 0.7, 1, 0.3)); + uv_edit_draw->draw_line(Point2(i, 0), Point2(i, s.height), grid_color); last_cell = cell; } } @@ -868,7 +924,7 @@ void Polygon2DEditor::_uv_draw() { if (i == 0) last_cell = cell; if (last_cell != cell) - uv_edit_draw->draw_line(Point2(0, i), Point2(s.width, i), Color(0.3, 0.7, 1, 0.3)); + uv_edit_draw->draw_line(Point2(0, i), Point2(s.width, i), grid_color); last_cell = cell; } } @@ -901,19 +957,26 @@ void Polygon2DEditor::_uv_draw() { Ref<Texture> handle = get_icon("EditorHandle", "EditorIcons"); + Color poly_line_color = Color(0.9, 0.5, 0.5); + Color prev_color = Color(0.5, 0.5, 0.5); Rect2 rect(Point2(), mtx.basis_xform(base_tex->get_size())); rect.expand_to(mtx.basis_xform(uv_edit_draw->get_size())); for (int i = 0; i < uvs.size(); i++) { int next = (i + 1) % uvs.size(); + + if (uv_drag && uv_move_current == UV_MODE_EDIT_POINT && EDITOR_DEF("editors/poly_editor/show_previous_outline", true)) { + uv_edit_draw->draw_line(mtx.xform(points_prev[i]), mtx.xform(points_prev[next]), prev_color, 2 * EDSCALE); + } + Vector2 next_point = uvs[next]; if (uv_create && i == uvs.size() - 1) { next_point = uv_create_to; } - uv_edit_draw->draw_line(mtx.xform(uvs[i]), mtx.xform(next_point), Color(0.9, 0.5, 0.5), 2); - if (weight_r.ptr()) { + uv_edit_draw->draw_line(mtx.xform(uvs[i]), mtx.xform(next_point), poly_line_color, 2 * EDSCALE); + if (weight_r.ptr()) { Vector2 draw_pos = mtx.xform(uvs[i]); float weight = weight_r[i]; uv_edit_draw->draw_rect(Rect2(draw_pos - Vector2(2, 2) * EDSCALE, Vector2(5, 5) * EDSCALE), Color(weight, weight, weight, 1.0)); @@ -926,7 +989,7 @@ void Polygon2DEditor::_uv_draw() { if (split_create) { Vector2 from = uvs[point_drag_index]; Vector2 to = uv_create_to; - uv_edit_draw->draw_line(mtx.xform(from), mtx.xform(to), Color(0.9, 0.5, 0.5), 2); + uv_edit_draw->draw_line(mtx.xform(from), mtx.xform(to), poly_line_color, 2); } PoolVector<int> splits = node->get_splits(); @@ -936,7 +999,7 @@ void Polygon2DEditor::_uv_draw() { int idx_to = splits[i + 1]; if (idx_from < 0 || idx_to >= uvs.size()) continue; - uv_edit_draw->draw_line(mtx.xform(uvs[idx_from]), mtx.xform(uvs[idx_to]), Color(0.9, 0.5, 0.5), 2); + uv_edit_draw->draw_line(mtx.xform(uvs[idx_from]), mtx.xform(uvs[idx_to]), poly_line_color, 2); } if (uv_mode == UV_MODE_PAINT_WEIGHT || uv_mode == UV_MODE_CLEAR_WEIGHT) { @@ -963,22 +1026,32 @@ void Polygon2DEditor::_uv_draw() { bool current = bone_path == skeleton->get_path_to(bone); + bool found_child = false; + for (int j = 0; j < bone->get_child_count(); j++) { - Node2D *n = Object::cast_to<Node2D>(bone->get_child(j)); + Bone2D *n = Object::cast_to<Bone2D>(bone->get_child(j)); if (!n) continue; - bool edit_bone = n->has_meta("_edit_bone_") && n->get_meta("_edit_bone_"); - if (edit_bone) { + found_child = true; - Transform2D bone_xform = node->get_global_transform().affine_inverse() * (skeleton->get_global_transform() * bone->get_skeleton_rest()); - Transform2D endpoint_xform = bone_xform * n->get_transform(); + Transform2D bone_xform = node->get_global_transform().affine_inverse() * (skeleton->get_global_transform() * bone->get_skeleton_rest()); + Transform2D endpoint_xform = bone_xform * n->get_transform(); - Color color = current ? Color(1, 1, 1) : Color(0.5, 0.5, 0.5); - uv_edit_draw->draw_line(mtx.xform(bone_xform.get_origin()), mtx.xform(endpoint_xform.get_origin()), Color(0, 0, 0), current ? 5 : 4); - uv_edit_draw->draw_line(mtx.xform(bone_xform.get_origin()), mtx.xform(endpoint_xform.get_origin()), color, current ? 3 : 2); - } + Color color = current ? Color(1, 1, 1) : Color(0.5, 0.5, 0.5); + uv_edit_draw->draw_line(mtx.xform(bone_xform.get_origin()), mtx.xform(endpoint_xform.get_origin()), Color(0, 0, 0), current ? 5 : 4); + uv_edit_draw->draw_line(mtx.xform(bone_xform.get_origin()), mtx.xform(endpoint_xform.get_origin()), color, current ? 3 : 2); + } + + if (!found_child) { + //draw normally + Transform2D bone_xform = node->get_global_transform().affine_inverse() * (skeleton->get_global_transform() * bone->get_skeleton_rest()); + Transform2D endpoint_xform = bone_xform * Transform2D(0, Vector2(bone->get_default_length(), 0)); + + Color color = current ? Color(1, 1, 1) : Color(0.5, 0.5, 0.5); + uv_edit_draw->draw_line(mtx.xform(bone_xform.get_origin()), mtx.xform(endpoint_xform.get_origin()), Color(0, 0, 0), current ? 5 : 4); + uv_edit_draw->draw_line(mtx.xform(bone_xform.get_origin()), mtx.xform(endpoint_xform.get_origin()), color, current ? 3 : 2); } } } @@ -992,15 +1065,23 @@ void Polygon2DEditor::_uv_draw() { updating_uv_scroll = true; uv_hscroll->set_min(rect.position.x); uv_hscroll->set_max(rect.position.x + rect.size.x); - uv_hscroll->set_page(uv_edit_draw->get_size().x); - uv_hscroll->set_value(uv_draw_ofs.x); - uv_hscroll->set_step(0.001); + if (ABS(rect.position.x - (rect.position.x + rect.size.x)) <= uv_edit_draw->get_size().x) { + uv_hscroll->hide(); + } else { + uv_hscroll->show(); + uv_hscroll->set_page(uv_edit_draw->get_size().x); + uv_hscroll->set_value(uv_draw_ofs.x); + } uv_vscroll->set_min(rect.position.y); uv_vscroll->set_max(rect.position.y + rect.size.y); - uv_vscroll->set_page(uv_edit_draw->get_size().y); - uv_vscroll->set_value(uv_draw_ofs.y); - uv_vscroll->set_step(0.001); + if (ABS(rect.position.y - (rect.position.y + rect.size.y)) <= uv_edit_draw->get_size().y) { + uv_vscroll->hide(); + } else { + uv_vscroll->show(); + uv_vscroll->set_page(uv_edit_draw->get_size().y); + uv_vscroll->set_value(uv_draw_ofs.y); + } updating_uv_scroll = false; } @@ -1017,9 +1098,9 @@ void Polygon2DEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("_set_snap_step_x"), &Polygon2DEditor::_set_snap_step_x); ClassDB::bind_method(D_METHOD("_set_snap_step_y"), &Polygon2DEditor::_set_snap_step_y); ClassDB::bind_method(D_METHOD("_uv_edit_mode_select"), &Polygon2DEditor::_uv_edit_mode_select); + ClassDB::bind_method(D_METHOD("_uv_edit_popup_hide"), &Polygon2DEditor::_uv_edit_popup_hide); ClassDB::bind_method(D_METHOD("_sync_bones"), &Polygon2DEditor::_sync_bones); ClassDB::bind_method(D_METHOD("_update_bone_list"), &Polygon2DEditor::_update_bone_list); - ClassDB::bind_method(D_METHOD("_bone_paint_selected"), &Polygon2DEditor::_bone_paint_selected); } @@ -1036,23 +1117,25 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) : AbstractPolygon2DEditor(p_editor) { node = NULL; - snap_step = Vector2(10, 10); - use_snap = false; - snap_show_grid = false; + snap_offset = EditorSettings::get_singleton()->get_project_metadata("polygon_2d_uv_editor", "snap_offset", Vector2()); + snap_step = EditorSettings::get_singleton()->get_project_metadata("polygon_2d_uv_editor", "snap_step", Vector2(10, 10)); + use_snap = EditorSettings::get_singleton()->get_project_metadata("polygon_2d_uv_editor", "snap_enabled", false); + snap_show_grid = EditorSettings::get_singleton()->get_project_metadata("polygon_2d_uv_editor", "show_grid", false); button_uv = memnew(ToolButton); add_child(button_uv); + button_uv->set_tooltip(TTR("Open Polygon 2D UV editor.")); button_uv->connect("pressed", this, "_menu_option", varray(MODE_EDIT_UV)); uv_mode = UV_MODE_EDIT_POINT; uv_edit = memnew(AcceptDialog); add_child(uv_edit); uv_edit->set_title(TTR("Polygon 2D UV Editor")); - uv_edit->set_self_modulate(Color(1, 1, 1, 0.9)); + uv_edit->set_resizable(true); + uv_edit->connect("popup_hide", this, "_uv_edit_popup_hide"); VBoxContainer *uv_main_vb = memnew(VBoxContainer); uv_edit->add_child(uv_main_vb); - //uv_edit->set_child_rect(uv_main_vb); HBoxContainer *uv_mode_hb = memnew(HBoxContainer); uv_edit_group.instance(); @@ -1099,14 +1182,14 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) : } uv_button[0]->set_tooltip(TTR("Create Polygon")); - uv_button[1]->set_tooltip(TTR("Move Point") + "\n" + TTR("Ctrl: Rotate") + "\n" + TTR("Shift: Move All") + "\n" + TTR("Shift+Ctrl: Scale")); + uv_button[1]->set_tooltip(TTR("Move Points") + "\n" + TTR("Ctrl: Rotate") + "\n" + TTR("Shift: Move All") + "\n" + TTR("Shift+Ctrl: Scale")); uv_button[2]->set_tooltip(TTR("Move Polygon")); uv_button[3]->set_tooltip(TTR("Rotate Polygon")); uv_button[4]->set_tooltip(TTR("Scale Polygon")); - uv_button[5]->set_tooltip(TTR("Connect two points to make a split")); - uv_button[6]->set_tooltip(TTR("Select a split to erase it")); - uv_button[7]->set_tooltip(TTR("Paint weights with specified intensity")); - uv_button[8]->set_tooltip(TTR("UnPaint weights with specified intensity")); + uv_button[5]->set_tooltip(TTR("Connect two points to make a split.")); + uv_button[6]->set_tooltip(TTR("Select a split to erase it.")); + uv_button[7]->set_tooltip(TTR("Paint weights with specified intensity.")); + uv_button[8]->set_tooltip(TTR("Unpaint weights with specified intensity.")); uv_button[0]->hide(); uv_button[5]->hide(); @@ -1124,7 +1207,7 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) : bone_paint_strength->set_step(0.01); bone_paint_strength->set_value(0.5); - bone_paint_radius_label = memnew(Label(" " + TTR("Radius:") + " ")); + bone_paint_radius_label = memnew(Label(TTR("Radius:"))); uv_mode_hb->add_child(bone_paint_radius_label); bone_paint_radius = memnew(SpinBox); uv_mode_hb->add_child(bone_paint_radius); @@ -1137,12 +1220,13 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) : bone_paint_radius->set_step(1); bone_paint_radius->set_value(32); - HBoxContainer *uv_main_hb = memnew(HBoxContainer); - uv_main_vb->add_child(uv_main_hb); - uv_edit_draw = memnew(Control); - uv_main_hb->add_child(uv_edit_draw); - uv_main_hb->set_v_size_flags(SIZE_EXPAND_FILL); + HSplitContainer *uv_main_hsc = memnew(HSplitContainer); + uv_main_vb->add_child(uv_main_hsc); + uv_main_hsc->set_v_size_flags(SIZE_EXPAND_FILL); + uv_edit_draw = memnew(Panel); + uv_main_hsc->add_child(uv_edit_draw); uv_edit_draw->set_h_size_flags(SIZE_EXPAND_FILL); + uv_edit_draw->set_custom_minimum_size(Size2(200, 200) * EDSCALE); uv_menu = memnew(MenuButton); uv_mode_hb->add_child(uv_menu); uv_menu->set_text(TTR("Edit")); @@ -1218,6 +1302,7 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) : uv_mode_hb->add_child(memnew(VSeparator)); uv_icon_zoom = memnew(TextureRect); + uv_icon_zoom->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED); uv_mode_hb->add_child(uv_icon_zoom); uv_zoom = memnew(HSlider); uv_zoom->set_min(0.01); @@ -1235,17 +1320,25 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) : uv_zoom->connect("value_changed", this, "_uv_scroll_changed"); uv_vscroll = memnew(VScrollBar); - uv_main_hb->add_child(uv_vscroll); + uv_vscroll->set_step(0.001); + uv_edit_draw->add_child(uv_vscroll); + uv_vscroll->set_anchors_and_margins_preset(PRESET_RIGHT_WIDE); uv_vscroll->connect("value_changed", this, "_uv_scroll_changed"); uv_hscroll = memnew(HScrollBar); - uv_main_vb->add_child(uv_hscroll); + uv_hscroll->set_step(0.001); + uv_edit_draw->add_child(uv_hscroll); + uv_hscroll->set_anchors_and_margins_preset(PRESET_BOTTOM_WIDE); + uv_hscroll->set_margin(MARGIN_RIGHT, -uv_vscroll->get_size().x * EDSCALE); uv_hscroll->connect("value_changed", this, "_uv_scroll_changed"); 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); - uv_main_hb->add_child(bone_scroll_main_vb); + sync_bones->set_h_size_flags(0); + sync_bones->connect("pressed", this, "_sync_bones"); + uv_main_hsc->add_child(bone_scroll_main_vb); bone_scroll = memnew(ScrollContainer); bone_scroll->set_v_scroll(true); bone_scroll->set_h_scroll(false); @@ -1253,7 +1346,6 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) : bone_scroll->set_v_size_flags(SIZE_EXPAND_FILL); bone_scroll_vb = memnew(VBoxContainer); bone_scroll->add_child(bone_scroll_vb); - sync_bones->connect("pressed", this, "_sync_bones"); uv_edit_draw->connect("draw", this, "_uv_draw"); uv_edit_draw->connect("gui_input", this, "_uv_input"); diff --git a/editor/plugins/polygon_2d_editor_plugin.h b/editor/plugins/polygon_2d_editor_plugin.h index f9b42a21c2..935f1cfff0 100644 --- a/editor/plugins/polygon_2d_editor_plugin.h +++ b/editor/plugins/polygon_2d_editor_plugin.h @@ -41,13 +41,11 @@ class Polygon2DEditor : public AbstractPolygon2DEditor { GDCLASS(Polygon2DEditor, AbstractPolygon2DEditor); enum Mode { - MODE_EDIT_UV = MODE_CONT, UVEDIT_POLYGON_TO_UV, UVEDIT_UV_TO_POLYGON, UVEDIT_UV_CLEAR, UVEDIT_GRID_SETTINGS - }; enum UVMode { @@ -73,7 +71,7 @@ class Polygon2DEditor : public AbstractPolygon2DEditor { ToolButton *uv_button[UV_MODE_MAX]; ToolButton *b_snap_enable; ToolButton *b_snap_grid; - Control *uv_edit_draw; + Panel *uv_edit_draw; HSlider *uv_zoom; SpinBox *uv_zoom_value; HScrollBar *uv_hscroll; @@ -125,6 +123,8 @@ class Polygon2DEditor : public AbstractPolygon2DEditor { virtual void _menu_option(int p_option); + void _cancel_editing(); + void _uv_scroll_changed(float); void _uv_input(const Ref<InputEvent> &p_input); void _uv_draw(); @@ -138,6 +138,7 @@ class Polygon2DEditor : public AbstractPolygon2DEditor { void _set_snap_step_y(float p_val); void _uv_edit_mode_select(int p_mode); + void _uv_edit_popup_hide(); void _bone_paint_selected(int p_index); protected: @@ -146,6 +147,9 @@ protected: virtual Vector2 _get_offset(int p_idx) const; + virtual bool _has_uv() const { return true; }; + virtual void _commit_action(); + void _notification(int p_what); static void _bind_methods(); diff --git a/editor/plugins/resource_preloader_editor_plugin.cpp b/editor/plugins/resource_preloader_editor_plugin.cpp index dd327d0a2c..bd4a35c9d8 100644 --- a/editor/plugins/resource_preloader_editor_plugin.cpp +++ b/editor/plugins/resource_preloader_editor_plugin.cpp @@ -44,7 +44,6 @@ void ResourcePreloaderEditor::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { load->set_icon(get_icon("Folder", "EditorIcons")); - _delete->set_icon(get_icon("Remove", "EditorIcons")); } if (p_what == NOTIFICATION_READY) { @@ -138,15 +137,11 @@ void ResourcePreloaderEditor::_item_edited() { } } -void ResourcePreloaderEditor::_delete_confirm_pressed() { +void ResourcePreloaderEditor::_remove_resource(const String &p_to_remove) { - if (!tree->get_selected()) - return; - - String to_remove = tree->get_selected()->get_text(0); undo_redo->create_action(TTR("Delete Resource")); - undo_redo->add_do_method(preloader, "remove_resource", to_remove); - undo_redo->add_undo_method(preloader, "add_resource", to_remove, preloader->get_resource(to_remove)); + undo_redo->add_do_method(preloader, "remove_resource", p_to_remove); + undo_redo->add_undo_method(preloader, "add_resource", p_to_remove, preloader->get_resource(p_to_remove)); undo_redo->add_do_method(this, "_update_library"); undo_redo->add_undo_method(this, "_update_library"); undo_redo->commit_action(); @@ -184,21 +179,6 @@ void ResourcePreloaderEditor::_paste_pressed() { undo_redo->commit_action(); } -void ResourcePreloaderEditor::_delete_pressed() { - - if (!tree->get_selected()) - return; - - _delete_confirm_pressed(); //it has undo.. why bother with a dialog.. - /* - dialog->set_title("Confirm..."); - dialog->set_text("Remove Resource '"+tree->get_selected()->get_text(0)+"' ?"); - //dialog->get_cancel()->set_text("Cancel"); - //dialog->get_ok()->show(); - dialog->get_ok()->set_text("Remove"); - dialog->popup_centered(Size2(300,60));*/ -} - void ResourcePreloaderEditor::_update_library() { tree->clear(); @@ -228,17 +208,20 @@ void ResourcePreloaderEditor::_update_library() { ERR_CONTINUE(r.is_null()); - ti->set_tooltip(0, r->get_path()); + String type = r->get_class(); + ti->set_icon(0, EditorNode::get_singleton()->get_class_icon(type, "Object")); + ti->set_tooltip(0, TTR("Instance:") + " " + r->get_path() + "\n" + TTR("Type:") + " " + type); + ti->set_text(1, r->get_path()); - ti->add_button(1, get_icon("InstanceOptions", "EditorIcons"), BUTTON_SUBSCENE, false, TTR("Open in Editor")); - ti->set_tooltip(1, TTR("Instance:") + " " + r->get_path() + "\n" + TTR("Type:") + " " + r->get_class()); ti->set_editable(1, false); ti->set_selectable(1, false); - String type = r->get_class(); - ti->set_text(2, type); - ti->set_selectable(2, false); - ti->set_icon(2, EditorNode::get_singleton()->get_class_icon(type, "")); + if (type == "PackedScene") { + ti->add_button(1, get_icon("InstanceOptions", "EditorIcons"), BUTTON_OPEN_SCENE, false, TTR("Open in Editor")); + } else { + ti->add_button(1, get_icon("Load", "EditorIcons"), BUTTON_EDIT_RESOURCE, false, TTR("Open in Editor")); + } + ti->add_button(1, get_icon("Remove", "EditorIcons"), BUTTON_REMOVE, false, TTR("Remove")); } //player->add_resource("default",resource); @@ -249,10 +232,16 @@ void ResourcePreloaderEditor::_cell_button_pressed(Object *p_item, int p_column, TreeItem *item = Object::cast_to<TreeItem>(p_item); ERR_FAIL_COND(!item); - String rpath = item->get_text(p_column); - - if (p_id == BUTTON_SUBSCENE) { + if (p_id == BUTTON_OPEN_SCENE) { + String rpath = item->get_text(p_column); EditorInterface::get_singleton()->open_scene_from_path(rpath); + + } else if (p_id == BUTTON_EDIT_RESOURCE) { + RES r = preloader->get_resource(item->get_text(0)); + EditorInterface::get_singleton()->edit_resource(r); + + } else if (p_id == BUTTON_REMOVE) { + _remove_resource(item->get_text(0)); } } @@ -365,12 +354,11 @@ void ResourcePreloaderEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("_gui_input"), &ResourcePreloaderEditor::_gui_input); ClassDB::bind_method(D_METHOD("_load_pressed"), &ResourcePreloaderEditor::_load_pressed); ClassDB::bind_method(D_METHOD("_item_edited"), &ResourcePreloaderEditor::_item_edited); - ClassDB::bind_method(D_METHOD("_delete_pressed"), &ResourcePreloaderEditor::_delete_pressed); ClassDB::bind_method(D_METHOD("_paste_pressed"), &ResourcePreloaderEditor::_paste_pressed); - ClassDB::bind_method(D_METHOD("_delete_confirm_pressed"), &ResourcePreloaderEditor::_delete_confirm_pressed); ClassDB::bind_method(D_METHOD("_files_load_request"), &ResourcePreloaderEditor::_files_load_request); ClassDB::bind_method(D_METHOD("_update_library"), &ResourcePreloaderEditor::_update_library); ClassDB::bind_method(D_METHOD("_cell_button_pressed"), &ResourcePreloaderEditor::_cell_button_pressed); + ClassDB::bind_method(D_METHOD("_remove_resource", "to_remove"), &ResourcePreloaderEditor::_remove_resource); ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &ResourcePreloaderEditor::get_drag_data_fw); ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &ResourcePreloaderEditor::can_drop_data_fw); @@ -391,9 +379,6 @@ ResourcePreloaderEditor::ResourcePreloaderEditor() { load->set_tooltip(TTR("Load Resource")); hbc->add_child(load); - _delete = memnew(Button); - hbc->add_child(_delete); - paste = memnew(Button); paste->set_text(TTR("Paste")); hbc->add_child(paste); @@ -403,13 +388,11 @@ ResourcePreloaderEditor::ResourcePreloaderEditor() { tree = memnew(Tree); tree->connect("button_pressed", this, "_cell_button_pressed"); - tree->set_columns(3); - tree->set_column_min_width(0, 3); - tree->set_column_min_width(1, 1); - tree->set_column_min_width(2, 1); + tree->set_columns(2); + tree->set_column_min_width(0, 2); + tree->set_column_min_width(1, 3); tree->set_column_expand(0, true); tree->set_column_expand(1, true); - tree->set_column_expand(2, true); tree->set_v_size_flags(SIZE_EXPAND_FILL); tree->set_drag_forwarding(this); @@ -419,10 +402,8 @@ ResourcePreloaderEditor::ResourcePreloaderEditor() { add_child(dialog); load->connect("pressed", this, "_load_pressed"); - _delete->connect("pressed", this, "_delete_pressed"); paste->connect("pressed", this, "_paste_pressed"); file->connect("files_selected", this, "_files_load_request"); - //dialog->connect("confirmed", this,"_delete_confirm_pressed"); tree->connect("item_edited", this, "_item_edited"); loading_scene = false; } diff --git a/editor/plugins/resource_preloader_editor_plugin.h b/editor/plugins/resource_preloader_editor_plugin.h index e737157785..0a8238ce18 100644 --- a/editor/plugins/resource_preloader_editor_plugin.h +++ b/editor/plugins/resource_preloader_editor_plugin.h @@ -43,11 +43,12 @@ class ResourcePreloaderEditor : public PanelContainer { GDCLASS(ResourcePreloaderEditor, PanelContainer); enum { - BUTTON_SUBSCENE = 0, + BUTTON_OPEN_SCENE, + BUTTON_EDIT_RESOURCE, + BUTTON_REMOVE }; Button *load; - Button *_delete; Button *paste; Tree *tree; bool loading_scene; @@ -62,8 +63,7 @@ class ResourcePreloaderEditor : public PanelContainer { void _load_scene_pressed(); void _files_load_request(const Vector<String> &p_paths); void _paste_pressed(); - void _delete_pressed(); - void _delete_confirm_pressed(); + void _remove_resource(const String &p_to_remove); void _update_library(); void _cell_button_pressed(Object *p_item, int p_column, int p_id); void _item_edited(); diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 7cda15bdc6..44f1625d06 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -40,6 +40,7 @@ #include "editor/editor_settings.h" #include "editor/find_in_files.h" #include "editor/node_dock.h" +#include "editor/plugins/shader_editor_plugin.h" #include "editor/script_editor_debugger.h" #include "scene/main/viewport.h" #include "script_text_editor.h" @@ -50,8 +51,7 @@ void ScriptEditorBase::_bind_methods() { ADD_SIGNAL(MethodInfo("name_changed")); ADD_SIGNAL(MethodInfo("edited_script_changed")); - ADD_SIGNAL(MethodInfo("request_help_search", PropertyInfo(Variant::STRING, "topic"))); - ADD_SIGNAL(MethodInfo("request_help_index")); + ADD_SIGNAL(MethodInfo("request_help", PropertyInfo(Variant::STRING, "topic"))); ADD_SIGNAL(MethodInfo("request_open_script_at_line", PropertyInfo(Variant::OBJECT, "script"), PropertyInfo(Variant::INT, "line"))); ADD_SIGNAL(MethodInfo("request_save_history")); ADD_SIGNAL(MethodInfo("go_to_help", PropertyInfo(Variant::STRING, "what"))); @@ -210,6 +210,9 @@ void ScriptEditorQuickOpen::_notification(int p_what) { search_box->set_right_icon(get_icon("Search", "EditorIcons")); search_box->set_clear_button_enabled(true); } break; + case NOTIFICATION_EXIT_TREE: { + disconnect("confirmed", this, "_confirmed"); + } break; } } @@ -490,7 +493,7 @@ void ScriptEditor::_open_recent_script(int p_idx) { edit(text_file, true); return; } - // if it's a path then its most likely a deleted file not help + // if it's a path then it's most likely a deleted file not help } else if (path.find("::") != -1) { // built-in script Ref<Script> script = ResourceLoader::load(path); @@ -894,12 +897,12 @@ void ScriptEditor::_file_dialog_action(String p_file) { } break; case THEME_SAVE_AS: { if (!EditorSettings::get_singleton()->save_text_editor_theme_as(p_file)) { - editor->show_warning(TTR("Error while saving theme"), TTR("Error saving")); + editor->show_warning(TTR("Error while saving theme."), TTR("Error Saving")); } } break; case THEME_IMPORT: { if (!EditorSettings::get_singleton()->import_text_editor_theme(p_file)) { - editor->show_warning(TTR("Error importing theme"), TTR("Error importing")); + editor->show_warning(TTR("Error importing theme."), TTR("Error Importing")); } } break; } @@ -972,13 +975,9 @@ void ScriptEditor::_menu_option(int p_option) { help_search_dialog->popup_dialog(); } break; - case SEARCH_CLASSES: { - - help_index->popup_dialog(); - } break; case SEARCH_WEBSITE: { - OS::get_singleton()->shell_open("http://docs.godotengine.org/"); + OS::get_singleton()->shell_open("https://docs.godotengine.org/"); } break; case WINDOW_NEXT: { @@ -1091,7 +1090,7 @@ void ScriptEditor::_menu_option(int p_option) { Ref<Script> scr = current->get_edited_resource(); if (scr == NULL || scr.is_null()) { - EditorNode::get_singleton()->show_warning("Can't obtain the script for running"); + EditorNode::get_singleton()->show_warning("Can't obtain the script for running."); break; } @@ -1104,13 +1103,13 @@ void ScriptEditor::_menu_option(int p_option) { } if (!scr->is_tool()) { - EditorNode::get_singleton()->show_warning("Script is not in tool mode, will not be able to run"); + EditorNode::get_singleton()->show_warning("Script is not in tool mode, will not be able to run."); return; } if (!ClassDB::is_parent_class(scr->get_instance_base_type(), "EditorScript")) { - EditorNode::get_singleton()->show_warning("To run this script, it must inherit EditorScript and be set to tool mode"); + EditorNode::get_singleton()->show_warning("To run this script, it must inherit EditorScript and be set to tool mode."); return; } @@ -1203,12 +1202,6 @@ void ScriptEditor::_menu_option(int p_option) { if (help) { switch (p_option) { - - case SEARCH_CLASSES: { - - help_index->popup_dialog(); - help_index->call_deferred("select_class", help->get_class()); - } break; case HELP_SEARCH_FIND: { help->popup_search(); } break; @@ -1315,7 +1308,6 @@ void ScriptEditor::_notification(int p_what) { EditorSettings::get_singleton()->connect("settings_changed", this, "_editor_settings_changed"); help_search->set_icon(get_icon("HelpSearch", "EditorIcons")); site_search->set_icon(get_icon("Instance", "EditorIcons")); - class_search->set_icon(get_icon("ClassList", "EditorIcons")); script_forward->set_icon(get_icon("Forward", "EditorIcons")); script_back->set_icon(get_icon("Back", "EditorIcons")); @@ -1327,7 +1319,6 @@ void ScriptEditor::_notification(int p_what) { get_tree()->connect("tree_changed", this, "_tree_changed"); editor->get_inspector_dock()->connect("request_help", this, "_request_help"); editor->connect("request_help_search", this, "_help_search"); - editor->connect("request_help_index", this, "_help_index"); } break; case NOTIFICATION_EXIT_TREE: { @@ -1347,7 +1338,6 @@ void ScriptEditor::_notification(int p_what) { help_search->set_icon(get_icon("HelpSearch", "EditorIcons")); site_search->set_icon(get_icon("Instance", "EditorIcons")); - class_search->set_icon(get_icon("ClassList", "EditorIcons")); script_forward->set_icon(get_icon("Forward", "EditorIcons")); script_back->set_icon(get_icon("Back", "EditorIcons")); @@ -1363,7 +1353,9 @@ void ScriptEditor::_notification(int p_what) { if (is_visible()) { find_in_files_button->show(); } else { - find_in_files->hide(); + if (find_in_files->is_visible_in_tree()) { + editor->hide_bottom_panel(); + } find_in_files_button->hide(); } @@ -1824,6 +1816,10 @@ Ref<TextFile> ScriptEditor::_load_text_file(const String &p_path, Error *r_error text_file->set_file_path(local_path); text_file->set_path(local_path, true); + if (ResourceLoader::get_timestamp_on_load()) { + text_file->set_last_modified_time(FileAccess::get_modified_time(path)); + } + if (r_error) { *r_error = OK; } @@ -1853,6 +1849,10 @@ Error ScriptEditor::_save_text_file(Ref<TextFile> p_text_file, const String &p_p file->close(); memdelete(file); + if (ResourceSaver::get_timestamp_on_save()) { + p_text_file->set_last_modified_time(FileAccess::get_modified_time(p_path)); + } + _res_saved_callback(sqscr); return OK; } @@ -1960,7 +1960,7 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra // doesn't have it, make a new one - ScriptEditorBase *se; + ScriptEditorBase *se = NULL; for (int i = script_editor_func_count - 1; i >= 0; i--) { se = script_editor_funcs[i](p_resource); @@ -2001,7 +2001,7 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra _save_layout(); se->connect("name_changed", this, "_update_script_names"); se->connect("edited_script_changed", this, "_script_changed"); - se->connect("request_help_search", this, "_help_search"); + se->connect("request_help", this, "_help_search"); se->connect("request_open_script_at_line", this, "_goto_script_line"); se->connect("go_to_help", this, "_help_class_goto"); se->connect("request_save_history", this, "_save_history"); @@ -2728,10 +2728,6 @@ void ScriptEditor::set_live_auto_reload_running_scripts(bool p_enabled) { auto_reload_running_scripts = p_enabled; } -void ScriptEditor::_help_index(String p_text) { - help_index->popup_dialog(); -} - void ScriptEditor::_help_search(String p_text) { help_search_dialog->popup_dialog(p_text); } @@ -2783,13 +2779,18 @@ void ScriptEditor::_on_find_in_files_requested(String text) { void ScriptEditor::_on_find_in_files_result_selected(String fpath, int line_number, int begin, int end) { RES res = ResourceLoader::load(fpath); - edit(res); - - ScriptEditorBase *seb = _get_current_editor(); + if (fpath.get_extension() == "shader") { + ShaderEditorPlugin *shader_editor = Object::cast_to<ShaderEditorPlugin>(EditorNode::get_singleton()->get_editor_data().get_editor("Shader")); + shader_editor->edit(res.ptr()); + shader_editor->make_visible(true); + shader_editor->get_shader_editor()->goto_line_selection(line_number - 1, begin, end); + } else { + edit(res); - ScriptTextEditor *ste = Object::cast_to<ScriptTextEditor>(seb); - if (ste) { - ste->goto_line_selection(line_number - 1, begin, end); + ScriptTextEditor *ste = Object::cast_to<ScriptTextEditor>(_get_current_editor()); + if (ste) { + ste->goto_line_selection(line_number - 1, begin, end); + } } } @@ -2806,8 +2807,7 @@ void ScriptEditor::_start_find_in_files(bool with_replace) { find_in_files->set_with_replace(with_replace); find_in_files->start_search(); - find_in_files_button->set_pressed(true); - find_in_files->show(); + editor->make_bottom_panel_item_visible(find_in_files); } void ScriptEditor::_on_find_in_files_modified_files(PoolStringArray paths) { @@ -2838,7 +2838,6 @@ void ScriptEditor::_bind_methods() { ClassDB::bind_method("_goto_script_line", &ScriptEditor::_goto_script_line); ClassDB::bind_method("_goto_script_line2", &ScriptEditor::_goto_script_line2); ClassDB::bind_method("_help_search", &ScriptEditor::_help_search); - ClassDB::bind_method("_help_index", &ScriptEditor::_help_index); ClassDB::bind_method("_save_history", &ScriptEditor::_save_history); ClassDB::bind_method("_copy_script_path", &ScriptEditor::_copy_script_path); @@ -2891,7 +2890,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { restoring_layout = false; waiting_update_names = false; pending_auto_reload = false; - auto_reload_running_scripts = false; + auto_reload_running_scripts = true; members_overview_enabled = EditorSettings::get_singleton()->get("text_editor/open_scripts/show_members_overview"); help_overview_enabled = EditorSettings::get_singleton()->get("text_editor/help/show_help_index"); editor = p_editor; @@ -2912,7 +2911,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { script_list = memnew(ItemList); list_split->add_child(script_list); - script_list->set_custom_minimum_size(Size2(150 * EDSCALE, 90)); //need to give a bit of limit to avoid it from disappearing + script_list->set_custom_minimum_size(Size2(150, 90) * EDSCALE); //need to give a bit of limit to avoid it from disappearing script_list->set_v_size_flags(SIZE_EXPAND_FILL); script_split->set_split_offset(140); _sort_list_on_update = true; @@ -2951,7 +2950,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { overview_vbox->add_child(members_overview); members_overview->set_allow_reselect(true); - members_overview->set_custom_minimum_size(Size2(0, 90)); //need to give a bit of limit to avoid it from disappearing + members_overview->set_custom_minimum_size(Size2(0, 90) * EDSCALE); //need to give a bit of limit to avoid it from disappearing members_overview->set_v_size_flags(SIZE_EXPAND_FILL); members_overview->set_allow_rmb_select(true); members_overview->set_drag_forwarding(this); @@ -2959,12 +2958,12 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { help_overview = memnew(ItemList); overview_vbox->add_child(help_overview); help_overview->set_allow_reselect(true); - help_overview->set_custom_minimum_size(Size2(0, 90)); //need to give a bit of limit to avoid it from disappearing + help_overview->set_custom_minimum_size(Size2(0, 90) * EDSCALE); //need to give a bit of limit to avoid it from disappearing help_overview->set_v_size_flags(SIZE_EXPAND_FILL); tab_container = memnew(TabContainer); tab_container->set_tabs_visible(false); - tab_container->set_custom_minimum_size(Size2(200 * EDSCALE, 0)); + tab_container->set_custom_minimum_size(Size2(200, 0) * EDSCALE); script_split->add_child(tab_container); tab_container->set_h_size_flags(SIZE_EXPAND_FILL); @@ -2978,10 +2977,11 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { file_menu = memnew(MenuButton); menu_hb->add_child(file_menu); file_menu->set_text(TTR("File")); + file_menu->set_switch_on_hover(true); file_menu->get_popup()->set_hide_on_window_lose_focus(true); - file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/new", TTR("New Script")), FILE_NEW); - file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/new_textfile", TTR("New TextFile")), FILE_NEW_TEXTFILE); - file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/open", TTR("Open")), FILE_OPEN); + file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/new", TTR("New Script...")), FILE_NEW); + file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/new_textfile", TTR("New TextFile...")), FILE_NEW_TEXTFILE); + file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/open", TTR("Open...")), FILE_OPEN); file_menu->get_popup()->add_submenu_item(TTR("Open Recent"), "RecentScripts", FILE_OPEN_RECENT); recent_scripts = memnew(PopupMenu); @@ -2997,7 +2997,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { file_menu->get_popup()->add_separator(); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/reload_script_soft", TTR("Soft Reload Script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_R), FILE_TOOL_RELOAD_SOFT); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/copy_path", TTR("Copy Script Path")), FILE_COPY_PATH); - file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/show_in_file_system", TTR("Show In File System")), SHOW_IN_FILE_SYSTEM); + file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/show_in_file_system", TTR("Show in FileSystem")), SHOW_IN_FILE_SYSTEM); file_menu->get_popup()->add_separator(); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/history_previous", TTR("History Previous"), KEY_MASK_ALT | KEY_LEFT), WINDOW_PREV); @@ -3010,10 +3010,11 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { theme_submenu->set_name("Theme"); file_menu->get_popup()->add_child(theme_submenu); theme_submenu->connect("id_pressed", this, "_theme_option"); - theme_submenu->add_shortcut(ED_SHORTCUT("script_editor/import_theme", TTR("Import Theme")), THEME_IMPORT); + theme_submenu->add_shortcut(ED_SHORTCUT("script_editor/import_theme", TTR("Import Theme...")), THEME_IMPORT); theme_submenu->add_shortcut(ED_SHORTCUT("script_editor/reload_theme", TTR("Reload Theme")), THEME_RELOAD); + theme_submenu->add_separator(); theme_submenu->add_shortcut(ED_SHORTCUT("script_editor/save_theme", TTR("Save Theme")), THEME_SAVE); - theme_submenu->add_shortcut(ED_SHORTCUT("script_editor/save_theme_as", TTR("Save Theme As")), THEME_SAVE_AS); + theme_submenu->add_shortcut(ED_SHORTCUT("script_editor/save_theme_as", TTR("Save Theme As...")), THEME_SAVE_AS); file_menu->get_popup()->add_separator(); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_docs", TTR("Close Docs")), CLOSE_DOCS); @@ -3029,6 +3030,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { script_search_menu = memnew(MenuButton); menu_hb->add_child(script_search_menu); script_search_menu->set_text(TTR("Search")); + script_search_menu->set_switch_on_hover(true); script_search_menu->get_popup()->set_hide_on_window_lose_focus(true); script_search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find", TTR("Find..."), KEY_MASK_CMD | KEY_F), HELP_SEARCH_FIND); script_search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find_next", TTR("Find Next"), KEY_F3), HELP_SEARCH_FIND_NEXT); @@ -3038,6 +3040,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { debug_menu = memnew(MenuButton); menu_hb->add_child(debug_menu); debug_menu->set_text(TTR("Debug")); + debug_menu->set_switch_on_hover(true); debug_menu->get_popup()->set_hide_on_window_lose_focus(true); debug_menu->get_popup()->add_shortcut(ED_SHORTCUT("debugger/step_over", TTR("Step Over"), KEY_F10), DEBUG_NEXT); debug_menu->get_popup()->add_shortcut(ED_SHORTCUT("debugger/step_into", TTR("Step Into"), KEY_F11), DEBUG_STEP); @@ -3073,12 +3076,6 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { menu_hb->add_child(site_search); site_search->set_tooltip(TTR("Open Godot online documentation")); - class_search = memnew(ToolButton); - class_search->set_text(TTR("Classes")); - class_search->connect("pressed", this, "_menu_option", varray(SEARCH_CLASSES)); - menu_hb->add_child(class_search); - class_search->set_tooltip(TTR("Search the class hierarchy.")); - help_search = memnew(ToolButton); help_search->set_text(TTR("Search Help")); help_search->connect("pressed", this, "_menu_option", varray(SEARCH_HELP)); @@ -3164,18 +3161,13 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { add_child(help_search_dialog); help_search_dialog->connect("go_to_help", this, "_help_class_goto"); - help_index = memnew(EditorHelpIndex); - add_child(help_index); - help_index->connect("open_class", this, "_help_class_open"); - find_in_files_dialog = memnew(FindInFilesDialog); find_in_files_dialog->connect(FindInFilesDialog::SIGNAL_FIND_REQUESTED, this, "_start_find_in_files", varray(false)); find_in_files_dialog->connect(FindInFilesDialog::SIGNAL_REPLACE_REQUESTED, this, "_start_find_in_files", varray(true)); add_child(find_in_files_dialog); find_in_files = memnew(FindInFilesPanel); - find_in_files_button = editor->add_bottom_panel_item(TTR("Search results"), find_in_files); - find_in_files_button->set_tooltip(TTR("Search in files")); - find_in_files->set_custom_minimum_size(Size2(0, 200)); + find_in_files_button = editor->add_bottom_panel_item(TTR("Search Results"), find_in_files); + find_in_files->set_custom_minimum_size(Size2(0, 200) * EDSCALE); find_in_files->connect(FindInFilesPanel::SIGNAL_RESULT_SELECTED, this, "_on_find_in_files_result_selected"); find_in_files->connect(FindInFilesPanel::SIGNAL_FILES_MODIFIED, this, "_on_find_in_files_modified_files"); find_in_files->hide(); diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index 28c07393f7..4be5345aaa 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -34,6 +34,7 @@ #include "core/script_language.h" #include "editor/code_editor.h" #include "editor/editor_help.h" +#include "editor/editor_help_search.h" #include "editor/editor_plugin.h" #include "editor/script_create_dialog.h" #include "scene/gui/item_list.h" @@ -155,7 +156,6 @@ class ScriptEditor : public PanelContainer { DEBUG_SHOW_KEEP_OPEN, DEBUG_WITH_EXTERNAL_EDITOR, SEARCH_HELP, - SEARCH_CLASSES, SEARCH_WEBSITE, HELP_SEARCH_FIND, HELP_SEARCH_FIND_NEXT, @@ -200,7 +200,6 @@ class ScriptEditor : public PanelContainer { Button *help_search; Button *site_search; - Button *class_search; EditorHelpSearch *help_search_dialog; ItemList *script_list; @@ -254,7 +253,7 @@ class ScriptEditor : public PanelContainer { Vector<ScriptHistory> history; int history_pos; - EditorHelpIndex *help_index; + Vector<String> previous_scripts; void _tab_changed(int p_which); void _menu_option(int p_option); diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 9b968c3523..6d4b1d1b9c 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -131,6 +131,7 @@ void ScriptTextEditor::_load_theme_settings() { Color safe_line_number_color = EDITOR_GET("text_editor/highlighting/safe_line_number_color"); Color caret_color = EDITOR_GET("text_editor/highlighting/caret_color"); Color caret_background_color = EDITOR_GET("text_editor/highlighting/caret_background_color"); + Color indent_guide_color = EDITOR_GET("text_editor/highlighting/indent_guide_color"); Color text_selected_color = EDITOR_GET("text_editor/highlighting/text_selected_color"); Color selection_color = EDITOR_GET("text_editor/highlighting/selection_color"); Color brace_mismatch_color = EDITOR_GET("text_editor/highlighting/brace_mismatch_color"); @@ -163,6 +164,7 @@ void ScriptTextEditor::_load_theme_settings() { text_edit->add_color_override("safe_line_number_color", safe_line_number_color); text_edit->add_color_override("caret_color", caret_color); text_edit->add_color_override("caret_background_color", caret_background_color); + text_edit->add_color_override("indent_guide_color", indent_guide_color); text_edit->add_color_override("font_selected_color", text_selected_color); text_edit->add_color_override("selection_color", selection_color); text_edit->add_color_override("brace_mismatch_color", brace_mismatch_color); @@ -179,7 +181,7 @@ void ScriptTextEditor::_load_theme_settings() { text_edit->add_color_override("search_result_border_color", search_result_border_color); text_edit->add_color_override("symbol_color", symbol_color); - text_edit->add_constant_override("line_spacing", EDITOR_DEF("text_editor/theme/line_spacing", 4)); + text_edit->add_constant_override("line_spacing", EDITOR_DEF("text_editor/theme/line_spacing", 6)); colors_cache.symbol_color = symbol_color; colors_cache.keyword_color = keyword_color; @@ -443,6 +445,7 @@ void ScriptTextEditor::_validate_script() { if (!script->get_language()->validate(text, line, col, errortxt, script->get_path(), &fnc, &warnings, &safe_lines)) { String error_text = "error(" + itos(line) + "," + itos(col) + "): " + errortxt; code_editor->set_error(error_text); + code_editor->set_error_pos(line - 1, col - 1); } else { code_editor->set_error(""); line = -1; @@ -773,7 +776,7 @@ void ScriptTextEditor::_edit_option(int p_op) { } break; case EDIT_CLONE_DOWN: { - code_editor->code_lines_down(); + code_editor->clone_lines_down(); } break; case EDIT_TOGGLE_FOLD_LINE: { @@ -817,6 +820,9 @@ void ScriptTextEditor::_edit_option(int p_op) { if (tx->get_selection_to_column() == 0) end -= 1; + int col_to = tx->get_selection_to_column(); + int cursor_pos = tx->cursor_get_column(); + // Check if all lines in the selected block are commented bool is_commented = true; for (int i = begin; i <= end; i++) { @@ -839,19 +845,42 @@ void ScriptTextEditor::_edit_option(int p_op) { } tx->set_line(i, line_text); } + + // Adjust selection & cursor position. + int offset = is_commented ? -1 : 1; + int col_from = tx->get_selection_from_column() > 0 ? tx->get_selection_from_column() + offset : 0; + + if (is_commented && tx->cursor_get_column() == tx->get_line(tx->cursor_get_line()).length() + 1) + cursor_pos += 1; + + if (tx->get_selection_to_column() != 0 && col_to != tx->get_line(tx->get_selection_to_line()).length() + 1) + col_to += offset; + + if (tx->cursor_get_column() != 0) + cursor_pos += offset; + + tx->select(begin, col_from, tx->get_selection_to_line(), col_to); + tx->cursor_set_column(cursor_pos); + } else { int begin = tx->cursor_get_line(); String line_text = tx->get_line(begin); - if (line_text.begins_with(delimiter)) + int col = tx->cursor_get_column(); + if (line_text.begins_with(delimiter)) { line_text = line_text.substr(delimiter.length(), line_text.length()); - else + col -= 1; + } else { line_text = delimiter + line_text; + col += 1; + } + tx->set_line(begin, line_text); + tx->cursor_set_column(col); } tx->end_complex_operation(); tx->update(); - //tx->deselect(); + } break; case EDIT_COMPLETE: { @@ -1023,7 +1052,7 @@ void ScriptTextEditor::_edit_option(int p_op) { if (text == "") text = tx->get_word_under_cursor(); if (text != "") { - emit_signal("request_help_search", text); + emit_signal("request_help", text); } } break; case LOOKUP_SYMBOL: { @@ -1049,7 +1078,7 @@ void ScriptTextEditor::set_syntax_highlighter(SyntaxHighlighter *p_highlighter) if (p_highlighter != NULL) highlighter_menu->set_item_checked(highlighter_menu->get_item_idx_from_text(p_highlighter->get_name()), true); else - highlighter_menu->set_item_checked(highlighter_menu->get_item_idx_from_text("Standard"), true); + highlighter_menu->set_item_checked(highlighter_menu->get_item_idx_from_text(TTR("Standard")), true); } void ScriptTextEditor::_change_syntax_highlighter(int p_idx) { @@ -1439,6 +1468,7 @@ ScriptTextEditor::ScriptTextEditor() { edit_menu = memnew(MenuButton); edit_menu->set_text(TTR("Edit")); + edit_menu->set_switch_on_hover(true); edit_menu->get_popup()->set_hide_on_window_lose_focus(true); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO); @@ -1482,7 +1512,7 @@ ScriptTextEditor::ScriptTextEditor() { convert_case->add_shortcut(ED_SHORTCUT("script_text_editor/capitalize", TTR("Capitalize"), KEY_MASK_SHIFT | KEY_F6), EDIT_CAPITALIZE); convert_case->connect("id_pressed", this, "_edit_option"); - highlighters["Standard"] = NULL; + highlighters[TTR("Standard")] = NULL; highlighter_menu = memnew(PopupMenu); highlighter_menu->set_name("highlighter_menu"); edit_menu->get_popup()->add_child(highlighter_menu); @@ -1493,6 +1523,7 @@ ScriptTextEditor::ScriptTextEditor() { search_menu = memnew(MenuButton); edit_hb->add_child(search_menu); search_menu->set_text(TTR("Search")); + search_menu->set_switch_on_hover(true); search_menu->get_popup()->set_hide_on_window_lose_focus(true); search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find"), SEARCH_FIND); search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_next"), SEARCH_FIND_NEXT); @@ -1557,8 +1588,8 @@ void ScriptTextEditor::register_editor() { ED_SHORTCUT("script_text_editor/complete_symbol", TTR("Complete Symbol"), KEY_MASK_CMD | KEY_SPACE); #endif ED_SHORTCUT("script_text_editor/trim_trailing_whitespace", TTR("Trim Trailing Whitespace"), KEY_MASK_CMD | KEY_MASK_ALT | KEY_T); - ED_SHORTCUT("script_text_editor/convert_indent_to_spaces", TTR("Convert Indent To Spaces"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_Y); - ED_SHORTCUT("script_text_editor/convert_indent_to_tabs", TTR("Convert Indent To Tabs"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_I); + ED_SHORTCUT("script_text_editor/convert_indent_to_spaces", TTR("Convert Indent to Spaces"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_Y); + ED_SHORTCUT("script_text_editor/convert_indent_to_tabs", TTR("Convert Indent to Tabs"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_I); ED_SHORTCUT("script_text_editor/auto_indent", TTR("Auto Indent"), KEY_MASK_CMD | KEY_I); #ifdef OSX_ENABLED diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index 17f93b55a1..e3389f25cf 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -70,6 +70,7 @@ void ShaderTextEditor::_load_theme_settings() { Color line_number_color = EDITOR_GET("text_editor/highlighting/line_number_color"); Color caret_color = EDITOR_GET("text_editor/highlighting/caret_color"); Color caret_background_color = EDITOR_GET("text_editor/highlighting/caret_background_color"); + Color indent_guide_color = EDITOR_GET("text_editor/highlighting/indent_guide_color"); Color text_selected_color = EDITOR_GET("text_editor/highlighting/text_selected_color"); Color selection_color = EDITOR_GET("text_editor/highlighting/selection_color"); Color brace_mismatch_color = EDITOR_GET("text_editor/highlighting/brace_mismatch_color"); @@ -98,6 +99,7 @@ void ShaderTextEditor::_load_theme_settings() { get_text_edit()->add_color_override("line_number_color", line_number_color); get_text_edit()->add_color_override("caret_color", caret_color); get_text_edit()->add_color_override("caret_background_color", caret_background_color); + get_text_edit()->add_color_override("indent_guide_color", indent_guide_color); get_text_edit()->add_color_override("font_selected_color", text_selected_color); get_text_edit()->add_color_override("selection_color", selection_color); get_text_edit()->add_color_override("brace_mismatch_color", brace_mismatch_color); @@ -193,6 +195,7 @@ void ShaderTextEditor::_validate_script() { if (err != OK) { String error_text = "error(" + itos(sl.get_error_line()) + "): " + sl.get_error_text(); set_error(error_text); + set_error_pos(sl.get_error_line() - 1, 0); for (int i = 0; i < get_text_edit()->get_line_count(); i++) get_text_edit()->set_line_as_marked(i, false); get_text_edit()->set_line_as_marked(sl.get_error_line() - 1, true); @@ -263,7 +266,7 @@ void ShaderEditor::_menu_option(int p_option) { shader_editor->delete_lines(); } break; case EDIT_CLONE_DOWN: { - shader_editor->code_lines_down(); + shader_editor->clone_lines_down(); } break; case EDIT_TOGGLE_COMMENT: { @@ -349,9 +352,9 @@ void ShaderEditor::_menu_option(int p_option) { void ShaderEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { - } - if (p_what == NOTIFICATION_DRAW) { + if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { + if (is_visible_in_tree()) + shader_editor->get_text_edit()->grab_focus(); } } @@ -367,6 +370,7 @@ void ShaderEditor::_editor_settings_changed() { shader_editor->get_text_edit()->set_indent_size(EditorSettings::get_singleton()->get("text_editor/indent/size")); shader_editor->get_text_edit()->set_indent_using_spaces(EditorSettings::get_singleton()->get("text_editor/indent/type")); shader_editor->get_text_edit()->set_auto_indent(EditorSettings::get_singleton()->get("text_editor/indent/auto_indent")); + shader_editor->get_text_edit()->set_draw_indent_guides(EditorSettings::get_singleton()->get("text_editor/indent/draw_indent_guides")); shader_editor->get_text_edit()->set_draw_tabs(EditorSettings::get_singleton()->get("text_editor/indent/draw_tabs")); shader_editor->get_text_edit()->set_show_line_numbers(EditorSettings::get_singleton()->get("text_editor/line_numbers/show_line_numbers")); shader_editor->get_text_edit()->set_syntax_coloring(EditorSettings::get_singleton()->get("text_editor/highlighting/syntax_highlighting")); @@ -388,7 +392,6 @@ void ShaderEditor::_bind_methods() { ClassDB::bind_method("_menu_option", &ShaderEditor::_menu_option); ClassDB::bind_method("_params_changed", &ShaderEditor::_params_changed); ClassDB::bind_method("apply_shaders", &ShaderEditor::apply_shaders); - //ClassDB::bind_method("_close_current_tab",&ShaderEditor::_close_current_tab); } void ShaderEditor::ensure_select_current() { @@ -404,6 +407,11 @@ void ShaderEditor::ensure_select_current() { }*/ } +void ShaderEditor::goto_line_selection(int p_line, int p_begin, int p_end) { + + shader_editor->goto_line_selection(p_line, p_begin, p_end); +} + void ShaderEditor::edit(const Ref<Shader> &p_shader) { if (p_shader.is_null() || !p_shader->is_text_shader()) @@ -526,9 +534,8 @@ ShaderEditor::ShaderEditor(EditorNode *p_node) { HBoxContainer *hbc = memnew(HBoxContainer); edit_menu = memnew(MenuButton); - //edit_menu->set_position(Point2(5, -1)); edit_menu->set_text(TTR("Edit")); - + edit_menu->set_switch_on_hover(true); edit_menu->get_popup()->set_hide_on_window_lose_focus(true); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO); @@ -548,12 +555,11 @@ ShaderEditor::ShaderEditor(EditorNode *p_node) { edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/clone_down"), EDIT_CLONE_DOWN); edit_menu->get_popup()->add_separator(); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/complete_symbol"), EDIT_COMPLETE); - edit_menu->get_popup()->connect("id_pressed", this, "_menu_option"); search_menu = memnew(MenuButton); - //search_menu->set_position(Point2(38, -1)); search_menu->set_text(TTR("Search")); + search_menu->set_switch_on_hover(true); search_menu->get_popup()->set_hide_on_window_lose_focus(true); search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find"), SEARCH_FIND); search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_next"), SEARCH_FIND_NEXT); diff --git a/editor/plugins/shader_editor_plugin.h b/editor/plugins/shader_editor_plugin.h index 2ea1562310..46e3dffdd5 100644 --- a/editor/plugins/shader_editor_plugin.h +++ b/editor/plugins/shader_editor_plugin.h @@ -120,6 +120,8 @@ public: void ensure_select_current(); void edit(const Ref<Shader> &p_shader); + void goto_line_selection(int p_line, int p_begin, int p_end); + virtual Size2 get_minimum_size() const { return Size2(0, 200); } void save_external_data(); @@ -143,6 +145,8 @@ public: virtual void make_visible(bool p_visible); virtual void selected_notify(); + ShaderEditor *get_shader_editor() const { return shader_editor; } + virtual void save_external_data(); virtual void apply_changes(); diff --git a/editor/plugins/skeleton_editor_plugin.cpp b/editor/plugins/skeleton_editor_plugin.cpp index e7d9f1b702..8b0beefb3e 100644 --- a/editor/plugins/skeleton_editor_plugin.cpp +++ b/editor/plugins/skeleton_editor_plugin.cpp @@ -151,6 +151,7 @@ void SkeletonEditor::_bind_methods() { } SkeletonEditor::SkeletonEditor() { + skeleton = NULL; options = memnew(MenuButton); SpatialEditor::get_singleton()->add_control_to_menu_panel(options); diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 114610c562..4fe278d005 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -534,9 +534,9 @@ void SpatialEditorViewport::_update_name() { String view_mode = orthogonal ? TTR("Orthogonal") : TTR("Perspective"); if (name != "") - view_menu->set_text("[ " + name + " " + view_mode + " ]"); + view_menu->set_text(name + " " + view_mode); else - view_menu->set_text("[ " + view_mode + " ]"); + view_menu->set_text(view_mode); view_menu->set_size(Vector2(0, 0)); // resets the button size } @@ -952,8 +952,10 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { if (b->is_pressed()) { int mod = _get_key_modifier(b); - if (mod == _get_key_modifier_setting("editors/3d/freelook/freelook_activation_modifier")) { - set_freelook_active(true); + if (!orthogonal) { + if (mod == _get_key_modifier_setting("editors/3d/freelook/freelook_activation_modifier")) { + set_freelook_active(true); + } } } else { set_freelook_active(false); @@ -1134,7 +1136,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } if (clicked) { _select_clicked(clicked_wants_append, true); - //clickd processing was deferred + // Processing was deferred. clicked = 0; } @@ -1241,7 +1243,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { if (!clicked_includes_current) { _select_clicked(clicked_wants_append, true); - //clickd processing was deferred + // Processing was deferred. } _compute_edit(_edit.mouse_pos); @@ -1339,7 +1341,8 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { List<Node *> &selection = editor_selection->get_selected_node_list(); - bool local_coords = (spatial_editor->are_local_coords_enabled() && _edit.plane != TRANSFORM_VIEW); // Disable local transformation for TRANSFORM_VIEW + // Disable local transformation for TRANSFORM_VIEW + bool local_coords = (spatial_editor->are_local_coords_enabled() && _edit.plane != TRANSFORM_VIEW); float snap = 0; if (_edit.snap || spatial_editor->is_snap_enabled()) { @@ -1468,7 +1471,8 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { List<Node *> &selection = editor_selection->get_selected_node_list(); - bool local_coords = (spatial_editor->are_local_coords_enabled() && _edit.plane != TRANSFORM_VIEW); // Disable local transformation for TRANSFORM_VIEW + // Disable local transformation for TRANSFORM_VIEW + bool local_coords = (spatial_editor->are_local_coords_enabled() && _edit.plane != TRANSFORM_VIEW); float snap = 0; if (_edit.snap || spatial_editor->is_snap_enabled()) { @@ -1643,6 +1647,8 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { nav_mode = NAVIGATION_ZOOM; } else if (freelook_active) { nav_mode = NAVIGATION_LOOK; + } else if (orthogonal) { + nav_mode = NAVIGATION_PAN; } } else if (m->get_button_mask() & BUTTON_MASK_MIDDLE) { @@ -1793,7 +1799,8 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { if (ED_IS_SHORTCUT("spatial_editor/focus_selection", p_event)) { _menu_option(VIEW_CENTER_TO_SELECTION); } - if (ED_IS_SHORTCUT("spatial_editor/switch_perspective_orthogonal", p_event)) { + // Orthgonal mode doesn't work in freelook. + if (!freelook_active && ED_IS_SHORTCUT("spatial_editor/switch_perspective_orthogonal", p_event)) { _menu_option(orthogonal ? VIEW_PERSPECTIVE : VIEW_ORTHOGONAL); _update_name(); } @@ -1823,7 +1830,8 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { set_message(TTR("Animation Key Inserted.")); } - if (ED_IS_SHORTCUT("spatial_editor/freelook_toggle", p_event)) { + // Freelook doesn't work in orthogonal mode. + if (!orthogonal && ED_IS_SHORTCUT("spatial_editor/freelook_toggle", p_event)) { set_freelook_active(!is_freelook_active()); } else if (k->get_scancode() == KEY_ESCAPE) { @@ -1893,7 +1901,7 @@ void SpatialEditorViewport::_nav_orbit(Ref<InputEventWithModifiers> p_event, con real_t degrees_per_pixel = EditorSettings::get_singleton()->get("editors/3d/navigation_feel/orbit_sensitivity"); real_t radians_per_pixel = Math::deg2rad(degrees_per_pixel); - bool invert_y_axis = EditorSettings::get_singleton()->get("editors/3d/navigation/invert_y-axis"); + bool invert_y_axis = EditorSettings::get_singleton()->get("editors/3d/navigation/invert_y_axis"); if (invert_y_axis) { cursor.x_rot -= p_relative.y * radians_per_pixel; @@ -1911,37 +1919,38 @@ void SpatialEditorViewport::_nav_orbit(Ref<InputEventWithModifiers> p_event, con void SpatialEditorViewport::_nav_look(Ref<InputEventWithModifiers> p_event, const Vector2 &p_relative) { - // Freelook only works properly in perspective. - // It could technically work in ortho, but it's terrible for a user due to FOV being a fixed width. - if (!orthogonal) { - real_t degrees_per_pixel = EditorSettings::get_singleton()->get("editors/3d/navigation_feel/orbit_sensitivity"); - real_t radians_per_pixel = Math::deg2rad(degrees_per_pixel); - bool invert_y_axis = EditorSettings::get_singleton()->get("editors/3d/navigation/invert_y-axis"); - - // Note: do NOT assume the camera has the "current" transform, because it is interpolated and may have "lag". - Transform prev_camera_transform = to_camera_transform(cursor); + if (orthogonal) { + _nav_pan(p_event, p_relative); + return; + } - if (invert_y_axis) { - cursor.x_rot -= p_relative.y * radians_per_pixel; - } else { - cursor.x_rot += p_relative.y * radians_per_pixel; - } - cursor.y_rot += p_relative.x * radians_per_pixel; - if (cursor.x_rot > Math_PI / 2.0) - cursor.x_rot = Math_PI / 2.0; - if (cursor.x_rot < -Math_PI / 2.0) - cursor.x_rot = -Math_PI / 2.0; + real_t degrees_per_pixel = EditorSettings::get_singleton()->get("editors/3d/navigation_feel/orbit_sensitivity"); + real_t radians_per_pixel = Math::deg2rad(degrees_per_pixel); + bool invert_y_axis = EditorSettings::get_singleton()->get("editors/3d/navigation/invert_y_axis"); - // Look is like the opposite of Orbit: the focus point rotates around the camera - Transform camera_transform = to_camera_transform(cursor); - Vector3 pos = camera_transform.xform(Vector3(0, 0, 0)); - Vector3 prev_pos = prev_camera_transform.xform(Vector3(0, 0, 0)); - Vector3 diff = prev_pos - pos; - cursor.pos += diff; + // Note: do NOT assume the camera has the "current" transform, because it is interpolated and may have "lag". + Transform prev_camera_transform = to_camera_transform(cursor); - name = ""; - _update_name(); + if (invert_y_axis) { + cursor.x_rot -= p_relative.y * radians_per_pixel; + } else { + cursor.x_rot += p_relative.y * radians_per_pixel; } + cursor.y_rot += p_relative.x * radians_per_pixel; + if (cursor.x_rot > Math_PI / 2.0) + cursor.x_rot = Math_PI / 2.0; + if (cursor.x_rot < -Math_PI / 2.0) + cursor.x_rot = -Math_PI / 2.0; + + // Look is like the opposite of Orbit: the focus point rotates around the camera + Transform camera_transform = to_camera_transform(cursor); + Vector3 pos = camera_transform.xform(Vector3(0, 0, 0)); + Vector3 prev_pos = prev_camera_transform.xform(Vector3(0, 0, 0)); + Vector3 diff = prev_pos - pos; + cursor.pos += diff; + + name = ""; + _update_name(); } void SpatialEditorViewport::set_freelook_active(bool active_now) { @@ -2124,7 +2133,7 @@ void SpatialEditorViewport::_notification(int p_what) { _update_freelook(delta); Node *scene_root = editor->get_scene_tree_dock()->get_editor_data()->get_edited_scene_root(); - if (previewing_cinema == true && scene_root != NULL) { + if (previewing_cinema && scene_root != NULL) { Camera *cam = scene_root->get_viewport()->get_camera(); if (cam != NULL && cam != previewing) { //then switch the viewport's camera to the scene's viewport camera @@ -2222,8 +2231,21 @@ void SpatialEditorViewport::_notification(int p_what) { bool show_info = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_INFORMATION)); info_label->set_visible(show_info); + Camera *current_camera; + + if (previewing) { + current_camera = previewing; + } else { + current_camera = camera; + } + if (show_info) { String text; + text += "X: " + rtos(current_camera->get_translation().x).pad_decimals(1) + "\n"; + text += "Y: " + rtos(current_camera->get_translation().y).pad_decimals(1) + "\n"; + text += "Z: " + rtos(current_camera->get_translation().z).pad_decimals(1) + "\n"; + text += TTR("Pitch") + ": " + itos(Math::round(current_camera->get_rotation_degrees().x)) + "\n"; + text += TTR("Yaw") + ": " + itos(Math::round(current_camera->get_rotation_degrees().y)) + "\n\n"; text += TTR("Objects Drawn") + ": " + itos(viewport->get_render_info(Viewport::RENDER_INFO_OBJECTS_IN_FRAME)) + "\n"; text += TTR("Material Changes") + ": " + itos(viewport->get_render_info(Viewport::RENDER_INFO_MATERIAL_CHANGES_IN_FRAME)) + "\n"; text += TTR("Shader Changes") + ": " + itos(viewport->get_render_info(Viewport::RENDER_INFO_SHADER_CHANGES_IN_FRAME)) + "\n"; @@ -2250,6 +2272,11 @@ void SpatialEditorViewport::_notification(int p_what) { float cinema_half_width = cinema_label->get_size().width / 2.0f; cinema_label->set_anchor_and_margin(MARGIN_LEFT, 0.5f, -cinema_half_width); } + + if (lock_rotation) { + float locked_half_width = locked_label->get_size().width / 2.0f; + locked_label->set_anchor_and_margin(MARGIN_LEFT, 0.5f, -locked_half_width); + } } if (p_what == NOTIFICATION_ENTER_TREE) { @@ -2260,21 +2287,36 @@ void SpatialEditorViewport::_notification(int p_what) { surface->connect("mouse_exited", this, "_surface_mouse_exit"); surface->connect("focus_entered", this, "_surface_focus_enter"); surface->connect("focus_exited", this, "_surface_focus_exit"); - info_label->add_style_override("normal", editor->get_gui_base()->get_stylebox("Information3dViewport", "EditorStyles")); - fps_label->add_style_override("normal", editor->get_gui_base()->get_stylebox("Information3dViewport", "EditorStyles")); - cinema_label->add_style_override("normal", editor->get_gui_base()->get_stylebox("Information3dViewport", "EditorStyles")); - preview_camera->set_icon(get_icon("Camera", "EditorIcons")); + _init_gizmo_instance(index); } + if (p_what == NOTIFICATION_EXIT_TREE) { _finish_gizmo_instances(); } - if (p_what == NOTIFICATION_MOUSE_ENTER) { - } + if (p_what == NOTIFICATION_THEME_CHANGED) { + + view_menu->set_icon(get_icon("GuiMiniTabMenu", "EditorIcons")); + preview_camera->set_icon(get_icon("Camera", "EditorIcons")); + + view_menu->add_style_override("normal", editor->get_gui_base()->get_stylebox("Information3dViewport", "EditorStyles")); + view_menu->add_style_override("hover", editor->get_gui_base()->get_stylebox("Information3dViewport", "EditorStyles")); + view_menu->add_style_override("pressed", editor->get_gui_base()->get_stylebox("Information3dViewport", "EditorStyles")); + view_menu->add_style_override("focus", editor->get_gui_base()->get_stylebox("Information3dViewport", "EditorStyles")); + view_menu->add_style_override("disabled", editor->get_gui_base()->get_stylebox("Information3dViewport", "EditorStyles")); - if (p_what == NOTIFICATION_DRAW) { + preview_camera->add_style_override("normal", editor->get_gui_base()->get_stylebox("Information3dViewport", "EditorStyles")); + preview_camera->add_style_override("hover", editor->get_gui_base()->get_stylebox("Information3dViewport", "EditorStyles")); + preview_camera->add_style_override("pressed", editor->get_gui_base()->get_stylebox("Information3dViewport", "EditorStyles")); + preview_camera->add_style_override("focus", editor->get_gui_base()->get_stylebox("Information3dViewport", "EditorStyles")); + preview_camera->add_style_override("disabled", editor->get_gui_base()->get_stylebox("Information3dViewport", "EditorStyles")); + + info_label->add_style_override("normal", editor->get_gui_base()->get_stylebox("Information3dViewport", "EditorStyles")); + fps_label->add_style_override("normal", editor->get_gui_base()->get_stylebox("Information3dViewport", "EditorStyles")); + cinema_label->add_style_override("normal", editor->get_gui_base()->get_stylebox("Information3dViewport", "EditorStyles")); + locked_label->add_style_override("normal", editor->get_gui_base()->get_stylebox("Information3dViewport", "EditorStyles")); } } @@ -2515,8 +2557,14 @@ void SpatialEditorViewport::_menu_option(int p_option) { if (!se) continue; - Transform xform = camera_transform; - xform.scale_basis(sp->get_scale()); + Transform xform; + if (orthogonal) { + xform = sp->get_global_transform(); + xform.basis.set_euler(camera_transform.basis.get_euler()); + } else { + xform = camera_transform; + xform.scale_basis(sp->get_scale()); + } undo_redo->add_do_method(sp, "set_global_transform", xform); undo_redo->add_undo_method(sp, "set_global_transform", sp->get_global_gizmo_transform()); @@ -2564,9 +2612,9 @@ void SpatialEditorViewport::_menu_option(int p_option) { lock_rotation = !current; view_menu->get_popup()->set_item_checked(idx, !current); if (lock_rotation) { - view_menu->set_icon(get_icon("Lock", "EditorIcons")); + locked_label->show(); } else { - view_menu->set_icon(Ref<Texture>()); + locked_label->hide(); } } break; @@ -2636,11 +2684,6 @@ void SpatialEditorViewport::_menu_option(int p_option) { bool current = view_menu->get_popup()->is_item_checked(idx); view_menu->get_popup()->set_item_checked(idx, !current); - if (current) - preview_camera->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 10 * EDSCALE); - else - preview_camera->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 15 * EDSCALE + fps_label->get_size().height); - } break; case VIEW_DISPLAY_NORMAL: { @@ -2754,7 +2797,7 @@ void SpatialEditorViewport::_toggle_camera_preview(bool p_activate) { VS::get_singleton()->viewport_attach_camera(viewport->get_viewport_rid(), camera->get_camera()); //restore if (!preview) preview_camera->hide(); - view_menu->show(); + view_menu->set_disabled(false); surface->update(); } else { @@ -2762,7 +2805,7 @@ void SpatialEditorViewport::_toggle_camera_preview(bool p_activate) { previewing = preview; previewing->connect("tree_exiting", this, "_preview_exited_scene"); VS::get_singleton()->viewport_attach_camera(viewport->get_viewport_rid(), preview->get_camera()); //replace - view_menu->hide(); + view_menu->set_disabled(true); surface->update(); } } @@ -3195,7 +3238,7 @@ bool SpatialEditorViewport::_create_instance(Node *parent, String &path, const P if (mesh != NULL) { MeshInstance *mesh_instance = memnew(MeshInstance); mesh_instance->set_mesh(mesh); - mesh_instance->set_name(mesh->get_name()); + mesh_instance->set_name(path.get_file().get_basename()); instanced_scene = mesh_instance; } else { if (!scene.is_valid()) { // invalid scene @@ -3419,9 +3462,10 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed surface->set_focus_mode(FOCUS_ALL); view_menu = memnew(MenuButton); + view_menu->set_flat(false); surface->add_child(view_menu); - view_menu->set_position(Point2(4, 4) * EDSCALE); - view_menu->set_self_modulate(Color(1, 1, 1, 0.5)); + view_menu->set_position(Point2(10, 10) * EDSCALE); + view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/top_view"), VIEW_TOP); view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/bottom_view"), VIEW_BOTTOM); view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/left_view"), VIEW_LEFT); @@ -3472,12 +3516,8 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed ED_SHORTCUT("spatial_editor/freelook_down", TTR("Freelook Down"), KEY_Q); ED_SHORTCUT("spatial_editor/freelook_speed_modifier", TTR("Freelook Speed Modifier"), KEY_SHIFT); - preview_camera = memnew(Button); - preview_camera->set_toggle_mode(true); - preview_camera->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_END, -90 * EDSCALE); - preview_camera->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 10 * EDSCALE); - preview_camera->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -10 * EDSCALE); - preview_camera->set_h_grow_direction(GROW_DIRECTION_BEGIN); + preview_camera = memnew(CheckBox); + preview_camera->set_position(Point2(10, 38) * EDSCALE); // Below the 'view_menu' MenuButton. preview_camera->set_text(TTR("Preview")); surface->add_child(preview_camera); preview_camera->hide(); @@ -3497,7 +3537,6 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed surface->add_child(info_label); info_label->hide(); - // FPS Counter. fps_label = memnew(Label); fps_label->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_END, -90 * EDSCALE); fps_label->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 10 * EDSCALE); @@ -3515,6 +3554,16 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed cinema_label->hide(); previewing_cinema = false; + locked_label = memnew(Label); + locked_label->set_anchor_and_margin(MARGIN_TOP, ANCHOR_END, -20 * EDSCALE); + locked_label->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, -10 * EDSCALE); + locked_label->set_h_grow_direction(GROW_DIRECTION_END); + locked_label->set_v_grow_direction(GROW_DIRECTION_BEGIN); + locked_label->set_align(Label::ALIGN_CENTER); + surface->add_child(locked_label); + locked_label->set_text(TTR("View Rotation Locked")); + locked_label->hide(); + accept = NULL; freelook_active = false; @@ -4155,10 +4204,10 @@ void SpatialEditor::set_state(const Dictionary &p_state) { gizmo_plugins.write[j]->set_state(state); switch (state) { - case EditorSpatialGizmoPlugin::ON_TOP: + case EditorSpatialGizmoPlugin::VISIBLE: gizmos_menu->set_item_icon(idx, gizmos_menu->get_icon("visibility_visible")); break; - case EditorSpatialGizmoPlugin::VISIBLE: + case EditorSpatialGizmoPlugin::ON_TOP: gizmos_menu->set_item_icon(idx, gizmos_menu->get_icon("visibility_xray")); break; case EditorSpatialGizmoPlugin::HIDDEN: @@ -4268,10 +4317,10 @@ void SpatialEditor::_menu_gizmo_toggled(int p_option) { // Change icon const int state = gizmos_menu->get_item_state(idx); switch (state) { - case EditorSpatialGizmoPlugin::ON_TOP: + case EditorSpatialGizmoPlugin::VISIBLE: gizmos_menu->set_item_icon(idx, view_menu->get_popup()->get_icon("visibility_visible")); break; - case EditorSpatialGizmoPlugin::VISIBLE: + case EditorSpatialGizmoPlugin::ON_TOP: gizmos_menu->set_item_icon(idx, view_menu->get_popup()->get_icon("visibility_xray")); break; case EditorSpatialGizmoPlugin::HIDDEN: @@ -4790,7 +4839,7 @@ void SpatialEditor::_init_gizmos_menu() { for (int i = 0; i < gizmo_plugins.size(); ++i) { if (!gizmo_plugins[i]->can_be_hidden()) continue; String plugin_name = gizmo_plugins[i]->get_name(); - gizmos_menu->add_multistate_item(TTR(plugin_name), 3, EditorSpatialGizmoPlugin::ON_TOP, i); + gizmos_menu->add_multistate_item(TTR(plugin_name), 3, EditorSpatialGizmoPlugin::VISIBLE, i); gizmos_menu->set_item_icon(gizmos_menu->get_item_index(i), gizmos_menu->get_icon("visibility_visible")); } } @@ -5426,6 +5475,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { transform_menu = memnew(MenuButton); transform_menu->set_text(TTR("Transform")); + transform_menu->set_switch_on_hover(true); hbc_menu->add_child(transform_menu); p = transform_menu->get_popup(); @@ -5438,7 +5488,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { view_menu = memnew(MenuButton); view_menu->set_text(TTR("View")); - view_menu->set_position(Point2(212, 0)); + view_menu->set_switch_on_hover(true); hbc_menu->add_child(view_menu); p = view_menu->get_popup(); @@ -5871,7 +5921,7 @@ void EditorSpatialGizmoPlugin::unregister_gizmo(EditorSpatialGizmo *p_gizmo) { } EditorSpatialGizmoPlugin::EditorSpatialGizmoPlugin() { - current_state = ON_TOP; + current_state = VISIBLE; } EditorSpatialGizmoPlugin::~EditorSpatialGizmoPlugin() { diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h index c552f21e39..c515a4aaf9 100644 --- a/editor/plugins/spatial_editor_plugin.h +++ b/editor/plugins/spatial_editor_plugin.h @@ -192,7 +192,7 @@ private: EditorSelection *editor_selection; UndoRedo *undo_redo; - Button *preview_camera; + CheckBox *preview_camera; ViewportContainer *viewport_container; MenuButton *view_menu; @@ -211,6 +211,7 @@ private: Label *info_label; Label *fps_label; Label *cinema_label; + Label *locked_label; struct _RayResult { @@ -753,9 +754,9 @@ class EditorSpatialGizmoPlugin : public Resource { GDCLASS(EditorSpatialGizmoPlugin, Resource); public: - static const int ON_TOP = 0; - static const int VISIBLE = 1; - static const int HIDDEN = 2; + static const int VISIBLE = 0; + static const int HIDDEN = 1; + static const int ON_TOP = 2; private: int current_state; diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp index 30246147c2..82936d63d2 100644 --- a/editor/plugins/sprite_frames_editor_plugin.cpp +++ b/editor/plugins/sprite_frames_editor_plugin.cpp @@ -548,7 +548,6 @@ void SpriteFramesEditor::edit(SpriteFrames *p_frames) { } else { hide(); - //set_physics_process(false); } } @@ -599,7 +598,7 @@ bool SpriteFramesEditor::can_drop_data_fw(const Point2 &p_point, const Variant & return false; for (int i = 0; i < files.size(); i++) { - String file = files[0]; + String file = files[i]; String ftype = EditorFileSystem::get_singleton()->get_file_type(file); if (!ClassDB::is_parent_class(ftype, "Texture")) { @@ -816,16 +815,26 @@ SpriteFramesEditor::SpriteFramesEditor() { void SpriteFramesEditorPlugin::edit(Object *p_object) { frames_editor->set_undo_redo(&get_undo_redo()); - SpriteFrames *s = Object::cast_to<SpriteFrames>(p_object); - if (!s) - return; + + SpriteFrames *s; + AnimatedSprite *animated_sprite = Object::cast_to<AnimatedSprite>(p_object); + if (animated_sprite) { + s = *animated_sprite->get_sprite_frames(); + } else { + s = Object::cast_to<SpriteFrames>(p_object); + } frames_editor->edit(s); } bool SpriteFramesEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("SpriteFrames"); + AnimatedSprite *animated_sprite = Object::cast_to<AnimatedSprite>(p_object); + if (animated_sprite && *animated_sprite->get_sprite_frames()) { + return true; + } else { + return p_object->is_class("SpriteFrames"); + } } void SpriteFramesEditorPlugin::make_visible(bool p_visible) { @@ -833,14 +842,11 @@ void SpriteFramesEditorPlugin::make_visible(bool p_visible) { if (p_visible) { button->show(); editor->make_bottom_panel_item_visible(frames_editor); - //frames_editor->set_process(true); } else { button->hide(); if (frames_editor->is_visible_in_tree()) editor->hide_bottom_panel(); - - //frames_editor->set_process(false); } } diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp index 4ff7046a35..52dd115b3e 100644 --- a/editor/plugins/text_editor.cpp +++ b/editor/plugins/text_editor.cpp @@ -84,6 +84,7 @@ void TextEditor::_load_theme_settings() { Color line_number_color = EDITOR_GET("text_editor/highlighting/line_number_color"); Color caret_color = EDITOR_GET("text_editor/highlighting/caret_color"); Color caret_background_color = EDITOR_GET("text_editor/highlighting/caret_background_color"); + Color indent_guide_color = EDITOR_GET("text_editor/highlighting/indent_guide_color"); Color text_selected_color = EDITOR_GET("text_editor/highlighting/text_selected_color"); Color selection_color = EDITOR_GET("text_editor/highlighting/selection_color"); Color brace_mismatch_color = EDITOR_GET("text_editor/highlighting/brace_mismatch_color"); @@ -115,6 +116,7 @@ void TextEditor::_load_theme_settings() { text_edit->add_color_override("line_number_color", line_number_color); text_edit->add_color_override("caret_color", caret_color); text_edit->add_color_override("caret_background_color", caret_background_color); + text_edit->add_color_override("indent_guide_color", indent_guide_color); text_edit->add_color_override("font_selected_color", text_selected_color); text_edit->add_color_override("selection_color", selection_color); text_edit->add_color_override("brace_mismatch_color", brace_mismatch_color); @@ -131,7 +133,7 @@ void TextEditor::_load_theme_settings() { text_edit->add_color_override("search_result_border_color", search_result_border_color); text_edit->add_color_override("symbol_color", symbol_color); - text_edit->add_constant_override("line_spacing", EDITOR_DEF("text_editor/theme/line_spacing", 4)); + text_edit->add_constant_override("line_spacing", EDITOR_DEF("text_editor/theme/line_spacing", 6)); colors_cache.font_color = text_color; colors_cache.symbol_color = symbol_color; @@ -360,7 +362,7 @@ void TextEditor::_edit_option(int p_op) { } break; case EDIT_CLONE_DOWN: { - code_editor->code_lines_down(); + code_editor->clone_lines_down(); } break; case EDIT_TOGGLE_FOLD_LINE: { diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index 33e1f7c6a3..aed3a7d503 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -169,15 +169,24 @@ void TextureRegionEditor::_region_draw() { updating_scroll = true; hscroll->set_min(scroll_rect.position.x); hscroll->set_max(scroll_rect.position.x + scroll_rect.size.x); - hscroll->set_page(edit_draw->get_size().x); - hscroll->set_value(draw_ofs.x); - hscroll->set_step(0.001); + if (ABS(scroll_rect.position.x - (scroll_rect.position.x + scroll_rect.size.x)) <= edit_draw->get_size().x) { + hscroll->hide(); + } else { + hscroll->show(); + hscroll->set_page(edit_draw->get_size().x); + hscroll->set_value(draw_ofs.x); + } vscroll->set_min(scroll_rect.position.y); vscroll->set_max(scroll_rect.position.y + scroll_rect.size.y); - vscroll->set_page(edit_draw->get_size().y); - vscroll->set_value(draw_ofs.y); - vscroll->set_step(0.001); + if (ABS(scroll_rect.position.y - (scroll_rect.position.y + scroll_rect.size.y)) <= edit_draw->get_size().y) { + vscroll->hide(); + draw_ofs.y = scroll_rect.position.y; + } else { + vscroll->show(); + vscroll->set_page(edit_draw->get_size().y); + vscroll->set_value(draw_ofs.y); + } updating_scroll = false; float margins[4]; @@ -299,6 +308,8 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { undo_redo->add_do_method(atlas_tex.ptr(), "set_region", rect); undo_redo->add_undo_method(atlas_tex.ptr(), "set_region", atlas_tex->get_region()); } + undo_redo->add_do_method(this, "_update_rect"); + undo_redo->add_undo_method(this, "_update_rect"); undo_redo->add_do_method(edit_draw, "update"); undo_redo->add_undo_method(edit_draw, "update"); undo_redo->commit_action(); @@ -336,7 +347,7 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { } else if (drag) { if (edited_margin >= 0) { - undo_redo->create_action("Set Margin"); + undo_redo->create_action(TTR("Set Margin")); static Margin m[4] = { MARGIN_TOP, MARGIN_BOTTOM, MARGIN_LEFT, MARGIN_RIGHT }; if (node_ninepatch) { undo_redo->add_do_method(node_ninepatch, "set_patch_margin", m[edited_margin], node_ninepatch->get_patch_margin(m[edited_margin])); @@ -348,7 +359,7 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { } edited_margin = -1; } else { - undo_redo->create_action("Set Region Rect"); + undo_redo->create_action(TTR("Set Region Rect")); if (node_sprite) { undo_redo->add_do_method(node_sprite, "set_region_rect", node_sprite->get_region_rect()); undo_redo->add_undo_method(node_sprite, "set_region_rect", rect_prev); @@ -364,6 +375,8 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { } drag_index = -1; } + undo_redo->add_do_method(this, "_update_rect"); + undo_redo->add_undo_method(this, "_update_rect"); undo_redo->add_do_method(edit_draw, "update"); undo_redo->add_undo_method(edit_draw, "update"); undo_redo->commit_action(); @@ -509,10 +522,7 @@ void TextureRegionEditor::_scroll_changed(float) { } void TextureRegionEditor::_set_snap_mode(int p_mode) { - snap_mode_button->get_popup()->set_item_checked(snap_mode, false); snap_mode = p_mode; - snap_mode_button->set_text(snap_mode_button->get_popup()->get_item_text(p_mode)); - snap_mode_button->get_popup()->set_item_checked(snap_mode, true); if (snap_mode == SNAP_GRID) hb_grid->show(); @@ -577,15 +587,26 @@ void TextureRegionEditor::_zoom_out() { } } -void TextureRegionEditor::apply_rect(const Rect2 &rect) { +void TextureRegionEditor::apply_rect(const Rect2 &p_rect) { + if (node_sprite) + node_sprite->set_region_rect(p_rect); + else if (node_ninepatch) + node_ninepatch->set_region_rect(p_rect); + else if (obj_styleBox.is_valid()) + obj_styleBox->set_region_rect(p_rect); + else if (atlas_tex.is_valid()) + atlas_tex->set_region(p_rect); +} + +void TextureRegionEditor::_update_rect() { if (node_sprite) - node_sprite->set_region_rect(rect); + rect = node_sprite->get_region_rect(); else if (node_ninepatch) - node_ninepatch->set_region_rect(rect); + rect = node_ninepatch->get_region_rect(); else if (obj_styleBox.is_valid()) - obj_styleBox->set_region_rect(rect); + rect = obj_styleBox->get_region_rect(); else if (atlas_tex.is_valid()) - atlas_tex->set_region(rect); + rect = atlas_tex->get_region(); } void TextureRegionEditor::_update_autoslice() { @@ -657,6 +678,10 @@ void TextureRegionEditor::_update_autoslice() { void TextureRegionEditor::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: + case NOTIFICATION_THEME_CHANGED: { + edit_draw->add_style_override("panel", get_stylebox("bg", "Tree")); + } break; case NOTIFICATION_READY: { zoom_out->set_icon(get_icon("ZoomLess", "EditorIcons")); zoom_reset->set_icon(get_icon("ZoomReset", "EditorIcons")); @@ -669,7 +694,7 @@ void TextureRegionEditor::_notification(int p_what) { } break; case MainLoop::NOTIFICATION_WM_FOCUS_IN: { // This happens when the user leaves the Editor and returns, - // he/she could have changed the textures, so the cache is cleared + // they could have changed the textures, so the cache is cleared. cache_map.clear(); _edit_region(); } break; @@ -702,6 +727,7 @@ void TextureRegionEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("_zoom_in"), &TextureRegionEditor::_zoom_in); ClassDB::bind_method(D_METHOD("_zoom_reset"), &TextureRegionEditor::_zoom_reset); ClassDB::bind_method(D_METHOD("_zoom_out"), &TextureRegionEditor::_zoom_out); + ClassDB::bind_method(D_METHOD("_update_rect"), &TextureRegionEditor::_update_rect); } bool TextureRegionEditor::is_stylebox() { @@ -774,6 +800,9 @@ void TextureRegionEditor::_edit_region() { texture = atlas_tex->get_atlas(); if (texture.is_null()) { + _zoom_reset(); + hscroll->hide(); + vscroll->hide(); edit_draw->update(); return; } @@ -790,15 +819,7 @@ void TextureRegionEditor::_edit_region() { } } - if (node_sprite) - rect = node_sprite->get_region_rect(); - else if (node_ninepatch) - rect = node_ninepatch->get_region_rect(); - else if (obj_styleBox.is_valid()) - rect = obj_styleBox->get_region_rect(); - else if (atlas_tex.is_valid()) - rect = atlas_tex->get_region(); - + _update_rect(); edit_draw->update(); } @@ -826,29 +847,23 @@ TextureRegionEditor::TextureRegionEditor(EditorNode *p_editor) { drag_index = -1; drag = false; - VBoxContainer *main_vb = memnew(VBoxContainer); - add_child(main_vb); - main_vb->set_anchors_and_margins_preset(Control::PRESET_WIDE); HBoxContainer *hb_tools = memnew(HBoxContainer); - main_vb->add_child(hb_tools); - + add_child(hb_tools); hb_tools->add_child(memnew(Label(TTR("Snap Mode:")))); - snap_mode_button = memnew(MenuButton); + snap_mode_button = memnew(OptionButton); hb_tools->add_child(snap_mode_button); - snap_mode_button->set_text(TTR("<None>")); - PopupMenu *p = snap_mode_button->get_popup(); - p->set_hide_on_checkable_item_selection(false); - p->add_radio_check_item(TTR("<None>"), 0); - p->add_radio_check_item(TTR("Pixel Snap"), 1); - p->add_radio_check_item(TTR("Grid Snap"), 2); - p->add_radio_check_item(TTR("Auto Slice"), 3); - p->set_item_checked(0, true); - p->connect("id_pressed", this, "_set_snap_mode"); + snap_mode_button->add_item(TTR("None"), 0); + snap_mode_button->add_item(TTR("Pixel Snap"), 1); + snap_mode_button->add_item(TTR("Grid Snap"), 2); + snap_mode_button->add_item(TTR("Auto Slice"), 3); + snap_mode_button->select(0); + snap_mode_button->connect("item_selected", this, "_set_snap_mode"); + hb_grid = memnew(HBoxContainer); hb_tools->add_child(hb_grid); - hb_grid->add_child(memnew(VSeparator)); + hb_grid->add_child(memnew(VSeparator)); hb_grid->add_child(memnew(Label(TTR("Offset:")))); sb_off_x = memnew(SpinBox); @@ -913,42 +928,47 @@ TextureRegionEditor::TextureRegionEditor(EditorNode *p_editor) { hb_grid->hide(); - HBoxContainer *main_hb = memnew(HBoxContainer); - main_vb->add_child(main_hb); - edit_draw = memnew(Control); - main_hb->add_child(edit_draw); - main_hb->set_v_size_flags(SIZE_EXPAND_FILL); - edit_draw->set_h_size_flags(SIZE_EXPAND_FILL); + edit_draw = memnew(Panel); + add_child(edit_draw); + edit_draw->set_v_size_flags(SIZE_EXPAND_FILL); + edit_draw->connect("draw", this, "_region_draw"); + edit_draw->connect("gui_input", this, "_region_input"); + + draw_zoom = 1.0; + edit_draw->set_clip_contents(true); - Control *separator = memnew(Control); - separator->set_h_size_flags(Control::SIZE_EXPAND_FILL); - hb_tools->add_child(separator); + HBoxContainer *zoom_hb = memnew(HBoxContainer); + edit_draw->add_child(zoom_hb); + zoom_hb->set_begin(Point2(5, 5)); zoom_out = memnew(ToolButton); + zoom_out->set_tooltip(TTR("Zoom Out")); zoom_out->connect("pressed", this, "_zoom_out"); - hb_tools->add_child(zoom_out); + zoom_hb->add_child(zoom_out); zoom_reset = memnew(ToolButton); + zoom_out->set_tooltip(TTR("Zoom Reset")); zoom_reset->connect("pressed", this, "_zoom_reset"); - hb_tools->add_child(zoom_reset); + zoom_hb->add_child(zoom_reset); zoom_in = memnew(ToolButton); + zoom_out->set_tooltip(TTR("Zoom In")); zoom_in->connect("pressed", this, "_zoom_in"); - hb_tools->add_child(zoom_in); + zoom_hb->add_child(zoom_in); vscroll = memnew(VScrollBar); - main_hb->add_child(vscroll); + vscroll->set_step(0.001); + edit_draw->add_child(vscroll); + vscroll->set_anchors_and_margins_preset(PRESET_RIGHT_WIDE); vscroll->connect("value_changed", this, "_scroll_changed"); hscroll = memnew(HScrollBar); - main_vb->add_child(hscroll); + hscroll->set_step(0.001); + edit_draw->add_child(hscroll); + hscroll->set_anchors_and_margins_preset(PRESET_BOTTOM_WIDE); + hscroll->set_margin(MARGIN_RIGHT, -vscroll->get_size().x * EDSCALE); hscroll->connect("value_changed", this, "_scroll_changed"); - edit_draw->connect("draw", this, "_region_draw"); - edit_draw->connect("gui_input", this, "_region_input"); - draw_zoom = 1.0; updating_scroll = false; - - edit_draw->set_clip_contents(true); } void TextureRegionEditorPlugin::edit(Object *p_object) { @@ -977,7 +997,6 @@ void TextureRegionEditorPlugin::make_visible(bool p_visible) { Dictionary TextureRegionEditorPlugin::get_state() const { Dictionary state; - state["zoom"] = region_editor->draw_zoom; state["snap_offset"] = region_editor->snap_offset; state["snap_step"] = region_editor->snap_step; state["snap_separation"] = region_editor->snap_separation; @@ -988,10 +1007,6 @@ Dictionary TextureRegionEditorPlugin::get_state() const { void TextureRegionEditorPlugin::set_state(const Dictionary &p_state) { Dictionary state = p_state; - if (state.has("zoom")) { - region_editor->draw_zoom = p_state["zoom"]; - } - if (state.has("snap_step")) { Vector2 s = state["snap_step"]; region_editor->sb_step_x->set_value(s.x); @@ -1015,6 +1030,7 @@ void TextureRegionEditorPlugin::set_state(const Dictionary &p_state) { if (state.has("snap_mode")) { region_editor->_set_snap_mode(state["snap_mode"]); + region_editor->snap_mode_button->select(state["snap_mode"]); } } diff --git a/editor/plugins/texture_region_editor_plugin.h b/editor/plugins/texture_region_editor_plugin.h index 61ef769f89..4f301ea916 100644 --- a/editor/plugins/texture_region_editor_plugin.h +++ b/editor/plugins/texture_region_editor_plugin.h @@ -43,9 +43,9 @@ @author Mariano Suligoy */ -class TextureRegionEditor : public Control { +class TextureRegionEditor : public VBoxContainer { - GDCLASS(TextureRegionEditor, Control); + GDCLASS(TextureRegionEditor, VBoxContainer); enum SnapMode { SNAP_NONE, @@ -55,7 +55,7 @@ class TextureRegionEditor : public Control { }; friend class TextureRegionEditorPlugin; - MenuButton *snap_mode_button; + OptionButton *snap_mode_button; ToolButton *zoom_in; ToolButton *zoom_reset; ToolButton *zoom_out; @@ -66,7 +66,7 @@ class TextureRegionEditor : public Control { SpinBox *sb_off_x; SpinBox *sb_sep_y; SpinBox *sb_sep_x; - Control *edit_draw; + Panel *edit_draw; VScrollBar *vscroll; HScrollBar *hscroll; @@ -111,7 +111,8 @@ class TextureRegionEditor : public Control { void _zoom_in(); void _zoom_reset(); void _zoom_out(); - void apply_rect(const Rect2 &rect); + void apply_rect(const Rect2 &p_rect); + void _update_rect(); void _update_autoslice(); protected: diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp index 27c3ff960b..1d8a80d3f3 100644 --- a/editor/plugins/tile_map_editor_plugin.cpp +++ b/editor/plugins/tile_map_editor_plugin.cpp @@ -31,6 +31,7 @@ #include "tile_map_editor_plugin.h" #include "canvas_item_editor_plugin.h" +#include "core/math/math_funcs.h" #include "core/os/input.h" #include "core/os/keyboard.h" #include "editor/editor_scale.h" @@ -43,8 +44,8 @@ void TileMapEditor::_notification(int p_what) { case NOTIFICATION_PROCESS: { - if (bucket_queue.size() && canvas_item_editor_viewport) { - canvas_item_editor_viewport->update(); + if (bucket_queue.size()) { + CanvasItemEditor::get_singleton()->update_viewport(); } } break; @@ -65,13 +66,11 @@ void TileMapEditor::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { - 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")); - rotate_90->set_icon(get_icon("Rotate90", "EditorIcons")); - rotate_180->set_icon(get_icon("Rotate180", "EditorIcons")); - rotate_270->set_icon(get_icon("Rotate270", "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")); + flip_vertical_button->set_icon(get_icon("MirrorY", "EditorIcons")); + clear_transform_button->set_icon(get_icon("Clear", "EditorIcons")); search_box->set_right_icon(get_icon("Search", "EditorIcons")); search_box->set_clear_button_enabled(true); @@ -97,27 +96,27 @@ void TileMapEditor::_menu_option(int p_option) { // immediately without pressing the left mouse button first tool = TOOL_NONE; - canvas_item_editor_viewport->update(); + CanvasItemEditor::get_singleton()->update_viewport(); } break; case OPTION_BUCKET: { tool = TOOL_BUCKET; - canvas_item_editor_viewport->update(); + CanvasItemEditor::get_singleton()->update_viewport(); } break; case OPTION_PICK_TILE: { tool = TOOL_PICKING; - canvas_item_editor_viewport->update(); + CanvasItemEditor::get_singleton()->update_viewport(); } break; case OPTION_SELECT: { tool = TOOL_SELECTING; selection_active = false; - canvas_item_editor_viewport->update(); + CanvasItemEditor::get_singleton()->update_viewport(); } break; case OPTION_COPY: { @@ -126,7 +125,7 @@ void TileMapEditor::_menu_option(int p_option) { if (selection_active) { tool = TOOL_PASTING; - canvas_item_editor_viewport->update(); + CanvasItemEditor::get_singleton()->update_viewport(); } } break; case OPTION_ERASE_SELECTION: { @@ -141,7 +140,7 @@ void TileMapEditor::_menu_option(int p_option) { selection_active = false; copydata.clear(); - canvas_item_editor_viewport->update(); + CanvasItemEditor::get_singleton()->update_viewport(); } break; case OPTION_FIX_INVALID: { @@ -165,7 +164,7 @@ void TileMapEditor::_menu_option(int p_option) { tool = TOOL_PASTING; - canvas_item_editor_viewport->update(); + CanvasItemEditor::get_singleton()->update_viewport(); } } break; } @@ -182,13 +181,13 @@ void TileMapEditor::_palette_multi_selected(int index, bool selected) { void TileMapEditor::_canvas_mouse_enter() { mouse_over = true; - canvas_item_editor_viewport->update(); + CanvasItemEditor::get_singleton()->update_viewport(); } void TileMapEditor::_canvas_mouse_exit() { mouse_over = false; - canvas_item_editor_viewport->update(); + CanvasItemEditor::get_singleton()->update_viewport(); } Vector<int> TileMapEditor::get_selected_tiles() const { @@ -301,7 +300,7 @@ void TileMapEditor::_set_cell(const Point2i &p_pos, Vector<int> p_values, bool p } node->set_cell(p_pos.x, p_pos.y, p_value, p_flip_h, p_flip_v, p_transpose); - if (manual_autotile || node->get_tileset()->tile_get_tile_mode(p_value) == TileSet::ATLAS_TILE) { + if (manual_autotile || (p_value != -1 && node->get_tileset()->tile_get_tile_mode(p_value) == TileSet::ATLAS_TILE)) { if (current != -1) { node->set_cell_autotile_coord(p_pos.x, p_pos.y, position); } @@ -357,6 +356,10 @@ void TileMapEditor::_update_palette() { if (!node) return; + // Update the clear button + clear_transform_button->set_disabled(!flip_h && !flip_v && !transpose); + + // Update the palette Vector<int> selected = get_selected_tiles(); palette->clear(); manual_palette->clear(); @@ -429,9 +432,6 @@ void TileMapEditor::_update_palette() { Ref<Texture> tex = tileset->tile_get_texture(entries[i].id); if (tex.is_valid()) { - Color color = tileset->tile_get_modulate(entries[i].id); - palette->set_item_icon_modulate(palette->get_item_count() - 1, color); - Rect2 region = tileset->tile_get_region(entries[i].id); if (tileset->tile_get_tile_mode(entries[i].id) == TileSet::AUTO_TILE || tileset->tile_get_tile_mode(entries[i].id) == TileSet::ATLAS_TILE) { @@ -440,10 +440,25 @@ void TileMapEditor::_update_palette() { region.position += (region.size + Vector2(spacing, spacing)) * tileset->autotile_get_icon_coordinate(entries[i].id); } - if (!region.has_no_area()) + // Transpose and flip + palette->set_item_icon_transposed(palette->get_item_count() - 1, transpose); + if (flip_h) { + region.size.x = -region.size.x; + } + if (flip_v) { + region.size.y = -region.size.y; + } + + // Set region + if (region.size != Size2()) palette->set_item_icon_region(palette->get_item_count() - 1, region); + // Set icon palette->set_item_icon(palette->get_item_count() - 1, tex); + + // Modulation + Color color = tileset->tile_get_modulate(entries[i].id); + palette->set_item_icon_modulate(palette->get_item_count() - 1, color); } palette->set_item_metadata(palette->get_item_count() - 1, entries[i].id); @@ -519,12 +534,12 @@ void TileMapEditor::_pick_tile(const Point2 &p_pos) { selected.push_back(id); set_selected_tiles(selected); - 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)); + flip_h = node->is_cell_x_flipped(p_pos.x, p_pos.y); + flip_v = node->is_cell_y_flipped(p_pos.x, p_pos.y); + transpose = node->is_cell_transposed(p_pos.x, p_pos.y); - _update_transform_buttons(); - canvas_item_editor_viewport->update(); + _update_palette(); + CanvasItemEditor::get_singleton()->update_viewport(); } PoolVector<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool erase, bool preview) { @@ -671,7 +686,7 @@ void TileMapEditor::_select(const Point2i &p_from, const Point2i &p_to) { rectangle.position = begin; rectangle.size = end - begin; - canvas_item_editor_viewport->update(); + CanvasItemEditor::get_singleton()->update_viewport(); } void TileMapEditor::_erase_selection() { @@ -978,7 +993,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { paint_undo.clear(); - canvas_item_editor_viewport->update(); + CanvasItemEditor::get_singleton()->update_viewport(); } } else if (tool == TOOL_RECTANGLE_PAINT) { @@ -995,7 +1010,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { } _finish_undo(); - canvas_item_editor_viewport->update(); + CanvasItemEditor::get_singleton()->update_viewport(); } } else if (tool == TOOL_PASTING) { @@ -1011,12 +1026,12 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { } _finish_undo(); - canvas_item_editor_viewport->update(); + CanvasItemEditor::get_singleton()->update_viewport(); return true; // We want to keep the Pasting tool } else if (tool == TOOL_SELECTING) { - canvas_item_editor_viewport->update(); + CanvasItemEditor::get_singleton()->update_viewport(); } else if (tool == TOOL_BUCKET) { @@ -1055,7 +1070,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { tool = TOOL_NONE; selection_active = false; - canvas_item_editor_viewport->update(); + CanvasItemEditor::get_singleton()->update_viewport(); return true; } @@ -1065,7 +1080,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { tool = TOOL_NONE; copydata.clear(); - canvas_item_editor_viewport->update(); + CanvasItemEditor::get_singleton()->update_viewport(); return true; } @@ -1106,7 +1121,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { _finish_undo(); if (tool == TOOL_RECTANGLE_ERASE || tool == TOOL_LINE_ERASE) { - canvas_item_editor_viewport->update(); + CanvasItemEditor::get_singleton()->update_viewport(); } tool = TOOL_NONE; @@ -1149,7 +1164,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { if (new_over_tile != over_tile) { over_tile = new_over_tile; - canvas_item_editor_viewport->update(); + CanvasItemEditor::get_singleton()->update_viewport(); } if (show_tile_info) { @@ -1235,7 +1250,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { _set_cell(points[i], invalid_cell); } - canvas_item_editor_viewport->update(); + CanvasItemEditor::get_singleton()->update_viewport(); } return true; @@ -1294,7 +1309,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { tool = TOOL_NONE; - canvas_item_editor_viewport->update(); + CanvasItemEditor::get_singleton()->update_viewport(); return true; } @@ -1308,13 +1323,13 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { // NOTE: We do not set tool = TOOL_PAINTING as this begins painting // immediately without pressing the left mouse button first tool = TOOL_NONE; - canvas_item_editor_viewport->update(); + CanvasItemEditor::get_singleton()->update_viewport(); return true; } if (ED_IS_SHORTCUT("tile_map_editor/bucket_fill", p_event)) { tool = TOOL_BUCKET; - canvas_item_editor_viewport->update(); + CanvasItemEditor::get_singleton()->update_viewport(); return true; } @@ -1327,7 +1342,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { tool = TOOL_SELECTING; selection_active = false; - canvas_item_editor_viewport->update(); + CanvasItemEditor::get_singleton()->update_viewport(); return true; } @@ -1337,7 +1352,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { if (selection_active) { tool = TOOL_PASTING; - canvas_item_editor_viewport->update(); + CanvasItemEditor::get_singleton()->update_viewport(); return true; } @@ -1354,7 +1369,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { tool = TOOL_PASTING; - canvas_item_editor_viewport->update(); + CanvasItemEditor::get_singleton()->update_viewport(); return true; } } @@ -1366,23 +1381,20 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { } if (ED_IS_SHORTCUT("tile_map_editor/mirror_x", p_event)) { flip_h = !flip_h; - mirror_x->set_pressed(flip_h); - _update_transform_buttons(); - canvas_item_editor_viewport->update(); + _update_palette(); + CanvasItemEditor::get_singleton()->update_viewport(); return true; } if (ED_IS_SHORTCUT("tile_map_editor/mirror_y", p_event)) { flip_v = !flip_v; - mirror_y->set_pressed(flip_v); - _update_transform_buttons(); - canvas_item_editor_viewport->update(); + _update_palette(); + CanvasItemEditor::get_singleton()->update_viewport(); return true; } if (ED_IS_SHORTCUT("tile_map_editor/transpose", p_event)) { transpose = !transpose; - transp->set_pressed(transpose); - _update_transform_buttons(); - canvas_item_editor_viewport->update(); + _update_palette(); + CanvasItemEditor::get_singleton()->update_viewport(); return true; } } @@ -1643,9 +1655,7 @@ void TileMapEditor::edit(Node *p_tile_map) { void TileMapEditor::_tileset_settings_changed() { _update_palette(); - - if (canvas_item_editor_viewport) - canvas_item_editor_viewport->update(); + CanvasItemEditor::get_singleton()->update_viewport(); } void TileMapEditor::_icon_size_changed(float p_value) { @@ -1666,7 +1676,10 @@ void TileMapEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("_canvas_mouse_enter"), &TileMapEditor::_canvas_mouse_enter); ClassDB::bind_method(D_METHOD("_canvas_mouse_exit"), &TileMapEditor::_canvas_mouse_exit); ClassDB::bind_method(D_METHOD("_tileset_settings_changed"), &TileMapEditor::_tileset_settings_changed); - ClassDB::bind_method(D_METHOD("_update_transform_buttons"), &TileMapEditor::_update_transform_buttons); + ClassDB::bind_method(D_METHOD("_rotate"), &TileMapEditor::_rotate); + ClassDB::bind_method(D_METHOD("_flip_horizontal"), &TileMapEditor::_flip_horizontal); + ClassDB::bind_method(D_METHOD("_flip_vertical"), &TileMapEditor::_flip_vertical); + ClassDB::bind_method(D_METHOD("_clear_transform"), &TileMapEditor::_clear_transform); ClassDB::bind_method(D_METHOD("_palette_selected"), &TileMapEditor::_palette_selected); ClassDB::bind_method(D_METHOD("_palette_multi_selected"), &TileMapEditor::_palette_multi_selected); @@ -1691,37 +1704,67 @@ TileMapEditor::CellOp TileMapEditor::_get_op_from_cell(const Point2i &p_pos) { return op; } -void TileMapEditor::_update_transform_buttons(Object *p_button) { - //ERR_FAIL_NULL(p_button); - ToolButton *b = Object::cast_to<ToolButton>(p_button); - //ERR_FAIL_COND(!b); - - if (b == rotate_0) { - mirror_x->set_pressed(false); - mirror_y->set_pressed(false); - transp->set_pressed(false); - } else if (b == rotate_90) { - mirror_x->set_pressed(true); - mirror_y->set_pressed(false); - transp->set_pressed(true); - } else if (b == rotate_180) { - mirror_x->set_pressed(true); - mirror_y->set_pressed(true); - transp->set_pressed(false); - } else if (b == rotate_270) { - mirror_x->set_pressed(false); - mirror_y->set_pressed(true); - transp->set_pressed(true); +void TileMapEditor::_rotate(int steps) { + const bool normal_rotation_matrix[][3] = { + { false, false, false }, + { true, true, false }, + { false, true, true }, + { true, false, true } + }; + + const bool mirrored_rotation_matrix[][3] = { + { false, true, false }, + { true, true, true }, + { false, false, true }, + { true, false, false } + }; + + if (transpose ^ flip_h ^ flip_v) { + // Odd number of flags activated = mirrored rotation + for (int i = 0; i < 4; i++) { + if (transpose == mirrored_rotation_matrix[i][0] && + flip_h == mirrored_rotation_matrix[i][1] && + flip_v == mirrored_rotation_matrix[i][2]) { + int new_id = Math::wrapi(i + steps, 0, 4); + transpose = mirrored_rotation_matrix[new_id][0]; + flip_h = mirrored_rotation_matrix[new_id][1]; + flip_v = mirrored_rotation_matrix[new_id][2]; + break; + } + } + } else { + // Even number of flags activated = normal rotation + for (int i = 0; i < 4; i++) { + if (transpose == normal_rotation_matrix[i][0] && + flip_h == normal_rotation_matrix[i][1] && + flip_v == normal_rotation_matrix[i][2]) { + int new_id = Math::wrapi(i + steps, 0, 4); + transpose = normal_rotation_matrix[new_id][0]; + flip_h = normal_rotation_matrix[new_id][1]; + flip_v = normal_rotation_matrix[new_id][2]; + break; + } + } } - flip_h = mirror_x->is_pressed(); - flip_v = mirror_y->is_pressed(); - transpose = transp->is_pressed(); + _update_palette(); +} + +void TileMapEditor::_flip_horizontal() { + flip_h = !flip_h; + _update_palette(); +} + +void TileMapEditor::_flip_vertical() { + flip_v = !flip_v; + _update_palette(); +} - 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); +void TileMapEditor::_clear_transform() { + transpose = false; + flip_h = false; + flip_v = false; + _update_palette(); } TileMapEditor::TileMapEditor(EditorNode *p_editor) { @@ -1754,10 +1797,8 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { ED_SHORTCUT("tile_map_editor/mirror_x", TTR("Mirror X"), KEY_A); ED_SHORTCUT("tile_map_editor/mirror_y", TTR("Mirror Y"), KEY_S); - HBoxContainer *tool_hb1 = memnew(HBoxContainer); - add_child(tool_hb1); - HBoxContainer *tool_hb2 = memnew(HBoxContainer); - add_child(tool_hb2); + HBoxContainer *tool_hb = memnew(HBoxContainer); + add_child(tool_hb); manual_button = memnew(CheckBox); manual_button->set_text("Disable Autotile"); @@ -1821,7 +1862,7 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { toolbar->add_child(tile_info); options = memnew(MenuButton); - options->set_text("Tile Map"); + options->set_text("TileMap"); options->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("TileMap", "EditorIcons")); options->set_process_unhandled_key_input(false); @@ -1842,52 +1883,37 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { p->connect("id_pressed", this, "_menu_option"); toolbar->add_child(options); - - transp = memnew(ToolButton); - transp->set_toggle_mode(true); - transp->set_tooltip(TTR("Transpose") + " (" + ED_GET_SHORTCUT("tile_map_editor/transpose")->get_as_text() + ")"); - transp->set_focus_mode(FOCUS_NONE); - transp->connect("pressed", this, "_update_transform_buttons", make_binds(transp)); - tool_hb1->add_child(transp); - mirror_x = memnew(ToolButton); - mirror_x->set_toggle_mode(true); - mirror_x->set_tooltip(TTR("Mirror X") + " (" + ED_GET_SHORTCUT("tile_map_editor/mirror_x")->get_as_text() + ")"); - mirror_x->set_focus_mode(FOCUS_NONE); - mirror_x->connect("pressed", this, "_update_transform_buttons", make_binds(mirror_x)); - tool_hb1->add_child(mirror_x); - mirror_y = memnew(ToolButton); - mirror_y->set_toggle_mode(true); - mirror_y->set_tooltip(TTR("Mirror Y") + " (" + ED_GET_SHORTCUT("tile_map_editor/mirror_y")->get_as_text() + ")"); - mirror_y->set_focus_mode(FOCUS_NONE); - mirror_y->connect("pressed", this, "_update_transform_buttons", make_binds(mirror_y)); - tool_hb1->add_child(mirror_y); - - rotate_0 = memnew(ToolButton); - rotate_0->set_toggle_mode(true); - rotate_0->set_tooltip(TTR("Rotate 0 degrees")); - rotate_0->set_focus_mode(FOCUS_NONE); - rotate_0->connect("pressed", this, "_update_transform_buttons", make_binds(rotate_0)); - tool_hb2->add_child(rotate_0); - rotate_90 = memnew(ToolButton); - rotate_90->set_toggle_mode(true); - rotate_90->set_tooltip(TTR("Rotate 90 degrees")); - rotate_90->set_focus_mode(FOCUS_NONE); - rotate_90->connect("pressed", this, "_update_transform_buttons", make_binds(rotate_90)); - tool_hb2->add_child(rotate_90); - rotate_180 = memnew(ToolButton); - rotate_180->set_toggle_mode(true); - rotate_180->set_tooltip(TTR("Rotate 180 degrees")); - rotate_180->set_focus_mode(FOCUS_NONE); - rotate_180->connect("pressed", this, "_update_transform_buttons", make_binds(rotate_180)); - tool_hb2->add_child(rotate_180); - rotate_270 = memnew(ToolButton); - rotate_270->set_toggle_mode(true); - rotate_270->set_tooltip(TTR("Rotate 270 degrees")); - rotate_270->set_focus_mode(FOCUS_NONE); - rotate_270->connect("pressed", this, "_update_transform_buttons", make_binds(rotate_270)); - tool_hb2->add_child(rotate_270); - - rotate_0->set_pressed(true); + rotate_left_button = memnew(ToolButton); + rotate_left_button->set_tooltip(TTR("Rotate left")); + rotate_left_button->set_focus_mode(FOCUS_NONE); + rotate_left_button->connect("pressed", this, "_rotate", varray(-1)); + tool_hb->add_child(rotate_left_button); + + rotate_right_button = memnew(ToolButton); + rotate_right_button->set_tooltip(TTR("Rotate right")); + rotate_right_button->set_focus_mode(FOCUS_NONE); + rotate_right_button->connect("pressed", this, "_rotate", varray(1)); + tool_hb->add_child(rotate_right_button); + + flip_horizontal_button = memnew(ToolButton); + flip_horizontal_button->set_tooltip(TTR("Flip horizontally")); + flip_horizontal_button->set_focus_mode(FOCUS_NONE); + flip_horizontal_button->connect("pressed", this, "_flip_horizontal"); + tool_hb->add_child(flip_horizontal_button); + + flip_vertical_button = memnew(ToolButton); + flip_vertical_button->set_tooltip(TTR("Flip vertically")); + flip_vertical_button->set_focus_mode(FOCUS_NONE); + flip_vertical_button->connect("pressed", this, "_flip_vertical"); + tool_hb->add_child(flip_vertical_button); + + clear_transform_button = memnew(ToolButton); + clear_transform_button->set_tooltip(TTR("Clear transform")); + clear_transform_button->set_focus_mode(FOCUS_NONE); + clear_transform_button->connect("pressed", this, "_clear_transform"); + tool_hb->add_child(clear_transform_button); + + clear_transform_button->set_disabled(true); } TileMapEditor::~TileMapEditor() { diff --git a/editor/plugins/tile_map_editor_plugin.h b/editor/plugins/tile_map_editor_plugin.h index 3d44647a1b..68e5806ee5 100644 --- a/editor/plugins/tile_map_editor_plugin.h +++ b/editor/plugins/tile_map_editor_plugin.h @@ -93,13 +93,13 @@ class TileMapEditor : public VBoxContainer { Label *tile_info; MenuButton *options; - ToolButton *transp; - ToolButton *mirror_x; - ToolButton *mirror_y; - ToolButton *rotate_0; - ToolButton *rotate_90; - ToolButton *rotate_180; - ToolButton *rotate_270; + + ToolButton *flip_horizontal_button; + ToolButton *flip_vertical_button; + ToolButton *rotate_left_button; + ToolButton *rotate_right_button; + ToolButton *clear_transform_button; + CheckBox *manual_button; Tool tool; @@ -196,11 +196,15 @@ class TileMapEditor : public VBoxContainer { void _tileset_settings_changed(); void _icon_size_changed(float p_value); + void _clear_transform(); + void _flip_horizontal(); + void _flip_vertical(); + void _rotate(int steps); + protected: void _notification(int p_what); static void _bind_methods(); CellOp _get_op_from_cell(const Point2i &p_pos); - void _update_transform_buttons(Object *p_button = NULL); public: HBoxContainer *get_toolbar() const { return toolbar; } diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp index 3de2284cea..cab9a4297d 100644 --- a/editor/plugins/tile_set_editor_plugin.cpp +++ b/editor/plugins/tile_set_editor_plugin.cpp @@ -172,6 +172,7 @@ Error TileSetEditor::update_library_file(Node *p_base_scene, Ref<TileSet> ml, bo } void TileSetEditor::_bind_methods() { + ClassDB::bind_method("_on_tileset_toolbar_button_pressed", &TileSetEditor::_on_tileset_toolbar_button_pressed); ClassDB::bind_method("_on_textures_added", &TileSetEditor::_on_textures_added); ClassDB::bind_method("_on_tileset_toolbar_confirm", &TileSetEditor::_on_tileset_toolbar_confirm); @@ -184,58 +185,69 @@ void TileSetEditor::_bind_methods() { ClassDB::bind_method("_on_workspace_input", &TileSetEditor::_on_workspace_input); ClassDB::bind_method("_on_tool_clicked", &TileSetEditor::_on_tool_clicked); ClassDB::bind_method("_on_priority_changed", &TileSetEditor::_on_priority_changed); + ClassDB::bind_method("_on_z_index_changed", &TileSetEditor::_on_z_index_changed); ClassDB::bind_method("_on_grid_snap_toggled", &TileSetEditor::_on_grid_snap_toggled); ClassDB::bind_method("_set_snap_step", &TileSetEditor::_set_snap_step); ClassDB::bind_method("_set_snap_off", &TileSetEditor::_set_snap_off); ClassDB::bind_method("_set_snap_sep", &TileSetEditor::_set_snap_sep); + ClassDB::bind_method("_zoom_in", &TileSetEditor::_zoom_in); + ClassDB::bind_method("_zoom_out", &TileSetEditor::_zoom_out); + ClassDB::bind_method("_zoom_reset", &TileSetEditor::_zoom_reset); } void TileSetEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { - - tileset_toolbar_buttons[TOOL_TILESET_ADD_TEXTURE]->set_icon(get_icon("ToolAddNode", "EditorIcons")); - tileset_toolbar_buttons[TOOL_TILESET_REMOVE_TEXTURE]->set_icon(get_icon("Remove", "EditorIcons")); - tileset_toolbar_tools->set_icon(get_icon("Tools", "EditorIcons")); - - tool_workspacemode[WORKSPACE_EDIT]->set_icon(get_icon("Edit", "EditorIcons")); - tool_workspacemode[WORKSPACE_CREATE_SINGLE]->set_icon(get_icon("AddSingleTile", "EditorIcons")); - tool_workspacemode[WORKSPACE_CREATE_AUTOTILE]->set_icon(get_icon("AddAutotile", "EditorIcons")); - tool_workspacemode[WORKSPACE_CREATE_ATLAS]->set_icon(get_icon("AddAtlasTile", "EditorIcons")); - - tools[TOOL_SELECT]->set_icon(get_icon("ToolSelect", "EditorIcons")); - tools[BITMASK_COPY]->set_icon(get_icon("Duplicate", "EditorIcons")); - tools[BITMASK_PASTE]->set_icon(get_icon("Override", "EditorIcons")); - tools[BITMASK_CLEAR]->set_icon(get_icon("Clear", "EditorIcons")); - tools[SHAPE_NEW_POLYGON]->set_icon(get_icon("CollisionPolygon2D", "EditorIcons")); - tools[SHAPE_DELETE]->set_icon(get_icon("Remove", "EditorIcons")); - tools[SHAPE_KEEP_INSIDE_TILE]->set_icon(get_icon("Snap", "EditorIcons")); - tools[TOOL_GRID_SNAP]->set_icon(get_icon("SnapGrid", "EditorIcons")); - tools[ZOOM_OUT]->set_icon(get_icon("ZoomLess", "EditorIcons")); - tools[ZOOM_1]->set_icon(get_icon("ZoomReset", "EditorIcons")); - tools[ZOOM_IN]->set_icon(get_icon("ZoomMore", "EditorIcons")); - tools[VISIBLE_INFO]->set_icon(get_icon("InformationSign", "EditorIcons")); - - tool_editmode[EDITMODE_REGION]->set_icon(get_icon("RegionEdit", "EditorIcons")); - tool_editmode[EDITMODE_COLLISION]->set_icon(get_icon("StaticBody2D", "EditorIcons")); - tool_editmode[EDITMODE_OCCLUSION]->set_icon(get_icon("LightOccluder2D", "EditorIcons")); - tool_editmode[EDITMODE_NAVIGATION]->set_icon(get_icon("Navigation2D", "EditorIcons")); - tool_editmode[EDITMODE_BITMASK]->set_icon(get_icon("PackedDataContainer", "EditorIcons")); - tool_editmode[EDITMODE_PRIORITY]->set_icon(get_icon("MaterialPreviewLight1", "EditorIcons")); - tool_editmode[EDITMODE_ICON]->set_icon(get_icon("LargeTexture", "EditorIcons")); + + switch (p_what) { + case NOTIFICATION_READY: { + + add_constant_override("autohide", 1); // Fixes the dragger always showing up. + } break; + case NOTIFICATION_ENTER_TREE: + case NOTIFICATION_THEME_CHANGED: { + + tileset_toolbar_buttons[TOOL_TILESET_ADD_TEXTURE]->set_icon(get_icon("ToolAddNode", "EditorIcons")); + tileset_toolbar_buttons[TOOL_TILESET_REMOVE_TEXTURE]->set_icon(get_icon("Remove", "EditorIcons")); + tileset_toolbar_tools->set_icon(get_icon("Tools", "EditorIcons")); + + tool_workspacemode[WORKSPACE_EDIT]->set_icon(get_icon("Edit", "EditorIcons")); + tool_workspacemode[WORKSPACE_CREATE_SINGLE]->set_icon(get_icon("AddSingleTile", "EditorIcons")); + tool_workspacemode[WORKSPACE_CREATE_AUTOTILE]->set_icon(get_icon("AddAutotile", "EditorIcons")); + tool_workspacemode[WORKSPACE_CREATE_ATLAS]->set_icon(get_icon("AddAtlasTile", "EditorIcons")); + + tools[TOOL_SELECT]->set_icon(get_icon("ToolSelect", "EditorIcons")); + tools[BITMASK_COPY]->set_icon(get_icon("Duplicate", "EditorIcons")); + tools[BITMASK_PASTE]->set_icon(get_icon("Override", "EditorIcons")); + tools[BITMASK_CLEAR]->set_icon(get_icon("Clear", "EditorIcons")); + tools[SHAPE_NEW_POLYGON]->set_icon(get_icon("CollisionPolygon2D", "EditorIcons")); + tools[SHAPE_DELETE]->set_icon(get_icon("Remove", "EditorIcons")); + tools[SHAPE_KEEP_INSIDE_TILE]->set_icon(get_icon("Snap", "EditorIcons")); + tools[TOOL_GRID_SNAP]->set_icon(get_icon("SnapGrid", "EditorIcons")); + tools[ZOOM_OUT]->set_icon(get_icon("ZoomLess", "EditorIcons")); + tools[ZOOM_1]->set_icon(get_icon("ZoomReset", "EditorIcons")); + tools[ZOOM_IN]->set_icon(get_icon("ZoomMore", "EditorIcons")); + tools[VISIBLE_INFO]->set_icon(get_icon("InformationSign", "EditorIcons")); + + tool_editmode[EDITMODE_REGION]->set_icon(get_icon("RegionEdit", "EditorIcons")); + tool_editmode[EDITMODE_COLLISION]->set_icon(get_icon("StaticBody2D", "EditorIcons")); + tool_editmode[EDITMODE_OCCLUSION]->set_icon(get_icon("LightOccluder2D", "EditorIcons")); + tool_editmode[EDITMODE_NAVIGATION]->set_icon(get_icon("Navigation2D", "EditorIcons")); + tool_editmode[EDITMODE_BITMASK]->set_icon(get_icon("PackedDataContainer", "EditorIcons")); + tool_editmode[EDITMODE_PRIORITY]->set_icon(get_icon("MaterialPreviewLight1", "EditorIcons")); + tool_editmode[EDITMODE_ICON]->set_icon(get_icon("LargeTexture", "EditorIcons")); + tool_editmode[EDITMODE_Z_INDEX]->set_icon(get_icon("Sort", "EditorIcons")); + + scroll->add_style_override("bg", get_stylebox("bg", "Tree")); + } break; } } TileSetEditor::TileSetEditor(EditorNode *p_editor) { editor = p_editor; - set_name("Tile Set Bottom Editor"); - - HSplitContainer *split = memnew(HSplitContainer); - split->set_anchors_and_margins_preset(PRESET_WIDE, PRESET_MODE_MINSIZE, 10); - add_child(split); + current_tile = -1; VBoxContainer *left_container = memnew(VBoxContainer); - split->add_child(left_container); + add_child(left_container); texture_list = memnew(ItemList); left_container->add_child(texture_list); @@ -247,30 +259,22 @@ TileSetEditor::TileSetEditor(EditorNode *p_editor) { left_container->add_child(tileset_toolbar_container); tileset_toolbar_buttons[TOOL_TILESET_ADD_TEXTURE] = memnew(ToolButton); - Vector<Variant> p; - p.push_back((int)TOOL_TILESET_ADD_TEXTURE); - tileset_toolbar_buttons[TOOL_TILESET_ADD_TEXTURE]->connect("pressed", this, "_on_tileset_toolbar_button_pressed", p); + tileset_toolbar_buttons[TOOL_TILESET_ADD_TEXTURE]->connect("pressed", this, "_on_tileset_toolbar_button_pressed", varray(TOOL_TILESET_ADD_TEXTURE)); tileset_toolbar_container->add_child(tileset_toolbar_buttons[TOOL_TILESET_ADD_TEXTURE]); - tileset_toolbar_buttons[TOOL_TILESET_ADD_TEXTURE]->set_tooltip(TTR("Add Texture(s) to TileSet")); + tileset_toolbar_buttons[TOOL_TILESET_ADD_TEXTURE]->set_tooltip(TTR("Add Texture(s) to TileSet.")); tileset_toolbar_buttons[TOOL_TILESET_REMOVE_TEXTURE] = memnew(ToolButton); - p = Vector<Variant>(); - p.push_back((int)TOOL_TILESET_REMOVE_TEXTURE); - tileset_toolbar_buttons[TOOL_TILESET_REMOVE_TEXTURE]->connect("pressed", this, "_on_tileset_toolbar_button_pressed", p); + tileset_toolbar_buttons[TOOL_TILESET_REMOVE_TEXTURE]->connect("pressed", this, "_on_tileset_toolbar_button_pressed", varray(TOOL_TILESET_REMOVE_TEXTURE)); tileset_toolbar_container->add_child(tileset_toolbar_buttons[TOOL_TILESET_REMOVE_TEXTURE]); - tileset_toolbar_buttons[TOOL_TILESET_REMOVE_TEXTURE]->set_tooltip(TTR("Remove current Texture from TileSet")); + tileset_toolbar_buttons[TOOL_TILESET_REMOVE_TEXTURE]->set_tooltip(TTR("Remove selected Texture from TileSet.")); Control *toolbar_separator = memnew(Control); toolbar_separator->set_h_size_flags(Control::SIZE_EXPAND_FILL); tileset_toolbar_container->add_child(toolbar_separator); tileset_toolbar_tools = memnew(MenuButton); - tileset_toolbar_tools->set_text("Tools"); - p = Vector<Variant>(); - p.push_back((int)TOOL_TILESET_CREATE_SCENE); + tileset_toolbar_tools->set_text(TTR("Tools")); tileset_toolbar_tools->get_popup()->add_item(TTR("Create from Scene"), TOOL_TILESET_CREATE_SCENE); - p = Vector<Variant>(); - p.push_back((int)TOOL_TILESET_MERGE_SCENE); tileset_toolbar_tools->get_popup()->add_item(TTR("Merge from Scene"), TOOL_TILESET_MERGE_SCENE); tileset_toolbar_tools->get_popup()->connect("id_pressed", this, "_on_tileset_toolbar_button_pressed"); @@ -279,7 +283,7 @@ TileSetEditor::TileSetEditor(EditorNode *p_editor) { //--------------- VBoxContainer *right_container = memnew(VBoxContainer); right_container->set_v_size_flags(SIZE_EXPAND_FILL); - split->add_child(right_container); + add_child(right_container); dragging_point = -1; creating_shape = false; @@ -296,21 +300,18 @@ TileSetEditor::TileSetEditor(EditorNode *p_editor) { Ref<ButtonGroup> g(memnew(ButtonGroup)); String workspace_label[WORKSPACE_MODE_MAX] = { "Edit", "New Single Tile", "New Autotile", "New Atlas" }; - for (int i = 0; i < (int)WORKSPACE_MODE_MAX; i++) { tool_workspacemode[i] = memnew(Button); - tool_workspacemode[i]->set_text(workspace_label[i]); + tool_workspacemode[i]->set_text(TTR(workspace_label[i])); tool_workspacemode[i]->set_toggle_mode(true); tool_workspacemode[i]->set_button_group(g); - Vector<Variant> p; - p.push_back(i); - tool_workspacemode[i]->connect("pressed", this, "_on_workspace_mode_changed", p); + tool_workspacemode[i]->connect("pressed", this, "_on_workspace_mode_changed", varray(i)); tool_hb->add_child(tool_workspacemode[i]); } Control *spacer = memnew(Control); spacer->set_h_size_flags(Control::SIZE_EXPAND_FILL); tool_hb->add_child(spacer); - tool_hb->move_child(spacer, (int)WORKSPACE_CREATE_SINGLE); + tool_hb->move_child(spacer, WORKSPACE_CREATE_SINGLE); tool_workspacemode[WORKSPACE_EDIT]->set_pressed(true); workspace_mode = WORKSPACE_EDIT; @@ -321,16 +322,13 @@ TileSetEditor::TileSetEditor(EditorNode *p_editor) { tool_hb = memnew(HBoxContainer); g = Ref<ButtonGroup>(memnew(ButtonGroup)); - String label[EDITMODE_MAX] = { "Region", "Collision", "Occlusion", "Navigation", "Bitmask", "Priority", "Icon" }; - + String label[EDITMODE_MAX] = { "Region", "Collision", "Occlusion", "Navigation", "Bitmask", "Priority", "Icon", "Z Index" }; for (int i = 0; i < (int)EDITMODE_MAX; i++) { tool_editmode[i] = memnew(Button); tool_editmode[i]->set_text(label[i]); tool_editmode[i]->set_toggle_mode(true); tool_editmode[i]->set_button_group(g); - Vector<Variant> p; - p.push_back(i); - tool_editmode[i]->connect("pressed", this, "_on_edit_mode_changed", p); + tool_editmode[i]->connect("pressed", this, "_on_edit_mode_changed", varray(i)); tool_hb->add_child(tool_editmode[i]); } tool_editmode[EDITMODE_COLLISION]->set_pressed(true); @@ -343,42 +341,38 @@ TileSetEditor::TileSetEditor(EditorNode *p_editor) { toolbar = memnew(HBoxContainer); Ref<ButtonGroup> tg(memnew(ButtonGroup)); - p = Vector<Variant>(); tools[TOOL_SELECT] = memnew(ToolButton); toolbar->add_child(tools[TOOL_SELECT]); - tools[TOOL_SELECT]->set_tooltip(TTR("Select sub-tile to use as icon, this will be also used on invalid autotile bindings.")); tools[TOOL_SELECT]->set_toggle_mode(true); tools[TOOL_SELECT]->set_button_group(tg); tools[TOOL_SELECT]->set_pressed(true); - p.push_back((int)TOOL_SELECT); - tools[TOOL_SELECT]->connect("pressed", this, "_on_tool_clicked", p); + tools[TOOL_SELECT]->connect("pressed", this, "_on_tool_clicked", varray(TOOL_SELECT)); + separator_bitmask = memnew(VSeparator); + toolbar->add_child(separator_bitmask); tools[BITMASK_COPY] = memnew(ToolButton); - p.push_back((int)BITMASK_COPY); - tools[BITMASK_COPY]->connect("pressed", this, "_on_tool_clicked", p); + tools[BITMASK_COPY]->set_tooltip(TTR("Copy bitmask.")); + tools[BITMASK_COPY]->connect("pressed", this, "_on_tool_clicked", varray(BITMASK_COPY)); toolbar->add_child(tools[BITMASK_COPY]); tools[BITMASK_PASTE] = memnew(ToolButton); - p = Vector<Variant>(); - p.push_back((int)BITMASK_PASTE); - tools[BITMASK_PASTE]->connect("pressed", this, "_on_tool_clicked", p); + tools[BITMASK_PASTE]->set_tooltip(TTR("Paste bitmask.")); + tools[BITMASK_PASTE]->connect("pressed", this, "_on_tool_clicked", varray(BITMASK_PASTE)); toolbar->add_child(tools[BITMASK_PASTE]); tools[BITMASK_CLEAR] = memnew(ToolButton); - p = Vector<Variant>(); - p.push_back((int)BITMASK_CLEAR); - tools[BITMASK_CLEAR]->connect("pressed", this, "_on_tool_clicked", p); + tools[BITMASK_CLEAR]->set_tooltip(TTR("Erase bitmask.")); + tools[BITMASK_CLEAR]->connect("pressed", this, "_on_tool_clicked", varray(BITMASK_CLEAR)); toolbar->add_child(tools[BITMASK_CLEAR]); tools[SHAPE_NEW_POLYGON] = memnew(ToolButton); toolbar->add_child(tools[SHAPE_NEW_POLYGON]); tools[SHAPE_NEW_POLYGON]->set_toggle_mode(true); tools[SHAPE_NEW_POLYGON]->set_button_group(tg); + tools[SHAPE_NEW_POLYGON]->set_tooltip(TTR("Create a new polygon.")); separator_delete = memnew(VSeparator); toolbar->add_child(separator_delete); tools[SHAPE_DELETE] = memnew(ToolButton); - p = Vector<Variant>(); - p.push_back((int)SHAPE_DELETE); - tools[SHAPE_DELETE]->connect("pressed", this, "_on_tool_clicked", p); + tools[SHAPE_DELETE]->connect("pressed", this, "_on_tool_clicked", varray(SHAPE_DELETE)); toolbar->add_child(tools[SHAPE_DELETE]); separator_grid = memnew(VSeparator); @@ -386,9 +380,11 @@ TileSetEditor::TileSetEditor(EditorNode *p_editor) { tools[SHAPE_KEEP_INSIDE_TILE] = memnew(ToolButton); tools[SHAPE_KEEP_INSIDE_TILE]->set_toggle_mode(true); tools[SHAPE_KEEP_INSIDE_TILE]->set_pressed(true); + tools[SHAPE_KEEP_INSIDE_TILE]->set_tooltip(TTR("Keep polygon inside region Rect.")); toolbar->add_child(tools[SHAPE_KEEP_INSIDE_TILE]); tools[TOOL_GRID_SNAP] = memnew(ToolButton); tools[TOOL_GRID_SNAP]->set_toggle_mode(true); + tools[TOOL_GRID_SNAP]->set_tooltip(TTR("Enable snap and show grid (configurable via the Inspector).")); tools[TOOL_GRID_SNAP]->connect("toggled", this, "_on_grid_snap_toggled"); toolbar->add_child(tools[TOOL_GRID_SNAP]); @@ -401,32 +397,35 @@ TileSetEditor::TileSetEditor(EditorNode *p_editor) { spin_priority->hide(); toolbar->add_child(spin_priority); + spin_z_index = memnew(SpinBox); + spin_z_index->set_min(VS::CANVAS_ITEM_Z_MIN); + spin_z_index->set_max(VS::CANVAS_ITEM_Z_MAX); + spin_z_index->set_step(1); + spin_z_index->set_custom_minimum_size(Size2(100, 0)); + spin_z_index->connect("value_changed", this, "_on_z_index_changed"); + spin_z_index->hide(); + toolbar->add_child(spin_z_index); + Control *separator = memnew(Control); separator->set_h_size_flags(SIZE_EXPAND_FILL); toolbar->add_child(separator); tools[ZOOM_OUT] = memnew(ToolButton); - p = Vector<Variant>(); - p.push_back((int)ZOOM_OUT); - tools[ZOOM_OUT]->connect("pressed", this, "_on_tool_clicked", p); + tools[ZOOM_OUT]->connect("pressed", this, "_zoom_out"); toolbar->add_child(tools[ZOOM_OUT]); tools[ZOOM_OUT]->set_tooltip(TTR("Zoom Out")); tools[ZOOM_1] = memnew(ToolButton); - p = Vector<Variant>(); - p.push_back((int)ZOOM_1); - tools[ZOOM_1]->connect("pressed", this, "_on_tool_clicked", p); + tools[ZOOM_1]->connect("pressed", this, "_zoom_reset"); toolbar->add_child(tools[ZOOM_1]); - tools[ZOOM_1]->set_tooltip(TTR("Reset Zoom")); + tools[ZOOM_1]->set_tooltip(TTR("Zoom Reset")); tools[ZOOM_IN] = memnew(ToolButton); - p = Vector<Variant>(); - p.push_back((int)ZOOM_IN); - tools[ZOOM_IN]->connect("pressed", this, "_on_tool_clicked", p); + tools[ZOOM_IN]->connect("pressed", this, "_zoom_in"); toolbar->add_child(tools[ZOOM_IN]); tools[ZOOM_IN]->set_tooltip(TTR("Zoom In")); tools[VISIBLE_INFO] = memnew(ToolButton); tools[VISIBLE_INFO]->set_toggle_mode(true); - tools[VISIBLE_INFO]->set_tooltip(TTR("Display tile's names (hold Alt Key)")); + tools[VISIBLE_INFO]->set_tooltip(TTR("Display Tile Names (Hold Alt Key)")); toolbar->add_child(tools[VISIBLE_INFO]); main_vb->add_child(toolbar); @@ -483,6 +482,11 @@ TileSetEditor::TileSetEditor(EditorNode *p_editor) { //--------------- helper = memnew(TilesetEditorContext(this)); tile_names_opacity = 0; + + // config scale + max_scale = 10.0f; + min_scale = 0.1f; + scale_ratio = 1.2f; } TileSetEditor::~TileSetEditor() { @@ -569,6 +573,10 @@ void TileSetEditor::_on_textures_added(const PoolStringArray &p_paths) { int invalid_count = 0; for (int i = 0; i < p_paths.size(); i++) { Ref<Texture> t = Ref<Texture>(ResourceLoader::load(p_paths[i])); + + ERR_EXPLAIN("'" + p_paths[i] + "' is not a valid texture."); + ERR_CONTINUE(!t.is_valid()); + if (texture_map.has(t->get_rid())) { invalid_count++; } else { @@ -577,9 +585,13 @@ void TileSetEditor::_on_textures_added(const PoolStringArray &p_paths) { texture_list->set_item_metadata(texture_list->get_item_count() - 1, t->get_rid()); } } - update_texture_list_icon(); - texture_list->select(texture_list->get_item_count() - 1); - _on_texture_list_selected(texture_list->get_item_count() - 1); + + if (texture_list->get_item_count() > 0) { + update_texture_list_icon(); + texture_list->select(texture_list->get_item_count() - 1); + _on_texture_list_selected(texture_list->get_item_count() - 1); + } + if (invalid_count > 0) { err_dialog->set_text(vformat(TTR("%s file(s) were not added because was already on the list."), String::num(invalid_count, 0))); err_dialog->popup_centered(Size2(300, 60)); @@ -587,10 +599,14 @@ void TileSetEditor::_on_textures_added(const PoolStringArray &p_paths) { } void TileSetEditor::_on_edit_mode_changed(int p_edit_mode) { + draw_handles = false; + creating_shape = false; edit_mode = (EditMode)p_edit_mode; switch (edit_mode) { case EDITMODE_REGION: { tools[TOOL_SELECT]->show(); + + separator_bitmask->hide(); tools[BITMASK_COPY]->hide(); tools[BITMASK_PASTE]->hide(); tools[BITMASK_CLEAR]->hide(); @@ -610,30 +626,16 @@ void TileSetEditor::_on_edit_mode_changed(int p_edit_mode) { tools[TOOL_SELECT]->set_pressed(true); tools[TOOL_SELECT]->set_tooltip(TTR("Drag handles to edit Rect.\nClick on another Tile to edit it.")); + tools[SHAPE_DELETE]->set_tooltip(TTR("Delete selected Rect.")); spin_priority->hide(); - } break; - case EDITMODE_BITMASK: { - tools[TOOL_SELECT]->show(); - tools[BITMASK_COPY]->show(); - tools[BITMASK_PASTE]->show(); - tools[BITMASK_CLEAR]->show(); - tools[SHAPE_NEW_POLYGON]->hide(); - - separator_delete->hide(); - tools[SHAPE_DELETE]->hide(); - - separator_grid->hide(); - tools[SHAPE_KEEP_INSIDE_TILE]->hide(); - tools[TOOL_GRID_SNAP]->hide(); - - tools[TOOL_SELECT]->set_pressed(true); - tools[TOOL_SELECT]->set_tooltip(TTR("LMB: set bit on.\nRMB: set bit off.\nClick on another Tile to edit it.")); - spin_priority->hide(); + spin_z_index->hide(); } break; case EDITMODE_COLLISION: case EDITMODE_NAVIGATION: case EDITMODE_OCCLUSION: { tools[TOOL_SELECT]->show(); + + separator_bitmask->hide(); tools[BITMASK_COPY]->hide(); tools[BITMASK_PASTE]->hide(); tools[BITMASK_CLEAR]->hide(); @@ -647,11 +649,38 @@ void TileSetEditor::_on_edit_mode_changed(int p_edit_mode) { tools[TOOL_GRID_SNAP]->show(); tools[TOOL_SELECT]->set_tooltip(TTR("Select current edited sub-tile.\nClick on another Tile to edit it.")); + tools[SHAPE_DELETE]->set_tooltip(TTR("Delete polygon.")); spin_priority->hide(); + spin_z_index->hide(); + select_coord(edited_shape_coord); } break; - default: { + case EDITMODE_BITMASK: { + tools[TOOL_SELECT]->show(); + + separator_bitmask->show(); + tools[BITMASK_COPY]->show(); + tools[BITMASK_PASTE]->show(); + tools[BITMASK_CLEAR]->show(); + tools[SHAPE_NEW_POLYGON]->hide(); + + separator_delete->hide(); + tools[SHAPE_DELETE]->hide(); + + separator_grid->hide(); + tools[SHAPE_KEEP_INSIDE_TILE]->hide(); + tools[TOOL_GRID_SNAP]->hide(); + + tools[TOOL_SELECT]->set_pressed(true); + tools[TOOL_SELECT]->set_tooltip(TTR("LMB: Set bit on.\nRMB: Set bit off.\nClick on another Tile to edit it.")); + spin_priority->hide(); + } break; + case EDITMODE_Z_INDEX: + case EDITMODE_PRIORITY: + case EDITMODE_ICON: { tools[TOOL_SELECT]->show(); + + separator_bitmask->hide(); tools[BITMASK_COPY]->hide(); tools[BITMASK_PASTE]->hide(); tools[BITMASK_CLEAR]->hide(); @@ -667,11 +696,18 @@ void TileSetEditor::_on_edit_mode_changed(int p_edit_mode) { if (edit_mode == EDITMODE_ICON) { tools[TOOL_SELECT]->set_tooltip(TTR("Select sub-tile to use as icon, this will be also used on invalid autotile bindings.\nClick on another Tile to edit it.")); spin_priority->hide(); - } else { + spin_z_index->hide(); + } else if (edit_mode == EDITMODE_PRIORITY) { tools[TOOL_SELECT]->set_tooltip(TTR("Select sub-tile to change its priority.\nClick on another Tile to edit it.")); spin_priority->show(); + spin_z_index->hide(); + } else { + tools[TOOL_SELECT]->set_tooltip(TTR("Select sub-tile to change its z index.\nClick on another Tile to edit it.")); + spin_priority->hide(); + spin_z_index->show(); } } break; + default: {} } workspace->update(); } @@ -693,15 +729,16 @@ void TileSetEditor::_on_workspace_mode_changed(int p_workspace_mode) { void TileSetEditor::_on_workspace_draw() { - const Color COLOR_AUTOTILE = Color(0.266373, 0.565288, 0.988281); - const Color COLOR_SINGLE = Color(0.988281, 0.909323, 0.266373); - const Color COLOR_ATLAS = Color(0.78653, 0.812835, 0.832031); - - if (tileset.is_null()) - return; - if (!get_current_texture().is_valid()) + if (tileset.is_null() || !get_current_texture().is_valid()) return; + const Color COLOR_AUTOTILE = Color(0.3, 0.6, 1); + const Color COLOR_SINGLE = Color(1, 1, 0.3); + const Color COLOR_ATLAS = Color(0.8, 0.8, 0.8); + const Color COLOR_SUBDIVISION = Color(0.3, 0.7, 0.6); + + draw_handles = false; + draw_highlight_current_tile(); draw_grid_snap(); @@ -795,10 +832,12 @@ void TileSetEditor::_on_workspace_draw() { spin_priority->set_suffix(" / " + String::num(total, 0)); draw_highlight_subtile(edited_shape_coord, queue_others); } break; + case EDITMODE_Z_INDEX: { + spin_z_index->set_value(tileset->autotile_get_z_index(get_current_tile(), edited_shape_coord)); + draw_highlight_subtile(edited_shape_coord); + } break; default: {} } - - draw_tile_subdivision(get_current_tile(), Color(0.347214, 0.722656, 0.617063)); } RID current_texture_rid = get_current_texture()->get_rid(); @@ -806,7 +845,7 @@ void TileSetEditor::_on_workspace_draw() { tileset->get_tile_list(tiles); for (List<int>::Element *E = tiles->front(); E; E = E->next()) { int t_id = E->get(); - if (tileset->tile_get_texture(t_id)->get_rid() == current_texture_rid && (t_id != get_current_tile() || edit_mode != EDITMODE_REGION)) { + if (tileset->tile_get_texture(t_id)->get_rid() == current_texture_rid && (t_id != get_current_tile() || edit_mode != EDITMODE_REGION || workspace_mode != WORKSPACE_EDIT)) { Rect2i region = tileset->tile_get_region(t_id); region.position += WORKSPACE_MARGIN; Color c; @@ -816,10 +855,11 @@ void TileSetEditor::_on_workspace_draw() { c = COLOR_AUTOTILE; else if (tileset->tile_get_tile_mode(t_id) == TileSet::ATLAS_TILE) c = COLOR_ATLAS; - draw_tile_subdivision(t_id, Color(0.347214, 0.722656, 0.617063, 0.5)); + draw_tile_subdivision(t_id, COLOR_SUBDIVISION); workspace->draw_rect(region, c, false); } } + if (edit_mode == EDITMODE_REGION) { if (workspace_mode != WORKSPACE_EDIT) { Rect2i region = edited_region; @@ -841,6 +881,12 @@ void TileSetEditor::_on_workspace_draw() { region = tileset->tile_get_region(t_id); region.position += WORKSPACE_MARGIN; } + + if (draw_edited_region) + draw_edited_region_subdivision(); + else + draw_tile_subdivision(t_id, COLOR_SUBDIVISION); + Color c; if (tileset->tile_get_tile_mode(t_id) == TileSet::SINGLE_TILE) c = COLOR_SINGLE; @@ -848,13 +894,10 @@ void TileSetEditor::_on_workspace_draw() { c = COLOR_AUTOTILE; else if (tileset->tile_get_tile_mode(t_id) == TileSet::ATLAS_TILE) c = COLOR_ATLAS; - if (draw_edited_region) - draw_edited_region_subdivision(); - else - draw_tile_subdivision(t_id, Color(0.347214, 0.722656, 0.617063, 1)); workspace->draw_rect(region, c, false); } } + workspace_overlay->update(); } @@ -874,9 +917,7 @@ void TileSetEditor::_on_workspace_process() { void TileSetEditor::_on_workspace_overlay_draw() { - if (!tileset.is_valid()) - return; - if (!get_current_texture().is_valid()) + if (!tileset.is_valid() || !get_current_texture().is_valid()) return; const Color COLOR_AUTOTILE = Color(0.266373, 0.565288, 0.988281); @@ -926,9 +967,8 @@ void TileSetEditor::_on_workspace_overlay_draw() { #define MIN_DISTANCE_SQUARED 6 void TileSetEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) { - if (tileset.is_null()) - return; - if (!get_current_texture().is_valid()) + + if (tileset.is_null() || !get_current_texture().is_valid()) return; static bool dragging; @@ -945,7 +985,7 @@ void TileSetEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) { Ref<InputEventMouseMotion> mm = p_ie; if (mb.is_valid()) { - if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { + if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT && !creating_shape) { if (!current_tile_region.has_point(mb->get_position())) { List<int> *tiles = new List<int>(); tileset->get_tile_list(tiles); @@ -964,6 +1004,13 @@ void TileSetEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) { } } } + + // Mouse Wheel Event + if (mb->get_button_index() == BUTTON_WHEEL_UP && mb->is_pressed() && mb->get_control()) { + _zoom_in(); + } else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && mb->is_pressed() && mb->get_control()) { + _zoom_out(); + } } // Drag Middle Mouse if (mm.is_valid()) { @@ -1010,10 +1057,14 @@ void TileSetEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) { tileset->tile_set_tile_mode(t_id, workspace_mode == WORKSPACE_CREATE_AUTOTILE ? TileSet::AUTO_TILE : TileSet::ATLAS_TILE); } set_current_tile(t_id); + tool_workspacemode[WORKSPACE_EDIT]->set_pressed(true); + tool_editmode[EDITMODE_COLLISION]->set_pressed(true); + edit_mode = EDITMODE_COLLISION; _on_workspace_mode_changed(WORKSPACE_EDIT); } } + edited_region = Rect2(); workspace->update(); workspace_overlay->update(); return; @@ -1179,7 +1230,8 @@ void TileSetEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) { case EDITMODE_COLLISION: case EDITMODE_OCCLUSION: case EDITMODE_NAVIGATION: - case EDITMODE_PRIORITY: { + case EDITMODE_PRIORITY: + case EDITMODE_Z_INDEX: { Vector2 shape_anchor = Vector2(0, 0); if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::AUTO_TILE || tileset->tile_get_tile_mode(get_current_tile()) == TileSet::ATLAS_TILE) { shape_anchor = edited_shape_coord; @@ -1394,6 +1446,7 @@ void TileSetEditor::_on_tool_clicked(int p_tool) { case EDITMODE_REGION: { if (workspace_mode == WORKSPACE_EDIT && get_current_tile() >= 0) { tileset->remove_tile(get_current_tile()); + set_current_tile(-1); workspace->update(); workspace_overlay->update(); } @@ -1439,24 +1492,6 @@ void TileSetEditor::_on_tool_clicked(int p_tool) { default: {} } } - } else if (p_tool == ZOOM_OUT) { - float scale = workspace->get_scale().x; - if (scale > 0.1) { - scale /= 2; - workspace->set_scale(Vector2(scale, scale)); - workspace_container->set_custom_minimum_size(workspace->get_rect().size * scale); - workspace_overlay->set_custom_minimum_size(workspace->get_rect().size * scale); - } - } else if (p_tool == ZOOM_1) { - workspace->set_scale(Vector2(1, 1)); - workspace_container->set_custom_minimum_size(workspace->get_rect().size); - workspace_overlay->set_custom_minimum_size(workspace->get_rect().size); - } else if (p_tool == ZOOM_IN) { - float scale = workspace->get_scale().x; - scale *= 2; - workspace->set_scale(Vector2(scale, scale)); - workspace_container->set_custom_minimum_size(workspace->get_rect().size * scale); - workspace_overlay->set_custom_minimum_size(workspace->get_rect().size * scale); } else if (p_tool == TOOL_SELECT) { if (creating_shape) { // Cancel Creation @@ -1472,6 +1507,11 @@ void TileSetEditor::_on_priority_changed(float val) { workspace->update(); } +void TileSetEditor::_on_z_index_changed(float val) { + tileset->autotile_set_z_index(get_current_tile(), edited_shape_coord, (int)val); + workspace->update(); +} + void TileSetEditor::_on_grid_snap_toggled(bool p_val) { helper->set_snap_options_visible(p_val); workspace->update(); @@ -1495,22 +1535,59 @@ void TileSetEditor::_set_snap_sep(Vector2 p_val) { workspace->update(); } +void TileSetEditor::_zoom_in() { + float scale = workspace->get_scale().x; + if (scale < max_scale) { + scale *= scale_ratio; + workspace->set_scale(Vector2(scale, scale)); + workspace_container->set_custom_minimum_size(workspace->get_rect().size * scale); + workspace_overlay->set_custom_minimum_size(workspace->get_rect().size * scale); + } +} +void TileSetEditor::_zoom_out() { + + float scale = workspace->get_scale().x; + if (scale > min_scale) { + scale /= scale_ratio; + workspace->set_scale(Vector2(scale, scale)); + workspace_container->set_custom_minimum_size(workspace->get_rect().size * scale); + workspace_overlay->set_custom_minimum_size(workspace->get_rect().size * scale); + } +} +void TileSetEditor::_zoom_reset() { + workspace->set_scale(Vector2(1, 1)); + workspace_container->set_custom_minimum_size(workspace->get_rect().size); + workspace_overlay->set_custom_minimum_size(workspace->get_rect().size); +} + void TileSetEditor::draw_highlight_current_tile() { - if (get_current_tile() >= 0) { - Rect2 region = tileset->tile_get_region(get_current_tile()); - region.position += WORKSPACE_MARGIN; - workspace->draw_rect(Rect2(0, 0, workspace->get_rect().size.x, region.position.y), Color(0.3, 0.3, 0.3, 0.3)); - workspace->draw_rect(Rect2(0, region.position.y, region.position.x, region.size.y), Color(0.3, 0.3, 0.3, 0.3)); - workspace->draw_rect(Rect2(region.position.x + region.size.x, region.position.y, workspace->get_rect().size.x - region.position.x - region.size.x, region.size.y), Color(0.3, 0.3, 0.3, 0.3)); - workspace->draw_rect(Rect2(0, region.position.y + region.size.y, workspace->get_rect().size.x, workspace->get_rect().size.y - region.size.y - region.position.y), Color(0.3, 0.3, 0.3, 0.3)); + Color shadow_color = Color(0.3, 0.3, 0.3, 0.3); + if ((workspace_mode == WORKSPACE_EDIT && get_current_tile() >= 0) || !edited_region.has_no_area()) { + Rect2 region; + if (edited_region.has_no_area()) { + region = tileset->tile_get_region(get_current_tile()); + region.position += WORKSPACE_MARGIN; + } else { + region = edited_region; + } + + if (region.position.y >= 0) + workspace->draw_rect(Rect2(0, 0, workspace->get_rect().size.x, region.position.y), shadow_color); + if (region.position.x >= 0) + workspace->draw_rect(Rect2(0, MAX(0, region.position.y), region.position.x, MIN(workspace->get_rect().size.y - region.position.y, MIN(region.size.y, region.position.y + region.size.y))), shadow_color); + if (region.position.x + region.size.x <= workspace->get_rect().size.x) + workspace->draw_rect(Rect2(region.position.x + region.size.x, MAX(0, region.position.y), workspace->get_rect().size.x - region.position.x - region.size.x, MIN(workspace->get_rect().size.y - region.position.y, MIN(region.size.y, region.position.y + region.size.y))), shadow_color); + if (region.position.y + region.size.y <= workspace->get_rect().size.y) + workspace->draw_rect(Rect2(0, region.position.y + region.size.y, workspace->get_rect().size.x, workspace->get_rect().size.y - region.size.y - region.position.y), shadow_color); } else { - workspace->draw_rect(Rect2(Point2(0, 0), workspace->get_rect().size), Color(0.3, 0.3, 0.3, 0.3)); + workspace->draw_rect(Rect2(Point2(0, 0), workspace->get_rect().size), shadow_color); } } void TileSetEditor::draw_highlight_subtile(Vector2 coord, const Vector<Vector2> &other_highlighted) { + Color shadow_color = Color(0.3, 0.3, 0.3, 0.3); Vector2 size = tileset->autotile_get_size(get_current_tile()); int spacing = tileset->autotile_get_spacing(get_current_tile()); Rect2 region = tileset->tile_get_region(get_current_tile()); @@ -1518,10 +1595,16 @@ void TileSetEditor::draw_highlight_subtile(Vector2 coord, const Vector<Vector2> coord.y *= (size.y + spacing); coord += region.position; coord += WORKSPACE_MARGIN; - workspace->draw_rect(Rect2(0, 0, workspace->get_rect().size.x, coord.y), Color(0.3, 0.3, 0.3, 0.3)); - workspace->draw_rect(Rect2(0, coord.y, coord.x, size.y), Color(0.3, 0.3, 0.3, 0.3)); - workspace->draw_rect(Rect2(coord.x + size.x, coord.y, workspace->get_rect().size.x - coord.x - size.x, size.y), Color(0.3, 0.3, 0.3, 0.3)); - workspace->draw_rect(Rect2(0, coord.y + size.y, workspace->get_rect().size.x, workspace->get_rect().size.y - size.y - coord.y), Color(0.3, 0.3, 0.3, 0.3)); + + if (coord.y >= 0) + workspace->draw_rect(Rect2(0, 0, workspace->get_rect().size.x, coord.y), shadow_color); + if (coord.x >= 0) + workspace->draw_rect(Rect2(0, MAX(0, coord.y), coord.x, MIN(workspace->get_rect().size.y - coord.y, MIN(size.y, coord.y + size.y))), shadow_color); + if (coord.x + size.x <= workspace->get_rect().size.x) + workspace->draw_rect(Rect2(coord.x + size.x, MAX(0, coord.y), workspace->get_rect().size.x - coord.x - size.x, MIN(workspace->get_rect().size.y - coord.y, MIN(size.y, coord.y + size.y))), shadow_color); + if (coord.y + size.y <= workspace->get_rect().size.y) + workspace->draw_rect(Rect2(0, coord.y + size.y, workspace->get_rect().size.x, workspace->get_rect().size.y - size.y - coord.y), shadow_color); + coord += Vector2(1, 1) / workspace->get_scale().x; workspace->draw_rect(Rect2(coord, size - Vector2(2, 2) / workspace->get_scale().x), Color(1, 0, 0), false); for (int i = 0; i < other_highlighted.size(); i++) { @@ -1541,35 +1624,35 @@ void TileSetEditor::draw_tile_subdivision(int p_id, Color p_color) const { Rect2 region = tileset->tile_get_region(p_id); Size2 size = tileset->autotile_get_size(p_id); int spacing = tileset->autotile_get_spacing(p_id); - float j = 0; + float j = size.x; + while (j < region.size.x) { - j += size.x; if (spacing <= 0) { workspace->draw_line(region.position + WORKSPACE_MARGIN + Point2(j, 0), region.position + WORKSPACE_MARGIN + Point2(j, region.size.y), c); } else { workspace->draw_rect(Rect2(region.position + WORKSPACE_MARGIN + Point2(j, 0), Size2(spacing, region.size.y)), c); } - j += spacing; + j += spacing + size.x; } - j = 0; + j = size.y; while (j < region.size.y) { - j += size.y; if (spacing <= 0) { workspace->draw_line(region.position + WORKSPACE_MARGIN + Point2(0, j), region.position + WORKSPACE_MARGIN + Point2(region.size.x, j), c); } else { workspace->draw_rect(Rect2(region.position + WORKSPACE_MARGIN + Point2(0, j), Size2(region.size.x, spacing)), c); } - j += spacing; + j += spacing + size.y; } } } void TileSetEditor::draw_edited_region_subdivision() const { - Color c = Color(0.347214, 0.722656, 0.617063, 1); + Color c = Color(0.3, 0.7, 0.6); Rect2 region = edited_region; Size2 size; int spacing; bool draw; + if (workspace_mode == WORKSPACE_EDIT) { int p_id = get_current_tile(); size = tileset->autotile_get_size(p_id); @@ -1580,66 +1663,72 @@ void TileSetEditor::draw_edited_region_subdivision() const { spacing = snap_separation.x; draw = workspace_mode != WORKSPACE_CREATE_SINGLE; } - if (draw) { - float j = 0; + if (draw) { + float j = size.x; while (j < region.size.x) { - j += size.x; if (spacing <= 0) { workspace->draw_line(region.position + Point2(j, 0), region.position + Point2(j, region.size.y), c); } else { workspace->draw_rect(Rect2(region.position + Point2(j, 0), Size2(spacing, region.size.y)), c); } - j += spacing; + j += spacing + size.x; } - j = 0; + j = size.y; while (j < region.size.y) { - j += size.y; if (spacing <= 0) { workspace->draw_line(region.position + Point2(0, j), region.position + Point2(region.size.x, j), c); } else { workspace->draw_rect(Rect2(region.position + Point2(0, j), Size2(region.size.x, spacing)), c); } - j += spacing; + j += spacing + size.y; } } } void TileSetEditor::draw_grid_snap() { if (tools[TOOL_GRID_SNAP]->is_pressed()) { - Color grid_color = Color(0.39, 0, 1, 0.2f); + Color grid_color = Color(0.4, 0, 1); Size2 s = workspace->get_size(); - int width_count = (int)(s.width / (snap_step.x + snap_separation.x)); - int height_count = (int)(s.height / (snap_step.y + snap_separation.y)); + int width_count = Math::floor((s.width - WORKSPACE_MARGIN.x) / (snap_step.x + snap_separation.x)); + int height_count = Math::floor((s.height - WORKSPACE_MARGIN.y) / (snap_step.y + snap_separation.y)); + int last_p = 0; if (snap_step.x != 0) { - int last_p = 0; for (int i = 0; i <= width_count; i++) { if (i == 0 && snap_offset.x != 0) { last_p = snap_offset.x; } - if (snap_separation.x != 0 && i != 0) { - workspace->draw_rect(Rect2(last_p, 0, snap_separation.x, s.height), grid_color); - last_p += snap_separation.x; - } else + if (snap_separation.x != 0) { + if (i != 0) { + workspace->draw_rect(Rect2(last_p, 0, snap_separation.x, s.height), grid_color); + last_p += snap_separation.x; + } else { + workspace->draw_rect(Rect2(last_p, 0, -snap_separation.x, s.height), grid_color); + } + } else { workspace->draw_line(Point2(last_p, 0), Point2(last_p, s.height), grid_color); - + } last_p += snap_step.x; } } - + last_p = 0; if (snap_step.y != 0) { - int last_p = 0; for (int i = 0; i <= height_count; i++) { if (i == 0 && snap_offset.y != 0) { last_p = snap_offset.y; } - if (snap_separation.x != 0 && i != 0) { - workspace->draw_rect(Rect2(0, last_p, s.width, snap_separation.y), grid_color); - last_p += snap_separation.y; - } else + if (snap_separation.x != 0) { + if (i != 0) { + workspace->draw_rect(Rect2(0, last_p, s.width, snap_separation.y), grid_color); + last_p += snap_separation.y; + } else { + workspace->draw_rect(Rect2(0, last_p, s.width, -snap_separation.y), grid_color); + } + } else { workspace->draw_line(Point2(0, last_p), Point2(s.width, last_p), grid_color); + } last_p += snap_step.y; } } @@ -1652,8 +1741,6 @@ void TileSetEditor::draw_polygon_shapes() { if (t_id < 0) return; - draw_handles = false; - switch (edit_mode) { case EDITMODE_COLLISION: { Vector<TileSet::ShapeData> sd = tileset->tile_get_shapes(t_id); @@ -2076,13 +2163,24 @@ void TileSetEditor::update_texture_list() { List<int> ids; tileset->get_tile_list(&ids); + Vector<int> ids_to_remove; for (List<int>::Element *E = ids.front(); E; E = E->next()) { + // Clear tiles referencing gone textures (user has been already given the chance to fix broken deps) + if (!tileset->tile_get_texture(E->get()).is_valid()) { + ids_to_remove.push_back(E->get()); + ERR_CONTINUE(!tileset->tile_get_texture(E->get()).is_valid()); + } + if (!texture_map.has(tileset->tile_get_texture(E->get())->get_rid())) { texture_list->add_item(tileset->tile_get_texture(E->get())->get_path().get_file()); texture_map.insert(tileset->tile_get_texture(E->get())->get_rid(), tileset->tile_get_texture(E->get())); texture_list->set_item_metadata(texture_list->get_item_count() - 1, tileset->tile_get_texture(E->get())->get_rid()); } } + for (int i = 0; i < ids_to_remove.size(); i++) { + tileset->remove_tile(ids_to_remove[i]); + } + if (texture_list->get_item_count() > 0 && selected_texture.is_valid()) { texture_list->select(texture_list->find_metadata(selected_texture->get_rid())); if (texture_list->get_selected_items().size() > 0) @@ -2108,6 +2206,18 @@ void TileSetEditor::update_texture_list_icon() { void TileSetEditor::update_workspace_tile_mode() { + if (!get_current_texture().is_valid()) { + tool_workspacemode[WORKSPACE_EDIT]->set_pressed(true); + workspace_mode = WORKSPACE_EDIT; + for (int i = 1; i < WORKSPACE_MODE_MAX; i++) { + tool_workspacemode[i]->set_disabled(true); + } + } else { + for (int i = 1; i < WORKSPACE_MODE_MAX; i++) { + tool_workspacemode[i]->set_disabled(false); + } + } + if (workspace_mode != WORKSPACE_EDIT) { for (int i = 0; i < EDITMODE_MAX; i++) { tool_editmode[i]->hide(); @@ -2126,7 +2236,9 @@ void TileSetEditor::update_workspace_tile_mode() { for (int i = 0; i < ZOOM_OUT; i++) { tools[i]->hide(); } + separator_editmode->hide(); + separator_bitmask->hide(); separator_delete->hide(); separator_grid->hide(); return; @@ -2138,7 +2250,7 @@ void TileSetEditor::update_workspace_tile_mode() { separator_editmode->show(); if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::SINGLE_TILE) { - if (tool_editmode[EDITMODE_ICON]->is_pressed() || tool_editmode[EDITMODE_PRIORITY]->is_pressed() || tool_editmode[EDITMODE_BITMASK]->is_pressed()) { + if (tool_editmode[EDITMODE_ICON]->is_pressed() || tool_editmode[EDITMODE_PRIORITY]->is_pressed() || tool_editmode[EDITMODE_BITMASK]->is_pressed() || tool_editmode[EDITMODE_Z_INDEX]->is_pressed()) { tool_editmode[EDITMODE_COLLISION]->set_pressed(true); edit_mode = EDITMODE_COLLISION; } @@ -2147,6 +2259,7 @@ void TileSetEditor::update_workspace_tile_mode() { tool_editmode[EDITMODE_ICON]->hide(); tool_editmode[EDITMODE_BITMASK]->hide(); tool_editmode[EDITMODE_PRIORITY]->hide(); + tool_editmode[EDITMODE_Z_INDEX]->hide(); } else if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::AUTO_TILE || tileset->tile_get_tile_mode(get_current_tile()) == TileSet::ATLAS_TILE) { if (edit_mode == EDITMODE_ICON) select_coord(tileset->autotile_get_icon_coordinate(get_current_tile())); @@ -2172,25 +2285,18 @@ void TileSetEditor::update_edited_region(const Vector2 &end_point) { edited_region = Rect2(region_from, Size2()); if (tools[TOOL_GRID_SNAP]->is_pressed()) { Vector2 grid_coord; - grid_coord.x = Math::floor((region_from.x - snap_offset.x) / (snap_step.x + snap_separation.x)); - grid_coord.y = Math::floor((region_from.y - snap_offset.y) / (snap_step.y + snap_separation.y)); - grid_coord.x *= (snap_step.x + snap_separation.x); - grid_coord.y *= (snap_step.y + snap_separation.y); + grid_coord = ((region_from - snap_offset) / (snap_step + snap_separation)).floor(); + grid_coord *= (snap_step + snap_separation); grid_coord += snap_offset; edited_region.expand_to(grid_coord); - grid_coord += snap_step; + grid_coord += snap_step + snap_separation; edited_region.expand_to(grid_coord); - grid_coord.x = Math::floor((end_point.x - snap_offset.x) / (snap_step.x + snap_separation.x)); - grid_coord.y = Math::floor((end_point.y - snap_offset.y) / (snap_step.y + snap_separation.y)); - grid_coord.x *= (snap_step.x + snap_separation.x); - grid_coord.y *= (snap_step.y + snap_separation.y); + + grid_coord = ((end_point - snap_offset) / (snap_step + snap_separation)).floor(); + grid_coord *= (snap_step + snap_separation); grid_coord += snap_offset; edited_region.expand_to(grid_coord); - grid_coord += snap_step; - if (grid_coord.x < end_point.x) - grid_coord.x += snap_separation.x; - if (grid_coord.y < end_point.y) - grid_coord.y += snap_separation.y; + grid_coord += snap_step + snap_separation; edited_region.expand_to(grid_coord); } else { edited_region.expand_to(end_point); @@ -2368,7 +2474,13 @@ void TilesetEditorContext::_get_property_list(List<PropertyInfo> *p_list) const } } +void TilesetEditorContext::_bind_methods() { + + ClassDB::bind_method("_hide_script_from_inspector", &TilesetEditorContext::_hide_script_from_inspector); +} + TilesetEditorContext::TilesetEditorContext(TileSetEditor *p_tileset_editor) { + tileset_editor = p_tileset_editor; } @@ -2382,8 +2494,7 @@ void TileSetEditorPlugin::edit(Object *p_node) { bool TileSetEditorPlugin::handles(Object *p_node) const { - return p_node->is_class("TileSet") || - p_node->is_class("TilesetEditorContext"); + return p_node->is_class("TileSet") || p_node->is_class("TilesetEditorContext"); } void TileSetEditorPlugin::make_visible(bool p_visible) { @@ -2398,6 +2509,41 @@ void TileSetEditorPlugin::make_visible(bool p_visible) { } } +Dictionary TileSetEditorPlugin::get_state() const { + + Dictionary state; + state["snap_offset"] = tileset_editor->snap_offset; + state["snap_step"] = tileset_editor->snap_step; + state["snap_separation"] = tileset_editor->snap_separation; + state["snap_enabled"] = tileset_editor->tools[TileSetEditor::TOOL_GRID_SNAP]->is_pressed(); + state["keep_inside_tile"] = tileset_editor->tools[TileSetEditor::SHAPE_KEEP_INSIDE_TILE]->is_pressed(); + return state; +} + +void TileSetEditorPlugin::set_state(const Dictionary &p_state) { + + Dictionary state = p_state; + if (state.has("snap_step")) { + tileset_editor->_set_snap_step(state["snap_step"]); + } + + if (state.has("snap_offset")) { + tileset_editor->_set_snap_off(state["snap_offset"]); + } + + if (state.has("snap_separation")) { + tileset_editor->_set_snap_sep(state["snap_separation"]); + } + + if (state.has("snap_enabled")) { + tileset_editor->tools[TileSetEditor::TOOL_GRID_SNAP]->set_pressed(state["snap_enabled"]); + } + + if (state.has("keep_inside_tile")) { + tileset_editor->tools[TileSetEditor::SHAPE_KEEP_INSIDE_TILE]->set_pressed(state["keep_inside_tile"]); + } +} + TileSetEditorPlugin::TileSetEditorPlugin(EditorNode *p_node) { editor = p_node; tileset_editor = memnew(TileSetEditor(p_node)); @@ -2405,6 +2551,6 @@ TileSetEditorPlugin::TileSetEditorPlugin(EditorNode *p_node) { tileset_editor->set_custom_minimum_size(Size2(0, 200) * EDSCALE); tileset_editor->hide(); - tileset_editor_button = p_node->add_bottom_panel_item(TTR("Tile Set"), tileset_editor); + tileset_editor_button = p_node->add_bottom_panel_item(TTR("TileSet"), tileset_editor); tileset_editor_button->hide(); } diff --git a/editor/plugins/tile_set_editor_plugin.h b/editor/plugins/tile_set_editor_plugin.h index 23bf68b90f..276e23f9ee 100644 --- a/editor/plugins/tile_set_editor_plugin.h +++ b/editor/plugins/tile_set_editor_plugin.h @@ -40,12 +40,12 @@ #define WORKSPACE_MARGIN Vector2(10, 10) class TilesetEditorContext; -class TileSetEditor : public Control { +class TileSetEditor : public HSplitContainer { friend class TileSetEditorPlugin; friend class TilesetEditorContext; - GDCLASS(TileSetEditor, Control) + GDCLASS(TileSetEditor, HSplitContainer) enum TextureToolButtons { TOOL_TILESET_ADD_TEXTURE, @@ -71,6 +71,7 @@ class TileSetEditor : public Control { EDITMODE_BITMASK, EDITMODE_PRIORITY, EDITMODE_ICON, + EDITMODE_Z_INDEX, EDITMODE_MAX }; @@ -134,13 +135,19 @@ class TileSetEditor : public Control { HSeparator *separator_editmode; HBoxContainer *toolbar; ToolButton *tools[TOOL_MAX]; + VSeparator *separator_bitmask; VSeparator *separator_delete; VSeparator *separator_grid; SpinBox *spin_priority; + SpinBox *spin_z_index; WorkspaceMode workspace_mode; EditMode edit_mode; int current_tile; + float max_scale; + float min_scale; + float scale_ratio; + void update_texture_list(); void update_texture_list_icon(); @@ -173,11 +180,16 @@ private: void _on_workspace_input(const Ref<InputEvent> &p_ie); void _on_tool_clicked(int p_tool); void _on_priority_changed(float val); + void _on_z_index_changed(float val); void _on_grid_snap_toggled(bool p_val); void _set_snap_step(Vector2 p_val); void _set_snap_off(Vector2 p_val); void _set_snap_sep(Vector2 p_val); + void _zoom_in(); + void _zoom_out(); + void _zoom_reset(); + void draw_highlight_current_tile(); void draw_highlight_subtile(Vector2 coord, const Vector<Vector2> &other_highlighted = Vector<Vector2>()); void draw_tile_subdivision(int p_id, Color p_color) const; @@ -204,6 +216,7 @@ class TilesetEditorContext : public Object { bool snap_options_visible; public: + bool _hide_script_from_inspector() { return true; } void set_tileset(const Ref<TileSet> &p_tileset); private: @@ -213,6 +226,7 @@ protected: bool _set(const StringName &p_name, const Variant &p_value); bool _get(const StringName &p_name, Variant &r_ret) const; void _get_property_list(List<PropertyInfo> *p_list) const; + static void _bind_methods(); public: TilesetEditorContext(TileSetEditor *p_tileset_editor); @@ -232,6 +246,8 @@ public: virtual void edit(Object *p_node); virtual bool handles(Object *p_node) const; virtual void make_visible(bool p_visible); + void set_state(const Dictionary &p_state); + Dictionary get_state() const; TileSetEditorPlugin(EditorNode *p_node); }; diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 39e50ec7f8..d3295c0f51 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -633,18 +633,23 @@ void VisualShaderEditor::_duplicate_nodes() { VisualShader::Type type = VisualShader::Type(edit_type->get_selected()); List<int> nodes; + Set<int> excluded; for (int i = 0; i < graph->get_child_count(); i++) { - if (Object::cast_to<GraphNode>(graph->get_child(i))) { - int id = String(graph->get_child(i)->get_name()).to_int(); + GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i)); + if (gn) { + int id = String(gn->get_name()).to_int(); Ref<VisualShaderNode> node = visual_shader->get_node(type, id); Ref<VisualShaderNodeOutput> output = node; - if (output.is_valid()) //can't duplicate output + if (output.is_valid()) { // can't duplicate output + excluded.insert(id); continue; - if (node.is_valid()) { + } + if (node.is_valid() && gn->is_selected()) { nodes.push_back(id); } + excluded.insert(id); } } @@ -683,15 +688,16 @@ void VisualShaderEditor::_duplicate_nodes() { undo_redo->add_undo_method(this, "_update_graph"); undo_redo->commit_action(); - //reselect + // reselect duplicated nodes by excluding the other ones for (int i = 0; i < graph->get_child_count(); i++) { - if (Object::cast_to<GraphNode>(graph->get_child(i))) { - int id = String(graph->get_child(i)->get_name()).to_int(); - if (nodes.find(id)) { - Object::cast_to<GraphNode>(graph->get_child(i))->set_selected(true); + GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i)); + if (gn) { + int id = String(gn->get_name()).to_int(); + if (!excluded.has(id)) { + gn->set_selected(true); } else { - Object::cast_to<GraphNode>(graph->get_child(i))->set_selected(false); + gn->set_selected(false); } } } @@ -798,7 +804,7 @@ VisualShaderEditor::VisualShaderEditor() { add_node = memnew(MenuButton); graph->get_zoom_hbox()->add_child(add_node); - add_node->set_text(TTR("Add Node..")); + add_node->set_text(TTR("Add Node...")); graph->get_zoom_hbox()->move_child(add_node, 0); add_node->get_popup()->connect("id_pressed", this, "_add_node"); |