From b519fd546a59d39a41faeb7ac22b23b2313b9d12 Mon Sep 17 00:00:00 2001 From: "Xavier(Home)" Date: Sat, 12 Apr 2025 20:34:16 +0800 Subject: [PATCH 1/9] add some missing `Abilities` API --- packages/panorama-types/types/api.d.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/panorama-types/types/api.d.ts b/packages/panorama-types/types/api.d.ts index 95fae64..07eb058 100644 --- a/packages/panorama-types/types/api.d.ts +++ b/packages/panorama-types/types/api.d.ts @@ -1159,6 +1159,8 @@ interface CScriptBindingPR_Abilities { GetCurrentCharges(nEntityIndex: AbilityEntityIndex): number; + GetCurrentAbilityCharges(nEntityIndex: AbilityEntityIndex): number; + GetEffectiveLevel(nEntityIndex: AbilityEntityIndex): number; GetHeroLevelRequiredToUpgrade(nEntityIndex: AbilityEntityIndex): number; @@ -1225,6 +1227,8 @@ interface CScriptBindingPR_Abilities { IsToggle(nEntityIndex: AbilityEntityIndex): boolean; + UsesAbilityCharges(nEntityIndex: AbilityEntityIndex): boolean; + GetAOERadius(nEntityIndex: AbilityEntityIndex): number; GetBackswingTime(nEntityIndex: AbilityEntityIndex): number; @@ -1247,6 +1251,8 @@ interface CScriptBindingPR_Abilities { GetUpgradeBlend(nEntityIndex: AbilityEntityIndex): number; + GetAbilityChargeRestoreTimeRemaining(nEntityIndex: AbilityEntityIndex): number; + /** * Get the local player's current active ability. (Pre-cast targetting state.) */ From 52ea06a5ea0261ca4f7f61736c2fe7e455f9ade1 Mon Sep 17 00:00:00 2001 From: "Xavier(Home)" Date: Sat, 12 Apr 2025 20:43:45 +0800 Subject: [PATCH 2/9] add some missing `Game` api --- packages/panorama-types/types/api.d.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/panorama-types/types/api.d.ts b/packages/panorama-types/types/api.d.ts index 07eb058..5b08ced 100644 --- a/packages/panorama-types/types/api.d.ts +++ b/packages/panorama-types/types/api.d.ts @@ -1443,6 +1443,12 @@ interface CScriptBindingPR_Game { IsInBanPhase(): boolean; + GetConvarBool(name: string): boolean; + + GetConvarInt(name: string): number; + + GetConvarFloat(name: string): number; + /** * Return the team id of the winning team. */ From ae3053c40f68611b647921c753576cfd2ae0a3e1 Mon Sep 17 00:00:00 2001 From: "Xavier(Home)" Date: Sat, 12 Apr 2025 20:45:53 +0800 Subject: [PATCH 3/9] run code lint --- packages/panorama-types/types/api.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/panorama-types/types/api.d.ts b/packages/panorama-types/types/api.d.ts index 5b08ced..cc0eb9c 100644 --- a/packages/panorama-types/types/api.d.ts +++ b/packages/panorama-types/types/api.d.ts @@ -1444,7 +1444,7 @@ interface CScriptBindingPR_Game { IsInBanPhase(): boolean; GetConvarBool(name: string): boolean; - + GetConvarInt(name: string): number; GetConvarFloat(name: string): number; From 7eb86375980c03b87bc9b798f3dd8b997b2afc8d Mon Sep 17 00:00:00 2001 From: "Xavier(Home)" Date: Sat, 12 Apr 2025 21:18:46 +0800 Subject: [PATCH 4/9] add all missing API from `cl_panorama_typescript_declarations` --- packages/panorama-types/types/api.d.ts | 95 ++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/packages/panorama-types/types/api.d.ts b/packages/panorama-types/types/api.d.ts index cc0eb9c..52b315d 100644 --- a/packages/panorama-types/types/api.d.ts +++ b/packages/panorama-types/types/api.d.ts @@ -343,6 +343,33 @@ interface CDOTA_PanoramaScript_GameUI { * Creates a localized version of the number */ ConstructNumberString(n: number): string; + + /** + * Query to check if Tips are available for the local player + */ + AreTipsAvailable(): boolean; + + /** + * Query to see if the local player can tip a specific player + */ + IsPlayerTippable(iPlayerID: number): boolean; + + /** + * Tip a player + */ + TipPlayer(iPlayerID: number): void; + + DisplayCustomContextualTip(...args: unknown[]): void; + + /** + * Set the text of a passed label for a DOTA Talent using ability values. + */ + SetupDOTATalentNameLabel(...args: unknown[]): void; + + /** + * Returns true if the passed ability is a talent. + */ + IsAbilityDOTATalent(pszAbilityName: string): boolean; } /** @@ -693,6 +720,11 @@ interface CScriptBindingPR_Players { */ GetTeam(iPlayerID: PlayerID): DOTATeam_t; + /** + * Get the player's selected hero id. + */ + GetSelectedHeroID(iPlayerID: PlayerID): HeroID; + /** * Average gold earned per minute for this player. */ @@ -720,6 +752,8 @@ interface CScriptBindingPR_Players { PlayerPortraitClicked(nClickedPlayerID: PlayerID, bHoldingCtrl: boolean, bHoldingAlt: boolean): void; + PlayerPortraitDoubleClicked(nClickedPlayerID: PlayerID, bHoldingCtrl: boolean, bHoldingAlt: boolean): void; + BuffClicked(nEntity: EntityIndex, nBuffSerial: number, bAlert: boolean): void; /** @@ -1116,6 +1150,11 @@ interface CScriptBindingPR_Entities { * Get the item contained in this physical item container. */ GetContainedItem(nEntityIndex: EntityIndex): ItemEntityIndex; + + /** + * Set the minimap icon on this client. + */ + SetMinimapIcon(nEntityIndex: number, pszMinimapIcon: string): void; } interface CScriptBindingPR_Abilities { @@ -1287,6 +1326,9 @@ interface CScriptBindingPR_Abilities { * Returns the keybind (as a string) for the specified ability. */ GetKeybind(nAbilityEntIndex: AbilityEntityIndex): string; + + /** Get the max ability charge count. */ + GetMaxAbilityCharges(nAbilityEntIndex: number): number; } interface CScriptBindingPR_Items { @@ -1697,6 +1739,54 @@ interface CScriptBindingPR_Game { * Registers a keybind that can be listened to with Game.AddCommand */ CreateCustomKeyBind(keyName: string, commandName: string): void; + + NemesticeGetGameplayTipNumber(): number; + + NemesticeSetGameplayTipNumber(nGameplayTipNumber: number): void; + + NemesticeShouldShowGameInfo(): boolean; + + NemesticeSetShowGameInfo(bShowGameInfo: boolean): void; + + Winter2022ShouldShowGameInfo(): boolean; + + Winter2022SetShowGameInfo(bShowGameInfo: boolean): void; + + Winter2022GetGameplayTipNumber(): number; + + Winter2022SetGameplayTipNumber(nGameplayTipNumber: number): void; + + ForceCustomUILoad(): void; + + CutToDefaultCamera(): void; + + PlayDataDrivenCamera(pszCameraName: string): number; + + SetJoyFocusPanel(...pPanelArg: unknown[]): void; + + PushJoyFocusPanel(...pPanelArg: unknown[]): void; + + PopJoyFocusPanel(): void; + + /** + *Whether the local player has muted voice chat for the specified player id + */ + IsPlayerMutedVoice(nPlayerID: number): boolean; + + /** + * Set whether the local player has muted voice chat for the specified player id + */ + SetPlayerMutedVoice(nPlayerID: number, bMutedVoice: boolean): void; + + /** + * Whether the local player has muted text chat for the specified player id + */ + IsPlayerMutedText(nPlayerID: number): boolean; + + /** + * Set whether the local player has muted text chat for the specified player id + */ + SetPlayerMutedText(nPlayerID: number, bMutedText: boolean): void; } interface CPanoramaScript_SteamUGC { @@ -1921,6 +2011,11 @@ interface DollarStatic { * Convert a string to HTML-safe */ HTMLEscape(string: string): string; + + /** + * Return true if a file exists. Path will usually start with 'file://{images}' + */ + BImageFileExists(path: string): void; } interface AsyncWebRequestResponse { From b79b13b7f809c2352dcbdf830ff86c2f724e4401 Mon Sep 17 00:00:00 2001 From: "Xavier(Home)" Date: Tue, 15 Apr 2025 15:08:44 +0800 Subject: [PATCH 5/9] fixed a return type error --- packages/panorama-types/types/api.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/panorama-types/types/api.d.ts b/packages/panorama-types/types/api.d.ts index 52b315d..8a4761e 100644 --- a/packages/panorama-types/types/api.d.ts +++ b/packages/panorama-types/types/api.d.ts @@ -2015,7 +2015,7 @@ interface DollarStatic { /** * Return true if a file exists. Path will usually start with 'file://{images}' */ - BImageFileExists(path: string): void; + BImageFileExists(path: string): boolean; } interface AsyncWebRequestResponse { From 1e944afa2e95acd8cdc947488cc546894ca2134c Mon Sep 17 00:00:00 2001 From: XavierCHN Date: Sat, 19 Apr 2025 16:11:17 +0800 Subject: [PATCH 6/9] Update api.d.ts --- packages/panorama-types/types/api.d.ts | 34 +++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/packages/panorama-types/types/api.d.ts b/packages/panorama-types/types/api.d.ts index 8a4761e..9367fcd 100644 --- a/packages/panorama-types/types/api.d.ts +++ b/packages/panorama-types/types/api.d.ts @@ -140,6 +140,23 @@ interface ScreenEntity { accurateCollision: boolean; } +interface ContextualTip { + TipAnnotation?: string; + DisplayDuration?: number; + PanoramaClasses?: string[]; + PanoramaSnippet?: string; + ReferencedAbilities?: string[]; + ReferencedUnits: string[]; + Variant?: number; + ForceAnnotation?: boolean; + IntParameter?: number; + IntParameter2?: number; + FloatParameter?: number; + FloatParameter2?: number; + StringParameter?: string; + StringParameter2?: string; +} + interface CDOTA_PanoramaScript_GameUI { /** * Control whether the default UI is enabled @@ -359,12 +376,15 @@ interface CDOTA_PanoramaScript_GameUI { */ TipPlayer(iPlayerID: number): void; - DisplayCustomContextualTip(...args: unknown[]): void; + /** + * Display a custom contextual tip (wizard tip) with specific loc string and duration + */ + DisplayCustomContextualTip(tip: ContextualTip): void; /** * Set the text of a passed label for a DOTA Talent using ability values. */ - SetupDOTATalentNameLabel(...args: unknown[]): void; + SetupDOTATalentNameLabel(panel: LabelPanel, sAbilityName: string): void; /** * Returns true if the passed ability is a talent. @@ -750,8 +770,14 @@ interface CScriptBindingPR_Players { */ IsSpectator(iPlayerID: PlayerID): boolean; + /** + * Player portrait click event. + */ PlayerPortraitClicked(nClickedPlayerID: PlayerID, bHoldingCtrl: boolean, bHoldingAlt: boolean): void; + /** + * Player portrait double click event. + */ PlayerPortraitDoubleClicked(nClickedPlayerID: PlayerID, bHoldingCtrl: boolean, bHoldingAlt: boolean): void; BuffClicked(nEntity: EntityIndex, nBuffSerial: number, bAlert: boolean): void; @@ -1762,9 +1788,9 @@ interface CScriptBindingPR_Game { PlayDataDrivenCamera(pszCameraName: string): number; - SetJoyFocusPanel(...pPanelArg: unknown[]): void; + SetJoyFocusPanel(pPanelArg?: Panel): void; - PushJoyFocusPanel(...pPanelArg: unknown[]): void; + PushJoyFocusPanel(pPanelArg?: Panel): void; PopJoyFocusPanel(): void; From f545e101b3021d0b37bc9606ce6e2b455ec66db6 Mon Sep 17 00:00:00 2001 From: "Xavier(Home)" Date: Fri, 25 Apr 2025 20:44:02 +0800 Subject: [PATCH 7/9] add support of panorama events --- packages/panorama-types/types/api.d.ts | 23 +- packages/panorama-types/types/common.d.ts | 1 + .../panorama-types/types/panorama-events.d.ts | 315 ++++++++++++++++++ test/panorama/panorama-events.ts | 36 ++ 4 files changed, 371 insertions(+), 4 deletions(-) create mode 100644 packages/panorama-types/types/panorama-events.d.ts create mode 100644 test/panorama/panorama-events.ts diff --git a/packages/panorama-types/types/api.d.ts b/packages/panorama-types/types/api.d.ts index 9367fcd..43080e3 100644 --- a/packages/panorama-types/types/api.d.ts +++ b/packages/panorama-types/types/api.d.ts @@ -29,6 +29,15 @@ declare namespace GameEvents { : InferCustomGameEventType; } +declare namespace PanoramaEvents { + type PanoramaEventName = keyof PanoramaEvent; + type InferPanoramaEventParams = T extends PanoramaEventName + ? PanoramaEvent[T] extends (...args: infer P) => void + ? P + : TUntyped + : TUntyped; +} + interface CDOTA_PanoramaScript_GameEvents { /** * Subscribe to a game event. @@ -1972,10 +1981,16 @@ interface DollarStatic { GetContextPanel(): Panel; Schedule(time: number, callback: () => void): ScheduleID; CancelScheduled(scheduledEvent: ScheduleID): void; - DispatchEvent(event: string, panelID?: string, ...args: any[]): void; - DispatchEvent(event: string, panel: PanelBase, ...args: any[]): void; - DispatchEventAsync(delay: number, event: string, panelID?: string, ...args: any[]): void; - DispatchEventAsync(delay: number, event: string, panel: PanelBase, ...args: any[]): void; + + DispatchEvent( + eventName: E extends PanoramaEvents.PanoramaEventName ? E : string, + ...args: PanoramaEvents.InferPanoramaEventParams + ): void; + DispatchEventAsync( + eventName: E extends PanoramaEvents.PanoramaEventName ? E : string, + ...args: PanoramaEvents.InferPanoramaEventParams + ): void; + Language(): string; /** * Localize a string. Optionally accepts Quantity, Precision, and Panel arguments. diff --git a/packages/panorama-types/types/common.d.ts b/packages/panorama-types/types/common.d.ts index 326c65f..1dc726f 100644 --- a/packages/panorama-types/types/common.d.ts +++ b/packages/panorama-types/types/common.d.ts @@ -2,6 +2,7 @@ /// /// /// +/// /// type EntityIndex = number & { _entityIndex: never }; diff --git a/packages/panorama-types/types/panorama-events.d.ts b/packages/panorama-types/types/panorama-events.d.ts new file mode 100644 index 0000000..3f0c006 --- /dev/null +++ b/packages/panorama-types/types/panorama-events.d.ts @@ -0,0 +1,315 @@ +/** + * Events provided by Valve's document: https://developer.valvesoftware.com/wiki/Dota_2_Workshop_Tools/Panorama/Events + */ +declare interface PanoramaEvent { + /** Add a CSS class to a panel. */ + AddStyle(panel: PanelBase, className: string): void; + + /** Add a CSS class to a panel after a specified delay. */ + AddStyleAfterDelay(panel: PanelBase, className: string, preDelay: number): void; + + /** Add a CSS class to all children of this panel. */ + AddStyleToEachChild(panel: PanelBase, className: string): void; + + /** Add a class for a specified duration, with optional pre-delay; clears existing timers when called with same class. */ + AddTimedStyle(panel: PanelBase, className: string, duration: number, preDelay: number): void; + + /** Fire another event after a delay (in seconds, the event is provided in string and parsed by javascript engine). */ + AsyncEvent(delay: number, event: string): void; + + /** Tip to display, panel to attach to (default 'DefaultTipAttachment') */ + DOTADisplayDashboardTip(str: string, panelName?: string): void; + + /** Hide the ability tooltip */ + DOTAHideAbilityTooltip(panel?: PanelBase): void; + + /** Hide the buff tooltip */ + DOTAHideBuffTooltip(panel?: PanelBase): void; + + /** Hide the dropped item tooltip */ + DOTAHideDroppedItemTooltip(panel?: PanelBase): void; + + /** Hide the econ item tooltip. */ + DOTAHideEconItemTooltip(panel?: PanelBase): void; + + /** Hide the profile card / battle cup tooltip. */ + DOTAHideProfileCardBattleCupTooltip(panel?: PanelBase): void; + + /** Hide the profile card tooltip. */ + DOTAHideProfileCardTooltip(panel: PanelBase): void; + + /** Hide the rank tier tooltip. */ + DOTAHideRankTierTooltip(panel?: PanelBase): void; + + /** Hide the rune tooltip. */ + DOTAHideRuneTooltip(panel?: PanelBase): void; + + /** Hide the text tooltip. */ + DOTAHideTextTooltip(panel?: PanelBase): void; + + /** Hide the ti10 event game tooltip. */ + DOTAHideTI10EventGameTooltip(panel?: PanelBase): void; + + /** Hide the title image text tooltip. */ + DOTAHideTitleImageTextTooltip(panel?: PanelBase): void; + + /** Hide the title text tooltip. */ + DOTAHideTitleTextTooltip(panel?: PanelBase): void; + + /** Show tooltip for an item in the entityIndex NPC's inventory. */ + DOTAShowAbilityInventoryItemTooltip(panel: PanelBase, entityIndex: EntityIndex, inventorySlot: number): void; + + /** Show tooltip for an item in the entityIndex NPC's shop. */ + DOTAShowAbilityShopItemTooltip( + panel: PanelBase, + abilityName: string, + guideName: string, + entityIndex: EntityIndex, + ): void; + + /** Show an ability tooltip. */ + DOTAShowAbilityTooltip(panel: PanelBase, abilityName: string): void; + + /** Show an ability tooltip. Level information comes from the entity specified by the entityIndex. */ + DOTAShowAbilityTooltipForEntityIndex(panel: PanelBase, abilityName: string, entityIndex: EntityIndex): void; + + /** Show an ability tooltip annotated with a particular guide's info. */ + DOTAShowAbilityTooltipForGuide(panel: PanelBase, abilityName: string, guideName: string): void; + + /** Show an ability tooltip for the specified hero. */ + DOTAShowAbilityTooltipForHero(panel: PanelBase, abilityName: string, heroid: EntityIndex, bOnEnemy: boolean): void; + + /** Show an ability tooltip for a specific level. */ + DOTAShowAbilityTooltipForLevel(panel: PanelBase, abilityName: string, level: number): void; + + /** Show a buff tooltip for the specified entityIndex + buff serial. */ + DOTAShowBuffTooltip(panel: PanelBase, entityIndex: EntityIndex, buffSerial: BuffID, bOnEnemy: boolean): void; + + /** Show the econ item tooltip for a given item, style, and hero. Use 0 for the default style, and -1 for the default hero. */ + DOTAShowEconItemTooltip(panel: PanelBase, itemDef: string, styleIndex: number, heroID: number): void; + + /** Show the battle cup portion of the user's profile card, if it exists */ + DOTAShowProfileCardBattleCupTooltip(panel: PanelBase, steamID: number): void; + + /** Show a user's profile card. Use pro name determines whether to use their professional team name if applicable. */ + DOTAShowProfileCardTooltip(panel: PanelBase, steamID: number, useProName: boolean): void; + + /** Show the rank tier tooltip for a user */ + DOTAShowRankTierTooltip(panel: PanelBase, steamID: number): void; + + /** Show a rune tooltip in the X Y location for the rune type */ + DOTAShowRuneTooltip(panel: PanelBase, X: number, Y: number, RuneType: number): void; + + /** Show a tooltip with the given text. */ + DOTAShowTextTooltip(panel: PanelBase, text: string): void; + + /** Show a tooltip with the given text. Also apply a CSS class named "style" to allow custom styling. */ + DOTAShowTextTooltipStyled(panel: PanelBase, text: string, style: string): void; + + /** Show a tooltip with the given title, image, and text. */ + DOTAShowTitleImageTextTooltip(panel: PanelBase, title: string, imagePath: string, text: string): void; + + /** Show a tooltip with the given title, image, and text. Also apply a CSS class named "style" to allow custom styling. */ + DOTAShowTitleImageTextTooltipStyled( + panel: PanelBase, + title: string, + imagePath: string, + text: string, + style: string, + ): void; + + /** Show a tooltip with the given title and text. */ + DOTAShowTitleTextTooltip(panel: PanelBase, title: string, text: string): void; + + /** Show a tooltip with the given title and text. Also apply a CSS class named "style" to allow custom styling. */ + DOTAShowTitleTextTooltipStyled(panel: PanelBase, title: string, text: string, style: string): void; + + /** Drop focus entirely from the window containing this panel. */ + DropInputFocus(panel?: PanelBase): void; + + /** Fire another event if this panel has a given class. */ + IfHasClassEvent(panel: PanelBase, className: string, event: string): void; + + /** Fire another event if this panel is hovered over. */ + IfHoverOtherEvent(panel: PanelBase, otherPanelID: string, event: string): void; + + /** Fire another event if this panel does not have a given class. */ + IfNotHasClassEvent(panel: PanelBase, className: string, event: string): void; + + /** Fire another event if this panel is not hovered over. */ + IfNotHoverOtherEvent(panel: PanelBase, otherPanelID: string, event: string): void; + + /** Move down from the panel. By default, this will change the focus position, but other panel types may implement this differently. */ + MovePanelDown(panel: PanelBase, repeatCount: number): void; + + /** Move left from the panel. By default, this will change the focus position, but other panel types may implement this differently. */ + MovePanelLeft(panel: PanelBase, repeatCount: number): void; + + /** Move right from the panel. By default, this will change the focus position, but other panel types may implement this differently. */ + MovePanelRight(panel: PanelBase, repeatCount: number): void; + + /** Move up from the panel. By default, this will change the focus position, but other panel types may implement this differently. */ + MovePanelUp(panel: PanelBase, repeatCount: number): void; + + /** Scroll the panel down by one page. */ + PageDown(): void; + + /** Scroll the panel left by one page. */ + PageLeft(): void; + + /** Scroll the panel right by one page. */ + PageRight(): void; + + /** Scroll the panel up by one page. */ + PageUp(): void; + + /** Scroll the panel down by one page. */ + PagePanelDown(panel: PanelBase): void; + + /** Scroll the panel left by one page. */ + PagePanelLeft(panel: PanelBase): void; + + /** Scroll the panel right by one page. */ + PagePanelRight(panel: PanelBase): void; + + /** Scroll the panel up by one page. */ + PagePanelUp(panel: PanelBase): void; + + /** Remove a CSS class from a panel. */ + RemoveStyle(panel: PanelBase, className: string): void; + + /** Remove a CSS class from a panel after a specified delay. */ + RemoveStyleAfterDelay(panel: PanelBase, className: string, preDelay: number): void; + + /** Remove a CSS class from all children of this panel. */ + RemoveStyleFromEachChild(panel: PanelBase, className: string): void; + + /** Scroll the panel down by one line. */ + ScrollDown(): void; + + /** Scroll the panel left by one line. */ + ScrollLeft(): void; + + /** Scroll the panel right by one line. */ + ScrollRight(): void; + + /** Scroll the panel up by one line. */ + ScrollUp(): void; + + /** Scroll the panel down by one line. */ + ScrollPanelDown(panel: PanelBase): void; + + /** Scroll the panel left by one line. */ + ScrollPanelLeft(panel: PanelBase): void; + + /** Scroll the panel right by one line. */ + ScrollPanelRight(panel: PanelBase): void; + + /** Scroll the panel up by one line. */ + ScrollPanelUp(panel: PanelBase): void; + + /** Scroll this panel to the bottom. */ + ScrollToBottom(): void; + + /** Scroll this panel to the top. */ + ScrollToTop(): void; + + /** Set whether any child panels are :selected. */ + SetChildPanelsSelected(panel: PanelBase, selected: boolean): void; + + /** Set focus to this panel. */ + SetInputFocus(panel: PanelBase): void; + + /** Sets whether the given panel is enabled */ + SetPanelEnabled(panel: PanelBase, enabled: boolean): void; + + /** Set whether this panel is :selected. */ + SetPanelSelected(panel: PanelBase, selected: boolean): void; + + /** Switch which class the panel has for a given attribute slot. Allows easily changing between multiple states. */ + SwitchStyle(panel: PanelBase, slot: string, className: string): void; + + /** Toggle whether this panel is :selected. */ + TogglePanelSelected(panel: PanelBase): void; + + /** Toggle whether a panel has the given CSS class. */ + ToggleStyle(panel: PanelBase, className: string): void; + + /** Remove then immediately add back a CSS class from a panel. Useful to re-trigger events like animations or sound effects. */ + TriggerStyle(panel: PanelBase, className: string): void; +} + +/** + * Dota Panorama Events collect in DotA2 xml files + */ +declare interface PanoramaEvent { + DOTAScenePanelSceneLoaded(panel: PanelBase): void; + DOTAScenePanelSceneUnloaded(panel: PanelBase): void; + DOTAScenePanelCameraLerpFinished(panel: PanelBase): void; + DOTAScenePanelSetRotationSpeed(panel: PanelBase, speed: number): void; + DOTASceneFireEntityInput( + panel: PanelBase, + entityName: string, + eventName: string, + eventParam: string | number, + ): void; + DOTAScenePanelSimulateWorld(panel: PanelBase, num: number): void; + DOTAScenePanelEntityClicked(panel: PanelBase, entityName: string): void; + DOTAScenePanelEntityMouseOver(panel: PanelBase, entityName: string): void; + DOTAScenePanelEntityMouseOut(panel: PanelBase, entityName: string): void; + DOTASceneSetCameraEntity(entityName: string, delay: number): void; + DOTAScenePanelResetRotation(): void; + DOTAGlobalSceneFireEntityInput(entityName: string, eventName: string, eventParam: string | number): void; + DOTAGlobalSceneSetCameraEntity(sceneId: string, entityName: string, delay: number): void; + DOTAGlobalSceneSetRootEntity(sceneId: string, entityName: string): void; + DOTAScenePanelDumpState(): void; + DOTAShowReferencePage(xmlPath: string): void; + DOTAShowReferencePageStyled(xmlPath: string, styleClass: string): void; + DOTAHUDShopOpened(shopType: DOTA_SHOP_TYPE, opened: boolean): void; + DOTAHUDToggleScoreboard(): void; + DOTAHUDShowScoreboard(): void; + DOTAHUDHideScoreboard(): void; +} + +/** + * UNDOCUMENTED BUT USEFUL EVENTS + */ +declare interface PanoramaEvent { + /** Dismiss all context menus */ + DismissAllContextMenus(): void; + + /** Built in browser goto the provided url. (will return to the dashboard) */ + BrowserGoToURL(url: string): void; + + /** Open your default browser and goto url. */ + ExternalBrowserGoToURL(url: string): void; + + /** Show custom layout parameters tooltip, layout is the xml file, the parameters are contacted with & symbol. */ + UIShowCustomLayoutParametersTooltip(panel: PanelBase, toolipId: string, xmlFile: string, parameters: string): void; + + /** Hide custom layout parameters tooltip. */ + UIHideCustomLayoutParametersTooltip(panel: PanelBase, toolipId: string): void; + + /** Show custom layout tooltip, layout is the xml file. */ + UIShowCustomLayoutTooltip(panel: PanelBase, toolipId: string, xmlFile: string): void; + + /** Hide custom layout tooltip */ + UIHideCustomLayoutTooltip(panel: PanelBase, toolipId: string): void; + + UIShowCustomLayoutPopup(id: string, xmlPath: string): void; + + /** Click the disconnect icon */ + DOTAHUDGameDisconnect(): void; + + /** Show the match details screen for the provided match id. */ + DOTAShowMatchDetails(matchId: number): void; + + /** Play a sound effect. */ + PlaySoundEffect(sound: string): void; + + /** Popup button is clicked */ + UIPopupButtonClicked(panel: PanelBase): void; + + /** Fire a game event clientside? */ + FireCustomGameEvent_Str(eventName: string, data: string | number): void; +} diff --git a/test/panorama/panorama-events.ts b/test/panorama/panorama-events.ts new file mode 100644 index 0000000..1ae5433 --- /dev/null +++ b/test/panorama/panorama-events.ts @@ -0,0 +1,36 @@ +/** + * The following code segments require correct parameters to be provided, + * as they are frequently used and the parameters are already predefined in panorama-events.d.ts. + */ +$.DispatchEvent('BrowserGoToURL', 'test'); +$.DispatchEvent('AddStyle', $('#test'), 'test_class'); +$.DispatchEvent('DOTAGlobalSceneSetCameraEntity', 'ModelBackground', 'dashboard_cam', 4); +$.DispatchEvent('PlaySoundEffect', 'playercard.card_to_dust'); + +// @ts-expect-error +$.DispatchEvent('AddStyle', $('#test')); +// @ts-expect-error +$.DispatchEvent('PlaySoundEffect', $.GetContextPanel(), 'playercard.card_to_dust'); + +/** + * The following code are syntactically legal + * since certain parameters may not be covered by standard validations + * programmers must explicitly validate parameter correctness themselves. + */ +$.DispatchEvent('DOTASetCurrentDashboardPageFullscreen', true); +$.DispatchEvent('UnknownEvent', 'test'); + +// users can define their own events and parameters. +declare global { + interface PanoramaEvent { + TestCustomEvent(panel: PanelBase, text: string): void; + } +} + +$.DispatchEvent('TestCustomEvent', $('#test'), 'some string'); +// @ts-expect-error +$.DispatchEvent('TestCustomEvent', $('#test'), 2); +// @ts-expect-error +$.DispatchEvent('TestCustomEvent', $('#test'), 2); + +export {}; From 98fa1660fe20b32f2dd3773842a112b37c411d0e Mon Sep 17 00:00:00 2001 From: "Xavier(Home)" Date: Fri, 25 Apr 2025 21:39:22 +0800 Subject: [PATCH 8/9] more apis and more tests --- packages/panorama-types/types/api.d.ts | 2 +- .../panorama-types/types/panorama-events.d.ts | 153 +++++++++++------- test/panorama/panorama-events.ts | 5 +- 3 files changed, 98 insertions(+), 62 deletions(-) diff --git a/packages/panorama-types/types/api.d.ts b/packages/panorama-types/types/api.d.ts index 43080e3..8ba1142 100644 --- a/packages/panorama-types/types/api.d.ts +++ b/packages/panorama-types/types/api.d.ts @@ -33,7 +33,7 @@ declare namespace PanoramaEvents { type PanoramaEventName = keyof PanoramaEvent; type InferPanoramaEventParams = T extends PanoramaEventName ? PanoramaEvent[T] extends (...args: infer P) => void - ? P + ? P | [PanelBase, ...P] : TUntyped : TUntyped; } diff --git a/packages/panorama-types/types/panorama-events.d.ts b/packages/panorama-types/types/panorama-events.d.ts index 3f0c006..67a1d3b 100644 --- a/packages/panorama-types/types/panorama-events.d.ts +++ b/packages/panorama-types/types/panorama-events.d.ts @@ -3,16 +3,16 @@ */ declare interface PanoramaEvent { /** Add a CSS class to a panel. */ - AddStyle(panel: PanelBase, className: string): void; + AddStyle(className: string): void; /** Add a CSS class to a panel after a specified delay. */ - AddStyleAfterDelay(panel: PanelBase, className: string, preDelay: number): void; + AddStyleAfterDelay(className: string, preDelay: number): void; /** Add a CSS class to all children of this panel. */ - AddStyleToEachChild(panel: PanelBase, className: string): void; + AddStyleToEachChild(className: string): void; /** Add a class for a specified duration, with optional pre-delay; clears existing timers when called with same class. */ - AddTimedStyle(panel: PanelBase, className: string, duration: number, preDelay: number): void; + AddTimedStyle(className: string, duration: number, preDelay: number): void; /** Fire another event after a delay (in seconds, the event is provided in string and parsed by javascript engine). */ AsyncEvent(delay: number, event: string): void; @@ -21,43 +21,43 @@ declare interface PanoramaEvent { DOTADisplayDashboardTip(str: string, panelName?: string): void; /** Hide the ability tooltip */ - DOTAHideAbilityTooltip(panel?: PanelBase): void; + DOTAHideAbilityTooltip(): void; /** Hide the buff tooltip */ - DOTAHideBuffTooltip(panel?: PanelBase): void; + DOTAHideBuffTooltip(): void; /** Hide the dropped item tooltip */ - DOTAHideDroppedItemTooltip(panel?: PanelBase): void; + DOTAHideDroppedItemTooltip(): void; /** Hide the econ item tooltip. */ - DOTAHideEconItemTooltip(panel?: PanelBase): void; + DOTAHideEconItemTooltip(): void; /** Hide the profile card / battle cup tooltip. */ - DOTAHideProfileCardBattleCupTooltip(panel?: PanelBase): void; + DOTAHideProfileCardBattleCupTooltip(): void; /** Hide the profile card tooltip. */ DOTAHideProfileCardTooltip(panel: PanelBase): void; /** Hide the rank tier tooltip. */ - DOTAHideRankTierTooltip(panel?: PanelBase): void; + DOTAHideRankTierTooltip(): void; /** Hide the rune tooltip. */ - DOTAHideRuneTooltip(panel?: PanelBase): void; + DOTAHideRuneTooltip(): void; /** Hide the text tooltip. */ - DOTAHideTextTooltip(panel?: PanelBase): void; + DOTAHideTextTooltip(): void; /** Hide the ti10 event game tooltip. */ - DOTAHideTI10EventGameTooltip(panel?: PanelBase): void; + DOTAHideTI10EventGameTooltip(): void; /** Hide the title image text tooltip. */ - DOTAHideTitleImageTextTooltip(panel?: PanelBase): void; + DOTAHideTitleImageTextTooltip(): void; /** Hide the title text tooltip. */ - DOTAHideTitleTextTooltip(panel?: PanelBase): void; + DOTAHideTitleTextTooltip(): void; /** Show tooltip for an item in the entityIndex NPC's inventory. */ - DOTAShowAbilityInventoryItemTooltip(panel: PanelBase, entityIndex: EntityIndex, inventorySlot: number): void; + DOTAShowAbilityInventoryItemTooltip(entityIndex: EntityIndex, inventorySlot: number): void; /** Show tooltip for an item in the entityIndex NPC's shop. */ DOTAShowAbilityShopItemTooltip( @@ -68,46 +68,46 @@ declare interface PanoramaEvent { ): void; /** Show an ability tooltip. */ - DOTAShowAbilityTooltip(panel: PanelBase, abilityName: string): void; + DOTAShowAbilityTooltip(abilityName: string): void; /** Show an ability tooltip. Level information comes from the entity specified by the entityIndex. */ - DOTAShowAbilityTooltipForEntityIndex(panel: PanelBase, abilityName: string, entityIndex: EntityIndex): void; + DOTAShowAbilityTooltipForEntityIndex(abilityName: string, entityIndex: EntityIndex): void; /** Show an ability tooltip annotated with a particular guide's info. */ - DOTAShowAbilityTooltipForGuide(panel: PanelBase, abilityName: string, guideName: string): void; + DOTAShowAbilityTooltipForGuide(abilityName: string, guideName: string): void; /** Show an ability tooltip for the specified hero. */ - DOTAShowAbilityTooltipForHero(panel: PanelBase, abilityName: string, heroid: EntityIndex, bOnEnemy: boolean): void; + DOTAShowAbilityTooltipForHero(abilityName: string, heroid: EntityIndex, bOnEnemy: boolean): void; /** Show an ability tooltip for a specific level. */ - DOTAShowAbilityTooltipForLevel(panel: PanelBase, abilityName: string, level: number): void; + DOTAShowAbilityTooltipForLevel(abilityName: string, level: number): void; /** Show a buff tooltip for the specified entityIndex + buff serial. */ - DOTAShowBuffTooltip(panel: PanelBase, entityIndex: EntityIndex, buffSerial: BuffID, bOnEnemy: boolean): void; + DOTAShowBuffTooltip(entityIndex: EntityIndex, buffSerial: BuffID, bOnEnemy: boolean): void; /** Show the econ item tooltip for a given item, style, and hero. Use 0 for the default style, and -1 for the default hero. */ - DOTAShowEconItemTooltip(panel: PanelBase, itemDef: string, styleIndex: number, heroID: number): void; + DOTAShowEconItemTooltip(itemDef: string, styleIndex: number, heroID: number): void; /** Show the battle cup portion of the user's profile card, if it exists */ - DOTAShowProfileCardBattleCupTooltip(panel: PanelBase, steamID: number): void; + DOTAShowProfileCardBattleCupTooltip(steamID: number): void; /** Show a user's profile card. Use pro name determines whether to use their professional team name if applicable. */ - DOTAShowProfileCardTooltip(panel: PanelBase, steamID: number, useProName: boolean): void; + DOTAShowProfileCardTooltip(steamID: number, useProName: boolean): void; /** Show the rank tier tooltip for a user */ - DOTAShowRankTierTooltip(panel: PanelBase, steamID: number): void; + DOTAShowRankTierTooltip(steamID: number): void; /** Show a rune tooltip in the X Y location for the rune type */ - DOTAShowRuneTooltip(panel: PanelBase, X: number, Y: number, RuneType: number): void; + DOTAShowRuneTooltip(X: number, Y: number, RuneType: number): void; /** Show a tooltip with the given text. */ - DOTAShowTextTooltip(panel: PanelBase, text: string): void; + DOTAShowTextTooltip(text: string): void; /** Show a tooltip with the given text. Also apply a CSS class named "style" to allow custom styling. */ - DOTAShowTextTooltipStyled(panel: PanelBase, text: string, style: string): void; + DOTAShowTextTooltipStyled(text: string, style: string): void; /** Show a tooltip with the given title, image, and text. */ - DOTAShowTitleImageTextTooltip(panel: PanelBase, title: string, imagePath: string, text: string): void; + DOTAShowTitleImageTextTooltip(title: string, imagePath: string, text: string): void; /** Show a tooltip with the given title, image, and text. Also apply a CSS class named "style" to allow custom styling. */ DOTAShowTitleImageTextTooltipStyled( @@ -119,37 +119,37 @@ declare interface PanoramaEvent { ): void; /** Show a tooltip with the given title and text. */ - DOTAShowTitleTextTooltip(panel: PanelBase, title: string, text: string): void; + DOTAShowTitleTextTooltip(title: string, text: string): void; /** Show a tooltip with the given title and text. Also apply a CSS class named "style" to allow custom styling. */ - DOTAShowTitleTextTooltipStyled(panel: PanelBase, title: string, text: string, style: string): void; + DOTAShowTitleTextTooltipStyled(title: string, text: string, style: string): void; /** Drop focus entirely from the window containing this panel. */ - DropInputFocus(panel?: PanelBase): void; + DropInputFocus(): void; /** Fire another event if this panel has a given class. */ - IfHasClassEvent(panel: PanelBase, className: string, event: string): void; + IfHasClassEvent(className: string, event: string): void; /** Fire another event if this panel is hovered over. */ - IfHoverOtherEvent(panel: PanelBase, otherPanelID: string, event: string): void; + IfHoverOtherEvent(otherPanelID: string, event: string): void; /** Fire another event if this panel does not have a given class. */ - IfNotHasClassEvent(panel: PanelBase, className: string, event: string): void; + IfNotHasClassEvent(className: string, event: string): void; /** Fire another event if this panel is not hovered over. */ - IfNotHoverOtherEvent(panel: PanelBase, otherPanelID: string, event: string): void; + IfNotHoverOtherEvent(otherPanelID: string, event: string): void; /** Move down from the panel. By default, this will change the focus position, but other panel types may implement this differently. */ - MovePanelDown(panel: PanelBase, repeatCount: number): void; + MovePanelDown(repeatCount: number): void; /** Move left from the panel. By default, this will change the focus position, but other panel types may implement this differently. */ - MovePanelLeft(panel: PanelBase, repeatCount: number): void; + MovePanelLeft(repeatCount: number): void; /** Move right from the panel. By default, this will change the focus position, but other panel types may implement this differently. */ - MovePanelRight(panel: PanelBase, repeatCount: number): void; + MovePanelRight(repeatCount: number): void; /** Move up from the panel. By default, this will change the focus position, but other panel types may implement this differently. */ - MovePanelUp(panel: PanelBase, repeatCount: number): void; + MovePanelUp(repeatCount: number): void; /** Scroll the panel down by one page. */ PageDown(): void; @@ -176,13 +176,13 @@ declare interface PanoramaEvent { PagePanelUp(panel: PanelBase): void; /** Remove a CSS class from a panel. */ - RemoveStyle(panel: PanelBase, className: string): void; + RemoveStyle(className: string): void; /** Remove a CSS class from a panel after a specified delay. */ - RemoveStyleAfterDelay(panel: PanelBase, className: string, preDelay: number): void; + RemoveStyleAfterDelay(className: string, preDelay: number): void; /** Remove a CSS class from all children of this panel. */ - RemoveStyleFromEachChild(panel: PanelBase, className: string): void; + RemoveStyleFromEachChild(className: string): void; /** Scroll the panel down by one line. */ ScrollDown(): void; @@ -215,28 +215,28 @@ declare interface PanoramaEvent { ScrollToTop(): void; /** Set whether any child panels are :selected. */ - SetChildPanelsSelected(panel: PanelBase, selected: boolean): void; + SetChildPanelsSelected(selected: boolean): void; /** Set focus to this panel. */ SetInputFocus(panel: PanelBase): void; /** Sets whether the given panel is enabled */ - SetPanelEnabled(panel: PanelBase, enabled: boolean): void; + SetPanelEnabled(enabled: boolean): void; /** Set whether this panel is :selected. */ - SetPanelSelected(panel: PanelBase, selected: boolean): void; + SetPanelSelected(selected: boolean): void; /** Switch which class the panel has for a given attribute slot. Allows easily changing between multiple states. */ - SwitchStyle(panel: PanelBase, slot: string, className: string): void; + SwitchStyle(slot: string, className: string): void; /** Toggle whether this panel is :selected. */ TogglePanelSelected(panel: PanelBase): void; /** Toggle whether a panel has the given CSS class. */ - ToggleStyle(panel: PanelBase, className: string): void; + ToggleStyle(className: string): void; /** Remove then immediately add back a CSS class from a panel. Useful to re-trigger events like animations or sound effects. */ - TriggerStyle(panel: PanelBase, className: string): void; + TriggerStyle(className: string): void; } /** @@ -246,17 +246,17 @@ declare interface PanoramaEvent { DOTAScenePanelSceneLoaded(panel: PanelBase): void; DOTAScenePanelSceneUnloaded(panel: PanelBase): void; DOTAScenePanelCameraLerpFinished(panel: PanelBase): void; - DOTAScenePanelSetRotationSpeed(panel: PanelBase, speed: number): void; + DOTAScenePanelSetRotationSpeed(speed: number): void; DOTASceneFireEntityInput( panel: PanelBase, entityName: string, eventName: string, eventParam: string | number, ): void; - DOTAScenePanelSimulateWorld(panel: PanelBase, num: number): void; - DOTAScenePanelEntityClicked(panel: PanelBase, entityName: string): void; - DOTAScenePanelEntityMouseOver(panel: PanelBase, entityName: string): void; - DOTAScenePanelEntityMouseOut(panel: PanelBase, entityName: string): void; + DOTAScenePanelSimulateWorld(num: number): void; + DOTAScenePanelEntityClicked(entityName: string): void; + DOTAScenePanelEntityMouseOver(entityName: string): void; + DOTAScenePanelEntityMouseOut(entityName: string): void; DOTASceneSetCameraEntity(entityName: string, delay: number): void; DOTAScenePanelResetRotation(): void; DOTAGlobalSceneFireEntityInput(entityName: string, eventName: string, eventParam: string | number): void; @@ -266,9 +266,12 @@ declare interface PanoramaEvent { DOTAShowReferencePage(xmlPath: string): void; DOTAShowReferencePageStyled(xmlPath: string, styleClass: string): void; DOTAHUDShopOpened(shopType: DOTA_SHOP_TYPE, opened: boolean): void; + DOTAHUDToggleShop(): void; + DOTAShopCancelSearch(): void; DOTAHUDToggleScoreboard(): void; DOTAHUDShowScoreboard(): void; DOTAHUDHideScoreboard(): void; + DOTAShowHomePage(): void; } /** @@ -285,19 +288,27 @@ declare interface PanoramaEvent { ExternalBrowserGoToURL(url: string): void; /** Show custom layout parameters tooltip, layout is the xml file, the parameters are contacted with & symbol. */ - UIShowCustomLayoutParametersTooltip(panel: PanelBase, toolipId: string, xmlFile: string, parameters: string): void; + UIShowCustomLayoutParametersTooltip(toolipId: string, xmlFile: string, parameters: string): void; /** Hide custom layout parameters tooltip. */ - UIHideCustomLayoutParametersTooltip(panel: PanelBase, toolipId: string): void; + UIHideCustomLayoutParametersTooltip(toolipId: string): void; /** Show custom layout tooltip, layout is the xml file. */ - UIShowCustomLayoutTooltip(panel: PanelBase, toolipId: string, xmlFile: string): void; + UIShowCustomLayoutTooltip(toolipId: string, xmlFile: string): void; /** Hide custom layout tooltip */ - UIHideCustomLayoutTooltip(panel: PanelBase, toolipId: string): void; + UIHideCustomLayoutTooltip(toolipId: string): void; + + UIHideCustomLayoutTooltip(toolipId: string): void; UIShowCustomLayoutPopup(id: string, xmlPath: string): void; + UIShowTextTooltip(text: string): void; + + UIShowTextTooltip(text: string): void; + + UIHideTextTooltip(): void; + /** Click the disconnect icon */ DOTAHUDGameDisconnect(): void; @@ -312,4 +323,28 @@ declare interface PanoramaEvent { /** Fire a game event clientside? */ FireCustomGameEvent_Str(eventName: string, data: string | number): void; + + /** display the damage armor tooltip */ + DOTAHUDShowDamageArmorTooltip(): void; + + /** hide the damage armor tooltip */ + DOTAHUDHideDamageArmorTooltip(): void; + + /** Show gold tooltip */ + DOTAHUDShowGoldTooltip(): void; + + /** Hide gold tooltip */ + DOTAHUDHideGoldTooltip(): void; + + /** Buff icon is clicked */ + DOTAHUDBuffClicked(): void; + + /** Go back to dashboard */ + DOTAHUDShowDashboard(): void; + + /** Show the settings popup panel */ + DOTAShowSettingsPopup(): void; + + /** Show the dropped item tooltip */ + DOTAShowDroppedItemTooltip(x: number, y: number, abilityName: string, playerId: PlayerID, unknown: boolean): void; } diff --git a/test/panorama/panorama-events.ts b/test/panorama/panorama-events.ts index 1ae5433..50fd2ef 100644 --- a/test/panorama/panorama-events.ts +++ b/test/panorama/panorama-events.ts @@ -6,11 +6,10 @@ $.DispatchEvent('BrowserGoToURL', 'test'); $.DispatchEvent('AddStyle', $('#test'), 'test_class'); $.DispatchEvent('DOTAGlobalSceneSetCameraEntity', 'ModelBackground', 'dashboard_cam', 4); $.DispatchEvent('PlaySoundEffect', 'playercard.card_to_dust'); +$.DispatchEvent('PlaySoundEffect', $.GetContextPanel(), 'playercard.card_to_dust'); // @ts-expect-error $.DispatchEvent('AddStyle', $('#test')); -// @ts-expect-error -$.DispatchEvent('PlaySoundEffect', $.GetContextPanel(), 'playercard.card_to_dust'); /** * The following code are syntactically legal @@ -32,5 +31,7 @@ $.DispatchEvent('TestCustomEvent', $('#test'), 'some string'); $.DispatchEvent('TestCustomEvent', $('#test'), 2); // @ts-expect-error $.DispatchEvent('TestCustomEvent', $('#test'), 2); +// @ts-expect-error +$.DispatchEvent('TestCustomEvent', $('#test'), 'string', 2); export {}; From 0c42ce6c2703ad0ecacc854a4b6a399e37913602 Mon Sep 17 00:00:00 2001 From: "Xavier(Home)" Date: Fri, 25 Apr 2025 21:55:48 +0800 Subject: [PATCH 9/9] add support of register event handler and drag events --- packages/panorama-types/types/api.d.ts | 25 +++++++++++-------- .../panorama-types/types/panorama-events.d.ts | 9 +++++++ test/panorama/panorama-events.ts | 16 ++++++++++++ 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/packages/panorama-types/types/api.d.ts b/packages/panorama-types/types/api.d.ts index 8ba1142..f13a82b 100644 --- a/packages/panorama-types/types/api.d.ts +++ b/packages/panorama-types/types/api.d.ts @@ -36,6 +36,11 @@ declare namespace PanoramaEvents { ? P | [PanelBase, ...P] : TUntyped : TUntyped; + type InferPanoramaCallback = T extends PanoramaEventName + ? PanoramaEvent[T] extends (...args: infer P) => void + ? (...args: P) => void + : (...args: any[]) => void + : (...args: any[]) => void; } interface CDOTA_PanoramaScript_GameEvents { @@ -2001,18 +2006,16 @@ interface DollarStatic { * @deprecated */ LocalizePlural(token: string, value: number, parent?: PanelBase): string; - RegisterEventHandler( - event: 'DragStart', - parent: PanelBase, - handler: (panelID: string, settings: DragSettings) => boolean, - ): void; - RegisterEventHandler( - event: 'DragEnd' | 'DragDrop' | 'DragEnter' | 'DragLeave', - parent: PanelBase, - handler: (panelID: string, dragged: Panel) => boolean, + + RegisterEventHandler( + eventName: E extends PanoramaEvents.PanoramaEventName ? E : string, + panel: PanelBase | string, + callback: PanoramaEvents.InferPanoramaCallback, ): void; - RegisterEventHandler(event: string, parent: PanelBase, handler: (...args: any[]) => void): void; - RegisterForUnhandledEvent(event: string, handler: (...args: any[]) => void): UnhandledEventListenerID; + RegisterForUnhandledEvent( + eventName: E extends PanoramaEvents.PanoramaEventName ? E : string, + callback: PanoramaEvents.InferPanoramaCallback, + ): UnhandledEventListenerID; UnregisterForUnhandledEvent(event: string, handle: UnhandledEventListenerID): void; Each(list: T[], callback: (item: T, index: number) => void): void; Each(map: { [key: string]: T }, callback: (value: T, key: string) => void): void; diff --git a/packages/panorama-types/types/panorama-events.d.ts b/packages/panorama-types/types/panorama-events.d.ts index 67a1d3b..ea936ff 100644 --- a/packages/panorama-types/types/panorama-events.d.ts +++ b/packages/panorama-types/types/panorama-events.d.ts @@ -347,4 +347,13 @@ declare interface PanoramaEvent { /** Show the dropped item tooltip */ DOTAShowDroppedItemTooltip(x: number, y: number, abilityName: string, playerId: PlayerID, unknown: boolean): void; + + /** + * Drag events + */ + DragStart(panel: PanelBase, settings: DragSettings): void; + DragEnter(panel: PanelBase, displayPanel: PanelBase): void; + DragLeave(panel: PanelBase, displayPanel: PanelBase): void; + DragDrop(panel: PanelBase, displayPanel: PanelBase): void; + DragEnd(panel: PanelBase, displayPanel: PanelBase): void; } diff --git a/test/panorama/panorama-events.ts b/test/panorama/panorama-events.ts index 50fd2ef..67fc177 100644 --- a/test/panorama/panorama-events.ts +++ b/test/panorama/panorama-events.ts @@ -10,6 +10,8 @@ $.DispatchEvent('PlaySoundEffect', $.GetContextPanel(), 'playercard.card_to_dust // @ts-expect-error $.DispatchEvent('AddStyle', $('#test')); +// @ts-expect-error +$.DispatchEvent('DOTAGlobalSceneSetCameraEntity', 'ModelBackground', 'dashboard_cam', '4'); /** * The following code are syntactically legal @@ -19,6 +21,20 @@ $.DispatchEvent('AddStyle', $('#test')); $.DispatchEvent('DOTASetCurrentDashboardPageFullscreen', true); $.DispatchEvent('UnknownEvent', 'test'); +/** + * Test of register event handlers + */ +$.RegisterEventHandler('DragStart', $('#test'), (panelId, settings) => {}); +$.RegisterEventHandler('DragStart', $('#test'), () => {}); +// @ts-expect-error +$.RegisterEventHandler('DragStart', $('#test'), (panelId, settings, badParam) => {}); + +$.RegisterEventHandler('UnknownEvent', $('#test'), () => {}); + +$.RegisterForUnhandledEvent('DOTAHUDBuffClicked', () => {}); +// @ts-expect-error +$.RegisterForUnhandledEvent('DOTAHUDBuffClicked', (panel) => {}); + // users can define their own events and parameters. declare global { interface PanoramaEvent {