Skip to content

Commit

Permalink
Editor UI fix for string parsing array's variant sub-hint (hint_strin…
Browse files Browse the repository at this point in the history
…g syntax).

F.e restrict Array's editor UI to allow only NodePaths of RigidBody type.

I think hint_string syntax was supposed to be:

(VARIANT_ID_INT):[(HINT_ID_INT)/(HINT_STRING)]
the section after colon is optional

but it's hard to figure out without any docs,
and broken string parser.

Use Example:

ADD_PROPERTY(PropertyInfo(Variant::ARRAY,
"hints_array", PROPERTY_HINT_NONE,
itos(Variant::NODE_PATH)+":"+itos(PROPERTY_HINT_NODE_PATH_VALID_TYPES)+"/RigidBody"),
"set_hints", "get_hints");
  • Loading branch information
lonegamedev committed Oct 17, 2019
1 parent 119bf23 commit f224740
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
14 changes: 6 additions & 8 deletions editor/array_property_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,14 @@ void ArrayPropertyEdit::edit(Object *p_obj, const StringName &p_prop, const Stri
if (!p_hint_string.empty()) {
int hint_subtype_seperator = p_hint_string.find(":");
if (hint_subtype_seperator >= 0) {
String subtype_string = p_hint_string.substr(0, hint_subtype_seperator);

int slash_pos = subtype_string.find("/");
String sub_str = p_hint_string.substr(0, hint_subtype_seperator);
subtype = Variant::Type(sub_str.to_int());
sub_str = p_hint_string.substr(hint_subtype_seperator + 1);
int slash_pos = sub_str.find("/");
if (slash_pos >= 0) {
subtype_hint = PropertyHint(subtype_string.substr(slash_pos + 1, subtype_string.size() - slash_pos - 1).to_int());
subtype_string = subtype_string.substr(0, slash_pos);
subtype_hint = PropertyHint(sub_str.substr(0, slash_pos).to_int());
subtype_hint_string = sub_str.substr(slash_pos + 1);
}

subtype_hint_string = p_hint_string.substr(hint_subtype_seperator + 1, p_hint_string.size() - hint_subtype_seperator - 1);
subtype = Variant::Type(subtype_string.to_int());
}
}
}
Expand Down
13 changes: 6 additions & 7 deletions editor/editor_properties_array_dict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,15 +477,14 @@ void EditorPropertyArray::setup(Variant::Type p_array_type, const String &p_hint
if (array_type == Variant::ARRAY && !p_hint_string.empty()) {
int hint_subtype_seperator = p_hint_string.find(":");
if (hint_subtype_seperator >= 0) {
String subtype_string = p_hint_string.substr(0, hint_subtype_seperator);
int slash_pos = subtype_string.find("/");
String sub_str = p_hint_string.substr(0, hint_subtype_seperator);
subtype = Variant::Type(sub_str.to_int());
sub_str = p_hint_string.substr(hint_subtype_seperator + 1);
int slash_pos = sub_str.find("/");
if (slash_pos >= 0) {
subtype_hint = PropertyHint(subtype_string.substr(slash_pos + 1, subtype_string.size() - slash_pos - 1).to_int());
subtype_string = subtype_string.substr(0, slash_pos);
subtype_hint = PropertyHint(sub_str.substr(0, slash_pos).to_int());
subtype_hint_string = sub_str.substr(slash_pos + 1);
}

subtype_hint_string = p_hint_string.substr(hint_subtype_seperator + 1, p_hint_string.size() - hint_subtype_seperator - 1);
subtype = Variant::Type(subtype_string.to_int());
}
}
}
Expand Down

0 comments on commit f224740

Please sign in to comment.