Skip to content

Commit

Permalink
Introduced a static check if UI can be opened
Browse files Browse the repository at this point in the history
Kinda meh right now, needs refinement
  • Loading branch information
Kirtle committed Jun 22, 2020
1 parent 6f1855c commit 064cf47
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
3 changes: 1 addition & 2 deletions Items/Accessories/CreativeWrench.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
9 changes: 4 additions & 5 deletions Items/SuperPaintingTool.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using BuilderEssentials.UI;
using BuilderEssentials.Utilities;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
Expand All @@ -10,7 +11,6 @@ namespace BuilderEssentials.Items
class SuperPaintingTool : ModItem
{
//TODO: ENSURE MULTIPLAYER COMPATIBILITY (66% done)
//TODO: ADD VANILLA PAINT COMPATIBILITY
public List<int> paints;
bool foundModdedPaint;
public override void SetDefaults()
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -100,7 +100,6 @@ public override void HoldItem(Player player)
}

player.showItemIcon = false;
//player.showItemIcon2 = 0;
}
}

Expand Down
28 changes: 28 additions & 0 deletions Utilities/UIUtilities.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}

0 comments on commit 064cf47

Please sign in to comment.