aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorLorenz <lo.scherf@gmail.com>2022-08-05 11:32:21 +0200
committerLorenz <lo.scherf@gmail.com>2022-08-05 11:32:21 +0200
commit085911df2e55ee3fd490aab2f225abd0f49d91e5 (patch)
treeaf2f8208fe71509b6f380adbd0084febef2ec26a /src/main
parentf8567326b4ea69c79d34461385714e8d317e279c (diff)
downloadNotEnoughUpdates-085911df2e55ee3fd490aab2f225abd0f49d91e5.tar.gz
NotEnoughUpdates-085911df2e55ee3fd490aab2f225abd0f49d91e5.tar.bz2
NotEnoughUpdates-085911df2e55ee3fd490aab2f225abd0f49d91e5.zip
created PageArrowsUtils and used it for minion helper and recipe viewer
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/core/util/PageArrowsUtils.java155
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java114
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperManager.java74
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlay.java78
4 files changed, 241 insertions, 180 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/util/PageArrowsUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/core/util/PageArrowsUtils.java
new file mode 100644
index 00000000..1207cfa9
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/core/util/PageArrowsUtils.java
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) 2022 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.core.util;
+
+import io.github.moulberry.notenoughupdates.util.Utils;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.FontRenderer;
+import net.minecraft.client.gui.ScaledResolution;
+import net.minecraft.util.MathHelper;
+import net.minecraft.util.ResourceLocation;
+import org.lwjgl.input.Mouse;
+import org.lwjgl.opengl.GL11;
+
+import java.awt.*;
+import java.util.function.Consumer;
+
+public class PageArrowsUtils {
+
+ public static final int BUTTON_POSITION_RIGHT_OFFSET_X = 37;
+ public static final int PAGE_STRING_OFFSET_X = 22;
+ public static final int PAGE_STRING_OFFSET_Y = 6;
+
+ public static final int BUTTON_WIDTH = 7;
+ public static final int BUTTON_HEIGHT = 11;
+
+ public static final ResourceLocation resourcePacksTexture = new ResourceLocation("textures/gui/resource_packs.png");
+
+ public static void onDraw(int guiLeft, int guiTop, int[] topLeftButton, int currentPage, int totalPages) {
+ if (totalPages < 2) return;
+
+ final ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft());
+ final int scaledWidth = scaledresolution.getScaledWidth();
+ final int scaledHeight = scaledresolution.getScaledHeight();
+ int mouseX = Mouse.getX() * scaledWidth / Minecraft.getMinecraft().displayWidth;
+ int mouseY = scaledHeight - Mouse.getY() * scaledHeight / Minecraft.getMinecraft().displayHeight - 1;
+
+ int buttonPositionLeftX = topLeftButton[0];
+ int buttonPositionRightX = buttonPositionLeftX + BUTTON_POSITION_RIGHT_OFFSET_X;
+ int pageStringX = buttonPositionLeftX + PAGE_STRING_OFFSET_X;
+ int buttonPositionY = topLeftButton[1];
+ int pageStringY = buttonPositionY + PAGE_STRING_OFFSET_Y;
+
+ boolean leftSelected = isWithinRect(
+ mouseX - guiLeft,
+ mouseY - guiTop,
+ buttonPositionLeftX,
+ buttonPositionY,
+ BUTTON_WIDTH,
+ BUTTON_HEIGHT
+ );
+ boolean rightSelected = isWithinRect(
+ mouseX - guiLeft,
+ mouseY - guiTop,
+ buttonPositionRightX,
+ buttonPositionY,
+ BUTTON_WIDTH,
+ BUTTON_HEIGHT
+ );
+ Minecraft.getMinecraft().getTextureManager().bindTexture(resourcePacksTexture);
+
+ if (currentPage != 0)
+ Utils.drawTexturedRect(
+ guiLeft + buttonPositionLeftX, guiTop + buttonPositionY, BUTTON_WIDTH, BUTTON_HEIGHT,
+ 34 / 256f, 48 / 256f,
+ leftSelected ? 37 / 256f : 5 / 256f, leftSelected ? 59 / 256f : 27 / 256f
+ );
+ if (currentPage != totalPages - 1)
+ Utils.drawTexturedRect(
+ guiLeft + buttonPositionRightX, guiTop + buttonPositionY, BUTTON_WIDTH, BUTTON_HEIGHT,
+ 10 / 256f, 24 / 256f,
+ rightSelected ? 37 / 256f : 5 / 256f, rightSelected ? 59 / 256f : 27 / 256f
+ );
+ GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
+
+ String selectedPage = (currentPage + 1) + "/" + totalPages;
+
+ FontRenderer fontRendererObj = Minecraft.getMinecraft().fontRendererObj;
+ Utils.drawStringCenteredScaledMaxWidth(selectedPage, fontRendererObj,
+ guiLeft + pageStringX, guiTop + pageStringY, false, 24, Color.BLACK.getRGB()
+ );
+ }
+
+ public static boolean onPageSwitch(
+ int guiLeft,
+ int guiTop,
+ int[] topLeft,
+ int currentPage,
+ int totalPages,
+ Consumer<Integer> pageChange
+ ) {
+ final ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft());
+ final int scaledWidth = scaledresolution.getScaledWidth();
+ final int scaledHeight = scaledresolution.getScaledHeight();
+ int mouseX = Mouse.getX() * scaledWidth / Minecraft.getMinecraft().displayWidth;
+ int mouseY = scaledHeight - Mouse.getY() * scaledHeight / Minecraft.getMinecraft().displayHeight - 1;
+
+ int buttonPositionLeftX = topLeft[0];
+ int buttonPositionRightX = buttonPositionLeftX + BUTTON_POSITION_RIGHT_OFFSET_X;
+ int buttonPositionY = topLeft[1];
+
+ if (isWithinRect(
+ mouseX - guiLeft,
+ mouseY - guiTop,
+ buttonPositionLeftX,
+ buttonPositionY,
+ BUTTON_WIDTH,
+ BUTTON_HEIGHT
+ ) &&
+ currentPage > 0) {
+ int newPage = currentPage - 1;
+ pageChange.accept(MathHelper.clamp_int(newPage, 0, totalPages - 1));
+ Utils.playPressSound();
+ return true;
+ }
+
+ if (isWithinRect(
+ mouseX - guiLeft,
+ mouseY - guiTop,
+ buttonPositionRightX,
+ buttonPositionY,
+ BUTTON_WIDTH,
+ BUTTON_HEIGHT
+ ) &&
+ currentPage < totalPages) {
+ int newPage = currentPage + 1;
+ pageChange.accept(MathHelper.clamp_int(newPage, 0, totalPages - 1));
+ Utils.playPressSound();
+ return true;
+ }
+
+ return false;
+ }
+
+ private static boolean isWithinRect(int x, int y, int topLeftX, int topLeftY, int width, int height) {
+ return topLeftX <= x && x < topLeftX + width
+ && topLeftY <= y && y < topLeftY + height;
+ }
+}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java
index 69343e99..8d075bd4 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java
@@ -21,6 +21,7 @@ package io.github.moulberry.notenoughupdates.miscgui;
import com.google.common.collect.ImmutableList;
import io.github.moulberry.notenoughupdates.NEUManager;
+import io.github.moulberry.notenoughupdates.core.util.PageArrowsUtils;
import io.github.moulberry.notenoughupdates.recipes.NeuRecipe;
import io.github.moulberry.notenoughupdates.recipes.RecipeSlot;
import io.github.moulberry.notenoughupdates.recipes.RecipeType;
@@ -38,9 +39,7 @@ import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
-import org.lwjgl.opengl.GL11;
-import java.awt.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
@@ -49,13 +48,10 @@ import java.util.List;
import java.util.Map;
public class GuiItemRecipe extends GuiScreen {
- public static final ResourceLocation resourcePacksTexture = new ResourceLocation("textures/gui/resource_packs.png");
public static final ResourceLocation tabsTexture = new ResourceLocation("notenoughupdates", "textures/gui/tab.png");
public static final int SLOT_SIZE = 16;
public static final int SLOT_SPACING = SLOT_SIZE + 2;
- public static final int BUTTON_WIDTH = 7;
- public static final int BUTTON_HEIGHT = 11;
public static final int TITLE_X = 28;
public static final int TITLE_Y = 6;
public static final int HOTBAR_SLOT_X = 8;
@@ -145,7 +141,8 @@ public class GuiItemRecipe extends GuiScreen {
Utils.drawItemStack(slot.getItemStack(), slot.getX(this), slot.getY(this), true);
}
- drawArrows(currentRecipe, mouseX, mouseY);
+ int[] topLeft = currentRecipe.getPageFlipPositionLeftTopCorner();
+ PageArrowsUtils.onDraw(guiLeft, guiTop, topLeft, currentIndex, getCurrentRecipeList().size());
Utils.drawStringScaledMaxWidth(
currentRecipe.getTitle(),
@@ -220,61 +217,6 @@ public class GuiItemRecipe extends GuiScreen {
}
}
- public static final int BUTTON_POSITION_RIGHT_OFFSET_X = 37;
- public static final int PAGE_STRING_OFFSET_X = 22;
- public static final int PAGE_STRING_OFFSET_Y = 6;
-
- private void drawArrows(
- NeuRecipe currentRecipe,
- int mouseX,
- int mouseY
- ) {
- int recipeCount = getCurrentRecipeList().size();
- if (recipeCount < 2) return;
- int[] topLeft = currentRecipe.getPageFlipPositionLeftTopCorner();
- int buttonPositionLeftX = topLeft[0];
- int buttonPositionRightX = buttonPositionLeftX + BUTTON_POSITION_RIGHT_OFFSET_X;
- int pageStringX = buttonPositionLeftX + PAGE_STRING_OFFSET_X;
- int buttonPositionY = topLeft[1];
- int pageStringY = buttonPositionY + PAGE_STRING_OFFSET_Y;
-
- boolean leftSelected = isWithinRect(
- mouseX - guiLeft,
- mouseY - guiTop,
- buttonPositionLeftX,
- buttonPositionY,
- BUTTON_WIDTH,
- BUTTON_HEIGHT
- );
- boolean rightSelected = isWithinRect(
- mouseX - guiLeft,
- mouseY - guiTop,
- buttonPositionRightX,
- buttonPositionY,
- BUTTON_WIDTH,
- BUTTON_HEIGHT
- );
- Minecraft.getMinecraft().getTextureManager().bindTexture(resourcePacksTexture);
-
- if (currentIndex != 0)
- Utils.drawTexturedRect(guiLeft + buttonPositionLeftX, guiTop + buttonPositionY, BUTTON_WIDTH, BUTTON_HEIGHT,
- 34 / 256f, 48 / 256f,
- leftSelected ? 37 / 256f : 5 / 256f, leftSelected ? 59 / 256f : 27 / 256f
- );
- if (currentIndex != recipeCount - 1)
- Utils.drawTexturedRect(guiLeft + buttonPositionRightX, guiTop + buttonPositionY, BUTTON_WIDTH, BUTTON_HEIGHT,
- 10 / 256f, 24 / 256f,
- rightSelected ? 37 / 256f : 5 / 256f, rightSelected ? 59 / 256f : 27 / 256f
- );
- GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
-
- String selectedPage = (currentIndex + 1) + "/" + recipeCount;
-
- Utils.drawStringCenteredScaledMaxWidth(selectedPage, fontRendererObj,
- guiLeft + pageStringX, guiTop + pageStringY, false, 24, Color.BLACK.getRGB()
- );
- }
-
public List<RecipeSlot> getPlayerInventory() {
List<RecipeSlot> slots = new ArrayList<>();
ItemStack[] inventory = Minecraft.getMinecraft().thePlayer.inventory.mainInventory;
@@ -327,7 +269,7 @@ public class GuiItemRecipe extends GuiScreen {
}
@Override
- protected void actionPerformed(GuiButton p_actionPerformed_1_) throws IOException {
+ protected void actionPerformed(GuiButton p_actionPerformed_1_) {
getCurrentRecipe().actionPerformed(p_actionPerformed_1_);
}
@@ -336,52 +278,8 @@ public class GuiItemRecipe extends GuiScreen {
super.mouseClicked(mouseX, mouseY, mouseButton);
NeuRecipe currentRecipe = getCurrentRecipe();
int[] topLeft = currentRecipe.getPageFlipPositionLeftTopCorner();
- int buttonPositionLeftX = topLeft[0];
- int buttonPositionRightX = buttonPositionLeftX + BUTTON_POSITION_RIGHT_OFFSET_X;
- int buttonPositionY = topLeft[1];
-
- if (isWithinRect(
- mouseX - guiLeft,
- mouseY - guiTop,
- buttonPositionLeftX,
- buttonPositionY,
- BUTTON_WIDTH,
- BUTTON_HEIGHT
- ) &&
- currentIndex > 0) {
- changeRecipe(currentTab, currentIndex - 1);
- Utils.playPressSound();
- return;
- }
-
- if (isWithinRect(
- mouseX - guiLeft,
- mouseY - guiTop,
- buttonPositionRightX,
- buttonPositionY,
- BUTTON_WIDTH,
- BUTTON_HEIGHT
- ) &&
- currentIndex < getCurrentRecipeList().size()) {
- changeRecipe(currentTab, currentIndex + 1);
- Utils.playPressSound();
- return;
- }
-
- for (int i = 0; i < tabs.size(); i++) {
- if (isWithinRect(
- mouseX - guiLeft,
- mouseY - guiTop,
- TAB_POS_X,
- TAB_POS_Y + TAB_OFFSET_Y * i,
- TAB_SIZE_X,
- TAB_SIZE_Y
- )) {
- changeRecipe(i, currentIndex);
- Utils.playPressSound();
- return;
- }
- }
+ PageArrowsUtils.onPageSwitch(guiLeft, guiTop, topLeft, currentIndex, getCurrentRecipeList().size(), pageChange ->
+ changeRecipe(currentTab, pageChange));
for (RecipeSlot slot : getAllRenderedSlots()) {
if (isWithinRect(mouseX, mouseY, slot.getX(this), slot.getY(this), SLOT_SIZE, SLOT_SIZE)) {
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperManager.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperManager.java
index e4b5faff..afba58e5 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperManager.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperManager.java
@@ -150,50 +150,62 @@ public class MinionHelperManager {
}
public void handleCommand(String[] args) {
- if (args.length == 2) {
+ if (args.length > 1) {
String parameter = args[1];
- if (parameter.equals("clearminion")) {
- minions.clear();
- Utils.addChatMessage("minion map cleared");
- return;
- }
- if (parameter.equals("reloadrepo")) {
- repo.setDirty();
- Utils.addChatMessage("repo reload requested");
- return;
- }
- if (parameter.equals("reloadapi")) {
- api.resetData();
- api.setDirty();
- Utils.addChatMessage("api reload requested");
- return;
- }
- if (parameter.equals("clearapi")) {
- api.resetData();
- Utils.addChatMessage("api data cleared");
- return;
+
+ if (args.length == 2) {
+ if (parameter.equals("clearminion")) {
+ minions.clear();
+ Utils.addChatMessage("minion map cleared");
+ return;
+ }
+ if (parameter.equals("reloadrepo")) {
+ repo.setDirty();
+ Utils.addChatMessage("repo reload requested");
+ return;
+ }
+ if (parameter.equals("reloadapi")) {
+ api.resetData();
+ api.setDirty();
+ Utils.addChatMessage("api reload requested");
+ return;
+ }
+ if (parameter.equals("clearapi")) {
+ api.resetData();
+ Utils.addChatMessage("api data cleared");
+ return;
+ }
}
- }
- if (args.length == 3) {
- String parameter = args[1];
+ if (args.length == 3) {
+ if (parameter.equals("maxperpage")) {
+ api.resetData();
+ int maxPerPage = Integer.parseInt(args[2]);
+ Utils.addChatMessage("set max per page to " + maxPerPage);
+ overlay.setMaxPerPage(maxPerPage);
+ return;
+ }
+ }
- if (parameter.equals("maxperpage")) {
- api.resetData();
- int maxPerPage = Integer.parseInt(args[2]);
- Utils.addChatMessage("set max per page to " + maxPerPage);
- overlay.setMaxPerPage(maxPerPage);
- return;
+ if (args.length == 4) {
+ if (parameter.equals("pagepos")) {
+ int x = Integer.parseInt(args[2]);
+ int y = Integer.parseInt(args[3]);
+ Utils.addChatMessage("set page pos to " + x + ";" + y);
+ overlay.setTopLeft(new int[] {x, y});
+ return;
+ }
}
}
Utils.addChatMessage("");
- Utils.addChatMessage("§3NEU Minion Helper commands: §c((for testing only!)");
+ Utils.addChatMessage("§3NEU Minion Helper commands: §c(for testing only!)");
Utils.addChatMessage("§6/neudevtest minion clearminion §7Clears the minion map");
Utils.addChatMessage("§6/neudevtest minion reloadrepo §7Manually loading the data from repo");
Utils.addChatMessage("§6/neudevtest minion reloadapi §7Manually loading the data from api");
Utils.addChatMessage("§6/neudevtest minion clearapi §7Clears the api data");
Utils.addChatMessage("§6/neudevtest minion maxperpage <number> §7Changes the max minions per page number");
+ Utils.addChatMessage("§6/neudevtest minion pagepos <x, y> §7Changes the position of the page numbers");
Utils.addChatMessage("");
}
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 a72a4d77..39eec55f 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
@@ -21,6 +21,7 @@ package io.github.moulberry.notenoughupdates.miscgui.minionhelper.render;
import com.google.common.collect.Lists;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
+import io.github.moulberry.notenoughupdates.core.util.PageArrowsUtils;
import io.github.moulberry.notenoughupdates.miscgui.TrophyRewardOverlay;
import io.github.moulberry.notenoughupdates.miscgui.minionhelper.Minion;
import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager;
@@ -44,7 +45,6 @@ import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import java.util.Arrays;
-import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -52,8 +52,11 @@ import java.util.Map;
public class MinionHelperOverlay {
private final MinionHelperManager manager;
private final MinionHelperOverlayHover hover;
+ private int[] topLeft = new int[]{190, 130};
private LinkedHashMap<String, OverviewLine> cacheRenderMap = null;
+ private int cacheTotalPages = -1;
+
private boolean showOnlyAvailable = true;
private int maxPerPage = 8;
@@ -71,6 +74,7 @@ public class MinionHelperOverlay {
public void resetCache() {
cacheRenderMap = null;
+ cacheTotalPages = -1;
}
//TODO use different texture
@@ -96,6 +100,15 @@ public class MinionHelperOverlay {
hover.renderHover(renderMap);
render(event, renderMap);
+
+ GuiScreen gui = event.gui;
+ if (gui instanceof AccessorGuiContainer) {
+ AccessorGuiContainer container = (AccessorGuiContainer) gui;
+ int guiLeft = container.getGuiLeft();
+ int guiTop = container.getGuiTop();
+ int totalPages = getTotalPages();
+ PageArrowsUtils.onDraw(guiLeft, guiTop, topLeft, currentPage, totalPages);
+ }
}
@SubscribeEvent
@@ -109,6 +122,16 @@ public class MinionHelperOverlay {
overviewLine.onClick();
event.setCanceled(true);
}
+
+ int totalPages = getTotalPages();
+ int guiLeft = ((AccessorGuiContainer) event.gui).getGuiLeft();
+ int guiTop = ((AccessorGuiContainer) event.gui).getGuiTop();
+ if (PageArrowsUtils.onPageSwitch(guiLeft, guiTop, topLeft, currentPage, totalPages, pageChange -> {
+ currentPage = pageChange;
+ resetCache();
+ })) {
+ event.setCanceled(true);
+ }
}
private Map<Minion, Long> getMissing() {
@@ -139,7 +162,6 @@ public class MinionHelperOverlay {
int a = guiLeft + xSize + 4;
FontRenderer fontRendererObj = minecraft.fontRendererObj;
- int index = 0;
int extra = 0;
for (Map.Entry<String, OverviewLine> entry : renderMap.entrySet()) {
String line = entry.getKey();
@@ -154,8 +176,6 @@ public class MinionHelperOverlay {
fontRendererObj.drawString(prefix + line, a + 6, guiTop + 6 + extra, -1, false);
extra += 10;
if (extra == maxPerPage + 2) extra = 15;
- index++;
- if (index == renderMap.values().size() - 2) extra = maxPerPage * 10 + 20;
}
}
@@ -164,7 +184,7 @@ public class MinionHelperOverlay {
Map<Minion, Long> prices = getMissing();
LinkedHashMap<String, OverviewLine> renderMap = new LinkedHashMap<>();
- int totalPages = getTotalPages(prices);
+ int totalPages = getTotalPages();
addTitle(prices, renderMap, totalPages);
@@ -172,36 +192,6 @@ public class MinionHelperOverlay {
addMinions(prices, renderMap);
}
- if (totalPages != currentPage + 1) {
- renderMap.put(
- " §eNext Page ->",
- new OverviewText(Collections.singletonList("§eClick to show page " + (currentPage + 2)), () -> {
- if (totalPages == currentPage + 1) return;
- currentPage++;
- resetCache();
- })
- );
- } else {
- renderMap.put(" §7Next Page ->", new OverviewText(Collections.singletonList("§7There is no next page"), () -> {
- }));
- }
- if (currentPage != 0) {
- renderMap.put(
- "§e<- Previous Page",
- new OverviewText(Collections.singletonList("§eClick to show page " + currentPage), () -> {
- if (currentPage == 0) return;
- currentPage--;
- resetCache();
- })
- );
- } else {
- renderMap.put(
- "§7<- Previous Page",
- new OverviewText(Collections.singletonList("§7There is no previous page"), () -> {
- })
- );
- }
-
cacheRenderMap = renderMap;
return renderMap;
}
@@ -216,9 +206,9 @@ public class MinionHelperOverlay {
} else {
name = pagePrefix + (showOnlyAvailable ? "Obtainable" : "All") + ": " + prices.size();
if (showOnlyAvailable) {
- hoverText = "There are " + prices.size() + " more minions in total!";
+ hoverText = "There are " + prices.size() + " more minions in total!";
} else {
- hoverText = "You can craft " + prices.size() + " more minions!";
+ hoverText = "You can craft " + prices.size() + " more minions!";
}
}
String toggleText = "§eClick to " + (showOnlyAvailable ? "show" : "hide") + " minion upgrades without requirements";
@@ -253,11 +243,16 @@ public class MinionHelperOverlay {
}
}
- private int getTotalPages(Map<Minion, Long> prices) {
+ private int getTotalPages() {
+ if (cacheTotalPages != -1) return cacheTotalPages;
+
+ Map<Minion, Long> prices = getMissing();
int totalPages = (int) ((double) prices.size() / maxPerPage);
if (prices.size() % maxPerPage != 0) {
totalPages++;
}
+
+ cacheTotalPages = totalPages;
return totalPages;
}
@@ -284,7 +279,6 @@ public class MinionHelperOverlay {
int mouseX = Mouse.getX() * scaledWidth / Minecraft.getMinecraft().displayWidth;
int mouseY = scaledHeight - Mouse.getY() * scaledHeight / Minecraft.getMinecraft().displayHeight - 1;
- int index = 0;
int extra = 0;
for (OverviewLine overviewLine : renderMap.values()) {
@@ -294,8 +288,6 @@ public class MinionHelperOverlay {
}
extra += 10;
if (extra == maxPerPage + 2) extra = 15;
- index++;
- if (index == renderMap.values().size() - 2) extra = maxPerPage * 10 + 20;
}
return null;
@@ -309,4 +301,8 @@ public class MinionHelperOverlay {
public void setMaxPerPage(int maxPerPage) {
this.maxPerPage = maxPerPage;
}
+
+ public void setTopLeft(int[] topLeft) {
+ this.topLeft = topLeft;
+ }
}