using System; using Robust.Client.GameObjects; using Robust.Client.UserInterface.CustomControls; using Robust.Shared.GameObjects; namespace Robust.Client.UserInterface; public static class BoundUserInterfaceExt { private static T GetWindow(BoundUserInterface bui) where T : BaseWindow, new() { var window = bui.CreateDisposableControl(); window.OnClose += bui.Close; var system = bui.EntMan.System(); system.RegisterControl(bui, window); return window; } /// /// Helper method to create a window and also handle closing the BUI when it's closed. /// public static T CreateWindow(this BoundUserInterface bui) where T : BaseWindow, new() { var window = GetWindow(bui); if (bui.EntMan.System().TryGetPosition(bui.Owner, bui.UiKey, out var position)) { window.Open(position); } else { window.OpenCentered(); } return window; } public static T CreateWindowCenteredLeft(this BoundUserInterface bui) where T : BaseWindow, new() { var window = GetWindow(bui); if (bui.EntMan.System().TryGetPosition(bui.Owner, bui.UiKey, out var position)) { window.Open(position); } else { window.OpenCenteredLeft(); } return window; } public static T CreateWindowCenteredRight(this BoundUserInterface bui) where T : BaseWindow, new() { var window = GetWindow(bui); if (bui.EntMan.System().TryGetPosition(bui.Owner, bui.UiKey, out var position)) { window.Open(position); } else { window.OpenCenteredRight(); } return window; } /// /// Creates a control for this BUI that will be disposed when it is disposed. /// /// /// /// public static T CreateDisposableControl(this BoundUserInterface bui) where T : Control, IDisposable, new() { var control = new T(); bui.Disposals ??= []; bui.Disposals.Add(control); return control; } }