Skip to content

Commit

Permalink
[Editor] Disable enum property items with duplicate values
Browse files Browse the repository at this point in the history
This helps with confusion over how selecting a key with a duplicate
value won't be selected as only the first entry with a particular value will
be selected.
  • Loading branch information
AThousandShips committed Aug 31, 2024
1 parent 61598c5 commit 739092d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion editor/editor_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,14 +688,21 @@ void EditorPropertyEnum::update_property() {

void EditorPropertyEnum::setup(const Vector<String> &p_options) {
options->clear();
RBSet<int64_t> values;
int64_t current_val = 0;
for (int i = 0; i < p_options.size(); i++) {
Vector<String> text_split = p_options[i].split(":");
if (text_split.size() != 1) {
current_val = text_split[1].to_int();
}
options->add_item(text_split[0]);
if (values.has(current_val)) {
options->add_item(vformat(TTR("%s (duplicate)"), text_split[0]));
options->set_item_disabled(i, true);
} else {
options->add_item(text_split[0]);
}
options->set_item_metadata(i, current_val);
values.insert(current_val);
current_val += 1;
}
}
Expand Down

0 comments on commit 739092d

Please sign in to comment.