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 27 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
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
2 changes: 1 addition & 1 deletion 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
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()->ResetCursorColor(255.f, 255.f, 255.f, 1.f);

// Reset the modules
CCore::GetSingleton().GetGame()->Reset();
Expand Down
37 changes: 36 additions & 1 deletion Client/gui/CGUI_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,12 +496,47 @@ bool CGUI_Impl::IsCursorEnabled()

void CGUI_Impl::SetCursorAlpha(float fAlpha, bool bOnlyCurrentServer)
{
CEGUI::MouseCursor::getSingleton().setAlpha(fAlpha);
CEGUI::MouseCursor::getSingleton().setAlpha(m_fCurrentServerCursorRed, m_fCurrentServerCursorGreen, m_fCurrentServerCursorBlue, fAlpha);
Proxy-99 marked this conversation as resolved.
Show resolved Hide resolved

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
m_fCurrentServerCursorRed = r;
m_fCurrentServerCursorGreen = g;
m_fCurrentServerCursorBlue = b;
m_fCurrentServerCursorAlpha = alpha;
}

void CGUI_Impl::GetCursorColor(float& r, float& g, float& b, float& alpha) noexcept
{
r = m_fCurrentServerCursorRed;
g = m_fCurrentServerCursorGreen;
b = m_fCurrentServerCursorBlue;
alpha = m_fCurrentServerCursorAlpha;
}

void CGUI_Impl::ResetMenuCursorColor() noexcept
{
CEGUI::MouseCursor::getSingleton().setColor(255.0f, 255.0f, 255.0f, 1.0f);
}

void CGUI_Impl::ResetCursorColor(float r, float g, float b, float alpha) noexcept
{
m_fCurrentServerCursorRed = r;
m_fCurrentServerCursorGreen = g;
m_fCurrentServerCursorBlue = b;
m_fCurrentServerCursorAlpha = alpha;
}

void CGUI_Impl::RestoreCurrentServerCursorColor() noexcept
{
CEGUI::MouseCursor::getSingleton().setColor(m_fCurrentServerCursorRed, m_fCurrentServerCursorGreen, m_fCurrentServerCursorBlue, m_fCurrentServerCursorAlpha);
}
Proxy-99 marked this conversation as resolved.
Show resolved Hide resolved

void CGUI_Impl::SetCurrentServerCursorAlpha(float fAlpha)
{
m_fCurrentServerCursorAlpha = fAlpha;
Expand Down
10 changes: 9 additions & 1 deletion Client/gui/CGUI_Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ class CGUI_Impl : public CGUI, public CGUITabList
void SetCursorAlpha(float fAlpha, bool bOnlyCurrentServer = false);
void SetCurrentServerCursorAlpha(float fAlpha);
float GetCurrentServerCursorAlpha();
void SetCursorColor(float r, float g, float b, float alpha) noexcept;
void GetCursorColor(float& r, float& g, float& b, float& alpha) noexcept;
void ResetMenuCursorColor() noexcept;
void RestoreCurrentServerCursorColor() noexcept;
void ResetCursorColor(float r, float g, float b, float alpha) noexcept;
Proxy-99 marked this conversation as resolved.
Show resolved Hide resolved
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 m_fCurrentServerCursorAlpha = 1.0f;
float m_fCurrentServerCursorRed = 255.0f;
float m_fCurrentServerCursorGreen = 255.0f;
float m_fCurrentServerCursorBlue = 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 @@ -3437,6 +3437,9 @@ void CClientGame::Event_OnIngame()
g_pGame->ResetAlphaTransparencies();
g_pGame->ResetModelTimes();

// Reset cursor color
g_pCore->GetGUI()->ResetCursorColor(255.f, 255.f, 255.f, 1.f);

// 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 @@ -5112,7 +5112,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(float r, float g, float b, float alpha) noexcept
{
if (!g_pCore->IsMenuVisible())
Proxy-99 marked this conversation as resolved.
Show resolved Hide resolved
g_pCore->GetGUI()->SetCursorColor(r, g, b, alpha);
Proxy-99 marked this conversation as resolved.
Show resolved Hide resolved
else
g_pCore->GetGUI()->ResetCursorColor(r, g, b, alpha); // Force values to be updated

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(float r, float g, float b, float alpha) noexcept;
static CLuaMultiReturn<float, float, float, float> GetCursorColor() noexcept;

private:
static bool SetTransferBoxVisible(bool visible);
static bool IsTransferBoxVisible();
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 ResetCursorColor(float r, float g, float b, float alpha) noexcept = 0;
virtual void RestoreCurrentServerCursorColor() noexcept = 0;
virtual void SetCurrentServerCursorAlpha(float fAlpha) = 0;
virtual float GetCurrentServerCursorAlpha() = 0;
virtual eCursorType GetCursorType() = 0;
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 setAlpha(float r, float g, float b, float alpha) noexcept;
void setColor(float r, float g, float b, float alpha) noexcept;

/*!
\brief
Expand Down
12 changes: 9 additions & 3 deletions vendor/cegui-0.4.0-custom/src/CEGUIMouseCursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,18 @@ void MouseCursor::offsetPosition(const Point& offset)
/*************************************************************************
Set the mouse cursor's alpha
*************************************************************************/
void MouseCursor::setAlpha(float alpha)
void MouseCursor::setAlpha(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));
}
Proxy-99 marked this conversation as resolved.
Show resolved Hide resolved


/*************************************************************************
Set the mouse cursor's color
*************************************************************************/
void MouseCursor::setColor(float r, float g, float b, float alpha) noexcept
{
d_colourRect.setColours(colour(r/255.f, g/255.f, b/255.f, alpha));
}
/*************************************************************************
Checks the mouse cursor position is within the current 'constrain'
Rect and adjusts as required.
Expand Down
Loading