* 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:
@@ -2,6 +2,7 @@
|
||||
using Content.Shared.APC;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.UserInterface;
|
||||
|
||||
namespace Content.Client.Power.APC
|
||||
{
|
||||
@@ -19,9 +20,8 @@ namespace Content.Client.Power.APC
|
||||
{
|
||||
base.Open();
|
||||
|
||||
_menu = new ApcMenu(this);
|
||||
_menu.OnClose += Close;
|
||||
_menu.OpenCentered();
|
||||
_menu = this.CreateWindow<ApcMenu>();
|
||||
_menu.OnBreaker += BreakerPressed;
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
@@ -36,15 +36,5 @@ namespace Content.Client.Power.APC
|
||||
{
|
||||
SendMessage(new ApcToggleMainBreakerMessage());
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
_menu?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,13 +17,19 @@ namespace Content.Client.Power.APC.UI
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class ApcMenu : FancyWindow
|
||||
{
|
||||
public ApcMenu(ApcBoundUserInterface owner)
|
||||
public event Action? OnBreaker;
|
||||
|
||||
public ApcMenu()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
EntityView.SetEntity(owner.Owner);
|
||||
BreakerButton.OnPressed += _ => owner.BreakerPressed();
|
||||
BreakerButton.OnPressed += _ => OnBreaker?.Invoke();
|
||||
}
|
||||
|
||||
public void SetEntity(EntityUid entity)
|
||||
{
|
||||
EntityView.SetEntity(entity);
|
||||
}
|
||||
|
||||
public void UpdateState(BoundUserInterfaceState state)
|
||||
|
||||
@@ -9,35 +9,39 @@ namespace Content.Client.Power.Generator;
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class GeneratorWindow : FancyWindow
|
||||
{
|
||||
private readonly EntityUid _entity;
|
||||
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly ILocalizationManager _loc = default!;
|
||||
|
||||
private readonly SharedPowerSwitchableSystem _switchable;
|
||||
private readonly FuelGeneratorComponent? _component;
|
||||
private PortableGeneratorComponentBuiState? _lastState;
|
||||
private EntityUid _entity;
|
||||
|
||||
public GeneratorWindow(PortableGeneratorBoundUserInterface bui, EntityUid entity)
|
||||
public float? MaximumPower;
|
||||
|
||||
public event Action<int>? OnPower;
|
||||
public event Action<bool>? OnState;
|
||||
public event Action? OnSwitchOutput;
|
||||
public event Action? OnEjectFuel;
|
||||
|
||||
public GeneratorWindow()
|
||||
{
|
||||
_entity = entity;
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
_entityManager.TryGetComponent(entity, out _component);
|
||||
_switchable = _entityManager.System<SharedPowerSwitchableSystem>();
|
||||
|
||||
EntityView.SetEntity(entity);
|
||||
TargetPower.IsValid += IsValid;
|
||||
TargetPower.ValueChanged += (args) =>
|
||||
{
|
||||
bui.SetTargetPower(args.Value);
|
||||
OnPower?.Invoke(args.Value);
|
||||
};
|
||||
|
||||
StartButton.OnPressed += _ => bui.Start();
|
||||
StopButton.OnPressed += _ => bui.Stop();
|
||||
OutputSwitchButton.OnPressed += _ => bui.SwitchOutput();
|
||||
FuelEject.OnPressed += _ => bui.EjectFuel();
|
||||
StartButton.OnPressed += _ => OnState?.Invoke(true);
|
||||
StopButton.OnPressed += _ => OnState?.Invoke(false);
|
||||
OutputSwitchButton.OnPressed += _ => OnSwitchOutput?.Invoke();
|
||||
FuelEject.OnPressed += _ => OnEjectFuel?.Invoke();
|
||||
}
|
||||
|
||||
public void SetEntity(EntityUid entity)
|
||||
{
|
||||
_entity = entity;
|
||||
EntityView.SetEntity(entity);
|
||||
}
|
||||
|
||||
private bool IsValid(int arg)
|
||||
@@ -45,7 +49,7 @@ public sealed partial class GeneratorWindow : FancyWindow
|
||||
if (arg < 0)
|
||||
return false;
|
||||
|
||||
if (arg > (_lastState?.MaximumPower / 1000.0f ?? 0))
|
||||
if (arg > (MaximumPower / 1000.0f ?? 0))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -53,16 +57,17 @@ public sealed partial class GeneratorWindow : FancyWindow
|
||||
|
||||
public void Update(PortableGeneratorComponentBuiState state)
|
||||
{
|
||||
if (_component == null)
|
||||
MaximumPower = state.MaximumPower;
|
||||
|
||||
if (!_entityManager.TryGetComponent(_entity, out FuelGeneratorComponent? component))
|
||||
return;
|
||||
|
||||
_lastState = state;
|
||||
if (!TargetPower.LineEditControl.HasKeyboardFocus())
|
||||
TargetPower.OverrideValue((int)(state.TargetPower / 1000.0f));
|
||||
var efficiency = SharedGeneratorSystem.CalcFuelEfficiency(state.TargetPower, state.OptimalPower, _component);
|
||||
var efficiency = SharedGeneratorSystem.CalcFuelEfficiency(state.TargetPower, state.OptimalPower, component);
|
||||
Efficiency.Text = efficiency.ToString("P1");
|
||||
|
||||
var burnRate = _component.OptimalBurnRate / efficiency;
|
||||
var burnRate = component.OptimalBurnRate / efficiency;
|
||||
var left = state.RemainingFuel / burnRate;
|
||||
|
||||
Eta.Text = Loc.GetString(
|
||||
@@ -102,14 +107,15 @@ public sealed partial class GeneratorWindow : FancyWindow
|
||||
}
|
||||
|
||||
var canSwitch = _entityManager.TryGetComponent(_entity, out PowerSwitchableComponent? switchable);
|
||||
var switcher = _entityManager.System<SharedPowerSwitchableSystem>();
|
||||
OutputSwitchLabel.Visible = canSwitch;
|
||||
OutputSwitchButton.Visible = canSwitch;
|
||||
|
||||
if (switchable != null)
|
||||
{
|
||||
var voltage = _switchable.VoltageString(_switchable.GetVoltage(_entity, switchable));
|
||||
var voltage = switcher.VoltageString(switcher.GetVoltage(_entity, switchable));
|
||||
OutputSwitchLabel.Text = Loc.GetString("portable-generator-ui-current-output", ("voltage", voltage));
|
||||
var nextVoltage = _switchable.VoltageString(_switchable.GetNextVoltage(_entity, switchable));
|
||||
var nextVoltage = switcher.VoltageString(switcher.GetNextVoltage(_entity, switchable));
|
||||
OutputSwitchButton.Text = Loc.GetString("power-switchable-switch-voltage", ("voltage", nextVoltage));
|
||||
OutputSwitchButton.Disabled = state.On;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Shared.Power.Generator;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.UserInterface;
|
||||
|
||||
namespace Content.Client.Power.Generator;
|
||||
|
||||
@@ -16,10 +17,25 @@ public sealed class PortableGeneratorBoundUserInterface : BoundUserInterface
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
_window = new GeneratorWindow(this, Owner);
|
||||
_window = this.CreateWindow<GeneratorWindow>();
|
||||
_window.SetEntity(Owner);
|
||||
_window.OnState += args =>
|
||||
{
|
||||
if (args)
|
||||
{
|
||||
Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
Stop();
|
||||
}
|
||||
};
|
||||
|
||||
_window.OnPower += SetTargetPower;
|
||||
_window.OnEjectFuel += EjectFuel;
|
||||
_window.OnSwitchOutput += SwitchOutput;
|
||||
|
||||
_window.OpenCenteredLeft();
|
||||
_window.OnClose += Close;
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
@@ -30,11 +46,6 @@ public sealed class PortableGeneratorBoundUserInterface : BoundUserInterface
|
||||
_window?.Update(msg);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
_window?.Dispose();
|
||||
}
|
||||
|
||||
public void SetTargetPower(int target)
|
||||
{
|
||||
SendMessage(new PortableGeneratorSetTargetPowerMessage(target));
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Shared.Power;
|
||||
using Robust.Client.UserInterface;
|
||||
|
||||
namespace Content.Client.Power;
|
||||
|
||||
@@ -11,9 +12,9 @@ public sealed class PowerMonitoringConsoleBoundUserInterface : BoundUserInterfac
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
_menu = new PowerMonitoringWindow(this, Owner);
|
||||
_menu.OpenCentered();
|
||||
_menu.OnClose += Close;
|
||||
_menu = this.CreateWindow<PowerMonitoringWindow>();
|
||||
_menu.SetEntity(Owner);
|
||||
_menu.SendPowerMonitoringConsoleMessageAction += SendPowerMonitoringConsoleMessage;
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
@@ -22,9 +23,6 @@ public sealed class PowerMonitoringConsoleBoundUserInterface : BoundUserInterfac
|
||||
|
||||
var castState = (PowerMonitoringConsoleBoundInterfaceState) state;
|
||||
|
||||
if (castState == null)
|
||||
return;
|
||||
|
||||
EntMan.TryGetComponent<TransformComponent>(Owner, out var xform);
|
||||
_menu?.ShowEntites
|
||||
(castState.TotalSources,
|
||||
@@ -40,13 +38,4 @@ public sealed class PowerMonitoringConsoleBoundUserInterface : BoundUserInterfac
|
||||
{
|
||||
SendMessage(new PowerMonitoringConsoleMessage(netEntity, group));
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
if (!disposing)
|
||||
return;
|
||||
|
||||
_menu?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public sealed partial class PowerMonitoringWindow
|
||||
if (windowEntry == null)
|
||||
return;
|
||||
|
||||
// Update sources and loads
|
||||
// Update sources and loads
|
||||
UpdateEntrySourcesOrLoads(masterContainer, windowEntry.SourcesContainer, focusSources, _sourceIcon);
|
||||
UpdateEntrySourcesOrLoads(masterContainer, windowEntry.LoadsContainer, focusLoads, _loadIconPath);
|
||||
|
||||
@@ -134,7 +134,7 @@ public sealed partial class PowerMonitoringWindow
|
||||
subEntry.Button.OnButtonUp += args => { ButtonAction(subEntry, masterContainer); };
|
||||
}
|
||||
|
||||
if (!_entManager.TryGetComponent<PowerMonitoringConsoleComponent>(_owner, out var console))
|
||||
if (!_entManager.TryGetComponent<PowerMonitoringConsoleComponent>(Entity, out var console))
|
||||
return;
|
||||
|
||||
// Update all children
|
||||
@@ -379,7 +379,7 @@ public sealed class PowerMonitoringWindowEntry : PowerMonitoringWindowBaseEntry
|
||||
|
||||
AddChild(MainContainer);
|
||||
|
||||
// Grid container to hold the list of sources when selected
|
||||
// Grid container to hold the list of sources when selected
|
||||
SourcesContainer = new BoxContainer()
|
||||
{
|
||||
Orientation = LayoutOrientation.Vertical,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user