diff --git a/Items/CalamityGlobalItemTooltip.cs b/Items/CalamityGlobalItemTooltip.cs index adc684d5f4..0a75421d40 100644 --- a/Items/CalamityGlobalItemTooltip.cs +++ b/Items/CalamityGlobalItemTooltip.cs @@ -196,7 +196,7 @@ namespace CalamityMod.Items { if (!item.IsAir && AppliedEnchantment.HasValue) { - foreach (string line in AppliedEnchantment.Value.Description.Split('\n')) + foreach (string line in AppliedEnchantment.Value.Description.ToString().Split('\n')) { TooltipLine descriptionLine = new TooltipLine(Mod, "Enchantment", CalamityUtils.ColorMessage(line, Color.DarkRed)); tooltips.Add(descriptionLine); diff --git a/Localization/en-US/Mods.CalamityMod.UI.hjson b/Localization/en-US/Mods.CalamityMod.UI.hjson index a1c88b60c1..866ee448d2 100644 --- a/Localization/en-US/Mods.CalamityMod.UI.hjson +++ b/Localization/en-US/Mods.CalamityMod.UI.hjson @@ -43,12 +43,20 @@ Bloodthirsty: { Ephemeral: { DisplayName: Ephemeral - Description: Causes the damage output of this item to discharge from exhaustive use.\nIts damage returns naturally when not being used. It starts off with more damage than it normally would have. + Description: + ''' + Causes the damage output of this item to discharge from exhaustive use. + Its damage returns naturally when not being used. It starts off with more damage than it normally would have. + ''' } Hellbound: { DisplayName: Hellbound - Description: Causes minions to be created with a 40 second timer.\nOnce it runs out, they explode violently. Minions do more damage the longer they live and idly explode as well. + Description: + ''' + Causes minions to be created with a 40 second timer. + Once it runs out, they explode violently. Minions do more damage the longer they live and idly explode as well. + ''' } Tainted: { @@ -63,12 +71,20 @@ Traitorous: { Withering: { DisplayName: Withering - Description: When hurt, you heal a percentage of the damage taken based on how much accumulated damage you did overall beforehand, up to 100%.\nAfter this, you gain a damage boost while holding this item but also take exponential damage over time the longer you hold it. + Description: + ''' + When hurt, you heal a percentage of the damage taken based on how much accumulated damage you did overall beforehand, up to 100%. + After this, you gain a damage boost while holding this item but also take exponential damage over time the longer you hold it. + ''' } Persecuted: { DisplayName: Persecuted - Description: When attacked, or over time, demon portals appear near you.\nIf sufficiently damaged they are friendly; otherwise they attack you. They become angered if a portal is damaged. + Description: + ''' + When attacked, or over time, demon portals appear near you. + If sufficiently damaged they are friendly; otherwise they attack you. They become angered if a portal is damaged. + ''' } Lecherous: { diff --git a/UI/CalamitasEnchantments/CalamitasEnchantUI.cs b/UI/CalamitasEnchantments/CalamitasEnchantUI.cs index 7adeac5a12..e3a00ad00d 100644 --- a/UI/CalamitasEnchantments/CalamitasEnchantUI.cs +++ b/UI/CalamitasEnchantments/CalamitasEnchantUI.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using Terraria; using Terraria.ID; +using Terraria.Localization; using Terraria.ModLoader; using Terraria.UI; using Terraria.UI.Chat; @@ -174,7 +175,7 @@ namespace CalamityMod.UI.CalamitasEnchants int cost = CurrentlyHeldItem.value * 4; // Increase the cost of enchanting significantly if doing so would upgrade the item directly. - if (SelectedEnchantment.HasValue && SelectedEnchantment.Value.Name == CalamityUtils.GetTextValue(EnchantmentManager.ExhumedNamePath)) + if (SelectedEnchantment.HasValue && SelectedEnchantment.Value.Name == CalamityUtils.GetText(EnchantmentManager.ExhumedNamePath)) cost = (int)MathHelper.Min(cost, Item.buyPrice(5)) * 5; // Make it 20% cheaper if the player has the Discount Card or Greedy Ring @@ -202,7 +203,7 @@ namespace CalamityMod.UI.CalamitasEnchants Vector2 vectorDrawPosition = descriptionDrawPositionTopLeft.ToVector2(); Vector2 scale = new Vector2(0.8f, 0.825f) * MathHelper.Clamp(ResolutionRatio, 0.825f, 1f) * Main.UIScale; - string unifiedDescription = SelectedEnchantment.Value.Description.Replace("\n", " "); + string unifiedDescription = SelectedEnchantment.Value.Description.ToString().Replace("\n", " "); foreach (string line in Utils.WordwrapString(unifiedDescription, FontAssets.MouseText.Value, 400, 16, out _)) { if (string.IsNullOrEmpty(line)) @@ -349,10 +350,11 @@ namespace CalamityMod.UI.CalamitasEnchants public static void DrawEnchantmentName(SpriteBatch spriteBatch, Vector2 nameDrawCenter) { Vector2 scale = new Vector2(0.8f, 0.745f) * Main.UIScale; - float textWidth = FontAssets.MouseText.Value.MeasureString(SelectedEnchantment.Value.Name).X * scale.X; + string enchName = SelectedEnchantment.Value.Name.ToString(); + float textWidth = FontAssets.MouseText.Value.MeasureString(enchName).X * scale.X; Color drawColor = SelectedEnchantment.Value.Equals(EnchantmentManager.ClearEnchantment) ? Color.White : Color.Orange; nameDrawCenter.X -= textWidth * 0.5f; - ChatManager.DrawColorCodedStringWithShadow(spriteBatch, FontAssets.MouseText.Value, SelectedEnchantment.Value.Name, nameDrawCenter, drawColor, 0f, Vector2.Zero, scale); + ChatManager.DrawColorCodedStringWithShadow(spriteBatch, FontAssets.MouseText.Value, enchName, nameDrawCenter, drawColor, 0f, Vector2.Zero, scale); } public static void InteractWithEnchantIcon(int cost) @@ -369,12 +371,14 @@ namespace CalamityMod.UI.CalamitasEnchants if (cost <= 0 || !Main.LocalPlayer.CanAfford(cost)) return; + bool IsExhuming = SelectedEnchantment.Value.Name == CalamityUtils.GetText(EnchantmentManager.ExhumedNamePath); + int oldPrefix = CurrentlyHeldItem.prefix; CurrentlyHeldItem.SetDefaults(CurrentlyHeldItem.type); CurrentlyHeldItem.Prefix(oldPrefix); CurrentlyHeldItem = CurrentlyHeldItem.Clone(); - if (SelectedEnchantment.Value.Name == CalamityUtils.GetTextValue(EnchantmentManager.ExhumedNamePath)) + if (IsExhuming) { CurrentlyHeldItem.SetDefaults(EnchantmentManager.ItemUpgradeRelationship[CurrentlyHeldItem.type]); CurrentlyHeldItem.Prefix(oldPrefix); @@ -385,6 +389,10 @@ namespace CalamityMod.UI.CalamitasEnchants SelectedEnchantment.Value.CreationEffect?.Invoke(CurrentlyHeldItem); } + /* + TODO -- Currently bugged. Apparently, CalamityGlobalItem isn't loaded for tooltipPrefixComparisonItem + This makes the modifier texts warped in numbers but at least it's not destroying the UI + // Update the compare item. This is used to check comparisons when showing reforge tooltip bonuses. // Updating it with the same bonuses as what was applied to the real item will negate the incorrect numbers, // such as absurd damage boosts. @@ -392,11 +400,12 @@ namespace CalamityMod.UI.CalamitasEnchants Main.tooltipPrefixComparisonItem = new Item(); Main.tooltipPrefixComparisonItem.SetDefaults(Main.tooltipPrefixComparisonItem.type); - if (SelectedEnchantment.Value.Name != CalamityUtils.GetTextValue(EnchantmentManager.ExhumedNamePath)) + if (!IsExhuming) { Main.tooltipPrefixComparisonItem.Calamity().AppliedEnchantment = SelectedEnchantment.Value; SelectedEnchantment.Value.CreationEffect?.Invoke(Main.tooltipPrefixComparisonItem); } + */ // Take away the money for the cost. Main.LocalPlayer.BuyItem(cost); @@ -404,7 +413,7 @@ namespace CalamityMod.UI.CalamitasEnchants // Reset the enchantment index to prevent index problems on a different item. EnchantIndex = 0; - if (SelectedEnchantment.Value.Name == CalamityUtils.GetTextValue(EnchantmentManager.ExhumedNamePath)) + if (IsExhuming) SoundEngine.PlaySound(EXSound, Main.LocalPlayer.Center); else SoundEngine.PlaySound(EnchSound, Main.LocalPlayer.Center); diff --git a/UI/CalamitasEnchantments/Enchantment.cs b/UI/CalamitasEnchantments/Enchantment.cs index bdf32fb2a9..9bc5deb41d 100644 --- a/UI/CalamitasEnchantments/Enchantment.cs +++ b/UI/CalamitasEnchantments/Enchantment.cs @@ -1,12 +1,13 @@ using System; using Terraria; +using Terraria.Localization; namespace CalamityMod.UI.CalamitasEnchants { public struct Enchantment { - public string Name; - public string Description; + public LocalizedText Name; + public LocalizedText Description; public string IconTexturePath; public Action CreationEffect; public Action HoldEffect; @@ -16,7 +17,7 @@ namespace CalamityMod.UI.CalamitasEnchants // This is internal because CanBeAppliedTo should be used over this field directly. // Using that has the benefit of null checks and is objectively superior to using the raw delegate. internal Predicate ApplyRequirement; - public Enchantment(string name, string description, int id, string iconTexturePath, Action creationEffect, Action holdEffect, Predicate requirement) + public Enchantment(LocalizedText name, LocalizedText description, int id, string iconTexturePath, Action creationEffect, Action holdEffect, Predicate requirement) { Name = name; Description = description; @@ -26,7 +27,7 @@ namespace CalamityMod.UI.CalamitasEnchants ID = id; IconTexturePath = iconTexturePath; } - public Enchantment(string name, string description, int id, string iconTexturePath, Action holdEffect, Predicate requirement) + public Enchantment(LocalizedText name, LocalizedText description, int id, string iconTexturePath, Action holdEffect, Predicate requirement) { Name = name; Description = description; @@ -36,7 +37,7 @@ namespace CalamityMod.UI.CalamitasEnchants ID = id; IconTexturePath = iconTexturePath; } - public Enchantment(string name, string description, int id, string iconTexturePath, Action creationEffect, Predicate requirement) + public Enchantment(LocalizedText name, LocalizedText description, int id, string iconTexturePath, Action creationEffect, Predicate requirement) { Name = name; Description = description; diff --git a/UI/CalamitasEnchantments/EnchantmentManager.cs b/UI/CalamitasEnchantments/EnchantmentManager.cs index 7953468972..3f76bf1485 100644 --- a/UI/CalamitasEnchantments/EnchantmentManager.cs +++ b/UI/CalamitasEnchantments/EnchantmentManager.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using System.Linq; using Terraria; using Terraria.ID; +using Terraria.Localization; using Terraria.ModLoader; namespace CalamityMod.UI.CalamitasEnchants @@ -69,8 +70,8 @@ namespace CalamityMod.UI.CalamitasEnchants if (secondaryArgumentCount > 7) throw new ArgumentNullException("ERROR: A maximum of 6 arguments can be supplied to this command."); - string name = string.Empty; - string description = string.Empty; + LocalizedText name = LocalizedText.Empty; + LocalizedText description = LocalizedText.Empty; int id = -1; string iconTexturePath = null; Predicate requirement = null; @@ -78,16 +79,16 @@ namespace CalamityMod.UI.CalamitasEnchants Action holdEffect = null; // First element - the name. - if (parameters.ElementAt(0) is string nameElement) + if (parameters.ElementAt(0) is LocalizedText nameElement) name = nameElement; else - throw new ArgumentException("The first argument to this command must be a string."); + throw new ArgumentException("The first argument to this command must be a LocalizedText."); // Second element - the description. - if (parameters.ElementAt(1) is string descriptionElement) + if (parameters.ElementAt(1) is LocalizedText descriptionElement) description = descriptionElement; else - throw new ArgumentException("The second argument to this command must be a string."); + throw new ArgumentException("The second argument to this command must be a LocalizedText."); // Third element - the ID. if (parameters.ElementAt(2) is int idElement) @@ -148,28 +149,28 @@ namespace CalamityMod.UI.CalamitasEnchants { EnchantmentList = new List { - new Enchantment(CalamityUtils.GetTextValue(ExhumedNamePath), CalamityUtils.GetTextValue("UI.Exhumed.Description"), + new Enchantment(CalamityUtils.GetText(ExhumedNamePath), CalamityUtils.GetText("UI.Exhumed.Description"), 1, "CalamityMod/UI/CalamitasEnchantments/CurseIcon_Exhumed", null, null, item => ItemUpgradeRelationship.ContainsKey(item.type)), - new Enchantment(CalamityUtils.GetTextValue("UI.Indignant.DisplayName"), CalamityUtils.GetTextValue("UI.Indignant.Description"), + new Enchantment(CalamityUtils.GetText("UI.Indignant.DisplayName"), CalamityUtils.GetText("UI.Indignant.Description"), 100, "CalamityMod/UI/CalamitasEnchantments/CurseIcon_Indignant", null, player => player.Calamity().cursedSummonsEnchant = true, item => item.IsEnchantable() && item.damage > 0 && item.CountsAsClass() && !item.IsWhip()), - new Enchantment(CalamityUtils.GetTextValue("UI.Aflame.DisplayName"), CalamityUtils.GetTextValue("UI.Aflame.Description"), + new Enchantment(CalamityUtils.GetText("UI.Aflame.DisplayName"), CalamityUtils.GetText("UI.Aflame.Description"), 200, "CalamityMod/UI/CalamitasEnchantments/CurseIcon_Aflame", null, player => player.Calamity().flamingItemEnchant = true, item => item.IsEnchantable() && item.damage > 0 && !item.CountsAsClass() && !item.IsWhip()), - new Enchantment(CalamityUtils.GetTextValue("UI.Oblatory.DisplayName"), CalamityUtils.GetTextValue("UI.Oblatory.Description"), + new Enchantment(CalamityUtils.GetText("UI.Oblatory.DisplayName"), CalamityUtils.GetText("UI.Oblatory.Description"), 300, "CalamityMod/UI/CalamitasEnchantments/CurseIcon_Oblatory", item => @@ -180,21 +181,21 @@ namespace CalamityMod.UI.CalamitasEnchants player => player.Calamity().lifeManaEnchant = true, item => item.IsEnchantable() && item.damage > 0 && item.CountsAsClass() && item.mana > 0 && item.type != ModContent.ItemType()), - new Enchantment(CalamityUtils.GetTextValue("UI.Resentful.DisplayName"), CalamityUtils.GetTextValue("UI.Resentful.Description"), + new Enchantment(CalamityUtils.GetText("UI.Resentful.DisplayName"), CalamityUtils.GetText("UI.Resentful.Description"), 400, "CalamityMod/UI/CalamitasEnchantments/CurseIcon_Resentful", null, player => player.Calamity().farProximityRewardEnchant = true, item => item.IsEnchantable() && item.damage > 0 && item.shoot > ProjectileID.None && !item.IsTrueMelee() && item.type != ModContent.ItemType()), - new Enchantment(CalamityUtils.GetTextValue("UI.Bloodthirsty.DisplayName"), CalamityUtils.GetTextValue("UI.Bloodthirsty.Description"), + new Enchantment(CalamityUtils.GetText("UI.Bloodthirsty.DisplayName"), CalamityUtils.GetText("UI.Bloodthirsty.Description"), 500, "CalamityMod/UI/CalamitasEnchantments/CurseIcon_Bloodthirsty", null, player => player.Calamity().closeProximityRewardEnchant = true, item => item.IsEnchantable() && item.damage > 0 && item.shoot > ProjectileID.None && !item.IsTrueMelee() && item.type != ModContent.ItemType()), - new Enchantment(CalamityUtils.GetTextValue("UI.Ephemeral.DisplayName"), CalamityUtils.GetTextValue("UI.Ephemeral.Description"), + new Enchantment(CalamityUtils.GetText("UI.Ephemeral.DisplayName"), CalamityUtils.GetText("UI.Ephemeral.Description"), 600, "CalamityMod/UI/CalamitasEnchantments/CurseIcon_Ephemeral", null, @@ -202,14 +203,14 @@ namespace CalamityMod.UI.CalamitasEnchants item => item.IsEnchantable() && item.damage > 0 && !item.CountsAsClass() && !item.CountsAsClass() && !item.channel && item.type != ModContent.ItemType()), - new Enchantment(CalamityUtils.GetTextValue("UI.Hellbound.DisplayName"), CalamityUtils.GetTextValue("UI.Hellbound.Description"), + new Enchantment(CalamityUtils.GetText("UI.Hellbound.DisplayName"), CalamityUtils.GetText("UI.Hellbound.Description"), 700, "CalamityMod/UI/CalamitasEnchantments/CurseIcon_Hellbound", null, player => player.Calamity().explosiveMinionsEnchant = true, item => item.IsEnchantable() && item.damage > 0 && item.CountsAsClass() && !item.IsWhip()), - new Enchantment(CalamityUtils.GetTextValue("UI.Tainted.DisplayName"), CalamityUtils.GetTextValue("UI.Tainted.Description"), + new Enchantment(CalamityUtils.GetText("UI.Tainted.DisplayName"), CalamityUtils.GetText("UI.Tainted.Description"), 800, "CalamityMod/UI/CalamitasEnchantments/CurseIcon_Tainted", item => item.useTime = item.useAnimation = 25, @@ -247,28 +248,28 @@ namespace CalamityMod.UI.CalamitasEnchants }, item => item.IsEnchantable() && item.damage > 0 && item.CountsAsClass() && !item.noUseGraphic && item.shoot > ProjectileID.None), - new Enchantment(CalamityUtils.GetTextValue("UI.Traitorous.DisplayName"), CalamityUtils.GetTextValue("UI.Traitorous.Description"), + new Enchantment(CalamityUtils.GetText("UI.Traitorous.DisplayName"), CalamityUtils.GetText("UI.Traitorous.Description"), 900, "CalamityMod/UI/CalamitasEnchantments/CurseIcon_Traitorous", null, player => player.Calamity().manaMonsterEnchant = true, item => item.IsEnchantable() && item.damage > 0 && item.CountsAsClass() && item.mana > 0), - new Enchantment(CalamityUtils.GetTextValue("UI.Withering.DisplayName"), CalamityUtils.GetTextValue("UI.Withering.Description"), + new Enchantment(CalamityUtils.GetText("UI.Withering.DisplayName"), CalamityUtils.GetText("UI.Withering.Description"), 1000, "CalamityMod/UI/CalamitasEnchantments/CurseIcon_Withered", null, player => player.Calamity().witheringWeaponEnchant = true, item => item.IsEnchantable() && item.damage > 0 && !item.CountsAsClass()), - new Enchantment(CalamityUtils.GetTextValue("UI.Persecuted.DisplayName"), CalamityUtils.GetTextValue("UI.Persecuted.Description"), + new Enchantment(CalamityUtils.GetText("UI.Persecuted.DisplayName"), CalamityUtils.GetText("UI.Persecuted.Description"), 1100, "CalamityMod/UI/CalamitasEnchantments/CurseIcon_Persecuted", null, player => player.Calamity().persecutedEnchant = true, item => item.IsEnchantable() && item.damage > 0 && item.shoot > ProjectileID.None), - new Enchantment(CalamityUtils.GetTextValue("UI.Lecherous.DisplayName"), CalamityUtils.GetTextValue("UI.Lecherous.Description"), + new Enchantment(CalamityUtils.GetText("UI.Lecherous.DisplayName"), CalamityUtils.GetText("UI.Lecherous.Description"), 1200, "CalamityMod/UI/CalamitasEnchantments/CurseIcon_Lecherous", null, @@ -300,8 +301,8 @@ namespace CalamityMod.UI.CalamitasEnchants }; // Special disenchantment thing. This is separated from the list on purpose. - ClearEnchantment = new Enchantment(CalamityUtils.GetTextValue("UI.Disenchant"), - string.Empty, + ClearEnchantment = new Enchantment(CalamityUtils.GetText("UI.Disenchant"), + LocalizedText.Empty, ClearEnchantmentID, null, item =>