diff options
author | Lorenz <lo.scherf@gmail.com> | 2022-08-06 10:34:52 +0200 |
---|---|---|
committer | Lorenz <lo.scherf@gmail.com> | 2022-08-06 10:34:52 +0200 |
commit | 580e8a302ed89ef99403a327d003278ff873b334 (patch) | |
tree | d5e35ea4c13749a871893eae7710c89fb377ac0d | |
parent | 7e8279d176c3dc04e92d4f28673035185586d897 (diff) | |
download | NotEnoughUpdates-580e8a302ed89ef99403a327d003278ff873b334.tar.gz NotEnoughUpdates-580e8a302ed89ef99403a327d003278ff873b334.tar.bz2 NotEnoughUpdates-580e8a302ed89ef99403a327d003278ff873b334.zip |
show minion upgrades needed until next slot
3 files changed, 126 insertions, 50 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 5eac048b..9a3a4883 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 @@ -42,6 +42,7 @@ import java.util.Map; public class MinionHelperManager { private static MinionHelperManager instance = null; private final Map<String, Minion> minions = new HashMap<>(); + private int needForNextSlot = -1; private final MinionHelperPriceCalculation priceCalculation = new MinionHelperPriceCalculation(this); private final MinionHelperRequirementsManager requirementsManager = new MinionHelperRequirementsManager(this); @@ -111,8 +112,8 @@ public class MinionHelperManager { minions.put(internalName, new Minion(internalName, tier)); } - public String formatInternalName(String text) { - return text.toUpperCase().replace(" ", "_"); + public String formatInternalName(String minionName) { + return minionName.toUpperCase().replace(" ", "_"); } public List<Minion> getChildren(Minion minion) { @@ -135,6 +136,7 @@ public class MinionHelperManager { api.onProfileSwitch(); overlay.onProfileSwitch(); + needForNextSlot = -1; } public void reloadData() { @@ -236,4 +238,13 @@ public class MinionHelperManager { public Map<String, Minion> getAllMinions() { return minions; } + + public void setNeedForNextSlot(int needForNextSlot) { + this.needForNextSlot = needForNextSlot; + overlay.resetCache(); + } + + public int getNeedForNextSlot() { + return needForNextSlot; + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperInventoryLoader.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperInventoryLoader.java index 1e8e3e27..fa3cc5de 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperInventoryLoader.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperInventoryLoader.java @@ -36,10 +36,11 @@ import java.util.ArrayList; import java.util.List; public class MinionHelperInventoryLoader { - private final List<String> loadedAlready = new ArrayList<>(); private final MinionHelperManager manager; + private final List<String> pagesSeenAlready = new ArrayList<>(); + private boolean shouldCheckNextSlot = true; - int ticks = 0; + private int ticks = 0; public MinionHelperInventoryLoader(MinionHelperManager manager) { this.manager = manager; @@ -55,60 +56,85 @@ public class MinionHelperInventoryLoader { if (ticks % 5 != 0) return; if (manager.inCraftedMinionsInventory()) { - checkInv(); + checkInventory(); } else { - loadedAlready.clear(); + pagesSeenAlready.clear(); + shouldCheckNextSlot = true; } } - private void checkInv() { + private void checkInventory() { Container openContainer = Minecraft.getMinecraft().thePlayer.openContainer; if (openContainer instanceof ContainerChest) { - Slot firstSlot = openContainer.inventorySlots.get(10); - boolean shouldLoad = false; - if (firstSlot != null) { - if (firstSlot.getHasStack()) { - ItemStack stack = firstSlot.getStack(); - String displayName = stack.getDisplayName(); - if (!loadedAlready.contains(displayName)) { - loadedAlready.add(displayName); - shouldLoad = true; - } - } + if (shouldCheckNextSlot) { + shouldCheckNextSlot = false; + checkNextSlot(openContainer); } - if (!shouldLoad) return; + loadMinionData(openContainer); + } + } - int crafted = 0; - for (Slot slot : openContainer.inventorySlots) { - if (!slot.getHasStack()) continue; - ItemStack stack = slot.getStack(); - if (stack == null) continue; - if (slot.slotNumber != slot.getSlotIndex()) continue; + private void checkNextSlot(Container openContainer) { + Slot informationSlot = openContainer.inventorySlots.get(50); + if (informationSlot.getHasStack()) { + ItemStack informationStack = informationSlot.getStack(); + for (String line : ItemUtils.getLore(informationStack)) { + if (line.contains("§aunique")) { + String[] split = line.split(" "); + int needForNextSlot = Integer.parseInt(StringUtils.cleanColour(split[1])); + manager.setNeedForNextSlot(needForNextSlot); + return; + } + } + } + } + private void loadMinionData(Container openContainer) { + Slot firstSlot = openContainer.inventorySlots.get(10); + boolean shouldLoad = false; + if (firstSlot != null) { + if (firstSlot.getHasStack()) { + ItemStack stack = firstSlot.getStack(); String displayName = stack.getDisplayName(); - if (!displayName.contains(" Minion")) continue; - - displayName = StringUtils.cleanColour(displayName); - int index = 0; - for (String line : ItemUtils.getLore(stack)) { - index++; - if (!line.contains("Tier")) { - continue; - } - if (line.contains("§a")) { - Minion minion = manager.getMinionByName(displayName, index); - if (!minion.isCrafted()) { - minion.setCrafted(true); - crafted++; - } - } + if (!pagesSeenAlready.contains(displayName)) { + pagesSeenAlready.add(displayName); + shouldLoad = true; } } - if (crafted > 0) { - manager.getOverlay().resetCache(); + } + + if (!shouldLoad) return; + + int crafted = 0; + for (Slot slot : openContainer.inventorySlots) { + if (!slot.getHasStack()) continue; + ItemStack stack = slot.getStack(); + if (stack == null) continue; + if (slot.slotNumber != slot.getSlotIndex()) continue; + + String displayName = stack.getDisplayName(); + if (!displayName.contains(" Minion")) continue; + + displayName = StringUtils.cleanColour(displayName); + int index = 0; + for (String line : ItemUtils.getLore(stack)) { + index++; + if (!line.contains("Tier")) { + continue; + } + if (line.contains("§a")) { + Minion minion = manager.getMinionByName(displayName, index); + if (!minion.isCrafted()) { + minion.setCrafted(true); + crafted++; + } + } } } + if (crafted > 0) { + manager.getOverlay().resetCache(); + } } } 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 84db8c00..5f1e7e16 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 @@ -45,10 +45,12 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; public class MinionHelperOverlay { @@ -177,7 +179,8 @@ public class MinionHelperOverlay { int a = guiLeft + xSize + 4; FontRenderer fontRendererObj = minecraft.fontRendererObj; - int extra = 0; + int i = 0; + int y = 0; for (Map.Entry<String, OverviewLine> entry : renderMap.entrySet()) { String line = entry.getKey(); OverviewLine overviewLine = entry.getValue(); @@ -188,9 +191,13 @@ public class MinionHelperOverlay { prefix = "§e"; } } - fontRendererObj.drawString(prefix + line, a + 6, guiTop + 6 + extra, -1, false); - extra += 10; - if (extra == maxPerPage + 2) extra = 15; + fontRendererObj.drawString(prefix + line, a + 6, guiTop + 6 + y, -1, false); + i++; + if (i == 2) { + y += 15; + } else { + y += 10; + } } } @@ -201,6 +208,7 @@ public class MinionHelperOverlay { LinkedHashMap<String, OverviewLine> renderMap = new LinkedHashMap<>(); addTitle(prices, renderMap); + addNeedToNextSlot(prices, renderMap); if (!prices.isEmpty()) { addMinions(prices, renderMap); @@ -210,6 +218,37 @@ public class MinionHelperOverlay { return renderMap; } + private void addNeedToNextSlot( + Map<Minion, Long> prices, + LinkedHashMap<String, OverviewLine> renderMap + ) { + int neededForNextSlot = manager.getNeedForNextSlot(); + if (neededForNextSlot == -1) { + renderMap.put("Next slot in: ?", new OverviewText(Collections.emptyList(), () -> {})); + return; + } + + long priceNeeded = 0; + int index = 0; + for (Long price : TrophyRewardOverlay.sortByValue(prices).values()) { + priceNeeded += price; + index++; + if (index == neededForNextSlot) break; + } + String format = manager.getPriceCalculation().formatCoins(priceNeeded); + String text = "Next slot in: §b" + neededForNextSlot + " §8- " + format; + List<String> list = new ArrayList<>(); + list.add("§7The combined upgrade cost for"); + list.add("§7the next §b" + index + " minions §7is " + format); + + if (!showOnlyAvailable) { + list.add(""); + list.add("§cThis shows minions that don't meet requirements!"); + } + + renderMap.put(text, new OverviewText(list, () -> {})); + } + private void addTitle(Map<Minion, Long> prices, LinkedHashMap<String, OverviewLine> renderMap) { String name; String hoverText; @@ -292,7 +331,7 @@ public class MinionHelperOverlay { int mouseX = Mouse.getX() * scaledWidth / Minecraft.getMinecraft().displayWidth; int mouseY = scaledHeight - Mouse.getY() * scaledHeight / Minecraft.getMinecraft().displayHeight - 1; - boolean first = true; + int i = 0; FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; for (Map.Entry<String, OverviewLine> entry : renderMap.entrySet()) { String text = entry.getKey(); @@ -301,9 +340,9 @@ public class MinionHelperOverlay { mouseY > y && mouseY < y + 11) { return entry.getValue(); } - if (first) { + i++; + if (i == 2) { y += 15; - first = false; } else { y += 10; } |