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

shipyard ui cleanup #1257

Merged
merged 12 commits into from
Jan 1, 2025
23 changes: 17 additions & 6 deletions Content.Client/_DV/Shipyard/UI/ShipyardBoundUserInterface.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Content.Shared.Access.Systems;
using Content.Shared.Shipyard;
using Content.Shared.Whitelist;
using Robust.Client.GameObjects;
using Robust.Client.Player;
using Robust.Shared.Prototypes;

Expand All @@ -28,10 +27,14 @@ protected override void Open()
{
base.Open();

_menu = new ShipyardConsoleMenu(Owner, _proto, EntMan, _player, _access, _whitelist);
if (_menu == null)
{
_menu = new ShipyardConsoleMenu(Owner, _proto, EntMan, _player, _access, _whitelist);
_menu.OnClose += Close;
_menu.OnPurchased += Purchase;
}

_menu.OpenCentered();
_menu.OnClose += Close;
_menu.OnPurchased += Purchase;
}

protected override void UpdateState(BoundUserInterfaceState state)
Expand All @@ -48,8 +51,16 @@ protected override void Dispose(bool disposing)
{
base.Dispose(disposing);

if (disposing)
_menu?.Dispose();
if (!disposing)
return;

if (_menu == null)
return;

_menu.OnClose -= Close;
_menu.OnPurchased -= Purchase;
_menu.Close();
_menu = null;
}

private void Purchase(string id)
Expand Down
1 change: 0 additions & 1 deletion Content.Client/_DV/Shipyard/UI/ShipyardConsoleMenu.xaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<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="500 360"
MinSize="460 280"
Expand Down
8 changes: 3 additions & 5 deletions Content.Client/_DV/Shipyard/UI/ShipyardConsoleMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
using Content.Shared.Shipyard.Prototypes;
using Content.Shared.Whitelist;
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
using Robust.Client.Player;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;

Expand All @@ -20,8 +18,8 @@ public sealed partial class ShipyardConsoleMenu : FancyWindow

public event Action<string>? OnPurchased;

private readonly List<VesselPrototype> _vessels = new();
private readonly List<string> _categories = new();
private readonly List<VesselPrototype> _vessels = [];
private readonly List<string> _categories = [];

