Skip to main content

ShopInterface

A class in Root.Township, Alta.Customization.

Checkout in the customization room: lists worn items the player doesn't own as a cart, shows the total and buys them through the Alta shop API. Client side.

Constructors​

MemberWhat it is
ShopInterface()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

MemberWhat it is
static ShopInterface instanceThe first shop interface created; not a strict singleton.
15 private and internal fields
MemberWhat it is
private TextRenderer balanceTextText showing the balance.
private List<ShopInterfaceItem> currentCartCart entries currently shown.
private int currentCartCostTotal price of the cart.
private PlayerCustomizationHandler customizationHandlerHandler whose worn items make up the cart.
private bool isBuyingTrue while a purchase is running, to block repeats.
private BoolUnityEvent isBuyingEventEvent raised with true when buying starts and false when it ends.
private ShopInterfaceItem itemPrefabPrefab for a cart entry.
private Transform itemsParentParent for cart entries.
private float itemsSpacingVertical gap between cart entries.
private static Logger loggerNLog logger for this class.
private PlayerCharacterCustomizationManager managerCustomization manager whose item events are watched.
private Dictionary<uint, ShopItemDetailedForUser> mappedItemsShop items by compressed SKU hash.
private StringHandler purchaseFailedWithErrorEvent given the error text when a purchase fails.
private AltaEvent successfullPurchaseEvent raised when every cart item was bought.
private TextRenderer totalCostText showing the cart total.

Methods​

MemberWhat it is
async void AttemptBuy()Buys each cart item through the API if the balance covers it; stops and shows an error on the first failure, then refreshes balance and cart.
void Refresh()Runs the login setup again and rebuilds the cart.
void UpdateBalance(int newBalance)Shows a balance on the balance text.
void UpdateCheckout()Rebuilds the cart from worn, unowned items, one entry per set on the store, and updates the total.
protected override async void LoggedIn()Loads shop items, fetches the balance, waits for the customization manager and rebuilds the cart when items change.
protected override void LoggedOut()Clears the shop item map.
protected override void OnDestroy()Unsubscribes from balance and item events and clears instance.
2 private and internal methods
MemberWhat it is
private void Awake()Sets instance if none is set.
private void UpdateCheckout(uint obj)Rebuilds the cart from worn, unowned items, one entry per set on the store, and updates the total.