summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
Diffstat (limited to 'editor')
-rw-r--r--editor/animation_track_editor.cpp231
-rw-r--r--editor/animation_track_editor.h11
-rw-r--r--editor/collada/collada.cpp3
-rw-r--r--editor/connections_dialog.cpp131
-rw-r--r--editor/connections_dialog.h12
-rw-r--r--editor/create_dialog.cpp24
-rw-r--r--editor/create_dialog.h2
-rw-r--r--editor/doc/doc_dump.cpp6
-rw-r--r--editor/editor_feature_profile.cpp889
-rw-r--r--editor/editor_feature_profile.h142
-rw-r--r--editor/editor_folding.cpp41
-rw-r--r--editor/editor_folding.h2
-rw-r--r--editor/editor_inspector.cpp36
-rw-r--r--editor/editor_inspector.h4
-rw-r--r--editor/editor_node.cpp146
-rw-r--r--editor/editor_node.h7
-rw-r--r--editor/editor_properties.cpp9
-rw-r--r--editor/editor_properties_array_dict.cpp6
-rw-r--r--editor/editor_settings.cpp12
-rw-r--r--editor/editor_settings.h1
-rw-r--r--editor/editor_themes.cpp4
-rw-r--r--editor/filesystem_dock.cpp51
-rw-r--r--editor/filesystem_dock.h5
-rw-r--r--editor/icons/icon_auto_key.svg56
-rw-r--r--editor/icons/icon_sprite_sheet.svg61
-rw-r--r--editor/import/editor_scene_importer_gltf.cpp7
-rw-r--r--editor/import/resource_importer_scene.cpp275
-rw-r--r--editor/import/resource_importer_scene.h2
-rw-r--r--editor/output_strings.cpp3
-rw-r--r--editor/plugins/animation_player_editor_plugin.cpp5
-rw-r--r--editor/plugins/animation_tree_player_editor_plugin.cpp15
-rw-r--r--editor/plugins/asset_library_editor_plugin.cpp6
-rw-r--r--editor/plugins/baked_lightmap_editor_plugin.cpp3
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp168
-rw-r--r--editor/plugins/canvas_item_editor_plugin.h3
-rw-r--r--editor/plugins/item_list_editor_plugin.h2
-rw-r--r--editor/plugins/mesh_instance_editor_plugin.cpp54
-rw-r--r--editor/plugins/mesh_library_editor_plugin.cpp3
-rw-r--r--editor/plugins/polygon_2d_editor_plugin.cpp3
-rw-r--r--editor/plugins/script_editor_plugin.cpp2
-rw-r--r--editor/plugins/script_text_editor.cpp4
-rw-r--r--editor/plugins/spatial_editor_plugin.cpp9
-rw-r--r--editor/plugins/sprite_editor_plugin.cpp287
-rw-r--r--editor/plugins/sprite_editor_plugin.h19
-rw-r--r--editor/plugins/sprite_frames_editor_plugin.cpp230
-rw-r--r--editor/plugins/sprite_frames_editor_plugin.h17
-rw-r--r--editor/plugins/tile_set_editor_plugin.cpp60
-rw-r--r--editor/plugins/visual_shader_editor_plugin.cpp64
-rw-r--r--editor/plugins/visual_shader_editor_plugin.h1
-rw-r--r--editor/project_settings_editor.cpp6
-rw-r--r--editor/property_editor.cpp21
-rw-r--r--editor/scene_tree_dock.cpp283
-rw-r--r--editor/scene_tree_dock.h5
-rw-r--r--editor/scene_tree_editor.cpp63
-rw-r--r--editor/scene_tree_editor.h4
-rwxr-xr-xeditor/translations/extract.py2
56 files changed, 3003 insertions, 515 deletions
diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp
index 8807a01f64..39c93fa785 100644
--- a/editor/animation_track_editor.cpp
+++ b/editor/animation_track_editor.cpp
@@ -109,9 +109,17 @@ public:
ERR_FAIL_COND_V(key == -1, false);
String name = p_name;
- if (name == "time") {
+ if (name == "time" || name == "frame") {
float new_time = p_value;
+
+ if (name == "frame") {
+ float fps = animation->get_step();
+ if (fps > 0) {
+ fps = 1.0 / fps;
+ }
+ new_time /= fps;
+ }
if (new_time == key_ofs)
return true;
@@ -413,6 +421,13 @@ public:
if (name == "time") {
r_ret = key_ofs;
return true;
+ } else if (name == "frame") {
+ float fps = animation->get_step();
+ if (fps > 0) {
+ fps = 1.0 / fps;
+ }
+ r_ret = key_ofs * fps;
+ return true;
} else if (name == "easing") {
r_ret = animation->track_get_key_transition(track, key);
return true;
@@ -527,7 +542,12 @@ public:
int key = animation->track_find_key(track, key_ofs, true);
ERR_FAIL_COND(key == -1);
- p_list->push_back(PropertyInfo(Variant::REAL, "time", PROPERTY_HINT_RANGE, "0," + rtos(animation->get_length()) + ",0.01"));
+ if (use_fps && animation->get_step() > 0) {
+ float max_frame = animation->get_length() / animation->get_step();
+ p_list->push_back(PropertyInfo(Variant::REAL, "frame", PROPERTY_HINT_RANGE, "0," + rtos(max_frame) + ",0.01"));
+ } else {
+ p_list->push_back(PropertyInfo(Variant::REAL, "time", PROPERTY_HINT_RANGE, "0," + rtos(animation->get_length()) + ",0.01"));
+ }
switch (animation->track_get_type(track)) {
@@ -648,6 +668,7 @@ public:
PropertyInfo hint;
NodePath base;
+ bool use_fps;
void notify_change() {
@@ -658,7 +679,13 @@ public:
return root_path;
}
+ void set_use_fps(bool p_enable) {
+ use_fps = p_enable;
+ _change_notify();
+ }
+
AnimationTrackKeyEdit() {
+ use_fps = false;
key_ofs = 0;
track = -1;
setting = false;
@@ -690,6 +717,9 @@ void AnimationTimelineEdit::_anim_length_changed(double p_new_len) {
return;
p_new_len = MAX(0.001, p_new_len);
+ if (use_fps && animation->get_step() > 0) {
+ p_new_len *= animation->get_step();
+ }
editing = true;
undo_redo->create_action(TTR("Change Animation Length"));
@@ -887,24 +917,53 @@ void AnimationTimelineEdit::_notification(int p_what) {
decimals = 0;
}
- for (int i = 0; i < zoomw; i++) {
+ if (use_fps) {
+
+ float step_size = animation->get_step();
+ if (step_size > 0) {
+
+ int prev_frame_ofs = -10000000;
- float pos = get_value() + double(i) / scale;
- float prev = get_value() + (double(i) - 1.0) / scale;
+ for (int i = 0; i < zoomw; i++) {
- int sc = int(Math::floor(pos * SC_ADJ));
- int prev_sc = int(Math::floor(prev * SC_ADJ));
- bool sub = (sc % SC_ADJ);
+ float pos = get_value() + double(i) / scale;
+ float prev = get_value() + (double(i) - 1.0) / scale;
- if ((sc / step) != (prev_sc / step) || (prev_sc < 0 && sc >= 0)) {
+ int frame = pos / step_size;
+ int prev_frame = prev / step_size;
- int scd = sc < 0 ? prev_sc : sc;
- draw_line(Point2(get_name_limit() + i, 0), Point2(get_name_limit() + i, h), linecolor);
- draw_string(font, Point2(get_name_limit() + i + 3, (h - font->get_height()) / 2 + font->get_ascent()).floor(), String::num((scd - (scd % step)) / double(SC_ADJ), decimals), sub ? color_time_dec : color_time_sec, zoomw - i);
+ bool sub = Math::floor(prev) == Math::floor(pos);
+
+ if (frame != prev_frame && i >= prev_frame_ofs) {
+
+ draw_line(Point2(get_name_limit() + i, 0), Point2(get_name_limit() + i, h), linecolor, Math::round(EDSCALE));
+
+ draw_string(font, Point2(get_name_limit() + i + 3 * EDSCALE, (h - font->get_height()) / 2 + font->get_ascent()).floor(), itos(frame), sub ? color_time_dec : color_time_sec, zoomw - i);
+ prev_frame_ofs = i + font->get_string_size(itos(frame)).x + 5 * EDSCALE;
+ }
+ }
+ }
+
+ } else {
+ for (int i = 0; i < zoomw; i++) {
+
+ float pos = get_value() + double(i) / scale;
+ float prev = get_value() + (double(i) - 1.0) / scale;
+
+ int sc = int(Math::floor(pos * SC_ADJ));
+ int prev_sc = int(Math::floor(prev * SC_ADJ));
+ bool sub = (sc % SC_ADJ);
+
+ if ((sc / step) != (prev_sc / step) || (prev_sc < 0 && sc >= 0)) {
+
+ int scd = sc < 0 ? prev_sc : sc;
+ draw_line(Point2(get_name_limit() + i, 0), Point2(get_name_limit() + i, h), linecolor, Math::round(EDSCALE));
+ draw_string(font, Point2(get_name_limit() + i + 3, (h - font->get_height()) / 2 + font->get_ascent()).floor(), String::num((scd - (scd % step)) / double(SC_ADJ), decimals), sub ? color_time_dec : color_time_sec, zoomw - i);
+ }
}
}
- draw_line(Vector2(0, get_size().height), get_size(), linecolor);
+ draw_line(Vector2(0, get_size().height), get_size(), linecolor, Math::round(EDSCALE));
}
}
@@ -961,7 +1020,11 @@ void AnimationTimelineEdit::update_values() {
return;
editing = true;
- length->set_value(animation->get_length());
+ if (use_fps && animation->get_step() > 0) {
+ length->set_value(animation->get_length() / animation->get_step());
+ } else {
+ length->set_value(animation->get_length());
+ }
loop->set_pressed(animation->has_loop());
editing = false;
}
@@ -978,7 +1041,7 @@ void AnimationTimelineEdit::_play_position_draw() {
if (px >= get_name_limit() && px < (play_position->get_size().width - get_buttons_width())) {
Color color = get_color("accent_color", "Editor");
- play_position->draw_line(Point2(px, 0), Point2(px, h), color);
+ play_position->draw_line(Point2(px, 0), Point2(px, h), color, Math::round(EDSCALE));
}
}
@@ -1046,6 +1109,15 @@ void AnimationTimelineEdit::_gui_input(const Ref<InputEvent> &p_event) {
}
}
+void AnimationTimelineEdit::set_use_fps(bool p_use_fps) {
+ use_fps = p_use_fps;
+ update_values();
+ update();
+}
+bool AnimationTimelineEdit::is_using_fps() const {
+ return use_fps;
+}
+
void AnimationTimelineEdit::set_hscroll(HScrollBar *p_hscroll) {
hscroll = p_hscroll;
@@ -1072,6 +1144,7 @@ void AnimationTimelineEdit::_bind_methods() {
AnimationTimelineEdit::AnimationTimelineEdit() {
+ use_fps = false;
editing = false;
name_limit = 150;
zoom = NULL;
@@ -1099,7 +1172,7 @@ AnimationTimelineEdit::AnimationTimelineEdit() {
len_hb->add_child(time_icon);
length = memnew(EditorSpinSlider);
length->set_min(0.001);
- length->set_max(3600);
+ length->set_max(36000);
length->set_step(0.01);
length->set_allow_greater(true);
length->set_custom_minimum_size(Vector2(70 * EDSCALE, 0));
@@ -1237,7 +1310,7 @@ void AnimationTrackEdit::_notification(int p_what) {
string_pos = string_pos.floor();
draw_string(font, string_pos, text, text_color, limit - ofs - hsep);
- draw_line(Point2(limit, 0), Point2(limit, get_size().height), linecolor);
+ draw_line(Point2(limit, 0), Point2(limit, get_size().height), linecolor, Math::round(EDSCALE));
}
// KEYFAMES //
@@ -1297,7 +1370,7 @@ void AnimationTrackEdit::_notification(int p_what) {
Ref<Texture> down_icon = get_icon("select_arrow", "Tree");
- draw_line(Point2(ofs, 0), Point2(ofs, get_size().height), linecolor);
+ draw_line(Point2(ofs, 0), Point2(ofs, get_size().height), linecolor, Math::round(EDSCALE));
ofs += hsep;
{
@@ -1344,7 +1417,7 @@ void AnimationTrackEdit::_notification(int p_what) {
}
ofs += down_icon->get_width();
- draw_line(Point2(ofs + hsep * 0.5, 0), Point2(ofs + hsep * 0.5, get_size().height), linecolor);
+ draw_line(Point2(ofs + hsep * 0.5, 0), Point2(ofs + hsep * 0.5, get_size().height), linecolor, Math::round(EDSCALE));
ofs += hsep;
}
@@ -1377,7 +1450,7 @@ void AnimationTrackEdit::_notification(int p_what) {
}
ofs += down_icon->get_width();
- draw_line(Point2(ofs + hsep * 0.5, 0), Point2(ofs + hsep * 0.5, get_size().height), linecolor);
+ draw_line(Point2(ofs + hsep * 0.5, 0), Point2(ofs + hsep * 0.5, get_size().height), linecolor, Math::round(EDSCALE));
ofs += hsep;
}
@@ -1410,7 +1483,7 @@ void AnimationTrackEdit::_notification(int p_what) {
}
ofs += down_icon->get_width();
- draw_line(Point2(ofs + hsep * 0.5, 0), Point2(ofs + hsep * 0.5, get_size().height), linecolor);
+ draw_line(Point2(ofs + hsep * 0.5, 0), Point2(ofs + hsep * 0.5, get_size().height), linecolor, Math::round(EDSCALE));
ofs += hsep;
}
@@ -1428,17 +1501,17 @@ void AnimationTrackEdit::_notification(int p_what) {
}
if (in_group) {
- draw_line(Vector2(timeline->get_name_limit(), get_size().height), get_size(), linecolor);
+ draw_line(Vector2(timeline->get_name_limit(), get_size().height), get_size(), linecolor, Math::round(EDSCALE));
} else {
- draw_line(Vector2(0, get_size().height), get_size(), linecolor);
+ draw_line(Vector2(0, get_size().height), get_size(), linecolor, Math::round(EDSCALE));
}
if (dropping_at != 0) {
Color drop_color = get_color("accent_color", "Editor");
if (dropping_at < 0) {
- draw_line(Vector2(0, 0), Vector2(get_size().width, 0), drop_color);
+ draw_line(Vector2(0, 0), Vector2(get_size().width, 0), drop_color, Math::round(EDSCALE));
} else {
- draw_line(Vector2(0, get_size().height), get_size(), drop_color);
+ draw_line(Vector2(0, get_size().height), get_size(), drop_color, Math::round(EDSCALE));
}
}
}
@@ -1487,7 +1560,7 @@ void AnimationTrackEdit::draw_key_link(int p_index, float p_pixels_sec, int p_x,
int from_x = MAX(p_x, p_clip_left);
int to_x = MIN(p_next_x, p_clip_right);
- draw_line(Point2(from_x + 1, get_size().height / 2), Point2(to_x, get_size().height / 2), color, 2);
+ draw_line(Point2(from_x + 1, get_size().height / 2), Point2(to_x, get_size().height / 2), color, Math::round(2 * EDSCALE));
}
void AnimationTrackEdit::draw_key(int p_index, float p_pixels_sec, int p_x, bool p_selected, int p_clip_left, int p_clip_right) {
@@ -1667,7 +1740,7 @@ void AnimationTrackEdit::_play_position_draw() {
if (px >= timeline->get_name_limit() && px < (get_size().width - timeline->get_buttons_width())) {
Color color = get_color("accent_color", "Editor");
- play_position->draw_line(Point2(px, 0), Point2(px, h), color);
+ play_position->draw_line(Point2(px, 0), Point2(px, h), color, Math::round(EDSCALE));
}
}
@@ -2370,9 +2443,9 @@ void AnimationTrackEditGroup::_notification(int p_what) {
Color linecolor = color;
linecolor.a = 0.2;
- draw_line(Point2(), Point2(get_size().width, 0), linecolor);
- draw_line(Point2(timeline->get_name_limit(), 0), Point2(timeline->get_name_limit(), get_size().height), linecolor);
- draw_line(Point2(get_size().width - timeline->get_buttons_width(), 0), Point2(get_size().width - timeline->get_buttons_width(), get_size().height), linecolor);
+ draw_line(Point2(), Point2(get_size().width, 0), linecolor, Math::round(EDSCALE));
+ draw_line(Point2(timeline->get_name_limit(), 0), Point2(timeline->get_name_limit(), get_size().height), linecolor, Math::round(EDSCALE));
+ draw_line(Point2(get_size().width - timeline->get_buttons_width(), 0), Point2(get_size().width - timeline->get_buttons_width(), get_size().height), linecolor, Math::round(EDSCALE));
int ofs = 0;
draw_texture(icon, Point2(ofs, int(get_size().height - icon->get_height()) / 2));
@@ -2383,7 +2456,7 @@ void AnimationTrackEditGroup::_notification(int p_what) {
if (px >= timeline->get_name_limit() && px < (get_size().width - timeline->get_buttons_width())) {
Color accent = get_color("accent_color", "Editor");
- draw_line(Point2(px, 0), Point2(px, get_size().height), accent);
+ draw_line(Point2(px, 0), Point2(px, get_size().height), accent, Math::round(EDSCALE));
}
}
}
@@ -2462,10 +2535,12 @@ void AnimationTrackEditor::set_animation(const Ref<Animation> &p_anim) {
hscroll->show();
edit->set_disabled(false);
step->set_block_signals(true);
- step->set_value(animation->get_step());
+
+ _update_step_spinbox();
step->set_block_signals(false);
step->set_read_only(false);
snap->set_disabled(false);
+ snap_mode->set_disabled(true);
} else {
hscroll->hide();
edit->set_disabled(true);
@@ -2474,6 +2549,7 @@ void AnimationTrackEditor::set_animation(const Ref<Animation> &p_anim) {
step->set_block_signals(false);
step->set_read_only(true);
snap->set_disabled(true);
+ snap_mode->set_disabled(false);
}
}
@@ -2518,6 +2594,43 @@ void AnimationTrackEditor::update_keying() {
bool AnimationTrackEditor::has_keying() const {
return keying;
}
+Dictionary AnimationTrackEditor::get_state() const {
+ Dictionary state;
+ state["fps_mode"] = timeline->is_using_fps();
+ state["zoom"] = zoom->get_value();
+ state["offset"] = timeline->get_value();
+ state["v_scroll"] = scroll->get_v_scrollbar()->get_value();
+ return state;
+}
+void AnimationTrackEditor::set_state(const Dictionary &p_state) {
+ if (p_state.has("fps_mode")) {
+ bool fps_mode = p_state["fps_mode"];
+ if (fps_mode) {
+ snap_mode->select(1);
+ } else {
+ snap_mode->select(0);
+ }
+ _snap_mode_changed(snap_mode->get_selected());
+ } else {
+ snap_mode->select(0);
+ _snap_mode_changed(snap_mode->get_selected());
+ }
+ if (p_state.has("zoom")) {
+ zoom->set_value(p_state["zoom"]);
+ } else {
+ zoom->set_value(1.0);
+ }
+ if (p_state.has("offset")) {
+ timeline->set_value(p_state["offset"]);
+ } else {
+ timeline->set_value(0);
+ }
+ if (p_state.has("v_scroll")) {
+ scroll->get_v_scrollbar()->set_value(p_state["v_scroll"]);
+ } else {
+ scroll->get_v_scrollbar()->set_value(0);
+ }
+}
void AnimationTrackEditor::cleanup() {
set_animation(Ref<Animation>());
@@ -3417,6 +3530,34 @@ void AnimationTrackEditor::_animation_changed() {
call_deferred("_animation_update");
}
+void AnimationTrackEditor::_snap_mode_changed(int p_mode) {
+
+ timeline->set_use_fps(p_mode == 1);
+ if (key_edit) {
+ key_edit->set_use_fps(p_mode == 1);
+ }
+ _update_step_spinbox();
+}
+
+void AnimationTrackEditor::_update_step_spinbox() {
+ if (!animation.is_valid()) {
+ return;
+ }
+ step->set_block_signals(true);
+
+ if (timeline->is_using_fps()) {
+ if (animation->get_step() == 0) {
+ step->set_value(0);
+ } else {
+ step->set_value(1.0 / animation->get_step());
+ }
+
+ } else {
+ step->set_value(animation->get_step());
+ }
+
+ step->set_block_signals(false);
+}
void AnimationTrackEditor::_animation_update() {
timeline->update();
@@ -3454,9 +3595,7 @@ void AnimationTrackEditor::_animation_update() {
bezier_edit->update();
- step->set_block_signals(true);
- step->set_value(animation->get_step());
- step->set_block_signals(false);
+ _update_step_spinbox();
animation_changing_awaiting_update = false;
}
@@ -3497,12 +3636,18 @@ void AnimationTrackEditor::_update_scroll(double) {
void AnimationTrackEditor::_update_step(double p_new_step) {
undo_redo->create_action(TTR("Change Animation Step"));
- undo_redo->add_do_method(animation.ptr(), "set_step", p_new_step);
+ float step_value = p_new_step;
+ if (timeline->is_using_fps()) {
+ if (step_value != 0.0) {
+ step_value = 1.0 / step_value;
+ }
+ }
+ undo_redo->add_do_method(animation.ptr(), "set_step", step_value);
undo_redo->add_undo_method(animation.ptr(), "set_step", animation->get_step());
step->set_block_signals(true);
undo_redo->commit_action();
step->set_block_signals(false);
- emit_signal("animation_step_changed", p_new_step);
+ emit_signal("animation_step_changed", step_value);
}
void AnimationTrackEditor::_update_length(double p_new_len) {
@@ -4787,6 +4932,7 @@ void AnimationTrackEditor::_bind_methods() {
ClassDB::bind_method("_edit_menu_pressed", &AnimationTrackEditor::_edit_menu_pressed);
ClassDB::bind_method("_view_group_toggle", &AnimationTrackEditor::_view_group_toggle);
ClassDB::bind_method("_selection_changed", &AnimationTrackEditor::_selection_changed);
+ ClassDB::bind_method("_snap_mode_changed", &AnimationTrackEditor::_snap_mode_changed);
ADD_SIGNAL(MethodInfo("timeline_changed", PropertyInfo(Variant::REAL, "position"), PropertyInfo(Variant::BOOL, "drag")));
ADD_SIGNAL(MethodInfo("keying_changed"));
@@ -4875,7 +5021,7 @@ AnimationTrackEditor::AnimationTrackEditor() {
bottom_hb->add_child(memnew(VSeparator));
snap = memnew(ToolButton);
- snap->set_text(TTR("Snap (s): "));
+ snap->set_text(TTR("Snap: "));
bottom_hb->add_child(snap);
snap->set_disabled(true);
snap->set_toggle_mode(true);
@@ -4883,7 +5029,7 @@ AnimationTrackEditor::AnimationTrackEditor() {
step = memnew(EditorSpinSlider);
step->set_min(0);
- step->set_max(1000);
+ step->set_max(1000000);
step->set_step(0.01);
step->set_hide_slider(true);
step->set_custom_minimum_size(Size2(100, 0) * EDSCALE);
@@ -4892,6 +5038,13 @@ AnimationTrackEditor::AnimationTrackEditor() {
step->connect("value_changed", this, "_update_step");
step->set_read_only(true);
+ snap_mode = memnew(OptionButton);
+ snap_mode->add_item(TTR("Seconds"));
+ snap_mode->add_item(TTR("FPS"));
+ bottom_hb->add_child(snap_mode);
+ snap_mode->connect("item_selected", this, "_snap_mode_changed");
+ snap_mode->set_disabled(true);
+
bottom_hb->add_child(memnew(VSeparator));
zoom_icon = memnew(TextureRect);
diff --git a/editor/animation_track_editor.h b/editor/animation_track_editor.h
index 29ce4f189e..5ac5999b68 100644
--- a/editor/animation_track_editor.h
+++ b/editor/animation_track_editor.h
@@ -76,6 +76,7 @@ class AnimationTimelineEdit : public Range {
Rect2 hsize_rect;
bool editing;
+ bool use_fps;
bool panning_timeline;
float panning_timeline_from;
@@ -110,6 +111,9 @@ public:
void update_values();
+ void set_use_fps(bool p_use_fps);
+ bool is_using_fps() const;
+
void set_hscroll(HScrollBar *p_hscroll);
AnimationTimelineEdit();
@@ -303,7 +307,9 @@ class AnimationTrackEditor : public VBoxContainer {
EditorSpinSlider *step;
TextureRect *zoom_icon;
ToolButton *snap;
+ OptionButton *snap_mode;
+ void _snap_mode_changed(int p_mode);
Vector<AnimationTrackEdit *> track_edits;
Vector<AnimationTrackEditGroup *> groups;
@@ -328,6 +334,8 @@ class AnimationTrackEditor : public VBoxContainer {
void _new_track_node_selected(NodePath p_path);
void _new_track_property_selected(String p_name);
+ void _update_step_spinbox();
+
PropertySelector *prop_selector;
PropertySelector *method_selector;
SceneTreeDialog *pick_track;
@@ -484,6 +492,9 @@ public:
void update_keying();
bool has_keying() const;
+ Dictionary get_state() const;
+ void set_state(const Dictionary &p_state);
+
void cleanup();
void set_anim_pos(float p_pos);
diff --git a/editor/collada/collada.cpp b/editor/collada/collada.cpp
index 94e6d4ded0..94a37a3118 100644
--- a/editor/collada/collada.cpp
+++ b/editor/collada/collada.cpp
@@ -166,7 +166,8 @@ Transform Collada::Node::compute_transform(Collada &state) const {
}
} break;
- default: {}
+ default: {
+ }
}
xform = xform * xform_step;
diff --git a/editor/connections_dialog.cpp b/editor/connections_dialog.cpp
index f775a0a14b..685c5de76c 100644
--- a/editor/connections_dialog.cpp
+++ b/editor/connections_dialog.cpp
@@ -37,6 +37,25 @@
#include "scene/gui/label.h"
#include "scene/gui/popup_menu.h"
+static Node *_find_first_script(Node *p_root, Node *p_node) {
+ if (p_node != p_root && p_node->get_owner() != p_root) {
+ return NULL;
+ }
+ if (!p_node->get_script().is_null()) {
+ return p_node;
+ }
+
+ for (int i = 0; i < p_node->get_child_count(); i++) {
+
+ Node *ret = _find_first_script(p_root, p_node->get_child(i));
+ if (ret) {
+ return ret;
+ }
+ }
+
+ return NULL;
+}
+
class ConnectDialogBinds : public Object {
GDCLASS(ConnectDialogBinds, Object);
@@ -122,17 +141,8 @@ void ConnectDialog::_tree_node_selected() {
Node *current = tree->get_selected();
- if (!current) {
- make_callback->hide();
- return;
- }
-
- if (current->get_script().is_null())
- make_callback->hide();
- else
- make_callback->show();
-
- dst_path->set_text(source->get_path_to(current));
+ dst_path = source->get_path_to(current);
+ get_ok()->set_disabled(false);
}
/*
@@ -160,7 +170,9 @@ void ConnectDialog::_add_bind() {
case Variant::BASIS: value = Basis(); break;
case Variant::TRANSFORM: value = Transform(); break;
case Variant::COLOR: value = Color(); break;
- default: { ERR_FAIL(); } break;
+ default: {
+ ERR_FAIL();
+ } break;
}
ERR_FAIL_COND(value.get_type() == Variant::NIL);
@@ -193,6 +205,7 @@ void ConnectDialog::_notification(int p_what) {
void ConnectDialog::_bind_methods() {
+ ClassDB::bind_method("_advanced_pressed", &ConnectDialog::_advanced_pressed);
ClassDB::bind_method("_cancel", &ConnectDialog::_cancel_pressed);
ClassDB::bind_method("_tree_node_selected", &ConnectDialog::_tree_node_selected);
ClassDB::bind_method("_add_bind", &ConnectDialog::_add_bind);
@@ -213,7 +226,7 @@ StringName ConnectDialog::get_signal_name() const {
NodePath ConnectDialog::get_dst_path() const {
- return dst_path->get_text();
+ return dst_path;
}
void ConnectDialog::set_dst_node(Node *p_node) {
@@ -270,8 +283,13 @@ void ConnectDialog::init(Connection c, bool bEdit) {
tree->set_selected(NULL);
tree->set_marked(source, true);
- set_dst_node(static_cast<Node *>(c.target));
- set_dst_method(c.method);
+ if (c.target) {
+ get_ok()->set_disabled(false);
+ set_dst_node(static_cast<Node *>(c.target));
+ set_dst_method(c.method);
+ } else {
+ get_ok()->set_disabled(true);
+ }
bool bDeferred = (c.flags & CONNECT_DEFERRED) == CONNECT_DEFERRED;
bool bOneshot = (c.flags & CONNECT_ONESHOT) == CONNECT_ONESHOT;
@@ -286,6 +304,36 @@ void ConnectDialog::init(Connection c, bool bEdit) {
bEditMode = bEdit;
}
+void ConnectDialog::popup_dialog(const String &p_for_signal, bool p_advanced) {
+
+ advanced->set_pressed(p_advanced);
+ from_signal->set_text(p_for_signal);
+ error_label->add_color_override("font_color", get_color("error_color", "Editor"));
+
+ if (p_advanced) {
+
+ popup_centered(Size2(900, 500) * EDSCALE);
+ connect_to_label->set_text("Connect to Node:");
+ tree->set_connect_to_script_mode(false);
+ error_label->hide();
+ } else {
+ popup_centered(Size2(700, 500) * EDSCALE);
+ connect_to_label->set_text("Connect to Script:");
+ tree->set_connect_to_script_mode(true);
+
+ if (!_find_first_script(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root())) {
+ error_label->show();
+ } else {
+ error_label->hide();
+ }
+ }
+}
+
+void ConnectDialog::_advanced_pressed() {
+ vbc_right->set_visible(advanced->is_pressed());
+ popup_dialog(from_signal->get_text(), advanced->is_pressed());
+}
+
ConnectDialog::ConnectDialog() {
VBoxContainer *vbc = memnew(VBoxContainer);
@@ -299,15 +347,27 @@ ConnectDialog::ConnectDialog() {
main_hb->add_child(vbc_left);
vbc_left->set_h_size_flags(SIZE_EXPAND_FILL);
+ from_signal = memnew(LineEdit);
+ from_signal->set_editable(false);
+ vbc_left->add_margin_child(TTR("From Signal:"), from_signal);
+
tree = memnew(SceneTreeEditor(false));
tree->get_scene_tree()->connect("item_activated", this, "_ok");
tree->connect("node_selected", this, "_tree_node_selected");
+ tree->set_connect_to_script_mode(true);
- vbc_left->add_margin_child(TTR("Connect To Node:"), tree, true);
+ Node *mc = vbc_left->add_margin_child(TTR("Connect To Script:"), tree, true);
+ connect_to_label = Object::cast_to<Label>(vbc_left->get_child(mc->get_index() - 1));
- VBoxContainer *vbc_right = memnew(VBoxContainer);
+ error_label = memnew(Label);
+ error_label->set_text(TTR("Scene does not contain any script."));
+ vbc_left->add_child(error_label);
+ error_label->hide();
+
+ vbc_right = memnew(VBoxContainer);
main_hb->add_child(vbc_right);
vbc_right->set_h_size_flags(SIZE_EXPAND_FILL);
+ vbc_right->hide();
HBoxContainer *add_bind_hb = memnew(HBoxContainer);
@@ -345,16 +405,18 @@ ConnectDialog::ConnectDialog() {
vbc_right->add_margin_child(TTR("Extra Call Arguments:"), bind_editor, true);
- dst_path = memnew(LineEdit);
- vbc->add_margin_child(TTR("Path to Node:"), dst_path);
-
HBoxContainer *dstm_hb = memnew(HBoxContainer);
- vbc->add_margin_child("Method In Node:", dstm_hb);
+ vbc_left->add_margin_child("Method to Create:", dstm_hb);
dst_method = memnew(LineEdit);
dst_method->set_h_size_flags(SIZE_EXPAND_FILL);
dstm_hb->add_child(dst_method);
+ advanced = memnew(CheckBox);
+ dstm_hb->add_child(advanced);
+ advanced->set_text(TTR("Advanced.."));
+ advanced->connect("pressed", this, "_advanced_pressed");
+
/*
dst_method_list = memnew( MenuButton );
dst_method_list->set_text("List...");
@@ -366,19 +428,13 @@ ConnectDialog::ConnectDialog() {
dst_method_list->set_end( Point2( 15,39 ) );
*/
- make_callback = memnew(CheckButton);
- make_callback->set_toggle_mode(true);
- make_callback->set_pressed(EDITOR_DEF("text_editor/tools/create_signal_callbacks", true));
- make_callback->set_text(TTR("Make Function"));
- dstm_hb->add_child(make_callback);
-
deferred = memnew(CheckButton);
deferred->set_text(TTR("Deferred"));
- dstm_hb->add_child(deferred);
+ vbc_right->add_child(deferred);
oneshot = memnew(CheckButton);
oneshot->set_text(TTR("Oneshot"));
- dstm_hb->add_child(oneshot);
+ vbc_right->add_child(oneshot);
set_as_toplevel(true);
@@ -427,7 +483,8 @@ void ConnectionsDock::_make_or_edit_connection() {
bool oshot = connect_dialog->get_oneshot();
cToMake.flags = CONNECT_PERSIST | (defer ? CONNECT_DEFERRED : 0) | (oshot ? CONNECT_ONESHOT : 0);
- bool add_script_function = connect_dialog->get_make_callback();
+ //conditions to add function, must have a script and must have a method
+ bool add_script_function = !target->get_script().is_null() && !ClassDB::has_method(target->get_class(), cToMake.method);
PoolStringArray script_function_args;
if (add_script_function) {
// pick up args here before "it" is deleted by update_tree
@@ -566,6 +623,7 @@ bool ConnectionsDock::_is_item_signal(TreeItem &item) {
/*
Open connection dialog with TreeItem data to CREATE a brand-new connection.
*/
+
void ConnectionsDock::_open_connection_dialog(TreeItem &item) {
String signal = item.get_metadata(0).operator Dictionary()["name"];
@@ -588,6 +646,10 @@ void ConnectionsDock::_open_connection_dialog(TreeItem &item) {
}
Node *dst_node = selectedNode->get_owner() ? selectedNode->get_owner() : selectedNode;
+ if (!dst_node || dst_node->get_script().is_null()) {
+ dst_node = _find_first_script(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root());
+ }
+
StringName dst_method = "_on_" + midname + "_" + signal;
Connection c;
@@ -596,9 +658,10 @@ void ConnectionsDock::_open_connection_dialog(TreeItem &item) {
c.target = dst_node;
c.method = dst_method;
+ //connect_dialog->set_title(TTR("Connect Signal: ") + signalname);
+ connect_dialog->popup_dialog(signalname, false);
connect_dialog->init(c);
- connect_dialog->set_title(TTR("Connect Signal: ") + signalname);
- connect_dialog->popup_centered_ratio();
+ connect_dialog->set_title(TTR("Connect a Signal to a Method"));
}
/*
@@ -610,9 +673,9 @@ void ConnectionsDock::_open_connection_dialog(Connection cToEdit) {
Node *dst = static_cast<Node *>(cToEdit.target);
if (src && dst) {
- connect_dialog->init(cToEdit, true);
- connect_dialog->set_title(TTR("Edit Connection: ") + cToEdit.signal);
+ connect_dialog->set_title(TTR("Edit Connection:") + cToEdit.signal);
connect_dialog->popup_centered_ratio();
+ connect_dialog->init(cToEdit, true);
}
}
diff --git a/editor/connections_dialog.h b/editor/connections_dialog.h
index 0e7e172ebb..59fe6dacfe 100644
--- a/editor/connections_dialog.h
+++ b/editor/connections_dialog.h
@@ -53,12 +53,15 @@ class ConnectDialog : public ConfirmationDialog {
GDCLASS(ConnectDialog, ConfirmationDialog);
+ Label *connect_to_label;
+ LineEdit *from_signal;
Node *source;
StringName signal;
- LineEdit *dst_path;
LineEdit *dst_method;
ConnectDialogBinds *cdbinds;
bool bEditMode;
+ NodePath dst_path;
+ VBoxContainer *vbc_right;
SceneTreeEditor *tree;
ConfirmationDialog *error;
@@ -66,13 +69,16 @@ class ConnectDialog : public ConfirmationDialog {
OptionButton *type_list;
CheckButton *deferred;
CheckButton *oneshot;
- CheckButton *make_callback;
+ CheckBox *advanced;
+
+ Label *error_label;
void ok_pressed();
void _cancel_pressed();
void _tree_node_selected();
void _add_bind();
void _remove_bind();
+ void _advanced_pressed();
protected:
void _notification(int p_what);
@@ -87,13 +93,13 @@ public:
void set_dst_method(const StringName &p_method);
Vector<Variant> get_binds() const;
- bool get_make_callback() { return make_callback->is_visible() && make_callback->is_pressed(); }
bool get_deferred() const;
bool get_oneshot() const;
bool is_editing() const;
void init(Connection c, bool bEdit = false);
+ void popup_dialog(const String &p_for_signal, bool p_advanced);
ConnectDialog();
~ConnectDialog();
};
diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp
index 364c5126d7..26bd651c2b 100644
--- a/editor/create_dialog.cpp
+++ b/editor/create_dialog.cpp
@@ -238,6 +238,26 @@ void CreateDialog::add_type(const String &p_type, HashMap<String, TreeItem *> &p
p_types[p_type] = item;
}
+bool CreateDialog::_is_class_disabled_by_feature_profile(const StringName &p_class) {
+
+ Ref<EditorFeatureProfile> profile = EditorFeatureProfileManager::get_singleton()->get_current_profile();
+ if (profile.is_null()) {
+ return false;
+ }
+
+ StringName class_name = p_class;
+
+ while (class_name != StringName()) {
+
+ if (profile->is_class_disabled(class_name)) {
+ return true;
+ }
+ class_name = ClassDB::get_parent_class(class_name);
+ }
+
+ return false;
+}
+
void CreateDialog::_update_search() {
search_options->clear();
@@ -264,6 +284,10 @@ void CreateDialog::_update_search() {
for (List<StringName>::Element *I = type_list.front(); I; I = I->next()) {
String type = I->get();
+
+ if (_is_class_disabled_by_feature_profile(type)) {
+ continue;
+ }
bool cpp_type = ClassDB::class_exists(type);
if (base_type == "Node" && type.begins_with("Editor"))
diff --git a/editor/create_dialog.h b/editor/create_dialog.h
index 2636e2ddef..d859f7cbe4 100644
--- a/editor/create_dialog.h
+++ b/editor/create_dialog.h
@@ -86,6 +86,8 @@ class CreateDialog : public ConfirmationDialog {
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
+ bool _is_class_disabled_by_feature_profile(const StringName &p_class);
+
protected:
void _notification(int p_what);
static void _bind_methods();
diff --git a/editor/doc/doc_dump.cpp b/editor/doc/doc_dump.cpp
index 1a68fe5bf2..6ccf0e26ea 100644
--- a/editor/doc/doc_dump.cpp
+++ b/editor/doc/doc_dump.cpp
@@ -199,7 +199,8 @@ void DocDump::dump(const String &p_file) {
case Variant::ARRAY:
case Variant::_RID:
- default: {}
+ default: {
+ }
}
_write_string(f, 3, "<argument index=\"" + itos(i) + "\" name=\"" + _escape_string(arginfo.name) + "\" type=\"" + type_name + "\" default=\"" + _escape_string(default_arg_text) + "\">");
@@ -227,7 +228,8 @@ void DocDump::dump(const String &p_file) {
}
break;
case PROPERTY_HINT_FILE: hint = "A file:"; break;
- default: {}
+ default: {
+ }
//case PROPERTY_HINT_RESOURCE_TYPE: hint="Type: "+arginfo.hint_string; break;
};
if (hint != "")
diff --git a/editor/editor_feature_profile.cpp b/editor/editor_feature_profile.cpp
new file mode 100644
index 0000000000..714df44e25
--- /dev/null
+++ b/editor/editor_feature_profile.cpp
@@ -0,0 +1,889 @@
+#include "editor_feature_profile.h"
+#include "core/io/json.h"
+#include "core/os/dir_access.h"
+#include "editor/editor_settings.h"
+#include "editor_node.h"
+#include "editor_scale.h"
+
+const char *EditorFeatureProfile::feature_names[FEATURE_MAX] = {
+ TTRC("3D Editor"),
+ TTRC("Script Editor"),
+ TTRC("Asset Library"),
+ TTRC("Scene Tree Editing"),
+ TTRC("Import Dock"),
+ TTRC("Node Dock"),
+ TTRC("Filesystem Dock")
+};
+
+const char *EditorFeatureProfile::feature_identifiers[FEATURE_MAX] = {
+ "3d",
+ "script",
+ "asset_lib",
+ "scene_tree",
+ "import_dock",
+ "node_dock",
+ "filesystem_dock"
+};
+
+void EditorFeatureProfile::set_disable_class(const StringName &p_class, bool p_disabled) {
+ if (p_disabled) {
+ disabled_classes.insert(p_class);
+ } else {
+ disabled_classes.erase(p_class);
+ }
+}
+
+bool EditorFeatureProfile::is_class_disabled(const StringName &p_class) const {
+ return disabled_classes.has(p_class);
+}
+
+void EditorFeatureProfile::set_disable_class_editor(const StringName &p_class, bool p_disabled) {
+ if (p_disabled) {
+ disabled_editors.insert(p_class);
+ } else {
+ disabled_editors.erase(p_class);
+ }
+}
+
+bool EditorFeatureProfile::is_class_editor_disabled(const StringName &p_class) const {
+ return disabled_editors.has(p_class);
+}
+
+void EditorFeatureProfile::set_disable_class_property(const StringName &p_class, const StringName &p_property, bool p_disabled) {
+
+ if (p_disabled) {
+ if (!disabled_properties.has(p_class)) {
+ disabled_properties[p_class] = Set<StringName>();
+ }
+
+ disabled_properties[p_class].insert(p_property);
+ } else {
+ ERR_FAIL_COND(!disabled_properties.has(p_class));
+ disabled_properties[p_class].erase(p_property);
+ if (disabled_properties[p_class].empty()) {
+ disabled_properties.erase(p_class);
+ }
+ }
+}
+bool EditorFeatureProfile::is_class_property_disabled(const StringName &p_class, const StringName &p_property) const {
+
+ if (!disabled_properties.has(p_class)) {
+ return false;
+ }
+
+ if (!disabled_properties[p_class].has(p_property)) {
+ return false;
+ }
+
+ return true;
+}
+
+bool EditorFeatureProfile::has_class_properties_disabled(const StringName &p_class) const {
+ return disabled_properties.has(p_class);
+}
+
+void EditorFeatureProfile::set_disable_feature(Feature p_feature, bool p_disable) {
+
+ ERR_FAIL_INDEX(p_feature, FEATURE_MAX);
+ features_disabled[p_feature] = p_disable;
+}
+bool EditorFeatureProfile::is_feature_disabled(Feature p_feature) const {
+ ERR_FAIL_INDEX_V(p_feature, FEATURE_MAX, false);
+ return features_disabled[p_feature];
+}
+
+String EditorFeatureProfile::get_feature_name(Feature p_feature) {
+ ERR_FAIL_INDEX_V(p_feature, FEATURE_MAX, String());
+ return feature_names[p_feature];
+}
+
+Error EditorFeatureProfile::save_to_file(const String &p_path) {
+
+ Dictionary json;
+ json["type"] = "feature_profile";
+ Array dis_classes;
+ for (Set<StringName>::Element *E = disabled_classes.front(); E; E = E->next()) {
+ dis_classes.push_back(String(E->get()));
+ }
+ dis_classes.sort();
+ json["disabled_classes"] = dis_classes;
+
+ Array dis_editors;
+ for (Set<StringName>::Element *E = disabled_editors.front(); E; E = E->next()) {
+ dis_editors.push_back(String(E->get()));
+ }
+ dis_editors.sort();
+ json["disabled_editors"] = dis_editors;
+
+ Array dis_props;
+
+ for (Map<StringName, Set<StringName> >::Element *E = disabled_properties.front(); E; E = E->next()) {
+ for (Set<StringName>::Element *F = E->get().front(); F; F = F->next()) {
+ dis_props.push_back(String(E->key()) + ":" + String(F->get()));
+ }
+ }
+
+ json["disabled_properties"] = dis_props;
+
+ Array dis_features;
+ for (int i = 0; i < FEATURE_MAX; i++) {
+ if (features_disabled[i]) {
+ dis_features.push_back(feature_identifiers[i]);
+ }
+ }
+
+ json["disabled_features"] = dis_features;
+
+ FileAccessRef f = FileAccess::open(p_path, FileAccess::WRITE);
+ ERR_FAIL_COND_V(!f, ERR_CANT_OPEN);
+
+ String text = JSON::print(json, "\t");
+ f->store_string(text);
+ f->close();
+ return OK;
+}
+
+Error EditorFeatureProfile::load_from_file(const String &p_path) {
+
+ Error err;
+ String text = FileAccess::get_file_as_string(p_path, &err);
+ if (err != OK) {
+ return err;
+ }
+
+ String err_str;
+ int err_line;
+ Variant v;
+ err = JSON::parse(text, v, err_str, err_line);
+ if (err != OK) {
+ ERR_PRINTS("Error parsing '" + p_path + "' on line " + itos(err_line) + ": " + err_str);
+ return ERR_PARSE_ERROR;
+ }
+
+ Dictionary json = v;
+
+ if (!json.has("type") || String(json["type"]) != "feature_profile") {
+ ERR_PRINTS("Error parsing '" + p_path + "', it's not a feature profile.");
+ return ERR_PARSE_ERROR;
+ }
+
+ disabled_classes.clear();
+
+ if (json.has("disabled_classes")) {
+ Array disabled_classes_arr = json["disabled_classes"];
+ for (int i = 0; i < disabled_classes_arr.size(); i++) {
+ disabled_classes.insert(disabled_classes_arr[i]);
+ }
+ }
+
+ disabled_editors.clear();
+
+ if (json.has("disabled_editors")) {
+ Array disabled_editors_arr = json["disabled_editors"];
+ for (int i = 0; i < disabled_editors_arr.size(); i++) {
+ disabled_editors.insert(disabled_editors_arr[i]);
+ }
+ }
+
+ disabled_properties.clear();
+
+ if (json.has("disabled_properties")) {
+ Array disabled_properties_arr = json["disabled_properties"];
+ for (int i = 0; i < disabled_properties_arr.size(); i++) {
+ String s = disabled_properties_arr[i];
+ set_disable_class_property(s.get_slice(":", 0), s.get_slice(":", 1), true);
+ }
+ }
+
+ if (json.has("disabled_features")) {
+
+ Array disabled_features_arr = json["disabled_features"];
+ for (int i = 0; i < FEATURE_MAX; i++) {
+ bool found = false;
+ String f = feature_identifiers[i];
+ for (int j = 0; j < disabled_features_arr.size(); j++) {
+ String fd = disabled_features_arr[j];
+ if (fd == f) {
+ found = true;
+ break;
+ }
+ }
+
+ features_disabled[i] = found;
+ }
+ }
+
+ return OK;
+}
+
+void EditorFeatureProfile::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_disable_class", "class_name", "disable"), &EditorFeatureProfile::set_disable_class);
+ ClassDB::bind_method(D_METHOD("is_class_disabled", "class_name"), &EditorFeatureProfile::is_class_disabled);
+
+ ClassDB::bind_method(D_METHOD("set_disable_class_editor", "class_name", "disable"), &EditorFeatureProfile::set_disable_class_editor);
+ ClassDB::bind_method(D_METHOD("is_class_editor_disabled", "class_name"), &EditorFeatureProfile::is_class_editor_disabled);
+
+ ClassDB::bind_method(D_METHOD("set_disable_class_property", "class_name", "property"), &EditorFeatureProfile::set_disable_class_property);
+ ClassDB::bind_method(D_METHOD("is_class_property_disabled", "class_name"), &EditorFeatureProfile::is_class_property_disabled);
+
+ ClassDB::bind_method(D_METHOD("set_disable_feature", "feature", "disable"), &EditorFeatureProfile::set_disable_feature);
+ ClassDB::bind_method(D_METHOD("is_feature_disabled", "feature"), &EditorFeatureProfile::is_feature_disabled);
+
+ ClassDB::bind_method(D_METHOD("get_feature_name", "feature"), &EditorFeatureProfile::_get_feature_name);
+
+ ClassDB::bind_method(D_METHOD("save_to_file", "path"), &EditorFeatureProfile::save_to_file);
+ ClassDB::bind_method(D_METHOD("load_from_file", "path"), &EditorFeatureProfile::load_from_file);
+
+ BIND_ENUM_CONSTANT(FEATURE_3D);
+ BIND_ENUM_CONSTANT(FEATURE_SCRIPT);
+ BIND_ENUM_CONSTANT(FEATURE_ASSET_LIB);
+ BIND_ENUM_CONSTANT(FEATURE_SCENE_TREE);
+ BIND_ENUM_CONSTANT(FEATURE_IMPORT_DOCK);
+ BIND_ENUM_CONSTANT(FEATURE_NODE_DOCK);
+ BIND_ENUM_CONSTANT(FEATURE_FILESYSTEM_DOCK);
+ BIND_ENUM_CONSTANT(FEATURE_MAX);
+}
+
+EditorFeatureProfile::EditorFeatureProfile() {
+
+ for (int i = 0; i < FEATURE_MAX; i++) {
+ features_disabled[i] = false;
+ }
+}
+
+//////////////////////////
+
+void EditorFeatureProfileManager::_notification(int p_what) {
+ if (p_what == NOTIFICATION_READY) {
+
+ current_profile = EDITOR_GET("_default_feature_profile");
+ if (current_profile != String()) {
+ current.instance();
+ Error err = current->load_from_file(EditorSettings::get_singleton()->get_feature_profiles_dir().plus_file(current_profile + ".profile"));
+ if (err != OK) {
+ ERR_PRINTS("Error loading default feature profile: " + current_profile);
+ current_profile = String();
+ current.unref();
+ }
+ }
+ _update_profile_list(current_profile);
+ }
+}
+
+String EditorFeatureProfileManager::_get_selected_profile() {
+ int idx = profile_list->get_selected();
+ if (idx < 0) {
+ return String();
+ }
+
+ return profile_list->get_item_metadata(idx);
+}
+
+void EditorFeatureProfileManager::_update_profile_list(const String &p_select_profile) {
+
+ String selected_profile;
+ if (p_select_profile == String()) { //default, keep
+ if (profile_list->get_selected() >= 0) {
+ selected_profile = profile_list->get_item_metadata(profile_list->get_selected());
+ if (!FileAccess::exists(EditorSettings::get_singleton()->get_feature_profiles_dir().plus_file(selected_profile + ".profile"))) {
+ selected_profile = String(); //does not exist
+ }
+ }
+ } else {
+ selected_profile = p_select_profile;
+ }
+
+ Vector<String> profiles;
+ DirAccessRef d = DirAccess::open(EditorSettings::get_singleton()->get_feature_profiles_dir());
+ ERR_FAIL_COND(!d);
+ d->list_dir_begin();
+ while (true) {
+ String f = d->get_next();
+ if (f == String()) {
+ break;
+ }
+
+ if (!d->current_is_dir()) {
+ int last_pos = f.find_last(".profile");
+ if (last_pos != -1) {
+ profiles.push_back(f.substr(0, last_pos));
+ }
+ }
+ }
+
+ profiles.sort();
+
+ profile_list->clear();
+
+ for (int i = 0; i < profiles.size(); i++) {
+ String name = profiles[i];
+
+ if (i == 0 && selected_profile == String()) {
+ selected_profile = name;
+ }
+
+ if (name == current_profile) {
+ name += " (current)";
+ }
+ profile_list->add_item(name);
+ int index = profile_list->get_item_count() - 1;
+ profile_list->set_item_metadata(index, profiles[i]);
+ if (profiles[i] == selected_profile) {
+ profile_list->select(index);
+ }
+ }
+
+ profile_actions[PROFILE_CLEAR]->set_disabled(current_profile == String());
+ profile_actions[PROFILE_ERASE]->set_disabled(selected_profile == String());
+ profile_actions[PROFILE_EXPORT]->set_disabled(selected_profile == String());
+ profile_actions[PROFILE_SET]->set_disabled(selected_profile == String());
+
+ current_profile_name->set_text(current_profile);
+
+ _update_selected_profile();
+}
+
+void EditorFeatureProfileManager::_profile_action(int p_action) {
+
+ switch (p_action) {
+ case PROFILE_CLEAR: {
+ EditorSettings::get_singleton()->set("_default_feature_profile", "");
+ EditorSettings::get_singleton()->save();
+ current_profile = "";
+ current.unref();
+ _update_profile_list();
+ } break;
+ case PROFILE_SET: {
+
+ String selected = _get_selected_profile();
+ ERR_FAIL_COND(selected == String());
+ if (selected == current_profile) {
+ return; //nothing to do here
+ }
+ EditorSettings::get_singleton()->set("_default_feature_profile", selected);
+ EditorSettings::get_singleton()->save();
+ current_profile = selected;
+ current = edited;
+
+ _update_profile_list();
+
+ } break;
+ case PROFILE_IMPORT: {
+
+ import_profiles->popup_centered_ratio();
+ } break;
+ case PROFILE_EXPORT: {
+
+ export_profile->popup_centered_ratio();
+ export_profile->set_current_file(_get_selected_profile() + ".profile");
+ } break;
+ case PROFILE_NEW: {
+
+ new_profile_dialog->popup_centered_minsize();
+ new_profile_name->clear();
+ new_profile_name->grab_focus();
+ } break;
+ case PROFILE_ERASE: {
+ String selected = _get_selected_profile();
+ ERR_FAIL_COND(selected == String());
+
+ erase_profile_dialog->set_text(vformat(TTR("Erase profile '%s'? (no undo)"), selected));
+ erase_profile_dialog->popup_centered_minsize();
+ } break;
+ }
+}
+
+void EditorFeatureProfileManager::_erase_selected_profile() {
+
+ String selected = _get_selected_profile();
+ ERR_FAIL_COND(selected == String());
+ DirAccessRef da = DirAccess::open(EditorSettings::get_singleton()->get_feature_profiles_dir());
+ ERR_FAIL_COND(!da);
+ da->remove(selected + ".profile");
+ if (selected == current_profile) {
+ _profile_action(PROFILE_CLEAR);
+ } else {
+ _update_profile_list();
+ }
+}
+
+void EditorFeatureProfileManager::_create_new_profile() {
+ String name = new_profile_name->get_text().strip_edges();
+ if (!name.is_valid_filename() || name.find(".") != -1) {
+ EditorNode::get_singleton()->show_warning(TTR("Profile must be a valid filename and must not contain '.'"));
+ return;
+ }
+ String file = EditorSettings::get_singleton()->get_feature_profiles_dir().plus_file(name + ".profile");
+ if (FileAccess::exists(file)) {
+ EditorNode::get_singleton()->show_warning(TTR("Profile with this name already exists."));
+ return;
+ }
+
+ Ref<EditorFeatureProfile> new_profile;
+ new_profile.instance();
+ new_profile->save_to_file(file);
+
+ _update_profile_list(name);
+}
+
+void EditorFeatureProfileManager::_profile_selected(int p_what) {
+
+ _update_selected_profile();
+}
+
+void EditorFeatureProfileManager::_fill_classes_from(TreeItem *p_parent, const String &p_class, const String &p_selected) {
+
+ TreeItem *class_item = class_list->create_item(p_parent);
+ class_item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
+ class_item->set_icon(0, EditorNode::get_singleton()->get_class_icon(p_class, "Node"));
+ String text = p_class;
+
+ bool disabled = edited->is_class_disabled(p_class);
+ bool disabled_editor = edited->is_class_editor_disabled(p_class);
+ bool disabled_properties = edited->has_class_properties_disabled(p_class);
+ if (disabled) {
+ class_item->set_custom_color(0, get_color("disabled_font_color", "Editor"));
+ } else if (disabled_editor && disabled_properties) {
+ text += " " + TTR("(Editor Disabled, Properties Disabled)");
+ } else if (disabled_properties) {
+ text += " " + TTR("(Properties Disabled)");
+ } else if (disabled_editor) {
+ text += " " + TTR("(Editor Disabled)");
+ }
+ class_item->set_text(0, text);
+ class_item->set_editable(0, true);
+ class_item->set_selectable(0, true);
+ class_item->set_metadata(0, p_class);
+
+ if (p_class == p_selected) {
+ class_item->select(0);
+ }
+ if (disabled) {
+ //class disabled, do nothing else (do not show further)
+ return;
+ }
+
+ class_item->set_checked(0, true); // if its not disabled, its checked
+
+ List<StringName> child_classes;
+ ClassDB::get_direct_inheriters_from_class(p_class, &child_classes);
+ child_classes.sort_custom<StringName::AlphCompare>();
+
+ for (List<StringName>::Element *E = child_classes.front(); E; E = E->next()) {
+ String name = E->get();
+ if (name.begins_with("Editor") || ClassDB::get_api_type(name) != ClassDB::API_CORE) {
+ continue;
+ }
+ _fill_classes_from(class_item, name, p_selected);
+ }
+}
+
+void EditorFeatureProfileManager::_class_list_item_selected() {
+
+ if (updating_features)
+ return;
+
+ property_list->clear();
+
+ TreeItem *item = class_list->get_selected();
+ if (!item) {
+ return;
+ }
+
+ Variant md = item->get_metadata(0);
+ if (md.get_type() != Variant::STRING) {
+ return;
+ }
+
+ String class_name = md;
+
+ if (edited->is_class_disabled(class_name)) {
+ return;
+ }
+
+ updating_features = true;
+ TreeItem *root = property_list->create_item();
+ TreeItem *options = property_list->create_item(root);
+ options->set_text(0, TTR("Class Options:"));
+
+ {
+ TreeItem *option = property_list->create_item(options);
+ option->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
+ option->set_editable(0, true);
+ option->set_selectable(0, true);
+ option->set_checked(0, !edited->is_class_editor_disabled(class_name));
+ option->set_text(0, TTR("Enable Contextual Editor"));
+ option->set_metadata(0, CLASS_OPTION_DISABLE_EDITOR);
+ }
+
+ TreeItem *properties = property_list->create_item(root);
+ properties->set_text(0, TTR("Enabled Properties:"));
+
+ List<PropertyInfo> props;
+
+ ClassDB::get_property_list(class_name, &props, true);
+
+ for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
+
+ String name = E->get().name;
+ if (!(E->get().usage & PROPERTY_USAGE_EDITOR))
+ continue;
+ TreeItem *property = property_list->create_item(properties);
+ property->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
+ property->set_editable(0, true);
+ property->set_selectable(0, true);
+ property->set_checked(0, !edited->is_class_property_disabled(class_name, name));
+ property->set_text(0, name.capitalize());
+ property->set_metadata(0, name);
+ String icon_type = Variant::get_type_name(E->get().type);
+ property->set_icon(0, EditorNode::get_singleton()->get_class_icon(icon_type));
+ }
+
+ updating_features = false;
+}
+
+void EditorFeatureProfileManager::_class_list_item_edited() {
+
+ if (updating_features)
+ return;
+
+ TreeItem *item = class_list->get_edited();
+ if (!item) {
+ return;
+ }
+
+ bool checked = item->is_checked(0);
+
+ Variant md = item->get_metadata(0);
+ if (md.get_type() == Variant::STRING) {
+ String class_selected = md;
+ edited->set_disable_class(class_selected, !checked);
+ _save_and_update();
+ _update_selected_profile();
+ } else if (md.get_type() == Variant::INT) {
+ int feature_selected = md;
+ edited->set_disable_feature(EditorFeatureProfile::Feature(feature_selected), !checked);
+ _save_and_update();
+ }
+}
+
+void EditorFeatureProfileManager::_property_item_edited() {
+ if (updating_features)
+ return;
+
+ TreeItem *class_item = class_list->get_selected();
+ if (!class_item) {
+ return;
+ }
+
+ Variant md = class_item->get_metadata(0);
+ if (md.get_type() != Variant::STRING) {
+ return;
+ }
+
+ String class_name = md;
+
+ TreeItem *item = property_list->get_edited();
+ if (!item) {
+ return;
+ }
+ bool checked = item->is_checked(0);
+
+ md = item->get_metadata(0);
+ if (md.get_type() == Variant::STRING) {
+ String property_selected = md;
+ edited->set_disable_class_property(class_name, property_selected, !checked);
+ _save_and_update();
+ _update_selected_profile();
+ } else if (md.get_type() == Variant::INT) {
+ int feature_selected = md;
+ switch (feature_selected) {
+ case CLASS_OPTION_DISABLE_EDITOR: {
+ edited->set_disable_class_editor(class_name, !checked);
+ _save_and_update();
+ _update_selected_profile();
+ } break;
+ }
+ }
+}
+
+void EditorFeatureProfileManager::_update_selected_profile() {
+
+ String class_selected;
+ int feature_selected = -1;
+
+ if (class_list->get_selected()) {
+ Variant md = class_list->get_selected()->get_metadata(0);
+ if (md.get_type() == Variant::STRING) {
+ class_selected = md;
+ } else if (md.get_type() == Variant::INT) {
+ feature_selected = md;
+ }
+ }
+
+ class_list->clear();
+
+ String profile = _get_selected_profile();
+ if (profile == String()) { //nothing selected, nothing edited
+ property_list->clear();
+ edited.unref();
+ return;
+ }
+
+ if (profile == current_profile) {
+ edited = current; //reuse current profile (which is what editor uses)
+ ERR_FAIL_COND(current.is_null()); //nothing selected, current should never be null
+ } else {
+ //reload edited, if different from current
+ edited.instance();
+ Error err = edited->load_from_file(EditorSettings::get_singleton()->get_feature_profiles_dir().plus_file(profile + ".profile"));
+ ERR_FAIL_COND(err != OK);
+ }
+
+ updating_features = true;
+
+ TreeItem *root = class_list->create_item();
+
+ TreeItem *features = class_list->create_item(root);
+ features->set_text(0, TTR("Enabled Features:"));
+ for (int i = 0; i < EditorFeatureProfile::FEATURE_MAX; i++) {
+
+ TreeItem *feature = class_list->create_item(features);
+ feature->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
+ feature->set_text(0, TTRGET(EditorFeatureProfile::get_feature_name(EditorFeatureProfile::Feature(i))));
+ feature->set_selectable(0, true);
+ feature->set_editable(0, true);
+ feature->set_metadata(0, i);
+ if (!edited->is_feature_disabled(EditorFeatureProfile::Feature(i))) {
+ feature->set_checked(0, true);
+ }
+
+ if (i == feature_selected) {
+ feature->select(0);
+ }
+ }
+
+ TreeItem *classes = class_list->create_item(root);
+ classes->set_text(0, TTR("Enabled Classes:"));
+
+ _fill_classes_from(classes, "Node", class_selected);
+ _fill_classes_from(classes, "Resource", class_selected);
+
+ updating_features = false;
+
+ _class_list_item_selected();
+}
+
+void EditorFeatureProfileManager::_import_profiles(const Vector<String> &p_paths) {
+
+ //test it first
+ for (int i = 0; i < p_paths.size(); i++) {
+ Ref<EditorFeatureProfile> profile;
+ profile.instance();
+ Error err = profile->load_from_file(p_paths[i]);
+ String basefile = p_paths[i].get_file();
+ if (err != OK) {
+ EditorNode::get_singleton()->show_warning(vformat(TTR("File '%s' format is invalid, import aborted."), basefile));
+ return;
+ }
+
+ String dst_file = EditorSettings::get_singleton()->get_feature_profiles_dir().plus_file(basefile);
+
+ if (FileAccess::exists(dst_file)) {
+ EditorNode::get_singleton()->show_warning(vformat(TTR("Profile '%s' already exists. Remote it first before importing, import aborted."), basefile.get_basename()));
+ return;
+ }
+ }
+
+ //do it second
+ for (int i = 0; i < p_paths.size(); i++) {
+ Ref<EditorFeatureProfile> profile;
+ profile.instance();
+ Error err = profile->load_from_file(p_paths[i]);
+ ERR_CONTINUE(err != OK);
+ String basefile = p_paths[i].get_file();
+ String dst_file = EditorSettings::get_singleton()->get_feature_profiles_dir().plus_file(basefile);
+ profile->save_to_file(dst_file);
+ }
+
+ _update_profile_list();
+}
+
+void EditorFeatureProfileManager::_export_profile(const String &p_path) {
+
+ ERR_FAIL_COND(edited.is_null());
+ Error err = edited->save_to_file(p_path);
+ if (err != OK) {
+ EditorNode::get_singleton()->show_warning(vformat(TTR("Error saving profile to path: '%s'."), p_path));
+ }
+}
+
+void EditorFeatureProfileManager::_save_and_update() {
+
+ String edited_path = _get_selected_profile();
+ ERR_FAIL_COND(edited_path == String());
+ ERR_FAIL_COND(edited.is_null());
+
+ edited->save_to_file(EditorSettings::get_singleton()->get_feature_profiles_dir().plus_file(edited_path + ".profile"));
+
+ if (edited == current) {
+ update_timer->start();
+ }
+}
+
+void EditorFeatureProfileManager::_emit_current_profile_changed() {
+
+ emit_signal("current_feature_profile_changed");
+}
+
+void EditorFeatureProfileManager::notify_changed() {
+ _emit_current_profile_changed();
+}
+
+Ref<EditorFeatureProfile> EditorFeatureProfileManager::get_current_profile() {
+ return current;
+}
+
+EditorFeatureProfileManager *EditorFeatureProfileManager::singleton = NULL;
+
+void EditorFeatureProfileManager::_bind_methods() {
+
+ ClassDB::bind_method("_update_selected_profile", &EditorFeatureProfileManager::_update_selected_profile);
+ ClassDB::bind_method("_profile_action", &EditorFeatureProfileManager::_profile_action);
+ ClassDB::bind_method("_create_new_profile", &EditorFeatureProfileManager::_create_new_profile);
+ ClassDB::bind_method("_profile_selected", &EditorFeatureProfileManager::_profile_selected);
+ ClassDB::bind_method("_erase_selected_profile", &EditorFeatureProfileManager::_erase_selected_profile);
+ ClassDB::bind_method("_import_profiles", &EditorFeatureProfileManager::_import_profiles);
+ ClassDB::bind_method("_export_profile", &EditorFeatureProfileManager::_export_profile);
+ ClassDB::bind_method("_class_list_item_selected", &EditorFeatureProfileManager::_class_list_item_selected);
+ ClassDB::bind_method("_class_list_item_edited", &EditorFeatureProfileManager::_class_list_item_edited);
+ ClassDB::bind_method("_property_item_edited", &EditorFeatureProfileManager::_property_item_edited);
+ ClassDB::bind_method("_emit_current_profile_changed", &EditorFeatureProfileManager::_emit_current_profile_changed);
+
+ ADD_SIGNAL(MethodInfo("current_feature_profile_changed"));
+}
+
+EditorFeatureProfileManager::EditorFeatureProfileManager() {
+
+ VBoxContainer *main_vbc = memnew(VBoxContainer);
+ add_child(main_vbc);
+
+ HBoxContainer *name_hbc = memnew(HBoxContainer);
+ current_profile_name = memnew(LineEdit);
+ name_hbc->add_child(current_profile_name);
+ current_profile_name->set_editable(false);
+ current_profile_name->set_h_size_flags(SIZE_EXPAND_FILL);
+ profile_actions[PROFILE_CLEAR] = memnew(Button(TTR("Unset")));
+ name_hbc->add_child(profile_actions[PROFILE_CLEAR]);
+ profile_actions[PROFILE_CLEAR]->set_disabled(true);
+ profile_actions[PROFILE_CLEAR]->connect("pressed", this, "_profile_action", varray(PROFILE_CLEAR));
+
+ main_vbc->add_margin_child(TTR("Current Profile"), name_hbc);
+
+ HBoxContainer *profiles_hbc = memnew(HBoxContainer);
+ profile_list = memnew(OptionButton);
+ profile_list->set_h_size_flags(SIZE_EXPAND_FILL);
+ profiles_hbc->add_child(profile_list);
+ profile_list->connect("item_selected", this, "_profile_selected");
+
+ profile_actions[PROFILE_SET] = memnew(Button(TTR("Make Current")));
+ profiles_hbc->add_child(profile_actions[PROFILE_SET]);
+ profile_actions[PROFILE_SET]->set_disabled(true);
+ profile_actions[PROFILE_SET]->connect("pressed", this, "_profile_action", varray(PROFILE_SET));
+
+ profile_actions[PROFILE_ERASE] = memnew(Button(TTR("Remove")));
+ profiles_hbc->add_child(profile_actions[PROFILE_ERASE]);
+ profile_actions[PROFILE_ERASE]->set_disabled(true);
+ profile_actions[PROFILE_ERASE]->connect("pressed", this, "_profile_action", varray(PROFILE_ERASE));
+
+ profiles_hbc->add_child(memnew(VSeparator));
+
+ profile_actions[PROFILE_NEW] = memnew(Button(TTR("New")));
+ profiles_hbc->add_child(profile_actions[PROFILE_NEW]);
+ profile_actions[PROFILE_NEW]->connect("pressed", this, "_profile_action", varray(PROFILE_NEW));
+
+ profiles_hbc->add_child(memnew(VSeparator));
+
+ profile_actions[PROFILE_IMPORT] = memnew(Button(TTR("Import")));
+ profiles_hbc->add_child(profile_actions[PROFILE_IMPORT]);
+ profile_actions[PROFILE_IMPORT]->connect("pressed", this, "_profile_action", varray(PROFILE_IMPORT));
+
+ profile_actions[PROFILE_EXPORT] = memnew(Button(TTR("Export")));
+ profiles_hbc->add_child(profile_actions[PROFILE_EXPORT]);
+ profile_actions[PROFILE_EXPORT]->set_disabled(true);
+ profile_actions[PROFILE_EXPORT]->connect("pressed", this, "_profile_action", varray(PROFILE_EXPORT));
+
+ main_vbc->add_margin_child(TTR("Available Profiles"), profiles_hbc);
+
+ h_split = memnew(HSplitContainer);
+ h_split->set_v_size_flags(SIZE_EXPAND_FILL);
+ main_vbc->add_child(h_split);
+
+ VBoxContainer *class_list_vbc = memnew(VBoxContainer);
+ h_split->add_child(class_list_vbc);
+ class_list_vbc->set_h_size_flags(SIZE_EXPAND_FILL);
+
+ class_list = memnew(Tree);
+ class_list_vbc->add_margin_child(TTR("Enabled Classes"), class_list, true);
+ class_list->set_hide_root(true);
+ class_list->set_hide_folding(true);
+ class_list->set_edit_checkbox_cell_only_when_checkbox_is_pressed(true);
+ class_list->connect("cell_selected", this, "_class_list_item_selected");
+ class_list->connect("item_edited", this, "_class_list_item_edited", varray(), CONNECT_DEFERRED);
+
+ VBoxContainer *property_list_vbc = memnew(VBoxContainer);
+ h_split->add_child(property_list_vbc);
+ property_list_vbc->set_h_size_flags(SIZE_EXPAND_FILL);
+
+ property_list = memnew(Tree);
+ property_list_vbc->add_margin_child(TTR("Class Options"), property_list, true);
+ property_list->set_hide_root(true);
+ property_list->set_hide_folding(true);
+ property_list->set_edit_checkbox_cell_only_when_checkbox_is_pressed(true);
+ property_list->connect("item_edited", this, "_property_item_edited", varray(), CONNECT_DEFERRED);
+
+ new_profile_dialog = memnew(ConfirmationDialog);
+ new_profile_dialog->set_title(TTR("New profile name:"));
+ new_profile_name = memnew(LineEdit);
+ new_profile_dialog->add_child(new_profile_name);
+ new_profile_name->set_custom_minimum_size(Size2(300 * EDSCALE, 1));
+ add_child(new_profile_dialog);
+ new_profile_dialog->connect("confirmed", this, "_create_new_profile");
+ new_profile_dialog->register_text_enter(new_profile_name);
+ new_profile_dialog->get_ok()->set_text(TTR("Create"));
+
+ erase_profile_dialog = memnew(ConfirmationDialog);
+ add_child(erase_profile_dialog);
+ erase_profile_dialog->set_title(TTR("Erase Profile"));
+ erase_profile_dialog->connect("confirmed", this, "_erase_selected_profile");
+
+ import_profiles = memnew(EditorFileDialog);
+ add_child(import_profiles);
+ import_profiles->set_mode(EditorFileDialog::MODE_OPEN_FILES);
+ import_profiles->add_filter("*.profile; Godot Feature Profile");
+ import_profiles->connect("files_selected", this, "_import_profiles");
+ import_profiles->set_title(TTR("Import Profile(s)"));
+ import_profiles->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
+
+ export_profile = memnew(EditorFileDialog);
+ add_child(export_profile);
+ export_profile->set_mode(EditorFileDialog::MODE_SAVE_FILE);
+ export_profile->add_filter("*.profile; Godot Feature Profile");
+ export_profile->connect("file_selected", this, "_export_profile");
+ export_profile->set_title(TTR("Export Profile"));
+ export_profile->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
+
+ set_title(TTR("Manage Editor Feature Profiles"));
+ EDITOR_DEF("_default_feature_profile", "");
+
+ update_timer = memnew(Timer);
+ update_timer->set_wait_time(1); //wait a second before updating editor
+ add_child(update_timer);
+ update_timer->connect("timeout", this, "_emit_current_profile_changed");
+ update_timer->set_one_shot(true);
+
+ updating_features = false;
+
+ singleton = this;
+}
diff --git a/editor/editor_feature_profile.h b/editor/editor_feature_profile.h
new file mode 100644
index 0000000000..b7c2ebc1b2
--- /dev/null
+++ b/editor/editor_feature_profile.h
@@ -0,0 +1,142 @@
+#ifndef EDITOR_FEATURE_PROFILE_H
+#define EDITOR_FEATURE_PROFILE_H
+
+#include "core/os/file_access.h"
+#include "core/reference.h"
+#include "editor/editor_file_dialog.h"
+#include "scene/gui/dialogs.h"
+#include "scene/gui/option_button.h"
+#include "scene/gui/separator.h"
+#include "scene/gui/split_container.h"
+#include "scene/gui/tree.h"
+
+class EditorFeatureProfile : public Reference {
+ GDCLASS(EditorFeatureProfile, Reference);
+
+public:
+ enum Feature {
+ FEATURE_3D,
+ FEATURE_SCRIPT,
+ FEATURE_ASSET_LIB,
+ FEATURE_SCENE_TREE,
+ FEATURE_IMPORT_DOCK,
+ FEATURE_NODE_DOCK,
+ FEATURE_FILESYSTEM_DOCK,
+ FEATURE_MAX
+ };
+
+private:
+ Set<StringName> disabled_classes;
+ Set<StringName> disabled_editors;
+ Map<StringName, Set<StringName> > disabled_properties;
+
+ bool features_disabled[FEATURE_MAX];
+ static const char *feature_names[FEATURE_MAX];
+ static const char *feature_identifiers[FEATURE_MAX];
+
+ String _get_feature_name(Feature p_feature) { return get_feature_name(p_feature); }
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_disable_class(const StringName &p_class, bool p_disabled);
+ bool is_class_disabled(const StringName &p_class) const;
+
+ void set_disable_class_editor(const StringName &p_class, bool p_disabled);
+ bool is_class_editor_disabled(const StringName &p_class) const;
+
+ void set_disable_class_property(const StringName &p_class, const StringName &p_property, bool p_disabled);
+ bool is_class_property_disabled(const StringName &p_class, const StringName &p_property) const;
+ bool has_class_properties_disabled(const StringName &p_class) const;
+
+ void set_disable_feature(Feature p_feature, bool p_disable);
+ bool is_feature_disabled(Feature p_feature) const;
+
+ Error save_to_file(const String &p_path);
+ Error load_from_file(const String &p_path);
+
+ static String get_feature_name(Feature p_feature);
+
+ EditorFeatureProfile();
+};
+
+VARIANT_ENUM_CAST(EditorFeatureProfile::Feature)
+
+class EditorFeatureProfileManager : public AcceptDialog {
+
+ GDCLASS(EditorFeatureProfileManager, AcceptDialog);
+
+ enum Action {
+ PROFILE_CLEAR,
+ PROFILE_SET,
+ PROFILE_IMPORT,
+ PROFILE_EXPORT,
+ PROFILE_NEW,
+ PROFILE_ERASE,
+ PROFILE_MAX
+ };
+
+ enum ClassOptions {
+ CLASS_OPTION_DISABLE_EDITOR
+ };
+
+ ConfirmationDialog *erase_profile_dialog;
+ ConfirmationDialog *new_profile_dialog;
+ LineEdit *new_profile_name;
+
+ LineEdit *current_profile_name;
+ OptionButton *profile_list;
+ Button *profile_actions[PROFILE_MAX];
+
+ HSplitContainer *h_split;
+
+ Tree *class_list;
+ Tree *property_list;
+
+ EditorFileDialog *import_profiles;
+ EditorFileDialog *export_profile;
+
+ void _profile_action(int p_action);
+ void _profile_selected(int p_what);
+
+ String current_profile;
+ void _update_profile_list(const String &p_select_profile = String());
+ void _update_selected_profile();
+ void _fill_classes_from(TreeItem *p_parent, const String &p_class, const String &p_selected);
+
+ Ref<EditorFeatureProfile> current;
+ Ref<EditorFeatureProfile> edited;
+
+ void _erase_selected_profile();
+ void _create_new_profile();
+ String _get_selected_profile();
+
+ void _import_profiles(const Vector<String> &p_paths);
+ void _export_profile(const String &p_path);
+
+ bool updating_features;
+
+ void _class_list_item_selected();
+ void _class_list_item_edited();
+ void _property_item_edited();
+ void _save_and_update();
+
+ Timer *update_timer;
+ void _emit_current_profile_changed();
+
+ static EditorFeatureProfileManager *singleton;
+
+protected:
+ static void _bind_methods();
+ void _notification(int p_what);
+
+public:
+ Ref<EditorFeatureProfile> get_current_profile();
+ void notify_changed();
+
+ static EditorFeatureProfileManager *get_singleton() { return singleton; }
+ EditorFeatureProfileManager();
+};
+
+#endif // EDITOR_FEATURE_PROFILE_H
diff --git a/editor/editor_folding.cpp b/editor/editor_folding.cpp
index 77c0f7491e..f6079624de 100644
--- a/editor/editor_folding.cpp
+++ b/editor/editor_folding.cpp
@@ -92,7 +92,7 @@ void EditorFolding::load_resource_folding(RES p_resource, const String &p_path)
_set_unfolds(p_resource.ptr(), unfolds);
}
-void EditorFolding::_fill_folds(const Node *p_root, const Node *p_node, Array &p_folds, Array &resource_folds, Set<RES> &resources) {
+void EditorFolding::_fill_folds(const Node *p_root, const Node *p_node, Array &p_folds, Array &resource_folds, Array& nodes_folded,Set<RES> &resources) {
if (p_root != p_node) {
if (!p_node->get_owner()) {
return; //not owned, bye
@@ -102,6 +102,9 @@ void EditorFolding::_fill_folds(const Node *p_root, const Node *p_node, Array &p
}
}
+ if (p_node->is_displayed_folded()) {
+ nodes_folded.push_back(p_root->get_path_to(p_node));
+ }
PoolVector<String> unfolds = _get_unfolds(p_node);
if (unfolds.size()) {
@@ -112,20 +115,22 @@ void EditorFolding::_fill_folds(const Node *p_root, const Node *p_node, Array &p
List<PropertyInfo> plist;
p_node->get_property_list(&plist);
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
- if (E->get().type == Variant::OBJECT) {
- RES res = p_node->get(E->get().name);
- if (res.is_valid() && !resources.has(res) && res->get_path() != String() && !res->get_path().is_resource_file()) {
-
- PoolVector<String> res_unfolds = _get_unfolds(res.ptr());
- resource_folds.push_back(res->get_path());
- resource_folds.push_back(res_unfolds);
- resources.insert(res);
+ if (E->get().usage & PROPERTY_USAGE_EDITOR) {
+ if (E->get().type == Variant::OBJECT) {
+ RES res = p_node->get(E->get().name);
+ if (res.is_valid() && !resources.has(res) && res->get_path() != String() && !res->get_path().is_resource_file()) {
+
+ PoolVector<String> res_unfolds = _get_unfolds(res.ptr());
+ resource_folds.push_back(res->get_path());
+ resource_folds.push_back(res_unfolds);
+ resources.insert(res);
+ }
}
}
}
for (int i = 0; i < p_node->get_child_count(); i++) {
- _fill_folds(p_root, p_node->get_child(i), p_folds, resource_folds, resources);
+ _fill_folds(p_root, p_node->get_child(i), p_folds, resource_folds, nodes_folded,resources);
}
}
void EditorFolding::save_scene_folding(const Node *p_scene, const String &p_path) {
@@ -135,10 +140,12 @@ void EditorFolding::save_scene_folding(const Node *p_scene, const String &p_path
Array unfolds, res_unfolds;
Set<RES> resources;
- _fill_folds(p_scene, p_scene, unfolds, res_unfolds, resources);
+ Array nodes_folded;
+ _fill_folds(p_scene, p_scene, unfolds, res_unfolds, nodes_folded, resources);
config->set_value("folding", "node_unfolds", unfolds);
config->set_value("folding", "resource_unfolds", res_unfolds);
+ config->set_value("folding", "nodes_folded", nodes_folded);
String path = EditorSettings::get_singleton()->get_project_settings_dir();
String file = p_path.get_file() + "-folding-" + p_path.md5_text() + ".cfg";
@@ -166,6 +173,10 @@ void EditorFolding::load_scene_folding(Node *p_scene, const String &p_path) {
if (config->has_section_key("folding", "resource_unfolds")) {
res_unfolds = config->get_value("folding", "resource_unfolds");
}
+ Array nodes_folded;
+ if (config->has_section_key("folding", "nodes_folded")) {
+ nodes_folded = config->get_value("folding", "nodes_folded");
+ }
ERR_FAIL_COND(unfolds.size() & 1);
ERR_FAIL_COND(res_unfolds.size() & 1);
@@ -193,6 +204,14 @@ void EditorFolding::load_scene_folding(Node *p_scene, const String &p_path) {
PoolVector<String> unfolds2 = res_unfolds[i + 1];
_set_unfolds(res.ptr(), unfolds2);
}
+
+ for(int i=0;i<nodes_folded.size();i++) {
+ NodePath fold_path = nodes_folded[i];
+ if (p_scene->has_node(fold_path)) {
+ Node *node = p_scene->get_node(fold_path);
+ node->set_display_folded(true);
+ }
+ }
}
bool EditorFolding::has_folding_data(const String &p_path) {
diff --git a/editor/editor_folding.h b/editor/editor_folding.h
index e4f7dbba80..5fc980c4a9 100644
--- a/editor/editor_folding.h
+++ b/editor/editor_folding.h
@@ -38,7 +38,7 @@ class EditorFolding {
PoolVector<String> _get_unfolds(const Object *p_object);
void _set_unfolds(Object *p_object, const PoolVector<String> &p_unfolds);
- void _fill_folds(const Node *p_root, const Node *p_node, Array &p_folds, Array &resource_folds, Set<RES> &resources);
+ void _fill_folds(const Node *p_root, const Node *p_node, Array &p_folds, Array &resource_folds, Array &nodes_folded, Set<RES> &resources);
void _do_object_unfolds(Object *p_object, Set<RES> &resources);
void _do_node_unfolds(Node *p_root, Node *p_node, Set<RES> &resources);
diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp
index 60fa5ff16f..c705f9af2b 100644
--- a/editor/editor_inspector.cpp
+++ b/editor/editor_inspector.cpp
@@ -1370,6 +1370,30 @@ void EditorInspector::_parse_added_editors(VBoxContainer *current_vbox, Ref<Edit
ped->added_editors.clear();
}
+bool EditorInspector::_is_property_disabled_by_feature_profile(const StringName &p_property) {
+
+ Ref<EditorFeatureProfile> profile = EditorFeatureProfileManager::get_singleton()->get_current_profile();
+ if (profile.is_null()) {
+ return false;
+ }
+
+ StringName class_name = object->get_class();
+
+ while (class_name != StringName()) {
+
+ if (profile->is_class_property_disabled(class_name, p_property)) {
+ return true;
+ }
+ if (profile->is_class_disabled(class_name)) {
+ //won't see properties of a disabled class
+ return true;
+ }
+ class_name = ClassDB::get_parent_class(class_name);
+ }
+
+ return false;
+}
+
void EditorInspector::update_tree() {
//to update properly if all is refreshed
@@ -1513,7 +1537,7 @@ void EditorInspector::update_tree() {
continue;
- } else if (!(p.usage & PROPERTY_USAGE_EDITOR))
+ } else if (!(p.usage & PROPERTY_USAGE_EDITOR) || _is_property_disabled_by_feature_profile(p.name))
continue;
if (p.usage & PROPERTY_USAGE_HIGH_END_GFX && VS::get_singleton()->is_low_end())
@@ -2132,6 +2156,10 @@ void EditorInspector::_node_removed(Node *p_node) {
void EditorInspector::_notification(int p_what) {
+ if (p_what == NOTIFICATION_READY) {
+ EditorFeatureProfileManager::get_singleton()->connect("current_feature_profile_changed", this, "_feature_profile_changed");
+ }
+
if (p_what == NOTIFICATION_ENTER_TREE) {
if (sub_inspector) {
@@ -2238,6 +2266,11 @@ String EditorInspector::get_object_class() const {
return object_class;
}
+void EditorInspector::_feature_profile_changed() {
+
+ update_tree();
+}
+
void EditorInspector::_bind_methods() {
ClassDB::bind_method("_property_changed", &EditorInspector::_property_changed, DEFVAL(""), DEFVAL(false));
@@ -2254,6 +2287,7 @@ void EditorInspector::_bind_methods() {
ClassDB::bind_method("_resource_selected", &EditorInspector::_resource_selected);
ClassDB::bind_method("_object_id_selected", &EditorInspector::_object_id_selected);
ClassDB::bind_method("_vscroll_changed", &EditorInspector::_vscroll_changed);
+ ClassDB::bind_method("_feature_profile_changed", &EditorInspector::_feature_profile_changed);
ClassDB::bind_method("refresh", &EditorInspector::refresh);
diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h
index 3d22cdb9a3..494e8b5833 100644
--- a/editor/editor_inspector.h
+++ b/editor/editor_inspector.h
@@ -323,6 +323,10 @@ class EditorInspector : public ScrollContainer {
void _vscroll_changed(double);
+ void _feature_profile_changed();
+
+ bool _is_property_disabled_by_feature_profile(const StringName &p_property);
+
protected:
static void _bind_methods();
void _notification(int p_what);
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 91e104667e..851d6a0aa6 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -306,7 +306,14 @@ void EditorNode::_notification(int p_what) {
VisualServer::get_singleton()->viewport_set_hide_canvas(get_scene_root()->get_viewport_rid(), true);
VisualServer::get_singleton()->viewport_set_disable_environment(get_viewport()->get_viewport_rid(), true);
- _editor_select(EDITOR_3D);
+ feature_profile_manager->notify_changed();
+
+ if (!main_editor_buttons[EDITOR_3D]->is_visible()) { //may be hidden due to feature profile
+ _editor_select(EDITOR_2D);
+ } else {
+ _editor_select(EDITOR_3D);
+ }
+
_update_debug_options();
/* DO NOT LOAD SCENES HERE, WAIT FOR FILE SCANNING AND REIMPORT TO COMPLETE */
@@ -558,11 +565,14 @@ void EditorNode::_editor_select_next() {
int editor = _get_current_main_editor();
- if (editor == editor_table.size() - 1) {
- editor = 0;
- } else {
- editor++;
- }
+ do {
+ if (editor == editor_table.size() - 1) {
+ editor = 0;
+ } else {
+ editor++;
+ }
+ } while (main_editor_buttons[editor]->is_visible());
+
_editor_select(editor);
}
@@ -570,11 +580,14 @@ void EditorNode::_editor_select_prev() {
int editor = _get_current_main_editor();
- if (editor == 0) {
- editor = editor_table.size() - 1;
- } else {
- editor--;
- }
+ do {
+ if (editor == 0) {
+ editor = editor_table.size() - 1;
+ } else {
+ editor--;
+ }
+ } while (main_editor_buttons[editor]->is_visible());
+
_editor_select(editor);
}
@@ -911,7 +924,8 @@ bool EditorNode::_find_and_save_edited_subresources(Object *obj, Map<RES, bool>
ret_changed = true;
}
} break;
- default: {}
+ default: {
+ }
}
}
@@ -1292,6 +1306,7 @@ void EditorNode::_dialog_action(String p_file) {
_save_default_environment();
_save_scene_with_preview(p_file, scene_idx);
_add_to_recent_scenes(p_file);
+ save_layout();
if (scene_idx != -1)
_discard_changes();
@@ -1440,17 +1455,48 @@ void EditorNode::_dialog_action(String p_file) {
bool EditorNode::item_has_editor(Object *p_object) {
+ if (_is_class_editor_disabled_by_feature_profile(p_object->get_class())) {
+ return false;
+ }
+
return editor_data.get_subeditors(p_object).size() > 0;
}
void EditorNode::edit_item_resource(RES p_resource) {
edit_item(p_resource.ptr());
}
+
+bool EditorNode::_is_class_editor_disabled_by_feature_profile(const StringName &p_class) {
+
+ Ref<EditorFeatureProfile> profile = EditorFeatureProfileManager::get_singleton()->get_current_profile();
+ if (profile.is_null()) {
+ return false;
+ }
+
+ StringName class_name = p_class;
+
+ while (class_name != StringName()) {
+
+ if (profile->is_class_disabled(class_name)) {
+ return true;
+ }
+ if (profile->is_class_editor_disabled(class_name)) {
+ return true;
+ }
+ class_name = ClassDB::get_parent_class(class_name);
+ }
+
+ return false;
+}
+
void EditorNode::edit_item(Object *p_object) {
Vector<EditorPlugin *> sub_plugins;
if (p_object) {
+ if (_is_class_editor_disabled_by_feature_profile(p_object->get_class())) {
+ return;
+ }
sub_plugins = editor_data.get_subeditors(p_object);
}
@@ -1640,6 +1686,12 @@ void EditorNode::_edit_current() {
EditorPlugin *main_plugin = editor_data.get_editor(current_obj);
+ for (int i = 0; i < editor_table.size(); i++) {
+ if (editor_table[i] == main_plugin && !main_editor_buttons[i]->is_visible()) {
+ main_plugin = NULL; //if button is not visible, then no plugin active
+ }
+ }
+
if (main_plugin) {
// special case if use of external editor is true
@@ -1677,7 +1729,11 @@ void EditorNode::_edit_current() {
}
}
- Vector<EditorPlugin *> sub_plugins = editor_data.get_subeditors(current_obj);
+ Vector<EditorPlugin *> sub_plugins;
+
+ if (!_is_class_editor_disabled_by_feature_profile(current_obj->get_class())) {
+ sub_plugins = editor_data.get_subeditors(current_obj);
+ }
if (!sub_plugins.empty()) {
_display_top_editors(false);
@@ -1685,7 +1741,6 @@ void EditorNode::_edit_current() {
_set_top_editors(sub_plugins);
_set_editing_top_editors(current_obj);
_display_top_editors(true);
-
} else if (!editor_plugins_over->get_plugins_list().empty()) {
hide_top_editors();
@@ -2359,6 +2414,11 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
export_template_manager->popup_manager();
} break;
+ case SETTINGS_MANAGE_FEATURE_PROFILES: {
+
+ feature_profile_manager->popup_centered_ratio();
+
+ } break;
case SETTINGS_TOGGLE_FULLSCREEN: {
OS::get_singleton()->set_window_fullscreen(!OS::get_singleton()->is_window_fullscreen());
@@ -2541,10 +2601,13 @@ void EditorNode::_editor_select(int p_which) {
if (selecting || changing_scene)
return;
- selecting = true;
-
ERR_FAIL_INDEX(p_which, editor_table.size());
+ if (!main_editor_buttons[p_which]->is_visible()) //button hidden, no editor
+ return;
+
+ selecting = true;
+
for (int i = 0; i < main_editor_buttons.size(); i++) {
main_editor_buttons[i]->set_pressed(i == p_which);
}
@@ -3284,6 +3347,7 @@ void EditorNode::register_editor_types() {
ClassDB::register_class<EditorProperty>();
ClassDB::register_class<AnimationTrackEditPlugin>();
ClassDB::register_class<ScriptCreateDialog>();
+ ClassDB::register_class<EditorFeatureProfile>();
// FIXME: Is this stuff obsolete, or should it be ported to new APIs?
ClassDB::register_class<EditorScenePostImport>();
@@ -3821,7 +3885,13 @@ void EditorNode::_update_dock_slots_visibility() {
} else {
for (int i = 0; i < DOCK_SLOT_MAX; i++) {
- if (dock_slot[i]->get_tab_count())
+ int tabs_visible = 0;
+ for (int j = 0; j < dock_slot[i]->get_tab_count(); j++) {
+ if (!dock_slot[i]->get_tab_hidden(j)) {
+ tabs_visible++;
+ }
+ }
+ if (tabs_visible)
dock_slot[i]->show();
else
dock_slot[i]->hide();
@@ -4000,6 +4070,7 @@ void EditorNode::_load_open_scenes_from_config(Ref<ConfigFile> p_layout, const S
for (int i = 0; i < scenes.size(); i++) {
load_scene(scenes[i]);
}
+ save_layout();
restoring_scenes = false;
}
@@ -4806,6 +4877,39 @@ void EditorNode::_resource_loaded(RES p_resource, const String &p_path) {
singleton->editor_folding.load_resource_folding(p_resource, p_path);
}
+void EditorNode::_feature_profile_changed() {
+
+ Ref<EditorFeatureProfile> profile = feature_profile_manager->get_current_profile();
+ TabContainer *import_tabs = cast_to<TabContainer>(import_dock->get_parent());
+ TabContainer *node_tabs = cast_to<TabContainer>(node_dock->get_parent());
+ TabContainer *fs_tabs = cast_to<TabContainer>(filesystem_dock->get_parent());
+ if (profile.is_valid()) {
+
+ import_tabs->set_tab_hidden(import_dock->get_index(), profile->is_feature_disabled(EditorFeatureProfile::FEATURE_IMPORT_DOCK));
+ node_tabs->set_tab_hidden(node_dock->get_index(), profile->is_feature_disabled(EditorFeatureProfile::FEATURE_NODE_DOCK));
+ fs_tabs->set_tab_hidden(filesystem_dock->get_index(), profile->is_feature_disabled(EditorFeatureProfile::FEATURE_FILESYSTEM_DOCK));
+
+ main_editor_buttons[EDITOR_3D]->set_visible(!profile->is_feature_disabled(EditorFeatureProfile::FEATURE_3D));
+ main_editor_buttons[EDITOR_SCRIPT]->set_visible(!profile->is_feature_disabled(EditorFeatureProfile::FEATURE_SCRIPT));
+ main_editor_buttons[EDITOR_ASSETLIB]->set_visible(!profile->is_feature_disabled(EditorFeatureProfile::FEATURE_ASSET_LIB));
+ if (profile->is_feature_disabled(EditorFeatureProfile::FEATURE_3D) || profile->is_feature_disabled(EditorFeatureProfile::FEATURE_ASSET_LIB) || profile->is_feature_disabled(EditorFeatureProfile::FEATURE_ASSET_LIB)) {
+ _editor_select(EDITOR_2D);
+ }
+ } else {
+
+ import_tabs->set_tab_hidden(import_dock->get_index(), false);
+ node_tabs->set_tab_hidden(node_dock->get_index(), false);
+ fs_tabs->set_tab_hidden(filesystem_dock->get_index(), false);
+ import_dock->set_visible(true);
+ node_dock->set_visible(true);
+ filesystem_dock->set_visible(true);
+ main_editor_buttons[EDITOR_3D]->set_visible(true);
+ main_editor_buttons[EDITOR_ASSETLIB]->set_visible(true);
+ }
+
+ _update_dock_slots_visibility();
+}
+
void EditorNode::_bind_methods() {
ClassDB::bind_method("_menu_option", &EditorNode::_menu_option);
@@ -4884,6 +4988,7 @@ void EditorNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("_video_driver_selected"), &EditorNode::_video_driver_selected);
ClassDB::bind_method(D_METHOD("_resources_changed"), &EditorNode::_resources_changed);
+ ClassDB::bind_method(D_METHOD("_feature_profile_changed"), &EditorNode::_feature_profile_changed);
ADD_SIGNAL(MethodInfo("play_pressed"));
ADD_SIGNAL(MethodInfo("pause_pressed"));
@@ -5397,8 +5502,11 @@ EditorNode::EditorNode() {
export_template_manager = memnew(ExportTemplateManager);
gui_base->add_child(export_template_manager);
+ feature_profile_manager = memnew(EditorFeatureProfileManager);
+ gui_base->add_child(feature_profile_manager);
about = memnew(EditorAbout);
gui_base->add_child(about);
+ feature_profile_manager->connect("current_feature_profile_changed", this, "_feature_profile_changed");
warning = memnew(AcceptDialog);
gui_base->add_child(warning);
@@ -5554,6 +5662,10 @@ EditorNode::EditorNode() {
}
p->add_separator();
+ p->add_item(TTR("Manage Editor Features"), SETTINGS_MANAGE_FEATURE_PROFILES);
+
+ p->add_separator();
+
p->add_item(TTR("Manage Export Templates"), SETTINGS_MANAGE_EXPORT_TEMPLATES);
// Help Menu
diff --git a/editor/editor_node.h b/editor/editor_node.h
index 267c70c773..5ed0bd4ac3 100644
--- a/editor/editor_node.h
+++ b/editor/editor_node.h
@@ -38,6 +38,7 @@
#include "editor/editor_about.h"
#include "editor/editor_data.h"
#include "editor/editor_export.h"
+#include "editor/editor_feature_profile.h"
#include "editor/editor_folding.h"
#include "editor/editor_inspector.h"
#include "editor/editor_log.h"
@@ -84,7 +85,6 @@
#include "scene/gui/tool_button.h"
#include "scene/gui/tree.h"
#include "scene/gui/viewport_container.h"
-
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
@@ -175,6 +175,7 @@ private:
SETTINGS_EDITOR_DATA_FOLDER,
SETTINGS_EDITOR_CONFIG_FOLDER,
SETTINGS_MANAGE_EXPORT_TEMPLATES,
+ SETTINGS_MANAGE_FEATURE_PROFILES,
SETTINGS_PICK_MAIN_SCENE,
SETTINGS_TOGGLE_FULLSCREEN,
SETTINGS_HELP,
@@ -294,6 +295,7 @@ private:
ProjectSettingsEditor *project_settings;
EditorFileDialog *file;
ExportTemplateManager *export_template_manager;
+ EditorFeatureProfileManager *feature_profile_manager;
EditorFileDialog *file_templates;
EditorFileDialog *file_export;
EditorFileDialog *file_export_lib;
@@ -610,6 +612,9 @@ private:
void _resources_changed(const PoolVector<String> &p_resources);
+ void _feature_profile_changed();
+ bool _is_class_editor_disabled_by_feature_profile(const StringName &p_class);
+
protected:
void _notification(int p_what);
static void _bind_methods();
diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp
index 0e8cd955b5..31f53305e2 100644
--- a/editor/editor_properties.cpp
+++ b/editor/editor_properties.cpp
@@ -2883,7 +2883,8 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
case PROPERTY_HINT_LAYERS_3D_PHYSICS:
lt = EditorPropertyLayers::LAYER_PHYSICS_3D;
break;
- default: {} //compiler could be smarter here and realize this can't happen
+ default: {
+ } //compiler could be smarter here and realize this can't happen
}
EditorPropertyLayers *editor = memnew(EditorPropertyLayers);
editor->setup(lt);
@@ -3020,7 +3021,8 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
case PROPERTY_HINT_PROPERTY_OF_BASE_TYPE: type = EditorPropertyMember::MEMBER_PROPERTY_OF_BASE_TYPE; break;
case PROPERTY_HINT_PROPERTY_OF_INSTANCE: type = EditorPropertyMember::MEMBER_PROPERTY_OF_INSTANCE; break;
case PROPERTY_HINT_PROPERTY_OF_SCRIPT: type = EditorPropertyMember::MEMBER_PROPERTY_OF_SCRIPT; break;
- default: {}
+ default: {
+ }
}
editor->setup(type, p_hint_text);
add_property_editor(p_path, editor);
@@ -3284,7 +3286,8 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
editor->setup(Variant::POOL_COLOR_ARRAY);
add_property_editor(p_path, editor);
} break;
- default: {}
+ default: {
+ }
}
return false; //can be overridden, although it will most likely be last anyway
diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp
index 0f6c6349ed..e3dc517a39 100644
--- a/editor/editor_properties_array_dict.cpp
+++ b/editor/editor_properties_array_dict.cpp
@@ -251,7 +251,8 @@ void EditorPropertyArray::update_property() {
case Variant::POOL_COLOR_ARRAY: {
arrtype = "PoolColorArray";
} break;
- default: {}
+ default: {
+ }
}
if (array.get_type() == Variant::NIL) {
@@ -862,7 +863,8 @@ void EditorPropertyDictionary::update_property() {
editor->setup(Variant::POOL_COLOR_ARRAY);
prop = editor;
} break;
- default: {}
+ default: {
+ }
}
if (i == amount) {
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp
index b9ed63c1b6..f54c51940f 100644
--- a/editor/editor_settings.cpp
+++ b/editor/editor_settings.cpp
@@ -832,6 +832,13 @@ void EditorSettings::create() {
} else {
dir->change_dir("..");
}
+
+ if (dir->change_dir("feature_profiles") != OK) {
+ dir->make_dir("feature_profiles");
+ } else {
+ dir->change_dir("..");
+ }
+
_create_script_templates(dir->get_current_dir().plus_file("script_templates"));
if (dir->change_dir("projects") != OK) {
@@ -1157,6 +1164,11 @@ String EditorSettings::get_cache_dir() const {
return cache_dir;
}
+String EditorSettings::get_feature_profiles_dir() const {
+
+ return get_settings_dir().plus_file("feature_profiles");
+}
+
// Metadata
void EditorSettings::set_project_metadata(const String &p_section, const String &p_key, Variant p_data) {
diff --git a/editor/editor_settings.h b/editor/editor_settings.h
index 1b44c15c54..43a8cbf739 100644
--- a/editor/editor_settings.h
+++ b/editor/editor_settings.h
@@ -169,6 +169,7 @@ public:
String get_text_editor_themes_dir() const;
String get_script_templates_dir() const;
String get_cache_dir() const;
+ String get_feature_profiles_dir() const;
void set_project_metadata(const String &p_section, const String &p_key, Variant p_data);
Variant get_project_metadata(const String &p_section, const String &p_key, Variant p_default) const;
diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp
index 335e3fcd29..9641e10114 100644
--- a/editor/editor_themes.cpp
+++ b/editor/editor_themes.cpp
@@ -204,7 +204,7 @@ void editor_register_and_generate_icons(Ref<Theme> p_theme, bool p_dark_theme =
}
// generate thumb files with the given thumb size
- bool force_filter = !(p_thumb_size == 64 && p_thumb_size == 32); // we don't need filter with original resolution
+ bool force_filter = p_thumb_size != 64 && p_thumb_size != 32; // we don't need filter with original resolution
if (p_thumb_size >= 64) {
float scale = (float)p_thumb_size / 64.0 * EDSCALE;
for (int i = 0; i < editor_bg_thumbs_count; i++) {
@@ -687,7 +687,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
theme->set_constant("button_margin", "Tree", default_margin_size * EDSCALE);
theme->set_constant("draw_relationship_lines", "Tree", relationship_line_opacity >= 0.01);
theme->set_constant("draw_guides", "Tree", relationship_line_opacity < 0.01);
- theme->set_constant("scroll_border", "Tree", default_margin_size * EDSCALE);
+ theme->set_constant("scroll_border", "Tree", 40 * EDSCALE);
theme->set_constant("scroll_speed", "Tree", 12);
Ref<StyleBoxFlat> style_tree_btn = style_default->duplicate();
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp
index b637148f2d..c32cd1de50 100644
--- a/editor/filesystem_dock.cpp
+++ b/editor/filesystem_dock.cpp
@@ -86,6 +86,13 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory
// Create all items for the files in the subdirectory
if (display_mode == DISPLAY_MODE_TREE_ONLY) {
for (int i = 0; i < p_dir->get_file_count(); i++) {
+
+ String file_type = p_dir->get_file_type(i);
+
+ if (_is_file_type_disabled_by_feature_profile(file_type)) {
+ //if type is disabled, file wont be displayed.
+ continue;
+ }
String file_name = p_dir->get_file(i);
if (searched_string.length() > 0) {
@@ -276,6 +283,7 @@ void FileSystemDock::_notification(int p_what) {
if (initialized)
return;
initialized = true;
+ EditorFeatureProfileManager::get_singleton()->connect("current_feature_profile_changed", this, "_feature_profile_changed");
EditorFileSystem::get_singleton()->connect("filesystem_changed", this, "_fs_changed");
EditorResourcePreview::get_singleton()->connect("preview_invalidated", this, "_preview_invalidated");
@@ -520,6 +528,26 @@ void FileSystemDock::_set_file_display(bool p_active) {
_update_file_list(true);
}
+bool FileSystemDock::_is_file_type_disabled_by_feature_profile(const StringName &p_class) {
+
+ Ref<EditorFeatureProfile> profile = EditorFeatureProfileManager::get_singleton()->get_current_profile();
+ if (profile.is_null()) {
+ return false;
+ }
+
+ StringName class_name = p_class;
+
+ while (class_name != StringName()) {
+
+ if (profile->is_class_disabled(class_name)) {
+ return true;
+ }
+ class_name = ClassDB::get_parent_class(class_name);
+ }
+
+ return false;
+}
+
void FileSystemDock::_search(EditorFileSystemDirectory *p_path, List<FileInfo> *matches, int p_max_items) {
if (matches->size() > p_max_items)
@@ -541,6 +569,11 @@ void FileSystemDock::_search(EditorFileSystemDirectory *p_path, List<FileInfo> *
fi.import_broken = !p_path->get_file_import_is_valid(i);
fi.import_status = 0;
+ if (_is_file_type_disabled_by_feature_profile(fi.type)) {
+ //this type is disabled, will not appear here
+ continue;
+ }
+
matches->push_back(fi);
if (matches->size() > p_max_items)
return;
@@ -988,6 +1021,7 @@ void FileSystemDock::_try_move_item(const FileOrFolder &p_item, const String &p_
for (int j = 0; j < ed->get_edited_scene_count(); j++) {
if (ed->get_scene_path(j) == file_changed_paths[i]) {
ed->get_edited_scene_root(j)->set_filename(new_item_path);
+ editor->save_layout();
break;
}
}
@@ -2092,6 +2126,10 @@ void FileSystemDock::_tree_rmb_select(const Vector2 &p_pos) {
}
}
+void FileSystemDock::_tree_empty_selected() {
+ tree->deselect_all();
+}
+
void FileSystemDock::_file_list_rmb_select(int p_item, const Vector2 &p_pos) {
// Right click is pressed in the file list
Vector<String> paths;
@@ -2259,6 +2297,11 @@ void FileSystemDock::_update_import_dock() {
import_dock_needs_update = false;
}
+void FileSystemDock::_feature_profile_changed() {
+
+ _update_display_mode(true);
+}
+
void FileSystemDock::_bind_methods() {
ClassDB::bind_method(D_METHOD("_file_list_gui_input"), &FileSystemDock::_file_list_gui_input);
@@ -2270,9 +2313,10 @@ void FileSystemDock::_bind_methods() {
ClassDB::bind_method(D_METHOD("_toggle_split_mode"), &FileSystemDock::_toggle_split_mode);
ClassDB::bind_method(D_METHOD("_tree_rmb_option", "option"), &FileSystemDock::_tree_rmb_option);
- ClassDB::bind_method(D_METHOD("_file_list_rmb_option", "option"), &FileSystemDock::_file_list_rmb_option);
-
ClassDB::bind_method(D_METHOD("_tree_rmb_select"), &FileSystemDock::_tree_rmb_select);
+ ClassDB::bind_method(D_METHOD("_tree_empty_selected"), &FileSystemDock::_tree_empty_selected);
+
+ ClassDB::bind_method(D_METHOD("_file_list_rmb_option", "option"), &FileSystemDock::_file_list_rmb_option);
ClassDB::bind_method(D_METHOD("_file_list_rmb_select"), &FileSystemDock::_file_list_rmb_select);
ClassDB::bind_method(D_METHOD("_file_list_rmb_pressed"), &FileSystemDock::_file_list_rmb_pressed);
@@ -2308,6 +2352,8 @@ void FileSystemDock::_bind_methods() {
ClassDB::bind_method(D_METHOD("_file_multi_selected"), &FileSystemDock::_file_multi_selected);
ClassDB::bind_method(D_METHOD("_update_import_dock"), &FileSystemDock::_update_import_dock);
+ ClassDB::bind_method(D_METHOD("_feature_profile_changed"), &FileSystemDock::_feature_profile_changed);
+
ADD_SIGNAL(MethodInfo("instance", PropertyInfo(Variant::POOL_STRING_ARRAY, "files")));
ADD_SIGNAL(MethodInfo("open"));
@@ -2405,6 +2451,7 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) {
tree->connect("item_activated", this, "_tree_activate_file");
tree->connect("multi_selected", this, "_tree_multi_selected");
tree->connect("item_rmb_selected", this, "_tree_rmb_select");
+ tree->connect("nothing_selected", this, "_tree_empty_selected");
tree->connect("gui_input", this, "_tree_gui_input");
file_list_vb = memnew(VBoxContainer);
diff --git a/editor/filesystem_dock.h b/editor/filesystem_dock.h
index cd052f9700..8b27938c8a 100644
--- a/editor/filesystem_dock.h
+++ b/editor/filesystem_dock.h
@@ -237,6 +237,7 @@ private:
void _tree_rmb_select(const Vector2 &p_pos);
void _file_list_rmb_select(int p_item, const Vector2 &p_pos);
void _file_list_rmb_pressed(const Vector2 &p_pos);
+ void _tree_empty_selected();
struct FileInfo {
String name;
@@ -268,6 +269,10 @@ private:
Vector<String> _tree_get_selected(bool remove_self_inclusion = true);
+ bool _is_file_type_disabled_by_feature_profile(const StringName &p_class);
+
+ void _feature_profile_changed();
+
protected:
void _notification(int p_what);
static void _bind_methods();
diff --git a/editor/icons/icon_auto_key.svg b/editor/icons/icon_auto_key.svg
new file mode 100644
index 0000000000..cbafe1ac38
--- /dev/null
+++ b/editor/icons/icon_auto_key.svg
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="16"
+ height="16"
+ version="1.1"
+ viewBox="0 0 16 16"
+ id="svg6"
+ sodipodi:docname="icon_auto_key.svg"
+ inkscape:version="0.92.4 (5da689c313, 2019-01-14)">
+ <metadata
+ id="metadata12">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title></dc:title>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <defs
+ id="defs10" />
+ <sodipodi:namedview
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1"
+ objecttolerance="10"
+ gridtolerance="10"
+ guidetolerance="10"
+ inkscape:pageopacity="0"
+ inkscape:pageshadow="2"
+ inkscape:window-width="1854"
+ inkscape:window-height="1016"
+ id="namedview8"
+ showgrid="false"
+ inkscape:zoom="10.429825"
+ inkscape:cx="10.199345"
+ inkscape:cy="-4.0344119"
+ inkscape:window-x="66"
+ inkscape:window-y="27"
+ inkscape:window-maximized="1"
+ inkscape:current-layer="svg6" />
+ <path
+ style="fill:#e0e0e0;fill-opacity:1;stroke-width:0.0333107"
+ d="M 3.5469681,13.426786 C 2.7965829,13.263778 2.2774312,12.503915 2.4037297,11.753472 c 0.1081234,-0.642451 0.6006808,-1.135008 1.2431317,-1.243131 0.9667125,-0.162696 1.8555225,0.726112 1.6928259,1.692826 -0.103766,0.616558 -0.5592173,1.098057 -1.1588427,1.225117 -0.2719576,0.05763 -0.3626872,0.05741 -0.6338765,-0.0014 z m 8.0861339,-0.08275 c -0.746862,-0.13829 -1.23937,-0.720718 -1.23937,-1.465649 0,-0.527377 0.244831,-0.978806 0.679757,-1.253362 0.471386,-0.297574 1.114188,-0.297574 1.585574,0 0.682727,0.430986 0.892336,1.362194 0.460575,2.046149 -0.307786,0.487563 -0.940521,0.773963 -1.486536,0.672862 z M 0.60726032,9.8305658 V 7.7161233 L 1.1770842,7.7070075 1.7469079,7.6978939 3.1889882,5.1995916 4.6310686,2.7012893 h 3.1726318 3.1726316 l 1.442755,2.4983023 1.442755,2.4983023 0.651097,0.00903 0.651096,0.00903 v 2.1145264 2.1145257 h -0.566282 -0.566281 v -0.161225 c 0,-0.234927 -0.113135,-0.639704 -0.255664,-0.914727 -0.16895,-0.326004 -0.574198,-0.731251 -0.900202,-0.9002019 -0.656732,-0.3403483 -1.428549,-0.3403483 -2.085281,0 -0.326004,0.1689519 -0.731252,0.5741989 -0.9002019,0.9002029 -0.1425297,0.275023 -0.2556639,0.6798 -0.2556639,0.914727 v 0.161225 H 7.8570969 6.0797346 L 6.0617736,11.686851 C 6.006289,10.889347 5.447548,10.170679 4.6603773,9.884336 4.4466221,9.8065798 4.3737631,9.797427 3.9716406,9.7978134 3.5871254,9.7981885 3.4905638,9.809405 3.3054265,9.8752358 2.5067319,10.159236 1.9362359,10.884501 1.8813215,11.68568 l -0.017772,0.259329 H 1.2354063 0.60726287 Z M 12.399247,7.7466889 c 0,-0.037287 -0.02623,-0.1073444 -0.0583,-0.1556843 -0.03206,-0.04834 -0.561225,-0.958444 -1.17592,-2.0224529 L 10.047407,3.6339894 7.6977565,3.6254406 C 5.4917229,3.6174174 5.3450379,3.6204563 5.2979001,3.6754094 5.1898818,3.8013046 2.9723198,7.6840061 2.9723198,7.7472381 c 0,0.067139 0.00758,0.067247 4.7134636,0.067247 h 4.7134636 z"
+ id="path6243"
+ inkscape:connector-curvature="0" />
+</svg>
diff --git a/editor/icons/icon_sprite_sheet.svg b/editor/icons/icon_sprite_sheet.svg
new file mode 100644
index 0000000000..eeb804f8b9
--- /dev/null
+++ b/editor/icons/icon_sprite_sheet.svg
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="16"
+ height="16"
+ version="1.1"
+ viewBox="0 0 16 16"
+ id="svg6"
+ sodipodi:docname="icon_sprite_sheet.svg"
+ inkscape:version="0.92.3 (2405546, 2018-03-11)">
+ <metadata
+ id="metadata12">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title></dc:title>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <defs
+ id="defs10" />
+ <sodipodi:namedview
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1"
+ objecttolerance="10"
+ gridtolerance="10"
+ guidetolerance="10"
+ inkscape:pageopacity="0"
+ inkscape:pageshadow="2"
+ inkscape:window-width="773"
+ inkscape:window-height="480"
+ id="namedview8"
+ showgrid="false"
+ inkscape:zoom="14.75"
+ inkscape:cx="8"
+ inkscape:cy="8"
+ inkscape:window-x="551"
+ inkscape:window-y="278"
+ inkscape:window-maximized="0"
+ inkscape:current-layer="g4" />
+ <g
+ transform="translate(0 -1036.4)"
+ id="g4">
+ <path
+ transform="translate(0 1036.4)"
+ d="m3 1c-1.1046 0-2 0.89543-2 2v10c0 1.1046 0.89543 2 2 2h10c1.1046 0 2-0.89543 2-2v-10c0-1.1046-0.89543-2-2-2h-10zm0 2h2v2h-2v-2zm4 0h2v2h-2v-2zm4 0h2v2h-2v-2zm-8 4h2v2h-2v-2zm4 0h2v2h-2v-2zm4 0h2v2h-2v-2zm-8 4h2v2h-2v-2zm4 0h2v2h-2v-2zm4 0h2v2h-2v-2z"
+ fill="#a5efac"
+ id="path2"
+ style="fill:#e0e0e0;fill-opacity:1" />
+ </g>
+</svg>
diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp
index e6e29df133..daa423e1d9 100644
--- a/editor/import/editor_scene_importer_gltf.cpp
+++ b/editor/import/editor_scene_importer_gltf.cpp
@@ -581,7 +581,9 @@ int EditorSceneImporterGLTF::_get_component_type_size(int component_type) {
case COMPONENT_TYPE_UNSIGNED_SHORT: return 2; break;
case COMPONENT_TYPE_INT: return 4; break;
case COMPONENT_TYPE_FLOAT: return 4; break;
- default: { ERR_FAIL_V(0); }
+ default: {
+ ERR_FAIL_V(0);
+ }
}
return 0;
}
@@ -631,7 +633,8 @@ Vector<double> EditorSceneImporterGLTF::_decode_accessor(GLTFState &state, int p
element_size = 16; //override for this case
}
} break;
- default: {}
+ default: {
+ }
}
Vector<double> dst_buffer;
diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp
index fb2e3c0401..ab515785da 100644
--- a/editor/import/resource_importer_scene.cpp
+++ b/editor/import/resource_importer_scene.cpp
@@ -279,7 +279,24 @@ static String _fixstr(const String &p_what, const String &p_str) {
return what;
}
-Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<ArrayMesh>, Ref<Shape> > &collision_map, LightBakeMode p_light_bake_mode) {
+static void _gen_shape_list(const Ref<Mesh> &mesh, List<Ref<Shape> > &r_shape_list, bool p_convex) {
+
+ if (!p_convex) {
+
+ Ref<Shape> shape = mesh->create_trimesh_shape();
+ r_shape_list.push_back(shape);
+ } else {
+
+ Vector<Ref<Shape> > cd = mesh->convex_decompose();
+ if (cd.size()) {
+ for (int i = 0; i < cd.size(); i++) {
+ r_shape_list.push_back(cd[i]);
+ }
+ }
+ }
+}
+
+Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh>, List<Ref<Shape> > > &collision_map, LightBakeMode p_light_bake_mode) {
// children first
for (int i = 0; i < p_node->get_child_count(); i++) {
@@ -365,37 +382,52 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Array
return p_node;
MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
if (mi) {
- Node *col = NULL;
-
- if (_teststr(name, "colonly")) {
- col = mi->create_trimesh_collision_node();
- if (col == NULL) {
- ERR_PRINTS("Error generating collision for mesh: " + name);
- } else {
-
- col->set_name(_fixstr(name, "colonly"));
+ Ref<Mesh> mesh = mi->get_mesh();
+
+ if (mesh.is_valid()) {
+ List<Ref<Shape> > shapes;
+ String fixed_name;
+ if (collision_map.has(mesh)) {
+ shapes = collision_map[mesh];
+ } else if (_teststr(name, "colonly")) {
+ _gen_shape_list(mesh, shapes, false);
+ collision_map[mesh] = shapes;
+ } else if (_teststr(name, "convcolonly")) {
+ _gen_shape_list(mesh, shapes, true);
+ collision_map[mesh] = shapes;
}
- } else {
- col = mi->create_convex_collision_node();
- if (col == NULL) {
- ERR_PRINTS("Error generating collision for mesh: " + name);
- } else {
- col->set_name(_fixstr(name, "convcolonly"));
+ if (_teststr(name, "colonly")) {
+ fixed_name = _fixstr(name, "colonly");
+ } else if (_teststr(name, "convcolonly")) {
+ fixed_name = _fixstr(name, "convcolonly");
}
- }
- if (col) {
- Object::cast_to<Spatial>(col)->set_transform(mi->get_transform());
- p_node->replace_by(col);
- memdelete(p_node);
- p_node = col;
+ ERR_FAIL_COND_V(fixed_name == String(), NULL);
+
+ if (shapes.size()) {
+
+ StaticBody *col = memnew(StaticBody);
+ col->set_transform(mi->get_transform());
+ col->set_name(fixed_name);
+ p_node->replace_by(col);
+ memdelete(p_node);
+ p_node = col;
+
+ int idx = 0;
+ for (List<Ref<Shape> >::Element *E = shapes.front(); E; E = E->next()) {
+
+ CollisionShape *cshape = memnew(CollisionShape);
+ cshape->set_shape(E->get());
+ col->add_child(cshape);
- StaticBody *sb = Object::cast_to<StaticBody>(col);
- CollisionShape *colshape = Object::cast_to<CollisionShape>(sb->get_child(0));
- colshape->set_name("shape");
- colshape->set_owner(p_node->get_owner());
+ cshape->set_name("shape" + itos(idx));
+ cshape->set_owner(col->get_owner());
+ idx++;
+ }
+ }
}
+
} else if (p_node->has_meta("empty_draw_type")) {
String empty_draw_type = String(p_node->get_meta("empty_draw_type"));
StaticBody *sb = memnew(StaticBody);
@@ -434,77 +466,91 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Array
if (isroot)
return p_node;
- // get mesh instance and bounding box
MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
- AABB aabb = mi->get_aabb();
-
- // create a new rigid body collision node
- RigidBody *rigid_body = memnew(RigidBody);
- Node *col = rigid_body;
- ERR_FAIL_COND_V(!col, NULL);
-
- // remove node name postfix
- col->set_name(_fixstr(name, "rigid"));
- // get mesh instance xform matrix to the rigid body collision node
- Object::cast_to<Spatial>(col)->set_transform(mi->get_transform());
- // save original node by duplicating it into a new instance and correcting the name
- Node *mesh = p_node->duplicate();
- mesh->set_name(_fixstr(name, "rigid"));
- // reset the xform matrix of the duplicated node so it can inherit parent node xform
- Object::cast_to<Spatial>(mesh)->set_transform(Transform(Basis()));
- // reparent the new mesh node to the rigid body collision node
- p_node->add_child(mesh);
- mesh->set_owner(p_node->get_owner());
- // replace the original node with the rigid body collision node
- p_node->replace_by(col);
- memdelete(p_node);
- p_node = col;
-
- // create an alias for the rigid body collision node
- RigidBody *rb = Object::cast_to<RigidBody>(col);
- // create a new Box collision shape and set the right extents
- Ref<BoxShape> shape = memnew(BoxShape);
- shape->set_extents(aabb.get_size() * 0.5);
- CollisionShape *colshape = memnew(CollisionShape);
- colshape->set_name("shape");
- colshape->set_shape(shape);
- // reparent the new collision shape to the rigid body collision node
- rb->add_child(colshape);
- colshape->set_owner(p_node->get_owner());
+ Ref<Mesh> mesh = mi->get_mesh();
+
+ if (mesh.is_valid()) {
+ List<Ref<Shape> > shapes;
+ if (collision_map.has(mesh)) {
+ shapes = collision_map[mesh];
+ } else {
+ _gen_shape_list(mesh, shapes, true);
+ }
+
+ RigidBody *rigid_body = memnew(RigidBody);
+ rigid_body->set_name(_fixstr(name, "rigid"));
+ p_node->replace_by(rigid_body);
+ rigid_body->set_transform(mi->get_transform());
+ p_node = rigid_body;
+ mi->set_name("mesh");
+ mi->set_transform(Transform());
+ rigid_body->add_child(mi);
+ mi->set_owner(rigid_body->get_owner());
+
+ int idx = 0;
+ for (List<Ref<Shape> >::Element *E = shapes.front(); E; E = E->next()) {
+
+ CollisionShape *cshape = memnew(CollisionShape);
+ cshape->set_shape(E->get());
+ rigid_body->add_child(cshape);
+
+ cshape->set_name("shape" + itos(idx));
+ cshape->set_owner(p_node->get_owner());
+ idx++;
+ }
+ }
} else if ((_teststr(name, "col") || (_teststr(name, "convcol"))) && Object::cast_to<MeshInstance>(p_node)) {
MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
- Node *col;
- if (_teststr(name, "col")) {
- String new_name = _fixstr(name, "col");
- if (mi->get_parent() && !mi->get_parent()->has_node(new_name)) {
- mi->set_name(new_name);
+ Ref<Mesh> mesh = mi->get_mesh();
+
+ if (mesh.is_valid()) {
+ List<Ref<Shape> > shapes;
+ String fixed_name;
+ if (collision_map.has(mesh)) {
+ shapes = collision_map[mesh];
+ } else if (_teststr(name, "col")) {
+ _gen_shape_list(mesh, shapes, false);
+ collision_map[mesh] = shapes;
+ } else if (_teststr(name, "convcol")) {
+ _gen_shape_list(mesh, shapes, true);
+ collision_map[mesh] = shapes;
}
- col = mi->create_trimesh_collision_node();
- ERR_FAIL_COND_V(!col, NULL);
- col->set_name("col");
- } else {
- String new_name = _fixstr(name, "convcol");
- if (mi->get_parent() && !mi->get_parent()->has_node(new_name)) {
- mi->set_name(new_name);
+ if (_teststr(name, "col")) {
+ fixed_name = _fixstr(name, "col");
+ } else if (_teststr(name, "convcol")) {
+ fixed_name = _fixstr(name, "convcol");
}
- col = mi->create_convex_collision_node();
- ERR_FAIL_COND_V(!col, NULL);
- col->set_name("convcol");
- }
+ if (fixed_name != String()) {
+ if (mi->get_parent() && !mi->get_parent()->has_node(fixed_name)) {
+ mi->set_name(fixed_name);
+ }
+ }
+
+ if (shapes.size()) {
+ StaticBody *col = memnew(StaticBody);
+ col->set_name("static_collision");
+ mi->add_child(col);
+ col->set_owner(mi->get_owner());
- p_node->add_child(col);
+ int idx = 0;
+ for (List<Ref<Shape> >::Element *E = shapes.front(); E; E = E->next()) {
- StaticBody *sb = Object::cast_to<StaticBody>(col);
- CollisionShape *colshape = Object::cast_to<CollisionShape>(sb->get_child(0));
- colshape->set_name("shape");
- col->add_child(colshape);
- colshape->set_owner(p_node->get_owner());
- sb->set_owner(p_node->get_owner());
+ CollisionShape *cshape = memnew(CollisionShape);
+ cshape->set_shape(E->get());
+ col->add_child(cshape);
+
+ cshape->set_name("shape" + itos(idx));
+ cshape->set_owner(p_node->get_owner());
+
+ idx++;
+ }
+ }
+ }
} else if (_teststr(name, "navmesh") && Object::cast_to<MeshInstance>(p_node)) {
@@ -574,48 +620,35 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Array
Ref<ArrayMesh> mesh = mi->get_mesh();
if (!mesh.is_null()) {
- if (_teststr(mesh->get_name(), "col") || _teststr(mesh->get_name(), "convcol")) {
- Ref<Shape> shape;
- if (_teststr(mesh->get_name(), "col")) {
- mesh->set_name(_fixstr(mesh->get_name(), "col"));
-
- if (collision_map.has(mesh)) {
- shape = collision_map[mesh];
-
- } else {
-
- shape = mesh->create_trimesh_shape();
- if (!shape.is_null())
- collision_map[mesh] = shape;
- }
- } else if (_teststr(mesh->get_name(), "convcol")) {
- mesh->set_name(_fixstr(mesh->get_name(), "convcol"));
+ List<Ref<Shape> > shapes;
+ if (collision_map.has(mesh)) {
+ shapes = collision_map[mesh];
+ } else if (_teststr(mesh->get_name(), "col")) {
+ _gen_shape_list(mesh, shapes, false);
+ collision_map[mesh] = shapes;
+ mesh->set_name(_fixstr(mesh->get_name(), "col"));
+ } else if (_teststr(mesh->get_name(), "convcol")) {
+ _gen_shape_list(mesh, shapes, true);
+ collision_map[mesh] = shapes;
+ mesh->set_name(_fixstr(mesh->get_name(), "convcol"));
+ }
- if (collision_map.has(mesh)) {
- shape = collision_map[mesh];
+ if (shapes.size()) {
+ StaticBody *col = memnew(StaticBody);
+ col->set_name("static_collision");
+ p_node->add_child(col);
+ col->set_owner(p_node->get_owner());
- } else {
+ int idx = 0;
+ for (List<Ref<Shape> >::Element *E = shapes.front(); E; E = E->next()) {
- shape = mesh->create_convex_shape();
- if (!shape.is_null())
- collision_map[mesh] = shape;
- }
- }
-
- if (!shape.is_null()) {
- StaticBody *col = memnew(StaticBody);
CollisionShape *cshape = memnew(CollisionShape);
- cshape->set_shape(shape);
+ cshape->set_shape(E->get());
col->add_child(cshape);
- col->set_transform(mi->get_transform());
- col->set_name(mi->get_name());
- p_node->replace_by(col);
- memdelete(p_node);
- p_node = col;
-
- cshape->set_name("shape");
+ cshape->set_name("shape" + itos(idx));
cshape->set_owner(p_node->get_owner());
+ idx++;
}
}
}
@@ -1269,7 +1302,7 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p
float anim_optimizer_maxang = p_options["animation/optimizer/max_angle"];
int light_bake_mode = p_options["meshes/light_baking"];
- Map<Ref<ArrayMesh>, Ref<Shape> > collision_map;
+ Map<Ref<Mesh>, List<Ref<Shape> > > collision_map;
scene = _fix_node(scene, scene, collision_map, LightBakeMode(light_bake_mode));
diff --git a/editor/import/resource_importer_scene.h b/editor/import/resource_importer_scene.h
index 99f8b1a8e0..b10c4da2e5 100644
--- a/editor/import/resource_importer_scene.h
+++ b/editor/import/resource_importer_scene.h
@@ -146,7 +146,7 @@ public:
void _make_external_resources(Node *p_node, const String &p_base_path, bool p_make_animations, bool p_keep_animations, bool p_make_materials, bool p_keep_materials, bool p_make_meshes, Map<Ref<Animation>, Ref<Animation> > &p_animations, Map<Ref<Material>, Ref<Material> > &p_materials, Map<Ref<ArrayMesh>, Ref<ArrayMesh> > &p_meshes);
- Node *_fix_node(Node *p_node, Node *p_root, Map<Ref<ArrayMesh>, Ref<Shape> > &collision_map, LightBakeMode p_light_bake_mode);
+ Node *_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh>, List<Ref<Shape> > > &collision_map, LightBakeMode p_light_bake_mode);
void _create_clips(Node *scene, const Array &p_clips, bool p_bake_all);
void _filter_anim_tracks(Ref<Animation> anim, Set<String> &keep);
diff --git a/editor/output_strings.cpp b/editor/output_strings.cpp
index 24b44f078f..baabaff9a8 100644
--- a/editor/output_strings.cpp
+++ b/editor/output_strings.cpp
@@ -105,7 +105,8 @@ void OutputStrings::_notification(int p_what) {
case LINE_LINK: {
} break;
- default: {}
+ default: {
+ }
}
line_ofs.y += font->get_ascent();
diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp
index bbaf41e3cc..41f35c3bed 100644
--- a/editor/plugins/animation_player_editor_plugin.cpp
+++ b/editor/plugins/animation_player_editor_plugin.cpp
@@ -670,6 +670,7 @@ Dictionary AnimationPlayerEditor::get_state() const {
if (EditorNode::get_singleton()->get_edited_scene() && is_visible_in_tree() && player) {
d["player"] = EditorNode::get_singleton()->get_edited_scene()->get_path_to(player);
d["animation"] = player->get_assigned_animation();
+ d["track_editor_state"] = track_editor->get_state();
}
return d;
@@ -696,6 +697,10 @@ void AnimationPlayerEditor::set_state(const Dictionary &p_state) {
_animation_edit();
}
}
+
+ if (p_state.has("track_editor_state")) {
+ track_editor->set_state(p_state["track_editor_state"]);
+ }
}
}
diff --git a/editor/plugins/animation_tree_player_editor_plugin.cpp b/editor/plugins/animation_tree_player_editor_plugin.cpp
index e2a44069d9..e21ae4834d 100644
--- a/editor/plugins/animation_tree_player_editor_plugin.cpp
+++ b/editor/plugins/animation_tree_player_editor_plugin.cpp
@@ -200,7 +200,8 @@ void AnimationTreePlayerEditor::_edit_dialog_changed() {
if (anim_tree->transition_node_get_current(edited_node) != edit_option->get_selected())
anim_tree->transition_node_set_current(edited_node, edit_option->get_selected());
} break;
- default: {}
+ default: {
+ }
}
}
@@ -457,7 +458,8 @@ void AnimationTreePlayerEditor::_popup_edit_dialog() {
edit_dialog->set_size(Size2(150, 100));
} break;
- default: {}
+ default: {
+ }
}
}
@@ -555,7 +557,8 @@ void AnimationTreePlayerEditor::_draw_node(const StringName &p_node) {
text += "->";
break;
- default: {}
+ default: {
+ }
}
font->draw(ci, ofs + ascofs + Point2(3, 0), text, font_color);
@@ -740,7 +743,8 @@ void AnimationTreePlayerEditor::_gui_input(Ref<InputEvent> p_event) {
//open editor
//_node_edit_property(click_node);
} break;
- default: {}
+ default: {
+ }
}
}
if (mb->get_button_index() == 2) {
@@ -817,7 +821,8 @@ void AnimationTreePlayerEditor::_gui_input(Ref<InputEvent> p_event) {
anim_tree->node_set_position(click_node, new_pos);
} break;
- default: {}
+ default: {
+ }
}
click_type = CLICK_NONE;
diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp
index 6d2cdfc583..386bc1738e 100644
--- a/editor/plugins/asset_library_editor_plugin.cpp
+++ b/editor/plugins/asset_library_editor_plugin.cpp
@@ -454,7 +454,8 @@ void EditorAssetLibraryItemDownload::_notification(int p_what) {
progress->set_max(1);
progress->set_value(0);
} break;
- default: {}
+ default: {
+ }
}
prev_status = cstatus;
}
@@ -612,7 +613,8 @@ void EditorAssetLibrary::_notification(int p_what) {
case HTTPClient::STATUS_BODY: {
load_status->set_value(0.4);
} break;
- default: {}
+ default: {
+ }
}
}
diff --git a/editor/plugins/baked_lightmap_editor_plugin.cpp b/editor/plugins/baked_lightmap_editor_plugin.cpp
index d90ff95c1f..d75f06de12 100644
--- a/editor/plugins/baked_lightmap_editor_plugin.cpp
+++ b/editor/plugins/baked_lightmap_editor_plugin.cpp
@@ -50,7 +50,8 @@ void BakedLightmapEditorPlugin::_bake() {
case BakedLightmap::BAKE_ERROR_CANT_CREATE_IMAGE:
EditorNode::get_singleton()->show_warning(TTR("Failed creating lightmap images, make sure path is writable."));
break;
- default: {}
+ default: {
+ }
}
}
}
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index c3cac582ad..b2923a1ff2 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -1340,6 +1340,10 @@ bool CanvasItemEditor::_gui_input_rotate(const Ref<InputEvent> &p_event) {
// Confirms the node rotation
if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && !b->is_pressed()) {
_commit_canvas_item_state(drag_selection, TTR("Rotate CanvasItem"));
+ if (key_auto_insert_button->is_pressed()) {
+ _insert_animation_keys(false, true, false, true);
+ }
+
drag_type = DRAG_NONE;
return true;
}
@@ -1641,6 +1645,9 @@ bool CanvasItemEditor::_gui_input_resize(const Ref<InputEvent> &p_event) {
// Confirm resize
if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && !b->is_pressed()) {
_commit_canvas_item_state(drag_selection, TTR("Resize CanvasItem"));
+ if (key_auto_insert_button->is_pressed()) {
+ _insert_animation_keys(false, false, true, true);
+ }
drag_type = DRAG_NONE;
viewport->update();
return true;
@@ -1747,6 +1754,10 @@ bool CanvasItemEditor::_gui_input_scale(const Ref<InputEvent> &p_event) {
// Confirm resize
if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && !b->is_pressed()) {
_commit_canvas_item_state(drag_selection, TTR("Scale CanvasItem"));
+ if (key_auto_insert_button->is_pressed()) {
+ _insert_animation_keys(false, false, true, true);
+ }
+
drag_type = DRAG_NONE;
viewport->update();
return true;
@@ -1852,6 +1863,9 @@ bool CanvasItemEditor::_gui_input_move(const Ref<InputEvent> &p_event) {
_commit_canvas_item_state(drag_selection, TTR("Move CanvasItem"), true);
}
+ if (key_auto_insert_button->is_pressed()) {
+ _insert_animation_keys(true, false, false, true);
+ }
drag_type = DRAG_NONE;
viewport->update();
return true;
@@ -3384,6 +3398,7 @@ void CanvasItemEditor::_notification(int p_what) {
key_rot_button->set_icon(get_icon("KeyRotation", "EditorIcons"));
key_scale_button->set_icon(get_icon("KeyScale", "EditorIcons"));
key_insert_button->set_icon(get_icon("Key", "EditorIcons"));
+ key_auto_insert_button->set_icon(get_icon("AutoKey", "EditorIcons"));
zoom_minus->set_icon(get_icon("ZoomLess", "EditorIcons"));
zoom_reset->set_icon(get_icon("ZoomReset", "EditorIcons"));
@@ -3716,6 +3731,77 @@ void CanvasItemEditor::_button_tool_select(int p_index) {
tool = (Tool)p_index;
}
+void CanvasItemEditor::_insert_animation_keys(bool p_location, bool p_rotation, bool p_scale, bool p_on_existing) {
+
+ Map<Node *, Object *> &selection = editor_selection->get_selection();
+
+ for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
+
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key());
+ if (!canvas_item || !canvas_item->is_visible_in_tree())
+ continue;
+
+ if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
+ continue;
+
+ if (Object::cast_to<Node2D>(canvas_item)) {
+ Node2D *n2d = Object::cast_to<Node2D>(canvas_item);
+
+ if (key_pos && p_location)
+ AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(n2d, "position", n2d->get_position(), p_on_existing);
+ if (key_rot && p_rotation)
+ AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(n2d, "rotation_degrees", Math::rad2deg(n2d->get_rotation()), p_on_existing);
+ if (key_scale && p_scale)
+ AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(n2d, "scale", n2d->get_scale(), p_on_existing);
+
+ if (n2d->has_meta("_edit_bone_") && n2d->get_parent_item()) {
+ //look for an IK chain
+ List<Node2D *> ik_chain;
+
+ Node2D *n = Object::cast_to<Node2D>(n2d->get_parent_item());
+ bool has_chain = false;
+
+ while (n) {
+
+ ik_chain.push_back(n);
+ if (n->has_meta("_edit_ik_")) {
+ has_chain = true;
+ break;
+ }
+
+ if (!n->get_parent_item())
+ break;
+ n = Object::cast_to<Node2D>(n->get_parent_item());
+ }
+
+ if (has_chain && ik_chain.size()) {
+
+ for (List<Node2D *>::Element *F = ik_chain.front(); F; F = F->next()) {
+
+ if (key_pos)
+ AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(F->get(), "position", F->get()->get_position(), p_on_existing);
+ if (key_rot)
+ AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(F->get(), "rotation_degrees", Math::rad2deg(F->get()->get_rotation()), p_on_existing);
+ if (key_scale)
+ AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(F->get(), "scale", F->get()->get_scale(), p_on_existing);
+ }
+ }
+ }
+
+ } else if (Object::cast_to<Control>(canvas_item)) {
+
+ Control *ctrl = Object::cast_to<Control>(canvas_item);
+
+ if (key_pos)
+ AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(ctrl, "rect_position", ctrl->get_position(), p_on_existing);
+ if (key_rot)
+ AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(ctrl, "rect_rotation", ctrl->get_rotation_degrees(), p_on_existing);
+ if (key_scale)
+ AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(ctrl, "rect_size", ctrl->get_size(), p_on_existing);
+ }
+ }
+}
+
void CanvasItemEditor::_popup_callback(int p_op) {
last_option = MenuOption(p_op);
@@ -3983,73 +4069,7 @@ void CanvasItemEditor::_popup_callback(int p_op) {
bool existing = p_op == ANIM_INSERT_KEY_EXISTING;
- Map<Node *, Object *> &selection = editor_selection->get_selection();
-
- for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
-
- CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key());
- if (!canvas_item || !canvas_item->is_visible_in_tree())
- continue;
-
- if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
- continue;
-
- if (Object::cast_to<Node2D>(canvas_item)) {
- Node2D *n2d = Object::cast_to<Node2D>(canvas_item);
-
- if (key_pos)
- AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(n2d, "position", n2d->get_position(), existing);
- if (key_rot)
- AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(n2d, "rotation_degrees", Math::rad2deg(n2d->get_rotation()), existing);
- if (key_scale)
- AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(n2d, "scale", n2d->get_scale(), existing);
-
- if (n2d->has_meta("_edit_bone_") && n2d->get_parent_item()) {
- //look for an IK chain
- List<Node2D *> ik_chain;
-
- Node2D *n = Object::cast_to<Node2D>(n2d->get_parent_item());
- bool has_chain = false;
-
- while (n) {
-
- ik_chain.push_back(n);
- if (n->has_meta("_edit_ik_")) {
- has_chain = true;
- break;
- }
-
- if (!n->get_parent_item())
- break;
- n = Object::cast_to<Node2D>(n->get_parent_item());
- }
-
- if (has_chain && ik_chain.size()) {
-
- for (List<Node2D *>::Element *F = ik_chain.front(); F; F = F->next()) {
-
- if (key_pos)
- AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(F->get(), "position", F->get()->get_position(), existing);
- if (key_rot)
- AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(F->get(), "rotation_degrees", Math::rad2deg(F->get()->get_rotation()), existing);
- if (key_scale)
- AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(F->get(), "scale", F->get()->get_scale(), existing);
- }
- }
- }
-
- } else if (Object::cast_to<Control>(canvas_item)) {
-
- Control *ctrl = Object::cast_to<Control>(canvas_item);
-
- if (key_pos)
- AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(ctrl, "rect_position", ctrl->get_position(), existing);
- if (key_rot)
- AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(ctrl, "rect_rotation", ctrl->get_rotation_degrees(), existing);
- if (key_scale)
- AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(ctrl, "rect_size", ctrl->get_size(), existing);
- }
- }
+ _insert_animation_keys(true, true, true, existing);
} break;
case ANIM_INSERT_POS: {
@@ -4866,6 +4886,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
key_loc_button->set_pressed(true);
key_loc_button->set_focus_mode(FOCUS_NONE);
key_loc_button->connect("pressed", this, "_popup_callback", varray(ANIM_INSERT_POS));
+ key_loc_button->set_tooltip(TTR("Translation mask for inserting keys."));
animation_hb->add_child(key_loc_button);
key_rot_button = memnew(Button);
key_rot_button->set_toggle_mode(true);
@@ -4873,21 +4894,30 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
key_rot_button->set_pressed(true);
key_rot_button->set_focus_mode(FOCUS_NONE);
key_rot_button->connect("pressed", this, "_popup_callback", varray(ANIM_INSERT_ROT));
+ key_rot_button->set_tooltip(TTR("Rotation mask for inserting keys."));
animation_hb->add_child(key_rot_button);
key_scale_button = memnew(Button);
key_scale_button->set_toggle_mode(true);
key_scale_button->set_flat(true);
key_scale_button->set_focus_mode(FOCUS_NONE);
key_scale_button->connect("pressed", this, "_popup_callback", varray(ANIM_INSERT_SCALE));
+ key_scale_button->set_tooltip(TTR("Scale mask for inserting keys."));
animation_hb->add_child(key_scale_button);
key_insert_button = memnew(Button);
key_insert_button->set_flat(true);
key_insert_button->set_focus_mode(FOCUS_NONE);
key_insert_button->connect("pressed", this, "_popup_callback", varray(ANIM_INSERT_KEY));
- key_insert_button->set_tooltip(TTR("Insert keys."));
+ key_insert_button->set_tooltip(TTR("Insert keys (based on mask)."));
key_insert_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/anim_insert_key", TTR("Insert Key"), KEY_INSERT));
-
animation_hb->add_child(key_insert_button);
+ key_auto_insert_button = memnew(Button);
+ key_auto_insert_button->set_flat(true);
+ key_auto_insert_button->set_toggle_mode(true);
+ key_auto_insert_button->set_focus_mode(FOCUS_NONE);
+ //key_auto_insert_button->connect("pressed", this, "_popup_callback", varray(ANIM_INSERT_KEY));
+ key_auto_insert_button->set_tooltip(TTR("Auto insert keys when objects are translated, rotated on scaled (based on mask).\nKeys are only added to existing tracks, no new tracks will be created.\nKeys must be inserted manually for the first time."));
+ key_auto_insert_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/anim_auto_insert_key", TTR("Auto Insert Key")));
+ animation_hb->add_child(key_auto_insert_button);
animation_menu = memnew(MenuButton);
animation_menu->set_text(TTR("Animation"));
diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h
index 9173c55ae0..14ea81f302 100644
--- a/editor/plugins/canvas_item_editor_plugin.h
+++ b/editor/plugins/canvas_item_editor_plugin.h
@@ -351,6 +351,7 @@ private:
Button *key_rot_button;
Button *key_scale_button;
Button *key_insert_button;
+ Button *key_auto_insert_button;
PopupMenu *selection_menu;
@@ -422,6 +423,8 @@ private:
Object *_get_editor_data(Object *p_what);
+ void _insert_animation_keys(bool p_location, bool p_rotation, bool p_scale, bool p_on_existing);
+
void _keying_changed();
void _unhandled_key_input(const Ref<InputEvent> &p_ev);
diff --git a/editor/plugins/item_list_editor_plugin.h b/editor/plugins/item_list_editor_plugin.h
index 679235e316..701632e576 100644
--- a/editor/plugins/item_list_editor_plugin.h
+++ b/editor/plugins/item_list_editor_plugin.h
@@ -157,7 +157,7 @@ public:
virtual void set_item_enabled(int p_idx, int p_enabled) { pp->set_item_disabled(p_idx, !p_enabled); }
virtual bool is_item_enabled(int p_idx) const { return !pp->is_item_disabled(p_idx); }
- virtual void set_item_id(int p_idx, int p_id) { pp->set_item_id(p_idx, p_idx); }
+ virtual void set_item_id(int p_idx, int p_id) { pp->set_item_id(p_idx, p_id); }
virtual int get_item_id(int p_idx) const { return pp->get_item_id(p_idx); }
virtual void set_item_separator(int p_idx, bool p_separator) { pp->set_item_as_separator(p_idx, p_separator); }
diff --git a/editor/plugins/mesh_instance_editor_plugin.cpp b/editor/plugins/mesh_instance_editor_plugin.cpp
index 3e10cdbbfa..cf111dc4ce 100644
--- a/editor/plugins/mesh_instance_editor_plugin.cpp
+++ b/editor/plugins/mesh_instance_editor_plugin.cpp
@@ -95,10 +95,7 @@ void MeshInstanceEditor::_menu_option(int p_option) {
return;
}
- if (trimesh_shape)
- ur->create_action(TTR("Create Static Trimesh Body"));
- else
- ur->create_action(TTR("Create Static Convex Body"));
+ ur->create_action(TTR("Create Static Trimesh Body"));
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
@@ -132,8 +129,7 @@ void MeshInstanceEditor::_menu_option(int p_option) {
} break;
- case MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE:
- case MENU_OPTION_CREATE_CONVEX_COLLISION_SHAPE: {
+ case MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE: {
if (node == get_tree()->get_edited_scene_root()) {
err_dialog->set_text(TTR("This doesn't work on scene root!"));
@@ -141,9 +137,7 @@ void MeshInstanceEditor::_menu_option(int p_option) {
return;
}
- bool trimesh_shape = (p_option == MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE);
-
- Ref<Shape> shape = trimesh_shape ? mesh->create_trimesh_shape() : mesh->create_convex_shape();
+ Ref<Shape> shape = mesh->create_trimesh_shape();
if (shape.is_null())
return;
@@ -154,10 +148,7 @@ void MeshInstanceEditor::_menu_option(int p_option) {
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
- if (trimesh_shape)
- ur->create_action(TTR("Create Trimesh Shape"));
- else
- ur->create_action(TTR("Create Convex Shape"));
+ ur->create_action(TTR("Create Trimesh Static Shape"));
ur->add_do_method(node->get_parent(), "add_child", cshape);
ur->add_do_method(node->get_parent(), "move_child", cshape, node->get_index() + 1);
@@ -165,6 +156,40 @@ void MeshInstanceEditor::_menu_option(int p_option) {
ur->add_do_reference(cshape);
ur->add_undo_method(node->get_parent(), "remove_child", cshape);
ur->commit_action();
+ } break;
+ case MENU_OPTION_CREATE_CONVEX_COLLISION_SHAPE: {
+
+ if (node == get_tree()->get_edited_scene_root()) {
+ err_dialog->set_text(TTR("This doesn't work on scene root!"));
+ err_dialog->popup_centered_minsize();
+ return;
+ }
+
+ Vector<Ref<Shape> > shapes = mesh->convex_decompose();
+
+ if (!shapes.size()) {
+ err_dialog->set_text(TTR("Failed creating shapes!"));
+ err_dialog->popup_centered_minsize();
+ return;
+ }
+ UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
+
+ ur->create_action(TTR("Create Convex Shape(s)"));
+
+ for (int i = 0; i < shapes.size(); i++) {
+
+ CollisionShape *cshape = memnew(CollisionShape);
+ cshape->set_shape(shapes[i]);
+
+ Node *owner = node->get_owner();
+
+ ur->add_do_method(node->get_parent(), "add_child", cshape);
+ ur->add_do_method(node->get_parent(), "move_child", cshape, node->get_index() + 1);
+ ur->add_do_method(cshape, "set_owner", owner);
+ ur->add_do_reference(cshape);
+ ur->add_undo_method(node->get_parent(), "remove_child", cshape);
+ }
+ ur->commit_action();
} break;
@@ -393,10 +418,9 @@ MeshInstanceEditor::MeshInstanceEditor() {
options->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("MeshInstance", "EditorIcons"));
options->get_popup()->add_item(TTR("Create Trimesh Static Body"), MENU_OPTION_CREATE_STATIC_TRIMESH_BODY);
- options->get_popup()->add_item(TTR("Create Convex Static Body"), MENU_OPTION_CREATE_STATIC_CONVEX_BODY);
options->get_popup()->add_separator();
options->get_popup()->add_item(TTR("Create Trimesh Collision Sibling"), MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE);
- options->get_popup()->add_item(TTR("Create Convex Collision Sibling"), MENU_OPTION_CREATE_CONVEX_COLLISION_SHAPE);
+ options->get_popup()->add_item(TTR("Create Convex Collision Sibling(s)"), MENU_OPTION_CREATE_CONVEX_COLLISION_SHAPE);
options->get_popup()->add_separator();
options->get_popup()->add_item(TTR("Create Navigation Mesh"), MENU_OPTION_CREATE_NAVMESH);
options->get_popup()->add_separator();
diff --git a/editor/plugins/mesh_library_editor_plugin.cpp b/editor/plugins/mesh_library_editor_plugin.cpp
index 89eb253afe..18586b2fe5 100644
--- a/editor/plugins/mesh_library_editor_plugin.cpp
+++ b/editor/plugins/mesh_library_editor_plugin.cpp
@@ -61,7 +61,8 @@ void MeshLibraryEditor::_menu_confirm() {
_import_scene_cbk(existing);
} break;
- default: {};
+ default: {
+ };
}
}
diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp
index 0dbbaf4177..af43f679fd 100644
--- a/editor/plugins/polygon_2d_editor_plugin.cpp
+++ b/editor/plugins/polygon_2d_editor_plugin.cpp
@@ -905,7 +905,8 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
bone_paint_pos = Vector2(mm->get_position().x, mm->get_position().y);
} break;
- default: {}
+ default: {
+ }
}
if (bone_painting) {
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index 42aba78e96..d7d4cec07d 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -1735,7 +1735,7 @@ void ScriptEditor::_update_script_names() {
String name = eh->get_class();
Ref<Texture> icon = get_icon("Help", "EditorIcons");
- String tooltip = name + TTR(" Class Reference");
+ String tooltip = vformat(TTR("%s Class Reference"), name);
_ScriptEditorItemData sd;
sd.icon = icon;
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index 9fc42e3862..c586985957 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -81,6 +81,8 @@ void ScriptTextEditor::set_edited_resource(const RES &p_res) {
emit_signal("name_changed");
code_editor->update_line_and_column();
+
+ _validate_script();
}
void ScriptTextEditor::_update_member_keywords() {
@@ -286,7 +288,7 @@ void ScriptTextEditor::_warning_clicked(Variant p_line) {
code_editor->get_text_edit()->cursor_set_line(p_line.operator int64_t());
} else if (p_line.get_type() == Variant::DICTIONARY) {
Dictionary meta = p_line.operator Dictionary();
- code_editor->get_text_edit()->insert_at("#warning-ignore:" + meta["code"].operator String(), meta["line"].operator int64_t() - 1);
+ code_editor->get_text_edit()->insert_at("# warning-ignore:" + meta["code"].operator String(), meta["line"].operator int64_t() - 1);
_validate_script();
}
}
diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp
index f48887d342..ba297539d3 100644
--- a/editor/plugins/spatial_editor_plugin.cpp
+++ b/editor/plugins/spatial_editor_plugin.cpp
@@ -1637,7 +1637,8 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
surface->update();
} break;
- default: {}
+ default: {
+ }
}
}
@@ -1704,7 +1705,8 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
} break;
- default: {}
+ default: {
+ }
}
}
@@ -1760,7 +1762,8 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
} break;
- default: {}
+ default: {
+ }
}
}
diff --git a/editor/plugins/sprite_editor_plugin.cpp b/editor/plugins/sprite_editor_plugin.cpp
index 3854d27567..fbc72b1396 100644
--- a/editor/plugins/sprite_editor_plugin.cpp
+++ b/editor/plugins/sprite_editor_plugin.cpp
@@ -31,7 +31,10 @@
#include "sprite_editor_plugin.h"
#include "canvas_item_editor_plugin.h"
+#include "scene/2d/collision_polygon_2d.h"
+#include "scene/2d/light_occluder_2d.h"
#include "scene/2d/mesh_instance_2d.h"
+#include "scene/2d/polygon_2d.h"
#include "scene/gui/box_container.h"
#include "thirdparty/misc/clipper.hpp"
@@ -116,8 +119,42 @@ void SpriteEditor::_menu_option(int p_option) {
return;
}
+ selected_menu_item = (Menu)p_option;
+
switch (p_option) {
- case MENU_OPTION_CREATE_MESH_2D: {
+ case MENU_OPTION_CONVERT_TO_MESH_2D: {
+
+ debug_uv_dialog->get_ok()->set_text(TTR("Create Mesh2D"));
+ debug_uv_dialog->set_title("Mesh2D Preview");
+
+ _update_mesh_data();
+ debug_uv_dialog->popup_centered();
+ debug_uv->update();
+
+ } break;
+ case MENU_OPTION_CONVERT_TO_POLYGON_2D: {
+
+ debug_uv_dialog->get_ok()->set_text(TTR("Create Polygon2D"));
+ debug_uv_dialog->set_title("Polygon2D Preview");
+
+ _update_mesh_data();
+ debug_uv_dialog->popup_centered();
+ debug_uv->update();
+ } break;
+ case MENU_OPTION_CREATE_COLLISION_POLY_2D: {
+
+ debug_uv_dialog->get_ok()->set_text(TTR("Create CollisionPolygon2D"));
+ debug_uv_dialog->set_title("CollisionPolygon2D Preview");
+
+ _update_mesh_data();
+ debug_uv_dialog->popup_centered();
+ debug_uv->update();
+
+ } break;
+ case MENU_OPTION_CREATE_LIGHT_OCCLUDER_2D: {
+
+ debug_uv_dialog->get_ok()->set_text(TTR("Create LightOccluder2D"));
+ debug_uv_dialog->set_title("LightOccluder2D Preview");
_update_mesh_data();
debug_uv_dialog->popup_centered();
@@ -169,47 +206,107 @@ void SpriteEditor::_update_mesh_data() {
computed_indices.clear();
Size2 img_size = Vector2(image->get_width(), image->get_height());
- for (int j = 0; j < lines.size(); j++) {
- lines.write[j] = expand(lines[j], rect, epsilon);
+ for (int i = 0; i < lines.size(); i++) {
+ lines.write[i] = expand(lines[i], rect, epsilon);
+ }
+
+ if (selected_menu_item == MENU_OPTION_CONVERT_TO_MESH_2D) {
+
+ for (int j = 0; j < lines.size(); j++) {
+ int index_ofs = computed_vertices.size();
+
+ for (int i = 0; i < lines[j].size(); i++) {
+ Vector2 vtx = lines[j][i];
+ computed_uv.push_back(vtx / img_size);
- int index_ofs = computed_vertices.size();
+ vtx -= rect.position; //offset by rect position
- for (int i = 0; i < lines[j].size(); i++) {
- Vector2 vtx = lines[j][i];
- computed_uv.push_back(vtx / img_size);
+ //flip if flipped
+ if (node->is_flipped_h())
+ vtx.x = rect.size.x - vtx.x - 1.0;
+ if (node->is_flipped_v())
+ vtx.y = rect.size.y - vtx.y - 1.0;
- vtx -= rect.position; //offset by rect position
+ if (node->is_centered())
+ vtx -= rect.size / 2.0;
- //flip if flipped
- if (node->is_flipped_h())
- vtx.x = rect.size.x - vtx.x - 1.0;
- if (node->is_flipped_v())
- vtx.y = rect.size.y - vtx.y - 1.0;
+ computed_vertices.push_back(vtx);
+ }
+
+ Vector<int> poly = Geometry::triangulate_polygon(lines[j]);
- if (node->is_centered())
- vtx -= rect.size / 2.0;
+ for (int i = 0; i < poly.size(); i += 3) {
+ for (int k = 0; k < 3; k++) {
+ int idx = i + k;
+ int idxn = i + (k + 1) % 3;
+ uv_lines.push_back(lines[j][poly[idx]]);
+ uv_lines.push_back(lines[j][poly[idxn]]);
- computed_vertices.push_back(vtx);
+ computed_indices.push_back(poly[idx] + index_ofs);
+ }
+ }
}
+ }
- Vector<int> poly = Geometry::triangulate_polygon(lines[j]);
+ outline_lines.clear();
+ computed_outline_lines.clear();
- for (int i = 0; i < poly.size(); i += 3) {
- for (int k = 0; k < 3; k++) {
- int idx = i + k;
- int idxn = i + (k + 1) % 3;
- uv_lines.push_back(lines[j][poly[idx]]);
- uv_lines.push_back(lines[j][poly[idxn]]);
+ if (selected_menu_item == MENU_OPTION_CONVERT_TO_POLYGON_2D || selected_menu_item == MENU_OPTION_CREATE_COLLISION_POLY_2D || selected_menu_item == MENU_OPTION_CREATE_LIGHT_OCCLUDER_2D) {
+ outline_lines.resize(lines.size());
+ computed_outline_lines.resize(lines.size());
+ for (int pi = 0; pi < lines.size(); pi++) {
+
+ Vector<Vector2> ol;
+ Vector<Vector2> col;
+
+ ol.resize(lines[pi].size());
+ col.resize(lines[pi].size());
+
+ for (int i = 0; i < lines[pi].size(); i++) {
+ Vector2 vtx = lines[pi][i];
+
+ ol.write[i] = vtx;
+
+ vtx -= rect.position; //offset by rect position
+
+ //flip if flipped
+ if (node->is_flipped_h())
+ vtx.x = rect.size.x - vtx.x - 1.0;
+ if (node->is_flipped_v())
+ vtx.y = rect.size.y - vtx.y - 1.0;
+
+ if (node->is_centered())
+ vtx -= rect.size / 2.0;
- computed_indices.push_back(poly[idx] + index_ofs);
+ col.write[i] = vtx;
}
+
+ outline_lines.write[pi] = ol;
+ computed_outline_lines.write[pi] = col;
}
}
debug_uv->update();
}
-void SpriteEditor::_create_mesh_node() {
+void SpriteEditor::_create_node() {
+ switch (selected_menu_item) {
+ case MENU_OPTION_CONVERT_TO_MESH_2D: {
+ _convert_to_mesh_2d_node();
+ } break;
+ case MENU_OPTION_CONVERT_TO_POLYGON_2D: {
+ _convert_to_polygon_2d_node();
+ } break;
+ case MENU_OPTION_CREATE_COLLISION_POLY_2D: {
+ _create_collision_polygon_2d_node();
+ } break;
+ case MENU_OPTION_CREATE_LIGHT_OCCLUDER_2D: {
+ _create_light_occluder_2d_node();
+ } break;
+ }
+}
+
+void SpriteEditor::_convert_to_mesh_2d_node() {
if (computed_vertices.size() < 3) {
err_dialog->set_text(TTR("Invalid geometry, can't replace by mesh."));
@@ -233,6 +330,117 @@ void SpriteEditor::_create_mesh_node() {
EditorNode::get_singleton()->get_scene_tree_dock()->replace_node(node, mesh_instance);
}
+void SpriteEditor::_convert_to_polygon_2d_node() {
+ Polygon2D *polygon_2d_instance = memnew(Polygon2D);
+
+ int total_point_count = 0;
+ for (int i = 0; i < computed_outline_lines.size(); i++)
+ total_point_count += computed_outline_lines[i].size();
+
+ PoolVector2Array polygon;
+ polygon.resize(total_point_count);
+ PoolVector2Array::Write polygon_write = polygon.write();
+
+ PoolVector2Array uvs;
+ uvs.resize(total_point_count);
+ PoolVector2Array::Write uvs_write = uvs.write();
+
+ int current_point_index = 0;
+
+ Array polys;
+ polys.resize(computed_outline_lines.size());
+
+ for (int i = 0; i < computed_outline_lines.size(); i++) {
+
+ Vector<Vector2> outline = computed_outline_lines[i];
+ Vector<Vector2> uv_outline = outline_lines[i];
+
+ if (outline.size() < 3) {
+ err_dialog->set_text(TTR("Invalid geometry, can't create polygon."));
+ err_dialog->popup_centered_minsize();
+ return;
+ }
+
+ PoolIntArray pia;
+ pia.resize(outline.size());
+ PoolIntArray::Write pia_write = pia.write();
+
+ for (int pi = 0; pi < outline.size(); pi++) {
+ polygon_write[current_point_index] = outline[pi];
+ uvs_write[current_point_index] = uv_outline[pi];
+ pia_write[pi] = current_point_index;
+ current_point_index++;
+ }
+
+ polys[i] = pia;
+ }
+
+ polygon_2d_instance->set_uv(uvs);
+ polygon_2d_instance->set_polygon(polygon);
+ polygon_2d_instance->set_polygons(polys);
+
+ EditorNode::get_singleton()->get_scene_tree_dock()->replace_node(node, polygon_2d_instance);
+}
+
+void SpriteEditor::_create_collision_polygon_2d_node() {
+ for (int i = 0; i < computed_outline_lines.size(); i++) {
+
+ Vector<Vector2> outline = computed_outline_lines[i];
+
+ if (outline.size() < 3) {
+ err_dialog->set_text(TTR("Invalid geometry, can't create collision polygon."));
+ err_dialog->popup_centered_minsize();
+ continue;
+ }
+
+ CollisionPolygon2D *collision_polygon_2d_instance = memnew(CollisionPolygon2D);
+ collision_polygon_2d_instance->set_polygon(outline);
+
+ _add_as_sibling_or_child(node, collision_polygon_2d_instance);
+ }
+}
+
+void SpriteEditor::_create_light_occluder_2d_node() {
+ for (int i = 0; i < computed_outline_lines.size(); i++) {
+
+ Vector<Vector2> outline = computed_outline_lines[i];
+
+ if (outline.size() < 3) {
+ err_dialog->set_text(TTR("Invalid geometry, can't create light occluder."));
+ err_dialog->popup_centered_minsize();
+ continue;
+ }
+
+ Ref<OccluderPolygon2D> polygon;
+ polygon.instance();
+
+ PoolVector2Array a;
+ a.resize(outline.size());
+ PoolVector2Array::Write aw = a.write();
+ for (int io = 0; io < outline.size(); io++) {
+ aw[io] = outline[io];
+ }
+ polygon->set_polygon(a);
+
+ LightOccluder2D *light_occluder_2d_instance = memnew(LightOccluder2D);
+ light_occluder_2d_instance->set_occluder_polygon(polygon);
+
+ _add_as_sibling_or_child(node, light_occluder_2d_instance);
+ }
+}
+
+void SpriteEditor::_add_as_sibling_or_child(Node2D *p_own_node, Node2D *p_new_node) {
+ // Can't make sibling if own node is scene root
+ if (p_own_node != this->get_tree()->get_edited_scene_root()) {
+ p_own_node->get_parent()->add_child(p_new_node, true);
+ p_new_node->set_transform(p_own_node->get_transform());
+ } else {
+ p_own_node->add_child(p_new_node, true);
+ }
+
+ p_new_node->set_owner(this->get_tree()->get_edited_scene_root());
+}
+
#if 0
void SpriteEditor::_create_uv_lines() {
@@ -298,16 +506,26 @@ void SpriteEditor::_create_uv_lines() {
#endif
void SpriteEditor::_debug_uv_draw() {
- if (uv_lines.size() == 0)
- return;
-
Ref<Texture> tex = node->get_texture();
ERR_FAIL_COND(!tex.is_valid());
debug_uv->set_clip_contents(true);
debug_uv->draw_texture(tex, Point2());
debug_uv->set_custom_minimum_size(tex->get_size());
//debug_uv->draw_set_transform(Vector2(), 0, debug_uv->get_size());
- debug_uv->draw_multiline(uv_lines, Color(1.0, 0.8, 0.7));
+
+ Color color = Color(1.0, 0.8, 0.7);
+
+ if (selected_menu_item == MENU_OPTION_CONVERT_TO_MESH_2D && uv_lines.size() > 0) {
+ debug_uv->draw_multiline(uv_lines, color);
+
+ } else if ((selected_menu_item == MENU_OPTION_CONVERT_TO_POLYGON_2D || selected_menu_item == MENU_OPTION_CREATE_COLLISION_POLY_2D || selected_menu_item == MENU_OPTION_CREATE_LIGHT_OCCLUDER_2D) && outline_lines.size() > 0) {
+ for (int i = 0; i < outline_lines.size(); i++) {
+ Vector<Vector2> outline = outline_lines[i];
+
+ debug_uv->draw_polyline(outline, color);
+ debug_uv->draw_line(outline[0], outline[outline.size() - 1], color);
+ }
+ }
}
void SpriteEditor::_bind_methods() {
@@ -315,7 +533,7 @@ void SpriteEditor::_bind_methods() {
ClassDB::bind_method("_menu_option", &SpriteEditor::_menu_option);
ClassDB::bind_method("_debug_uv_draw", &SpriteEditor::_debug_uv_draw);
ClassDB::bind_method("_update_mesh_data", &SpriteEditor::_update_mesh_data);
- ClassDB::bind_method("_create_mesh_node", &SpriteEditor::_create_mesh_node);
+ ClassDB::bind_method("_create_node", &SpriteEditor::_create_node);
}
SpriteEditor::SpriteEditor() {
@@ -327,7 +545,10 @@ SpriteEditor::SpriteEditor() {
options->set_text(TTR("Sprite"));
options->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("Sprite", "EditorIcons"));
- options->get_popup()->add_item(TTR("Convert to 2D Mesh"), MENU_OPTION_CREATE_MESH_2D);
+ options->get_popup()->add_item(TTR("Convert to Mesh2D"), MENU_OPTION_CONVERT_TO_MESH_2D);
+ options->get_popup()->add_item(TTR("Convert to Polygon2D"), MENU_OPTION_CONVERT_TO_POLYGON_2D);
+ options->get_popup()->add_item(TTR("Create CollisionPolygon2D Sibling"), MENU_OPTION_CREATE_COLLISION_POLY_2D);
+ options->get_popup()->add_item(TTR("Create LightOccluder2D Sibling"), MENU_OPTION_CREATE_LIGHT_OCCLUDER_2D);
options->get_popup()->connect("id_pressed", this, "_menu_option");
@@ -335,7 +556,7 @@ SpriteEditor::SpriteEditor() {
add_child(err_dialog);
debug_uv_dialog = memnew(ConfirmationDialog);
- debug_uv_dialog->get_ok()->set_text(TTR("Create 2D Mesh"));
+ debug_uv_dialog->get_ok()->set_text(TTR("Create Mesh2D"));
debug_uv_dialog->set_title("Mesh 2D Preview");
VBoxContainer *vb = memnew(VBoxContainer);
debug_uv_dialog->add_child(vb);
@@ -347,7 +568,7 @@ SpriteEditor::SpriteEditor() {
debug_uv = memnew(Control);
debug_uv->connect("draw", this, "_debug_uv_draw");
scroll->add_child(debug_uv);
- debug_uv_dialog->connect("confirmed", this, "_create_mesh_node");
+ debug_uv_dialog->connect("confirmed", this, "_create_node");
HBoxContainer *hb = memnew(HBoxContainer);
hb->add_child(memnew(Label(TTR("Simplification: "))));
diff --git a/editor/plugins/sprite_editor_plugin.h b/editor/plugins/sprite_editor_plugin.h
index 7250e3df59..460f5a5707 100644
--- a/editor/plugins/sprite_editor_plugin.h
+++ b/editor/plugins/sprite_editor_plugin.h
@@ -41,9 +41,14 @@ class SpriteEditor : public Control {
GDCLASS(SpriteEditor, Control);
enum Menu {
- MENU_OPTION_CREATE_MESH_2D,
+ MENU_OPTION_CONVERT_TO_MESH_2D,
+ MENU_OPTION_CONVERT_TO_POLYGON_2D,
+ MENU_OPTION_CREATE_COLLISION_POLY_2D,
+ MENU_OPTION_CREATE_LIGHT_OCCLUDER_2D
};
+ Menu selected_menu_item;
+
Sprite *node;
MenuButton *options;
@@ -55,7 +60,8 @@ class SpriteEditor : public Control {
ConfirmationDialog *debug_uv_dialog;
Control *debug_uv;
Vector<Vector2> uv_lines;
-
+ Vector<Vector<Vector2> > outline_lines;
+ Vector<Vector<Vector2> > computed_outline_lines;
Vector<Vector2> computed_vertices;
Vector<Vector2> computed_uv;
Vector<int> computed_indices;
@@ -71,7 +77,14 @@ class SpriteEditor : public Control {
void _debug_uv_draw();
void _update_mesh_data();
- void _create_mesh_node();
+
+ void _create_node();
+ void _convert_to_mesh_2d_node();
+ void _convert_to_polygon_2d_node();
+ void _create_collision_polygon_2d_node();
+ void _create_light_occluder_2d_node();
+
+ void _add_as_sibling_or_child(Node2D *p_own_node, Node2D *p_new_node);
protected:
void _node_removed(Node *p_node);
diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp
index 5ba2fde763..33b8347f94 100644
--- a/editor/plugins/sprite_frames_editor_plugin.cpp
+++ b/editor/plugins/sprite_frames_editor_plugin.cpp
@@ -38,11 +38,167 @@
void SpriteFramesEditor::_gui_input(Ref<InputEvent> p_event) {
}
+void SpriteFramesEditor::_open_sprite_sheet() {
+
+ file_split_sheet->clear_filters();
+ List<String> extensions;
+ ResourceLoader::get_recognized_extensions_for_type("Texture", &extensions);
+ for (int i = 0; i < extensions.size(); i++) {
+ file_split_sheet->add_filter("*." + extensions[i]);
+ }
+
+ file_split_sheet->popup_centered_ratio();
+}
+
+void SpriteFramesEditor::_sheet_preview_draw() {
+ Size2i size = split_sheet_preview->get_size();
+ int h = split_sheet_h->get_value();
+ int v = split_sheet_v->get_value();
+ const float a = 0.3;
+ for (int i = 1; i < h; i++) {
+ for (int j = 1; j < v; j++) {
+
+ int x = i * size.width / h;
+ int y = i * size.height / v;
+
+ split_sheet_preview->draw_line(Point2(x, 0), Point2(x, size.height), Color(1, 1, 1, a));
+ split_sheet_preview->draw_line(Point2(x + 1, 0), Point2(x + 1, size.height), Color(0, 0, 0, a));
+
+ split_sheet_preview->draw_line(Point2(0, y), Point2(size.width, y), Color(1, 1, 1, a));
+ split_sheet_preview->draw_line(Point2(0, y + 1), Point2(size.width, y + 1), Color(0, 0, 0, a));
+ }
+ }
+
+ Color accent = get_color("accent_color", "Editor");
+
+ for (Set<int>::Element *E = frames_selected.front(); E; E = E->next()) {
+ int idx = E->get();
+ int x = (idx % h) * size.width / h;
+ int y = (idx / v) * size.height / v;
+ int width = size.width / h;
+ int height = size.height / v;
+
+ split_sheet_preview->draw_rect(Rect2(x + 5, y + 5, width - 10, height - 10), Color(0, 0, 0, 0.35), true);
+ split_sheet_preview->draw_rect(Rect2(x + 0, y + 0, width - 0, height - 0), Color(0, 0, 0, 1), false);
+ split_sheet_preview->draw_rect(Rect2(x + 1, y + 1, width - 2, height - 2), Color(0, 0, 0, 1), false);
+ split_sheet_preview->draw_rect(Rect2(x + 2, y + 2, width - 4, height - 4), accent, false);
+ split_sheet_preview->draw_rect(Rect2(x + 3, y + 3, width - 6, height - 6), accent, false);
+ split_sheet_preview->draw_rect(Rect2(x + 4, y + 4, width - 8, height - 8), Color(0, 0, 0, 1), false);
+ split_sheet_preview->draw_rect(Rect2(x + 5, y + 5, width - 10, height - 10), Color(0, 0, 0, 1), false);
+ }
+
+ if (frames_selected.size() == 0) {
+ split_sheet_dialog->get_ok()->set_disabled(true);
+ split_sheet_dialog->get_ok()->set_text(TTR("No frames selected"));
+ } else {
+ split_sheet_dialog->get_ok()->set_disabled(false);
+ split_sheet_dialog->get_ok()->set_text(vformat(TTR("Add %d frame(s)"), frames_selected.size()));
+ }
+}
+void SpriteFramesEditor::_sheet_preview_input(const Ref<InputEvent> &p_event) {
+
+ Ref<InputEventMouseButton> mb = p_event;
+
+ if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
+ Size2i size = split_sheet_preview->get_size();
+ int h = split_sheet_h->get_value();
+ int v = split_sheet_v->get_value();
+
+ int x = CLAMP(int(mb->get_position().x) * h / size.width, 0, h - 1);
+ int y = CLAMP(int(mb->get_position().y) * v / size.height, 0, v - 1);
+
+ int idx = h * y + x;
+
+ if (mb->get_shift() && last_frame_selected >= 0) {
+ //select multiple
+ int from = idx;
+ int to = last_frame_selected;
+ if (from > to) {
+ SWAP(from, to);
+ }
+
+ for (int i = from; i <= to; i++) {
+ if (mb->get_control()) {
+ frames_selected.erase(i);
+ } else {
+ frames_selected.insert(i);
+ }
+ }
+ } else {
+ if (frames_selected.has(idx)) {
+ frames_selected.erase(idx);
+ } else {
+ frames_selected.insert(idx);
+ }
+ }
+
+ last_frame_selected = idx;
+ split_sheet_preview->update();
+ }
+}
+
+void SpriteFramesEditor::_sheet_add_frames() {
+
+ Size2i size = split_sheet_preview->get_size();
+ int h = split_sheet_h->get_value();
+ int v = split_sheet_v->get_value();
+
+ undo_redo->create_action(TTR("Add Frame"));
+
+ int fc = frames->get_frame_count(edited_anim);
+
+ for (Set<int>::Element *E = frames_selected.front(); E; E = E->next()) {
+ int idx = E->get();
+ int x = (idx % h) * size.width / h;
+ int y = (idx / v) * size.height / v;
+ int width = size.width / h;
+ int height = size.height / v;
+
+ Ref<AtlasTexture> at;
+ at.instance();
+ at->set_atlas(split_sheet_preview->get_texture());
+ at->set_region(Rect2(x, y, width, height));
+
+ undo_redo->add_do_method(frames, "add_frame", edited_anim, at, -1);
+ undo_redo->add_undo_method(frames, "remove_frame", edited_anim, fc);
+ }
+
+ undo_redo->add_do_method(this, "_update_library");
+ undo_redo->add_undo_method(this, "_update_library");
+ undo_redo->commit_action();
+}
+
+void SpriteFramesEditor::_sheet_spin_changed(double) {
+ frames_selected.clear();
+ last_frame_selected = -1;
+ split_sheet_preview->update();
+}
+
+void SpriteFramesEditor::_prepare_sprite_sheet(const String &p_file) {
+
+ Ref<Resource> texture = ResourceLoader::load(p_file);
+ if (!texture.is_valid()) {
+ EditorNode::get_singleton()->show_warning("Unable to load images");
+ ERR_FAIL_COND(!texture.is_valid());
+ }
+ if (texture != split_sheet_preview->get_texture()) {
+ //different texture, reset to 4x4
+ split_sheet_h->set_value(4);
+ split_sheet_v->set_value(4);
+ }
+ frames_selected.clear();
+ last_frame_selected = -1;
+
+ split_sheet_preview->set_texture(texture);
+ split_sheet_dialog->popup_centered_ratio(0.65);
+}
+
void SpriteFramesEditor::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
load->set_icon(get_icon("Load", "EditorIcons"));
+ load_sheet->set_icon(get_icon("SpriteSheet", "EditorIcons"));
copy->set_icon(get_icon("ActionCopy", "EditorIcons"));
paste->set_icon(get_icon("ActionPaste", "EditorIcons"));
empty->set_icon(get_icon("InsertBefore", "EditorIcons"));
@@ -72,6 +228,7 @@ void SpriteFramesEditor::_file_load_request(const PoolVector<String> &p_path, in
if (resource.is_null()) {
dialog->set_text(TTR("ERROR: Couldn't load frame resource!"));
dialog->set_title(TTR("Error!"));
+
//dialog->get_cancel()->set_text("Close");
dialog->get_ok()->set_text(TTR("Close"));
dialog->popup_centered_minsize();
@@ -655,6 +812,12 @@ void SpriteFramesEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &SpriteFramesEditor::get_drag_data_fw);
ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &SpriteFramesEditor::can_drop_data_fw);
ClassDB::bind_method(D_METHOD("drop_data_fw"), &SpriteFramesEditor::drop_data_fw);
+ ClassDB::bind_method(D_METHOD("_prepare_sprite_sheet"), &SpriteFramesEditor::_prepare_sprite_sheet);
+ ClassDB::bind_method(D_METHOD("_open_sprite_sheet"), &SpriteFramesEditor::_open_sprite_sheet);
+ ClassDB::bind_method(D_METHOD("_sheet_preview_draw"), &SpriteFramesEditor::_sheet_preview_draw);
+ ClassDB::bind_method(D_METHOD("_sheet_preview_input"), &SpriteFramesEditor::_sheet_preview_input);
+ ClassDB::bind_method(D_METHOD("_sheet_spin_changed"), &SpriteFramesEditor::_sheet_spin_changed);
+ ClassDB::bind_method(D_METHOD("_sheet_add_frames"), &SpriteFramesEditor::_sheet_add_frames);
}
SpriteFramesEditor::SpriteFramesEditor() {
@@ -712,9 +875,15 @@ SpriteFramesEditor::SpriteFramesEditor() {
sub_vb->add_child(hbc);
load = memnew(ToolButton);
- load->set_tooltip(TTR("Load Resource"));
+ load->set_tooltip(TTR("Add a Texture from File"));
hbc->add_child(load);
+ load_sheet = memnew(ToolButton);
+ load_sheet->set_tooltip(TTR("Add frames from a Sprite Sheet"));
+ hbc->add_child(load_sheet);
+
+ hbc->add_child(memnew(VSeparator));
+
copy = memnew(ToolButton);
copy->set_tooltip(TTR("Copy"));
hbc->add_child(copy);
@@ -723,6 +892,8 @@ SpriteFramesEditor::SpriteFramesEditor() {
paste->set_tooltip(TTR("Paste"));
hbc->add_child(paste);
+ hbc->add_spacer(false);
+
empty = memnew(ToolButton);
empty->set_tooltip(TTR("Insert Empty (Before)"));
hbc->add_child(empty);
@@ -731,7 +902,7 @@ SpriteFramesEditor::SpriteFramesEditor() {
empty2->set_tooltip(TTR("Insert Empty (After)"));
hbc->add_child(empty2);
- hbc->add_spacer(false);
+ hbc->add_child(memnew(VSeparator));
move_up = memnew(ToolButton);
move_up->set_tooltip(TTR("Move (Before)"));
@@ -766,6 +937,7 @@ SpriteFramesEditor::SpriteFramesEditor() {
add_child(dialog);
load->connect("pressed", this, "_load_pressed");
+ load_sheet->connect("pressed", this, "_open_sprite_sheet");
_delete->connect("pressed", this, "_delete_pressed");
copy->connect("pressed", this, "_copy_pressed");
paste->connect("pressed", this, "_paste_pressed");
@@ -780,6 +952,60 @@ SpriteFramesEditor::SpriteFramesEditor() {
updating = false;
edited_anim = "default";
+
+ split_sheet_dialog = memnew(ConfirmationDialog);
+ add_child(split_sheet_dialog);
+ VBoxContainer *split_sheet_vb = memnew(VBoxContainer);
+ split_sheet_dialog->add_child(split_sheet_vb);
+ split_sheet_dialog->set_title(TTR("Select Frames"));
+ split_sheet_dialog->connect("confirmed", this, "_sheet_add_frames");
+
+ ScrollContainer *scroll = memnew(ScrollContainer);
+ split_sheet_preview = memnew(TextureRect);
+ split_sheet_preview->set_expand(false);
+ split_sheet_preview->set_mouse_filter(MOUSE_FILTER_PASS);
+ split_sheet_preview->connect("draw", this, "_sheet_preview_draw");
+ split_sheet_preview->connect("gui_input", this, "_sheet_preview_input");
+
+ scroll->set_enable_h_scroll(true);
+ scroll->set_enable_v_scroll(true);
+ CenterContainer *cc = memnew(CenterContainer);
+ cc->add_child(split_sheet_preview);
+ cc->set_h_size_flags(SIZE_EXPAND_FILL);
+ cc->set_v_size_flags(SIZE_EXPAND_FILL);
+ scroll->add_child(cc);
+
+ split_sheet_vb->add_margin_child(TTR("Base Image:"), scroll, true);
+
+ HBoxContainer *split_sheet_hb = memnew(HBoxContainer);
+ split_sheet_hb->add_spacer();
+ Label *ss_label = memnew(Label(TTR("Horizontal:")));
+ split_sheet_hb->add_child(ss_label);
+ split_sheet_h = memnew(SpinBox);
+ split_sheet_h->set_min(1);
+ split_sheet_h->set_max(128);
+ split_sheet_h->set_step(1);
+ split_sheet_hb->add_child(split_sheet_h);
+ split_sheet_hb->add_spacer();
+ split_sheet_h->connect("value_changed", this, "_sheet_spin_changed");
+
+ ss_label = memnew(Label(TTR("Vertical:")));
+ split_sheet_hb->add_child(ss_label);
+ split_sheet_v = memnew(SpinBox);
+ split_sheet_v->set_min(1);
+ split_sheet_v->set_max(128);
+ split_sheet_v->set_step(1);
+ split_sheet_hb->add_child(split_sheet_v);
+ split_sheet_hb->add_spacer();
+ split_sheet_v->connect("value_changed", this, "_sheet_spin_changed");
+
+ split_sheet_vb->add_margin_child(TTR("Split Settings:"), split_sheet_hb);
+
+ file_split_sheet = memnew(EditorFileDialog);
+ file_split_sheet->set_title(TTR("Create frames from Sprite Sheet"));
+ file_split_sheet->set_mode(EditorFileDialog::MODE_OPEN_FILE);
+ add_child(file_split_sheet);
+ file_split_sheet->connect("file_selected", this, "_prepare_sprite_sheet");
}
void SpriteFramesEditorPlugin::edit(Object *p_object) {
diff --git a/editor/plugins/sprite_frames_editor_plugin.h b/editor/plugins/sprite_frames_editor_plugin.h
index 55dd10074e..383e99f87e 100644
--- a/editor/plugins/sprite_frames_editor_plugin.h
+++ b/editor/plugins/sprite_frames_editor_plugin.h
@@ -37,6 +37,7 @@
#include "scene/gui/dialogs.h"
#include "scene/gui/file_dialog.h"
#include "scene/gui/split_container.h"
+#include "scene/gui/texture_rect.h"
#include "scene/gui/tree.h"
class SpriteFramesEditor : public HSplitContainer {
@@ -44,6 +45,7 @@ class SpriteFramesEditor : public HSplitContainer {
GDCLASS(SpriteFramesEditor, HSplitContainer);
ToolButton *load;
+ ToolButton *load_sheet;
ToolButton *_delete;
ToolButton *copy;
ToolButton *paste;
@@ -71,6 +73,14 @@ class SpriteFramesEditor : public HSplitContainer {
StringName edited_anim;
+ ConfirmationDialog *split_sheet_dialog;
+ TextureRect *split_sheet_preview;
+ SpinBox *split_sheet_h;
+ SpinBox *split_sheet_v;
+ EditorFileDialog *file_split_sheet;
+ Set<int> frames_selected;
+ int last_frame_selected;
+
void _load_pressed();
void _load_scene_pressed();
void _file_load_request(const PoolVector<String> &p_path, int p_at_pos = -1);
@@ -99,6 +109,13 @@ class SpriteFramesEditor : public HSplitContainer {
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
+ void _open_sprite_sheet();
+ void _prepare_sprite_sheet(const String &p_file);
+ void _sheet_preview_draw();
+ void _sheet_spin_changed(double);
+ void _sheet_preview_input(const Ref<InputEvent> &p_event);
+ void _sheet_add_frames();
+
protected:
void _notification(int p_what);
void _gui_input(Ref<InputEvent> p_event);
diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp
index 5bc1067718..8cf00cf67d 100644
--- a/editor/plugins/tile_set_editor_plugin.cpp
+++ b/editor/plugins/tile_set_editor_plugin.cpp
@@ -770,7 +770,8 @@ void TileSetEditor::_on_edit_mode_changed(int p_edit_mode) {
spin_z_index->show();
}
} break;
- default: {}
+ default: {
+ }
}
_update_toggle_shape_button();
workspace->update();
@@ -940,7 +941,8 @@ void TileSetEditor::_on_workspace_draw() {
spin_z_index->set_value(tileset->autotile_get_z_index(get_current_tile(), edited_shape_coord));
draw_highlight_subtile(edited_shape_coord);
} break;
- default: {}
+ default: {
+ }
}
}
@@ -1036,25 +1038,26 @@ void TileSetEditor::_on_workspace_overlay_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) {
- Rect2i region = tileset->tile_get_region(t_id);
- region.position += WORKSPACE_MARGIN;
- region.position *= workspace->get_scale().x;
- Color c;
- if (tileset->tile_get_tile_mode(t_id) == TileSet::SINGLE_TILE)
- c = COLOR_SINGLE;
- else if (tileset->tile_get_tile_mode(t_id) == TileSet::AUTO_TILE)
- c = COLOR_AUTOTILE;
- else if (tileset->tile_get_tile_mode(t_id) == TileSet::ATLAS_TILE)
- c = COLOR_ATLAS;
- String tile_id_name = String::num(t_id, 0) + ": " + tileset->tile_get_name(t_id);
- Ref<Font> font = get_font("font", "Label");
- region.set_size(font->get_string_size(tile_id_name));
- workspace_overlay->draw_rect(region, c);
- region.position.y += region.size.y - 2;
- c = Color(0.1, 0.1, 0.1);
- workspace_overlay->draw_string(font, region.position, tile_id_name, c);
- }
+ if (tileset->tile_get_texture(t_id)->get_rid() != current_texture_rid)
+ continue;
+
+ Rect2 region = tileset->tile_get_region(t_id);
+ region.position += WORKSPACE_MARGIN;
+ region.position *= workspace->get_scale().x;
+ Color c;
+ if (tileset->tile_get_tile_mode(t_id) == TileSet::SINGLE_TILE)
+ c = COLOR_SINGLE;
+ else if (tileset->tile_get_tile_mode(t_id) == TileSet::AUTO_TILE)
+ c = COLOR_AUTOTILE;
+ else if (tileset->tile_get_tile_mode(t_id) == TileSet::ATLAS_TILE)
+ c = COLOR_ATLAS;
+ String tile_id_name = String::num(t_id, 0) + ": " + tileset->tile_get_name(t_id);
+ Ref<Font> font = get_font("font", "Label");
+ region.set_size(font->get_string_size(tile_id_name));
+ workspace_overlay->draw_rect(region, c);
+ region.position.y += region.size.y - 2;
+ c = Color(0.1, 0.1, 0.1);
+ workspace_overlay->draw_string(font, region.position, tile_id_name, c);
}
}
@@ -1570,7 +1573,8 @@ void TileSetEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) {
}
}
} break;
- default: {}
+ default: {
+ }
}
}
}
@@ -1724,7 +1728,8 @@ void TileSetEditor::_on_tool_clicked(int p_tool) {
undo_redo->commit_action();
}
} break;
- default: {}
+ default: {
+ }
}
}
} else if (p_tool == TOOL_SELECT) {
@@ -1894,7 +1899,8 @@ void TileSetEditor::_select_next_tile() {
edited_shape_coord = Vector2();
_select_edited_shape_coord();
} break;
- default: {}
+ default: {
+ }
}
}
}
@@ -1931,7 +1937,8 @@ void TileSetEditor::_select_previous_tile() {
edited_shape_coord = cell_count;
_select_edited_shape_coord();
} break;
- default: {}
+ default: {
+ }
}
}
}
@@ -2668,7 +2675,8 @@ void TileSetEditor::draw_polygon_shapes() {
}
}
} break;
- default: {}
+ default: {
+ }
}
if (creating_shape) {
diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp
index f71ff84bbe..0aba7f3d15 100644
--- a/editor/plugins/visual_shader_editor_plugin.cpp
+++ b/editor/plugins/visual_shader_editor_plugin.cpp
@@ -453,7 +453,8 @@ void VisualShaderEditor::_update_graph() {
Vector3 v = default_value;
button->set_text(String::num(v.x, 3) + "," + String::num(v.y, 3) + "," + String::num(v.z, 3));
} break;
- default: {}
+ default: {
+ }
}
}
@@ -1003,6 +1004,58 @@ void VisualShaderEditor::_duplicate_nodes() {
}
}
+void VisualShaderEditor::_on_nodes_delete() {
+
+ VisualShader::Type type = VisualShader::Type(edit_type->get_selected());
+ List<int> to_erase;
+
+ for (int i = 0; i < graph->get_child_count(); i++) {
+ GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
+ if (gn) {
+ if (gn->is_selected() && gn->is_close_button_visible()) {
+ to_erase.push_back(gn->get_name().operator String().to_int());
+ }
+ }
+ }
+
+ if (to_erase.empty())
+ return;
+
+ undo_redo->create_action(TTR("Delete Nodes"));
+
+ for (List<int>::Element *F = to_erase.front(); F; F = F->next()) {
+ undo_redo->add_do_method(visual_shader.ptr(), "remove_node", type, F->get());
+ undo_redo->add_undo_method(visual_shader.ptr(), "add_node", type, visual_shader->get_node(type, F->get()), visual_shader->get_node_position(type, F->get()), F->get());
+ }
+
+ List<VisualShader::Connection> conns;
+ visual_shader->get_node_connections(type, &conns);
+
+ List<VisualShader::Connection> used_conns;
+ for (List<int>::Element *F = to_erase.front(); F; F = F->next()) {
+ for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) {
+ if (E->get().from_node == F->get() || E->get().to_node == F->get()) {
+
+ bool cancel = false;
+ for (List<VisualShader::Connection>::Element *R = used_conns.front(); R; R = R->next()) {
+ if (R->get().from_node == E->get().from_node && R->get().from_port == E->get().from_port && R->get().to_node == E->get().to_node && R->get().to_port == E->get().to_port) {
+ cancel = true; // to avoid ERR_ALREADY_EXISTS warning
+ break;
+ }
+ }
+ if (!cancel) {
+ undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
+ used_conns.push_back(E->get());
+ }
+ }
+ }
+ }
+
+ undo_redo->add_do_method(this, "_update_graph");
+ undo_redo->add_undo_method(this, "_update_graph");
+ undo_redo->commit_action();
+}
+
void VisualShaderEditor::_mode_selected(int p_id) {
_update_options_menu();
_update_graph();
@@ -1174,6 +1227,7 @@ void VisualShaderEditor::_bind_methods() {
ClassDB::bind_method("_node_selected", &VisualShaderEditor::_node_selected);
ClassDB::bind_method("_scroll_changed", &VisualShaderEditor::_scroll_changed);
ClassDB::bind_method("_delete_request", &VisualShaderEditor::_delete_request);
+ ClassDB::bind_method("_on_nodes_delete", &VisualShaderEditor::_on_nodes_delete);
ClassDB::bind_method("_node_changed", &VisualShaderEditor::_node_changed);
ClassDB::bind_method("_edit_port_default_input", &VisualShaderEditor::_edit_port_default_input);
ClassDB::bind_method("_port_edited", &VisualShaderEditor::_port_edited);
@@ -1223,6 +1277,7 @@ VisualShaderEditor::VisualShaderEditor() {
graph->connect("node_selected", this, "_node_selected");
graph->connect("scroll_offset_changed", this, "_scroll_changed");
graph->connect("duplicate_nodes_request", this, "_duplicate_nodes");
+ graph->connect("delete_nodes_request", this, "_on_nodes_delete");
graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR);
graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_VECTOR);
graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_BOOLEAN);
@@ -1345,9 +1400,10 @@ VisualShaderEditor::VisualShaderEditor() {
add_options.push_back(AddOption("ColorUniform", "Color", "Variables", "VisualShaderNodeColorUniform", TTR("Color uniform."), -1, VisualShaderNode::PORT_TYPE_COLOR));
// BOOLEAN
-
- add_options.push_back(AddOption("BooleanConstant", "Boolean", "Variables", "VisualShaderNodeBooleanConstant", TTR("Boolean constant."), -1, VisualShaderNode::PORT_TYPE_BOOLEAN));
- add_options.push_back(AddOption("BooleanUniform", "Boolean", "Variables", "VisualShaderNodeBooleanUniform", TTR("Boolean uniform."), -1, VisualShaderNode::PORT_TYPE_BOOLEAN));
+ add_options.push_back(AddOption("If", "Conditional", "Functions", "VisualShaderNodeIf", TTR("Returns an associated vector if the provided scalars are equal, greater or less."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
+ add_options.push_back(AddOption("Switch", "Conditional", "Functions", "VisualShaderNodeSwitch", TTR("Returns an associated vector if the provided boolean value is true or false."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
+ add_options.push_back(AddOption("BooleanConstant", "Conditional", "Variables", "VisualShaderNodeBooleanConstant", TTR("Boolean constant."), -1, VisualShaderNode::PORT_TYPE_BOOLEAN));
+ add_options.push_back(AddOption("BooleanUniform", "Conditional", "Variables", "VisualShaderNodeBooleanUniform", TTR("Boolean uniform."), -1, VisualShaderNode::PORT_TYPE_BOOLEAN));
// INPUT
diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h
index 2709d72931..4b0b48ad92 100644
--- a/editor/plugins/visual_shader_editor_plugin.h
+++ b/editor/plugins/visual_shader_editor_plugin.h
@@ -143,6 +143,7 @@ class VisualShaderEditor : public VBoxContainer {
void _node_selected(Object *p_node);
void _delete_request(int);
+ void _on_nodes_delete();
void _removed_from_graph();
diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp
index bb72c621be..2d7ad8bc04 100644
--- a/editor/project_settings_editor.cpp
+++ b/editor/project_settings_editor.cpp
@@ -294,7 +294,8 @@ void ProjectSettingsEditor::_device_input_add() {
ie = jb;
} break;
- default: {}
+ default: {
+ }
}
if (idx < 0 || idx >= events.size()) {
@@ -519,7 +520,8 @@ void ProjectSettingsEditor::_add_item(int p_item, Ref<InputEvent> p_exiting_even
}
} break;
- default: {}
+ default: {
+ }
}
}
diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp
index c45a97800c..4fa1bd74fe 100644
--- a/editor/property_editor.cpp
+++ b/editor/property_editor.cpp
@@ -310,7 +310,8 @@ void CustomPropertyEditor::_menu_option(int p_which) {
}
} break;
- default: {}
+ default: {
+ }
}
}
@@ -1049,7 +1050,8 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
case Variant::POOL_COLOR_ARRAY: {
} break;
- default: {}
+ default: {
+ }
}
updating = false;
@@ -1091,7 +1093,8 @@ void CustomPropertyEditor::_file_selected(String p_file) {
emit_signal("variant_changed");
hide();
} break;
- default: {}
+ default: {
+ }
}
}
@@ -1432,7 +1435,8 @@ void CustomPropertyEditor::_action_pressed(int p_which) {
} break;
- default: {};
+ default: {
+ };
}
}
@@ -1699,7 +1703,8 @@ void CustomPropertyEditor::_modified(String p_string) {
case Variant::POOL_COLOR_ARRAY: {
} break;
- default: {}
+ default: {
+ }
}
updating = false;
@@ -1753,7 +1758,8 @@ void CustomPropertyEditor::_focus_enter() {
}
}
} break;
- default: {}
+ default: {
+ }
}
}
@@ -1774,7 +1780,8 @@ void CustomPropertyEditor::_focus_exit() {
value_editor[i]->select(0, 0);
}
} break;
- default: {}
+ default: {
+ }
}
}
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp
index 7e4861cd09..bd245d5da9 100644
--- a/editor/scene_tree_dock.cpp
+++ b/editor/scene_tree_dock.cpp
@@ -290,12 +290,18 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
switch (p_tool) {
case TOOL_BATCH_RENAME: {
+ if (!profile_allow_editing) {
+ break;
+ }
Tree *tree = scene_tree->get_scene_tree();
if (tree->is_anything_selected()) {
rename_dialog->popup_centered();
}
} break;
case TOOL_RENAME: {
+ if (!profile_allow_editing) {
+ break;
+ }
Tree *tree = scene_tree->get_scene_tree();
if (tree->is_anything_selected()) {
tree->grab_focus();
@@ -304,6 +310,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
} break;
case TOOL_NEW: {
+ if (!profile_allow_editing) {
+ break;
+ }
String preferred = "";
Node *current_edited_scene_root = EditorNode::get_singleton()->get_edited_scene();
@@ -319,6 +328,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
} break;
case TOOL_INSTANCE: {
+ if (!profile_allow_editing) {
+ break;
+ }
Node *scene = edited_scene;
if (!scene) {
@@ -332,10 +344,17 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
} break;
case TOOL_REPLACE: {
+ if (!profile_allow_editing) {
+ break;
+ }
create_dialog->popup_create(false, true);
} break;
case TOOL_ATTACH_SCRIPT: {
+ if (!profile_allow_script_editing) {
+ break;
+ }
+
List<Node *> selection = editor_selection->get_selected_node_list();
if (selection.empty())
break;
@@ -377,6 +396,10 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
} break;
case TOOL_CLEAR_SCRIPT: {
+ if (!profile_allow_script_editing) {
+ break;
+ }
+
Array selection = editor_selection->get_selected_nodes();
if (selection.empty())
@@ -404,6 +427,10 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
case TOOL_MOVE_UP:
case TOOL_MOVE_DOWN: {
+ if (!profile_allow_editing) {
+ break;
+ }
+
if (!scene_tree->get_selected())
break;
@@ -464,6 +491,10 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
} break;
case TOOL_DUPLICATE: {
+ if (!profile_allow_editing) {
+ break;
+ }
+
if (!edited_scene)
break;
@@ -533,6 +564,10 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
} break;
case TOOL_REPARENT: {
+ if (!profile_allow_editing) {
+ break;
+ }
+
if (!scene_tree->get_selected())
break;
@@ -559,6 +594,10 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
} break;
case TOOL_MAKE_ROOT: {
+ if (!profile_allow_editing) {
+ break;
+ }
+
List<Node *> nodes = editor_selection->get_selected_node_list();
ERR_FAIL_COND(nodes.size() != 1);
@@ -616,6 +655,10 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
} break;
case TOOL_MULTI_EDIT: {
+ if (!profile_allow_editing) {
+ break;
+ }
+
Node *root = EditorNode::get_singleton()->get_edited_scene();
if (!root)
break;
@@ -630,6 +673,10 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
case TOOL_ERASE: {
+ if (!profile_allow_editing) {
+ break;
+ }
+
List<Node *> remove_list = editor_selection->get_selected_node_list();
if (remove_list.empty())
@@ -649,10 +696,18 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
} break;
case TOOL_MERGE_FROM_SCENE: {
+ if (!profile_allow_editing) {
+ break;
+ }
+
EditorNode::get_singleton()->merge_from_scene();
} break;
case TOOL_NEW_SCENE_FROM: {
+ if (!profile_allow_editing) {
+ break;
+ }
+
Node *scene = editor_data->get_edited_scene_root();
if (!scene) {
@@ -704,6 +759,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
new_scene_from_dialog->set_title(TTR("Save New Scene As..."));
} break;
case TOOL_COPY_NODE_PATH: {
+
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *>::Element *e = selection.front();
if (e) {
@@ -723,6 +779,11 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT);
} break;
case TOOL_SCENE_EDITABLE_CHILDREN: {
+
+ if (!profile_allow_editing) {
+ break;
+ }
+
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *>::Element *e = selection.front();
if (e) {
@@ -740,6 +801,11 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
}
} break;
case TOOL_SCENE_USE_PLACEHOLDER: {
+
+ if (!profile_allow_editing) {
+ break;
+ }
+
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *>::Element *e = selection.front();
if (e) {
@@ -760,6 +826,11 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
}
} break;
case TOOL_SCENE_MAKE_LOCAL: {
+
+ if (!profile_allow_editing) {
+ break;
+ }
+
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *>::Element *e = selection.front();
if (e) {
@@ -782,6 +853,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
}
} break;
case TOOL_SCENE_OPEN: {
+
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *>::Element *e = selection.front();
if (e) {
@@ -792,9 +864,17 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
}
} break;
case TOOL_SCENE_CLEAR_INHERITANCE: {
+ if (!profile_allow_editing) {
+ break;
+ }
+
clear_inherit_confirm->popup_centered_minsize();
} break;
case TOOL_SCENE_CLEAR_INHERITANCE_CONFIRM: {
+ if (!profile_allow_editing) {
+ break;
+ }
+
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *>::Element *e = selection.front();
if (e) {
@@ -807,6 +887,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
}
} break;
case TOOL_SCENE_OPEN_INHERITED: {
+
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *>::Element *e = selection.front();
if (e) {
@@ -894,6 +975,8 @@ void SceneTreeDock::_notification(int p_what) {
break;
first_enter = false;
+ EditorFeatureProfileManager::get_singleton()->connect("current_feature_profile_changed", this, "_feature_profile_changed");
+
CanvasItemEditorPlugin *canvas_item_plugin = Object::cast_to<CanvasItemEditorPlugin>(editor_data->get_editor("2D"));
if (canvas_item_plugin) {
canvas_item_plugin->get_canvas_item_editor()->connect("item_lock_status_changed", scene_tree, "_update_tree");
@@ -1640,7 +1723,12 @@ void SceneTreeDock::_delete_confirm() {
}
void SceneTreeDock::_update_script_button() {
- if (EditorNode::get_singleton()->get_editor_selection()->get_selection().size() == 0) {
+
+ if (!profile_allow_script_editing) {
+
+ button_create_script->hide();
+ button_clear_script->hide();
+ } else if (EditorNode::get_singleton()->get_editor_selection()->get_selection().size() == 0) {
button_create_script->hide();
button_clear_script->hide();
} else if (EditorNode::get_singleton()->get_editor_selection()->get_selection().size() == 1) {
@@ -1653,7 +1741,7 @@ void SceneTreeDock::_update_script_button() {
button_clear_script->show();
}
} else {
- button_create_script->show();
+ button_create_script->hide();
Array selection = editor_selection->get_selected_nodes();
for (int i = 0; i < selection.size(); i++) {
Node *n = Object::cast_to<Node>(selection[i]);
@@ -1760,6 +1848,8 @@ void SceneTreeDock::_create() {
replace_node(n, newnode);
}
}
+
+ scene_tree->get_scene_tree()->call_deferred("grab_focus");
}
void SceneTreeDock::replace_node(Node *p_node, Node *p_by_node, bool p_keep_properties) {
@@ -2074,11 +2164,14 @@ void SceneTreeDock::_add_children_to_popup(Object *p_obj, int p_depth) {
}
void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
+
if (!EditorNode::get_singleton()->get_edited_scene()) {
menu->clear();
- menu->add_icon_shortcut(get_icon("Add", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/add_child_node"), TOOL_NEW);
- menu->add_icon_shortcut(get_icon("Instance", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/instance_scene"), TOOL_INSTANCE);
+ if (profile_allow_editing) {
+ menu->add_icon_shortcut(get_icon("Add", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/add_child_node"), TOOL_NEW);
+ menu->add_icon_shortcut(get_icon("Instance", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/instance_scene"), TOOL_INSTANCE);
+ }
menu->set_size(Size2(1, 1));
menu->set_position(p_menu_pos);
@@ -2098,80 +2191,101 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
Node *selected = selection[0];
- subresources.clear();
- menu_subresources->clear();
- menu_subresources->set_size(Size2(1, 1));
- _add_children_to_popup(selection.front()->get(), 0);
- if (menu->get_item_count() > 0)
- menu->add_separator();
+ if (profile_allow_editing) {
+ subresources.clear();
+ menu_subresources->clear();
+ menu_subresources->set_size(Size2(1, 1));
+ _add_children_to_popup(selection.front()->get(), 0);
+ if (menu->get_item_count() > 0)
+ menu->add_separator();
- menu->add_icon_shortcut(get_icon("Add", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/add_child_node"), TOOL_NEW);
- menu->add_icon_shortcut(get_icon("Instance", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/instance_scene"), TOOL_INSTANCE);
- menu->add_separator();
+ menu->add_icon_shortcut(get_icon("Add", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/add_child_node"), TOOL_NEW);
+ menu->add_icon_shortcut(get_icon("Instance", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/instance_scene"), TOOL_INSTANCE);
+ menu->add_separator();
+ }
existing_script = selected->get_script();
}
- if (!existing_script.is_valid()) {
- menu->add_icon_shortcut(get_icon("ScriptCreate", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/attach_script"), TOOL_ATTACH_SCRIPT);
- }
- if (selection.size() > 1 || existing_script.is_valid()) {
- menu->add_icon_shortcut(get_icon("ScriptRemove", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/clear_script"), TOOL_CLEAR_SCRIPT);
- menu->add_icon_shortcut(get_icon("ScriptExtend", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/extend_script"), TOOL_ATTACH_SCRIPT);
- }
+ if (profile_allow_script_editing) {
- menu->add_separator();
- if (selection.size() == 1) {
- menu->add_icon_shortcut(get_icon("Rename", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/rename"), TOOL_RENAME);
+ if (selection.size() == 1) {
+ if (!existing_script.is_valid()) {
+ menu->add_icon_shortcut(get_icon("ScriptCreate", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/attach_script"), TOOL_ATTACH_SCRIPT);
+ } else {
+ menu->add_icon_shortcut(get_icon("ScriptExtend", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/extend_script"), TOOL_ATTACH_SCRIPT);
+ }
+ }
+ if (selection.size() > 1 || existing_script.is_valid()) {
+ menu->add_icon_shortcut(get_icon("ScriptRemove", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/clear_script"), TOOL_CLEAR_SCRIPT);
+ }
+ menu->add_separator();
}
- menu->add_icon_shortcut(get_icon("Reload", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/change_node_type"), TOOL_REPLACE);
- if (scene_tree->get_selected() != edited_scene) {
- menu->add_separator();
- menu->add_icon_shortcut(get_icon("MoveUp", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/move_up"), TOOL_MOVE_UP);
- menu->add_icon_shortcut(get_icon("MoveDown", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/move_down"), TOOL_MOVE_DOWN);
- menu->add_icon_shortcut(get_icon("Duplicate", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/duplicate"), TOOL_DUPLICATE);
- menu->add_icon_shortcut(get_icon("Reparent", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/reparent"), TOOL_REPARENT);
+ if (profile_allow_editing) {
+ if (selection.size() == 1) {
+ menu->add_icon_shortcut(get_icon("Rename", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/rename"), TOOL_RENAME);
+ }
+ menu->add_icon_shortcut(get_icon("Reload", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/change_node_type"), TOOL_REPLACE);
+
+ if (scene_tree->get_selected() != edited_scene) {
+ menu->add_separator();
+ menu->add_icon_shortcut(get_icon("MoveUp", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/move_up"), TOOL_MOVE_UP);
+ menu->add_icon_shortcut(get_icon("MoveDown", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/move_down"), TOOL_MOVE_DOWN);
+ menu->add_icon_shortcut(get_icon("Duplicate", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/duplicate"), TOOL_DUPLICATE);
+ menu->add_icon_shortcut(get_icon("Reparent", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/reparent"), TOOL_REPARENT);
+ menu->add_icon_shortcut(get_icon("NewRoot", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/make_root"), TOOL_MAKE_ROOT);
+ }
}
if (selection.size() == 1) {
- menu->add_icon_shortcut(get_icon("NewRoot", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/make_root"), TOOL_MAKE_ROOT);
- menu->add_separator();
- menu->add_icon_shortcut(get_icon("Blend", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/merge_from_scene"), TOOL_MERGE_FROM_SCENE);
- menu->add_icon_shortcut(get_icon("CreateNewSceneFrom", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/save_branch_as_scene"), TOOL_NEW_SCENE_FROM);
- menu->add_separator();
+ if (profile_allow_editing) {
+ menu->add_separator();
+ menu->add_icon_shortcut(get_icon("Blend", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/merge_from_scene"), TOOL_MERGE_FROM_SCENE);
+ menu->add_icon_shortcut(get_icon("CreateNewSceneFrom", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/save_branch_as_scene"), TOOL_NEW_SCENE_FROM);
+ menu->add_separator();
+ }
menu->add_icon_shortcut(get_icon("CopyNodePath", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/copy_node_path"), TOOL_COPY_NODE_PATH);
+
bool is_external = (selection[0]->get_filename() != "");
if (is_external) {
bool is_inherited = selection[0]->get_scene_inherited_state() != NULL;
bool is_top_level = selection[0]->get_owner() == NULL;
if (is_inherited && is_top_level) {
menu->add_separator();
- menu->add_item(TTR("Clear Inheritance"), TOOL_SCENE_CLEAR_INHERITANCE);
+ if (profile_allow_editing) {
+ menu->add_item(TTR("Clear Inheritance"), TOOL_SCENE_CLEAR_INHERITANCE);
+ }
menu->add_icon_item(get_icon("Load", "EditorIcons"), TTR("Open in Editor"), TOOL_SCENE_OPEN_INHERITED);
} else if (!is_top_level) {
menu->add_separator();
bool editable = EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(selection[0]);
bool placeholder = selection[0]->get_scene_instance_load_placeholder();
- menu->add_check_item(TTR("Editable Children"), TOOL_SCENE_EDITABLE_CHILDREN);
- menu->add_check_item(TTR("Load As Placeholder"), TOOL_SCENE_USE_PLACEHOLDER);
- menu->add_item(TTR("Make Local"), TOOL_SCENE_MAKE_LOCAL);
+ if (profile_allow_editing) {
+ menu->add_check_item(TTR("Editable Children"), TOOL_SCENE_EDITABLE_CHILDREN);
+ menu->add_check_item(TTR("Load As Placeholder"), TOOL_SCENE_USE_PLACEHOLDER);
+ menu->add_item(TTR("Make Local"), TOOL_SCENE_MAKE_LOCAL);
+ }
menu->add_icon_item(get_icon("Load", "EditorIcons"), TTR("Open in Editor"), TOOL_SCENE_OPEN);
- menu->set_item_checked(menu->get_item_idx_from_text(TTR("Editable Children")), editable);
- menu->set_item_checked(menu->get_item_idx_from_text(TTR("Load As Placeholder")), placeholder);
+ if (profile_allow_editing) {
+ menu->set_item_checked(menu->get_item_idx_from_text(TTR("Editable Children")), editable);
+ menu->set_item_checked(menu->get_item_idx_from_text(TTR("Load As Placeholder")), placeholder);
+ }
}
}
}
- if (selection.size() > 1) {
+ if (profile_allow_editing && selection.size() > 1) {
//this is not a commonly used action, it makes no sense for it to be where it was nor always present.
menu->add_separator();
menu->add_icon_shortcut(get_icon("Rename", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/batch_rename"), TOOL_BATCH_RENAME);
}
menu->add_separator();
- menu->add_icon_item(get_icon("Help", "EditorIcons"), TTR("Open documentation"), TOOL_OPEN_DOCUMENTATION);
+ menu->add_icon_item(get_icon("Help", "EditorIcons"), TTR("Open Documentation"), TOOL_OPEN_DOCUMENTATION);
- menu->add_separator();
- menu->add_icon_shortcut(get_icon("Remove", "EditorIcons"), ED_SHORTCUT("scene_tree/delete", TTR("Delete Node(s)"), KEY_DELETE), TOOL_ERASE);
+ if (profile_allow_editing) {
+ menu->add_separator();
+ menu->add_icon_shortcut(get_icon("Remove", "EditorIcons"), ED_SHORTCUT("scene_tree/delete", TTR("Delete Node(s)"), KEY_DELETE), TOOL_ERASE);
+ }
menu->set_size(Size2(1, 1));
menu->set_position(p_menu_pos);
menu->popup();
@@ -2321,6 +2435,30 @@ void SceneTreeDock::_favorite_root_selected(const String &p_class) {
_tool_selected(TOOL_CREATE_FAVORITE, false);
}
+void SceneTreeDock::_feature_profile_changed() {
+
+ Ref<EditorFeatureProfile> profile = EditorFeatureProfileManager::get_singleton()->get_current_profile();
+
+ if (profile.is_valid()) {
+
+ profile_allow_editing = !profile->is_feature_disabled(EditorFeatureProfile::FEATURE_SCENE_TREE);
+ profile_allow_script_editing = !profile->is_feature_disabled(EditorFeatureProfile::FEATURE_SCRIPT);
+
+ button_add->set_visible(profile_allow_editing);
+ button_instance->set_visible(profile_allow_editing);
+ scene_tree->set_can_rename(profile_allow_editing);
+
+ } else {
+ button_add->set_visible(true);
+ button_instance->set_visible(true);
+ scene_tree->set_can_rename(true);
+ profile_allow_editing = true;
+ profile_allow_script_editing = true;
+ }
+
+ _update_script_button();
+}
+
void SceneTreeDock::_bind_methods() {
ClassDB::bind_method(D_METHOD("_tool_selected"), &SceneTreeDock::_tool_selected, DEFVAL(false));
@@ -2353,6 +2491,7 @@ void SceneTreeDock::_bind_methods() {
ClassDB::bind_method(D_METHOD("_update_script_button"), &SceneTreeDock::_update_script_button);
ClassDB::bind_method(D_METHOD("_favorite_root_selected"), &SceneTreeDock::_favorite_root_selected);
ClassDB::bind_method(D_METHOD("_update_create_root_dialog"), &SceneTreeDock::_update_create_root_dialog);
+ ClassDB::bind_method(D_METHOD("_feature_profile_changed"), &SceneTreeDock::_feature_profile_changed);
ClassDB::bind_method(D_METHOD("instance"), &SceneTreeDock::instance);
@@ -2372,7 +2511,6 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel
HBoxContainer *filter_hbc = memnew(HBoxContainer);
filter_hbc->add_constant_override("separate", 0);
- ToolButton *tb;
ED_SHORTCUT("scene_tree/rename", TTR("Rename"));
ED_SHORTCUT("scene_tree/batch_rename", TTR("Batch Rename"), KEY_MASK_CMD | KEY_F2);
@@ -2393,19 +2531,17 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel
ED_SHORTCUT("scene_tree/delete_no_confirm", TTR("Delete (No Confirm)"), KEY_MASK_SHIFT | KEY_DELETE);
ED_SHORTCUT("scene_tree/delete", TTR("Delete"), KEY_DELETE);
- tb = memnew(ToolButton);
- tb->connect("pressed", this, "_tool_selected", make_binds(TOOL_NEW, false));
- tb->set_tooltip(TTR("Add/Create a New Node"));
- tb->set_shortcut(ED_GET_SHORTCUT("scene_tree/add_child_node"));
- filter_hbc->add_child(tb);
- button_add = tb;
+ button_add = memnew(ToolButton);
+ button_add->connect("pressed", this, "_tool_selected", make_binds(TOOL_NEW, false));
+ button_add->set_tooltip(TTR("Add/Create a New Node"));
+ button_add->set_shortcut(ED_GET_SHORTCUT("scene_tree/add_child_node"));
+ filter_hbc->add_child(button_add);
- tb = memnew(ToolButton);
- tb->connect("pressed", this, "_tool_selected", make_binds(TOOL_INSTANCE, false));
- tb->set_tooltip(TTR("Instance a scene file as a Node. Creates an inherited scene if no root node exists."));
- tb->set_shortcut(ED_GET_SHORTCUT("scene_tree/instance_scene"));
- filter_hbc->add_child(tb);
- button_instance = tb;
+ button_instance = memnew(ToolButton);
+ button_instance->connect("pressed", this, "_tool_selected", make_binds(TOOL_INSTANCE, false));
+ button_instance->set_tooltip(TTR("Instance a scene file as a Node. Creates an inherited scene if no root node exists."));
+ button_instance->set_shortcut(ED_GET_SHORTCUT("scene_tree/instance_scene"));
+ filter_hbc->add_child(button_instance);
vbc->add_child(filter_hbc);
filter = memnew(LineEdit);
@@ -2415,21 +2551,19 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel
filter->add_constant_override("minimum_spaces", 0);
filter->connect("text_changed", this, "_filter_changed");
- tb = memnew(ToolButton);
- tb->connect("pressed", this, "_tool_selected", make_binds(TOOL_ATTACH_SCRIPT, false));
- tb->set_tooltip(TTR("Attach a new or existing script for the selected node."));
- tb->set_shortcut(ED_GET_SHORTCUT("scene_tree/attach_script"));
- filter_hbc->add_child(tb);
- tb->hide();
- button_create_script = tb;
-
- tb = memnew(ToolButton);
- tb->connect("pressed", this, "_tool_selected", make_binds(TOOL_CLEAR_SCRIPT, false));
- tb->set_tooltip(TTR("Clear a script for the selected node."));
- tb->set_shortcut(ED_GET_SHORTCUT("scene_tree/clear_script"));
- filter_hbc->add_child(tb);
- button_clear_script = tb;
- tb->hide();
+ button_create_script = memnew(ToolButton);
+ button_create_script->connect("pressed", this, "_tool_selected", make_binds(TOOL_ATTACH_SCRIPT, false));
+ button_create_script->set_tooltip(TTR("Attach a new or existing script for the selected node."));
+ button_create_script->set_shortcut(ED_GET_SHORTCUT("scene_tree/attach_script"));
+ filter_hbc->add_child(button_create_script);
+ button_create_script->hide();
+
+ button_clear_script = memnew(ToolButton);
+ button_clear_script->connect("pressed", this, "_tool_selected", make_binds(TOOL_CLEAR_SCRIPT, false));
+ button_clear_script->set_tooltip(TTR("Clear a script for the selected node."));
+ button_clear_script->set_shortcut(ED_GET_SHORTCUT("scene_tree/clear_script"));
+ filter_hbc->add_child(button_clear_script);
+ button_clear_script->hide();
button_hb = memnew(HBoxContainer);
vbc->add_child(button_hb);
@@ -2537,6 +2671,9 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel
set_process_input(true);
set_process(true);
+ profile_allow_editing = true;
+ profile_allow_script_editing = true;
+
EDITOR_DEF("interface/editors/show_scene_tree_root_selection", true);
EDITOR_DEF("_use_favorites_root_selection", false);
}
diff --git a/editor/scene_tree_dock.h b/editor/scene_tree_dock.h
index 653d0a4eca..e66525d721 100644
--- a/editor/scene_tree_dock.h
+++ b/editor/scene_tree_dock.h
@@ -212,6 +212,11 @@ class SceneTreeDock : public VBoxContainer {
void _update_create_root_dialog();
void _favorite_root_selected(const String &p_class);
+ void _feature_profile_changed();
+
+ bool profile_allow_editing;
+ bool profile_allow_script_editing;
+
protected:
void _notification(int p_what);
static void _bind_methods();
diff --git a/editor/scene_tree_editor.cpp b/editor/scene_tree_editor.cpp
index c023c41747..f2d11c2753 100644
--- a/editor/scene_tree_editor.cpp
+++ b/editor/scene_tree_editor.cpp
@@ -48,6 +48,9 @@ Node *SceneTreeEditor::get_scene_node() {
void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_id) {
+ if (connect_to_script_mode) {
+ return; //dont do anything in this mode
+ }
TreeItem *item = Object::cast_to<TreeItem>(p_item);
ERR_FAIL_COND(!item);
@@ -190,7 +193,25 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) {
item->set_icon(0, icon);
item->set_metadata(0, p_node->get_path());
- if (part_of_subscene) {
+ if (connect_to_script_mode) {
+ Color accent = get_color("accent_color", "Editor");
+
+ if (!p_node->get_script().is_null()) {
+ //has script
+ item->add_button(0, get_icon("Script", "EditorIcons"), BUTTON_SCRIPT);
+ } else {
+ //has no script
+ item->set_custom_color(0, get_color("disabled_font_color", "Editor"));
+ item->set_selectable(0, false);
+ accent.a *= 0.7;
+ }
+
+ if (marked.has(p_node)) {
+ item->set_text(0, String(p_node->get_name()) + " " + TTR("(Connecting From)"));
+
+ item->set_custom_color(0, accent);
+ }
+ } else if (part_of_subscene) {
//item->set_selectable(0,marked_selectable);
if (valid_types.size() == 0) {
@@ -199,7 +220,9 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) {
} else if (marked.has(p_node)) {
- item->set_selectable(0, marked_selectable);
+ if (!connect_to_script_mode) {
+ item->set_selectable(0, marked_selectable);
+ }
item->set_custom_color(0, get_color("error_color", "Editor"));
} else if (!marked_selectable && !marked_children_selectable) {
@@ -620,6 +643,7 @@ void SceneTreeEditor::set_selected(Node *p_node, bool p_emit_selected) {
item->set_as_cursor(0);
selected = p_node;
tree->ensure_cursor_is_visible();
+
} else {
if (!p_node)
selected = NULL;
@@ -974,6 +998,11 @@ void SceneTreeEditor::_warning_changed(Node *p_for_node) {
update_timer->start();
}
+void SceneTreeEditor::set_connect_to_script_mode(bool p_enable) {
+ connect_to_script_mode = p_enable;
+ update_tree();
+}
+
void SceneTreeEditor::_bind_methods() {
ClassDB::bind_method("_tree_changed", &SceneTreeEditor::_tree_changed);
@@ -1016,6 +1045,7 @@ void SceneTreeEditor::_bind_methods() {
SceneTreeEditor::SceneTreeEditor(bool p_label, bool p_can_rename, bool p_can_open_instance) {
+ connect_to_script_mode = false;
undo_redo = NULL;
tree_dirty = true;
selected = NULL;
@@ -1091,22 +1121,17 @@ SceneTreeEditor::~SceneTreeEditor() {
void SceneTreeDialog::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE) {
- connect("confirmed", this, "_select");
- }
-
- if (p_what == NOTIFICATION_EXIT_TREE) {
- disconnect("confirmed", this, "_select");
- }
- if (p_what == NOTIFICATION_DRAW) {
-
- RID ci = get_canvas_item();
- get_stylebox("panel", "PopupMenu")->draw(ci, Rect2(Point2(), get_size()));
- }
-
- if (p_what == NOTIFICATION_VISIBILITY_CHANGED && is_visible_in_tree()) {
-
- tree->update_tree();
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE: {
+ connect("confirmed", this, "_select");
+ } break;
+ case NOTIFICATION_EXIT_TREE: {
+ disconnect("confirmed", this, "_select");
+ } break;
+ case NOTIFICATION_VISIBILITY_CHANGED: {
+ if (is_visible_in_tree())
+ tree->update_tree();
+ } break;
}
}
@@ -1135,8 +1160,6 @@ SceneTreeDialog::SceneTreeDialog() {
tree = memnew(SceneTreeEditor(false, false, true));
add_child(tree);
- //set_child_rect(tree);
-
tree->get_scene_tree()->connect("item_activated", this, "_select");
}
diff --git a/editor/scene_tree_editor.h b/editor/scene_tree_editor.h
index aa4d4dd58a..9158c4aa48 100644
--- a/editor/scene_tree_editor.h
+++ b/editor/scene_tree_editor.h
@@ -67,6 +67,8 @@ class SceneTreeEditor : public Control {
AcceptDialog *error;
AcceptDialog *warning;
+ bool connect_to_script_mode;
+
int blocked;
void _compute_hash(Node *p_node, uint64_t &hash);
@@ -151,6 +153,8 @@ public:
void update_tree() { _update_tree(); }
+ void set_connect_to_script_mode(bool p_enable);
+
Tree *get_scene_tree() { return tree; }
SceneTreeEditor(bool p_label = true, bool p_can_rename = false, bool p_can_open_instance = false);
diff --git a/editor/translations/extract.py b/editor/translations/extract.py
index fd9b1183c4..2075bd5f3c 100755
--- a/editor/translations/extract.py
+++ b/editor/translations/extract.py
@@ -60,7 +60,7 @@ def process_file(f, fname):
lc = 1
while (l):
- patterns = ['RTR(\"', 'TTR(\"']
+ patterns = ['RTR(\"', 'TTR(\"','TTRC(\"']
idx = 0
pos = 0
while (pos >= 0):