Remove some BUI boilerplate (#28399)
* Remove some BUI boilerplate - The disposals overrides got removed due to the helper method handling it. - Replace window creation with CreateWindow helper. - Fixed some stinky code which would cause exceptions. * More * moar * weh * done * More BUIs * More updates * weh * moar * look who it is * weh * merge * weh * fixes
This commit is contained in:
@@ -12,42 +12,34 @@ namespace Content.Client.Kitchen.UI
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class GrinderMenu : FancyWindow
|
||||
{
|
||||
private readonly IEntityManager _entityManager;
|
||||
private readonly IPrototypeManager _prototypeManager;
|
||||
private readonly ReagentGrinderBoundUserInterface _owner;
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
private readonly Dictionary<int, EntityUid> _chamberVisualContents = new();
|
||||
|
||||
public GrinderMenu(ReagentGrinderBoundUserInterface owner, IEntityManager entityManager, IPrototypeManager prototypeManager)
|
||||
public event Action? OnToggleAuto;
|
||||
public event Action? OnGrind;
|
||||
public event Action? OnJuice;
|
||||
public event Action? OnEjectAll;
|
||||
public event Action? OnEjectBeaker;
|
||||
public event Action<EntityUid>? OnEjectChamber;
|
||||
|
||||
public GrinderMenu()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
_entityManager = entityManager;
|
||||
_prototypeManager = prototypeManager;
|
||||
_owner = owner;
|
||||
AutoModeButton.OnPressed += owner.ToggleAutoMode;
|
||||
GrindButton.OnPressed += owner.StartGrinding;
|
||||
JuiceButton.OnPressed += owner.StartJuicing;
|
||||
ChamberContentBox.EjectButton.OnPressed += owner.EjectAll;
|
||||
BeakerContentBox.EjectButton.OnPressed += owner.EjectBeaker;
|
||||
IoCManager.InjectDependencies(this);
|
||||
AutoModeButton.OnPressed += _ => OnToggleAuto?.Invoke();
|
||||
GrindButton.OnPressed += _ => OnGrind?.Invoke();
|
||||
JuiceButton.OnPressed += _ => OnJuice?.Invoke();
|
||||
ChamberContentBox.EjectButton.OnPressed += _ => OnEjectAll?.Invoke();
|
||||
BeakerContentBox.EjectButton.OnPressed += _ => OnEjectBeaker?.Invoke();
|
||||
ChamberContentBox.BoxContents.OnItemSelected += OnChamberBoxContentsItemSelected;
|
||||
BeakerContentBox.BoxContents.SelectMode = ItemList.ItemListSelectMode.None;
|
||||
}
|
||||
|
||||
private void OnChamberBoxContentsItemSelected(ItemList.ItemListSelectedEventArgs args)
|
||||
{
|
||||
_owner.EjectChamberContent(_chamberVisualContents[args.ItemIndex]);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
_chamberVisualContents.Clear();
|
||||
GrindButton.OnPressed -= _owner.StartGrinding;
|
||||
JuiceButton.OnPressed -= _owner.StartJuicing;
|
||||
ChamberContentBox.EjectButton.OnPressed -= _owner.EjectAll;
|
||||
BeakerContentBox.EjectButton.OnPressed -= _owner.EjectBeaker;
|
||||
ChamberContentBox.BoxContents.OnItemSelected -= OnChamberBoxContentsItemSelected;
|
||||
OnEjectChamber?.Invoke(_chamberVisualContents[args.ItemIndex]);
|
||||
}
|
||||
|
||||
public void UpdateState(ReagentGrinderInterfaceState state)
|
||||
|
||||
@@ -3,6 +3,7 @@ using Content.Shared.Kitchen.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
@@ -19,28 +20,15 @@ namespace Content.Client.Kitchen.UI
|
||||
|
||||
[ViewVariables]
|
||||
private readonly Dictionary<int, ReagentQuantity> _reagents = new();
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
|
||||
public MicrowaveUpdateUserInterfaceState currentState = default!;
|
||||
|
||||
private IEntityManager _entManager;
|
||||
|
||||
public MicrowaveBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
||||
{
|
||||
_entManager = IoCManager.Resolve<IEntityManager>();
|
||||
}
|
||||
|
||||
public TimeSpan GetCurrentTime()
|
||||
{
|
||||
return _gameTiming.CurTime;
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
_menu = new MicrowaveMenu(this);
|
||||
_menu.OpenCentered();
|
||||
_menu.OnClose += Close;
|
||||
_menu = this.CreateWindow<MicrowaveMenu>();
|
||||
_menu.StartButton.OnPressed += _ => SendPredictedMessage(new MicrowaveStartCookMessage());
|
||||
_menu.EjectButton.OnPressed += _ => SendPredictedMessage(new MicrowaveEjectMessage());
|
||||
_menu.IngredientsList.OnItemSelected += args =>
|
||||
@@ -74,38 +62,23 @@ namespace Content.Client.Kitchen.UI
|
||||
};
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
if (!disposing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_solids.Clear();
|
||||
_menu?.Dispose();
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
base.UpdateState(state);
|
||||
if (state is not MicrowaveUpdateUserInterfaceState cState)
|
||||
if (state is not MicrowaveUpdateUserInterfaceState cState || _menu == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_menu.IsBusy = cState.IsMicrowaveBusy;
|
||||
_menu.CurrentCooktimeEnd = cState.CurrentCookTimeEnd;
|
||||
|
||||
_menu?.ToggleBusyDisableOverlayPanel(cState.IsMicrowaveBusy || cState.ContainedSolids.Length == 0);
|
||||
currentState = cState;
|
||||
|
||||
_menu.ToggleBusyDisableOverlayPanel(cState.IsMicrowaveBusy || cState.ContainedSolids.Length == 0);
|
||||
// TODO move this to a component state and ensure the net ids.
|
||||
RefreshContentsDisplay(_entManager.GetEntityArray(cState.ContainedSolids));
|
||||
|
||||
if (_menu == null) return;
|
||||
RefreshContentsDisplay(EntMan.GetEntityArray(cState.ContainedSolids));
|
||||
|
||||
//Set the cook time info label
|
||||
var cookTime = cState.ActiveButtonIndex == 0
|
||||
var cookTime = cState.ActiveButtonIndex == 0
|
||||
? Loc.GetString("microwave-menu-instant-button")
|
||||
: cState.CurrentCookTime.ToString();
|
||||
|
||||
|
||||
@@ -9,22 +9,20 @@ namespace Content.Client.Kitchen.UI
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class MicrowaveMenu : FancyWindow
|
||||
{
|
||||
public sealed class MicrowaveCookTimeButton : Button
|
||||
{
|
||||
public uint CookTime;
|
||||
}
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
|
||||
public event Action<BaseButton.ButtonEventArgs, int>? OnCookTimeSelected;
|
||||
|
||||
public ButtonGroup CookTimeButtonGroup { get; }
|
||||
private readonly MicrowaveBoundUserInterface _owner;
|
||||
|
||||
public MicrowaveMenu(MicrowaveBoundUserInterface owner)
|
||||
public bool IsBusy;
|
||||
public TimeSpan CurrentCooktimeEnd;
|
||||
|
||||
public MicrowaveMenu()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
CookTimeButtonGroup = new ButtonGroup();
|
||||
InstantCookButton.Group = CookTimeButtonGroup;
|
||||
_owner = owner;
|
||||
InstantCookButton.OnPressed += args =>
|
||||
{
|
||||
OnCookTimeSelected?.Invoke(args, 0);
|
||||
@@ -65,14 +63,20 @@ namespace Content.Client.Kitchen.UI
|
||||
protected override void FrameUpdate(FrameEventArgs args)
|
||||
{
|
||||
base.FrameUpdate(args);
|
||||
if(!_owner.currentState.IsMicrowaveBusy)
|
||||
|
||||
if (!IsBusy)
|
||||
return;
|
||||
|
||||
if(_owner.currentState.CurrentCookTimeEnd > _owner.GetCurrentTime())
|
||||
if (CurrentCooktimeEnd > _timing.CurTime)
|
||||
{
|
||||
CookTimeInfoLabel.Text = Loc.GetString("microwave-bound-user-interface-cook-time-label",
|
||||
("time",_owner.currentState.CurrentCookTimeEnd.Subtract(_owner.GetCurrentTime()).Seconds));
|
||||
("time", CurrentCooktimeEnd.Subtract(_timing.CurTime).Seconds));
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MicrowaveCookTimeButton : Button
|
||||
{
|
||||
public uint CookTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using Content.Shared.Kitchen;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
@@ -8,8 +9,6 @@ namespace Content.Client.Kitchen.UI
|
||||
{
|
||||
public sealed class ReagentGrinderBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
[ViewVariables]
|
||||
private GrinderMenu? _menu;
|
||||
|
||||
@@ -21,20 +20,13 @@ namespace Content.Client.Kitchen.UI
|
||||
{
|
||||
base.Open();
|
||||
|
||||
_menu = new GrinderMenu(this, EntMan, _prototypeManager);
|
||||
_menu.OpenCentered();
|
||||
_menu.OnClose += Close;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
if (!disposing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_menu?.Dispose();
|
||||
_menu = this.CreateWindow<GrinderMenu>();
|
||||
_menu.OnToggleAuto += ToggleAutoMode;
|
||||
_menu.OnGrind += StartGrinding;
|
||||
_menu.OnJuice += StartJuicing;
|
||||
_menu.OnEjectAll += EjectAll;
|
||||
_menu.OnEjectBeaker += EjectBeaker;
|
||||
_menu.OnEjectChamber += EjectChamberContent;
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
@@ -52,27 +44,27 @@ namespace Content.Client.Kitchen.UI
|
||||
_menu?.HandleMessage(message);
|
||||
}
|
||||
|
||||
public void ToggleAutoMode(BaseButton.ButtonEventArgs args)
|
||||
public void ToggleAutoMode()
|
||||
{
|
||||
SendMessage(new ReagentGrinderToggleAutoModeMessage());
|
||||
}
|
||||
|
||||
public void StartGrinding(BaseButton.ButtonEventArgs? _ = null)
|
||||
public void StartGrinding()
|
||||
{
|
||||
SendMessage(new ReagentGrinderStartMessage(GrinderProgram.Grind));
|
||||
}
|
||||
|
||||
public void StartJuicing(BaseButton.ButtonEventArgs? _ = null)
|
||||
public void StartJuicing()
|
||||
{
|
||||
SendMessage(new ReagentGrinderStartMessage(GrinderProgram.Juice));
|
||||
}
|
||||
|
||||
public void EjectAll(BaseButton.ButtonEventArgs? _ = null)
|
||||
public void EjectAll()
|
||||
{
|
||||
SendMessage(new ReagentGrinderEjectChamberAllMessage());
|
||||
}
|
||||
|
||||
public void EjectBeaker(BaseButton.ButtonEventArgs? _ = null)
|
||||
public void EjectBeaker()
|
||||
{
|
||||
SendMessage(new ItemSlotButtonPressedEvent(SharedReagentGrinder.BeakerSlotId));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user