Material generators from Afterlight (#18387)
This commit is contained in:
26
Content.Client/Power/Generator/GeneratorWindow.xaml
Normal file
26
Content.Client/Power/Generator/GeneratorWindow.xaml
Normal file
@@ -0,0 +1,26 @@
|
||||
<controls:FancyWindow xmlns="https://spacestation14.io"
|
||||
xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls"
|
||||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
|
||||
MinSize="350 130"
|
||||
SetSize="360 180"
|
||||
Title="{Loc 'generator-ui-title'}">
|
||||
<BoxContainer Margin="4 0" Orientation="Horizontal">
|
||||
<BoxContainer Orientation="Vertical" HorizontalExpand="True" SizeFlagsStretchRatio="2" VerticalAlignment="Center" Margin="5">
|
||||
<GridContainer Margin="2 0 0 0" Columns="2" HorizontalExpand="True">
|
||||
<!-- Power -->
|
||||
<Label Text="{Loc 'generator-ui-target-power-label'}"/>
|
||||
<SpinBox Name="TargetPower" HorizontalExpand="True"/>
|
||||
<Label Text="{Loc 'generator-ui-efficiency-label'}"/>
|
||||
<Label Name="Efficiency" Text="???%" HorizontalExpand="True"/>
|
||||
<Label Text="{Loc 'generator-ui-fuel-use-label'}"/>
|
||||
<ProgressBar Name="FuelFraction" MinValue="0" MaxValue="1" HorizontalExpand="True"/>
|
||||
<Label Text="{Loc 'generator-ui-fuel-left-label'}"/>
|
||||
<Label Name="FuelLeft" Text="0" HorizontalExpand="True"/>
|
||||
</GridContainer>
|
||||
</BoxContainer>
|
||||
<cc:VSeparator StyleClasses="LowDivider"/>
|
||||
<PanelContainer Margin="12 0 0 0" StyleClasses="Inset" VerticalAlignment="Center">
|
||||
<SpriteView Name="EntityView" SetSize="64 64" Scale="2 2" OverrideDirection="South" Margin="15"/>
|
||||
</PanelContainer>
|
||||
</BoxContainer>
|
||||
</controls:FancyWindow>
|
||||
57
Content.Client/Power/Generator/GeneratorWindow.xaml.cs
Normal file
57
Content.Client/Power/Generator/GeneratorWindow.xaml.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using Content.Client.UserInterface.Controls;
|
||||
using Content.Shared.Power.Generator;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
namespace Content.Client.Power.Generator;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class GeneratorWindow : FancyWindow
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
|
||||
private readonly FuelGeneratorComponent? _component;
|
||||
private SolidFuelGeneratorComponentBuiState? _lastState;
|
||||
|
||||
public GeneratorWindow(SolidFuelGeneratorBoundUserInterface bui, EntityUid vis)
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
_entityManager.TryGetComponent(vis, out _component);
|
||||
|
||||
EntityView.SetEntity(vis);
|
||||
TargetPower.IsValid += IsValid;
|
||||
TargetPower.ValueChanged += (args) =>
|
||||
{
|
||||
bui.SetTargetPower(args.Value);
|
||||
};
|
||||
}
|
||||
|
||||
private bool IsValid(int arg)
|
||||
{
|
||||
if (arg < 0)
|
||||
return false;
|
||||
|
||||
if (arg > (_lastState?.MaximumPower / 1000.0f ?? 0))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Update(SolidFuelGeneratorComponentBuiState state)
|
||||
{
|
||||
if (_component == null)
|
||||
return;
|
||||
|
||||
var oldState = _lastState;
|
||||
_lastState = state;
|
||||
// ReSharper disable once CompareOfFloatsByEqualityOperator
|
||||
if (oldState?.TargetPower != state.TargetPower)
|
||||
TargetPower.OverrideValue((int)(state.TargetPower / 1000.0f));
|
||||
Efficiency.Text = SharedGeneratorSystem.CalcFuelEfficiency(state.TargetPower, state.OptimalPower, _component).ToString("P1");
|
||||
FuelFraction.Value = state.RemainingFuel - (int) state.RemainingFuel;
|
||||
FuelLeft.Text = ((int) MathF.Floor(state.RemainingFuel)).ToString();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using Content.Shared.Power.Generator;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
namespace Content.Client.Power.Generator;
|
||||
|
||||
[UsedImplicitly]
|
||||
public sealed class SolidFuelGeneratorBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
private GeneratorWindow? _window;
|
||||
|
||||
public SolidFuelGeneratorBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
_window = new GeneratorWindow(this, Owner);
|
||||
|
||||
_window.OpenCenteredLeft();
|
||||
_window.OnClose += Close;
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
if (state is not SolidFuelGeneratorComponentBuiState msg)
|
||||
return;
|
||||
|
||||
_window?.Update(msg);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
_window?.Dispose();
|
||||
}
|
||||
|
||||
public void SetTargetPower(int target)
|
||||
{
|
||||
SendMessage(new SetTargetPowerMessage(target));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user