Fix & extend add reagent verb (#4954)
* AddReagentWindow * addReagent command * functional UI * fix networking * add comments & docstrings * Remove unecesary system * cleanup & close-eui * tweak default window size * fix EUI closing error * fix merge issues * fix merge
This commit is contained in:
@@ -1,95 +0,0 @@
|
||||
using Content.Server.Administration.Managers;
|
||||
using Content.Server.Chemistry.Components.SolutionManager;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.EUI;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Eui;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Administration.UI
|
||||
{
|
||||
public sealed class AdminAddReagentEui : BaseEui
|
||||
{
|
||||
private readonly IEntity _target;
|
||||
[Dependency] private readonly IAdminManager _adminManager = default!;
|
||||
|
||||
public AdminAddReagentEui(IEntity target)
|
||||
{
|
||||
_target = target;
|
||||
|
||||
IoCManager.InjectDependencies(this);
|
||||
}
|
||||
|
||||
public override void Opened()
|
||||
{
|
||||
StateDirty();
|
||||
}
|
||||
|
||||
public override EuiStateBase GetNewState()
|
||||
{
|
||||
if (EntitySystem.Get<SolutionContainerSystem>()
|
||||
.TryGetSolution(_target.Uid, "default", out var container))
|
||||
{
|
||||
return new AdminAddReagentEuiState
|
||||
{
|
||||
CurVolume = container.CurrentVolume,
|
||||
MaxVolume = container.MaxVolume
|
||||
};
|
||||
}
|
||||
|
||||
return new AdminAddReagentEuiState
|
||||
{
|
||||
CurVolume = FixedPoint2.Zero,
|
||||
MaxVolume = FixedPoint2.Zero
|
||||
};
|
||||
}
|
||||
|
||||
public override void HandleMessage(EuiMessageBase msg)
|
||||
{
|
||||
switch (msg)
|
||||
{
|
||||
case AdminAddReagentEuiMsg.Close:
|
||||
Close();
|
||||
break;
|
||||
case AdminAddReagentEuiMsg.DoAdd doAdd:
|
||||
// Double check that user wasn't de-adminned in the mean time...
|
||||
// Or the target was deleted.
|
||||
if (!_adminManager.HasAdminFlag(Player, AdminFlags.Fun) || _target.Deleted)
|
||||
{
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
var id = doAdd.ReagentId;
|
||||
var amount = doAdd.Amount;
|
||||
var solutionsSys = EntitySystem.Get<SolutionContainerSystem>();
|
||||
|
||||
if (_target.TryGetComponent(out InjectableSolutionComponent? injectable)
|
||||
&& solutionsSys.TryGetSolution(_target.Uid, injectable.Name, out var targetSolution))
|
||||
{
|
||||
var solution = new Solution(id, amount);
|
||||
solutionsSys.Inject(_target.Uid, targetSolution, solution);
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO decide how to find the solution
|
||||
if (solutionsSys.TryGetSolution(_target.Uid, "default", out var solution))
|
||||
{
|
||||
solutionsSys.TryAddReagent(_target.Uid,solution, id, amount, out _);
|
||||
}
|
||||
}
|
||||
|
||||
StateDirty();
|
||||
|
||||
if (doAdd.CloseAfter)
|
||||
Close();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
54
Content.Server/Administration/UI/EditSolutionsEui.cs
Normal file
54
Content.Server/Administration/UI/EditSolutionsEui.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Content.Server.Chemistry.Components.SolutionManager;
|
||||
using Content.Server.EUI;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Eui;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Administration.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// Admin Eui for displaying and editing the reagents in a solution.
|
||||
/// </summary>
|
||||
[UsedImplicitly]
|
||||
public sealed class EditSolutionsEui : BaseEui
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
public readonly EntityUid Target;
|
||||
|
||||
public EditSolutionsEui(EntityUid entity)
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
Target = entity;
|
||||
}
|
||||
|
||||
public override void Opened()
|
||||
{
|
||||
base.Opened();
|
||||
StateDirty();
|
||||
}
|
||||
|
||||
public override void Closed()
|
||||
{
|
||||
base.Closed();
|
||||
EntitySystem.Get<AdminVerbSystem>().OnEditSolutionsEuiClosed(Player);
|
||||
}
|
||||
|
||||
public override EuiStateBase GetNewState()
|
||||
{
|
||||
var solutions = _entityManager.GetComponentOrNull<SolutionContainerManagerComponent>(Target)?.Solutions;
|
||||
return new EditSolutionsEuiState(Target, solutions);
|
||||
}
|
||||
|
||||
public override void HandleMessage(EuiMessageBase msg)
|
||||
{
|
||||
switch (msg)
|
||||
{
|
||||
case EditSolutionsEuiMsg.Close:
|
||||
Close();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user