private void DisplayStat() { var stat = Constants.LastEndActionClickedName; int statId = (int)Soul.GetFieldValue(stat + "_Id"); int statLevel = (int)Soul.GetFieldValue(stat + "_Level"); int statAdd = (int)Soul.GetFieldValue(stat + "_Add"); string statName = Soul.SoulStatsNames[statId]; string statDescription = Soul.SoulStatsDescriptions[statId]; string statUnit = Soul.SoulStatsUnit[statId]; var fullTitle = statName + (statLevel > 0 ? " " + statLevel.ToString() : string.Empty); var currentDescription = statDescription + MakeContent("Current:", " +" + (statAdd * statLevel) + " " + statUnit); //Plural if (statUnit.Length > 3 && statUnit[0] != '<') //Check '<' because of custom materials { if (statAdd * statLevel > 1) { currentDescription += "s"; } } Instantiator.NewPopupYesNo(fullTitle, currentDescription, null, "Ok", AfterDisplayStat); object AfterDisplayStat(bool result) { return(result); } }
private void AddAction() { var stat = Constants.LastEndActionClickedName.Substring(Helper.CharacterAfterString(Constants.LastEndActionClickedName, "Add")); int statId = (int)Soul.GetFieldValue(stat + "_Id"); int statLevel = (int)Soul.GetFieldValue(stat + "_Level"); int statMax = (int)Soul.GetFieldValue(stat + "_Max"); int statAdd = (int)Soul.GetFieldValue(stat + "_Add"); int statPrice = (int)Soul.GetFieldValue(stat + "_Price"); string statName = Soul.SoulStatsNames[statId]; string statDescription = Soul.SoulStatsDescriptions[statId]; string statUnit = Soul.SoulStatsUnit[statId]; var fullTitle = statName + (statLevel > 0 ? " " + statLevel.ToString() : string.Empty); var currentDescription = statDescription + MakeContent("Current:", " +" + (statAdd * statLevel) + " " + statUnit); var currentPrice = statPrice * (statLevel + 1); var negative = "Cancel"; var positive = "<material=\"LongOrange\">" + currentPrice.ToString() + "</material>"; if (statLevel == statMax || Soul.Xp < currentPrice) { negative = null; positive = "Back"; } var nextDescription = string.Empty; if (statLevel != statMax) { nextDescription += MakeContent("Next:", " +" + (statAdd * (statLevel + 1)) + " " + statUnit); } //Plural if (statUnit.Length > 3 && statUnit[0] != '<') //Check '<' because of custom materials { if (statAdd * statLevel > 1) { currentDescription += "s"; } if (statAdd * (statLevel + 1) > 1 && nextDescription != string.Empty) { nextDescription += "s"; } } Instantiator.NewPopupYesNo(fullTitle, currentDescription + nextDescription, negative, positive, AfterAddAction); object AfterAddAction(bool result) { if (result == false || statLevel == statMax || Soul.Xp < currentPrice) { return(result); } Soul.Xp -= currentPrice; var levelFieldInfo = Soul.GetType().GetField(stat + "_Level"); levelFieldInfo.SetValue(Soul, statLevel + 1); UpdateTreeDisplay(); return(result); } }
private void HandleTreeBranchDisplay(string stat) { int statLevel = (int)Soul.GetFieldValue(stat + "_Level"); int statMax = (int)Soul.GetFieldValue(stat + "_Max"); int statId = (int)Soul.GetFieldValue(stat + "_Id"); int statPrice = (int)Soul.GetFieldValue(stat + "_Price"); GameObject treeBranch = GameObject.Find(stat); for (int i = 1; i <= statLevel; ++i) { if (i == 1) { treeBranch.transform.Find("Icon").GetComponent <SpriteRenderer>().sprite = Helper.GetSpriteFromSpriteSheet("Sprites/IconsSoulTree_" + (statId * 2)); } treeBranch.transform.Find("Level" + i.ToString("D2")).GetComponent <SpriteRenderer>().sprite = SoulTreeOnLevel; } treeBranch.transform.Find("Level").GetComponent <TMPro.TextMeshPro>().text = statLevel.ToString(); var currentPrice = statPrice * (statLevel + 1); var priceTextObject = treeBranch.transform.Find("Price").GetComponent <TMPro.TextMeshPro>(); var addSpriteObject = treeBranch.transform.Find("Add" + stat).GetComponent <SpriteRenderer>(); if (statLevel == statMax) { priceTextObject.enabled = true; priceTextObject.text = "Max"; addSpriteObject.enabled = false; } else if (Soul.Xp > currentPrice) { priceTextObject.enabled = false; addSpriteObject.enabled = true; } else { priceTextObject.enabled = true; priceTextObject.text = "<material=\"LongOrange\">" + currentPrice.ToString() + "</material>"; addSpriteObject.enabled = false; } }
private void SetButtons() { int nbSoulStats = Soul.SoulStats.Length; GameObject.Find("ButtonBack").GetComponent <ButtonBhv>().EndActionDelegate = GoToPreviousScene; int nbStats = 0; for (int i = 0; i < nbSoulStats; ++i) { var stat = Soul.SoulStats[i]; int statLevel = (int)Soul.GetFieldValue(stat + "_Level"); if (statLevel <= 0) { continue; } int statId = (int)Soul.GetFieldValue(stat + "_Id"); int statAdd = (int)Soul.GetFieldValue(stat + "_Add"); string statUnit = Soul.SoulStatsUnit[statId]; var desc = "+" + (statAdd * statLevel) + " " + statUnit; //Plural if (statUnit.Length > 3 && statUnit[0] != '<') //Check '<' because of custom materials { if (statAdd * statLevel > 1) { desc += "s"; } } var soulStat = Instantiator.NewSoulStat( new Vector3(_soulStatOriginX + (nbStats % 3) * _soulStatWidth, _soulStatOriginY - (nbStats / 3) * _soulStatHeight, 0.0f), statLevel, statId, desc); soulStat.GetComponent <ButtonBhv>().EndActionDelegate = DisplayStat; soulStat.name = stat; ++nbStats; } }