shipyard ui cleanup (#1257)
* small cleanup * use BankClient for balance updating * pro * fixes fixes fixes * untroll engine --------- Signed-off-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: deltanedas <@deltanedas:kde.org> Co-authored-by: Tad "Taddy" Johnson <120885811+TadJohnson00@users.noreply.github.com> Co-authored-by: Milon <milonpl.git@proton.me> Co-authored-by: Milon <plmilonpl@gmail.com>
This commit is contained in:
parent
a28c339fe8
commit
36d634bdff
|
|
@ -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;
|
||||
|
||||
|
|
@ -28,10 +27,14 @@ public sealed class ShipyardConsoleBoundUserInterface : BoundUserInterface
|
|||
{
|
||||
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)
|
||||
|
|
@ -48,8 +51,16 @@ public sealed class ShipyardConsoleBoundUserInterface : BoundUserInterface
|
|||
{
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -4,9 +4,7 @@ using Content.Shared.Shipyard;
|
|||
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;
|
||||
|
||||
|
|
@ -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;
|
||||
|
|
@ -80,7 +78,7 @@ public sealed partial class ShipyardConsoleMenu : FancyWindow
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public sealed partial class VesselRow : PanelContainer
|
|||
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();
|
||||
|
|
|
|||
|
|
@ -2,12 +2,11 @@ using Content.Server.Cargo.Components;
|
|||
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;
|
||||
|
||||
|
|
@ -26,7 +25,9 @@ public sealed class ShipyardConsoleSystem : SharedShipyardConsoleSystem
|
|||
{
|
||||
base.Initialize();
|
||||
|
||||
Subs.BuiEvents<ShipyardConsoleComponent>(ShipyardConsoleUiKey.Key, subs =>
|
||||
SubscribeLocalEvent<ShipyardConsoleComponent, BankBalanceUpdatedEvent>(OnBalanceUpdated);
|
||||
Subs.BuiEvents<ShipyardConsoleComponent>(ShipyardConsoleUiKey.Key,
|
||||
subs =>
|
||||
{
|
||||
subs.Event<BoundUIOpenedEvent>(OnOpened);
|
||||
});
|
||||
|
|
@ -61,13 +62,17 @@ public sealed class ShipyardConsoleSystem : SharedShipyardConsoleSystem
|
|||
|
||||
_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);
|
||||
}
|
||||
|
||||
// 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);
|
||||
private void OnBalanceUpdated(Entity<ShipyardConsoleComponent> ent, ref BankBalanceUpdatedEvent args)
|
||||
{
|
||||
if (!_ui.IsUiOpen(ent.Owner, ShipyardConsoleUiKey.Key))
|
||||
return;
|
||||
|
||||
UpdateUI(ent, args.Balance);
|
||||
}
|
||||
|
||||
private void OnOpened(Entity<ShipyardConsoleComponent> ent, ref BoundUIOpenedEvent args)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ using Content.Shared._DV.CCVars;
|
|||
using Content.Shared.Tag;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Configuration;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Content.Server.Shipyard;
|
||||
|
||||
|
|
|
|||
|
|
@ -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!;
|
||||
|
|
@ -23,7 +23,8 @@ public abstract class SharedShipyardConsoleSystem : EntitySystem
|
|||
{
|
||||
base.Initialize();
|
||||
|
||||
Subs.BuiEvents<ShipyardConsoleComponent>(ShipyardConsoleUiKey.Key, subs =>
|
||||
Subs.BuiEvents<ShipyardConsoleComponent>(ShipyardConsoleUiKey.Key,
|
||||
subs =>
|
||||
{
|
||||
subs.Event<ShipyardConsolePurchaseMessage>(OnPurchase);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
description: Used to purchase and sell shuttles
|
||||
components:
|
||||
- type: ShipyardConsole
|
||||
- type: BankClient
|
||||
- type: AccessReader
|
||||
access: [[ Captain ]]
|
||||
- type: ActivatableUI
|
||||
|
|
|
|||
Loading…
Reference in New Issue