Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panorama Template & Event System #25

Open
wants to merge 6 commits into
base: old-wiki
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions docs/Panorama/event-system.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
layout: default
title: Event System
parent: Panorama
nav_order: 100
---

# Event System
Panorama uses an event system to communicate between the engine and panels but also between panels. They can be defined and subscribed to via Javascript.

## Defining Events
```
**TODO** What is the difference between these two functions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never actually used $.DefinePanelEvent but panel events are things like onmouseover, onactivate etc... No idea why you'd want define custom ones from JS tbh.

Worth distinguishing the two though. Regular events are basically like you say below. Panel events are subscribed to using panel.SetPanelEvent(event name, callback)

```
You can define your own global events within the ``scripts/util/event-definition.js`` file by calling the ``$.DefineEvent`` and ``$.DefinePanelEvent`` functions.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep panel events out of this, since they aren't really referenced anywhere else here and might just be confusing


### Example
```js
$.DefineEvent("LoadTutorialMap", 0); // Event "LoadTutorialMap" with no arguments
$.DefineEvent("LoadStoryMap", 1); // Event "LoadStoryMap" with one argument
```

## Subscribing to Events
Any panel can subscribe to an event by calling ``$.RegisterForUnhandledEvent`` or ``$.RegisterEventHandler`` within JavaScript. These functions will be called, when the event is fired. Some events may include additional parameters, which will be forwarded to your function.

#### $.RegisterForUnhandledEvent(``EVENT_NAME``, ``CALLBACK``)
This function can be used to subscribe to events.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notably, this will only get fired if none of the handlers registered with "RegisterEventHandler" returned true (or i guess a truthy value in a JS setting)


#### $.RegisterEventHandler(``EVENT_NAME``, ``CONTEXT``, ``CALLBACK``)
This function can be used to subscribe to events within a specific context. This context can be another panel or its own panel by calling ``$.GetContextPanel()``.

### Example
```js
class MainMenu {
static {
$.RegisterForUnhandledEvent("ChaosShowPauseMenu", this.onShowPauseMenu.bind(this));

// Custom Event with a parameter
$.DefineEvent("LoadMap", 1);
$.RegisterForUnhandledEvent("LoadMap", this.playMap.bind(this));
}

static onShowPauseMenu() {
// ...
}
static playMap(map) {
// [map] contains the parameters value
}
}
```

## Dispatching Events
Events can be dispached via JavaScript by calling ``$.DispatchEvent``.

### Example
```js
$.DispatchEvent("LoadTutorialMap"); // Event "LoadTutorialMap" with no arguments
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also pass as target panel as second parameter. Or if you use DispatchEventAsync, the second param is the delay, then optional target panel and then the rest

$.DispatchEvent("LoadStoryMap", "sp_a1_intro1"); // Event "LoadStoryMap" with one argument
```

## Global Events
Global events are events that are defined on an engine level. These events are usually prefixed by ``Chaos`` and are fired at various engine related events.

### Event Reference

| Event Name | Parameters | Description |
|----------------------------------|------------|-------------------------------------------------------------------|
| `ChaosShowMainMenu` | *None* | Shows the main menu. |
| `ChaosHideMainMenu` | *None* | Hides the main menu. |
| `ChaosShowPauseMenu` | *None* | Shows the pause menu. |
| `ChaosHidePauseMenu` | *None* | Hides the pause menu. |
| | | |
| `ChaosMainMenuPauseGame` | *None* | Pauses the game. |
| `ChaosMainMenuResumeGame` | *None* | Resumes the game if paused. |
| | | |
| `ChaosShowIntroMovie` | *None* | Display the intro movie. |
| `ChaosHideIntroMovie` | *None* | Hides the intro movie (Can also be used to skip the intro movie). |
| | | |
| `ChaosVideoSettingsInit` | *None* | Initialized video settings |
| `ChaosVideoSettingsResetDefault` | *None* | Resets the video settings to default |
| `ChaosApplyVideoSettings` | *None* | Applies the video settings |

## Further documentation
[Panorama/Events on Valve Developer Community](https://developer.valvesoftware.com/wiki/Dota_2_Workshop_Tools/Panorama/Events)