GameUI
- 不要与 game_ui 实体混淆
GameUI 是提供 VGUI 'frontend': broadly speaking, 主菜单还有加载界面的代码。
GameUI panels are children of their own dedicated panel ("GameUI Panel"). 客户端的 RootPanel 只用于游戏里的HUD元素。
Source 2009
In the original branches of Source (from Episode One to The Orange Box ), 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 .
Left 4 Dead
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.
创建一个新的窗口
- 新建一个类, 继承自
CBaseModFrame
。 - 在
game\resource\ui\basemodui\
创建一个accompanying "<class name>.res" 脚本。 - 向
WINDOW_TYPE
添加一个新的enum(【术语】枚举) - 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
初始化顺序为:
CGameUI::Initialize()
CBaseModPanel::RunFrame()
CBaseModPanel::OnGameUIActivated()
CBaseModPanel::OpenFrontScreen()
CBaseModPanel::OpenWindow()
CBaseModPanel
is a singleton; CBaseModFrame
是所有窗口的基类。