diff options
Diffstat (limited to 'editor')
69 files changed, 565 insertions, 2231 deletions
diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index e66aa88eb9..83047caf98 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -37,6 +37,7 @@ #include "editor/editor_scale.h" #include "editor/plugins/animation_player_editor_plugin.h" #include "scene/animation/animation_player.h" +#include "scene/gui/separator.h" #include "scene/gui/view_panner.h" #include "scene/main/window.h" #include "scene/scene_string_names.h" diff --git a/editor/animation_track_editor.h b/editor/animation_track_editor.h index 18ce2ded63..cb7d3c7d96 100644 --- a/editor/animation_track_editor.h +++ b/editor/animation_track_editor.h @@ -33,11 +33,14 @@ #include "editor/editor_data.h" #include "editor/editor_spin_slider.h" -#include "editor/property_editor.h" #include "editor/property_selector.h" +#include "scene/3d/node_3d.h" +#include "scene/gui/check_box.h" #include "scene/gui/control.h" #include "scene/gui/menu_button.h" +#include "scene/gui/option_button.h" +#include "scene/gui/panel_container.h" #include "scene/gui/scroll_bar.h" #include "scene/gui/slider.h" #include "scene/gui/spin_box.h" diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 99ca82b311..b0eb384efc 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -1045,6 +1045,8 @@ void CodeTextEditor::update_editor_settings() { guideline_cols.append(EditorSettings::get_singleton()->get("text_editor/appearance/guidelines/line_length_guideline_soft_column")); } text_editor->set_line_length_guidelines(guideline_cols); + } else { + text_editor->set_line_length_guidelines(TypedArray<int>()); } } diff --git a/editor/debugger/debug_adapter/debug_adapter_protocol.cpp b/editor/debugger/debug_adapter/debug_adapter_protocol.cpp index 92ea0f15e9..4c445eb766 100644 --- a/editor/debugger/debug_adapter/debug_adapter_protocol.cpp +++ b/editor/debugger/debug_adapter/debug_adapter_protocol.cpp @@ -37,6 +37,7 @@ #include "editor/doc_tools.h" #include "editor/editor_log.h" #include "editor/editor_node.h" +#include "editor/editor_settings.h" DebugAdapterProtocol *DebugAdapterProtocol::singleton = nullptr; diff --git a/editor/debugger/debug_adapter/debug_adapter_server.cpp b/editor/debugger/debug_adapter/debug_adapter_server.cpp index e9fc7ec913..41e6b1f308 100644 --- a/editor/debugger/debug_adapter/debug_adapter_server.cpp +++ b/editor/debugger/debug_adapter/debug_adapter_server.cpp @@ -33,6 +33,7 @@ #include "core/os/os.h" #include "editor/editor_log.h" #include "editor/editor_node.h" +#include "editor/editor_settings.h" DebugAdapterServer::DebugAdapterServer() { _EDITOR_DEF("network/debug_adapter/remote_port", remote_port); diff --git a/editor/debugger/editor_debugger_tree.cpp b/editor/debugger/editor_debugger_tree.cpp index bdab1cfecb..dbd2c61d44 100644 --- a/editor/debugger/editor_debugger_tree.cpp +++ b/editor/debugger/editor_debugger_tree.cpp @@ -225,6 +225,39 @@ void EditorDebuggerTree::update_scene_tree(const SceneDebuggerTree *p_tree, int updating_scene_tree = false; } +Variant EditorDebuggerTree::get_drag_data(const Point2 &p_point) { + if (get_button_id_at_position(p_point) != -1) { + return Variant(); + } + + TreeItem *selected = get_selected(); + if (!selected) { + return Variant(); + } + + String path = selected->get_text(0); + + HBoxContainer *hb = memnew(HBoxContainer); + TextureRect *tf = memnew(TextureRect); + tf->set_texture(selected->get_icon(0)); + tf->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED); + hb->add_child(tf); + Label *label = memnew(Label(path)); + hb->add_child(label); + set_drag_preview(hb); + + if (!selected->get_parent() || !selected->get_parent()->get_parent()) { + path = "."; + } else { + while (selected->get_parent()->get_parent() != get_root()) { + selected = selected->get_parent(); + path = selected->get_text(0) + "/" + path; + } + } + + return vformat("\"%s\"", path); +} + String EditorDebuggerTree::get_selected_path() { if (!get_selected()) { return ""; diff --git a/editor/debugger/editor_debugger_tree.h b/editor/debugger/editor_debugger_tree.h index 9d163fd548..5b2df8abd5 100644 --- a/editor/debugger/editor_debugger_tree.h +++ b/editor/debugger/editor_debugger_tree.h @@ -65,6 +65,8 @@ protected: void _notification(int p_what); public: + virtual Variant get_drag_data(const Point2 &p_point) override; + String get_selected_path(); ObjectID get_selected_object(); int get_current_debugger(); // Would love to have one tree for every debugger. diff --git a/editor/debugger/script_editor_debugger.cpp b/editor/debugger/script_editor_debugger.cpp index 41095a7267..ac2e958c5b 100644 --- a/editor/debugger/script_editor_debugger.cpp +++ b/editor/debugger/script_editor_debugger.cpp @@ -50,7 +50,6 @@ #include "editor/plugins/canvas_item_editor_plugin.h" #include "editor/plugins/editor_debugger_plugin.h" #include "editor/plugins/node_3d_editor_plugin.h" -#include "editor/property_editor.h" #include "main/performance.h" #include "scene/3d/camera_3d.h" #include "scene/debugger/scene_debugger.h" diff --git a/editor/dependency_editor.cpp b/editor/dependency_editor.cpp index 4f89e1b2d1..5b4da0e32b 100644 --- a/editor/dependency_editor.cpp +++ b/editor/dependency_editor.cpp @@ -37,6 +37,7 @@ #include "editor/editor_file_system.h" #include "editor/editor_node.h" #include "editor/editor_scale.h" +#include "editor/editor_settings.h" #include "scene/gui/margin_container.h" void DependencyEditor::_searched(const String &p_path) { diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp index 556a0176cb..b6d7bbc45f 100644 --- a/editor/editor_audio_buses.cpp +++ b/editor/editor_audio_buses.cpp @@ -37,6 +37,7 @@ #include "editor/editor_file_dialog.h" #include "editor/editor_node.h" #include "editor/editor_scale.h" +#include "editor/editor_settings.h" #include "filesystem_dock.h" #include "scene/resources/font.h" #include "servers/audio_server.h" diff --git a/editor/editor_command_palette.cpp b/editor/editor_command_palette.cpp index 174a97d471..ba1f2fd6af 100644 --- a/editor/editor_command_palette.cpp +++ b/editor/editor_command_palette.cpp @@ -32,6 +32,7 @@ #include "core/os/keyboard.h" #include "editor/editor_node.h" #include "editor/editor_scale.h" +#include "editor/editor_settings.h" #include "scene/gui/control.h" #include "scene/gui/tree.h" diff --git a/editor/editor_help_search.cpp b/editor/editor_help_search.cpp index 424195e4dd..297d1226e3 100644 --- a/editor/editor_help_search.cpp +++ b/editor/editor_help_search.cpp @@ -34,6 +34,7 @@ #include "editor/editor_feature_profile.h" #include "editor/editor_node.h" #include "editor/editor_scale.h" +#include "editor/editor_settings.h" void EditorHelpSearch::_update_icons() { search_box->set_right_icon(results_tree->get_theme_icon(SNAME("Search"), SNAME("EditorIcons"))); diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 57acc0b2c5..e06e3cbc5f 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -471,6 +471,9 @@ void EditorProperty::update_revert_and_pin_status() { bool new_can_revert = EditorPropertyRevert::can_property_revert(object, property, ¤t) && !is_read_only(); if (new_can_revert != can_revert || new_pinned != pinned) { + if (new_can_revert != can_revert) { + emit_signal(SNAME("property_can_revert_changed"), property, new_can_revert); + } can_revert = new_can_revert; pinned = new_pinned; update(); @@ -784,6 +787,9 @@ void EditorProperty::expand_all_folding() { void EditorProperty::collapse_all_folding() { } +void EditorProperty::expand_revertable() { +} + void EditorProperty::set_selectable(bool p_selectable) { selectable = p_selectable; } @@ -966,6 +972,7 @@ void EditorProperty::_bind_methods() { ADD_SIGNAL(MethodInfo("property_keyed_with_value", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::NIL, "value", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT))); ADD_SIGNAL(MethodInfo("property_checked", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::BOOL, "checked"))); ADD_SIGNAL(MethodInfo("property_pinned", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::BOOL, "pinned"))); + ADD_SIGNAL(MethodInfo("property_can_revert_changed", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::BOOL, "can_revert"))); ADD_SIGNAL(MethodInfo("resource_selected", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"))); ADD_SIGNAL(MethodInfo("object_id_selected", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::INT, "id"))); ADD_SIGNAL(MethodInfo("selected", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::INT, "focusable_idx"))); @@ -1225,12 +1232,15 @@ void EditorInspectorSection::_notification(int p_what) { // Get the section header font. Ref<Font> font = get_theme_font(SNAME("bold"), SNAME("EditorFonts")); int font_size = get_theme_font_size(SNAME("bold_size"), SNAME("EditorFonts")); + Color font_color = get_theme_color(SNAME("font_color"), SNAME("Editor")); // Get the right direction arrow texture, if the section is foldable. Ref<Texture2D> arrow; + bool folded = foldable; if (foldable) { if (object->editor_is_section_unfolded(section)) { arrow = get_theme_icon(SNAME("arrow"), SNAME("Tree")); + folded = false; } else { if (is_layout_rtl()) { arrow = get_theme_icon(SNAME("arrow_collapsed_mirrored"), SNAME("Tree")); @@ -1274,28 +1284,71 @@ void EditorInspectorSection::_notification(int p_what) { } draw_rect(header_rect, c); - // Draw header title and folding arrow. - const int arrow_margin = 2; - const int arrow_width = arrow.is_valid() ? arrow->get_width() : 0; - Color color = get_theme_color(SNAME("font_color")); - float text_width = get_size().width - Math::round(arrow_width + arrow_margin * EDSCALE) - section_indent; - Point2 text_offset = Point2(0, font->get_ascent(font_size) + (header_height - font->get_height(font_size)) / 2); - HorizontalAlignment text_align = HORIZONTAL_ALIGNMENT_LEFT; - if (rtl) { - text_align = HORIZONTAL_ALIGNMENT_RIGHT; - } else { - text_offset.x = section_indent + Math::round(arrow_width + arrow_margin * EDSCALE); - } - draw_string(font, text_offset.floor(), label, text_align, text_width, font_size, color); + // Draw header title, folding arrow and coutn of revertable properties. + { + int separation = Math::round(2 * EDSCALE); - if (arrow.is_valid()) { - Point2 arrow_position = Point2(0, (header_height - arrow->get_height()) / 2); + int margin_start = section_indent + separation; + int margin_end = separation; + + // - Arrow. + if (arrow.is_valid()) { + Point2 arrow_position; + if (rtl) { + arrow_position.x = get_size().width - (margin_start + arrow->get_width()); + } else { + arrow_position.x = margin_start; + } + arrow_position.y = (header_height - arrow->get_height()) / 2; + draw_texture(arrow, arrow_position); + margin_start += arrow->get_width(); + } + + int available = get_size().width - (margin_start + margin_end); + + // - Count of revertable properties. + String num_revertable_str; + int num_revertable_width = 0; + if (folded && revertable_properties.size()) { + int label_width = font->get_string_size(label, HORIZONTAL_ALIGNMENT_LEFT, available, font_size, TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_CONSTRAIN_ELLIPSIS).x; + + Ref<Font> light_font = get_theme_font(SNAME("main"), SNAME("EditorFonts")); + int light_font_size = get_theme_font_size(SNAME("main_size"), SNAME("EditorFonts")); + Color light_font_color = get_theme_color(SNAME("disabled_font_color"), SNAME("Editor")); + + // Can we fit the long version of the revertable count text? + if (revertable_properties.size() == 1) { + num_revertable_str = "(1 change)"; + } else { + num_revertable_str = vformat("(%d changes)", revertable_properties.size()); + } + num_revertable_width = light_font->get_string_size(num_revertable_str, HORIZONTAL_ALIGNMENT_LEFT, -1.0f, light_font_size, TextServer::JUSTIFICATION_NONE).x; + if (label_width + separation + num_revertable_width > available) { + // We'll have to use the short version. + num_revertable_str = vformat("(%d)", revertable_properties.size()); + num_revertable_width = light_font->get_string_size(num_revertable_str, HORIZONTAL_ALIGNMENT_LEFT, -1.0f, light_font_size, TextServer::JUSTIFICATION_NONE).x; + } + + Point2 text_offset = Point2( + margin_end, + light_font->get_ascent(light_font_size) + (header_height - light_font->get_height(light_font_size)) / 2); + if (!rtl) { + text_offset.x = get_size().width - (text_offset.x + num_revertable_width); + } + draw_string(light_font, text_offset, num_revertable_str, HORIZONTAL_ALIGNMENT_LEFT, -1.0f, light_font_size, light_font_color, TextServer::JUSTIFICATION_NONE); + margin_end += num_revertable_width + separation; + available -= num_revertable_width + separation; + } + + // - Label. + Point2 text_offset = Point2( + margin_start, + font->get_ascent(font_size) + (header_height - font->get_height(font_size)) / 2); if (rtl) { - arrow_position.x = get_size().width - section_indent - arrow->get_width() - Math::round(arrow_margin * EDSCALE); - } else { - arrow_position.x = section_indent + Math::round(arrow_margin * EDSCALE); + text_offset.x = margin_end; } - draw_texture(arrow, arrow_position.floor()); + HorizontalAlignment text_align = rtl ? HORIZONTAL_ALIGNMENT_RIGHT : HORIZONTAL_ALIGNMENT_LEFT; + draw_string(font, text_offset, label, text_align, available, font_size, font_color, TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_CONSTRAIN_ELLIPSIS); } // Draw dropping highlight. @@ -1471,6 +1524,22 @@ void EditorInspectorSection::fold() { update(); } +bool EditorInspectorSection::has_revertable_properties() const { + return !revertable_properties.is_empty(); +} + +void EditorInspectorSection::property_can_revert_changed(const String &p_path, bool p_can_revert) { + bool had_revertable_properties = has_revertable_properties(); + if (p_can_revert) { + revertable_properties.insert(p_path); + } else { + revertable_properties.erase(p_path); + } + if (has_revertable_properties() != had_revertable_properties) { + update(); + } +} + void EditorInspectorSection::_bind_methods() { ClassDB::bind_method(D_METHOD("setup", "section", "label", "object", "bg_color", "foldable"), &EditorInspectorSection::setup); ClassDB::bind_method(D_METHOD("get_vbox"), &EditorInspectorSection::get_vbox); @@ -2330,7 +2399,7 @@ String EditorInspector::get_selected_path() const { return property_selected; } -void EditorInspector::_parse_added_editors(VBoxContainer *current_vbox, Ref<EditorInspectorPlugin> ped) { +void EditorInspector::_parse_added_editors(VBoxContainer *current_vbox, EditorInspectorSection *p_section, Ref<EditorInspectorPlugin> ped) { for (const EditorInspectorPlugin::AddedEditor &F : ped->added_editors) { EditorProperty *ep = Object::cast_to<EditorProperty>(F.property_editor); current_vbox->add_child(F.property_editor); @@ -2370,6 +2439,10 @@ void EditorInspector::_parse_added_editors(VBoxContainer *current_vbox, Ref<Edit } } + if (p_section) { + ep->connect("property_can_revert_changed", callable_mp(p_section, &EditorInspectorSection::property_can_revert_changed)); + } + ep->set_read_only(read_only); ep->update_property(); ep->_update_pin_flags(); @@ -2476,9 +2549,11 @@ void EditorInspector::update_tree() { // Get the lists of editors to add the beginning. for (Ref<EditorInspectorPlugin> &ped : valid_plugins) { ped->parse_begin(object); - _parse_added_editors(main_vbox, ped); + _parse_added_editors(main_vbox, nullptr, ped); } + StringName type_name; + // Get the lists of editors for properties. for (List<PropertyInfo>::Element *E_property = plist.front(); E_property; E_property = E_property->next()) { PropertyInfo &p = E_property->get(); @@ -2549,6 +2624,7 @@ void EditorInspector::update_tree() { category_vbox = nullptr; //reset String type = p.name; + type_name = p.name; // Set the category icon. if (!ClassDB::class_exists(type) && !ScriptServer::is_global_class(type) && p.hint_string.length() && FileAccess::exists(p.hint_string)) { @@ -2582,24 +2658,23 @@ void EditorInspector::update_tree() { if (use_doc_hints) { // Sets the category tooltip to show documentation. - StringName type2 = p.name; - if (!class_descr_cache.has(type2)) { + if (!class_descr_cache.has(type_name)) { String descr; DocTools *dd = EditorHelp::get_doc_data(); - HashMap<String, DocData::ClassDoc>::Iterator E = dd->class_list.find(type2); + HashMap<String, DocData::ClassDoc>::Iterator E = dd->class_list.find(type_name); if (E) { descr = DTR(E->value.brief_description); } - class_descr_cache[type2] = descr; + class_descr_cache[type_name] = descr; } - category->set_tooltip(p.name + "::" + (class_descr_cache[type2].is_empty() ? "" : class_descr_cache[type2])); + category->set_tooltip(p.name + "::" + (class_descr_cache[type_name].is_empty() ? "" : class_descr_cache[type_name])); } // Add editors at the start of a category. for (Ref<EditorInspectorPlugin> &ped : valid_plugins) { ped->parse_category(object, p.name); - _parse_added_editors(main_vbox, ped); + _parse_added_editors(main_vbox, nullptr, ped); } continue; @@ -2791,7 +2866,7 @@ void EditorInspector::update_tree() { // Add editors at the start of a group. for (Ref<EditorInspectorPlugin> &ped : valid_plugins) { ped->parse_group(object, path); - _parse_added_editors(section->get_vbox(), ped); + _parse_added_editors(section->get_vbox(), section, ped); } vbox_per_path[root_vbox][acc_path] = section->get_vbox(); @@ -2864,7 +2939,7 @@ void EditorInspector::update_tree() { // Build the doc hint, to use as tooltip. // Get the class name. - StringName classname = object->get_class_name(); + StringName classname = type_name == "" ? object->get_class_name() : type_name; if (!object_class.is_empty()) { classname = object_class; } @@ -2973,6 +3048,12 @@ void EditorInspector::update_tree() { editor_property_map[prop].push_back(ep); } } + + EditorInspectorSection *section = Object::cast_to<EditorInspectorSection>(current_vbox->get_parent()); + if (section) { + ep->connect("property_can_revert_changed", callable_mp(section, &EditorInspectorSection::property_can_revert_changed)); + } + ep->set_draw_warning(draw_warning); ep->set_use_folding(use_folding); ep->set_checkable(checkable); @@ -3025,7 +3106,7 @@ void EditorInspector::update_tree() { // Get the lists of to add at the end. for (Ref<EditorInspectorPlugin> &ped : valid_plugins) { ped->parse_end(object); - _parse_added_editors(main_vbox, ped); + _parse_added_editors(main_vbox, nullptr, ped); } } @@ -3178,6 +3259,44 @@ void EditorInspector::expand_all_folding() { } } +void EditorInspector::expand_revertable() { + HashSet<EditorInspectorSection *> sections_to_unfold[2]; + for (EditorInspectorSection *E : sections) { + if (E->has_revertable_properties()) { + sections_to_unfold[0].insert(E); + } + } + + // Climb up the hierachy doing double buffering with the sets. + int a = 0; + int b = 1; + while (sections_to_unfold[a].size()) { + for (EditorInspectorSection *E : sections_to_unfold[a]) { + E->unfold(); + + Node *n = E->get_parent(); + while (n) { + if (Object::cast_to<EditorInspector>(n)) { + break; + } + if (Object::cast_to<EditorInspectorSection>(n) && !sections_to_unfold[a].has((EditorInspectorSection *)n)) { + sections_to_unfold[b].insert((EditorInspectorSection *)n); + } + n = n->get_parent(); + } + } + + sections_to_unfold[a].clear(); + SWAP(a, b); + } + + for (const KeyValue<StringName, List<EditorProperty *>> &F : editor_property_map) { + for (EditorProperty *E : F.value) { + E->expand_revertable(); + } + } +} + void EditorInspector::set_scroll_offset(int p_offset) { set_v_scroll(p_offset); } diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h index 4ec3513da5..54533de960 100644 --- a/editor/editor_inspector.h +++ b/editor/editor_inspector.h @@ -184,6 +184,7 @@ public: virtual void expand_all_folding(); virtual void collapse_all_folding(); + virtual void expand_revertable(); virtual Variant get_drag_data(const Point2 &p_point) override; virtual void update_cache(); @@ -281,6 +282,8 @@ class EditorInspectorSection : public Container { Timer *dropping_unfold_timer = nullptr; bool dropping = false; + HashSet<StringName> revertable_properties; + void _test_unfold(); protected: @@ -299,6 +302,9 @@ public: void unfold(); void fold(); + bool has_revertable_properties() const; + void property_can_revert_changed(const String &p_path, bool p_can_revert); + EditorInspectorSection(); ~EditorInspectorSection(); }; @@ -517,7 +523,7 @@ class EditorInspector : public ScrollContainer { void _edit_request_change(Object *p_object, const String &p_prop); void _filter_changed(const String &p_text); - void _parse_added_editors(VBoxContainer *current_vbox, Ref<EditorInspectorPlugin> ped); + void _parse_added_editors(VBoxContainer *current_vbox, EditorInspectorSection *p_section, Ref<EditorInspectorPlugin> ped); void _vscroll_changed(double); @@ -579,6 +585,7 @@ public: void collapse_all_folding(); void expand_all_folding(); + void expand_revertable(); void set_scroll_offset(int p_offset); int get_scroll_offset() const; diff --git a/editor/editor_log.cpp b/editor/editor_log.cpp index 012666d625..38cc85bb4e 100644 --- a/editor/editor_log.cpp +++ b/editor/editor_log.cpp @@ -35,7 +35,9 @@ #include "editor/editor_node.h" #include "editor/editor_paths.h" #include "editor/editor_scale.h" +#include "editor/editor_settings.h" #include "scene/gui/center_container.h" +#include "scene/gui/separator.h" #include "scene/resources/font.h" void EditorLog::_error_handler(void *p_self, const char *p_func, const char *p_file, int p_line, const char *p_error, const char *p_errorexp, bool p_editor_notify, ErrorHandlerType p_type) { diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 8b540f9787..ce885032a3 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -49,6 +49,7 @@ #include "main/main.h" #include "scene/3d/importer_mesh_instance_3d.h" #include "scene/gui/center_container.h" +#include "scene/gui/color_picker.h" #include "scene/gui/control.h" #include "scene/gui/dialogs.h" #include "scene/gui/file_dialog.h" @@ -149,6 +150,7 @@ #include "editor/plugins/debugger_editor_plugin.h" #include "editor/plugins/editor_debugger_plugin.h" #include "editor/plugins/editor_preview_plugins.h" +#include "editor/plugins/editor_resource_conversion_plugin.h" #include "editor/plugins/font_config_plugin.h" #include "editor/plugins/gdextension_export_plugin.h" #include "editor/plugins/gpu_particles_2d_editor_plugin.h" @@ -2200,9 +2202,10 @@ void EditorNode::_edit_current(bool p_skip_foreign) { Object *prev_inspected_object = InspectorDock::get_inspector_singleton()->get_edited_object(); bool disable_folding = bool(EDITOR_GET("interface/inspector/disable_folding")); - bool stay_in_script_editor_on_node_selected = bool(EDITOR_GET("text_editor/behavior/navigation/stay_in_script_editor_on_node_selected")); bool is_resource = current_obj->is_class("Resource"); bool is_node = current_obj->is_class("Node"); + bool stay_in_script_editor_on_node_selected = bool(EDITOR_GET("text_editor/behavior/navigation/stay_in_script_editor_on_node_selected")); + bool skip_main_plugin = false; String editable_warning; // None by default. @@ -2239,8 +2242,8 @@ void EditorNode::_edit_current(bool p_skip_foreign) { NodeDock::get_singleton()->set_node(current_node); SceneTreeDock::get_singleton()->set_selected(current_node); InspectorDock::get_singleton()->update(current_node); - if (!inspector_only) { - inspector_only = stay_in_script_editor_on_node_selected && ScriptEditor::get_singleton()->is_visible_in_tree(); + if (!inspector_only && !skip_main_plugin) { + skip_main_plugin = stay_in_script_editor_on_node_selected && ScriptEditor::get_singleton()->is_visible_in_tree(); } } else { NodeDock::get_singleton()->set_node(nullptr); @@ -2316,7 +2319,7 @@ void EditorNode::_edit_current(bool p_skip_foreign) { } } - if (main_plugin) { + if (main_plugin && !skip_main_plugin) { // Special case if use of external editor is true. Resource *current_res = Object::cast_to<Resource>(current_obj); if (main_plugin->get_name() == "Script" && !current_obj->is_class("VisualScript") && current_res && !current_res->is_built_in() && (bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor")) || overrides_external_editor(current_obj))) { diff --git a/editor/editor_node.h b/editor/editor_node.h index c521c0fb04..0201e84eaf 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -37,7 +37,6 @@ #include "editor/editor_run.h" #include "editor/export/editor_export.h" #include "editor/inspector_dock.h" -#include "editor/property_editor.h" typedef void (*EditorNodeInitCallback)(); typedef void (*EditorPluginInitializeCallback)(); @@ -48,6 +47,7 @@ class AudioStreamPreviewGenerator; class BackgroundProgress; class Button; class CenterContainer; +class ColorPicker; class ConfirmationDialog; class Control; class DependencyEditor; @@ -67,6 +67,7 @@ class EditorPlugin; class EditorPluginList; class EditorQuickOpen; class EditorResourcePreview; +class EditorResourceConversionPlugin; class EditorRun; class EditorRunNative; class EditorSettingsDialog; diff --git a/editor/editor_plugin_settings.cpp b/editor/editor_plugin_settings.cpp index 3a0b875b8c..5a010a66c1 100644 --- a/editor/editor_plugin_settings.cpp +++ b/editor/editor_plugin_settings.cpp @@ -37,6 +37,7 @@ #include "editor/editor_node.h" #include "editor/editor_scale.h" #include "scene/gui/margin_container.h" +#include "scene/gui/tree.h" void EditorPluginSettings::_notification(int p_what) { switch (p_what) { diff --git a/editor/editor_plugin_settings.h b/editor/editor_plugin_settings.h index 7c6d93e6f4..9c619066f2 100644 --- a/editor/editor_plugin_settings.h +++ b/editor/editor_plugin_settings.h @@ -34,8 +34,8 @@ #include "core/object/undo_redo.h" #include "editor/editor_data.h" #include "editor/plugin_config_dialog.h" -#include "property_editor.h" -#include "scene/gui/dialogs.h" + +class Tree; class EditorPluginSettings : public VBoxContainer { GDCLASS(EditorPluginSettings, VBoxContainer); diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 919443eeb8..5298b818e7 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -1580,6 +1580,11 @@ void EditorPropertyEasing::_spin_value_changed(double p_value) { // which can cause crashes and other issues. p_value = CLAMP(p_value, -1'000'000, 1'000'000); + if (positive_only) { + // Force a positive or zero value if a negative value was manually entered by double-clicking. + p_value = MAX(0.0, p_value); + } + emit_changed(get_edited_property(), p_value); _spin_focus_exited(); } @@ -1591,9 +1596,9 @@ void EditorPropertyEasing::_spin_focus_exited() { easing_draw->update(); } -void EditorPropertyEasing::setup(bool p_full, bool p_flip) { +void EditorPropertyEasing::setup(bool p_positive_only, bool p_flip) { flip = p_flip; - full = p_full; + positive_only = p_positive_only; } void EditorPropertyEasing::_notification(int p_what) { @@ -1601,13 +1606,13 @@ void EditorPropertyEasing::_notification(int p_what) { case NOTIFICATION_THEME_CHANGED: case NOTIFICATION_ENTER_TREE: { preset->clear(); - preset->add_icon_item(get_theme_icon(SNAME("CurveConstant"), SNAME("EditorIcons")), "Zero", EASING_ZERO); preset->add_icon_item(get_theme_icon(SNAME("CurveLinear"), SNAME("EditorIcons")), "Linear", EASING_LINEAR); - preset->add_icon_item(get_theme_icon(SNAME("CurveIn"), SNAME("EditorIcons")), "In", EASING_IN); - preset->add_icon_item(get_theme_icon(SNAME("CurveOut"), SNAME("EditorIcons")), "Out", EASING_OUT); - if (full) { - preset->add_icon_item(get_theme_icon(SNAME("CurveInOut"), SNAME("EditorIcons")), "In-Out", EASING_IN_OUT); - preset->add_icon_item(get_theme_icon(SNAME("CurveOutIn"), SNAME("EditorIcons")), "Out-In", EASING_OUT_IN); + preset->add_icon_item(get_theme_icon(SNAME("CurveIn"), SNAME("EditorIcons")), "Ease In", EASING_IN); + preset->add_icon_item(get_theme_icon(SNAME("CurveOut"), SNAME("EditorIcons")), "Ease Out", EASING_OUT); + preset->add_icon_item(get_theme_icon(SNAME("CurveConstant"), SNAME("EditorIcons")), "Zero", EASING_ZERO); + if (!positive_only) { + preset->add_icon_item(get_theme_icon(SNAME("CurveInOut"), SNAME("EditorIcons")), "Ease In-Out", EASING_IN_OUT); + preset->add_icon_item(get_theme_icon(SNAME("CurveOutIn"), SNAME("EditorIcons")), "Ease Out-In", EASING_OUT_IN); } easing_draw->set_custom_minimum_size(Size2(0, get_theme_font(SNAME("font"), SNAME("Label"))->get_height(get_theme_font_size(SNAME("font_size"), SNAME("Label"))) * 2)); } break; @@ -3918,6 +3923,12 @@ void EditorPropertyResource::expand_all_folding() { } } +void EditorPropertyResource::expand_revertable() { + if (sub_inspector) { + sub_inspector->expand_revertable(); + } +} + void EditorPropertyResource::set_use_sub_inspector(bool p_enable) { use_sub_inspector = p_enable; } @@ -4099,20 +4110,20 @@ EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_ case Variant::FLOAT: { if (p_hint == PROPERTY_HINT_EXP_EASING) { EditorPropertyEasing *editor = memnew(EditorPropertyEasing); - bool full = true; + bool positive_only = false; bool flip = false; - Vector<String> hints = p_hint_text.split(","); + const Vector<String> hints = p_hint_text.split(","); for (int i = 0; i < hints.size(); i++) { - String h = hints[i].strip_edges(); - if (h == "attenuation") { + const String hint = hints[i].strip_edges(); + if (hint == "attenuation") { flip = true; } - if (h == "inout") { - full = true; + if (hint == "positive_only") { + positive_only = true; } } - editor->setup(full, flip); + editor->setup(positive_only, flip); return editor; } else { diff --git a/editor/editor_properties.h b/editor/editor_properties.h index b3aac6e8ca..6a1360d2ca 100644 --- a/editor/editor_properties.h +++ b/editor/editor_properties.h @@ -443,6 +443,7 @@ class EditorPropertyEasing : public EditorProperty { bool dragging = false; bool full = false; bool flip = false; + bool positive_only = false; enum { EASING_ZERO, @@ -471,7 +472,7 @@ protected: public: virtual void update_property() override; - void setup(bool p_full, bool p_flip); + void setup(bool p_positive_only, bool p_flip); EditorPropertyEasing(); }; @@ -856,6 +857,7 @@ public: void collapse_all_folding() override; void expand_all_folding() override; + void expand_revertable() override; void set_use_sub_inspector(bool p_enable); diff --git a/editor/editor_resource_picker.cpp b/editor/editor_resource_picker.cpp index 60c091a4b0..d850773a6d 100644 --- a/editor/editor_resource_picker.cpp +++ b/editor/editor_resource_picker.cpp @@ -38,6 +38,7 @@ #include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/filesystem_dock.h" +#include "editor/plugins/editor_resource_conversion_plugin.h" #include "editor/plugins/script_editor_plugin.h" #include "editor/scene_tree_dock.h" diff --git a/editor/editor_run_native.cpp b/editor/editor_run_native.cpp index ec5edab860..d8b738be17 100644 --- a/editor/editor_run_native.cpp +++ b/editor/editor_run_native.cpp @@ -32,6 +32,7 @@ #include "editor/editor_node.h" #include "editor/editor_scale.h" +#include "editor/editor_settings.h" #include "editor/export/editor_export_platform.h" void EditorRunNative::_notification(int p_what) { diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index 5d60baf202..02380c4e39 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -1660,6 +1660,9 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { style_dictionary_add_item->set_expand_margin_size(SIDE_RIGHT, 4 * EDSCALE); theme->set_stylebox("DictionaryAddItem", "EditorStyles", style_dictionary_add_item); + Ref<StyleBoxEmpty> vshader_label_style = make_empty_stylebox(2, 1, 2, 1); + theme->set_stylebox("label_style", "VShaderEditor", vshader_label_style); + // adaptive script theme constants // for comments and elements with lower relevance const Color dim_color = Color(font_color.r, font_color.g, font_color.b, 0.5); @@ -1669,17 +1672,14 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { const Color alpha2 = Color(mono_value, mono_value, mono_value, 0.14); const Color alpha3 = Color(mono_value, mono_value, mono_value, 0.27); - // editor main color - const Color main_color = dark_theme ? Color(0.34, 0.7, 1.0) : Color(0.02, 0.5, 1.0); - - const Color symbol_color = Color(0.34, 0.57, 1.0).lerp(mono_color, dark_theme ? 0.5 : 0.3); - const Color keyword_color = Color(1.0, 0.44, 0.52); - const Color control_flow_keyword_color = dark_theme ? Color(1.0, 0.55, 0.8) : Color(0.8, 0.4, 0.6); - const Color basetype_color = dark_theme ? Color(0.26, 1.0, 0.76) : Color(0.0, 0.76, 0.38); - const Color type_color = basetype_color.lerp(mono_color, dark_theme ? 0.4 : 0.3); - const Color usertype_color = basetype_color.lerp(mono_color, dark_theme ? 0.7 : 0.5); - const Color comment_color = dim_color; - const Color string_color = (dark_theme ? Color(1.0, 0.85, 0.26) : Color(1.0, 0.82, 0.09)).lerp(mono_color, dark_theme ? 0.5 : 0.3); + const Color symbol_color = dark_theme ? Color(0.67, 0.79, 1) : Color(0, 0, 0.61); + const Color keyword_color = dark_theme ? Color(1.0, 0.44, 0.52) : Color(0.9, 0.135, 0.51); + const Color control_flow_keyword_color = dark_theme ? Color(1.0, 0.55, 0.8) : Color(0.743, 0.12, 0.8); + const Color base_type_color = dark_theme ? Color(0.26, 1.0, 0.76) : Color(0, 0.6, 0.2); + const Color engine_type_color = dark_theme ? Color(0.56, 1, 0.86) : Color(0.11, 0.55, 0.4); + const Color user_type_color = dark_theme ? Color(0.78, 1, 0.93) : Color(0.18, 0.45, 0.4); + const Color comment_color = dark_theme ? dim_color : Color(0.08, 0.08, 0.08, 0.5); + const Color string_color = dark_theme ? Color(1, 0.93, 0.63) : Color(0.6, 0.42, 0); // Use the brightest background color on a light theme (which generally uses a negative contrast rate). const Color te_background_color = dark_theme ? background_color : dark_color_3; @@ -1692,24 +1692,24 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { const Color completion_font_color = font_color; const Color text_color = font_color; const Color line_number_color = dim_color; - const Color safe_line_number_color = dim_color * Color(1, 1.2, 1, 1.5); + const Color safe_line_number_color = dark_theme ? (dim_color * Color(1, 1.2, 1, 1.5)) : Color(0, 0.4, 0, 0.75); const Color caret_color = mono_color; const Color caret_background_color = mono_color.inverted(); const Color text_selected_color = dark_color_3; - const Color brace_mismatch_color = error_color; + const Color brace_mismatch_color = dark_theme ? error_color : Color(1, 0.08, 0, 1); const Color current_line_color = alpha1; const Color line_length_guideline_color = dark_theme ? base_color : background_color; const Color word_highlighted_color = alpha1; - const Color number_color = basetype_color.lerp(mono_color, dark_theme ? 0.5 : 0.3); - const Color function_color = main_color; - const Color member_variable_color = main_color.lerp(mono_color, 0.6); + const Color number_color = dark_theme ? Color(0.63, 1, 0.88) : Color(0, 0.55, 0.28, 1); + const Color function_color = dark_theme ? Color(0.34, 0.7, 1.0) : Color(0, 0.225, 0.9, 1); + const Color member_variable_color = dark_theme ? Color(0.34, 0.7, 1.0).lerp(mono_color, 0.6) : Color(0, 0.4, 0.68, 1); const Color mark_color = Color(error_color.r, error_color.g, error_color.b, 0.3); const Color bookmark_color = Color(0.08, 0.49, 0.98); - const Color breakpoint_color = error_color; + const Color breakpoint_color = dark_theme ? error_color : Color(1, 0.27, 0.2, 1); const Color executing_line_color = Color(0.98, 0.89, 0.27); const Color code_folding_color = alpha3; const Color search_result_color = alpha1; - const Color search_result_border_color = Color(0.41, 0.61, 0.91, 0.38); + const Color search_result_border_color = dark_theme ? Color(0.41, 0.61, 0.91, 0.38) : Color(0, 0.4, 1, 0.38); EditorSettings *setting = EditorSettings::get_singleton(); String text_editor_color_theme = setting->get("text_editor/theme/color_theme"); @@ -1717,9 +1717,9 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { setting->set_initial_value("text_editor/theme/highlighting/symbol_color", symbol_color, true); setting->set_initial_value("text_editor/theme/highlighting/keyword_color", keyword_color, true); setting->set_initial_value("text_editor/theme/highlighting/control_flow_keyword_color", control_flow_keyword_color, true); - setting->set_initial_value("text_editor/theme/highlighting/base_type_color", basetype_color, true); - setting->set_initial_value("text_editor/theme/highlighting/engine_type_color", type_color, true); - setting->set_initial_value("text_editor/theme/highlighting/user_type_color", usertype_color, true); + setting->set_initial_value("text_editor/theme/highlighting/base_type_color", base_type_color, true); + setting->set_initial_value("text_editor/theme/highlighting/engine_type_color", engine_type_color, true); + setting->set_initial_value("text_editor/theme/highlighting/user_type_color", user_type_color, true); setting->set_initial_value("text_editor/theme/highlighting/comment_color", comment_color, true); setting->set_initial_value("text_editor/theme/highlighting/string_color", string_color, true); setting->set_initial_value("text_editor/theme/highlighting/background_color", te_background_color, true); diff --git a/editor/export/editor_export_platform.cpp b/editor/export/editor_export_platform.cpp index 57ae83aeee..34b407779e 100644 --- a/editor/export/editor_export_platform.cpp +++ b/editor/export/editor_export_platform.cpp @@ -41,6 +41,7 @@ #include "editor/editor_node.h" #include "editor/editor_paths.h" #include "editor/editor_scale.h" +#include "editor/editor_settings.h" #include "editor/plugins/script_editor_plugin.h" #include "editor_export_plugin.h" diff --git a/editor/export/export_template_manager.cpp b/editor/export/export_template_manager.cpp index 7d20081217..a7d9d7f068 100644 --- a/editor/export/export_template_manager.cpp +++ b/editor/export/export_template_manager.cpp @@ -37,8 +37,10 @@ #include "editor/editor_node.h" #include "editor/editor_paths.h" #include "editor/editor_scale.h" +#include "editor/editor_settings.h" #include "editor/progress_dialog.h" #include "scene/gui/file_dialog.h" +#include "scene/gui/separator.h" #include "scene/gui/tree.h" #include "scene/main/http_request.h" diff --git a/editor/export/project_export.cpp b/editor/export/project_export.cpp index a20f19efc8..cb82cefbbb 100644 --- a/editor/export/project_export.cpp +++ b/editor/export/project_export.cpp @@ -38,6 +38,7 @@ #include "editor/editor_properties.h" #include "editor/editor_scale.h" #include "editor/export/editor_export.h" +#include "scene/gui/check_button.h" #include "scene/gui/link_button.h" #include "scene/gui/tree.h" diff --git a/editor/import/scene_import_settings.cpp b/editor/import/scene_import_settings.cpp index 410f01a9c6..6c12464b5a 100644 --- a/editor/import/scene_import_settings.cpp +++ b/editor/import/scene_import_settings.cpp @@ -35,6 +35,7 @@ #include "editor/editor_inspector.h" #include "editor/editor_node.h" #include "editor/editor_scale.h" +#include "editor/editor_settings.h" #include "scene/3d/importer_mesh_instance_3d.h" #include "scene/animation/animation_player.h" #include "scene/resources/importer_mesh.h" diff --git a/editor/import_defaults_editor.cpp b/editor/import_defaults_editor.cpp index 9d96822aef..a70f5225e9 100644 --- a/editor/import_defaults_editor.cpp +++ b/editor/import_defaults_editor.cpp @@ -36,6 +36,7 @@ #include "editor/editor_autoload_settings.h" #include "editor/editor_plugin_settings.h" #include "editor/editor_sectioned_inspector.h" +#include "editor/editor_settings.h" #include "editor/localization_editor.h" #include "editor/shader_globals_editor.h" #include "scene/gui/center_container.h" diff --git a/editor/import_dock.cpp b/editor/import_dock.cpp index f9e5885f9d..087ef48b56 100644 --- a/editor/import_dock.cpp +++ b/editor/import_dock.cpp @@ -34,6 +34,7 @@ #include "editor/editor_node.h" #include "editor/editor_resource_preview.h" #include "editor/editor_scale.h" +#include "editor/editor_settings.h" class ImportDockParameters : public Object { GDCLASS(ImportDockParameters, Object); diff --git a/editor/inspector_dock.cpp b/editor/inspector_dock.cpp index e0dd5610ee..79d94246ad 100644 --- a/editor/inspector_dock.cpp +++ b/editor/inspector_dock.cpp @@ -33,6 +33,7 @@ #include "editor/editor_file_dialog.h" #include "editor/editor_node.h" #include "editor/editor_scale.h" +#include "editor/editor_settings.h" #include "editor/plugins/script_editor_plugin.h" InspectorDock *InspectorDock::singleton = nullptr; @@ -64,6 +65,9 @@ void InspectorDock::_menu_option_confirm(int p_option, bool p_confirmed) { case COLLAPSE_ALL: { _menu_collapseall(); } break; + case EXPAND_REVERTABLE: { + _menu_expand_revertable(); + } break; case RESOURCE_SAVE: { _save_resource(false); @@ -400,6 +404,10 @@ void InspectorDock::_menu_expandall() { inspector->expand_all_folding(); } +void InspectorDock::_menu_expand_revertable() { + inspector->expand_revertable(); +} + void InspectorDock::_warning_pressed() { warning_dialog->popup_centered(); } @@ -518,6 +526,8 @@ void InspectorDock::update(Object *p_object) { p->clear(); p->add_icon_shortcut(get_theme_icon(SNAME("GuiTreeArrowDown"), SNAME("EditorIcons")), ED_SHORTCUT("property_editor/expand_all", TTR("Expand All")), EXPAND_ALL); p->add_icon_shortcut(get_theme_icon(SNAME("GuiTreeArrowRight"), SNAME("EditorIcons")), ED_SHORTCUT("property_editor/collapse_all", TTR("Collapse All")), COLLAPSE_ALL); + // Calling it 'revertable' internally, because that's what the implementation is based on, but labeling it as 'non-default' because that's more user friendly, even if not 100% accurate. + p->add_shortcut(ED_SHORTCUT("property_editor/expand_revertable", TTR("Expand Non-Default")), EXPAND_REVERTABLE); p->add_separator(TTR("Property Name Style")); p->add_radio_check_item(TTR("Raw"), PROPERTY_NAME_STYLE_RAW); diff --git a/editor/inspector_dock.h b/editor/inspector_dock.h index e3d35c2157..e32410151f 100644 --- a/editor/inspector_dock.h +++ b/editor/inspector_dock.h @@ -61,6 +61,7 @@ class InspectorDock : public VBoxContainer { COLLAPSE_ALL, EXPAND_ALL, + EXPAND_REVERTABLE, // Matches `EditorPropertyNameProcessor::Style`. PROPERTY_NAME_STYLE_RAW, @@ -124,6 +125,7 @@ class InspectorDock : public VBoxContainer { void _edit_back(); void _menu_collapseall(); void _menu_expandall(); + void _menu_expand_revertable(); void _select_history(int p_idx); void _prepare_history(); diff --git a/editor/plugins/abstract_polygon_2d_editor.cpp b/editor/plugins/abstract_polygon_2d_editor.cpp index 9d80e7a193..cb77cd78bf 100644 --- a/editor/plugins/abstract_polygon_2d_editor.cpp +++ b/editor/plugins/abstract_polygon_2d_editor.cpp @@ -35,6 +35,8 @@ #include "core/os/keyboard.h" #include "editor/editor_node.h" #include "editor/editor_scale.h" +#include "editor/editor_settings.h" +#include "scene/gui/separator.h" bool AbstractPolygon2DEditor::Vertex::operator==(const AbstractPolygon2DEditor::Vertex &p_vertex) const { return polygon == p_vertex.polygon && vertex == p_vertex.vertex; diff --git a/editor/plugins/animation_blend_space_1d_editor.cpp b/editor/plugins/animation_blend_space_1d_editor.cpp index 7481882cbe..32d97c65a9 100644 --- a/editor/plugins/animation_blend_space_1d_editor.cpp +++ b/editor/plugins/animation_blend_space_1d_editor.cpp @@ -34,6 +34,7 @@ #include "editor/editor_file_dialog.h" #include "editor/editor_node.h" #include "editor/editor_scale.h" +#include "editor/editor_settings.h" #include "scene/animation/animation_blend_tree.h" StringName AnimationNodeBlendSpace1DEditor::get_blend_position_path() const { diff --git a/editor/plugins/animation_blend_space_1d_editor.h b/editor/plugins/animation_blend_space_1d_editor.h index 3488b4bf30..9b06f3248f 100644 --- a/editor/plugins/animation_blend_space_1d_editor.h +++ b/editor/plugins/animation_blend_space_1d_editor.h @@ -33,11 +33,11 @@ #include "editor/editor_plugin.h" #include "editor/plugins/animation_tree_editor_plugin.h" -#include "editor/property_editor.h" #include "scene/animation/animation_blend_space_1d.h" #include "scene/gui/button.h" #include "scene/gui/graph_edit.h" #include "scene/gui/popup.h" +#include "scene/gui/separator.h" #include "scene/gui/tree.h" class AnimationNodeBlendSpace1DEditor : public AnimationTreeNodeEditorPlugin { diff --git a/editor/plugins/animation_blend_space_2d_editor.cpp b/editor/plugins/animation_blend_space_2d_editor.cpp index 14d009f03b..dc764725dd 100644 --- a/editor/plugins/animation_blend_space_2d_editor.cpp +++ b/editor/plugins/animation_blend_space_2d_editor.cpp @@ -38,6 +38,7 @@ #include "editor/editor_file_dialog.h" #include "editor/editor_node.h" #include "editor/editor_scale.h" +#include "editor/editor_settings.h" #include "scene/animation/animation_blend_tree.h" #include "scene/animation/animation_player.h" #include "scene/gui/menu_button.h" diff --git a/editor/plugins/animation_blend_space_2d_editor.h b/editor/plugins/animation_blend_space_2d_editor.h index 88b9072599..26471df051 100644 --- a/editor/plugins/animation_blend_space_2d_editor.h +++ b/editor/plugins/animation_blend_space_2d_editor.h @@ -33,11 +33,11 @@ #include "editor/editor_plugin.h" #include "editor/plugins/animation_tree_editor_plugin.h" -#include "editor/property_editor.h" #include "scene/animation/animation_blend_space_2d.h" #include "scene/gui/button.h" #include "scene/gui/graph_edit.h" #include "scene/gui/popup.h" +#include "scene/gui/separator.h" #include "scene/gui/tree.h" class AnimationNodeBlendSpace2DEditor : public AnimationTreeNodeEditorPlugin { diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp index 561651e5f5..79be2d04b3 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.cpp +++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp @@ -38,6 +38,7 @@ #include "editor/editor_inspector.h" #include "editor/editor_node.h" #include "editor/editor_scale.h" +#include "editor/editor_settings.h" #include "scene/animation/animation_player.h" #include "scene/gui/menu_button.h" #include "scene/gui/panel.h" diff --git a/editor/plugins/animation_blend_tree_editor_plugin.h b/editor/plugins/animation_blend_tree_editor_plugin.h index b5bf91a1da..18199676b8 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.h +++ b/editor/plugins/animation_blend_tree_editor_plugin.h @@ -33,7 +33,6 @@ #include "editor/editor_plugin.h" #include "editor/plugins/animation_tree_editor_plugin.h" -#include "editor/property_editor.h" #include "scene/animation/animation_blend_tree.h" #include "scene/gui/button.h" #include "scene/gui/graph_edit.h" diff --git a/editor/plugins/animation_state_machine_editor.cpp b/editor/plugins/animation_state_machine_editor.cpp index fe5a772b0d..473450b292 100644 --- a/editor/plugins/animation_state_machine_editor.cpp +++ b/editor/plugins/animation_state_machine_editor.cpp @@ -38,6 +38,7 @@ #include "editor/editor_file_dialog.h" #include "editor/editor_node.h" #include "editor/editor_scale.h" +#include "editor/editor_settings.h" #include "scene/animation/animation_blend_tree.h" #include "scene/animation/animation_player.h" #include "scene/gui/menu_button.h" diff --git a/editor/plugins/animation_state_machine_editor.h b/editor/plugins/animation_state_machine_editor.h index ea16abd64c..165940e639 100644 --- a/editor/plugins/animation_state_machine_editor.h +++ b/editor/plugins/animation_state_machine_editor.h @@ -33,7 +33,6 @@ #include "editor/editor_plugin.h" #include "editor/plugins/animation_tree_editor_plugin.h" -#include "editor/property_editor.h" #include "scene/animation/animation_node_state_machine.h" #include "scene/gui/button.h" #include "scene/gui/graph_edit.h" diff --git a/editor/plugins/animation_tree_editor_plugin.h b/editor/plugins/animation_tree_editor_plugin.h index ab4ef5a001..a33d97f62f 100644 --- a/editor/plugins/animation_tree_editor_plugin.h +++ b/editor/plugins/animation_tree_editor_plugin.h @@ -32,7 +32,6 @@ #define ANIMATION_TREE_EDITOR_PLUGIN_H #include "editor/editor_plugin.h" -#include "editor/property_editor.h" #include "scene/animation/animation_tree.h" #include "scene/gui/button.h" #include "scene/gui/graph_edit.h" diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index a2b9c84992..6f8d33532f 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -53,6 +53,7 @@ #include "scene/gui/flow_container.h" #include "scene/gui/grid_container.h" #include "scene/gui/nine_patch_rect.h" +#include "scene/gui/separator.h" #include "scene/gui/subviewport_container.h" #include "scene/gui/view_panner.h" #include "scene/main/canvas_layer.h" diff --git a/editor/plugins/control_editor_plugin.cpp b/editor/plugins/control_editor_plugin.cpp index ec038174fc..2756e45cf4 100644 --- a/editor/plugins/control_editor_plugin.cpp +++ b/editor/plugins/control_editor_plugin.cpp @@ -31,7 +31,9 @@ #include "control_editor_plugin.h" #include "editor/editor_node.h" +#include "editor/editor_settings.h" #include "editor/plugins/canvas_item_editor_plugin.h" +#include "scene/gui/separator.h" void ControlPositioningWarning::_update_warning() { if (!control_node) { diff --git a/editor/plugins/curve_editor_plugin.cpp b/editor/plugins/curve_editor_plugin.cpp index 2954071054..8aeab684e3 100644 --- a/editor/plugins/curve_editor_plugin.cpp +++ b/editor/plugins/curve_editor_plugin.cpp @@ -36,6 +36,7 @@ #include "core/os/keyboard.h" #include "editor/editor_node.h" #include "editor/editor_scale.h" +#include "editor/editor_settings.h" CurveEditor::CurveEditor() { _selected_point = -1; diff --git a/editor/plugins/debugger_editor_plugin.cpp b/editor/plugins/debugger_editor_plugin.cpp index 5c90d70982..c572b5b7fe 100644 --- a/editor/plugins/debugger_editor_plugin.cpp +++ b/editor/plugins/debugger_editor_plugin.cpp @@ -35,6 +35,7 @@ #include "editor/debugger/editor_debugger_server.h" #include "editor/editor_node.h" #include "editor/editor_scale.h" +#include "editor/editor_settings.h" #include "editor/fileserver/editor_file_server.h" #include "editor/plugins/script_editor_plugin.h" #include "scene/gui/menu_button.h" diff --git a/editor/plugins/editor_resource_conversion_plugin.cpp b/editor/plugins/editor_resource_conversion_plugin.cpp new file mode 100644 index 0000000000..91394dbac7 --- /dev/null +++ b/editor/plugins/editor_resource_conversion_plugin.cpp @@ -0,0 +1,64 @@ +/*************************************************************************/ +/* editor_resource_conversion_plugin.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "editor_resource_conversion_plugin.h" + +void EditorResourceConversionPlugin::_bind_methods() { + GDVIRTUAL_BIND(_converts_to); + GDVIRTUAL_BIND(_handles, "resource"); + GDVIRTUAL_BIND(_convert, "resource"); +} + +String EditorResourceConversionPlugin::converts_to() const { + String ret; + if (GDVIRTUAL_CALL(_converts_to, ret)) { + return ret; + } + + return ""; +} + +bool EditorResourceConversionPlugin::handles(const Ref<Resource> &p_resource) const { + bool ret; + if (GDVIRTUAL_CALL(_handles, p_resource, ret)) { + return ret; + } + + return false; +} + +Ref<Resource> EditorResourceConversionPlugin::convert(const Ref<Resource> &p_resource) const { + Ref<Resource> ret; + if (GDVIRTUAL_CALL(_convert, p_resource, ret)) { + return ret; + } + + return Ref<Resource>(); +} diff --git a/editor/plugins/editor_resource_conversion_plugin.h b/editor/plugins/editor_resource_conversion_plugin.h new file mode 100644 index 0000000000..34b0837383 --- /dev/null +++ b/editor/plugins/editor_resource_conversion_plugin.h @@ -0,0 +1,54 @@ +/*************************************************************************/ +/* editor_resource_conversion_plugin.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef EDITOR_RESOURCE_CONVERSION_PLUGIN_H +#define EDITOR_RESOURCE_CONVERSION_PLUGIN_H + +#include "core/io/resource.h" +#include "core/object/gdvirtual.gen.inc" +#include "core/object/script_language.h" + +class EditorResourceConversionPlugin : public RefCounted { + GDCLASS(EditorResourceConversionPlugin, RefCounted); + +protected: + static void _bind_methods(); + + GDVIRTUAL0RC(String, _converts_to) + GDVIRTUAL1RC(bool, _handles, Ref<Resource>) + GDVIRTUAL1RC(Ref<Resource>, _convert, Ref<Resource>) + +public: + virtual String converts_to() const; + virtual bool handles(const Ref<Resource> &p_resource) const; + virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const; +}; + +#endif // EDITOR_RESOURCE_CONVERSION_PLUGIN_H diff --git a/editor/plugins/gradient_editor_plugin.cpp b/editor/plugins/gradient_editor_plugin.cpp index 4cdca95fca..542aee879b 100644 --- a/editor/plugins/gradient_editor_plugin.cpp +++ b/editor/plugins/gradient_editor_plugin.cpp @@ -33,6 +33,7 @@ #include "canvas_item_editor_plugin.h" #include "editor/editor_node.h" #include "editor/editor_scale.h" +#include "editor/editor_settings.h" #include "node_3d_editor_plugin.h" Size2 GradientEditor::get_minimum_size() const { diff --git a/editor/plugins/material_editor_plugin.cpp b/editor/plugins/material_editor_plugin.cpp index 4f8f6568d1..00fc8cc7d6 100644 --- a/editor/plugins/material_editor_plugin.cpp +++ b/editor/plugins/material_editor_plugin.cpp @@ -32,6 +32,7 @@ #include "editor/editor_node.h" #include "editor/editor_scale.h" +#include "editor/editor_settings.h" #include "scene/gui/subviewport_container.h" #include "scene/resources/fog_material.h" #include "scene/resources/particles_material.h" diff --git a/editor/plugins/material_editor_plugin.h b/editor/plugins/material_editor_plugin.h index 9c6247d59b..fc3da5fd9f 100644 --- a/editor/plugins/material_editor_plugin.h +++ b/editor/plugins/material_editor_plugin.h @@ -32,7 +32,7 @@ #define MATERIAL_EDITOR_PLUGIN_H #include "editor/editor_plugin.h" -#include "editor/property_editor.h" +#include "editor/plugins/editor_resource_conversion_plugin.h" #include "scene/3d/camera_3d.h" #include "scene/3d/light_3d.h" #include "scene/3d/mesh_instance_3d.h" diff --git a/editor/plugins/path_3d_editor_plugin.cpp b/editor/plugins/path_3d_editor_plugin.cpp index 2605a60d48..65b15a6001 100644 --- a/editor/plugins/path_3d_editor_plugin.cpp +++ b/editor/plugins/path_3d_editor_plugin.cpp @@ -34,6 +34,7 @@ #include "core/math/geometry_3d.h" #include "core/os/keyboard.h" #include "editor/editor_node.h" +#include "editor/editor_settings.h" #include "node_3d_editor_plugin.h" #include "scene/resources/curve.h" diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index e2f5d459e0..bbf5ffa462 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -591,7 +591,7 @@ void ScriptEditor::_go_to_tab(int p_idx) { } } - Control *c = Object::cast_to<Control>(tab_container->get_tab_control(p_idx)); + Control *c = tab_container->get_tab_control(p_idx); if (!c) { return; } @@ -813,7 +813,7 @@ void ScriptEditor::_close_tab(int p_idx, bool p_save, bool p_history_back) { if (history_pos >= 0) { idx = tab_container->get_tab_idx_from_control(history[history_pos].control); } - tab_container->set_current_tab(idx); + _go_to_tab(idx); } else { _update_selected_editor_menu(); } @@ -1448,20 +1448,20 @@ void ScriptEditor::_menu_option(int p_option) { case WINDOW_MOVE_UP: { if (tab_container->get_current_tab() > 0) { tab_container->move_child(current, tab_container->get_current_tab() - 1); - tab_container->set_current_tab(tab_container->get_current_tab() - 1); + tab_container->set_current_tab(tab_container->get_current_tab()); _update_script_names(); } } break; case WINDOW_MOVE_DOWN: { if (tab_container->get_current_tab() < tab_container->get_tab_count() - 1) { tab_container->move_child(current, tab_container->get_current_tab() + 1); - tab_container->set_current_tab(tab_container->get_current_tab() + 1); + tab_container->set_current_tab(tab_container->get_current_tab()); _update_script_names(); } } break; default: { if (p_option >= WINDOW_SELECT_BASE) { - tab_container->set_current_tab(p_option - WINDOW_SELECT_BASE); + _go_to_tab(p_option - WINDOW_SELECT_BASE); _update_script_names(); } } @@ -1494,14 +1494,14 @@ void ScriptEditor::_menu_option(int p_option) { case WINDOW_MOVE_UP: { if (tab_container->get_current_tab() > 0) { tab_container->move_child(help, tab_container->get_current_tab() - 1); - tab_container->set_current_tab(tab_container->get_current_tab() - 1); + tab_container->set_current_tab(tab_container->get_current_tab()); _update_script_names(); } } break; case WINDOW_MOVE_DOWN: { if (tab_container->get_current_tab() < tab_container->get_tab_count() - 1) { tab_container->move_child(help, tab_container->get_current_tab() + 1); - tab_container->set_current_tab(tab_container->get_current_tab() + 1); + tab_container->set_current_tab(tab_container->get_current_tab()); _update_script_names(); } } break; @@ -2125,8 +2125,8 @@ void ScriptEditor::_update_script_names() { sd.index = i; sedata.set(i, sd); } - tab_container->set_current_tab(new_prev_tab); - tab_container->set_current_tab(new_cur_tab); + _go_to_tab(new_prev_tab); + _go_to_tab(new_cur_tab); _sort_list_on_update = false; } @@ -2154,7 +2154,6 @@ void ScriptEditor::_update_script_names() { } if (tab_container->get_current_tab() == sedata_filtered[i].index) { script_list->select(index); - _script_selected(index); script_name_label->set_text(sedata_filtered[i].name); script_icon->set_texture(sedata_filtered[i].icon); diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index f77e23e63e..e700412188 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -41,7 +41,6 @@ #include "editor/filesystem_dock.h" #include "editor/plugins/visual_shader_editor_plugin.h" #include "editor/project_settings_editor.h" -#include "editor/property_editor.h" #include "editor/shader_create_dialog.h" #include "scene/gui/split_container.h" #include "servers/display_server.h" diff --git a/editor/plugins/shader_file_editor_plugin.cpp b/editor/plugins/shader_file_editor_plugin.cpp index 4564f60fa5..4874944d33 100644 --- a/editor/plugins/shader_file_editor_plugin.cpp +++ b/editor/plugins/shader_file_editor_plugin.cpp @@ -37,7 +37,6 @@ #include "editor/editor_node.h" #include "editor/editor_scale.h" #include "editor/editor_settings.h" -#include "editor/property_editor.h" #include "servers/display_server.h" #include "servers/rendering/shader_types.h" diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp index 2e9b89f1f3..196d87da36 100644 --- a/editor/plugins/text_editor.cpp +++ b/editor/plugins/text_editor.cpp @@ -32,6 +32,7 @@ #include "core/os/keyboard.h" #include "editor/editor_node.h" +#include "editor/editor_settings.h" void TextEditor::add_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) { ERR_FAIL_COND(p_highlighter.is_null()); diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index a2b09b95eb..0bd8a8a484 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -35,7 +35,9 @@ #include "core/os/keyboard.h" #include "editor/editor_node.h" #include "editor/editor_scale.h" +#include "editor/editor_settings.h" #include "scene/gui/check_box.h" +#include "scene/gui/separator.h" #include "scene/gui/view_panner.h" #include "scene/resources/texture.h" diff --git a/editor/plugins/theme_editor_plugin.cpp b/editor/plugins/theme_editor_plugin.cpp index b4eab5f811..2a61ea0baa 100644 --- a/editor/plugins/theme_editor_plugin.cpp +++ b/editor/plugins/theme_editor_plugin.cpp @@ -36,6 +36,7 @@ #include "editor/editor_resource_picker.h" #include "editor/editor_scale.h" #include "editor/progress_dialog.h" +#include "scene/gui/color_picker.h" void ThemeItemImportTree::_update_items_tree() { import_items_tree->clear(); diff --git a/editor/plugins/theme_editor_preview.cpp b/editor/plugins/theme_editor_preview.cpp index 0c7303dda4..b5c6c6d651 100644 --- a/editor/plugins/theme_editor_preview.cpp +++ b/editor/plugins/theme_editor_preview.cpp @@ -36,6 +36,7 @@ #include "editor/editor_node.h" #include "editor/editor_scale.h" #include "scene/gui/button.h" +#include "scene/gui/check_button.h" #include "scene/gui/color_picker.h" #include "scene/gui/progress_bar.h" #include "scene/resources/packed_scene.h" diff --git a/editor/plugins/version_control_editor_plugin.cpp b/editor/plugins/version_control_editor_plugin.cpp index 443d5975cd..cf55465417 100644 --- a/editor/plugins/version_control_editor_plugin.cpp +++ b/editor/plugins/version_control_editor_plugin.cpp @@ -35,6 +35,8 @@ #include "editor/editor_file_system.h" #include "editor/editor_node.h" #include "editor/editor_scale.h" +#include "editor/editor_settings.h" +#include "scene/gui/separator.h" VersionControlEditorPlugin *VersionControlEditorPlugin::singleton = nullptr; diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 626071aa72..e28122d93c 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -40,10 +40,17 @@ #include "editor/editor_node.h" #include "editor/editor_properties.h" #include "editor/editor_scale.h" +#include "editor/plugins/curve_editor_plugin.h" #include "editor/plugins/shader_editor_plugin.h" #include "scene/animation/animation_player.h" +#include "scene/gui/button.h" +#include "scene/gui/code_edit.h" +#include "scene/gui/graph_edit.h" #include "scene/gui/menu_button.h" #include "scene/gui/panel.h" +#include "scene/gui/popup.h" +#include "scene/gui/rich_text_label.h" +#include "scene/gui/tree.h" #include "scene/gui/view_panner.h" #include "scene/main/window.h" #include "scene/resources/visual_shader_nodes.h" @@ -91,17 +98,6 @@ void VisualShaderNodePlugin::_bind_methods() { /////////////////// -static Ref<StyleBoxEmpty> make_empty_stylebox(float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_bottom = -1) { - Ref<StyleBoxEmpty> style(memnew(StyleBoxEmpty)); - style->set_default_margin(SIDE_LEFT, p_margin_left * EDSCALE); - style->set_default_margin(SIDE_RIGHT, p_margin_right * EDSCALE); - style->set_default_margin(SIDE_BOTTOM, p_margin_bottom * EDSCALE); - style->set_default_margin(SIDE_TOP, p_margin_top * EDSCALE); - return style; -} - -/////////////////// - VisualShaderGraphPlugin::VisualShaderGraphPlugin() { } @@ -364,8 +360,6 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) { Control *offset; - static Ref<StyleBoxEmpty> label_style = make_empty_stylebox(2, 1, 2, 1); - static const Color type_color[] = { Color(0.38, 0.85, 0.96), // scalar (float) Color(0.49, 0.78, 0.94), // scalar (int) @@ -765,14 +759,14 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) { } else { Label *label = memnew(Label); label->set_text(name_left); - label->add_theme_style_override("normal", label_style); //more compact + label->add_theme_style_override("normal", editor->get_theme_stylebox(SNAME("label_style"), SNAME("VShaderEditor"))); //more compact hb->add_child(label); if (vsnode->is_input_port_default(i, mode) && !port_left_used) { Label *hint_label = memnew(Label); hint_label->set_text(TTR("[default]")); hint_label->add_theme_color_override("font_color", editor->get_theme_color(SNAME("font_readonly_color"), SNAME("TextEdit"))); - hint_label->add_theme_style_override("normal", label_style); + hint_label->add_theme_style_override("normal", editor->get_theme_stylebox(SNAME("label_style"), SNAME("VShaderEditor"))); hb->add_child(hint_label); } } @@ -813,7 +807,7 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) { } else { Label *label = memnew(Label); label->set_text(name_right); - label->add_theme_style_override("normal", label_style); //more compact + label->add_theme_style_override("normal", editor->get_theme_stylebox(SNAME("label_style"), SNAME("VShaderEditor"))); //more compact hb->add_child(label); } } @@ -1080,6 +1074,23 @@ VisualShaderGraphPlugin::~VisualShaderGraphPlugin() { ///////////////// +void VisualShaderEditedProperty::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_edited_property", "value"), &VisualShaderEditedProperty::set_edited_property); + ClassDB::bind_method(D_METHOD("get_edited_property"), &VisualShaderEditedProperty::get_edited_property); + + ADD_PROPERTY(PropertyInfo(Variant::NIL, "edited_property", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT), "set_edited_property", "get_edited_property"); +} + +void VisualShaderEditedProperty::set_edited_property(Variant p_variant) { + edited_property = p_variant; +} + +Variant VisualShaderEditedProperty::get_edited_property() const { + return edited_property; +} + +///////////////// + Vector2 VisualShaderEditor::selection_center; List<VisualShaderEditor::CopyItem> VisualShaderEditor::copy_items_buffer; List<VisualShader::Connection> VisualShaderEditor::copy_connections_buffer; @@ -2287,10 +2298,8 @@ void VisualShaderEditor::_port_name_focus_out(Object *line_edit, int p_node_id, } } -void VisualShaderEditor::_port_edited() { +void VisualShaderEditor::_port_edited(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing) { VisualShader::Type type = get_current_shader_type(); - - Variant value = property_editor->get_variant(); Ref<VisualShaderNode> vsn = visual_shader->get_node(type, editing_node); ERR_FAIL_COND(!vsn.is_valid()); @@ -2298,30 +2307,51 @@ void VisualShaderEditor::_port_edited() { Ref<VisualShaderNodeCustom> custom = Object::cast_to<VisualShaderNodeCustom>(vsn.ptr()); if (custom.is_valid()) { - undo_redo->add_do_method(custom.ptr(), "_set_input_port_default_value", editing_port, value); + undo_redo->add_do_method(custom.ptr(), "_set_input_port_default_value", editing_port, p_value); undo_redo->add_undo_method(custom.ptr(), "_set_input_port_default_value", editing_port, vsn->get_input_port_default_value(editing_port)); } else { - undo_redo->add_do_method(vsn.ptr(), "set_input_port_default_value", editing_port, value); + undo_redo->add_do_method(vsn.ptr(), "set_input_port_default_value", editing_port, p_value); undo_redo->add_undo_method(vsn.ptr(), "set_input_port_default_value", editing_port, vsn->get_input_port_default_value(editing_port)); } - undo_redo->add_do_method(graph_plugin.ptr(), "set_input_port_default_value", type, editing_node, editing_port, value); + undo_redo->add_do_method(graph_plugin.ptr(), "set_input_port_default_value", type, editing_node, editing_port, p_value); undo_redo->add_undo_method(graph_plugin.ptr(), "set_input_port_default_value", type, editing_node, editing_port, vsn->get_input_port_default_value(editing_port)); undo_redo->commit_action(); - - property_editor->hide(); } void VisualShaderEditor::_edit_port_default_input(Object *p_button, int p_node, int p_port) { VisualShader::Type type = get_current_shader_type(); + Ref<VisualShaderNode> vs_node = visual_shader->get_node(type, p_node); + Variant value = vs_node->get_input_port_default_value(p_port); + + edited_property_holder->set_edited_property(value); + + if (property_editor) { + property_editor->disconnect("property_changed", callable_mp(this, &VisualShaderEditor::_port_edited)); + property_editor_popup->remove_child(property_editor); + } - Ref<VisualShaderNode> vsn = visual_shader->get_node(type, p_node); + // TODO: Define these properties with actual PropertyInfo and feed it to the property editor widget. + property_editor = EditorInspector::instantiate_property_editor(edited_property_holder.ptr(), value.get_type(), "edited_property", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE); + if (property_editor) { + property_editor->set_object_and_property(edited_property_holder.ptr(), "edited_property"); + property_editor->update_property(); + property_editor->set_name_split_ratio(0); + property_editor_popup->add_child(property_editor); + + property_editor->connect("property_changed", callable_mp(this, &VisualShaderEditor::_port_edited)); + + Button *button = Object::cast_to<Button>(p_button); + if (button) { + property_editor_popup->set_position(button->get_screen_position() + Vector2(0, button->get_size().height) * graph->get_zoom()); + } + property_editor_popup->reset_size(); + if (button) { + property_editor_popup->popup(); + } else { + property_editor_popup->popup_centered_ratio(); + } + } - Button *button = Object::cast_to<Button>(p_button); - ERR_FAIL_COND(!button); - Variant value = vsn->get_input_port_default_value(p_port); - property_editor->set_position(button->get_screen_position() + Vector2(0, button->get_size().height)); - property_editor->edit(nullptr, "", value.get_type(), value, 0, ""); - property_editor->popup(); editing_node = p_node; editing_port = p_port; } @@ -5636,10 +5666,11 @@ VisualShaderEditor::VisualShaderEditor() { graph_plugin.instantiate(); graph_plugin->set_editor(this); - property_editor = memnew(CustomPropertyEditor); - add_child(property_editor); + property_editor_popup = memnew(PopupPanel); + property_editor_popup->set_min_size(Size2i(180, 0) * EDSCALE); + add_child(property_editor_popup); - property_editor->connect("variant_changed", callable_mp(this, &VisualShaderEditor::_port_edited)); + edited_property_holder.instantiate(); } class VisualShaderNodePluginInputEditor : public OptionButton { diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h index 2feed6108a..b846c34f9e 100644 --- a/editor/plugins/visual_shader_editor_plugin.h +++ b/editor/plugins/visual_shader_editor_plugin.h @@ -32,16 +32,21 @@ #define VISUAL_SHADER_EDITOR_PLUGIN_H #include "editor/editor_plugin.h" -#include "editor/plugins/curve_editor_plugin.h" -#include "editor/property_editor.h" -#include "scene/gui/button.h" -#include "scene/gui/code_edit.h" -#include "scene/gui/graph_edit.h" -#include "scene/gui/popup.h" -#include "scene/gui/rich_text_label.h" -#include "scene/gui/tree.h" +#include "editor/plugins/editor_resource_conversion_plugin.h" #include "scene/resources/visual_shader.h" +class Button; +class CodeEdit; +class CodeHighlighter; +class CurveEditor; +class GraphEdit; +class GraphNode; +class PopupMenu; +class PopupPanel; +class RichTextLabel; +class TextEdit; +class Tree; + class VisualShaderEditor; class VisualShaderNodePlugin : public RefCounted { @@ -137,13 +142,31 @@ public: ~VisualShaderGraphPlugin(); }; +class VisualShaderEditedProperty : public RefCounted { + GDCLASS(VisualShaderEditedProperty, RefCounted); + +private: + Variant edited_property; + +protected: + static void _bind_methods(); + +public: + void set_edited_property(Variant p_variant); + Variant get_edited_property() const; + + VisualShaderEditedProperty() {} +}; + class VisualShaderEditor : public VBoxContainer { GDCLASS(VisualShaderEditor, VBoxContainer); friend class VisualShaderGraphPlugin; - CustomPropertyEditor *property_editor = nullptr; + PopupPanel *property_editor_popup = nullptr; + EditorProperty *property_editor = nullptr; int editing_node = -1; int editing_port = -1; + Ref<VisualShaderEditedProperty> edited_property_holder; Ref<VisualShader> visual_shader; GraphEdit *graph = nullptr; @@ -358,7 +381,7 @@ class VisualShaderEditor : public VBoxContainer { void _node_changed(int p_id); void _edit_port_default_input(Object *p_button, int p_node, int p_port); - void _port_edited(); + void _port_edited(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing); int to_node = -1; int to_slot = -1; diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp index be1ad1ca9c..fba8c5c522 100644 --- a/editor/project_settings_editor.cpp +++ b/editor/project_settings_editor.cpp @@ -34,6 +34,7 @@ #include "editor/editor_log.h" #include "editor/editor_node.h" #include "editor/editor_scale.h" +#include "editor/editor_settings.h" #include "servers/movie_writer/movie_writer.h" ProjectSettingsEditor *ProjectSettingsEditor::singleton = nullptr; @@ -74,8 +75,13 @@ void ProjectSettingsEditor::_setting_edited(const String &p_name) { queue_save(); } +void ProjectSettingsEditor::_update_advanced(bool p_is_advanced) { + custom_properties->set_visible(p_is_advanced); +} + void ProjectSettingsEditor::_advanced_toggled(bool p_button_pressed) { EditorSettings::get_singleton()->set_project_metadata("project_settings", "advanced_mode", p_button_pressed); + _update_advanced(p_button_pressed); general_settings_inspector->set_restrict_to_basic_settings(!p_button_pressed); } @@ -584,35 +590,35 @@ ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) { advanced->connect("toggled", callable_mp(this, &ProjectSettingsEditor::_advanced_toggled)); search_bar->add_child(advanced); - HBoxContainer *header = memnew(HBoxContainer); - general_editor->add_child(header); + custom_properties = memnew(HBoxContainer); + general_editor->add_child(custom_properties); property_box = memnew(LineEdit); property_box->set_placeholder(TTR("Select a Setting or Type its Name")); property_box->set_h_size_flags(Control::SIZE_EXPAND_FILL); property_box->connect("text_changed", callable_mp(this, &ProjectSettingsEditor::_property_box_changed)); - header->add_child(property_box); + custom_properties->add_child(property_box); feature_box = memnew(OptionButton); feature_box->set_custom_minimum_size(Size2(120, 0) * EDSCALE); feature_box->connect("item_selected", callable_mp(this, &ProjectSettingsEditor::_feature_selected)); - header->add_child(feature_box); + custom_properties->add_child(feature_box); type_box = memnew(OptionButton); type_box->set_custom_minimum_size(Size2(120, 0) * EDSCALE); - header->add_child(type_box); + custom_properties->add_child(type_box); add_button = memnew(Button); add_button->set_text(TTR("Add")); add_button->set_disabled(true); add_button->connect("pressed", callable_mp(this, &ProjectSettingsEditor::_add_setting)); - header->add_child(add_button); + custom_properties->add_child(add_button); del_button = memnew(Button); del_button->set_text(TTR("Delete")); del_button->set_disabled(true); del_button->connect("pressed", callable_mp(this, &ProjectSettingsEditor::_delete_setting)); - header->add_child(del_button); + custom_properties->add_child(del_button); general_settings_inspector = memnew(SectionedInspector); general_settings_inspector->get_inspector()->set_undo_redo(EditorNode::get_singleton()->get_undo_redo()); @@ -693,6 +699,7 @@ ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) { advanced->set_pressed(true); } + _update_advanced(use_advanced); general_settings_inspector->set_restrict_to_basic_settings(!use_advanced); import_defaults_editor = memnew(ImportDefaultsEditor); diff --git a/editor/project_settings_editor.h b/editor/project_settings_editor.h index 455aaae11c..849c50b9ba 100644 --- a/editor/project_settings_editor.h +++ b/editor/project_settings_editor.h @@ -61,6 +61,7 @@ class ProjectSettingsEditor : public AcceptDialog { LineEdit *search_box = nullptr; CheckButton *advanced = nullptr; + HBoxContainer *custom_properties = nullptr; LineEdit *property_box = nullptr; OptionButton *feature_box = nullptr; OptionButton *type_box = nullptr; @@ -77,6 +78,7 @@ class ProjectSettingsEditor : public AcceptDialog { UndoRedo *undo_redo = nullptr; void _advanced_toggled(bool p_button_pressed); + void _update_advanced(bool p_is_advanced); void _property_box_changed(const String &p_text); void _update_property_box(); void _feature_selected(int p_index); diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp deleted file mode 100644 index 5f4375b424..0000000000 --- a/editor/property_editor.cpp +++ /dev/null @@ -1,1898 +0,0 @@ -/*************************************************************************/ -/* property_editor.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "property_editor.h" - -#include "core/config/project_settings.h" -#include "core/input/input.h" -#include "core/io/image_loader.h" -#include "core/io/marshalls.h" -#include "core/io/resource_loader.h" -#include "core/math/expression.h" -#include "core/object/class_db.h" -#include "core/os/keyboard.h" -#include "core/string/print_string.h" -#include "core/templates/pair.h" -#include "editor/array_property_edit.h" -#include "editor/create_dialog.h" -#include "editor/dictionary_property_edit.h" -#include "editor/editor_file_dialog.h" -#include "editor/editor_file_system.h" -#include "editor/editor_help.h" -#include "editor/editor_node.h" -#include "editor/editor_scale.h" -#include "editor/editor_settings.h" -#include "editor/filesystem_dock.h" -#include "editor/multi_node_edit.h" -#include "editor/property_selector.h" -#include "editor/scene_tree_dock.h" -#include "scene/gui/label.h" -#include "scene/main/window.h" -#include "scene/resources/font.h" -#include "scene/resources/packed_scene.h" -#include "scene/scene_string_names.h" - -void EditorResourceConversionPlugin::_bind_methods() { - GDVIRTUAL_BIND(_converts_to); - GDVIRTUAL_BIND(_handles, "resource"); - GDVIRTUAL_BIND(_convert, "resource"); -} - -String EditorResourceConversionPlugin::converts_to() const { - String ret; - if (GDVIRTUAL_CALL(_converts_to, ret)) { - return ret; - } - - return ""; -} - -bool EditorResourceConversionPlugin::handles(const Ref<Resource> &p_resource) const { - bool ret; - if (GDVIRTUAL_CALL(_handles, p_resource, ret)) { - return ret; - } - - return false; -} - -Ref<Resource> EditorResourceConversionPlugin::convert(const Ref<Resource> &p_resource) const { - Ref<Resource> ret; - if (GDVIRTUAL_CALL(_convert, p_resource, ret)) { - return ret; - } - - return Ref<Resource>(); -} - -void CustomPropertyEditor::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_WM_CLOSE_REQUEST: { - hide(); - } break; - } -} - -void CustomPropertyEditor::_menu_option(int p_which) { - switch (type) { - case Variant::INT: { - if (hint == PROPERTY_HINT_FLAGS) { - int idx = menu->get_item_index(p_which); - uint32_t item_value = menu->get_item_metadata(idx); - uint32_t value = v; - // If the item wasn't previously checked it means it was pressed, - // otherwise it was unpressed. - if (!menu->is_item_checked(idx)) { - v = value | item_value; - } else { - v = value & ~item_value; - } - emit_signal(SNAME("variant_changed")); - } else if (hint == PROPERTY_HINT_ENUM) { - v = menu->get_item_metadata(p_which); - emit_signal(SNAME("variant_changed")); - } - } break; - case Variant::STRING: { - if (hint == PROPERTY_HINT_ENUM) { - v = hint_text.get_slice(",", p_which); - emit_signal(SNAME("variant_changed")); - } - } break; - case Variant::OBJECT: { - switch (p_which) { - case OBJ_MENU_LOAD: { - file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE); - String type = (hint == PROPERTY_HINT_RESOURCE_TYPE) ? hint_text : String(); - - List<String> extensions; - for (int i = 0; i < type.get_slice_count(","); i++) { - ResourceLoader::get_recognized_extensions_for_type(type.get_slice(",", i), &extensions); - } - - HashSet<String> valid_extensions; - for (const String &E : extensions) { - valid_extensions.insert(E); - } - - file->clear_filters(); - for (const String &E : valid_extensions) { - file->add_filter("*." + E, E.to_upper()); - } - - file->popup_file_dialog(); - } break; - - case OBJ_MENU_EDIT: { - Ref<RefCounted> r = v; - - if (!r.is_null()) { - emit_signal(SNAME("resource_edit_request")); - hide(); - } - } break; - case OBJ_MENU_CLEAR: { - v = Variant(); - emit_signal(SNAME("variant_changed")); - hide(); - } break; - - case OBJ_MENU_MAKE_UNIQUE: { - Ref<Resource> res_orig = v; - if (res_orig.is_null()) { - return; - } - - List<PropertyInfo> property_list; - res_orig->get_property_list(&property_list); - List<Pair<String, Variant>> propvalues; - - for (const PropertyInfo &pi : property_list) { - Pair<String, Variant> p; - if (pi.usage & PROPERTY_USAGE_STORAGE) { - p.first = pi.name; - p.second = res_orig->get(pi.name); - } - - propvalues.push_back(p); - } - - String orig_type = res_orig->get_class(); - - Object *inst = ClassDB::instantiate(orig_type); - - Ref<Resource> res = Ref<Resource>(Object::cast_to<Resource>(inst)); - - ERR_FAIL_COND(res.is_null()); - - for (const Pair<String, Variant> &p : propvalues) { - res->set(p.first, p.second); - } - - v = res; - emit_signal(SNAME("variant_changed")); - hide(); - } break; - - case OBJ_MENU_COPY: { - EditorSettings::get_singleton()->set_resource_clipboard(v); - - } break; - case OBJ_MENU_PASTE: { - v = EditorSettings::get_singleton()->get_resource_clipboard(); - emit_signal(SNAME("variant_changed")); - - } break; - case OBJ_MENU_NEW_SCRIPT: { - if (Object::cast_to<Node>(owner)) { - SceneTreeDock::get_singleton()->open_script_dialog(Object::cast_to<Node>(owner), false); - } - - } break; - case OBJ_MENU_EXTEND_SCRIPT: { - if (Object::cast_to<Node>(owner)) { - SceneTreeDock::get_singleton()->open_script_dialog(Object::cast_to<Node>(owner), true); - } - - } break; - case OBJ_MENU_SHOW_IN_FILE_SYSTEM: { - Ref<Resource> r = v; - FileSystemDock *file_system_dock = FileSystemDock::get_singleton(); - file_system_dock->navigate_to_path(r->get_path()); - // Ensure that the FileSystem dock is visible. - TabContainer *tab_container = (TabContainer *)file_system_dock->get_parent_control(); - tab_container->set_current_tab(tab_container->get_tab_idx_from_control(file_system_dock)); - } break; - default: { - if (p_which >= CONVERT_BASE_ID) { - int to_type = p_which - CONVERT_BASE_ID; - - Vector<Ref<EditorResourceConversionPlugin>> conversions = EditorNode::get_singleton()->find_resource_conversion_plugin(Ref<Resource>(v)); - - ERR_FAIL_INDEX(to_type, conversions.size()); - - Ref<Resource> new_res = conversions[to_type]->convert(v); - - v = new_res; - emit_signal(SNAME("variant_changed")); - break; - } - ERR_FAIL_COND(inheritors_array.is_empty()); - - String intype = inheritors_array[p_which - TYPE_BASE_ID]; - - if (intype == "ViewportTexture") { - scene_tree->set_title(TTR("Pick a Viewport")); - scene_tree->popup_scenetree_dialog(); - picking_viewport = true; - return; - } - - Variant obj = ClassDB::instantiate(intype); - - if (!obj) { - if (ScriptServer::is_global_class(intype)) { - obj = EditorNode::get_editor_data().script_class_instance(intype); - } else { - obj = EditorNode::get_editor_data().instance_custom_type(intype, "Resource"); - } - } - - ERR_BREAK(!obj); - Resource *res = Object::cast_to<Resource>(obj); - ERR_BREAK(!res); - if (owner && hint == PROPERTY_HINT_RESOURCE_TYPE && hint_text == "Script") { - //make visual script the right type - res->call("set_instance_base_type", owner->get_class()); - } - - EditorNode::get_editor_data().instantiate_object_properties(obj); - v = obj; - - emit_signal(SNAME("variant_changed")); - - } break; - } - - } break; - default: { - } - } -} - -void CustomPropertyEditor::hide_menu() { - menu->hide(); -} - -Variant CustomPropertyEditor::get_variant() const { - return v; -} - -String CustomPropertyEditor::get_name() const { - return name; -} - -bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::Type p_type, const Variant &p_variant, int p_hint, String p_hint_text) { - owner = p_owner; - updating = true; - name = p_name; - v = p_variant; - field_names.clear(); - hint = p_hint; - hint_text = p_hint_text; - type_button->hide(); - if (color_picker) { - color_picker->hide(); - } - texture_preview->hide(); - inheritors_array.clear(); - text_edit->hide(); - easing_draw->hide(); - spinbox->hide(); - slider->hide(); - menu->clear(); - menu->reset_size(); - - for (int i = 0; i < MAX_VALUE_EDITORS; i++) { - if (i < MAX_VALUE_EDITORS / 4) { - value_hboxes[i]->hide(); - } - value_editor[i]->hide(); - value_label[i]->hide(); - if (i < 4) { - scroll[i]->hide(); - } - } - - for (int i = 0; i < MAX_ACTION_BUTTONS; i++) { - action_buttons[i]->hide(); - } - - checks20gc->hide(); - for (int i = 0; i < 20; i++) { - checks20[i]->hide(); - } - - type = (p_variant.get_type() != Variant::NIL && p_variant.get_type() != Variant::RID && p_type != Variant::OBJECT) ? p_variant.get_type() : p_type; - - switch (type) { - case Variant::BOOL: { - checks20gc->show(); - - CheckBox *c = checks20[0]; - c->set_text("True"); - checks20gc->set_position(Vector2(4, 4) * EDSCALE); - c->set_pressed(v); - c->show(); - - checks20gc->set_size(checks20gc->get_minimum_size()); - set_size(checks20gc->get_position() + checks20gc->get_size() + c->get_size() + Vector2(4, 4) * EDSCALE); - - } break; - case Variant::INT: - case Variant::FLOAT: { - if (hint == PROPERTY_HINT_RANGE) { - int c = hint_text.get_slice_count(","); - float min = 0, max = 100, step = type == Variant::FLOAT ? .01 : 1; - if (c >= 1) { - if (!hint_text.get_slice(",", 0).is_empty()) { - min = hint_text.get_slice(",", 0).to_float(); - } - } - if (c >= 2) { - if (!hint_text.get_slice(",", 1).is_empty()) { - max = hint_text.get_slice(",", 1).to_float(); - } - } - - if (c >= 3) { - if (!hint_text.get_slice(",", 2).is_empty()) { - step = hint_text.get_slice(",", 2).to_float(); - } - } - - if (c >= 4 && hint_text.get_slice(",", 3) == "slider") { - slider->set_min(min); - slider->set_max(max); - slider->set_step(step); - slider->set_value(v); - slider->show(); - set_size(Size2(110, 30) * EDSCALE); - } else { - spinbox->set_min(min); - spinbox->set_max(max); - spinbox->set_step(step); - spinbox->set_value(v); - spinbox->show(); - set_size(Size2(70, 35) * EDSCALE); - } - - } else if (hint == PROPERTY_HINT_ENUM) { - Vector<String> options = hint_text.split(","); - int current_val = 0; - for (int i = 0; i < options.size(); i++) { - Vector<String> text_split = options[i].split(":"); - if (text_split.size() != 1) { - current_val = text_split[1].to_int(); - } - menu->add_item(text_split[0]); - menu->set_item_metadata(i, current_val); - current_val += 1; - } - menu->set_position(get_position()); - menu->popup(); - hide(); - updating = false; - return false; - - } else if (hint == PROPERTY_HINT_LAYERS_2D_PHYSICS || - hint == PROPERTY_HINT_LAYERS_2D_RENDER || - hint == PROPERTY_HINT_LAYERS_2D_NAVIGATION || - hint == PROPERTY_HINT_LAYERS_3D_PHYSICS || - hint == PROPERTY_HINT_LAYERS_3D_RENDER || - hint == PROPERTY_HINT_LAYERS_3D_NAVIGATION) { - String basename; - switch (hint) { - case PROPERTY_HINT_LAYERS_2D_RENDER: - basename = "layer_names/2d_render"; - break; - case PROPERTY_HINT_LAYERS_2D_PHYSICS: - basename = "layer_names/2d_physics"; - break; - case PROPERTY_HINT_LAYERS_2D_NAVIGATION: - basename = "layer_names/2d_navigation"; - break; - case PROPERTY_HINT_LAYERS_3D_RENDER: - basename = "layer_names/3d_render"; - break; - case PROPERTY_HINT_LAYERS_3D_PHYSICS: - basename = "layer_names/3d_physics"; - break; - case PROPERTY_HINT_LAYERS_3D_NAVIGATION: - basename = "layer_names/3d_navigation"; - break; - } - - checks20gc->show(); - uint32_t flgs = v; - for (int i = 0; i < 2; i++) { - Point2 ofs(4, 4); - ofs.y += 22 * i; - for (int j = 0; j < 10; j++) { - int idx = i * 10 + j; - CheckBox *c = checks20[idx]; - c->set_text(ProjectSettings::get_singleton()->get(basename + "/layer_" + itos(idx + 1))); - c->set_pressed(flgs & (1 << (i * 10 + j))); - c->show(); - } - } - - show(); - - checks20gc->set_position(Vector2(4, 4) * EDSCALE); - checks20gc->set_size(checks20gc->get_minimum_size()); - - set_size(Vector2(4, 4) * EDSCALE + checks20gc->get_position() + checks20gc->get_size()); - - } else if (hint == PROPERTY_HINT_EXP_EASING) { - easing_draw->set_anchor_and_offset(SIDE_LEFT, Control::ANCHOR_BEGIN, 5 * EDSCALE); - easing_draw->set_anchor_and_offset(SIDE_RIGHT, Control::ANCHOR_END, -5 * EDSCALE); - easing_draw->set_anchor_and_offset(SIDE_TOP, Control::ANCHOR_BEGIN, 5 * EDSCALE); - easing_draw->set_anchor_and_offset(SIDE_BOTTOM, Control::ANCHOR_END, -30 * EDSCALE); - type_button->set_anchor_and_offset(SIDE_LEFT, Control::ANCHOR_BEGIN, 3 * EDSCALE); - type_button->set_anchor_and_offset(SIDE_RIGHT, Control::ANCHOR_END, -3 * EDSCALE); - type_button->set_anchor_and_offset(SIDE_TOP, Control::ANCHOR_END, -25 * EDSCALE); - type_button->set_anchor_and_offset(SIDE_BOTTOM, Control::ANCHOR_END, -7 * EDSCALE); - type_button->set_text(TTR("Preset...")); - type_button->get_popup()->clear(); - type_button->get_popup()->add_item(TTR("Linear"), EASING_LINEAR); - type_button->get_popup()->add_item(TTR("Ease In"), EASING_EASE_IN); - type_button->get_popup()->add_item(TTR("Ease Out"), EASING_EASE_OUT); - if (hint_text != "attenuation") { - type_button->get_popup()->add_item(TTR("Zero"), EASING_ZERO); - type_button->get_popup()->add_item(TTR("Easing In-Out"), EASING_IN_OUT); - type_button->get_popup()->add_item(TTR("Easing Out-In"), EASING_OUT_IN); - } - - type_button->show(); - easing_draw->show(); - set_size(Size2(200, 150) * EDSCALE); - } else if (hint == PROPERTY_HINT_FLAGS) { - Vector<String> flags = hint_text.split(","); - uint32_t value = v; - for (int i = 0; i < flags.size(); i++) { - uint32_t current_val; - Vector<String> text_split = flags[i].split(":"); - if (text_split.size() != 1) { - current_val = text_split[1].to_int(); - } else { - current_val = 1 << i; - } - menu->add_check_item(text_split[0], current_val); - menu->set_item_metadata(i, current_val); - if ((value & current_val) == current_val) { - menu->set_item_checked(menu->get_item_index(current_val), true); - } - } - menu->set_position(get_position()); - menu->popup(); - hide(); - updating = false; - return false; - - } else { - List<String> names; - names.push_back("value:"); - config_value_editors(1, 1, 50, names); - value_editor[0]->set_text(TS->format_number(String::num(v))); - } - - } break; - case Variant::STRING: { - if (hint == PROPERTY_HINT_LOCALE_ID) { - List<String> names; - names.push_back(TTR("Locale...")); - names.push_back(TTR("Clear")); - config_action_buttons(names); - } else if (hint == PROPERTY_HINT_FILE || hint == PROPERTY_HINT_GLOBAL_FILE) { - List<String> names; - names.push_back(TTR("File...")); - names.push_back(TTR("Clear")); - config_action_buttons(names); - } else if (hint == PROPERTY_HINT_DIR || hint == PROPERTY_HINT_GLOBAL_DIR) { - List<String> names; - names.push_back(TTR("Dir...")); - names.push_back(TTR("Clear")); - config_action_buttons(names); - } else if (hint == PROPERTY_HINT_ENUM) { - Vector<String> options = hint_text.split(","); - for (int i = 0; i < options.size(); i++) { - menu->add_item(options[i], i); - } - menu->set_position(get_position()); - menu->popup(); - hide(); - updating = false; - return false; - - } else if (hint == PROPERTY_HINT_MULTILINE_TEXT) { - text_edit->show(); - text_edit->set_text(v); - text_edit->deselect(); - - int button_margin = text_edit->get_theme_constant(SNAME("button_margin"), SNAME("Dialogs")); - int margin = text_edit->get_theme_constant(SNAME("margin"), SNAME("Dialogs")); - - action_buttons[0]->set_anchor(SIDE_LEFT, Control::ANCHOR_END); - action_buttons[0]->set_anchor(SIDE_TOP, Control::ANCHOR_END); - action_buttons[0]->set_anchor(SIDE_RIGHT, Control::ANCHOR_END); - action_buttons[0]->set_anchor(SIDE_BOTTOM, Control::ANCHOR_END); - action_buttons[0]->set_begin(Point2(-70 * EDSCALE, -button_margin + 5 * EDSCALE)); - action_buttons[0]->set_end(Point2(-margin, -margin)); - action_buttons[0]->set_text(TTR("Close")); - action_buttons[0]->show(); - - } else if (hint == PROPERTY_HINT_TYPE_STRING) { - if (!create_dialog) { - create_dialog = memnew(CreateDialog); - create_dialog->connect("create", callable_mp(this, &CustomPropertyEditor::_create_dialog_callback)); - add_child(create_dialog); - } - - if (!hint_text.is_empty()) { - create_dialog->set_base_type(hint_text); - } else { - create_dialog->set_base_type("Object"); - } - - create_dialog->popup_create(false); - hide(); - updating = false; - return false; - - } else if (hint == PROPERTY_HINT_METHOD_OF_VARIANT_TYPE) { -#define MAKE_PROPSELECT \ - if (!property_select) { \ - property_select = memnew(PropertySelector); \ - property_select->connect("selected", callable_mp(this, &CustomPropertyEditor::_create_selected_property)); \ - add_child(property_select); \ - } \ - hide(); - - MAKE_PROPSELECT; - - Variant::Type type = Variant::NIL; - for (int i = 0; i < Variant::VARIANT_MAX; i++) { - if (hint_text == Variant::get_type_name(Variant::Type(i))) { - type = Variant::Type(i); - } - } - if (type != Variant::NIL) { - property_select->select_method_from_basic_type(type, v); - } - updating = false; - return false; - - } else if (hint == PROPERTY_HINT_METHOD_OF_BASE_TYPE) { - MAKE_PROPSELECT - - property_select->select_method_from_base_type(hint_text, v); - - updating = false; - return false; - - } else if (hint == PROPERTY_HINT_METHOD_OF_INSTANCE) { - MAKE_PROPSELECT - - Object *instance = ObjectDB::get_instance(ObjectID(hint_text.to_int())); - if (instance) { - property_select->select_method_from_instance(instance, v); - } - updating = false; - return false; - - } else if (hint == PROPERTY_HINT_METHOD_OF_SCRIPT) { - MAKE_PROPSELECT - - Object *obj = ObjectDB::get_instance(ObjectID(hint_text.to_int())); - if (Object::cast_to<Script>(obj)) { - property_select->select_method_from_script(Object::cast_to<Script>(obj), v); - } - - updating = false; - return false; - - } else if (hint == PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE) { - MAKE_PROPSELECT - Variant::Type type = Variant::NIL; - String tname = hint_text; - if (tname.contains(".")) { - tname = tname.get_slice(".", 0); - } - for (int i = 0; i < Variant::VARIANT_MAX; i++) { - if (tname == Variant::get_type_name(Variant::Type(i))) { - type = Variant::Type(Variant::Type(i)); - } - } - - if (type != Variant::NIL) { - property_select->select_property_from_basic_type(type, v); - } - - updating = false; - return false; - - } else if (hint == PROPERTY_HINT_PROPERTY_OF_BASE_TYPE) { - MAKE_PROPSELECT - - property_select->select_property_from_base_type(hint_text, v); - - updating = false; - return false; - - } else if (hint == PROPERTY_HINT_PROPERTY_OF_INSTANCE) { - MAKE_PROPSELECT - - Object *instance = ObjectDB::get_instance(ObjectID(hint_text.to_int())); - if (instance) { - property_select->select_property_from_instance(instance, v); - } - - updating = false; - return false; - - } else if (hint == PROPERTY_HINT_PROPERTY_OF_SCRIPT) { - MAKE_PROPSELECT - - Object *obj = ObjectDB::get_instance(ObjectID(hint_text.to_int())); - if (Object::cast_to<Script>(obj)) { - property_select->select_property_from_script(Object::cast_to<Script>(obj), v); - } - - updating = false; - return false; - - } else { - List<String> names; - names.push_back("string:"); - config_value_editors(1, 1, 50, names); - value_editor[0]->set_text(v); - } - - } break; - case Variant::VECTOR2: { - field_names.push_back("x"); - field_names.push_back("y"); - config_value_editors(2, 2, 10, field_names); - Vector2 vec = v; - value_editor[0]->set_text(String::num(vec.x)); - value_editor[1]->set_text(String::num(vec.y)); - } break; - case Variant::RECT2: { - field_names.push_back("x"); - field_names.push_back("y"); - field_names.push_back("w"); - field_names.push_back("h"); - config_value_editors(4, 4, 10, field_names); - Rect2 r = v; - value_editor[0]->set_text(String::num(r.position.x)); - value_editor[1]->set_text(String::num(r.position.y)); - value_editor[2]->set_text(String::num(r.size.x)); - value_editor[3]->set_text(String::num(r.size.y)); - } break; - case Variant::VECTOR3: { - field_names.push_back("x"); - field_names.push_back("y"); - field_names.push_back("z"); - config_value_editors(3, 3, 10, field_names); - Vector3 vec = v; - value_editor[0]->set_text(String::num(vec.x)); - value_editor[1]->set_text(String::num(vec.y)); - value_editor[2]->set_text(String::num(vec.z)); - } break; - case Variant::PLANE: { - field_names.push_back("x"); - field_names.push_back("y"); - field_names.push_back("z"); - field_names.push_back("d"); - config_value_editors(4, 4, 10, field_names); - Plane plane = v; - value_editor[0]->set_text(String::num(plane.normal.x)); - value_editor[1]->set_text(String::num(plane.normal.y)); - value_editor[2]->set_text(String::num(plane.normal.z)); - value_editor[3]->set_text(String::num(plane.d)); - - } break; - case Variant::QUATERNION: { - field_names.push_back("x"); - field_names.push_back("y"); - field_names.push_back("z"); - field_names.push_back("w"); - config_value_editors(4, 4, 10, field_names); - Quaternion q = v; - value_editor[0]->set_text(String::num(q.x)); - value_editor[1]->set_text(String::num(q.y)); - value_editor[2]->set_text(String::num(q.z)); - value_editor[3]->set_text(String::num(q.w)); - - } break; - case Variant::AABB: { - field_names.push_back("px"); - field_names.push_back("py"); - field_names.push_back("pz"); - field_names.push_back("sx"); - field_names.push_back("sy"); - field_names.push_back("sz"); - config_value_editors(6, 3, 16, field_names); - - AABB aabb = v; - value_editor[0]->set_text(String::num(aabb.position.x)); - value_editor[1]->set_text(String::num(aabb.position.y)); - value_editor[2]->set_text(String::num(aabb.position.z)); - value_editor[3]->set_text(String::num(aabb.size.x)); - value_editor[4]->set_text(String::num(aabb.size.y)); - value_editor[5]->set_text(String::num(aabb.size.z)); - - } break; - case Variant::TRANSFORM2D: { - field_names.push_back("xx"); - field_names.push_back("xy"); - field_names.push_back("yx"); - field_names.push_back("yy"); - field_names.push_back("ox"); - field_names.push_back("oy"); - config_value_editors(6, 2, 16, field_names); - - Transform2D basis = v; - for (int i = 0; i < 6; i++) { - value_editor[i]->set_text(String::num(basis.columns[i / 2][i % 2])); - } - - } break; - case Variant::BASIS: { - field_names.push_back("xx"); - field_names.push_back("xy"); - field_names.push_back("xz"); - field_names.push_back("yx"); - field_names.push_back("yy"); - field_names.push_back("yz"); - field_names.push_back("zx"); - field_names.push_back("zy"); - field_names.push_back("zz"); - config_value_editors(9, 3, 16, field_names); - - Basis basis = v; - for (int i = 0; i < 9; i++) { - value_editor[i]->set_text(String::num(basis.rows[i / 3][i % 3])); - } - - } break; - case Variant::TRANSFORM3D: { - field_names.push_back("xx"); - field_names.push_back("xy"); - field_names.push_back("xz"); - field_names.push_back("xo"); - field_names.push_back("yx"); - field_names.push_back("yy"); - field_names.push_back("yz"); - field_names.push_back("yo"); - field_names.push_back("zx"); - field_names.push_back("zy"); - field_names.push_back("zz"); - field_names.push_back("zo"); - config_value_editors(12, 4, 16, field_names); - - Transform3D tr = v; - for (int i = 0; i < 9; i++) { - value_editor[(i / 3) * 4 + i % 3]->set_text(String::num(tr.basis.rows[i / 3][i % 3])); - } - - value_editor[3]->set_text(String::num(tr.origin.x)); - value_editor[7]->set_text(String::num(tr.origin.y)); - value_editor[11]->set_text(String::num(tr.origin.z)); - - } break; - case Variant::COLOR: { - if (!color_picker) { - //late init for performance - color_picker = memnew(ColorPicker); - color_picker->set_deferred_mode(true); - value_vbox->add_child(color_picker); - color_picker->hide(); - color_picker->connect("color_changed", callable_mp(this, &CustomPropertyEditor::_color_changed)); - color_picker->connect("show", callable_mp(EditorNode::get_singleton(), &EditorNode::setup_color_picker).bind(color_picker)); - } - - color_picker->show(); - color_picker->set_edit_alpha(hint != PROPERTY_HINT_COLOR_NO_ALPHA); - color_picker->set_pick_color(v); - color_picker->set_focus_on_line_edit(); - - } break; - - case Variant::NODE_PATH: { - List<String> names; - names.push_back(TTR("Assign")); - names.push_back(TTR("Clear")); - - if (owner && owner->is_class("Node") && (v.get_type() == Variant::NODE_PATH) && Object::cast_to<Node>(owner)->has_node(v)) { - names.push_back(TTR("Select Node")); - } - - config_action_buttons(names); - - } break; - case Variant::OBJECT: { - if (hint != PROPERTY_HINT_RESOURCE_TYPE) { - break; - } - - if (p_name == "script" && hint_text == "Script" && Object::cast_to<Node>(owner)) { - menu->add_item(TTR("New Script"), OBJ_MENU_NEW_SCRIPT); - menu->add_separator(); - } else if (!hint_text.is_empty()) { - int idx = 0; - - Vector<EditorData::CustomType> custom_resources; - - if (EditorNode::get_editor_data().get_custom_types().has("Resource")) { - custom_resources = EditorNode::get_editor_data().get_custom_types()["Resource"]; - } - - for (int i = 0; i < hint_text.get_slice_count(","); i++) { - String base = hint_text.get_slice(",", i); - - HashSet<String> valid_inheritors; - valid_inheritors.insert(base); - List<StringName> inheritors; - ClassDB::get_inheriters_from_class(base.strip_edges(), &inheritors); - - for (int j = 0; j < custom_resources.size(); j++) { - inheritors.push_back(custom_resources[j].name); - } - - List<StringName>::Element *E = inheritors.front(); - while (E) { - valid_inheritors.insert(E->get()); - E = E->next(); - } - - for (const String &j : valid_inheritors) { - const String &t = j; - - bool is_custom_resource = false; - Ref<Texture2D> icon; - if (!custom_resources.is_empty()) { - for (int k = 0; k < custom_resources.size(); k++) { - if (custom_resources[k].name == t) { - is_custom_resource = true; - if (custom_resources[k].icon.is_valid()) { - icon = custom_resources[k].icon; - } - break; - } - } - } - - if (!is_custom_resource && (!ClassDB::can_instantiate(t) || ClassDB::is_virtual(t))) { - continue; - } - - inheritors_array.push_back(t); - - int id = TYPE_BASE_ID + idx; - - menu->add_item(vformat(TTR("New %s"), t), id); - - idx++; - } - } - - if (menu->get_item_count()) { - menu->add_separator(); - } - } - - menu->add_item(TTR("Load"), OBJ_MENU_LOAD); - - if (!Ref<Resource>(v).is_null()) { - menu->add_item(TTR("Edit"), OBJ_MENU_EDIT); - menu->add_item(TTR("Clear"), OBJ_MENU_CLEAR); - menu->add_item(TTR("Make Unique"), OBJ_MENU_MAKE_UNIQUE); - - Ref<Resource> r = v; - if (r.is_valid() && r->get_path().is_resource_file()) { - menu->add_separator(); - menu->add_item(TTR("Show in FileSystem"), OBJ_MENU_SHOW_IN_FILE_SYSTEM); - } - } - - Ref<Resource> cb = EditorSettings::get_singleton()->get_resource_clipboard(); - bool paste_valid = false; - if (cb.is_valid()) { - if (hint_text.is_empty()) { - paste_valid = true; - } else { - for (int i = 0; i < hint_text.get_slice_count(","); i++) { - if (ClassDB::is_parent_class(cb->get_class(), hint_text.get_slice(",", i))) { - paste_valid = true; - break; - } - } - } - } - - if (!Ref<Resource>(v).is_null() || paste_valid) { - menu->add_separator(); - - if (!Ref<Resource>(v).is_null()) { - menu->add_item(TTR("Copy"), OBJ_MENU_COPY); - } - - if (paste_valid) { - menu->add_item(TTR("Paste"), OBJ_MENU_PASTE); - } - } - - if (!Ref<Resource>(v).is_null()) { - Vector<Ref<EditorResourceConversionPlugin>> conversions = EditorNode::get_singleton()->find_resource_conversion_plugin(Ref<Resource>(v)); - if (conversions.size()) { - menu->add_separator(); - } - for (int i = 0; i < conversions.size(); i++) { - String what = conversions[i]->converts_to(); - menu->add_item(vformat(TTR("Convert to %s"), what), CONVERT_BASE_ID + i); - } - } - - menu->set_position(get_position()); - menu->popup(); - hide(); - updating = false; - return false; - } break; - case Variant::DICTIONARY: { - } break; - case Variant::PACKED_BYTE_ARRAY: { - } break; - case Variant::PACKED_INT32_ARRAY: { - } break; - case Variant::PACKED_FLOAT32_ARRAY: { - } break; - case Variant::PACKED_INT64_ARRAY: { - } break; - case Variant::PACKED_FLOAT64_ARRAY: { - } break; - case Variant::PACKED_STRING_ARRAY: { - } break; - case Variant::PACKED_VECTOR3_ARRAY: { - } break; - case Variant::PACKED_COLOR_ARRAY: { - } break; - default: { - } - } - - updating = false; - return true; -} - -void CustomPropertyEditor::_file_selected(String p_file) { - switch (type) { - case Variant::STRING: { - if (hint == PROPERTY_HINT_FILE || hint == PROPERTY_HINT_DIR) { - v = ProjectSettings::get_singleton()->localize_path(p_file); - emit_signal(SNAME("variant_changed")); - hide(); - } - - if (hint == PROPERTY_HINT_GLOBAL_FILE || hint == PROPERTY_HINT_GLOBAL_DIR) { - v = p_file; - emit_signal(SNAME("variant_changed")); - hide(); - } - - } break; - case Variant::OBJECT: { - String type = (hint == PROPERTY_HINT_RESOURCE_TYPE) ? hint_text : String(); - - Ref<Resource> res = ResourceLoader::load(p_file, type); - if (res.is_null()) { - error->set_text(TTR("Error loading file: Not a resource!")); - error->popup_centered(); - break; - } - v = res; - emit_signal(SNAME("variant_changed")); - hide(); - } break; - default: { - } - } -} - -void CustomPropertyEditor::_locale_selected(String p_locale) { - if (type == Variant::STRING && hint == PROPERTY_HINT_LOCALE_ID) { - v = p_locale; - emit_signal(SNAME("variant_changed")); - hide(); - } -} - -void CustomPropertyEditor::_type_create_selected(int p_idx) { - if (type == Variant::INT || type == Variant::FLOAT) { - float newval = 0; - switch (p_idx) { - case EASING_LINEAR: { - newval = 1; - } break; - case EASING_EASE_IN: { - newval = 2.0; - } break; - case EASING_EASE_OUT: { - newval = 0.5; - } break; - case EASING_ZERO: { - newval = 0; - } break; - case EASING_IN_OUT: { - newval = -0.5; - } break; - case EASING_OUT_IN: { - newval = -2.0; - } break; - } - - v = newval; - emit_signal(SNAME("variant_changed")); - easing_draw->update(); - - } else if (type == Variant::OBJECT) { - ERR_FAIL_INDEX(p_idx, inheritors_array.size()); - - String intype = inheritors_array[p_idx]; - - Variant obj = ClassDB::instantiate(intype); - - if (!obj) { - if (ScriptServer::is_global_class(intype)) { - obj = EditorNode::get_editor_data().script_class_instance(intype); - } else { - obj = EditorNode::get_editor_data().instance_custom_type(intype, "Resource"); - } - } - - ERR_FAIL_COND(!obj); - ERR_FAIL_COND(!Object::cast_to<Resource>(obj)); - - EditorNode::get_editor_data().instantiate_object_properties(obj); - v = obj; - - emit_signal(SNAME("variant_changed")); - hide(); - } -} - -void CustomPropertyEditor::_color_changed(const Color &p_color) { - v = p_color; - emit_signal(SNAME("variant_changed")); -} - -void CustomPropertyEditor::_node_path_selected(NodePath p_path) { - if (picking_viewport) { - Node *to_node = get_node(p_path); - if (!Object::cast_to<Viewport>(to_node)) { - EditorNode::get_singleton()->show_warning(TTR("Selected node is not a Viewport!")); - return; - } - - Ref<ViewportTexture> vt; - vt.instantiate(); - vt->set_viewport_path_in_scene(get_tree()->get_edited_scene_root()->get_path_to(to_node)); - vt->setup_local_to_scene(); - v = vt; - emit_signal(SNAME("variant_changed")); - return; - } - - if (hint == PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE && !hint_text.is_empty()) { - Node *node = get_node(hint_text); - if (node) { - Node *tonode = node->get_node(p_path); - if (tonode) { - p_path = node->get_path_to(tonode); - } - } - - } else if (owner) { - Node *node = nullptr; - - if (owner->is_class("Node")) { - node = Object::cast_to<Node>(owner); - } else if (owner->is_class("ArrayPropertyEdit")) { - node = Object::cast_to<ArrayPropertyEdit>(owner)->get_node(); - } else if (owner->is_class("DictionaryPropertyEdit")) { - node = Object::cast_to<DictionaryPropertyEdit>(owner)->get_node(); - } - if (!node) { - v = p_path; - emit_signal(SNAME("variant_changed")); - call_deferred(SNAME("hide")); //to not mess with dialogs - return; - } - - Node *tonode = node->get_node(p_path); - if (tonode) { - p_path = node->get_path_to(tonode); - } - } - - v = p_path; - emit_signal(SNAME("variant_changed")); - call_deferred(SNAME("hide")); //to not mess with dialogs -} - -void CustomPropertyEditor::_action_pressed(int p_which) { - if (updating) { - return; - } - - switch (type) { - case Variant::BOOL: { - v = checks20[0]->is_pressed(); - emit_signal(SNAME("variant_changed")); - } break; - case Variant::INT: { - if (hint == PROPERTY_HINT_LAYERS_2D_PHYSICS || - hint == PROPERTY_HINT_LAYERS_2D_RENDER || - hint == PROPERTY_HINT_LAYERS_2D_NAVIGATION || - hint == PROPERTY_HINT_LAYERS_3D_PHYSICS || - hint == PROPERTY_HINT_LAYERS_3D_RENDER || - hint == PROPERTY_HINT_LAYERS_3D_NAVIGATION) { - uint32_t f = v; - if (checks20[p_which]->is_pressed()) { - f |= (1 << p_which); - } else { - f &= ~(1 << p_which); - } - - v = f; - emit_signal(SNAME("variant_changed")); - } - - } break; - case Variant::STRING: { - if (hint == PROPERTY_HINT_MULTILINE_TEXT) { - hide(); - } else if (hint == PROPERTY_HINT_LOCALE_ID) { - locale->popup_locale_dialog(); - } else if (hint == PROPERTY_HINT_FILE || hint == PROPERTY_HINT_GLOBAL_FILE) { - if (p_which == 0) { - if (hint == PROPERTY_HINT_FILE) { - file->set_access(EditorFileDialog::ACCESS_RESOURCES); - } else { - file->set_access(EditorFileDialog::ACCESS_FILESYSTEM); - } - - file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE); - file->clear_filters(); - - file->clear_filters(); - - if (!hint_text.is_empty()) { - Vector<String> extensions = hint_text.split(","); - for (int i = 0; i < extensions.size(); i++) { - String filter = extensions[i]; - if (filter.begins_with(".")) { - filter = "*" + extensions[i]; - } else if (!filter.begins_with("*")) { - filter = "*." + extensions[i]; - } - - file->add_filter(filter, extensions[i].to_upper()); - } - } - file->popup_file_dialog(); - } else { - v = ""; - emit_signal(SNAME("variant_changed")); - hide(); - } - - } else if (hint == PROPERTY_HINT_DIR || hint == PROPERTY_HINT_GLOBAL_DIR) { - if (p_which == 0) { - if (hint == PROPERTY_HINT_DIR) { - file->set_access(EditorFileDialog::ACCESS_RESOURCES); - } else { - file->set_access(EditorFileDialog::ACCESS_FILESYSTEM); - } - file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_DIR); - file->clear_filters(); - file->popup_file_dialog(); - } else { - v = ""; - emit_signal(SNAME("variant_changed")); - hide(); - } - } - - } break; - case Variant::NODE_PATH: { - if (p_which == 0) { - picking_viewport = false; - scene_tree->set_title(TTR("Pick a Node")); - scene_tree->popup_scenetree_dialog(); - - } else if (p_which == 1) { - v = NodePath(); - emit_signal(SNAME("variant_changed")); - hide(); - } else if (p_which == 2) { - if (owner->is_class("Node") && (v.get_type() == Variant::NODE_PATH) && Object::cast_to<Node>(owner)->has_node(v)) { - Node *target_node = Object::cast_to<Node>(owner)->get_node(v); - EditorNode::get_singleton()->get_editor_selection()->clear(); - SceneTreeDock::get_singleton()->set_selected(target_node); - } - - hide(); - } - - } break; - case Variant::OBJECT: { - if (p_which == 0) { - ERR_FAIL_COND(inheritors_array.is_empty()); - - String intype = inheritors_array[0]; - - if (hint == PROPERTY_HINT_RESOURCE_TYPE) { - Variant obj = ClassDB::instantiate(intype); - - if (!obj) { - if (ScriptServer::is_global_class(intype)) { - obj = EditorNode::get_editor_data().script_class_instance(intype); - } else { - obj = EditorNode::get_editor_data().instance_custom_type(intype, "Resource"); - } - } - - ERR_BREAK(!obj); - ERR_BREAK(!Object::cast_to<Resource>(obj)); - - EditorNode::get_editor_data().instantiate_object_properties(obj); - v = obj; - - emit_signal(SNAME("variant_changed")); - hide(); - } - } else if (p_which == 1) { - file->set_access(EditorFileDialog::ACCESS_RESOURCES); - file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE); - List<String> extensions; - String type = (hint == PROPERTY_HINT_RESOURCE_TYPE) ? hint_text : String(); - - ResourceLoader::get_recognized_extensions_for_type(type, &extensions); - file->clear_filters(); - for (const String &E : extensions) { - file->add_filter("*." + E, E.to_upper()); - } - - file->popup_file_dialog(); - - } else if (p_which == 2) { - Ref<Resource> r = v; - - if (!r.is_null()) { - emit_signal(SNAME("resource_edit_request")); - hide(); - } - - } else if (p_which == 3) { - v = Variant(); - emit_signal(SNAME("variant_changed")); - hide(); - } else if (p_which == 4) { - Ref<Resource> res_orig = v; - if (res_orig.is_null()) { - return; - } - - List<PropertyInfo> property_list; - res_orig->get_property_list(&property_list); - List<Pair<String, Variant>> propvalues; - - for (const PropertyInfo &pi : property_list) { - Pair<String, Variant> p; - if (pi.usage & PROPERTY_USAGE_STORAGE) { - p.first = pi.name; - p.second = res_orig->get(pi.name); - } - - propvalues.push_back(p); - } - - Ref<Resource> res = Ref<Resource>(ClassDB::instantiate(res_orig->get_class())); - - ERR_FAIL_COND(res.is_null()); - - for (const Pair<String, Variant> &p : propvalues) { - res->set(p.first, p.second); - } - - v = res; - emit_signal(SNAME("variant_changed")); - hide(); - } - - } break; - - default: { - }; - } -} - -void CustomPropertyEditor::_drag_easing(const Ref<InputEvent> &p_ev) { - Ref<InputEventMouseMotion> mm = p_ev; - - if (mm.is_valid() && (mm->get_button_mask() & MouseButton::MASK_LEFT) != MouseButton::NONE) { - float rel = mm->get_relative().x; - if (rel == 0) { - return; - } - - bool flip = hint_text == "attenuation"; - - if (flip) { - rel = -rel; - } - - float val = v; - if (val == 0) { - return; - } - bool sg = val < 0; - val = Math::absf(val); - - val = Math::log(val) / Math::log((float)2.0); - //logspace - val += rel * 0.05; - - val = Math::pow(2.0f, val); - if (sg) { - val = -val; - } - - v = val; - easing_draw->update(); - emit_signal(SNAME("variant_changed")); - } -} - -void CustomPropertyEditor::_draw_easing() { - RID ci = easing_draw->get_canvas_item(); - - Size2 s = easing_draw->get_size(); - Rect2 r(Point2(), s); - r = r.grow(3); - easing_draw->get_theme_stylebox(SNAME("normal"), SNAME("LineEdit"))->draw(ci, r); - - int points = 48; - - float prev = 1.0; - float exp = v; - bool flip = hint_text == "attenuation"; - - Ref<Font> f = easing_draw->get_theme_font(SNAME("font"), SNAME("Label")); - int font_size = easing_draw->get_theme_font_size(SNAME("font_size"), SNAME("Label")); - Color color = easing_draw->get_theme_color(SNAME("font_color"), SNAME("Label")); - - for (int i = 1; i <= points; i++) { - float ifl = i / float(points); - float iflp = (i - 1) / float(points); - - float h = 1.0 - Math::ease(ifl, exp); - - if (flip) { - ifl = 1.0 - ifl; - iflp = 1.0 - iflp; - } - - RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2(iflp * s.width, prev * s.height), Point2(ifl * s.width, h * s.height), color); - prev = h; - } - - f->draw_string(ci, Point2(10, 10 + f->get_ascent(font_size)), String::num(exp, 2), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, color); -} - -void CustomPropertyEditor::_text_edit_changed() { - v = text_edit->get_text(); - emit_signal(SNAME("variant_changed")); -} - -void CustomPropertyEditor::_create_dialog_callback() { - v = create_dialog->get_selected_type(); - emit_signal(SNAME("variant_changed")); -} - -void CustomPropertyEditor::_create_selected_property(const String &p_prop) { - v = p_prop; - emit_signal(SNAME("variant_changed")); -} - -void CustomPropertyEditor::_modified(String p_string) { - if (updating) { - return; - } - - Variant prev_v = v; - - updating = true; - switch (type) { - case Variant::INT: { - String text = TS->parse_number(value_editor[0]->get_text()); - Ref<Expression> expr; - expr.instantiate(); - Error err = expr->parse(text); - if (err != OK) { - v = value_editor[0]->get_text().to_int(); - return; - } else { - v = expr->execute(Array(), nullptr, false, false); - } - - if (v != prev_v) { - emit_signal(SNAME("variant_changed")); - } - } break; - case Variant::FLOAT: { - if (hint != PROPERTY_HINT_EXP_EASING) { - String text = TS->parse_number(value_editor[0]->get_text()); - v = _parse_real_expression(text); - if (v != prev_v) { - emit_signal(SNAME("variant_changed")); - } - } - - } break; - case Variant::STRING: { - v = value_editor[0]->get_text(); - emit_signal(SNAME("variant_changed")); - } break; - case Variant::VECTOR2: { - Vector2 vec; - vec.x = _parse_real_expression(value_editor[0]->get_text()); - vec.y = _parse_real_expression(value_editor[1]->get_text()); - v = vec; - if (v != prev_v) { - _emit_changed_whole_or_field(); - } - - } break; - case Variant::RECT2: { - Rect2 r2; - - r2.position.x = _parse_real_expression(value_editor[0]->get_text()); - r2.position.y = _parse_real_expression(value_editor[1]->get_text()); - r2.size.x = _parse_real_expression(value_editor[2]->get_text()); - r2.size.y = _parse_real_expression(value_editor[3]->get_text()); - v = r2; - if (v != prev_v) { - _emit_changed_whole_or_field(); - } - - } break; - - case Variant::VECTOR3: { - Vector3 vec; - vec.x = _parse_real_expression(value_editor[0]->get_text()); - vec.y = _parse_real_expression(value_editor[1]->get_text()); - vec.z = _parse_real_expression(value_editor[2]->get_text()); - v = vec; - if (v != prev_v) { - _emit_changed_whole_or_field(); - } - - } break; - case Variant::PLANE: { - Plane pl; - pl.normal.x = _parse_real_expression(value_editor[0]->get_text()); - pl.normal.y = _parse_real_expression(value_editor[1]->get_text()); - pl.normal.z = _parse_real_expression(value_editor[2]->get_text()); - pl.d = _parse_real_expression(value_editor[3]->get_text()); - v = pl; - if (v != prev_v) { - _emit_changed_whole_or_field(); - } - - } break; - case Variant::QUATERNION: { - Quaternion q; - q.x = _parse_real_expression(value_editor[0]->get_text()); - q.y = _parse_real_expression(value_editor[1]->get_text()); - q.z = _parse_real_expression(value_editor[2]->get_text()); - q.w = _parse_real_expression(value_editor[3]->get_text()); - v = q; - if (v != prev_v) { - _emit_changed_whole_or_field(); - } - - } break; - case Variant::AABB: { - Vector3 pos; - Vector3 size; - - pos.x = _parse_real_expression(value_editor[0]->get_text()); - pos.y = _parse_real_expression(value_editor[1]->get_text()); - pos.z = _parse_real_expression(value_editor[2]->get_text()); - size.x = _parse_real_expression(value_editor[3]->get_text()); - size.y = _parse_real_expression(value_editor[4]->get_text()); - size.z = _parse_real_expression(value_editor[5]->get_text()); - v = AABB(pos, size); - if (v != prev_v) { - _emit_changed_whole_or_field(); - } - - } break; - case Variant::TRANSFORM2D: { - Transform2D m; - for (int i = 0; i < 6; i++) { - m.columns[i / 2][i % 2] = _parse_real_expression(value_editor[i]->get_text()); - } - - v = m; - if (v != prev_v) { - _emit_changed_whole_or_field(); - } - - } break; - case Variant::BASIS: { - Basis m; - for (int i = 0; i < 9; i++) { - m.rows[i / 3][i % 3] = _parse_real_expression(value_editor[i]->get_text()); - } - - v = m; - if (v != prev_v) { - _emit_changed_whole_or_field(); - } - - } break; - case Variant::TRANSFORM3D: { - Basis basis; - for (int i = 0; i < 9; i++) { - basis.rows[i / 3][i % 3] = _parse_real_expression(value_editor[(i / 3) * 4 + i % 3]->get_text()); - } - - Vector3 origin; - - origin.x = _parse_real_expression(value_editor[3]->get_text()); - origin.y = _parse_real_expression(value_editor[7]->get_text()); - origin.z = _parse_real_expression(value_editor[11]->get_text()); - - v = Transform3D(basis, origin); - if (v != prev_v) { - _emit_changed_whole_or_field(); - } - - } break; - case Variant::COLOR: { - } break; - - case Variant::NODE_PATH: { - v = NodePath(value_editor[0]->get_text()); - if (v != prev_v) { - emit_signal(SNAME("variant_changed")); - } - } break; - case Variant::DICTIONARY: { - } break; - case Variant::PACKED_BYTE_ARRAY: { - } break; - case Variant::PACKED_INT32_ARRAY: { - } break; - case Variant::PACKED_FLOAT32_ARRAY: { - } break; - case Variant::PACKED_STRING_ARRAY: { - } break; - case Variant::PACKED_VECTOR3_ARRAY: { - } break; - case Variant::PACKED_COLOR_ARRAY: { - } break; - default: { - } - } - - updating = false; -} - -real_t CustomPropertyEditor::_parse_real_expression(String text) { - Ref<Expression> expr; - expr.instantiate(); - Error err = expr->parse(text); - real_t out; - if (err != OK) { - out = value_editor[0]->get_text().to_float(); - } else { - out = expr->execute(Array(), nullptr, false, true); - } - return out; -} - -void CustomPropertyEditor::_emit_changed_whole_or_field() { - if (!Input::get_singleton()->is_key_pressed(Key::SHIFT)) { - emit_signal(SNAME("variant_changed")); - } else { - emit_signal(SNAME("variant_field_changed"), field_names[focused_value_editor]); - } -} - -void CustomPropertyEditor::_range_modified(double p_value) { - v = p_value; - emit_signal(SNAME("variant_changed")); -} - -void CustomPropertyEditor::_focus_enter() { - switch (type) { - case Variant::FLOAT: - case Variant::STRING: - case Variant::VECTOR2: - case Variant::RECT2: - case Variant::VECTOR3: - case Variant::PLANE: - case Variant::QUATERNION: - case Variant::AABB: - case Variant::TRANSFORM2D: - case Variant::BASIS: - case Variant::TRANSFORM3D: { - for (int i = 0; i < MAX_VALUE_EDITORS; ++i) { - if (value_editor[i]->has_focus()) { - focused_value_editor = i; - value_editor[i]->select_all(); - break; - } - } - } break; - default: { - } - } -} - -void CustomPropertyEditor::_focus_exit() { - _modified(String()); -} - -void CustomPropertyEditor::config_action_buttons(const List<String> &p_strings) { - Ref<StyleBox> sb = action_buttons[0]->get_theme_stylebox(SNAME("button")); - int margin_top = sb->get_margin(SIDE_TOP); - int margin_left = sb->get_margin(SIDE_LEFT); - int margin_bottom = sb->get_margin(SIDE_BOTTOM); - int margin_right = sb->get_margin(SIDE_RIGHT); - - int max_width = 0; - int height = 0; - - for (int i = 0; i < MAX_ACTION_BUTTONS; i++) { - if (i < p_strings.size()) { - action_buttons[i]->show(); - action_buttons[i]->set_text(p_strings[i]); - - Size2 btn_m_size = action_buttons[i]->get_minimum_size(); - if (btn_m_size.width > max_width) { - max_width = btn_m_size.width; - } - - } else { - action_buttons[i]->hide(); - } - } - - for (int i = 0; i < p_strings.size(); i++) { - Size2 btn_m_size = action_buttons[i]->get_size(); - action_buttons[i]->set_position(Point2(0, height) + Point2(margin_left, margin_top)); - action_buttons[i]->set_size(Size2(max_width, btn_m_size.height)); - - height += btn_m_size.height; - } - set_size(Size2(max_width, height) + Size2(margin_left + margin_right, margin_top + margin_bottom)); -} - -void CustomPropertyEditor::config_value_editors(int p_amount, int p_columns, int p_label_w, const List<String> &p_strings) { - int cell_width = 95; - int cell_height = 25; - int cell_margin = 5; - int rows = ((p_amount - 1) / p_columns) + 1; - - set_size(Size2(cell_margin + p_label_w + (cell_width + cell_margin + p_label_w) * p_columns, cell_margin + (cell_height + cell_margin) * rows) * EDSCALE); - - for (int i = 0; i < MAX_VALUE_EDITORS; i++) { - value_label[i]->get_parent()->remove_child(value_label[i]); - value_editor[i]->get_parent()->remove_child(value_editor[i]); - - int box_id = i / p_columns; - value_hboxes[box_id]->add_child(value_label[i]); - value_hboxes[box_id]->add_child(value_editor[i]); - - if (i < MAX_VALUE_EDITORS / 4) { - if (i <= p_amount / 4) { - value_hboxes[i]->show(); - } else { - value_hboxes[i]->hide(); - } - } - - if (i < p_amount) { - value_editor[i]->show(); - value_label[i]->show(); - value_label[i]->set_text(i < p_strings.size() ? p_strings[i] : String("")); - value_editor[i]->set_editable(!read_only); - } else { - value_editor[i]->hide(); - value_label[i]->hide(); - } - } -} - -void CustomPropertyEditor::_bind_methods() { - ADD_SIGNAL(MethodInfo("variant_changed")); - ADD_SIGNAL(MethodInfo("variant_field_changed", PropertyInfo(Variant::STRING, "field"))); - ADD_SIGNAL(MethodInfo("resource_edit_request")); -} - -CustomPropertyEditor::CustomPropertyEditor() { - value_vbox = memnew(VBoxContainer); - add_child(value_vbox); - - for (int i = 0; i < MAX_VALUE_EDITORS; i++) { - if (i < MAX_VALUE_EDITORS / 4) { - value_hboxes[i] = memnew(HBoxContainer); - value_vbox->add_child(value_hboxes[i]); - value_hboxes[i]->hide(); - } - int hbox_idx = i / 4; - value_label[i] = memnew(Label); - value_hboxes[hbox_idx]->add_child(value_label[i]); - value_label[i]->hide(); - value_editor[i] = memnew(LineEdit); - value_hboxes[hbox_idx]->add_child(value_editor[i]); - value_editor[i]->set_h_size_flags(Control::SIZE_EXPAND_FILL); - value_editor[i]->hide(); - value_editor[i]->connect("text_submitted", callable_mp(this, &CustomPropertyEditor::_modified)); - value_editor[i]->connect("focus_entered", callable_mp(this, &CustomPropertyEditor::_focus_enter)); - value_editor[i]->connect("focus_exited", callable_mp(this, &CustomPropertyEditor::_focus_exit)); - } - focused_value_editor = -1; - - for (int i = 0; i < 4; i++) { - scroll[i] = memnew(HScrollBar); - scroll[i]->hide(); - scroll[i]->set_min(0); - scroll[i]->set_max(1.0); - scroll[i]->set_step(0.01); - add_child(scroll[i]); - } - - checks20gc = memnew(GridContainer); - add_child(checks20gc); - checks20gc->set_columns(11); - - for (int i = 0; i < 20; i++) { - if (i == 5 || i == 15) { - Control *space = memnew(Control); - space->set_custom_minimum_size(Size2(20, 0) * EDSCALE); - checks20gc->add_child(space); - } - - checks20[i] = memnew(CheckBox); - checks20[i]->set_toggle_mode(true); - checks20[i]->set_focus_mode(Control::FOCUS_NONE); - checks20gc->add_child(checks20[i]); - checks20[i]->hide(); - checks20[i]->connect("pressed", callable_mp(this, &CustomPropertyEditor::_action_pressed).bind(i)); - checks20[i]->set_tooltip(vformat(TTR("Bit %d, val %d."), i, 1 << i)); - } - - text_edit = memnew(TextEdit); - value_vbox->add_child(text_edit); - text_edit->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT, Control::PRESET_MODE_MINSIZE, 5); - text_edit->set_v_size_flags(Control::SIZE_EXPAND_FILL); - text_edit->set_offset(SIDE_BOTTOM, -30); - - text_edit->hide(); - text_edit->connect("text_changed", callable_mp(this, &CustomPropertyEditor::_text_edit_changed)); - - color_picker = nullptr; - - file = memnew(EditorFileDialog); - value_vbox->add_child(file); - file->hide(); - - file->connect("file_selected", callable_mp(this, &CustomPropertyEditor::_file_selected)); - file->connect("dir_selected", callable_mp(this, &CustomPropertyEditor::_file_selected)); - - locale = memnew(EditorLocaleDialog); - value_vbox->add_child(locale); - locale->hide(); - - locale->connect("locale_selected", callable_mp(this, &CustomPropertyEditor::_locale_selected)); - - error = memnew(ConfirmationDialog); - error->set_title(TTR("Error!")); - value_vbox->add_child(error); - - scene_tree = memnew(SceneTreeDialog); - value_vbox->add_child(scene_tree); - scene_tree->connect("selected", callable_mp(this, &CustomPropertyEditor::_node_path_selected)); - scene_tree->get_scene_tree()->set_show_enabled_subscene(true); - - texture_preview = memnew(TextureRect); - value_vbox->add_child(texture_preview); - texture_preview->hide(); - - easing_draw = memnew(Control); - value_vbox->add_child(easing_draw); - easing_draw->hide(); - easing_draw->connect("draw", callable_mp(this, &CustomPropertyEditor::_draw_easing)); - easing_draw->connect("gui_input", callable_mp(this, &CustomPropertyEditor::_drag_easing)); - easing_draw->set_default_cursor_shape(Control::CURSOR_MOVE); - - type_button = memnew(MenuButton); - value_vbox->add_child(type_button); - type_button->hide(); - type_button->get_popup()->connect("id_pressed", callable_mp(this, &CustomPropertyEditor::_type_create_selected)); - - menu = memnew(PopupMenu); - // menu->set_pass_on_modal_close_click(false); - value_vbox->add_child(menu); - menu->connect("id_pressed", callable_mp(this, &CustomPropertyEditor::_menu_option)); - - evaluator = nullptr; - - spinbox = memnew(SpinBox); - value_vbox->add_child(spinbox); - spinbox->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT, Control::PRESET_MODE_MINSIZE, 5); - spinbox->connect("value_changed", callable_mp(this, &CustomPropertyEditor::_range_modified)); - - slider = memnew(HSlider); - value_vbox->add_child(slider); - slider->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT, Control::PRESET_MODE_MINSIZE, 5); - slider->connect("value_changed", callable_mp(this, &CustomPropertyEditor::_range_modified)); - - action_hboxes = memnew(HBoxContainer); - action_hboxes->set_alignment(BoxContainer::ALIGNMENT_CENTER); - value_vbox->add_child(action_hboxes); - for (int i = 0; i < MAX_ACTION_BUTTONS; i++) { - action_buttons[i] = memnew(Button); - action_buttons[i]->hide(); - action_hboxes->add_child(action_buttons[i]); - action_buttons[i]->connect("pressed", callable_mp(this, &CustomPropertyEditor::_action_pressed).bind(i)); - } - - create_dialog = nullptr; - property_select = nullptr; -} diff --git a/editor/property_editor.h b/editor/property_editor.h deleted file mode 100644 index 27d1cabc3d..0000000000 --- a/editor/property_editor.h +++ /dev/null @@ -1,184 +0,0 @@ -/*************************************************************************/ -/* property_editor.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef PROPERTY_EDITOR_H -#define PROPERTY_EDITOR_H - -#include "editor/editor_locale_dialog.h" -#include "editor/scene_tree_editor.h" -#include "scene/gui/button.h" -#include "scene/gui/check_box.h" -#include "scene/gui/check_button.h" -#include "scene/gui/color_picker.h" -#include "scene/gui/dialogs.h" -#include "scene/gui/grid_container.h" -#include "scene/gui/label.h" -#include "scene/gui/menu_button.h" -#include "scene/gui/split_container.h" -#include "scene/gui/text_edit.h" -#include "scene/gui/texture_rect.h" -#include "scene/gui/tree.h" - -class CreateDialog; -class EditorFileDialog; -class PropertyValueEvaluator; -class PropertySelector; - -class EditorResourceConversionPlugin : public RefCounted { - GDCLASS(EditorResourceConversionPlugin, RefCounted); - -protected: - static void _bind_methods(); - - GDVIRTUAL0RC(String, _converts_to) - GDVIRTUAL1RC(bool, _handles, Ref<Resource>) - GDVIRTUAL1RC(Ref<Resource>, _convert, Ref<Resource>) - -public: - virtual String converts_to() const; - virtual bool handles(const Ref<Resource> &p_resource) const; - virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const; -}; - -class CustomPropertyEditor : public PopupPanel { - GDCLASS(CustomPropertyEditor, PopupPanel); - - enum { - MAX_VALUE_EDITORS = 12, - MAX_ACTION_BUTTONS = 5, - OBJ_MENU_LOAD = 0, - OBJ_MENU_EDIT = 1, - OBJ_MENU_CLEAR = 2, - OBJ_MENU_MAKE_UNIQUE = 3, - OBJ_MENU_COPY = 4, - OBJ_MENU_PASTE = 5, - OBJ_MENU_NEW_SCRIPT = 6, - OBJ_MENU_EXTEND_SCRIPT = 7, - OBJ_MENU_SHOW_IN_FILE_SYSTEM = 8, - TYPE_BASE_ID = 100, - CONVERT_BASE_ID = 1000 - }; - - enum { - EASING_LINEAR, - EASING_EASE_IN, - EASING_EASE_OUT, - EASING_ZERO, - EASING_IN_OUT, - EASING_OUT_IN - }; - - PopupMenu *menu = nullptr; - SceneTreeDialog *scene_tree = nullptr; - EditorFileDialog *file = nullptr; - EditorLocaleDialog *locale = nullptr; - ConfirmationDialog *error = nullptr; - String name; - Variant::Type type; - Variant v; - List<String> field_names; - int hint = 0; - String hint_text; - HBoxContainer *value_hboxes[MAX_VALUE_EDITORS / 4]; - VBoxContainer *value_vbox = nullptr; - LineEdit *value_editor[MAX_VALUE_EDITORS]; - int focused_value_editor; - Label *value_label[MAX_VALUE_EDITORS]; - HScrollBar *scroll[4]; - HBoxContainer *action_hboxes = nullptr; - Button *action_buttons[MAX_ACTION_BUTTONS]; - MenuButton *type_button = nullptr; - Vector<String> inheritors_array; - TextureRect *texture_preview = nullptr; - ColorPicker *color_picker = nullptr; - TextEdit *text_edit = nullptr; - bool read_only = false; - bool picking_viewport = false; - GridContainer *checks20gc = nullptr; - CheckBox *checks20[20]; - SpinBox *spinbox = nullptr; - HSlider *slider = nullptr; - - Control *easing_draw = nullptr; - CreateDialog *create_dialog = nullptr; - PropertySelector *property_select = nullptr; - - Object *owner = nullptr; - - bool updating = false; - - PropertyValueEvaluator *evaluator = nullptr; - - void _text_edit_changed(); - void _file_selected(String p_file); - void _locale_selected(String p_locale); - void _modified(String p_string); - - real_t _parse_real_expression(String text); - - void _range_modified(double p_value); - void _focus_enter(); - void _focus_exit(); - void _action_pressed(int p_which); - void _type_create_selected(int p_idx); - void _create_dialog_callback(); - void _create_selected_property(const String &p_prop); - - void _color_changed(const Color &p_color); - void _draw_easing(); - void _menu_option(int p_which); - - void _drag_easing(const Ref<InputEvent> &p_ev); - - void _node_path_selected(NodePath p_path); - void show_value_editors(int p_amount); - void config_value_editors(int p_amount, int p_columns, int p_label_w, const List<String> &p_strings); - void config_action_buttons(const List<String> &p_strings); - - void _emit_changed_whole_or_field(); - -protected: - void _notification(int p_what); - static void _bind_methods(); - -public: - void hide_menu(); - - Variant get_variant() const; - String get_name() const; - - void set_read_only(bool p_read_only) { read_only = p_read_only; } - - bool edit(Object *p_owner, const String &p_name, Variant::Type p_type, const Variant &p_variant, int p_hint, String p_hint_text); - - CustomPropertyEditor(); -}; - -#endif // PROPERTY_EDITOR_H diff --git a/editor/property_selector.cpp b/editor/property_selector.cpp index 841c3ff3b1..1b17a740dd 100644 --- a/editor/property_selector.cpp +++ b/editor/property_selector.cpp @@ -32,8 +32,12 @@ #include "core/os/keyboard.h" #include "editor/doc_tools.h" +#include "editor/editor_help.h" #include "editor/editor_node.h" #include "editor/editor_scale.h" +#include "scene/gui/line_edit.h" +#include "scene/gui/rich_text_label.h" +#include "scene/gui/tree.h" void PropertySelector::_text_changed(const String &p_newtext) { _update_search(); diff --git a/editor/property_selector.h b/editor/property_selector.h index e2bf5c02b7..9f1af576dd 100644 --- a/editor/property_selector.h +++ b/editor/property_selector.h @@ -31,9 +31,11 @@ #ifndef PROPERTY_SELECTOR_H #define PROPERTY_SELECTOR_H -#include "editor/editor_help.h" -#include "editor/property_editor.h" -#include "scene/gui/rich_text_label.h" +#include "scene/gui/dialogs.h" + +class EditorHelpBit; +class LineEdit; +class Tree; class PropertySelector : public ConfirmationDialog { GDCLASS(PropertySelector, ConfirmationDialog); diff --git a/editor/rename_dialog.cpp b/editor/rename_dialog.cpp index 3222fb6eec..665aca6a37 100644 --- a/editor/rename_dialog.cpp +++ b/editor/rename_dialog.cpp @@ -42,6 +42,7 @@ #include "plugins/script_editor_plugin.h" #include "scene/gui/control.h" #include "scene/gui/label.h" +#include "scene/gui/separator.h" #include "scene/gui/tab_container.h" RenameDialog::RenameDialog(SceneTreeEditor *p_scene_tree_editor, UndoRedo *p_undo_redo) { |