Skip to content
This repository has been archived by the owner on Apr 27, 2024. It is now read-only.

Shipyards and bank system from Frontier Station #6

Closed
wants to merge 11 commits into from
7 changes: 6 additions & 1 deletion Content.Client/Access/UI/IdCardConsoleBoundUserInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,16 @@ public void SubmitData(string newFullName, string newJobTitle, List<string> newA
if (newJobTitle.Length > MaxJobTitleLength)
newJobTitle = newJobTitle[..MaxJobTitleLength];

SendMessage(new WriteToTargetIdMessage(
SendMessage(new SharedIdCardSystem.WriteToTargetIdMessage(
newFullName,
newJobTitle,
newAccessList,
newJobPrototype));
}

public void SubmitShipData(string newShuttleName, string newShuttleSuffix)
{
SendMessage(new SharedIdCardSystem.WriteToShuttleDeedMessage(newShuttleName, newShuttleSuffix));
}
}
}
8 changes: 7 additions & 1 deletion Content.Client/Access/UI/IdCardConsoleWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@
<Label Name="JobTitleLabel" Text="{Loc 'id-card-console-window-job-title-label'}" />
<LineEdit Name="JobTitleLineEdit" HorizontalExpand="True" />
<Button Name="JobTitleSaveButton" Text="{Loc 'id-card-console-window-save-button'}" Disabled="True" />

<Label Name="ShipNameLabel" Text="{Loc 'id-card-console-window-ship-name-label'}" />
<GridContainer Columns="2" HSeparationOverride="4" HorizontalExpand="True">
<LineEdit Name="ShipNameLineEdit" HorizontalExpand="True" />
<LineEdit Name="ShipSuffixLineEdit" HorizontalExpand="True" />
</GridContainer>
<Button Name="ShipNameSaveButton" Text="{Loc 'id-card-console-window-save-button'}" Disabled="True" />
</GridContainer>
<Control MinSize="0 8" />
<GridContainer Columns="2">
<Label Text="{Loc 'id-card-console-window-job-selection-label'}" />
<OptionButton Name="JobPresetOptionButton" />
Expand Down
73 changes: 73 additions & 0 deletions Content.Client/Access/UI/IdCardConsoleWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Linq;
using Content.Shared.Access;
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Roles;
using Robust.Client.AutoGenerated;
Expand All @@ -8,6 +9,7 @@
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
using static Content.Shared.Access.Components.IdCardConsoleComponent;
using static Content.Shared.Shipyard.Components.ShuttleDeedComponent;

