Skip to content

Game.UI.Menu.NotificationUISystem

Assembly: Assembly-CSharp
Namespace: Game.UI.Menu

Type: class NotificationUISystem

Base: UISystemBase

Summary:
NotificationUISystem manages the in-game notification UI list for mod-related events (downloads, installs, subscriptions and transfer progress). It binds a notifications collection to the UI (via ValueBinding) and listens to PlatformManager events to add, update and remove notifications. Notifications are represented by the nested NotificationInfo type; removals can be delayed via the DelayedNotificationInfo helper. The system keeps a simple cache of Mod objects for creating thumbnail/title data when needed and coalesces updates to the UI with a dirty flag so the binding is only triggered when necessary.


Fields

  • private const string kGroup
    Internal binding group name ("notification"). Used when creating UI bindings.

  • private const string kInstallation
    Suffix constant for installation notifications ("installation").

  • private const string kDownloading
    Suffix constant for downloading notifications ("downloading").

  • private const float kDelay
    Default removal delay (2f).

  • private ValueBinding<List<NotificationInfo>> m_NotificationsBinding
    Binding used to expose the list of current NotificationInfo objects to the UI layer.

  • private Dictionary<string, DelayedNotificationInfo> m_PendingRemoval
    Map of notification id -> pending removal info. Each entry will remove its notification after its delay expires.

  • private Dictionary<string, NotificationInfo> m_NotificationsMap
    Primary storage of active notifications by identifier.

  • private Dictionary<int, Mod> m_ModInfoCache
    Cache of Mod objects (keyed by mod id) used to populate thumbnails/titles for notifications when the mod is referenced before full mod data is available.

  • private bool m_Dirty
    Internal flag marking that the notifications binding needs to be refreshed (TriggerUpdate) at the next update.

Properties

  • public static int width { get; }
    Returns a scaled thumbnail width in pixels based on the current Screen.width relative to 1920 (ceil of 48 * scale). Used to request thumbnails sized appropriately for current resolution.

Constructors

  • public NotificationUISystem()
    Default parameterless constructor. The class initializes its collections and sets up bindings and event handlers in OnCreate (the engine calls the lifecycle methods).

  • private DelayedNotificationInfo.NotificationInfo(NotificationInfo notification, float delay)
    Constructor for the nested DelayedNotificationInfo; stores the NotificationInfo and initial delay.

  • public NotificationInfo.NotificationInfo(string id)
    Constructor for nested NotificationInfo. Initializes a notification with a required identifier. NotificationInfo implements IJsonWritable for serialization.

