aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io
diff options
context:
space:
mode:
authorLorenz <lo.scherf@gmail.com>2022-08-02 12:39:56 +0200
committerLorenz <lo.scherf@gmail.com>2022-08-02 12:39:56 +0200
commit5f1d53b27742615f043801e7ccacb74248a3e0e5 (patch)
treeec1db39c85dcd5dd4a5c95d205531ad4bfbd1a4c /src/main/java/io
parenta5a6dd79389377563b09f3d17f74d364623de73d (diff)
downloadNotEnoughUpdates-5f1d53b27742615f043801e7ccacb74248a3e0e5.tar.gz
NotEnoughUpdates-5f1d53b27742615f043801e7ccacb74248a3e0e5.tar.bz2
NotEnoughUpdates-5f1d53b27742615f043801e7ccacb74248a3e0e5.zip
add page support
Diffstat (limited to 'src/main/java/io')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperManager.java9
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlay.java113
2 files changed, 99 insertions, 23 deletions
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 6af7af32..c9397067 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
@@ -135,6 +135,7 @@ public class MinionHelperManager {
}
api.onProfileSwitch();
+ overlay.onProfileSwitch();
}
public void reloadData() {
@@ -172,6 +173,13 @@ public class MinionHelperManager {
Utils.addChatMessage("api data cleared");
return;
}
+ if (parameter.equals("maxperpage")) {
+ api.resetData();
+ int maxPerPage = Integer.parseInt(args[1]);
+ Utils.addChatMessage("set max per page to " + maxPerPage);
+ overlay.setMaxPerPage(maxPerPage);
+ return;
+ }
}
Utils.addChatMessage("");
@@ -180,6 +188,7 @@ public class MinionHelperManager {
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("");
}
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 8e44b7c5..fa2e351a 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
@@ -44,6 +44,7 @@ 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;
@@ -55,6 +56,9 @@ public class MinionHelperOverlay {
private LinkedHashMap<String, OverviewLine> cacheRenderMap = null;
private boolean showOnlyAvailable = true;
+ private int maxPerPage = 8;
+ private int currentPage = 0;
+
public MinionHelperOverlay(MinionHelperManager manager) {
this.manager = manager;
hover = new MinionHelperOverlayHover(this, manager);
@@ -135,6 +139,7 @@ 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();
@@ -148,6 +153,9 @@ 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;
}
}
@@ -156,54 +164,100 @@ public class MinionHelperOverlay {
Map<Minion, Long> prices = getMissing();
LinkedHashMap<String, OverviewLine> renderMap = new LinkedHashMap<>();
+
String toggleText = "§eClick to " + (showOnlyAvailable ? "show" : "hide") + " minion upgrades without requirements";
+
+ int pageNr = currentPage + 1;
+ int totalPages = getTotalPages(prices);
+
+ String pagePrefix = "(" + pageNr + "/" + totalPages + ") ";
+
if (prices.isEmpty()) {
renderMap.put(
- "all minions collected!",
- new OverviewText(Arrays.asList("No minions to craft avaliable!", toggleText), this::toggleShowAvailable)
+ pagePrefix + "all minions collected!",
+ new OverviewText(
+ Arrays.asList("No minions to craft avaliable!", toggleText),
+ this::toggleShowAvailable
+ )
);
} else {
renderMap.put(
- "To craft: " + prices.size(),
+ pagePrefix + "To craft: " + prices.size(),
new OverviewText(
Arrays.asList("You can craft " + prices.size() + " more minions!", toggleText),
this::toggleShowAvailable
)
);
- int i = 0;
-
- //TODO change
- int max = 9;
+ int skipPreviousPages = currentPage * maxPerPage;
+ int i = 0;
Map<Minion, Long> sort = TrophyRewardOverlay.sortByValue(prices);
for (Minion minion : sort.keySet()) {
- String displayName = minion.getDisplayName();
- if (displayName == null) {
- if (NotEnoughUpdates.INSTANCE.config.hidden.dev) {
- Utils.addChatMessage("§cDisplayname is null for " + minion.getInternalName());
+ if (i >= skipPreviousPages) {
+ String displayName = minion.getDisplayName();
+ if (displayName == null) {
+ if (NotEnoughUpdates.INSTANCE.config.hidden.dev) {
+ Utils.addChatMessage("§cDisplayname is null for " + minion.getInternalName());
+ }
+ continue;
}
- continue;
- }
- displayName = displayName.replace(" Minion", "");
- String format = manager.getPriceCalculation().calculateUpgradeCostsFormat(minion, true);
- String requirementFormat = !minion.doesMeetRequirements() ? "§7§o" : "";
- renderMap.put(
- requirementFormat + displayName + " " + minion.getTier() + " §r§8- " + format,
- minion
- );
+ displayName = displayName.replace(" Minion", "");
+ String format = manager.getPriceCalculation().calculateUpgradeCostsFormat(minion, true);
+ String requirementFormat = !minion.doesMeetRequirements() ? "§7§o" : "";
+ renderMap.put(
+ requirementFormat + displayName + " " + minion.getTier() + " §r§8- " + format,
+ minion
+ );
+ }
i++;
- if (i == max) break;
+ if (i == ((currentPage + 1) * maxPerPage)) break;
}
}
+ 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;
}
+ private int getTotalPages(Map<Minion, Long> prices) {
+ int totalPages = (int) ((double) prices.size() / maxPerPage);
+ if (prices.size() % maxPerPage != 0) {
+ totalPages++;
+ }
+ return totalPages;
+ }
+
private void toggleShowAvailable() {
showOnlyAvailable = !showOnlyAvailable;
+ currentPage = 0;
resetCache();
}
@@ -225,15 +279,28 @@ public class MinionHelperOverlay {
int mouseY = scaledHeight - Mouse.getY() * scaledHeight / Minecraft.getMinecraft().displayHeight - 1;
int index = 0;
+ int extra = 0;
for (OverviewLine overviewLine : renderMap.values()) {
if (mouseX > x && mouseX < x + 130 &&
- mouseY > y + index && mouseY < y + 13 + index) {
+ mouseY > y + extra && mouseY < y + 13 + extra) {
return overviewLine;
}
- index += 10;
+ extra += 10;
+ if (extra == maxPerPage + 2) extra = 15;
+ index++;
+ if (index == renderMap.values().size() - 2) extra = maxPerPage * 10 + 20;
}
return null;
}
+
+ public void onProfileSwitch() {
+ currentPage = 0;
+ showOnlyAvailable = true;
+ }
+
+ public void setMaxPerPage(int maxPerPage) {
+ this.maxPerPage = maxPerPage;
+ }
}