namespace Content.Client.Access.UI
{
Expand All @@ -25,7 +27,9 @@ public sealed partial class IdCardConsoleWindow : DefaultWindow

private string? _lastFullName;
private string? _lastJobTitle;
private string?[]? _lastShuttleName;
private string? _lastJobProto;
private bool _interfaceEnabled = false;

public IdCardConsoleWindow(IdCardConsoleBoundUserInterface owner, IPrototypeManager prototypeManager,
List<ProtoId<AccessLevelPrototype>> accessLevels)
Expand All @@ -50,6 +54,10 @@ public IdCardConsoleWindow(IdCardConsoleBoundUserInterface owner, IPrototypeMana
};
JobTitleSaveButton.OnPressed += _ => SubmitData();

ShipNameLineEdit.OnTextChanged += _ => EnsureValidShuttleName();
ShipSuffixLineEdit.OnTextChanged += _ => EnsureValidShuttleName();
ShipNameSaveButton.OnPressed += _ => SubmitShuttleData();

var jobs = _prototypeManager.EnumeratePrototypes<JobPrototype>().ToList();
jobs.Sort((x, y) => string.Compare(x.LocalizedName, y.LocalizedName, StringComparison.CurrentCulture));

Expand Down Expand Up @@ -182,6 +190,29 @@ public void UpdateState(IdCardConsoleBoundUserInterfaceState state)

JobTitleSaveButton.Disabled = !interfaceEnabled || !jobTitleDirty;

// Frontier - shuttle renaming support
ShipNameLabel.Modulate = interfaceEnabled ? Color.White : Color.Gray;

ShipNameLineEdit.Editable = interfaceEnabled && state.HasOwnedShuttle;
ShipSuffixLineEdit.Editable = false; // "Make sure you cannot change the suffix at all." - @dvir001, 2023.11.16

if (interfaceEnabled && state.HasOwnedShuttle)
{
var parts = state.TargetShuttleNameParts ?? new string?[] { null, null };
ShipNameLineEdit.Text = !interfaceEnabled ? string.Empty : parts[0] ?? string.Empty;
ShipSuffixLineEdit.Text = !interfaceEnabled ? string.Empty : parts[1] ?? string.Empty;

ShipNameSaveButton.Disabled = !interfaceEnabled || !state.HasOwnedShuttle;
}
else
{
ShipSuffixLineEdit.Text = string.Empty;
ShipNameLineEdit.Text = !state.HasOwnedShuttle
? Loc.GetString("id-card-console-window-shuttle-placeholder")
: string.Empty;
ShipNameSaveButton.Disabled = true;
}

JobPresetOptionButton.Disabled = !interfaceEnabled;

foreach (var (accessName, button) in _accessButtons)
Expand All @@ -203,6 +234,41 @@ public void UpdateState(IdCardConsoleBoundUserInterfaceState state)
_lastFullName = state.TargetIdFullName;
_lastJobTitle = state.TargetIdJobTitle;
_lastJobProto = state.TargetIdJobPrototype;
_lastShuttleName = state.TargetShuttleNameParts;
_interfaceEnabled = interfaceEnabled;

EnsureValidShuttleName();
}

// <summary>
// Invoked when a shuttle name field is edited.
// Checks whether the name is valid and, if it is, enabled the save button.
//
// The form of a valid name is: "<CORP> <NAME> <SUFFIX>"
// Where <CORP> is usually a 2-5 character string like NT14, KC, SL;
// <NAME> is the shuttle name like Construct;
// and <SUFFIX> is an immutable ID like QT-225.
// </summary>
private void EnsureValidShuttleName()
{
var name = ShipNameLineEdit.Text;
var suffix = ShipSuffixLineEdit.Text;

// We skip suffix validation because it's immutable and is ignored by the server
var valid = name.Length <= MaxNameLength
&& name.Trim().Length >= 3; // Arbitrary client-side number, should hopefully be long enough.

ShipNameSaveButton.Disabled = !_interfaceEnabled || !valid;

// If still enabled, check for dirtiness and disable it if the name is not dirty
if (!ShipNameSaveButton.Disabled)
{
var dirty = _lastShuttleName != null &&
((_lastShuttleName[0] ?? string.Empty) != name
|| (_lastShuttleName[1] ?? string.Empty) != suffix);

ShipNameSaveButton.Disabled = !dirty;
}
}

private void SubmitData()
Expand All @@ -218,5 +284,12 @@ private void SubmitData()
_accessButtons.Where(x => x.Value.Pressed).Select(x => x.Key).ToList(),
jobProtoDirty ? _jobPrototypeIds[JobPresetOptionButton.SelectedId] : string.Empty);
}

private void SubmitShuttleData()
{
_owner.SubmitShipData(
ShipNameLineEdit.Text,
ShipSuffixLineEdit.Text);
}
}
}
58 changes: 58 additions & 0 deletions Content.Client/Bank/BUI/BankATMMenuBoundUserInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Content.Client.Bank.UI;
using Content.Shared.Bank.BUI;
using Content.Shared.Bank.Events;
using Robust.Client.GameObjects;

namespace Content.Client.Cargo.BUI;

public sealed class BankATMMenuBoundUserInterface : BoundUserInterface
{
private BankATMMenu? _menu;

public BankATMMenuBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) {}

protected override void Open()
{
base.Open();

_menu = new BankATMMenu();
_menu.WithdrawRequest += OnWithdraw;
_menu.DepositRequest += OnDeposit;
_menu.OnClose += Close;
_menu.OpenCentered();
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
_menu?.Dispose();
}
}

