Skip to content

Game.UI.InGame.PoliciesSection

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

Type: public class

Base: InfoSectionBase

Summary:
PoliciesSection is an InfoSection used by the in-game UI to display and bind policy-related information for the currently selected entity (building, district or route). It ties the UI to the PoliciesUISystem, listens for policy-unlock events to request UI updates, and writes the appropriate policy data into the JSON writer when requested by the UI layer. The section is visible only when the selected entity has a Policy component and when the PoliciesUISystem can gather policy info for that selection.


Fields

  • private PoliciesUISystem m_PoliciesUISystem
    Holds a reference to the game's PoliciesUISystem (retrieved from World). Used to gather policies for the selected entity and to bind policy data into the UI writer. Subscriptions to the PoliciesUISystem.EventPolicyUnlocked are also managed through this field.

  • private enum PoliciesKey { Building, District }
    A small private enum used to choose tooltip keys when processing the selected entity type. It distinguishes between Building and District tooltips.

Properties

  • protected override string group { get; }
    Returns the group name used by the base InfoSection infrastructure. This override returns the constant "PoliciesSection", which identifies this section in UI grouping and debugging.

Constructors

  • public PoliciesSection()
    Default parameterless constructor. The real initialization happens in OnCreate; the constructor is preserved and present for the managed type system.

Methods

  • protected override void OnCreate()
    Initializes the section when it is created by the UI system. This method:
  • Calls base.OnCreate().
  • Retrieves or creates the PoliciesUISystem from World and stores it in m_PoliciesUISystem.
  • Subscribes m_InfoUISystem.RequestUpdate to m_PoliciesUISystem.EventPolicyUnlocked so the UI refreshes when a new policy is unlocked.

  • protected override void OnDestroy()
    Cleans up subscriptions when the section is destroyed. This method:

  • Calls base.OnDestroy().
  • Removes the previously attached m_InfoUISystem.RequestUpdate handler from m_PoliciesUISystem.EventPolicyUnlocked to avoid dangling event handlers.

  • protected override void Reset()
    Empty override in this class. Provided by the InfoSectionBase lifecycle; nothing is reset explicitly here.

  • protected override void OnUpdate()
    Controls visibility each update tick. It sets base.visible to true only if:

  • The currently selected entity has a Policy component, and
  • m_PoliciesUISystem.GatherSelectedInfoPolicies(selectedEntity) returns true (meaning the system successfully gathered policy info for that entity).

  • protected override void OnProcess()
    Adds tooltip keys/tags based on the type of the selected entity:

  • If the selected entity has a Building component, adds the Building PoliciesKey tooltip key.
  • Else if it has a District component, adds the District PoliciesKey tooltip key.
  • Else if it has a Route component, adds tooltip tags for CargoRoute and TransportLine.

  • public override void OnWriteProperties(IJsonWriter writer)
    Writes policy data into the provided IJsonWriter for the UI to render. Behavior:

  • Writes a property named "policies".
  • If the selected entity is a Building, calls m_PoliciesUISystem.BindBuildingPolicies(writer).
  • Else if a District, calls m_PoliciesUISystem.BindDistrictPolicies(writer).
  • Else if a Route, calls m_PoliciesUISystem.BindRoutePolicies(writer).
  • Otherwise writes null for the "policies" property.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // Obtain the PoliciesUISystem and subscribe to policy-unlocked events
    m_PoliciesUISystem = base.World.GetOrCreateSystemManaged<PoliciesUISystem>();
    m_PoliciesUISystem.EventPolicyUnlocked += m_InfoUISystem.RequestUpdate;
}

[Preserve]
protected override void OnDestroy()
{
    // Unsubscribe to avoid leaks
    if (m_PoliciesUISystem != null)
        m_PoliciesUISystem.EventPolicyUnlocked -= m_InfoUISystem.RequestUpdate;
    base.OnDestroy();
}

Notes and tips for modders: - PoliciesSection expects the PoliciesUISystem to implement methods like GatherSelectedInfoPolicies(...) and Bind{Building|District|Route}Policies(IJsonWriter), and to expose an EventPolicyUnlocked action. If you extend or replace PoliciesUISystem, ensure these entry points remain compatible. - The section relies on the presence of Policy, Building, District, and Route components on entities. When creating custom entity types or components, add the appropriate components so this section can operate on them. - Keep event subscription/unsubscription balanced to prevent memory leaks or missing UI updates.