VGUI PanelList

From Valve Developer Community
(Redirected from PanelList)
Jump to: navigation, search

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

Save these files and add them to your client project.

How to use them

To use this you will need to make a new panel (covered in other tutorials on this site). Also you will need a subpanel and you can use the existing subpanel or make a new sub panel of your own following the guild lines below.

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

Sub-panels must inherit from PD_BasePanel (found in PanelList_h). 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;
	}