Skip to content

Commit

Permalink
Refactored even more code
Browse files Browse the repository at this point in the history
Added a recipe to the AutoHammer and made the mod release ready.
  • Loading branch information
Kirtle committed Jul 7, 2020
1 parent f7127f5 commit e8ca564
Show file tree
Hide file tree
Showing 18 changed files with 181 additions and 198 deletions.
33 changes: 12 additions & 21 deletions BuilderPlayer.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
using BuilderEssentials.UI;
using BuilderEssentials.Utilities;
using log4net.Repository.Hierarchy;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using Terraria;
using Terraria.GameInput;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ModLoader.Config;
using Terraria.ModLoader.IO;

namespace BuilderEssentials
Expand Down Expand Up @@ -58,6 +53,13 @@ public enum CreativeWheelItem

//Mirror Wand
public bool mirrorWandEffects;

void FillListWithEmptyItems(ref List<Item> list, int size)
{
for (int i = 0; i < size; i++)
list.Add(new Item());
}

public override void Initialize()
{
infiniteRange = false;
Expand Down Expand Up @@ -115,13 +117,13 @@ public override void ResetEffects()
player.showItemIcon = false;
infiniteRange = false;

if (!player.inventory[player.selectedItem].IsAir)
if (!player.HeldItem.IsAir)
{
if (BasePanel.creativeWheelPanel != null)
if (CreativeWheel.CreativeWheelPanel != null)
{
BasePanel.creativeWheelPanel.Remove();
BasePanel.creativeWheelUIOpen = false;
BasePanel.isCreativeWheelVisible = false;
CreativeWheel.CreativeWheelPanel.Remove();
CreativeWheel.CreativeWheelUIOpen = false;
CreativeWheel.IsCreativeWheelVisible = false;
}
}

Expand Down Expand Up @@ -221,20 +223,9 @@ public override void Load(TagCompound tag)

public override void OnEnterWorld(Player player)
{
if (!IsNormalAccessories)
BasePanel.buildingModeButton.SetImage(BuilderEssentials.BuildingModeOn);
else
BasePanel.buildingModeButton.SetImage(BuilderEssentials.BuildingModeOff);

//Loads (or populates) all lists on enter world
Tools.BuildingModeToggle();
Tools.BuildingModeToggle();
}

void FillListWithEmptyItems(ref List<Item> list, int size)
{
for (int i = 0; i < size; i++)
list.Add(new Item());
}
}
}
16 changes: 10 additions & 6 deletions Items/Accessories/CreativeWrench.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public override void UpdateAccessory(Player player, bool hideVisual)
{
modPlayer = Main.LocalPlayer.GetModPlayer<BuilderPlayer>();

//Checking if player's heldItem is air
if (!player.HeldItem.IsAir)
Tools.UIPanelLogic(CreativeWheel.CreativeWheelPanel, ref CreativeWheel.CreativeWheelUIOpen, ref CreativeWheel.IsCreativeWheelVisible);

//Accessory Stats
player.blockRange += 55;
player.wallSpeed += 10;
Expand All @@ -54,11 +58,11 @@ public override void UpdateAccessory(Player player, bool hideVisual)

//Right click timer
if (Main.mouseRight && Tools.IsUIAvailable() &&
player.inventory[player.selectedItem].IsAir &&
(!player.mouseInterface || CreativeWheelRework.CreativeWheelReworkPanel.IsMouseHovering))
player.HeldItem.IsAir &&
(!player.mouseInterface || CreativeWheel.CreativeWheelPanel.IsMouseHovering))
{
if (++mouseRightTimer == 2)
BasePanel.creativeWheelUIOpen = !BasePanel.creativeWheelUIOpen;
CreativeWheel.CreativeWheelUIOpen = !CreativeWheel.CreativeWheelUIOpen;
}

if (Main.mouseRightRelease)
Expand All @@ -71,14 +75,14 @@ public override void UpdateAccessory(Player player, bool hideVisual)

