Game.UI.InGame.TicketPriceSection
Assembly: Assembly-CSharp
Namespace: Game.UI.InGame
Type: class
Base: InfoSectionBase
Summary:
TicketPriceSection is a UI info section used in-game to display and control the ticket-price policy for transport lines (passenger lines). It binds a UI slider/trigger ("setTicketPrice") to the PoliciesUISystem, reads transport configuration data (to get the ticket-price policy prefab), updates slider state from entity policy data, and controls visibility so the section only shows for applicable passenger transport lines. It uses ECS queries and prefab lookups to resolve the policy entity and slider configuration.
Fields
-
private PoliciesUISystem m_PoliciesUISystem
Holds a reference to the PoliciesUISystem retrieved from the ECS World in OnCreate. Used to apply policy changes (SetPolicy) for the selected entity/line. -
private Entity m_TicketPricePolicy
Entity handle/ID for the ticket-price policy prefab (resolved from UITransportConfigurationPrefab). Used to compare against policies attached to the selected entity and to set the policy. -
private EntityQuery m_ConfigQuery
EntityQuery used to find UITransportConfigurationData singletons in the world so the class can get the UITransportConfigurationPrefab that contains the ticket-price policy reference.
Properties
-
protected override string group { get; }
Returns the UI group name for this section: "TicketPriceSection". Used when creating bindings (group identifier). -
private UIPolicySlider sliderData { get; set; }
Holds the UIPolicySlider state currently shown by the UI (current adjustment value and configuration). Updated in OnProcess by reading the entity's Policy buffer and the PolicySliderData from the policy prefab.
Constructors
public TicketPriceSection()
Default constructor. Marked with [Preserve] in the original source to avoid stripping; no custom initialization beyond base constructor.
Methods
-
protected override void Reset()
Called to reset the section. In this implementation it's empty (no reset logic). -
protected override void OnCreate()
Initializes the section: - Calls base.OnCreate().
- Gets the PoliciesUISystem via base.World.GetOrCreateSystemManaged
() and stores it in m_PoliciesUISystem. - Creates an EntityQuery for UITransportConfigurationData and stores it in m_ConfigQuery.
-
Adds a TriggerBinding
with group "TicketPriceSection" and action "setTicketPrice" bound to OnSetTicketPrice, enabling the UI to call OnSetTicketPrice when the user changes the slider. -
protected override void OnGameLoaded(Context serializationContext)
Called when game data is loaded: -
If m_ConfigQuery is not empty, gets the singleton UITransportConfigurationPrefab and resolves the m_TicketPricePolicy Entity from that prefab using m_PrefabSystem.GetEntity(...). This locates which policy entity represents ticket price adjustments.
-
private void OnSetTicketPrice(int newPrice)
Invoked from the UI binding when the player sets a new ticket price: - Calls m_PoliciesUISystem.SetPolicy(selectedEntity, m_TicketPricePolicy, newPrice > 0, Mathf.Clamp(newPrice, sliderData.range.min, sliderData.range.max));
-
This enables the policy if newPrice > 0 and clamps the adjustment value to the policy's allowed range before applying it to the selected entity (transport line).
-
private bool Visible()
Determines whether the section should be visible for the currently selected entity/prefab: -
Returns true only if the selected entity has Route, TransportLine and RouteWaypoint components, and a Policy component, and the selected prefab has TransportLineData; additionally, it returns false if that TransportLineData indicates a cargo transport (component.m_CargoTransport == true). Effectively this shows the section only for passenger transport lines.
-
protected override void OnUpdate()
Called every frame to update UI visibility: -
Sets base.visible = Visible().
-
protected override void OnProcess()
Called when the section processes its data to update UI content: - Reads the DynamicBuffer
from the selectedEntity (read-only). - Reads PolicySliderData from the ticket-price policy prefab entity.
- Iterates the policy buffer to find an entry where buffer[i].m_Policy == m_TicketPricePolicy:
- If found, creates a UIPolicySlider with the current adjustment (buffer[i].m_Adjustment if the policy is active, otherwise 0f) and the policy's component data, storing it in sliderData.
- If not found, creates a UIPolicySlider with 0f and the policy component data (policy not set on the entity).
-
This prepares sliderData for the UI and for serialization.
-
public override void OnWriteProperties(IJsonWriter writer)
Serializes UI state: - Writes a JSON property named "sliderData" and writes the sliderData object. Used for serialization of the UI state.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
m_PoliciesUISystem = base.World.GetOrCreateSystemManaged<PoliciesUISystem>();
m_ConfigQuery = GetEntityQuery(ComponentType.ReadOnly<UITransportConfigurationData>());
AddBinding(new TriggerBinding<int>(group, "setTicketPrice", OnSetTicketPrice));
}
Additional notes: - Attributes seen in source: [CompilerGenerated] on the class and [Preserve] on methods/ctor to avoid link-time stripping. - Dependencies: UIPolicySlider, UITransportConfigurationPrefab, PolicySliderData, PoliciesUISystem, Policy, PolicyFlags, UI binding system (TriggerBinding), PrefabSystem and EntityManager methods are required for full functionality. - The class assumes selectedEntity and selectedPrefab are provided by the InfoSectionBase context (the currently selected object in the UI).