Skip to content

Commit

Permalink
Added ability to size label,icon and amount text.
Browse files Browse the repository at this point in the history
Bar spacing is now applied before the first element.
Font is now stored in a separate res file (QuantityPanelScheme.res)

Maybe something else too.
  • Loading branch information
AdamWillden committed Nov 1, 2020
1 parent 4b7191e commit 905de6a
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 34 deletions.
30 changes: 27 additions & 3 deletions cl_dll/ff/ff_hud_buildstate_base.cpp
Expand Up @@ -65,9 +65,13 @@ static ConVar hud_buildstate_color_amount_g( "hud_buildstate_color_amount_g", "2
static ConVar hud_buildstate_color_amount_b( "hud_buildstate_color_amount_b", "255", FCVAR_ARCHIVE, "Amount color blue component");
static ConVar hud_buildstate_color_amount_a( "hud_buildstate_color_amount_a", "255", FCVAR_ARCHIVE, "Amount color alpha component");

static ConVar hud_buildstate_shadow_icon( "hud_buildstate_shadow_icon", "0", FCVAR_ARCHIVE, "Icon Shadow (0 Off, 1 On)");
static ConVar hud_buildstate_shadow_label( "hud_buildstate_shadow_label", "0", FCVAR_ARCHIVE, "Label Shadow (0 Off, 1 On)");
static ConVar hud_buildstate_shadow_amount( "hud_buildstate_shadow_amount", "0", FCVAR_ARCHIVE, "Amount Shadow (0 Off, 1 On)");
static ConVar hud_buildstate_shadow_icon( "hud_buildstate_shadow_icon", "0", FCVAR_ARCHIVE, "Icon Shadow (0 Off, 1 On)", true, 0, true, 1);
static ConVar hud_buildstate_shadow_label( "hud_buildstate_shadow_label", "0", FCVAR_ARCHIVE, "Label Shadow (0 Off, 1 On)", true, 0, true, 1);
static ConVar hud_buildstate_shadow_amount( "hud_buildstate_shadow_amount", "0", FCVAR_ARCHIVE, "Amount Shadow (0 Off, 1 On)", true, 0, true, 1);

static ConVar hud_buildstate_size_icon( "hud_buildstate_size_icon", "2", FCVAR_ARCHIVE, "Icon Size (0-4)", true, 0, true, 4);
static ConVar hud_buildstate_size_label( "hud_buildstate_size_label", "2", FCVAR_ARCHIVE, "Label Shadow (0-4)", true, 0, true, 4);
static ConVar hud_buildstate_size_amount( "hud_buildstate_size_amount", "2", FCVAR_ARCHIVE, "Amount Shadow (0-4)", true, 0, true, 4);

static ConVar hud_buildstate_colorMode_bar( "hud_buildstate_colorMode_bar", "2", FCVAR_ARCHIVE, "Bar color mode (0=Custom, 1=Stepped Intensity, 2=Faded Intensity, 3=Team Coloured)");
static ConVar hud_buildstate_colorMode_barBackground( "hud_buildstate_colorMode_barBackground", "2", FCVAR_ARCHIVE, "Bar Background color mode (0=Custom, 1=Stepped Intensity, 2=Faded Intensity, 3=Team Coloured)");
Expand Down Expand Up @@ -304,6 +308,26 @@ void CHudBuildStateBase::CheckCvars(bool updateBarPositions)
OnColorModeAmountChanged();
}


if(m_qb_iSizeIcon != hud_buildstate_size_icon.GetInt())
{
m_qb_iSizeIcon = hud_buildstate_size_icon.GetInt();
OnSizeIconChanged();
updateBarPositions = true;
}
if(m_qb_iSizeLabel != hud_buildstate_size_label.GetInt())
{
m_qb_iSizeLabel = hud_buildstate_size_label.GetInt();
OnSizeLabelChanged();
updateBarPositions = true;
}
if(m_qb_iSizeAmount != hud_buildstate_size_amount.GetInt())
{
m_qb_iSizeAmount = hud_buildstate_size_amount.GetInt();
OnSizeAmountChanged();
updateBarPositions = true;
}

