fix: фиксы под тесты
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
using Content.Client.Actions;
|
||||
using Content.Client.Gameplay;
|
||||
using Content.Client.UserInterface.Systems.Actions;
|
||||
using Content.Client.UserInterface.Systems.Gameplay;
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Borer;
|
||||
@@ -14,8 +12,7 @@ using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.Borer;
|
||||
|
||||
|
||||
public sealed class ReagentUIController : UIController, IOnSystemChanged<ActionsSystem>, IOnStateEntered<GameplayState>
|
||||
public sealed class ReagentUIController : UIController, IOnSystemChanged<ActionsSystem>
|
||||
{
|
||||
[Dependency] private readonly GameplayStateLoadController _gameplayStateLoad = default!;
|
||||
[UISystemDependency] private readonly SharedBorerSystem _borerSystem = default!;
|
||||
@@ -23,17 +20,16 @@ public sealed class ReagentUIController : UIController, IOnSystemChanged<Actions
|
||||
|
||||
private ReagentWindow? _window;
|
||||
|
||||
private bool _reagentsLoaded = false;
|
||||
private bool _reagentsLoaded;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
|
||||
_gameplayStateLoad.OnScreenLoad += LoadGui;
|
||||
_gameplayStateLoad.OnScreenUnload += UnloadGui;
|
||||
|
||||
SubscribeLocalEvent<BorerInjectWindowOpenEvent>(ev =>
|
||||
SubscribeLocalEvent<BorerInjectWindowOpenEvent>(_ =>
|
||||
{
|
||||
OpenWindow();
|
||||
});
|
||||
@@ -44,6 +40,10 @@ public sealed class ReagentUIController : UIController, IOnSystemChanged<Actions
|
||||
DebugTools.Assert(_window == null);
|
||||
_window = UIManager.CreateWindow<ReagentWindow>();
|
||||
LayoutContainer.SetAnchorPreset(_window, LayoutContainer.LayoutPreset.CenterTop);
|
||||
|
||||
CommandBinds.Builder
|
||||
.Bind(ContentKeyFunctions.OpenActionsMenu, InputCmdHandler.FromDelegate(_ => OpenWindow()))
|
||||
.Register<ReagentWindow>();
|
||||
}
|
||||
|
||||
private void UnloadGui()
|
||||
@@ -53,29 +53,35 @@ public sealed class ReagentUIController : UIController, IOnSystemChanged<Actions
|
||||
_window.Dispose();
|
||||
_window = null;
|
||||
}
|
||||
|
||||
CommandBinds.Unregister<ReagentWindow>();
|
||||
}
|
||||
|
||||
private void OnInjectReagent(string protoId, int cost)
|
||||
{
|
||||
_borerSystem.RaiseInjectEvent(protoId, cost);
|
||||
}
|
||||
|
||||
private void OpenWindow()
|
||||
{
|
||||
var ent = _playerManager.LocalEntity;
|
||||
if (_window == null || _window.IsOpen || !ent.HasValue)
|
||||
return;
|
||||
|
||||
if (!_reagentsLoaded)
|
||||
{
|
||||
foreach (var reagent in _borerSystem.GetReagents(ent.Value))
|
||||
{
|
||||
var button = new Button();
|
||||
button.Text = Loc.GetString("borer-ui-secrete-inject-label",
|
||||
("reagent",Loc.GetString("reagent-name-"+
|
||||
reagent.Key.ToLower().Replace("spacedrugs", "space-drugs"))),
|
||||
("reagent", Loc.GetString("reagent-name-" +
|
||||
reagent.Key.ToLower().Replace("spacedrugs", "space-drugs"))),
|
||||
("cost", reagent.Value));
|
||||
|
||||
button.OnPressed += _ => OnInjectReagent(reagent.Key, reagent.Value);
|
||||
_window.MainContainer.AddChild(button);
|
||||
}
|
||||
|
||||
_reagentsLoaded = true;
|
||||
}
|
||||
|
||||
@@ -95,16 +101,4 @@ public sealed class ReagentUIController : UIController, IOnSystemChanged<Actions
|
||||
private void OnComponentLinked(ActionsComponent component)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnStateEntered(GameplayState state)
|
||||
{
|
||||
CommandBinds.Builder
|
||||
.Bind(ContentKeyFunctions.OpenActionsMenu, InputCmdHandler.FromDelegate(_ => OpenWindow()))
|
||||
.Register<ReagentWindow>();
|
||||
}
|
||||
|
||||
public void OnStateExited(GameplayState state)
|
||||
{
|
||||
CommandBinds.Unregister<ReagentWindow>();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user