Zh/GameUI: Difference between revisions

From Valve Developer Community
< Zh
Jump to navigation Jump to search
m (Amicdict moved page GameUI:zh-cn to GameUI/zh)
mNo edit summary
 
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{lang|GameUI}}
{{LanguageBar}}
:''不要与 [[game_ui]] 实体混淆''


'''GameUI''' 是提供 [[VGUI]] 'frontend': broadly speaking, 主菜单还有加载界面的代码。
:''不要与 {{L|game_ui}} 实体混淆''


GameUI panels are children of their own dedicated panel ("GameUI Panel"). 客户端的 [[RootPanel]] 只用于游戏里的HUD元素。
'''GameUI''' 是提供 {{LCategory|VGUI|VGUI}}  "前端" 的代码:广泛地说,主菜单还有加载界面的代码。


== Source 2009 ==
GameUI面板是其专用面板 ("GameUI Panel") 的子对象。 客户端的 {{L|RootPanel}} 只用于游戏里的HUD元素。


[[File:Ep2_menu.jpg|thumb|[[Source 2009]] GameUI. Closed source.]]
== {{src04|name}} 到 {{src13|name}} ==


In the original branches of Source (from [[Episode One (engine branch)|Episode One]] to [[Orange Box|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.
[[File:Ep2_menu.jpg|thumb|{{L|Orange_Box_(engine_branch)#2009/MP|Source 2009}} 的GameUI。闭源。]]


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]].
在Source引擎的原始分支中 (从 {{L|Source_2004|Source 2004}} 到 {{L|Source_2013|橙盒}}),GameUI是一个封闭的引擎库,只能通过编辑 {{L|res}} 脚本文件进行有限地操作。这些脚本定义了宽度、高度、元素位置等属性,开发者可以添加新的非交互元素,并通过一定技巧隐藏现有元素。


== Left 4 Dead ==
开发者能够 {{L|VGUI2: Creating a panel|创建新的VGUI面板}} ,其行为与GameUI原生面板完全一致。从 {{L|Source_SDK_Base_2013|Source 2013}} 引擎开始 (该版本采用了 ''{{L|Team Fortress 2|军团要塞2}}'' 的组件),此类面板可通过 {{L|Override GameUI|覆盖}} 默认主菜单实现自定义—— {{L|IGameUI}} 接口为此新增了四个专用函数。


[[File:Swarm menu.jpg|thumb|[[Left 4 Dead (engine branch)|Left 4 Dead branch]] GameUI. Alien Swarm's SDK provides the code.]]
== {{l4d|name}} 到 {{as|name}} 引擎分支 ==


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.
[[File:Swarm menu.jpg|thumb|{{L|Left_4_Dead_engine_branch|求生之路分支}} 的GameUI。异形丛生的SDK提供了代码。]]


{{tip|VGUI panels very similar to Source 2009 ones can still be created with this incarnation of the code.}}
{{L|Alien_Swarm/Authoring_Tools|异形丛生 SDK}} 包含了新版L4D风格GameUI的完整源代码,该UI系统已被移至客户端库中。其设计针对主机平台(无指向设备)进行了重构:所有功能被整合到同一套可导航菜单系统中,用户无法同时操作多个区域。其编程实现也大幅简化。
 
{{tip|使用此版本代码,仍可创建与Source 2009极其相似的VGUI面板。}}


=== 创建一个新的窗口 ===
=== 创建一个新的窗口 ===


# 新建一个类, 继承自 <code>[[CBaseModFrame]]</code>
# 新建一个继承自 <code>{{L|CBaseModFrame}}</code> 的类。
# 在<code>game\resource\ui\basemodui\</code>创建一个accompanying "<class name>.res" 脚本。
# 在 <code>game\resource\ui\basemodui\</code> 目录下创建对应的 "<class name>.res" 脚本。
# <code>WINDOW_TYPE</code> 添加一个新的enum(【术语】枚举)
# <code>WINDOW_TYPE</code> enum(【术语】枚举)中添加新条目。
# Edit the enormous switch in <code>CBaseModPanel::OpenWindow()</code> to include your new enum and class.
# 修改 <code>CBaseModPanel::OpenWindow()</code> 中庞大的switch语句,加入新枚举和类。


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!
这种笨拙的枚举/switch indirection的设计,大概是为了让单个"窗口类型"值能根据UI状态打开不同窗口对象——遗憾的是Valve至今没有实际应用过!


=== Opening windows ===
=== 窗口打开机制 ===


Use <code>CBaseModFrame* CBaseModPanel::OpenWindow()</code>:
使用代码 <code>CBaseModFrame* CBaseModPanel::OpenWindow()</code>
<source lang=cpp>
<source lang=cpp>
#include "gameui\swarm\basemodpanel.h"
#include "gameui\swarm\basemodpanel.h"
Line 46: Line 47:
</source>
</source>


The arguments are:
参数说明如下:


; <code>WINDOW_TYPE &wt</code>
; <code>WINDOW_TYPE &wt</code>
: An [[W:Enumerated_type|enum]] value that defines which precise window to open.
: 定义具体打开哪个窗口的[[W:Enumerated_type|枚举值]]
; <code>[[CBaseModFrame]]* caller</code>
; <code>{{L|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.
: 发起打开请求的父窗口,除其他作用外,新窗口的 ""back"" 按钮将指向该对象。
; <code>[[bool]] hidePrevious</code>
; <code>{{L|bool}} hidePrevious</code>
: Hides <code>caller</code> if true.
: 若为true则隐藏 <code>caller</code> 窗口。
; <code>[[KeyValues]]* pParameters</code>
; <code>{{L|KeyValues}}* pParameters</code>
: Passed on to the new window.
: 传递给新窗口的参数集。


<code>OnOpen()</code> is called on the opened window.
新窗口打开时会触发 <code>OnOpen()</code> 函数的调用。


=== Startup ===
=== 启动 ===


初始化顺序为:
初始化顺序为:
Line 69: Line 70:
# <code>CBaseModPanel::OpenWindow()</code>
# <code>CBaseModPanel::OpenWindow()</code>


<code>CBaseModPanel</code> is a singleton; <code>CBaseModFrame</code> 是所有窗口的基类。
<code>CBaseModPanel</code> 是单例对象; <code>CBaseModFrame</code> 是所有窗口的基类。


[[Category:VGUI:zh-cn]] [[Category:Programming:zh-cn]]
{{ACategory|VGUI}} {{ACategory|Programming}}
{{ACategory|VGUI}} {{ACategory|Programming}}

Latest revision as of 04:36, 24 June 2025

English (en)Deutsch (de)中文 (zh)Translate (Translate)
不要与 game_ui(en) 实体混淆

GameUI 是提供 VGUI(en) "前端" 的代码:广泛地说,主菜单还有加载界面的代码。

GameUI面板是其专用面板 ("GameUI Panel") 的子对象。 客户端的 RootPanel(en) 只用于游戏里的HUD元素。

起源2004 到 起源2013

Source 2009(en) 的GameUI。闭源。

在Source引擎的原始分支中 (从 Source 2004(en)橙盒(en)),GameUI是一个封闭的引擎库,只能通过编辑 res(en) 脚本文件进行有限地操作。这些脚本定义了宽度、高度、元素位置等属性,开发者可以添加新的非交互元素,并通过一定技巧隐藏现有元素。

开发者能够 创建新的VGUI面板(en) ,其行为与GameUI原生面板完全一致。从 Source 2013(en) 引擎开始 (该版本采用了 军团要塞2(en) 的组件),此类面板可通过 覆盖(en) 默认主菜单实现自定义—— IGameUI(en) 接口为此新增了四个专用函数。

求生之路 到 异形丛生 引擎分支

求生之路分支(en) 的GameUI。异形丛生的SDK提供了代码。

异形丛生 SDK(en) 包含了新版L4D风格GameUI的完整源代码,该UI系统已被移至客户端库中。其设计针对主机平台(无指向设备)进行了重构:所有功能被整合到同一套可导航菜单系统中,用户无法同时操作多个区域。其编程实现也大幅简化。

Tip.png提示:使用此版本代码,仍可创建与Source 2009极其相似的VGUI面板。

创建一个新的窗口

  1. 新建一个继承自 CBaseModFrame(en) 的类。
  2. game\resource\ui\basemodui\ 目录下创建对应的 "<class name>.res" 脚本。
  3. WINDOW_TYPE enum(【术语】枚举)中添加新条目。
  4. 修改 CBaseModPanel::OpenWindow() 中庞大的switch语句,加入新枚举和类。

这种笨拙的枚举/switch indirection的设计,大概是为了让单个"窗口类型"值能根据UI状态打开不同窗口对象——遗憾的是Valve至今没有实际应用过!

窗口打开机制

使用代码 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 );
}

参数说明如下:

WINDOW_TYPE &wt
定义具体打开哪个窗口的枚举值
CBaseModFrame(en)* caller
发起打开请求的父窗口,除其他作用外,新窗口的 ""back"" 按钮将指向该对象。
bool(en) hidePrevious
若为true则隐藏 caller 窗口。
KeyValues(en)* pParameters
传递给新窗口的参数集。

新窗口打开时会触发 OnOpen() 函数的调用。

启动

初始化顺序为:

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

CBaseModPanel 是单例对象; CBaseModFrame 是所有窗口的基类。