Merge pull request #67232 from bruvzg/popup_edit
Improve Popup / Window behavior in the edited scene tree.
This commit is contained in:
commit
15b68f7601
4 changed files with 51 additions and 49 deletions
|
@ -77,6 +77,7 @@ void Popup::_update_theme_item_cache() {
|
|||
void Popup::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_VISIBILITY_CHANGED: {
|
||||
if (!is_in_edited_scene_root()) {
|
||||
if (is_visible()) {
|
||||
_initialize_visible_parents();
|
||||
} else {
|
||||
|
@ -84,21 +85,28 @@ void Popup::_notification(int p_what) {
|
|||
emit_signal(SNAME("popup_hide"));
|
||||
popped_up = false;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_WM_WINDOW_FOCUS_IN: {
|
||||
if (!is_in_edited_scene_root()) {
|
||||
if (has_focus()) {
|
||||
popped_up = true;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
if (!is_in_edited_scene_root()) {
|
||||
_deinitialize_visible_parents();
|
||||
}
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_WM_CLOSE_REQUEST:
|
||||
case NOTIFICATION_APPLICATION_FOCUS_OUT: {
|
||||
if (!is_in_edited_scene_root()) {
|
||||
_close_pressed();
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
@ -126,6 +134,16 @@ void Popup::_bind_methods() {
|
|||
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 {
|
||||
ERR_FAIL_COND_V(!is_inside_tree(), Rect2());
|
||||
Rect2i parent_rect = get_usable_parent_rect();
|
||||
|
|
|
@ -59,6 +59,7 @@ protected:
|
|||
virtual void _update_theme_item_cache() override;
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
void _validate_property(PropertyInfo &p_property) const;
|
||||
|
||||
virtual void _parent_focused();
|
||||
|
||||
|
|
|
@ -157,26 +157,18 @@ void Window::set_flag(Flags p_flag, bool p_enabled) {
|
|||
embedder->_sub_window_update(this);
|
||||
|
||||
} else if (window_id != DisplayServer::INVALID_WINDOW_ID) {
|
||||
#ifdef TOOLS_ENABLED
|
||||
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))) {
|
||||
if (!is_in_edited_scene_root()) {
|
||||
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 {
|
||||
ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false);
|
||||
if (window_id != DisplayServer::INVALID_WINDOW_ID) {
|
||||
#ifdef TOOLS_ENABLED
|
||||
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))) {
|
||||
if (!is_in_edited_scene_root()) {
|
||||
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];
|
||||
}
|
||||
|
@ -232,6 +224,14 @@ bool Window::is_embedded() const {
|
|||
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() {
|
||||
ERR_FAIL_COND(window_id != DisplayServer::INVALID_WINDOW_ID);
|
||||
|
||||
|
@ -259,15 +259,12 @@ void Window::_make_window() {
|
|||
#endif
|
||||
DisplayServer::get_singleton()->window_set_title(tr_title, 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))) {
|
||||
DisplayServer::get_singleton()->window_set_exclusive(window_id, exclusive);
|
||||
} else {
|
||||
|
||||
if (is_in_edited_scene_root()) {
|
||||
DisplayServer::get_singleton()->window_set_exclusive(window_id, false);
|
||||
}
|
||||
#else
|
||||
} else {
|
||||
DisplayServer::get_singleton()->window_set_exclusive(window_id, exclusive);
|
||||
#endif
|
||||
}
|
||||
|
||||
_update_window_size();
|
||||
|
||||
|
@ -465,14 +462,10 @@ void Window::set_visible(bool p_visible) {
|
|||
//update transient exclusive
|
||||
if (transient_parent) {
|
||||
if (exclusive && visible) {
|
||||
#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()) {
|
||||
ERR_FAIL_COND_MSG(transient_parent->exclusive_child && transient_parent->exclusive_child != this, "Transient parent has another exclusive child.");
|
||||
transient_parent->exclusive_child = this;
|
||||
}
|
||||
#else
|
||||
transient_parent->exclusive_child = this;
|
||||
#endif
|
||||
} else {
|
||||
if (transient_parent->exclusive_child == this) {
|
||||
transient_parent->exclusive_child = nullptr;
|
||||
|
@ -519,13 +512,9 @@ void Window::_make_transient() {
|
|||
window->transient_children.insert(this);
|
||||
if (is_inside_tree() && is_visible() && exclusive) {
|
||||
if (transient_parent->exclusive_child == nullptr) {
|
||||
#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()) {
|
||||
transient_parent->exclusive_child = this;
|
||||
}
|
||||
#else
|
||||
transient_parent->exclusive_child = this;
|
||||
#endif
|
||||
} else if (transient_parent->exclusive_child != this) {
|
||||
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;
|
||||
|
||||
if (!embedder && window_id != DisplayServer::INVALID_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))) {
|
||||
DisplayServer::get_singleton()->window_set_exclusive(window_id, exclusive);
|
||||
} else {
|
||||
if (is_in_edited_scene_root()) {
|
||||
DisplayServer::get_singleton()->window_set_exclusive(window_id, false);
|
||||
}
|
||||
#else
|
||||
} else {
|
||||
DisplayServer::get_singleton()->window_set_exclusive(window_id, exclusive);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (transient_parent) {
|
||||
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.");
|
||||
#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()) {
|
||||
transient_parent->exclusive_child = this;
|
||||
}
|
||||
#else
|
||||
transient_parent->exclusive_child = this;
|
||||
#endif
|
||||
} else {
|
||||
if (transient_parent->exclusive_child == this) {
|
||||
transient_parent->exclusive_child = nullptr;
|
||||
|
|
|
@ -234,6 +234,8 @@ public:
|
|||
void set_clamp_to_embedder(bool p_enable);
|
||||
bool is_clamped_to_embedder() const;
|
||||
|
||||
bool is_in_edited_scene_root() const;
|
||||
|
||||
bool can_draw() const;
|
||||
|
||||
void set_ime_active(bool p_active);
|
||||
|
|
Loading…
Reference in a new issue