VGUI2: Hardcoded Controls: Difference between revisions
(Created page with "Category:TutorialsC {{Stub}} ==Requirements== Have read and understood (or understand):<br> *VGUI Documentation *VGUI2:_Creating_a_panel Can code: *...") |
m (→MyPanel.cpp) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[[Category:Tutorials]][[Category:VGUI|C]] | [[Category:Tutorials]][[Category:VGUI|C]] | ||
{{Stub}} | {{Pov}}{{Stub}} | ||
==Requirements== | ==Requirements== | ||
Have read and understood (or understand):<br> | Have read and understood (or understand):<br> | ||
Line 11: | Line 11: | ||
This tutorial is a continuation on [[VGUI2:_Creating_a_panel|Creating A Panel]] | This tutorial is a continuation on [[VGUI2:_Creating_a_panel|Creating A Panel]] | ||
In Half-Life 1, controls were added via code from the Server and Client libraries and | In Half-Life 1, controls were added via code from the Server and Client libraries and are still supported by the source | ||
engine | engine. There are more options for these controls to be customized rather then in RES files. | ||
This is very | This is very useful if you do not want people to modify your panel controls via RES files. | ||
You have the choice in-between 50 elements, individually stored in the vgui_controls folder. | You have the choice in-between 50 elements, individually stored in the vgui_controls folder. | ||
Line 30: | Line 30: | ||
// Non RES-File Control Tutorial | // Non RES-File Control Tutorial | ||
#include <vgui_controls/Button.h> | #include <vgui_controls/Button.h> | ||
//------------------------------ | |||
//CMyPanel class: Tutorial example class | //CMyPanel class: Tutorial example class | ||
class CMyPanel : public vgui::Frame | class CMyPanel : public vgui::Frame | ||
Line 53: | Line 53: | ||
</source> | </source> | ||
The control is defined, now we need to create it here but you can still have both the res file and code defined controls at the same time but if SetScheme is called after you call any control manipulation functions, the res file will overwrite the operations performed in the code. Anyways, we are going to be assigning a click and release sound to this button. | |||
<source lang="cpp"> | <source lang="cpp"> | ||
Line 85: | Line 85: | ||
m_pCloseButton->SetDepressedSound("common/bugreporter_succeeded.wav"); | m_pCloseButton->SetDepressedSound("common/bugreporter_succeeded.wav"); | ||
m_pCloseButton->SetReleadedSound("ui/buttonclick.wav"); | m_pCloseButton->SetReleadedSound("ui/buttonclick.wav"); | ||
//------------------------------ | |||
} | } | ||
</source> | </source> |
Latest revision as of 20:00, 2 May 2014

Requirements
Have read and understood (or understand):
Can code:
- C++
- Script
This tutorial is a continuation on Creating A Panel
In Half-Life 1, controls were added via code from the Server and Client libraries and are still supported by the source engine. There are more options for these controls to be customized rather then in RES files. This is very useful if you do not want people to modify your panel controls via RES files.
You have the choice in-between 50 elements, individually stored in the vgui_controls folder.
First start off by adding our header file.
MyPanel.cpp
//The following include files are necessary to allow your MyPanel.cpp to compile.
#include "cbase.h"
#include "IMyPanel.h"
using namespace vgui;
#include <vgui/IVGui.h>
#include <vgui_controls/Frame.h>
// Non RES-File Control Tutorial
#include <vgui_controls/Button.h>
//------------------------------
//CMyPanel class: Tutorial example class
class CMyPanel : public vgui::Frame
{
DECLARE_CLASS_SIMPLE(CMyPanel, vgui::Frame);
//CMyPanel : This Class / vgui::Frame : BaseClass
CMyPanel(vgui::VPANEL parent); // Constructor
~CMyPanel(){}; // Destructor
protected:
//VGUI overrides:
virtual void OnTick();
virtual void OnCommand(const char* pcCommand);
private:
//Other used VGUI control Elements:
// Our Code Defined Control
Button *m_pCloseButton;
};
The control is defined, now we need to create it here but you can still have both the res file and code defined controls at the same time but if SetScheme is called after you call any control manipulation functions, the res file will overwrite the operations performed in the code. Anyways, we are going to be assigning a click and release sound to this button.
// Constuctor: Initializes the Panel
CMyPanel::CMyPanel(vgui::VPANEL parent) : BaseClass(NULL, "MyPanel")
{
SetParent( parent );
SetKeyBoardInputEnabled( true );
SetMouseInputEnabled( true );
SetProportional( false );
SetTitleBarVisible( true );
SetMinimizeButtonVisible( false );
SetMaximizeButtonVisible( false );
SetCloseButtonVisible( false );
SetSizeable( false );
SetMoveable( false );
SetVisible( true );
SetScheme(vgui::scheme()->LoadSchemeFromFile("resource/SourceScheme.res", "SourceScheme"));
LoadControlSettings("resource/UI/MyPanel.res");
vgui::ivgui()->AddTickSignal( GetVPanel(), 100 );
// Code Defined Control Creation
m_pCloseButton = new Button(this, "", "Close", this, "turnoff");
m_pCloseButton->SetPos(314, 162);
m_pCloseButton->SetDepressedSound("common/bugreporter_succeeded.wav");
m_pCloseButton->SetReleadedSound("ui/buttonclick.wav");
//------------------------------
}