diff --git a/Items/Accessories/Wings/MOAB.cs b/Items/Accessories/Wings/MOAB.cs index f046d2c970..40a85ef039 100644 --- a/Items/Accessories/Wings/MOAB.cs +++ b/Items/Accessories/Wings/MOAB.cs @@ -1,4 +1,5 @@ -using Microsoft.Xna.Framework; +using System.IO; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.Audio; @@ -35,38 +36,50 @@ namespace CalamityMod.Items.Accessories.Wings Item.value = CalamityGlobalItem.RarityLightPurpleBuyPrice; Item.rare = ItemRarityID.LightPurple; } - - public override void SaveData(TagCompound tag) + #region Toggleable Wings + bool toggleEnabled { - tag.Add("wingsDisabled", Item.wingSlot == -1); - } - - public override void LoadData(TagCompound tag) - { - if (tag.TryGet("wingsDisabled", out bool wingsDisabled)) + get { return Item.wingSlot != -1; } + set { - if (wingsDisabled) Item.wingSlot = -1; + if (value) + Item.wingSlot = wingSlot; + else + Item.wingSlot = -1; } } - public override bool CanRightClick() - { - if (!Main.keyState.PressingShift()) - return false; - return true; - } + public override bool CanRightClick() => Main.keyState.PressingShift(); public override void RightClick(Player player) { - if (Item.wingSlot == wingSlot) - Item.wingSlot = -1; - else - Item.wingSlot = wingSlot; + toggleEnabled = !toggleEnabled; + Item.NetStateChanged(); } - public override bool ConsumeItem(Player player) => false; + public override void SaveData(TagCompound tag) + { + tag.Add("toggleEffect", toggleEnabled); + } + public override void LoadData(TagCompound tag) + { + toggleEnabled = tag.GetBool("toggleEffect"); + } + public override void NetSend(BinaryWriter writer) + { + writer.Write(toggleEnabled); + } + public override void NetReceive(BinaryReader reader) + { + toggleEnabled = reader.ReadBoolean(); + } + public override void PostDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) + { + CalamityUtils.DrawInventoryDot(spriteBatch, position, new Vector2(16, 16) * Main.inventoryScale, toggleEnabled); + } + #endregion public override void UpdateAccessory(Player player, bool hideVisual) { - if (Item.wingSlot != -1 && player.controlJump && player.wingTime > 0f && player.jump == 0 && player.velocity.Y != 0f && !hideVisual) + if (toggleEnabled && player.controlJump && player.wingTime > 0f && player.jump == 0 && player.velocity.Y != 0f && !hideVisual) { player.rocketDelay2--; if (player.rocketDelay2 <= 0) @@ -131,34 +144,6 @@ namespace CalamityMod.Items.Accessories.Wings // Mirrors the +5% luck from Lucky Horseshoe (vanilla behavior). player.Calamity().calamityBonusLuck += 0.05f; } - - //This code is commented out so it can be used when we get a MOAB wingless sprite - /*public override bool PreDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) - { - frame = new Rectangle(0, (Item.wingSlot == -1 ? frame.Height / 2 : 0), frame.Width, frame.Height / 2); - position -= -new Vector2(0, frame.Height/2-2); - CalamityUtils.DrawInventoryCustomScale( - spriteBatch, - texture: TextureAssets.Item[Type].Value, - position, - frame, - drawColor, - itemColor, - origin, - scale - ); - return false; - }*/ - - //This entire method can be deleted when we get a wingless sprite - public override void UpdateInventory(Player player) - { - if (Item.wingSlot == -1) - Item.color = Color.DarkGray; - else - Item.color = Color.Transparent; - } - public override void AddRecipes() { CreateRecipe(). diff --git a/Items/Accessories/Wings/TracersCelestial.cs b/Items/Accessories/Wings/TracersCelestial.cs index d21cd12c6e..88e2755350 100644 --- a/Items/Accessories/Wings/TracersCelestial.cs +++ b/Items/Accessories/Wings/TracersCelestial.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System.IO; +using System.Linq; using CalamityMod.CalPlayer; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -33,37 +34,50 @@ namespace CalamityMod.Items.Accessories.Wings { base.SetDefaults(); Item.width = 36; - Item.height = 32; + Item.height = 40; Item.value = CalamityGlobalItem.RarityRedBuyPrice; Item.rare = ItemRarityID.Red; } - public override void SaveData(TagCompound tag) + #region Toggleable Wings + bool toggleEnabled { - tag.Add("wingsDisabled", Item.wingSlot == -1); - } - - public override void LoadData(TagCompound tag) - { - if (tag.TryGet("wingsDisabled", out bool wingsDisabled)) - { - if (wingsDisabled) Item.wingSlot = -1; + get { return Item.wingSlot != -1; } + set + { + if (value) + Item.wingSlot = wingSlot; + else + Item.wingSlot = -1; } } - public override bool CanRightClick() - { - if (!Main.keyState.PressingShift()) - return false; - return true; - } + public override bool CanRightClick() => Main.keyState.PressingShift(); public override void RightClick(Player player) { - if (Item.wingSlot == wingSlot) - Item.wingSlot = -1; - else - Item.wingSlot = wingSlot; + toggleEnabled = !toggleEnabled; + Item.NetStateChanged(); } - public override bool ConsumeItem(Player player) => false; + public override void SaveData(TagCompound tag) + { + tag.Add("toggleEffect", toggleEnabled); + } + public override void LoadData(TagCompound tag) + { + toggleEnabled = tag.GetBool("toggleEffect"); + } + public override void NetSend(BinaryWriter writer) + { + writer.Write(toggleEnabled); + } + public override void NetReceive(BinaryReader reader) + { + toggleEnabled = reader.ReadBoolean(); + } + public override void PostDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) + { + CalamityUtils.DrawInventoryDot(spriteBatch, position, new Vector2(16, 16) * Main.inventoryScale, toggleEnabled); + } + #endregion public override void UpdateAccessory(Player player, bool hideVisual) { if (player.controlJump && player.wingTime > 0f && player.jump == 0 && player.velocity.Y != 0f && !hideVisual) @@ -90,12 +104,13 @@ namespace CalamityMod.Items.Accessories.Wings player.fireWalk = true; player.lavaImmune = true; player.buffImmune[BuffID.OnFire] = true; - player.noFallDmg = true; if (Item.wingSlot == -1) //Only applies if tracers are plucked + player.noFallDmg = true; + if (!toggleEnabled) { player.rocketBoots = player.vanityRocketBoots = 4; modPlayer.angelTreads = true; } - modPlayer.tracersDust = !hideVisual; + modPlayer.tracersDust = !hideVisual && toggleEnabled; modPlayer.tracersCelestial = true; } @@ -111,30 +126,19 @@ namespace CalamityMod.Items.Accessories.Wings public override bool PreDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) { - //This code is commented out as it's for when Tracers get wingless sprites. Uncomment it then. - //frame = new Rectangle(0,(Item.wingSlot == -1 ? frame.Height / 2 : 0), frame.Width, frame.Height / 2); //Draws the tracers with/without wings depending on if they're set to function as wings. - //position -= -new Vector2((Item.wingSlot == -1 ? 4 : 0), frame.Height / 2 - (Item.wingSlot == -1 ? 2 : 0)); - CalamityUtils.DrawInventoryCustomScale( - spriteBatch, - texture: TextureAssets.Item[Type].Value, - position, - frame, - drawColor, - itemColor, - origin, - scale, - wantedScale: 0.9f, - drawOffset: new(1f, 0f) - ); + var tex = TextureAssets.Item[Type].Value; + frame = tex.Frame(2, 1, toggleEnabled ? 0 : 1); + spriteBatch.Draw(tex, position, frame, Color.White, 0, frame.Size() * 0.5f, Main.inventoryScale * 0.8f, SpriteEffects.None, 0); return false; } - // This code is to color the sprite until we get wingless sprites. - public override void UpdateInventory(Player player) + + public override bool PreDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, ref float rotation, ref float scale, int whoAmI) { - if (Item.wingSlot == -1) - Item.color = Color.DarkGray; - else - Item.color = Color.Transparent; + + var tex = TextureAssets.Item[Type].Value; + var frame = tex.Frame(2, 1, toggleEnabled ? 0 : 1); + spriteBatch.Draw(tex, Item.Center - Main.screenPosition, frame, lightColor, rotation, frame.Size() * 0.5f, scale, SpriteEffects.None, 0); + return false; } } } diff --git a/Items/Accessories/Wings/TracersCelestial.png b/Items/Accessories/Wings/TracersCelestial.png index 11e351774f..ccb6df8508 100644 Binary files a/Items/Accessories/Wings/TracersCelestial.png and b/Items/Accessories/Wings/TracersCelestial.png differ diff --git a/Items/Accessories/Wings/TracersElysian.cs b/Items/Accessories/Wings/TracersElysian.cs index 6ed61d216f..2c6aea530e 100644 --- a/Items/Accessories/Wings/TracersElysian.cs +++ b/Items/Accessories/Wings/TracersElysian.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System.IO; +using System.Linq; using CalamityMod.CalPlayer; using CalamityMod.Items.Materials; using CalamityMod.Rarities; @@ -40,45 +41,46 @@ namespace CalamityMod.Items.Accessories.Wings Item.value = CalamityGlobalItem.RarityDarkBlueBuyPrice; Item.rare = ModContent.RarityType(); } - public override void SaveData(TagCompound tag) + #region Toggleable Wings + bool toggleEnabled { - tag.Add("wingsDisabled", Item.wingSlot == -1); - } - - public override void LoadData(TagCompound tag) - { - if (tag.TryGet("wingsDisabled", out bool wingsDisabled)) + get { return Item.wingSlot != -1; } + set { - if (wingsDisabled) Item.wingSlot = -1; + if (value) + Item.wingSlot = wingSlot; + else + Item.wingSlot = -1; } } - - public override bool CanRightClick() - { - if (!Main.keyState.PressingShift()) - return false; - if (Main.LocalPlayer.armor.Contains(Item)) foreach (var item in Main.LocalPlayer.armor) - { - if (item.wingSlot > 0 && item.wingSlot != wingSlot) - return false; - } - return true; - } + public override bool CanRightClick() => Main.keyState.PressingShift(); public override void RightClick(Player player) { - if (Item.wingSlot == wingSlot) - { - Item.wingSlot = -1; - Item.color = Color.Gray; - } - else - { - Item.wingSlot = wingSlot; - Item.color = Color.White; - } + toggleEnabled = !toggleEnabled; + Item.NetStateChanged(); } - public override bool ConsumeItem(Player player) => false; + public override void SaveData(TagCompound tag) + { + tag.Add("toggleEffect", toggleEnabled); + } + public override void LoadData(TagCompound tag) + { + toggleEnabled = tag.GetBool("toggleEffect"); + } + public override void NetSend(BinaryWriter writer) + { + writer.Write(toggleEnabled); + } + public override void NetReceive(BinaryReader reader) + { + toggleEnabled = reader.ReadBoolean(); + } + public override void PostDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) + { + CalamityUtils.DrawInventoryDot(spriteBatch, position, new Vector2(16, 16) * Main.inventoryScale, toggleEnabled); + } + #endregion public override void UpdateAccessory(Player player, bool hideVisual) { if (player.controlJump && player.wingTime > 0f && player.jump == 0 && player.velocity.Y != 0f && !hideVisual) @@ -107,12 +109,12 @@ namespace CalamityMod.Items.Accessories.Wings player.buffImmune[BuffID.OnFire] = true; player.noFallDmg = true; player.socialShadowRocketBoots = true; - if (Item.wingSlot == -1) //Only applies if tracers are plucked + if (!toggleEnabled) //Only applies if tracers are plucked { player.rocketBoots = player.vanityRocketBoots = 1; modPlayer.angelTreads = true; } - modPlayer.tracersDust = !hideVisual; + modPlayer.tracersDust = !hideVisual && toggleEnabled; modPlayer.tracersElysian = true; } @@ -126,34 +128,5 @@ namespace CalamityMod.Items.Accessories.Wings AddTile(). Register(); } - - public override bool PreDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) - { - //This code is commented out as it's for when Tracers get wingless sprites. Uncomment it then. - //frame = new Rectangle(0, (Item.wingSlot == -1 ? frame.Height / 2 : 0), frame.Width, frame.Height / 2); //Draws the tracers with/without wings depending on if they're set to function as wings. - //position -= -new Vector2((Item.wingSlot == -1 ? 4 : 0), frame.Height / 2 - (Item.wingSlot == -1 ? 2 : 0)); - - CalamityUtils.DrawInventoryCustomScale( - spriteBatch, - texture: TextureAssets.Item[Type].Value, - position, - frame, - drawColor, - itemColor, - origin, - scale, - wantedScale: 0.9f, - drawOffset: new(1f, 0f) - ); - return false; - } - // This code is to color the sprite until we get wingless sprites. - public override void UpdateInventory(Player player) - { - if (Item.wingSlot == -1) - Item.color = Color.DarkGray; - else - Item.color = Color.Transparent; - } } } diff --git a/Items/Accessories/Wings/TracersSeraph.cs b/Items/Accessories/Wings/TracersSeraph.cs index 0159f6b818..ccea0aadfa 100644 --- a/Items/Accessories/Wings/TracersSeraph.cs +++ b/Items/Accessories/Wings/TracersSeraph.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System.IO; +using System.Linq; using CalamityMod.CalPlayer; using CalamityMod.Items.Materials; using CalamityMod.Projectiles.Melee; @@ -33,44 +34,6 @@ namespace CalamityMod.Items.Accessories.Wings ArmorIDs.Wing.Sets.Stats[Item.wingSlot] = new WingStats(250, 11f, 2.8f); wingSlot = Item.wingSlot; } - public override void SaveData(TagCompound tag) - { - tag.Add("wingsDisabled", Item.wingSlot == -1); - } - - public override void LoadData(TagCompound tag) - { - if (tag.TryGet("wingsDisabled", out bool wingsDisabled)) - { - if (wingsDisabled) Item.wingSlot = -1; - } - } - - public override bool CanRightClick() - { - if (!Main.keyState.PressingShift()) - return false; - if (Main.LocalPlayer.armor.Contains(Item)) foreach (var item in Main.LocalPlayer.armor) - { - if (item.wingSlot > 0 && item.wingSlot != wingSlot) - return false; - } - return true; - } - public override void RightClick(Player player) - { - if (Item.wingSlot == wingSlot){ - Item.wingSlot = -1; - Item.color = Color.Gray; - } - else - { - Item.wingSlot = wingSlot; - Item.color = Color.White; - } - } - - public override bool ConsumeItem(Player player) => false; public override void SetDefaults() { base.SetDefaults(); @@ -79,6 +42,46 @@ namespace CalamityMod.Items.Accessories.Wings Item.value = CalamityGlobalItem.RarityVioletBuyPrice; Item.rare = ModContent.RarityType(); } + #region Toggleable Wings + bool toggleEnabled + { + get { return Item.wingSlot != -1; } + set + { + if (value) + Item.wingSlot = wingSlot; + else + Item.wingSlot = -1; + } + } + public override bool CanRightClick() => Main.keyState.PressingShift(); + public override void RightClick(Player player) + { + toggleEnabled = !toggleEnabled; + Item.NetStateChanged(); + } + public override bool ConsumeItem(Player player) => false; + public override void SaveData(TagCompound tag) + { + tag.Add("toggleEffect", toggleEnabled); + } + public override void LoadData(TagCompound tag) + { + toggleEnabled = tag.GetBool("toggleEffect"); + } + public override void NetSend(BinaryWriter writer) + { + writer.Write(toggleEnabled); + } + public override void NetReceive(BinaryReader reader) + { + toggleEnabled = reader.ReadBoolean(); + } + public override void PostDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) + { + CalamityUtils.DrawInventoryDot(spriteBatch, position, new Vector2(16, 16) * Main.inventoryScale, toggleEnabled); + } + #endregion public override void UpdateAccessory(Player player, bool hideVisual) { @@ -112,7 +115,7 @@ namespace CalamityMod.Items.Accessories.Wings player.rocketBoots = player.vanityRocketBoots = 2; modPlayer.angelTreads = true; } - modPlayer.tracersDust = !hideVisual; + modPlayer.tracersDust = !hideVisual && toggleEnabled; modPlayer.tracersSeraph = true; // Grants immunity to Auric Rejection and other walk-on-block effects } @@ -125,33 +128,5 @@ namespace CalamityMod.Items.Accessories.Wings AddTile(). Register(); } - - public override bool PreDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) - { - //This code is commented out as it's for when Tracers get wingless sprites. Uncomment it then. - //frame = new Rectangle(0, (Item.wingSlot == -1 ? frame.Height / 2 : 0), frame.Width, frame.Height / 2); //Draws the tracers with/without wings depending on if they're set to function as wings. - //position -= -new Vector2((Item.wingSlot == -1 ? 4 : 0), frame.Height / 2 - (Item.wingSlot == -1 ? 6 : 4)); - CalamityUtils.DrawInventoryCustomScale( - spriteBatch, - texture: TextureAssets.Item[Type].Value, - position, - frame, - drawColor, - itemColor, - origin, - scale, - wantedScale: 0.8f, - drawOffset: new(1f, 0f) - ); - return false; - } - // This code is to color the sprite until we get wingless sprites. - public override void UpdateInventory(Player player) - { - if (Item.wingSlot == -1) - Item.color = Color.DarkGray; - else - Item.color = Color.Transparent; - } } }