public Entity<ShipyardConsoleComponent> Console;
private string? _category;
Expand Down Expand Up @@ -80,7 +78,7 @@ private void PopulateProducts()
var search = SearchBar.Text.Trim().ToLowerInvariant();
foreach (var vessel in _vessels)
{
if (search.Length != 0 && !vessel.Name.ToLowerInvariant().Contains(search))
if (search.Length != 0 && !vessel.Name.Contains(search, StringComparison.InvariantCultureIgnoreCase))
continue;
if (_category != null && !vessel.Categories.Contains(_category))
continue;
Expand Down
2 changes: 1 addition & 1 deletion Content.Client/_DV/Shipyard/UI/VesselRow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
HorizontalExpand="True">
<BoxContainer Orientation="Horizontal"
HorizontalExpand="True">
<Button Name="Purchase" Text="{Loc 'purchase'}" StyleClasses="LabelSubText" />
<Button Name="Purchase" Text="{Loc 'shipyard-console-purchase'}" StyleClasses="LabelSubText" />
<Label Name="VesselName" HorizontalExpand="True" />
<PanelContainer>
<PanelContainer.PanelOverride>
Expand Down
2 changes: 1 addition & 1 deletion Content.Client/_DV/Shipyard/UI/VesselRow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public VesselRow(VesselPrototype vessel, bool access)
VesselName.Text = vessel.Name;

var tooltip = new Tooltip();
tooltip.SetMessage(FormattedMessage.FromMarkup(vessel.Description));
tooltip.SetMessage(FormattedMessage.FromMarkupOrThrow(vessel.Description));
Purchase.TooltipSupplier = _ => tooltip;
Purchase.Disabled = !access;
Purchase.OnPressed += _ => OnPurchasePressed?.Invoke();
Expand Down
19 changes: 12 additions & 7 deletions Content.Server/_DV/Shipyard/ShipyardConsoleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
using Content.Server.Cargo.Systems;
using Content.Server.Radio.EntitySystems;
using Content.Server.Station.Systems;
using Content.Shared.Cargo.Components;
using Content.Shared.Shipyard;
using Content.Shared.Shipyard.Prototypes;
using Content.Shared.Whitelist;
using Robust.Server.GameObjects;
using Robust.Shared.Random;
using System.Diagnostics.CodeAnalysis;

namespace Content.Server.Shipyard;

Expand All @@ -26,7 +25,9 @@ public override void Initialize()
{
base.Initialize();

Subs.BuiEvents<ShipyardConsoleComponent>(ShipyardConsoleUiKey.Key, subs =>
SubscribeLocalEvent<ShipyardConsoleComponent, BankBalanceUpdatedEvent>(OnBalanceUpdated);
Subs.BuiEvents<ShipyardConsoleComponent>(ShipyardConsoleUiKey.Key,
subs =>
{
subs.Event<BoundUIOpenedEvent>(OnOpened);
});
Expand Down Expand Up @@ -61,13 +62,17 @@ protected override void TryPurchase(Entity<ShipyardConsoleComponent> ent, Entity

_cargo.UpdateBankAccount(bank, bank.Comp, -vessel.Price);

var message = Loc.GetString("shipyard-console-docking", ("vessel", vessel.Name.ToString()));
var message = Loc.GetString("shipyard-console-docking", ("vessel", vessel.Name));
_radio.SendRadioMessage(ent, message, ent.Comp.Channel, ent);
Audio.PlayPvs(ent.Comp.ConfirmSound, ent);
}

private void OnBalanceUpdated(Entity<ShipyardConsoleComponent> ent, ref BankBalanceUpdatedEvent args)
{
if (!_ui.IsUiOpen(ent.Owner, ShipyardConsoleUiKey.Key))
return;

// TODO: make the ui updating more robust, make pr upstream to have UpdateBankAccount support things that arent ordering consoles
// TODO: then have shipyard have that component and update the ui when it changes balance
UpdateUI(ent, bank.Comp.Balance);
UpdateUI(ent, args.Balance);
}

private void OnOpened(Entity<ShipyardConsoleComponent> ent, ref BoundUIOpenedEvent args)
Expand Down
1 change: 0 additions & 1 deletion Content.Server/_DV/Shipyard/ShipyardSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Content.Shared.Tag;
using Robust.Server.GameObjects;
using Robust.Shared.Configuration;
using System.Diagnostics.CodeAnalysis;

namespace Content.Server.Shipyard;

Expand Down
7 changes: 4 additions & 3 deletions Content.Shared/_DV/Shipyard/SharedShipyardConsoleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace Content.Shared.Shipyard;
/// </summary>
public abstract class SharedShipyardConsoleSystem : EntitySystem
{
[Dependency] protected readonly AccessReaderSystem _access = default!;
[Dependency] protected readonly IPrototypeManager _proto = default!;
[Dependency] private readonly AccessReaderSystem _access = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] protected readonly SharedAudioSystem Audio = default!;
[Dependency] protected readonly SharedPopupSystem Popup = default!;
[Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
Expand All @@ -23,7 +23,8 @@ public override void Initialize()
{
base.Initialize();

Subs.BuiEvents<ShipyardConsoleComponent>(ShipyardConsoleUiKey.Key, subs =>
Subs.BuiEvents<ShipyardConsoleComponent>(ShipyardConsoleUiKey.Key,
subs =>
{
subs.Event<ShipyardConsolePurchaseMessage>(OnPurchase);
});
Expand Down
18 changes: 4 additions & 14 deletions Content.Shared/_DV/Shipyard/ShipyardUi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,16 @@ public enum ShipyardConsoleUiKey : byte
}

[Serializable, NetSerializable]
public sealed class ShipyardConsoleState : BoundUserInterfaceState
public sealed class ShipyardConsoleState(int balance) : BoundUserInterfaceState
{
public readonly int Balance;

public ShipyardConsoleState(int balance)
{
Balance = balance;
}
public readonly int Balance = balance;
}

/// <summary>
/// Ask the server to purchase a vessel.
/// </summary>
[Serializable, NetSerializable]
public sealed class ShipyardConsolePurchaseMessage : BoundUserInterfaceMessage
public sealed class ShipyardConsolePurchaseMessage(string vessel) : BoundUserInterfaceMessage
{
public readonly ProtoId<VesselPrototype> Vessel;

public ShipyardConsolePurchaseMessage(string vessel)
{
Vessel = vessel;
}
public readonly ProtoId<VesselPrototype> Vessel = vessel;
}
1 change: 1 addition & 0 deletions Resources/Locale/en-US/_DV/shipyard/shipyard-console.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ shipyard-console-menu-title = Shipyard Console

shipyard-console-error = Temporary embargo is in place, try later?
shipyard-console-docking = {$vessel} is en route to the station, eta 60 seconds.
shipyard-console-purchase = Purchase
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
description: Used to purchase and sell shuttles
components:
- type: ShipyardConsole
- type: BankClient
- type: AccessReader
access: [[ Captain ]]
- type: ActivatableUI
Expand Down
Loading