Skip to content

Game.UI.InGame.ToolbarUISystem

Assembly:
Namespace: Game.UI.InGame

Type: class

Base: UISystemBase, IPreDeserialize

Summary:
ToolbarUISystem manages the in-game toolbar UI for Cities: Skylines 2. It constructs and exposes bindings for toolbar groups, asset menus, categories, assets, themes and asset packs, and handles user selections and tool activation. The system coordinates Prefab lookups, UI highlighting, filtering by themes/packs, and reacts to unlocked/unique asset state changes. It is intended to run on the main ECS World and be used by other systems or UI code to query or change the current toolbar selection state.


Fields

  • private PrefabSystem m_PrefabSystem
    System used to lookup prefabs and to map entities to prefab instances.

  • private CityConfigurationSystem m_CityConfigurationSystem
    Provides city configuration data (used to initialize default theme selection on load).

  • private ToolSystem m_ToolSystem
    Tool management system; used to activate and switch tools based on selection.

  • private ObjectToolSystem m_ObjectToolSystem
    Object tool used to place assets; used to read/write age mask state.

  • private DefaultToolSystem m_DefaultTool
    Default (fallback) tool used when no prefab/tool should be active.

  • private UniqueAssetTrackingSystem m_UniqueAssetTrackingSystem
    Tracks unique asset placement; ToolbarUISystem subscribes to its EventUniqueAssetStatusChanged.

  • private PrefabUISystem m_PrefabUISystem
    Helper system used for UI-related prefab info (requirements, cost etc).

  • private ImageSystem m_ImageSystem
    Provides icons/thumbnails and placeholder icons used by the toolbar bindings.

  • private UpgradeMenuUISystem m_UpgradeMenuUISystem
    Used to avoid switching tools while upgrade UI is active.

  • private ActionsSection m_ActionsSection
    Used to know when the lot editing actions section is active.

  • private EntityQuery m_ThemeQuery
    EntityQuery for theme prefabs used when listing themes.

  • private EntityQuery m_AssetPackQuery
    EntityQuery for asset pack prefabs used when listing packs.

  • private EntityQuery m_ToolbarGroupQuery
    EntityQuery used to find toolbar groups (UI toolbar elements).

  • private EntityQuery m_UnlockedPrefabQuery
    Query used to detect unlocked prefabs that affect toolbar refresh.

  • private RawValueBinding m_ToolbarGroupsBinding
    Binding that produces toolbar groups JSON for the UI.

  • private RawMapBinding<Entity> m_AssetMenuCategoriesBinding
    Binding for categories inside an asset menu.

  • private RawMapBinding<Entity> m_AssetsBinding
    Binding for assets inside a category (returns filtered list).

  • private RawValueBinding m_ThemesBinding
    Binding that produces theme list for the currently selected category.

  • private RawValueBinding m_AssetPacksBinding
    Binding that produces asset pack list for the currently selected category.

  • private ValueBinding<int> m_AgeMaskBinding
    Binding exposing the age filter for the object tool (used by UI).

  • private GetterValueBinding<List<Entity>> m_SelectedThemesBinding
    Binding exposing the currently selected themes to the UI.

  • private GetterValueBinding<List<Entity>> m_SelectedAssetPacksBinding
    Binding exposing the currently selected asset packs to the UI.

  • private ValueBinding<Entity> m_SelectedAssetMenuBinding
    Binding for the selected asset menu entity.

  • private ValueBinding<Entity> m_SelectedAssetCategoryBinding
    Binding for the selected asset category entity.

  • private ValueBinding<Entity> m_SelectedAssetBinding
    Binding for the currently selected asset entity.

  • private Dictionary<Entity, Entity> m_LastSelectedCategories
    Remembers last selected category per asset menu (for UX).

  • private Dictionary<Entity, Entity> m_LastSelectedAssets
    Remembers last selected asset per category (for UX).

  • private List<Entity> m_SelectedThemes
    Current list of selected theme entities.

  • private List<Entity> m_SelectedAssetPacks
    Current list of selected asset pack entities.

  • private bool m_UniqueAssetStatusChanged
    Flag set when UniqueAssetTrackingSystem reports a change; triggers a UI refresh.

  • private bool m_HasUnlockedPrefabLastFrame
    Used to batch/update toolbar bindings after prefab unlocks.

Properties

  • public bool hasActiveSelection { get; }
    Returns true if there is an active selection in the toolbar (either an asset menu selected or a specific asset selected). Useful for other systems or UI code that need to know whether the user currently has an active item selection.

Constructors

  • public ToolbarUISystem()
    Default constructor. The system initializes its bindings and internal collections during OnCreate.

