Fix crash when toggling flag property value
This commit is contained in:
parent
c40855f818
commit
97f547a63a
1 changed files with 28 additions and 19 deletions
|
@ -832,26 +832,35 @@ void EditorPropertyFlags::setup(const Vector<String> &p_options) {
|
||||||
bool first = true;
|
bool first = true;
|
||||||
uint32_t current_val;
|
uint32_t current_val;
|
||||||
for (int i = 0; i < p_options.size(); i++) {
|
for (int i = 0; i < p_options.size(); i++) {
|
||||||
|
// An empty option is not considered a "flag".
|
||||||
String option = p_options[i].strip_edges();
|
String option = p_options[i].strip_edges();
|
||||||
if (!option.is_empty()) {
|
if (option.is_empty()) {
|
||||||
CheckBox *cb = memnew(CheckBox);
|
continue;
|
||||||
cb->set_text(option);
|
}
|
||||||
cb->set_clip_text(true);
|
const int flag_index = flags.size(); // Index of the next element (added by the code below).
|
||||||
cb->connect("pressed", callable_mp(this, &EditorPropertyFlags::_flag_toggled).bind(i));
|
|
||||||
add_focusable(cb);
|
// Value for a flag can be explicitly overridden.
|
||||||
vbox->add_child(cb);
|
Vector<String> text_split = p_options[i].split(":");
|
||||||
flags.push_back(cb);
|
if (text_split.size() != 1) {
|
||||||
Vector<String> text_split = p_options[i].split(":");
|
current_val = text_split[1].to_int();
|
||||||
if (text_split.size() != 1) {
|
} else {
|
||||||
current_val = text_split[1].to_int();
|
current_val = 1 << i;
|
||||||
} else {
|
}
|
||||||
current_val = 1 << i;
|
flag_values.push_back(current_val);
|
||||||
}
|
|
||||||
flag_values.push_back(current_val);
|
// Create a CheckBox for the current flag.
|
||||||
if (first) {
|
CheckBox *cb = memnew(CheckBox);
|
||||||
set_label_reference(cb);
|
cb->set_text(option);
|
||||||
first = false;
|
cb->set_clip_text(true);
|
||||||
}
|
cb->connect("pressed", callable_mp(this, &EditorPropertyFlags::_flag_toggled).bind(flag_index));
|
||||||
|
add_focusable(cb);
|
||||||
|
vbox->add_child(cb);
|
||||||
|
flags.push_back(cb);
|
||||||
|
|
||||||
|
// Can't use `i == 0` because we want to find the first none-empty option.
|
||||||
|
if (first) {
|
||||||
|
set_label_reference(cb);
|
||||||
|
first = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue