Ss14 ui eui and ui manager

From space-sunrise/sunrise-station · View interactive version

Ss14 ui eui and ui manager is an AI agent skill from the GitHub repository space-sunrise/sunrise-station. An in-depth practical guide to the combination of EUI, UserInterfaceSystem and UserInterfaceManager in SS14: choosing an approach, lifecycle, state/message exchange, window management via UIController and secure network patterns.

How to use this skill

Skill file

EUI + UserInterfaceSystem + UserInterfaceManager

This skill only covers UI lifecycle architecture and networking for interfaces :)

Details of XAML layout and styling are provided in separate skills.

Source of truth and selection of examples

  1. Priority: current engine code and current game code.
  2. Use the documentation from docs as a secondary source.
  3. Do not use a code older than 2 years.
  4. Do not use examples with TODO/FIXME/problematic comments on the UI grid and lifecycle.

When to choose what

  1. Local window/widget without server state?
  1. Is the interface tied to the entity and its components?
  1. Server-side dialog/control panel that doesn't have to live on the entity?

Mental model

Patterns

Anti-patterns

Code examples

Example 1: secure window lifecycle in `UIController`

public sealed class OptionsUIController : UIController
{
    private OptionsMenu _optionsWindow = default!;

    private void EnsureWindow()
    {
        if (_optionsWindow is { Disposed: false })
            return;

        // Creation via UIManager, not direct new.
        _optionsWindow = UIManager.CreateWindow<OptionsMenu>();
    }

    public void ToggleWindow()
    {
        EnsureWindow();

        if (_optionsWindow.IsOpen)
            _optionsWindow.Close();
        else
            _optionsWindow.OpenCentered();
    }
}

Example 2: entity-bound UI (BUI) with windowed view

protected override void Open()
{
    base.Open();

    // We create a window as part of the lifecycle BUI.
    _menu = this.CreateWindow<JukeboxMenu>();

    _menu.OnPlayPressed += shouldPlay =>
    {
        // The client sends a typed message to the BUI server part.
        SendMessage(shouldPlay ? new JukeboxPlayingMessage() : new JukeboxPauseMessage());
    };

    _menu.OnStopPressed += () => SendMessage(new JukeboxStopMessage());
}

Example 3: Restoring the window position for the BUI

public static T CreateWindow<T>(this BoundUserInterface bui) where T : BaseWindow, new()
{
    var window = GetWindow<T>(bui);

    if (bui.EntMan.System<UserInterfaceSystem>().TryGetPosition(bui.Owner, bui.UiKey, out var position))
        window.Open(position);
    else
        window.OpenCentered();

    return window;
}

Example 4: server-side EUI manager and deferred state sending

public void QueueStateUpdate(BaseEui eui)
{
    _stateUpdateQueue.Enqueue((eui.Player, eui.Id));
}

public void SendUpdates()
{
    while (_stateUpdateQueue.TryDequeue(out var tuple))
    {
        var (player, id) = tuple;
        if (!_playerData.TryGetValue(player, out var plyDat) || !plyDat.OpenUIs.TryGetValue(id, out var ui))
            continue;

        // Real state sending in one place lifecycle.
        ui.DoStateUpdate();
    }
}

Example 5: type-safe EUI state + client-side application

[Serializable, NetSerializable]
public sealed class PlayerPanelEuiState(
    NetUserId guid,
    string username,
    TimeSpan playtime)
    : EuiStateBase
{
    public readonly NetUserId Guid = guid;
    public readonly string Username = username;
    public readonly TimeSpan Playtime = playtime;
}

public override void HandleState(EuiStateBase state)
{
    if (state is not PlayerPanelEuiState s)
        return;

    // The UI is updated from the state snapshot.
    PlayerPanel.SetUsername(s.Username);
    PlayerPanel.SetPlaytime(s.Playtime);
}

Mini checklist

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.