From 74ce1f87133ad6c52cffe041b22fd8e6825c102c Mon Sep 17 00:00:00 2001 From: Xottab-DUTY Date: Wed, 15 Jan 2025 05:28:38 +0300 Subject: [PATCH] Changed meaning of CUICursor::WarpToWindow's second bool parameter There's no need to change visibility with automatic system in CDialogHolder now. But it's useful to center cursor on something. --- src/xrGame/ui/UIMapFilters.cpp | 2 +- src/xrUICore/Cursor/UICursor.cpp | 25 ++++++++++++------------- src/xrUICore/Cursor/UICursor.h | 2 +- src/xrUICore/ui_focus.cpp | 2 +- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/xrGame/ui/UIMapFilters.cpp b/src/xrGame/ui/UIMapFilters.cpp index a58f631dd60..77c68f11b14 100644 --- a/src/xrGame/ui/UIMapFilters.cpp +++ b/src/xrGame/ui/UIMapFilters.cpp @@ -135,7 +135,7 @@ void CUIMapFilters::SelectFilter(bool select, bool next /*= true*/) if (!select) { m_selected_filter = -1; - cursor.WarpToWindow(nullptr, pInput->IsCurrentInputTypeController()); + cursor.WarpToWindow(nullptr); } else { diff --git a/src/xrUICore/Cursor/UICursor.cpp b/src/xrUICore/Cursor/UICursor.cpp index 46110438485..4b2357e6e5f 100644 --- a/src/xrUICore/Cursor/UICursor.cpp +++ b/src/xrUICore/Cursor/UICursor.cpp @@ -116,28 +116,27 @@ void CUICursor::UpdateCursorPosition(int _dx, int _dy) clamp(vPos.y, 0.f, UI_BASE_HEIGHT); } -void CUICursor::WarpToWindow(const CUIWindow* wnd, bool change_visibility /*= true*/) +void CUICursor::WarpToWindow(const CUIWindow* wnd, bool center /*= false*/) { - // When change_visibility is true, call Show/Hide anyway - // to update autohide data if (!wnd) { - if (change_visibility) - Hide(); + SetUICursorPosition({ UI_BASE_WIDTH / 2.0f, UI_BASE_HEIGHT / 2.0f }); return; } - if (change_visibility) - Show(); - - if (!IsVisible()) - return; - Fvector2 pos; wnd->GetAbsolutePos(pos); Fvector2 size = wnd->GetWndSize(); - const Fvector2 sizeOfThird = Fvector2(size).div(3); - pos.add(size).sub(sizeOfThird); + if (center) + { + size.mul(0.5f); + pos.add(size); + } + else + { + const Fvector2 sizeOfThird = Fvector2(size).div(3.0f); + pos.add(size).sub(sizeOfThird); + } SetUICursorPosition(pos); } diff --git a/src/xrUICore/Cursor/UICursor.h b/src/xrUICore/Cursor/UICursor.h index 13f417c4b30..14ce65083c1 100644 --- a/src/xrUICore/Cursor/UICursor.h +++ b/src/xrUICore/Cursor/UICursor.h @@ -28,7 +28,7 @@ class XRUICORE_API CUICursor : public pureRender, public CDeviceResetNotifier, p void OnDeviceReset() override; void OnUIReset() override; - void WarpToWindow(const CUIWindow* wnd, bool change_visibility = true); + void WarpToWindow(const CUIWindow* wnd, bool center = false); void UpdateCursorPosition(int _dx, int _dy); void SetUICursorPosition(Fvector2 pos); diff --git a/src/xrUICore/ui_focus.cpp b/src/xrUICore/ui_focus.cpp index c5a1afab4ca..0d3fa383639 100644 --- a/src/xrUICore/ui_focus.cpp +++ b/src/xrUICore/ui_focus.cpp @@ -194,7 +194,7 @@ void CUIFocusSystem::Update(const CUIWindow* root) void CUIFocusSystem::SetFocused(const CUIWindow* window) { m_current_focused = window; - UI().GetUICursor().WarpToWindow(window, true); + UI().GetUICursor().WarpToWindow(window); } std::pair CUIFocusSystem::FindClosestFocusable(const Fvector2& from, FocusDirection direction) const