public static KeyValuePair <Sprite, string> RecalculateValues(List <CurrencyNode> usedCurrencyNodes, bool setIcon = true) { //Debug.Log("CurrencyConverter.RecalculateValues()"); Sprite returnSprite = null; List <string> returnStrings = new List <string>(); Dictionary <Currency, CurrencyNode> squishedNodes = new Dictionary <Currency, CurrencyNode>(); foreach (CurrencyNode currencyNode in usedCurrencyNodes) { if (currencyNode.currency != null) { if (squishedNodes.ContainsKey(currencyNode.currency)) { CurrencyNode tmp = squishedNodes[currencyNode.currency]; tmp.MyAmount += currencyNode.MyAmount; squishedNodes[currencyNode.currency] = tmp; } else { CurrencyNode tmp = new CurrencyNode(); tmp.currency = currencyNode.currency; tmp.MyAmount = currencyNode.MyAmount; squishedNodes.Add(tmp.currency, tmp); } } } if (squishedNodes.Count > 0) { //Debug.Log("LootableDrop.RecalculateValues(): squishedNodes.count: " + squishedNodes.Count); bool nonZeroFound = false; foreach (KeyValuePair <Currency, int> keyValuePair in CurrencyConverter.RedistributeCurrency(squishedNodes.ElementAt(0).Value.currency, squishedNodes.ElementAt(0).Value.MyAmount)) { if (keyValuePair.Value > 0 && nonZeroFound == false) { nonZeroFound = true; if (setIcon) { //Debug.Log("LootableDrop.RecalculateValues(): setting icon: " + keyValuePair.Key.MyIcon.name); returnSprite = keyValuePair.Key.Icon; } } if (nonZeroFound == true) { returnStrings.Add(keyValuePair.Value + " " + keyValuePair.Key.DisplayName); } } } //Debug.Log("LootableDrop.RecalculateValues(): " + summary); return(new KeyValuePair <Sprite, string>(returnSprite, string.Join("\n", returnStrings))); }
public void UpdateCurrencyAmount(Currency currency, int currencyAmount, string priceString) { //Debug.Log(gameObject.name + ".CurrencyBarController.UpdateCurrencyAmount(" + currency.DisplayName + ", " + currencyAmount + ", " + priceString + ")"); Dictionary <Currency, int> currencyList = CurrencyConverter.RedistributeCurrency(currency, currencyAmount); ClearCurrencyAmounts(); // spawn new ones if (priceText != null) { if (priceString != string.Empty) { priceText.gameObject.SetActive(true); priceText.text = priceString; } } int counter = 0; foreach (KeyValuePair <Currency, int> currencyPair in currencyList) { //Debug.Log(gameObject.name + ".CurrencyBarController.UpdateCurrencyAmount(" + currency.MyName + ", " + currencyAmount + "): currencyPair.Key: " + currencyPair.Key + "; currencyPair.Value: " + currencyPair.Value); //GameObject go = Instantiate(currencyAmountPrefab, currencyAmountParent.transform); //go.transform.SetAsFirstSibling(); //CurrencyAmountController currencyAmountController = go.GetComponent<CurrencyAmountController>(); //currencyAmountControllers.Add(currencyAmountController); if (currencyAmountControllers.Count > counter) { CurrencyAmountController currencyAmountController = currencyAmountControllers[counter]; currencyAmountController.gameObject.SetActive(true); if (currencyAmountController.MyCurrencyIcon != null) { currencyAmountController.MyCurrencyIcon.SetDescribable(currencyPair.Key); } if (currencyAmountController.MyAmountText != null) { currencyAmountController.MyAmountText.text = currencyPair.Value.ToString(); } } counter += 1; } }