Skip to content

Game.UI.InGame.EventJournalUISystem

Assembly:
Assembly-CSharp

Namespace:
Game.UI.InGame

Type:
class

Base:
UISystemBase

Summary:
EventJournalUISystem is a UI system that exposes the in-game event journal to the UI layer. It binds the recent event entries and individual event entry data to JSON bindings used by the UI. The system listens for changes in the EventJournalSystem (new entries and event data changes) and updates the UI bindings accordingly. It also exposes open/close triggers for the journal UI.


Fields

  • private const string kGroup = "eventJournal"
    Group name used for UI bindings — all bindings created by this system are under the "eventJournal" group.

  • private const int kMaxMessages = 100
    Maximum number of messages the UI exposes for the events list (used when building the events array — bound to "events").

  • private IEventJournalSystem m_EventJournalSystem
    Reference to the EventJournalSystem (managed ECS system) that stores journal entries and their data. The system subscribes to this to receive notifications when entries are added or when entry data changes.

  • private PrefabSystem m_PrefabSystem
    Reference to the PrefabSystem used to resolve event prefabs and their JournalEventComponent (to read icons and other prefab-defined metadata).

  • private EntityQuery m_TimeDataQuery
    EntityQuery used to obtain the global TimeData singleton so the system can compute event dates relative to the city's first frame.

  • private RawMapBinding<Entity> m_EventMap
    RawMapBinding that provides per-entity bindings for individual journal entries. This writes a JSON object for a given event Entity (the binder calls BindJournalEntry).

  • private RawValueBinding m_Events
    RawValueBinding used to expose the events list (most recent events up to kMaxMessages) to the UI; this calls BindEvents.

Properties

  • public Action eventJournalOpened { get; set; }
    Action invoked when the UI trigger "openJournal" fires. UI or other systems can subscribe to this to react when the journal is opened.

  • public Action eventJournalClosed { get; set; }
    Action invoked when the UI trigger "closeJournal" fires. UI or other systems can subscribe to this to react when the journal is closed.

Constructors

  • public EventJournalUISystem()
    Default constructor. The system relies on OnCreate to set up bindings and references.

Methods

  • protected override void OnCreate() : System.Void
    Initializes the system:
  • Obtains PrefabSystem and EventJournalSystem from the World.
  • Subscribes to EventJournalSystem events:
    • eventEventDataChanged -> OnEventDataChanged(entity) to update a specific journal entry binding.
    • eventEntryAdded -> OnEntryAdded() to refresh the events list binding.
  • Builds UI bindings:
    • TriggerBinding("eventJournal", "openJournal") -> invokes eventJournalOpened.
    • TriggerBinding("eventJournal", "closeJournal") -> invokes eventJournalClosed.
    • RawValueBinding("eventJournal", "events", BindEvents) -> provides the array of recent events.
    • RawMapBinding("eventJournal", "eventMap", BindJournalEntry) -> provides per-entity event info objects.

Note: methods and delegates are marked with [Preserve] to avoid stripping for AOT.

  • protected override void OnUpdate() : System.Void
    Empty override. The system performs updates reactively via bindings and event callbacks rather than per-frame work here.

  • private void OnEventDataChanged(Entity entity) : System.Void
    Callback invoked when an event entity's data changes. Calls m_EventMap.Update(entity) so the UI is updated for that entry.

  • private void OnEntryAdded() : System.Void
    Callback invoked when a new event entry is added to the journal. Calls m_Events.Update() so the events list in the UI refreshes.

  • private void BindEvents(IJsonWriter binder) : System.Void
    Writes a JSON array of recent events (most recent first) using the binder. The array length is the minimum of the journal length and kMaxMessages (100). Entries are written in reverse order (newest first).

  • private void BindJournalEntry(Entity entity, IJsonWriter binder) : System.Void
    Writes a JSON object for a single journal entry with the following structure ("eventJournal.EventInfo"):

  • id: prefab name (string)
  • icon: component.m_Icon (string or sprite reference as provided by JournalEventComponent)
  • date: integer representing startFrame - TimeData.m_FirstFrame (city-relative frame index)
  • data: an array of eventJournal.UIEventData objects (or null) — each entry contains:
    • type: name of EventDataTrackingType enum
    • value: numeric value (raw value from tracking data)
  • effects: an array of eventJournal.UIEventData objects (or null) — each entry contains:
    • type: name of EventCityEffectTrackingType enum
    • value: percentile change computed with EventJournalUtils.GetPercentileChange

Implementation details: - Resolves EventJournalEntry info and associated prefab Entity. - Gets EventPrefab from PrefabSystem and reads JournalEventComponent. - Uses m_TimeDataQuery to convert frames to a date relative to the city's first frame. - Uses m_EventJournalSystem.TryGetData and TryGetCityEffects to include optional arrays (writes null when absent).

Usage Example

// Get the system instance and subscribe to open/close notifications:
var uiSystem = World.GetOrCreateSystemManaged<Game.UI.InGame.EventJournalUISystem>();
uiSystem.eventJournalOpened += () =>
{
    // Called when the UI triggers "openJournal" (e.g. user opens the journal)
    Debug.Log("Event journal opened");
};
uiSystem.eventJournalClosed += () =>
{
    Debug.Log("Event journal closed");
};

// If you need to inspect or debug the JSON emitted by BindJournalEntry/BindEvents,
// you can obtain the EventJournalSystem and iterate entries, or rely on the UI bindings.
var eventJournalSystem = World.GetOrCreateSystemManaged<Game.Events.EventJournalSystem>();
// Example: enumerate last entries (read-only)
for (int i = eventJournalSystem.eventJournal.Length - 1; i >= 0 && i >= eventJournalSystem.eventJournal.Length - 100; --i)
{
    var entry = eventJournalSystem.eventJournal[i];
    // handle entry...
}

Additional notes and modding tips: - Bindings created use the "eventJournal" group. To add new UI fields, either extend BindJournalEntry or add new bindings under the same group name. - BindJournalEntry uses prefab metadata (JournalEventComponent) for icons and id. To customize appearance, add or modify JournalEventComponent on event prefabs. - The system updates UI reactively via event callbacks (eventEntryAdded and eventEventDataChanged). Those events are exposed by EventJournalSystem; you can raise or listen to them when modifying journal data. - kMaxMessages limits the number of events exposed to UI to avoid sending very large payloads to the UI layer.