Panorama事件

From Valve Developer Community
Jump to: navigation, search
English (en)
... Icon-Important.png

Panorama事件是一种用来沟通多个板元素的方法。受支持的事件有很多种,有些事件是通用的,有些则只适用于某几种板。大多数支持JS代码的板也支持使用事件。

Panorama events are a way to communicate information between multiple panels. There are many different event types, some of which are generally useful and some that are only useful on specific Panels. Most places that accept javascript functions will also accept events.

下面是一个使用事件的简例:

.DemoButton
{
    width: 50px;
    height: 50px;
    background-color: black;
}
.Toggled
{
    background-color: blue;
}
/* Using events */
<Button class="DemoButton" onactivate="ToggleStyle( Toggled )" />

/* Using javascript */
<Button class="DemoButton" onactivate="$.ToggleStyle( 'Toggled' )" />

Multiple events can be fired at the same time by using a semicolon between them:

<Button class="DemoButton" onactivate="ToggleStyle( Toggled ); AddStyle( HasBeenActivated )" />

有些事件也可以将其他事件作为变量:

<!-- Toggle the style after 0.5 seconds -->
<Button class="DemoButton" onactivate="AsyncEvent( 0.5, ToggleStyle( Toggled ) )" />

事件常规

事件总是由某个板发出的,但是并不总是由这个板处理。事件使用下列运算进行处理:

  1. 发出事件的板获得对事件进行首次处理的机会。
  2. 如果该板没有处理这个事件,板的父类将获得对事件进行处理的机会。
  3. 如果没有任何父类对事件做出处理,“未处理事件处理器”将会被调用并试图处理事件。

当你从一个子类发出一个事件,但是希望父类去处理事件的时候,这种方法就显得非常有用了。比如说:

<Panel id="Scroller" style="flow-children: down; overflow: squish scroll;">
  <Label text="假设这里有一堆文本。" />
  <Label text="多到需要用到滚动条 />
  <Label text="..." />
  <Button id="ScrollToTopButton" onactivate="ScrollToTop()">
    <Label text="Scroll to Top" />
  </Button>
</Panel>

在这个例子中,尽管事件ScrollToTop() 是由#ScrollToTopButton发出的,但是是由它的父类#Scroller 最终处理的。

the ScrollToTop() event is fired on the #ScrollToTopButton, the parent #Scroller is the one that actually handles it.

板事件

板事件是一种特殊的事件类型,它的第一个参数(可选)是所希望发出事件的板的ID。这样就可以让一个事件从其他一些板那里轻松地修改属性。 Panel events are a special type of event whose first parameter is optionally the ID of the panel you want the event to fire on. This allows an event to easily modify properties off of some other panel.

几个例子:

<Panel id="Controls">
  <!-- AddStyle会向Control1添加“Clicked”类。尽管Addstyle是一个板事件,但是它并未选择使用板ID作为第一个变量(记住这是可选的)。-->
  <Button id="Control1" onactivate="AddStyle( Clicked )" />

  <!-- AddStyle将对#Controls板添加“Clicked”类。-->
  <Button id="Control2" onactivate="AddStyle( Controls, Clicked )" />

  <!-- AddStyle将对#SomeOtherPanel板添加“Clicked”类,尽管这些板并不属于这个按钮的继承类。 -->
  <Button id="Control3" onactivate="AddStyle( SomeOtherPanel, Clicked )" />
</Panel>
<Panel id="SomeOtherPanel" />

注意,只有在同一个XML布局文件内的板ID才能被事件调用。

默认事件属性

Panorama支持一系列能够在与玩家互动时自动发出事件(或者javascript)的属性。大多数这样的事件和HTML5的属性一致,除了一些panorama特有的附加属性,和一些HTML5不支持的属性。

属性 描述
onload 板已完成加载。
onactivate 板被鼠标/键盘/控制器等的操作激活。
onmouseactivate 板被鼠标操作激活。
oncontextmenu 用户右键点击了该板,或按下了键盘上的内容菜单键。
onfocus 板获得了键盘聚焦(译者注:按一下tab,程序就会切换所选中的控件,就是键盘聚焦的形式之一。)
ondescendantfocus 板的继承之一获得了键盘聚焦。
onblur 板失去键盘聚焦。
ondescendantblur 板的继承之一失去了键盘聚焦。
oncancel 玩家按下了ESC键。
onmouseover 鼠标开始悬停在板上。获得选择器 :hover
onmouseout 鼠标结束悬停在板上。失去选择器 :hover
ondblclick 用户双击了板。
onmoveup 用户试图从板向上移动(上箭头键)。
onmovedown 用户试图从板向下移动(下箭头键)。
onmoveleft 用户试图从板向左移动(下箭头键)。
onmoveright 用户试图从板向右移动(右箭头键)。
ontabforward 用户试图从该板正向跳格(tab)(译者注:单tab键为正向,shift+tab为逆向)。
ontabbackward 用户试图从该板逆向跳格(shift+tab)
onselect 板获得选择器 :selected
ondeselect 板失去选择器 :selected
onscrolledtobottom 板被完全滚动到底部。
onscrolledtorightedge 板被完全滚动到右边缘

