这篇条目有关 Source引擎。如需详情,点击这里。

Zh/Game text: Difference between revisions

From Valve Developer Community
< Zh
Jump to navigation Jump to search
(Created page with "{{LanguageBar}} Category:GUI Entities {{CD|CGameText|file1=maprules.cpp}} {{tabs|game_text|goldsrc=1|source=2|main=source}} left|link= {{this is a|point entity|name=game_text|except-multi={{L4d2|4}}}}{{ref|1}} 此实体用于在玩家屏幕上显示文本,并且不像{{ent|env_message}}使用<code>titles.txt</code>文件内预置的文本{{confirm}},此实体的文本内容可以直接在Hammer中定义。在多人游戏中,此实体...")
 
No edit summary
Line 27: Line 27:
== 键值 ==
== 键值 ==
{{KV Targetname}}
{{KV Targetname}}
{{KV|Message Text|intn=message|string|Message to display onscreen. <tt>\n</tt> signifies a new line in the text.}}
{{KV|Message Text|intn=message|string|需要在屏幕上显示的文本,<tt>\n</tt>表示文本中另起一横的部分}}
:{{bug|Hammer will automatically change backslashes to forward slashes, making <tt>\n</tt> impossible to enter.<!--
:{{bug|Hammer会自动将反斜杠替换为正斜杠,使得无法使用<tt>\n</tt><!--
-->{{workaround|<ul><!--
-->{{workaround|<ul><!--
--><li> Edit the VMF with a text editor, although this will need to be reapplied after each save<!--
--><li>使用文本编辑器修改VMF,但每次保存之后都要重复该步骤<!--
--><li> Edit the BSP entity lump with a hex editor, although this will need to be reapplied after each compile<!--
--><li>使用十六进制编辑器修改BSP的实体数据块,但每次编译之后都要重复该步骤<!--
--><li> Use [[AddOutput]] to set the message, as outputs are not affected</ul>}}<!--
--><li>使用[[AddOutput]]来传递文本内容,因为输出不受此影响</ul>}}<!--
-->{{tip|{{hammerpp|2}} does not do this.}} }}
-->{{tip|{{hammerpp|2}}不会这样}} }}
{{KV|X (0 - 1.0 {{=}} left to right) (-1 centers)|intn=x|string|Horizontal position on the player's screens to draw the text. The value should be between 0 and 1, where 0 is the far left of the screen and 1 is the far right. -1 centers the text.}}
{{KV|X(0 - 1.0 {{=}} left to right) (-1 centers)|intn=x|string|文本在玩家屏幕上的水平位置,值应介于0和1之间。0为屏幕最左侧,1为屏幕最右侧,-1为居中}}
{{KV|Y (0 - 1.0 {{=}} top to bottom) (-1 centers)|intn=y|string|Vertical position on the player's screens to draw the text. The value should be between 0 and 1, where 0 is the top of the screen and 1 is the bottom. -1 centers the text.}}
{{KV|Y (0 - 1.0 {{=}} top to bottom) (-1 centers)|intn=y|string|文本在玩家屏幕上的垂直位置,值应介于0和1之间。0为屏幕最上方,1为屏幕最下方,-1为居中}}
{{KV|Text Effect|intn=effect|choices|Text scan effect}}
{{KV|Text Effect|intn=effect|choices|文本的渲染效果}}
:*0: Fade In/Out. The whole text is faded in, and then faded out.
:*0: 淡入/淡出。整个文本逐渐显示,然后逐渐消失
:*1: Credits {{todo|Unknown—seems to act like Fade In/Out. Provide description.}}
:*1: 致谢名单。{{todo|用途不明,似乎和淡入淡出一样,需要更多信息}}
:*2: Scan Out. The text is scanned in letter by letter, and the whole text is then faded out.
:*2: 逐字显示。文本逐字显示,然后整个文本淡出
{{KV|Color1|intn=color|color255|The primary color used by all the text effects. {{note|The color values seem to be added to the background, so either a bright white background or black text will cause the message to be invisible.}} {{note|This keyvalue will default to black for entities not created in Hammer.}} }}
{{KV|Color1|intn=color|color255|文本所使用的主要颜色。{{note|颜色值似乎被添加到游戏背景中,所以纯白或纯黑背景下会导致文本不可见}} {{note|对于不通过Hammer内创建的实体,其默认值为黑色}} }}
{{KV|Color2|intn=color2|color255|The scanning color for the letter being scanned if the ''Text Effect'' keyvalue is set to ''Scan Out''—usually a different shade of Color1.}}
{{KV|Color2|intn=color2|color255|''Text Effect''类型为''逐字显示(Scan Out)''时,则该值为字符完全显示前使用的颜色,通常使用与Color1不同的颜色。}}
{{KV|Fade in Time (or character scan time)|intn=fadein|string|The time it should take for the text to fully fade in.}}
{{KV|Fade in Time (or character scan time)|intn=fadein|string|文本完全淡入(或逐字显示所需)所需的时间。}}
{{KV|Fade Out Time|intn=fadeout|string|The time it should take for the text to fade out, after the hold time has expired.}}
{{KV|Fade Out Time|intn=fadeout|string|停留时间过后,文本淡出所需的时间。}}
{{KV|Hold Time|intn=holdtime|string|The time the text should stay onscreen, after fading in, before it begins to fade out.{{note|This value defaults to zero for entities not created in Hammer.}}}}
{{KV|Hold Time|intn=holdtime|string|文本在淡入之后和开始淡出之前应在屏幕上停留的时间。{{note|对于不通过Hammer内创建的实体,其默认值为0}}}}
{{KV|Scan time (scan effect only)|intn=fxtime|string|If the 'Text Effect' is set to Scan Out, this is the time it should take to scan out all the letters in the text.}}
{{KV|Scan time (scan effect only)|intn=fxtime|string|当''Text Effect''类型为''逐字显示(Scan Out)''时,则该值为完全显示所有字符所需的时间}}
{{KV|Text Channel|intn=channel|choices|You can have up to six individual <tt>game_text</tt> messages onscreen at once, stored in channels. Select which channel this text should be placed in, which will overwrite any active message already in that channel.}}
{{KV|Text Channel|intn=channel|choices|最多可以在屏幕上显示六条单独的<tt>game_text</tt>文本,这些文本被储存在指定的频道中,此键值定义文本应在哪个频道显示,这将覆盖频道中任何已有的文本信息}}
:*0: Channel 0 (may be used by some HUD elements) {{Not in FGD}}
:*0: Channel 0 (可能用于部分HUD元素) {{Not in FGD}}
:*1: Channel 1
:*1: Channel 1
:*2: Channel 2 ({{portal2}} Small text size)
:*2: Channel 2 ({{portal2}} 小号文本)
:*3: Channel 3 ({{portal2}} Large text size)
:*3: Channel 3 ({{portal2}} 大号文本)
:*4: Channel 4
:*4: Channel 4
:*5: Channel 5 (may be used by some HUD elements) {{Not in FGD}}
:*5: Channel 5 (可能用于部分HUD元素) {{Not in FGD}}
{{warning|Some HUDs may use Channel 0 and/or Channel 5.}}
{{warning|部分HUD元素可能使用频道0或5}}
{{KV|Master|intn=master|string|Legacy support: The name of a master entity. If the master hasn't been activated, this entity will not activate.}}
{{KV|Master|intn=master|string|旧版支持:主实体的名称。如果主实体尚未激活,则此实体不会激活。}}


== Inputs ==
== Inputs ==
{{IO|Display|Display the message text.{{note|If the All Players flag is not set, the player must be the {{ent|!activator}} of this input in order for the text to be shown.}}}}
{{IO|Display|显示文本信息{{note|如果未在Flags中勾选All Players,则玩家必须得是{{ent|!activator}}才能看见文本}}}}
{{IO|SetText|Set the text to display.|param=string|since={{as}}}}
{{IO|SetText|设置要显示的文本|param=string|since={{as}}}}
{{tip|{{ent|AddOutput|message}} can be used to change text at runtime in older games which do not support <tt>SetText</tt>, although the <code>Display</code> input must be fired again.}}
{{tip|在不支持<tt>SetText</tt>的旧游戏中,可以使用{{ent|AddOutput|message}}来修改文本内容,但是必须得重新触发<code>Display</code>来更新文本}}
{{IO|SetPosX|Set the X position of the text. (0 - 1.0 {{=}} left to right) (-1 centers)|param=float|since={{portal2}}}}
{{IO|SetPosX|设置文本的水平位置 (0 - 1.0 {{=}}从左到右) (-1为居中)|param=float|since={{portal2}}}}
{{IO|SetPosY|Set the Y position of the text. (0 - 1.0 {{=}} top to bottom) (-1 centers)|param=float|since={{portal2}}}}
{{IO|SetPosY|设置文本的垂直位置. (0 - 1.0 {{=}}从上到下) (-1为居中)|param=float|since={{portal2}}}}
{{IO|SetTextColor|Set color of the front text.|param=color255|since={{portal2}}}}
{{IO|SetTextColor|设置文本的主颜色|param=color255|since={{portal2}}}}
{{IO|SetTextColor2|Set color of the transition text.|param=color255|since={{portal2}}}}
{{IO|SetTextColor2|设置文本的过渡颜色|param=color255|since={{portal2}}}}


== See also ==
== See also ==
* {{ent|game_text_tf}} - {{tf2}} Displays a custom HUD message with icons on a specified team's screen.
* {{ent|game_text_tf}} - {{tf2}}在指定团队的屏幕上显示带有图标的自定义HUD文本
* {{ent|point_worldtext}} - {{tf2}}{{csgo}} A similar entity that displays a custom message in the world with far more flexibility.
* {{ent|point_worldtext}} - {{tf2}}{{csgo}}一个类似的实体,以更大的灵活性在游戏内显示自定义文本
* {{ent|training_annotation}} - {{tf2}} A similar entity that points to a specified location in the world.
* {{ent|training_annotation}} - {{tf2}}一个类似的实体,指向游戏上的指定位置
* {{ent|env_hudhint}} - Displays a custom HUD message.  Commonly used to show key-binds.
* {{ent|env_hudhint}} - 显示自定义HUD文本。通常用于显示按键绑定
* {{ent|env_message}} - Displays a pre-defined message on the players screen.
* {{ent|env_message}} - 在玩家屏幕上显示预置的文本
* {{ent|point_message}} - A similar entity that displays a small custom message at a specific position in the game world.
* {{ent|point_message}} - 一个类似的实体,在游戏内的特定位置显示一条小型自定义文本
* [[Customizable triggered HUD-message]] - How to create a new entity that is similar to <tt>game_text</tt> but can receive the message string via a triggered input.
* [[Customizable triggered HUD-message]] - 如何创建一个类似于<tt>game_text</tt>但可以通过触发输入接收消息字符串的新实体。


== References ==
== References ==
# [https://forums.alliedmods.net/showthread.php?t=340355|In Left 4 Dead 2, the feature is not functioning. Here is a technical explanation for this issue.]
# [https://forums.alliedmods.net/showthread.php?t=340355 |在L4D2中,该功能无法使用。以下是该问题的技术说明]

Revision as of 07:53, 12 January 2025

English (en)中文 (zh)Translate (Translate)
C++ 类层级
CGameText
CRulePointEntity
CRuleEntity
CBaseEntity
C++ maprules.cpp
Game text.png

game_text是一个点实体(en),可在所有的 起源 起源 游戏,除了 求生之路2 求生之路2中使用。[1] 此实体用于在玩家屏幕上显示文本,并且不像env_message使用titles.txt文件内预置的文本[证实],此实体的文本内容可以直接在Hammer中定义。在多人游戏中,此实体通常只会向触发“Display”输出的触发者显示文本。通过勾选“All Players” Flag可以给所有玩家显示文本


Note.png注意:如果你要创建独立模组的话,建议使用env_message实体,该实体使用titles.txt脚本内预置的键值作为文本参数,这样无需重新编译地图即可更改文本。不像game_text实体,其还可以使用双引号与换横符
Tip.png提示:虽然实体注释另有说明,但是game_text在大部分起源游戏都支持使用多语言文本(例如#HL2_Chapter4_Title)
Warning.png警告:在实体键值或IO中使用双引号(")会导致VMF损坏,所以不能将其用于Text Message键值(甚至连反斜杠("\")也不可以)。不过你可以使用两个单引号('')或者中文引号(例如)代替

注意事项

Game_text作为HUD元素的一部分渲染的,更准确的说,是🖿/scripts/HudLayout.txt里的HudMessage元素。

由于历史遗留问题,该实体最初是为低分辨率显示器创建的,所以默认情况下被限制为基于640x480分辨率进行缩放

这会导致分辨率高于1920x1080时出现缩放问题,文本会变得更大,并且一部分文本会被隐藏

该问题还会导致仅适用屏幕的部分区域进行文本绘制,并且长行文本或屏幕边缘附近的文本在宽屏上会被裁剪。这回影响其他适用HudMessage元素渲染的文本,比如经典的“A. I. Disabled”提示

Note.png修复:前往🖿/scripts/HudLayout.txt并找到"HudMessage"部分,修改"wide""tall"的值(默认分别为640和480)为“f0”(显示器的完整尺寸)。这将增加文本出现的不可见VGUI屏幕的最大尺寸,使其扩展到 1920x1080 分辨率以上.[仅在2K、4K和带鱼屏上进行测试,尚不确认是否适用于所有分辨率]

选项

All Players : [1]
如未勾选,则仅向!activator显示文本

键值

Name (目标名称) <target_source>[ Edit ]
这个名称是其他实体通过 输入/输出(en) 或其他 关键值(en)(如 parentnametarget) 来引用该实体时使用的标识符。
该名称也会显示在 Hammer 编辑器的 2D 视图和 实体报告(en) 中。
参见:  所有实体均可使用的 通用键值、输入与输出(en)

Message Text (message) <字符串(en)>
需要在屏幕上显示的文本,\n表示文本中另起一横的部分
Icon-Bug.png错误:Hammer会自动将反斜杠替换为正斜杠,使得无法使用\n
PlacementTip.png解决方案:
  • 使用文本编辑器修改VMF,但每次保存之后都要重复该步骤
  • 使用十六进制编辑器修改BSP的实体数据块,但每次编译之后都要重复该步骤
  • 使用AddOutput来传递文本内容,因为输出不受此影响
Tip.png提示:Hammer++ Hammer++不会这样
  [todo tested in ?]
X(0 - 1.0 = left to right) (-1 centers) (x) <字符串(en)>
文本在玩家屏幕上的水平位置,值应介于0和1之间。0为屏幕最左侧,1为屏幕最右侧,-1为居中
Y (0 - 1.0 = top to bottom) (-1 centers) (y) <字符串(en)>
文本在玩家屏幕上的垂直位置,值应介于0和1之间。0为屏幕最上方,1为屏幕最下方,-1为居中
Text Effect (effect) <choices>
文本的渲染效果
  • 0: 淡入/淡出。整个文本逐渐显示,然后逐渐消失
  • 1: 致谢名单。
    待完善: 用途不明,似乎和淡入淡出一样,需要更多信息
  • 2: 逐字显示。文本逐字显示,然后整个文本淡出
Color1 (color) <color255(en)>
文本所使用的主要颜色。
Note.png注意:颜色值似乎被添加到游戏背景中,所以纯白或纯黑背景下会导致文本不可见
Note.png注意:对于不通过Hammer内创建的实体,其默认值为黑色
Color2 (color2) <color255(en)>
Text Effect类型为逐字显示(Scan Out)时,则该值为字符完全显示前使用的颜色,通常使用与Color1不同的颜色。
Fade in Time (or character scan time) (fadein) <字符串(en)>
文本完全淡入(或逐字显示所需)所需的时间。
Fade Out Time (fadeout) <字符串(en)>
停留时间过后,文本淡出所需的时间。
Hold Time (holdtime) <字符串(en)>
文本在淡入之后和开始淡出之前应在屏幕上停留的时间。
Note.png注意:对于不通过Hammer内创建的实体,其默认值为0
Scan time (scan effect only) (fxtime) <字符串(en)>
Text Effect类型为逐字显示(Scan Out)时,则该值为完全显示所有字符所需的时间
Text Channel (channel) <choices>
最多可以在屏幕上显示六条单独的game_text文本,这些文本被储存在指定的频道中,此键值定义文本应在哪个频道显示,这将覆盖频道中任何已有的文本信息
  • 0: Channel 0 (可能用于部分HUD元素) 不存在于FGD!
  • 1: Channel 1
  • 2: Channel 2 (传送门2 小号文本)
  • 3: Channel 3 (传送门2 大号文本)
  • 4: Channel 4
  • 5: Channel 5 (可能用于部分HUD元素) 不存在于FGD!
Warning.png警告:部分HUD元素可能使用频道0或5
Master (master) <字符串(en)>
旧版支持:主实体的名称。如果主实体尚未激活,则此实体不会激活。

Inputs

Display
显示文本信息
Note.png注意:如果未在Flags中勾选All Players,则玩家必须得是!activator才能看见文本
SetText <字符串(en)> (存在于自 异形丛生 以来)
设置要显示的文本
Tip.png提示:在不支持SetText的旧游戏中,可以使用AddOutput message来修改文本内容,但是必须得重新触发Display来更新文本
SetPosX <浮点型(en)> (存在于自 传送门2 以来)
设置文本的水平位置 (0 - 1.0 =从左到右) (-1为居中)
SetPosY <浮点型(en)> (存在于自 传送门2 以来)
设置文本的垂直位置. (0 - 1.0 =从上到下) (-1为居中)
SetTextColor <color255(en)> (存在于自 传送门2 以来)
设置文本的主颜色
SetTextColor2 <color255(en)> (存在于自 传送门2 以来)
设置文本的过渡颜色

See also

  • game_text_tf - 军团要塞2在指定团队的屏幕上显示带有图标的自定义HUD文本
  • point_worldtext - 军团要塞2反恐精英:全球攻势一个类似的实体,以更大的灵活性在游戏内显示自定义文本
  • training_annotation - 军团要塞2一个类似的实体,指向游戏上的指定位置
  • env_hudhint - 显示自定义HUD文本。通常用于显示按键绑定
  • env_message - 在玩家屏幕上显示预置的文本
  • point_message - 一个类似的实体,在游戏内的特定位置显示一条小型自定义文本
  • Customizable triggered HUD-message - 如何创建一个类似于game_text但可以通过触发输入接收消息字符串的新实体。

References

  1. |在L4D2中,该功能无法使用。以下是该问题的技术说明