if(m_qb_iOffsetIconX != hud_buildstate_offset_icon_x.GetInt() || m_qb_iOffsetIconY != hud_buildstate_offset_icon_y.GetInt())
{
m_qb_iOffsetIconX = hud_buildstate_offset_icon_x.GetInt();
Expand Down
99 changes: 82 additions & 17 deletions cl_dll/ff/ff_hud_quantitybar.cpp
Expand Up @@ -21,15 +21,63 @@

void CHudQuantityBar::ApplySchemeSettings( vgui::IScheme *pScheme )
{
m_hfQuantityBarText[0] = pScheme->GetFont( "QuantityBar", true );
m_hfQuantityBarText[1] = pScheme->GetFont( "QuantityBarShadow", true );
m_hfQuantityBarText[2] = pScheme->GetFont( "QuantityBar", false );
m_hfQuantityBarIcon[0] = pScheme->GetFont( "QuantityBarIcon", true );
m_hfQuantityBarIcon[1] = pScheme->GetFont( "QuantityBarIconShadow", true );
m_hfQuantityBarIcon[2] = pScheme->GetFont( "QuantityBarIcon", false );
m_hfQuantityBarGlyph[0] = pScheme->GetFont( "QuantityBarIcon", true );
m_hfQuantityBarGlyph[1] = pScheme->GetFont( "QuantityBarIconShadow", true );
m_hfQuantityBarGlyph[2] = pScheme->GetFont( "QuantityBarIcon", false );
//the non scaled fonts are used for positioning calculations
//for 'simplicity' and consistency everything is calculated as if in 640x480

//decided I'll make the text size variable too
//size*3 then offset for shadow and non proportional

vgui::HScheme QuantityBarScheme = vgui::scheme()->LoadSchemeFromFile("resource/QuantityPanelScheme.res", "QuantityPanelScheme");
vgui::IScheme *qbScheme = vgui::scheme()->GetIScheme(QuantityBarScheme);

m_hfQuantityBarText[0] = qbScheme->GetFont( "QuantityBar0", true );
m_hfQuantityBarText[1] = qbScheme->GetFont( "QuantityBarShadow0", true );
m_hfQuantityBarText[2] = qbScheme->GetFont( "QuantityBar0", false );
m_hfQuantityBarText[3] = qbScheme->GetFont( "QuantityBar1", true );
m_hfQuantityBarText[4] = qbScheme->GetFont( "QuantityBarShadow1", true );
m_hfQuantityBarText[5] = qbScheme->GetFont( "QuantityBar1", false );
m_hfQuantityBarText[6] = qbScheme->GetFont( "QuantityBar2", true );
m_hfQuantityBarText[7] = qbScheme->GetFont( "QuantityBarShadow2", true );
m_hfQuantityBarText[8] = qbScheme->GetFont( "QuantityBar2", false );
m_hfQuantityBarText[9] = qbScheme->GetFont( "QuantityBar3", true );
m_hfQuantityBarText[10] = qbScheme->GetFont( "QuantityBarShadow3", true );
m_hfQuantityBarText[11] = qbScheme->GetFont( "QuantityBar3", false );
m_hfQuantityBarText[12] = qbScheme->GetFont( "QuantityBar4", true );
m_hfQuantityBarText[13] = qbScheme->GetFont( "QuantityBarShadow4", true );
m_hfQuantityBarText[14] = qbScheme->GetFont( "QuantityBar4", false );


m_hfQuantityBarIcon[0] = qbScheme->GetFont( "QuantityBarIcon0", true );
m_hfQuantityBarIcon[1] = qbScheme->GetFont( "QuantityBarIconShadow0", true );
m_hfQuantityBarIcon[2] = qbScheme->GetFont( "QuantityBarIcon0", false );
m_hfQuantityBarIcon[3] = qbScheme->GetFont( "QuantityBarIcon1", true );
m_hfQuantityBarIcon[4] = qbScheme->GetFont( "QuantityBarIconShadow1", true );
m_hfQuantityBarIcon[5] = qbScheme->GetFont( "QuantityBarIcon1", false );
m_hfQuantityBarIcon[6] = qbScheme->GetFont( "QuantityBarIcon2", true );
m_hfQuantityBarIcon[7] = qbScheme->GetFont( "QuantityBarIconShadow2", true );
m_hfQuantityBarIcon[8] = qbScheme->GetFont( "QuantityBarIcon2", false );
m_hfQuantityBarIcon[9] = qbScheme->GetFont( "QuantityBarIcon3", true );
m_hfQuantityBarIcon[10] = qbScheme->GetFont( "QuantityBarIconShadow3", true );
m_hfQuantityBarIcon[11] = qbScheme->GetFont( "QuantityBarIcon3", false );
m_hfQuantityBarIcon[12] = qbScheme->GetFont( "QuantityBarIcon4", true );
m_hfQuantityBarIcon[13] = qbScheme->GetFont( "QuantityBarIconShadow4", true );
m_hfQuantityBarIcon[14] = qbScheme->GetFont( "QuantityBarIcon4", false );

m_hfQuantityBarGlyph[0] = qbScheme->GetFont( "QuantityBarGlyph0", true );
m_hfQuantityBarGlyph[1] = qbScheme->GetFont( "QuantityBarGlyphShadow0", true );
m_hfQuantityBarGlyph[2] = qbScheme->GetFont( "QuantityBarGlyph0", false );
m_hfQuantityBarGlyph[3] = qbScheme->GetFont( "QuantityBarGlyph1", true );
m_hfQuantityBarGlyph[4] = qbScheme->GetFont( "QuantityBarGlyphShadow1", true );
m_hfQuantityBarGlyph[5] = qbScheme->GetFont( "QuantityBarGlyph1", false );
m_hfQuantityBarGlyph[6] = qbScheme->GetFont( "QuantityBarGlyph2", true );
m_hfQuantityBarGlyph[7] = qbScheme->GetFont( "QuantityBarGlyphShadow2", true );
m_hfQuantityBarGlyph[8] = qbScheme->GetFont( "QuantityBarGlyph2", false );
m_hfQuantityBarGlyph[9] = qbScheme->GetFont( "QuantityBarGlyph3", true );
m_hfQuantityBarGlyph[10] = qbScheme->GetFont( "QuantityBarGlyphShadow3", true );
m_hfQuantityBarGlyph[11] = qbScheme->GetFont( "QuantityBarGlyph3", false );
m_hfQuantityBarGlyph[12] = qbScheme->GetFont( "QuantityBarGlyph4", true );
m_hfQuantityBarGlyph[13] = qbScheme->GetFont( "QuantityBarGlyphShadow4", true );
m_hfQuantityBarGlyph[14] = qbScheme->GetFont( "QuantityBarGlyph4", false );

SetBorder(pScheme->GetBorder("ScoreBoardItemBorder"));

Expand All @@ -53,6 +101,23 @@ void CHudQuantityBar::SetIconFontGlyph(bool bIconIsGlyph)
m_bIconFontGlyph = bIconIsGlyph;
}


void CHudQuantityBar::SetIconSize( int newIconSize )
{
m_iSizeIcon = newIconSize;
RecalculateIconPosition();
}
void CHudQuantityBar::SetLabelSize( int newLabelSize )
{
m_iSizeLabel = newLabelSize;
RecalculateLabelPosition();
}
void CHudQuantityBar::SetAmountSize( int newAmountSize )
{
m_iSizeAmount = newAmountSize;
RecalculateAmountPosition();
}

void CHudQuantityBar::SetAmount(int iAmount)
{
m_iAmount = iAmount;
Expand Down Expand Up @@ -342,23 +407,23 @@ void CHudQuantityBar::GetPanelPositioningData(int& iWidth, int& iHeight, int& iB
void CHudQuantityBar::RecalculateIconPosition()
{
if(m_bIconFontGlyph)
CalculateTextAlignmentOffset(m_iIconAlignmentOffsetX, m_iIconAlignmentOffsetY, m_iIconWidth, m_iIconHeight, TEXTALIGN_CENTER, m_hfQuantityBarGlyph[2], m_wszIcon);
CalculateTextAlignmentOffset(m_iIconAlignmentOffsetX, m_iIconAlignmentOffsetY, m_iIconWidth, m_iIconHeight, TEXTALIGN_CENTER, m_hfQuantityBarGlyph[m_iSizeIcon*3 + 2], m_wszIcon);
else
CalculateTextAlignmentOffset(m_iIconAlignmentOffsetX, m_iIconAlignmentOffsetY, m_iIconWidth, m_iIconHeight, TEXTALIGN_CENTER, m_hfQuantityBarIcon[2], m_wszIcon);
CalculateTextAlignmentOffset(m_iIconAlignmentOffsetX, m_iIconAlignmentOffsetY, m_iIconWidth, m_iIconHeight, TEXTALIGN_CENTER, m_hfQuantityBarIcon[m_iSizeIcon*3 + 2], m_wszIcon);
m_iIconPosX = m_iLeft + m_iOffsetXIcon + m_iIconAlignmentOffsetX;
m_iIconPosY = m_iTop + m_iOffsetYIcon + m_iIconAlignmentOffsetY;
}

void CHudQuantityBar::RecalculateLabelPosition()
{
CalculateTextAlignmentOffset(m_iLabelAlignmentOffsetX, m_iLabelAlignmentOffsetY, m_iLabelWidth, m_iLabelHeight, m_iTextAlignLabel, m_hfQuantityBarText[2], m_wszLabel);
CalculateTextAlignmentOffset(m_iLabelAlignmentOffsetX, m_iLabelAlignmentOffsetY, m_iLabelWidth, m_iLabelHeight, m_iTextAlignLabel, m_hfQuantityBarText[m_iSizeLabel*3 + 2], m_wszLabel);
m_iLabelPosX = m_iLeft + m_iOffsetXLabel + m_iLabelAlignmentOffsetX;
m_iLabelPosY = m_iTop + m_iOffsetYLabel + m_iLabelAlignmentOffsetY;
}

void CHudQuantityBar::RecalculateAmountPosition()
{
CalculateTextAlignmentOffset(m_iAmountAlignmentOffsetX, m_iAmountAlignmentOffsetY, m_iAmountWidth, m_iAmountHeight, m_iTextAlignAmount, m_hfQuantityBarText[2], m_wszAmountString);
CalculateTextAlignmentOffset(m_iAmountAlignmentOffsetX, m_iAmountAlignmentOffsetY, m_iAmountWidth, m_iAmountHeight, m_iTextAlignAmount, m_hfQuantityBarText[m_iSizeAmount*3 + 2], m_wszAmountString);
m_iAmountPosX = m_iLeft + m_iOffsetXAmount + m_iAmountAlignmentOffsetX;
m_iAmountPosY = m_iTop + m_iOffsetYAmount + m_iAmountAlignmentOffsetY;
}
Expand Down Expand Up @@ -406,9 +471,9 @@ void CHudQuantityBar::Paint()
if(m_bShowIcon && m_wszIcon)
{
if(m_bIconFontGlyph)
vgui::surface()->DrawSetTextFont(m_hfQuantityBarGlyph[m_bIconFontShadow]);
vgui::surface()->DrawSetTextFont(m_hfQuantityBarGlyph[m_iSizeIcon * 3 + (m_bIconFontShadow ? 1 : 0)]);
else
vgui::surface()->DrawSetTextFont(m_hfQuantityBarIcon[m_bIconFontShadow]);
vgui::surface()->DrawSetTextFont(m_hfQuantityBarIcon[m_iSizeIcon * 3 + (m_bIconFontShadow ? 1 : 0)]);

vgui::surface()->DrawSetTextColor( m_ColorIcon );
vgui::surface()->DrawSetTextPos(m_iIconPosX * m_flScale, m_iIconPosY * m_flScale);
Expand All @@ -417,15 +482,15 @@ void CHudQuantityBar::Paint()

if(m_bShowLabel && m_wszLabel)
{
vgui::surface()->DrawSetTextFont(m_hfQuantityBarText[m_bLabelFontShadow]);
vgui::surface()->DrawSetTextFont(m_hfQuantityBarText[m_iSizeLabel * 3 + (m_bLabelFontShadow ? 1 : 0)]);
vgui::surface()->DrawSetTextColor( m_ColorLabel );
vgui::surface()->DrawSetTextPos(m_iLabelPosX * m_flScale, m_iLabelPosY * m_flScale);
vgui::surface()->DrawUnicodeString( m_wszLabel );
}

if(m_bShowAmount && m_wszAmount)
{
vgui::surface()->DrawSetTextFont(m_hfQuantityBarText[m_bAmountFontShadow]);
vgui::surface()->DrawSetTextFont(m_hfQuantityBarText[m_iSizeAmount * 3 + (m_bAmountFontShadow ? 1 : 0)]);
vgui::surface()->DrawSetTextColor( m_ColorAmount );
vgui::surface()->DrawSetTextPos(m_iAmountPosX * m_flScale, m_iAmountPosY * m_flScale);
vgui::surface()->DrawUnicodeString( m_wszAmountString );
Expand Down
14 changes: 11 additions & 3 deletions cl_dll/ff/ff_hud_quantitybar.h
Expand Up @@ -143,6 +143,10 @@ class CHudQuantityBar : public CHudElement, public vgui::Panel
void SetLabelColor( Color newLabelColor );
void SetTeamColor( Color newTeamColor );

void SetAmountSize( int newAmountSize );
void SetIconSize( int newIconSize );
void SetLabelSize( int newLabelSize );

void SetIconOffsetX(int iconOffsetX);
void SetIconOffsetY(int iconOffsetY);
void SetIconOffset(int iconOffsetX, int iconOffsetY);
Expand Down Expand Up @@ -182,9 +186,9 @@ class CHudQuantityBar : public CHudElement, public vgui::Panel

virtual void ApplySchemeSettings( vgui::IScheme *pScheme );

vgui::HFont m_hfQuantityBarText[3];
vgui::HFont m_hfQuantityBarIcon[3];
vgui::HFont m_hfQuantityBarGlyph[3];
vgui::HFont m_hfQuantityBarText[15];
vgui::HFont m_hfQuantityBarIcon[15];
vgui::HFont m_hfQuantityBarGlyph[15];

bool m_bAmountFontShadow;
bool m_bLabelFontShadow;
Expand Down Expand Up @@ -253,6 +257,10 @@ class CHudQuantityBar : public CHudElement, public vgui::Panel

wchar_t m_wszAmountString[ 10 ];

int m_iSizeAmount;
int m_iSizeIcon;
int m_iSizeLabel;

bool m_bShowBar;
bool m_bShowBarBackground;
bool m_bShowBarBorder;
Expand Down
42 changes: 31 additions & 11 deletions cl_dll/ff/vgui/ff_quantitypanel.cpp
Expand Up @@ -25,12 +25,16 @@ namespace vgui

SetBorder(pScheme->GetBorder("ScoreBoardItemBorder"));

m_hfHeaderText[0] = pScheme->GetFont( "QuantityPanelHeader", true );
m_hfHeaderText[1] = pScheme->GetFont( "QuantityPanelHeaderShadow", true );
m_hfHeaderText[2] = pScheme->GetFont( "QuantityPanelHeader", false );
m_hfHeaderIcon[0] = pScheme->GetFont( "QuantityPanelHeaderIcon", true );
m_hfHeaderIcon[1] = pScheme->GetFont( "QuantityPanelHeaderIconShadow", true );
m_hfHeaderIcon[2] = pScheme->GetFont( "QuantityPanelHeaderIcon", false );

vgui::HScheme QuantityBarScheme = vgui::scheme()->LoadSchemeFromFile("resource/QuantityPanelScheme.res", "QuantityPanelScheme");
vgui::IScheme *qbScheme = vgui::scheme()->GetIScheme(QuantityBarScheme);

m_hfHeaderText[0] = qbScheme->GetFont( "QuantityPanelHeader", true );
m_hfHeaderText[1] = qbScheme->GetFont( "QuantityPanelHeaderShadow", true );
m_hfHeaderText[2] = qbScheme->GetFont( "QuantityPanelHeader", false );
m_hfHeaderIcon[0] = qbScheme->GetFont( "QuantityPanelHeaderIcon", true );
m_hfHeaderIcon[1] = qbScheme->GetFont( "QuantityPanelHeaderIconShadow", true );
m_hfHeaderIcon[2] = qbScheme->GetFont( "QuantityPanelHeaderIcon", false );

BaseClass::ApplySchemeSettings( pScheme );
}
Expand Down Expand Up @@ -185,8 +189,8 @@ namespace vgui
{
int iPosX, iPosY;

iPosX = m_qb_iPositionX + iColumnWidths + m_iColumnOffset[iColumn] + (iColumn) * m_qb_iSpacingX * m_flScale;
iPosY = m_qb_iPositionY + iRowHeights + m_iRowOffset[iRow] + (iRow) * m_qb_iSpacingY * m_flScale;
iPosX = m_qb_iPositionX + iColumnWidths + m_iColumnOffset[iColumn] + (iColumn+1) * m_qb_iSpacingX * m_flScale;
iPosY = m_qb_iPositionY + iRowHeights + m_iRowOffset[iRow] + (iRow+1) * m_qb_iSpacingY * m_flScale;

m_QBars[i]->SetPos( iPosX, iPosY );

Expand All @@ -200,8 +204,8 @@ namespace vgui
//include the height of the row
iRowHeights += m_iRowHeight[iRow++];

int iX1 = m_qb_iPositionX + iColumnWidths + iColumn * m_qb_iSpacingX * m_flScale;
int iY1 = m_qb_iPositionY + iRowHeights + iRow * m_qb_iSpacingY * m_flScale;
int iX1 = m_qb_iPositionX + iColumnWidths + (iColumn+1) * m_qb_iSpacingX * m_flScale;
int iY1 = m_qb_iPositionY + iRowHeights + (iRow+1) * m_qb_iSpacingY * m_flScale;

//these are used to get equal padding on either side
bool HeaderLeft = false;
Expand Down Expand Up @@ -400,7 +404,23 @@ namespace vgui
for(int i = 0; i < m_iQBars; i++)
m_QBars[i]->SetAmountColorMode(m_qb_iColorModeAmount);
}


void FFQuantityPanel::OnSizeLabelChanged( )
{
for(int i = 0; i < m_iQBars; i++)
m_QBars[i]->SetLabelSize(m_qb_iSizeLabel);
}

void FFQuantityPanel::OnSizeIconChanged( )
{
for(int i = 0; i < m_iQBars; i++)
m_QBars[i]->SetIconSize(m_qb_iSizeIcon);
}
void FFQuantityPanel::OnSizeAmountChanged( )
{
for(int i = 0; i < m_iQBars; i++)
m_QBars[i]->SetAmountSize(m_qb_iSizeAmount);
}

void FFQuantityPanel::OnIconShadowChanged( )
{
Expand Down
8 changes: 8 additions & 0 deletions cl_dll/ff/vgui/ff_quantitypanel.h
Expand Up @@ -162,6 +162,10 @@ namespace vgui
void OnShowIconChanged();
void OnShowLabelChanged();
void OnShowAmountChanged();

void OnSizeIconChanged();
void OnSizeLabelChanged();
void OnSizeAmountChanged();

void OnColorBarChanged();
void OnColorBarBackgroundChanged();
Expand Down Expand Up @@ -290,6 +294,10 @@ namespace vgui
bool m_qb_bShadowLabel;
bool m_qb_bShadowAmount;

int m_qb_iSizeIcon;
int m_qb_iSizeLabel;
int m_qb_iSizeAmount;

int m_qb_iColorModeBar;
int m_qb_iColorModeBarBackground;
int m_qb_iColorModeBarBorder;
Expand Down

0 comments on commit 905de6a

Please sign in to comment.