mirror of
https://github.com/godotengine/godot.git
synced 2026-01-06 10:11:57 +03: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:
@@ -627,14 +627,12 @@ EditorPropertyEnum::EditorPropertyEnum() {
|
||||
|
||||
///////////////////// FLAGS /////////////////////////
|
||||
|
||||
void EditorPropertyFlags::_flag_toggled() {
|
||||
uint32_t value = 0;
|
||||
for (int i = 0; i < flags.size(); i++) {
|
||||
if (flags[i]->is_pressed()) {
|
||||
uint32_t val = 1;
|
||||
val <<= flag_indices[i];
|
||||
value |= val;
|
||||
}
|
||||
void EditorPropertyFlags::_flag_toggled(int p_index) {
|
||||
uint32_t value = get_edited_object()->get(get_edited_property());
|
||||
if (flags[p_index]->is_pressed()) {
|
||||
value |= flag_values[p_index];
|
||||
} else {
|
||||
value &= ~flag_values[p_index];
|
||||
}
|
||||
|
||||
emit_changed(get_edited_property(), value);
|
||||
@@ -644,13 +642,7 @@ void EditorPropertyFlags::update_property() {
|
||||
uint32_t value = get_edited_object()->get(get_edited_property());
|
||||
|
||||
for (int i = 0; i < flags.size(); i++) {
|
||||
uint32_t val = 1;
|
||||
val <<= flag_indices[i];
|
||||
if (value & val) {
|
||||
flags[i]->set_pressed(true);
|
||||
} else {
|
||||
flags[i]->set_pressed(false);
|
||||
}
|
||||
flags[i]->set_pressed((value & flag_values[i]) == flag_values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -658,17 +650,24 @@ void EditorPropertyFlags::setup(const Vector<String> &p_options) {
|
||||
ERR_FAIL_COND(flags.size());
|
||||
|
||||
bool first = true;
|
||||
uint32_t current_val;
|
||||
for (int i = 0; i < p_options.size(); i++) {
|
||||
String option = p_options[i].strip_edges();
|
||||
if (option != "") {
|
||||
CheckBox *cb = memnew(CheckBox);
|
||||
cb->set_text(option);
|
||||
cb->set_clip_text(true);
|
||||
cb->connect("pressed", this, "_flag_toggled");
|
||||
cb->connect("pressed", this, "_flag_toggled", varray(i));
|
||||
add_focusable(cb);
|
||||
vbox->add_child(cb);
|
||||
flags.push_back(cb);
|
||||
flag_indices.push_back(i);
|
||||
Vector<String> text_split = p_options[i].split(":");
|
||||
if (text_split.size() != 1) {
|
||||
current_val = text_split[1].to_int();
|
||||
} else {
|
||||
current_val = 1 << i;
|
||||
}
|
||||
flag_values.push_back(current_val);
|
||||
if (first) {
|
||||
set_label_reference(cb);
|
||||
first = false;
|
||||
|
||||
Reference in New Issue
Block a user