From 40484161755dcff2d759e97b48bdfbcda92b7814 Mon Sep 17 00:00:00 2001 From: Ozzatron Date: Sat, 18 Apr 2020 21:39:57 -0400 Subject: [PATCH] Fixed helmet bug. Made utility function for hotkey tooltips. --- Items/Accessories/AsgardianAegis.cs | 4 ++-- Items/Accessories/AstralArcanum.cs | 4 ++-- Items/Accessories/CelestialJewel.cs | 4 ++-- Items/Accessories/ElysianAegis.cs | 4 ++-- Items/Accessories/MomentumCapacitor.cs | 4 ++-- Items/Accessories/PlaguedFuelPack.cs | 14 ++++++-------- Items/Accessories/SandCloak.cs | 4 ++-- Items/Accessories/SpectralVeil.cs | 4 ++-- Items/Armor/BloodflareHornedHelm.cs | 2 +- Items/Armor/BrimflameScowl.cs | 2 +- Items/Armor/DemonshadeHelm.cs | 2 +- Items/Armor/OmegaBlueHelmet.cs | 2 +- Items/Armor/PlagueReaperMask.cs | 2 +- Items/Armor/TarragonHelm.cs | 2 +- Items/NormalityRelocator.cs | 2 +- Utilities/CalamityUtils.cs | 26 ++++++++++++++++++++++++++ 16 files changed, 53 insertions(+), 29 deletions(-) diff --git a/Items/Accessories/AsgardianAegis.cs b/Items/Accessories/AsgardianAegis.cs index e720df5661..281db90beb 100644 --- a/Items/Accessories/AsgardianAegis.cs +++ b/Items/Accessories/AsgardianAegis.cs @@ -20,7 +20,7 @@ namespace CalamityMod.Items.Accessories "+40 max life\n" + "Grants a supreme holy flame dash\n" + "Can be used to ram enemies\n" + - "This line is modified below\n" + + "TOOLTIP LINE HERE\n" + "Activating this buff will reduce your movement speed and increase enemy aggro\n" + "10% damage reduction while submerged in liquid\n" + "Toggle visibility of this accessory to enable/disable the dash"); @@ -38,7 +38,7 @@ namespace CalamityMod.Items.Accessories public override void ModifyTooltips(List list) { - string hotkey = CalamityMod.AegisHotKey.GetAssignedKeys().Count > 0 ? CalamityMod.AegisHotKey.GetAssignedKeys()[0] : "N"; + string hotkey = CalamityMod.AegisHotKey.TooltipHotkeyString(); foreach (TooltipLine line2 in list) { if (line2.mod == "Terraria" && line2.Name == "Tooltip5") diff --git a/Items/Accessories/AstralArcanum.cs b/Items/Accessories/AstralArcanum.cs index b4242a258c..e73a1929ad 100644 --- a/Items/Accessories/AstralArcanum.cs +++ b/Items/Accessories/AstralArcanum.cs @@ -18,7 +18,7 @@ namespace CalamityMod.Items.Accessories "If this effect triggers you get healed for the projectile's damage\n" + "Boosts life regen even while under the effects of a damaging debuff\n" + "While under the effects of a damaging debuff you will gain 20 defense\n" + - "This line is modified below"); + "TOOLTIP LINE HERE"); } public override void SetDefaults() @@ -32,7 +32,7 @@ namespace CalamityMod.Items.Accessories public override void ModifyTooltips(List list) { - string hotkey = CalamityMod.AstralArcanumUIHotkey.GetAssignedKeys().Count > 0 ? CalamityMod.AstralArcanumUIHotkey.GetAssignedKeys()[0] : "O"; + string hotkey = CalamityMod.AstralArcanumUIHotkey.TooltipHotkeyString(); foreach (TooltipLine line2 in list) { if (line2.mod == "Terraria" && line2.Name == "Tooltip6") diff --git a/Items/Accessories/CelestialJewel.cs b/Items/Accessories/CelestialJewel.cs index e166bf55f5..4c4b1a54f2 100644 --- a/Items/Accessories/CelestialJewel.cs +++ b/Items/Accessories/CelestialJewel.cs @@ -14,7 +14,7 @@ namespace CalamityMod.Items.Accessories DisplayName.SetDefault("Celestial Jewel"); Tooltip.SetDefault("Boosts life regen even while under the effects of a damaging debuff\n" + "While under the effects of a damaging debuff you will gain 20 defense\n" + - "This line is modified below"); + "TOOLTIP LINE HERE"); } public override void SetDefaults() @@ -28,7 +28,7 @@ namespace CalamityMod.Items.Accessories public override void ModifyTooltips(List list) { - string hotkey = CalamityMod.AstralTeleportHotKey.GetAssignedKeys().Count > 0 ? CalamityMod.AstralTeleportHotKey.GetAssignedKeys()[0] : "P"; + string hotkey = CalamityMod.AstralTeleportHotKey.TooltipHotkeyString(); foreach (TooltipLine line2 in list) { if (line2.mod == "Terraria" && line2.Name == "Tooltip2") diff --git a/Items/Accessories/ElysianAegis.cs b/Items/Accessories/ElysianAegis.cs index 9753df4253..6f29a6674e 100644 --- a/Items/Accessories/ElysianAegis.cs +++ b/Items/Accessories/ElysianAegis.cs @@ -17,7 +17,7 @@ namespace CalamityMod.Items.Accessories "+40 max life and increased life regen\n" + "Grants a supreme holy flame dash\n" + "Can be used to ram enemies\n" + - "This line is modified below\n" + + "TOOLTIP LINE HERE\n" + "Activating this buff will reduce your movement speed and increase enemy aggro\n" + "Toggle visibility of this accessory to enable/disable the dash"); } @@ -35,7 +35,7 @@ namespace CalamityMod.Items.Accessories public override void ModifyTooltips(List list) { - string hotkey = CalamityMod.AegisHotKey.GetAssignedKeys().Count > 0 ? CalamityMod.AegisHotKey.GetAssignedKeys()[0] : "N"; + string hotkey = CalamityMod.AegisHotKey.TooltipHotkeyString(); foreach (TooltipLine line2 in list) { if (line2.mod == "Terraria" && line2.Name == "Tooltip5") diff --git a/Items/Accessories/MomentumCapacitor.cs b/Items/Accessories/MomentumCapacitor.cs index d68a30a91e..f688b56b2c 100644 --- a/Items/Accessories/MomentumCapacitor.cs +++ b/Items/Accessories/MomentumCapacitor.cs @@ -10,7 +10,7 @@ namespace CalamityMod.Items.Accessories public override void SetStaticDefaults() { DisplayName.SetDefault("Momentum Capacitor"); - Tooltip.SetDefault("This line is modified below\n" + + Tooltip.SetDefault("TOOLTIP LINE HERE\n" + "Rogue projectiles that enter the field get a constant acceleration and 15% damage boost\n" + "These boosts can only happen to a projectile once\n" + "There can only be one field"); @@ -27,7 +27,7 @@ namespace CalamityMod.Items.Accessories public override void ModifyTooltips(List list) { - string hotkey = CalamityMod.MomentumCapacitatorHotkey.GetAssignedKeys().Count > 0 ? CalamityMod.MomentumCapacitatorHotkey.GetAssignedKeys()[0] : "U"; + string hotkey = CalamityMod.MomentumCapacitatorHotkey.TooltipHotkeyString(); foreach (TooltipLine line2 in list) { if (line2.mod == "Terraria" && line2.Name == "Tooltip0") diff --git a/Items/Accessories/PlaguedFuelPack.cs b/Items/Accessories/PlaguedFuelPack.cs index 9a54e65991..458a6bbe33 100644 --- a/Items/Accessories/PlaguedFuelPack.cs +++ b/Items/Accessories/PlaguedFuelPack.cs @@ -13,7 +13,7 @@ namespace CalamityMod.Items.Accessories DisplayName.SetDefault("Plagued Fuel Pack"); Tooltip.SetDefault("5% increased rogue damage\n" + "15% increased rogue projectile velocity\n" + - "Press Q to consume 25% of your maximum stealth to perform a swift upwards/diagonal dash which leaves a trail of plagued clouds\n" + + "TOOLTIP LINE HERE" + "This effect has a 3 second cooldown before it can be used again"); } @@ -33,16 +33,14 @@ namespace CalamityMod.Items.Accessories player.Calamity().plaguedFuelPack = true; } - public override void ModifyTooltips(List tooltips) + public override void ModifyTooltips(List list) { - if (CalamityMod.PlaguePackHotKey.GetAssignedKeys().Count > 0) + string hotkey = CalamityMod.PlaguePackHotKey.TooltipHotkeyString(); + foreach (TooltipLine line in list) { - foreach (TooltipLine line in tooltips) + if (line.mod == "Terraria" && line.Name == "Tooltip2") { - if (line.mod == "Terraria" && line.Name == "Tooltip2") - { - line.text = "Press " + CalamityMod.PlaguePackHotKey.GetAssignedKeys()[0] + " to consume 25% of your maximum stealth to perform a swift upwards/diagonal dash which leaves a trail of plagued clouds"; - } + line.text = "Press " + hotkey + " to consume 25% of your maximum stealth to perform a swift upwards/diagonal dash which leaves a trail of plagued clouds"; } } } diff --git a/Items/Accessories/SandCloak.cs b/Items/Accessories/SandCloak.cs index 0ed37811c0..03d49f872d 100644 --- a/Items/Accessories/SandCloak.cs +++ b/Items/Accessories/SandCloak.cs @@ -12,7 +12,7 @@ namespace CalamityMod.Items.Accessories { DisplayName.SetDefault("Sand Cloak"); Tooltip.SetDefault("+1 defense and 5% increased movement speed\n" + - "This line is modified below\n" + + "TOOLTIP LINE HERE\n" + "This effect has a 30 second cooldown before it can be used again"); } @@ -27,7 +27,7 @@ namespace CalamityMod.Items.Accessories public override void ModifyTooltips(List list) { - string hotkey = CalamityMod.SandCloakHotkey.GetAssignedKeys().Count > 0 ? CalamityMod.SandCloakHotkey.GetAssignedKeys()[0] : "C"; + string hotkey = CalamityMod.SandCloakHotkey.TooltipHotkeyString(); foreach (TooltipLine line2 in list) { if (line2.mod == "Terraria" && line2.Name == "Tooltip1") diff --git a/Items/Accessories/SpectralVeil.cs b/Items/Accessories/SpectralVeil.cs index cc854ea423..e71486da20 100644 --- a/Items/Accessories/SpectralVeil.cs +++ b/Items/Accessories/SpectralVeil.cs @@ -12,7 +12,7 @@ namespace CalamityMod.Items.Accessories { DisplayName.SetDefault("Spectral Veil"); Tooltip.SetDefault("The inside of the cloak is full of teeth...\n" + - "This line is modified below\n" + + "TOOLTIP LINE HERE\n" + "Teleportation is disabled while Chaos State is active\n" + "If you dodge something while invulnerable, you instantly gain full stealth"); } @@ -28,7 +28,7 @@ namespace CalamityMod.Items.Accessories public override void ModifyTooltips(List list) { - string hotkey = CalamityMod.SpectralVeilHotKey.GetAssignedKeys().Count > 0 ? CalamityMod.SpectralVeilHotKey.GetAssignedKeys()[0] : "Z"; + string hotkey = CalamityMod.SpectralVeilHotKey.TooltipHotkeyString(); foreach (TooltipLine line2 in list) { if (line2.mod == "Terraria" && line2.Name == "Tooltip1") diff --git a/Items/Armor/BloodflareHornedHelm.cs b/Items/Armor/BloodflareHornedHelm.cs index 8a04270a1a..8762114229 100644 --- a/Items/Armor/BloodflareHornedHelm.cs +++ b/Items/Armor/BloodflareHornedHelm.cs @@ -41,7 +41,7 @@ namespace CalamityMod.Items.Armor CalamityPlayer modPlayer = player.Calamity(); modPlayer.bloodflareSet = true; modPlayer.bloodflareRanged = true; - string hotkey = CalamityMod.TarraHotKey.GetAssignedKeys().Count > 0 ? CalamityMod.TarraHotKey.GetAssignedKeys()[0] : "Y"; + string hotkey = CalamityMod.TarraHotKey.TooltipHotkeyString(); player.setBonus = "Greatly increases life regen\n" + "Enemies below 50% life have a chance to drop hearts when struck\n" + "Enemies above 50% life have a chance to drop mana stars when struck\n" + diff --git a/Items/Armor/BrimflameScowl.cs b/Items/Armor/BrimflameScowl.cs index 3ac36f2843..3fc8cc75af 100644 --- a/Items/Armor/BrimflameScowl.cs +++ b/Items/Armor/BrimflameScowl.cs @@ -77,7 +77,7 @@ namespace CalamityMod.Items.Armor modPlayer.brimflameSet = true; player.magicDamage += 0.15f; player.magicCrit += 15; - string hotkey = CalamityMod.TarraHotKey.GetAssignedKeys().Count > 0 ? CalamityMod.TarraHotKey.GetAssignedKeys()[0] : "Y"; + string hotkey = CalamityMod.TarraHotKey.TooltipHotkeyString(); player.setBonus = "Grants an additional 15% increased damage and magic crit\n" + "Press " + hotkey + " to trigger a brimflame frenzy effect\n" + "While under this effect, your damage is significantly boosted\n" + diff --git a/Items/Armor/DemonshadeHelm.cs b/Items/Armor/DemonshadeHelm.cs index 8e6910bf8a..15ca18f95d 100644 --- a/Items/Armor/DemonshadeHelm.cs +++ b/Items/Armor/DemonshadeHelm.cs @@ -39,7 +39,7 @@ namespace CalamityMod.Items.Armor public override void UpdateArmorSet(Player player) { - string hotkey = CalamityMod.TarraHotKey.GetAssignedKeys().Count > 0 ? CalamityMod.TarraHotKey.GetAssignedKeys()[0] : "Y"; + string hotkey = CalamityMod.TarraHotKey.TooltipHotkeyString(); player.setBonus = "100% increased minion damage\n" + "All attacks inflict the demon flame debuff\n" + "Shadowbeams and demon scythes will fire down when you are hit\n" + diff --git a/Items/Armor/OmegaBlueHelmet.cs b/Items/Armor/OmegaBlueHelmet.cs index 2aa74a60c0..34decfba78 100644 --- a/Items/Armor/OmegaBlueHelmet.cs +++ b/Items/Armor/OmegaBlueHelmet.cs @@ -51,7 +51,7 @@ namespace CalamityMod.Items.Armor public override void UpdateArmorSet(Player player) { - string hotkey = CalamityMod.TarraHotKey.GetAssignedKeys().Count > 0 ? CalamityMod.TarraHotKey.GetAssignedKeys()[0] : "Y"; + string hotkey = CalamityMod.TarraHotKey.TooltipHotkeyString(); player.setBonus = "Increases armor penetration by 50\n" + "10% increased damage and critical strike chance\n" + "Short-ranged tentacles heal you by sucking enemy life\n" + diff --git a/Items/Armor/PlagueReaperMask.cs b/Items/Armor/PlagueReaperMask.cs index ce96870613..8e665a4118 100644 --- a/Items/Armor/PlagueReaperMask.cs +++ b/Items/Armor/PlagueReaperMask.cs @@ -40,7 +40,7 @@ namespace CalamityMod.Items.Armor public override void UpdateArmorSet(Player player) { - string hotkey = CalamityMod.TarraHotKey.GetAssignedKeys().Count > 0 ? CalamityMod.TarraHotKey.GetAssignedKeys()[0] : "Y"; + string hotkey = CalamityMod.TarraHotKey.TooltipHotkeyString(); player.setBonus = "25% reduced ammo usage and 5% increased flight time\n" + "Enemies receive 10% more damage from ranged projectiles when afflicted by the Plague\n" + "Getting hit causes the plague cinders to rain from above\n" + diff --git a/Items/Armor/TarragonHelm.cs b/Items/Armor/TarragonHelm.cs index 3c6c15f972..24b488fc9c 100644 --- a/Items/Armor/TarragonHelm.cs +++ b/Items/Armor/TarragonHelm.cs @@ -45,7 +45,7 @@ namespace CalamityMod.Items.Armor CalamityPlayer modPlayer = player.Calamity(); modPlayer.tarraSet = true; modPlayer.tarraMelee = true; - string hotkey = CalamityMod.TarraHotKey.GetAssignedKeys().Count > 0 ? CalamityMod.TarraHotKey.GetAssignedKeys()[0] : "Y"; + string hotkey = CalamityMod.TarraHotKey.TooltipHotkeyString(); player.setBonus = "Increased heart pickup range\n" + "Enemies have a chance to drop extra hearts on death\n" + "You have a 25% chance to gain a life regen buff when you take damage\n" + diff --git a/Items/NormalityRelocator.cs b/Items/NormalityRelocator.cs index 1340fb5786..ed2b2dfe70 100644 --- a/Items/NormalityRelocator.cs +++ b/Items/NormalityRelocator.cs @@ -33,7 +33,7 @@ namespace CalamityMod.Items public override void ModifyTooltips(List list) { - string hotkey = CalamityMod.NormalityRelocatorHotKey.GetAssignedKeys().Count > 0 ? CalamityMod.NormalityRelocatorHotKey.GetAssignedKeys()[0] : "Z"; + string hotkey = CalamityMod.NormalityRelocatorHotKey.TooltipHotkeyString(); foreach (TooltipLine line2 in list) { if (line2.mod == "Terraria" && line2.Name == "Tooltip1") diff --git a/Utilities/CalamityUtils.cs b/Utilities/CalamityUtils.cs index 2c7f817d7a..ab3773f1b7 100644 --- a/Utilities/CalamityUtils.cs +++ b/Utilities/CalamityUtils.cs @@ -231,6 +231,32 @@ namespace CalamityMod */ } + /// + /// Converts the given ModHotKey into a string for insertion into item tooltips.

+ /// This allows the user's actual keybind choices to be shown to them in tooltips. + ///
+ /// The ModHotKey to convert to a string. + /// + public static string TooltipHotkeyString(this ModHotKey mhk) + { + if (Main.dedServ || mhk is null) + return ""; + + List keys = mhk.GetAssignedKeys(); + if (keys.Count == 0) + return "[NONE]"; + else + { + StringBuilder sb = new StringBuilder(16); + sb.Append(keys[0]); + + // In almost all cases, this code won't run, because there won't be multiple bindings for the hotkey. But just in case... + for (int i = 1; i < keys.Count; ++i) + sb.Append(" / ").Append(keys[i]); + return sb.ToString(); + } + } + private const float WorldInsertionOffset = 15f; /// /// If the given item is outside the world, force it to be within the world boundaries.