Ikony drużyny

Z Valve Developer Community
Skocz do: nawigacja, szukaj


English (en)Deutsch (de)Polski (pl)Português do Brasil (pt-br)Русский (ru)
... Icon-Important.png

Ten poradnik nalieruje cię jak to zaplementować element HUDu który wyświetla obraz/logo zależnie od drużyny w której jesteś. Na przykład, jeśli gracz jest w jednej drużynie, wyświetl 'ten obraz', ale jeśli gracz jest w innej drużynie, wyświetl 'ten obraz'. To jest oczekiwany rezultat: Hud icon example.png

Wymagania

Dla tego poradnika będziesz potrzebować dwóch obrazów vtf z skonfigurowanymi ustawieniami vmt. Przykład pliku vmt jest poniżej, jeśli tego potrzebujesz:

"UnlitGeneric"
{
	"$basetexture" "vgui/hud/teamicons/iraqiran"
        "$translucent" "1"
        "$ignorez" "1" 
}

Element HUDu

Stwórz dwa pliki w projekcie client-side nazwanym jakkolwielk jal chcesz ale dla tego poradnika będe używał Rteamicon.cpp & Rteamicon.h.

Teraz otwórz Rteamicon.cpp i wklej następujący nagłówek:

// ======= *********-|RECOIL|-********* =======//
// Programmer: John Stuart                                                    
// ============================================//

#include "hud.h"
#include "cbase.h"
#include "Rteamicon.h"
#include "iclientmode.h"
#include "hud_macros.h"
#include "c_team.h"
#include "vgui_controls/controls.h"
#include "vgui/ISurface.h"
#include "hl2mp_gamerules.h"
#include "tier0/memdbgon.h"

using namespace vgui;

DECLARE_HUDELEMENT( CRTeamIcon );

Teraz that we have the header files musimy stworzyć konstruktor. Poniżej using namespace vgui; wklej to:

//-----------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------
CRTeamIcon::CRTeamIcon( const char *pElementName ) : CHudElement( pElementName ), BaseClass( NULL, "CRTeamIcon" )
{
   Panel *pParent = g_pClientMode->GetViewport();
   SetParent( pParent );   
   
   SetVisible( true );
   SetEnabled( true );

   // This defines m_nIraqIcon as "vgui/hud/teamicons/iraqiran" which calls the vtf.. duh.
   m_nIraqIcon = vgui::surface()->CreateNewTextureID();
   vgui::surface()->DrawSetTextureFile( m_nIraqIcon, "vgui/hud/teamicons/iraqiran" , true, false);

   // You get the deal now..
   m_nBritishIcon = vgui::surface()->CreateNewTextureID();
   vgui::surface()->DrawSetTextureFile( m_nBritishIcon, "vgui/hud/teamicons/ukusa" , true, false);

   SetHiddenBits( HIDEHUD_PLAYERDEAD | HIDEHUD_NEEDSUIT );
}

Teraz konstruktor jest gotowy, możemy iść dalej i stworzyć główną funkcję dla tej roboty, dla tego przykładu użyjemy "Paint Background" ponieważ gdybyś chciał użyć zwyczajnego "Paint" miałbyś czarne tło.

//-----------------------------------------------------------
// Purpose: If pPlayer (me) is on team Combine, display Iraq icon
// Purpose+: else if i'm on team Rebels display British icon.
//-----------------------------------------------------------
void CRTeamIcon::PaintBackground()
{  
   SetBgColor(Color(0,0,0,0));
   
   CBasePlayer *pPlayer = UTIL_PlayerByIndex(engine->GetLocalPlayer());

      if(pPlayer->GetTeamNumber() == TEAM_COMBINE)
	  {
           vgui::surface()->DrawSetColor(GetFgColor());
	   vgui::surface()->DrawSetTexture( m_nIraqIcon );
	   vgui::surface()->DrawTexturedRect(0, 0, GetWide(), GetTall());
	   //DevMsg("Team Combine Icon Displayed\n"); // Spams console hehe :D
	  }
	  else if(pPlayer->GetTeamNumber() == TEAM_REBELS)
	  {
           vgui::surface()->DrawSetColor(GetFgColor());
	   vgui::surface()->DrawSetTexture( m_nBritishIcon );
	   vgui::surface()->DrawTexturedRect(0, 0, GetWide(), GetTall());
	   //DevMsg("Team Rebels Icon Displayed\n"); 
	  }

      SetPaintBorderEnabled(false);

	  BaseClass::PaintBackground();
}

Teraz prawie skończyliśmy pracę nad elementem HUDu, żeby to wszystko zadziałało musimy ukończyć plik nagłówka. Otwórz Rteamicon.h i wklej to tam:

// ======= *********-|RECOIL|-********* =======//
// Programmer: John Stuart                                          
// ============================================//

#include "hudelement.h"
#include <vgui_controls/Panel.h>

using namespace vgui;

//-----------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------
class CRTeamIcon : public CHudElement, public Panel
{
   DECLARE_CLASS_SIMPLE( CRTeamIcon, Panel );

   public:

       CRTeamIcon( const char *pElementName );

   protected:

       virtual void PaintBackground();

       int m_nIraqIcon;
       int m_nBritishIcon;

};

Materiał

Teraz hud działa, możemy przystąpić do wyświetlania obrazka na HUDzie. coprawdy jest już tam, ale nie jest zdefiniowany. Więc przejdźmy dalej. Otwórz plik "scripts/HudLayout.res" i wklej to:

	CRTeamIcon
	{
		"fieldName" "CRTeamIcon"
	        "xpos" "r62"
		"ypos" "0"
		"wide" "64"
		"tall" "32"
		"visible" "1"
		"enabled" "1"
      
		"PaintBackgroundType"   "2"
	}

Oczywiście możesz zmiemić położenie i rozmiar obrazka edytując wartości: xpos,ypos,wide,tall.

Rezultat

Teraz powinieneś mieć element hud'u który wyświetla ikonę na twoim HUDzie w której drużynie jesteś.