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

@@ -50,14 +50,14 @@ namespace Content.Server.Kitchen.EntitySystems
SubscribeLocalEvent<MicrowaveComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<MicrowaveComponent, SolutionChangedEvent>(OnSolutionChange);
SubscribeLocalEvent<MicrowaveComponent, InteractUsingEvent>(OnInteractUsing, after: new[]{typeof(AnchorableSystem)});
SubscribeLocalEvent<MicrowaveComponent, InteractUsingEvent>(OnInteractUsing, after: new[] { typeof(AnchorableSystem) });
SubscribeLocalEvent<MicrowaveComponent, BreakageEventArgs>(OnBreak);
SubscribeLocalEvent<MicrowaveComponent, PowerChangedEvent>(OnPowerChanged);
SubscribeLocalEvent<MicrowaveComponent, SuicideEvent>(OnSuicide);
SubscribeLocalEvent<MicrowaveComponent, RefreshPartsEvent>(OnRefreshParts);
SubscribeLocalEvent<MicrowaveComponent, UpgradeExamineEvent>(OnUpgradeExamine);
SubscribeLocalEvent<MicrowaveComponent, MicrowaveStartCookMessage>((u,c,m) => Wzhzhzh(u,c,m.Session.AttachedEntity));
SubscribeLocalEvent<MicrowaveComponent, MicrowaveStartCookMessage>((u, c, m) => Wzhzhzh(u, c, m.Session.AttachedEntity));
SubscribeLocalEvent<MicrowaveComponent, MicrowaveEjectMessage>(OnEjectMessage);
SubscribeLocalEvent<MicrowaveComponent, MicrowaveEjectSolidIndexedMessage>(OnEjectIndex);
SubscribeLocalEvent<MicrowaveComponent, MicrowaveSelectCookTimeMessage>(OnSelectTime);
@@ -70,7 +70,7 @@ namespace Content.Server.Kitchen.EntitySystems
{
if (!TryComp<MicrowaveComponent>(uid, out var microwaveComponent))
return;
SetAppearance(microwaveComponent, MicrowaveVisualState.Cooking);
SetAppearance(uid, MicrowaveVisualState.Cooking, microwaveComponent);
microwaveComponent.PlayingStream =
_audio.PlayPvs(microwaveComponent.LoopingSound, uid, AudioParams.Default.WithLoop(true).WithMaxDistance(5));
@@ -80,7 +80,7 @@ namespace Content.Server.Kitchen.EntitySystems
{
if (!TryComp<MicrowaveComponent>(uid, out var microwaveComponent))
return;
SetAppearance(microwaveComponent, MicrowaveVisualState.Idle);
SetAppearance(uid, MicrowaveVisualState.Idle, microwaveComponent);
microwaveComponent.PlayingStream?.Stop();
}
@@ -175,7 +175,7 @@ namespace Content.Server.Kitchen.EntitySystems
private void OnInit(EntityUid uid, MicrowaveComponent component, ComponentInit ags)
{
component.Storage = _container.EnsureContainer<Container>(uid,"microwave_entity_container");
component.Storage = _container.EnsureContainer<Container>(uid, "microwave_entity_container");
}
private void OnSuicide(EntityUid uid, MicrowaveComponent component, SuicideEvent args)
@@ -227,7 +227,7 @@ namespace Content.Server.Kitchen.EntitySystems
private void OnInteractUsing(EntityUid uid, MicrowaveComponent component, InteractUsingEvent args)
{
if(args.Handled)
if (args.Handled)
return;
if (!(TryComp<ApcPowerReceiverComponent>(uid, out var apc) && apc.Powered))
{
@@ -255,7 +255,7 @@ namespace Content.Server.Kitchen.EntitySystems
private void OnBreak(EntityUid uid, MicrowaveComponent component, BreakageEventArgs args)
{
component.Broken = true;
SetAppearance(component, MicrowaveVisualState.Broken);
SetAppearance(uid, MicrowaveVisualState.Broken, component);
RemComp<ActiveMicrowaveComponent>(uid);
_sharedContainer.EmptyContainer(component.Storage);
UpdateUserInterfaceState(uid, component);
@@ -265,7 +265,7 @@ namespace Content.Server.Kitchen.EntitySystems
{
if (!args.Powered)
{
SetAppearance(component, MicrowaveVisualState.Idle);
SetAppearance(uid, MicrowaveVisualState.Idle, component);
RemComp<ActiveMicrowaveComponent>(uid);
_sharedContainer.EmptyContainer(component.Storage);
}
@@ -288,22 +288,22 @@ namespace Content.Server.Kitchen.EntitySystems
var ui = _userInterface.GetUiOrNull(uid, MicrowaveUiKey.Key);
if (ui == null)
return;
var state = new MicrowaveUpdateUserInterfaceState(
UserInterfaceSystem.SetUiState(ui, new MicrowaveUpdateUserInterfaceState(
component.Storage.ContainedEntities.ToArray(),
HasComp<ActiveMicrowaveComponent>(uid),
component.CurrentCookTimeButtonIndex,
component.CurrentCookTimerTime
);
_userInterface.SetUiState(ui, state);
));
}
public void SetAppearance(MicrowaveComponent component, MicrowaveVisualState state)
public void SetAppearance(EntityUid uid, MicrowaveVisualState state, MicrowaveComponent component)
{
var display = component.Broken ? MicrowaveVisualState.Broken : state;
_appearance.SetData(component.Owner, PowerDeviceVisuals.VisualState, display);
_appearance.SetData(uid, PowerDeviceVisuals.VisualState, display);
}
public bool HasContents(MicrowaveComponent component)
public static bool HasContents(MicrowaveComponent component)
{
return component.Storage.ContainedEntities.Any();
}
@@ -338,7 +338,7 @@ namespace Content.Server.Kitchen.EntitySystems
if (_tag.HasTag(item, "MicrowaveMachineUnsafe") || _tag.HasTag(item, "Metal"))
{
component.Broken = true;
SetAppearance(component, MicrowaveVisualState.Broken);
SetAppearance(uid, MicrowaveVisualState.Broken, component);
_audio.PlayPvs(component.ItemBreakSound, uid);
return;
}
@@ -390,11 +390,11 @@ namespace Content.Server.Kitchen.EntitySystems
UpdateUserInterfaceState(uid, component);
}
public (FoodRecipePrototype, int) CanSatisfyRecipe(MicrowaveComponent component, FoodRecipePrototype recipe, Dictionary<string, int> solids, Dictionary<string, FixedPoint2> reagents)
public static (FoodRecipePrototype, int) CanSatisfyRecipe(MicrowaveComponent component, FoodRecipePrototype recipe, Dictionary<string, int> solids, Dictionary<string, FixedPoint2> reagents)
{
var portions = 0;
if(component.CurrentCookTimerTime % recipe.CookTime != 0)
if (component.CurrentCookTimerTime % recipe.CookTime != 0)
{
//can't be a multiple of this recipe
return (recipe, 0);
@@ -427,13 +427,15 @@ namespace Content.Server.Kitchen.EntitySystems
}
//cook only as many of those portions as time allows
return (recipe, (int)Math.Min(portions, component.CurrentCookTimerTime / recipe.CookTime));
return (recipe, (int) Math.Min(portions, component.CurrentCookTimerTime / recipe.CookTime));
}
public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (var (active, microwave) in EntityManager.EntityQuery<ActiveMicrowaveComponent, MicrowaveComponent>())
var query = EntityQueryEnumerator<ActiveMicrowaveComponent, MicrowaveComponent>();
while (query.MoveNext(out var uid, out var active, out var microwave))
{
//check if there's still cook time left
active.CookTimeRemaining -= frameTime;
@@ -445,7 +447,7 @@ namespace Content.Server.Kitchen.EntitySystems
if (active.PortionedRecipe.Item1 != null)
{
var coords = Transform(microwave.Owner).Coordinates;
var coords = Transform(uid).Coordinates;
for (var i = 0; i < active.PortionedRecipe.Item2; i++)
{
SubtractContents(microwave, active.PortionedRecipe.Item1);
@@ -454,9 +456,9 @@ namespace Content.Server.Kitchen.EntitySystems
}
_sharedContainer.EmptyContainer(microwave.Storage);
UpdateUserInterfaceState(microwave.Owner, microwave);
EntityManager.RemoveComponentDeferred<ActiveMicrowaveComponent>(active.Owner);
_audio.PlayPvs(microwave.FoodDoneSound, microwave.Owner, AudioParams.Default.WithVolume(-1));
UpdateUserInterfaceState(uid, microwave);
EntityManager.RemoveComponentDeferred<ActiveMicrowaveComponent>(uid);
_audio.PlayPvs(microwave.FoodDoneSound, uid, AudioParams.Default.WithVolume(-1));
}
}