void SetMethods(ItemButton btn) { btn.GetComponent <Button>().onClick.AddListener(() => { btn.GetComponent <UIHighlight>().MakeStatic(); }); btn.GetComponent <UIHighlight>().OnMadeStaticAction += () => { Trade(); }; }
protected virtual void Start() { if (LayoutGroup == null || ItemButtonPrefab == null || ItemList == null) { return; } int count = ItemList.Count; for (int i = 0; i < count; i++) { ItemButton button = CreateButton(ItemList[i].Item); button.transform.SetParent(LayoutGroup.transform); button.transform.localScale = Vector3.one; m_Buttons.Add(button.GetComponent <Button>()); } if (RightBuffer != null) { RightBuffer.SetAsLastSibling(); } for (int k = 1; k < m_Buttons.Count - 1; k++) { Button button = m_Buttons[k]; SetupNavigation(button, m_Buttons[k - 1], m_Buttons[k + 1]); } SetupNavigation(m_Buttons[0], BackButton, m_Buttons[1]); SetupNavigation(m_Buttons[m_Buttons.Count - 1], m_Buttons[m_Buttons.Count - 2], null); }
public void TransferItems() { Debug.Log("went through"); if (amount != 0) { //money transfer currInv.money += amount * selectedItem.cost; otherInv.money -= amount * selectedItem.cost; //item transfer currInv.RemoveItems(selectedItem, amount); //should never return false otherInv.AddItems(selectedItem, amount); //update item lists itemList = new List <Item>(currInv.itemDict.Keys); itemIndex = 0; UpdateItemList(itemList, currInv, itemIndex); } //exit back to item scrolling if (itemList.Count == 0) { //inventory has no more items to display Debug.Log("No more items to buy/sell"); int lastType = menuType; menuType = 0; ItemButton.GetComponent <Button>().interactable = false; switch (lastType) { case -1: BuyButton.SetActive(true); SellButton.GetComponent <Button>().enabled = true; ES.SetSelectedGameObject(SellButton); StartCoroutine("MoveLeft"); break; case 1: SellButton.SetActive(true); BuyButton.GetComponent <Button>().enabled = true; ES.SetSelectedGameObject(BuyButton); StartCoroutine("MoveRight"); break; } } else { Button button = ItemList.GetComponentInChildren <Button>(); button.interactable = true; ES.SetSelectedGameObject(button.gameObject); itemScrolling = true; } AmountSelection.SetActive(false); selectedItem = null; }
public void SetItem(Item addedItem) { item = addedItem; isEmpty = false; itemButton.name = item.itemName; var img = itemButton.GetComponent <Image>(); img.type = Image.Type.Simple; img.sprite = item.GetItemIcon; img.preserveAspect = true; }
//взять кнопку из пула и просетапить ее полученным аргументом itemToSetupWith public void TakeOneButtonFromPoolAndSetupWith(Item itemToSetupWith) { GameObject returningGameObject = buttonObjectPool.GetObject(this.transform); ItemButton buttonUnderConstruction = returningGameObject.GetComponent <ItemButton> (); buttonUnderConstruction.Setup(itemToSetupWith); // фиксим якоря и оффсеты при возвращении из пула RectTransform buttonRectTransform = buttonUnderConstruction.GetComponent <RectTransform>(); buttonRectTransform.anchorMax = new Vector2(1, 1); buttonRectTransform.anchorMin = new Vector2(0, 0); buttonRectTransform.offsetMin = new Vector2(buttonRectTransform.offsetMin.x, 0); buttonRectTransform.offsetMax = new Vector2(buttonRectTransform.offsetMax.x, 0); buttonRectTransform.offsetMin = new Vector2(buttonRectTransform.offsetMin.y, 0); buttonRectTransform.offsetMax = new Vector2(buttonRectTransform.offsetMax.y, 0); }
public void OpenBuy() { menuType = 1; menu.transform.localPosition = new Vector3(180, 0, 0); AmountSelection.transform.localPosition = new Vector3(-95, -55, 0); SellButton.SetActive(false); BuyButton.GetComponent <Button>().enabled = false; ItemButton.GetComponent <Button>().interactable = true; ES.SetSelectedGameObject(ItemButton); itemList = new List <Item>(npcInv.itemDict.Keys); currInv = npcInv; otherInv = playerInv; UpdateItemList(itemList, currInv, 0); if (itemList.Count == 0) { //the button throws exceptions when there are no items selected, this prevents that ItemButton.GetComponent <Button>().interactable = false; } StartCoroutine("MoveLeft"); }
public static void MoveItemInInventory(ItemButton movedtoItemSlot, bool selectAmount = false, int amountToMove = 0) { GameManager gm = GameManager.instance; if (ctrlPressed) { // show the UI for how many you want to switch over GameObject go = GameObject.Find("DropUI"); GameObject canvas = go.transform.Find("DropCanvas").gameObject; DropPanel.item = replicatedItem; canvas.SetActive(true); Destroy(replicatedItem.gameObject); return; } if (gm.itemsHeld[movedtoItemSlot.itemAmount] != "") { if (gm.itemsHeld[movedtoItemSlot.itemAmount] == replicatedItem.itemName) { int amount = Int32.Parse(itemSlotDraggedFrom.amountText.text); if (!selectAmount) { gm.numberOfItems[itemSlotDraggedFrom.itemAmount] = 0; gm.itemsHeld[itemSlotDraggedFrom.itemAmount] = ""; } else { amount = amountToMove; } gm.numberOfItems[movedtoItemSlot.itemAmount] += amount; } else { // currently, it won't let you split a stack into a stack of something that isn't of the same type - everything will get flipped. string movedFromItemName = gm.itemsHeld[itemSlotDraggedFrom.itemAmount]; string movedToItemName = gm.itemsHeld[movedtoItemSlot.itemAmount]; int movedFromAmount = gm.numberOfItems[itemSlotDraggedFrom.itemAmount]; int movedToAmount = gm.numberOfItems[movedtoItemSlot.itemAmount]; // this is a different item, we want to switch the items around at this point gm.itemsHeld[itemSlotDraggedFrom.itemAmount] = movedToItemName; gm.numberOfItems[itemSlotDraggedFrom.itemAmount] = movedToAmount; gm.itemsHeld[movedtoItemSlot.itemAmount] = movedFromItemName; gm.numberOfItems[movedtoItemSlot.itemAmount] = movedFromAmount; } } else { int amount = Int32.Parse(itemSlotDraggedFrom.GetComponent <ItemButton>().amountText.text); if (!selectAmount) { gm.numberOfItems[itemSlotDraggedFrom.itemAmount] = 0; gm.itemsHeld[itemSlotDraggedFrom.itemAmount] = ""; } else { gm.numberOfItems[itemSlotDraggedFrom.itemAmount] -= amountToMove; amount = amountToMove; } // just add a new one gm.itemsHeld[movedtoItemSlot.itemAmount] = replicatedItem.itemName; gm.numberOfItems[movedtoItemSlot.itemAmount] = amount; } Inventory.instance.showItems(); }
// Update is called once per frame void Update() { int lastType = menuType; if (Input.GetButtonDown("Cancel")) { if (!itemScrolling) { //exit back to buy/sell menus AmountSelection.SetActive(false); Button button = ItemList.GetComponentInChildren <Button>(); button.interactable = true; ES.SetSelectedGameObject(button.gameObject); selectedItem = null; itemScrolling = true; } else if (menuType != 0) { menuType = 0; ItemButton.GetComponent <Button>().interactable = false; switch (lastType) { case -1: BuyButton.SetActive(true); SellButton.GetComponent <Button>().enabled = true; ES.SetSelectedGameObject(SellButton); StartCoroutine("MoveLeft"); break; case 1: SellButton.SetActive(true); BuyButton.GetComponent <Button>().enabled = true; ES.SetSelectedGameObject(BuyButton); StartCoroutine("MoveRight"); break; } } else { //exit out of the shop altogether ReturnToLast(); } } if (Input.GetButtonDown("Vertical")) { if (menuType != 0 && itemScrolling && itemList.Count != 0) { if (Input.GetAxisRaw("Vertical") > 0) { //scroll items up itemIndex--; } else { //scroll items down itemIndex++; } //loop around itemIndex += itemList.Count; itemIndex %= itemList.Count; UpdateItemList(itemList, currInv, itemIndex); } else if (menuType != 0 && !itemScrolling) { //amount select if (Input.GetAxisRaw("Vertical") > 0) { //increase amount changeItemAmount(1); } else { //decrease amount changeItemAmount(-1); } } } }