Skip to content

Game.UI.Menu.MenuUISystem

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

Type: class

Base: UISystemBase, IPreDeserialize

Summary:
MenuUISystem is the UI system responsible for the game's main menu and save/load/new-game flows. It wires up a large set of UI bindings (maps, themes, saves, cloud targets, game modes, tutorial settings, mod UI toggles, etc.), subscribes to asset database changes, handles user actions (continue, new game, load, save, quicksave/quickload, delete/share, start editor, exit to main menu), and coordinates with core game systems (PrefabSystem, CityConfigurationSystem, TimeSystem, MapMetadataSystem, GameModeSystem, GameScreenUISystem, Asset upload UI). It performs IO-heavy operations (load/save) on background tasks via TaskManager and ensures UI updates are performed on the main thread when required. The class also contains nested helper types (ThemeInfo, NewGameArgs, LoadGameArgs, GameOptions, DefaultGameOptions, SaveabilityStatus) used for serialization and UI data transfer.


Fields

  • private PrefabSystem m_PrefabSystem
    References the PrefabSystem; used to react when content availability changes and to evaluate prerequisites.

  • private CityConfigurationSystem m_CityConfigurationSystem
    Holds/overrides city configuration (name, options, used mods, etc.) used when starting or loading games.

  • private TimeSystem m_TimeSystem
    Used to set starting time for new games and to query current simulation time for save metadata.

  • private MapMetadataSystem m_MapMetadataSystem
    Tracks metadata for selected maps (name, theme, starting year) used for display and when loading.

  • private StandaloneAssetUploadPanelUISystem m_AssetUploadPanelUISystem
    Used to show the upload UI for sharing saves and maps.

  • private GameScreenUISystem m_GameScreenUISystem
    Used to switch to other UI screens (e.g., pause menu during save).

  • private GameModeSystem m_GameModeSystem
    Used to list and override game modes for new/load workflows.

  • private ValueBinding<int> m_ActiveScreenBinding
    Binding that stores which menu screen is active (Menu, NewGame, LoadGame, Options, Credits).

  • private GetterValueBinding<List<ThemeInfo>> m_ThemesBinding
    Getter binding that provides theme list to the UI.

  • private ValueBinding<List<MapInfo>> m_MapsBinding
    Binding for available maps displayed in the menu.

  • private ValueBinding<HashSet<int>> m_AvailableMapFilters
    Keeps available map filter tabs (default vs custom).

  • private ValueBinding<int> m_SelectedMapFilter
    The currently selected map filter tab.

  • private GetterValueBinding<List<GameModeInfo>> m_GameModesBinding
    Binding for available game modes.

  • private ValueBinding<string> m_CurrentGameModeBinding
    UI binding for the currently selected game mode name.

  • private ValueBinding<List<SaveInfo>> m_SavesBinding
    Binding for the list of saves.

  • private ValueBinding<string> m_SavePreviewBinding
    Stores a URI for the save preview thumbnail shown in save UI.

  • private ValueBinding<string> m_LastSaveNameBinding
    Last explicitly named save (used for quicksave fallback).

  • private ValueBinding<int> m_SaveGameSlotsBinding
    Number of save game slots.

  • private GetterValueBinding<SaveabilityStatus> m_SaveabilityBinding
    Binding exposing whether saving is possible and why not.

  • private ValueBinding<List<string>> m_AvailableCloudTargetsBinding
    Cloud storage targets available for save/upload.

  • private GetterValueBinding<string> m_SelectedCloudTargetBinding
    Currently selected cloud target name (getter binding).

  • private DefaultGameOptions m_DefaultGameOptions
    Helper exposing default options for new games from SharedSettings.

  • private MenuHelpers.SaveGamePreviewSettings m_PreviewSettings
    Settings used when generating the save preview image.

  • private EntityQuery m_XPQuery
    Entity query used to fetch XP component data from ECS world.

  • private bool m_IsLoading
    Internal flag denoting if a load is in progress (used internally).

  • private string m_LastSelectedCloudTarget
    Tracks last used cloud target for quicksave/last save.

  • private PdxModsUI m_ModsUI
    Manages the Paradox Mods UI integration.

  • private static int s_PreviewId
    Static incrementing id used when creating save preview URIs.

Properties

  • public MenuScreen activeScreen { get; private set }
    UI-facing property mapped to m_ActiveScreenBinding. Use to get or set which menu screen is currently active. Setting updates the binding and drives menu UI.

Additional info: Writing to this property updates the underlying ValueBinding so UI will reflect the change. The enum MenuScreen lists screens: Menu, NewGame, LoadGame, Options, Credits.

