Example #1
0
        public override void ShowDialog(string title, string description, string yes, string no, int minValue, int maxValue, IntValDialogCallback yesCallback, IntValDialogCallback noCallback)
        {
            base.ShowDialog(title, description, yes, no, minValue, maxValue, yesCallback, noCallback);

            inputField.onValueChange.AddListener((string result) =>
            {
                uint amount = uint.Parse(result); // Let's trust Unity on this...

                float finalPrice = 0.0f;
                if (action == ItemBuySellDialogAction.Buying)
                {
                    finalPrice = vendor.GetBuyPrice(inventoryItem, amount);
                }
                else if (action == ItemBuySellDialogAction.Selling)
                {
                    finalPrice = vendor.GetSellPrice(inventoryItem, amount);
                }
                else if (action == ItemBuySellDialogAction.BuyingBack)
                {
                    finalPrice = vendor.GetBuyBackPrice(inventoryItem, amount);
                }

                price.text = InventorySettingsManager.instance.currencyFormatter.Format(finalPrice);
                if (action == ItemBuySellDialogAction.Buying || action == ItemBuySellDialogAction.BuyingBack)
                {
                    if (finalPrice > InventoryManager.instance.inventory.gold)
                    {
                        price.color = unAffordableColor;
                    }
                    else
                    {
                        price.color = affordableColor;
                    }
                }
                else
                {
                    price.color = affordableColor;
                }
            });
            inputField.onValueChange.Invoke(inputField.text); // Hit the event on start
        }