This article's documentation is for anything that uses the Source engine. Click here for more information.

Uk/VGUI Health bar: Difference between revisions

From Valve Developer Community
< Uk
Jump to navigation Jump to search
m (otherlang2 > lang)
m (fixed language template. also some formatting.)
Line 1: Line 1:
{{lang|VGUI_Health_bar|title=VGUI Смуга здоров'я}}
{{lang|VGUI Health bar|title=VGUI Смуга здоров'я}}[[Category:Programming:ua]][[Category:Tutorials:ua]]{{source topicon|suf=:ua}}
[[File:Health Bar.png|thumb]]
[[File:Health Bar.png|thumb]]


==Огляд==
==Огляд==
Привіт, друзі! Ми додамо панель здоров'я до "Source".  
Привіт, друзі! Ми додамо панель здоров'я до {{src13|suf=:ua}} [[Source SDK 2013]] {{en}}.  
==Програма==
==Програма==
Зробити '''hud_healthbar.cpp''' та '''hud_healthbar.h''' У розділі "Client":
Зробити <code>hud_healthbar.cpp</code> та <code>hud_healthbar.h</code> У розділі «Client»:


==hudhealthbar.cpp==
==<code>hudhealthbar.cpp</code>==
<source lang="cpp">
<source lang="cpp">
#include "cbase.h"  
#include "cbase.h"  
Line 126: Line 126:
</source>
</source>


==hudhealthbar.h==
==<code>hudhealthbar.h</code>==
<source lang="cpp">
<source lang="cpp">
#if !defined HUD_HULL_H
#if !defined HUD_HULL_H
Line 180: Line 180:
</source>
</source>


==HudLayout.res==
==<code>HudLayout.res</code>==
Вставте це '''HudLayout.res''' в '''scripts''' папку:
Вставте це <code>HudLayout.res</code> в <code>scripts</code> папку:
<pre>
<pre>
HudHull
HudHull

Revision as of 09:01, 23 May 2022

English (en)Español (es)Русский (ru)Українська (uk)Translate (Translate)
Health Bar.png

Огляд

Привіт, друзі! Ми додамо панель здоров'я до Source 2013 Source SDK 2013

Warning icon.png
This article has been marked as a candidate for speedy deletion for the following reason:
Use {{Flag|en}} instead.
If you object to this decision, then please discuss why here (If you make a discussion section also create this redirect page). If this page doesn't meet the criteria for speedy deletion, then please remove this notice, but do not remove it from pages that you have created yourself
Administrators / Moderators - Remember to check if anything links here and the page history before deleting.

.

Програма

Зробити hud_healthbar.cpp та hud_healthbar.h У розділі «Client»:

hudhealthbar.cpp

#include "cbase.h" 
#include "hud.h" 
#include "hud_macros.h" 
#include "c_baseplayer.h" 
#include "hudhealthbar.h" 
#include "iclientmode.h" 
#include "vgui/ISurface.h"

using namespace vgui;

#include "tier0/memdbgon.h" 

DECLARE_HUDELEMENT (CHudHealthbar);

# define HULL_INIT 80 

//------------------------------------------------------------------------
// Purpose: Конструктор
//------------------------------------------------------------------------

CHudHealthbar:: CHudHealthbar (const char * pElementName) : 
	CHudElement (pElementName), BaseClass (NULL, "HudHealthbar")
{
	vgui:: Panel * pParent = g_pClientMode-> GetViewport ();
	SetParent (pParent);

	SetHiddenBits (HIDEHUD_HEALTH | HIDEHUD_PLAYERDEAD | HIDEHUD_NEEDSUIT);
}

//------------------------------------------------------------------------
// Purpose:
//------------------------------------------------------------------------

void CHudHealthbar:: Init()
{
	Reset();
}

//------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------

void CHudHealthbar:: Reset (void)
{
	m_flHull = HULL_INIT;
	m_nHullLow = -1;
	SetBgColor (Color (0,0,0,128));
}


//------------------------------------------------------------------------
// Purpose:
//------------------------------------------------------------------------

void CHudHealthbar:: OnThink (void)
{
	float newHull = 0;
	C_BasePlayer * local = C_BasePlayer:: GetLocalPlayer ();

	if (!local)
		return;

	// Never below zero 
	newHull = max(local->GetHealth(), 0);

	// DevMsg("Sheild at is at: %f\n",newShield);
	// Only update the fade if we've changed health
	if (newHull == m_flHull)
		return;

	m_flHull = newHull;
}


//------------------------------------------------------------------------
// Purpose: нічия
//------------------------------------------------------------------------

void CHudHealthbar::Paint()
{
	// Get bar chunks

	int chunkCount = m_flBarWidth / (m_flBarChunkWidth + m_flBarChunkGap);
	int enabledChunks = (int)((float)chunkCount * (m_flHull / 100.0f) + 0.5f );

	// Draw the suit power bar
	surface()->DrawSetColor (m_HullColor);

	int xpos = m_flBarInsetX, ypos = m_flBarInsetY;

	for (int i = 0; i < enabledChunks; i++)
	{
		surface()->DrawFilledRect(xpos, ypos, xpos + m_flBarChunkWidth, ypos + m_flBarHeight);
		xpos += (m_flBarChunkWidth + m_flBarChunkGap);
	}

	// Draw the exhausted portion of the bar.
	surface()->DrawSetColor(Color(m_HullColor [0], m_HullColor [1], m_HullColor [2], m_iHullDisabledAlpha));

	for (int i = enabledChunks; i < chunkCount; i++)
	{
		surface()->DrawFilledRect(xpos, ypos, xpos + m_flBarChunkWidth, ypos + m_flBarHeight);
		xpos += (m_flBarChunkWidth + m_flBarChunkGap);
	}

	// Draw our name

	surface()->DrawSetTextFont(m_hTextFont);
	surface()->DrawSetTextColor(m_HullColor);
	surface()->DrawSetTextPos(text_xpos, text_ypos);

	//wchar_t *tempString = vgui::localize()->Find("#Valve_Hud_AUX_POWER");

	surface()->DrawPrintText(L"HULL", wcslen(L"HULL"));
}

hudhealthbar.h

#if !defined HUD_HULL_H
#define HUD_HULL_H 

#ifdef _WIN32
#pragma once
#endif

#include "hudelement.h"
#include "hud_numericdisplay.h"

//-----------------------------------------------------------------------------
// Purpose: Показує бар!
//-----------------------------------------------------------------------------

class CHudHealthbar : public CHudElement, public vgui::Panel
{

	DECLARE_CLASS_SIMPLE(CHudHull, vgui::Panel);

public:
	CHudHealthbar(const char * pElementName);

	virtual void Init (void);
	virtual void Reset (void);
	virtual void OnThink (void);

protected:
	virtual void Paint();

private:
	CPanelAnimationVar(Color, m_HullColor, "HullColor", "255 0 0 255");
	CPanelAnimationVar(int, m_iHullDisabledAlpha, "HullDisabledAlpha", "50");
	CPanelAnimationVarAliasType(float, m_flBarInsetX, "BarInsetX", "26", "proportional_float");
	CPanelAnimationVarAliasType(float, m_flBarInsetY, "BarInsetY", "3", "proportional_float");
	CPanelAnimationVarAliasType(float, m_flBarWidth, "BarWidth", "84", "proportional_float");
	CPanelAnimationVarAliasType(float, m_flBarHeight, "BarHeight", "4", "proportional_float");
	CPanelAnimationVarAliasType(float, m_flBarChunkWidth, "BarChunkWidth", "2", "proportional_float");
	CPanelAnimationVarAliasType(float, m_flBarChunkGap, "BarChunkGap", "1", "proportional_float");
	CPanelAnimationVar(vgui::HFont, m_hTextFont, "TextFont", "HUDBarText");
	CPanelAnimationVarAliasType(float, text_xpos, "text_xpos", "2", "proportional_float");
	CPanelAnimationVarAliasType(float, text_ypos, "text_ypos", "2", "proportional_float");
	CPanelAnimationVarAliasType(float, text2_xpos, "text2_xpos", "8", "proportional_float");
	CPanelAnimationVarAliasType(float, text2_ypos, "text2_ypos", "40", "proportional_float");
	CPanelAnimationVarAliasType(float, text2_gap, "text2_gap", "10", "proportional_float");
	float m_flHull;
	int m_nHullLow;

};

#endif // HUD_SUITPOWER_H

HudLayout.res

Вставте це HudLayout.res в scripts папку:

HudHull
{

	"fieldName" "HudHealthbar"
	"visible" "1"
	"enabled" "1"
	"xpos" "12"
	"ypos" "420"
	"wide" "120"
	"tall" "10"
	"text_xpos" "5"
	"text_ypos" "2"
	"TextColor" "0 255 0 80"
	"PaintBackgroundType" "2"

}