Reapply "Remove some BUI boilerplate" (#30214) (#30219)

* Reapply "Remove some BUI boilerplate" (#30214)

This reverts commit cb0ba66be3.

* Fix gas tank

* Fix PA

* Fix microwave

* Comms console underwrap

* Fix rcd

* log wehs
This commit is contained in:
metalgearsloth
2024-07-21 14:48:13 +10:00
committed by GitHub
parent 87e52e50b4
commit edb05e36bb
137 changed files with 1102 additions and 1757 deletions

View File

@@ -15,13 +15,12 @@ namespace Content.Client.Power;
[GenerateTypedNameReferences]
public sealed partial class PowerMonitoringWindow : FancyWindow
{
private readonly IEntityManager _entManager;
[Dependency] private IEntityManager _entManager = default!;
private readonly SpriteSystem _spriteSystem;
private readonly IGameTiming _gameTiming;
[Dependency] private IGameTiming _gameTiming = default!;
private const float BlinkFrequency = 1f;
private EntityUid? _owner;
private NetEntity? _focusEntity;
public event Action<NetEntity?, PowerMonitoringConsoleGroup>? SendPowerMonitoringConsoleMessageAction;
@@ -34,40 +33,14 @@ public sealed partial class PowerMonitoringWindow : FancyWindow
{ PowerMonitoringConsoleGroup.APC, (new SpriteSpecifier.Texture(new ResPath("/Textures/Interface/NavMap/beveled_triangle.png")), Color.LimeGreen) },
};
public PowerMonitoringWindow(PowerMonitoringConsoleBoundUserInterface userInterface, EntityUid? owner)
public EntityUid Entity;
public PowerMonitoringWindow()
{
RobustXamlLoader.Load(this);
_entManager = IoCManager.Resolve<IEntityManager>();
_gameTiming = IoCManager.Resolve<IGameTiming>();
IoCManager.InjectDependencies(this);
_spriteSystem = _entManager.System<SpriteSystem>();
_owner = owner;
// Pass owner to nav map
NavMap.Owner = _owner;
// Set nav map grid uid
var stationName = Loc.GetString("power-monitoring-window-unknown-location");
if (_entManager.TryGetComponent<TransformComponent>(owner, out var xform))
{
NavMap.MapUid = xform.GridUid;
// Assign station name
if (_entManager.TryGetComponent<MetaDataComponent>(xform.GridUid, out var stationMetaData))
stationName = stationMetaData.EntityName;
var msg = new FormattedMessage();
msg.AddMarkup(Loc.GetString("power-monitoring-window-station-name", ("stationName", stationName)));
StationName.SetMessage(msg);
}
else
{
StationName.SetMessage(stationName);
NavMap.Visible = false;
}
// Set trackable entity selected action
NavMap.TrackedEntitySelectedAction += SetTrackedEntityFromNavMap;
@@ -88,9 +61,37 @@ public sealed partial class PowerMonitoringWindow : FancyWindow
ShowHVCable.OnToggled += _ => OnShowCableToggled(PowerMonitoringConsoleLineGroup.HighVoltage);
ShowMVCable.OnToggled += _ => OnShowCableToggled(PowerMonitoringConsoleLineGroup.MediumVoltage);
ShowLVCable.OnToggled += _ => OnShowCableToggled(PowerMonitoringConsoleLineGroup.Apc);
}
// Set power monitoring message action
SendPowerMonitoringConsoleMessageAction += userInterface.SendPowerMonitoringConsoleMessage;
public void SetEntity(EntityUid uid)
{
Entity = uid;
// Pass owner to nav map
NavMap.Owner = uid;
// Set nav map grid uid
var stationName = Loc.GetString("power-monitoring-window-unknown-location");
if (_entManager.TryGetComponent<TransformComponent>(uid, out var xform))
{
NavMap.MapUid = xform.GridUid;
// Assign station name
if (_entManager.TryGetComponent<MetaDataComponent>(xform.GridUid, out var stationMetaData))
stationName = stationMetaData.EntityName;
var msg = new FormattedMessage();
msg.AddMarkupOrThrow(Loc.GetString("power-monitoring-window-station-name", ("stationName", stationName)));
StationName.SetMessage(msg);
}
else
{
StationName.SetMessage(stationName);
NavMap.Visible = false;
}
}
private void OnTabChanged(int tab)
@@ -113,10 +114,7 @@ public sealed partial class PowerMonitoringWindow : FancyWindow
PowerMonitoringConsoleEntry[] focusLoads,
EntityCoordinates? monitorCoords)
{
if (_owner == null)
return;
if (!_entManager.TryGetComponent<PowerMonitoringConsoleComponent>(_owner.Value, out var console))
if (!_entManager.TryGetComponent<PowerMonitoringConsoleComponent>(Entity, out var console))
return;
// Update power status text
@@ -161,13 +159,13 @@ public sealed partial class PowerMonitoringWindow : FancyWindow
}
// Show monitor location
var mon = _entManager.GetNetEntity(_owner);
var mon = _entManager.GetNetEntity(Entity);
if (monitorCoords != null && mon != null)
if (monitorCoords != null && mon.IsValid())
{
var texture = _spriteSystem.Frame0(new SpriteSpecifier.Texture(new ResPath("/Textures/Interface/NavMap/beveled_circle.png")));
var blip = new NavMapBlip(monitorCoords.Value, texture, Color.Cyan, true, false);
NavMap.TrackedEntities[mon.Value] = blip;
NavMap.TrackedEntities[mon] = blip;
}
// If the entry group doesn't match the current tab, the data is out dated, do not use it
@@ -239,7 +237,7 @@ public sealed partial class PowerMonitoringWindow : FancyWindow
if (netEntity == null)
return;
if (!_entManager.TryGetComponent<PowerMonitoringConsoleComponent>(_owner, out var console))
if (!_entManager.TryGetComponent<PowerMonitoringConsoleComponent>(Entity, out var console))
return;
if (!console.PowerMonitoringDeviceMetaData.TryGetValue(netEntity.Value, out var metaData))
@@ -266,7 +264,7 @@ public sealed partial class PowerMonitoringWindow : FancyWindow
{
AutoScrollToFocus();
// Warning sign pulse
// Warning sign pulse
var lit = _gameTiming.RealTime.TotalSeconds % BlinkFrequency > BlinkFrequency / 2f;
SystemWarningPanel.Modulate = lit ? Color.White : new Color(178, 178, 178);
}