事件列表

Generated using dump_panorama_events on 9/20/2021 by 西索酱.

更多整理在 https://www.npmjs.com/package/@mobilc/panorama-type

事件 板事件? 描述
AddStyle(string class) Yes 向板添加一个css类。
AddStyleAfterDelay(string class, float pre-delay) Yes Add a CSS class to a panel after a specified delay.
AddStyleToEachChild(string class) Yes 向板的所有继承添加一个CSS类。
AddTimedStyle(string class, float duration, float pre-delay) Yes Add a class for a specified duration, with optional pre-delay; clears existing timers when called with same class.
AsyncEvent(float delay, event eventToFire) No 在一定延迟(以秒记)后发出另一个事件。
DOTADisplayDashboardTip(string string, string optional string) No Tip to display, panel to attach to (default 'DefaultTipAttachment')
DOTAHideAbilityTooltip() Yes 隐藏技能栏。
DOTAHideBuffTooltip() Yes 隐藏BUFF栏。
DOTAHideDroppedItemTooltip() Yes Hide the dropped item tooltip
DOTAHideEconItemTooltip() Yes 隐藏经济/物品栏。
DOTAHideProfileCardBattleCupTooltip() Yes Hide the profile card / battle cup tooltip.
DOTAHideProfileCardTooltip() Yes 隐藏英雄头像。
DOTAHideRankTierTooltip() Yes Hide the rank tier tooltip.
DOTAHideRuneTooltip() Yes Hide the rune tooltip
DOTAHideTextTooltip() Yes 隐藏文本框。
DOTAHideTI10EventGameTooltip() Yes Hide the ti10 event game tooltip
DOTAHideTitleImageTextTooltip() Yes 隐藏图片文本框。
DOTAHideTitleTextTooltip() Yes Hide the title text tooltip.
DOTALiveStreamUpcoming(uint32 time) Yes Notify change in RTime32 we expect the stream to start
DOTALiveStreamVideoLive(bool isLive) Yes Notify change in video state (is it pointing at a live stream page or not)
DOTAShowAbilityInventoryItemTooltip(int32 entityIndex, int32 inventorySlot) Yes Show tooltip for an item in the entityIndex NPC's inventory.
DOTAShowAbilityShopItemTooltip(string abilityName, string guideName, int32 entityIndex) Yes Show tooltip for an item in the entityIndex NPC's shop.
DOTAShowAbilityTooltip(string abilityName) Yes 显示技能栏。
DOTAShowAbilityTooltipForEntityIndex(string abilityName, int32 entityIndex) Yes 显示技能栏。等级信息将从由实体索引具体化的实体获取。
DOTAShowAbilityTooltipForGuide(string abilityName, string guideName) Yes Show an ability tooltip annotated with a particular guide's info.
DOTAShowAbilityTooltipForHero(string abilityName, int32 heroid, bool) Yes Show an ability tooltip for the specified hero.
DOTAShowAbilityTooltipForLevel(string abilityName, int32) Yes Show an ability tooltip for a specific level.
DOTAShowBuffTooltip(int32 entityIndex, int32 buffSerial, bool bOnEnemy) Yes Show a buff tooltip for the specified entityIndex + buff serial.
DOTAShowEconItemTooltip(class item_definition_index_t itemDef, class style_index_t styleIndex, int32 heroID) Yes 根据指定物品、样式、英雄,显示经济物品栏。0表示默认样式,-1表示默认英雄。
DOTAShowProfileCardBattleCupTooltip(uint64 steamID) Yes Show the battle cup portion of the user's profile card, if it exists
DOTAShowProfileCardTooltip(uint64 steamID, bool useProName) Yes Show a user's profile card. Use pro name determines whether to use their professional team name if applicable.
DOTAShowRankTierTooltip(uint64 steamID, enum EDOTAPlayerMMRType) Yes Show the rank tier tooltip for a user
DOTAShowRuneTooltip(int32 X, int32 Y, int32 RuneType) Yes Show a rune tooltip in the X Y location for the rune type
DOTAShowTextTooltip(string text) Yes 显示包含指定信息的提示栏。
DOTAShowTextTooltipStyled(string text, string style) Yes 显示包含指定信息的提示栏。同时应用名为“style”的CSS类来使用定制样式。
DOTAShowTI10EventGameTooltip(struct TI10EventGameTooltipInfo_t const * __ptr64 X) Yes Show a ti10 event game tooltip
DOTAShowTitleImageTextTooltip(string title, string imagePath, string text) Yes 显示包含指定标题、图像、文本的提示栏。
DOTAShowTitleImageTextTooltipStyled(string title, string imagePath, string text, string style) Yes 显示包含指定标题、图像、文本的提示栏。同时应用名为“style”的CSS类来使用定制样式。
DOTAShowTitleTextTooltip(string title, string text) Yes 显示包含指定标题和文本的提示栏。
DOTAShowTitleTextTooltipStyled(string title, string text, string style) Yes 显示包含指定标题和文本的提示栏。同时应用名为“style”的CSS类来使用定制样式。
DropInputFocus() Yes Drop focus entirely from the window containing this panel.
IfHasClassEvent(string class, event eventToFire) Yes 如果该板含有指定的类,则发出另一个事件。
IfHoverOtherEvent(string otherPanelID, event eventToFire) Yes 如果光标悬浮在某个具有特定ID的板上,则发出另一个事件。
IfNotHasClassEvent(string class, event eventToFire) Yes 如果该板不含有指定的类,则发出另一个事件
IfNotHoverOtherEvent(string otherPanelID, event eventToFire) Yes 如果光标悬浮在某个不具有特定ID的板上,则发出另一个事件。
MovePanelDown(int32 repeatCount) Yes 从一个板向下移动。默认情况下,聚焦位置将会被改变,但某些类型的板可能会做出不同的操作。
MovePanelLeft(int32 repeatCount) Yes 从一个板向左移动。默认情况下,聚焦位置将会被改变,但某些类型的板可能会做出不同的操作。
MovePanelRight(int32 repeatCount) Yes 从一个板向右移动。默认情况下,聚焦位置将会被改变,但某些类型的板可能会做出不同的操作。
MovePanelUp(int32 repeatCount) Yes 从一个板向上移动。默认情况下,聚焦位置将会被改变,但某些类型的板可能会做出不同的操作。
PageDown() No 将板向下滚动一页。
PageLeft() No 将板向左滚动一页。
PagePanelDown() Yes 将板向下滚动一页。
PagePanelLeft() Yes 将板向左滚动一夜。
PagePanelRight() Yes 将板向右滚动一页
PagePanelUp() Yes 将板向上滚动一页。
PageRight() No 将板向右滚动一页。
PageUp() No 将板向上滚动一页。
RemoveStyle(string class) Yes 从板中移除一个 CSS类。
RemoveStyleAfterDelay(string class, float pre-delay) Yes Remove a CSS class from a panel after a specified delay.
RemoveStyleFromEachChild(string class) Yes 从板的所有的子板中移除一个CSS类。
ScrollDown() No 将板向下滚动一行。
ScrollLeft() No 将板向左滚动一行。
ScrollPanelDown() Yes 将板向下滚动一行。
ScrollPanelLeft() Yes 将板向左滚动一行。
ScrollPanelRight() Yes 将板向右滚动一行。
ScrollPanelUp() Yes 将板向上滚动一行。
ScrollRight() No 将板向右滚动一行。
ScrollToBottom() Yes 将板滚动到底部。
ScrollToTop() Yes 将板滚动到顶部
ScrollUp() No 将板向上滚动一行。
SetChildPanelsSelected(bool selected) Yes 设定所有子板是否被选择。
SetInputFocus() Yes 将聚焦设定到此板上。
SetPanelEnabled(bool enabled) Yes Sets whether the given panel is enabled
SetPanelSelected(bool selected) Yes 设定该板是否被选择。
SwitchStyle(string slot, string class) Yes Switch which class the panel has for a given attribute slot. Allows easily changing between multiple states.
TogglePanelSelected() Yes 切换该板的被选择状态。
ToggleStyle(string class) Yes 切换该板是否含有某CSS类。
TriggerStyle(string class) Yes Remove then immediately add back a CSS class from a panel. Useful to re-trigger events like animations or sound effects.