-
Notifications
You must be signed in to change notification settings - Fork 10
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
base: old-wiki
Are you sure you want to change the base?
Changes from 1 commit
32b5594
71bb4c3
2c42222
796c035
4c95912
c9a51ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
``` | ||
You can define your own global events within the ``scripts/util/event-definition.js`` file by calling the ``$.DefineEvent`` and ``$.DefinePanelEvent`` functions. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
$.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) |
There was a problem hiding this comment.
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 likeonmouseover
,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)