Game.UI.InGame.MapTilesUISystem
Assembly: Assembly-CSharp
Namespace: Game.UI.InGame
Type: Class
Base: UISystemBase
Summary:
System responsible for the in-game Map Tiles UI. It creates and updates UI bindings that expose map-tile related data (available resources, prices, upkeep, purchase flags, expansion permits) to the UI layer, reacts to UI triggers (open/close map tile view, purchase selection), and coordinates with underlying game systems: MapTilePurchaseSystem (selection, costs, purchases), CityConfigurationSystem (unlock state), AudioManager (UI sounds) and GameScreenUISystem (ensuring main screen active when opening the view). It also exposes a static property to indicate whether the map tile view is currently active.
Fields
-
private const string kGroup = "mapTiles"
Group name used for UI bindings. -
private MapTilePurchaseSystem m_MapTileSystem
Reference to the MapTilePurchaseSystem used for selection, querying resource amounts, costs, purchases and upkeep. -
private CityConfigurationSystem m_CityConfigurationSystem
Reference to city configuration state (used to check whether map tiles are unlocked). -
private AudioManager m_AudioManager
Reference to the audio manager used to play UI sounds when opening/closing the map tile view. -
private GameScreenUISystem m_GameScreenUISystem
Reference to the game-screen UI system used to ensure the main game screen is active when opening the map tile view. -
private EntityQuery m_SoundQuery
EntityQuery used to fetch ToolUXSoundSettingsData singleton containing camera zoom in/out UI sound entities. -
private GetterValueBinding<bool> m_MapTilesPanelVisibleBinding
Binding that exposes whether the map tile panel should be visible (map tile view active and map tiles not unlocked). -
private GetterValueBinding<bool> m_MapTilesViewActiveBinding
Binding that exposes whether the map tile view is active. -
private RawValueBinding m_ResourcesBinding
Raw binding used to write an array of resource objects (fertile land, forest, oil, ore, fish) into the UI. -
private ValueBinding<UIMapTileResource> m_BuildableLandBinding
Binding exposing the BuildableLand resource UI object. -
private ValueBinding<UIMapTileResource> m_WaterBinding
Binding exposing the GroundWater (water) resource UI object. -
private GetterValueBinding<int> m_PurchasePriceBinding
Binding exposing current purchase price for selected tiles (uses m_MapTileSystem.cost). -
private GetterValueBinding<int> m_PurchaseUpkeepBinding
Binding exposing upkeep cost for purchased tiles (uses m_MapTileSystem.upkeep). -
private GetterValueBinding<int> m_PurchaseFlagsBinding
Binding exposing purchase flags/status (casts m_MapTileSystem.status to int). -
private GetterValueBinding<int> m_ExpansionPermitsBinding
Binding exposing available expansion permits (m_MapTileSystem.GetAvailableTiles()). -
private GetterValueBinding<int> m_ExpansionPermitCostBinding
Binding exposing the expansion permit cost or selected tile count (m_MapTileSystem.GetSelectedTileCount()). -
private int m_LastSelected
Internal cache of the last selected tile count to avoid redundant UI updates. -
private bool m_IsLastTimeZoomOut
Internal flag used to avoid repeating camera zoom UI sound when toggling the view.
Properties
public static bool mapTileViewActive { get; private set }
Static property indicating whether the map tile view is currently active. Set internally by SetMapTileViewActive and cleared during game preload. UI bindings use this to determine visibility and state.
Nested Types
public readonly struct UIMapTileResource : IJsonWritable
- Properties:
public string id { get; }
— resource identifier (e.g., "BuildableLand", "Oil").public string icon { get; }
— path to the resource icon.public float value { get; }
— numeric amount/quantity for the resource.public string unit { get; }
— unit string for the resource (e.g., "area", "weight", "volume").
- Constructor:
public UIMapTileResource(string id, string icon, float value, string unit)
— creates a resource object for UI serialization.
- Methods:
public void Write(IJsonWriter writer)
— writes the resource as JSON for the UI (type "mapTiles.UIMapTileResource" and properties id, icon, value, unit).
Constructors
public MapTilesUISystem()
Default constructor. Marked with [Preserve] in the source to avoid stripping.
Methods
-
protected override void OnCreate()
Initializes the system: obtains references to required managed systems (MapTilePurchaseSystem, CityConfigurationSystem, AudioManager, GameScreenUISystem), sets up all UI bindings (bindings for panel visibility, view active, resources, individual resource bindings, purchase/permit bindings), registers trigger bindings for toggling view and purchasing selection, prepares the EntityQuery for UI sound settings, and initializes internal flags. -
private void BindResources(IJsonWriter binder)
Writes the array of resource UI objects to the provided JSON writer. It outputs five resources in order: FertileLand, Forest, Oil, Ore, Fish. Used by m_ResourcesBinding. -
private UIMapTileResource GetResource(MapFeature feature)
Returns a UIMapTileResource for the provided MapFeature. It maps features to id, icon path and unit, and queries m_MapTileSystem.GetFeatureAmount(feature) to obtain the numeric value. Handles BuildableLand, FertileLand, Forest, Oil, Ore, Fish and defaults to GroundWater for water. -
protected override void OnUpdate()
Regular update tick for the UI system. Updates view and panel bindings and expansion permit count every frame. If the map tile view is active: - Calls m_MapTileSystem.Update().
-
If the user is selecting tiles, updates purchase flags and, when the selected tile count changes, updates cached values and refreshes related bindings (purchase price, upkeep, expansion permit cost, resources, buildable land and water resource bindings).
-
protected override void OnGamePreload(Purpose purpose, GameMode mode)
Called on game preload; ensures mapTileViewActive is reset to false when a new game/preload occurs. -
private void SetMapTileViewActive(bool enabled)
Handler for the "setMapTileViewActive" UI trigger. Ensures the main game screen is active before opening the view, sets the static mapTileViewActive flag and toggles m_MapTileSystem.selecting (only allow selecting if tiles are not unlocked). Plays either camera zoom in or zoom out UI sound depending on state and previous state (avoids repeating sound while loading). -
private void PurchaseMapTiles()
Handler for the "purchaseMapTiles" UI trigger. Calls m_MapTileSystem.PurchaseSelection() to perform the purchase of selected tiles.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
m_MapTileSystem = base.World.GetOrCreateSystemManaged<MapTilePurchaseSystem>();
m_CityConfigurationSystem = base.World.GetOrCreateSystemManaged<CityConfigurationSystem>();
m_AudioManager = base.World.GetOrCreateSystemManaged<AudioManager>();
m_GameScreenUISystem = base.World.GetOrCreateSystemManaged<GameScreenUISystem>();
AddBinding(m_MapTilesPanelVisibleBinding = new GetterValueBinding<bool>(
"mapTiles", "mapTilePanelVisible",
() => mapTileViewActive && !m_CityConfigurationSystem.unlockMapTiles));
AddBinding(m_MapTilesViewActiveBinding = new GetterValueBinding<bool>(
"mapTiles", "mapTileViewActive",
() => mapTileViewActive));
AddBinding(m_BuildableLandBinding = new ValueBinding<UIMapTileResource>(
"mapTiles", "buildableLand", GetResource(MapFeature.BuildableLand), new ValueWriter<UIMapTileResource>()));
AddBinding(m_WaterBinding = new ValueBinding<UIMapTileResource>(
"mapTiles", "water", GetResource(MapFeature.GroundWater), new ValueWriter<UIMapTileResource>()));
AddBinding(m_PurchasePriceBinding = new GetterValueBinding<int>(
"mapTiles", "purchasePrice", () => m_MapTileSystem.cost));
AddBinding(m_PurchaseUpkeepBinding = new GetterValueBinding<int>(
"mapTiles", "purchaseUpkeep", () => m_MapTileSystem.upkeep));
AddBinding(m_PurchaseFlagsBinding = new GetterValueBinding<int>(
"mapTiles", "purchaseFlags", () => (int)m_MapTileSystem.status));
AddBinding(m_ExpansionPermitsBinding = new GetterValueBinding<int>(
"mapTiles", "expansionPermits", () => m_MapTileSystem.GetAvailableTiles()));
AddBinding(m_ExpansionPermitCostBinding = new GetterValueBinding<int>(
"mapTiles", "expansionPermitCost", () => m_MapTileSystem.GetSelectedTileCount()));
AddBinding(m_ResourcesBinding = new RawValueBinding("mapTiles", "resources", BindResources));
AddBinding(new TriggerBinding<bool>("mapTiles", "setMapTileViewActive", SetMapTileViewActive));
AddBinding(new TriggerBinding("mapTiles", "purchaseMapTiles", PurchaseMapTiles));
m_SoundQuery = GetEntityQuery(ComponentType.ReadOnly<ToolUXSoundSettingsData>());
m_IsLastTimeZoomOut = false;
}
If you want, I can also produce concise API-style documentation for the nested UIMapTileResource struct separately, or generate sample UI JSON payloads that the bindings produce.