VGUI: Making GameUI Panels: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Polish version)
(Replaced content with "#REDIRECT VGUI2:_Creating_a_panel")
 
(24 intermediate revisions by 7 users not shown)
Line 1: Line 1:
==Resource\UI\TestPanel.res==
#REDIRECT [[VGUI2:_Creating_a_panel]]
Oto przykład panelu, kiedy wydana jest komenda w każdym czasie:
"Resource/UI/TestPanel.res"
{
"testpanel"
{
"ControlName" "CTestPanel"
"fieldName" "testpanel"
"title" "Test Panel"
"xpos" "0"
"ypos" "0"
"wide" "200"
"tall" "200"
"autoResize" "0"
"pinCorner" "0"
"visible" "1"
"enabled" "1"
"tabPosition" "0"
}
"Label1"
{
"ControlName" "Label"
"fieldName" "Label1"
"xpos" "8"
"ypos" "32"
"wide" "200"
"tall" "175"
"wrap" "1"
"autoResize" "0"
"pinCorner" "0"
"visible" "1"
"enabled" "1"
"tabPosition" "0"
"labelText" "An example label inside of an example frame"
"textAlignment" "north"
"dulltext" "0"
"brighttext" "0"
}
"close"
{
"ControlName" "Button"
"fieldName" "close"
"xpos" "68"
"ypos" "168"
"wide" "64"
"tall" "24"
"labelText" "#GameUI_Close"
"Command" "Close"
"autoResize" "0"
"pinCorner" "0"
"visible" "1"
"enabled" "1"
"tabPosition" "0"
}
}
 
==cl_dll\vgui_helpers.h==
Dodaj to następująco po Includach:
class IGameUI
{
public:
virtual void Create( vgui::VPANEL parent ) = 0;
virtual void Destroy( void ) = 0;
virtual vgui::Panel *GetPanel(void) = 0;
};
#define DeclarePanel(className,panelClassName,globalPanel)\
class className : public IGameUI\
{\
private:\
panelClassName *myPanel;\
public:\
className(void)\
{\
myPanel = NULL;\
}\
void Create( vgui::VPANEL parent )\
{\
myPanel = new panelClassName( parent );\
}\
void Destroy( void )\
{\
if(myPanel)\
{\
myPanel->SetParent( (vgui::Panel *)NULL );\
delete myPanel;\
}\
}\
vgui::Panel *GetPanel(void)\
{\
return myPanel;\
}\
};\
extern IGameUI *globalPanel
//Nie używaj panelClassName ale skopiuj to i wklej do głównego kodu
#define PanelGlobals(className,panelClassName,globalPanel)\
static className g_##className##Panel;\
IGameUI *globalPanel = (IGameUI *)&g_##className##Panel
#define ToggleVisibility(panel)\
panel->SetVisible(!panel->IsVisible())
//Tylko prototyp AlignPanel istnieje
#define CenterThisPanelOnScreen()\
int x,w,h;\
GetBounds(x,x,w,h);\
SetPos((ScreenWidth()-w)/2,(ScreenHeight()-h)/2)
#define CenterPanelOnScreen(panel)\
int x,w,h;\
panel->GetBounds(x,x,w,h);\
panel->SetPos((panel->ScreenWidth()-w)/2,(panel->ScreenHeight()-h)/2)
 
==cl_dll\testpanel.h==
#ifndef TESTPANEL_H
#define TESTPANEL_H
#ifdef _WIN32
#pragma once
#endif
#include "vgui_helpers.h"
#include <vgui_controls/Frame.h>
using namespace vgui;
class CTestPanel : public Frame
{
DECLARE_CLASS_SIMPLE(CTestPanel,Frame);
public:
CTestPanel( vgui::VPANEL parent );
};
DeclarePanel(CTest,CTestPanel,test);
#endif // TESTPANEL_H
 
==cl_dll\testpanel.cpp==
#include "cbase.h"
#include "testpanel.h"
// memdbgon Musi być ostatnim zincludowanym plikiem w pliku .cpp !!!
#include "tier0/memdbgon.h"
PanelGlobals(CTest,CTestPanel,test);
CON_COMMAND(ToggleTestPanel,NULL)
{
ToggleVisibility(test->GetPanel());
}
CTestPanel::CTestPanel( vgui::VPANEL parent ) : BaseClass( NULL, "testpanel" )
{
SetParent(parent);
vgui::HScheme scheme = vgui::scheme()->LoadSchemeFromFile("resource/SourceScheme.res", "SourceScheme");
SetScheme( scheme );
LoadControlSettings("Resource/UI/TestPanel.res");
CenterThisPanelOnScreen();//Zapamiętaj, HL2 wspiera panoramiczne ekrany
SetVisible(false);//Widoczna na polecenie później
//Other useful options
//SetSizeable(false);
//SetMoveable(false);
}
 
Widzisz jak dużo definicji zostało zdredukowanych dla programowania dla testpanel.cpp i testpanel.h?
 
==cl_dll\vgui_int.cpp==
Teraz mamy system dla panelu...
 
Wpierw idź do nagłówka zawartości (Includes) '''Dodaj twój testpanel.h do listy includów (includes)''' i możesz mieć dostęp do swojego nowego panelu
 
Zjedź na dół do VGui_CreateGlobalPanels and i dodaj to po drugiej lini:
VPANEL uiParent = enginevgui->GetPanel( PANEL_GAMEUIDLL );
 
Panel GameUI jest tym co użyjemy do robienia naszych paneli
 
W tej samej funkcji, dodaj to do listy "Creates":
test->Create( uiParent );
 
Zjedź troche na dół, aż do VGui_Shutdown i dodaj to do listy zniszczonych (Destroys):
test->Destroy();
 
==Konkluzja==
Teraz mamy panel tworzony podczas włączania, niszczony podczas wyłączania, i dostępny przez komende.
Zapamiętaj to:
* Nie musisz używać ramki dla panelu
* Możesz to zrobić, że komenda otworzy to ale już nie może zamknąć tego
* Możesz to zrobić, że panel będzie stworzony jednorazowo poprzez wydanie komendy, i znoszczone jednorazowo poprzez zamknięcie tego, więc nie musi to siedzieć w pamięci
 
Tu jest przykład co możemy zrobić bazując na tym kodzie:<br>
[[Image:Gameui.jpg]]
{{otherlang:en}}
{{otherlang:en:it|VGUI:_Making_GameUI_Panels:it}}
[[Category:Programming]]
[[Category:VGUI|M]]

Latest revision as of 14:28, 10 February 2012