Skip to content

Commit

Permalink
FFQuantityItem: Reduce code complexity (clean code)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamWillden committed Oct 20, 2020
1 parent b8e3ee8 commit a3e1f46
Showing 1 changed file with 24 additions and 38 deletions.
62 changes: 24 additions & 38 deletions cl_dll/ff/vgui/ff_quantityitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1536,13 +1536,15 @@ namespace vgui
{
if(m_bIntensityAmountScaled && m_iMaxAmount != 0)
{
m_ColorIntensityFaded = GetIntensityColor((int)((float)m_iAmount/(float)m_iMaxAmount * 100), 100, 2, m_clrBarCustomColor.a(), m_iIntensityRed, m_iIntensityOrange, m_iIntensityYellow, m_iIntensityGreen, m_bIntensityInvertScale);
m_ColorIntensityStepped = GetIntensityColor((int)((float)m_iAmount/(float)m_iMaxAmount * 100), 100, 1, m_clrBarCustomColor.a(), m_iIntensityRed, m_iIntensityOrange ,m_iIntensityYellow, m_iIntensityGreen, m_bIntensityInvertScale);
int iAmount = (int)((float)m_iAmount/(float)m_iMaxAmount * 100);

m_ColorIntensityFaded = GetIntensityColor(iAmount, 100, 2, 255, m_iIntensityRed, m_iIntensityOrange, m_iIntensityYellow, m_iIntensityGreen, m_bIntensityInvertScale);
m_ColorIntensityStepped = GetIntensityColor(iAmount, 100, 1, 255, m_iIntensityRed, m_iIntensityOrange ,m_iIntensityYellow, m_iIntensityGreen, m_bIntensityInvertScale);
}
else
{
m_ColorIntensityFaded = GetIntensityColor(m_iAmount, m_iMaxAmount, 2, m_clrBarCustomColor.a(), m_iIntensityRed, m_iIntensityOrange, m_iIntensityYellow, m_iIntensityGreen, m_bIntensityInvertScale);
m_ColorIntensityStepped = GetIntensityColor(m_iAmount, m_iMaxAmount, 1, m_clrBarCustomColor.a(), m_iIntensityRed, m_iIntensityOrange, m_iIntensityYellow, m_iIntensityGreen, m_bIntensityInvertScale);
m_ColorIntensityFaded = GetIntensityColor(m_iAmount, m_iMaxAmount, 2, 255, m_iIntensityRed, m_iIntensityOrange, m_iIntensityYellow, m_iIntensityGreen, m_bIntensityInvertScale);
m_ColorIntensityStepped = GetIntensityColor(m_iAmount, m_iMaxAmount, 1, 255, m_iIntensityRed, m_iIntensityOrange, m_iIntensityYellow, m_iIntensityGreen, m_bIntensityInvertScale);
}

if(!m_bShowAmountMax)
Expand Down Expand Up @@ -1576,46 +1578,30 @@ namespace vgui
SetIntensityColor(m_ColorIcon, m_iIconColorMode, m_clrIconCustomColor);
SetIntensityColor(m_ColorLabel, m_iLabelColorMode, m_clrLabelCustomColor);
SetIntensityColor(m_ColorAmount, m_iAmountColorMode, m_clrAmountCustomColor);

m_iBarX0QuantityOffset = 0;
m_iBarX1QuantityOffset = 0;
m_iBarY0QuantityOffset = 0;
m_iBarY1QuantityOffset = 0;

if(m_iBarOrientation == ORIENTATION_HORIZONTAL_INVERTED)
switch (m_iBarOrientation)
{
case ORIENTATION_HORIZONTAL_INVERTED:
m_iBarX0QuantityOffset = m_iBarWidth - (m_iBarWidth * m_iAmount/m_iMaxAmount);
if( (m_iBarX1QuantityOffset + m_iBarY0QuantityOffset + m_iBarY1QuantityOffset ) != 0 )
{
m_iBarX1QuantityOffset = 0;
m_iBarY0QuantityOffset = 0;
m_iBarY1QuantityOffset = 0;
}
}
else if(m_iBarOrientation == ORIENTATION_VERTICAL)
{
break;

case ORIENTATION_VERTICAL:
m_iBarY0QuantityOffset = m_iBarHeight - (m_iBarHeight * m_iAmount/m_iMaxAmount);
if( (m_iBarX0QuantityOffset + m_iBarX1QuantityOffset + m_iBarY1QuantityOffset ) != 0 )
{
m_iBarX0QuantityOffset = 0;
m_iBarX1QuantityOffset = 0;
m_iBarY1QuantityOffset = 0;
}
}
else if(m_iBarOrientation == ORIENTATION_VERTICAL_INVERTED)
{
break;

case ORIENTATION_VERTICAL_INVERTED:
m_iBarY1QuantityOffset = (m_iBarHeight * m_iAmount/m_iMaxAmount) - m_iBarHeight;
if( (m_iBarX0QuantityOffset + m_iBarX1QuantityOffset + m_iBarY0QuantityOffset ) != 0 )
{
m_iBarX0QuantityOffset = 0;
m_iBarX1QuantityOffset = 0;
m_iBarY0QuantityOffset = 0;
}
}
else //m_iBarOrientation == ORIENTATION_HORIZONTAL (or anything else)
{
break;

case ORIENTATION_HORIZONTAL:
default:
m_iBarX1QuantityOffset = (m_iBarWidth * m_iAmount/m_iMaxAmount) - m_iBarWidth;
if( (m_iBarX0QuantityOffset + m_iBarY0QuantityOffset + m_iBarY1QuantityOffset ) != 0 )
{
m_iBarX0QuantityOffset = 0;
m_iBarY0QuantityOffset = 0;
m_iBarY1QuantityOffset = 0;
}
break;
}
}

Expand Down

0 comments on commit a3e1f46

Please sign in to comment.