1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-21 14:57:09 +00:00

Support explicit values in flag properties, add C# flags support

- Add support for explicit values in properties using `PROPERTY_HINT_FLAGS`
that works the same way it does for enums.
- Fix enums and flags in VisualScriptEditor (it wasn't considering the
explicit value).
- Use `PROPERTY_HINT_FLAGS` for C# enums with the FlagsAttribute instead
of `PROPERTY_HINT_ENUM`.
This commit is contained in:
Raul Santos
2022-03-06 18:04:29 +01:00
parent cec7fc4ffe
commit 862691a9f7
10 changed files with 101 additions and 36 deletions

View File

@@ -114,15 +114,16 @@ void CustomPropertyEditor::_menu_option(int p_which) {
switch (type) {
case Variant::INT: {
if (hint == PROPERTY_HINT_FLAGS) {
int val = v;
if (val & (1 << p_which)) {
val &= ~(1 << p_which);
int idx = menu->get_item_index(p_which);
uint32_t item_value = menu->get_item_metadata(idx);
uint32_t value = v;
// If the item wasn't previously checked it means it was pressed,
// otherwise it was unpressed.
if (!menu->is_item_checked(idx)) {
v = value | item_value;
} else {
val |= (1 << p_which);
v = value & ~item_value;
}
v = val;
emit_signal("variant_changed");
} else if (hint == PROPERTY_HINT_ENUM) {
v = menu->get_item_metadata(p_which);
@@ -482,15 +483,19 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
set_size(Size2(200, 150) * EDSCALE);
} else if (hint == PROPERTY_HINT_FLAGS) {
Vector<String> flags = hint_text.split(",");
uint32_t value = v;
for (int i = 0; i < flags.size(); i++) {
String flag = flags[i];
if (flag == "") {
continue;
uint32_t current_val;
Vector<String> text_split = flags[i].split(":");
if (text_split.size() != 1) {
current_val = text_split[1].to_int();
} else {
current_val = 1 << i;
}
menu->add_check_item(flag, i);
int f = v;
if (f & (1 << i)) {
menu->set_item_checked(menu->get_item_index(i), true);
menu->add_check_item(text_split[0], current_val);
menu->set_item_metadata(i, current_val);
if ((value & current_val) == current_val) {
menu->set_item_checked(menu->get_item_index(current_val), true);
}
}
menu->set_position(get_position());