Add APC power meter (#14196)

This commit is contained in:
Kevin Zheng
2023-02-21 07:23:38 -08:00
committed by GitHub
parent 322006ab81
commit 32b9a7b781
5 changed files with 14 additions and 2 deletions

View File

@@ -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'}"/>

View File

@@ -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)

View File

@@ -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));
}
}

View File

@@ -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;
}

View File

@@ -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:{" "}