notification_util¶
Source: base/tealdef/game_mechanics/notifications/notification_util.d.tl
Notes
Helpers that read notification type resources and change or read the notifications game-script state.
NotificationUtil¶
record global base/tealdef/game_mechanics/notifications/notification_util.d.tl:3
global record NotificationUtil
Load: local notification_util = ug_require "::/game_mechanics/notifications/notification_util.tl"
Notes
Helpers for notification type resources and the notifications game-script state.
Details
Functions that take a NotificationsState change that table; the game script uses
them inside its own update and event handler. Scripts outside it should send the
Notifications events instead (see Notification).
Fields
| Name | Type | Description |
|---|---|---|
defaultAutoDismissDurationMs |
integer |
Default autoDismissDuration of a notification, 60000 ms of game time. used 19× in the base game |
Functions
getGuiTypeFromNotificationType(name : string) : NotificationGuiData.Type base/tealdef/game_mechanics/notifications/notification_util.d.tl:6
Call as notification_util.getGuiTypeFromNotificationType
Notes
Reads the GUI category of a notification type from its .res file.
| Parameter | Type | Description |
|---|---|---|
name |
string |
Notification type script, as in Notification.type. |
Returns NotificationGuiData.Type: The guiType of the resource, or "Unknown" if there is no such notification resource or it has no guiType.
Used in the base game: 11 times in 6 files
base/content/gui/gui/line_vehicle_mgmt/line_react_util.tl:71
base/content/gui/gui/statistics/statistics_react_util.tl:276
base/content/gui/gui/entity_window/entity_window_util.tl:2068
base/content/game_mechanics/game_mechanics/notifications/gui/notification_log.tl:33
base/content/game_mechanics/game_mechanics/notifications/gui/notification_popups.tl:64
base/content/game_mechanics/game_mechanics/notifications/types/notification_react_util.tl:129
getInitiallyIgnoredTypes() : {string : boolean} base/tealdef/game_mechanics/notifications/notification_util.d.tl:7
Call as notification_util.getInitiallyIgnoredTypes
Notes
Reads initiallyIgnoredType of all notification resources.
Returns {string : boolean}: Map from notification type script name to whether it is ignored in a new game.
getNotificationType2Label() : {string : string} base/tealdef/game_mechanics/notifications/notification_util.d.tl:8
Call as notification_util.getNotificationType2Label
Notes
Reads the labels of all notification resources, as shown in the log filter.
Returns {string : string}: Map from notification type script name to its label; types without a label are left out.
getAllNotificationGuiTypes() : {NotificationGuiData.Type} base/tealdef/game_mechanics/notifications/notification_util.d.tl:9
Call as notification_util.getAllNotificationGuiTypes
Notes
Collects the GUI categories used by all notification resources.
Returns {NotificationGuiData.Type}: Distinct categories in no fixed order; "Unknown" stands for resources without guiType.
getAllNotificationTypesForGuiType(guiType : NotificationGuiData.Type) : {string} base/tealdef/game_mechanics/notifications/notification_util.d.tl:10
Call as notification_util.getAllNotificationTypesForGuiType
Notes
Lists all notification types of one GUI category.
| Parameter | Type | Description |
|---|---|---|
guiType |
NotificationGuiData.Type |
The category. |
Returns {string}: Notification type script names.
Used in the base game: 3 times in 2 files
base/content/game_mechanics/game_mechanics/notifications/notifications.script.tl:753
base/content/game_mechanics/game_mechanics/notifications/gui/notification_log.tl:217
getNotificationSimUpdateScript(type : string) : string base/tealdef/game_mechanics/notifications/notification_util.d.tl:11
Call as notification_util.getNotificationSimUpdateScript
Notes
Reads the simUpdateScript of a notification type.
| Parameter | Type | Description |
|---|---|---|
type |
string |
Notification type script, as in Notification.type. |
Returns string: The function path, e.g. "::/game_mechanics/notifications/types/overcrowding.sim.script@updateData", or nil.
removeNotification(NotificationsState, integer) base/tealdef/game_mechanics/notifications/notification_util.d.tl:13
Call as notification_util.removeNotification
Notes
Deletes a notification from the state and the history.
| Parameter | Type | Description |
|---|---|---|
#1 |
NotificationsState |
Notifications state to change. |
#2 |
integer |
Id of the notification. Unknown ids are ignored. |
addNotification(NotificationsState, Notification) : integer base/tealdef/game_mechanics/notifications/notification_util.d.tl:14
Call as notification_util.addNotification
Notes
Stores a new notification, runs its sim update script and trims the history to 100 entries.
| Parameter | Type | Description |
|---|---|---|
#1 |
NotificationsState |
Notifications state to change. |
#2 |
Notification |
The notification. |
Returns integer: Id of the new notification; nil if its type is fully ignored, -1 if no free id was found.
Details
It does not check paused; the add event handler does.
enlistNotification(state : NotificationsState, notificationId : integer) base/tealdef/game_mechanics/notifications/notification_util.d.tl:15
Call as notification_util.enlistNotification
Notes
Clears the dismissed flag so the notification shows in the pop-ups again.
| Parameter | Type | Description |
|---|---|---|
state |
NotificationsState |
Notifications state to change. |
notificationId |
integer |
Id of the notification. |
dismissNotification(state : NotificationsState, notificationId : integer) base/tealdef/game_mechanics/notifications/notification_util.d.tl:16
Call as notification_util.dismissNotification
Notes
Sets the dismissed flag, which hides the notification from the pop-ups.
| Parameter | Type | Description |
|---|---|---|
state |
NotificationsState |
Notifications state to change. |
notificationId |
integer |
Id of the notification. |
updatePersistentNotifications(NotificationsState, {string : {integer}}, PersistentNotifications) base/tealdef/game_mechanics/notifications/notification_util.d.tl:17
Call as notification_util.updatePersistentNotifications
Notes
Applies a PersistentNotifications update; the updatePersistent event calls it.
| Parameter | Type | Description |
|---|---|---|
#1 |
NotificationsState |
Notifications state to change. |
#2 |
{string : {integer}} |
Persistent notification ids by type, from getPersistentHistoryByType. |
#3 |
PersistentNotifications |
The update. |
removePersistentNotifications(NotificationsState, {string : {integer}}, RemovePersistentNotifications) base/tealdef/game_mechanics/notifications/notification_util.d.tl:18
Call as notification_util.removePersistentNotifications
Notes
Expires the persistent notifications that match a RemovePersistentNotifications; the removePersistent event calls it.
| Parameter | Type | Description |
|---|---|---|
#1 |
NotificationsState |
Notifications state to change. |
#2 |
{string : {integer}} |
Persistent notification ids by type, from getPersistentHistoryByType. |
#3 |
RemovePersistentNotifications |
Type and entities to match. |
externalGetNotificationsState() : NotificationsState base/tealdef/game_mechanics/notifications/notification_util.d.tl:19
Call as notification_util.externalGetNotificationsState
Notes
Reads the state of the notifications game script from its GAME_SCRIPT component.
Returns NotificationsState: The state as a Lua table.
getPersistentHistoryByType(state : NotificationsState) : {string : {integer}} base/tealdef/game_mechanics/notifications/notification_util.d.tl:20
Call as notification_util.getPersistentHistoryByType
Notes
Groups the ids of persistent notifications in the history by type.
| Parameter | Type | Description |
|---|---|---|
state |
NotificationsState |
Notifications state. |
Returns {string : {integer}}: Map from notification type to ids, in history order.
externalGetNotificationsStateNative() : NativeLuaTable base/tealdef/game_mechanics/notifications/notification_util.d.tl:23
Call as notification_util.externalGetNotificationsStateNative
Notes
Reads the notifications game-script state without converting it to a Lua table (state_native of the GAME_SCRIPT component).
Returns NativeLuaTable: The native state; read it with the ...FromNative functions.
Used in the base game: 19 times in 13 files
base/content/gui/gui/line_vehicle_mgmt/line_react_util.tl:109
local notificationStateNative : NativeLuaTable = notification_util.externalGetNotificationsStateNative()
base/content/gui/gui/main/game_tooltips.tl:172
local notificationStateNative : NativeLuaTable = notification_util.externalGetNotificationsStateNative()
base/content/gui/gui/statistics/statistic_warehouses.tl:311
notificationsState = notification_util.getPersistingEntity2NotificationFromNative(notification_util.externalGetNotificationsStateNative()),
base/content/gui/gui/statistics/statistic_lines.tl:384
notificationsState = notification_util.getPersistingEntity2NotificationFromNative(notification_util.externalGetNotificationsStateNative()),
base/content/gui/gui/statistics/statistic_stations.tl:272
notificationsState = notification_util.getPersistingEntity2NotificationFromNative(notification_util.externalGetNotificationsStateNative()),
base/content/gui/gui/statistics/statistics_react_util.tl:267
… and 7 more files.
getPersistingEntity2NotificationFromNative(nativeState : NativeLuaTable) : {Engine.Entity : {integer}} base/tealdef/game_mechanics/notifications/notification_util.d.tl:24
Call as notification_util.getPersistingEntity2NotificationFromNative
Notes
Maps each entity to the persistent notifications that stick to it.
| Parameter | Type | Description |
|---|---|---|
nativeState |
NativeLuaTable |
State from externalGetNotificationsStateNative. |
Returns {Engine.Entity : {integer}}: Map from entity to notification ids.
Used in the base game: 12 times in 10 files
base/content/gui/gui/line_vehicle_mgmt/line_react_util.tl:110
local persistingEntity2Notification = notification_util.getPersistingEntity2NotificationFromNative(notificationStateNative)
base/content/gui/gui/main/game_tooltips.tl:173
local persistingEntity2Notification = notification_util.getPersistingEntity2NotificationFromNative(notificationStateNative)
base/content/gui/gui/statistics/statistic_warehouses.tl:311
notificationsState = notification_util.getPersistingEntity2NotificationFromNative(notification_util.externalGetNotificationsStateNative()),
base/content/gui/gui/statistics/statistic_lines.tl:384
notificationsState = notification_util.getPersistingEntity2NotificationFromNative(notification_util.externalGetNotificationsStateNative()),
base/content/gui/gui/statistics/statistic_stations.tl:272
notificationsState = notification_util.getPersistingEntity2NotificationFromNative(notification_util.externalGetNotificationsStateNative()),
base/content/gui/gui/statistics/statistic_industries.tl:395
… and 4 more files.
getHistoryFromNative(nativeState : NativeLuaTable) : {integer} base/tealdef/game_mechanics/notifications/notification_util.d.tl:25
Call as notification_util.getHistoryFromNative
Notes
Copies the history from the native state.
| Parameter | Type | Description |
|---|---|---|
nativeState |
NativeLuaTable |
State from externalGetNotificationsStateNative. |
Returns {integer}: Notification ids, oldest first.
Used in the base game: 2 times in 2 files
base/content/game_mechanics/game_mechanics/notifications/gui/notification_log.tl:335
base/content/game_mechanics/game_mechanics/notifications/gui/notification_popups.tl:251
getNotificationFromNative(nativeState : NativeLuaTable, notificationId : integer) : Notification base/tealdef/game_mechanics/notifications/notification_util.d.tl:26
Call as notification_util.getNotificationFromNative
Notes
Copies one notification from the native state.
| Parameter | Type | Description |
|---|---|---|
nativeState |
NativeLuaTable |
State from externalGetNotificationsStateNative. |
notificationId |
integer |
Id of the notification. |
Returns Notification: The notification as a Lua table.
Used in the base game: 5 times in 5 files
base/content/gui/gui/line_vehicle_mgmt/line_react_util.tl:116
local notification = notification_util.getNotificationFromNative(notificationStateNative, notificationId)
base/content/gui/gui/main/game_tooltips.tl:178
local notification = notification_util.getNotificationFromNative(notificationStateNative, notificationId)
base/content/gui/gui/statistics/statistics_react_util.tl:360
base/content/gui/gui/entity_window/entity_window_util.tl:2138
local notification = notification_util.getNotificationFromNative(notificationStateNative, notificationId)
base/content/game_mechanics/game_mechanics/notifications/types/notification_react_util.tl:107
getNotificationEntryFromNative(nativeState : NativeLuaTable, notificationId : integer) : NotificationsState.Entry base/tealdef/game_mechanics/notifications/notification_util.d.tl:27
Call as notification_util.getNotificationEntryFromNative
Notes
Copies one state entry (notification with display flags) from the native state.
| Parameter | Type | Description |
|---|---|---|
nativeState |
NativeLuaTable |
State from externalGetNotificationsStateNative. |
notificationId |
integer |
Id of the notification. |
Returns NotificationsState.Entry: The entry as a Lua table.
makeDefaultWouldClick(entityAndRevision : {EntityUtil.EntityAndRevision}) : function() : boolean base/tealdef/game_mechanics/notifications/notification_util.d.tl:29
Call as notification_util.makeDefaultWouldClick
Notes
Makes a wouldClick function for NotificationGuiData.
| Parameter | Type | Description |
|---|---|---|
entityAndRevision |
{EntityUtil.EntityAndRevision} |
Entities of the notification. |
Returns function() : boolean: Function that returns true if one of the entities still exists unchanged.
Used in the base game: 20 times in 20 files
base/content/landmarks/landmarks_notification.script.tl:82
base/content/landmarks/landmarks_notification_nonpersistent.script.tl:11
base/content/game_mechanics/game_mechanics/company/company_notification_prospection.script.tl:87
wouldClick = notification_util.makeDefaultWouldClick({notificationParams.resultEntity, notificationParams.townEntity}),
base/content/game_mechanics/game_mechanics/company/company_notification_greenify.script.tl:34
base/content/game_mechanics/game_mechanics/company/company_notification_marketing.script.tl:64
base/content/game_mechanics/game_mechanics/towns/town_notification.script.tl:26
… and 14 more files.
makeDefaultOnClick(entityAndRevision : {EntityUtil.EntityAndRevision}) : function(stack : boolean) : boolean base/tealdef/game_mechanics/notifications/notification_util.d.tl:30
Call as notification_util.makeDefaultOnClick
Notes
Makes an onClick function for NotificationGuiData that moves the camera to the first entity that still exists unchanged and selects it.
| Parameter | Type | Description |
|---|---|---|
entityAndRevision |
{EntityUtil.EntityAndRevision} |
Entities of the notification. |
Returns function(stack : boolean) : boolean: Function that takes stack (passed with the selectEntity GUI event) and returns true if it found an entity.
Used in the base game: 20 times in 20 files
base/content/landmarks/landmarks_notification.script.tl:83
base/content/landmarks/landmarks_notification_nonpersistent.script.tl:12
base/content/game_mechanics/game_mechanics/company/company_notification_prospection.script.tl:88
onClick = notification_util.makeDefaultOnClick({notificationParams.resultEntity, notificationParams.townEntity}),
base/content/game_mechanics/game_mechanics/company/company_notification_greenify.script.tl:35
base/content/game_mechanics/game_mechanics/company/company_notification_marketing.script.tl:65
base/content/game_mechanics/game_mechanics/towns/town_notification.script.tl:27
… and 14 more files.