From 064cf47c10af309f4ff45be8fa5765e43a23eb41 Mon Sep 17 00:00:00 2001 From: Kirtle Date: Mon, 22 Jun 2020 05:34:58 +0100 Subject: [PATCH] Introduced a static check if UI can be opened Kinda meh right now, needs refinement --- Items/Accessories/CreativeWrench.cs | 3 +-- Items/SuperPaintingTool.cs | 9 ++++----- Utilities/UIUtilities.cs | 28 ++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 Utilities/UIUtilities.cs diff --git a/Items/Accessories/CreativeWrench.cs b/Items/Accessories/CreativeWrench.cs index bd16c83..15754d1 100644 --- a/Items/Accessories/CreativeWrench.cs +++ b/Items/Accessories/CreativeWrench.cs @@ -49,8 +49,7 @@ public override void UpdateAccessory(Player player, bool hideVisual) //TODO: Make a static bool in Utilities that evaluates if it is possible to open a UI to improve readability //Thanks direwolf420 for the monstrosity checks //Right click timer - if (Main.mouseRight && player.talkNPC == -1 && !Main.HoveringOverAnNPC && !player.showItemIcon && !Main.editSign - && !Main.editChest && !Main.blockInput && !player.dead && !Main.gamePaused && Main.hasFocus && !player.CCed + if (Main.mouseRight && UIUtilities.IsUIAvailable() && (!player.mouseInterface || (BasePanel.creativeWheelUIOpen && CreativeWheelRework.CreativeWheelReworkPanel.IsMouseHovering)) && !BasePanel.paintingUIOpen && player.inventory[player.selectedItem].IsAir && !Main.playerInventory) { diff --git a/Items/SuperPaintingTool.cs b/Items/SuperPaintingTool.cs index 2cc3de4..276282a 100644 --- a/Items/SuperPaintingTool.cs +++ b/Items/SuperPaintingTool.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using BuilderEssentials.UI; +using BuilderEssentials.Utilities; using Terraria; using Terraria.ID; using Terraria.ModLoader; @@ -10,7 +11,6 @@ namespace BuilderEssentials.Items class SuperPaintingTool : ModItem { //TODO: ENSURE MULTIPLAYER COMPATIBILITY (66% done) - //TODO: ADD VANILLA PAINT COMPATIBILITY public List paints; bool foundModdedPaint; public override void SetDefaults() @@ -50,10 +50,10 @@ public override void UpdateInventory(Player player) BasePanel.paintingUIOpen = false; } - if (Main.mouseRight && player.talkNPC == -1 && !Main.HoveringOverAnNPC && !player.showItemIcon && !Main.editSign - && !Main.editChest && !Main.blockInput && !player.dead && !Main.gamePaused && Main.hasFocus && !player.CCed + if (Main.mouseRight && UIUtilities.IsUIAvailable() && (!player.mouseInterface || (BasePanel.paintingUIOpen && BasePanel.paintingPanel.IsMouseHovering)) - && player.inventory[player.selectedItem].IsTheSameAs(item) && !BasePanel.creativeWheelUIOpen) + && player.inventory[player.selectedItem].IsTheSameAs(item) + && !BasePanel.creativeWheelUIOpen) { if (++mouseRightTimer == 2) BasePanel.paintingUIOpen = !BasePanel.paintingUIOpen; @@ -100,7 +100,6 @@ public override void HoldItem(Player player) } player.showItemIcon = false; - //player.showItemIcon2 = 0; } } diff --git a/Utilities/UIUtilities.cs b/Utilities/UIUtilities.cs new file mode 100644 index 0000000..be4650f --- /dev/null +++ b/Utilities/UIUtilities.cs @@ -0,0 +1,28 @@ +using Terraria; + +namespace BuilderEssentials.Utilities +{ + public class UIUtilities + { + public static bool IsUIAvailable() + { + //Add specific UI mouse hoverings etc.. + var player = Main.LocalPlayer; + return Main.hasFocus && + !Main.playerInventory && + !Main.drawingPlayerChat && + !Main.editSign && + !Main.editChest && + !Main.blockInput && + !Main.gamePaused && + !player.mouseInterface && + !Main.mapFullscreen && + !Main.HoveringOverAnNPC && + !player.showItemIcon && + player.talkNPC == -1 && + (player.itemTime == 0 && player.itemAnimation == 0) && + !player.dead && + !player.CCed; + } + } +} \ No newline at end of file