GameUI: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Created page with ''''GameUI''' is the code which provides 'frontend': broadly the main menu and loading screens. == Source 2009 == thumb|[[Source 2009 GameUI. Closed source…')
 
m (Nesciuse moved page GameUI/en to GameUI without leaving a redirect: Move en subpage to basepage)
 
(33 intermediate revisions by 13 users not shown)
Line 1: Line 1:
'''GameUI''' is the code which provides 'frontend': broadly the main menu and loading screens.
{{LanguageBar}}


== Source 2009 ==
:''Not to be confused with the [[game_ui]] entity.''


[[File:Ep2_menu.jpg|thumb|[[Source 2009]] GameUI. Closed source.]]
'''GameUI''' is the code which provides the [[VGUI]] 'frontend': broadly speaking, the main menu and loading screens.


In [[Source 2009]] (and earlier), GameUI is an 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.
GameUI panels are children of their own dedicated panel ("GameUI Panel"). The client's [[RootPanel]] is used only for in-game HUD elements.


== Left 4 Dead ==
== {{src04|name}} to {{src13|name}} ==


[[File:Swarm menu.jpg|thumb|[[Left 4 Dead (engine branch)|Left 4 Dead branch]] GameUI. Alien Swarm's SDK provides the code.]]
[[File:Ep2_menu.jpg|thumb|GameUI from {{src09|1}} - {{src13|1}} branch. The UI source code is available publicly on [https://github.com/ValveSoftware/source-sdk-2013 Source SDK 2013 GitHub page].]]
<!-- NOTE: Source 2007 is slightly different when it's come to achievement UI, and other element.-->
In the original branches of Source (from {{src04|1}} to {{src13|1}}), 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.


The [[Alien Swarm SDK]] contains the complete source for the newer L4D-style GameUI, as it has been moved into the client. This version of gameui still supports the earlier Windows-like UI but in general 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.
It is possible to [[VGUI2: Creating a panel|create new VGUI panels]] that behave in exactly the same way as GameUI ones. Starting with [[Source SDK 2013|Source 2013]] (which uses elements from ''[[Team Fortress 2]]''), such panels can [[Override GameUI|override]] the default main menu with four new functions included in [[IGameUI]].<br />


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.
It's worth noting that this version of GameUI still exists internally in every Source game made by Valve, though to what extent it is accessible or functional varies by game. Newer games (starting with {{l4dbranch|1}}) typically only use it for the [[console]] and server browser. {{csgo|1}} since newer updates have removed nearly all commands (except {{code|openserverbrowser}}) to show the original GameUI.


[[Category:Programming]]
== {{l4d|name}} to {{as|name}} engine branch ==
 
[[File:Swarm menu.jpg|thumb|{{l4dbranch|1}} GameUI. {{as|3.1}}'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. It's also far, far easier to program.
 
{{tip|VGUI panels very similar to Source 2009 ones can still be created with this incarnation of the code.}}
 
=== Creating a new window ===
 
# 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 [[W:Enumerated_type|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>
 
<code>CBaseModPanel</code> is a singleton; <code>CBaseModFrame</code> is the base class of all windows.
 
== {{p2|name}} ==
{{Todo|Document these.}}
[[Category:VGUI]] [[Category:Programming]]

Latest revision as of 06:54, 12 July 2024

English (en)Deutsch (de)中文 (zh)Translate (Translate)
Not to be confused with the game_ui entity.

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

GameUI panels are children of their own dedicated panel ("GameUI Panel"). The client's RootPanel is used only for in-game HUD elements.

Source 2004 to Source 2013

GameUI from Source 2009 - Source 2013 branch. The UI source code is available publicly on Source SDK 2013 GitHub page.

In the original branches of Source (from Source 2004 to Source 2013), 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.

It is possible to create new VGUI panels that behave in exactly the same way as GameUI ones. Starting with Source 2013 (which uses elements from Team Fortress 2), such panels can override the default main menu with four new functions included in IGameUI.

It's worth noting that this version of GameUI still exists internally in every Source game made by Valve, though to what extent it is accessible or functional varies by game. Newer games (starting with Left 4 Dead engine branch) typically only use it for the console and server browser. Counter-Strike: Global Offensive since newer updates have removed nearly all commands (except openserverbrowser) to show the original GameUI.

Left 4 Dead to Alien Swarm engine branch

Left 4 Dead engine 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. It's also far, far easier to program.

Tip.pngTip:VGUI panels very similar to Source 2009 ones can still be created with this incarnation of the code.

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()

CBaseModPanel is a singleton; CBaseModFrame is the base class of all windows.

Portal 2

Todo: Document these.