Constructors

  • public MenuUISystem()
    Default constructor. Minimal initialization; actual setup happens in OnCreate and OnWorldReady.

Additional info: The class is a managed ECS system. The constructor is preserved ([Preserve]) in the source and the system expects OnCreate to register all the UI bindings and callbacks.

Methods

  • protected override void OnCreate()
    Initializes the system: obtains references to dependent world systems, creates DefaultGameOptions, loads preview settings from AssetDatabase, registers a large set of bindings (ValueBinding, GetterValueBinding, TriggerBinding) for UI, creates entity queries, and constructs PdxModsUI.

Additional info: This is the main registration point. Bindings include: active screen, save/load triggers, new/load game triggers (with JSON reader types), cloud target selection, map filter selection, save preview, themes/maps/saves listings, mods UI toggles, and more. Many bindings use ValueWriters/ListWriters to convert to UI format.

  • protected override void OnWorldReady()
    Called when world is ready; it updates prerequisites bindings, registers PrefabSystem content-availability changed handler, and subscribes to AssetDatabase change events for clouds, maps, and saves.

Additional info: Subscriptions ensure the menu updates in response to asset DB changes.

  • protected override void OnGameLoaded(Context serializationContext)
    Invoked when the game world has finished loading. Updates current game mode binding.

Additional info: Used to reflect the loaded game mode name in the menu UI after a load.

  • protected override void OnDestroy()
    Cleans up: disposes PdxModsUI, unsubscribes from AssetDatabase events, unregisters PrefabSystem callbacks, and calls base.OnDestroy.

  • public void PreDeserialize(Context context)
    Implements IPreDeserialize. If the deserialize purpose is Cleanup resets active screen to default (0).

  • private void OnContentAvailabilityChanged(ContentPrefab contentPrefab)
    Called when prefab content availability changes; updates owned prerequisite binding and refreshes maps/saves.

  • private void UpdateClouds(AssetChangedEventArgs args)
    Handler for cloud changes. Schedules UI updates on main thread: refreshes available cloud targets and selected cloud target binding.

  • private void UpdateMaps(AssetChangedEventArgs args) / private void UpdateMaps()
    AssetDatabase handler that refreshes available map filters, ensures selected filter is valid, and updates the maps binding using MenuHelpers.UpdateMeta with FilterMaps callback.

  • private void UpdateSaves(AssetChangedEventArgs args) / private void UpdateSaves()
    Refreshes saves list and updates UI continue binding.

  • private void OnSaveGameScreenVisibilityChanged(bool visible)
    When save-game screen is shown, constructs a save-preview URI (screencapture://...) and updates m_SavePreviewBinding; clears it when hidden.

Additional info: Uses m_PreviewSettings and s_PreviewId to avoid cache collisions.

  • private void ApplyTutorialSettings(bool showTutorials, bool resetTutorials)
    Applies tutorial visibility and optionally resets tutorial seen flags in shared settings.

  • private bool IsEditorEnabled()
    Returns whether the editor should be available (checks modding disabled config and platform).

  • private bool IsModsUIActive()
    Returns whether PdxModsUI is currently active.

  • private void ShowModsUI()
    Opens Paradox Mods UI if the platform has UGC privilege; special handling for PlayStation to integrate with platform UI callbacks.

  • private async void OnPSModsUIClosed()
    PlayStation-specific flow executed when the PS mods UI closes: checks active playset mods and notifies paradoxBindings if mods should be deactivated.

  • private List<string> GetCreditFiles()
    Returns the list of markdown files shown in the Credits dialog.

  • private List<ThemeInfo> GetThemes()
    Constructs and returns available themes (hard-coded example: European and North American).

  • private void SafeContinueGame() / private async Task ContinueGame()
    Enqueues and executes continue-game behavior: loads the last save if valid and updates bindings. Handles OperationCanceledException and logs other exceptions.

Additional info: Sets m_MapMetadataSystem.mapName and PlatformManager.instance.achievementsEnabled based on save read-only flag.

  • private void SafeNewGame(NewGameArgs args) / private async Task NewGame(NewGameArgs args)
    Enqueues and starts a new game on background task. Finds the selected map, applies overrides (theme, game mode, city options), sets starting year, and calls GameManager.instance.Load for Purpose.NewGame.

Additional info: ApplyOptions is used to set city configuration overrides and write values into SharedSettings.userState.

  • private void SafeLoadGame(LoadGameArgs args, bool dismiss) / private async Task LoadGame(LoadGameArgs args, bool dismiss)
    Enqueues and performs load of a selected save. Optionally dismisses the load confirmation. Applies overrides and calls GameManager.instance.Load for Purpose.LoadGame.

  • private void ApplyOptions(string cityName, Dictionary<string, bool> options)
    Applies per-game options to CityConfigurationSystem and persists corresponding SharedSettings.userState flags (left-hand traffic, natural disasters, unlocks, unlimited money, unlock map tiles), then saves user state.

  • public SaveInfo GetSaveInfo(bool autoSave)
    Gathers snapshot information for a save: theme, city name, population, money, XP, simulation date, options, map name, whether save is autoSave, used mods, and current game mode.

  • private void SafeSaveGame(string saveName) / private async Task SaveGame(string saveName)
    Enqueues and performs a save flow: gets a save preview texture, picks the selected cloud database, checks overwrite confirmation (HandlesOverwrite), shows pause menu during save, and calls GameManager.instance.Save. Updates the last save name and last selected cloud target on success.

  • private bool SaveExists(ILocalAssetDatabase database, string name, out PackageAsset asset)
    Helper that checks if a save with a given name exists in the provided database.

  • private Task<bool> HandlesOverwrite(ILocalAssetDatabase database, string saveName)
    If a save exists and the user hasn't dismissed overwrite confirmations, shows a confirmation dialog and returns a Task that completes with the user's answer. Otherwise returns true immediately.

  • private void SafeQuickSave() / private async Task QuickSave()
    Performs a quicksave: determines save name (last save name or city name or fallback), captures a RenderTexture preview via ScreenCaptureHelper, builds SaveInfo, checks overwrite, and calls GameManager.instance.Save. Ensures to destroy the temporary render target afterwards.

  • private void SafeQuickLoad(bool dismiss) / private async Task QuickLoad(bool dismiss)
    If dismiss is requested, adds the dismissed confirmation and attempts to continue from the last save when possible.

  • public void DeleteSave(string guid)
    Deletes a save by GUID using SaveHelpers.DeleteSaveGame.

  • public void ShareSave(string id)
    Finds the SaveInfo by id and opens the asset upload UI for that save's metadata.

  • public void ShareMap(string id)
    Finds the MapInfo by id and opens the asset upload UI for the map's metadata.

  • private async void StartEditor()
    Starts the editor mode (GameMode.Editor, Purpose.NewMap) by calling GameManager.instance.Load. Resets override flags before loading.

  • private async void ExitToMainMenu()
    Exits to main menu via GameManager.instance.MainMenu; also resets override flags.

  • private void SelectCloudTarget(string cloudTarget)
    Updates SharedSettings.instance.userState.lastCloudTarget and references chosen database properties.

  • private SaveabilityStatus GetSaveabilityStatus()
    Returns whether saving is possible (dependent on available cloud targets) and provides a reasonHash when saving is not possible.

  • private GameOptions GetGameOptions()
    Returns a GameOptions instance representing the current city configuration flags and used mods.

  • private static bool IsDefaultAsset(IAssetData asset)
    Helper that checks whether an asset is from the default game AssetDatabase.

  • private HashSet<int> GetAvailableMapFilters()
    Scans all map assets and returns a set of available map filter tabs (0 for default maps, 1 for custom maps).

  • private void OnSelectMapFilter(int tab)
    Handler that updates selected map filter and refreshes the map list.

  • private bool FilterMaps(Metadata<MapInfo> meta)
    Filtering callback used by UpdateMaps to decide which maps to show based on the selected map filter and whether prerequisites are met.

Usage Example

// Simple example showing how to change the active menu screen and trigger a continue action.
// Typically you interact with MenuUISystem via the UI bindings, but as a modder you might
// get the system from the world and call methods directly.

var menuSystem = World.DefaultGameObjectInjectionWorld.GetOrCreateSystemManaged<Game.UI.Menu.MenuUISystem>();

// Switch to the LoadGame screen
menuSystem.activeScreen = Game.UI.Menu.MenuUISystem.MenuScreen.LoadGame;

// Trigger continue (this enqueues an async continue task)
menuSystem.SafeContinueGame();

Additional notes: - Many save/load/new operations run asynchronously via TaskManager and GameManager; exceptions are caught and logged; OperationCanceledException is expected when a task is cancelled. - UI updates that must run on the main thread use GameManager.instance.RunOnMainThread. - For modders: prefer using the same bindings/events when integrating custom UI panels; the system uses MenuHelpers.UpdateMeta and AssetDatabase subscriptions to keep lists current.