@@ -347,10 +347,15 @@ void EditorPropertyArray::_create_new_property_slot() {
347
347
slots.push_back (slot);
348
348
}
349
349
350
+ void EditorPropertyArray::set_preview_value (bool p_preview_value) {
351
+ preview_value = p_preview_value;
352
+ }
353
+
350
354
void EditorPropertyArray::update_property () {
351
355
Variant array = get_edited_property_value ();
352
356
353
357
String array_type_name = Variant::get_type_name (array_type);
358
+ String array_sub_type_name;
354
359
if (array_type == Variant::ARRAY && subtype != Variant::NIL) {
355
360
String type_name;
356
361
if (subtype == Variant::OBJECT && (subtype_hint == PROPERTY_HINT_RESOURCE_TYPE || subtype_hint == PROPERTY_HINT_NODE_TYPE)) {
@@ -359,11 +364,23 @@ void EditorPropertyArray::update_property() {
359
364
type_name = Variant::get_type_name (subtype);
360
365
}
361
366
362
- array_type_name = vformat (" %s[%s]" , array_type_name, type_name);
367
+ if (preview_value) {
368
+ array_sub_type_name = vformat (" [%s] " , type_name);
369
+ } else {
370
+ array_type_name = vformat (" %s[%s]" , array_type_name, type_name);
371
+ }
363
372
}
364
373
365
374
if (!array.is_array ()) {
366
- edit->set_text (vformat (TTR (" (Nil) %s" ), array_type_name));
375
+ if (preview_value) {
376
+ edit->set_text_alignment (HORIZONTAL_ALIGNMENT_LEFT);
377
+ edit->set_button_icon (get_editor_theme_icon (SNAME (" Nil" )));
378
+ edit->set_text (array_type_name);
379
+ } else {
380
+ edit->set_text_alignment (HORIZONTAL_ALIGNMENT_CENTER);
381
+ edit->set_button_icon (Ref<Texture2D>());
382
+ edit->set_text (vformat (TTR (" (Nil) %s" ), array_type_name));
383
+ }
367
384
edit->set_pressed (false );
368
385
if (container) {
369
386
set_bottom_editor (nullptr );
@@ -383,7 +400,25 @@ void EditorPropertyArray::update_property() {
383
400
_page_changed (max_page);
384
401
}
385
402
386
- edit->set_text (vformat (TTR (" %s (size %s)" ), array_type_name, itos (size)));
403
+ if (preview_value) {
404
+ String ctr_str = array.get_construct_string ().trim_prefix (array_type_name + " (" ).trim_suffix (" )" ).replace (" \n " , " " );
405
+ if (array_type == Variant::ARRAY && subtype != Variant::NIL) {
406
+ int type_end = ctr_str.find (" ](" );
407
+ if (type_end > 0 ) {
408
+ ctr_str = ctr_str.substr (type_end + 2 );
409
+ }
410
+ }
411
+
412
+ edit->set_text_overrun_behavior (TextServer::OVERRUN_TRIM_ELLIPSIS);
413
+ edit->set_text_alignment (HORIZONTAL_ALIGNMENT_LEFT);
414
+ edit->set_button_icon (get_editor_theme_icon (array_type_name));
415
+ edit->set_text (vformat (" %s%s" , array_sub_type_name, ctr_str));
416
+ edit->set_tooltip_text (vformat (TTR (" %s%s (size %d)" ), array_type_name, array_sub_type_name, size));
417
+ } else {
418
+ edit->set_text_alignment (HORIZONTAL_ALIGNMENT_CENTER);
419
+ edit->set_button_icon (Ref<Texture2D>());
420
+ edit->set_text (vformat (TTR (" %s (size %s)" ), array_type_name, itos (size)));
421
+ }
387
422
388
423
bool unfolded = get_edited_object ()->editor_is_section_unfolded (get_edited_property ());
389
424
if (edit->is_pressed () != unfolded) {
@@ -961,20 +996,7 @@ void EditorPropertyDictionary::_create_new_property_slot(int p_idx) {
961
996
962
997
EditorProperty *prop_key = nullptr ;
963
998
if (p_idx != EditorPropertyDictionaryObject::NEW_KEY_INDEX && p_idx != EditorPropertyDictionaryObject::NEW_VALUE_INDEX) {
964
- if (key_subtype == Variant::OBJECT) {
965
- EditorPropertyObjectID *editor = memnew (EditorPropertyObjectID);
966
- editor->setup (" Object" );
967
- prop_key = editor;
968
- } else {
969
- prop_key = EditorInspector::instantiate_property_editor (this , key_subtype, " " , key_subtype_hint, key_subtype_hint_string, PROPERTY_USAGE_NONE);
970
- }
971
- prop_key->set_read_only (true );
972
- prop_key->set_selectable (false );
973
- prop_key->set_focus_mode (Control::FOCUS_NONE);
974
- prop_key->set_draw_background (false );
975
- prop_key->set_use_folding (is_using_folding ());
976
- prop_key->set_h_size_flags (SIZE_EXPAND_FILL);
977
- prop_key->set_draw_label (false );
999
+ prop_key = memnew (EditorPropertyNil);
978
1000
hbox->add_child (prop_key);
979
1001
}
980
1002
@@ -1096,10 +1118,15 @@ void EditorPropertyDictionary::setup(PropertyHint p_hint, const String &p_hint_s
1096
1118
}
1097
1119
}
1098
1120
1121
+ void EditorPropertyDictionary::set_preview_value (bool p_preview_value) {
1122
+ preview_value = p_preview_value;
1123
+ }
1124
+
1099
1125
void EditorPropertyDictionary::update_property () {
1100
1126
Variant updated_val = get_edited_property_value ();
1101
1127
1102
1128
String dict_type_name = " Dictionary" ;
1129
+ String dict_sub_type_name;
1103
1130
if (key_subtype != Variant::NIL || value_subtype != Variant::NIL) {
1104
1131
String key_subtype_name = " Variant" ;
1105
1132
if (key_subtype == Variant::OBJECT && (key_subtype_hint == PROPERTY_HINT_RESOURCE_TYPE || key_subtype_hint == PROPERTY_HINT_NODE_TYPE)) {
@@ -1113,11 +1140,23 @@ void EditorPropertyDictionary::update_property() {
1113
1140
} else if (value_subtype != Variant::NIL) {
1114
1141
value_subtype_name = Variant::get_type_name (value_subtype);
1115
1142
}
1116
- dict_type_name += vformat (" [%s, %s]" , key_subtype_name, value_subtype_name);
1143
+ if (preview_value) {
1144
+ dict_sub_type_name = vformat (" [%s, %s] " , key_subtype_name, value_subtype_name);
1145
+ } else {
1146
+ dict_type_name += vformat (" [%s, %s]" , key_subtype_name, value_subtype_name);
1147
+ }
1117
1148
}
1118
1149
1119
1150
if (updated_val.get_type () != Variant::DICTIONARY) {
1120
- edit->set_text (vformat (TTR (" (Nil) %s" ), dict_type_name)); // This provides symmetry with the array property.
1151
+ if (preview_value) {
1152
+ edit->set_text_alignment (HORIZONTAL_ALIGNMENT_LEFT);
1153
+ edit->set_button_icon (get_editor_theme_icon (SNAME (" Nil" )));
1154
+ edit->set_text (dict_type_name);
1155
+ } else {
1156
+ edit->set_text_alignment (HORIZONTAL_ALIGNMENT_CENTER);
1157
+ edit->set_button_icon (Ref<Texture2D>());
1158
+ edit->set_text (vformat (TTR (" (Nil) %s" ), dict_type_name));
1159
+ }
1121
1160
edit->set_pressed (false );
1122
1161
if (container) {
1123
1162
set_bottom_editor (nullptr );
@@ -1133,7 +1172,25 @@ void EditorPropertyDictionary::update_property() {
1133
1172
Dictionary dict = updated_val;
1134
1173
object->set_dict (updated_val);
1135
1174
1136
- edit->set_text (vformat (TTR (" %s (size %d)" ), dict_type_name, dict.size ()));
1175
+ if (preview_value) {
1176
+ String ctr_str = updated_val.get_construct_string ().replace (" \n " , " " );
1177
+ if (key_subtype != Variant::NIL || value_subtype != Variant::NIL) {
1178
+ int type_end = ctr_str.find (" ](" );
1179
+ if (type_end > 0 ) {
1180
+ ctr_str = ctr_str.substr (type_end + 2 ).trim_suffix (" )" );
1181
+ }
1182
+ }
1183
+
1184
+ edit->set_text_overrun_behavior (TextServer::OVERRUN_TRIM_ELLIPSIS);
1185
+ edit->set_text_alignment (HORIZONTAL_ALIGNMENT_LEFT);
1186
+ edit->set_button_icon (get_editor_theme_icon (dict_type_name));
1187
+ edit->set_text (vformat (" %s%s" , dict_sub_type_name, ctr_str));
1188
+ edit->set_tooltip_text (vformat (TTR (" %s%s (size %d)" ), dict_type_name, dict_sub_type_name, dict.size ()));
1189
+ } else {
1190
+ edit->set_text_alignment (HORIZONTAL_ALIGNMENT_CENTER);
1191
+ edit->set_button_icon (Ref<Texture2D>());
1192
+ edit->set_text (vformat (TTR (" %s (size %d)" ), dict_type_name, dict.size ()));
1193
+ }
1137
1194
1138
1195
bool unfolded = get_edited_object ()->editor_is_section_unfolded (get_edited_property ());
1139
1196
if (edit->is_pressed () != unfolded) {
@@ -1199,6 +1256,44 @@ void EditorPropertyDictionary::update_property() {
1199
1256
if (!slot_visible) {
1200
1257
continue ;
1201
1258
}
1259
+
1260
+ // Check if the editor property key needs to be updated.
1261
+ if (slot.prop_key ) {
1262
+ Variant key;
1263
+ object->get_by_property_name (slot.key_name , key);
1264
+ Variant::Type key_type = key.get_type ();
1265
+
1266
+ bool key_as_id = Object::cast_to<EncodedObjectAsID>(key);
1267
+ if (key_type != slot.key_type || (key_type == Variant::OBJECT && key_as_id != slot.key_as_id )) {
1268
+ slot.key_as_id = key_as_id;
1269
+ slot.key_type = key_type;
1270
+ EditorProperty *new_prop = nullptr ;
1271
+ if (key_type == Variant::OBJECT && key_as_id) {
1272
+ EditorPropertyObjectID *editor = memnew (EditorPropertyObjectID);
1273
+ editor->setup (" Object" );
1274
+ new_prop = editor;
1275
+ } else {
1276
+ new_prop = EditorInspector::instantiate_property_editor (this , key_type, " " , key_subtype_hint, key_subtype_hint_string, PROPERTY_USAGE_NONE);
1277
+ }
1278
+ new_prop->set_read_only (true );
1279
+ new_prop->set_selectable (false );
1280
+ new_prop->set_focus_mode (Control::FOCUS_NONE);
1281
+ new_prop->set_draw_background (false );
1282
+ new_prop->set_use_folding (is_using_folding ());
1283
+ new_prop->set_h_size_flags (SIZE_EXPAND_FILL);
1284
+ new_prop->set_draw_label (false );
1285
+ EditorPropertyArray *arr_prop = Object::cast_to<EditorPropertyArray>(new_prop);
1286
+ if (arr_prop) {
1287
+ arr_prop->set_preview_value (true );
1288
+ }
1289
+ EditorPropertyDictionary *dict_prop = Object::cast_to<EditorPropertyDictionary>(new_prop);
1290
+ if (dict_prop) {
1291
+ dict_prop->set_preview_value (true );
1292
+ }
1293
+ slot.set_key_prop (new_prop);
1294
+ }
1295
+ }
1296
+
1202
1297
Variant value;
1203
1298
object->get_by_property_name (slot.prop_name , value);
1204
1299
Variant::Type value_type = value.get_type ();
@@ -1231,7 +1326,6 @@ void EditorPropertyDictionary::update_property() {
1231
1326
} else if (slot.index != EditorPropertyDictionaryObject::NEW_KEY_INDEX && slot.index != EditorPropertyDictionaryObject::NEW_VALUE_INDEX) {
1232
1327
Variant key = dict.get_key_at_index (slot.index );
1233
1328
String cs = key.get_construct_string ();
1234
- slot.prop ->set_label (cs);
1235
1329
slot.prop ->set_tooltip_text (cs);
1236
1330
}
1237
1331
0 commit comments