* trading portal replace traveling storeship * clean up content * clean up content 2 * seel and buy realization * fixes * Update migration.yml * Update migration.yml * Update dev_map.yml * Update dev_map.yml * thats work correctly now * bugfies and visual * factions * faction restruct + name reduce * unnesting sell cargo positions * unnesting cargo positions * more cargo content * Update buy.yml * improve tradeportal visual * Update migration.yml * Bank ad Commandant removal * merchant objectives * finish * clean up content * Update migration.yml * fix goal calculation * Update comoss.yml * Update dev_map.yml
117 lines
4.5 KiB
C#
117 lines
4.5 KiB
C#
using System.Text;
|
|
using Content.Shared._CP14.Cargo;
|
|
using Content.Shared.UserInterface;
|
|
|
|
namespace Content.Server._CP14.Cargo;
|
|
|
|
public sealed partial class CP14CargoSystem
|
|
{
|
|
public void InitializeUI()
|
|
{
|
|
SubscribeLocalEvent<CP14TradingInfoBoardComponent, BeforeActivatableUIOpenEvent>(OnBeforeUIOpen);
|
|
}
|
|
|
|
private void TryInitStore(Entity<CP14TradingInfoBoardComponent> ent)
|
|
{
|
|
//TODO: more accurate way to find the trading portal, without lookup
|
|
var entitiesInRange = _lookup.GetEntitiesInRange<CP14TradingPortalComponent>(Transform(ent).Coordinates, 2);
|
|
foreach (var trading in entitiesInRange)
|
|
{
|
|
ent.Comp.TradingPortal = trading;
|
|
ent.Comp.CahcedFaction = trading.Comp.Faction;
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void OnBeforeUIOpen(Entity<CP14TradingInfoBoardComponent> ent, ref BeforeActivatableUIOpenEvent args)
|
|
{
|
|
//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.
|
|
|
|
if (ent.Comp.TradingPortal is null)
|
|
TryInitStore(ent);
|
|
|
|
UpdateUIProducts(ent);
|
|
}
|
|
|
|
private void UpdateUIProducts(Entity<CP14TradingInfoBoardComponent> ent)
|
|
{
|
|
if (ent.Comp.TradingPortal is null)
|
|
return;
|
|
|
|
if (!TryComp<CP14TradingPortalComponent>(ent.Comp.TradingPortal.Value, out var tradePortalComp))
|
|
return;
|
|
|
|
var prodBuy = new HashSet<CP14StoreUiProductEntry>();
|
|
var prodSell = new HashSet<CP14StoreUiProductEntry>();
|
|
|
|
//Add special buy positions
|
|
foreach (var (proto, price) in tradePortalComp.CurrentSpecialBuyPositions)
|
|
{
|
|
var name = proto.NameOverride ?? proto.Service.GetName(_proto);
|
|
var desc = new StringBuilder();
|
|
//desc.Append(Loc.GetString(proto.Desc) + "\n");
|
|
desc.Append("\n" + Loc.GetString("cp14-store-buy-hint", ("name", name), ("code", "[color=yellow][bold]#" + proto.Code + "[/bold][/color]")));
|
|
|
|
prodBuy.Add(new CP14StoreUiProductEntry(proto.ID, proto.IconOverride ?? proto.Service.GetTexture(_proto), proto.Service.GetEntityView(_proto), name, desc.ToString(), price, true));
|
|
}
|
|
|
|
//Add static buy positions
|
|
foreach (var (proto, price) in tradePortalComp.CurrentBuyPositions)
|
|
{
|
|
var name = proto.NameOverride ?? proto.Service.GetName(_proto);
|
|
var desc = new StringBuilder();
|
|
//desc.Append(Loc.GetString(proto.Desc) + "\n");
|
|
desc.Append("\n" + Loc.GetString("cp14-store-buy-hint", ("name", name), ("code", "[color=yellow][bold]#" + proto.Code + "[/bold][/color]")));
|
|
|
|
prodBuy.Add(new CP14StoreUiProductEntry(proto.ID, proto.IconOverride ?? proto.Service.GetTexture(_proto), proto.Service.GetEntityView(_proto), name, desc.ToString(), price, false));
|
|
}
|
|
|
|
//Add special sell positions
|
|
foreach (var (proto, price) in tradePortalComp.CurrentSpecialSellPositions)
|
|
{
|
|
var name = proto.Service.GetName(_proto);
|
|
|
|
var desc = new StringBuilder();
|
|
//desc.Append(Loc.GetString(proto.Desc) + "\n");
|
|
desc.Append("\n" + Loc.GetString("cp14-store-sell-hint", ("name", name)));
|
|
|
|
prodSell.Add(new CP14StoreUiProductEntry(
|
|
proto.ID,
|
|
proto.Service.GetTexture(_proto),
|
|
proto.Service.GetEntityView(_proto),
|
|
name,
|
|
desc.ToString(),
|
|
price,
|
|
true));
|
|
}
|
|
|
|
//Add static sell positions
|
|
foreach (var proto in tradePortalComp.CurrentSellPositions)
|
|
{
|
|
var name = proto.Key.Service.GetName(_proto);
|
|
|
|
var desc = new StringBuilder();
|
|
//desc.Append(Loc.GetString(proto.Key.Desc) + "\n");
|
|
desc.Append("\n" + Loc.GetString("cp14-store-sell-hint", ("name", name)));
|
|
|
|
prodSell.Add(new CP14StoreUiProductEntry(
|
|
proto.Key.ID,
|
|
proto.Key.Service.GetTexture(_proto),
|
|
proto.Key.Service.GetEntityView(_proto),
|
|
name,
|
|
desc.ToString(),
|
|
proto.Value,
|
|
false));
|
|
}
|
|
|
|
var shopName = ":3";
|
|
//Get shop name
|
|
if (ent.Comp.CahcedFaction is not null && _proto.TryIndex(ent.Comp.CahcedFaction.Value, out var indexedShop))
|
|
{
|
|
shopName = Loc.GetString(indexedShop.Name);
|
|
}
|
|
|
|
_userInterface.SetUiState(ent.Owner, CP14StoreUiKey.Key, new CP14StoreUiState(shopName, prodBuy, prodSell));
|
|
}
|
|
}
|