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