Cleaner BoundUserInterfaces (#17736)
This commit is contained in:
@@ -10,6 +10,7 @@ using Content.Shared.Popups;
|
||||
using Content.Shared.Shuttles.BUIStates;
|
||||
using Content.Shared.Shuttles.Events;
|
||||
using Content.Shared.Shuttles.Systems;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Player;
|
||||
@@ -264,7 +265,8 @@ public sealed partial class EmergencyShuttleSystem
|
||||
}
|
||||
|
||||
// TODO: This is fucking bad
|
||||
if (!component.AuthorizedEntities.Remove(MetaData(idCard.Owner).EntityName)) return;
|
||||
if (!component.AuthorizedEntities.Remove(MetaData(idCard.Owner).EntityName))
|
||||
return;
|
||||
|
||||
_logger.Add(LogType.EmergencyShuttle, LogImpact.High, $"Emergency shuttle early launch REPEAL by {args.Session:user}");
|
||||
var remaining = component.AuthorizationsRequired - component.AuthorizedEntities.Count;
|
||||
@@ -276,7 +278,8 @@ public sealed partial class EmergencyShuttleSystem
|
||||
private void OnEmergencyAuthorize(EntityUid uid, EmergencyShuttleConsoleComponent component, EmergencyShuttleAuthorizeMessage args)
|
||||
{
|
||||
var player = args.Session.AttachedEntity;
|
||||
if (player == null) return;
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
if (!_idSystem.TryFindIdCard(player.Value, out var idCard) || !_reader.IsAllowed(idCard.Owner, uid))
|
||||
{
|
||||
@@ -285,7 +288,8 @@ public sealed partial class EmergencyShuttleSystem
|
||||
}
|
||||
|
||||
// TODO: This is fucking bad
|
||||
if (!component.AuthorizedEntities.Add(MetaData(idCard.Owner).EntityName)) return;
|
||||
if (!component.AuthorizedEntities.Add(MetaData(idCard.Owner).EntityName))
|
||||
return;
|
||||
|
||||
_logger.Add(LogType.EmergencyShuttle, LogImpact.High, $"Emergency shuttle early launch AUTH by {args.Session:user}");
|
||||
var remaining = component.AuthorizationsRequired - component.AuthorizedEntities.Count;
|
||||
@@ -296,7 +300,7 @@ public sealed partial class EmergencyShuttleSystem
|
||||
playSound: false, colorOverride: DangerColor);
|
||||
|
||||
if (!CheckForLaunch(component))
|
||||
SoundSystem.Play("/Audio/Misc/notice1.ogg", Filter.Broadcast());
|
||||
_audio.PlayGlobal("/Audio/Misc/notice1.ogg", Filter.Broadcast(), recordReplay: true);
|
||||
|
||||
UpdateAllEmergencyConsoles();
|
||||
}
|
||||
@@ -317,9 +321,10 @@ public sealed partial class EmergencyShuttleSystem
|
||||
|
||||
private void UpdateAllEmergencyConsoles()
|
||||
{
|
||||
foreach (var comp in EntityQuery<EmergencyShuttleConsoleComponent>(true))
|
||||
var query = AllEntityQuery<EmergencyShuttleConsoleComponent>();
|
||||
while (query.MoveNext(out var uid, out var comp))
|
||||
{
|
||||
UpdateConsoleState(comp.Owner, comp);
|
||||
UpdateConsoleState(uid, comp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,12 +337,16 @@ public sealed partial class EmergencyShuttleSystem
|
||||
auths.Add(auth);
|
||||
}
|
||||
|
||||
_uiSystem.GetUiOrNull(uid, EmergencyConsoleUiKey.Key)?.SetState(new EmergencyConsoleBoundUserInterfaceState()
|
||||
{
|
||||
EarlyLaunchTime = EarlyLaunchAuthorized ? _timing.CurTime + TimeSpan.FromSeconds(_consoleAccumulator) : null,
|
||||
Authorizations = auths,
|
||||
AuthorizationsRequired = component.AuthorizationsRequired,
|
||||
});
|
||||
if (_uiSystem.TryGetUi(uid, EmergencyConsoleUiKey.Key, out var bui))
|
||||
UserInterfaceSystem.SetUiState(
|
||||
bui,
|
||||
new EmergencyConsoleBoundUserInterfaceState()
|
||||
{
|
||||
EarlyLaunchTime = EarlyLaunchAuthorized ? _timing.CurTime + TimeSpan.FromSeconds(_consoleAccumulator) : null,
|
||||
Authorizations = auths,
|
||||
AuthorizationsRequired = component.AuthorizationsRequired,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private bool CheckForLaunch(EmergencyShuttleConsoleComponent component)
|
||||
@@ -375,7 +384,7 @@ public sealed partial class EmergencyShuttleSystem
|
||||
playSound: false,
|
||||
colorOverride: DangerColor);
|
||||
|
||||
SoundSystem.Play("/Audio/Misc/notice1.ogg", Filter.Broadcast());
|
||||
_audio.PlayGlobal("/Audio/Misc/notice1.ogg", Filter.Broadcast(), recordReplay: true);
|
||||
}
|
||||
|
||||
public bool DelayEmergencyRoundEnd()
|
||||
|
||||
@@ -20,36 +20,36 @@ public sealed class RadarConsoleSystem : SharedRadarConsoleSystem
|
||||
|
||||
private void OnRadarStartup(EntityUid uid, RadarConsoleComponent component, ComponentStartup args)
|
||||
{
|
||||
UpdateState(component);
|
||||
UpdateState(uid, component);
|
||||
}
|
||||
|
||||
protected override void UpdateState(RadarConsoleComponent component)
|
||||
protected override void UpdateState(EntityUid uid, RadarConsoleComponent component)
|
||||
{
|
||||
var xform = Transform(component.Owner);
|
||||
var xform = Transform(uid);
|
||||
var onGrid = xform.ParentUid == xform.GridUid;
|
||||
EntityCoordinates? coordinates = onGrid ? xform.Coordinates : null;
|
||||
Angle? angle = onGrid ? xform.LocalRotation : null;
|
||||
|
||||
// Use ourself I guess.
|
||||
if (TryComp<IntrinsicUIComponent>(component.Owner, out var intrinsic))
|
||||
if (TryComp<IntrinsicUIComponent>(uid, out var intrinsic))
|
||||
{
|
||||
foreach (var uiKey in intrinsic.UIs)
|
||||
{
|
||||
if (uiKey.Key?.Equals(RadarConsoleUiKey.Key) == true)
|
||||
{
|
||||
coordinates = new EntityCoordinates(component.Owner, Vector2.Zero);
|
||||
coordinates = new EntityCoordinates(uid, Vector2.Zero);
|
||||
angle = Angle.Zero;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var radarState = new RadarConsoleBoundInterfaceState(
|
||||
component.MaxRange,
|
||||
coordinates,
|
||||
angle,
|
||||
new List<DockingInterfaceState>());
|
||||
|
||||
_uiSystem.GetUiOrNull(component.Owner, RadarConsoleUiKey.Key)?.SetState(radarState);
|
||||
if (_uiSystem.TryGetUi(uid, RadarConsoleUiKey.Key, out var bui))
|
||||
UserInterfaceSystem.SetUiState(bui, new RadarConsoleBoundInterfaceState(
|
||||
component.MaxRange,
|
||||
coordinates,
|
||||
angle,
|
||||
new List<DockingInterfaceState>()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ public sealed partial class ShuttleConsoleSystem : SharedShuttleConsoleSystem
|
||||
RefreshShuttleConsoles();
|
||||
}
|
||||
|
||||
public void RefreshShuttleConsoles(EntityUid uid)
|
||||
public void RefreshShuttleConsoles(EntityUid _)
|
||||
{
|
||||
// TODO: Should really call this per shuttle in some instances.
|
||||
RefreshShuttleConsoles();
|
||||
@@ -149,7 +149,7 @@ public sealed partial class ShuttleConsoleSystem : SharedShuttleConsoleSystem
|
||||
var docks = GetAllDocks();
|
||||
var query = AllEntityQuery<ShuttleConsoleComponent>();
|
||||
|
||||
while (query.MoveNext(out var uid, out var comp))
|
||||
while (query.MoveNext(out var uid, out var _))
|
||||
{
|
||||
UpdateState(uid, docks);
|
||||
}
|
||||
@@ -160,7 +160,7 @@ public sealed partial class ShuttleConsoleSystem : SharedShuttleConsoleSystem
|
||||
/// </summary>
|
||||
private void OnConsoleUIClose(EntityUid uid, ShuttleConsoleComponent component, BoundUIClosedEvent args)
|
||||
{
|
||||
if ((ShuttleConsoleUiKey)args.UiKey != ShuttleConsoleUiKey.Key ||
|
||||
if ((ShuttleConsoleUiKey) args.UiKey != ShuttleConsoleUiKey.Key ||
|
||||
args.Session.AttachedEntity is not { } user)
|
||||
{
|
||||
return;
|
||||
@@ -211,19 +211,18 @@ public sealed partial class ShuttleConsoleSystem : SharedShuttleConsoleSystem
|
||||
{
|
||||
RemovePilot(user, pilotComponent);
|
||||
|
||||
if (console == component)
|
||||
{
|
||||
// This feels backwards; is this intended to be a toggle?
|
||||
if (console == uid)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
AddPilot(user, component);
|
||||
AddPilot(uid, user, component);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void OnGetState(EntityUid uid, PilotComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new PilotComponentState(component.Console?.Owner);
|
||||
args.State = new PilotComponentState(component.Console);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -328,15 +327,16 @@ public sealed partial class ShuttleConsoleSystem : SharedShuttleConsoleSystem
|
||||
|
||||
docks ??= GetAllDocks();
|
||||
|
||||
_ui.GetUiOrNull(consoleUid, ShuttleConsoleUiKey.Key)
|
||||
?.SetState(new ShuttleConsoleBoundInterfaceState(
|
||||
if (_ui.TryGetUi(consoleUid, ShuttleConsoleUiKey.Key, out var bui))
|
||||
UserInterfaceSystem.SetUiState(bui, new ShuttleConsoleBoundInterfaceState(
|
||||
ftlState,
|
||||
ftlTime,
|
||||
destinations,
|
||||
range,
|
||||
consoleXform?.Coordinates,
|
||||
consoleXform?.LocalRotation,
|
||||
docks));
|
||||
docks
|
||||
));
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
@@ -351,7 +351,7 @@ public sealed partial class ShuttleConsoleSystem : SharedShuttleConsoleSystem
|
||||
if (comp.Console == null)
|
||||
continue;
|
||||
|
||||
if (!_blocker.CanInteract(uid, comp.Console.Owner))
|
||||
if (!_blocker.CanInteract(uid, comp.Console))
|
||||
{
|
||||
toRemove.Add((uid, comp));
|
||||
}
|
||||
@@ -395,21 +395,21 @@ public sealed partial class ShuttleConsoleSystem : SharedShuttleConsoleSystem
|
||||
ClearPilots(component);
|
||||
}
|
||||
|
||||
public void AddPilot(EntityUid entity, ShuttleConsoleComponent component)
|
||||
public void AddPilot(EntityUid uid, EntityUid entity, ShuttleConsoleComponent component)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(entity, out PilotComponent? pilotComponent) ||
|
||||
component.SubscribedPilots.Contains(pilotComponent))
|
||||
if (!EntityManager.TryGetComponent(entity, out PilotComponent? pilotComponent)
|
||||
|| component.SubscribedPilots.Contains(entity))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_eyeSystem.SetZoom(entity, component.Zoom, ignoreLimits:true);
|
||||
_eyeSystem.SetZoom(entity, component.Zoom, ignoreLimits: true);
|
||||
|
||||
component.SubscribedPilots.Add(pilotComponent);
|
||||
component.SubscribedPilots.Add(entity);
|
||||
|
||||
_alertsSystem.ShowAlert(entity, AlertType.PilotingShuttle);
|
||||
|
||||
pilotComponent.Console = component;
|
||||
pilotComponent.Console = uid;
|
||||
ActionBlockerSystem.UpdateCanMove(entity);
|
||||
pilotComponent.Position = EntityManager.GetComponent<TransformComponent>(entity).Coordinates;
|
||||
Dirty(pilotComponent);
|
||||
@@ -419,14 +419,14 @@ public sealed partial class ShuttleConsoleSystem : SharedShuttleConsoleSystem
|
||||
{
|
||||
var console = pilotComponent.Console;
|
||||
|
||||
if (console is not ShuttleConsoleComponent helmsman)
|
||||
if (!TryComp<ShuttleConsoleComponent>(console, out var helm))
|
||||
return;
|
||||
|
||||
pilotComponent.Console = null;
|
||||
pilotComponent.Position = null;
|
||||
_eyeSystem.ResetZoom(pilotUid);
|
||||
|
||||
if (!helmsman.SubscribedPilots.Remove(pilotComponent))
|
||||
if (!helm.SubscribedPilots.Remove(pilotUid))
|
||||
return;
|
||||
|
||||
_alertsSystem.ClearAlert(pilotUid, AlertType.PilotingShuttle);
|
||||
@@ -447,9 +447,11 @@ public sealed partial class ShuttleConsoleSystem : SharedShuttleConsoleSystem
|
||||
|
||||
public void ClearPilots(ShuttleConsoleComponent component)
|
||||
{
|
||||
var query = GetEntityQuery<PilotComponent>();
|
||||
while (component.SubscribedPilots.TryGetValue(0, out var pilot))
|
||||
{
|
||||
RemovePilot(pilot.Owner, pilot);
|
||||
if (query.TryGetComponent(pilot, out var pilotComponent))
|
||||
RemovePilot(pilot, pilotComponent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user