VGUI2: Non RES-File Controls: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
Line 44: Line 44:
  //Other used VGUI control Elements:
  //Other used VGUI control Elements:
         // Our Code Defined Control
         // Our Code Defined Control
         Button m_pCloseButton;
         Button *m_pCloseButton;
  };
  };
</source>
</source>

Revision as of 21:31, 9 February 2012

Stub

This article or section is a stub. You can help by expanding it.

Requirements

Have read and understood (or understand):

Can code:

  • C++
  • Script

This tutorial is a continuation on Creating A Panel

In HL1 controls were added via code from the Server and Client libraries and is still supported by the source engine and controls can be added. There are more options for these controls to be customized rather then in RES files.

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;
 };

ok now we got our control 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. 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, "Command");
        m_pCloseButton->SetPos(314, 162);
	m_pCloseButton->SetDepressedSound("common/bugreporter_succeeded.wav");
        m_pCloseButton->SetReleadedSound("ui/buttonclick.wav");
	
}