Methods

  • protected override void OnCreate() : System.Void
    Initializes references to dependent systems, registers UniqueAssetTrackingSystem event handler, sets up EntityQueries, creates all UI bindings (toolbar groups, assets, themes, packs, selected items and triggers), and initializes internal caches/lists.

  • protected override void OnDestroy() : System.Void
    Unsubscribes from UniqueAssetTrackingSystem events and performs system teardown.

  • protected override void OnUpdate() : System.Void
    Main per-frame logic. Synchronizes prefab tool with currently selected prefab, clears selection when tool changes, updates bindings when prefabs unlock or unique asset state changes, and conditionally activates prefab tool for selected item when relevant.

  • protected override void OnGameLoaded(Context serializationContext) : System.Void
    Called when a game is loaded. Resets selected themes/asset packs to defaults and updates toolbar bindings accordingly.

  • public void PreDeserialize(Context context) : System.Void
    Implementation of IPreDeserialize. Called before deserialization to clear selection and saved last-selected caches.

  • private void BindToolbarGroups(IJsonWriter writer) : System.Void
    Binding method that writes an array of toolbar groups with their children into the UI JSON. Uses GetSortedToolbarGroups and UIObjectInfo helpers and binds per-item metadata (name, icon, locked state, requirements, sounds, shortcut, highlight).

  • private void BindAssetCategories(IJsonWriter writer, Entity assetMenu) : System.Void
    Writes asset categories for a given asset menu entity to JSON (name, icon, locked state, uiTag, highlight). Writes an empty array if assetMenu is invalid.

  • private NativeList<UIObjectInfo> GetSortedCategories(DynamicBuffer<UIGroupElement> elements)
    Helper that returns and sorts category UIObjectInfo entries, removing invalid categories (those without UIAssetCategoryData or without children).

  • private void BindAssets(IJsonWriter writer, Entity assetCategory) : System.Void
    Writes the list of assets in a category to JSON, filtering by currently selected themes/packs and excluding upgrade-prefabs. Uses BindAsset for each item.

  • public void BindAsset(IJsonWriter writer, Entity entity, bool unique = false, bool placed = false) : System.Void
    Writes a single asset's JSON representation (name, icon, dlc label, theme icon, locked, unique/placed flags, construction cost, etc.). It reads prefab components for DLC and requirements and uses PrefabUISystem to bind cost and requirements.

  • private void BindThemes(IJsonWriter writer) : System.Void
    Writes available themes for the currently selected category. If in editor mode or there are no themes for the category, writes an empty array. Highlights themes that contain highlighted items.

  • private void SetSelectedThemes(List<Entity> themes) : System.Void
    Trigger handler called by UI to set selected themes. Updates selection, finds an appropriate asset to select (keeps closest match), and applies the change (optionally activating tool).

  • private void SetAgeMask(int ageMask) : System.Void
    Sets the ObjectToolSystem age mask and updates the binding shown in UI.

  • private void SetSelectedAssetPacks(List<Entity> packs) : System.Void
    Trigger handler to set selected packs. Works similarly to SetSelectedThemes, finding a matching/closest asset and applying selection.

  • private void BindPacks(IJsonWriter writer) : System.Void
    Writes available asset packs for the currently selected category. Highlights packs containing highlighted items.

  • private void SelectAssetMenu(Entity assetMenu) : System.Void
    Sets the selected asset menu, picks a category and asset to select (using last selections or the first unlocked item), and applies the new selection.

  • private void SelectAssetCategory(Entity assetCategory) : System.Void
    Selects a category: resets selected packs, tries to restore last-selected asset for that category, and applies selection; if no unlocked assets are found, it will clear packs and attempt again.

  • private void SelectAsset(Entity assetEntity, bool updateTool) : System.Void
    Selects a specific asset entity. If the asset doesn't match current theme/pack filters, it will compute appropriate theme/pack selections that include the asset. Optionally activates the prefab tool.

  • public void ClearAssetSelection() : System.Void
    Clears the current asset/menu/category selection and updates the UI/tool accordingly (calls ClearAssetSelection(true)).

  • private void ClearAssetSelection(bool updateTool) : System.Void
    Clears selection and can optionally update the active tool (resets to default tool if updateTool is true).

  • private void Apply(List<Entity> themes, List<Entity> packs, Entity assetMenuEntity, Entity assetCategoryEntity, Entity assetEntity, bool updateTool = false) : System.Void
    Core method that applies a new selection state: updates the tool (if requested), updates highlights and all bindings, updates last-selected caches, and makes sure the age mask UI syncs with ObjectToolSystem.

  • private void UpdateHighlights(List<Entity> themes, List<Entity> packs, Entity assetMenuEntity, Entity assetCategoryEntity, Entity assetEntity) : System.Void
    Updates UIHighlight components on menu, categories and individual items according to the new selection and re-writes appropriate bindings so UI updates these highlight states.

  • private void ActivatePrefabTool(Entity assetEntity) : System.Void
    Helper that activates the prefab tool for a given prefab entity if it is not locked and the prefab exists; otherwise falls back to the DefaultToolSystem.

  • private bool IsMatchingTheme(Entity assetEntity, List<Entity> themes) : System.Boolean
    Checks whether an asset matches the provided themes (or no theme restrictions). Returns false for Entity.Null.

  • private bool IsMatchingPack(Entity assetEntity, List<Entity> packs) : System.Boolean
    Checks whether an asset matches the provided packs. Returns false for Entity.Null.

  • private bool IsMatchingAssetCategory(Entity assetEntity, Entity assetCategoryEntity) : System.Boolean
    Checks whether an asset belongs to the provided category.

  • private Entity GetFirstTheme(Entity assetEntity) : Entity
    Returns the first Theme entity required by a given asset, or Entity.Null.

  • private Entity GetFirstPack(Entity assetEntity) : Entity
    Returns the first AssetPack entity required by a given asset, or Entity.Null.

  • private Entity GetClosestAssetInThemes(Entity oldAssetEntity, Entity groupEntity, List<Entity> themes) : Entity
    Tries to find the closest matching asset in another theme set by comparing naming/prefix patterns. Falls back to GetFirstUnlockedItem when no close match is found.

  • private Entity GetClosestAssetInPacks(Entity oldAssetEntity, Entity groupEntity, List<Entity> packs) : Entity
    Finds a close match in packs for an old asset or falls back to first unlocked.

  • private Entity GetFirstItem(Entity groupEntity, List<Entity> themes, List<Entity> packs) : Entity
    Returns the first item in a group that matches themes/packs, or Entity.Null.

  • private Entity GetFirstUnlockedItem(Entity groupEntity, List<Entity> themes, List<Entity> packs) : Entity
    Returns the first unlocked item matching filters. If none unlocked, returns first item regardless of lock.

  • private NativeArray<UIObjectInfo> GetSortedToolbarGroups() : NativeArray<UIObjectInfo>
    Collects toolbar group entities and priorities, builds UIObjectInfo array and sorts them by priority before returning.

  • private void FilterByTheme(NativeList<UIObjectInfo> elementInfos, Entity themeEntity) : System.Void
    Filters a list of UI objects so only those matching a single theme remain.

  • private List<Entity> FilterThemesByAsset(NativeList<UIObjectInfo> themes, Entity asset) : List<Entity>
    Filter the provided themes list to only themes compatible with the specified asset; updates and returns m_SelectedThemes.

  • private List<Entity> FilterPacksByAsset(NativeList<UIObjectInfo> assetPacks, Entity asset) : List<Entity>
    Filter the provided packs list to only packs compatible with the specified asset; updates and returns m_SelectedAssetPacks.

  • private void FilterByPack(NativeList<UIObjectInfo> elementInfos, Entity packEntity) : System.Void
    Filters a list of UI objects so only those matching a single pack remain.

  • private void FilterByThemes(NativeList<UIObjectInfo> elementInfos, List<Entity> themes) : System.Void
    Filters a list of UI objects using a set of themes (drops objects that require a different theme).

  • private void FilterByPacks(NativeList<UIObjectInfo> elementInfos, List<Entity> packs) : System.Void
    Filters elements to only include those that belong to one of the selected packs.

  • private void FilterOutUpgrades(NativeList<UIObjectInfo> elementInfos) : System.Void
    Removes service upgrade prefabs from a list (they are omitted from the asset list).

  • private void ToggleToolOptions(bool enabled) : System.Void
    Toggles the tool options UI for the currently active tool (if present).

