Merge pull request #96386 from AThousandShips/enum_inspector_improve

[Editor] Merge duplicate entries in enum property inspector
This commit is contained in:
Rémi Verschelde 2024-09-13 11:21:40 +02:00
commit ac652cf2a0
No known key found for this signature in database
GPG Key ID: C3336907360768E1
1 changed files with 9 additions and 4 deletions

View File

@ -687,16 +687,21 @@ void EditorPropertyEnum::update_property() {
void EditorPropertyEnum::setup(const Vector<String> &p_options) { void EditorPropertyEnum::setup(const Vector<String> &p_options) {
options->clear(); options->clear();
HashMap<int64_t, Vector<String>> items;
int64_t current_val = 0; int64_t current_val = 0;
for (int i = 0; i < p_options.size(); i++) { for (const String &option : p_options) {
Vector<String> text_split = p_options[i].split(":"); Vector<String> text_split = option.split(":");
if (text_split.size() != 1) { if (text_split.size() != 1) {
current_val = text_split[1].to_int(); current_val = text_split[1].to_int();
} }
options->add_item(text_split[0]); items[current_val].push_back(text_split[0]);
options->set_item_metadata(i, current_val);
current_val += 1; current_val += 1;
} }
for (const KeyValue<int64_t, Vector<String>> &K : items) {
options->add_item(String(", ").join(K.value));
options->set_item_metadata(-1, K.key);
}
} }
void EditorPropertyEnum::set_option_button_clip(bool p_enable) { void EditorPropertyEnum::set_option_button_clip(bool p_enable) {