Add barebone nuke (#5242)
Co-authored-by: Alexander Evgrashin <evgrashin.adl@gmail.com>
This commit is contained in:
79
Content.Client/Nuke/NukeBoundUserInterface.cs
Normal file
79
Content.Client/Nuke/NukeBoundUserInterface.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using Content.Client.Traitor.Uplink;
|
||||
using Content.Shared.Nuke;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Client.Nuke
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class NukeBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
private NukeMenu? _menu;
|
||||
|
||||
public NukeBoundUserInterface([NotNull] ClientUserInterfaceComponent owner, [NotNull] object uiKey) : base(owner, uiKey)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
_menu = new NukeMenu();
|
||||
_menu.OpenCentered();
|
||||
_menu.OnClose += Close;
|
||||
|
||||
_menu.OnKeypadButtonPressed += i =>
|
||||
{
|
||||
SendMessage(new NukeKeypadMessage(i));
|
||||
};
|
||||
_menu.OnEnterButtonPressed += () =>
|
||||
{
|
||||
SendMessage(new NukeKeypadEnterMessage());
|
||||
};
|
||||
_menu.OnClearButtonPressed += () =>
|
||||
{
|
||||
SendMessage(new NukeKeypadClearMessage());
|
||||
};
|
||||
|
||||
_menu.EjectButton.OnPressed += _ =>
|
||||
{
|
||||
SendMessage(new NukeEjectMessage());
|
||||
};
|
||||
_menu.AnchorButton.OnPressed += _ =>
|
||||
{
|
||||
SendMessage(new NukeAnchorMessage());
|
||||
};
|
||||
_menu.ArmButton.OnPressed += _ =>
|
||||
{
|
||||
SendMessage(new NukeArmedMessage());
|
||||
};
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
base.UpdateState(state);
|
||||
|
||||
if (_menu == null)
|
||||
return;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case NukeUiState msg:
|
||||
{
|
||||
_menu.UpdateState(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
if (!disposing)
|
||||
return;
|
||||
|
||||
_menu?.Close();
|
||||
_menu?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
46
Content.Client/Nuke/NukeMenu.xaml
Normal file
46
Content.Client/Nuke/NukeMenu.xaml
Normal file
@@ -0,0 +1,46 @@
|
||||
<SS14Window xmlns="https://spacestation14.io"
|
||||
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
|
||||
Title="{Loc 'nuke-user-interface-title'}"
|
||||
MinSize="256 256"
|
||||
SetSize="256 256">
|
||||
<BoxContainer Orientation="Vertical"
|
||||
HorizontalExpand="True"
|
||||
VerticalExpand="True">
|
||||
<!-- First status label -->
|
||||
<PanelContainer Margin="0 0 0 5">
|
||||
<PanelContainer.PanelOverride>
|
||||
<gfx:StyleBoxFlat BackgroundColor="#001c00" />
|
||||
</PanelContainer.PanelOverride>
|
||||
<Label Name="FirstStatusLabel"/>
|
||||
</PanelContainer>
|
||||
<!-- Second status label -->
|
||||
<PanelContainer Margin="0 0 0 5">
|
||||
<PanelContainer.PanelOverride>
|
||||
<gfx:StyleBoxFlat BackgroundColor="#001c00" />
|
||||
</PanelContainer.PanelOverride>
|
||||
<Label Name="SecondStatusLabel"/>
|
||||
</PanelContainer>
|
||||
<BoxContainer Orientation="Horizontal" >
|
||||
<GridContainer Columns="3"
|
||||
Name="KeypadGrid">
|
||||
<!-- Keypad is filled by code -->
|
||||
</GridContainer>
|
||||
<BoxContainer Orientation="Vertical"
|
||||
HorizontalExpand="True"
|
||||
Margin="5 0">
|
||||
<Button Name="EjectButton"
|
||||
Text="{Loc 'nuke-user-interface-eject-button'}"
|
||||
Margin="0 0 0 5"
|
||||
Access="Public"/>
|
||||
<Button Name="AnchorButton"
|
||||
Text="{Loc 'nuke-user-interface-anchor-button'}"
|
||||
Margin="0 0 0 5"
|
||||
Access="Public"/>
|
||||
<Button Name="ArmButton"
|
||||
Text="{Loc 'nuke-user-interface-arm-button'}"
|
||||
Access="Public"
|
||||
StyleClasses="Caution"/>
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
</SS14Window>
|
||||
115
Content.Client/Nuke/NukeMenu.xaml.cs
Normal file
115
Content.Client/Nuke/NukeMenu.xaml.cs
Normal file
@@ -0,0 +1,115 @@
|
||||
using System;
|
||||
using Content.Shared.Nuke;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Client.Nuke
|
||||
{
|
||||
[GenerateTypedNameReferences]
|
||||
public partial class NukeMenu : SS14Window
|
||||
{
|
||||
public event Action<int>? OnKeypadButtonPressed;
|
||||
public event Action? OnClearButtonPressed;
|
||||
public event Action? OnEnterButtonPressed;
|
||||
|
||||
public NukeMenu()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
FillKeypadGrid();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fill keypad buttons in keypad grid
|
||||
/// </summary>
|
||||
private void FillKeypadGrid()
|
||||
{
|
||||
// add 3 rows of keypad buttons (1-9)
|
||||
for (var i = 1; i <= 9; i++)
|
||||
{
|
||||
AddKeypadButton(i);
|
||||
}
|
||||
|
||||
// clear button
|
||||
var clearBtn = new Button()
|
||||
{
|
||||
Text = "C"
|
||||
};
|
||||
clearBtn.OnPressed += _ => OnClearButtonPressed?.Invoke();
|
||||
KeypadGrid.AddChild(clearBtn);
|
||||
|
||||
// zero button
|
||||
AddKeypadButton(0);
|
||||
|
||||
// enter button
|
||||
var enterBtn = new Button()
|
||||
{
|
||||
Text = "E"
|
||||
};
|
||||
enterBtn.OnPressed += _ => OnEnterButtonPressed?.Invoke();
|
||||
KeypadGrid.AddChild(enterBtn);
|
||||
}
|
||||
|
||||
private void AddKeypadButton(int i)
|
||||
{
|
||||
var btn = new Button()
|
||||
{
|
||||
Text = i.ToString()
|
||||
};
|
||||
|
||||
btn.OnPressed += _ => OnKeypadButtonPressed?.Invoke(i);
|
||||
KeypadGrid.AddChild(btn);
|
||||
}
|
||||
|
||||
public void UpdateState(NukeUiState state)
|
||||
{
|
||||
string firstMsg, secondMsg;
|
||||
switch (state.Status)
|
||||
{
|
||||
case NukeStatus.AWAIT_DISK:
|
||||
firstMsg = Loc.GetString("nuke-user-interface-first-status-device-locked");
|
||||
secondMsg = Loc.GetString("nuke-user-interface-second-status-await-disk");
|
||||
break;
|
||||
case NukeStatus.AWAIT_CODE:
|
||||
firstMsg = Loc.GetString("nuke-user-interface-first-status-input-code");
|
||||
secondMsg = Loc.GetString("nuke-user-interface-second-status-current-code",
|
||||
("code", VisualizeCode(state.EnteredCodeLength, state.MaxCodeLength)));
|
||||
break;
|
||||
case NukeStatus.AWAIT_ARM:
|
||||
firstMsg = Loc.GetString("nuke-user-interface-first-status-device-ready");
|
||||
secondMsg = Loc.GetString("nuke-user-interface-second-status-time",
|
||||
("time", state.RemainingTime));
|
||||
break;
|
||||
case NukeStatus.ARMED:
|
||||
firstMsg = Loc.GetString("nuke-user-interface-first-status-device-armed");
|
||||
secondMsg = Loc.GetString("nuke-user-interface-second-status-time",
|
||||
("time", state.RemainingTime));
|
||||
break;
|
||||
default:
|
||||
// shouldn't normally be here
|
||||
firstMsg = Loc.GetString("nuke-user-interface-status-error");
|
||||
secondMsg = Loc.GetString("nuke-user-interface-status-error");
|
||||
break;
|
||||
}
|
||||
|
||||
FirstStatusLabel.Text = firstMsg;
|
||||
SecondStatusLabel.Text = secondMsg;
|
||||
|
||||
EjectButton.Disabled = !state.DiskInserted;
|
||||
AnchorButton.Disabled = !state.DiskInserted;
|
||||
AnchorButton.Pressed = state.IsAnchored;
|
||||
ArmButton.Disabled = !state.AllowArm;
|
||||
}
|
||||
|
||||
private string VisualizeCode(int codeLength, int maxLength)
|
||||
{
|
||||
var code = new string('*', codeLength);
|
||||
var blanksCount = maxLength - codeLength;
|
||||
var blanks = new string('_', blanksCount);
|
||||
return code + blanks;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user