Exemplo n.º 1
0
    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;
    }
Exemplo n.º 2
0
    public static void SetBuyButtonState(bool active, string cost = "")
    {
        if (BuyButton.activeSelf)
        {
            BuyButton.GetComponent <Button>().interactable = active;

            if (cost.Length > 0)
            {
                GameObject.Find("TextPrize").GetComponent <Text>().text = cost;
            }
        }
    }
Exemplo n.º 3
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");
    }
Exemplo n.º 4
0
 public static void ShowBuyButton(bool show)
 {
     BuyButton.GetComponent <Button>().interactable = false;
     BuyButton.SetActive(show);
 }
Exemplo n.º 5
0
    // 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);
                }
            }
        }
    }