Methods

  • protected override void OnCreate()
    Initializes the UI system:
  • Binds this UI to NotificationSystem.
  • Creates m_NotificationsMap, m_PendingRemoval and m_ModInfoCache.
  • Adds the ValueBinding for the notifications list and a TriggerBinding for selectNotification.
  • Subscribes to PlatformManager events (onModSubscriptionChanged, onModDownloadStarted, onModDownloadCompleted, onModDownloadFailed, onModInstallProgress, onTransferOnGoing). This is where the notification system starts reacting to platform and transfer events.

  • protected override void OnDestroy()
    Unbinds the UI from NotificationSystem and performs teardown.

  • public static string GetTitle(string titleId)
    Utility to format a localization key for notification titles in the format "Menu.NOTIFICATION_TITLE[]".

  • public static string GetText(string textId)
    Utility to format a localization key for notification descriptions in the format "Menu.NOTIFICATION_DESCRIPTION[]".

  • private void AddModNotification(Mod mod, string notificationId = null)
    Creates or updates a notification for the provided Mod. Uses the mod displayName (LocalizedString.Value), constructs a thumbnail URL with the width property, and sets the mod.onClick action so selecting the notification opens whatever the mod defines.

  • private string GetModNotificationId(Mod mod, string suffix = null)
    Helper that returns GetModNotificationId(mod.id.ToString(), suffix).

  • private string GetModNotificationId(string modId, string suffix = null)
    Constructs a notification identifier for a mod and optional suffix; when suffix is non-empty returns "modId.suffix", otherwise "modId". This is used to produce stable ids for different notification types for a single mod (e.g. installation/downloading).

  • private void HandleModSubscription(IModSupport psi, Mod mod, ModSubscriptionStatus status)
    Handler for mod subscription changes. Creates an id using the subscription status enum string, prepares localized title/text and thumbnail, and calls RemoveNotification with a 2s delay so the UI shows the result briefly before removing the notification.

  • private void HandleModDownloadStarted(IModSupport psi, Mod mod)
    Caches the mod in m_ModInfoCache, adds an installation notification and sets an initial InstallPending (progress 0).

  • private void HandleModDownloadCompleted(IModSupport psi, Mod mod)
    Removes the installation notification after a 2s delay and marks it complete (progress 100).

  • private void HandleModDownloadFailed(IModSupport psi, Mod mod)
    Removes the installation notification after a 2s delay and marks it failed (progress 100).

  • private void HandleModInstallProgress(IModSupport psi, int modId, TransferStatus status)
    Updates or adds installation notifications with progress state and percent. If the status refers to a download transfer and progress has started, it may add a separate "downloading" notification (using m_ModInfoCache if needed). When a download completes it schedules a removal of the downloading notification (2s), similar to other handlers.

  • private void HandleTransferOnGoing(ITransferSupport psi, TransferStatus status)
    Handles generic transfer updates for downloads/transfers. If a downloading notification exists for the transfer id, updates its text/progress or removes it when complete/failed.

  • protected override void OnUpdate()
    Called every frame (or UI tick). Calls ProcessPendingRemovals with the current frame delta time, and if m_Dirty is set triggers the notifications binding update (m_NotificationsBinding.TriggerUpdate()) and clears the dirty flag. Ensures deferred updates are batched.

  • private void SelectNotification(string notificationId)
    Invoked by the TriggerBinding when the user selects a notification in the UI. Looks up the NotificationInfo and invokes its onClicked action if present.

  • private void UpdateNotification(NotificationInfo notificationInfo, LocalizedString? title, LocalizedString? text, string thumbnail, ProgressState? progressState, int? progress, Action onClicked)
    Merges provided optional values into an existing NotificationInfo instance. Only sets fields if the provided value is present and it doesn't overwrite existing meaningful values unnecessarily (e.g., only sets title if new title provided and existing title is empty; only sets thumbnail if a thumbnail is provided and none exists; sets progress/progressState when provided; sets onClicked only if non-null and not already set).

  • public NotificationInfo AddOrUpdateNotification(string identifier, LocalizedString? title = null, LocalizedString? text = null, string thumbnail = null, ProgressState? progressState = null, int? progress = null, Action onClicked = null)
    Add a new notification or update an existing one with the provided values. If a new NotificationInfo is created it is added to m_NotificationsMap and the bound collection. Marks the system dirty so the UI gets refreshed.

  • public void RemoveNotification(string identifier, float delay = 0f, LocalizedString? title = null, LocalizedString? text = null, string thumbnail = null, ProgressState? progressState = null, int? progress = null, Action onClicked = null)
    Removes or schedules removal of a notification. If delay == 0 the notification is removed immediately from the binding and map. Otherwise, the notification is either added to m_PendingRemoval with the given delay or its existing pending removal is reset to the new delay. The method first calls AddOrUpdateNotification so the removal can also update the notification text/state (e.g., mark complete or failed) before it disappears.

  • public bool NotificationExists(string identifier)
    Returns true if a notification with the given identifier is currently tracked (m_NotificationsMap contains key).

  • private void ProcessPendingRemovals(float deltaTime)
    Iterates over m_PendingRemoval and updates each DelayedNotificationInfo by deltaTime. When an entry's delay expires, the associated NotificationInfo is removed from the bound list, from m_NotificationsMap, and the pending removal entry is removed. The method sets m_Dirty if any notification was removed so the UI will be refreshed.

  • void DelayedNotificationInfo.Reset(float delay)
    Resets the pending delay to a new value (used to refresh scheduled removals when a new remove request for the same id arrives).

  • bool DelayedNotificationInfo.Update(float deltaTime, out NotificationInfo notification)
    Decrements the internal delay by deltaTime and returns true with the NotificationInfo out when the delay reaches zero or less (indicating the notification should be removed).

  • void NotificationInfo.Write(IJsonWriter writer)
    NotificationInfo implements IJsonWritable to allow serialization of its properties into a JSON writer. It writes id, thumbnail, title, text, progressState and progress.

Usage Example

// Example: add or update a mod-related notification from your code:
using Game.UI.Localization; // for LocalizedString
using Game.UI.Menu;         // for NotificationUISystem
using UnityEngine;          // for Debug

// Suppose you obtain a reference to the NotificationUISystem instance (engine-managed).
// For example, if you have a global accessor or created one as part of your UI:
// NotificationUISystem notificationSystem = ...;

var title = LocalizedString.Value("MyMod.DisplayName");
var text  = LocalizedString.Value("MyMod.Installing");
string thumbnailUrl = "http://example.com/mythumb.png?width=" + NotificationUISystem.width;
notificationSystem.AddOrUpdateNotification(
    identifier: "mymod.installation",
    title: title,
    text: text,
    thumbnail: thumbnailUrl,
    progressState: ProgressState.Progressing,
    progress: 25,
    onClicked: () => Debug.Log("Notification clicked")
);

// To mark it complete and remove after 2 seconds:
notificationSystem.RemoveNotification(
    identifier: "mymod.installation",
    delay: 2f,
    text: LocalizedString.Value("MyMod.InstallComplete"),
    progressState: ProgressState.Complete,
    progress: 100
);

Notes: - Notification ids should be stable strings; the system uses them to update/remove existing notifications. - Use GetModNotificationId/mod helper wrappers if you follow the same id suffixing pattern (installation/downloading). - The UI binding is automatically updated when m_Dirty is set; AddOrUpdateNotification and RemoveNotification mark the system dirty so changes appear in the UI on the next tick.