aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java2
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java366
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionProfit.java16
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DungeonNpcProfitOverlay.java15
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/AccessoryBagOverlay.java72
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/TrophyRewardOverlay.java17
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlay.java16
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/overlays/EquipmentOverlay.java25
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/events/ButtonExclusionZoneEvent.kt69
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/util/Rectangle.kt68
-rw-r--r--src/test/kotlin/io/github/moulberry/notenoughupdates/util/RectangleTest.kt49
11 files changed, 414 insertions, 301 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java
index 6160ac8d..049955de 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java
@@ -75,6 +75,7 @@ import io.github.moulberry.notenoughupdates.miscfeatures.updater.AutoUpdater;
import io.github.moulberry.notenoughupdates.miscfeatures.world.EnderNodeHighlighter;
import io.github.moulberry.notenoughupdates.miscfeatures.world.FrozenTreasuresHighlighter;
import io.github.moulberry.notenoughupdates.miscfeatures.world.GlowingMushroomHighlighter;
+import io.github.moulberry.notenoughupdates.miscgui.AccessoryBagOverlay;
import io.github.moulberry.notenoughupdates.miscgui.CalendarOverlay;
import io.github.moulberry.notenoughupdates.miscgui.InventoryStorageSelector;
import io.github.moulberry.notenoughupdates.miscgui.SignCalculator;
@@ -357,6 +358,7 @@ public class NotEnoughUpdates {
MinecraftForge.EVENT_BUS.register(MuseumItemHighlighter.INSTANCE);
MinecraftForge.EVENT_BUS.register(MuseumCheapestItemOverlay.INSTANCE);
MinecraftForge.EVENT_BUS.register(new WardrobeMouseButtons());
+ MinecraftForge.EVENT_BUS.register(AccessoryBagOverlay.INSTANCE);
if (Minecraft.getMinecraft().getResourceManager() instanceof IReloadableResourceManager) {
IReloadableResourceManager manager = (IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager();
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java
index f15a26a7..a35c9a6c 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java
@@ -29,6 +29,7 @@ import io.github.moulberry.notenoughupdates.auction.CustomAHGui;
import io.github.moulberry.notenoughupdates.commands.profile.ViewProfileCommand;
import io.github.moulberry.notenoughupdates.core.GuiScreenElementWrapper;
import io.github.moulberry.notenoughupdates.dungeons.DungeonWin;
+import io.github.moulberry.notenoughupdates.events.ButtonExclusionZoneEvent;
import io.github.moulberry.notenoughupdates.miscfeatures.AbiphoneWarning;
import io.github.moulberry.notenoughupdates.miscfeatures.AuctionBINWarning;
import io.github.moulberry.notenoughupdates.miscfeatures.AuctionProfit;
@@ -59,6 +60,7 @@ import io.github.moulberry.notenoughupdates.overlays.TextOverlay;
import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer;
import io.github.moulberry.notenoughupdates.util.ItemUtils;
import io.github.moulberry.notenoughupdates.util.NotificationHandler;
+import io.github.moulberry.notenoughupdates.util.Rectangle;
import io.github.moulberry.notenoughupdates.util.SBInfo;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.client.Minecraft;
@@ -105,6 +107,7 @@ import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
+import java.util.function.BiConsumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -484,96 +487,70 @@ public class RenderListener {
if (CalendarOverlay.isEnabled() || event.isCanceled()) return;
if (NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard() && NotificationHandler.shouldRenderOverlay(event.gui) &&
event.gui instanceof GuiContainer) {
- doInventoryButtons = true;
-
- int zOffset = 50;
-
- GlStateManager.translate(0, 0, zOffset);
-
- int xSize = ((AccessorGuiContainer) event.gui).getXSize();
- int ySize = ((AccessorGuiContainer) event.gui).getYSize();
- int guiLeft = ((AccessorGuiContainer) event.gui).getGuiLeft();
- int guiTop = ((AccessorGuiContainer) event.gui).getGuiTop();
+ renderButtons((GuiContainer) event.gui);
+ }
+ }
- if (!NEUApi.disableInventoryButtons) {
- if (!EnchantingSolvers.disableButtons()) {
- for (NEUConfig.InventoryButton button : NotEnoughUpdates.INSTANCE.config.hidden.inventoryButtons) {
- if (!button.isActive()) continue;
- if (button.playerInvOnly && !(event.gui instanceof GuiInventory)) continue;
+ public void iterateButtons(GuiContainer gui, BiConsumer<NEUConfig.InventoryButton, Rectangle> acceptButton) {
+ if (NEUApi.disableInventoryButtons || EnchantingSolvers.disableButtons()) {
+ return;
+ }
- int x = guiLeft + button.x;
- int y = guiTop + button.y;
- if (button.anchorRight) {
- x += xSize;
- }
- if (button.anchorBottom) {
- y += ySize;
- }
- if (AccessoryBagOverlay.isInAccessoryBag()) {
- if (x > guiLeft + xSize && x < guiLeft + xSize + 80 + 28 + 5 && y > guiTop - 18 && y < guiTop + 150) {
- x += 80 + 28;
- }
- }
- if (TrophyRewardOverlay.inTrophyFishingInventory()) {
- int diffX = 162;
- if (x > guiLeft + xSize && x < guiLeft + xSize + diffX + 5 && y > guiTop - 18 && y < guiTop + 120) {
- x += diffX;
- }
- }
- if (MinionHelperManager.getInstance().inCraftedMinionsInventory()) {
- int diffX = 172;
- if (x > guiLeft + xSize && x < guiLeft + xSize + diffX + 5 && y > guiTop - 18 && y < guiTop + 128) {
- x += diffX;
- }
- }
- if (AuctionProfit.inAuctionPage()) {
- if (x + 18 > guiLeft + xSize && x + 18 < guiLeft + xSize + 4 + 28 + 20 && y > guiTop - 180 &&
- y < guiTop + 56) {
- x -= 68 - 200;
- }
- }
- if (EquipmentOverlay.isRenderingArmorHud()) {
- if (x < guiLeft + xSize - 150 && x > guiLeft + xSize - 200 && y > guiTop && y < guiTop + 84) {
- x -= 25;
- }
- }
- if (EquipmentOverlay.isRenderingPetHud()) {
- if (x < guiLeft + xSize - 150 && x > guiLeft + xSize - 200 && y > guiTop + 60 && y < guiTop + 120) {
- x -= 25;
- }
- }
- if (inDungeonPage || DungeonNpcProfitOverlay.isRendering()) {
- if (x + 10 > guiLeft + xSize && x + 18 < guiLeft + xSize + 4 + 28 + 20 && y > guiTop - 180 &&
- y < guiTop + 100) {
- x += 185;
- }
- }
+ AccessorGuiContainer accessor = (AccessorGuiContainer) gui;
+ Rectangle guiRectangle = new Rectangle(
+ accessor.getGuiLeft(),
+ accessor.getGuiTop(),
+ accessor.getXSize(),
+ accessor.getYSize()
+ );
+
+ ButtonExclusionZoneEvent buttonExclusionZoneEvent = new ButtonExclusionZoneEvent(gui, guiRectangle);
+ buttonExclusionZoneEvent.post();
+ for (NEUConfig.InventoryButton button : NotEnoughUpdates.INSTANCE.config.hidden.inventoryButtons) {
+ if (!button.isActive()) continue;
+ if (button.playerInvOnly && !(gui instanceof GuiInventory)) continue;
+
+ Rectangle buttonPosition = buttonExclusionZoneEvent.findButtonPosition(new Rectangle(
+ accessor.getGuiLeft() + button.x + (button.anchorRight ? accessor.getXSize() : 0),
+ accessor.getGuiTop() + button.y + (button.anchorBottom ? accessor.getYSize() : 0),
+ 18, 18
+ )
+ );
+ acceptButton.accept(button, buttonPosition);
+ }
+ }
- GlStateManager.color(1, 1, 1, 1f);
-
- GlStateManager.enableDepth();
- GlStateManager.enableAlpha();
- Minecraft.getMinecraft().getTextureManager().bindTexture(EDITOR);
- Utils.drawTexturedRect(
- x,
- y,
- 18,
- 18,
- button.backgroundIndex * 18 / 256f,
- (button.backgroundIndex * 18 + 18) / 256f,
- 18 / 256f,
- 36 / 256f,
- GL11.GL_NEAREST
- );
+ public void renderButtons(GuiContainer gui) {
+ doInventoryButtons = true;
- if (button.icon != null && !button.icon.trim().isEmpty()) {
- GuiInvButtonEditor.renderIcon(button.icon, x + 1, y + 1);
- }
- }
- }
+ int zOffset = 50;
+ GlStateManager.pushMatrix();
+ GlStateManager.pushAttrib();
+ GlStateManager.translate(0, 0, zOffset);
+ iterateButtons(gui, (button, buttonPosition) -> {
+ GlStateManager.color(1, 1, 1, 1f);
+ GlStateManager.enableDepth();
+ GlStateManager.enableAlpha();
+
+ Minecraft.getMinecraft().getTextureManager().bindTexture(EDITOR);
+ Utils.drawTexturedRect(
+ buttonPosition.getX(),
+ buttonPosition.getY(),
+ 18,
+ 18,
+ button.backgroundIndex * 18 / 256f,
+ (button.backgroundIndex * 18 + 18) / 256f,
+ 18 / 256f,
+ 36 / 256f,
+ GL11.GL_NEAREST
+ );
+
+ if (button.icon != null && !button.icon.trim().isEmpty()) {
+ GuiInvButtonEditor.renderIcon(button.icon, buttonPosition.getX() + 1, buttonPosition.getY() + 1);
}
- GlStateManager.translate(0, 0, -zOffset);
- }
+ });
+ GlStateManager.popMatrix();
+ GlStateManager.popAttrib();
}
/**
@@ -620,105 +597,51 @@ public class RenderListener {
}
}
- boolean hoveringButton = false;
+ final boolean[] hoveringButton = {false};
if (!doInventoryButtons) return;
if (NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard() && NotificationHandler.shouldRenderOverlay(event.gui) &&
event.gui instanceof GuiContainer) {
- int xSize = ((AccessorGuiContainer) event.gui).getXSize();
- int ySize = ((AccessorGuiContainer) event.gui).getYSize();
- int guiLeft = ((AccessorGuiContainer) event.gui).getGuiLeft();
- int guiTop = ((AccessorGuiContainer) event.gui).getGuiTop();
-
- if (!NEUApi.disableInventoryButtons) {
- if (!EnchantingSolvers.disableButtons()) {
- for (NEUConfig.InventoryButton button : NotEnoughUpdates.INSTANCE.config.hidden.inventoryButtons) {
- if (!button.isActive()) continue;
- if (button.playerInvOnly && !(event.gui instanceof GuiInventory)) continue;
-
- int x = guiLeft + button.x;
- int y = guiTop + button.y;
- if (button.anchorRight) {
- x += xSize;
- }
- if (button.anchorBottom) {
- y += ySize;
- }
- if (AccessoryBagOverlay.isInAccessoryBag()) {
- if (x > guiLeft + xSize && x < guiLeft + xSize + 80 + 28 + 5 && y > guiTop - 18 && y < guiTop + 150) {
- x += 80 + 28;
- }
- }
- if (TrophyRewardOverlay.inTrophyFishingInventory()) {
- int diffX = 162;
- if (x > guiLeft + xSize && x < guiLeft + xSize + diffX + 5 && y > guiTop - 18 && y < guiTop + 120) {
- x += diffX;
- }
- }
- if (MinionHelperManager.getInstance().inCraftedMinionsInventory()) {
- int diffX = 172;
- if (x > guiLeft + xSize && x < guiLeft + xSize + diffX + 5 && y > guiTop - 18 && y < guiTop + 128) {
- x += diffX;
- }
- }
- if (AuctionProfit.inAuctionPage()) {
- if (x + 18 > guiLeft + xSize && x + 18 < guiLeft + xSize + 4 + 28 + 20 && y > guiTop - 180 &&
- y < guiTop + 56) {
- x -= 68 - 200;
- }
- }
- if (EquipmentOverlay.isRenderingArmorHud()) {
- if (x < guiLeft + xSize - 150 && x > guiLeft + xSize - 200 && y > guiTop && y < guiTop + 84) {
- x -= 25;
- }
- }
- if (EquipmentOverlay.isRenderingPetHud()) {
- if (x < guiLeft + xSize - 150 && x > guiLeft + xSize - 200 && y > guiTop + 60 && y < guiTop + 120) {
- x -= 25;
- }
- }
-
- if (inDungeonPage || DungeonNpcProfitOverlay.isRendering()) {
- if (x + 10 > guiLeft + xSize && x + 18 < guiLeft + xSize + 4 + 28 + 20 && y > guiTop - 180 &&
- y < guiTop + 100) {
- x += 185;
- }
- }
-
- if (x - guiLeft >= 85 && x - guiLeft <= 115 && y - guiTop >= 4 && y - guiTop <= 25) {
- disableCraftingText = true;
- }
+ AccessorGuiContainer acc = (AccessorGuiContainer) event.gui;
+ Rectangle mousePosition = new Rectangle(event.mouseX, event.mouseY, 0, 0);
+ Rectangle craftingTextRectangle = new Rectangle(acc.getGuiLeft() + 85, acc.getGuiTop() + 4, 30, 21);
+ iterateButtons((GuiContainer) guiScreen, (button, buttonPosition) -> {
- if (event.mouseX >= x && event.mouseX <= x + 18 && event.mouseY >= y && event.mouseY <= y + 18) {
- hoveringButton = true;
- long currentTime = System.currentTimeMillis();
+ if (buttonPosition.intersects(craftingTextRectangle)) {
+ disableCraftingText = true;
+ }
- if (buttonHovered != button) {
- buttonHoveredMillis = currentTime;
- buttonHovered = button;
- }
+ if (!buttonPosition.intersects(mousePosition)) {
+ return;
+ }
+ hoveringButton[0] = true;
+ long currentTime = System.currentTimeMillis();
- if (currentTime - buttonHoveredMillis > NotEnoughUpdates.INSTANCE.config.inventoryButtons.tooltipDelay) {
- String command = button.command.trim();
- if (!command.startsWith("/")) {
- command = "/" + command;
- }
+ if (buttonHovered != button) {
+ buttonHoveredMillis = currentTime;
+ buttonHovered = button;
+ }
- Utils.drawHoveringText(
- Lists.newArrayList("\u00a77" + command),
- event.mouseX,
- event.mouseY,
- event.gui.width,
- event.gui.height,
- -1,
- Minecraft.getMinecraft().fontRendererObj
- );
- }
- }
- }
+ if (currentTime - buttonHoveredMillis <= NotEnoughUpdates.INSTANCE.config.inventoryButtons.tooltipDelay) {
+ return;
}
- }
+ String command = button.command.trim();
+ if (!command.startsWith("/")) {
+ command = "/" + command;
+ }
+
+ Utils.drawHoveringText(
+ Lists.newArrayList("\u00a77" + command),
+ event.mouseX,
+ event.mouseY,
+ event.gui.width,
+ event.gui.height,
+ -1,
+ Minecraft.getMinecraft().fontRendererObj
+ );
+
+ });
}
- if (!hoveringButton) buttonHovered = null;
+ if (!hoveringButton[0]) buttonHovered = null;
if (AuctionBINWarning.getInstance().shouldShow()) {
AuctionBINWarning.getInstance().render();
@@ -1107,85 +1030,28 @@ public class RenderListener {
if (!doInventoryButtons) return;
if (NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard() && NotificationHandler.shouldRenderOverlay(event.gui) &&
Mouse.getEventButton() >= 0 && event.gui instanceof GuiContainer) {
- int xSize = ((AccessorGuiContainer) event.gui).getXSize();
- int ySize = ((AccessorGuiContainer) event.gui).getYSize();
- int guiLeft = ((AccessorGuiContainer) event.gui).getGuiLeft();
- int guiTop = ((AccessorGuiContainer) event.gui).getGuiTop();
- if (!NEUApi.disableInventoryButtons) {
- if (!EnchantingSolvers.disableButtons()) {
- for (NEUConfig.InventoryButton button : NotEnoughUpdates.INSTANCE.config.hidden.inventoryButtons) {
- if (!button.isActive()) continue;
- if (button.playerInvOnly && !(event.gui instanceof GuiInventory)) continue;
-
- int x = guiLeft + button.x;
- int y = guiTop + button.y;
- if (button.anchorRight) {
- x += xSize;
- }
- if (button.anchorBottom) {
- y += ySize;
- }
- if (AccessoryBagOverlay.isInAccessoryBag()) {
- if (x > guiLeft + xSize && x < guiLeft + xSize + 80 + 28 + 5 && y > guiTop - 18 && y < guiTop + 150) {
- x += 80 + 28;
- }
- }
- if (TrophyRewardOverlay.inTrophyFishingInventory()) {
- int diffX = 162;
- if (x > guiLeft + xSize && x < guiLeft + xSize + diffX + 5 && y > guiTop - 18 && y < guiTop + 120) {
- x += diffX;
- }
- }
- if (MinionHelperManager.getInstance().inCraftedMinionsInventory()) {
- int diffX = 172;
- if (x > guiLeft + xSize && x < guiLeft + xSize + diffX + 5 && y > guiTop - 18 && y < guiTop + 128) {
- x += diffX;
- }
- }
- if (AuctionProfit.inAuctionPage()) {
- if (x + 18 > guiLeft + xSize && x + 18 < guiLeft + xSize + 4 + 28 + 20 && y > guiTop - 180 &&
- y < guiTop + 56) {
- x -= 68 - 200;
- }
- }
- if (EquipmentOverlay.isRenderingArmorHud()) {
- if (x < guiLeft + xSize - 150 && x > guiLeft + xSize - 200 && y > guiTop && y < guiTop + 84) {
- x -= 25;
- }
+ Rectangle mouseRect = new Rectangle(mouseX, mouseY, 0, 0);
+ iterateButtons((GuiContainer) event.gui, (button, buttonPositon) -> {
+ if (!buttonPositon.intersects(mouseRect)) {
+ return;
+ }
+ if (Minecraft.getMinecraft().thePlayer.inventory.getItemStack() == null) {
+ int clickType = NotEnoughUpdates.INSTANCE.config.inventoryButtons.clickType;
+ if ((clickType == 0 && Mouse.getEventButtonState()) ||
+ (clickType == 1 && !Mouse.getEventButtonState())) {
+ String command = button.command.trim();
+ if (!command.startsWith("/")) {
+ command = "/" + command;
}
- if (EquipmentOverlay.isRenderingPetHud()) {
- if (x < guiLeft + xSize - 150 && x > guiLeft + xSize - 200 && y > guiTop + 60 && y < guiTop + 120) {
- x -= 25;
- }
- }
- if (inDungeonPage || DungeonNpcProfitOverlay.isRendering()) {
- if (x + 10 > guiLeft + xSize && x + 18 < guiLeft + xSize + 4 + 28 + 20 && y > guiTop - 180 &&
- y < guiTop + 100) {
- x += 185;
- }
- }
-
- if (mouseX >= x && mouseX <= x + 18 && mouseY >= y && mouseY <= y + 18) {
- if (Minecraft.getMinecraft().thePlayer.inventory.getItemStack() == null) {
- int clickType = NotEnoughUpdates.INSTANCE.config.inventoryButtons.clickType;
- if ((clickType == 0 && Mouse.getEventButtonState()) ||
- (clickType == 1 && !Mouse.getEventButtonState())) {
- String command = button.command.trim();
- if (!command.startsWith("/")) {
- command = "/" + command;
- }
- if (ClientCommandHandler.instance.executeCommand(Minecraft.getMinecraft().thePlayer, command) == 0) {
- NotEnoughUpdates.INSTANCE.sendChatMessage(command);
- }
- }
- } else {
- event.setCanceled(true);
- }
- return;
+ if (ClientCommandHandler.instance.executeCommand(Minecraft.getMinecraft().thePlayer, command) == 0) {
+ NotEnoughUpdates.INSTANCE.sendChatMessage(command);
}
}
+ } else {
+ event.setCanceled(true);
}
- }
+
+ });
}
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionProfit.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionProfit.java
index 82c392e4..894d48f8 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionProfit.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionProfit.java
@@ -21,7 +21,9 @@ package io.github.moulberry.notenoughupdates.miscfeatures;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.core.util.StringUtils;
+import io.github.moulberry.notenoughupdates.events.ButtonExclusionZoneEvent;
import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer;
+import io.github.moulberry.notenoughupdates.util.Rectangle;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
@@ -45,6 +47,20 @@ public class AuctionProfit {
new ResourceLocation("notenoughupdates:auction_profit.png");
@SubscribeEvent
+ public void onButtonExclusionZones(ButtonExclusionZoneEvent event) {
+ if (inAuctionPage()) {
+ event.blockArea(
+ new Rectangle(
+ event.getGuiBaseRect().getRight(),
+ event.getGuiBaseRect().getTop(),
+ 128 /*width*/ + 4 /*space*/, 56
+ ),
+ ButtonExclusionZoneEvent.PushDirection.TOWARDS_RIGHT
+ );
+ }
+ }
+
+ @SubscribeEvent
public void onDrawBackground(GuiScreenEvent.BackgroundDrawnEvent event) {
if (!inAuctionPage()) return;
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DungeonNpcProfitOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DungeonNpcProfitOverlay.java
index 34a40c2f..f32f89af 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DungeonNpcProfitOverlay.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DungeonNpcProfitOverlay.java
@@ -23,8 +23,10 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.core.util.StringUtils;
+import io.github.moulberry.notenoughupdates.events.ButtonExclusionZoneEvent;
import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer;
import io.github.moulberry.notenoughupdates.util.ItemUtils;
+import io.github.moulberry.notenoughupdates.util.Rectangle;
import io.github.moulberry.notenoughupdates.util.SBInfo;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.client.Minecraft;
@@ -98,6 +100,19 @@ public class DungeonNpcProfitOverlay {
}
@SubscribeEvent
+ public void onButtonExclusionZones(ButtonExclusionZoneEvent event) {
+ if (isRendering())
+ event.blockArea(
+ new Rectangle(
+ event.getGuiBaseRect().getRight(),
+ event.getGuiBaseRect().getTop(),
+ 180 /*width*/ + 4 /*space*/, 101
+ ),
+ ButtonExclusionZoneEvent.PushDirection.TOWARDS_RIGHT
+ );
+ }
+
+ @SubscribeEvent
public void onDrawBackground(GuiScreenEvent.BackgroundDrawnEvent event) {
if (!NotEnoughUpdates.INSTANCE.config.dungeons.croesusProfitOverlay || !(event.gui instanceof GuiChest)) {
chestProfits = null;
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/AccessoryBagOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/AccessoryBagOverlay.java
index 530dcfd1..02f81f8f 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/AccessoryBagOverlay.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/AccessoryBagOverlay.java
@@ -25,9 +25,11 @@ import com.google.gson.JsonObject;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.auction.APIManager;
import io.github.moulberry.notenoughupdates.core.util.StringUtils;
+import io.github.moulberry.notenoughupdates.events.ButtonExclusionZoneEvent;
import io.github.moulberry.notenoughupdates.listener.RenderListener;
import io.github.moulberry.notenoughupdates.profileviewer.PlayerStats;
import io.github.moulberry.notenoughupdates.util.Constants;
+import io.github.moulberry.notenoughupdates.util.Rectangle;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
@@ -45,6 +47,7 @@ import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.EnumChatFormatting;
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL14;
@@ -73,6 +76,22 @@ public class AccessoryBagOverlay {
private static final int TAB_MISSING = 4;
private static final int TAB_OPTIMIZER = 5;
+ public static final AccessoryBagOverlay INSTANCE = new AccessoryBagOverlay();
+
+ @SubscribeEvent
+ public void onButtonExclusionZones(ButtonExclusionZoneEvent event) {
+ if (isInAccessoryBag()) {
+ event.blockArea(
+ new Rectangle(
+ event.getGuiBaseRect().getRight(),
+ event.getGuiBaseRect().getTop(),
+ 80 /*pane*/ + 24 /*tabs*/ + 4 /*space*/, 150
+ ),
+ ButtonExclusionZoneEvent.PushDirection.TOWARDS_RIGHT
+ );
+ }
+ }
+
private static final ItemStack[] TAB_STACKS = new ItemStack[]{
Utils.createItemStack(Items.dye, EnumChatFormatting.DARK_AQUA + "Basic Information",
10, EnumChatFormatting.GREEN + "- Talis count by rarity"
@@ -576,15 +595,9 @@ public class AccessoryBagOverlay {
int yIndex = 0;
long currentTime = System.currentTimeMillis();
- int marqueeOffset = (int) (currentTime / 500 % 100);
for (ItemStack missingStack : missing) {
String s = missingStack.getDisplayName();
- //int marueeOffset
- //if(s.length()) {
-
- //}
-
s = Minecraft.getMinecraft().fontRendererObj.trimStringToWidth(s, 70);
String clean = StringUtils.cleanColourNotModifiers(s);
@@ -1018,51 +1031,8 @@ public class AccessoryBagOverlay {
}
}
- /*private static void renderAlignedString(String first, String second, float x, float y, int length) {
- FontRenderer fontRendererObj = Minecraft.getMinecraft().fontRendererObj;
-
- if(fontRendererObj.getStringWidth(first + " " + second) >= length) {
- for(int xOff=-2; xOff<=2; xOff++) {
- for(int yOff=-2; yOff<=2; yOff++) {
- if(Math.abs(xOff) != Math.abs(yOff)) {
- Utils.drawStringCenteredScaledMaxWidth(Utils.cleanColourNotModifiers(first + " " + second), Minecraft.getMinecraft().fontRendererObj,
- x+length/2f+xOff/2f, y+4+yOff/2f, false, length,
- new Color(0, 0, 0, 200/Math.max(Math.abs(xOff), Math.abs(yOff))).getRGB());
- }
- }
- }
-
- GlStateManager.color(1, 1, 1, 1);
- Utils.drawStringCenteredScaledMaxWidth(first + " " + second, Minecraft.getMinecraft().fontRendererObj,
- x+length/2f, y+4, false, length, 4210752);
- } else {
- for(int xOff=-2; xOff<=2; xOff++) {
- for(int yOff=-2; yOff<=2; yOff++) {
- if(Math.abs(xOff) != Math.abs(yOff)) {
- fontRendererObj.drawString(Utils.cleanColourNotModifiers(first),
- x+xOff/2f, y+yOff/2f,
- new Color(0, 0, 0, 200/Math.max(Math.abs(xOff), Math.abs(yOff))).getRGB(), false);
- }
- }
- }
-
- int secondLen = fontRendererObj.getStringWidth(second);
- GlStateManager.color(1, 1, 1, 1);
- fontRendererObj.drawString(first, x, y, 4210752, false);
- for(int xOff=-2; xOff<=2; xOff++) {
- for(int yOff=-2; yOff<=2; yOff++) {
- if(Math.abs(xOff) != Math.abs(yOff)) {
- fontRendererObj.drawString(Utils.cleanColourNotModifiers(second),
- x+length-secondLen+xOff/2f, y+yOff/2f,
- new Color(0, 0, 0, 200/Math.max(Math.abs(xOff), Math.abs(yOff))).getRGB(), false);
- }
- }
- }
-
- GlStateManager.color(1, 1, 1, 1);
- fontRendererObj.drawString(second, x+length-secondLen, y, 4210752, false);
- }
- }*/
+
+
private static final HashMap<String, Pattern> STAT_PATTERN_MAP_BONUS = new HashMap<String, Pattern>() {{
String STAT_PATTERN_BONUS_END = ": (?:\\+|-)[0-9]+(?:\\.[0-9]+)?\\%? \\(((?:\\+|-)[0-9]+)%?";
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TrophyRewardOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TrophyRewardOverlay.java
index 828e50b1..a14f0101 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TrophyRewardOverlay.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TrophyRewardOverlay.java
@@ -22,9 +22,11 @@ package io.github.moulberry.notenoughupdates.miscgui;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
+import io.github.moulberry.notenoughupdates.events.ButtonExclusionZoneEvent;
import io.github.moulberry.notenoughupdates.events.RepositoryReloadEvent;
import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer;
import io.github.moulberry.notenoughupdates.util.Constants;
+import io.github.moulberry.notenoughupdates.util.Rectangle;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
@@ -95,6 +97,21 @@ public class TrophyRewardOverlay {
return line.get(1);
}
+ @SubscribeEvent
+ public void onButtonExclusionZones(ButtonExclusionZoneEvent event) {
+ if (inTrophyFishingInventory()) {
+ event.blockArea(
+ new Rectangle(
+ event.getGuiBaseRect().getRight(),
+ event.getGuiBaseRect().getTop(),
+ 168 /*width*/ + 4 /*space*/,
+ 128
+ ),
+ ButtonExclusionZoneEvent.PushDirection.TOWARDS_RIGHT
+ );
+ }
+ }
+
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onDrawBackground(GuiScreenEvent.BackgroundDrawnEvent event) {
if (!inTrophyFishingInventory()) return;
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlay.java
index 33753d6c..6ba285df 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlay.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlay.java
@@ -23,6 +23,7 @@ import com.google.common.collect.Lists;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.core.util.ArrowPagesUtils;
import io.github.moulberry.notenoughupdates.core.util.StringUtils;
+import io.github.moulberry.notenoughupdates.events.ButtonExclusionZoneEvent;
import io.github.moulberry.notenoughupdates.miscgui.TrophyRewardOverlay;
import io.github.moulberry.notenoughupdates.miscgui.minionhelper.Minion;
import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager;
@@ -31,6 +32,7 @@ import io.github.moulberry.notenoughupdates.miscgui.minionhelper.render.renderab
import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer;
import io.github.moulberry.notenoughupdates.util.ItemUtils;
import io.github.moulberry.notenoughupdates.util.NotificationHandler;
+import io.github.moulberry.notenoughupdates.util.Rectangle;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
@@ -91,6 +93,20 @@ public class MinionHelperOverlay {
}
@SubscribeEvent
+ public void onButtonExclusionZones(ButtonExclusionZoneEvent event) {
+ if (manager.inCraftedMinionsInventory() && NotEnoughUpdates.INSTANCE.config.minionHelper.gui) {
+ event.blockArea(
+ new Rectangle(
+ event.getGuiBaseRect().getRight(),
+ event.getGuiBaseRect().getTop(),
+ 168 /*width*/ + 4 /*space*/, 128
+ ),
+ ButtonExclusionZoneEvent.PushDirection.TOWARDS_RIGHT
+ );
+ }
+ }
+
+ @SubscribeEvent
public void onDrawBackground(GuiScreenEvent.BackgroundDrawnEvent event) {
if (!manager.inCraftedMinionsInventory()) return;
if (!NotEnoughUpdates.INSTANCE.config.minionHelper.gui) return;
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/EquipmentOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/EquipmentOverlay.java
index 5cd8f6b3..c0056d3d 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/EquipmentOverlay.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/EquipmentOverlay.java
@@ -24,12 +24,14 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import io.github.moulberry.notenoughupdates.NEUManager;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
+import io.github.moulberry.notenoughupdates.events.ButtonExclusionZoneEvent;
import io.github.moulberry.notenoughupdates.events.GuiInventoryBackgroundDrawnEvent;
import io.github.moulberry.notenoughupdates.miscfeatures.PetInfoOverlay;
import io.github.moulberry.notenoughupdates.miscgui.GuiInvButtonEditor;
import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer;
import io.github.moulberry.notenoughupdates.options.NEUConfig;
import io.github.moulberry.notenoughupdates.util.ItemUtils;
+import io.github.moulberry.notenoughupdates.util.Rectangle;
import io.github.moulberry.notenoughupdates.util.SBInfo;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.client.Minecraft;
@@ -147,6 +149,29 @@ public class EquipmentOverlay {
public ItemStack petStack;
//<editor-fold desc="events">
+ @SubscribeEvent
+ public void onButtonExclusionZones(ButtonExclusionZoneEvent event) {
+ if (isRenderingArmorHud()) {
+ event.blockArea(
+ new Rectangle(
+ event.getGuiBaseRect().getRight() - 200,
+ event.getGuiBaseRect().getTop(),
+ 50, 84
+ ),
+ ButtonExclusionZoneEvent.PushDirection.TOWARDS_LEFT
+ );
+ }
+ if (isRenderingPetHud()) {
+ event.blockArea(
+ new Rectangle(
+ event.getGuiBaseRect().getRight() - 200,
+ event.getGuiBaseRect().getTop() + 60,
+ 50, 60
+ ),
+ ButtonExclusionZoneEvent.PushDirection.TOWARDS_LEFT
+ );
+ }
+ }
@SubscribeEvent
public void onGuiTick(TickEvent.ClientTickEvent event) {
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/events/ButtonExclusionZoneEvent.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/events/ButtonExclusionZoneEvent.kt
new file mode 100644
index 00000000..3c8ce418
--- /dev/null
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/events/ButtonExclusionZoneEvent.kt
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2023 Linnea Gräf
+ *
+ * This file is part of NotEnoughUpdates.
+ *
+ * NotEnoughUpdates is free software: you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * NotEnoughUpdates is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package io.github.moulberry.notenoughupdates.events
+
+import io.github.moulberry.notenoughupdates.events.ButtonExclusionZoneEvent.PushDirection.*
+import io.github.moulberry.notenoughupdates.util.Rectangle
+import net.minecraft.client.gui.GuiScreen
+import java.util.*
+
+class ButtonExclusionZoneEvent(
+ val gui: GuiScreen,
+ val guiBaseRect: Rectangle,
+) : NEUEvent() {
+ enum class PushDirection {
+ TOWARDS_RIGHT,
+ TOWARDS_LEFT,
+ TOWARDS_TOP,
+ TOWARDS_BOTTOM,
+ }
+
+ data class ExclusionZone(
+ val area: Rectangle,
+ val pushDirection: PushDirection,
+ )
+
+ val occupiedRects = mutableListOf<ExclusionZone>()
+ fun blockArea(area: Rectangle, direction: PushDirection) {
+ occupiedRects.add(ExclusionZone(area, direction))
+ }
+
+ @JvmOverloads
+ fun findButtonPosition(button: Rectangle, margin: Int = 0): Rectangle {
+ val processedAreas = IdentityHashMap<ExclusionZone, Unit>()
+
+ var buttonPosition = button
+ while (true) {
+ val overlappingExclusionZone =
+ occupiedRects.find { it !in processedAreas && it.area.intersects(buttonPosition) } ?: break
+ buttonPosition = when (overlappingExclusionZone.pushDirection) {
+ TOWARDS_RIGHT -> buttonPosition.copy(x = overlappingExclusionZone.area.right + margin)
+ TOWARDS_LEFT -> buttonPosition.copy(x = overlappingExclusionZone.area.left - buttonPosition.width - margin)
+ TOWARDS_TOP -> buttonPosition.copy(y = overlappingExclusionZone.area.top - buttonPosition.height - margin)
+ TOWARDS_BOTTOM -> buttonPosition.copy(y = overlappingExclusionZone.area.bottom + margin)
+ }
+ processedAreas[overlappingExclusionZone] = Unit
+ }
+
+ return buttonPosition
+ }
+
+
+}
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/Rectangle.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/Rectangle.kt
new file mode 100644
index 00000000..2251d0e3
--- /dev/null
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/Rectangle.kt
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2023 NotEnoughUpdates contributors
+ *
+ * This file is part of NotEnoughUpdates.
+ *
+ * NotEnoughUpdates is free software: you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * NotEnoughUpdates is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package io.github.moulberry.notenoughupdates.util
+
+/**
+ * An axis aligned rectangle in the following coordinate space:
+ *
+ * * The top direction is towards y=-INF
+ * * The bottom direction is towards y=+INF
+ * * The right direction is towards x=+INF
+ * * The left direction is towards x=-INF
+ */
+data class Rectangle(
+ val x: Int, val y: Int,
+ val width: Int, val height: Int,
+) {
+ /**
+ * The left edge of this rectangle (Low X)
+ */
+ val left get() = x
+
+ /**
+ * The right edge of this rectangle (High X)
+ */
+ val right get() = x + width
+
+ /**
+ * The top edge of this rectangle (Low X)
+ */
+ val top get() = y
+
+ /**
+ * The bottom edge of this rectangle (High X)
+ */
+ val bottom get() = y + height
+
+ init {
+ require(width >= 0)
+ require(height >= 0)
+ }
+
+ /**
+ * Check for intersections between two rectangles. Two rectangles with perfectly aligned edges do *not* count as
+ * intersecting.
+ */
+ fun intersects(other: Rectangle): Boolean {
+ val intersectsX = !(right <= other.left || left >= other.right)
+ val intersectsY = !(top >= other.bottom || bottom <= other.top)
+ return intersectsX && intersectsY
+ }
+}
diff --git a/src/test/kotlin/io/github/moulberry/notenoughupdates/util/RectangleTest.kt b/src/test/kotlin/io/github/moulberry/notenoughupdates/util/RectangleTest.kt
new file mode 100644
index 00000000..6d4270dd
--- /dev/null
+++ b/src/test/kotlin/io/github/moulberry/notenoughupdates/util/RectangleTest.kt
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2023 NotEnoughUpdates contributors
+ *
+ * This file is part of NotEnoughUpdates.
+ *
+ * NotEnoughUpdates is free software: you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * NotEnoughUpdates is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package io.github.moulberry.notenoughupdates.util
+
+import org.junit.jupiter.api.Assertions.assertFalse
+import org.junit.jupiter.api.Assertions.assertTrue
+import org.junit.jupiter.api.Test
+import org.junit.jupiter.api.assertThrows
+
+class RectangleTest {
+
+ @Test
+ fun testNoNegativeSizes() {
+ assertThrows<IllegalArgumentException> {
+ Rectangle(0, 0, -1, 0)
+ }
+ assertThrows<IllegalArgumentException> {
+ Rectangle(0, 0, 0, -1)
+ }
+ }
+
+ @Test
+ fun testOverlaps() {
+ val topLeft = Rectangle(0, 0, 10, 10)
+ assertTrue(topLeft.intersects(topLeft))
+ assertTrue(topLeft.intersects(Rectangle(9, 2, 1, 1)))
+ assertTrue(topLeft.intersects(Rectangle(-2, -2, 4, 4)))
+ assertTrue(topLeft.intersects(Rectangle(4, 4, 1, 1)))
+ assertFalse(topLeft.intersects(Rectangle(-2,-2, 1,1)))
+ assertFalse(topLeft.intersects(Rectangle(-2,-2, 2,2)))
+ }
+}