Add inspector support for typed property hints
This commit is contained in:
@ -2849,6 +2849,7 @@
|
||||
<constant name="PROPERTY_HINT_TYPE_STRING" value="23" enum="PropertyHint">
|
||||
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.
|
||||
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].
|
||||
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.
|
||||
[codeblocks]
|
||||
[gdscript]
|
||||
# Array of elem_type.
|
||||
@ -2923,10 +2924,12 @@
|
||||
Hints that an [int] property is a pointer. Used by GDExtension.
|
||||
</constant>
|
||||
<constant name="PROPERTY_HINT_ARRAY_TYPE" value="31" enum="PropertyHint">
|
||||
Hints that a property is an [Array] with the stored type specified in the hint string.
|
||||
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]).
|
||||
Use the hint string format from [constant PROPERTY_HINT_TYPE_STRING] for more control over the stored type.
|
||||
</constant>
|
||||
<constant name="PROPERTY_HINT_DICTIONARY_TYPE" value="38" enum="PropertyHint">
|
||||
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]).
|
||||
Use the hint string format from [constant PROPERTY_HINT_TYPE_STRING] for more control over the stored types.
|
||||
</constant>
|
||||
<constant name="PROPERTY_HINT_LOCALE_ID" value="32" enum="PropertyHint">
|
||||
Hints that a string property is a locale code. Editing it will show a locale dialog for picking language and country.
|
||||
|
||||
@ -865,6 +865,14 @@ void EditorPropertyArray::setup(Variant::Type p_array_type, const String &p_hint
|
||||
|
||||
subtype_hint_string = p_hint_string.substr(hint_subtype_separator + 1);
|
||||
subtype = Variant::Type(subtype_string.to_int());
|
||||
} else {
|
||||
subtype = Variant::get_type_by_name(p_hint_string);
|
||||
|
||||
if (subtype == Variant::VARIANT_MAX) {
|
||||
subtype = Variant::OBJECT;
|
||||
subtype_hint = PROPERTY_HINT_RESOURCE_TYPE;
|
||||
subtype_hint_string = p_hint_string;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1155,12 +1163,21 @@ void EditorPropertyDictionary::setup(PropertyHint p_hint, const String &p_hint_s
|
||||
|
||||
key_subtype_hint_string = key.substr(hint_key_subtype_separator + 1);
|
||||
key_subtype = Variant::Type(key_subtype_string.to_int());
|
||||
} else {
|
||||
key_subtype = Variant::get_type_by_name(key);
|
||||
|
||||
Variant new_key = object->get_new_item_key();
|
||||
VariantInternal::initialize(&new_key, key_subtype);
|
||||
object->set_new_item_key(new_key);
|
||||
if (key_subtype == Variant::VARIANT_MAX) {
|
||||
key_subtype = Variant::OBJECT;
|
||||
key_subtype_hint = PROPERTY_HINT_RESOURCE_TYPE;
|
||||
key_subtype_hint_string = key;
|
||||
}
|
||||
}
|
||||
|
||||
Variant new_key = object->get_new_item_key();
|
||||
VariantInternal::initialize(&new_key, key_subtype);
|
||||
object->set_new_item_key(new_key);
|
||||
}
|
||||
|
||||
if (types.size() > 1 && !types[1].is_empty()) {
|
||||
String value = types[1];
|
||||
int hint_value_subtype_separator = value.find_char(':');
|
||||
@ -1174,11 +1191,19 @@ void EditorPropertyDictionary::setup(PropertyHint p_hint, const String &p_hint_s
|
||||
|
||||
value_subtype_hint_string = value.substr(hint_value_subtype_separator + 1);
|
||||
value_subtype = Variant::Type(value_subtype_string.to_int());
|
||||
} else {
|
||||
value_subtype = Variant::get_type_by_name(value);
|
||||
|
||||
Variant new_value = object->get_new_item_value();
|
||||
VariantInternal::initialize(&new_value, value_subtype);
|
||||
object->set_new_item_value(new_value);
|
||||
if (value_subtype == Variant::VARIANT_MAX) {
|
||||
value_subtype = Variant::OBJECT;
|
||||
value_subtype_hint = PROPERTY_HINT_RESOURCE_TYPE;
|
||||
value_subtype_hint_string = value;
|
||||
}
|
||||
}
|
||||
|
||||
Variant new_value = object->get_new_item_value();
|
||||
VariantInternal::initialize(&new_value, value_subtype);
|
||||
object->set_new_item_value(new_value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user