2024-10-15 15:22:06 +03:00
|
|
|
using System.Text;
|
2024-10-29 12:18:35 +03:00
|
|
|
using Content.Shared._CP14.Cargo;
|
2024-10-15 15:22:06 +03:00
|
|
|
using Content.Shared.UserInterface;
|
|
|
|
|
|
2024-10-26 18:18:30 +03:00
|
|
|
namespace Content.Server._CP14.Cargo;
|
2024-10-15 15:22:06 +03:00
|
|
|
|
|
|
|
|
public sealed partial class CP14CargoSystem
|
|
|
|
|
{
|
2024-10-19 01:09:15 +03:00
|
|
|
public void InitializeUI()
|
2024-10-15 15:22:06 +03:00
|
|
|
{
|
|
|
|
|
SubscribeLocalEvent<CP14CargoStoreComponent, BeforeActivatableUIOpenEvent>(OnBeforeUIOpen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TryInitStore(Entity<CP14CargoStoreComponent> ent)
|
|
|
|
|
{
|
|
|
|
|
//TODO: There's no support for multiple stations. (settlements).
|
|
|
|
|
var stations = _station.GetStations();
|
|
|
|
|
|
|
|
|
|
if (stations.Count == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!TryComp<CP14StationTravelingStoreShipTargetComponent>(stations[0], out var station))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ent.Comp.Station = new Entity<CP14StationTravelingStoreShipTargetComponent>(stations[0], station);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnBeforeUIOpen(Entity<CP14CargoStoreComponent> ent, ref BeforeActivatableUIOpenEvent args)
|
|
|
|
|
{
|
2024-10-19 01:09:15 +03:00
|
|
|
//TODO: If you open a store on a mapping, and initStore() it, the entity will throw an error when you try to save the grid\map.
|
|
|
|
|
|
2024-10-15 15:22:06 +03:00
|
|
|
if (ent.Comp.Station is null)
|
|
|
|
|
TryInitStore(ent);
|
|
|
|
|
|
|
|
|
|
UpdateUIProducts(ent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateAllStores()
|
|
|
|
|
{
|
2024-10-19 01:09:15 +03:00
|
|
|
//TODO: redo
|
2024-10-15 15:22:06 +03:00
|
|
|
var query = EntityQueryEnumerator<CP14CargoStoreComponent>();
|
|
|
|
|
while (query.MoveNext(out var uid, out var store))
|
|
|
|
|
{
|
|
|
|
|
UpdateUIProducts((uid, store));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateUIProducts(Entity<CP14CargoStoreComponent> ent)
|
|
|
|
|
{
|
|
|
|
|
if (ent.Comp.Station is null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var prodBuy = new HashSet<CP14StoreUiProductEntry>();
|
|
|
|
|
var prodSell = new HashSet<CP14StoreUiProductEntry>();
|
|
|
|
|
|
|
|
|
|
foreach (var proto in ent.Comp.Station.Value.Comp.CurrentBuyPositions)
|
|
|
|
|
{
|
|
|
|
|
|
2024-10-19 01:09:15 +03:00
|
|
|
var name = Loc.GetString(proto.Key.Name);
|
2024-10-15 15:22:06 +03:00
|
|
|
var desc = new StringBuilder();
|
2024-10-19 01:09:15 +03:00
|
|
|
desc.Append(Loc.GetString(proto.Key.Desc) + "\n");
|
|
|
|
|
foreach (var service in proto.Key.Services)
|
2024-10-15 15:22:06 +03:00
|
|
|
{
|
|
|
|
|
desc.Append(service.GetDescription(_proto, EntityManager));
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-25 00:23:35 +03:00
|
|
|
desc.Append("\n" + Loc.GetString("cp14-store-buy-hint", ("name", Loc.GetString(proto.Key.Name)), ("code", "[color=yellow][bold]#" + proto.Key.Code + "[/bold][/color]")));
|
2024-10-19 01:09:15 +03:00
|
|
|
|
|
|
|
|
prodBuy.Add(new CP14StoreUiProductEntry(proto.Key.ID, proto.Key.Icon, name, desc.ToString(), proto.Value));
|
2024-10-15 15:22:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var proto in ent.Comp.Station.Value.Comp.CurrentSellPositions)
|
|
|
|
|
{
|
2024-10-19 01:09:15 +03:00
|
|
|
var name = Loc.GetString(proto.Key.Name);
|
2024-10-15 15:22:06 +03:00
|
|
|
|
|
|
|
|
var desc = new StringBuilder();
|
2024-10-19 01:09:15 +03:00
|
|
|
desc.Append(Loc.GetString(proto.Key.Desc) + "\n");
|
|
|
|
|
desc.Append(proto.Key.Service.GetDescription(_proto, EntityManager) + "\n");
|
|
|
|
|
desc.Append("\n" + Loc.GetString("cp14-store-sell-hint", ("name", Loc.GetString(proto.Key.Name))));
|
2024-10-15 15:22:06 +03:00
|
|
|
|
2024-10-19 01:09:15 +03:00
|
|
|
prodSell.Add(new CP14StoreUiProductEntry(proto.Key.ID, proto.Key.Icon, name, desc.ToString(), proto.Value));
|
2024-10-15 15:22:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var stationComp = ent.Comp.Station.Value.Comp;
|
|
|
|
|
_userInterface.SetUiState(ent.Owner, CP14StoreUiKey.Key, new CP14StoreUiState(prodBuy, prodSell, stationComp.OnStation, stationComp.NextTravelTime));
|
|
|
|
|
}
|
|
|
|
|
}
|