Skip to content

Game.UI.Menu.WhatsNewPanelUISystem

Assembly: Game
Namespace: Game.UI.Menu

Type: class

Base: UISystemBase

Summary:
WhatsNewPanelUISystem is a UI system responsible for populating and controlling the "What's New" panel shown in the main menu. It: - Finds all entities with UIWhatsNewPanelPrefab data, filters them by owned DLCs, and sorts them by DLC id. - Binds JSON data for the panel to the UI via a RawValueBinding, and exposes bindings for visibility and initial selected tab. - Detects whether any DLCs with "what's new" pages are unseen and sets the initial tab accordingly; toggles SharedSettings.instance.userInterface.showWhatsNewPanel. - On close, marks DLCs as seen in SharedSettings.userState.seenWhatsNew (if closed with dismiss = true). - Uses PrefabSystem to resolve UIWhatsNewPanelPrefab instances for each entity in the query.


Fields

  • private const string kGroup = "whatsnew"
    Group name used for the bindings; used as the first binding group key.

  • private RawValueBinding m_PanelBinding
    Binding that provides the JSON data (via BindPanel) for the panel UI (key "whatsnew", "panel").

  • private ValueBinding<bool> m_VisibilityBinding
    Boolean binding controlling panel visibility (key "whatsnew", "visible"). Initialized to false in OnCreate.

  • private ValueBinding<int> m_InitialTabBinding
    Integer binding that indicates which tab/page should be initially selected (key "whatsnew", "initialTab"). Initialized to 0 in OnCreate and updated later based on unseen DLCs.

  • private EntityQuery m_Query
    EntityQuery that selects entities with UIWhatsNewPanelPrefab component data. Used to enumerate WhatsNew panel prefabs.

  • private PrefabSystem m_PrefabSystem
    Cached reference to the game's PrefabSystem, acquired in OnCreate and used to resolve UIWhatsNewPanelPrefab instances from entities.

  • private struct DlcComparer : IComparer<Entity>
    Private comparer type used to sort entities by their UIWhatsNewPanelPrefab's DLC id (and by entity id if equal). See nested type details below.

Properties

  • None.

Constructors

  • public WhatsNewPanelUISystem()
    Default parameterless constructor. Marked with [Preserve] attribute in the source (to avoid stripping).

Methods

  • protected override void OnCreate() : System.Void
    Initializes the system:
  • Calls base.OnCreate().
  • Retrieves PrefabSystem from World and stores in m_PrefabSystem.
  • Adds the bindings:
    • m_PanelBinding = new RawValueBinding("whatsnew", "panel", BindPanel)
    • m_VisibilityBinding = new ValueBinding("whatsnew", "visible", initialValue: false)
    • m_InitialTabBinding = new ValueBinding("whatsnew", "initialTab", 0)
    • new TriggerBinding("whatsnew", "close", OnClose)
  • Creates an EntityQuery for UIWhatsNewPanelPrefab (m_Query). This method sets up everything the UI needs to request panel data and to signal close events.

  • private void OnClose(bool dismiss) : System.Void
    Called when the UI triggers the "close" binding. Behavior:

  • Always sets the visibility binding to false.
  • If dismiss == true, marks all owned DLCs that provide whats-new content as seen:
    • Iterates over all entities in m_Query, sorted by DlcComparer.
    • For each prefab, gets DlcRequirement and if CheckRequirement() is true and the DLC name is not already in SharedSettings.instance.userState.seenWhatsNew, adds it.
    • Sets SharedSettings.instance.userInterface.showWhatsNewPanel = false.
  • If dismiss == false, it just hides the panel without updating seenWhatsNew.

  • protected override void OnGameLoadingComplete(Purpose purpose, GameMode mode) : System.Void
    Called when game loading completes. In MainMenu mode it:

  • Collects owned WhatsNew prefabs via GetSortedWhatsNewTabs.
  • Determines if there are any unseen DLC whats-new entries:
    • Iterates the sorted prefabs, checks DlcRequirement and whether the DLC name is in SharedSettings.instance.userState.seenWhatsNew.
    • If unseen entries exist, computes the smallest DLC id among them and chooses the corresponding prefab index as initial tab.
    • Sets m_InitialTabBinding to that index (or last index if not found).
    • Sets SharedSettings.instance.userInterface.showWhatsNewPanel = true to request display.
  • If no unseen entries exist, sets m_InitialTabBinding to the last tab.
  • Updates m_PanelBinding (so UI fetches JSON) and m_VisibilityBinding from SharedSettings.userInterface.showWhatsNewPanel.

  • private void BindPanel(IJsonWriter writer) : System.Void
    Writes the JSON array describing all tabs/pages/items/images for the UIWhatsNewPanel. For each UIWhatsNewPanelPrefab the method:

  • Writes the DLC id ("id") and DLC name ("dlc") from the prefab's DlcRequirement.
  • Writes "pages" array; for each page writes "items" array; for each item writes:

    • "images": array of objects with "image" (URI), "aspectRatio", and "width".
    • "title", "subtitle", "paragraphs": writes the localization ids if present or null otherwise.
    • "justify": integer value of the justify enum.
    • "width": item width. This is the core serialization used by the UI layer to construct the panel views.
  • private List<UIWhatsNewPanelPrefab> GetSortedWhatsNewTabs(EntityQuery query) : List
    Builds a list of UIWhatsNewPanelPrefab instances for entities in the query:

  • Converts the query to a temporary NativeArray, sorts it using DlcComparer (by DLC id).
  • Iterates the entities, resolves each prefab via m_PrefabSystem.GetPrefab(entity).
  • Filters prefabs by PlatformManager.instance.IsDlcOwned(component.m_Dlc).
  • Returns the list of owned, sorted prefabs. Note: Allocator.Temp is used for the native array and the method assumes m_PrefabSystem is initialized.

  • Nested type: private struct DlcComparer : IComparer<Entity>

  • Fields:
    • private EntityManager m_EntityManager — used to access component data for each entity.
  • Constructor:
    • public DlcComparer(EntityManager entityManager) — stores the EntityManager reference.
  • Method:
    • public int Compare(Entity a, Entity b) — compares entities by UIWhatsNewPanelPrefabData.m_Id (DLC id). If ids are equal, falls back to Entity.CompareTo to get a deterministic order.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // Acquire the prefab system and register bindings that let the UI request
    // the panel JSON and control visibility/initial tab.
    m_PrefabSystem = base.World.GetOrCreateSystemManaged<PrefabSystem>();
    AddBinding(m_PanelBinding = new RawValueBinding("whatsnew", "panel", BindPanel));
    AddBinding(m_VisibilityBinding = new ValueBinding<bool>("whatsnew", "visible", initialValue: false));
    AddBinding(m_InitialTabBinding = new ValueBinding<int>("whatsnew", "initialTab", 0));
    AddBinding(new TriggerBinding<bool>("whatsnew", "close", OnClose));
    m_Query = GetEntityQuery(ComponentType.ReadOnly<UIWhatsNewPanelPrefabData>());
}

Notes and implementation caveats: - The system relies on SharedSettings.instance to persist which DLCs the user has already seen. Make sure that userState and userInterface objects exist and are accessible during MainMenu flow. - BindPanel builds JSON directly; any changes to the UIWhatsNewPanelPrefab data model require keeping this serializer in sync. - GetSortedWhatsNewTabs uses Allocator.Temp for the native array, which is suitable for short-lived usage inside a method; ensure it is not retained.