Prevent Popup
s it the edited scene tree from closing on focus loss. Hide irrelevant Popup
flags from the editor inspector.
This commit is contained in:
parent
28f642097a
commit
2e1fcbe14b
@ -77,6 +77,7 @@ void Popup::_update_theme_item_cache() {
|
|||||||
void Popup::_notification(int p_what) {
|
void Popup::_notification(int p_what) {
|
||||||
switch (p_what) {
|
switch (p_what) {
|
||||||
case NOTIFICATION_VISIBILITY_CHANGED: {
|
case NOTIFICATION_VISIBILITY_CHANGED: {
|
||||||
|
if (!is_in_edited_scene_root()) {
|
||||||
if (is_visible()) {
|
if (is_visible()) {
|
||||||
_initialize_visible_parents();
|
_initialize_visible_parents();
|
||||||
} else {
|
} else {
|
||||||
@ -84,21 +85,28 @@ void Popup::_notification(int p_what) {
|
|||||||
emit_signal(SNAME("popup_hide"));
|
emit_signal(SNAME("popup_hide"));
|
||||||
popped_up = false;
|
popped_up = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case NOTIFICATION_WM_WINDOW_FOCUS_IN: {
|
case NOTIFICATION_WM_WINDOW_FOCUS_IN: {
|
||||||
|
if (!is_in_edited_scene_root()) {
|
||||||
if (has_focus()) {
|
if (has_focus()) {
|
||||||
popped_up = true;
|
popped_up = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case NOTIFICATION_EXIT_TREE: {
|
case NOTIFICATION_EXIT_TREE: {
|
||||||
|
if (!is_in_edited_scene_root()) {
|
||||||
_deinitialize_visible_parents();
|
_deinitialize_visible_parents();
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case NOTIFICATION_WM_CLOSE_REQUEST:
|
case NOTIFICATION_WM_CLOSE_REQUEST:
|
||||||
case NOTIFICATION_APPLICATION_FOCUS_OUT: {
|
case NOTIFICATION_APPLICATION_FOCUS_OUT: {
|
||||||
|
if (!is_in_edited_scene_root()) {
|
||||||
_close_pressed();
|
_close_pressed();
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -126,6 +134,16 @@ void Popup::_bind_methods() {
|
|||||||
ADD_SIGNAL(MethodInfo("popup_hide"));
|
ADD_SIGNAL(MethodInfo("popup_hide"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Popup::_validate_property(PropertyInfo &p_property) const {
|
||||||
|
if (
|
||||||
|
p_property.name == "transient" ||
|
||||||
|
p_property.name == "exclusive" ||
|
||||||
|
p_property.name == "popup_window" ||
|
||||||
|
p_property.name == "unfocusable") {
|
||||||
|
p_property.usage = PROPERTY_USAGE_NO_EDITOR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Rect2i Popup::_popup_adjust_rect() const {
|
Rect2i Popup::_popup_adjust_rect() const {
|
||||||
ERR_FAIL_COND_V(!is_inside_tree(), Rect2());
|
ERR_FAIL_COND_V(!is_inside_tree(), Rect2());
|
||||||
Rect2i parent_rect = get_usable_parent_rect();
|
Rect2i parent_rect = get_usable_parent_rect();
|
||||||
|
@ -59,6 +59,7 @@ protected:
|
|||||||
virtual void _update_theme_item_cache() override;
|
virtual void _update_theme_item_cache() override;
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
void _validate_property(PropertyInfo &p_property) const;
|
||||||
|
|
||||||
virtual void _parent_focused();
|
virtual void _parent_focused();
|
||||||
|
|
||||||
|
@ -157,26 +157,18 @@ void Window::set_flag(Flags p_flag, bool p_enabled) {
|
|||||||
embedder->_sub_window_update(this);
|
embedder->_sub_window_update(this);
|
||||||
|
|
||||||
} else if (window_id != DisplayServer::INVALID_WINDOW_ID) {
|
} else if (window_id != DisplayServer::INVALID_WINDOW_ID) {
|
||||||
#ifdef TOOLS_ENABLED
|
if (!is_in_edited_scene_root()) {
|
||||||
if ((p_flag != FLAG_POPUP) || !(Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && (get_tree()->get_edited_scene_root()->is_ancestor_of(this) || get_tree()->get_edited_scene_root() == this))) {
|
|
||||||
DisplayServer::get_singleton()->window_set_flag(DisplayServer::WindowFlags(p_flag), p_enabled, window_id);
|
DisplayServer::get_singleton()->window_set_flag(DisplayServer::WindowFlags(p_flag), p_enabled, window_id);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
DisplayServer::get_singleton()->window_set_flag(DisplayServer::WindowFlags(p_flag), p_enabled, window_id);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::get_flag(Flags p_flag) const {
|
bool Window::get_flag(Flags p_flag) const {
|
||||||
ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false);
|
ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false);
|
||||||
if (window_id != DisplayServer::INVALID_WINDOW_ID) {
|
if (window_id != DisplayServer::INVALID_WINDOW_ID) {
|
||||||
#ifdef TOOLS_ENABLED
|
if (!is_in_edited_scene_root()) {
|
||||||
if ((p_flag != FLAG_POPUP) || !(Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && (get_tree()->get_edited_scene_root()->is_ancestor_of(this) || get_tree()->get_edited_scene_root() == this))) {
|
|
||||||
flags[p_flag] = DisplayServer::get_singleton()->window_get_flag(DisplayServer::WindowFlags(p_flag), window_id);
|
flags[p_flag] = DisplayServer::get_singleton()->window_get_flag(DisplayServer::WindowFlags(p_flag), window_id);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
flags[p_flag] = DisplayServer::get_singleton()->window_get_flag(DisplayServer::WindowFlags(p_flag), window_id);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
return flags[p_flag];
|
return flags[p_flag];
|
||||||
}
|
}
|
||||||
@ -232,6 +224,14 @@ bool Window::is_embedded() const {
|
|||||||
return _get_embedder() != nullptr;
|
return _get_embedder() != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Window::is_in_edited_scene_root() const {
|
||||||
|
#ifdef TOOLS_ENABLED
|
||||||
|
return (Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && (get_tree()->get_edited_scene_root()->is_ancestor_of(this) || get_tree()->get_edited_scene_root() == this));
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void Window::_make_window() {
|
void Window::_make_window() {
|
||||||
ERR_FAIL_COND(window_id != DisplayServer::INVALID_WINDOW_ID);
|
ERR_FAIL_COND(window_id != DisplayServer::INVALID_WINDOW_ID);
|
||||||
|
|
||||||
@ -259,15 +259,12 @@ void Window::_make_window() {
|
|||||||
#endif
|
#endif
|
||||||
DisplayServer::get_singleton()->window_set_title(tr_title, window_id);
|
DisplayServer::get_singleton()->window_set_title(tr_title, window_id);
|
||||||
DisplayServer::get_singleton()->window_attach_instance_id(get_instance_id(), window_id);
|
DisplayServer::get_singleton()->window_attach_instance_id(get_instance_id(), window_id);
|
||||||
#ifdef TOOLS_ENABLED
|
|
||||||
if (!(Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && (get_tree()->get_edited_scene_root()->is_ancestor_of(this) || get_tree()->get_edited_scene_root() == this))) {
|
if (is_in_edited_scene_root()) {
|
||||||
DisplayServer::get_singleton()->window_set_exclusive(window_id, exclusive);
|
|
||||||
} else {
|
|
||||||
DisplayServer::get_singleton()->window_set_exclusive(window_id, false);
|
DisplayServer::get_singleton()->window_set_exclusive(window_id, false);
|
||||||
}
|
} else {
|
||||||
#else
|
|
||||||
DisplayServer::get_singleton()->window_set_exclusive(window_id, exclusive);
|
DisplayServer::get_singleton()->window_set_exclusive(window_id, exclusive);
|
||||||
#endif
|
}
|
||||||
|
|
||||||
_update_window_size();
|
_update_window_size();
|
||||||
|
|
||||||
@ -465,14 +462,10 @@ void Window::set_visible(bool p_visible) {
|
|||||||
//update transient exclusive
|
//update transient exclusive
|
||||||
if (transient_parent) {
|
if (transient_parent) {
|
||||||
if (exclusive && visible) {
|
if (exclusive && visible) {
|
||||||
#ifdef TOOLS_ENABLED
|
if (!is_in_edited_scene_root()) {
|
||||||
if (!(Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && (get_tree()->get_edited_scene_root()->is_ancestor_of(this) || get_tree()->get_edited_scene_root() == this))) {
|
|
||||||
ERR_FAIL_COND_MSG(transient_parent->exclusive_child && transient_parent->exclusive_child != this, "Transient parent has another exclusive child.");
|
ERR_FAIL_COND_MSG(transient_parent->exclusive_child && transient_parent->exclusive_child != this, "Transient parent has another exclusive child.");
|
||||||
transient_parent->exclusive_child = this;
|
transient_parent->exclusive_child = this;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
transient_parent->exclusive_child = this;
|
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
if (transient_parent->exclusive_child == this) {
|
if (transient_parent->exclusive_child == this) {
|
||||||
transient_parent->exclusive_child = nullptr;
|
transient_parent->exclusive_child = nullptr;
|
||||||
@ -519,13 +512,9 @@ void Window::_make_transient() {
|
|||||||
window->transient_children.insert(this);
|
window->transient_children.insert(this);
|
||||||
if (is_inside_tree() && is_visible() && exclusive) {
|
if (is_inside_tree() && is_visible() && exclusive) {
|
||||||
if (transient_parent->exclusive_child == nullptr) {
|
if (transient_parent->exclusive_child == nullptr) {
|
||||||
#ifdef TOOLS_ENABLED
|
if (!is_in_edited_scene_root()) {
|
||||||
if (!(Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && (get_tree()->get_edited_scene_root()->is_ancestor_of(this) || get_tree()->get_edited_scene_root() == this))) {
|
|
||||||
transient_parent->exclusive_child = this;
|
transient_parent->exclusive_child = this;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
transient_parent->exclusive_child = this;
|
|
||||||
#endif
|
|
||||||
} else if (transient_parent->exclusive_child != this) {
|
} else if (transient_parent->exclusive_child != this) {
|
||||||
ERR_PRINT("Making child transient exclusive, but parent has another exclusive child");
|
ERR_PRINT("Making child transient exclusive, but parent has another exclusive child");
|
||||||
}
|
}
|
||||||
@ -568,27 +557,19 @@ void Window::set_exclusive(bool p_exclusive) {
|
|||||||
exclusive = p_exclusive;
|
exclusive = p_exclusive;
|
||||||
|
|
||||||
if (!embedder && window_id != DisplayServer::INVALID_WINDOW_ID) {
|
if (!embedder && window_id != DisplayServer::INVALID_WINDOW_ID) {
|
||||||
#ifdef TOOLS_ENABLED
|
if (is_in_edited_scene_root()) {
|
||||||
if (!(Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && (get_tree()->get_edited_scene_root()->is_ancestor_of(this) || get_tree()->get_edited_scene_root() == this))) {
|
|
||||||
DisplayServer::get_singleton()->window_set_exclusive(window_id, exclusive);
|
|
||||||
} else {
|
|
||||||
DisplayServer::get_singleton()->window_set_exclusive(window_id, false);
|
DisplayServer::get_singleton()->window_set_exclusive(window_id, false);
|
||||||
}
|
} else {
|
||||||
#else
|
|
||||||
DisplayServer::get_singleton()->window_set_exclusive(window_id, exclusive);
|
DisplayServer::get_singleton()->window_set_exclusive(window_id, exclusive);
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transient_parent) {
|
if (transient_parent) {
|
||||||
if (p_exclusive && is_inside_tree() && is_visible()) {
|
if (p_exclusive && is_inside_tree() && is_visible()) {
|
||||||
ERR_FAIL_COND_MSG(transient_parent->exclusive_child && transient_parent->exclusive_child != this, "Transient parent has another exclusive child.");
|
ERR_FAIL_COND_MSG(transient_parent->exclusive_child && transient_parent->exclusive_child != this, "Transient parent has another exclusive child.");
|
||||||
#ifdef TOOLS_ENABLED
|
if (!is_in_edited_scene_root()) {
|
||||||
if (!(Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && (get_tree()->get_edited_scene_root()->is_ancestor_of(this) || get_tree()->get_edited_scene_root() == this))) {
|
|
||||||
transient_parent->exclusive_child = this;
|
transient_parent->exclusive_child = this;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
transient_parent->exclusive_child = this;
|
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
if (transient_parent->exclusive_child == this) {
|
if (transient_parent->exclusive_child == this) {
|
||||||
transient_parent->exclusive_child = nullptr;
|
transient_parent->exclusive_child = nullptr;
|
||||||
|
@ -234,6 +234,8 @@ public:
|
|||||||
void set_clamp_to_embedder(bool p_enable);
|
void set_clamp_to_embedder(bool p_enable);
|
||||||
bool is_clamped_to_embedder() const;
|
bool is_clamped_to_embedder() const;
|
||||||
|
|
||||||
|
bool is_in_edited_scene_root() const;
|
||||||
|
|
||||||
bool can_draw() const;
|
bool can_draw() const;
|
||||||
|
|
||||||
void set_ime_active(bool p_active);
|
void set_ime_active(bool p_active);
|
||||||
|
Loading…
Reference in New Issue
Block a user