Greetings, Commanders.

This post is a bit different. Usually I write about what you will do in the game, like commanding fleets, designing ships or handling diplomacy. This time I want to write about how you will do it, because I spent the last few weeks rebuilding the whole user interface.

Think about a normal situation in the middle of a game. You are managing three colonies, a fleet is on its way to intercept an enemy, a diplomacy proposal is waiting, and the power grid on your main mining colony is about to fail. If the UI is slow or the information on screen is not up to date, the game stops working. You end up fighting the controls instead of the enemy.

The MVVM Refactor

The game shows a lot of information at the same time, and the old UI did not handle it well. So I removed the old UI systems and moved everything to an MVVM (Model-View-ViewModel) architecture using Unity's UI Toolkit and VisualTreeAssets.

In non-developer terms this means that what you see on screen (the Views) is now separated from the game simulation (the Models). They communicate through a layer in the middle (the ViewModels).

For example, when one of your ships takes damage, the game logic doesn't need to find the health bar and tell it to update. Instead the health bar is "listening" to an Observable<T> property on the ViewModel. When the ship's armor value changes in the simulation, the Observable fires and the health bar updates through its Subscribe() callback. Nobody has to remember to connect these by hand, and forgetting to do that is a common source of UI bugs.

Shared Top UI and Kahn's Algorithm

The MVVM architecture made it possible to build the new Shared Top UI. The global HUD elements, like your credits, the current date and notifications, are registered through a ServiceLocator so they can be accessed from any screen.

The systems also need to start in the right order. All the UI services, and the other game systems too, register themselves at startup. Then I use Kahn's Algorithm (a topological sort) to resolve the dependencies between them. If BudgetUI needs the Players and GameDate systems before it can draw anything, the sort makes sure those systems are initialized first.

The result is that the important information is always visible at the top of the screen, whether you are looking at a colony, the sector map or designing a destroyer in the shipyard. Also, no system tries to draw before the systems it depends on exist.

There is also a new notification system. When a neutral faction contacts you, or an AI fleet changes its behavior, a small notification slides into view. Because of the MVVM structure the notifications are lightweight and don't interrupt what you are doing.

Why Rebuild It Now?

Rebuilding the UI architecture in the middle of development is painful. But it had to be done. The original games used mostly nested menus and static screens. For the remake to feel like a modern game, it needs overlays that update in real time, data binding, and UI code that is separated from the game logic.

This should mean fewer bugs when I add new features, and a smoother interface when the game is released. It is easier to do it now than a year from now.

What's Next

Now that the UI architecture is in place, I'm going back to the tactical layer. The AI fleets are getting an upgrade so they move around the sector in a smarter way.

Signing out,

  • Jari