Merge pull request #59328 from raulsntos/csharp-flag-enums-3.x

This commit is contained in:
Rémi Verschelde 2022-08-05 19:37:29 +02:00 committed by GitHub
commit 1b7037807f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 101 additions and 36 deletions

View file

@ -869,7 +869,49 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
EditorResourcePreview::get_singleton()->queue_edited_resource_preview(res, this, "_button_resource_previewed", arr);
} else if (pi.type == Variant::INT && pi.hint == PROPERTY_HINT_ENUM) {
button->set_text(pi.hint_string.get_slice(",", value));
bool found = false;
Vector<String> options = pi.hint_string.split(",");
int64_t current_val = 0;
for (int j = 0; j < options.size(); j++) {
const Vector<String> text_split = options[j].split(":");
if (text_split.size() != 1) {
current_val = text_split[1].to_int64();
}
if (value.operator int() == current_val) {
button->set_text(text_split[0]);
found = true;
break;
}
current_val += 1;
}
if (!found) {
button->set_text(value);
}
} else if (pi.type == Variant::INT && pi.hint == PROPERTY_HINT_FLAGS) {
Vector<String> value_texts;
const Vector<String> options = pi.hint_string.split(",");
uint32_t v = value;
for (int j = 0; j < options.size(); j++) {
uint32_t current_val;
Vector<String> text_split = options[j].split(":");
if (text_split.size() != -1) {
current_val = text_split[1].to_int();
} else {
current_val = 1 << i;
}
if ((v & current_val) == current_val) {
value_texts.push_back(text_split[0]);
}
}
if (value_texts.size() != 0) {
String value_text = value_texts[0];
for (int j = 1; j < value_texts.size(); j++) {
value_text += " | " + value_texts[j];
}
button->set_text(value_text);
} else {
button->set_text(value);
}
} else {
button->set_text(value);
}