Browse Source

Merge pull request #111201 from KoBeWi/datameta

Ensure correct metadata for enum items
Rémi Verschelde 2 months ago
parent
commit
6d33ad2917
2 changed files with 11 additions and 8 deletions
  1. 10 8
      editor/inspector/editor_properties.cpp
  2. 1 0
      editor/inspector/editor_properties.h

+ 10 - 8
editor/inspector/editor_properties.cpp

@@ -400,6 +400,7 @@ void EditorPropertyTextEnum::update_property() {
 		// Manually entered value.
 		// Manually entered value.
 		if (default_option < 0 && !current_value.is_empty()) {
 		if (default_option < 0 && !current_value.is_empty()) {
 			option_button->add_item(current_value, options.size() + 1001);
 			option_button->add_item(current_value, options.size() + 1001);
+			option_button->set_item_metadata(-1, current_value);
 			option_button->select(0);
 			option_button->select(0);
 
 
 			option_button->add_separator();
 			option_button->add_separator();
@@ -409,7 +410,8 @@ void EditorPropertyTextEnum::update_property() {
 		option_button->add_item("", options.size() + 1000);
 		option_button->add_item("", options.size() + 1000);
 
 
 		for (int i = 0; i < options.size(); i++) {
 		for (int i = 0; i < options.size(); i++) {
-			option_button->add_item(options[i], i);
+			option_button->add_item(option_names[i], i);
+			option_button->set_item_metadata(-1, options[i]);
 			if (options[i] == current_value) {
 			if (options[i] == current_value) {
 				option_button->select(option_button->get_item_count() - 1);
 				option_button->select(option_button->get_item_count() - 1);
 			}
 			}
@@ -429,6 +431,11 @@ void EditorPropertyTextEnum::setup(const Vector<String> &p_options, const Vector
 	loose_mode = p_loose_mode;
 	loose_mode = p_loose_mode;
 
 
 	options = p_options;
 	options = p_options;
+	if (p_option_names.is_empty()) {
+		option_names = p_options;
+	} else {
+		option_names = p_option_names;
+	}
 
 
 	if (loose_mode) {
 	if (loose_mode) {
 		// Add an explicit empty value for clearing the property in the loose mode.
 		// Add an explicit empty value for clearing the property in the loose mode.
@@ -436,13 +443,8 @@ void EditorPropertyTextEnum::setup(const Vector<String> &p_options, const Vector
 		option_button->set_item_metadata(-1, String());
 		option_button->set_item_metadata(-1, String());
 	}
 	}
 
 
-	bool use_option_names = !p_option_names.is_empty();
-	for (int i = 0; i < p_options.size(); i++) {
-		if (use_option_names) {
-			option_button->add_item(p_option_names[i], i);
-		} else {
-			option_button->add_item(p_options[i], i);
-		}
+	for (int i = 0; i < options.size(); i++) {
+		option_button->add_item(option_names[i], i);
 		option_button->set_item_metadata(-1, options[i]);
 		option_button->set_item_metadata(-1, options[i]);
 	}
 	}
 
 

+ 1 - 0
editor/inspector/editor_properties.h

@@ -134,6 +134,7 @@ class EditorPropertyTextEnum : public EditorProperty {
 	Button *cancel_button = nullptr;
 	Button *cancel_button = nullptr;
 
 
 	Vector<String> options;
 	Vector<String> options;
+	Vector<String> option_names;
 	bool string_name = false;
 	bool string_name = false;
 	bool loose_mode = false;
 	bool loose_mode = false;