Usage Example

// Example from another system or a mod entry point to interact with the toolbar system.
// Make sure you call this on the main thread/Update context (ECS systems).
var toolbar = World.DefaultGameObjectInjectionWorld.GetExistingSystemManaged<Game.UI.InGame.ToolbarUISystem>();
if (toolbar != null)
{
    // Select an asset menu entity (assetMenuEntity must be a valid Entity for a UIAssetMenu)
    toolbar.SelectAssetMenu(assetMenuEntity);

    // Select a specific asset by entity and optionally activate the prefab tool
    toolbar.SelectAsset(assetEntity, updateTool: true);

    // Programmatically change selected themes (list of Theme entities)
    toolbar.SetSelectedThemes(new List<Entity> { themeEntity1, themeEntity2 });

    // Clear any selection and reset tool
    toolbar.ClearAssetSelection();
}

Additional notes for modders: - ToolbarUISystem heavily uses EntityManager queries, component buffers and Native containers. Methods that allocate Native lists/arrays always dispose them in the method; avoid copying or holding Native containers beyond the call unless you manage their lifetime. - To update UI-visible data, the system uses bindings (RawValueBinding, RawMapBinding, ValueBinding). Trigger these by calling the public trigger methods (SelectAssetMenu, SetSelectedThemes, etc.) rather than directly manipulating bindings. - The system subscribes to UniqueAssetTrackingSystem.EventUniqueAssetStatusChanged to refresh asset lists when unique assets are placed/removed. - Be mindful of Editor vs Game mode: some bindings (themes/packs) return empty arrays in editor mode. - When calling into this system from other systems or code, prefer GetExistingSystemManaged/GetOrCreateSystemManaged depending on whether you want to create it if missing; ensure your calls run while the world and systems are initialized.