Added the flight bar
This commit is contained in:
1 parent
f0cd8f78e4
commit
9b6831f63f
16 files changed
+301
-4
No files matched your search
@@ -901,6 +901,7 @@ namespace CalamityMod.CalPlayer
|
||||
public bool kamiBoost = false;
|
||||
public bool avertorBonus = false;
|
||||
public bool divineBless = false;
|
||||
public bool infiniteFlight = false;
|
||||
#endregion
|
||||
|
||||
#region Minion
|
||||
@@ -2060,6 +2061,8 @@ namespace CalamityMod.CalPlayer
|
||||
|
||||
AbleToSelectExoMech = false;
|
||||
|
||||
infiniteFlight = false;
|
||||
|
||||
EnchantHeldItemEffects(Player, Player.Calamity(), Player.ActiveItem());
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -2419,6 +2419,12 @@ namespace CalamityMod.CalPlayer
|
||||
#region Other Buff Effects
|
||||
private void OtherBuffEffects()
|
||||
{
|
||||
//Infinite flight granted by some boss attacks
|
||||
if (infiniteFlight)
|
||||
{
|
||||
Player.wingTime = Player.wingTimeMax;
|
||||
}
|
||||
|
||||
if (gravityNormalizer)
|
||||
{
|
||||
Player.buffImmune[BuffID.VortexDebuff] = true;
|
||||
|
||||
@@ -160,6 +160,22 @@ namespace CalamityMod
|
||||
[Range(0f, 100f)]
|
||||
[DefaultValue(SpeedrunTimerUI.DefaultTimerPosY)]
|
||||
public float SpeedrunTimerPosY { get; set; }
|
||||
|
||||
[BackgroundColor(192, 54, 64, 192)]
|
||||
[DefaultValue(true)]
|
||||
public bool FlightBar { get; set; }
|
||||
|
||||
[BackgroundColor(192, 54, 64, 192)]
|
||||
[SliderColor(224, 165, 56, 128)]
|
||||
[Range(0f, 100f)]
|
||||
[DefaultValue(UI.FlightBar.DefaultFlightPosX)]
|
||||
public float FlightBarPosX { get; set; }
|
||||
|
||||
[BackgroundColor(192, 54, 64, 192)]
|
||||
[SliderColor(224, 165, 56, 128)]
|
||||
[Range(0f, 100f)]
|
||||
[DefaultValue(UI.FlightBar.DefaultFlightPosY)]
|
||||
public float FlightBarPosY { get; set; }
|
||||
#endregion
|
||||
|
||||
#region General Gameplay Changes
|
||||
|
||||
@@ -364,6 +364,7 @@ namespace CalamityMod
|
||||
StealthUI.Load();
|
||||
ChargeMeterUI.Load();
|
||||
AstralArcanumUI.Load(this);
|
||||
FlightBar.Load();
|
||||
|
||||
// TODO -- Is this not possible to place in ModNPC.Load or ModNPC.SetStaticDefaults ?
|
||||
// Centralizing head texture registration like this seems absurdly stiff
|
||||
@@ -467,6 +468,7 @@ namespace CalamityMod
|
||||
StealthUI.Unload();
|
||||
ChargeMeterUI.Unload();
|
||||
AstralArcanumUI.Unload();
|
||||
FlightBar.Unload();
|
||||
|
||||
if (!Main.dedServ)
|
||||
{
|
||||
|
||||
@@ -170,6 +170,29 @@ CalamityConfig: {
|
||||
'''
|
||||
}
|
||||
|
||||
FlightBar: {
|
||||
Label: "[i:CalamityMod/DrewsWings] Display Flight Bar"
|
||||
Tooltip: Enables the Flight Bar UI, which displays the player's flight capabilities
|
||||
}
|
||||
|
||||
FlightBarPosX: {
|
||||
Label: "[i:LaserRuler] Flight Bar X Position"
|
||||
Tooltip:
|
||||
'''
|
||||
The X position of the Flight Bar, measured as a % of your screen height.
|
||||
The meter can be dragged with the mouse if Lock Meter Positions is disabled.
|
||||
'''
|
||||
}
|
||||
|
||||
FlightBarPosY: {
|
||||
Label: "[i:LaserRuler] Flight Bar Y Position"
|
||||
Tooltip:
|
||||
'''
|
||||
The Y position of the Flight Bar, measured as a % of your screen height.
|
||||
The meter can be dragged with the mouse if Lock Meter Positions is disabled.
|
||||
'''
|
||||
}
|
||||
|
||||
ForceTownSafety: {
|
||||
Label: "[i:Sunflower] Force Town Safety"
|
||||
Tooltip:
|
||||
|
||||
@@ -3,6 +3,7 @@ SmallWorldWarning: "[c/FF0000:SMALL WORLDS NOT SUPPORTED BY CALAMITY]"
|
||||
Adrenaline: Adrenaline
|
||||
Nanomachines: Nanomachines
|
||||
Rage: Rage
|
||||
Flight: "{0} Flight Remaining"
|
||||
Charge: Current Charge
|
||||
DefenseDamage: Defense Damage
|
||||
SulphurousWater: Sulphuric Poisoning
|
||||
|
||||
@@ -992,8 +992,7 @@ namespace CalamityMod.NPCs.DevourerofGods
|
||||
{
|
||||
if (!Main.player[Main.myPlayer].dead && Main.player[Main.myPlayer].active && Vector2.Distance(Main.player[Main.myPlayer].Center, NPC.Center) < CalamityGlobalNPC.CatchUpDistance350Tiles)
|
||||
{
|
||||
if (Main.player[Main.myPlayer].wingTime < Main.player[Main.myPlayer].wingTimeMax)
|
||||
Main.player[Main.myPlayer].wingTime = Main.player[Main.myPlayer].wingTimeMax;
|
||||
Main.player[Main.myPlayer].Calamity().infiniteFlight = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -811,8 +811,7 @@ namespace CalamityMod.NPCs.ExoMechs.Ares
|
||||
{
|
||||
if (!Main.player[Main.myPlayer].dead && Main.player[Main.myPlayer].active && Vector2.Distance(Main.player[Main.myPlayer].Center, NPC.Center) < DeathrayEnrageDistance)
|
||||
{
|
||||
if (Main.player[Main.myPlayer].wingTime < Main.player[Main.myPlayer].wingTimeMax)
|
||||
Main.player[Main.myPlayer].wingTime = Main.player[Main.myPlayer].wingTimeMax;
|
||||
Main.player[Main.myPlayer].Calamity().infiniteFlight = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -96,6 +96,13 @@ namespace CalamityMod.Systems
|
||||
SulphurousWaterMeterUI.Draw(Main.spriteBatch, Main.LocalPlayer);
|
||||
return true;
|
||||
}, InterfaceScaleType.None));
|
||||
|
||||
//Flight bar
|
||||
layers.Insert(mouseIndex, new LegacyGameInterfaceLayer("Flight UI", () =>
|
||||
{
|
||||
FlightBar.Draw(Main.spriteBatch, Main.LocalPlayer);
|
||||
return true;
|
||||
}, InterfaceScaleType.None));
|
||||
|
||||
// Charge meter
|
||||
layers.Insert(mouseIndex, new LegacyGameInterfaceLayer("Charge UI", () =>
|
||||
|
||||
@@ -0,0 +1,241 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
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;
|
||||
|
||||
namespace CalamityMod.UI
|
||||
{
|
||||
// TODO -- This can be made into a ModSystem with simple OnModLoad and Unload hooks.
|
||||
public class FlightBar
|
||||
{
|
||||
// These values were handpicked on a 1080p screen by Amber. Please disregard the bizarre precision.
|
||||
internal const float DefaultFlightPosX = 40.9375f;
|
||||
internal const float DefaultFlightPosY = 7.2222223f; //yes really, that many twos were handpicked, how? your guess is as good as mine lmao
|
||||
private const float MouseDragEpsilon = 0.05f; // 0.05%
|
||||
private const int FlightAnimFrameDelay = 5;
|
||||
private const int FlightAnimFrames = 17;
|
||||
|
||||
private static int FlightAnimFrame = -1;
|
||||
private static int FlightAnimTimer = 0;
|
||||
|
||||
private static Vector2? dragOffset = null;
|
||||
private static Texture2D borderTexture, flightBarAnimTexture, barTexture, disabledBarTexture, infiniteBarTexture, limitedBarTexture;
|
||||
private static bool completedAnimation = false;
|
||||
|
||||
private static Texture2D GetApplicableBorder(CalamityPlayer modPlayer)
|
||||
{
|
||||
if (modPlayer.Player.equippedWings != null && modPlayer.Player.wingTimeMax == 0)
|
||||
return disabledBarTexture;
|
||||
if (modPlayer.infiniteFlight && completedAnimation)
|
||||
return infiniteBarTexture;
|
||||
if (modPlayer.weakPetrification || modPlayer.vHex || modPlayer.icarusFolly || modPlayer.DoGExtremeGravity)
|
||||
return limitedBarTexture;
|
||||
return borderTexture;
|
||||
}
|
||||
|
||||
private static object GetFlightTime(CalamityPlayer modPlayer)
|
||||
{
|
||||
object result;
|
||||
if (modPlayer.Player.equippedWings != null && modPlayer.Player.wingTimeMax == 0)
|
||||
result = 0;
|
||||
if (modPlayer.infiniteFlight && completedAnimation)
|
||||
{
|
||||
result = "∞"; //infinite flight
|
||||
}
|
||||
else
|
||||
{
|
||||
int currentFlight = (int)modPlayer.Player.wingTime;
|
||||
int maxFlight = modPlayer.Player.wingTimeMax;
|
||||
string percent = (100f * currentFlight / maxFlight).ToString("0.00");
|
||||
StringBuilder sb = new StringBuilder(32);
|
||||
sb.Append(percent);
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static void Load()
|
||||
{
|
||||
borderTexture = ModContent.Request<Texture2D>("CalamityMod/UI/FlightBar/FlightBarBorder", AssetRequestMode.ImmediateLoad).Value;
|
||||
flightBarAnimTexture = ModContent.Request<Texture2D>("CalamityMod/UI/FlightBar/FlightBarAnim", AssetRequestMode.ImmediateLoad).Value;
|
||||
barTexture = ModContent.Request<Texture2D>("CalamityMod/UI/FlightBar/FlightBar", AssetRequestMode.ImmediateLoad).Value;
|
||||
disabledBarTexture = ModContent.Request<Texture2D>("CalamityMod/UI/FlightBar/FlightBarBorderDisabled", AssetRequestMode.ImmediateLoad).Value;
|
||||
infiniteBarTexture = ModContent.Request<Texture2D>("CalamityMod/UI/FlightBar/FlightBarBorderInfinite", AssetRequestMode.ImmediateLoad).Value;
|
||||
limitedBarTexture = ModContent.Request<Texture2D>("CalamityMod/UI/FlightBar/FlightBarBorderReduced", AssetRequestMode.ImmediateLoad).Value;
|
||||
Reset();
|
||||
}
|
||||
|
||||
internal static void Unload()
|
||||
{
|
||||
Reset();
|
||||
borderTexture = flightBarAnimTexture = barTexture = disabledBarTexture = infiniteBarTexture = limitedBarTexture = null;
|
||||
FlightAnimFrame = -1;
|
||||
FlightAnimTimer = 0;
|
||||
completedAnimation = false;
|
||||
}
|
||||
|
||||
private static void Reset() => dragOffset = null;
|
||||
|
||||
|
||||
|
||||
public static void Draw(SpriteBatch spriteBatch, Player player)
|
||||
{
|
||||
// Sanity check the planned position before drawing
|
||||
Vector2 screenRatioPosition = new Vector2(CalamityConfig.Instance.FlightBarPosX, CalamityConfig.Instance.FlightBarPosY);
|
||||
if (screenRatioPosition.X < 0f || screenRatioPosition.X > 100f)
|
||||
screenRatioPosition.X = DefaultFlightPosX;
|
||||
if (screenRatioPosition.Y < 0f || screenRatioPosition.Y > 100f)
|
||||
screenRatioPosition.Y = DefaultFlightPosY;
|
||||
|
||||
// Convert the screen ratio position to an absolute position in pixels
|
||||
// Cast to integer to prevent blurriness which results from decimal pixel positions
|
||||
float uiScale = Main.UIScale;
|
||||
Vector2 screenPos = screenRatioPosition;
|
||||
screenPos.X = (int)(screenPos.X * 0.01f * Main.screenWidth);
|
||||
screenPos.Y = (int)(screenPos.Y * 0.01f * Main.screenHeight);
|
||||
|
||||
CalamityPlayer modPlayer = player.Calamity();
|
||||
|
||||
// If not drawing the flight bar, save its latest position to config and leave.
|
||||
if (CalamityConfig.Instance.FlightBar && player.wingsLogic > 0)
|
||||
{
|
||||
DrawFlightBar(spriteBatch, modPlayer, screenPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool changed = false;
|
||||
if (CalamityConfig.Instance.FlightBarPosX != screenRatioPosition.X)
|
||||
{
|
||||
CalamityConfig.Instance.FlightBarPosX = screenRatioPosition.X;
|
||||
changed = true;
|
||||
}
|
||||
if (CalamityConfig.Instance.FlightBarPosY != screenRatioPosition.Y)
|
||||
{
|
||||
CalamityConfig.Instance.FlightBarPosY = screenRatioPosition.Y;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (changed)
|
||||
CalamityMod.SaveConfig(CalamityConfig.Instance);
|
||||
}
|
||||
|
||||
Rectangle mouseHitbox = new Rectangle((int)Main.MouseScreen.X, (int)Main.MouseScreen.Y, 8, 8);
|
||||
Rectangle flightBar = Utils.CenteredRectangle(screenPos, borderTexture.Size() * uiScale);
|
||||
|
||||
MouseState ms = Mouse.GetState();
|
||||
Vector2 mousePos = Main.MouseScreen;
|
||||
|
||||
// Handle mouse dragging
|
||||
if (flightBar.Intersects(mouseHitbox))
|
||||
{
|
||||
if (!CalamityConfig.Instance.MeterPosLock)
|
||||
Main.LocalPlayer.mouseInterface = true;
|
||||
|
||||
if (modPlayer.Player.equippedWings != null && modPlayer.Player.wingTimeMax > 0) //equipped wings and max wingtime above 0 (so not disabled bar)
|
||||
{
|
||||
string textToDisplay = CalamityUtils.GetText("UI.Flight").Format((GetFlightTime(modPlayer).ToString() + (modPlayer.infiniteFlight ? "" : "%"))); //the percent is here and not in localisation otherwise it looks like a dick when it's infinite flight
|
||||
Main.instance.MouseText(textToDisplay, 0, 0, -1, -1, -1, -1);
|
||||
}
|
||||
|
||||
Vector2 newScreenRatioPosition = screenRatioPosition;
|
||||
// As long as the mouse button is held down, drag the meter along with an offset.
|
||||
if (!CalamityConfig.Instance.MeterPosLock && ms.LeftButton == ButtonState.Pressed)
|
||||
{
|
||||
// If the drag offset doesn't exist yet, create it.
|
||||
if (!dragOffset.HasValue)
|
||||
dragOffset = mousePos - screenPos;
|
||||
|
||||
// Given the mouse's absolute current position, compute where the corner of the flight bar should be based on the original drag offset.
|
||||
Vector2 newCorner = mousePos - dragOffset.GetValueOrDefault(Vector2.Zero);
|
||||
|
||||
// Convert the new corner position into a screen ratio position.
|
||||
newScreenRatioPosition.X = (100f * newCorner.X) / Main.screenWidth;
|
||||
newScreenRatioPosition.Y = (100f * newCorner.Y) / Main.screenHeight;
|
||||
}
|
||||
|
||||
// Compute the change in position. If it is large enough, actually move the meter
|
||||
Vector2 delta = newScreenRatioPosition - screenRatioPosition;
|
||||
if (Math.Abs(delta.X) >= MouseDragEpsilon || Math.Abs(delta.Y) >= MouseDragEpsilon)
|
||||
{
|
||||
CalamityConfig.Instance.FlightBarPosX = newScreenRatioPosition.X;
|
||||
CalamityConfig.Instance.FlightBarPosY = newScreenRatioPosition.Y;
|
||||
}
|
||||
|
||||
// When the mouse is released, save the config and destroy the drag offset.
|
||||
if (ms.LeftButton == ButtonState.Released)
|
||||
{
|
||||
dragOffset = null;
|
||||
CalamityMod.SaveConfig(CalamityConfig.Instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
private const int FlightAnimFrameDelay = 5;
|
||||
private const int FlightAnimFrames = 17;
|
||||
|
||||
private static int FlightAnimFrame = -1;
|
||||
private static int FlightAnimTimer = 0;
|
||||
*/
|
||||
private static void DrawFlightBar(SpriteBatch spriteBatch, CalamityPlayer modPlayer, Vector2 screenPos)
|
||||
{
|
||||
float uiScale = Main.UIScale;
|
||||
Player player = modPlayer.Player;
|
||||
float flightRatio = player.wingTime / player.wingTimeMax;
|
||||
if (!completedAnimation && FlightAnimFrame == -1 && modPlayer.infiniteFlight)
|
||||
FlightAnimFrame++;
|
||||
if (FlightAnimFrame > -1) //animation started, complete it.
|
||||
{
|
||||
FlightAnimTimer++;
|
||||
if (FlightAnimTimer >= FlightAnimFrameDelay)
|
||||
{
|
||||
if (FlightAnimFrame >= FlightAnimFrames)
|
||||
{
|
||||
FlightAnimFrame = -1;
|
||||
FlightAnimTimer = 0;
|
||||
completedAnimation = modPlayer.infiniteFlight; //completed animation sets to true if infinite flight still exists
|
||||
}
|
||||
else
|
||||
{
|
||||
FlightAnimTimer = 0;
|
||||
FlightAnimFrame++;
|
||||
}
|
||||
}
|
||||
}
|
||||
Texture2D correctBorder = GetApplicableBorder(modPlayer); //Fetch texture after animation calculations in case update to infinite flight
|
||||
|
||||
if (completedAnimation && !modPlayer.infiniteFlight && correctBorder != infiniteBarTexture)
|
||||
completedAnimation = false; //reset flight anim once infinite flight expires.
|
||||
|
||||
|
||||
float offset = (correctBorder.Width - barTexture.Width) * 0.5f;
|
||||
spriteBatch.Draw(correctBorder, screenPos, null, Color.White, 0f, correctBorder.Size() * 0.5f, uiScale, SpriteEffects.None, 0);
|
||||
if (correctBorder != disabledBarTexture && correctBorder != infiniteBarTexture) //neither requires an internal bar to be drawn
|
||||
{
|
||||
int correctHeight = (correctBorder == limitedBarTexture ? barTexture.Height / 2 : barTexture.Height);
|
||||
Rectangle barRectangle = barTexture.Bounds;
|
||||
barRectangle.Height = (int)(correctHeight * flightRatio);
|
||||
Vector2 origin = correctBorder.Size() * 0.5f;
|
||||
|
||||
spriteBatch.Draw(barTexture, screenPos - new Vector2(offset * uiScale, 11), barRectangle, Color.White, MathHelper.ToRadians(180), origin, uiScale, SpriteEffects.None, 0);
|
||||
}
|
||||
if (!completedAnimation && FlightAnimFrame >= 0)
|
||||
{
|
||||
Vector2 origin = new Vector2(correctBorder.Width * 0.5f, (correctBorder.Height / FlightAnimFrames) * 0.5f);
|
||||
float animOffset = 5f;
|
||||
float xOffset = (correctBorder.Width - flightBarAnimTexture.Width) / 2f;
|
||||
int frameHeight = (flightBarAnimTexture.Height / FlightAnimFrames) - 1;
|
||||
float yOffset = FlightAnimFrame == 0 ? 0 : ((correctBorder.Height / FlightAnimFrame) - frameHeight) / 2f ;
|
||||
Vector2 sizeDiffOffset = new Vector2(xOffset, yOffset);
|
||||
Rectangle animCropRect = new Rectangle(0, (frameHeight + 1) * FlightAnimFrame, flightBarAnimTexture.Width, frameHeight);
|
||||
spriteBatch.Draw(flightBarAnimTexture, screenPos + sizeDiffOffset, animCropRect, Color.White, 0f, origin, uiScale, SpriteEffects.None, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 285 B |
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 515 B |
Binary file not shown.
|
After Width: | Height: | Size: 493 B |
Binary file not shown.
|
After Width: | Height: | Size: 451 B |
Binary file not shown.
|
After Width: | Height: | Size: 517 B |
Reference in new issue
Block a user