Give nukies the ability to declare war for a TC boost (#19291)
Co-authored-by: Kevin Zheng <kevinz5000@gmail.com>
This commit is contained in:
49
Content.Client/NukeOps/WarDeclaratorBoundUserInterface.cs
Normal file
49
Content.Client/NukeOps/WarDeclaratorBoundUserInterface.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using Content.Shared.NukeOps;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Client.NukeOps;
|
||||
|
||||
[UsedImplicitly]
|
||||
public sealed class WarDeclaratorBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
[ViewVariables]
|
||||
private WarDeclaratorWindow? _window;
|
||||
|
||||
public WarDeclaratorBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) {}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
|
||||
_window = new WarDeclaratorWindow();
|
||||
if (State != null)
|
||||
UpdateState(State);
|
||||
|
||||
_window.OpenCentered();
|
||||
|
||||
_window.OnClose += Close;
|
||||
_window.OnActivated += OnWarDeclaratorActivated;
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
base.UpdateState(state);
|
||||
if (_window == null || state is not WarDeclaratorBoundUserInterfaceState cast)
|
||||
return;
|
||||
|
||||
_window?.UpdateState(cast);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
if (disposing) _window?.Dispose();
|
||||
}
|
||||
|
||||
private void OnWarDeclaratorActivated(string message)
|
||||
{
|
||||
SendMessage(new WarDeclaratorActivateMessage(message));
|
||||
}
|
||||
}
|
||||
18
Content.Client/NukeOps/WarDeclaratorWindow.xaml
Normal file
18
Content.Client/NukeOps/WarDeclaratorWindow.xaml
Normal file
@@ -0,0 +1,18 @@
|
||||
<DefaultWindow xmlns="https://spacestation14.io"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="{Loc 'war-declarator-ui-header'}">
|
||||
<BoxContainer Orientation="Vertical" SeparationOverride="4" MinWidth="440">
|
||||
<TextEdit Name="MessageEdit"
|
||||
HorizontalExpand="True"
|
||||
MinHeight="200"
|
||||
Access="Public" />
|
||||
<Button Name="WarButton"
|
||||
Text="{Loc 'war-declarator-ui-war-button'}"
|
||||
StyleClasses="Caution"
|
||||
Access="Public"/>
|
||||
<Label Name="StatusLabel"
|
||||
Access="Public"/>
|
||||
<Label Name="InfoLabel"
|
||||
Access="Public"/>
|
||||
</BoxContainer>
|
||||
</DefaultWindow>
|
||||
138
Content.Client/NukeOps/WarDeclaratorWindow.xaml.cs
Normal file
138
Content.Client/NukeOps/WarDeclaratorWindow.xaml.cs
Normal file
@@ -0,0 +1,138 @@
|
||||
using Content.Client.Stylesheets;
|
||||
using Content.Shared.NukeOps;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.NukeOps;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class WarDeclaratorWindow : DefaultWindow
|
||||
{
|
||||
private readonly IGameTiming _gameTiming;
|
||||
|
||||
public event Action<string>? OnActivated;
|
||||
|
||||
private TimeSpan _endTime;
|
||||
private TimeSpan _timeStamp;
|
||||
private WarConditionStatus _status;
|
||||
|
||||
public WarDeclaratorWindow()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
_gameTiming = IoCManager.Resolve<IGameTiming>();
|
||||
|
||||
WarButton.OnPressed += ActivateWarDeclarator;
|
||||
|
||||
var loc = IoCManager.Resolve<ILocalizationManager>();
|
||||
MessageEdit.Placeholder = new Rope.Leaf(loc.GetString("war-declarator-message-placeholder"));
|
||||
}
|
||||
|
||||
protected override void Draw(DrawingHandleScreen handle)
|
||||
{
|
||||
base.Draw(handle);
|
||||
UpdateTimer();
|
||||
}
|
||||
|
||||
public void UpdateState(WarDeclaratorBoundUserInterfaceState state)
|
||||
{
|
||||
WarButton.Disabled = state.Status != WarConditionStatus.YES_WAR;
|
||||
|
||||
_timeStamp = state.Delay;
|
||||
_endTime = state.EndTime;
|
||||
_status = state.Status;
|
||||
|
||||
switch(state.Status)
|
||||
{
|
||||
case WarConditionStatus.WAR_READY:
|
||||
StatusLabel.Text = Loc.GetString("war-declarator-boost-declared");
|
||||
InfoLabel.Text = Loc.GetString("war-declarator-conditions-ready");
|
||||
StatusLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateLow);
|
||||
break;
|
||||
case WarConditionStatus.WAR_DELAY:
|
||||
StatusLabel.Text = Loc.GetString("war-declarator-boost-declared-delay");
|
||||
UpdateTimer();
|
||||
StatusLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateLow);
|
||||
break;
|
||||
case WarConditionStatus.YES_WAR:
|
||||
StatusLabel.Text = Loc.GetString("war-declarator-boost-possible");
|
||||
UpdateTimer();
|
||||
StatusLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateGood);
|
||||
break;
|
||||
case WarConditionStatus.NO_WAR_SMALL_CREW:
|
||||
StatusLabel.Text = Loc.GetString("war-declarator-boost-impossible");
|
||||
InfoLabel.Text = Loc.GetString("war-declarator-conditions-small-crew", ("min", state.MinCrew));
|
||||
StatusLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateNone);
|
||||
break;
|
||||
case WarConditionStatus.NO_WAR_SHUTTLE_DEPARTED:
|
||||
StatusLabel.Text = Loc.GetString("war-declarator-boost-impossible");
|
||||
InfoLabel.Text = Loc.GetString("war-declarator-conditions-left-outpost");
|
||||
StatusLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateNone);
|
||||
break;
|
||||
case WarConditionStatus.NO_WAR_TIMEOUT:
|
||||
StatusLabel.Text = Loc.GetString("war-declarator-boost-impossible");
|
||||
InfoLabel.Text = Loc.GetString("war-declarator-conditions-time-out");
|
||||
StatusLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateNone);
|
||||
break;
|
||||
default:
|
||||
StatusLabel.Text = Loc.GetString("war-declarator-boost-impossible");
|
||||
InfoLabel.Text = Loc.GetString("war-declarator-conditions-unknown");
|
||||
StatusLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateNone);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateTimer()
|
||||
{
|
||||
switch(_status)
|
||||
{
|
||||
case WarConditionStatus.YES_WAR:
|
||||
var gameruleTime = _gameTiming.CurTime.Subtract(_timeStamp);
|
||||
var timeLeft = _endTime.Subtract(gameruleTime);
|
||||
|
||||
if (timeLeft > TimeSpan.Zero)
|
||||
{
|
||||
InfoLabel.Text = Loc.GetString("war-declarator-boost-timer", ("minutes", timeLeft.Minutes), ("seconds", timeLeft.Seconds));
|
||||
}
|
||||
else
|
||||
{
|
||||
_status = WarConditionStatus.NO_WAR_TIMEOUT;
|
||||
StatusLabel.Text = Loc.GetString("war-declarator-boost-impossible");
|
||||
InfoLabel.Text = Loc.GetString("war-declarator-conditions-time-out");
|
||||
StatusLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateNone);
|
||||
WarButton.Disabled = true;
|
||||
}
|
||||
break;
|
||||
case WarConditionStatus.WAR_DELAY:
|
||||
var timeAfterDeclaration = _gameTiming.CurTime.Subtract(_timeStamp);
|
||||
var timeRemain = _endTime.Subtract(timeAfterDeclaration);
|
||||
|
||||
if (timeRemain > TimeSpan.Zero)
|
||||
{
|
||||
InfoLabel.Text = Loc.GetString("war-declarator-boost-timer", ("minutes", timeRemain.Minutes), ("seconds", timeRemain.Seconds));
|
||||
}
|
||||
else
|
||||
{
|
||||
_status = WarConditionStatus.WAR_READY;
|
||||
StatusLabel.Text = Loc.GetString("war-declarator-boost-declared");
|
||||
InfoLabel.Text = Loc.GetString("war-declarator-conditions-ready");
|
||||
StatusLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateLow);
|
||||
WarButton.Disabled = true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void ActivateWarDeclarator(BaseButton.ButtonEventArgs obj)
|
||||
{
|
||||
var message = Rope.Collapse(MessageEdit.TextRope);
|
||||
OnActivated?.Invoke(message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user