Use get_node_or_null when null checks are present

Avoids duplicate or unnecessary errors
This commit is contained in:
Ninni Pipping
2023-06-05 14:56:54 +02:00
parent 37d1dfef9d
commit 0c16082e1e
7 changed files with 28 additions and 40 deletions

View File

@@ -2063,14 +2063,10 @@ Control *Control::find_next_valid_focus() const {
// If the focus property is manually overwritten, attempt to use it.
if (!data.focus_next.is_empty()) {
Node *n = get_node(data.focus_next);
Control *c;
if (n) {
c = Object::cast_to<Control>(n);
ERR_FAIL_COND_V_MSG(!c, nullptr, "Next focus node is not a control: " + n->get_name() + ".");
} else {
return nullptr;
}
Node *n = get_node_or_null(data.focus_next);
ERR_FAIL_NULL_V_MSG(n, nullptr, "Next focus node path is invalid: '" + data.focus_next + "'.");
Control *c = Object::cast_to<Control>(n);
ERR_FAIL_NULL_V_MSG(c, nullptr, "Next focus node is not a control: '" + n->get_name() + "'.");
if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE) {
return c;
}
@@ -2154,14 +2150,10 @@ Control *Control::find_prev_valid_focus() const {
// If the focus property is manually overwritten, attempt to use it.
if (!data.focus_prev.is_empty()) {
Node *n = get_node(data.focus_prev);
Control *c;
if (n) {
c = Object::cast_to<Control>(n);
ERR_FAIL_COND_V_MSG(!c, nullptr, "Previous focus node is not a control: " + n->get_name() + ".");
} else {
return nullptr;
}
Node *n = get_node_or_null(data.focus_prev);
ERR_FAIL_NULL_V_MSG(n, nullptr, "Previous focus node path is invalid: '" + data.focus_prev + "'.");
Control *c = Object::cast_to<Control>(n);
ERR_FAIL_NULL_V_MSG(c, nullptr, "Previous focus node is not a control: '" + n->get_name() + "'.");
if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE) {
return c;
}
@@ -2250,14 +2242,10 @@ Control *Control::_get_focus_neighbor(Side p_side, int p_count) {
return nullptr;
}
if (!data.focus_neighbor[p_side].is_empty()) {
Control *c = nullptr;
Node *n = get_node(data.focus_neighbor[p_side]);
if (n) {
c = Object::cast_to<Control>(n);
ERR_FAIL_COND_V_MSG(!c, nullptr, "Neighbor focus node is not a control: " + n->get_name() + ".");
} else {
return nullptr;
}
Node *n = get_node_or_null(data.focus_neighbor[p_side]);
ERR_FAIL_NULL_V_MSG(n, nullptr, "Neighbor focus node path is invalid: '" + data.focus_neighbor[p_side] + "'.");
Control *c = Object::cast_to<Control>(n);
ERR_FAIL_NULL_V_MSG(c, nullptr, "Neighbor focus node is not a control: '" + n->get_name() + "'.");
bool valid = true;
if (!c->is_visible()) {
valid = false;