Game.PSI.PdxSdk.PdxModsUI
Assembly: Game
Namespace: Game.PSI.PdxSdk
Type: public class PdxModsUI
Base: IPdxModsUI, IDisposable
Summary:
PdxModsUI is the game's integration point for Paradox Mods UI (ModsUI). It provides:
- a platform reference (PdxSdkPlatform) and helpers to show/destroy the Mods UI,
- properties used by the PDX SDK (locale, input mode, view adapter and logger),
- lifecycle/event wiring to keep the Mods UI in sync with game input/device and localization changes.
The class contains two important nested helper types: - ColossalUIViewAdapter (implements ICohtmlViewAdapter): wraps a Colossal UI UIView, manages an input barrier, exposes binding/event helpers, and forwards UI text input/caret events back to the game input system. - ModsUILogger (derives from LogService): routes PDX Mod UI logs into the game's Colossal log with mapping between log levels.
Notes: - uiViewAdapter returns a new ColossalUIViewAdapter instance each time it is accessed. - GetInputMode() maps the game's control scheme and gamepad type to the PDX SDK InputMode enum and throws if it encounters an unknown scheme/type.
Fields
-
private static ILog log
Static logger for this class (Colossal.Logging.ILog). It's initialized from LogManager with the name "PdxModsUI" and configured to not show errors in the UI. -
private static readonly string kModsUIHost
Constant host name for the Mods UI host ("modsui"). -
private static readonly string kModsUIUri
Constant URI constructed from the host ("assetdb://modsui/index.html"). Used when creating the Colossal UIView. -
private PdxSdkPlatform m_PdxPlatform
Back-reference to the platform integration (PdxSdkPlatform). Used to forward calls such as ShowModsUI, DestroyModsUI, ChangeModsUILanguage and UpdateInputMode.
Properties
-
public PdxSdkPlatform platform { get; }
Returns the current PdxSdkPlatform instance (backed by m_PdxPlatform). May be null if not registered. -
public string locale { get; }
Returns the current active locale id converted to the PDX language format. Implementation: GameManager.instance.localizationManager.activeLocaleId.ToPdxLanguage().ToString().Replace('_','-'). -
public ICohtmlViewAdapter uiViewAdapter { get; }
Creates and returns a new ColossalUIViewAdapter each call. The adapter provides view creation, binding, event registration and input/caret forwarding to the InputManager. -
public ILogService logger { get; }
Creates and returns a new ModsUILogger(LogLevel.L2_Warning) instance. This is the log service passed to the SDK. -
public bool isActive { get; }
True when m_PdxPlatform is not null and the platform reports its mods UI active (m_PdxPlatform.isModsUIActive).
Constructors
public PdxModsUI()
Sets up event wiring and platform discovery:- Subscribes to Game.Input.InputManager.instance.EventActiveDeviceChanged to track input device/scheme changes.
- Subscribes to GameManager.instance.localizationManager.onActiveDictionaryChanged to update the Mods UI language when locale changes.
- Obtains a PdxSdkPlatform via PlatformManager.instance.GetPSI
("PdxSdk") and calls SetPdxModsUI(this) if available. - Registers a PlatformManager.instance.onPlatformRegistered callback to pick up the platform if it is registered later and call SetPdxModsUI(this).
This ensures the PdxModsUI gets a reference to the platform when it becomes available and that it reacts to input device and locale changes.
Methods
-
public void Show()
Requests the platform to show the Mods UI: m_PdxPlatform?.ShowModsUI(). -
public void Destroy()
Requests the platform to destroy/close the Mods UI: m_PdxPlatform?.DestroyModsUI(). -
private void OnActiveDeviceChanged(InputDevice newDevice, InputDevice oldDevice, bool schemeChanged)
Internal event handler invoked when the active input device changes. If the control scheme changed or the active scheme is the Gamepad scheme, calls m_PdxPlatform?.UpdateInputMode() to update UI hints/input mode. -
private void UpdateLocale()
Internal handler for localization changes. Calls m_PdxPlatform?.ChangeModsUILanguage(locale) to update the Mods UI language. -
public void Dispose()
Unsubscribes from EventActiveDeviceChanged and onActiveDictionaryChanged. This cleans up event subscriptions established in the constructor. -
public InputMode GetInputMode()
Maps the game's input state to the PDX SDK InputMode enum: - KeyboardAndMouse => InputMode.KeyboardAndMouse
- Gamepad => maps Game.Input.InputManager.GamepadType:
- Xbox => InputMode.XboxSeriesXS
- PS => InputMode.PS5 Throws an Exception for unknown control schemes or unknown gamepad types with messages:
- "Unknown control scheme {activeControlScheme}"
- "Unknown control scheme {activeControlScheme} with gamepad {finalInputHintsType}"
Nested types behavior (overview):
- ColossalUIViewAdapter
- Manages a UIView created via UIManager.defaultUISystem.CreateView(kModsUIUri, settings).
- Creates an InputBarrier via Game.Input.InputManager.instance.CreateGlobalBarrier("ColossalUIViewAdapter") and toggles it when Enable()/Disable() are called.
- Listens to UIView.Listener.ReadyForBindings, TextInputTypeChanged and CaretRectChanged and forwards changes to the InputManager (hasInputFieldFocus, caretRect).
- Exposes methods: Enable, Disable, Reload, BindCall, RegisterForEvent, UnbindCall, UnregisterFromEvent, TriggerEvent, AddHostLocation, RemoveHostLocation, Dispose.
- BindCall/RegisterForEvent throw Exception("Not ready for bindings") if the view is not ready.
-
ReadyForBindings event is raised when the underlying UIView signals readiness.
-
ModsUILogger
- Implements WriteLogEntry to map LogService log levels to the Colossal logging methods (log.Info/log.Warn/log.Error).
- Formats source based on callerFilePath when source is null.
Usage Example
// Create and show the Mods UI
var modsUI = new PdxModsUI();
modsUI.Show();
// Create an adapter to interact with the Cohtml view (each access returns a new adapter)
using (var adapter = (Game.PSI.PdxSdk.PdxModsUI).uiViewAdapter) {
// Wait for ReadyForBindings event before binding or registering calls/events
adapter.ReadyForBindings += () => {
adapter.BindCall("someCallFromJS", new Action(() => Debug.Log("Called from JS")));
adapter.RegisterForEvent("someEvent", new Action<object>((msg) => Debug.Log("Event: " + msg)));
};
// Example: add host locations so the view can resolve assets
adapter.AddHostLocation("ModsUI", new List<string> { "Assets/ModsUI" });
// enable/disable the view
adapter.Enable();
// ...
adapter.Disable();
}
// Destroy and cleanup when done
modsUI.Destroy();
modsUI.Dispose();
Notes: - The adapter must be ready (ReadyForBindings) before calling BindCall/RegisterForEvent; otherwise those methods will throw an exception. - uiViewAdapter returns a fresh ColossalUIViewAdapter; remember to Dispose the adapter to avoid leaking the underlying UIView and InputBarrier.