Merge pull request #14826 from carlosfvieira/14371-F_key_Viewport_focus_problem
Fix spatial editor plugin issues on multi viewport view menu shortcuts (only those that are bound to keys)
This commit is contained in:
commit
256a60bc6e
4 changed files with 70 additions and 44 deletions
|
@ -809,17 +809,27 @@ bool SpatialEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_hig
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpatialEditorViewport::_smouseenter() {
|
void SpatialEditorViewport::_surface_mouse_enter() {
|
||||||
|
|
||||||
if (!surface->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field()))
|
if (!surface->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field()))
|
||||||
surface->grab_focus();
|
surface->grab_focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpatialEditorViewport::_smouseexit() {
|
void SpatialEditorViewport::_surface_mouse_exit() {
|
||||||
|
|
||||||
_remove_preview();
|
_remove_preview();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SpatialEditorViewport::_surface_focus_enter() {
|
||||||
|
|
||||||
|
view_menu->set_disable_shortcuts(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpatialEditorViewport::_surface_focus_exit() {
|
||||||
|
|
||||||
|
view_menu->set_disable_shortcuts(true);
|
||||||
|
}
|
||||||
|
|
||||||
void SpatialEditorViewport::_list_select(Ref<InputEventMouseButton> b) {
|
void SpatialEditorViewport::_list_select(Ref<InputEventMouseButton> b) {
|
||||||
|
|
||||||
_find_items_at_pos(b->get_position(), clicked_includes_current, selection_results, b->get_shift());
|
_find_items_at_pos(b->get_position(), clicked_includes_current, selection_results, b->get_shift());
|
||||||
|
@ -1775,51 +1785,36 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ED_IS_SHORTCUT("spatial_editor/bottom_view", p_event)) {
|
if (ED_IS_SHORTCUT("spatial_editor/bottom_view", p_event)) {
|
||||||
cursor.y_rot = 0;
|
_menu_option(VIEW_BOTTOM);
|
||||||
cursor.x_rot = -Math_PI / 2.0;
|
|
||||||
set_message(TTR("Bottom View."), 2);
|
|
||||||
name = TTR("Bottom");
|
|
||||||
_update_name();
|
|
||||||
}
|
}
|
||||||
if (ED_IS_SHORTCUT("spatial_editor/top_view", p_event)) {
|
if (ED_IS_SHORTCUT("spatial_editor/top_view", p_event)) {
|
||||||
cursor.y_rot = 0;
|
_menu_option(VIEW_TOP);
|
||||||
cursor.x_rot = Math_PI / 2.0;
|
|
||||||
set_message(TTR("Top View."), 2);
|
|
||||||
name = TTR("Top");
|
|
||||||
_update_name();
|
|
||||||
}
|
}
|
||||||
if (ED_IS_SHORTCUT("spatial_editor/rear_view", p_event)) {
|
if (ED_IS_SHORTCUT("spatial_editor/rear_view", p_event)) {
|
||||||
cursor.x_rot = 0;
|
_menu_option(VIEW_REAR);
|
||||||
cursor.y_rot = Math_PI;
|
|
||||||
set_message(TTR("Rear View."), 2);
|
|
||||||
name = TTR("Rear");
|
|
||||||
_update_name();
|
|
||||||
}
|
}
|
||||||
if (ED_IS_SHORTCUT("spatial_editor/front_view", p_event)) {
|
if (ED_IS_SHORTCUT("spatial_editor/front_view", p_event)) {
|
||||||
cursor.x_rot = 0;
|
_menu_option(VIEW_FRONT);
|
||||||
cursor.y_rot = 0;
|
|
||||||
set_message(TTR("Front View."), 2);
|
|
||||||
name = TTR("Front");
|
|
||||||
_update_name();
|
|
||||||
}
|
}
|
||||||
if (ED_IS_SHORTCUT("spatial_editor/left_view", p_event)) {
|
if (ED_IS_SHORTCUT("spatial_editor/left_view", p_event)) {
|
||||||
cursor.x_rot = 0;
|
_menu_option(VIEW_LEFT);
|
||||||
cursor.y_rot = Math_PI / 2.0;
|
|
||||||
set_message(TTR("Left View."), 2);
|
|
||||||
name = TTR("Left");
|
|
||||||
_update_name();
|
|
||||||
}
|
}
|
||||||
if (ED_IS_SHORTCUT("spatial_editor/right_view", p_event)) {
|
if (ED_IS_SHORTCUT("spatial_editor/right_view", p_event)) {
|
||||||
cursor.x_rot = 0;
|
_menu_option(VIEW_RIGHT);
|
||||||
cursor.y_rot = -Math_PI / 2.0;
|
}
|
||||||
set_message(TTR("Right View."), 2);
|
if (ED_IS_SHORTCUT("spatial_editor/focus_origin", p_event)) {
|
||||||
name = TTR("Right");
|
_menu_option(VIEW_CENTER_TO_ORIGIN);
|
||||||
_update_name();
|
}
|
||||||
|
if (ED_IS_SHORTCUT("spatial_editor/focus_selection", p_event)) {
|
||||||
|
_menu_option(VIEW_CENTER_TO_SELECTION);
|
||||||
}
|
}
|
||||||
if (ED_IS_SHORTCUT("spatial_editor/switch_perspective_orthogonal", p_event)) {
|
if (ED_IS_SHORTCUT("spatial_editor/switch_perspective_orthogonal", p_event)) {
|
||||||
_menu_option(orthogonal ? VIEW_PERSPECTIVE : VIEW_ORTHOGONAL);
|
_menu_option(orthogonal ? VIEW_PERSPECTIVE : VIEW_ORTHOGONAL);
|
||||||
_update_name();
|
_update_name();
|
||||||
}
|
}
|
||||||
|
if (ED_IS_SHORTCUT("spatial_editor/align_selection_with_view", p_event)) {
|
||||||
|
_menu_option(VIEW_ALIGN_SELECTION_WITH_VIEW);
|
||||||
|
}
|
||||||
if (ED_IS_SHORTCUT("spatial_editor/insert_anim_key", p_event)) {
|
if (ED_IS_SHORTCUT("spatial_editor/insert_anim_key", p_event)) {
|
||||||
if (!get_selected_count() || _edit.mode != TRANSFORM_NONE)
|
if (!get_selected_count() || _edit.mode != TRANSFORM_NONE)
|
||||||
return;
|
return;
|
||||||
|
@ -2229,8 +2224,10 @@ void SpatialEditorViewport::_notification(int p_what) {
|
||||||
|
|
||||||
surface->connect("draw", this, "_draw");
|
surface->connect("draw", this, "_draw");
|
||||||
surface->connect("gui_input", this, "_sinput");
|
surface->connect("gui_input", this, "_sinput");
|
||||||
surface->connect("mouse_entered", this, "_smouseenter");
|
surface->connect("mouse_entered", this, "_surface_mouse_enter");
|
||||||
surface->connect("mouse_exited", this, "_smouseexit");
|
surface->connect("mouse_exited", this, "_surface_mouse_exit");
|
||||||
|
surface->connect("focus_entered", this, "_surface_focus_enter");
|
||||||
|
surface->connect("focus_exited", this, "_surface_focus_exit");
|
||||||
info_label->add_style_override("normal", editor->get_gui_base()->get_stylebox("Information3dViewport", "EditorStyles"));
|
info_label->add_style_override("normal", editor->get_gui_base()->get_stylebox("Information3dViewport", "EditorStyles"));
|
||||||
fps_label->add_style_override("normal", editor->get_gui_base()->get_stylebox("Information3dViewport", "EditorStyles"));
|
fps_label->add_style_override("normal", editor->get_gui_base()->get_stylebox("Information3dViewport", "EditorStyles"));
|
||||||
preview_camera->set_icon(get_icon("Camera", "EditorIcons"));
|
preview_camera->set_icon(get_icon("Camera", "EditorIcons"));
|
||||||
|
@ -2404,47 +2401,54 @@ void SpatialEditorViewport::_menu_option(int p_option) {
|
||||||
|
|
||||||
case VIEW_TOP: {
|
case VIEW_TOP: {
|
||||||
|
|
||||||
cursor.x_rot = Math_PI / 2.0;
|
|
||||||
cursor.y_rot = 0;
|
cursor.y_rot = 0;
|
||||||
|
cursor.x_rot = Math_PI / 2.0;
|
||||||
|
set_message(TTR("Top View."), 2);
|
||||||
name = TTR("Top");
|
name = TTR("Top");
|
||||||
_update_name();
|
_update_name();
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case VIEW_BOTTOM: {
|
case VIEW_BOTTOM: {
|
||||||
|
|
||||||
cursor.x_rot = -Math_PI / 2.0;
|
|
||||||
cursor.y_rot = 0;
|
cursor.y_rot = 0;
|
||||||
|
cursor.x_rot = -Math_PI / 2.0;
|
||||||
|
set_message(TTR("Bottom View."), 2);
|
||||||
name = TTR("Bottom");
|
name = TTR("Bottom");
|
||||||
_update_name();
|
_update_name();
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case VIEW_LEFT: {
|
case VIEW_LEFT: {
|
||||||
|
|
||||||
cursor.y_rot = Math_PI / 2.0;
|
|
||||||
cursor.x_rot = 0;
|
cursor.x_rot = 0;
|
||||||
|
cursor.y_rot = Math_PI / 2.0;
|
||||||
|
set_message(TTR("Left View."), 2);
|
||||||
name = TTR("Left");
|
name = TTR("Left");
|
||||||
_update_name();
|
_update_name();
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case VIEW_RIGHT: {
|
case VIEW_RIGHT: {
|
||||||
|
|
||||||
cursor.y_rot = -Math_PI / 2.0;
|
|
||||||
cursor.x_rot = 0;
|
cursor.x_rot = 0;
|
||||||
|
cursor.y_rot = -Math_PI / 2.0;
|
||||||
|
set_message(TTR("Right View."), 2);
|
||||||
name = TTR("Right");
|
name = TTR("Right");
|
||||||
_update_name();
|
_update_name();
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case VIEW_FRONT: {
|
case VIEW_FRONT: {
|
||||||
|
|
||||||
cursor.y_rot = 0;
|
|
||||||
cursor.x_rot = 0;
|
cursor.x_rot = 0;
|
||||||
|
cursor.y_rot = 0;
|
||||||
|
set_message(TTR("Front View."), 2);
|
||||||
name = TTR("Front");
|
name = TTR("Front");
|
||||||
_update_name();
|
_update_name();
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case VIEW_REAR: {
|
case VIEW_REAR: {
|
||||||
|
|
||||||
cursor.y_rot = Math_PI;
|
|
||||||
cursor.x_rot = 0;
|
cursor.x_rot = 0;
|
||||||
|
cursor.y_rot = Math_PI;
|
||||||
|
set_message(TTR("Rear View."), 2);
|
||||||
name = TTR("Rear");
|
name = TTR("Rear");
|
||||||
_update_name();
|
_update_name();
|
||||||
|
|
||||||
|
@ -2888,8 +2892,11 @@ Dictionary SpatialEditorViewport::get_state() const {
|
||||||
void SpatialEditorViewport::_bind_methods() {
|
void SpatialEditorViewport::_bind_methods() {
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("_draw"), &SpatialEditorViewport::_draw);
|
ClassDB::bind_method(D_METHOD("_draw"), &SpatialEditorViewport::_draw);
|
||||||
ClassDB::bind_method(D_METHOD("_smouseenter"), &SpatialEditorViewport::_smouseenter);
|
|
||||||
ClassDB::bind_method(D_METHOD("_smouseexit"), &SpatialEditorViewport::_smouseexit);
|
ClassDB::bind_method(D_METHOD("_surface_mouse_enter"), &SpatialEditorViewport::_surface_mouse_enter);
|
||||||
|
ClassDB::bind_method(D_METHOD("_surface_mouse_exit"), &SpatialEditorViewport::_surface_mouse_exit);
|
||||||
|
ClassDB::bind_method(D_METHOD("_surface_focus_enter"), &SpatialEditorViewport::_surface_focus_enter);
|
||||||
|
ClassDB::bind_method(D_METHOD("_surface_focus_exit"), &SpatialEditorViewport::_surface_focus_exit);
|
||||||
ClassDB::bind_method(D_METHOD("_sinput"), &SpatialEditorViewport::_sinput);
|
ClassDB::bind_method(D_METHOD("_sinput"), &SpatialEditorViewport::_sinput);
|
||||||
ClassDB::bind_method(D_METHOD("_menu_option"), &SpatialEditorViewport::_menu_option);
|
ClassDB::bind_method(D_METHOD("_menu_option"), &SpatialEditorViewport::_menu_option);
|
||||||
ClassDB::bind_method(D_METHOD("_toggle_camera_preview"), &SpatialEditorViewport::_toggle_camera_preview);
|
ClassDB::bind_method(D_METHOD("_toggle_camera_preview"), &SpatialEditorViewport::_toggle_camera_preview);
|
||||||
|
@ -3356,6 +3363,8 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed
|
||||||
view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/align_selection_with_view"), VIEW_ALIGN_SELECTION_WITH_VIEW);
|
view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/align_selection_with_view"), VIEW_ALIGN_SELECTION_WITH_VIEW);
|
||||||
view_menu->get_popup()->connect("id_pressed", this, "_menu_option");
|
view_menu->get_popup()->connect("id_pressed", this, "_menu_option");
|
||||||
|
|
||||||
|
view_menu->set_disable_shortcuts(true);
|
||||||
|
|
||||||
ED_SHORTCUT("spatial_editor/freelook_left", TTR("Freelook Left"), KEY_A);
|
ED_SHORTCUT("spatial_editor/freelook_left", TTR("Freelook Left"), KEY_A);
|
||||||
ED_SHORTCUT("spatial_editor/freelook_right", TTR("Freelook Right"), KEY_D);
|
ED_SHORTCUT("spatial_editor/freelook_right", TTR("Freelook Right"), KEY_D);
|
||||||
ED_SHORTCUT("spatial_editor/freelook_forward", TTR("Freelook Forward"), KEY_W);
|
ED_SHORTCUT("spatial_editor/freelook_forward", TTR("Freelook Forward"), KEY_W);
|
||||||
|
|
|
@ -273,8 +273,11 @@ private:
|
||||||
Transform to_camera_transform(const Cursor &p_cursor) const;
|
Transform to_camera_transform(const Cursor &p_cursor) const;
|
||||||
void _draw();
|
void _draw();
|
||||||
|
|
||||||
void _smouseenter();
|
void _surface_mouse_enter();
|
||||||
void _smouseexit();
|
void _surface_mouse_exit();
|
||||||
|
void _surface_focus_enter();
|
||||||
|
void _surface_focus_exit();
|
||||||
|
|
||||||
void _sinput(const Ref<InputEvent> &p_event);
|
void _sinput(const Ref<InputEvent> &p_event);
|
||||||
void _update_freelook(real_t delta);
|
void _update_freelook(real_t delta);
|
||||||
SpatialEditor *spatial_editor;
|
SpatialEditor *spatial_editor;
|
||||||
|
|
|
@ -33,6 +33,9 @@
|
||||||
|
|
||||||
void MenuButton::_unhandled_key_input(Ref<InputEvent> p_event) {
|
void MenuButton::_unhandled_key_input(Ref<InputEvent> p_event) {
|
||||||
|
|
||||||
|
if (disable_shortcuts)
|
||||||
|
return;
|
||||||
|
|
||||||
if (p_event->is_pressed() && !p_event->is_echo() && (Object::cast_to<InputEventKey>(p_event.ptr()) || Object::cast_to<InputEventJoypadButton>(p_event.ptr()) || Object::cast_to<InputEventAction>(*p_event))) {
|
if (p_event->is_pressed() && !p_event->is_echo() && (Object::cast_to<InputEventKey>(p_event.ptr()) || Object::cast_to<InputEventJoypadButton>(p_event.ptr()) || Object::cast_to<InputEventAction>(*p_event))) {
|
||||||
|
|
||||||
if (!get_parent() || !is_visible_in_tree() || is_disabled())
|
if (!get_parent() || !is_visible_in_tree() || is_disabled())
|
||||||
|
@ -98,14 +101,22 @@ void MenuButton::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("_unhandled_key_input"), &MenuButton::_unhandled_key_input);
|
ClassDB::bind_method(D_METHOD("_unhandled_key_input"), &MenuButton::_unhandled_key_input);
|
||||||
ClassDB::bind_method(D_METHOD("_set_items"), &MenuButton::_set_items);
|
ClassDB::bind_method(D_METHOD("_set_items"), &MenuButton::_set_items);
|
||||||
ClassDB::bind_method(D_METHOD("_get_items"), &MenuButton::_get_items);
|
ClassDB::bind_method(D_METHOD("_get_items"), &MenuButton::_get_items);
|
||||||
|
ClassDB::bind_method(D_METHOD("set_disable_shortcuts", "disabled"), &MenuButton::set_disable_shortcuts);
|
||||||
|
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "items", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_items", "_get_items");
|
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "items", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_items", "_get_items");
|
||||||
|
|
||||||
ADD_SIGNAL(MethodInfo("about_to_show"));
|
ADD_SIGNAL(MethodInfo("about_to_show"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MenuButton::set_disable_shortcuts(bool p_disabled) {
|
||||||
|
|
||||||
|
disable_shortcuts = p_disabled;
|
||||||
|
}
|
||||||
|
|
||||||
MenuButton::MenuButton() {
|
MenuButton::MenuButton() {
|
||||||
|
|
||||||
set_flat(true);
|
set_flat(true);
|
||||||
|
set_disable_shortcuts(false);
|
||||||
set_enabled_focus_mode(FOCUS_NONE);
|
set_enabled_focus_mode(FOCUS_NONE);
|
||||||
popup = memnew(PopupMenu);
|
popup = memnew(PopupMenu);
|
||||||
popup->hide();
|
popup->hide();
|
||||||
|
|
|
@ -40,6 +40,7 @@ class MenuButton : public Button {
|
||||||
GDCLASS(MenuButton, Button);
|
GDCLASS(MenuButton, Button);
|
||||||
|
|
||||||
bool clicked;
|
bool clicked;
|
||||||
|
bool disable_shortcuts;
|
||||||
PopupMenu *popup;
|
PopupMenu *popup;
|
||||||
virtual void pressed();
|
virtual void pressed();
|
||||||
|
|
||||||
|
@ -54,6 +55,8 @@ protected:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PopupMenu *get_popup();
|
PopupMenu *get_popup();
|
||||||
|
void set_disable_shortcuts(bool p_disabled);
|
||||||
|
|
||||||
MenuButton();
|
MenuButton();
|
||||||
~MenuButton();
|
~MenuButton();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue