diff --git a/Client/core/CCore.cpp b/Client/core/CCore.cpp index 12e8cf81d54..6cdfc38b9bf 100644 --- a/Client/core/CCore.cpp +++ b/Client/core/CCore.cpp @@ -588,7 +588,7 @@ bool CCore::IsSettingsVisible() return false; } -bool CCore::IsMenuVisible() +bool CCore::IsMenuVisible() const noexcept { if (m_pLocalGUI) { diff --git a/Client/core/CCore.h b/Client/core/CCore.h index 3439a484ded..acef17b3e8d 100644 --- a/Client/core/CCore.h +++ b/Client/core/CCore.h @@ -138,7 +138,7 @@ class CCore : public CCoreInterface, public CSingleton // GUI bool IsSettingsVisible(); - bool IsMenuVisible(); + bool IsMenuVisible() const noexcept; bool IsCursorForcedVisible(); bool IsCursorControlsToggled() { return m_bCursorToggleControls; } void HideMainMenu(); diff --git a/Client/core/CGUI.cpp b/Client/core/CGUI.cpp index 62735363475..77ad97d1138 100644 --- a/Client/core/CGUI.cpp +++ b/Client/core/CGUI.cpp @@ -385,12 +385,6 @@ void CLocalGUI::SetConsoleVisible(bool bVisible) // Set the visible state m_pConsole->SetVisible(bVisible); - - CGUI* pGUI = CCore::GetSingleton().GetGUI(); - if (bVisible) - pGUI->SetCursorAlpha(1.0f); - else if (!g_pCore->IsMenuVisible()) - pGUI->SetCursorAlpha(pGUI->GetCurrentServerCursorAlpha()); } } @@ -434,10 +428,8 @@ void CLocalGUI::SetMainMenuVisible(bool bVisible) else { pGUI->SelectInputHandlers(INPUT_MOD); - } - - if (!bVisible) - pGUI->SetCursorAlpha(pGUI->GetCurrentServerCursorAlpha()); + pGUI->RestoreCurrentServerCursorColor(); // Restore the cursor color when we close the main menu + } } } diff --git a/Client/core/CMainMenu.cpp b/Client/core/CMainMenu.cpp index 1ef82a75c6e..b3007a3b07b 100644 --- a/Client/core/CMainMenu.cpp +++ b/Client/core/CMainMenu.cpp @@ -606,7 +606,7 @@ void CMainMenu::Update() if (pGUI) { - pGUI->SetCursorAlpha(1.0f); + pGUI->ResetMenuCursorColor(); // Reset cursor menu color when we open up main menu m_bCursorAlphaReset = true; } } @@ -792,7 +792,7 @@ void CMainMenu::SetVisible(bool bVisible, bool bOverlay, bool bFrameDelay) m_bHideGame = !bOverlay; } -bool CMainMenu::IsVisible() +bool CMainMenu::IsVisible() const noexcept { return m_bIsVisible; } diff --git a/Client/core/CMainMenu.h b/Client/core/CMainMenu.h index 72b549f01ee..c005a04ad5d 100644 --- a/Client/core/CMainMenu.h +++ b/Client/core/CMainMenu.h @@ -51,7 +51,7 @@ class CMainMenu void Hide(); void SetVisible(bool bVisible, bool bOverlay = true, bool bFrameDelay = true); - bool IsVisible(); + bool IsVisible() const noexcept; bool IsFading() { return m_ucFade == FADE_IN || m_ucFade == FADE_OUT; } void SetIsIngame(bool bIsIngame); diff --git a/Client/core/CMessageLoopHook.cpp b/Client/core/CMessageLoopHook.cpp index 5424e23435c..841bb6fc832 100644 --- a/Client/core/CMessageLoopHook.cpp +++ b/Client/core/CMessageLoopHook.cpp @@ -295,9 +295,10 @@ LRESULT CALLBACK CMessageLoopHook::ProcessMessage(HWND hwnd, UINT uMsg, WPARAM w pConsole->SetVisible(false); CGUI* pGUI = g_pCore->GetGUI(); - if (!g_pCore->IsMenuVisible()) - pGUI->SetCursorAlpha(pGUI->GetCurrentServerCursorAlpha()); + if (!g_pCore->IsMenuVisible()) + pGUI->RestoreCurrentServerCursorColor(); + return true; } diff --git a/Client/core/CModManager.cpp b/Client/core/CModManager.cpp index d1e15b10b9d..50821674d01 100644 --- a/Client/core/CModManager.cpp +++ b/Client/core/CModManager.cpp @@ -217,8 +217,8 @@ void CModManager::Unload() CCore::GetSingleton().SetClientMessageProcessor(NULL); CCore::GetSingleton().GetCommands()->SetExecuteHandler(NULL); - // Reset cursor alpha - CCore::GetSingleton().GetGUI()->SetCursorAlpha(1.0f, true); + // Reset cursor color + CCore::GetSingleton().GetGUI()->ResetCursorColorVariables(); // Reset the modules CCore::GetSingleton().GetGame()->Reset(); diff --git a/Client/gui/CGUI_Impl.cpp b/Client/gui/CGUI_Impl.cpp index 67d625ed5ec..d5afc95ace1 100644 --- a/Client/gui/CGUI_Impl.cpp +++ b/Client/gui/CGUI_Impl.cpp @@ -30,7 +30,7 @@ using std::list; #define CGUI_SA_GOTHIC_SIZE 47 #define CGUI_MTA_SANS_FONT_SIZE 9 -CGUI_Impl::CGUI_Impl(IDirect3DDevice9* pDevice) : m_HasSchemeLoaded(false), m_fCurrentServerCursorAlpha(1.0f) +CGUI_Impl::CGUI_Impl(IDirect3DDevice9* pDevice) : m_HasSchemeLoaded(false), CurrentServerCursorAlpha(255.0f) { m_RenderOkTimer.SetMaxIncrement(100); @@ -496,20 +496,55 @@ bool CGUI_Impl::IsCursorEnabled() void CGUI_Impl::SetCursorAlpha(float fAlpha, bool bOnlyCurrentServer) { - CEGUI::MouseCursor::getSingleton().setAlpha(fAlpha); + CEGUI::MouseCursor::getSingleton().setColor(CurrentServerCursorRed, CurrentServerCursorGreen, CurrentServerCursorBlue, fAlpha); if (bOnlyCurrentServer) SetCurrentServerCursorAlpha(fAlpha); } +void CGUI_Impl::SetCursorColor(float r, float g, float b, float alpha) noexcept +{ + CEGUI::MouseCursor::getSingleton().setColor(r, g, b, alpha); + CurrentServerCursorRed = r; + CurrentServerCursorGreen = g; + CurrentServerCursorBlue = b; + CurrentServerCursorAlpha = alpha; +} + +void CGUI_Impl::GetCursorColor(float& r, float& g, float& b, float& alpha) noexcept +{ + r = CurrentServerCursorRed; + g = CurrentServerCursorGreen; + b = CurrentServerCursorBlue; + alpha = CurrentServerCursorAlpha; +} + +void CGUI_Impl::ResetMenuCursorColor() noexcept +{ + CEGUI::MouseCursor::getSingleton().setColor(255.0f, 255.0f, 255.0f, 255.0f); +} + +void CGUI_Impl::ResetCursorColorVariables() noexcept +{ + CurrentServerCursorRed = 255.f; + CurrentServerCursorGreen = 255.f; + CurrentServerCursorBlue = 255.f; + CurrentServerCursorAlpha = 255.f; +} + +void CGUI_Impl::RestoreCurrentServerCursorColor() noexcept +{ + CEGUI::MouseCursor::getSingleton().setColor(CurrentServerCursorRed, CurrentServerCursorGreen, CurrentServerCursorBlue, CurrentServerCursorAlpha); +} + void CGUI_Impl::SetCurrentServerCursorAlpha(float fAlpha) { - m_fCurrentServerCursorAlpha = fAlpha; + CurrentServerCursorAlpha = fAlpha; } float CGUI_Impl::GetCurrentServerCursorAlpha() { - return m_fCurrentServerCursorAlpha; + return CurrentServerCursorAlpha; } eCursorType CGUI_Impl::GetCursorType() diff --git a/Client/gui/CGUI_Impl.h b/Client/gui/CGUI_Impl.h index 30153808665..d4ce2000f0d 100644 --- a/Client/gui/CGUI_Impl.h +++ b/Client/gui/CGUI_Impl.h @@ -142,9 +142,14 @@ class CGUI_Impl : public CGUI, public CGUITabList void SetCursorEnabled(bool bEnabled); bool IsCursorEnabled(); - void SetCursorAlpha(float fAlpha, bool bOnlyCurrentServer = false); - void SetCurrentServerCursorAlpha(float fAlpha); + void SetCursorAlpha(float fAlpha, bool bOnlyCurrentServer = false) override; + void SetCurrentServerCursorAlpha(float fAlpha) override; float GetCurrentServerCursorAlpha(); + void SetCursorColor(float r, float g, float b, float alpha) noexcept override; + void GetCursorColor(float& r, float& g, float& b, float& alpha) noexcept override; + void ResetMenuCursorColor() noexcept override; + void RestoreCurrentServerCursorColor() noexcept override; + void ResetCursorColorVariables() noexcept override; eCursorType GetCursorType(); void AddChild(CGUIElement_Impl* pChild); @@ -311,7 +316,10 @@ class CGUI_Impl : public CGUI, public CGUITabList CEGUI::DefaultWindow* m_pTop; const CEGUI::Image* m_pCursor; - float m_fCurrentServerCursorAlpha; + float CurrentServerCursorAlpha = {255.0f}; + float CurrentServerCursorRed = {255.0f}; + float CurrentServerCursorGreen = {255.0f}; + float CurrentServerCursorBlue = {255.0f}; CGUIFont_Impl* m_pDefaultFont; CGUIFont_Impl* m_pSmallFont; diff --git a/Client/mods/deathmatch/logic/CClientGame.cpp b/Client/mods/deathmatch/logic/CClientGame.cpp index dcb73b17389..be01bd06a65 100644 --- a/Client/mods/deathmatch/logic/CClientGame.cpp +++ b/Client/mods/deathmatch/logic/CClientGame.cpp @@ -3447,6 +3447,9 @@ void CClientGame::Event_OnIngame() // Reset weapon render g_pGame->SetWeaponRenderEnabled(true); + + // Reset cursor color + g_pCore->GetGUI()->ResetCursorColorVariables(); // Make sure we can access all areas g_pGame->GetStats()->ModifyStat(CITIES_PASSED, 2.0); diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index fdb7a897a88..67aa17c3349 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -5120,7 +5120,7 @@ bool CStaticFunctionDefinitions::SetCursorAlpha(float fAlpha) { if (fAlpha >= 0.0f && fAlpha <= 1.0f) { - if (!m_pCore->IsMenuVisible() && !m_pCore->GetConsole()->IsVisible()) + if (!m_pCore->IsMenuVisible()) m_pGUI->SetCursorAlpha(fAlpha, true); else m_pGUI->SetCurrentServerCursorAlpha(fAlpha); diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaClientDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaClientDefs.cpp index 2d9e72c340a..1a0ae36d43f 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaClientDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaClientDefs.cpp @@ -23,7 +23,9 @@ void CLuaClientDefs::LoadFunctions() {"isChatInputBlocked", ArgumentParser}, {"clearDebugBox", ArgumentParser}, {"isMTAWindowFocused", ArgumentParser}, - {"isCapsLockEnabled", ArgumentParser}}; + {"isCapsLockEnabled", ArgumentParser}, + {"setCursorColor", ArgumentParser}, + {"getCursorColor", ArgumentParser}}; for (const auto& [name, func] : functions) CLuaCFunctions::AddFunction(name, func); @@ -80,3 +82,20 @@ bool CLuaClientDefs::IsCapsLockEnabled() { return ((::GetKeyState(VK_CAPITAL) & 0x0001) != 0); } + +bool CLuaClientDefs::SetCursorColor(std::optional r, std::optional g, std::optional b, std::optional alpha) noexcept +{ + if (!g_pCore->IsMenuVisible()) + g_pCore->GetGUI()->SetCursorColor(r.value_or(255.0f), g.value_or(255.0f), b.value_or(255.0f), alpha.value_or(255.0f)); + else + g_pCore->GetGUI()->ResetCursorColorVariables(); // Force variables to be updated when close the main menu it will set the new color + + return true; +} + +CLuaMultiReturn CLuaClientDefs::GetCursorColor() noexcept +{ + float r, g, b, alpha; + g_pCore->GetGUI()->GetCursorColor(r, g, b, alpha); + return {r, g, b, alpha}; +} diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaClientDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaClientDefs.h index 7b3b276b83e..36ac8b0fd68 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaClientDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaClientDefs.h @@ -18,6 +18,9 @@ class CLuaClientDefs : public CLuaDefs public: static void LoadFunctions(); + static bool SetCursorColor(std::optional r, std::optional g, std::optional b, std::optional alpha) noexcept; + static CLuaMultiReturn GetCursorColor() noexcept; + private: static bool SetTransferBoxVisible(bool visible); static bool IsTransferBoxVisible(); diff --git a/Client/sdk/core/CCoreInterface.h b/Client/sdk/core/CCoreInterface.h index c591d546e5e..1a31048f014 100644 --- a/Client/sdk/core/CCoreInterface.h +++ b/Client/sdk/core/CCoreInterface.h @@ -100,7 +100,7 @@ class CCoreInterface virtual void EnableChatInput(char* szCommand, DWORD dwColor) = 0; virtual bool IsChatInputEnabled() = 0; virtual bool IsSettingsVisible() = 0; - virtual bool IsMenuVisible() = 0; + virtual bool IsMenuVisible() const noexcept = 0; virtual bool IsCursorForcedVisible() = 0; virtual bool IsCursorControlsToggled() = 0; virtual void CallSetCursorPos(int X, int Y) = 0; diff --git a/Client/sdk/gui/CGUI.h b/Client/sdk/gui/CGUI.h index d6e27bd3da5..dbf6ffed15a 100644 --- a/Client/sdk/gui/CGUI.h +++ b/Client/sdk/gui/CGUI.h @@ -126,6 +126,11 @@ class CGUI virtual void SetCursorEnabled(bool bEnabled) = 0; virtual bool IsCursorEnabled() = 0; virtual void SetCursorAlpha(float fAlpha, bool bOnlyCurrentServer = false) = 0; + virtual void SetCursorColor(float r, float g, float b, float alpha) noexcept = 0; + virtual void GetCursorColor(float& r, float& g, float& b, float& alpha) noexcept = 0; + virtual void ResetMenuCursorColor() noexcept = 0; + virtual void ResetCursorColorVariables() noexcept = 0; + virtual void RestoreCurrentServerCursorColor() noexcept = 0; virtual void SetCurrentServerCursorAlpha(float fAlpha) = 0; virtual float GetCurrentServerCursorAlpha() = 0; virtual eCursorType GetCursorType() = 0; diff --git a/vendor/cegui-0.4.0-custom/include/CEGUIColourRect.h b/vendor/cegui-0.4.0-custom/include/CEGUIColourRect.h index abd814a5cc4..13457e350a9 100644 --- a/vendor/cegui-0.4.0-custom/include/CEGUIColourRect.h +++ b/vendor/cegui-0.4.0-custom/include/CEGUIColourRect.h @@ -176,7 +176,7 @@ class CEGUIEXPORT ColourRect \param col colour that is to be set for all four corners of the ColourRect; */ - void setColours(const colour& col); + void setColours(const colour& col) noexcept; /*! diff --git a/vendor/cegui-0.4.0-custom/include/CEGUIMouseCursor.h b/vendor/cegui-0.4.0-custom/include/CEGUIMouseCursor.h index 27682e2efd1..a51a3aca854 100644 --- a/vendor/cegui-0.4.0-custom/include/CEGUIMouseCursor.h +++ b/vendor/cegui-0.4.0-custom/include/CEGUIMouseCursor.h @@ -187,7 +187,8 @@ class CEGUIEXPORT MouseCursor : public EventSet, public Singleton \return Nothing. */ - void setAlpha(float alpha); + + void setColor(float r, float g, float b, float alpha) noexcept; /*! \brief diff --git a/vendor/cegui-0.4.0-custom/src/CEGUIColourRect.cpp b/vendor/cegui-0.4.0-custom/src/CEGUIColourRect.cpp index a30077f911f..031d18aebdd 100644 --- a/vendor/cegui-0.4.0-custom/src/CEGUIColourRect.cpp +++ b/vendor/cegui-0.4.0-custom/src/CEGUIColourRect.cpp @@ -154,7 +154,7 @@ ColourRect ColourRect::getSubRectangle( float left, float right, float top, floa /************************************************************************* Set the colour of all four corners simultaneously. *************************************************************************/ -void ColourRect::setColours(const colour& col) +void ColourRect::setColours(const colour& col) noexcept { d_top_left = d_top_right = d_bottom_left = d_bottom_right = col; } diff --git a/vendor/cegui-0.4.0-custom/src/CEGUIMouseCursor.cpp b/vendor/cegui-0.4.0-custom/src/CEGUIMouseCursor.cpp index 5c8b12db41e..119da7b8147 100644 --- a/vendor/cegui-0.4.0-custom/src/CEGUIMouseCursor.cpp +++ b/vendor/cegui-0.4.0-custom/src/CEGUIMouseCursor.cpp @@ -147,14 +147,12 @@ void MouseCursor::offsetPosition(const Point& offset) /************************************************************************* - Set the mouse cursor's alpha + Set the mouse cursor's color *************************************************************************/ -void MouseCursor::setAlpha(float alpha) +void MouseCursor::setColor(float r, float g, float b, float alpha) noexcept { - d_colourRect.setColours(colour(1.0f, 1.0f, 1.0f, alpha)); + d_colourRect.setColours(colour(r/255.f, g/255.f, b/255.f, alpha/255.f)); } - - /************************************************************************* Checks the mouse cursor position is within the current 'constrain' Rect and adjusts as required.