![]() |
|
Close Help |
Part II
Stuff in red is half life code
Stuff in green is Mazor's code
Stuff in blue is comments
Stuff in orange is files
Stuff in white is just normal tex
Alright, you made it this far, now there isn't much more to be done, you have the basis already, now we just gotta do some normal VGUI code. Adding panels and labels and such. So, lets get started...
Lets begin adding an element, our first element will be the player's health:
Open up vgui_newhud.h
Find: class NewHUD : public Panel
now, in the private declarations, add this:
// health
CTransparentPanel *m_pStatsPanel;
Label *m_pPlayerHealth;
char m_szPlayerHealth[512];
// health
Open up vgui_ScorePanel.cpp
Find: NewHUD::NewHUD(int x,int y, int wide, int tall) : Panel(x,y,wide,tall)
We need to add the text scheme the health text will use, for this, we will use the basic text scheme.
Add these lines:
// schemes
CSchemeManager *pSchemes =
gViewPort->GetSchemeManager();
SchemeHandle_t hTitleScheme =
pSchemes->getSchemeHandle( "Basic Text" );
// schemes
Now, for the game to NOT crash when we start, we need to set the m_szPlayerHealth value to hold a blank spot, so, lets add this:
// zero out the values
strcpy(m_szPlayerHealth, "");
// zero out the values
Ok, you got your schemes, now we can add the panel and label, add these lines below what we just added:
// health
// Make the stats panel
m_pStatsPanel= new CTransparentPanel(100, 0, ScreenHeight -
YRES(60), ScreenWidth * 0.2, YRES(60)
);
m_pStatsPanel->setBgColor(0,0,0,100);
m_pStatsPanel->setParent(this);
m_pStatsPanel->setBorder(
new LineBorder( Color( 255, 255, 255, 0 ) ) );
// Make the health label
m_pPlayerHealth =
new Label( "", XRES(5), YRES(20) , XRES(125), YRES(18)
);
m_pPlayerHealth->setFont( pSchemes->getFont(hTitleScheme)
);
m_pPlayerHealth->setBgColor( 0,0,0, 255);
m_pPlayerHealth->setContentAlignment(
vgui::Label::a_west );
m_pPlayerHealth->setParent(m_pStatsPanel);
// health
Ok, your done making the panel and label, now you have to keep the values fresh and keep them updated, so, find the NewHUD::Update() function, this is where we will keep the values updated.
Add these lines to the update function:
// health
// copy over the health into the variable
sprintf(m_szPlayerHealth, "Health: %d", gHUD.m_Health.m_iHealth);
// update the value to the label
m_pPlayerHealth->setText(m_szPlayerHealth);
// health
There, what that all did was add a transparent panel to the bottom left corner of the screen and put in the player's health. You can change the size and color and everything by just simply changing some of the values that I had in there already. Its pretty easy, if you don't understand VGUI, learn it using rkzad's tutorials, they are great tutorials. That is how I learned VGUI.
http://hlci.valveworld.com/index.php?site=vguicltuts
Any Q's, comments, or gripes: mailto:mazor@spudgunmod.net?SUBJECT=VGUI Tutorials