Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shuttle records console to allow copying ship deeds #2214

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Content.Client._NF.ShuttleRecords.UI;
using Content.Shared._NF.ShuttleRecords;
using Content.Shared._NF.ShuttleRecords.Events;
using Robust.Client.UserInterface.Controls;

namespace Content.Client._NF.ShuttleRecords.BUI;

public sealed class ShuttleRecordsConsoleBoundUserInterface(
EntityUid owner,
Enum uiKey
) : BoundUserInterface(owner, uiKey)
{
private ShuttleRecordsWindow? _window;

protected override void Open()
{
base.Open();
_window ??= new ShuttleRecordsWindow();
_window.OnCopyDeed += CopyDeed;
_window.OpenCentered();
}

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

if (_window == null || state is not ShuttleRecordsConsoleInterfaceState shuttleRecordsConsoleInterfaceState)
return;

_window?.UpdateState(shuttleRecordsConsoleInterfaceState);
}

/*
* This black magic code prevents multiple pop ups of the window from appearing.
*/
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
_window?.Dispose();
}

private void CopyDeed(ShuttleRecord shuttleRecord)
{
SendMessage(new CopyDeedMessage(shuttleRecord.EntityUid));
Close();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<PanelContainer xmlns="https://spacestation14.io"
Access="Public"
HorizontalExpand="True"
VerticalExpand="True"
MinSize="250 300">
<BoxContainer Orientation="Vertical">
<Label Name="ShuttleName" Margin="4 0 0 0"/>
<Label Name="ShuttleOwner" Margin="4 0 0 0"/>
<Label Name="ShuttleActivity" Margin="4 0 0 0"/>
<Button Name="CopyDeedButton" Text="{Loc 'shuttle-records-copy-deed-button'}" Access="Public"/>
</BoxContainer>
</PanelContainer>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;

namespace Content.Client._NF.ShuttleRecords.UI;

[GenerateTypedNameReferences]
public sealed partial class ShuttleRecordDetailsControl : PanelContainer
{
public sealed class ViewState(string shuttleName, string shuttleOwnerName, string activity, string toolTip = "", bool disabled = false)
{
public string ShuttleName { get; } = shuttleName;

public string ShuttleOwnerName { get; } = shuttleOwnerName;

public string Activity { get; } = activity;

public bool Disabled { get; } = disabled;

public string ToolTip { get; } = toolTip;
}

public ShuttleRecordDetailsControl(ViewState state)
{
RobustXamlLoader.Load(this);
ShuttleName.Text = state.ShuttleName;
ShuttleOwner.Text = state.ShuttleOwnerName;
ShuttleActivity.Text = state.Activity;
ToolTip = state.ToolTip;
CopyDeedButton.Disabled = state.Disabled;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Button xmlns="https://spacestation14.io">
<BoxContainer Orientation="Horizontal">
<Label Name="ShuttleName" Margin="4 0 0 0"/>
</BoxContainer>
</Button>
26 changes: 26 additions & 0 deletions Content.Client/_NF/ShuttleRecords/UI/ShuttleRecordListItem.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;

namespace Content.Client._NF.ShuttleRecords.UI;

[GenerateTypedNameReferences]
public sealed partial class ShuttleRecordListItem : Button
{
public sealed class ViewState(string shuttleName, string toolTip = "", bool disabled = false)
{
public string ShuttleName { get; } = shuttleName;

public bool Disabled { get; } = disabled;

public string ToolTip { get; } = toolTip;
}

public ShuttleRecordListItem(ViewState state)
{
RobustXamlLoader.Load(this);
ShuttleName.Text = state.ShuttleName;
ToolTip = state.ToolTip;
Disabled = state.Disabled;
}
}
40 changes: 40 additions & 0 deletions Content.Client/_NF/ShuttleRecords/UI/ShuttleRecordsWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<DefaultWindow xmlns="https://spacestation14.io"
xmlns:graphics="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
Title="{Loc 'shuttle-records-console-window-title'}"
MinSize="500 300">

<BoxContainer HorizontalExpand="True" VerticalExpand="True" Orientation="Horizontal" Margin="5">

<BoxContainer Orientation="Vertical" MinSize="250 300">
<Label Text="{Loc 'shuttle-records-transactions'}" />
<PanelContainer VerticalExpand="True" HorizontalExpand="True" Margin="10">
<PanelContainer.PanelOverride>
<graphics:StyleBoxFlat BorderThickness="2" BorderColor="#777777" />
</PanelContainer.PanelOverride>
<BoxContainer Orientation="Vertical"
VerticalExpand="True"
HorizontalExpand="True">


<ScrollContainer HorizontalExpand="True"
VerticalExpand="True"
VScrollEnabled="True">
<BoxContainer Name="ShuttleRecordList"
Orientation="Vertical"
HorizontalExpand="True"
VerticalExpand="True"
MinSize="50 50"
Margin="4">
</BoxContainer>
</ScrollContainer>
</BoxContainer>
</PanelContainer>
<Label Name="TransactionCostLabel" Text=""/>
</BoxContainer>

<BoxContainer Name="ShuttleRecordDetailsContainer" Orientation="Vertical" MinSize="250 300">
<Label Text="{Loc 'shuttle-records-detail-title'}" />

</BoxContainer>
</BoxContainer>
</DefaultWindow>
84 changes: 84 additions & 0 deletions Content.Client/_NF/ShuttleRecords/UI/ShuttleRecordsWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System.Linq;
using Content.Shared._NF.ShuttleRecords;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;

namespace Content.Client._NF.ShuttleRecords.UI;

[GenerateTypedNameReferences]
public sealed partial class ShuttleRecordsWindow : DefaultWindow
{
[Dependency] private readonly ILocalizationManager _loc = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;

public Action<ShuttleRecord>? OnCopyDeed;

public ShuttleRecordsWindow()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
}

public void UpdateState(ShuttleRecordsConsoleInterfaceState state)
{
ShuttleRecordList.RemoveAllChildren();
var viewStateList = BuildShuttleRecordListItemViewStateList(state.Records);
foreach (var pair in viewStateList)
{
var listItem = new ShuttleRecordListItem(pair.ViewState);
listItem.OnPressed += _ => OnShuttleRecordListItemPressed(pair.ShuttleRecord);
ShuttleRecordList.AddChild(listItem);
}

TransactionCostLabel.Text = _loc.GetString(
messageId: "shuttle-records-transaction-cost",
arg: ("cost", state.TransactionCost)
);
}

public record ShuttleRecordViewStatePair(
ShuttleRecord ShuttleRecord,
ShuttleRecordListItem.ViewState ViewState
);

private List<ShuttleRecordViewStatePair> BuildShuttleRecordListItemViewStateList(
List<ShuttleRecord> shuttleRecords)
{
return shuttleRecords.Select(shuttleRecord =>
new ShuttleRecordViewStatePair(
shuttleRecord,
new ShuttleRecordListItem.ViewState(
shuttleRecord.Name + " " + shuttleRecord.Suffix,
disabled: false,
toolTip: ""
)
))
.ToList();
}

private void OnShuttleRecordListItemPressed(ShuttleRecord shuttleRecord)
{
ShuttleRecordDetailsContainer.RemoveAllChildren();
var shuttleStatus = ShuttleExists(netEntity: shuttleRecord.EntityUid)
? _loc.GetString(messageId: "shuttle-records-shuttle-status-active")
: _loc.GetString(messageId: "shuttle-records-shuttle-status-inactive");
var viewState = new ShuttleRecordDetailsControl.ViewState(
shuttleName: _loc.GetString(messageId: "shuttle-records-shuttle-name-label",
arg: ("name", shuttleRecord.Name + shuttleRecord.Suffix)),
shuttleOwnerName: _loc.GetString(messageId: "shuttle-records-shuttle-owner-label",
arg: ("owner", shuttleRecord.OwnerName)),
activity: _loc.GetString(messageId: "shuttle-records-shuttle-status", arg: ("status", shuttleStatus)),
disabled: false,
toolTip: ""
);
var control = new ShuttleRecordDetailsControl(state: viewState);
control.CopyDeedButton.OnPressed += _ => OnCopyDeed?.Invoke(shuttleRecord);
ShuttleRecordDetailsContainer.AddChild(child: control);
}

private bool ShuttleExists(NetEntity netEntity)
{
return _entityManager.TryGetEntity(netEntity, out _);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Content.Server.Cargo.Components;
/// <summary>
/// Added to the abstract representation of a station to track its money.
/// </summary>
[RegisterComponent, Access(typeof(SharedCargoSystem))]
[RegisterComponent]
public sealed partial class StationBankAccountComponent : Component
{
[ViewVariables(VVAccess.ReadWrite), DataField("balance")]
Expand Down
Loading
Loading