VGUI PanelList: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 9: Line 9:


==The Code==
==The Code==
CPP: http://developer.valvesoftware.com/wiki/PanelList_cpp<br>
CPP: [[PanelList_cpp]]<br>
H: http://developer.valvesoftware.com/wiki/PanelList_h
H: [[PanelList_h]]
<p>
<p>
Save these two files and add them to your client project.
Save these two files and add them to your client project.
Line 48: Line 48:


===The sub panel===
===The sub panel===
Main Code: http://developer.valvesoftware.com/wiki/PanelList_SubPanel
Main Code: [[PanelList_SubPanel]]
<br><br>
<br><br>
Things to note:
Things to note:

Revision as of 20:15, 13 June 2008


Panel List

This is a simple panel list that i made for use on Perfect Dark SP Source. It lists a bunch of panels and has the ability to group them as well. This is not final code but it should work (might be a couple of bugs).

The Result

From the picture you can see the header, and the sub panels with the ability to scroll and select. This image is from PerfectDark Source SP.
Panellist example.jpg

The Code

CPP: PanelList_cpp
H: PanelList_h

Save these two files and add them to your client project.

How to use them

To use this you will ether need to make a new panel or use and existing panel. This is covered in other tutorials on this site!


Header

Add this to the top of the header file

	//make sure you change this to reflect your file name!
	#include "pd_panel_list.h"

Add this to your class:

private:
	PD_PanelList *m_pPanelList;


Constructor

	//makes new object
	m_pPanelList = new PD_PanelList(this, "Map_PL");

	//sets the x, y pos and the w, h
	m_pPanelList->SetBounds(15,40,350,255);

	//Very Important. Means it will relay messages to this panel
	m_pPanelList->AddActionSignalTarget( this );

	//usefull if you want key commands to go up/down
	m_pPanelList->SetKeyBoardInputEnabled( true );


The sub panel

Main Code: PanelList_SubPanel

Things to note:

  • Parent class must be PD_BasePanel as this sets up mouse events
  • Must have a resize method (other wise it will never look right) which resizes the elements
  • Can have any panel elements on it
  • Need to set mouse imput enabled to false on all child elements. Other wise this will over ride the panellist mouse events


Adding panels

Addding panels is as easy as making a new panel then adding it to the panellist.

	//make sure you pass the panel list as parent because it will control the panel!
	SubPanel *temp= new SubPanel(m_pPanelList, name);

	//Set the sub panel up
	temp->SetTitle("Panel Title");
	temp->SetText("Some Text");

	//this is to fix a bug that i havnt fixed yet. If adding a duplicate panel it doesnt delete temp
	//but doesnt add it to the list ether
	if (m_pPanelList->AddPanel(temp)==-1)
	{
		delete temp;
	}