Cleaner BoundUserInterfaces (#17736)

This commit is contained in:
TemporalOroboros
2023-07-08 09:02:17 -07:00
committed by GitHub
parent 55b4fb1649
commit 3ac4cf85db
137 changed files with 1069 additions and 972 deletions

View File

@@ -1,29 +1,25 @@
using System.Collections.Generic;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Kitchen.Components;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Prototypes;
namespace Content.Client.Kitchen.UI
{
[UsedImplicitly]
public sealed class MicrowaveBoundUserInterface : BoundUserInterface
{
[Dependency] private readonly IEntityManager _entityManager = default!;
[ViewVariables]
private MicrowaveMenu? _menu;
[ViewVariables]
private readonly Dictionary<int, EntityUid> _solids = new();
private readonly Dictionary<int, Solution.ReagentQuantity> _reagents =new();
public MicrowaveBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner,uiKey)
[ViewVariables]
private readonly Dictionary<int, Solution.ReagentQuantity> _reagents = new();
public MicrowaveBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
@@ -40,10 +36,10 @@ namespace Content.Client.Kitchen.UI
SendMessage(new MicrowaveEjectSolidIndexedMessage(_solids[args.ItemIndex]));
};
_menu.OnCookTimeSelected += (args,buttonIndex) =>
_menu.OnCookTimeSelected += (args, buttonIndex) =>
{
var actualButton = (MicrowaveMenu.MicrowaveCookTimeButton) args.Button ;
SendMessage(new MicrowaveSelectCookTimeMessage(buttonIndex,actualButton.CookTime));
var actualButton = (MicrowaveMenu.MicrowaveCookTimeButton) args.Button;
SendMessage(new MicrowaveSelectCookTimeMessage(buttonIndex, actualButton.CookTime));
};
}
@@ -93,7 +89,7 @@ namespace Content.Client.Kitchen.UI
_menu.IngredientsList.Clear();
foreach (var entity in containedSolids)
{
if (_entityManager.Deleted(entity))
if (EntMan.Deleted(entity))
{
return;
}
@@ -101,11 +97,11 @@ namespace Content.Client.Kitchen.UI
// TODO just use sprite view
Texture? texture;
if (_entityManager.TryGetComponent(entity, out IconComponent? iconComponent))
if (EntMan.TryGetComponent<IconComponent>(entity, out var iconComponent))
{
texture = _entityManager.System<SpriteSystem>().GetIcon(iconComponent);
texture = EntMan.System<SpriteSystem>().GetIcon(iconComponent);
}
else if (_entityManager.TryGetComponent(entity, out SpriteComponent? spriteComponent))
else if (EntMan.TryGetComponent<SpriteComponent>(entity, out var spriteComponent))
{
texture = spriteComponent.Icon?.Default;
}
@@ -114,7 +110,7 @@ namespace Content.Client.Kitchen.UI
continue;
}
var solidItem = _menu.IngredientsList.AddItem(_entityManager.GetComponent<MetaDataComponent>(entity).EntityName, texture);
var solidItem = _menu.IngredientsList.AddItem(EntMan.GetComponent<MetaDataComponent>(entity).EntityName, texture);
var solidIndex = _menu.IngredientsList.IndexOf(solidItem);
_solids.Add(solidIndex, entity);
}

View File

@@ -8,18 +8,20 @@ namespace Content.Client.Kitchen.UI
{
public sealed class ReagentGrinderBoundUserInterface : BoundUserInterface
{
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[ViewVariables]
private GrinderMenu? _menu;
public ReagentGrinderBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) { }
public ReagentGrinderBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
protected override void Open()
{
base.Open();
_menu = new GrinderMenu(this, _entityManager, _prototypeManager);
_menu = new GrinderMenu(this, EntMan, _prototypeManager);
_menu.OpenCentered();
_menu.OnClose += Close;
}
@@ -38,10 +40,8 @@ namespace Content.Client.Kitchen.UI
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
if (!(state is ReagentGrinderInterfaceState cState))
{
if (state is not ReagentGrinderInterfaceState cState)
return;
}
_menu?.UpdateState(cState);
}
@@ -52,10 +52,29 @@ namespace Content.Client.Kitchen.UI
_menu?.HandleMessage(message);
}
public void StartGrinding(BaseButton.ButtonEventArgs? args = null) => SendMessage(new ReagentGrinderStartMessage(GrinderProgram.Grind));
public void StartJuicing(BaseButton.ButtonEventArgs? args = null) => SendMessage(new ReagentGrinderStartMessage(GrinderProgram.Juice));
public void EjectAll(BaseButton.ButtonEventArgs? args = null) => SendMessage(new ReagentGrinderEjectChamberAllMessage());
public void EjectBeaker(BaseButton.ButtonEventArgs? args = null) => SendMessage(new ItemSlotButtonPressedEvent(SharedReagentGrinder.BeakerSlotId));
public void EjectChamberContent(EntityUid uid) => SendMessage(new ReagentGrinderEjectChamberContentMessage(uid));
public void StartGrinding(BaseButton.ButtonEventArgs? _ = null)
{
SendMessage(new ReagentGrinderStartMessage(GrinderProgram.Grind));
}
public void StartJuicing(BaseButton.ButtonEventArgs? _ = null)
{
SendMessage(new ReagentGrinderStartMessage(GrinderProgram.Juice));
}
public void EjectAll(BaseButton.ButtonEventArgs? _ = null)
{
SendMessage(new ReagentGrinderEjectChamberAllMessage());
}
public void EjectBeaker(BaseButton.ButtonEventArgs? _ = null)
{
SendMessage(new ItemSlotButtonPressedEvent(SharedReagentGrinder.BeakerSlotId));
}
public void EjectChamberContent(EntityUid uid)
{
SendMessage(new ReagentGrinderEjectChamberContentMessage(uid));
}
}
}