GameUI: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
(→‎Left 4 Dead: creating and opening windows)
Line 11: Line 11:
[[File:Swarm menu.jpg|thumb|[[Left 4 Dead (engine branch)|Left 4 Dead branch]] GameUI. Alien Swarm's SDK provides the code.]]
[[File:Swarm menu.jpg|thumb|[[Left 4 Dead (engine branch)|Left 4 Dead branch]] GameUI. Alien Swarm's SDK provides the code.]]


The [[Alien Swarm SDK]] contains the complete source for the newer L4D-style GameUI, which has been moved into the client. It has been redesigned for ease of use on consoles (which lack a pointing device): everything is integrated into the same navigable menu system, and you can't be in more than area at once.
The [[Alien Swarm SDK]] contains the complete source for the newer L4D-style GameUI, which has been moved into the client library. It has been redesigned for consoles' lack of a pointing device: everything is integrated into the same navigable menu system, and you can't be in more than area at once.


{{note|The Source 2009 GameUI is still available in the L4D branch, and the two can co-exist.}}
{{note|The Source 2009 GameUI is still available in the L4D branch, and the two can co-exist.}}


The root function is <code>CGameUI::Initialize()</code>. Unfortunately, the server browser code is ''not'' included, and it would seem that the old DLL provides that still.
=== Creating a new window ===


[[Category:Programming]]
# Create a new class, inheriting from <code>[[CBaseModFrame]]</code>.
# Create an accompanying "<class name>.res" script in <code>game\resource\ui\basemodui\</code>.
# Add a new entry to the <code>WINDOW_TYPE</code> enum.
# Edit the enormous switch in <code>CBaseModPanel::OpenWindow()</code> to include your new enum and class.
 
The ugly enum/switch indirection is presumably designed to allow a single "window type" value to open slightly different window objects depending on the UI's state. Too bad Valve haven't found any excuse to do that yet!
 
=== Opening windows ===
 
Use <code>CBaseModFrame* CBaseModPanel::OpenWindow()</code>:
<source lang=cpp>
#include "gameui\swarm\basemodpanel.h"
 
using namespace BaseModUI;
 
void openwindow()
{
CBaseModFrame* mainMenu = CBaseModPanel::GetSingleton().GetWindow( WT_MAINMENU );
CBaseModPanel::GetSingleton().OpenWindow( WT_GAMESETTINGS, mainMenu );
}
</source>
 
The arguments are:
 
; <code>WINDOW_TYPE &wt</code>
: An [[enum]] value that defines which precise window to open.
; <code>[[CBaseModFrame]]* caller</code>
: The window which requested this one to open. Among other things, this becomes the target of 'back' buttons on the new window.
; <code>[[bool]] hidePrevious</code>
: Hides <code>caller</code> if true.
; <code>[[KeyValues]]* pParameters</code>
: Passed on to the new window.
 
<code>OnOpen()</code> is called on the opened window.
 
=== Startup ===
 
The initialization sequence is:
 
# <code>CGameUI::Initialize()</code>
# <code>CBaseModPanel::RunFrame()</code>
# <code>CBaseModPanel::OnGameUIActivated()</code>
# <code>CBaseModPanel::OpenFrontScreen()</code>
# <code>CBaseModPanel::OpenWindow()</code>
 
[[Category:VGUI]] [[Category:Programming]]

Revision as of 13:08, 23 July 2010

GameUI is the code which provides 'frontend': broadly speaking, the main menu and loading screens.

Source 2009

Source 2009 GameUI. Closed source.

In Source 2009 (and earlier), GameUI is a closed engine library manipulable to a limited extent by editing .res script files. These define properties like width, height, element location, and so on. You can add new non-interactive elements, and with a bit of effort hide existing ones.

Left 4 Dead

Left 4 Dead branch GameUI. Alien Swarm's SDK provides the code.

The Alien Swarm SDK contains the complete source for the newer L4D-style GameUI, which has been moved into the client library. It has been redesigned for consoles' lack of a pointing device: everything is integrated into the same navigable menu system, and you can't be in more than area at once.

Note.pngNote:The Source 2009 GameUI is still available in the L4D branch, and the two can co-exist.

Creating a new window

  1. Create a new class, inheriting from CBaseModFrame.
  2. Create an accompanying "<class name>.res" script in game\resource\ui\basemodui\.
  3. Add a new entry to the WINDOW_TYPE enum.
  4. Edit the enormous switch in CBaseModPanel::OpenWindow() to include your new enum and class.

The ugly enum/switch indirection is presumably designed to allow a single "window type" value to open slightly different window objects depending on the UI's state. Too bad Valve haven't found any excuse to do that yet!

Opening windows

Use CBaseModFrame* CBaseModPanel::OpenWindow():

#include "gameui\swarm\basemodpanel.h"

using namespace BaseModUI;

void openwindow()
{
	CBaseModFrame* mainMenu = CBaseModPanel::GetSingleton().GetWindow( WT_MAINMENU );
	CBaseModPanel::GetSingleton().OpenWindow( WT_GAMESETTINGS, mainMenu );
}

The arguments are:

WINDOW_TYPE &wt
An enum value that defines which precise window to open.
CBaseModFrame* caller
The window which requested this one to open. Among other things, this becomes the target of 'back' buttons on the new window.
bool hidePrevious
Hides caller if true.
KeyValues* pParameters
Passed on to the new window.

OnOpen() is called on the opened window.

Startup

The initialization sequence is:

  1. CGameUI::Initialize()
  2. CBaseModPanel::RunFrame()
  3. CBaseModPanel::OnGameUIActivated()
  4. CBaseModPanel::OpenFrontScreen()
  5. CBaseModPanel::OpenWindow()