5757#include " scene/resources/mesh.h"
5858#include " scene/resources/visual_shader_nodes.h"
5959
60- // /////////////////// Nil /////////////////////////
60+ // /////////////////// NIL /////////////////////////
6161
6262void EditorPropertyNil::update_property () {
6363}
@@ -68,6 +68,91 @@ EditorPropertyNil::EditorPropertyNil() {
6868 add_child (prop_label);
6969}
7070
71+ // ////////////////// VARIANT ///////////////////////
72+
73+ void EditorPropertyVariant::_change_type (int p_to_type) {
74+ new_type = Variant::Type (p_to_type);
75+
76+ Variant zero;
77+ Callable::CallError ce;
78+ Variant::construct (new_type, zero, nullptr , 0 , ce);
79+ emit_changed (get_edited_property (), zero);
80+ }
81+
82+ void EditorPropertyVariant::_set_read_only (bool p_read_only) {
83+ change_type->set_disabled (p_read_only);
84+ if (sub_property) {
85+ sub_property->set_read_only (p_read_only);
86+ }
87+ }
88+
89+ void EditorPropertyVariant::_notification (int p_what) {
90+ if (p_what == NOTIFICATION_THEME_CHANGED) {
91+ change_type->set_button_icon (get_editor_theme_icon (" Edit" ));
92+
93+ PopupMenu *popup = change_type->get_popup ();
94+ for (int i = 0 ; i < popup->get_item_count (); i++) {
95+ popup->set_item_icon (i, get_editor_theme_icon (Variant::get_type_name (Variant::Type (popup->get_item_id (i)))));
96+ }
97+ }
98+ }
99+
100+ void EditorPropertyVariant::update_property () {
101+ const Variant &value = get_edited_property_value ();
102+ if (new_type == Variant::VARIANT_MAX) {
103+ new_type = value.get_type ();
104+ }
105+
106+ if (new_type != current_type) {
107+ current_type = new_type;
108+
109+ if (sub_property) {
110+ memdelete (sub_property);
111+ sub_property = nullptr ;
112+ }
113+
114+ if (current_type == Variant::OBJECT) {
115+ sub_property = EditorInspector::instantiate_property_editor (nullptr , current_type, " " , PROPERTY_HINT_RESOURCE_TYPE, " Resource" , PROPERTY_USAGE_NONE);
116+ } else {
117+ sub_property = EditorInspector::instantiate_property_editor (nullptr , current_type, " " , PROPERTY_HINT_NONE, " " , PROPERTY_USAGE_NONE);
118+ }
119+ ERR_FAIL_NULL (sub_property);
120+
121+ sub_property->set_object_and_property (get_edited_object (), get_edited_property ());
122+ sub_property->set_name_split_ratio (0 );
123+ sub_property->set_selectable (false );
124+ sub_property->set_use_folding (is_using_folding ());
125+ sub_property->set_read_only (is_read_only ());
126+ sub_property->set_h_size_flags (SIZE_EXPAND_FILL);
127+ sub_property->connect (SNAME (" property_changed" ), callable_mp ((EditorProperty *)this , &EditorProperty::emit_changed));
128+ content->add_child (sub_property);
129+ content->move_child (sub_property, 0 );
130+ sub_property->update_property ();
131+ } else if (sub_property) {
132+ sub_property->update_property ();
133+ }
134+ new_type = Variant::VARIANT_MAX;
135+ }
136+
137+ EditorPropertyVariant::EditorPropertyVariant () {
138+ content = memnew (HBoxContainer);
139+ add_child (content);
140+
141+ change_type = memnew (MenuButton);
142+ change_type->set_flat (false );
143+
144+ PopupMenu *popup = change_type->get_popup ();
145+ for (int i = 0 ; i < Variant::VARIANT_MAX; i++) {
146+ if (i == Variant::CALLABLE || i == Variant::SIGNAL || i == Variant::RID) {
147+ // These types can't be constructed or serialized properly, so skip them.
148+ continue ;
149+ }
150+ popup->add_item (Variant::get_type_name (Variant::Type (i)), i);
151+ }
152+ popup->connect (SceneStringName (id_pressed), callable_mp (this , &EditorPropertyVariant::_change_type));
153+ content->add_child (change_type);
154+ }
155+
71156// /////////////////// TEXT /////////////////////////
72157
73158void EditorPropertyText::_set_read_only (bool p_read_only) {
@@ -3510,8 +3595,11 @@ EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_
35103595 switch (p_type) {
35113596 // atomic types
35123597 case Variant::NIL: {
3513- EditorPropertyNil *editor = memnew (EditorPropertyNil);
3514- return editor;
3598+ if (p_usage & PROPERTY_USAGE_NIL_IS_VARIANT) {
3599+ return memnew (EditorPropertyVariant);
3600+ } else {
3601+ return memnew (EditorPropertyNil);
3602+ }
35153603 } break ;
35163604 case Variant::BOOL: {
35173605 EditorPropertyCheck *editor = memnew (EditorPropertyCheck);
0 commit comments