6
StarHorizon_Public/Content.Client/_NF/Shipyard/BUI/ShipyardConsoleBoundUserInterface.cs
2025-11-03 10:15:18 +03:00

87 lines
3.2 KiB
C#

using Content.Client._NF.Shipyard.UI;
using Content.Shared.Containers.ItemSlots;
using Content.Shared._NF.Shipyard.BUI;
using Content.Shared._NF.Shipyard.Events;
using static Robust.Client.UserInterface.Controls.BaseButton;
using Robust.Client.UserInterface;
namespace Content.Client._NF.Shipyard.BUI;
public sealed class ShipyardConsoleBoundUserInterface : BoundUserInterface
{
private ShipyardConsoleMenu? _menu;
// private ShipyardRulesPopup? _rulesWindow; // Frontier
public int Balance { get; private set; }
public int? ShipSellValue { get; private set; }
public ShipyardConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
protected override void Open()
{
base.Open();
if (_menu == null)
{
_menu = this.CreateWindow<ShipyardConsoleMenu>();
_menu.OnOrderApproved += ApproveOrder;
_menu.OnSellShip += SellShip;
_menu.TargetIdButton.OnPressed += _ => SendMessage(new ItemSlotButtonPressedEvent("ShipyardConsole-targetId"));
// Disable the NFSD popup for now.
// var rules = new FormattedMessage();
// _rulesWindow = new ShipyardRulesPopup(this);
// if (ShipyardConsoleUiKey.Security == (ShipyardConsoleUiKey) UiKey)
// {
// rules.AddText(Loc.GetString($"shipyard-rules-default1"));
// rules.PushNewline();
// rules.AddText(Loc.GetString($"shipyard-rules-default2"));
// _rulesWindow.ShipRules.SetMessage(rules);
// _rulesWindow.OpenCentered();
// }
}
}
private void Populate(List<string> availablePrototypes, List<string> unavailablePrototypes, bool freeListings, bool validId)
{
if (_menu == null)
return;
_menu.PopulateProducts(availablePrototypes, unavailablePrototypes, freeListings, validId);
_menu.PopulateCategories(availablePrototypes, unavailablePrototypes);
_menu.PopulateClasses(availablePrototypes, unavailablePrototypes);
_menu.PopulateEngines(availablePrototypes, unavailablePrototypes);
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
if (state is not ShipyardConsoleInterfaceState cState)
return;
Balance = cState.Balance;
ShipSellValue = cState.ShipSellValue;
var castState = (ShipyardConsoleInterfaceState) state;
Populate(castState.ShipyardPrototypes.available, castState.ShipyardPrototypes.unavailable, castState.FreeListings, castState.IsTargetIdPresent);
_menu?.UpdateState(castState);
}
private void ApproveOrder(ButtonEventArgs args)
{
if (args.Button.Parent?.Parent is not VesselRow row || row.Vessel == null)
{
return;
}
var vesselId = row.Vessel.ID;
SendMessage(new ShipyardConsolePurchaseMessage(vesselId));
}
private void SellShip(ButtonEventArgs args)
{
//reserved for a sanity check, but im not sure what since we check all the important stuffs on server already
SendMessage(new ShipyardConsoleSellMessage());
}
}