83 lines
2.3 KiB
C#
83 lines
2.3 KiB
C#
using Content.Shared._Sunrise.CodeConsole;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.CustomControls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
|
|
namespace Content.Client._Sunrise.CodeConsole;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class CodeConsoleMenu : DefaultWindow
|
|
{
|
|
public event Action<int>? OnKeypadButtonPressed;
|
|
public event Action? OnClearButtonPressed;
|
|
public event Action? OnEnterButtonPressed;
|
|
|
|
public CodeConsoleMenu()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
FillKeypadGrid();
|
|
}
|
|
|
|
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(CodeConsoleUiState state)
|
|
{
|
|
if (state.IsLocked)
|
|
StatusLabel.Text = Loc.GetString("code-console-interface-code-waiting");
|
|
else
|
|
StatusLabel.Text = Loc.GetString("code-console-interface-opened");
|
|
|
|
CodeEnteringLabel.Text = Loc.GetString("nuke-user-interface-second-status-current-code",
|
|
("code", VisualizeCode(state.EnteredCodeLength, state.MaxCodeLength)));
|
|
|
|
|
|
ActivateButton.Disabled = state.IsLocked;
|
|
LockButton.Disabled = state.IsLocked;
|
|
}
|
|
|
|
private static string VisualizeCode(int codeLength, int maxLength)
|
|
{
|
|
var code = new string('*', codeLength);
|
|
var blanksCount = maxLength - codeLength;
|
|
var blanks = new string('_', blanksCount);
|
|
return code + blanks;
|
|
}
|
|
}
|