|
40 | 40 | #include "editor/editor_scale.h"
|
41 | 41 | #include "editor/editor_settings.h"
|
42 | 42 | #include "multi_node_edit.h"
|
| 43 | +#include "scene/gui/center_container.h" |
43 | 44 | #include "scene/property_utils.h"
|
44 | 45 | #include "scene/resources/packed_scene.h"
|
45 | 46 |
|
@@ -2506,7 +2507,7 @@ void EditorInspector::update_tree() {
|
2506 | 2507 | List<PropertyInfo>::Element *N = E_property->next();
|
2507 | 2508 | bool valid = true;
|
2508 | 2509 | while (N) {
|
2509 |
| - if (N->get().usage & PROPERTY_USAGE_EDITOR && (!restrict_to_basic || (N->get().usage & PROPERTY_USAGE_EDITOR_BASIC_SETTING))) { |
| 2510 | + if (!N->get().name.begins_with("metadata/_") && N->get().usage & PROPERTY_USAGE_EDITOR && (!restrict_to_basic || (N->get().usage & PROPERTY_USAGE_EDITOR_BASIC_SETTING))) { |
2510 | 2511 | break;
|
2511 | 2512 | }
|
2512 | 2513 | if (N->get().usage & PROPERTY_USAGE_CATEGORY) {
|
@@ -2580,7 +2581,7 @@ void EditorInspector::update_tree() {
|
2580 | 2581 |
|
2581 | 2582 | continue;
|
2582 | 2583 |
|
2583 |
| - } else if (!(p.usage & PROPERTY_USAGE_EDITOR) || _is_property_disabled_by_feature_profile(p.name) || (restrict_to_basic && !(p.usage & PROPERTY_USAGE_EDITOR_BASIC_SETTING))) { |
| 2584 | + } else if (p.name.begins_with("metadata/_") || !(p.usage & PROPERTY_USAGE_EDITOR) || _is_property_disabled_by_feature_profile(p.name) || (restrict_to_basic && !(p.usage & PROPERTY_USAGE_EDITOR_BASIC_SETTING))) { |
2584 | 2585 | // Ignore properties that are not supposed to be in the inspector.
|
2585 | 2586 | continue;
|
2586 | 2587 | }
|
@@ -2915,7 +2916,7 @@ void EditorInspector::update_tree() {
|
2915 | 2916 | ep->set_checked(checked);
|
2916 | 2917 | ep->set_keying(keying);
|
2917 | 2918 | ep->set_read_only(property_read_only);
|
2918 |
| - ep->set_deletable(deletable_properties); |
| 2919 | + ep->set_deletable(deletable_properties || p.name.begins_with("metadata/")); |
2919 | 2920 | }
|
2920 | 2921 |
|
2921 | 2922 | current_vbox->add_child(F.property_editor);
|
@@ -2956,6 +2957,15 @@ void EditorInspector::update_tree() {
|
2956 | 2957 | }
|
2957 | 2958 | }
|
2958 | 2959 |
|
| 2960 | + if (!hide_metadata) { |
| 2961 | + Button *add_md = memnew(Button); |
| 2962 | + add_md->set_text(TTR("Add Metadata")); |
| 2963 | + add_md->set_focus_mode(Control::FOCUS_NONE); |
| 2964 | + add_md->set_icon(get_theme_icon("Add", "EditorIcons")); |
| 2965 | + add_md->connect("pressed", callable_mp(this, &EditorInspector::_show_add_meta_dialog)); |
| 2966 | + main_vbox->add_child(add_md); |
| 2967 | + } |
| 2968 | + |
2959 | 2969 | // Get the lists of to add at the end.
|
2960 | 2970 | for (Ref<EditorInspectorPlugin> &ped : valid_plugins) {
|
2961 | 2971 | ped->parse_end(object);
|
@@ -3055,6 +3065,11 @@ void EditorInspector::set_hide_script(bool p_hide) {
|
3055 | 3065 | update_tree();
|
3056 | 3066 | }
|
3057 | 3067 |
|
| 3068 | +void EditorInspector::set_hide_metadata(bool p_hide) { |
| 3069 | + hide_metadata = p_hide; |
| 3070 | + update_tree(); |
| 3071 | +} |
| 3072 | + |
3058 | 3073 | void EditorInspector::set_use_filter(bool p_use) {
|
3059 | 3074 | use_filter = p_use;
|
3060 | 3075 | update_tree();
|
@@ -3323,6 +3338,14 @@ void EditorInspector::_property_deleted(const String &p_path) {
|
3323 | 3338 | return;
|
3324 | 3339 | }
|
3325 | 3340 |
|
| 3341 | + if (p_path.begins_with("metadata/")) { |
| 3342 | + String name = p_path.replace_first("metadata/", ""); |
| 3343 | + undo_redo->create_action(vformat(TTR("Remove metadata %s"), name)); |
| 3344 | + undo_redo->add_do_method(object, "remove_meta", name); |
| 3345 | + undo_redo->add_undo_method(object, "set_meta", name, object->get_meta(name)); |
| 3346 | + undo_redo->commit_action(); |
| 3347 | + } |
| 3348 | + |
3326 | 3349 | emit_signal(SNAME("property_deleted"), p_path);
|
3327 | 3350 | }
|
3328 | 3351 |
|
@@ -3650,6 +3673,81 @@ Variant EditorInspector::get_property_clipboard() const {
|
3650 | 3673 | return property_clipboard;
|
3651 | 3674 | }
|
3652 | 3675 |
|
| 3676 | +void EditorInspector::_add_meta_confirm() { |
| 3677 | + String name = add_meta_name->get_text(); |
| 3678 | + |
| 3679 | + object->editor_set_section_unfold("metadata", true); // Ensure metadata is unfolded when adding a new metadata. |
| 3680 | + |
| 3681 | + Variant defval; |
| 3682 | + Callable::CallError ce; |
| 3683 | + Variant::construct(Variant::Type(add_meta_type->get_selected_id()), defval, nullptr, 0, ce); |
| 3684 | + undo_redo->create_action(vformat(TTR("Add metadata %s"), name)); |
| 3685 | + undo_redo->add_do_method(object, "set_meta", name, defval); |
| 3686 | + undo_redo->add_undo_method(object, "remove_meta", name); |
| 3687 | + undo_redo->commit_action(); |
| 3688 | +} |
| 3689 | + |
| 3690 | +void EditorInspector::_check_meta_name(String name) { |
| 3691 | + String error; |
| 3692 | + |
| 3693 | + if (name == "") { |
| 3694 | + error = TTR("Metadata can't be empty."); |
| 3695 | + } else if (!name.is_valid_identifier()) { |
| 3696 | + error = TTR("Invalid metadata identifier."); |
| 3697 | + } else if (object->has_meta(name)) { |
| 3698 | + error = TTR("Metadata already exists."); |
| 3699 | + } |
| 3700 | + |
| 3701 | + if (error != "") { |
| 3702 | + add_meta_error->add_theme_color_override("font_color", get_theme_color(SNAME("error_color"), SNAME("Editor"))); |
| 3703 | + add_meta_error->set_text(error); |
| 3704 | + add_meta_dialog->get_ok_button()->set_disabled(true); |
| 3705 | + } else { |
| 3706 | + add_meta_error->add_theme_color_override("font_color", get_theme_color(SNAME("success_color"), SNAME("Editor"))); |
| 3707 | + add_meta_error->set_text(TTR("Metadata name is valid.")); |
| 3708 | + add_meta_dialog->get_ok_button()->set_disabled(false); |
| 3709 | + } |
| 3710 | +} |
| 3711 | + |
| 3712 | +void EditorInspector::_show_add_meta_dialog() { |
| 3713 | + if (!add_meta_dialog) { |
| 3714 | + add_meta_dialog = memnew(ConfirmationDialog); |
| 3715 | + add_meta_dialog->set_title(TTR("Add Metadata Property")); |
| 3716 | + VBoxContainer *vbc = memnew(VBoxContainer); |
| 3717 | + add_meta_dialog->add_child(vbc); |
| 3718 | + HBoxContainer *hbc = memnew(HBoxContainer); |
| 3719 | + vbc->add_child(hbc); |
| 3720 | + hbc->add_child(memnew(Label(TTR("Name:")))); |
| 3721 | + add_meta_name = memnew(LineEdit); |
| 3722 | + add_meta_name->set_custom_minimum_size(Size2(200 * EDSCALE, 1)); |
| 3723 | + hbc->add_child(add_meta_name); |
| 3724 | + hbc->add_child(memnew(Label(TTR("Type:")))); |
| 3725 | + add_meta_type = memnew(OptionButton); |
| 3726 | + for (int i = 0; i < Variant::VARIANT_MAX; i++) { |
| 3727 | + if (i == Variant::NIL || i == Variant::RID || i == Variant::CALLABLE || i == Variant::SIGNAL) { |
| 3728 | + continue; //not editable by inspector. |
| 3729 | + } |
| 3730 | + String type = i == Variant::OBJECT ? String("Resource") : Variant::get_type_name(Variant::Type(i)); |
| 3731 | + |
| 3732 | + add_meta_type->add_icon_item(get_theme_icon(type, "EditorIcons"), type, i); |
| 3733 | + } |
| 3734 | + hbc->add_child(add_meta_type); |
| 3735 | + add_meta_dialog->get_ok_button()->set_text(TTR("Add")); |
| 3736 | + add_child(add_meta_dialog); |
| 3737 | + add_meta_dialog->register_text_enter(add_meta_name); |
| 3738 | + add_meta_dialog->connect("confirmed", callable_mp(this, &EditorInspector::_add_meta_confirm)); |
| 3739 | + add_meta_error = memnew(Label); |
| 3740 | + vbc->add_child(add_meta_error); |
| 3741 | + |
| 3742 | + add_meta_name->connect("text_changed", callable_mp(this, &EditorInspector::_check_meta_name)); |
| 3743 | + } |
| 3744 | + |
| 3745 | + add_meta_dialog->popup_centered(); |
| 3746 | + add_meta_name->set_text(""); |
| 3747 | + _check_meta_name(""); |
| 3748 | + add_meta_name->grab_focus(); |
| 3749 | +} |
| 3750 | + |
3653 | 3751 | void EditorInspector::_bind_methods() {
|
3654 | 3752 | ClassDB::bind_method("_edit_request_change", &EditorInspector::_edit_request_change);
|
3655 | 3753 |
|
|
0 commit comments