Skip to content

Commit

Permalink
Basic cursor demand system implementation (#943)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Dec 23, 2024
1 parent 482d6df commit a278e3f
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/xrGame/ui/UIDialogWnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CUIDialogWnd : public CUIWindow
CUIFocusSystem* GetCurrentFocusSystem() const override { return GetHolder(); }

virtual bool StopAnyMove() { return true; }
virtual bool NeedCursor() const { return true; }
virtual bool NeedCursor() const { return pInput->IsCurrentInputTypeKeyboardMouse(); }
virtual bool NeedCenterCursor() const { return true; }
virtual bool WorkInPause() const { return m_bWorkInPause; }
virtual bool Dispatch(int cmd, int param) { return true; }
Expand Down
8 changes: 8 additions & 0 deletions src/xrGame/ui/UIPdaWnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,14 @@ void CUIPdaWnd::DrawHint()
m_hint_wnd->Draw();
}

bool CUIPdaWnd::NeedCursor() const
{
if (m_pActiveDialog && m_pActiveDialog->IsUsingCursorRightNow())
return true;

return CUIDialogWnd::NeedCursor();
}

void CUIPdaWnd::UpdatePda()
{
if (pUILogsWnd)
Expand Down
3 changes: 2 additions & 1 deletion src/xrGame/ui/UIPdaWnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ class CUIPdaWnd final : public CUIDialogWnd
void SetActiveSubdialog(const shared_str& section);
CUITabControl* GetTabControl() const { return UITabControl; }

virtual bool StopAnyMove() { return false; }
bool StopAnyMove() override { return false; }
bool NeedCursor() const override;
void UpdatePda();
void UpdateRankingWnd();

Expand Down
14 changes: 14 additions & 0 deletions src/xrGame/ui/UIScriptWnd_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ struct CUIDialogWndExWrapperBase final : public CUIDialogWndEx, public luabind::
return ptr->self_type::inherited::Dispatch(cmd, param);
}

bool NeedCursor() const override
{
if (luabind::call_member<bool>(this, "NeedCursor"))
return true;
return inherited::NeedCursor();
}

static bool NeedCursor_static(inherited* ptr)
{
return ptr->self_type::inherited::NeedCursor();
}

pcstr GetDebugType() override { return "CUIScriptWnd"; }

bool FillDebugTree(const CUIDebugState& debugState) override
Expand Down Expand Up @@ -222,6 +234,8 @@ SCRIPT_EXPORT(CUIDialogWndEx, (CUIDialogWnd, IFactoryObject),
.def("Dispatch", &BaseType::Dispatch, &WrapType::Dispatch_static)
.def("Load", &BaseType::Load)

.def("NeedCursor", &BaseType::NeedCursor, &WrapType::NeedCursor_static)

.def("GetButton", &BaseType::GetControl<CUIButton>)
.def("GetMessageBox", &BaseType::GetControl<CUIMessageBox>)
.def("GetPropertiesBox",&BaseType::GetControl<CUIPropertiesBox>)
Expand Down
5 changes: 5 additions & 0 deletions src/xrGame/ui/UITaskWnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ void CUITaskWnd::Show_TaskListWnd(bool status) const
m_task_wnd->Show(status);
}

bool CUITaskWnd::IsUsingCursorRightNow() const
{
return m_pKeyboardCapturer == &m_filters;
}

void CUITaskWnd::TaskSetTargetMap(CGameTask* task) const
{
if (!task || !IsSecondaryTasksEnabled())
Expand Down
2 changes: 2 additions & 0 deletions src/xrGame/ui/UITaskWnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class CUITaskWnd final : public CUIWindow, public CUIWndCallback
void SecondaryTasksEnabled(bool enable) { m_filters.SetFilterEnabled(CUIMapFilters::SecondaryTasks, enable); }
void PrimaryObjectsEnabled(bool enable) { m_filters.SetFilterEnabled(CUIMapFilters::PrimaryObjects, enable); }

bool IsUsingCursorRightNow() const override;

private:
void TaskSetTargetMap(CGameTask* task) const;
void TaskShowMapSpot(CGameTask* task, bool show) const;
Expand Down
3 changes: 3 additions & 0 deletions src/xrUICore/Cursor/UICursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ void CUICursor::WarpToWindow(CUIWindow* wnd, bool change_visibility /*= true*/)
if (change_visibility)
Show();

if (!IsVisible())
return;

Fvector2 pos;
wnd->GetAbsolutePos(pos);
Fvector2 size = wnd->GetWndSize();
Expand Down
3 changes: 3 additions & 0 deletions src/xrUICore/Windows/UIWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ class XRUICORE_API CUIWindow : public CUISimpleWindow, public CUIDebuggable

CUIWindow* FindChild(const shared_str name);

[[nodiscard]]
virtual bool IsUsingCursorRightNow() const { return false; }

[[nodiscard]]
IC bool CursorOverWindow() const { return m_bCursorOverWindow; }

Expand Down
1 change: 1 addition & 0 deletions src/xrUICore/Windows/UIWindow_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ SCRIPT_EXPORT(CUIWindow, (),
.def("IsAutoDelete", &CUIWindow::IsAutoDelete)

.def("IsCursorOverWindow", &CUIWindow::CursorOverWindow)
.def("IsUsingCursorRightNow", &CUIWindow::IsUsingCursorRightNow)
.def("FocusReceiveTime", &CUIWindow::FocusReceiveTime)
.def("GetAbsoluteRect", &CUIWindow::GetAbsoluteRect)

Expand Down

0 comments on commit a278e3f

Please sign in to comment.