Posted by: ts2do
Date posted: Jun 23 2005 User Rating: 4 out of 5.0 | Number of views: 6539 Number of comments: 10 | Description: Explanation on handling VGUI without having a connection to a game. |
Here's an example of a panel you want to show when a command is issed at any time:
| | | "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" } } |
To start off, add these defines into vgui_helpers.h:
| | | #define DeclarePanel(className,panelClassName,globalPanel)\ class I##className\ {\ public:\ virtual void Create( vgui::VPANEL parent ) = 0;\ virtual void Destroy( void ) = 0;\ };\ class className : public I##className\ {\ 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;\ }\ }\ };\ extern I##className *globalPanel
#define DeclareAccessiblePanel(className,panelClassName,globalPanel)\ class I##className\ {\ public:\ virtual void Create( vgui::VPANEL parent ) = 0;\ virtual void Destroy( void ) = 0;\ virtual vgui::Panel *GetPanel(void) = 0;\ };\ class className : public I##className\ {\ private:\ panelClassName *myPanel;\ public:\ className(void)\ {\ myPanel = NULL;\ }\ void Create( vgui::VPANEL parent )\ {\ myPanel = new panelClassName( parent );\ }\ vgui::Panel *GetPanel(void)\ {\ return myPanel;\ }\ void Destroy( void )\ {\ if(myPanel)\ {\ myPanel->SetParent( (vgui::Panel *)NULL );\ delete myPanel;\ }\ }\ };\ extern I##className *globalPanel
#define PanelGlobals(className,panelClassName,globalPanel)\ static className g_##className##Panel;\ I##className *globalPanel = (I##className *)&g_##className##Panel
#define ToggleVisibility(panel)\ panel->SetVisible(!panel->IsVisible())
#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) |
testpanel.h
| | | #ifndef TESTPANEL_H #define TESTPANEL_H #ifdef _WIN32 #pragma once #endif #include "vgui_helpers2.h" #include <vgui_controls/Frame.h> using namespace vgui; class CTestPanel : public Frame { DECLARE_CLASS_SIMPLE(CTestPanel,Frame); public: CTestPanel( vgui::VPANEL parent ); }; DeclareAccessiblePanel(CTest,CTestPanel,test); #endif |
testpanel.cpp
| | | #include "cbase.h" #include "testpanel.h"
#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(); SetVisible(false); } |
See how much the defines reduced the coding for testpanel.cpp and testpanel.h?
Now that we have the framework for the panel... Go to the includes in vgui_int.cpp and add testpanel.h Scroll down to VGui_CreateGlobalPanels and add this after the second line:
| | | | VPANEL uiParent = enginevgui->GetPanel( PANEL_GAMEUIDLL ); |
The GameUI panel is what we're going to be making our panels in
In the same function, add this to the list of Creates:
| | | | test->Create( uiParent ); |
Scroll down a little until you get to VGui_Shutdown and add this to the list of Destroys:
Now we have a panel that's created during startup, destroyed on shutdown, and accessible through a command. Keep these in mind though: You don't have to use a frame for the panel You can make it so the command to show it can't close it also You can make it so the panel is created once the command is issued, and destroyed once it's closed, so it doesn't take up RAM
Here's an example of what I did based on this code

The hotkeys for opening the build menu for the selected EditablePanel, which can also be a Frame or Frame subclasses, are Ctrl+Shift+Alt+B The build menu makes creation easier by allowing you to dynamically edit a resource file by creating controls and moving them. |
|
User Comments
Showing comments 1-10
I get the following error:
vgui_int.obj : error LNK2001: unresolved external symbol "class ICTest * test" (?test@@3PAVICTest@@A) .\cl_dll___Win32_HL2_Release/client.dll : fatal error LNK1120: 1 unresolved externals
What am I doing wrong? |
|
|
Do you have your panel declared? |
|
|
Yes, I think so.. I followed every step of the tutorial. |
|
|
After reviewing the error, it seems that you didn't do PanelGlobals |
|
|
I didn't remove anything from the code from above ("PanelGlobals(CTest,CTestPanel,test);" remains in testpanel.cpp). The only thing I changed is "#include "vgui_helpers2.h"" in testpanel.h to "#include "vgui_helpers.h"". |
|
HERE'S YOUR PROBLEM: Go to the includes in vgui_int.cpp and add testpanel.h |
|
|
I already did that.. That doesn't solve the problem. |
|
|
well...i got the same problem...i just included my "testpanel.cpp" to vgui_int.cpp and it compiled fine :D but there is no vgui panel showing :( |
|
|
where is the .res file supposed to go? In ui? |
|
|
RES file goes into the resource directory under your mod |
|
You must register to post a comment. If you have already registered, you must login.
|
296 Approved Articless
5 Pending Articles
3940 Registered Members
0 People Online (23 guests)
|
|