void DrawItem(InventoryItemStack pStack) { if (pStack != null) { ItemUIPrefab.GetComponent <Button>().interactable = true; ItemUIPrefab.ItemIcon.color = Color.white; ItemUIPrefab.ItemIcon.sprite = pStack.ContainedItem.Icon; ItemUIPrefab.ItemAmount.text = pStack.Amount.ToString(); } else { ItemUIPrefab.GetComponent <Button>().interactable = false; ItemUIPrefab.ItemIcon.color = new Color(0, 0, 0, 0); ItemUIPrefab.ItemAmount.text = ""; } ItemStackUI itemUI = Instantiate(ItemUIPrefab, ItemUIContainer); itemUI.Button = itemUI.GetComponent <Button>(); itemUI.ItemStack = pStack; DrawnItems.Add(itemUI); itemUI.Button.onClick.AddListener(delegate { SetSelectedItem(pStack); }); if (TransferUI != null && TransferUI.IsOpen) { itemUI.Button.onClick.AddListener(delegate { TransferUI.TransferItem(pStack, this); }); } else if (CraftingInputUI != null && CraftingInputUI.IsOpen) { itemUI.Button.onClick.AddListener(delegate { CraftingInputUI.AddItem(pStack, this); }); } }
public void DrawBasket() { ClearBasketItems(); BuyButton.onClick.RemoveAllListeners(); float weight = 0; BasketValue = 0; int slotAmt = BasketInventory.ContainedStacks.Count; float availableWeight = PlayerInventory.MaxWeight - PlayerInventory.CurrentWeight; float availableStacks = PlayerInventory.MaxStacks - PlayerInventory.ContainedStacks.Count; bool canBuy = true; foreach (InventoryItemStack itemStack in BasketInventory.ContainedStacks) { ItemStackUI itemUI = Instantiate(StackUI, BasketItemsContainer); itemUI.ItemIcon.sprite = itemStack.ContainedItem.Icon; itemUI.ItemAmount.text = itemStack.Amount.ToString(); float price = itemStack.Amount * ((itemStack.ContainedItem.Value) + (itemStack.ContainedItem.Value * (itemStack.ContainedItem.Markup / 100))); itemUI.ItemIcon.color = Color.white; itemUI.GetComponent <Button>().interactable = true; itemUI.GetComponent <Button>().onClick.AddListener( delegate() { RemoveFromBasket(itemStack); } ); weight += itemStack.Amount * itemStack.ContainedItem.Weight; BasketValue += price; } WeightText.text = "Weight: " + weight.ToString("F2") + "/" + availableWeight.ToString("F2"); if (weight <= availableWeight) { WeightText.color = Color.green; } else { WeightText.color = Color.red; canBuy = false; } SlotsText.text = "Slots: " + slotAmt.ToString() + "/" + availableStacks.ToString(); if (slotAmt <= availableStacks) { SlotsText.color = Color.green; } else { SlotsText.color = Color.red; canBuy = false; } TotalPriceText.text = "Total: " + BasketValue.ToString("F2") + "/" + PlayerInventory.Gold.ToString("F2"); if (BasketValue <= PlayerInventory.Gold) { TotalPriceText.color = Color.green; } else { TotalPriceText.color = Color.red; canBuy = false; } if (canBuy && BasketInventory.ContainedStacks.Count > 0) { BuyButton.interactable = true; BuyButton.onClick.AddListener(delegate() { BuyBasket(); }); } else { BuyButton.interactable = false; } }