Skip to content

Commit 3b4cf41

Browse files
committed
Merge pull request #105368 from lodetrick/editor-typed-hint
Add inspector support for typed property hint formats
2 parents 2fd48c0 + 294303e commit 3b4cf41

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

doc/classes/@GlobalScope.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2849,6 +2849,7 @@
28492849
<constant name="PROPERTY_HINT_TYPE_STRING" value="23" enum="PropertyHint">
28502850
If a property is [String], hints that the property represents a particular type (class). This allows to select a type from the create dialog. The property will store the selected type as a string.
28512851
If a property is [Array], hints the editor how to show elements. The [code]hint_string[/code] must encode nested types using [code]":"[/code] and [code]"/"[/code].
2852+
If a property is [Dictionary], hints the editor how to show elements. The [code]hint_string[/code] is the same as [Array], with a [code]";"[/code] separating the key and value.
28522853
[codeblocks]
28532854
[gdscript]
28542855
# Array of elem_type.
@@ -2923,10 +2924,12 @@
29232924
Hints that an [int] property is a pointer. Used by GDExtension.
29242925
</constant>
29252926
<constant name="PROPERTY_HINT_ARRAY_TYPE" value="31" enum="PropertyHint">
2926-
Hints that a property is an [Array] with the stored type specified in the hint string.
2927+
Hints that a property is an [Array] with the stored type specified in the hint string. The hint string contains the type of the array (e.g. [code]"String"[/code]).
2928+
Use the hint string format from [constant PROPERTY_HINT_TYPE_STRING] for more control over the stored type.
29272929
</constant>
29282930
<constant name="PROPERTY_HINT_DICTIONARY_TYPE" value="38" enum="PropertyHint">
29292931
Hints that a property is a [Dictionary] with the stored types specified in the hint string. The hint string contains the key and value types separated by a semicolon (e.g. [code]"int;String"[/code]).
2932+
Use the hint string format from [constant PROPERTY_HINT_TYPE_STRING] for more control over the stored types.
29302933
</constant>
29312934
<constant name="PROPERTY_HINT_LOCALE_ID" value="32" enum="PropertyHint">
29322935
Hints that a string property is a locale code. Editing it will show a locale dialog for picking language and country.

editor/editor_properties_array_dict.cpp

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,14 @@ void EditorPropertyArray::setup(Variant::Type p_array_type, const String &p_hint
865865

866866
subtype_hint_string = p_hint_string.substr(hint_subtype_separator + 1);
867867
subtype = Variant::Type(subtype_string.to_int());
868+
} else {
869+
subtype = Variant::get_type_by_name(p_hint_string);
870+
871+
if (subtype == Variant::VARIANT_MAX) {
872+
subtype = Variant::OBJECT;
873+
subtype_hint = PROPERTY_HINT_RESOURCE_TYPE;
874+
subtype_hint_string = p_hint_string;
875+
}
868876
}
869877
}
870878
}
@@ -1155,12 +1163,21 @@ void EditorPropertyDictionary::setup(PropertyHint p_hint, const String &p_hint_s
11551163

11561164
key_subtype_hint_string = key.substr(hint_key_subtype_separator + 1);
11571165
key_subtype = Variant::Type(key_subtype_string.to_int());
1166+
} else {
1167+
key_subtype = Variant::get_type_by_name(key);
11581168

1159-
Variant new_key = object->get_new_item_key();
1160-
VariantInternal::initialize(&new_key, key_subtype);
1161-
object->set_new_item_key(new_key);
1169+
if (key_subtype == Variant::VARIANT_MAX) {
1170+
key_subtype = Variant::OBJECT;
1171+
key_subtype_hint = PROPERTY_HINT_RESOURCE_TYPE;
1172+
key_subtype_hint_string = key;
1173+
}
11621174
}
1175+
1176+
Variant new_key = object->get_new_item_key();
1177+
VariantInternal::initialize(&new_key, key_subtype);
1178+
object->set_new_item_key(new_key);
11631179
}
1180+
11641181
if (types.size() > 1 && !types[1].is_empty()) {
11651182
String value = types[1];
11661183
int hint_value_subtype_separator = value.find_char(':');
@@ -1174,11 +1191,19 @@ void EditorPropertyDictionary::setup(PropertyHint p_hint, const String &p_hint_s
11741191

11751192
value_subtype_hint_string = value.substr(hint_value_subtype_separator + 1);
11761193
value_subtype = Variant::Type(value_subtype_string.to_int());
1194+
} else {
1195+
value_subtype = Variant::get_type_by_name(value);
11771196

1178-
Variant new_value = object->get_new_item_value();
1179-
VariantInternal::initialize(&new_value, value_subtype);
1180-
object->set_new_item_value(new_value);
1197+
if (value_subtype == Variant::VARIANT_MAX) {
1198+
value_subtype = Variant::OBJECT;
1199+
value_subtype_hint = PROPERTY_HINT_RESOURCE_TYPE;
1200+
value_subtype_hint_string = value;
1201+
}
11811202
}
1203+
1204+
Variant new_value = object->get_new_item_value();
1205+
VariantInternal::initialize(&new_value, value_subtype);
1206+
object->set_new_item_value(new_value);
11821207
}
11831208
}
11841209

0 commit comments

Comments
 (0)