Gravity generator rewrite (#4828)
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
committed by
GitHub
parent
0e33b246db
commit
059fa9ae48
@@ -10,28 +10,25 @@ namespace Content.Client.Gravity.UI
|
||||
{
|
||||
private GravityGeneratorWindow? _window;
|
||||
|
||||
public bool IsOn;
|
||||
|
||||
public GravityGeneratorBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base (owner, uiKey)
|
||||
{
|
||||
SendMessage(new SharedGravityGeneratorComponent.GeneratorStatusRequestMessage());
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
|
||||
IsOn = false;
|
||||
|
||||
_window = new GravityGeneratorWindow(this);
|
||||
_window = new GravityGeneratorWindow(this, Owner);
|
||||
|
||||
/*
|
||||
_window.Switch.OnPressed += _ =>
|
||||
{
|
||||
SendMessage(new SharedGravityGeneratorComponent.SwitchGeneratorMessage(!IsOn));
|
||||
SendMessage(new SharedGravityGeneratorComponent.GeneratorStatusRequestMessage());
|
||||
};
|
||||
*/
|
||||
|
||||
_window.OpenCentered();
|
||||
_window.OnClose += Close;
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
@@ -39,8 +36,7 @@ namespace Content.Client.Gravity.UI
|
||||
base.UpdateState(state);
|
||||
|
||||
var castState = (SharedGravityGeneratorComponent.GeneratorState) state;
|
||||
IsOn = castState.On;
|
||||
_window?.UpdateButton();
|
||||
_window?.UpdateState(castState);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
@@ -50,5 +46,10 @@ namespace Content.Client.Gravity.UI
|
||||
|
||||
_window?.Dispose();
|
||||
}
|
||||
|
||||
public void SetPowerSwitch(bool on)
|
||||
{
|
||||
SendMessage(new SharedGravityGeneratorComponent.SwitchGeneratorMessage(on));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,35 @@
|
||||
<SS14Window xmlns="https://spacestation14.io"
|
||||
Title="{Loc 'gravity-generator-window-title'}"
|
||||
MinSize="270 130"
|
||||
SetSize="270 130">
|
||||
<BoxContainer Orientation="Vertical">
|
||||
<BoxContainer Orientation="Horizontal">
|
||||
<RichTextLabel Name="Status" />
|
||||
<ui:FancyWindow xmlns="https://spacestation14.io"
|
||||
xmlns:ui="clr-namespace:Content.Client.UserInterface"
|
||||
Title="{Loc 'gravity-generator-window-title'}"
|
||||
MinSize="270 130"
|
||||
SetSize="360 180">
|
||||
<BoxContainer Margin="4 0" Orientation="Horizontal">
|
||||
<BoxContainer Orientation="Vertical" HorizontalExpand="True">
|
||||
<GridContainer Margin="2 0 0 0" Columns="2">
|
||||
<!-- Power -->
|
||||
<Label Text="{Loc 'gravity-generator-window-power'}" HorizontalExpand="True" StyleClasses="StatusFieldTitle" />
|
||||
<BoxContainer Orientation="Horizontal" MinWidth="120">
|
||||
<Button Name="OnButton" Text="{Loc 'gravity-generator-window-power-on'}" StyleClasses="OpenRight" />
|
||||
<Button Name="OffButton" Text="{Loc 'gravity-generator-window-power-off'}" StyleClasses="OpenLeft" />
|
||||
</BoxContainer>
|
||||
<Control /> <!-- Empty control to act as a spacer in the grid. -->
|
||||
<Label Name="PowerLabel" Text="0 / 0 W" />
|
||||
<!-- Status -->
|
||||
<Label Text="{Loc 'gravity-generator-window-status'}" StyleClasses="StatusFieldTitle" />
|
||||
<Label Name="StatusLabel" Text="{Loc 'gravity-generator-window-status-fully-charged'}" />
|
||||
<!-- ETA -->
|
||||
<Label Text="{Loc 'gravity-generator-window-eta'}" StyleClasses="StatusFieldTitle" />
|
||||
<Label Name="EtaLabel" Text="N/A" />
|
||||
<!-- Charge -->
|
||||
<Label Text="{Loc 'gravity-generator-window-charge'}" StyleClasses="StatusFieldTitle" />
|
||||
<ProgressBar Name="ChargeBar" MaxValue="255">
|
||||
<Label Name="ChargeText" Margin="4 0" Text="0 %" />
|
||||
</ProgressBar>
|
||||
</GridContainer>
|
||||
</BoxContainer>
|
||||
<Button Name="Switch"
|
||||
Access="Public"
|
||||
TextAlign="Center"
|
||||
MinHeight="60" />
|
||||
<PanelContainer Margin="12 0 0 0" StyleClasses="Inset" VerticalAlignment="Center">
|
||||
<SpriteView Name="EntityView" SetSize="96 96" OverrideDirection="South" />
|
||||
</PanelContainer>
|
||||
</BoxContainer>
|
||||
</SS14Window>
|
||||
|
||||
</ui:FancyWindow>
|
||||
|
||||
@@ -1,39 +1,80 @@
|
||||
using Content.Client.Message;
|
||||
using System;
|
||||
using Content.Client.Message;
|
||||
using Content.Client.UserInterface;
|
||||
using Content.Shared.Gravity;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.Client.Gravity.UI
|
||||
{
|
||||
[GenerateTypedNameReferences]
|
||||
public partial class GravityGeneratorWindow : SS14Window
|
||||
public partial class GravityGeneratorWindow : FancyWindow
|
||||
{
|
||||
private readonly ButtonGroup _buttonGroup = new();
|
||||
|
||||
private readonly GravityGeneratorBoundUserInterface _owner;
|
||||
|
||||
public GravityGeneratorWindow(GravityGeneratorBoundUserInterface ui)
|
||||
public GravityGeneratorWindow(GravityGeneratorBoundUserInterface ui, ClientUserInterfaceComponent component)
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
_owner = ui;
|
||||
|
||||
UpdateButton();
|
||||
OnButton.Group = _buttonGroup;
|
||||
OffButton.Group = _buttonGroup;
|
||||
|
||||
OnButton.OnPressed += _ => _owner.SetPowerSwitch(true);
|
||||
OffButton.OnPressed += _ => _owner.SetPowerSwitch(false);
|
||||
|
||||
EntityView.Sprite = component.Owner.GetComponent<SpriteComponent>();
|
||||
}
|
||||
|
||||
public void UpdateButton()
|
||||
public void UpdateState(SharedGravityGeneratorComponent.GeneratorState state)
|
||||
{
|
||||
string status = Loc.GetString(_owner.IsOn
|
||||
? "gravity-generator-window-is-on"
|
||||
: "gravity-generator-window-is-off");
|
||||
if (state.On)
|
||||
OnButton.Pressed = true;
|
||||
else
|
||||
OffButton.Pressed = true;
|
||||
|
||||
Status.SetMarkup(Loc.GetString("gravity-generator-window-status-label", ("status", status)));
|
||||
PowerLabel.Text = Loc.GetString(
|
||||
"gravity-generator-window-power-label",
|
||||
("draw", state.PowerDraw),
|
||||
("max", state.PowerDrawMax));
|
||||
|
||||
Switch.Text = Loc.GetString(_owner.IsOn
|
||||
? "gravity-generator-window-turn-off-button"
|
||||
: "gravity-generator-window-turn-on-button");
|
||||
PowerLabel.SetOnlyStyleClass(MathHelper.CloseTo(state.PowerDraw, state.PowerDrawMax) ? "Good" : "Caution");
|
||||
|
||||
ChargeBar.Value = state.Charge;
|
||||
ChargeText.Text = (state.Charge / 255f).ToString("P0");
|
||||
StatusLabel.Text = Loc.GetString(state.PowerStatus switch
|
||||
{
|
||||
GravityGeneratorPowerStatus.Off => "gravity-generator-window-status-off",
|
||||
GravityGeneratorPowerStatus.Discharging => "gravity-generator-window-status-discharging",
|
||||
GravityGeneratorPowerStatus.Charging => "gravity-generator-window-status-charging",
|
||||
GravityGeneratorPowerStatus.FullyCharged => "gravity-generator-window-status-fully-charged",
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
});
|
||||
|
||||
StatusLabel.SetOnlyStyleClass(state.PowerStatus switch
|
||||
{
|
||||
GravityGeneratorPowerStatus.Off => "Danger",
|
||||
GravityGeneratorPowerStatus.Discharging => "Caution",
|
||||
GravityGeneratorPowerStatus.Charging => "Caution",
|
||||
GravityGeneratorPowerStatus.FullyCharged => "Good",
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
});
|
||||
|
||||
EtaLabel.Text = state.EtaSeconds >= 0
|
||||
? Loc.GetString("gravity-generator-window-eta-value", ("left", TimeSpan.FromSeconds(state.EtaSeconds)))
|
||||
: Loc.GetString("gravity-generator-window-eta-none");
|
||||
|
||||
EtaLabel.SetOnlyStyleClass(state.EtaSeconds >= 0 ? "Caution" : "Disabled");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user