mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
* UIControllerManager Implemented UI Controller Manager * added fetch function * added note * Hiding some internal stuff * Implemented event on gamestate switch for ui * Fix serialization field assigner emit * fixing issues with ILEmitter stuff * AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH Blame Smug * fixing nullref * Add checking for no backing field / property for ui system dependencies * fixes Gamestate detection * Implemented event on UIControllers on system load * Updated systemload/unload listeners * Had this backwards lol * Fix nulling systems before calling OnSystemUnloaded, broke InventoryUIController.Hands.cs * Created UI Window management system - A manager that allows for easy creation and access of popup or gamestate windows * Changing to use basewindow instead of default window * Implemented UI Theming that isn't ass * Updated default theme loading and validation * Added path validation for themes * Implemented UI Themes * Implemented UI Theme prototypes * Implementing theming for texture buttons and Texturerects * fixing server error * Remove IUILink * Implemented default theme overriding and theme colors * Fixing sandbox lul * Added error for not finding UITheme * fixing setting default theme in content * Move entity and tile spawn window logic to controllers * Add 2 TODOs * Merge fixes * Add IOnStateChanged for UI controllers * Fix inventory window being slow to open Caches resources when the UI theme is changed * Remove caching on theme change The real fix was fixing the path for resources * Remove test method * Fix crash when controllers implement non generic interfaces * Add controllers frame update * Split UserInterfaceManager into partials - Created UI screen * Converted more UI managers into partials * Setup UIScreen manager system * Added some widget utility funcs updated adding widgets * Started removing HUDManager * Moved UiController Manager to Partials Finished moving all UIController code to UIManager * Fixed screen loading * Fixed Screen scaling * Fixed Screen scaling cleanup * wat * IwantToDie * Fixed resolving ResourceCache instead of IResourceCache * Split IOnStateChanged into IOnStateEntered and IOnStateExited * Implemented helpers for adjusting UIAutoscale for screens * Fixed autoscale, removed archiving from autoscale * Implemented popups and adjusted some stuff * Fixing some popup related shinanegans * Fixing some draw order issues * fixing dumb shit * Fix indentation in UserInterfaceManager.Input.cs * Moved screen setup to post init (run after content) * Fix updating theme * Merge fixes * Fix resolving sprite system on control creation * Fix min size of tile spawn window * Add UIController.Initialize method * https://tenor.com/view/minor-spelling-mistake-gif-21179057 * Add doc comment to UIController * Split UIController.cs and UISystemDependency.cs into their own files * Add more documentation to ui controllers * Add AttributeUsage to UISystemDependencyAttribute * Fix method naming * Add documentation for assigners * Return casted widgets where relevant * Fix entity spawner scroll (#1) * Add CloseOnClick and CloseOnEscape for popups * Remove named windows and popups * Cleanup controller code * Add IOnStateChanged, IOnSystemChanged, IOnSystemLoaded, IOnSystemUnloaded * Add more docs to state and system change interfaces * Fixing Window issues * Fixing some window fuckery * Added OnOpen event to windows, updated sandbox window Sandbox windows now persist values and positions * Recurse through controls to register widgets (#2) * Allow path to be folder * Fix local player shutdown * Fixing escape menu * Fix backing field in DataDefinition.Emitters * Ent+Tile spawn no crash * Skip no-spawn in entity spawn menu Co-authored-by: Jezithyr <jmaster9999@gmail.com> Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> Co-authored-by: Jezithyr <Jezithyr@gmail.com> Co-authored-by: wrexbe <81056464+wrexbe@users.noreply.github.com> Co-authored-by: Flipp Syder <76629141+vulppine@users.noreply.github.com> Co-authored-by: wrexbe <wrexbe@protonmail.com>
119 lines
3.7 KiB
C#
119 lines
3.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Robust.Client.State;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.CustomControls;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Robust.Client.UserInterface;
|
|
|
|
internal partial class UserInterfaceManager
|
|
{
|
|
private readonly Dictionary<Type, Queue<BaseWindow>> _windowsByType = new();
|
|
private readonly Dictionary<Type, Queue<Popup>> _popupsByType = new();
|
|
|
|
public T CreatePopup<T>() where T : Popup, new()
|
|
{
|
|
var newPopup = _typeFactory.CreateInstance<T>();
|
|
_popupsByType.GetOrNew(typeof(T)).Enqueue(newPopup);
|
|
ModalRoot.AddChild(newPopup);
|
|
return newPopup;
|
|
}
|
|
|
|
public bool RemoveFirstPopup<T>() where T : Popup, new()
|
|
{
|
|
if (!_popupsByType.TryGetValue(typeof(T),out var popupQueue)) return false;
|
|
var oldPopup = popupQueue.Dequeue();
|
|
if (popupQueue.Count == 0)
|
|
{
|
|
_popupsByType.Remove(typeof(T));
|
|
}
|
|
oldPopup.Close();
|
|
oldPopup.Dispose();
|
|
return true;
|
|
}
|
|
|
|
public bool TryGetFirstPopup<T>(out T? popup) where T : Popup, new()
|
|
{
|
|
popup = null;
|
|
var success = _popupsByType.TryGetValue(typeof(T), out var win);
|
|
if (win is {Count: > 0})
|
|
{
|
|
popup = (T)win.Peek();
|
|
}
|
|
return success;
|
|
}
|
|
|
|
public bool TryGetFirstPopup(Type type, out Popup? popup)
|
|
{
|
|
popup = null;
|
|
if (!typeof(Popup).IsAssignableFrom(type)) return false;
|
|
if (!_popupsByType.TryGetValue(type, out var popupQueue) || popupQueue.Count == 0) return false;
|
|
popup = popupQueue.Peek();
|
|
return true;
|
|
}
|
|
|
|
public bool RemoveFirstWindow<T>() where T : BaseWindow, new()
|
|
{
|
|
if (!_windowsByType.TryGetValue(typeof(T),out var windowQueue)) return false;
|
|
var oldWindow = windowQueue.Dequeue();
|
|
if (windowQueue.Count == 0)
|
|
{
|
|
_windowsByType.Remove(typeof(T));
|
|
}
|
|
_uiManager.StateRoot.RemoveChild(oldWindow);
|
|
oldWindow.Dispose();
|
|
return true;
|
|
}
|
|
|
|
public T GetFirstWindow<T>() where T : BaseWindow, new()
|
|
{
|
|
if (!_windowsByType.TryGetValue(typeof(T), out var windowQueue) || windowQueue.Count == 0)
|
|
throw new Exception("Window of type" + typeof(T) + " not found!");
|
|
return (T)windowQueue.Peek();
|
|
}
|
|
|
|
public T CreateWindow<T>() where T : BaseWindow, new()
|
|
{
|
|
//If we sandbox this we break creating engine windows. The argument is type bounded anyway so it only accepts
|
|
//public classes that inherit from BaseWindow.
|
|
var newWindow = _typeFactory.CreateInstanceUnchecked<T>();
|
|
_windowsByType.GetOrNew(typeof(T)).Enqueue(newWindow);
|
|
return newWindow;
|
|
}
|
|
|
|
private void RegisterWindowOfType(BaseWindow window)
|
|
{
|
|
if (_windowsByType.ContainsKey(window.GetType())) return;
|
|
_windowsByType.GetOrNew(window.GetType()).Enqueue(window);
|
|
}
|
|
|
|
public bool TryGetFirstWindow<T>(out T? window) where T : BaseWindow, new()
|
|
{
|
|
window = null;
|
|
var success = _windowsByType.TryGetValue(typeof(T), out var win);
|
|
if (win is {Count: > 0})
|
|
{
|
|
window = (T)win.Peek();
|
|
}
|
|
return success;
|
|
}
|
|
|
|
public bool TryGetFirstWindow(Type type, out BaseWindow? window)
|
|
{
|
|
window = null;
|
|
if (!typeof(BaseWindow).IsAssignableFrom(type)) return false;
|
|
if (!_windowsByType.TryGetValue(type, out var winQueue) || winQueue.Count == 0) return false;
|
|
window = winQueue.Peek();
|
|
return true;
|
|
}
|
|
public void ClearWindows()
|
|
{
|
|
foreach (var data in _windowsByType)
|
|
{
|
|
data.Value.Dequeue().Dispose();
|
|
}
|
|
_windowsByType.Clear();
|
|
}
|
|
}
|