mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Move escape menu out of engine.
This commit is contained in:
@@ -5,6 +5,8 @@ namespace Robust.Client.Interfaces.State
|
||||
{
|
||||
public interface IStateManager
|
||||
{
|
||||
event Action<StateChangedEventArgs> OnStateChanged;
|
||||
|
||||
Client.State.State CurrentState { get; }
|
||||
void RequestStateChange<T>() where T : Client.State.State, new();
|
||||
void Update(ProcessFrameEventArgs e);
|
||||
@@ -15,4 +17,16 @@ namespace Robust.Client.Interfaces.State
|
||||
void MouseWheelMove(MouseWheelEventArgs e);
|
||||
void FormResize();
|
||||
}
|
||||
|
||||
public sealed class StateChangedEventArgs : EventArgs
|
||||
{
|
||||
public StateChangedEventArgs(Client.State.State oldState, Client.State.State newState)
|
||||
{
|
||||
OldState = oldState;
|
||||
NewState = newState;
|
||||
}
|
||||
|
||||
public Client.State.State OldState { get; }
|
||||
public Client.State.State NewState { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,7 +268,6 @@
|
||||
<Compile Include="UserInterface\Controls\HBoxContainer.cs" />
|
||||
<Compile Include="UserInterface\CustomControls\DebugConsole.cs" />
|
||||
<Compile Include="UserInterface\CustomControls\SS14Window.cs" />
|
||||
<Compile Include="UserInterface\CustomControls\EscapeMenu.cs" />
|
||||
<Compile Include="UserInterface\CustomControls\FPSCounter.cs" />
|
||||
<Compile Include="UserInterface\CustomControls\DebugNetPanel.cs" />
|
||||
<Compile Include="UserInterface\CustomControls\OptionsMenu.cs" />
|
||||
|
||||
@@ -6,10 +6,11 @@ using Robust.Shared.IoC;
|
||||
|
||||
namespace Robust.Client.State
|
||||
{
|
||||
public class StateManager : IStateManager
|
||||
internal sealed class StateManager : IStateManager
|
||||
{
|
||||
[Dependency] private readonly IDynamicTypeFactory _typeFactory;
|
||||
|
||||
public event Action<StateChangedEventArgs> OnStateChanged;
|
||||
public State CurrentState { get; private set; }
|
||||
|
||||
#region Updates & Statechanges
|
||||
@@ -48,10 +49,13 @@ namespace Robust.Client.State
|
||||
|
||||
var newState = (State)_typeFactory.CreateInstance(type);
|
||||
|
||||
var old = CurrentState;
|
||||
CurrentState?.Shutdown();
|
||||
|
||||
CurrentState = newState;
|
||||
CurrentState.Startup();
|
||||
|
||||
OnStateChanged?.Invoke(new StateChangedEventArgs(old, CurrentState));
|
||||
}
|
||||
|
||||
#endregion Updates & Statechanges
|
||||
|
||||
@@ -5,7 +5,6 @@ using Robust.Client.Interfaces.Graphics.ClientEye;
|
||||
using Robust.Client.Interfaces.Input;
|
||||
using Robust.Client.Interfaces.Placement;
|
||||
using Robust.Client.Interfaces.UserInterface;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
@@ -13,15 +12,10 @@ using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Robust.Client.Console;
|
||||
using Robust.Client.GameObjects.EntitySystems;
|
||||
using Robust.Client.Interfaces.Graphics;
|
||||
using Robust.Client.Interfaces.ResourceManagement;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Shared.Interfaces.Configuration;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.Interfaces.Timing;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Robust.Client.State.States
|
||||
{
|
||||
@@ -39,59 +33,21 @@ namespace Robust.Client.State.States
|
||||
[Dependency] private readonly IEyeManager eyeManager;
|
||||
[Dependency] private readonly IEntitySystemManager entitySystemManager;
|
||||
[Dependency] private readonly IGameTiming timing;
|
||||
[Dependency] private readonly IClientConsole _console;
|
||||
[Dependency] private readonly IPrototypeManager prototypeManager;
|
||||
[Dependency] private readonly IResourceCache resourceCache;
|
||||
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager;
|
||||
[Dependency] private readonly IDisplayManager _displayManager;
|
||||
[Dependency] private readonly IConfigurationManager _configurationManager;
|
||||
[Dependency] private readonly IMapManager _mapManager;
|
||||
|
||||
private EscapeMenu escapeMenu;
|
||||
private IEntity lastHoveredEntity;
|
||||
|
||||
public override void Startup()
|
||||
{
|
||||
inputManager.KeyBindStateChanged += OnKeyBindStateChanged;
|
||||
|
||||
escapeMenu = new EscapeMenu(_displayManager,_console, _tileDefinitionManager,
|
||||
placementManager, prototypeManager, resourceCache, _configurationManager)
|
||||
{
|
||||
Visible = false
|
||||
};
|
||||
escapeMenu.AddToScreen();
|
||||
|
||||
var escapeMenuCommand = InputCmdHandler.FromDelegate(session =>
|
||||
{
|
||||
if (escapeMenu.Visible)
|
||||
{
|
||||
if (escapeMenu.IsAtFront())
|
||||
{
|
||||
escapeMenu.Visible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
escapeMenu.MoveToFront();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
escapeMenu.OpenCentered();
|
||||
}
|
||||
});
|
||||
inputManager.SetInputCommand(EngineKeyFunctions.EscapeMenu, escapeMenuCommand);
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
escapeMenu.Dispose();
|
||||
|
||||
playerManager.LocalPlayer.DetachEntity();
|
||||
|
||||
userInterfaceManager.StateRoot.DisposeAllChildren();
|
||||
|
||||
inputManager.SetInputCommand(EngineKeyFunctions.EscapeMenu, null);
|
||||
|
||||
inputManager.KeyBindStateChanged -= OnKeyBindStateChanged;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.Client.UserInterface.CustomControls
|
||||
{
|
||||
internal class EntitySpawnWindow : SS14Window
|
||||
public sealed class EntitySpawnWindow : SS14Window
|
||||
{
|
||||
protected override ResourcePath ScenePath => new ResourcePath("/Scenes/Placement/EntitySpawnPanel.tscn");
|
||||
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.Console;
|
||||
using Robust.Client.Interfaces.Graphics;
|
||||
using Robust.Client.Interfaces.Placement;
|
||||
using Robust.Client.Interfaces.ResourceManagement;
|
||||
using Robust.Shared.Interfaces.Configuration;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Robust.Client.UserInterface.CustomControls
|
||||
{
|
||||
public class EscapeMenu : SS14Window
|
||||
{
|
||||
private readonly IClientConsole _console;
|
||||
private readonly ITileDefinitionManager __tileDefinitionManager;
|
||||
private readonly IPlacementManager _placementManager;
|
||||
private readonly IPrototypeManager _prototypeManager;
|
||||
private readonly IResourceCache _resourceCache;
|
||||
private readonly IDisplayManager _displayManager;
|
||||
private readonly IConfigurationManager _configSystem;
|
||||
|
||||
private BaseButton QuitButton;
|
||||
private BaseButton OptionsButton;
|
||||
private BaseButton SpawnEntitiesButton;
|
||||
private BaseButton SpawnTilesButton;
|
||||
private OptionsMenu optionsMenu;
|
||||
|
||||
public EscapeMenu(IDisplayManager displayManager,
|
||||
IClientConsole console,
|
||||
ITileDefinitionManager tileDefinitionManager,
|
||||
IPlacementManager placementManager,
|
||||
IPrototypeManager prototypeManager,
|
||||
IResourceCache resourceCache,
|
||||
IConfigurationManager configSystem) : base(displayManager)
|
||||
{
|
||||
_configSystem = configSystem;
|
||||
_displayManager = displayManager;
|
||||
_console = console;
|
||||
__tileDefinitionManager = tileDefinitionManager;
|
||||
_placementManager = placementManager;
|
||||
_prototypeManager = prototypeManager;
|
||||
_resourceCache = resourceCache;
|
||||
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
private void PerformLayout()
|
||||
{
|
||||
optionsMenu = new OptionsMenu(_displayManager, _configSystem)
|
||||
{
|
||||
Visible = false
|
||||
};
|
||||
optionsMenu.AddToScreen();
|
||||
|
||||
Resizable = false;
|
||||
HideOnClose = true;
|
||||
|
||||
Title = "Menu";
|
||||
|
||||
var vBox = new VBoxContainer {SeparationOverride = 2};
|
||||
Contents.AddChild(vBox);
|
||||
|
||||
SpawnEntitiesButton = new Button {Text = "Spawn Entities"};
|
||||
SpawnEntitiesButton.OnPressed += OnSpawnEntitiesButtonClicked;
|
||||
vBox.AddChild(SpawnEntitiesButton);
|
||||
|
||||
SpawnTilesButton = new Button {Text = "Spawn Tiles"};
|
||||
SpawnTilesButton.OnPressed += OnSpawnTilesButtonClicked;
|
||||
vBox.AddChild(SpawnTilesButton);
|
||||
|
||||
// Add a spacer.
|
||||
vBox.AddChild(new Control { CustomMinimumSize = (0, 5)});
|
||||
|
||||
OptionsButton = new Button {Text = "Options"};
|
||||
OptionsButton.OnPressed += OnOptionsButtonClicked;
|
||||
vBox.AddChild(OptionsButton);
|
||||
|
||||
QuitButton = new Button {Text = "Quit"};
|
||||
QuitButton.OnPressed += OnQuitButtonClicked;
|
||||
vBox.AddChild(QuitButton);
|
||||
|
||||
Size = CombinedMinimumSize;
|
||||
}
|
||||
|
||||
private void OnQuitButtonClicked(BaseButton.ButtonEventArgs args)
|
||||
{
|
||||
_console.ProcessCommand("disconnect");
|
||||
Dispose();
|
||||
}
|
||||
|
||||
private void OnOptionsButtonClicked(BaseButton.ButtonEventArgs args)
|
||||
{
|
||||
optionsMenu.OpenCentered();
|
||||
}
|
||||
|
||||
private void OnSpawnEntitiesButtonClicked(BaseButton.ButtonEventArgs args)
|
||||
{
|
||||
var window = new EntitySpawnWindow(_displayManager, _placementManager, _prototypeManager, _resourceCache);
|
||||
window.AddToScreen();
|
||||
window.OpenToLeft();
|
||||
}
|
||||
|
||||
private void OnSpawnTilesButtonClicked(BaseButton.ButtonEventArgs args)
|
||||
{
|
||||
var window = new TileSpawnWindow(__tileDefinitionManager, _placementManager, _displayManager, _resourceCache);
|
||||
window.AddToScreen();
|
||||
window.OpenToLeft();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
if (disposing)
|
||||
{
|
||||
optionsMenu.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ using Robust.Shared.Maths;
|
||||
|
||||
namespace Robust.Client.UserInterface.CustomControls
|
||||
{
|
||||
internal sealed class OptionsMenu : SS14Window
|
||||
public sealed class OptionsMenu : SS14Window
|
||||
{
|
||||
private Button ApplyButton;
|
||||
private CheckBox VSyncCheckBox;
|
||||
|
||||
@@ -15,7 +15,7 @@ using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.Client.UserInterface.CustomControls
|
||||
{
|
||||
internal class TileSpawnWindow : SS14Window
|
||||
public sealed class TileSpawnWindow : SS14Window
|
||||
{
|
||||
private readonly ITileDefinitionManager __tileDefinitionManager;
|
||||
private readonly IPlacementManager _placementManager;
|
||||
|
||||
Reference in New Issue
Block a user