Files
crystall-punk-14/Content.Server/_CP14/TravelingStoreShip/CP14CargoSystem.UI.cs
Ed d259191d3d Cargo system (#487)
* simple storeship arriving

* pupu

* ship cycling

* buy positions prototypes

* i hate UI

* PriceControl

* second tab ui

* baloon! pallets!

* update shop in town

* setup billboard timer

* split to sell and buy categories

* renaming gaming

* actually selling

* fix infinity selling

* improve timer

* move description too rigt part UI

* bar selling

* iron cabinet

* purge currency categories

* remove town balance, add money box

* special proposal, FTLImmune anchor

* fix UI

* remove tests buying

* Update CP14StoreWindow.xaml.cs

* currency converter

* currency clean up

* Update CP14CargoSystem.cs

* clean up part 2

* rider petpet

* coins audio

* coin improvment

* Update coins.yml

* translate

* more coins roundstart

* Update wallet.yml

* Update wallet.yml

* generate coin problem fix

* refactor proto reading

* fixes

* huh

* shuttle logshit fix, add to tavern map

* Update CP14StationTravelingStoreShipTargetComponent.cs
2024-10-15 15:22:06 +03:00

88 lines
2.9 KiB
C#

using System.Text;
using Content.Shared._CP14.TravelingStoreShip;
using Content.Shared.UserInterface;
namespace Content.Server._CP14.TravelingStoreShip;
public sealed partial class CP14CargoSystem
{
public void InitializeStore()
{
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)
{
if (ent.Comp.Station is null)
TryInitStore(ent);
UpdateUIProducts(ent);
}
//TODO: redo
private void UpdateAllStores()
{
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)
{
if (!_proto.TryIndex(proto.Key, out var indexedProto))
continue;
var name = Loc.GetString(indexedProto.Name);
var desc = new StringBuilder();
desc.Append(Loc.GetString(indexedProto.Desc) + "\n");
foreach (var service in indexedProto.Services)
{
desc.Append(service.GetDescription(_proto, EntityManager));
}
prodBuy.Add(new CP14StoreUiProductEntry(proto.Key.Id, indexedProto.Icon, name, desc.ToString(), proto.Value));
}
foreach (var proto in ent.Comp.Station.Value.Comp.CurrentSellPositions)
{
if (!_proto.TryIndex(proto.Key, out var indexedProto))
continue;
var name = Loc.GetString(indexedProto.Name);
var desc = new StringBuilder();
desc.Append(Loc.GetString(indexedProto.Desc) + "\n");
desc.Append(indexedProto.Service.GetDescription(_proto, EntityManager));
prodSell.Add(new CP14StoreUiProductEntry(proto.Key.Id, indexedProto.Icon, name, desc.ToString(), proto.Value));
}
var stationComp = ent.Comp.Station.Value.Comp;
_userInterface.SetUiState(ent.Owner, CP14StoreUiKey.Key, new CP14StoreUiState(prodBuy, prodSell, stationComp.OnStation, stationComp.NextTravelTime));
}
}