From e8ca564208bb8a87f8cfa8870436a3920cdedbb5 Mon Sep 17 00:00:00 2001 From: Kirtle Date: Tue, 7 Jul 2020 07:29:03 +0100 Subject: [PATCH] Refactored even more code Added a recipe to the AutoHammer and made the mod release ready. --- BuilderPlayer.cs | 33 ++-- Items/Accessories/CreativeWrench.cs | 16 +- Items/AutoHammer.cs | 32 +++- Items/InfinitePaintBucket.cs | 3 +- Items/MirrorWand.cs | 3 - Items/MultiWand.cs | 11 +- Items/SuperPaintingTool.cs | 3 +- UI/AutoHammerWheel.cs | 4 +- UI/BasePanel.cs | 163 +++++++----------- ...reativeWheelRework.cs => CreativeWheel.cs} | 36 ++-- UI/MultiWandWheel.cs | 12 +- UI/PaintWheel.cs | 4 +- Utilities/BuildingMode.cs | 9 +- Utilities/InfinitePlacement.cs | 3 +- Utilities/ItemPicker.cs | 4 +- Utilities/MiscUtilities.cs | 36 +++- build.txt | 2 +- description.txt | 5 +- 18 files changed, 181 insertions(+), 198 deletions(-) rename UI/{CreativeWheelRework.cs => CreativeWheel.cs} (85%) diff --git a/BuilderPlayer.cs b/BuilderPlayer.cs index 1841530..dbf94d7 100644 --- a/BuilderPlayer.cs +++ b/BuilderPlayer.cs @@ -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 @@ -58,6 +53,13 @@ public enum CreativeWheelItem //Mirror Wand public bool mirrorWandEffects; + + void FillListWithEmptyItems(ref List list, int size) + { + for (int i = 0; i < size; i++) + list.Add(new Item()); + } + public override void Initialize() { infiniteRange = false; @@ -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; } } @@ -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 list, int size) - { - for (int i = 0; i < size; i++) - list.Add(new Item()); - } } } diff --git a/Items/Accessories/CreativeWrench.cs b/Items/Accessories/CreativeWrench.cs index 365c996..e4ff3ce 100644 --- a/Items/Accessories/CreativeWrench.cs +++ b/Items/Accessories/CreativeWrench.cs @@ -36,6 +36,10 @@ public override void UpdateAccessory(Player player, bool hideVisual) { modPlayer = Main.LocalPlayer.GetModPlayer(); + //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; @@ -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) @@ -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) { diff --git a/Items/AutoHammer.cs b/Items/AutoHammer.cs index f24983e..4980fc9 100644 --- a/Items/AutoHammer.cs +++ b/Items/AutoHammer.cs @@ -1,6 +1,5 @@ using BuilderEssentials.UI; using BuilderEssentials.Utilities; -using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; using Terraria.ModLoader; @@ -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; } @@ -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; @@ -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(); + } } } diff --git a/Items/InfinitePaintBucket.cs b/Items/InfinitePaintBucket.cs index 7e34bec..c9e2ca0 100644 --- a/Items/InfinitePaintBucket.cs +++ b/Items/InfinitePaintBucket.cs @@ -1,5 +1,4 @@ -using BuilderEssentials.UI; -using Terraria; +using Terraria; using Terraria.ID; using Terraria.ModLoader; diff --git a/Items/MirrorWand.cs b/Items/MirrorWand.cs index 0e36a50..7d49587 100644 --- a/Items/MirrorWand.cs +++ b/Items/MirrorWand.cs @@ -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; diff --git a/Items/MultiWand.cs b/Items/MultiWand.cs index 33e48df..70b40a4 100644 --- a/Items/MultiWand.cs +++ b/Items/MultiWand.cs @@ -35,7 +35,7 @@ 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; @@ -43,7 +43,7 @@ public override void UpdateInventory(Player player) 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; @@ -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)) @@ -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; diff --git a/Items/SuperPaintingTool.cs b/Items/SuperPaintingTool.cs index 72ba2a6..dcd9f47 100644 --- a/Items/SuperPaintingTool.cs +++ b/Items/SuperPaintingTool.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using BuilderEssentials.UI; using BuilderEssentials.Utilities; @@ -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; diff --git a/UI/AutoHammerWheel.cs b/UI/AutoHammerWheel.cs index 39d018a..d2c53f2 100644 --- a/UI/AutoHammerWheel.cs +++ b/UI/AutoHammerWheel.cs @@ -16,8 +16,8 @@ class AutoHammerWheel : UIPanel private static float AutoHammerWheelHeight; private static List 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) diff --git a/UI/BasePanel.cs b/UI/BasePanel.cs index ea21637..0dc10bc 100644 --- a/UI/BasePanel.cs +++ b/UI/BasePanel.cs @@ -1,7 +1,6 @@ using Terraria; using Terraria.UI; using Terraria.GameContent.UI.Elements; -using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework; using BuilderEssentials.Utilities; using System.Collections.Generic; @@ -11,16 +10,12 @@ namespace BuilderEssentials.UI public class BasePanel : UIState { public static UIImageButton buildingModeButton; - public static Texture2D buttonTexture; - public static UIPanel creativeWheelPanel; public static bool isBuildingModeButtonVisible; - public static bool isCreativeWheelVisible; - public static bool creativeWheelUIOpen; static UIText hoverText; + static string text; public override void OnInitialize() { - buttonTexture = BuilderEssentials.BuildingModeOff; - buildingModeButton = new UIImageButton(buttonTexture); + buildingModeButton = new UIImageButton(BuilderEssentials.BuildingModeOff); buildingModeButton.VAlign = 0f; buildingModeButton.HAlign = 0f; buildingModeButton.Top.Set(40f, 0); @@ -29,112 +24,51 @@ public override void OnInitialize() buildingModeButton.SetVisibility(0f, 0f); Append(buildingModeButton); } - public override void Update(GameTime gameTime) - { - if (Main.playerInventory) - { - if (!isBuildingModeButtonVisible) - { - buildingModeButton.SetVisibility(1f, .4f); - isBuildingModeButtonVisible = true; - } - if (isCreativeWheelVisible) - { - creativeWheelPanel.Remove(); - creativeWheelUIOpen = false; - isCreativeWheelVisible = false; - } - - if (PaintWheel.IsPaintingUIVisible) - { - PaintWheel.PaintWheelPanel.Remove(); - PaintWheel.PaintingUIOpen = false; - PaintWheel.IsPaintingUIVisible = false; - } - - if (MultiWandWheel.IsWandsUIVisible) - { - MultiWandWheel.MultiWandWheelPanel.Remove(); - MultiWandWheel.WandsWheelUIOpen = false; - MultiWandWheel.IsWandsUIVisible = false; - } - - if (AutoHammerWheel.IsAutoHammerUIVisible) - { - AutoHammerWheel.AutoHammerWheelPanel.Remove(); - AutoHammerWheel.AutoHammerUIOpen = false; - AutoHammerWheel.IsAutoHammerUIVisible = false; - } - } - else //!Main.playerInventory - { - if (isBuildingModeButtonVisible) - { - buildingModeButton.SetVisibility(0f, 0f); - isBuildingModeButtonVisible = false; - } - } + public void ChangeAccessories_OnClick(UIMouseEvent evt, UIElement listeningElement) + { + if (isBuildingModeButtonVisible) + Tools.BuildingModeToggle(); + } + public override void Update(GameTime gameTime) + { //Blocks mouse from interacting with the world when hovering on UI interfaces if ((buildingModeButton.IsMouseHovering && isBuildingModeButtonVisible) || - (creativeWheelPanel != null && creativeWheelPanel.IsMouseHovering && isCreativeWheelVisible) || - (PaintWheel.Hovering || MultiWandWheel.Hovering || AutoHammerWheel.Hovering)) + (CreativeWheel.Hovering || PaintWheel.Hovering || MultiWandWheel.Hovering || AutoHammerWheel.Hovering)) Main.LocalPlayer.mouseInterface = true; - //CreativeWrench Wheel UI - if (creativeWheelUIOpen && !isCreativeWheelVisible) + if (Main.playerInventory && !isBuildingModeButtonVisible) { - //creativeWheelPanel = CreativeWheel.CreateCreativeWheelPanel(Main.mouseX, Main.mouseY, this); - creativeWheelPanel = CreativeWheelRework.CreateCreativeWheelReworkPanel(Main.mouseX, Main.mouseY, this); - isCreativeWheelVisible = true; + buildingModeButton.SetVisibility(1f, .4f); + isBuildingModeButtonVisible = true; } - else if (!creativeWheelUIOpen && isCreativeWheelVisible) + else if (!Main.playerInventory && isBuildingModeButtonVisible) { - creativeWheelPanel.Remove(); - isCreativeWheelVisible = false; + buildingModeButton.SetVisibility(0f, 0f); + isBuildingModeButtonVisible = false; } + //CreativeWrench Wheel UI + if (Tools.UIPanelLogic(CreativeWheel.CreativeWheelPanel, ref CreativeWheel.CreativeWheelUIOpen, ref CreativeWheel.IsCreativeWheelVisible)) + CreativeWheel.CreateCreativeWheelReworkPanel(Main.mouseX, Main.mouseY, this); + //SuperPaintingTool Paint UI - if (PaintWheel.PaintingUIOpen && !PaintWheel.IsPaintingUIVisible) - { - PaintWheel.CreatePaintWheel(Main.mouseX, Main.mouseY, this); //Method to create it - PaintWheel.IsPaintingUIVisible = true; - } - else if (!PaintWheel.PaintingUIOpen && PaintWheel.IsPaintingUIVisible) - { - PaintWheel.PaintWheelPanel.Remove(); - PaintWheel.IsPaintingUIVisible = false; - } + if (Tools.UIPanelLogic(PaintWheel.PaintWheelPanel, ref PaintWheel.PaintingUIOpen, ref PaintWheel.IsPaintingUIVisible)) + PaintWheel.CreatePaintWheel(Main.mouseX, Main.mouseY, this); //Wand Wheel UI - if (MultiWandWheel.WandsWheelUIOpen && !MultiWandWheel.IsWandsUIVisible) - { + if (Tools.UIPanelLogic(MultiWandWheel.MultiWandWheelPanel, ref MultiWandWheel.WandsWheelUIOpen, ref MultiWandWheel.IsWandsUIVisible)) MultiWandWheel.CreateMultiWandWheelPanel(Main.mouseX, Main.mouseY, this); - MultiWandWheel.IsWandsUIVisible = true; - } - else if (!MultiWandWheel.WandsWheelUIOpen && MultiWandWheel.IsWandsUIVisible) - { - MultiWandWheel.MultiWandWheelPanel.Remove(); - MultiWandWheel.IsWandsUIVisible = false; - } //AutoHammer Wheel UI - if (AutoHammerWheel.AutoHammerUIOpen && !AutoHammerWheel.IsAutoHammerUIVisible) - { + if (Tools.UIPanelLogic(AutoHammerWheel.AutoHammerWheelPanel, ref AutoHammerWheel.AutoHammerUIOpen, ref AutoHammerWheel.IsAutoHammerUIVisible)) AutoHammerWheel.CreateAutoHammerWheelPanel(Main.mouseX, Main.mouseY, this); - AutoHammerWheel.IsAutoHammerUIVisible = true; - } - else if (!AutoHammerWheel.AutoHammerUIOpen && AutoHammerWheel.IsAutoHammerUIVisible) - { - AutoHammerWheel.AutoHammerWheelPanel.Remove(); - AutoHammerWheel.IsAutoHammerUIVisible = false; - } //Tooltips while hovering CWElements - if (CreativeWheelRework.CreativeWheelReworkPanel != null) + if (CreativeWheel.CreativeWheelPanel != null && CreativeWheel.IsCreativeWheelVisible) { - List hoveredElements = CreativeWheelRework.CreativeWheelElements.FindAll(x => x.IsMouseHovering == true); + List hoveredElements = CreativeWheel.CreativeWheelElements.FindAll(x => x.IsMouseHovering == true); if (hoverText != null) { @@ -143,8 +77,7 @@ public override void Update(GameTime gameTime) } //Don't need the actual list itself, just a reference of it - var elementsList = CreativeWheelRework.CreativeWheelElements; - string text = ""; + var elementsList = CreativeWheel.CreativeWheelElements; foreach (var element in hoveredElements) { if (element == elementsList[0]) @@ -158,20 +91,42 @@ public override void Update(GameTime gameTime) if (element == elementsList[4]) text = "Gives infinite pick up range"; - hoverText = new UIText(text, 1, false); - hoverText.VAlign = 0f; - hoverText.HAlign = 0f; - hoverText.Left.Set(Main.mouseX + 22, 0); - hoverText.Top.Set(Main.mouseY + 22, 0); + hoverText = Tools.CreateUIText(text, Main.mouseX + 22, Main.mouseY + 22); Append(hoverText); } } - } - public void ChangeAccessories_OnClick(UIMouseEvent evt, UIElement listeningElement) - { - if (isBuildingModeButtonVisible) - Tools.BuildingModeToggle(); + //Tooltips while hovering Multi Wand Elements + if (MultiWandWheel.MultiWandWheelPanel != null && MultiWandWheel.IsWandsUIVisible) + { + List hoveredElements = MultiWandWheel.WandWheelElements.FindAll(x => x.IsMouseHovering == true); + + if (hoverText != null) + { + hoverText.Remove(); + hoverText = null; + } + + var elementsList = MultiWandWheel.WandWheelElements; + foreach (var element in hoveredElements) + { + if (element == elementsList[0]) + text = "Places living wood (wood)"; + if (element == elementsList[1]) + text = "Places bones (bone)"; + if (element == elementsList[2]) + text = "Places leaves (wood)"; + if (element == elementsList[3]) + text = "Places Hives (hive)"; + if (element == elementsList[4]) + text = "Places living rich mahogany (rich mahogany)"; + if (element == elementsList[5]) + text = "Places rich mahogany leaves (rich mahogany)"; + + hoverText = Tools.CreateUIText(text, Main.mouseX + 22, Main.mouseY + 22); + Append(hoverText); + } + } } } } diff --git a/UI/CreativeWheelRework.cs b/UI/CreativeWheel.cs similarity index 85% rename from UI/CreativeWheelRework.cs rename to UI/CreativeWheel.cs index 2caa823..52e6763 100644 --- a/UI/CreativeWheelRework.cs +++ b/UI/CreativeWheel.cs @@ -1,24 +1,24 @@ using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Input; using System; using System.Collections.Generic; using Terraria; -using Terraria.UI; using Terraria.GameContent.UI.Elements; -using Terraria.ModLoader; using static BuilderEssentials.BuilderPlayer; namespace BuilderEssentials.UI { - public class CreativeWheelRework + public class CreativeWheel { static BuilderPlayer modPlayer; - public static UIPanel CreativeWheelReworkPanel; + public static UIPanel CreativeWheelPanel; public static float CreativeWheelReworkWidth; public static float CreativeWheelReworkHeight; public static List CreativeWheelElements; private static List CreativeWheelHammerElements; private static readonly int numberOfElements = 5; + public static bool IsCreativeWheelVisible; + public static bool CreativeWheelUIOpen; + public static bool Hovering = CreativeWheelPanel != null && CreativeWheelPanel.IsMouseHovering && IsCreativeWheelVisible; public static UIPanel CreateCreativeWheelReworkPanel(int mouseX, int mouseY, BasePanel basePanel) { @@ -27,20 +27,20 @@ public static UIPanel CreateCreativeWheelReworkPanel(int mouseX, int mouseY, Bas CreativeWheelReworkWidth = 250f; CreativeWheelReworkHeight = 250f; - CreativeWheelReworkPanel = new UIPanel(); - CreativeWheelReworkPanel.VAlign = 0f; - CreativeWheelReworkPanel.HAlign = 0f; - CreativeWheelReworkPanel.Width.Set(CreativeWheelReworkWidth, 0); - CreativeWheelReworkPanel.Height.Set(CreativeWheelReworkHeight, 0); - CreativeWheelReworkPanel.Left.Set(mouseX - CreativeWheelReworkWidth / 2, 0); //mouseX - this.width/2 - CreativeWheelReworkPanel.Top.Set(mouseY - CreativeWheelReworkHeight / 2, 0); //mouseY - this.height/2 - CreativeWheelReworkPanel.BorderColor = Color.Transparent; //Color.Transparent; - CreativeWheelReworkPanel.BackgroundColor = Color.Transparent; + CreativeWheelPanel = new UIPanel(); + CreativeWheelPanel.VAlign = 0f; + CreativeWheelPanel.HAlign = 0f; + CreativeWheelPanel.Width.Set(CreativeWheelReworkWidth, 0); + CreativeWheelPanel.Height.Set(CreativeWheelReworkHeight, 0); + CreativeWheelPanel.Left.Set(mouseX - CreativeWheelReworkWidth / 2, 0); //mouseX - this.width/2 + CreativeWheelPanel.Top.Set(mouseY - CreativeWheelReworkHeight / 2, 0); //mouseY - this.height/2 + CreativeWheelPanel.BorderColor = Color.Transparent; //Color.Transparent; + CreativeWheelPanel.BackgroundColor = Color.Transparent; CreateLayout(); - basePanel.Append(CreativeWheelReworkPanel); + basePanel.Append(CreativeWheelPanel); - return CreativeWheelReworkPanel; + return CreativeWheelPanel; } private static void CreateLayout() { @@ -79,7 +79,7 @@ private static void CreateLayout() //Append them to the Main Panel for (int i = 0; i < CreativeWheelElements.Count; i++) - CreativeWheelReworkPanel.Append(CreativeWheelElements[i]); + CreativeWheelPanel.Append(CreativeWheelElements[i]); } private static void MainElementClick(int index) @@ -148,7 +148,7 @@ private static void CreateHammerLayout(int selectedIndex) CreativeWheelHammerElements[selectedIndex].SetVisibility(1f, 1f); for (int i = 0; i < CreativeWheelHammerElements.Count; i++) - CreativeWheelReworkPanel.Append(CreativeWheelHammerElements[i]); + CreativeWheelPanel.Append(CreativeWheelHammerElements[i]); } private static void RemoveHammerLayout() diff --git a/UI/MultiWandWheel.cs b/UI/MultiWandWheel.cs index a44fe66..13a1ffa 100644 --- a/UI/MultiWandWheel.cs +++ b/UI/MultiWandWheel.cs @@ -1,10 +1,6 @@ using Microsoft.Xna.Framework; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Terraria; using Terraria.GameContent.UI.Elements; namespace BuilderEssentials.UI @@ -14,10 +10,10 @@ class MultiWandWheel : UIPanel public static UIPanel MultiWandWheelPanel; private static float MultiWandWheelWidth; private static float MultiWandWheelHeight; - private static List WandWheelElements; - private static int selectedIndex = 0; - public static bool IsWandsUIVisible { get; set; } - public static bool WandsWheelUIOpen { get; set; } + public static List WandWheelElements; + public static int selectedIndex = 0; + public static bool IsWandsUIVisible; + public static bool WandsWheelUIOpen; public static bool Hovering = MultiWandWheelPanel != null && MultiWandWheelPanel.IsMouseHovering && IsWandsUIVisible; public static UIPanel CreateMultiWandWheelPanel(int mouseX, int mouseY, BasePanel basePanel) diff --git a/UI/PaintWheel.cs b/UI/PaintWheel.cs index 086b529..1105950 100644 --- a/UI/PaintWheel.cs +++ b/UI/PaintWheel.cs @@ -17,8 +17,8 @@ public class PaintWheel private static List paintToolsList; public static int selectedIndex = 30; //No color public static int selectedToolIndex = 0; - public static bool IsPaintingUIVisible { get; set; } - public static bool PaintingUIOpen { get; set; } + public static bool IsPaintingUIVisible; + public static bool PaintingUIOpen; public static bool Hovering = PaintWheelPanel != null && PaintWheelPanel.IsMouseHovering && IsPaintingUIVisible; public static UIPanel CreatePaintWheel(int mouseX, int mouseY, BasePanel basePanel) { diff --git a/Utilities/BuildingMode.cs b/Utilities/BuildingMode.cs index d7b48a0..286b8b4 100644 --- a/Utilities/BuildingMode.cs +++ b/Utilities/BuildingMode.cs @@ -1,12 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BuilderEssentials.UI; +using BuilderEssentials.UI; using Terraria; -using Terraria.ID; -using Terraria.ModLoader; namespace BuilderEssentials.Utilities { diff --git a/Utilities/InfinitePlacement.cs b/Utilities/InfinitePlacement.cs index 02faa8f..a910155 100644 --- a/Utilities/InfinitePlacement.cs +++ b/Utilities/InfinitePlacement.cs @@ -1,5 +1,4 @@ -using BuilderEssentials.Items.Accessories; -using System.Collections.Generic; +using System.Collections.Generic; using Terraria; using Terraria.ID; using Terraria.ModLoader; diff --git a/Utilities/ItemPicker.cs b/Utilities/ItemPicker.cs index 8c8bf75..fef58dd 100644 --- a/Utilities/ItemPicker.cs +++ b/Utilities/ItemPicker.cs @@ -56,7 +56,7 @@ public static void PickItem(ref int oldPosX, ref int oldPosY) if (player.inventory[i].IsTheSameAs(item)) { //Finds item in inventory and switch with selected item - Item selectedItem = player.inventory[player.selectedItem]; + Item selectedItem = player.HeldItem; player.inventory[player.selectedItem] = player.inventory[i]; player.inventory[i] = selectedItem; isItemInInventory = true; @@ -71,7 +71,7 @@ public static void PickItem(ref int oldPosX, ref int oldPosY) if (player.inventory[i].IsAir) { //Find first air space in inventory and switches selected item to there - Item selectedItem = player.inventory[player.selectedItem]; + Item selectedItem = player.HeldItem; player.inventory[i] = selectedItem; player.inventory[player.selectedItem] = item; diff --git a/Utilities/MiscUtilities.cs b/Utilities/MiscUtilities.cs index 5f8d8c9..e84740b 100644 --- a/Utilities/MiscUtilities.cs +++ b/Utilities/MiscUtilities.cs @@ -3,8 +3,8 @@ using BuilderEssentials.UI; using Microsoft.Xna.Framework; using System; -using System.Threading; using Terraria; +using Terraria.GameContent.UI.Elements; using Terraria.ID; using Terraria.ModLoader; @@ -292,6 +292,40 @@ public static bool ToolHasRange(int range) return inRange; } + + public static bool UIPanelLogic(UIPanel UIPanel, ref bool UIOpen, ref bool UIVisible) + { + if (UIPanel != null && Main.playerInventory) + { + UIPanel.Remove(); + UIOpen = false; + UIVisible = false; + return false; + } + + if (UIOpen && !UIVisible) + { + UIVisible = true; + return true; + } + else if (!UIOpen && UIVisible) + { + UIPanel.Remove(); + UIVisible = false; + } + return false; + } + + public static UIText CreateUIText(string text, int left, int top) + { + UIText hoverText = new UIText(text, 1, false); + hoverText.VAlign = 0f; + hoverText.HAlign = 0f; + hoverText.Left.Set(left, 0); + hoverText.Top.Set(top, 0); + + return hoverText; + } } //class MirrorWandGlobalTile : GlobalTile diff --git a/build.txt b/build.txt index 428c0d9..c083e8a 100644 --- a/build.txt +++ b/build.txt @@ -1,5 +1,5 @@ displayName = Builder Essentials author = Kirtle -version = 0.1.14 +version = 0.1.14.1 buildIgnore = *.csproj, *.user, obj\*, bin\*, .vs\* homepage = https://discord.gg/wQYMbQq \ No newline at end of file diff --git a/description.txt b/description.txt index 95ee4bb..f35cd18 100644 --- a/description.txt +++ b/description.txt @@ -20,11 +20,10 @@ For more info/previews check the mod's Homepage! Happy Building! Latest Changelog: - - Added options to Building Mode in the Mod Config - - Fixed mod compatibility issues and a Placement Anywhere bug - Fixed Zoom/UI Scale related bugs - - Added a Mutli Wand (contains all six default wands) - Fixed a bug preventing the user to join a Multiplayer Server + - Added a Mutli Wand (contains all six default wands) + - Added the AutoHammer as its own item If you find any bug/weird behaviour please report it in our mod's homepage. Thank you!