using Friflo.Engine.ECS.Systems; using Microsoft.Xna.Framework; using Myra; using Myra.Graphics2D.UI; using MrGameEng.Core; namespace MrGameEng.UI; /// /// Draw system rendering the scene's Myra . Must run after the scene's /// world rendering (register UI last in the draw phase) — the UI is drawn on top in window /// pixels and also processes mouse/keyboard interaction during render. /// public sealed class UiRenderSystem : BaseSystem { private readonly Desktop _desktop; /// Creates the system for . public UiRenderSystem(Desktop desktop) => _desktop = desktop; /// protected override void OnUpdateGroup() => _desktop.Render(); } /// Wires the UI module (Myra) into a . public static class SceneUiExtensions { private static bool _environmentInitialized; /// /// Creates a Myra for this scene and registers /// in the draw phase. Call from OnLoad /// after UseRenderer2D() so the UI draws on top of the world. /// Build the UI by assigning . /// public static Desktop UseUI(this Scene scene) { // Геттер MyraEnvironment.Game бросает исключение, пока Game не задан — проверять через ??= нельзя. if (!_environmentInitialized) { MyraEnvironment.Game = scene.Context.Services.Get(); _environmentInitialized = true; } var desktop = new Desktop(); scene.DrawSystems.Add(new UiRenderSystem(desktop)); return desktop; } }