From af2b103d6bb587631dbd5dac14faeff005826592 Mon Sep 17 00:00:00 2001 From: Ozzatron Date: Mon, 6 Jun 2022 17:30:38 -0400 Subject: [PATCH] UI rework fully implemented. Default positions optimized. --- UI/ChargeMeterUI.cs | 11 ++++++----- UI/RipperUI.cs | 9 +++++---- UI/SpeedrunTimerUI.cs | 8 ++++++-- UI/StealthUI.cs | 20 ++++++++++++-------- 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/UI/ChargeMeterUI.cs b/UI/ChargeMeterUI.cs index d449335243..b6ea73e722 100644 --- a/UI/ChargeMeterUI.cs +++ b/UI/ChargeMeterUI.cs @@ -1,9 +1,9 @@ using System; -using CalamityMod.CalPlayer; using CalamityMod.Items; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; +using ReLogic.Content; using Terraria; using Terraria.ModLoader; @@ -11,8 +11,9 @@ namespace CalamityMod.UI { public class ChargeMeterUI { - internal const float DefaultChargePosX = 49.47917f; - internal const float DefaultChargePosY = 43f; + // These values were handpicked on a 1080p screen by Ozzatron. Please disregard the bizarre precision. + internal const float DefaultChargePosX = 50.104603f; + internal const float DefaultChargePosY = 58.05169f; private const float MouseDragEpsilon = 0.05f; // 0.05% private static Vector2? dragOffset = null; @@ -20,8 +21,8 @@ namespace CalamityMod.UI internal static void Load() { - edgeTexture = ModContent.Request("CalamityMod/ExtraTextures/UI/ChargeMeterBorder").Value; - barTexture = ModContent.Request("CalamityMod/ExtraTextures/UI/ChargeMeter").Value; + edgeTexture = ModContent.Request("CalamityMod/ExtraTextures/UI/ChargeMeterBorder", AssetRequestMode.ImmediateLoad).Value; + barTexture = ModContent.Request("CalamityMod/ExtraTextures/UI/ChargeMeter", AssetRequestMode.ImmediateLoad).Value; Reset(); } diff --git a/UI/RipperUI.cs b/UI/RipperUI.cs index 083f521ed5..d7d4c944ea 100644 --- a/UI/RipperUI.cs +++ b/UI/RipperUI.cs @@ -13,10 +13,11 @@ namespace CalamityMod.UI { public static class RipperUI { - public const float DefaultRagePosX = 26.04167f; - public const float DefaultRagePosY = 3f; - public const float DefaultAdrenPosX = 33.8542f; - public const float DefaultAdrenPosY = 3f; + // These values were handpicked on a 1080p screen by Ozzatron. Please disregard the bizarre precision. + public const float DefaultRagePosX = 35.77406f; + public const float DefaultRagePosY = 3.9761431f; + public const float DefaultAdrenPosX = 35.77406f; + public const float DefaultAdrenPosY = 8.846918f; private const float MouseDragEpsilon = 0.05f; // 0.05% private const int RageAnimFrameDelay = 6; diff --git a/UI/SpeedrunTimerUI.cs b/UI/SpeedrunTimerUI.cs index 6ca4b91b95..b0bec532bf 100644 --- a/UI/SpeedrunTimerUI.cs +++ b/UI/SpeedrunTimerUI.cs @@ -34,9 +34,13 @@ namespace CalamityMod.UI { public class SpeedrunTimerUI { + // These values put the Speedrun Timer roughly at the top center of a 1080p screen. internal const float DefaultTimerPosX = 46f; internal const float DefaultTimerPosY = 1.481f; + private static readonly float SplitHorizontalOffset = +30f; + private static readonly float SplitVerticalOffset = +44f; + public static void Draw(Player player) { if (Main.gameMenu || !CalamityConfig.Instance.SpeedrunTimer) @@ -72,8 +76,8 @@ namespace CalamityMod.UI TimeSpan split = calamityPlayer.lastSplit; text = split.ToString(split.Days > 0 ? formatStrDays : formatStr); scale = 1f; - float lineTwoY = screenPos.Y + 44f; - float lineTwoX = screenPos.X - 58f; + float lineTwoX = screenPos.X + SplitHorizontalOffset; + float lineTwoY = screenPos.Y + SplitVerticalOffset; Texture2D texture = GetSplitIcon(calamityPlayer.lastSplitType); // If a split icon exists, draw it. diff --git a/UI/StealthUI.cs b/UI/StealthUI.cs index 3be4acdcf2..d6f81d3296 100644 --- a/UI/StealthUI.cs +++ b/UI/StealthUI.cs @@ -3,6 +3,7 @@ using CalamityMod.CalPlayer; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; +using ReLogic.Content; using Terraria; using Terraria.ModLoader; @@ -10,8 +11,9 @@ namespace CalamityMod.UI { public class StealthUI { - internal const float DefaultStealthPosX = 42.7083f; - internal const float DefaultStealthPosY = 56.0000f; + // These values were handpicked on a 1080p screen by Ozzatron. Please disregard the bizarre precision. + internal const float DefaultStealthPosX = 50.104603f; + internal const float DefaultStealthPosY = 55.765408f; private const float MouseDragEpsilon = 0.05f; // 0.05% private static Vector2? dragOffset = null; @@ -19,10 +21,10 @@ namespace CalamityMod.UI internal static void Load() { - edgeTexture = ModContent.Request("CalamityMod/ExtraTextures/UI/StealthMeter").Value; - indicatorTexture = ModContent.Request("CalamityMod/ExtraTextures/UI/StealthMeterStrikeIndicator").Value; - barTexture = ModContent.Request("CalamityMod/ExtraTextures/UI/StealthMeterBar").Value; - fullBarTexture = ModContent.Request("CalamityMod/ExtraTextures/UI/StealthMeterBarFull").Value; + edgeTexture = ModContent.Request("CalamityMod/ExtraTextures/UI/StealthMeter", AssetRequestMode.ImmediateLoad).Value; + indicatorTexture = ModContent.Request("CalamityMod/ExtraTextures/UI/StealthMeterStrikeIndicator", AssetRequestMode.ImmediateLoad).Value; + barTexture = ModContent.Request("CalamityMod/ExtraTextures/UI/StealthMeterBar", AssetRequestMode.ImmediateLoad).Value; + fullBarTexture = ModContent.Request("CalamityMod/ExtraTextures/UI/StealthMeterBarFull", AssetRequestMode.ImmediateLoad).Value; Reset(); } @@ -66,8 +68,10 @@ namespace CalamityMod.UI CalamityConfig.Instance.StealthMeterPosY = screenRatioPosition.Y; changed = true; } + if (changed) CalamityMod.SaveConfig(CalamityConfig.Instance); + return; } float offset = (edgeTexture.Width - barTexture.Width) * 0.5f; @@ -77,9 +81,9 @@ namespace CalamityMod.UI if (modPlayer.StealthStrikeAvailable()) spriteBatch.Draw(indicatorTexture, screenPos, null, Color.White * modPlayer.stealthUIAlpha, 0f, indicatorTexture.Size() * 0.5f, uiScale, SpriteEffects.None, 0); - float completionRatio = modPlayer.rogueStealth / modPlayer.rogueStealthMax; + float completionRatio = modPlayer.rogueStealthMax <= 0f ? 0f : modPlayer.rogueStealth / modPlayer.rogueStealthMax; Rectangle barRectangle = new Rectangle(0, 0, (int)(barTexture.Width * completionRatio), barTexture.Width); - bool full = modPlayer.rogueStealth >= modPlayer.rogueStealthMax; + bool full = (modPlayer.rogueStealthMax > 0f) && (modPlayer.rogueStealth >= modPlayer.rogueStealthMax); spriteBatch.Draw(full ? fullBarTexture : barTexture, screenPos + new Vector2(offset * uiScale, 0), barRectangle, Color.White * modPlayer.stealthUIAlpha, 0f, indicatorTexture.Size() * 0.5f, uiScale, SpriteEffects.None, 0); Rectangle mouseHitbox = new Rectangle((int)Main.MouseScreen.X, (int)Main.MouseScreen.Y, 8, 8);