Notification

BannerGames edited this page Aug 13, 2018 · 11 revisions

The Notification object is the central way to define what is shown in a popup-message (or in the side-bar) in game.

Creating the object

new Notification(header, text, buttonText, weeksUntilFired) or new Notification({}) where {} object defines properties as listed below.

Since version 1.6 you can also use new Notification(header, text, {}), or new Notification(header, text, buttonText, {}) or new Notification(header, text, butttonText, weeksUntilFired, {}) to provide additional properties when convenient.

Properties

property (bold means mandatory) description
header the header/caption text for the message.
text the text for the Notification (can include {n} to define multiple screens at once - see advanced uses below).
buttonText (default: OK) the button text or texts for the message.
weeksUntilFired (default: 0) the delay in weeks (float) when the notification should actually be displayed.
image the image or images shown to the left of the notification window (image needs to be 200x200)
options array of button texts to give multi-choice options (between 2 and 3)
sourceId required when using options - the id of the event that should be notified when an option is selected. If this is not specified or a match is not found options won't do anything.
type (default: 'Default') New in v.1.6 - can be any of these:

NotificationType.Default (default)
NotificationType.PlatformNews,
NotificationType.IndustryNews,
NotificationType.NewResearchAvailable,
NotificationType.CompanyMilestones,
NotificationType.SalesReports,
NotificationType.GameReports,
NotificationType.Events,
NotificationType.AutoPopup,
NotificationType.Others

Setting the type of a notification will affect whether the notification will auto-open or appear in the sidebar according to the players 'Messages' settings.
If left to the Default setting, the game will try to infer the type from the content. Notifications with options are automatically classified as Events. If no type can be inferred, the notifications will appear as 'Others'.

If set to AutoPopup the notification will always automatically open when spawned. The player cannot override this behaviour.
previewImage New in v.1.6 - If the notification type is set to be shown in the sidebar, then this optional preview image will be shown alongside it. Should be 130x130 pixels. If it is not set, it will try to fallback to the image property. If that's not set, it will try to infer a standard icon from the notification type, otherwise a generic 'info' icon is shown.

Methods

The Notification object also defines utility methods which can be used to define what should happen after a notification is displayed.

method description
adjustCash function({amount:value, label:label}) - adjusts the cash of the company and provides a label text which will show up in the animated cash log
adjustHype function({amount:value}) - adjusts the hype of the current game
adjustFans function({amount:value}) - adjusts the fans of the company
setFlag function({key:key, value:value}) - sets a custom flag on the company.flags collection. (accessible via GameManager.company.flags[key])

Note: Since v1.6 notifications can appear in a sidebar. If this is the case, any of the above methods will only be called at the time when the player opens the notification, not when it first appears in the sidebar. The methods will also be called when the notification times out or is dismissed via right-click.

Advanced Uses

Multiple Screens

Often, it's better to break up longer texts into multiple screens. Rather than specifying multiple Notifications you can do this by adding a {n} inside the text of a notification. {n} (n, stands for new) will cause the text to be split and the parts will be shown in different screens. Depending on how many {n} you use, you can also override the buttonText and the image for each Notification separately, simply by specifying an array of texts and images. If you use options then these will only show on the last screen of the notification.

Manually adding notifications

Usually you will want to add notifications via the GDT.AddEvent API but you can also add a Notification on its own to the game by directly adding it to the GameManager.company.notifications array.

Example

GameManager.company.notifications.push(new Notification("News".localize(), "My custom notification".localize()));

Note: GameManager.company is only available when a game is running/loaded. It will be undefined when loading your mod. If you want to add general-use events then use GDT.AddEvent() instead.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.