private void OnWithdraw()
{
if (_menu?.Amount is not int amount)
return;

SendMessage(new BankWithdrawMessage(amount));
}

private void OnDeposit()
{
SendMessage(new BankDepositMessage());
}

protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);

if (state is not BankATMMenuInterfaceState bankState)
return;

_menu?.SetEnabled(bankState.Enabled);
_menu?.SetBalance(bankState.Balance);
_menu?.SetDeposit(bankState.Deposit);
}
}
63 changes: 63 additions & 0 deletions Content.Client/Bank/BUI/StationBankATMMenuBoundUserInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Content.Client.Bank.UI;
using Content.Shared.Bank.BUI;
using Content.Shared.Bank.Events;
using Robust.Client.GameObjects;
using Content.Shared.Access.Systems;

namespace Content.Client.Cargo.BUI;

public sealed class StationBankATMMenuBoundUserInterface : BoundUserInterface
{
private StationBankATMMenu? _menu;

public StationBankATMMenuBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) {}

protected override void Open()
{
base.Open();

_menu = new StationBankATMMenu();
_menu.WithdrawRequest += OnWithdraw;
_menu.DepositRequest += OnDeposit;
_menu.OnClose += Close;
_menu.PopulateReasons();
_menu.OpenCentered();
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
_menu?.Dispose();
}
}

private void OnWithdraw()
{
if (_menu?.Amount is not int amount)
return;

SendMessage(new StationBankWithdrawMessage(amount, _menu.Reason, _menu.Description));
}

private void OnDeposit()
{
if (_menu?.Amount is not int amount)
return;

SendMessage(new StationBankDepositMessage(amount, _menu.Reason, _menu.Description));
}

protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);

if (state is not StationBankATMMenuInterfaceState bankState)
return;

_menu?.SetEnabled(bankState.Enabled);
_menu?.SetBalance(bankState.Balance);
_menu?.SetDeposit(bankState.Deposit);
}
}
51 changes: 51 additions & 0 deletions Content.Client/Bank/BUI/WithdrawlBankATMMenuBoundUserInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Content.Client.Bank.UI;
using Content.Shared.Bank.BUI;
using Content.Shared.Bank.Events;
using Robust.Client.GameObjects;

namespace Content.Client.Cargo.BUI;

public sealed class WithdrawBankATMMenuBoundUserInterface : BoundUserInterface
{
private WithdrawBankATMMenu? _menu;

public WithdrawBankATMMenuBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) {}

protected override void Open()
{
base.Open();

_menu = new WithdrawBankATMMenu();
_menu.WithdrawRequest += OnWithdraw;
_menu.OnClose += Close;
_menu.OpenCentered();
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
_menu?.Dispose();
}
}

private void OnWithdraw()
{
if (_menu?.Amount is not int amount)
return;

SendMessage(new BankWithdrawMessage(amount));
}

protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);

if (state is not BankATMMenuInterfaceState bankState)
return;

_menu?.SetEnabled(bankState.Enabled);
_menu?.SetBalance(bankState.Balance);
}
}
26 changes: 26 additions & 0 deletions Content.Client/Bank/UI/BankATMMenu.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
SetSize="300 176"
MinSize="300 176">
<BoxContainer Margin="10 2 10 2" Orientation="Vertical">
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'bank-atm-menu-balance-label'}"
StyleClasses="LabelKeyText" />
<Label Name="BalanceLabel"
Text="{Loc 'bank-atm-menu-no-bank'}" />
</BoxContainer>
<LineEdit Name="WithdrawEdit" MinSize="80 0" />
<Button Name="WithdrawButton"
Text="{Loc 'bank-atm-menu-withdraw-button'}"/>
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'bank-atm-menu-deposit-label'}"
StyleClasses="LabelKeyText" />
<Label Name="DepositLabel"
Text="{Loc 'bank-atm-menu-no-deposit'}" />
</BoxContainer>
<Button Name="DepositButton"
Text="{Loc 'bank-atm-menu-deposit-button'}"/>
<TextureButton VerticalExpand="True" />
</BoxContainer>
</controls:FancyWindow>
Loading
Loading