Extract CCamera::ZoomAllowed function to reduce duplicate code

This commit is contained in:
Robert Müller 2024-07-16 18:00:39 +02:00
parent 3c43dcd636
commit f574f759d4
2 changed files with 26 additions and 14 deletions

View file

@ -101,7 +101,7 @@ void CCamera::OnRender()
m_Zoom = clamp(m_Zoom, MinZoomLevel(), MaxZoomLevel());
}
if(!(m_pClient->m_Snap.m_SpecInfo.m_Active || GameClient()->m_GameInfo.m_AllowZoom || Client()->State() == IClient::STATE_DEMOPLAYBACK))
if(!ZoomAllowed())
{
m_ZoomSet = false;
m_Zoom = 1.0f;
@ -210,28 +210,31 @@ void CCamera::OnReset()
void CCamera::ConZoomPlus(IConsole::IResult *pResult, void *pUserData)
{
CCamera *pSelf = (CCamera *)pUserData;
if(pSelf->m_pClient->m_Snap.m_SpecInfo.m_Active || pSelf->GameClient()->m_GameInfo.m_AllowZoom || pSelf->Client()->State() == IClient::STATE_DEMOPLAYBACK)
{
pSelf->ScaleZoom(CCamera::ZOOM_STEP);
if(!pSelf->ZoomAllowed())
return;
if(pSelf->GameClient()->m_MultiViewActivated)
pSelf->GameClient()->m_MultiViewPersonalZoom++;
}
pSelf->ScaleZoom(CCamera::ZOOM_STEP);
if(pSelf->GameClient()->m_MultiViewActivated)
pSelf->GameClient()->m_MultiViewPersonalZoom++;
}
void CCamera::ConZoomMinus(IConsole::IResult *pResult, void *pUserData)
{
CCamera *pSelf = (CCamera *)pUserData;
if(pSelf->m_pClient->m_Snap.m_SpecInfo.m_Active || pSelf->GameClient()->m_GameInfo.m_AllowZoom || pSelf->Client()->State() == IClient::STATE_DEMOPLAYBACK)
{
pSelf->ScaleZoom(1 / CCamera::ZOOM_STEP);
if(!pSelf->ZoomAllowed())
return;
if(pSelf->GameClient()->m_MultiViewActivated)
pSelf->GameClient()->m_MultiViewPersonalZoom--;
}
pSelf->ScaleZoom(1 / CCamera::ZOOM_STEP);
if(pSelf->GameClient()->m_MultiViewActivated)
pSelf->GameClient()->m_MultiViewPersonalZoom--;
}
void CCamera::ConZoom(IConsole::IResult *pResult, void *pUserData)
{
CCamera *pSelf = (CCamera *)pUserData;
if(!pSelf->ZoomAllowed())
return;
float TargetLevel = pResult->NumArguments() ? pResult->GetFloat(0) : g_Config.m_ClDefaultZoom;
pSelf->ChangeZoom(std::pow(CCamera::ZOOM_STEP, TargetLevel - 10), pSelf->m_pClient->m_Snap.m_SpecInfo.m_Active && pSelf->GameClient()->m_MultiViewActivated ? g_Config.m_ClMultiViewZoomSmoothness : g_Config.m_ClSmoothZoomTime);
@ -377,3 +380,10 @@ void CCamera::SetZoom(float Target, int Smoothness)
{
ChangeZoom(Target, Smoothness);
}
bool CCamera::ZoomAllowed() const
{
return GameClient()->m_Snap.m_SpecInfo.m_Active ||
GameClient()->m_GameInfo.m_AllowZoom ||
Client()->State() == IClient::STATE_DEMOPLAYBACK;
}

View file

@ -54,11 +54,13 @@ public:
virtual void OnConsoleInit() override;
virtual void OnReset() override;
void SetZoom(float Target, int Smoothness);
void SetView(ivec2 Pos, bool Relative = false);
void GotoSwitch(int Number, int Offset = -1);
void GotoTele(int Number, int Offset = -1);
void SetZoom(float Target, int Smoothness);
bool ZoomAllowed() const;
private:
static void ConZoomPlus(IConsole::IResult *pResult, void *pUserData);
static void ConZoomMinus(IConsole::IResult *pResult, void *pUserData);