Skip to content

Commit 8d91f83

Browse files
committed
Ensure correct metadata for enum items
1 parent 7fbc3a5 commit 8d91f83

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

editor/inspector/editor_properties.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ void EditorPropertyTextEnum::update_property() {
400400
// Manually entered value.
401401
if (default_option < 0 && !current_value.is_empty()) {
402402
option_button->add_item(current_value, options.size() + 1001);
403+
option_button->set_item_metadata(-1, current_value);
403404
option_button->select(0);
404405

405406
option_button->add_separator();
@@ -409,7 +410,8 @@ void EditorPropertyTextEnum::update_property() {
409410
option_button->add_item("", options.size() + 1000);
410411

411412
for (int i = 0; i < options.size(); i++) {
412-
option_button->add_item(options[i], i);
413+
option_button->add_item(option_names[i], i);
414+
option_button->set_item_metadata(-1, options[i]);
413415
if (options[i] == current_value) {
414416
option_button->select(option_button->get_item_count() - 1);
415417
}
@@ -429,20 +431,20 @@ void EditorPropertyTextEnum::setup(const Vector<String> &p_options, const Vector
429431
loose_mode = p_loose_mode;
430432

431433
options = p_options;
434+
if (p_option_names.is_empty()) {
435+
option_names = p_options;
436+
} else {
437+
option_names = p_option_names;
438+
}
432439

433440
if (loose_mode) {
434441
// Add an explicit empty value for clearing the property in the loose mode.
435442
option_button->add_item("", options.size() + 1000);
436443
option_button->set_item_metadata(-1, String());
437444
}
438445

439-
bool use_option_names = !p_option_names.is_empty();
440-
for (int i = 0; i < p_options.size(); i++) {
441-
if (use_option_names) {
442-
option_button->add_item(p_option_names[i], i);
443-
} else {
444-
option_button->add_item(p_options[i], i);
445-
}
446+
for (int i = 0; i < options.size(); i++) {
447+
option_button->add_item(option_names[i], i);
446448
option_button->set_item_metadata(-1, options[i]);
447449
}
448450

editor/inspector/editor_properties.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class EditorPropertyTextEnum : public EditorProperty {
134134
Button *cancel_button = nullptr;
135135

136136
Vector<String> options;
137+
Vector<String> option_names;
137138
bool string_name = false;
138139
bool loose_mode = false;
139140

0 commit comments

Comments
 (0)