Skip to content

Commit

Permalink
Added missing hud stuff to 2003. hope it all works!
Browse files Browse the repository at this point in the history
This is so dexter (& shok?) can help with the following:

buildstate_sg is a buildstate is a quantitypanel
quantitypanel has children as quantitybar
buildstate has cvars to define the style of the children

As it stands now buildstate checks the cvars every other tick to see if they've changed from the ones saved as members
if they've changed then the member gets updated and it updates the child quantity bars
theres a lot of the same variables

I've had a thought, not sure if it's worth doing depending on how I do this whole thing but would solve the duplicated member problem: Have a style class that the quantity bars are given a pointer to, the buildstate class updates the style object based on the cvars.

I just need a better way to update the styles.

Side note: The color fading is broken in some way at the moment but I'm not sure how. It might just be because the SG goes above 100 and the color scale hasn't adapted for that - it's something I am aware of and need to fix.

# Conflicts:
#	cl_dll/client_scratch-2003.vcproj
#	cl_dll/client_scratch-2005.vcproj
#	cl_dll/client_scratch-2008.vcproj
  • Loading branch information
AdamWillden committed Nov 1, 2020
1 parent 05a0391 commit 9184ee9
Show file tree
Hide file tree
Showing 5 changed files with 535 additions and 131 deletions.
8 changes: 8 additions & 0 deletions cl_dll/client_scratch-2005.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,14 @@
RelativePath=".\ff\ff_hud_buildstate.h"
>
</File>
<File
RelativePath=".\ff\ff_hud_buildstate_base.cpp"
>
</File>
<File
RelativePath=".\ff\ff_hud_buildstate_base.h"
>
</File>
<File
RelativePath=".\ff\ff_hud_buildstate_sentry.cpp"
>
Expand Down
72 changes: 45 additions & 27 deletions cl_dll/ff/ff_hud_buildstate_sentry.cpp
Original file line number Diff line number Diff line change
@@ -1,55 +1,77 @@
#include "cbase.h"
#include "ff_quantitypanel.h"
#include "ff_hud_buildstate_base.h"

#include "c_ff_player.h" //required to cast base player

#include "iclientmode.h" //to set panel parent as the cliends viewport

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

class CHudBuildStateSentry : public CHudElement, public vgui::FFQuantityPanel
static ConVar hud_buildstate_sg_x( "hud_buildstate_sg_x", "0", FCVAR_ARCHIVE, "Panel's X position on 640 480 Resolution");
static ConVar hud_buildstate_sg_y( "hud_buildstate_sg_y", "0", FCVAR_ARCHIVE, "Panel's Y Position on 640 480 Resolution");
static ConVar hud_buildstate_sg_align_horiz( "hud_buildstate_sg_align_horiz", "0", FCVAR_ARCHIVE, "Panel's horizontal alignment to the specified position (0=left, 1=center, 2=right");
static ConVar hud_buildstate_sg_align_vert( "hud_buildstate_sg_align_vert", "0", FCVAR_ARCHIVE, "Panel's vertical alignment to the specified position (0=top, 1=middle, 2=bottom");
static ConVar hud_buildstate_sg_columns( "hud_buildstate_sg_columns", "1", FCVAR_ARCHIVE, "Number of quantity bar columns");

class CHudBuildStateSentry : public CHudElement, public CHudBuildStateBase
{
DECLARE_CLASS_SIMPLE( CHudBuildStateSentry, vgui::FFQuantityPanel );
DECLARE_CLASS_SIMPLE( CHudBuildStateSentry, CHudBuildStateBase );

public:
CHudBuildStateSentry(const char *pElementName) : CHudElement(pElementName), vgui::FFQuantityPanel(NULL, "HudBuildStateSentry")
CHudBuildStateSentry(const char *pElementName) : CHudElement(pElementName), CHudBuildStateBase(NULL, "HudBuildStateSentry")
{
SetParent(g_pClientMode->GetViewport());
SetHiddenBits( 0 );

m_bBuilt = false;
m_flScale = 1.0f;
vgui::ivgui()->AddTickSignal(GetVPanel(), 250); //only update 4 times a second

vgui::ivgui()->AddTickSignal(GetVPanel(), 500); //only update 2 times a second
}

~CHudBuildStateSentry( void ) {}

virtual void Init( void );
virtual void OnTick( void );
virtual void Paint( void );
virtual void ApplySchemeSettings( vgui::IScheme *pScheme );


void MsgFunc_SentryMsg(bf_read &msg);

protected:
virtual void CheckCvars();
private:
// could probably do this without these now
// but would need an alternative of selecting the one you want easily
CHudQuantityBar *m_qbSentryHealth;
CHudQuantityBar *m_qbSentryLevel;

bool m_bBuilt;
vgui::HFont m_hfText;
};

DECLARE_HUDELEMENT(CHudBuildStateSentry);
DECLARE_HUD_MESSAGE(CHudBuildStateSentry, SentryMsg);

void CHudBuildStateSentry::ApplySchemeSettings( vgui::IScheme *pScheme )
void CHudBuildStateSentry::CheckCvars()
{
m_hfText = pScheme->GetFont( "QuantityPanel", IsProportional() );

UpdateQuantityBarPositions();
FFQuantityPanel::ApplySchemeSettings( pScheme );
bool updateBarPositions = false;

if(m_iX != hud_buildstate_sg_x.GetInt() || m_iY != hud_buildstate_sg_y.GetInt())
{
m_iX = hud_buildstate_sg_x.GetInt();
m_iY = hud_buildstate_sg_y.GetInt();
}

if(m_iHorizontalAlign != hud_buildstate_sg_align_horiz.GetInt())
m_iHorizontalAlign = hud_buildstate_sg_align_horiz.GetInt();

if(m_iVerticalAlign != hud_buildstate_sg_align_vert.GetInt())
m_iVerticalAlign = hud_buildstate_sg_align_vert.GetInt();

if(m_qb_iColumns != hud_buildstate_sg_columns.GetInt())
{
m_qb_iColumns = hud_buildstate_sg_columns.GetInt();
updateBarPositions = true;
}

BaseClass::CheckCvars(updateBarPositions);
}

