Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functions to set in game Cursor Color for client #3558

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
9c2a471
cursor color function
Proxy-99 Jul 7, 2024
dc4f25d
fix wrong swap
Proxy-99 Jul 7, 2024
db2d63a
fixes swap parameters
Proxy-99 Jul 7, 2024
f5382f3
fixes , add getCursorColor
Proxy-99 Jul 8, 2024
425e344
on reconnect reset values
Proxy-99 Jul 8, 2024
ff33395
Merge branch 'master' into cursor
Proxy-99 Jul 9, 2024
0e98917
review fixes
Proxy-99 Jul 9, 2024
f1e256d
bug fix when using setCursorAlpha and start resource using F8 won't r…
Proxy-99 Jul 9, 2024
3cf01a2
refactor setCursorAlpha
Proxy-99 Jul 9, 2024
2b8febc
menu cursor color fix
Proxy-99 Jul 11, 2024
b05c646
reset color correctly
Proxy-99 Jul 11, 2024
2a53605
clean up
Proxy-99 Jul 11, 2024
0303d57
bug fix of values
Proxy-99 Jul 11, 2024
d75c3d8
Merge branch 'master' into cursor
Proxy-99 Jul 11, 2024
4279002
float fixes
Proxy-99 Jul 11, 2024
f62c161
tederis review fixes
Proxy-99 Jul 13, 2024
b645694
review 2 tracer
Proxy-99 Jul 13, 2024
58f2b02
small fix for useless if condition
Proxy-99 Jul 13, 2024
127efaa
simplify
Proxy-99 Jul 13, 2024
24e5809
typos
Proxy-99 Jul 13, 2024
1331fc9
Merge branch 'master' into cursor
Proxy-99 Jul 16, 2024
c61f033
review fixes
Proxy-99 Jul 16, 2024
1f5aae9
noexcept
Proxy-99 Jul 16, 2024
acd0139
Merge branch 'master' into cursor
Proxy-99 Jul 16, 2024
468f3db
Merge branch 'master' into cursor
Proxy-99 Sep 4, 2024
32b268d
Merge branch 'master' into cursor
Proxy-99 Nov 6, 2024
e836bfe
Merge branch 'master' into cursor
Proxy-99 Dec 15, 2024
b29f780
Merge branch 'master' into cursor
Proxy-99 Jan 4, 2025
e384afd
make arguments optional
Proxy-99 Jan 5, 2025
f8e81e0
Merge branch 'master' into cursor
Proxy-99 Jan 5, 2025
97b3e66
alpha to work with range 0 to 255
Proxy-99 Jan 5, 2025
e505b75
remove setAlpha
Proxy-99 Jan 5, 2025
81d0a4d
part 2
Proxy-99 Jan 5, 2025
4727877
override and fixes
Proxy-99 Jan 5, 2025
d6afa43
Merge branch 'master' into cursor
Proxy-99 Jan 5, 2025
23b2b6f
review
Proxy-99 Jan 6, 2025
2ab8d6b
Merge branch 'cursor' of https://github.com/Proxy-99/mtasa-blue into …
Proxy-99 Jan 6, 2025
7ca3bba
Merge branch 'master' into cursor
Proxy-99 Jan 6, 2025
f7540f3
Merge branch 'master' into cursor
Proxy-99 Jan 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Client/core/CCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ bool CCore::IsSettingsVisible()
return false;
}

bool CCore::IsMenuVisible()
bool CCore::IsMenuVisible() const noexcept
{
if (m_pLocalGUI)
{
Expand Down
2 changes: 1 addition & 1 deletion Client/core/CCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class CCore : public CCoreInterface, public CSingleton<CCore>

// GUI
bool IsSettingsVisible();
bool IsMenuVisible();
bool IsMenuVisible() const noexcept;
bool IsCursorForcedVisible();
bool IsCursorControlsToggled() { return m_bCursorToggleControls; }
void HideMainMenu();
Expand Down
12 changes: 2 additions & 10 deletions Client/core/CGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions Client/core/CMainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion Client/core/CMainMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions Client/core/CMessageLoopHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions Client/core/CModManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
43 changes: 39 additions & 4 deletions Client/gui/CGUI_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Proxy-99 marked this conversation as resolved.
Show resolved Hide resolved
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);
}
Proxy-99 marked this conversation as resolved.
Show resolved Hide resolved

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()
Expand Down
14 changes: 11 additions & 3 deletions Client/gui/CGUI_Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions Client/mods/deathmatch/logic/CClientGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 20 additions & 1 deletion Client/mods/deathmatch/logic/luadefs/CLuaClientDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ void CLuaClientDefs::LoadFunctions()
{"isChatInputBlocked", ArgumentParser<IsChatInputBlocked>},
{"clearDebugBox", ArgumentParser<ClearDebug>},
{"isMTAWindowFocused", ArgumentParser<IsMTAWindowFocused>},
{"isCapsLockEnabled", ArgumentParser<IsCapsLockEnabled>}};
{"isCapsLockEnabled", ArgumentParser<IsCapsLockEnabled>},
{"setCursorColor", ArgumentParser<SetCursorColor>},
{"getCursorColor", ArgumentParser<GetCursorColor>}};
Proxy-99 marked this conversation as resolved.
Show resolved Hide resolved

for (const auto& [name, func] : functions)
CLuaCFunctions::AddFunction(name, func);
Expand Down Expand Up @@ -80,3 +82,20 @@ bool CLuaClientDefs::IsCapsLockEnabled()
{
return ((::GetKeyState(VK_CAPITAL) & 0x0001) != 0);
}

bool CLuaClientDefs::SetCursorColor(std::optional<float> r, std::optional<float> g, std::optional<float> b, std::optional<float> alpha) noexcept
{
if (!g_pCore->IsMenuVisible())
Proxy-99 marked this conversation as resolved.
Show resolved Hide resolved
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<float, float, float, float> CLuaClientDefs::GetCursorColor() noexcept
{
float r, g, b, alpha;
g_pCore->GetGUI()->GetCursorColor(r, g, b, alpha);
return {r, g, b, alpha};
Proxy-99 marked this conversation as resolved.
Show resolved Hide resolved
}
3 changes: 3 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaClientDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class CLuaClientDefs : public CLuaDefs
public:
static void LoadFunctions();

static bool SetCursorColor(std::optional<float> r, std::optional<float> g, std::optional<float> b, std::optional<float> alpha) noexcept;
static CLuaMultiReturn<float, float, float, float> GetCursorColor() noexcept;

private:
static bool SetTransferBoxVisible(bool visible);
static bool IsTransferBoxVisible();
Expand Down
2 changes: 1 addition & 1 deletion Client/sdk/core/CCoreInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions Client/sdk/gui/CGUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion vendor/cegui-0.4.0-custom/include/CEGUIColourRect.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;


/*!
Expand Down
3 changes: 2 additions & 1 deletion vendor/cegui-0.4.0-custom/include/CEGUIMouseCursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ class CEGUIEXPORT MouseCursor : public EventSet, public Singleton<MouseCursor>
\return
Nothing.
*/
void setAlpha(float alpha);

void setColor(float r, float g, float b, float alpha) noexcept;

/*!
\brief
Expand Down
2 changes: 1 addition & 1 deletion vendor/cegui-0.4.0-custom/src/CEGUIColourRect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 3 additions & 5 deletions vendor/cegui-0.4.0-custom/src/CEGUIMouseCursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading