VGUI PanelList: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
m (→‎The Result: Unicodifying, replaced: [[Image: → [[File:)
 
(11 intermediate revisions by 4 users not shown)
Line 1: Line 1:
[[Category:VGUI]]
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).


==Panel List==
==The Result==
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).
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.


==The Result==
[[File:Panellist_example.jpg]]
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.<br>
[[Image:Panellist_example.jpg]]


==The Code==
==The Code==
CPP: [[PanelList_cpp]]<br>
 
H: [[PanelList_h]]
* [[PanelList_cpp]]
<p>
* [[PanelList_h]]
Save these two files and add them to your client project.
* [[PanelList_SubPanel]] (an example)
 
Save these files and add them to your client project.


==How to use them==
==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!
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===
===Header===
Add this to the top of the header file
Add this to the top of the header file
<pre>
 
//make sure you change this to reflect your file name!
//make sure you change this to reflect your file name!
#include "pd_panel_list.h"
#include "pd_panel_list.h"
</pre>
 
Add this to your class:
Add this to your class:
<pre>
private:
PD_PanelList *m_pPanelList;
</pre>


private:
PD_PanelList *m_pPanelList;


===Constructor===
===Constructor===
<pre>
//makes new object
m_pPanelList = new PD_PanelList(this, "Map_PL");


//sets the x, y pos and the w, h
//makes new object
m_pPanelList->SetBounds(15,40,350,255);
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 );


//Very Important. Means it will relay messages to this panel
===The sub panel===
m_pPanelList->AddActionSignalTarget( this );
 
//usefull if you want key commands to go up/down
m_pPanelList->SetKeyBoardInputEnabled( true );
</pre>


Sub-panels must inherit from <code>PD_BasePanel</code> (found in [[PanelList_h]]). Things to note:


===The sub panel===
Main Code: [[PanelList_SubPanel]]
<br><br>
Things to note:
*Parent class must be PD_BasePanel as this sets up mouse events
*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
*Must have a resize method (other wise it will never look right) which resizes the elements
Line 56: Line 51:
*Need to set mouse imput enabled to false on all child elements. Other wise this will over ride the panellist mouse events
*Need to set mouse imput enabled to false on all child elements. Other wise this will over ride the panellist mouse events


===Adding panels===


===Adding panels===
Addding panels is as easy as making a new panel then adding it to the panellist.
Addding panels is as easy as making a new panel then adding it to the panellist.
<pre>
//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
//make sure you pass the panel list as parent because it will control the panel!
temp->SetTitle("Panel Title");
SubPanel *temp= new SubPanel(m_pPanelList, name);
temp->SetText("Some Text");
//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;
}


//this is to fix a bug that i havnt fixed yet. If adding a duplicate panel it doesnt delete temp
[[Category:Custom VGUI Controls]]
//but doesnt add it to the list ether
[[Category:Free source code]]
if (m_pPanelList->AddPanel(temp)==-1)
{
delete temp;
}
</pre>

Latest revision as of 00:17, 7 January 2024

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