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>
347 lines
12 KiB
C#
347 lines
12 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Client.Input;
|
|
using Robust.Client.Player;
|
|
using Robust.Client.ResourceManagement;
|
|
using Robust.Client.State;
|
|
using Robust.Client.Timing;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.CustomControls;
|
|
using Robust.Shared;
|
|
using Robust.Shared.Configuration;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Input;
|
|
using Robust.Shared.Input.Binding;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Maths;
|
|
using Robust.Shared.Network;
|
|
using Robust.Shared.Profiling;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Reflection;
|
|
using Robust.Shared.Timing;
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
namespace Robust.Client.UserInterface
|
|
{
|
|
internal sealed partial class UserInterfaceManager : IUserInterfaceManagerInternal
|
|
{
|
|
[Dependency] private readonly IInputManager _inputManager = default!;
|
|
[Dependency] private readonly IFontManager _fontManager = default!;
|
|
[Dependency] private readonly IClydeInternal _clyde = default!;
|
|
[Dependency] private readonly IClientGameTiming _gameTiming = default!;
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
|
[Dependency] private readonly IStateManager _stateManager = default!;
|
|
[Dependency] private readonly IClientNetManager _netManager = default!;
|
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
|
[Dependency] private readonly IPrototypeManager _protoManager = default!;
|
|
[Dependency] private readonly IUserInterfaceManagerInternal _userInterfaceManager = default!;
|
|
[Dependency] private readonly IResourceCache _resourceCache = default!;
|
|
[Dependency] private readonly IDynamicTypeFactoryInternal _typeFactory = default!;
|
|
[Dependency] private readonly IUserInterfaceManager _uiManager = default!;
|
|
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
|
|
[Dependency] private readonly ProfManager _prof = default!;
|
|
[Dependency] private readonly IReflectionManager _reflectionManager = default!;
|
|
[Dependency] private readonly IEntitySystemManager _systemManager = default!;
|
|
|
|
[ViewVariables] public InterfaceTheme ThemeDefaults { get; private set; } = default!;
|
|
[ViewVariables]
|
|
public Stylesheet? Stylesheet
|
|
{
|
|
get => _stylesheet;
|
|
set
|
|
{
|
|
_stylesheet = value;
|
|
|
|
foreach (var root in _roots)
|
|
{
|
|
if (root.Stylesheet != null)
|
|
{
|
|
root.StylesheetUpdateRecursive();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
[ViewVariables] public ViewportContainer MainViewport { get; private set; } = default!;
|
|
[ViewVariables] public LayoutContainer StateRoot { get; private set; } = default!;
|
|
[ViewVariables] public PopupContainer ModalRoot { get; private set; } = default!;
|
|
[ViewVariables] public WindowRoot RootControl { get; private set; } = default!;
|
|
[ViewVariables] public LayoutContainer WindowRoot { get; private set; } = default!;
|
|
[ViewVariables] public LayoutContainer PopupRoot { get; private set; } = default!;
|
|
[ViewVariables] public DropDownDebugConsole DebugConsole { get; private set; } = default!;
|
|
[ViewVariables] public IDebugMonitors DebugMonitors => _debugMonitors;
|
|
private DebugMonitors _debugMonitors = default!;
|
|
|
|
private bool _rendering = true;
|
|
|
|
private readonly Queue<Control> _styleUpdateQueue = new();
|
|
private readonly Queue<Control> _measureUpdateQueue = new();
|
|
private readonly Queue<Control> _arrangeUpdateQueue = new();
|
|
private Stylesheet? _stylesheet;
|
|
|
|
public void Initialize()
|
|
{
|
|
_configurationManager.OnValueChanged(CVars.DisplayUIScale, _uiScaleChanged, true);
|
|
ThemeDefaults = new InterfaceThemeDummy();
|
|
_initScaling();
|
|
_setupControllers();
|
|
_initializeCommon();
|
|
|
|
DebugConsole = new DropDownDebugConsole();
|
|
RootControl.AddChild(DebugConsole);
|
|
DebugConsole.SetPositionInParent(ModalRoot.GetPositionInParent());
|
|
|
|
_debugMonitors = new DebugMonitors(_gameTiming, _playerManager, _eyeManager, _inputManager, _stateManager,
|
|
_clyde, _netManager, _mapManager);
|
|
DebugConsole.BelowConsole.AddChild(_debugMonitors);
|
|
|
|
_inputManager.SetInputCommand(EngineKeyFunctions.ShowDebugConsole,
|
|
InputCmdHandler.FromDelegate(session => DebugConsole.Toggle()));
|
|
|
|
_inputManager.SetInputCommand(EngineKeyFunctions.ShowDebugMonitors,
|
|
InputCmdHandler.FromDelegate(enabled: session => { DebugMonitors.Visible = true; },
|
|
disabled: session => { DebugMonitors.Visible = false; }));
|
|
|
|
_inputManager.SetInputCommand(EngineKeyFunctions.HideUI,
|
|
InputCmdHandler.FromDelegate(
|
|
enabled: session => _rendering = false,
|
|
disabled: session => _rendering = true));
|
|
|
|
_inputManager.UIKeyBindStateChanged += OnUIKeyBindStateChanged;
|
|
_initThemes();
|
|
}
|
|
public void PostInitialize()
|
|
{
|
|
_initializeScreens();
|
|
_initializeControllers();
|
|
}
|
|
private void _initializeCommon()
|
|
{
|
|
RootControl = CreateWindowRoot(_clyde.MainWindow);
|
|
RootControl.Name = "MainWindowRoot";
|
|
_clyde.DestroyWindow += WindowDestroyed;
|
|
|
|
MainViewport = new MainViewportContainer(_eyeManager)
|
|
{
|
|
Name = "MainViewport"
|
|
};
|
|
RootControl.AddChild(MainViewport);
|
|
|
|
StateRoot = new LayoutContainer
|
|
{
|
|
Name = "StateRoot",
|
|
MouseFilter = Control.MouseFilterMode.Ignore
|
|
};
|
|
RootControl.AddChild(StateRoot);
|
|
|
|
WindowRoot = new LayoutContainer
|
|
{
|
|
Name = "WindowRoot",
|
|
MouseFilter = Control.MouseFilterMode.Ignore
|
|
};
|
|
RootControl.AddChild(WindowRoot);
|
|
|
|
ModalRoot = new PopupContainer
|
|
{
|
|
Name = "ModalRoot",
|
|
MouseFilter = Control.MouseFilterMode.Ignore,
|
|
};
|
|
RootControl.AddChild(ModalRoot);
|
|
|
|
PopupRoot = new LayoutContainer
|
|
{
|
|
Name = "PopupRoot",
|
|
MouseFilter = Control.MouseFilterMode.Ignore
|
|
};
|
|
RootControl.AddChild(PopupRoot);
|
|
|
|
_tooltip = new Tooltip();
|
|
PopupRoot.AddChild(_tooltip);
|
|
_tooltip.Visible = false;
|
|
}
|
|
|
|
public void InitializeTesting()
|
|
{
|
|
ThemeDefaults = new InterfaceThemeDummy();
|
|
|
|
_initializeCommon();
|
|
}
|
|
|
|
public event Action<PostDrawUIRootEventArgs>? OnPostDrawUIRoot;
|
|
|
|
private void WindowDestroyed(WindowDestroyedEventArgs args)
|
|
{
|
|
DestroyWindowRoot(args.Window);
|
|
}
|
|
|
|
public void FrameUpdate(FrameEventArgs args)
|
|
{
|
|
using (_prof.Group("Update"))
|
|
{
|
|
foreach (var root in _roots)
|
|
{
|
|
using (_prof.Group("Root"))
|
|
{
|
|
var totalUpdated = root.DoFrameUpdateRecursive(args);
|
|
|
|
_prof.WriteValue("Total", ProfData.Int32(totalUpdated));
|
|
}
|
|
}
|
|
}
|
|
|
|
// Process queued style & layout updates.
|
|
using (_prof.Group("Style"))
|
|
{
|
|
var total = 0;
|
|
while (_styleUpdateQueue.Count != 0)
|
|
{
|
|
var control = _styleUpdateQueue.Dequeue();
|
|
|
|
if (control.Disposed)
|
|
continue;
|
|
|
|
control.DoStyleUpdate();
|
|
total += 1;
|
|
}
|
|
|
|
_prof.WriteValue("Total", ProfData.Int32(total));
|
|
}
|
|
|
|
using (_prof.Group("Measure"))
|
|
{
|
|
var total = 0;
|
|
while (_measureUpdateQueue.Count != 0)
|
|
{
|
|
var control = _measureUpdateQueue.Dequeue();
|
|
|
|
if (control.Disposed)
|
|
continue;
|
|
|
|
RunMeasure(control);
|
|
total += 1;
|
|
}
|
|
|
|
_prof.WriteValue("Total", ProfData.Int32(total));
|
|
}
|
|
|
|
using (_prof.Group("Arrange"))
|
|
{
|
|
var total = 0;
|
|
while (_arrangeUpdateQueue.Count != 0)
|
|
{
|
|
var control = _arrangeUpdateQueue.Dequeue();
|
|
|
|
if (control.Disposed)
|
|
continue;
|
|
|
|
RunArrange(control);
|
|
total += 1;
|
|
}
|
|
|
|
_prof.WriteValue("Total", ProfData.Int32(total));
|
|
}
|
|
|
|
UpdateControllers(args);
|
|
|
|
// count down tooltip delay if we're not showing one yet and
|
|
// are hovering the mouse over a control without moving it
|
|
if (_tooltipDelay != null && !showingTooltip)
|
|
{
|
|
_tooltipTimer += args.DeltaSeconds;
|
|
if (_tooltipTimer >= _tooltipDelay)
|
|
{
|
|
_showTooltip();
|
|
}
|
|
}
|
|
|
|
if (_needUpdateActiveCursor)
|
|
{
|
|
_needUpdateActiveCursor = false;
|
|
UpdateActiveCursor();
|
|
}
|
|
}
|
|
|
|
private void _render(IRenderHandle renderHandle, ref int total, Control control, Vector2i position, Color modulate,
|
|
UIBox2i? scissorBox)
|
|
{
|
|
if (!control.Visible)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// Manual clip test with scissor region as optimization.
|
|
var controlBox = UIBox2i.FromDimensions(position, control.PixelSize);
|
|
|
|
if (scissorBox != null)
|
|
{
|
|
var clipMargin = control.RectDrawClipMargin;
|
|
var clipTestBox = new UIBox2i(controlBox.Left - clipMargin, controlBox.Top - clipMargin,
|
|
controlBox.Right + clipMargin, controlBox.Bottom + clipMargin);
|
|
|
|
if (!scissorBox.Value.Intersects(clipTestBox))
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
var clip = control.RectClipContent;
|
|
var scissorRegion = scissorBox;
|
|
if (clip)
|
|
{
|
|
scissorRegion = controlBox;
|
|
if (scissorBox != null)
|
|
{
|
|
// Make the final scissor region a sub region of scissorBox
|
|
var s = scissorBox.Value;
|
|
var result = s.Intersection(scissorRegion.Value);
|
|
if (result == null)
|
|
{
|
|
// Uhm... No intersection so... don't draw anything at all?
|
|
return;
|
|
}
|
|
|
|
scissorRegion = result.Value;
|
|
}
|
|
|
|
renderHandle.SetScissor(scissorRegion);
|
|
}
|
|
|
|
total += 1;
|
|
|
|
var handle = renderHandle.DrawingHandleScreen;
|
|
handle.SetTransform(position, Angle.Zero, Vector2.One);
|
|
modulate *= control.Modulate;
|
|
|
|
if (_rendering || control.AlwaysRender)
|
|
{
|
|
// Handle modulation with care.
|
|
var oldMod = handle.Modulate;
|
|
handle.Modulate = modulate * control.ActualModulateSelf;
|
|
control.DrawInternal(renderHandle);
|
|
handle.Modulate = oldMod;
|
|
handle.UseShader(null);
|
|
}
|
|
|
|
foreach (var child in control.Children)
|
|
{
|
|
_render(renderHandle, ref total, child, position + child.PixelPosition, modulate, scissorRegion);
|
|
}
|
|
|
|
if (clip)
|
|
{
|
|
renderHandle.SetScissor(scissorBox);
|
|
}
|
|
}
|
|
|
|
public Color GetMainClearColor() => RootControl.ActualBgColor;
|
|
|
|
~UserInterfaceManager()
|
|
{
|
|
ClearWindows();
|
|
}
|
|
}
|
|
}
|