Skip to content

Commit

Permalink
FFQuantityItem: Reduce nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamWillden committed Oct 21, 2020
1 parent a3e1f46 commit c028240
Showing 1 changed file with 48 additions and 43 deletions.
91 changes: 48 additions & 43 deletions cl_dll/ff/vgui/ff_quantityitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,33 +644,41 @@ namespace vgui

void FFQuantityItem::SetTeamColor( Color newTeamColor )
{
if(m_ColorTeam != newTeamColor)
if(m_ColorTeam == newTeamColor)
{
m_ColorTeam = newTeamColor;
if(m_iBarColorMode == ITEM_COLOR_MODE_TEAMCOLORED)
{
RecalculateColor(m_iBarColorMode, m_ColorBar, m_clrBarCustomColor);
}
if(m_iBarBorderColorMode == ITEM_COLOR_MODE_TEAMCOLORED)
{
RecalculateColor(m_iBarBorderColorMode, m_ColorBarBorder, m_clrBarBorderCustomColor);
}
if(m_iBarBackgroundColorMode == ITEM_COLOR_MODE_TEAMCOLORED)
{
RecalculateColor(m_iBarBackgroundColorMode, m_ColorBarBackground, m_clrBarBackgroundCustomColor);
}
if(m_iIconColorMode == ITEM_COLOR_MODE_TEAMCOLORED)
{
RecalculateColor(m_iIconColorMode, m_ColorIcon, m_clrIconCustomColor);
}
if(m_iLabelColorMode == ITEM_COLOR_MODE_TEAMCOLORED)
{
RecalculateColor(m_iLabelColorMode, m_ColorLabel, m_clrLabelCustomColor);
}
if(m_iAmountColorMode == ITEM_COLOR_MODE_TEAMCOLORED)
{
RecalculateColor(m_iAmountColorMode, m_ColorAmount, m_clrAmountCustomColor);
}
return;
}

m_ColorTeam = newTeamColor;

if(m_iBarColorMode == ITEM_COLOR_MODE_TEAMCOLORED)
{
RecalculateColor(m_iBarColorMode, m_ColorBar, m_clrBarCustomColor);
}

if(m_iBarBorderColorMode == ITEM_COLOR_MODE_TEAMCOLORED)
{
RecalculateColor(m_iBarBorderColorMode, m_ColorBarBorder, m_clrBarBorderCustomColor);
}

if(m_iBarBackgroundColorMode == ITEM_COLOR_MODE_TEAMCOLORED)
{
RecalculateColor(m_iBarBackgroundColorMode, m_ColorBarBackground, m_clrBarBackgroundCustomColor);
}

if(m_iIconColorMode == ITEM_COLOR_MODE_TEAMCOLORED)
{
RecalculateColor(m_iIconColorMode, m_ColorIcon, m_clrIconCustomColor);
}

if(m_iLabelColorMode == ITEM_COLOR_MODE_TEAMCOLORED)
{
RecalculateColor(m_iLabelColorMode, m_ColorLabel, m_clrLabelCustomColor);
}

if(m_iAmountColorMode == ITEM_COLOR_MODE_TEAMCOLORED)
{
RecalculateColor(m_iAmountColorMode, m_ColorAmount, m_clrAmountCustomColor);
}
}

Expand Down Expand Up @@ -1547,27 +1555,24 @@ namespace vgui
m_ColorIntensityStepped = GetIntensityColor(m_iAmount, m_iMaxAmount, 1, 255, m_iIntensityRed, m_iIntensityOrange, m_iIntensityYellow, m_iIntensityGreen, m_bIntensityInvertScale);
}

if(!m_bShowAmountMax)
if(m_bShowAmountMax)
{
if(m_iMaxAmount == 100)// already same as a percentage so no need to convert
{
_snwprintf( m_wszAmountString, 255, L"%s%%", m_wszAmount );
}
else
{
char szPercent[ 5 ];
wchar_t wszPercent[ 10 ];
float percent = ((float)m_iAmount/(float)m_iMaxAmount*100.0f);
Q_snprintf( szPercent, 5, "%i%", (int)percent);

localize()->ConvertANSIToUnicode( szPercent, wszPercent, sizeof( wszPercent ) );

_snwprintf( m_wszAmountString, 9, L"%s%%", wszPercent );
}
_snwprintf( m_wszAmountString, 9, L"%s/%s", m_wszAmount, m_wszAmountMax );
}
else if(m_iMaxAmount == 100)// already same as a percentage so no need to convert
{
_snwprintf( m_wszAmountString, 255, L"%s%%", m_wszAmount );
}
else
{
_snwprintf( m_wszAmountString, 9, L"%s/%s", m_wszAmount, m_wszAmountMax );
char szPercent[ 5 ];
wchar_t wszPercent[ 10 ];
float percent = ((float)m_iAmount/(float)m_iMaxAmount*100.0f);
Q_snprintf( szPercent, 5, "%i%", (int)percent);

localize()->ConvertANSIToUnicode( szPercent, wszPercent, sizeof( wszPercent ) );

_snwprintf( m_wszAmountString, 9, L"%s%%", wszPercent );
}

RecalculateAmountPosition();
Expand Down

0 comments on commit c028240

Please sign in to comment.