/*
     * -----------
     * SELL BUTTON
     * -----------
     */

    public void Sell_Button()
    {
        // if theres nothing in the items to sell inventory do nothing.
        if (buyAndSellItems.GetInventorySize() < 1)
        {
            return;
        }

        for (int i = 0; i < buyAndSellItems.GetInventorySize(); i++)
        {
            // check if the item exists
            ItemContainer item = buyAndSellItems.GetItemFromIndex(i);
            if (item != null)
            {
                // check if it actually sold.
                bool sold = shop.SellItem(player, item.Id, item.Value);
                // tell player if it didnt sell.
                if (!sold)
                {
                    outputWarning.text += string.Format("Item: {0} couldn't be sold.\n", item.Name);
                }
            }
        }

        // clear the items to sell inventory
        buyAndSellItems.RemoveAll();

        // clear all the inputs
        foreach (InputField input in inputs)
        {
            input.text = "";
        }
    }
    public void Button_SetShopBuy()
    {
        // hide the sell buy option panel
        sellBuyOptionPanel.SetActive(false);

        // make the shop panel visible
        shopPanel.SetActive(true);

        // make the buy button visible
        buyButton.SetActive(true);

        if (shopText != null)
        {
            shopText.text = "BUY";
        }

        currInv = shop.inv;

        // set the hud icons to show the current inventory's items
        for (int i = 0; i < itemIcons.Length; i++)
        {
            if (currInv.GetItemFromIndex(i) != null)
            {
                itemIcons[i].sprite = currInv.GetItemFromIndex(i).Image;
            }
            else
            {
                itemIcons[i].gameObject.SetActive(false);
                inputs[i].gameObject.SetActive(false);
            }
        }
    }
    // parsing the text entered into the input fields then cloning the item from the player inventory.
    // the cloned items quantity is changed to the input amount and then its added to the items to sell
    // inventory.
    private bool ParseAndAdd(int index, string text)
    {
        // Clear the HUD output warning.
        outputWarning.text = "";

        ItemContainer item = currInv.GetItemFromIndex(index);

        if (text == "" || text == "0")
        {
            return(false);
        }

        if (item == null)
        {
            outputWarning.text = "ERROR: Item doesn't exist?";
            return(false);
        }

        if (item.Price == 0)
        {
            outputWarning.text = string.Format("Item {0} cannot be sold.\n", item.Name);
            return(false);
        }
        else
        {
            int i;

            if (int.TryParse(text, out i))
            {
                if (i > 0)
                {
                    ItemContainer clone = new ItemContainer(item)
                    {
                        Value = i
                    };
                    buyAndSellItems.AddItem(clone);
                    return(true);
                }
                outputWarning.text = string.Format("Invalid amount entered for: {0}", item.Name);
                return(false);
            }
            outputWarning.text = string.Format("Invalid input entered for: {0}", item.Name);
            return(false);
        }
    }