//AutoHammer
if (Main.mouseLeft && modPlayer.creativeWheelSelectedIndex.Contains((int)CreativeWheelItem.AutoHammer) &&
player.inventory[player.selectedItem].IsAir && CreativeWheelRework.CreativeWheelReworkPanel != null &&
player.HeldItem.IsAir && CreativeWheel.CreativeWheelPanel != null &&
!player.mouseInterface && !Main.playerInventory)
{
if (!CreativeWheelRework.CreativeWheelReworkPanel.IsMouseHovering)
if (!CreativeWheel.CreativeWheelPanel.IsMouseHovering)
Tools.ChangeSlope(ref oldPosX, ref oldPosY, ref previousClickedTile, modPlayer.autoHammerSelectedIndex);
}
else if (Main.mouseLeft && modPlayer.creativeWheelSelectedIndex.Contains((int)CreativeWheelItem.AutoHammer)
&& !player.inventory[player.selectedItem].IsAir && !player.mouseInterface && !Main.playerInventory)
&& !player.HeldItem.IsAir && !player.mouseInterface && !Main.playerInventory)
{
if (!autoHammerAlert)
{
Expand Down
32 changes: 24 additions & 8 deletions Items/AutoHammer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using BuilderEssentials.UI;
using BuilderEssentials.Utilities;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
Expand All @@ -18,6 +17,7 @@ public override void SetStaticDefaults()
public override void SetDefaults()
{
item.CloneDefaults(ItemID.Pwnhammer);
item.rare = ItemRarityID.Red;
item.tileBoost += 2;
toolRange = 8;
}
Expand All @@ -27,15 +27,9 @@ public override void HoldItem(Player player)
{
if (player.whoAmI == Main.myPlayer)
{
if (AutoHammerWheel.AutoHammerWheelPanel != null && !player.inventory[player.selectedItem].IsTheSameAs(item))
{
AutoHammerWheel.AutoHammerWheelPanel.Remove();
AutoHammerWheel.AutoHammerUIOpen = false;
}

if (Main.mouseRight && Tools.IsUIAvailable()
&& (!player.mouseInterface || (AutoHammerWheel.AutoHammerUIOpen && AutoHammerWheel.AutoHammerWheelPanel.IsMouseHovering))
&& player.inventory[player.selectedItem].IsTheSameAs(item))
&& player.HeldItem.IsTheSameAs(item))
{
if (++mouseRightTimer == 2)
AutoHammerWheel.AutoHammerUIOpen = !AutoHammerWheel.AutoHammerUIOpen;
Expand Down Expand Up @@ -76,5 +70,27 @@ public override bool CanUseItem(Player player)

return true;
}

public override void UpdateInventory(Player player)
{
if (player.whoAmI == Main.myPlayer)
{
if (AutoHammerWheel.AutoHammerWheelPanel != null && !player.HeldItem.IsTheSameAs(item))
{
AutoHammerWheel.AutoHammerWheelPanel.Remove();
AutoHammerWheel.AutoHammerUIOpen = false;
}
}
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.Pwnhammer);
recipe.AddIngredient(ItemID.Wood, 200);
recipe.AddTile(TileID.MythrilAnvil);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}
3 changes: 1 addition & 2 deletions Items/InfinitePaintBucket.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BuilderEssentials.UI;
using Terraria;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

Expand Down
3 changes: 0 additions & 3 deletions Items/MirrorWand.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using BuilderEssentials.UI;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
Expand Down
11 changes: 6 additions & 5 deletions Items/MultiWand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public override void UpdateInventory(Player player)
{
if (player.whoAmI == Main.myPlayer)
{
if (MultiWandWheel.MultiWandWheelPanel != null && !player.inventory[player.selectedItem].IsTheSameAs(item))
if (MultiWandWheel.MultiWandWheelPanel != null && !player.HeldItem.IsTheSameAs(item))
{
MultiWandWheel.MultiWandWheelPanel.Remove();
MultiWandWheel.WandsWheelUIOpen = false;
}

if (Main.mouseRight && Tools.IsUIAvailable()
&& (!player.mouseInterface || (MultiWandWheel.WandsWheelUIOpen && MultiWandWheel.MultiWandWheelPanel.IsMouseHovering))
&& player.inventory[player.selectedItem].IsTheSameAs(item))
&& player.HeldItem.IsTheSameAs(item))
{
if (++mouseRightTimer == 2)
MultiWandWheel.WandsWheelUIOpen = !MultiWandWheel.WandsWheelUIOpen;
Expand Down Expand Up @@ -75,9 +75,10 @@ public override bool UseItem(Player player)
oldPosX = posX;
oldPosY = posY;

if (placementAnywhere || Tools.HasTileAround(posX, posY))
if ((placementAnywhere || Tools.HasTileAround(posX, posY)) &&
!MultiWandWheel.MultiWandWheelPanel.IsMouseHovering && !MultiWandWheel.IsWandsUIVisible)
{
switch (modPlayer.wandWheelSelectedIndex)
switch (MultiWandWheel.selectedIndex)
{
case 0: //living wood
if (infinitePlacement || Tools.ReduceItemStack(ItemID.Wood))
Expand Down Expand Up @@ -142,7 +143,7 @@ public override void HoldItem(Player player)
if (modPlayer.infiniteRange || Tools.ToolHasRange(toolRange))
{
player.showItemIcon = true;
switch (modPlayer.wandWheelSelectedIndex)
switch (MultiWandWheel.selectedIndex)
{
case 0:
player.showItemIcon2 = ItemID.LivingWoodWand;
Expand Down
3 changes: 1 addition & 2 deletions Items/SuperPaintingTool.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using BuilderEssentials.UI;
using BuilderEssentials.Utilities;
Expand Down Expand Up @@ -57,7 +56,7 @@ public override void UpdateInventory(Player player)

if (Main.mouseRight && Tools.IsUIAvailable()
&& (!player.mouseInterface || (PaintWheel.PaintingUIOpen && PaintWheel.PaintWheelPanel.IsMouseHovering))
&& player.inventory[player.selectedItem].IsTheSameAs(item))
&& player.HeldItem.IsTheSameAs(item))
{
if (++mouseRightTimer == 2)
PaintWheel.PaintingUIOpen = !PaintWheel.PaintingUIOpen;
Expand Down
4 changes: 2 additions & 2 deletions UI/AutoHammerWheel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class AutoHammerWheel : UIPanel
private static float AutoHammerWheelHeight;
private static List<UIImageButton> AutoHammerElements;
public static int selectedIndex = 5;//full tile
public static bool IsAutoHammerUIVisible { get; set; }
public static bool AutoHammerUIOpen { get; set; }
public static bool IsAutoHammerUIVisible;
public static bool AutoHammerUIOpen;
public static bool Hovering = AutoHammerWheelPanel != null && AutoHammerWheelPanel.IsMouseHovering && IsAutoHammerUIVisible;

public static UIPanel CreateAutoHammerWheelPanel(int mouseX, int mouseY, BasePanel basePanel)
Expand Down
Loading

0 comments on commit e8ca564

Please sign in to comment.