From 4f712ff96adf8354b9fd94cc031db8d3a76fd43e Mon Sep 17 00:00:00 2001 From: Elmo Date: Wed, 14 Jul 2010 16:54:29 +0000 Subject: [PATCH] Committing before I fuck up what I want to do next. Paint is now much smaller. Most changes are now done when needed and not constantly calculated. The bars scale properly now but I'm not sure what happens with positioning - I'll worry about that later. Nothing configurable. # Conflicts: # cl_dll/ff/vgui/ff_panel.h --- cl_dll/ff/ff_hud_buildstate_sentry.cpp | 53 ++- cl_dll/ff/ff_hud_quantitybar.cpp | 489 +++++++++++++++---------- cl_dll/ff/ff_hud_quantitybar.h | 179 +++++---- cl_dll/ff/vgui/ff_quantitypanel.cpp | 99 ++++- cl_dll/ff/vgui/ff_quantitypanel.h | 46 ++- 5 files changed, 527 insertions(+), 339 deletions(-) diff --git a/cl_dll/ff/ff_hud_buildstate_sentry.cpp b/cl_dll/ff/ff_hud_buildstate_sentry.cpp index 44dc57390..ef58d8bed 100644 --- a/cl_dll/ff/ff_hud_buildstate_sentry.cpp +++ b/cl_dll/ff/ff_hud_buildstate_sentry.cpp @@ -11,7 +11,7 @@ class CHudBuildStateSentry : public CHudElement, public vgui::FFQuantityPanel { - //DECLARE_CLASS_SIMPLE( CHudBuildStateSentry, vgui::FFQuantityPanel ); + DECLARE_CLASS_SIMPLE( CHudBuildStateSentry, vgui::FFQuantityPanel ); public: CHudBuildStateSentry(const char *pElementName) : CHudElement(pElementName), vgui::FFQuantityPanel(NULL, "HudBuildStateSentry") @@ -23,17 +23,18 @@ class CHudBuildStateSentry : public CHudElement, public vgui::FFQuantityPanel m_qbSentryLevel = new CHudQuantityBar(this, "BuildStateSentryLevel"); m_bBuilt = false; - m_iBarPadding = 30; - vgui::ivgui()->AddTickSignal(GetVPanel()); //only update 4 times a second + m_flScale = 1.0f; + + vgui::ivgui()->AddTickSignal(GetVPanel(), 250); //only update 4 times a second } ~CHudBuildStateSentry( void ) {} - void Init( void ); - void VidInit( void ); - void OnTick( void ); - void Paint( void ); + virtual void Init( void ); + virtual void VidInit( void ); + virtual void OnTick( void ); + virtual void Paint( void ); void MsgFunc_SentryMsg(bf_read &msg); @@ -42,7 +43,6 @@ class CHudBuildStateSentry : public CHudElement, public vgui::FFQuantityPanel CHudQuantityBar *m_qbSentryLevel; bool m_bBuilt; - int m_iBarPadding; }; DECLARE_HUDELEMENT(CHudBuildStateSentry); @@ -51,6 +51,7 @@ DECLARE_HUD_MESSAGE(CHudBuildStateSentry, SentryMsg); void CHudBuildStateSentry::Init() { HOOK_HUD_MESSAGE(CHudBuildStateSentry, SentryMsg); + //SetAutoResize(PIN_TOPLEFT,AUTORESIZE_DOWNANDRIGHT,0,0,0,0); <-- this would be nice?? wchar_t *tempString = vgui::localize()->Find("#FF_PLAYER_SENTRYGUN"); @@ -66,25 +67,27 @@ void CHudBuildStateSentry::Init() m_qbSentryHealth->SetLabelText("#FF_ITEM_HEALTH"); m_qbSentryHealth->SetIconChar(":"); - m_qbSentryHealth->SetPosition(m_iBarPadding, m_iBarPadding + 15); - m_qbSentryHealth->SetLabelAlignment(m_qbSentryHealth->ALIGN_RIGHT); m_qbSentryHealth->SetVisible(false); + m_qbSentryHealth->SetPos(40,40); m_qbSentryLevel->SetLabelText("#FF_ITEM_LEVEL"); m_qbSentryLevel->SetAmountMax(3); - m_qbSentryLevel->SetPosition(m_iBarPadding, m_iBarPadding + 35); - m_qbSentryLevel->SetLabelAlignment(2); m_qbSentryLevel->SetIntensityControl(1,2,2,3); m_qbSentryLevel->SetVisible(false); + m_qbSentryLevel->SetPos(40,60); } void CHudBuildStateSentry::VidInit() { - SetPos( vgui::scheme()->GetProportionalScaledValue(100), vgui::scheme()->GetProportionalScaledValue(100) ); - SetWide( vgui::scheme()->GetProportionalScaledValue( 100 ) ); - SetTall( vgui::scheme()->GetProportionalScaledValue( 100 ) ); } void CHudBuildStateSentry::OnTick() { + BaseClass::OnTick(); + + //TO-DO + //I think these should maybe be in VidInit - find out + SetPos( vgui::scheme()->GetProportionalScaledValue(10), vgui::scheme()->GetProportionalScaledValue(325) ); + SetSize(vgui::scheme()->GetProportionalScaledValue(120),vgui::scheme()->GetProportionalScaledValue(90)); + if (!engine->IsInGame()) return; @@ -123,20 +126,6 @@ void CHudBuildStateSentry::OnTick() m_qbSentryHealth->SetVisible(true); m_qbSentryLevel->SetVisible(true); } - - - // Get the screen width/height - int iScreenWide, iScreenTall; - vgui::surface()->GetScreenSize( iScreenWide, iScreenTall ); - - // "map" screen res to 640/480 - float flXScale = 640.0f / iScreenWide; - float flYScale = 480.0f / iScreenTall; - - m_qbSentryHealth->SetScaleX(flXScale); - m_qbSentryLevel->SetScaleX(flXScale); - m_qbSentryHealth->SetScaleY(flYScale); - m_qbSentryLevel->SetScaleY(flYScale); } void CHudBuildStateSentry::Paint() @@ -151,12 +140,12 @@ void CHudBuildStateSentry::Paint() pText = L"Not Built"; // wide char text vgui::surface()->DrawSetTextFont( m_hfText ); // set the font vgui::surface()->DrawSetTextColor( m_ColorText ); - vgui::surface()->DrawSetTextPos( 10, 50 ); // x,y position + vgui::surface()->DrawSetTextPos( 10 * m_flScale, 50 * m_flScale ); // x,y position vgui::surface()->DrawPrintText( pText, wcslen(pText) ); // print text } - + //paint header - FFQuantityPanel::Paint(); + BaseClass::Paint(); } void CHudBuildStateSentry::MsgFunc_SentryMsg(bf_read &msg) diff --git a/cl_dll/ff/ff_hud_quantitybar.cpp b/cl_dll/ff/ff_hud_quantitybar.cpp index d05f04738..8cfcdbe33 100644 --- a/cl_dll/ff/ff_hud_quantitybar.cpp +++ b/cl_dll/ff/ff_hud_quantitybar.cpp @@ -14,16 +14,13 @@ #include "cbase.h" #include "ff_hud_quantitybar.h" -#include -#include - #include "ff_utils.h" // memdbgon must be the last include file in a .cpp file!!! #include "tier0/memdbgon.h" - void CHudQuantityBar::ApplySchemeSettings( vgui::IScheme *pScheme ) - { +void CHudQuantityBar::ApplySchemeSettings( vgui::IScheme *pScheme ) +{ m_hfQuantityBarText = pScheme->GetFont( "QuantityBar", IsProportional() ); m_hfQuantityBarIcon = pScheme->GetFont( "QuantityBarIcon", IsProportional() ); m_hfQuantityBarTextShadow = pScheme->GetFont( "QuantityBarShadow", IsProportional() ); @@ -34,12 +31,11 @@ m_hfLabel = m_hfQuantityBarText; BaseClass::ApplySchemeSettings( pScheme ); - } - +} -void CHudQuantityBar::SetAmountFont(vgui::HFont newAmountFont) { m_hfAmount = newAmountFont; } -void CHudQuantityBar::SetIconFont(vgui::HFont newIconFont) { m_hfIcon = newIconFont; } -void CHudQuantityBar::SetLabelFont(vgui::HFont newLabelFont) { m_hfLabel = newLabelFont; } +void CHudQuantityBar::SetAmountFont(vgui::HFont newAmountFont) { m_hfAmount = newAmountFont; } //updatesomething +void CHudQuantityBar::SetIconFont(vgui::HFont newIconFont) { m_hfIcon = newIconFont; } //updatesomething +void CHudQuantityBar::SetLabelFont(vgui::HFont newLabelFont) { m_hfLabel = newLabelFont; } //updatesomething void CHudQuantityBar::SetAmount(int iAmount) { @@ -48,10 +44,8 @@ void CHudQuantityBar::SetAmount(int iAmount) char szAmount[10]; Q_snprintf( szAmount, 5, "%i%", iAmount ); vgui::localize()->ConvertANSIToUnicode( szAmount, m_wszAmount, sizeof( m_wszAmount ) ); - - m_ColorIntensityFaded = getIntensityColor(m_iAmount, m_iMaxAmount, 2, m_ColorBar.a(), m_iIntenisityRed,m_iIntenisityOrange,m_iIntenisityYellow,m_iIntenisityGreen,m_bIntenisityInvertScale); - m_ColorIntensityStepped = getIntensityColor(m_iAmount, m_iMaxAmount, 1, m_ColorBar.a(), m_iIntenisityRed,m_iIntenisityOrange,m_iIntenisityYellow,m_iIntenisityGreen,m_bIntenisityInvertScale); - + + RecalculateQuantity(); } void CHudQuantityBar::SetAmountMax(int iAmountMax) { @@ -63,6 +57,8 @@ void CHudQuantityBar::SetAmountMax(int iAmountMax) Q_snprintf( szAmountMax, 5, "%i%", iAmountMax ); vgui::localize()->ConvertANSIToUnicode( szAmountMax, m_wszAmountMax, sizeof( m_wszAmountMax ) ); } + + RecalculateQuantity(); } void CHudQuantityBar::SetIconChar(char *newIconChar) @@ -74,6 +70,7 @@ void CHudQuantityBar::SetIconChar(char *newIconChar) void CHudQuantityBar::SetLabelText(char *newLabelText) { wchar_t *pszTemp = vgui::localize()->Find( newLabelText ); + if( pszTemp ) wcscpy( m_wszLabel, pszTemp ); else @@ -88,13 +85,16 @@ void CHudQuantityBar::SetLabelText(wchar_t *newLabelText) wcscpy( m_wszLabel, newLabelText ); } -void CHudQuantityBar::SetPosition(int iPositionX, int iPositionY) { m_iLeft = iPositionX; m_iTop = iPositionY; } -void CHudQuantityBar::SetScaleX(float flScaleX){ m_flScaleX = flScaleX; } -void CHudQuantityBar::SetScaleY(float flScaleY){ m_flScaleY = flScaleY; } -//void CHudQuantityBar::SetVisible(bool isVisible) { m_bVisible = isVisible; } +void CHudQuantityBar::SetPos(int iPositionX, int iPositionY) +{ + m_iLeft = iPositionX; + m_iTop = iPositionY; +} void CHudQuantityBar::SetBarWidth(int iBarWidth) { m_iBarWidth = iBarWidth; } void CHudQuantityBar::SetBarHeight(int iBarHeight) { m_iBarHeight = iBarHeight; } +void CHudQuantityBar::SetBarSize(int iBarWidth, int iBarHeight) { m_iBarWidth = iBarWidth; m_iBarHeight = iBarHeight; } + void CHudQuantityBar::SetBarBorderWidth(int iBarBorderWidth) { m_iBarBorderWidth = iBarBorderWidth; }; void CHudQuantityBar::SetBarOrientation(int iOrientation) { m_iBarOrientation = iOrientation; } @@ -107,39 +107,79 @@ void CHudQuantityBar::ShowLabel(bool bShowLabel) { m_bShowLabel = bShowLabel; } void CHudQuantityBar::ShowAmount(bool bShowAmount) { m_bShowAmount = bShowAmount; } void CHudQuantityBar::ShowAmountMax(bool bShowMax) { m_bShowAmountMax = bShowMax; } -void CHudQuantityBar::SetBarColor( Color newBarColor ) { m_ColorBar = newBarColor; } -void CHudQuantityBar::SetBarBorderColor( Color newBarBorderColor ) { m_ColorBarBorder = newBarBorderColor; } -void CHudQuantityBar::SetBarBackgroundColor( Color newBarBackgroundColor ) { m_ColorBarBackground = newBarBackgroundColor; } -void CHudQuantityBar::SetAmountColor( Color newAmountColor ) { m_ColorAmount = newAmountColor; } -void CHudQuantityBar::SetIconColor( Color newIconColor ) { m_ColorIcon = newIconColor; } -void CHudQuantityBar::SetLabelColor( Color newLabelColor ) { m_ColorLabel = newLabelColor; } -void CHudQuantityBar::SetTeamColor( Color newTeamColor ) { m_ColorTeam = newTeamColor; } - -void CHudQuantityBar::SetBarColorMode( int iColorModeBar ) { m_ColorModeBar = iColorModeBar; } -void CHudQuantityBar::SetBarBorderColorMode( int iColorModeBarBorder ) { m_ColorModeBarBorder = iColorModeBarBorder; } -void CHudQuantityBar::SetBarBackgroundColorMode( int iColorModeBarBackround ) { m_ColorModeBarBackground = iColorModeBarBackround; } -void CHudQuantityBar::SetAmountColorMode( int iColorModeAmount ) { m_ColorModeAmount = iColorModeAmount; } -void CHudQuantityBar::SetIconColorMode( int iColorModeIcon ) { m_ColorModeIcon = iColorModeIcon; } -void CHudQuantityBar::SetLabelColorMode( int iColorModeLabel ) { m_ColorModeLabel = iColorModeLabel; } - -void CHudQuantityBar::SetBarOffsetX(int barOffsetX) { m_iOffsetXBar = barOffsetX; } -void CHudQuantityBar::SetBarOffsetY(int barOffsetY) { m_iOffsetYBar = barOffsetY; } +void CHudQuantityBar::SetBarColor( Color newBarColor ) { + m_ColorBarCustom = newBarColor; + RecalculateColor(m_ColorModeBar, m_ColorBar, m_ColorBarCustom); +} + +void CHudQuantityBar::SetBarBorderColor( Color newBarBorderColor ) { + m_ColorBarBorderCustom = newBarBorderColor; + RecalculateColor(m_ColorModeBarBorder, m_ColorBarBorder, m_ColorBarBorderCustom); +} +void CHudQuantityBar::SetBarBackgroundColor( Color newBarBackgroundColor ) { + m_ColorBarBackgroundCustom = newBarBackgroundColor; + RecalculateColor(m_ColorModeBarBackground, m_ColorBarBackground, m_ColorBarBackgroundCustom); +} +void CHudQuantityBar::SetAmountColor( Color newAmountColor ) { + m_ColorAmountCustom = newAmountColor; + RecalculateColor(m_ColorModeAmount, m_ColorAmount, m_ColorAmountCustom); +} +void CHudQuantityBar::SetIconColor( Color newIconColor ) { + m_ColorIconCustom = newIconColor; + RecalculateColor(m_ColorModeIcon, m_ColorIcon, m_ColorIconCustom); +} +void CHudQuantityBar::SetLabelColor( Color newLabelColor ) { + m_ColorLabelCustom = newLabelColor; + RecalculateColor(m_ColorModeLabel, m_ColorLabel, m_ColorLabelCustom); +} +void CHudQuantityBar::SetTeamColor( Color newTeamColor ) { + m_ColorTeam = newTeamColor; + //see which use team colour and update?? +} + +void CHudQuantityBar::SetBarColorMode( int iColorModeBar ) { + m_ColorModeBar = iColorModeBar; + RecalculateColor(m_ColorModeBar, m_ColorBarBorder, m_ColorBarCustom); +} +void CHudQuantityBar::SetBarBorderColorMode( int iColorModeBarBorder ) { + m_ColorModeBarBorder = iColorModeBarBorder; + RecalculateColor(m_ColorModeBarBorder, m_ColorBarBorder, m_ColorBarBorderCustom); +} +void CHudQuantityBar::SetBarBackgroundColorMode( int iColorModeBarBackround ) { + m_ColorModeBarBackground = iColorModeBarBackround; + RecalculateColor(m_ColorModeBarBackground, m_ColorBarBackground, m_ColorBarBackgroundCustom); +} +void CHudQuantityBar::SetAmountColorMode( int iColorModeAmount ) { + m_ColorModeAmount = iColorModeAmount; + RecalculateColor(m_ColorModeAmount, m_ColorAmount, m_ColorAmountCustom); +} +void CHudQuantityBar::SetIconColorMode( int iColorModeIcon ) { + m_ColorModeIcon = iColorModeIcon; + RecalculateColor(m_ColorModeIcon, m_ColorIcon, m_ColorIconCustom); + +} +void CHudQuantityBar::SetLabelColorMode( int iColorModeLabel ) { + m_ColorModeLabel = iColorModeLabel; + RecalculateColor(m_ColorModeLabel, m_ColorLabel, m_ColorLabelCustom); +} + void CHudQuantityBar::SetIconOffsetX(int iconOffsetX) { m_iOffsetXIcon = iconOffsetX; } void CHudQuantityBar::SetIconOffsetY(int iconOffsetY) { m_iOffsetYIcon = iconOffsetY; } +void CHudQuantityBar::SetIconOffset(int iconOffsetX, int iconOffsetY) { m_iOffsetXIcon = iconOffsetX; m_iOffsetYIcon = iconOffsetY; } + void CHudQuantityBar::SetLabelOffsetX(int labelOffsetX) { m_iOffsetXLabel = labelOffsetX; } void CHudQuantityBar::SetLabelOffsetY(int labelOffsetY) { m_iOffsetYLabel = labelOffsetY; } +void CHudQuantityBar::SetLabelOffset(int labelOffsetX, int labelOffsetY) { m_iOffsetXLabel = labelOffsetX; m_iOffsetYLabel = labelOffsetY; } + void CHudQuantityBar::SetAmountOffsetX(int amountOffsetX) { m_iOffsetXAmount = amountOffsetX; } void CHudQuantityBar::SetAmountOffsetY(int amountOffsetY) { m_iOffsetYAmount = amountOffsetY; } +void CHudQuantityBar::SetAmountOffset(int amountOffsetX, int amountOffsetY) { m_iOffsetXAmount = amountOffsetX; m_iOffsetYAmount = amountOffsetY; } int CHudQuantityBar::GetAmount() {return m_iAmount; } -void CHudQuantityBar::SetLabelAlignment(int iLabelAlign) { m_iAlignLabel = iLabelAlign; } -void CHudQuantityBar::SetAmountAlignment(int iAmountAlign) { m_iAlignAmount = iAmountAlign; } +void CHudQuantityBar::SetLabelTextAlignment(int iLabelTextAlign) { m_iTextAlignLabel = iLabelTextAlign; } +void CHudQuantityBar::SetAmountTextAlignment(int iAmountTextAlign) { m_iTextAlignAmount = iAmountTextAlign; } -void CHudQuantityBar::SetIntensityControl(int iRed, int iOrange,int iYellow, int iGreen) -{ - SetIntensityControl(iRed,iOrange,iYellow,iGreen,false); -} void CHudQuantityBar::SetIntensityControl(int iRed, int iOrange,int iYellow, int iGreen, bool bInvertScale) { m_iIntenisityRed = iRed; @@ -149,192 +189,257 @@ void CHudQuantityBar::SetIntensityControl(int iRed, int iOrange,int iYellow, int m_bIntenisityInvertScale = bInvertScale; } -void CHudQuantityBar::PaintBackground() +void CHudQuantityBar::OnTick() { - if((m_bShowBarBackground || m_bShowBarBorder)) + // Get the screen width/height + int iScreenWide, iScreenTall; + vgui::surface()->GetScreenSize( iScreenWide, iScreenTall ); + + // "map" screen res to 640/480 + float flScaleX = 1 / (640.0f / iScreenWide); + float flScaleY = 1 / (480.0f / iScreenTall); + + if( m_flScale != (flScaleXDrawSetColor( barBorderColor ); - for(int i = 1; m_flScaleX>m_flScaleY ? i<=m_iBarBorderWidth*1/m_flScaleX : i<=m_iBarBorderWidth*1/m_flScaleY;++i) - { - vgui::surface()->DrawOutlinedRect( iLeft + iOffsetXBar - i, iTop + iOffsetYBar - i, iRight + iOffsetXBar + i, iBottom + iOffsetYBar + i); - } - } + m_flScale = (flScaleXDrawSetColor( m_ColorBarBorder ); + for( int i = 1; i <= (m_iBarBorderWidth * m_flScale); ++i ) + { + vgui::surface()->DrawOutlinedRect( + m_iLeft * m_flScale - i, + m_iTop * m_flScale - i, + (m_iLeft + m_iBarWidth) * m_flScale + i, + (m_iTop + m_iBarHeight) * m_flScale + i + ); + } + } - vgui::surface()->DrawSetColor( barBackgroundColor ); - vgui::surface()->DrawFilledRect( iLeft + iOffsetXBar, iTop + iOffsetYBar, iLeft + iBarWidth + iOffsetXBar, iBottom + iOffsetYBar); + if(m_bShowBarBackground) + { + vgui::surface()->DrawSetColor( m_ColorBarBackground ); + vgui::surface()->DrawFilledRect( + m_iLeft * m_flScale, + m_iTop * m_flScale, + (m_iLeft + m_iBarWidth) * m_flScale, + (m_iTop + m_iBarHeight) * m_flScale + ); } if(m_bShowBar) { - Color barColor; - if(m_ColorModeBar == COLOR_MODE_STEPPED ) - barColor.SetColor(m_ColorIntensityStepped.r(),m_ColorIntensityStepped.g(),m_ColorIntensityStepped.b(),m_ColorBar.a()); - else if(m_ColorModeBar == 2 ) - barColor.SetColor(m_ColorIntensityFaded.r(),m_ColorIntensityFaded.g(),m_ColorIntensityFaded.b(),m_ColorBar.a()); - else if(m_ColorModeBar == 3 ) - barColor.SetColor(m_ColorTeam.r(),m_ColorTeam.g(),m_ColorTeam.b(),m_ColorBar.a()); - else - barColor = m_ColorBar; - - vgui::surface()->DrawSetColor( barColor ); - if(m_iBarOrientation == ORIENTATION_HORIZONTAL_INVERTED) - vgui::surface()->DrawFilledRect( iRight + iOffsetXBar - (iBarWidth * m_iAmount/m_iMaxAmount), iTop + iOffsetYBar, iRight + iOffsetXBar, iBottom + iOffsetYBar); - else if(m_iBarOrientation == ORIENTATION_VERTICAL) - vgui::surface()->DrawFilledRect( iLeft + iOffsetXBar, iTop + iOffsetYBar, iRight + iOffsetXBar, iTop + iOffsetYBar + (iBarHeight * m_iAmount/m_iMaxAmount)); - else if(m_iBarOrientation == ORIENTATION_VERTICAL_INVERTED) - vgui::surface()->DrawFilledRect( iLeft + iOffsetXBar, iBottom + iOffsetYBar - (iBarHeight * m_iAmount/m_iMaxAmount), iRight + iOffsetXBar, iBottom + iOffsetYBar); - else //m_iBarOrientation == ORIENTATION_HORIZONTAL (or anything else) - vgui::surface()->DrawFilledRect( iLeft + iOffsetXBar, iTop + iOffsetYBar, iLeft + iOffsetXBar + (iBarWidth * m_iAmount/m_iMaxAmount), iBottom + iOffsetYBar); + vgui::surface()->DrawSetColor( m_ColorBar ); + vgui::surface()->DrawFilledRect( + (m_iLeft + m_iBarX0QuantityOffset) * m_flScale, + (m_iTop + m_iBarY0QuantityOffset) * m_flScale, + (m_iLeft + m_iBarWidth + m_iBarX1QuantityOffset) * m_flScale, + (m_iTop + m_iBarHeight + m_iBarY1QuantityOffset) * m_flScale + ); } if(m_bShowIcon && m_hfIcon && m_wszIcon) { - int iconWidth, iconHeight; - Color iconColor; - if(m_ColorModeIcon == COLOR_MODE_STEPPED ) - iconColor.SetColor(m_ColorIntensityStepped.r(),m_ColorIntensityStepped.g(),m_ColorIntensityStepped.b(),m_ColorIcon.a()); - else if(m_ColorModeIcon == COLOR_MODE_FADED ) - iconColor.SetColor(m_ColorIntensityFaded.r(),m_ColorIntensityFaded.g(),m_ColorIntensityFaded.b(),m_ColorIcon.a()); - else if(m_ColorModeIcon == COLOR_MODE_TEAMCOLORED ) - iconColor.SetColor(m_ColorTeam.r(),m_ColorTeam.g(),m_ColorTeam.b(),m_ColorIcon.a()); - else - iconColor = m_ColorIcon; - - vgui::surface()->GetTextSize(m_hfIcon, m_wszIcon, iconWidth, iconHeight); vgui::surface()->DrawSetTextFont(m_hfIcon); - vgui::surface()->DrawSetTextColor( iconColor ); - vgui::surface()->DrawSetTextPos(iLeft + iOffsetXIcon - iconWidth/2, iTop + iOffsetYIcon + (iBarHeight+2-iconHeight)/2 + 1); + vgui::surface()->DrawSetTextColor( m_ColorIcon ); + vgui::surface()->DrawSetTextPos( + (m_iLeft + m_iOffsetXIcon) * m_flScale + iIconAlignmentOffsetX, + (m_iTop + m_iOffsetYIcon) * m_flScale + iIconAlignmentOffsetY + ); vgui::surface()->DrawUnicodeString( m_wszIcon ); } + if(m_bShowLabel && m_hfLabel && m_wszLabel) - { - int labelWidth, labelHeight; - Color labelColor; - if(m_ColorModeLabel == COLOR_MODE_STEPPED ) - labelColor.SetColor(m_ColorIntensityStepped.r(),m_ColorIntensityStepped.g(),m_ColorIntensityStepped.b(),m_ColorLabel.a()); - else if(m_ColorModeLabel == COLOR_MODE_FADED ) - labelColor.SetColor(m_ColorIntensityFaded.r(),m_ColorIntensityFaded.g(),m_ColorIntensityFaded.b(),m_ColorLabel.a()); - else if(m_ColorModeLabel == COLOR_MODE_TEAMCOLORED ) - labelColor.SetColor(m_ColorTeam.r(),m_ColorTeam.g(),m_ColorTeam.b(),m_ColorLabel.a()); - else - labelColor = m_ColorLabel; - - vgui::surface()->GetTextSize(m_hfLabel, m_wszLabel, labelWidth, labelHeight); + { vgui::surface()->DrawSetTextFont(m_hfLabel); - vgui::surface()->DrawSetTextColor( labelColor ); + vgui::surface()->DrawSetTextColor( m_ColorLabel ); + vgui::surface()->DrawSetTextPos( + (m_iLeft + m_iOffsetXLabel) * m_flScale + iLabelAlignmentOffsetX, + (m_iTop + m_iOffsetYLabel) * m_flScale + iLabelAlignmentOffsetY + ); + vgui::surface()->DrawUnicodeString( m_wszLabel ); + } - if(m_iAlignLabel == ALIGN_CENTER) - vgui::surface()->DrawSetTextPos(iLeft - labelWidth/2 + iOffsetXLabel, iTop + (iBarHeight+2-labelHeight)/2 + iOffsetYLabel); - else if(m_iAlignLabel == ALIGN_RIGHT) - vgui::surface()->DrawSetTextPos(iLeft - labelWidth + iOffsetXLabel, iTop + (iBarHeight+2-labelHeight)/2 + iOffsetYLabel); + if(m_bShowAmount && m_hfAmount && m_wszAmount) + { + vgui::surface()->DrawSetTextFont(m_hfAmount); + vgui::surface()->DrawSetTextColor( m_ColorAmount ); + vgui::surface()->DrawSetTextPos( + (m_iLeft + m_iOffsetXAmount) * m_flScale + iAmountAlignmentOffsetX, + (m_iTop + m_iOffsetYAmount) * m_flScale + iAmountAlignmentOffsetY + ); + vgui::surface()->DrawUnicodeString( m_wszAmountString ); + } +} + +void CHudQuantityBar::RecalculateQuantity() +//all this regardless of whether each item is actually being shown +//(incase the user changes options during the game) +{ + m_ColorIntensityFaded = getIntensityColor(m_iAmount, m_iMaxAmount, 2, m_ColorBarCustom.a(), m_iIntenisityRed,m_iIntenisityOrange,m_iIntenisityYellow,m_iIntenisityGreen,m_bIntenisityInvertScale); + m_ColorIntensityStepped = getIntensityColor(m_iAmount, m_iMaxAmount, 1, m_ColorBarCustom.a(), m_iIntenisityRed,m_iIntenisityOrange,m_iIntenisityYellow,m_iIntenisityGreen,m_bIntenisityInvertScale); + + if(!m_bShowAmountMax) + { + if(m_iMaxAmount == 100)// already a percentage no need to convert + _snwprintf( m_wszAmountString, 255, L"%s%%", m_wszAmount ); else - vgui::surface()->DrawSetTextPos(iLeft + iOffsetXLabel, iTop + (iBarHeight+2-labelHeight)/2 + iOffsetYLabel); + { + char szPercent[ 5 ]; + wchar_t wszPercent[ 10 ]; + float percent = ((float)m_iAmount/(float)m_iMaxAmount*100.0f); + Q_snprintf( szPercent, 5, "%i%", (int)percent); - vgui::surface()->DrawUnicodeString( m_wszLabel ); - } + vgui::localize()->ConvertANSIToUnicode( szPercent, wszPercent, sizeof( wszPercent ) ); - wchar_t wszString[ 10 ]; + _snwprintf( m_wszAmountString, 9, L"%s%%", wszPercent ); + } + } + else + { + _snwprintf( m_wszAmountString, 9, L"%s/%s", m_wszAmount, m_wszAmountMax ); + } - if(m_bShowAmount && m_hfAmount && m_wszAmount) + if(m_ColorModeBarBorder == COLOR_MODE_FADED ) + m_ColorBarBorder.SetColor(m_ColorIntensityFaded.r(),m_ColorIntensityFaded.g(),m_ColorIntensityFaded.b(),m_ColorBarBorderCustom.a()); + else if(m_ColorModeBarBorder == COLOR_MODE_STEPPED ) + m_ColorBarBorder.SetColor(m_ColorIntensityStepped.r(),m_ColorIntensityStepped.g(),m_ColorIntensityStepped.b(),m_ColorBarBorder.a()); + + if(m_ColorModeBarBackground == COLOR_MODE_FADED ) + m_ColorBarBackground.SetColor(m_ColorIntensityFaded.r(),m_ColorIntensityFaded.g(),m_ColorIntensityFaded.b(),m_ColorBarBackgroundCustom.a()); + else if(m_ColorModeBarBackground == COLOR_MODE_STEPPED ) + m_ColorBarBackground.SetColor(m_ColorIntensityStepped.r(),m_ColorIntensityStepped.g(),m_ColorIntensityStepped.b(),m_ColorBarBackgroundCustom.a()); + + if(m_ColorModeBar == COLOR_MODE_FADED ) + m_ColorBar.SetColor(m_ColorIntensityFaded.r(),m_ColorIntensityFaded.g(),m_ColorIntensityFaded.b(),m_ColorBarCustom.a()); + else if(m_ColorModeBar == COLOR_MODE_STEPPED ) + m_ColorBar.SetColor(m_ColorIntensityStepped.r(),m_ColorIntensityStepped.g(),m_ColorIntensityStepped.b(),m_ColorBarCustom.a()); + + if(m_ColorModeIcon == COLOR_MODE_FADED ) + m_ColorIcon.SetColor(m_ColorIntensityFaded.r(),m_ColorIntensityFaded.g(),m_ColorIntensityFaded.b(),m_ColorIconCustom.a()); + else if(m_ColorModeIcon == COLOR_MODE_STEPPED ) + m_ColorIcon.SetColor(m_ColorIntensityStepped.r(),m_ColorIntensityStepped.g(),m_ColorIntensityStepped.b(),m_ColorIconCustom.a()); + + if(m_ColorModeLabel == COLOR_MODE_FADED ) + m_ColorLabel.SetColor(m_ColorIntensityFaded.r(),m_ColorIntensityFaded.g(),m_ColorIntensityFaded.b(),m_ColorLabelCustom.a()); + else if(m_ColorModeLabel == COLOR_MODE_STEPPED ) + m_ColorLabel.SetColor(m_ColorIntensityStepped.r(),m_ColorIntensityStepped.g(),m_ColorIntensityStepped.b(),m_ColorLabelCustom.a()); + + if(m_ColorModeAmount == COLOR_MODE_FADED ) + m_ColorAmount.SetColor(m_ColorIntensityFaded.r(),m_ColorIntensityFaded.g(),m_ColorIntensityFaded.b(),m_ColorAmountCustom.a()); + else if(m_ColorModeAmount == COLOR_MODE_STEPPED ) + m_ColorAmount.SetColor(m_ColorIntensityStepped.r(),m_ColorIntensityStepped.g(),m_ColorIntensityStepped.b(),m_ColorAmountCustom.a()); + + if(m_iBarOrientation == ORIENTATION_HORIZONTAL_INVERTED) { - if(!m_bShowAmountMax) + m_iBarX0QuantityOffset = m_iBarWidth-(m_iBarHeight * m_iAmount/m_iMaxAmount); + if( (m_iBarX1QuantityOffset + m_iBarY0QuantityOffset + m_iBarY1QuantityOffset) > 0 ) { - if(m_iMaxAmount == 100)// already a percentage no need to convert - _snwprintf( wszString, 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); - - vgui::localize()->ConvertANSIToUnicode( szPercent, wszPercent, sizeof( wszPercent ) ); - - _snwprintf( wszString, 9, L"%s%%", wszPercent ); - } + m_iBarX1QuantityOffset = 0; + m_iBarY0QuantityOffset = 0; + m_iBarY1QuantityOffset = 0; } - else + } + else if(m_iBarOrientation == ORIENTATION_VERTICAL) + { + m_iBarY0QuantityOffset = m_iBarHeight - (m_iBarHeight * m_iAmount/m_iMaxAmount); + if( (m_iBarX0QuantityOffset + m_iBarX1QuantityOffset + m_iBarY1QuantityOffset) > 0 ) { - _snwprintf( wszString, 9, L"%s/%s", m_wszAmount, m_wszAmountMax ); + m_iBarX0QuantityOffset = 0; + m_iBarX1QuantityOffset = 0; + m_iBarY1QuantityOffset = 0; } - - int amountWidth, amountHeight; - Color amountColor; - if(m_ColorModeAmount == COLOR_MODE_STEPPED ) - amountColor.SetColor(m_ColorIntensityStepped.r(),m_ColorIntensityStepped.g(),m_ColorIntensityStepped.b(),m_ColorAmount.a()); - else if(m_ColorModeAmount == COLOR_MODE_FADED ) - amountColor.SetColor(m_ColorIntensityFaded.r(),m_ColorIntensityFaded.g(),m_ColorIntensityFaded.b(),m_ColorAmount.a()); - else if(m_ColorModeAmount == COLOR_MODE_TEAMCOLORED ) - amountColor.SetColor(m_ColorTeam.r(),m_ColorTeam.g(),m_ColorTeam.b(),m_ColorAmount.a()); - else - amountColor = m_ColorAmount; + } + else if(m_iBarOrientation == 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) + { + 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; + } + } +} - vgui::surface()->GetTextSize(m_hfAmount, wszString, amountWidth, amountHeight); - vgui::surface()->DrawSetTextFont(m_hfAmount); - vgui::surface()->DrawSetTextColor( amountColor ); +void CHudQuantityBar::RecalculateColor(int &colorMode, Color &color, Color &colorCustom) +{ + if(colorMode == COLOR_MODE_STEPPED ) + color.SetColor(m_ColorIntensityStepped.r(),m_ColorIntensityStepped.g(),m_ColorIntensityStepped.b(),colorCustom.a()); + else if(m_ColorModeBarBackground == COLOR_MODE_TEAMCOLORED ) + color.SetColor(m_ColorTeam.r(),m_ColorTeam.g(),m_ColorTeam.b(),colorCustom.a()); + else if( m_ColorModeBarBorder == COLOR_MODE_FADED ) + color.SetColor(m_ColorIntensityFaded.r(),m_ColorIntensityFaded.g(),m_ColorIntensityFaded.b(),colorCustom.a()); + else + color = colorCustom; +} - if(m_iAlignAmount == ALIGN_CENTER) - vgui::surface()->DrawSetTextPos(iLeft - amountWidth/2 + iOffsetXAmount, iTop + (iBarHeight+2-amountHeight)/2 + iOffsetYAmount); - else if(m_iAlignAmount == ALIGN_RIGHT) - vgui::surface()->DrawSetTextPos(iLeft - amountWidth + iOffsetXAmount, iTop + (iBarHeight+2-amountHeight)/2 + iOffsetYAmount); - else - vgui::surface()->DrawSetTextPos(iLeft + iOffsetXAmount, iTop + (iBarHeight+2-amountHeight)/2 + iOffsetYAmount); +void CHudQuantityBar::CalculateAbsTextAlignmentOffset(int &outX, int &outY, int iAlignmentMode, vgui::HFont hfFont, wchar_t* wszString) +{ + int iWide, iTall; + vgui::surface()->GetTextSize(hfFont, wszString, iWide, iTall); - vgui::surface()->DrawUnicodeString( wszString ); + outY = (m_iBarHeight * m_flScale - iTall) / 2; + switch(iAlignmentMode) + { + case TEXTALIGN_CENTER: + outX = - iWide/2; + break; + case TEXTALIGN_RIGHT: + outX = - iWide; + break; + case TEXTALIGN_LEFT: + default: + outX = 0; } } \ No newline at end of file diff --git a/cl_dll/ff/ff_hud_quantitybar.h b/cl_dll/ff/ff_hud_quantitybar.h index c27f1f260..d2996eb97 100644 --- a/cl_dll/ff/ff_hud_quantitybar.h +++ b/cl_dll/ff/ff_hud_quantitybar.h @@ -31,88 +31,71 @@ class CHudQuantityBar : public CHudElement, public vgui::Panel CHudQuantityBar(vgui::Panel *parent, const char *pElementName) : CHudElement(pElementName), vgui::Panel(parent, pElementName) { SetParent( parent ); - SetSize(vgui::scheme()->GetProportionalScaledValue(640), vgui::scheme()->GetProportionalScaledValue(480)); - - m_flScaleX = 1.0f; - m_flScaleY = 1.0f; - m_iTop = 50; - m_iLeft = 50; - - m_iBarWidth = 60; - m_iBarHeight = 13; - m_iBarBorderWidth = 1; - - m_iBarOrientation = ORIENTATION_HORIZONTAL; - - m_iAlignLabel = ALIGN_RIGHT; - m_iAlignAmount = ALIGN_CENTER; - - m_iOffsetXBar = 0; - m_iOffsetYBar = 0; - m_iOffsetXIcon = 5; - m_iOffsetYIcon = 0; - m_iOffsetXLabel = -5; - m_iOffsetYLabel = 0; - m_iOffsetXAmount = 35; - m_iOffsetYAmount = 0; - - m_iIntenisityRed = 20; - m_iIntenisityOrange = 50; - m_iIntenisityYellow = 80; - m_iIntenisityGreen = 100; - m_bIntenisityInvertScale = false; - - m_ColorModeBar = COLOR_MODE_STEPPED; - m_ColorModeBarBorder = COLOR_MODE_CUSTOM; - m_ColorModeBarBackground = COLOR_MODE_STEPPED; - m_ColorModeIcon = COLOR_MODE_CUSTOM; - m_ColorModeLabel = COLOR_MODE_CUSTOM; - m_ColorModeAmount = COLOR_MODE_CUSTOM; - - SetAmountMax(100); //use the function to generate the text - - m_bShowBar = true; - m_bShowBarBackground = true; - m_bShowBarBorder = true; - m_bShowIcon = true; - m_bShowLabel = true; - m_bShowAmount = true; - m_bShowAmountMax = true; - m_bVisible = true; - - m_ColorBarBorder.SetColor(192,192,192,255); - m_ColorBarBackground.SetColor(255,255,255,80); - m_ColorBar.SetColor(255,255,255,255); - m_ColorIcon.SetColor(255,255,255,255); - m_ColorLabel.SetColor(255,255,255,255); - m_ColorAmount.SetColor(255,255,255,255); + SetSize(vgui::scheme()->GetProportionalScaledValue(640),vgui::scheme()->GetProportionalScaledValue(480)); + + m_flScale = 1.0f; + + SetPos(0,0); + SetBarSize(60, 13); + SetBarBorderWidth(1); + + SetBarOrientation(ORIENTATION_HORIZONTAL); + + m_iTextAlignLabel = TEXTALIGN_RIGHT; + m_iTextAlignAmount = TEXTALIGN_CENTER; + + SetIconOffset(5,0); + SetLabelOffset(-5, 0); + SetAmountOffset(35, 0); + + SetIntensityControl(20,50,80,100); + + SetBarBorderColor(Color(255,255,255,255)); + SetBarBackgroundColor(Color(192,192,192,80)); + SetBarColor(Color(255,255,255,255)); + SetIconColor(Color(255,255,255,255)); + SetLabelColor(Color(255,255,255,255)); + SetAmountColor(Color(255,255,255,255)); + + SetBarColorMode(COLOR_MODE_STEPPED); + SetBarBorderColorMode(COLOR_MODE_CUSTOM); + SetBarBackgroundColorMode(COLOR_MODE_STEPPED); + SetIconColorMode(COLOR_MODE_CUSTOM); + SetLabelColorMode(COLOR_MODE_CUSTOM); + SetAmountColorMode(COLOR_MODE_CUSTOM); + + SetAmountMax(100); + + ShowBar(true); + ShowBarBackground(true); + ShowBarBorder(true); + ShowIcon(true); + ShowLabel(true); + ShowAmount(true); + ShowAmountMax(true); + + vgui::ivgui()->AddTickSignal(GetVPanel(), 250); //only update 4 times a second } - enum { + enum ColorMode { COLOR_MODE_CUSTOM=0, COLOR_MODE_STEPPED, COLOR_MODE_FADED, COLOR_MODE_TEAMCOLORED }; - enum { - ALIGN_LEFT=0, - ALIGN_CENTER, - ALIGN_RIGHT + enum TextAlignment { + TEXTALIGN_LEFT=0, + TEXTALIGN_CENTER, + TEXTALIGN_RIGHT }; - enum { + enum OrientationMode { ORIENTATION_HORIZONTAL=0, ORIENTATION_VERTICAL, ORIENTATION_HORIZONTAL_INVERTED, ORIENTATION_VERTICAL_INVERTED }; - - void SetScaleX(float flScaleX); - void SetScaleY(float flScaleY); - - //void SetBarOffset(int x, int y); - void SetAmountFont(vgui::HFont newAmountFont); void SetIconFont(vgui::HFont newIconFont); void SetLabelFont(vgui::HFont newLabelFont); @@ -124,14 +107,14 @@ class CHudQuantityBar : public CHudElement, public vgui::Panel void SetLabelText(char *newLabelText); void SetLabelText(wchar_t *newLabelText); - void SetPosition(int iPositionX, int iPositionY); void SetBarWidth(int iBarWidth); void SetBarHeight(int iBarHeight); + void SetBarSize(int iBarWidth, int iBarHeight); void SetBarBorderWidth(int iBarBorderWidth); void SetBarOrientation(int iOrientation); - void SetLabelAlignment(int iLabelAlign); - void SetAmountAlignment(int iAmountAlign); + void SetLabelTextAlignment(int iLabelTextAlign); + void SetAmountTextAlignment(int iAmountTextAlign); void ShowBar(bool bShowBar); void ShowBarBorder(bool bShowBarBorder); @@ -141,8 +124,6 @@ class CHudQuantityBar : public CHudElement, public vgui::Panel void ShowLabel(bool bShowLabel); void ShowAmountMax(bool bShowAmountMax); - //void SetVisible(bool bIsVisible); - void SetBarColor( Color newColorBar ); void SetBarBorderColor( Color newBarBorderColor ); void SetBarBackgroundColor( Color newBarBorderColor ); @@ -151,14 +132,15 @@ class CHudQuantityBar : public CHudElement, public vgui::Panel void SetLabelColor( Color newLabelColor ); void SetTeamColor( Color newTeamColor ); - void SetBarOffsetX(int barOffsetX); - void SetBarOffsetY(int barOffsetY); void SetIconOffsetX(int iconOffsetX); void SetIconOffsetY(int iconOffsetY); + void SetIconOffset(int iconOffsetX, int iconOffsetY); void SetLabelOffsetX(int labelOffsetX); void SetLabelOffsetY(int labelOffsetY); + void SetLabelOffset(int labelOffsetX, int labelOffsetY); void SetAmountOffsetX(int amountOffsetX); void SetAmountOffsetY(int amountOffsetY); + void SetAmountOffset(int amountOffsetX, int amountOffsetY); void SetBarColorMode( int iColorModeBar ); void SetBarBorderColorMode( int iColorModeBarBorder ); @@ -167,14 +149,21 @@ class CHudQuantityBar : public CHudElement, public vgui::Panel void SetIconColorMode( int iColorModeIcon ); void SetLabelColorMode( int iColoModerLabel ); - void SetIntensityControl(int iRed, int iOrange,int iYellow, int iGreen); - void SetIntensityControl(int iRed, int iOrange,int iYellow, int iGreen, bool bInvertScale); + void SetIntensityControl(int iRed, int iOrange,int iYellow, int iGreen, bool bInvertScale = false); int GetAmount(); virtual void Paint(); - virtual void PaintBackground(); + virtual void OnTick(); + virtual void SetPos(int iPositionX, int iPositionY); + protected: + void CalculateAbsTextAlignmentOffset(int &outX, int &outY, int iAlignmentMode, vgui::HFont hfFont, wchar_t* wszString); + void RecalculateQuantity(); + void RecalculateDimentions(); + + void RecalculateColor(int &colorMode, Color &color, Color &colorCustom); + virtual void ApplySchemeSettings( vgui::IScheme *pScheme ); vgui::HFont m_hfAmount; @@ -186,10 +175,15 @@ class CHudQuantityBar : public CHudElement, public vgui::Panel vgui::HFont m_hfQuantityBarTextShadow; vgui::HFont m_hfQuantityBarIconShadow; - float m_flScaleX; - float m_flScaleY; + float m_flScale; + int m_iTop; int m_iLeft; + + int m_iBarX0QuantityOffset; + int m_iBarY0QuantityOffset; + int m_iBarX1QuantityOffset; + int m_iBarY1QuantityOffset; int m_iAmount; int m_iMaxAmount; @@ -199,11 +193,9 @@ class CHudQuantityBar : public CHudElement, public vgui::Panel int m_iBarBorderWidth; int m_iBarOrientation; - int m_iAlignLabel; - int m_iAlignAmount; + int m_iTextAlignLabel; + int m_iTextAlignAmount; - int m_iOffsetXBar; - int m_iOffsetYBar; int m_iOffsetXIcon; int m_iOffsetYIcon; int m_iOffsetXLabel; @@ -216,6 +208,8 @@ class CHudQuantityBar : public CHudElement, public vgui::Panel wchar_t m_wszIcon[ 2 ]; wchar_t m_wszLabel[ 32 ]; + wchar_t m_wszAmountString[ 10 ]; + bool m_bShowBar; bool m_bShowBarBackground; bool m_bShowBarBorder; @@ -224,23 +218,28 @@ class CHudQuantityBar : public CHudElement, public vgui::Panel bool m_bShowAmount; bool m_bShowAmountMax; - bool m_bVisible; - int m_iIntenisityRed; int m_iIntenisityOrange; int m_iIntenisityYellow; int m_iIntenisityGreen; int m_bIntenisityInvertScale; - Color m_ColorBar; + Color m_ColorBarCustom; + Color m_ColorBarBorderCustom; + Color m_ColorBarBackgroundCustom; + Color m_ColorIconCustom; + Color m_ColorLabelCustom; + Color m_ColorAmountCustom; + Color m_ColorTeam; + Color m_ColorIntensityFaded; + Color m_ColorIntensityStepped; + Color m_ColorBarBorder; - Color m_ColorBarBackground; + Color m_ColorBarBackground; + Color m_ColorBar; Color m_ColorIcon; Color m_ColorLabel; Color m_ColorAmount; - Color m_ColorTeam; - Color m_ColorIntensityFaded; - Color m_ColorIntensityStepped; int m_ColorModeBar; int m_ColorModeBarBorder; diff --git a/cl_dll/ff/vgui/ff_quantitypanel.cpp b/cl_dll/ff/vgui/ff_quantitypanel.cpp index 2a479c913..10b25e29c 100644 --- a/cl_dll/ff/vgui/ff_quantitypanel.cpp +++ b/cl_dll/ff/vgui/ff_quantitypanel.cpp @@ -1,16 +1,15 @@ #include "cbase.h" #include "ff_quantitypanel.h" -#include +#include "ff_hud_quantitybar.h" +#include +#include #include +#include namespace vgui { void FFQuantityPanel::ApplySchemeSettings( vgui::IScheme *pScheme ) { - SetSize(vgui::scheme()->GetProportionalScaledValue(640), vgui::scheme()->GetProportionalScaledValue(480)); - - m_ColorBackground = pScheme->GetColor( "HUD_BG_Default", Color(255,0,0,255) ); - m_ColorBorder = pScheme->GetColor( "HUD_Border_Default", Color(255,0,0,255) ); m_ColorHeaderText = pScheme->GetColor( "HUD_Tone_Bright", Color(255,0,0,255) ); m_ColorHeaderIcon = m_ColorHeaderText; m_ColorText = pScheme->GetColor( "HUD_Tone_Default", Color(255,0,0,255) ); @@ -19,35 +18,102 @@ namespace vgui SetPaintBorderEnabled(true); SetPaintEnabled(true); - SetBgColor(Color(244,244,244,120)); - SetBorderColor(m_ColorBorder); - SetPaintBackgroundType(1); + SetPaintBackgroundType(2); SetBorder(pScheme->GetBorder("ScoreBoardItemBorder")); + SetBgColor(pScheme->GetColor( "HUD_BG_Default", Color(255,0,0,255))); m_hfHeaderText = pScheme->GetFont( "QuantityPanelHeader", IsProportional() ); m_hfHeaderIcon = pScheme->GetFont( "QuantityPanelHeaderIcon", IsProportional() ); m_hfText = pScheme->GetFont( "QuantityPanel", IsProportional() ); Panel::ApplySchemeSettings( pScheme ); - } + } + + void FFQuantityPanel::OnTick() + { + // Get the screen width/height + int iScreenWide, iScreenTall; + vgui::surface()->GetScreenSize( iScreenWide, iScreenTall ); + + // "map" screen res to 640/480 + float flScaleX = 1 / (640.0f / iScreenWide); + float flScaleY = 1 / (480.0f / iScreenTall); + + if( m_flScale != (flScaleX(GetChild(i)); + if (qbPtr) + // If child is a quantity bar + { + if(iRow == 0) + if(iColumn == 0) + //very first item + qbPtr->SetPos( + m_iQuantityBarPositionX + m_iColumnOffset[iColumn], + m_iQuantityBarPositionY + m_iRowOffset[iRow] + ); + else + qbPtr->SetPos( + m_iQuantityBarPositionX + m_iColumnOffset[iColumn] + m_iColumnWidth[iColumn - 1] + iColumn * m_iQuantityBarSpacingX, + m_iQuantityBarPositionY + m_iRowOffset[iRow] + ); + else + if(iColumn == 0) + qbPtr->SetPos( + m_iQuantityBarPositionX + m_iColumnOffset[iColumn], + m_iQuantityBarPositionY + m_iRowOffset[iRow] + m_iRowWidth[iColumn - 1] + iRow * m_iQuantityBarSpacingY + ); + else + qbPtr->SetPos( + m_iQuantityBarPositionX + m_iColumnOffset[iColumn] + m_iColumnWidth[iColumn - 1] + iColumn * m_iQuantityBarSpacingX, + m_iQuantityBarPositionY + m_iRowOffset[iRow] + m_iRowWidth[iColumn - 1] + iRow * m_iQuantityBarSpacingY + ); + + //m_qbShells->SetPosition(iLeft + iOffsetX, iTop + iOffsetY); + ++iColumn; + if(iColumn >= m_iNumQuantityBarColumns) + { + iColumn = 0; + ++iRow; + } + } + } + */ + } + } + void FFQuantityPanel::Paint() { //Paint Header Text vgui::surface()->DrawSetTextFont( m_hfHeaderText ); - vgui::surface()->DrawSetColor( m_ColorHeaderText.r(), m_ColorHeaderText.g(), m_ColorHeaderText.b(), m_ColorHeaderText.a() ); - vgui::surface()->DrawSetTextPos( 40, 10 ); + vgui::surface()->DrawSetTextColor( m_ColorHeaderText.r(), m_ColorHeaderText.g(), m_ColorHeaderText.b(), m_ColorHeaderText.a() ); + vgui::surface()->DrawSetTextPos( m_iHeaderTextX * m_flScale, m_iHeaderTextY * m_flScale ); vgui::surface()->DrawUnicodeString( m_wszHeaderText ); //Paint Header Icon vgui::surface()->DrawSetTextFont( m_hfHeaderIcon ); - vgui::surface()->DrawSetColor( m_ColorHeaderIcon.r(), m_ColorHeaderIcon.g(), m_ColorHeaderIcon.b(), m_ColorHeaderIcon.a() ); - vgui::surface()->DrawSetTextPos( 10, 10 ); + vgui::surface()->DrawSetTextColor( m_ColorHeaderIcon.r(), m_ColorHeaderIcon.g(), m_ColorHeaderIcon.b(), m_ColorHeaderIcon.a() ); + vgui::surface()->DrawSetTextPos( m_iHeaderIconX * m_flScale, m_iHeaderIconY * m_flScale ); vgui::surface()->DrawUnicodeString( m_wszHeaderIcon ); + + Panel::Paint(); } void FFQuantityPanel::SetHeaderText(wchar_t *newHeaderText) { wcscpy( m_wszHeaderText, newHeaderText ); } void FFQuantityPanel::SetHeaderIconChar(char *newHeaderIconChar) - { + { char szIconChar[5]; Q_snprintf( szIconChar, 2, "%s%", newHeaderIconChar ); vgui::localize()->ConvertANSIToUnicode( szIconChar, m_wszHeaderIcon, sizeof( m_wszHeaderIcon ) ); @@ -55,8 +121,9 @@ namespace vgui void FFQuantityPanel::SetHeaderTextColor( Color newHeaderTextColor ) { m_ColorHeaderText = newHeaderTextColor; } void FFQuantityPanel::SetHeaderIconColor( Color newHeaderIconColor ) { m_ColorHeaderIcon = newHeaderIconColor; } - void FFQuantityPanel::SetBackgroundColor( Color newBackgroundColor ) { m_ColorBackground = newBackgroundColor; } - void FFQuantityPanel::SetBorderColor( Color newBorderColor ) { m_ColorBorder = newBorderColor; } + + void FFQuantityPanel::SetHeaderTextPosition( int iPositionX, int iPositionY ) { m_iHeaderTextX = iPositionX; m_iHeaderTextY = iPositionY; } + void FFQuantityPanel::SetHeaderIconPosition( int iPositionX, int iPositionY ) { m_iHeaderIconX = iPositionX; m_iHeaderIconY = iPositionY; } void FFQuantityPanel::SetHeaderTextFont(vgui::HFont newHeaderTextFont) { m_hfHeaderText = newHeaderTextFont; } void FFQuantityPanel::SetHeaderIconFont(vgui::HFont newHeaderIconFont) { m_hfHeaderIcon = newHeaderIconFont; } diff --git a/cl_dll/ff/vgui/ff_quantitypanel.h b/cl_dll/ff/vgui/ff_quantitypanel.h index 26740b27f..97a0fb454 100644 --- a/cl_dll/ff/vgui/ff_quantitypanel.h +++ b/cl_dll/ff/vgui/ff_quantitypanel.h @@ -20,14 +20,26 @@ namespace vgui { class FFQuantityPanel : public Panel { + DECLARE_CLASS_SIMPLE( FFQuantityPanel, Panel ); public: - FFQuantityPanel() : Panel() { } - FFQuantityPanel(Panel *parent) : Panel(parent) { } - FFQuantityPanel(Panel *parent, const char *panelName) : Panel(parent, panelName) { } - FFQuantityPanel(Panel *parent, const char *panelName, HScheme scheme) : Panel(parent, panelName, scheme) { } + FFQuantityPanel() : Panel() { FFQuantityPanelInit(); } + FFQuantityPanel(Panel *parent) : Panel(parent) { FFQuantityPanelInit(); } + FFQuantityPanel(Panel *parent, const char *panelName) : Panel(parent, panelName) { FFQuantityPanelInit(); } + FFQuantityPanel(Panel *parent, const char *panelName, HScheme scheme) : Panel(parent, panelName, scheme) { FFQuantityPanelInit(); } + + void FFQuantityPanelInit() { + m_flScale = 1.0f; + SetHeaderTextPosition(30,15); + SetHeaderIconPosition(10,10); + m_iQuantityBarSpacingX = 10; + m_iQuantityBarSpacingY = 10; + m_iQuantityBarPositionX = 35; + m_iQuantityBarPositionY = 35; + } virtual void FFQuantityPanel::Paint( void ); virtual void FFQuantityPanel::ApplySchemeSettings( vgui::IScheme *pScheme ); + virtual void FFQuantityPanel::OnTick( void ); void SetHeaderText(wchar_t *newHeaderText); void SetHeaderIconChar(char *newHeaderIconChar); @@ -35,27 +47,43 @@ namespace vgui void SetHeaderTextFont(vgui::HFont newHeaderTextFont); void SetHeaderIconFont(vgui::HFont newHeaderIconFont); + void SetHeaderTextPosition( int iPositionX, int iPositionY ); + void SetHeaderIconPosition( int iPositionX, int iPositionY ); + void SetHeaderTextColor( Color newHeaderTextColor ); void SetHeaderIconColor( Color newHeaderIconColor ); - void SetBackgroundColor( Color newBackgroundColor ); - void SetBorderColor( Color newBorderColor ); protected: - int m_iBorderWidth; + float m_flScale; + vgui::HFont m_hfHeaderText; vgui::HFont m_hfHeaderIcon; vgui::HFont m_hfText; + int m_iHeaderTextX; + int m_iHeaderTextY; + int m_iHeaderIconX; + int m_iHeaderIconY; + wchar_t m_wszHeaderText[50]; wchar_t m_wszHeaderIcon[2]; Color m_ColorHeaderText; Color m_ColorHeaderIcon; Color m_ColorText; - Color m_ColorBackground; - Color m_ColorBorder; + + int m_iQuantityBarSpacingX; + int m_iQuantityBarSpacingY; + int m_iQuantityBarPositionX; + int m_iQuantityBarPositionY; + int m_iNumQuantityBarColumns; + + int* m_iColumnOffset; + int* m_iColumnWidth; + int* m_iRowOffset; + int* m_iRowWidth; }; }