Anomalies (#13371)
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using Content.Shared.Anomaly;
|
||||
using Content.Shared.Gravity;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
namespace Content.Client. Anomaly.Ui;
|
||||
|
||||
[UsedImplicitly]
|
||||
public sealed class AnomalyGeneratorBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
private AnomalyGeneratorWindow? _window;
|
||||
|
||||
public AnomalyGeneratorBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base (owner, uiKey)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
|
||||
_window = new (Owner.Owner);
|
||||
|
||||
_window.OpenCentered();
|
||||
_window.OnClose += Close;
|
||||
|
||||
_window.OnGenerateButtonPressed += () =>
|
||||
{
|
||||
SendMessage(new AnomalyGeneratorGenerateButtonPressedEvent());
|
||||
};
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
base.UpdateState(state);
|
||||
|
||||
if (state is not AnomalyGeneratorUserInterfaceState msg)
|
||||
return;
|
||||
_window?.UpdateState(msg);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
if (!disposing) return;
|
||||
|
||||
_window?.Dispose();
|
||||
}
|
||||
|
||||
public void SetPowerSwitch(bool on)
|
||||
{
|
||||
SendMessage(new SharedGravityGeneratorComponent.SwitchGeneratorMessage(on));
|
||||
}
|
||||
}
|
||||
|
||||
48
Content.Client/Anomaly/Ui/AnomalyGeneratorWindow.xaml
Normal file
48
Content.Client/Anomaly/Ui/AnomalyGeneratorWindow.xaml
Normal file
@@ -0,0 +1,48 @@
|
||||
<controls:FancyWindow xmlns="https://spacestation14.io"
|
||||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
|
||||
Title="{Loc 'anomaly-generator-ui-title'}"
|
||||
MinSize="270 180"
|
||||
SetSize="360 180">
|
||||
<BoxContainer Margin="10 0 10 0"
|
||||
Orientation="Vertical"
|
||||
HorizontalExpand="True"
|
||||
VerticalExpand="True">
|
||||
<BoxContainer Orientation="Horizontal">
|
||||
<BoxContainer Orientation="Vertical" HorizontalExpand="True">
|
||||
<BoxContainer Orientation="Horizontal"
|
||||
HorizontalExpand="True"
|
||||
VerticalExpand="True"
|
||||
Margin="0 0 0 0"
|
||||
VerticalAlignment="Center">
|
||||
<Label Text="{Loc 'anomaly-generator-fuel-display'}" StyleClasses="StatusFieldTitle" />
|
||||
<ProgressBar Name="FuelBar"
|
||||
HorizontalExpand="True"
|
||||
MaxValue="1"
|
||||
MinValue="0"
|
||||
SetHeight="25"
|
||||
Margin="10 0 10 0"
|
||||
VerticalAlignment="Center">
|
||||
<Label Name="FuelText"
|
||||
Margin="4 0"
|
||||
Text="0 %" />
|
||||
</ProgressBar>
|
||||
</BoxContainer>
|
||||
<RichTextLabel Name="CooldownLabel" StyleClasses="StatusFieldTitle" />
|
||||
<RichTextLabel Name="ReadyLabel" StyleClasses="StatusFieldTitle" />
|
||||
</BoxContainer>
|
||||
<PanelContainer Margin="12 0 0 0"
|
||||
StyleClasses="Inset"
|
||||
VerticalAlignment="Center">
|
||||
<SpriteView Name="EntityView"
|
||||
SetSize="96 96"
|
||||
OverrideDirection="South" />
|
||||
</PanelContainer>
|
||||
</BoxContainer>
|
||||
<BoxContainer VerticalExpand="True"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center">
|
||||
<Button Name="GenerateButton"
|
||||
Text="{Loc 'anomaly-generator-generate'}"></Button>
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
</controls:FancyWindow>
|
||||
80
Content.Client/Anomaly/Ui/AnomalyGeneratorWindow.xaml.cs
Normal file
80
Content.Client/Anomaly/Ui/AnomalyGeneratorWindow.xaml.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using Content.Client.Message;
|
||||
using Content.Shared.Anomaly;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Timing;
|
||||
using FancyWindow = Content.Client.UserInterface.Controls.FancyWindow;
|
||||
|
||||
namespace Content.Client.Anomaly.Ui;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class AnomalyGeneratorWindow : FancyWindow
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
|
||||
private TimeSpan _cooldownEnd = TimeSpan.Zero;
|
||||
private bool _hasEnoughFuel;
|
||||
|
||||
public Action? OnGenerateButtonPressed;
|
||||
|
||||
public AnomalyGeneratorWindow(EntityUid gen)
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
EntityView.Sprite = _entityManager.GetComponent<SpriteComponent>(gen);
|
||||
|
||||
GenerateButton.OnPressed += _ => OnGenerateButtonPressed?.Invoke();
|
||||
}
|
||||
|
||||
public void UpdateState(AnomalyGeneratorUserInterfaceState state)
|
||||
{
|
||||
_cooldownEnd = state.CooldownEndTime;
|
||||
_hasEnoughFuel = state.FuelCost <= state.FuelAmount;
|
||||
|
||||
var fuelCompletion = Math.Clamp((float) state.FuelAmount / state.FuelCost, 0f, 1f);
|
||||
|
||||
FuelBar.Value = fuelCompletion;
|
||||
FuelText.Text = $"{fuelCompletion:P}";
|
||||
|
||||
UpdateTimer();
|
||||
UpdateReady(); // yes this can trigger twice. no i don't care
|
||||
}
|
||||
|
||||
public void UpdateTimer()
|
||||
{
|
||||
if (_timing.CurTime > _cooldownEnd)
|
||||
{
|
||||
CooldownLabel.SetMarkup(Loc.GetString("anomaly-generator-no-cooldown"));
|
||||
}
|
||||
else
|
||||
{
|
||||
var timeLeft = _cooldownEnd - _timing.CurTime;
|
||||
var timeString = $"{timeLeft.Minutes:0}:{timeLeft.Seconds:00}";
|
||||
CooldownLabel.SetMarkup(Loc.GetString("anomaly-generator-cooldown", ("time", timeString)));
|
||||
UpdateReady();
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateReady()
|
||||
{
|
||||
var ready = _hasEnoughFuel && _timing.CurTime > _cooldownEnd;
|
||||
|
||||
var msg = ready
|
||||
? Loc.GetString("anomaly-generator-yes-fire")
|
||||
: Loc.GetString("anomaly-generator-no-fire");
|
||||
ReadyLabel.SetMarkup(msg);
|
||||
|
||||
GenerateButton.Disabled = !ready;
|
||||
}
|
||||
|
||||
protected override void FrameUpdate(FrameEventArgs args)
|
||||
{
|
||||
base.FrameUpdate(args);
|
||||
|
||||
UpdateTimer();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
using Content.Shared.Anomaly;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
namespace Content.Client.Anomaly.Ui;
|
||||
|
||||
[UsedImplicitly]
|
||||
public sealed class AnomalyScannerBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
private AnomalyScannerMenu? _menu;
|
||||
|
||||
public AnomalyScannerBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
|
||||
_menu = new AnomalyScannerMenu();
|
||||
_menu.OpenCentered();
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
base.UpdateState(state);
|
||||
|
||||
if (state is not AnomalyScannerUserInterfaceState msg)
|
||||
return;
|
||||
|
||||
if (_menu == null)
|
||||
return;
|
||||
|
||||
_menu.LastMessage = msg.Message;
|
||||
_menu.NextPulseTime = msg.NextPulseTime;
|
||||
_menu.UpdateMenu();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
if (!disposing)
|
||||
return;
|
||||
_menu?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
12
Content.Client/Anomaly/Ui/AnomalyScannerMenu.xaml
Normal file
12
Content.Client/Anomaly/Ui/AnomalyScannerMenu.xaml
Normal file
@@ -0,0 +1,12 @@
|
||||
<controls:FancyWindow
|
||||
xmlns="https://spacestation14.io"
|
||||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
|
||||
Title="{Loc 'anomaly-scanner-ui-title'}"
|
||||
MinSize="350 260"
|
||||
SetSize="350 260">
|
||||
<BoxContainer Orientation="Vertical" VerticalExpand="True" Margin="10 0 10 10">
|
||||
<RichTextLabel Name="TextDisplay"></RichTextLabel>
|
||||
</BoxContainer>
|
||||
</controls:FancyWindow>
|
||||
|
||||
|
||||
47
Content.Client/Anomaly/Ui/AnomalyScannerMenu.xaml.cs
Normal file
47
Content.Client/Anomaly/Ui/AnomalyScannerMenu.xaml.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using Content.Client.Message;
|
||||
using Content.Client.UserInterface.Controls;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.Anomaly.Ui;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class AnomalyScannerMenu : FancyWindow
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
|
||||
public FormattedMessage LastMessage = new();
|
||||
public TimeSpan? NextPulseTime;
|
||||
|
||||
public AnomalyScannerMenu()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
}
|
||||
|
||||
public void UpdateMenu()
|
||||
{
|
||||
var msg = new FormattedMessage(LastMessage);
|
||||
|
||||
if (NextPulseTime != null)
|
||||
{
|
||||
msg.PushNewline();
|
||||
msg.PushNewline();
|
||||
var time = NextPulseTime.Value - _timing.CurTime;
|
||||
var timestring = $"{time.Minutes:00}:{time.Seconds:00}";
|
||||
msg.AddMarkup(Loc.GetString("anomaly-scanner-pulse-timer", ("time", timestring)));
|
||||
}
|
||||
|
||||
TextDisplay.SetMarkup(msg.ToMarkup());
|
||||
}
|
||||
|
||||
protected override void FrameUpdate(FrameEventArgs args)
|
||||
{
|
||||
base.FrameUpdate(args);
|
||||
|
||||
if (NextPulseTime != null)
|
||||
UpdateMenu();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user