void CHudBuildStateSentry::Init()
Expand All @@ -64,38 +86,34 @@ void CHudBuildStateSentry::Init()
m_qbSentryHealth = AddChild("BuildStateSentryHealth");
m_qbSentryLevel = AddChild("BuildStateSentryLevel");

SetPaintBackgroundEnabled(false);
SetPaintBorderEnabled(false);
SetPaintEnabled(false);

SetHeaderText(tempString);
SetHeaderIconChar("R");

m_qbSentryHealth->SetLabelText("#FF_ITEM_HEALTH");
m_qbSentryHealth->SetLabelText("#FF_iTEM_HEALTH");
m_qbSentryHealth->SetIconChar(":");
m_qbSentryHealth->SetVisible(false);

m_qbSentryLevel->SetLabelText("#FF_ITEM_LEVEL");
m_qbSentryLevel->SetLabelText("#FF_iTEM_lEVEL");
m_qbSentryLevel->SetAmountMax(3);
m_qbSentryLevel->SetIntensityControl(1,2,2,3);
m_qbSentryLevel->SetVisible(false);
}

void CHudBuildStateSentry::OnTick()
{
SetPos( vgui::scheme()->GetProportionalScaledValue(10), vgui::scheme()->GetProportionalScaledValue(190) );
//SetPos( vgui::scheme()->GetProportionalScaledValue(0), vgui::scheme()->GetProportionalScaledValue(0) );

BaseClass::OnTick();


CheckCvars();

if (!engine->IsInGame())
return;

// Get the local player
C_FFPlayer *pPlayer = ToFFPlayer(C_BasePlayer::GetLocalPlayer());

// If the player is not an FFPlayer or is not an Engineer
if (!pPlayer && pPlayer->GetClassSlot() != CLASS_ENGINEER)
if (!pPlayer || pPlayer->GetClassSlot() != CLASS_ENGINEER)
//hide the panel
{
SetPaintBackgroundEnabled(false);
Expand Down Expand Up @@ -140,7 +158,7 @@ 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( m_iQuantityBarPositionX * m_flScale, m_iQuantityBarPositionY * m_flScale ); // x,y position
vgui::surface()->DrawSetTextPos( m_qb_iPositionX * m_flScale, m_qb_iPositionY * m_flScale ); // x,y position
vgui::surface()->DrawPrintText( pText, wcslen(pText) ); // print text
}

Expand Down
24 changes: 12 additions & 12 deletions cl_dll/ff/ff_hud_quantitybar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,32 +291,32 @@ void CHudQuantityBar::GetDimentions(int& iWidth, int& iHeight, int& iBarOffsetX,
int iX1 = m_iLeft + m_iBarWidth;
int iY1 = m_iTop + m_iBarHeight;

if( m_iIconPosX < iX0 )
if( m_bShowIcon && m_iIconPosX < iX0 )
iX0 = m_iIconPosX;
if( m_iLabelPosX < iX0 )
if( m_bShowLabel && m_iLabelPosX < iX0 )
iX0 = m_iLabelPosX;
if( m_iAmountPosX < iX0 )
if( m_bShowAmount && m_iAmountPosX < iX0 )
iX0 = m_iAmountPosX;

if( m_iIconPosY < iY0 )
if( m_bShowIcon && m_iIconPosY < iY0 )
iY0 = m_iIconPosY;
if( m_iLabelPosY < iY0 )
if( m_bShowLabel && m_iLabelPosY < iY0 )
iY0 = m_iLabelPosY;
if( m_iAmountPosY < iY0 )
if( m_bShowAmount && m_iAmountPosY < iY0 )
iY0 = m_iAmountPosY;

if( (m_iIconPosX + m_iIconWidth) > iX1 )
if( m_bShowIcon && (m_iIconPosX + m_iIconWidth) > iX1 )
iX1 = m_iIconPosX + m_iIconWidth;
if( (m_iLabelPosX + m_iLabelWidth) > iX1 )
if( m_bShowLabel && (m_iLabelPosX + m_iLabelWidth) > iX1 )
iX1 = m_iLabelPosX + m_iLabelWidth;
if( (m_iAmountPosX + m_iAmountWidth) > iX1 )
if( m_bShowAmount && (m_iAmountPosX + m_iAmountWidth) > iX1 )
iX1 = m_iAmountPosX + m_iAmountWidth;

if( (m_iIconPosY + m_iIconHeight) > iY1 )
if( m_bShowIcon && (m_iIconPosY + m_iIconHeight) > iY1 )
iY1 = m_iIconPosY + m_iIconHeight;
if( (m_iLabelPosY + m_iLabelHeight) > iY1 )
if( m_bShowLabel && (m_iLabelPosY + m_iLabelHeight) > iY1 )
iY1 = m_iLabelPosY + m_iLabelHeight;
if( (m_iAmountPosY + m_iAmountHeight) > iY1 )
if( m_bShowAmount && (m_iAmountPosY + m_iAmountHeight) > iY1 )
iY1 = m_iAmountPosY + m_iAmountHeight;

iWidth = iX1 - iX0;
Expand Down
Loading

0 comments on commit 9184ee9

Please sign in to comment.