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

Fix isPlayerHudComponentVisible incompatible with command showhud #1609

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion Client/game_sa/CHudSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,16 @@ void CHudSA::SetComponentVisible(eHudComponent component, bool bVisible)
//
// CHudSA::IsComponentVisible
//
bool CHudSA::IsComponentVisible(eHudComponent component)
bool CHudSA::IsComponentVisible(eHudComponent component, bool bOutIsEnabled)
{
SHudComponent* pComponent = MapFind(m_HudComponentMap, component);
if (pComponent)
{
if (bOutIsEnabled)
{
if (g_pCore->GetGame()->GetHud()->IsDisabled())
return false;
}
Comment on lines +279 to +283
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use if (bIsEnabled && ...->IsDisabled())?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah sure

// Determine if invisible by matching data with disabled values
uchar* pSrc = (uchar*)(&pComponent->disabledData);
uchar* pDest = (uchar*)(pComponent->uiDataAddr);
Expand Down
2 changes: 1 addition & 1 deletion Client/game_sa/CHudSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class CHudSA : public CHud
bool CalcScreenCoors(CVector* vecPosition1, CVector* vecPosition2, float* fX, float* fY, bool bSetting1, bool bSetting2);
void Draw2DPolygon(float fX1, float fY1, float fX2, float fY2, float fX3, float fY3, float fX4, float fY4, DWORD dwColor);
void SetComponentVisible(eHudComponent component, bool bVisible);
bool IsComponentVisible(eHudComponent component);
bool IsComponentVisible(eHudComponent component, bool bOutIsEnabled);
void AdjustComponents(float fAspectRatio);
void ResetComponentAdjustment();

Expand Down
4 changes: 2 additions & 2 deletions Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1951,9 +1951,9 @@ bool CStaticFunctionDefinitions::ShowPlayerHudComponent(eHudComponent component,
return true;
}

bool CStaticFunctionDefinitions::IsPlayerHudComponentVisible(eHudComponent component, bool& bOutIsVisible)
bool CStaticFunctionDefinitions::IsPlayerHudComponentVisible(eHudComponent component, bool bOutIsEnabled, bool& bOutIsVisible)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This, and elsewhere, should be bCheckEnabled.

{
bOutIsVisible = g_pGame->GetHud()->IsComponentVisible(component);
bOutIsVisible = g_pGame->GetHud()->IsComponentVisible(component, bOutIsEnabled);
return true;
}
Comment on lines -1954 to 1958
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're modifying this function, it's probably better to remove it. We don't put code in CStaticFunctionDefinitions anymore. You can call g_pGame->GetHud()->IsComponentVisible directly. The rest of the PR looks okay.


Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class CStaticFunctionDefinitions

// Player set funcs
static bool ShowPlayerHudComponent(eHudComponent component, bool bShow);
static bool IsPlayerHudComponentVisible(eHudComponent component, bool& bOutIsVisible);
static bool IsPlayerHudComponentVisible(eHudComponent component, bool bOutIsEnabled, bool& bOutIsVisible);
static bool SetPlayerMoney(long lMoney, bool bInstant);
static bool GivePlayerMoney(long lMoney);
static bool TakePlayerMoney(long lMoney);
Expand Down
6 changes: 4 additions & 2 deletions Client/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,16 +334,18 @@ int CLuaPlayerDefs::ShowPlayerHudComponent(lua_State* luaVM)

int CLuaPlayerDefs::IsPlayerHudComponentVisible(lua_State* luaVM)
{
// bool isPlayerHudComponentVisible ( string componen )
// bool isPlayerHudComponentVisible ( string component, checkEnabled = true )
eHudComponent component;
bool bIsEnabled;

CScriptArgReader argStream(luaVM);
argStream.ReadEnumString(component);
argStream.ReadBool(bIsEnabled, true);

if (!argStream.HasErrors())
{
bool bIsVisible;
if (CStaticFunctionDefinitions::IsPlayerHudComponentVisible(component, bIsVisible))
if (CStaticFunctionDefinitions::IsPlayerHudComponentVisible(component, bIsEnabled, bIsVisible))
{
lua_pushboolean(luaVM, bIsVisible);
return 1;
Expand Down
2 changes: 1 addition & 1 deletion Client/sdk/game/CHud.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CHud
// virtual VOID SetVehicleName( char * szName )=0;
// virtual VOID SetZoneName( char * szName )=0;
virtual void SetComponentVisible(eHudComponent component, bool bVisible) = 0;
virtual bool IsComponentVisible(eHudComponent component) = 0;
virtual bool IsComponentVisible(eHudComponent component, bool bOutIsEnabled) = 0;
virtual void AdjustComponents(float fAspectRatio) = 0;
virtual void ResetComponentAdjustment() = 0;
};