diff --git a/Content.Client/Administration/UI/Tabs/AdminbusTab/AdminbusTab.xaml.cs b/Content.Client/Administration/UI/Tabs/AdminbusTab/AdminbusTab.xaml.cs index 3d3b1e7118..4383300cee 100644 --- a/Content.Client/Administration/UI/Tabs/AdminbusTab/AdminbusTab.xaml.cs +++ b/Content.Client/Administration/UI/Tabs/AdminbusTab/AdminbusTab.xaml.cs @@ -1,9 +1,11 @@ using System.IO; using Content.Client.Administration.Managers; using Content.Client.Sandbox; +using Content.Client.UserInterface.Systems.DecalPlacer; using Content.Shared.Administration; using Robust.Client.AutoGenerated; using Robust.Client.UserInterface; +using Robust.Client.UserInterface.Controllers.Implementations; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.XAML; @@ -46,17 +48,17 @@ namespace Content.Client.Administration.UI.Tabs.AdminbusTab private void SpawnEntitiesButtonOnPressed(BaseButton.ButtonEventArgs obj) { - EntitySystem.Get().ToggleEntitySpawnWindow(); + IoCManager.Resolve().GetUIController().ToggleWindow(); } private void SpawnTilesButtonOnOnPressed(BaseButton.ButtonEventArgs obj) { - EntitySystem.Get().ToggleTilesWindow(); + IoCManager.Resolve().GetUIController().ToggleWindow(); } private void SpawnDecalsButtonOnPressed(BaseButton.ButtonEventArgs obj) { - EntitySystem.Get().ToggleDecalsWindow(); + IoCManager.Resolve().GetUIController().ToggleWindow(); } } } diff --git a/Content.Client/Changelog/ChangelogButton.cs b/Content.Client/Changelog/ChangelogButton.cs index 6b1116cca0..b029770857 100644 --- a/Content.Client/Changelog/ChangelogButton.cs +++ b/Content.Client/Changelog/ChangelogButton.cs @@ -1,7 +1,7 @@ using Content.Client.Stylesheets; +using Content.Client.UserInterface.Systems.EscapeMenu; +using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; -using Robust.Shared.IoC; -using Robust.Shared.Localization; namespace Content.Client.Changelog { @@ -13,7 +13,7 @@ namespace Content.Client.Changelog { IoCManager.InjectDependencies(this); - OnPressed += OnOnPressed; + OnPressed += OnChangelogPressed; // So that measuring before opening returns a correct height, // and the window has the correct size when opened. @@ -35,9 +35,9 @@ namespace Content.Client.Changelog _changelogManager.NewChangelogEntriesChanged -= UpdateStuff; } - private void OnOnPressed(ButtonEventArgs obj) + private void OnChangelogPressed(ButtonEventArgs obj) { - new ChangelogWindow().OpenCentered(); + IoCManager.Resolve().GetUIController().ToggleWindow(); } private void UpdateStuff() diff --git a/Content.Client/Changelog/ChangelogWindow.xaml.cs b/Content.Client/Changelog/ChangelogWindow.xaml.cs index 2134f8275a..f666693772 100644 --- a/Content.Client/Changelog/ChangelogWindow.xaml.cs +++ b/Content.Client/Changelog/ChangelogWindow.xaml.cs @@ -1,6 +1,7 @@ using System.Linq; using Content.Client.Resources; using Content.Client.Stylesheets; +using Content.Client.UserInterface.Systems.EscapeMenu; using Content.Shared.Administration; using JetBrains.Annotations; using Robust.Client.AutoGenerated; @@ -204,7 +205,7 @@ namespace Content.Client.Changelog public void Execute(IConsoleShell shell, string argStr, string[] args) { - new ChangelogWindow().OpenCentered(); + IoCManager.Resolve().GetUIController().ToggleWindow(); } } } diff --git a/Content.Client/Decals/UI/DecalPlacerWindow.xaml.cs b/Content.Client/Decals/UI/DecalPlacerWindow.xaml.cs index d6fb41aafd..51f48e6927 100644 --- a/Content.Client/Decals/UI/DecalPlacerWindow.xaml.cs +++ b/Content.Client/Decals/UI/DecalPlacerWindow.xaml.cs @@ -7,7 +7,6 @@ using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.CustomControls; using Robust.Client.UserInterface.XAML; using Robust.Client.Utility; -using Robust.Shared.Prototypes; using static Robust.Client.UserInterface.Controls.BaseButton; namespace Content.Client.Decals.UI; @@ -15,7 +14,6 @@ namespace Content.Client.Decals.UI; [GenerateTypedNameReferences] public sealed partial class DecalPlacerWindow : DefaultWindow { - private readonly IPrototypeManager _prototypeManager; private readonly DecalPlacementSystem _decalPlacementSystem; public FloatSpinBox RotationSpinBox; @@ -31,11 +29,10 @@ public sealed partial class DecalPlacerWindow : DefaultWindow private bool _cleanable; private int _zIndex; - public DecalPlacerWindow(IPrototypeManager prototypeManager) + public DecalPlacerWindow() { RobustXamlLoader.Load(this); - _prototypeManager = prototypeManager; _decalPlacementSystem = EntitySystem.Get(); // This needs to be done in C# so we can have custom stuff passed in the constructor @@ -98,8 +95,6 @@ public sealed partial class DecalPlacerWindow : DefaultWindow }; // i have to make this a member method for some reason and i have no idea why its only for spinboxes ZIndexSpinBox.ValueChanged += ZIndexSpinboxChanged; - - Populate(); } private void OnColorPicked(Color color) @@ -173,9 +168,8 @@ public sealed partial class DecalPlacerWindow : DefaultWindow RefreshList(); } - public void Populate() + public void Populate(IEnumerable prototypes) { - var prototypes = _prototypeManager.EnumeratePrototypes(); _decals = new Dictionary(); foreach (var decalPrototype in prototypes) { diff --git a/Content.Client/Entry/EntryPoint.cs b/Content.Client/Entry/EntryPoint.cs index b8ab52922e..cc71f8431d 100644 --- a/Content.Client/Entry/EntryPoint.cs +++ b/Content.Client/Entry/EntryPoint.cs @@ -49,7 +49,6 @@ namespace Content.Client.Entry { [Dependency] private readonly IPlayerManager _playerManager = default!; [Dependency] private readonly IBaseClient _baseClient = default!; - [Dependency] private readonly IEscapeMenuOwner _escapeMenuOwner = default!; [Dependency] private readonly IGameController _gameController = default!; [Dependency] private readonly IStateManager _stateManager = default!; [Dependency] private readonly IEntityManager _entityManager = default!; @@ -130,8 +129,6 @@ namespace Content.Client.Entry IoCManager.Resolve().OverrideDefault(CVars.NetBufferSize, NetBufferSizeOverride); #endif - _escapeMenuOwner.Initialize(); - _baseClient.PlayerJoinedServer += (_, _) => { IoCManager.Resolve().CreateNewMapEntity(MapId.Nullspace); diff --git a/Content.Client/Info/RulesAndInfoWindow.cs b/Content.Client/Info/RulesAndInfoWindow.cs index 60351247a3..fde0394974 100644 --- a/Content.Client/Info/RulesAndInfoWindow.cs +++ b/Content.Client/Info/RulesAndInfoWindow.cs @@ -1,4 +1,5 @@ using Content.Client.Options.UI; +using Content.Client.UserInterface.Systems.EscapeMenu; using Robust.Client.ResourceManagement; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; @@ -15,13 +16,10 @@ namespace Content.Client.Info [Dependency] private readonly IEntitySystemManager _sysMan = default!; [Dependency] private readonly RulesManager _rules = default!; - private OptionsMenu optionsMenu; - public RulesAndInfoWindow() { IoCManager.InjectDependencies(this); - optionsMenu = new OptionsMenu(); Title = Loc.GetString("ui-info-title"); @@ -52,7 +50,12 @@ namespace Content.Client.Info AddSection(tutorialList, Loc.GetString("ui-info-header-gameplay"), "Gameplay.txt", true); AddSection(tutorialList, Loc.GetString("ui-info-header-sandbox"), "Sandbox.txt", true); - infoControlSection.ControlsButton.OnPressed += _ => optionsMenu.OpenCentered(); + infoControlSection.ControlsButton.OnPressed += OnOptionsPressed; + } + + private void OnOptionsPressed(BaseButton.ButtonEventArgs obj) + { + IoCManager.Resolve().GetUIController().ToggleWindow(); } private static void AddSection(Info info, Control control) diff --git a/Content.Client/IoC/ClientContentIoC.cs b/Content.Client/IoC/ClientContentIoC.cs index e8ee8389a0..cde59b9268 100644 --- a/Content.Client/IoC/ClientContentIoC.cs +++ b/Content.Client/IoC/ClientContentIoC.cs @@ -30,7 +30,6 @@ namespace Content.Client.IoC IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); - IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); diff --git a/Content.Client/Lobby/LobbyState.cs b/Content.Client/Lobby/LobbyState.cs index 47c0a69993..7f4a98542a 100644 --- a/Content.Client/Lobby/LobbyState.cs +++ b/Content.Client/Lobby/LobbyState.cs @@ -9,6 +9,7 @@ using Content.Client.Lobby.UI; using Content.Client.Preferences; using Content.Client.Preferences.UI; using Content.Client.Resources; +using Content.Client.UserInterface.Systems.EscapeMenu; using Content.Client.Voting; using Content.Shared.GameTicking; using Robust.Client; @@ -106,7 +107,7 @@ namespace Content.Client.Lobby }; _lobby.LeaveButton.OnPressed += _ => _consoleHost.ExecuteCommand("disconnect"); - _lobby.OptionsButton.OnPressed += _ => new OptionsMenu().Open(); + _lobby.OptionsButton.OnPressed += OnOptionsPressed; _gameTicker.InfoBlobUpdated += UpdateLobbyUi; @@ -114,6 +115,11 @@ namespace Content.Client.Lobby _gameTicker.LobbyLateJoinStatusUpdated += LobbyLateJoinStatusUpdated; } + private void OnOptionsPressed(BaseButton.ButtonEventArgs obj) + { + IoCManager.Resolve().GetUIController().ToggleWindow(); + } + protected override void Shutdown() { _gameTicker.InfoBlobUpdated -= UpdateLobbyUi; diff --git a/Content.Client/MainMenu/MainMenu.cs b/Content.Client/MainMenu/MainMenu.cs index 47bc8a4910..8a3c3b02ab 100644 --- a/Content.Client/MainMenu/MainMenu.cs +++ b/Content.Client/MainMenu/MainMenu.cs @@ -2,6 +2,7 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using Content.Client.Options.UI; using Content.Client.MainMenu.UI; +using Content.Client.UserInterface.Systems.EscapeMenu; using Robust.Client; using Robust.Client.ResourceManagement; using Robust.Client.UserInterface; @@ -28,7 +29,6 @@ namespace Content.Client.MainMenu [Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!; private MainMenuControl _mainMenuControl = default!; - private OptionsMenu _optionsMenu = default!; private bool _isConnecting; // ReSharper disable once InconsistentNaming @@ -46,8 +46,6 @@ namespace Content.Client.MainMenu _mainMenuControl.AddressBox.OnTextEntered += AddressBoxEntered; _client.RunLevelChanged += RunLevelChanged; - - _optionsMenu = new OptionsMenu(); } /// @@ -57,7 +55,6 @@ namespace Content.Client.MainMenu _netManager.ConnectFailed -= _onConnectFailed; _mainMenuControl.Dispose(); - _optionsMenu.Dispose(); } private void QuitButtonPressed(BaseButton.ButtonEventArgs args) @@ -67,7 +64,7 @@ namespace Content.Client.MainMenu private void OptionsButtonPressed(BaseButton.ButtonEventArgs args) { - _optionsMenu.OpenCentered(); + IoCManager.Resolve().GetUIController().ToggleWindow(); } private void DirectConnectButtonPressed(BaseButton.ButtonEventArgs args) diff --git a/Content.Client/Options/EscapeMenuOwner.cs b/Content.Client/Options/EscapeMenuOwner.cs deleted file mode 100644 index 426921c759..0000000000 --- a/Content.Client/Options/EscapeMenuOwner.cs +++ /dev/null @@ -1,89 +0,0 @@ -using Content.Client.Gameplay; -using Content.Client.HUD; -using Content.Client.Viewport; -using Robust.Client.Console; -using Robust.Client.Input; -using Robust.Client.State; -using Robust.Shared.Input; -using Robust.Shared.Input.Binding; -using Robust.Shared.IoC; - -namespace Content.Client.Options -{ - internal sealed class EscapeMenuOwner : IEscapeMenuOwner - { - [Dependency] private readonly IClientConsoleHost _consoleHost = default!; - [Dependency] private readonly IInputManager _inputManager = default!; - [Dependency] private readonly IStateManager _stateManager = default!; - [Dependency] private readonly IGameHud _gameHud = default!; - - private UI.EscapeMenu? _escapeMenu; - - public void Initialize() - { - _stateManager.OnStateChanged += StateManagerOnOnStateChanged; - - _gameHud.EscapeButtonToggled += _setOpenValue; - } - - private void StateManagerOnOnStateChanged(StateChangedEventArgs obj) - { - if (obj.NewState is GameplayStateBase) - { - // Switched TO GameScreen. - _escapeMenu = new UI.EscapeMenu(_consoleHost); - - _escapeMenu.OnClose += () => _gameHud.EscapeButtonDown = false; - - _inputManager.SetInputCommand(EngineKeyFunctions.EscapeMenu, - InputCmdHandler.FromDelegate(_ => Enabled())); - } - else if (obj.OldState is GameplayStateBase) - { - // Switched FROM GameScreen. - _escapeMenu?.Dispose(); - _escapeMenu = null; - - _inputManager.SetInputCommand(EngineKeyFunctions.EscapeMenu, null); - } - } - - private void Enabled() - { - if (_escapeMenu != null && _escapeMenu.IsOpen) - { - if (_escapeMenu.IsAtFront()) - { - _setOpenValue(false); - } - else - { - _escapeMenu.MoveToFront(); - } - } - else - { - _setOpenValue(true); - } - } - - private void _setOpenValue(bool value) - { - if (value) - { - _gameHud.EscapeButtonDown = true; - _escapeMenu?.OpenCentered(); - } - else - { - _gameHud.EscapeButtonDown = false; - _escapeMenu?.Close(); - } - } - } - - public interface IEscapeMenuOwner - { - void Initialize(); - } -} diff --git a/Content.Client/Options/UI/EscapeMenu.xaml b/Content.Client/Options/UI/EscapeMenu.xaml index 3095d07a71..cb7edb921a 100644 --- a/Content.Client/Options/UI/EscapeMenu.xaml +++ b/Content.Client/Options/UI/EscapeMenu.xaml @@ -1,16 +1,17 @@ - - + -