Add APC power meter (#14196)
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
<Label Text="{Loc 'apc-menu-breaker-label'}"/>
|
||||
<Button Name="BreakerButton" Text="{Loc 'apc-menu-breaker-button'}"></Button>
|
||||
</BoxContainer>
|
||||
<Label Name="PowerLabel"/>
|
||||
<BoxContainer Orientation="Horizontal">
|
||||
<Label Text="{Loc 'apc-menu-external-label'}"/>
|
||||
<Label Name="ExternalPowerStateLabel" Text="{Loc 'apc-menu-power-state-good'}"/>
|
||||
|
||||
@@ -32,6 +32,11 @@ namespace Content.Client.Power.APC.UI
|
||||
BreakerButton.Pressed = castState.MainBreaker;
|
||||
}
|
||||
|
||||
if (PowerLabel != null)
|
||||
{
|
||||
PowerLabel.Text = Loc.GetString("apc-menu-power-label", ("power", castState.Power));
|
||||
}
|
||||
|
||||
if (ExternalPowerStateLabel != null)
|
||||
{
|
||||
switch (castState.ApcExternalPower)
|
||||
|
||||
@@ -135,9 +135,12 @@ namespace Content.Server.Power.EntitySystems
|
||||
if (!Resolve(uid, ref apc, ref battery, ref ui))
|
||||
return;
|
||||
|
||||
var netBattery = Comp<PowerNetworkBatteryComponent>(uid);
|
||||
float power = netBattery is not null ? netBattery.CurrentSupply : 0f;
|
||||
|
||||
if (_userInterfaceSystem.GetUiOrNull(uid, ApcUiKey.Key, ui) is { } bui)
|
||||
{
|
||||
bui.SetState(new ApcBoundInterfaceState(apc.MainBreakerEnabled, apc.LastExternalState, battery.CurrentCharge / battery.MaxCharge));
|
||||
bui.SetState(new ApcBoundInterfaceState(apc.MainBreakerEnabled, (int)MathF.Ceiling(power), apc.LastExternalState, battery.CurrentCharge / battery.MaxCharge));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,12 +57,14 @@ namespace Content.Shared.APC
|
||||
public sealed class ApcBoundInterfaceState : BoundUserInterfaceState
|
||||
{
|
||||
public readonly bool MainBreaker;
|
||||
public readonly int Power;
|
||||
public readonly ApcExternalPowerState ApcExternalPower;
|
||||
public readonly float Charge;
|
||||
|
||||
public ApcBoundInterfaceState(bool mainBreaker, ApcExternalPowerState apcExternalPower, float charge)
|
||||
public ApcBoundInterfaceState(bool mainBreaker, int power, ApcExternalPowerState apcExternalPower, float charge)
|
||||
{
|
||||
MainBreaker = mainBreaker;
|
||||
Power = power;
|
||||
ApcExternalPower = apcExternalPower;
|
||||
Charge = charge;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
apc-menu-title = APC
|
||||
apc-menu-breaker-label = Main Breaker:{" "}
|
||||
apc-menu-breaker-button = Toggle
|
||||
apc-menu-power-label = Power: {$power} W
|
||||
apc-menu-external-label = External Power:{" "}
|
||||
apc-menu-charge-label = Charge:{" "}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user