diff --git a/CalamityMod.cs b/CalamityMod.cs index a868177574..651049393d 100644 --- a/CalamityMod.cs +++ b/CalamityMod.cs @@ -1070,6 +1070,14 @@ namespace CalamityMod ExoMechSelectionUI.Draw(Main.spriteBatch); return true; }, InterfaceScaleType.None)); + + // Defense damage indicator. + layers.Insert(mouseIndex, new LegacyGameInterfaceLayer("Defense Damage Indicator", () => + { + if (Main.EquipPage != 1 && Main.EquipPage != 2) + DefenseDamageDisplayUI.Draw(Main.spriteBatch); + return true; + }, InterfaceScaleType.None)); } // Invasion UIs. diff --git a/ExtraTextures/UI/DefenseDamage.png b/ExtraTextures/UI/DefenseDamage.png new file mode 100644 index 0000000000..7beb9a8722 Binary files /dev/null and b/ExtraTextures/UI/DefenseDamage.png differ diff --git a/ExtraTextures/UI/DefenseDamageHover.png b/ExtraTextures/UI/DefenseDamageHover.png new file mode 100644 index 0000000000..46d1d8fa5b Binary files /dev/null and b/ExtraTextures/UI/DefenseDamageHover.png differ diff --git a/Localization/CalamityLocalization.cs b/Localization/CalamityLocalization.cs index 9c871d9bd8..10c3cd54c1 100644 --- a/Localization/CalamityLocalization.cs +++ b/Localization/CalamityLocalization.cs @@ -2,6 +2,7 @@ using Terraria.ModLoader; namespace CalamityMod.Localization { + // TODO - At some point change this to use proper localization files. public class CalamityLocalization { private static string[][] _localizations; @@ -199,6 +200,8 @@ namespace CalamityMod.Localization new [] { "AcidRainStart", "A toxic downpour falls over the wasteland seas!" }, new [] { "AcidRainEnd", "The sulphuric skies begin to clear..." }, + + new [] { "DefenseDamage", "Defense Damage" } }; } diff --git a/UI/DefenseDamageDisplayUI.cs b/UI/DefenseDamageDisplayUI.cs new file mode 100644 index 0000000000..477f67de93 --- /dev/null +++ b/UI/DefenseDamageDisplayUI.cs @@ -0,0 +1,46 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System.Reflection; +using Terraria; +using Terraria.UI.Chat; +using Terraria.Localization; +using Terraria.ModLoader; + +namespace CalamityMod.UI +{ + public static class DefenseDamageDisplayUI + { + public static void Draw(SpriteBatch spriteBatch) + { + int defenseDamage = Main.LocalPlayer.Calamity().CurrentDefenseDamage; + + // Do nothing if no defense damage has been incurred. + if (defenseDamage <= 0) + return; + + string defenseDamageText = (-defenseDamage).ToString(); + Texture2D defenseDamageIcon = ModContent.GetTexture("CalamityMod/ExtraTextures/UI/DefenseDamage"); + Vector2 defenseDamageIconCenter = new Vector2(Main.screenWidth - Main.UIScale * 96f, Main.UIScale * 4f) + defenseDamageIcon.Size() * 0.5f; + Rectangle defenseDamageIconArea = Utils.CenteredRectangle(defenseDamageIconCenter, defenseDamageIcon.Size() * Main.UIScale); + Vector2 defenseDamageTextArea = Main.fontMouseText.MeasureString(defenseDamageText); + Vector2 defenseDamageTextDrawPosition = defenseDamageIconCenter + new Vector2(6f, 16f) - defenseDamageTextArea * 0.5f; + Rectangle mouseArea = new Rectangle(Main.mouseX, Main.mouseY, 2, 2); + bool hoveringOverIcon = mouseArea.Intersects(defenseDamageIconArea); + if (hoveringOverIcon) + defenseDamageIcon = ModContent.GetTexture("CalamityMod/ExtraTextures/UI/DefenseDamageHover"); + + // Draw the icon. + spriteBatch.Draw(defenseDamageIcon, defenseDamageIconCenter, null, Color.White, 0f, defenseDamageIcon.Size() * 0.5f, Main.UIScale, 0, 0f); + + // Draw the amount of defense damage currently in effect as text. It is negatively signed as an indicator that it is quantity of loss and not gain. + ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, defenseDamageText, defenseDamageTextDrawPosition, Color.IndianRed, 0f, Vector2.Zero, Vector2.One * Main.UIScale * 0.75f); + + // Display the amount of defense and defense damage the player has if hovering over the icon. + if (hoveringOverIcon) + { + Main.hoverItemName = $"{Main.LocalPlayer.statDefense} {Language.GetTextValue("LegacyInterface.10")}" + + $"\n{defenseDamage} {Language.GetTextValue("Mods.CalamityMod.DefenseDamage")}"; + } + } + } +}