Files
tbd-station-14/Content.Client/Power/Battery/BatteryMenu.xaml
Pieter-Jan Briers ffe130b38d Battery (SMES/substation) interface (#36386)
* Add ENERGYWATTHOURS() loc function

Takes in joules (energy), displays as watt-hours.

* Add simple OnOffButton control

* Re-add Inset style class

This was sloppily removed at some point?? Whatever, I need it.

* Add helper functions for setting title/guidebook IDs on FancyWindow

Reagent dispenser uses these, more in the next commits.

* Add BuiPredictionState helper

This enables me to implement coarse prediction manually in the battery UI.

Basically it's a local buffer of predicted inputs that can easily be replayed against future BUI states from the server.

* Add input coalescing infrastructure

I ran into the following problem: Robust's Slider control absolutely *spams* input events, to such a degree that it actually causes issues for the networking layer if directly passed through. For something like a slider, we just need to send the most recent value.

There is no good way for us to handle this in the control itself, as it *really* needs to happen in PreEngine. For simplicity reasons (for BUIs) I came to the conclusion it's best if it's there, as it's *before* any new states from the server can be applied. We can't just do this in Update() or something on the control as the timing just doesn't line up.

I made a content system, BuiPreTickUpdateSystem, that runs in the ModRunLevel.PreEngine phase to achieve this. It runs a method on a new IBuiPreTickUpdate interface on all open BUIs. They can then implement their own coalescing logic.

In the simplest case, this coalescing logic can just be "save the last value, and if we have any new value since the last update, send an input event." This is what the new InputCoalescer<T> type is for.

Adding new coalescing logic should be possible in the future, of course. It's all just small helpers.

* Battery interface

This adds a proper interface to batteries (SMES/substation). Players can turn IO on and off, and they can change charge and discharge rate. There's also a ton of numbers and stuff. It looks great.

This actually enables charge and discharge rates to be changed for these devices. The settings for both have been set between 5kW and 150kW.

* Oops, forgot to remove these style class defs.
2025-04-27 21:08:34 +10:00

147 lines
8.8 KiB
XML

<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
SetSize="650 330"
Resizable="False">
<BoxContainer Orientation="Vertical">
<!-- Top row: main content -->
<BoxContainer Name="MainContent" Orientation="Horizontal" VerticalExpand="True" Margin="4">
<!-- Left pane: I/O, passthrough, sprite view -->
<BoxContainer Name="IOPane" Orientation="Vertical" HorizontalExpand="True">
<!-- Top row: input -->
<BoxContainer Name="InputRow" Orientation="Horizontal">
<!-- Input power line -->
<PanelContainer Name="InPowerLine" SetHeight="2" VerticalAlignment="Top" SetWidth="32"
Margin="2 16" />
<!-- Box with breaker, label, values -->
<PanelContainer HorizontalExpand="True" StyleClasses="Inset">
<BoxContainer Orientation="Vertical">
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'battery-menu-in'}" HorizontalExpand="True" VerticalAlignment="Top"
StyleClasses="LabelKeyText" />
<controls:OnOffButton Name="InBreaker" />
</BoxContainer>
<Label Name="InValue" />
</BoxContainer>
</PanelContainer>
</BoxContainer>
<!-- Middle row: Entity view & passthrough -->
<BoxContainer Name="MiddleRow" Orientation="Horizontal" VerticalExpand="True">
<SpriteView Name="EntityView" SetSize="64 64" Scale="2 2" OverrideDirection="South" Margin="15" />
<BoxContainer Orientation="Vertical" VerticalAlignment="Center" HorizontalExpand="True"
HorizontalAlignment="Right">
<Label HorizontalAlignment="Right" Text="{Loc 'battery-menu-passthrough'}" StyleClasses="StatusFieldTitle" />
<Label HorizontalAlignment="Right" Name="PassthroughValue" />
</BoxContainer>
</BoxContainer>
<!-- Bottom row: output -->
<BoxContainer Name="OutputRow" Orientation="Horizontal">
<!-- Output power line -->
<PanelContainer Name="OutPowerLine" SetHeight="2" VerticalAlignment="Bottom" SetWidth="32"
Margin="2 16" />
<!-- Box with breaker, label, values -->
<PanelContainer HorizontalExpand="True" StyleClasses="Inset">
<BoxContainer Orientation="Vertical">
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'battery-menu-out'}" HorizontalExpand="True" VerticalAlignment="Top"
StyleClasses="LabelKeyText" />
<controls:OnOffButton Name="OutBreaker" />
</BoxContainer>
<Label Name="OutValue" />
</BoxContainer>
</PanelContainer>
</BoxContainer>
</BoxContainer>
<!-- Separator connecting panes with some wires -->
<BoxContainer Orientation="Vertical" SetWidth="22" Margin="2 16">
<PanelContainer Name="InSecondPowerLine" SetHeight="2" />
<PanelContainer Name="PassthroughPowerLine" SetWidth="2" HorizontalAlignment="Center" VerticalExpand="True" />
<PanelContainer Name="OutSecondPowerLine" SetHeight="2" />
</BoxContainer>
<!-- Middle pane: charge/discharge -->
<BoxContainer Name="ChargeDischarge" Orientation="Vertical" HorizontalExpand="True">
<!-- Charge -->
<PanelContainer VerticalExpand="True" StyleClasses="Inset" Margin="0 0 0 8">
<BoxContainer Orientation="Vertical">
<Label Text="{Loc 'battery-menu-charge-header'}" StyleClasses="LabelKeyText" />
<BoxContainer Orientation="Vertical" VerticalExpand="True" VerticalAlignment="Center">
<Slider Name="ChargeRateSlider" />
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'battery-menu-max'}" StyleClasses="StatusFieldTitle" HorizontalExpand="True" />
<Label Name="ChargeMaxValue" />
</BoxContainer>
</BoxContainer>
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'battery-menu-current'}" StyleClasses="StatusFieldTitle" HorizontalExpand="True" />
<Label Name="ChargeCurrentValue" />
</BoxContainer>
</BoxContainer>
</PanelContainer>
<!-- Discharge -->
<PanelContainer VerticalExpand="True" StyleClasses="Inset">
<BoxContainer Orientation="Vertical">
<Label Text="{Loc 'battery-menu-discharge-header'}" StyleClasses="LabelKeyText" />
<BoxContainer Orientation="Vertical" VerticalExpand="True" VerticalAlignment="Center">
<Slider Name="DischargeRateSlider" />
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'battery-menu-max'}" StyleClasses="StatusFieldTitle" HorizontalExpand="True" />
<Label Name="DischargeMaxValue" />
</BoxContainer>
</BoxContainer>
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'battery-menu-current'}" StyleClasses="StatusFieldTitle" HorizontalExpand="True" />
<Label Name="DischargeCurrentValue" />
</BoxContainer>
</BoxContainer>
</PanelContainer>
</BoxContainer>
<!-- Separator connecting panes with some wires -->
<BoxContainer Orientation="Vertical" SetWidth="22" Margin="2 16">
<PanelContainer Name="ChargePowerLine" SetHeight="2" VerticalAlignment="Top" VerticalExpand="True" />
<PanelContainer Name="DischargePowerLine" SetHeight="2" VerticalAlignment="Bottom" VerticalExpand="True" />
</BoxContainer>
<!-- Right pane: storage -->
<PanelContainer Name="Storage" StyleClasses="Inset" HorizontalExpand="True">
<BoxContainer Orientation="Vertical">
<Label Text="{Loc 'battery-menu-storage-header'}" StyleClasses="LabelKeyText" />
<GridContainer Columns="2">
<Label Text="{Loc 'battery-menu-stored'}" StyleClasses="StatusFieldTitle" />
<Label Name="StoredPercentageValue" HorizontalAlignment="Right" HorizontalExpand="True" />
<Label Text="{Loc 'battery-menu-energy'}" StyleClasses="StatusFieldTitle" />
<Label Name="StoredEnergyValue" HorizontalAlignment="Right" />
<Label Name="EtaLabel" StyleClasses="StatusFieldTitle" />
<Label Name="EtaValue" HorizontalAlignment="Right" />
</GridContainer>
<!-- Charge meter -->
<GridContainer Name="ChargeMeter" Columns="3" VerticalExpand="True" Margin="0 24 0 0">
</GridContainer>
</BoxContainer>
</PanelContainer>
</BoxContainer>
<!-- Footer -->
<BoxContainer Name="Footer" Orientation="Vertical">
<PanelContainer StyleClasses="LowDivider" />
<BoxContainer Orientation="Horizontal" Margin="10 2 5 0" VerticalAlignment="Bottom">
<Label Text="{Loc 'battery-menu-footer-left'}" StyleClasses="WindowFooterText" />
<Label Text="{Loc 'battery-menu-footer-right'}" StyleClasses="WindowFooterText"
HorizontalAlignment="Right" HorizontalExpand="True" Margin="0 0 5 0" />
<TextureRect StyleClasses="NTLogoDark" Stretch="KeepAspectCentered"
VerticalAlignment="Center" HorizontalAlignment="Right" SetSize="19 19" />
</BoxContainer>
</BoxContainer>
</BoxContainer>
</controls:FancyWindow>