From 34696506f8c45528ba81c48a3018e14592936dec Mon Sep 17 00:00:00 2001 From: Lorenz Date: Wed, 10 Aug 2022 23:32:41 +0200 Subject: extra button for toggle show/hide not obtainable --- .../minionhelper/render/MinionHelperOverlay.java | 80 ++++++++++++--------- .../render/MinionHelperOverlayHover.java | 65 ++++++++++++++--- .../util/MinionHelperPriceCalculation.java | 2 +- .../assets/notenoughupdates/minion_overlay.png | Bin 350 -> 390 bytes 4 files changed, 104 insertions(+), 43 deletions(-) (limited to 'src/main') 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 afea502f..db44ff25 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,7 +45,6 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; 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; @@ -54,6 +53,8 @@ import java.util.Map; public class MinionHelperOverlay { private final ResourceLocation minionOverlayImage = new ResourceLocation("notenoughupdates:minion_overlay.png"); + private final ResourceLocation greenCheckImage = new ResourceLocation("notenoughupdates:dungeon_map/green_check.png"); + private final ResourceLocation whiteCheckImage = new ResourceLocation("notenoughupdates:dungeon_map/white_check.png"); private final MinionHelperManager manager; private final MinionHelperOverlayHover hover; @@ -147,6 +148,30 @@ public class MinionHelperOverlay { event.setCanceled(true); } } + checkToggleClick(); + } + + private void checkToggleClick() { + GuiScreen gui = Minecraft.getMinecraft().currentScreen; + if (!(gui instanceof GuiChest)) return; + + int xSize = ((AccessorGuiContainer) gui).getXSize(); + int guiLeft = ((AccessorGuiContainer) gui).getGuiLeft(); + int guiTop = ((AccessorGuiContainer) gui).getGuiTop(); + + int x = guiLeft + xSize + 4 + 149 - 3; + int y = guiTop + 109 - 3; + + 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; + + if (mouseX > x && mouseX < x + 16 && + mouseY > y && mouseY < y + 16) { + toggleShowAvailable(); + } } @SubscribeEvent @@ -188,23 +213,20 @@ public class MinionHelperOverlay { GL11.glColor4f(1, 1, 1, 1); GlStateManager.disableLighting(); Utils.drawTexturedRect(guiLeft + xSize + 4, guiTop, 168, 128, 0, 1f, 0, 1f, GL11.GL_NEAREST); + if (showOnlyAvailable) { + minecraft.getTextureManager().bindTexture(greenCheckImage); + } else { + minecraft.getTextureManager().bindTexture(whiteCheckImage); + } + Utils.drawTexturedRect(guiLeft + xSize + 4 + 149, guiTop + 109, 10, 10, 0, 1f, 0, 1f, GL11.GL_NEAREST); int a = guiLeft + xSize + 4; - FontRenderer fontRendererObj = minecraft.fontRendererObj; - int i = 0; int y = 0; + FontRenderer fontRendererObj = minecraft.fontRendererObj; for (Map.Entry entry : renderMap.entrySet()) { String line = entry.getKey(); - OverviewLine overviewLine = entry.getValue(); - String prefix = ""; - if (overviewLine instanceof Minion) { - Minion minion = (Minion) overviewLine; - if (minion == hover.getLastHovered()) { - prefix = "§e"; - } - } - fontRendererObj.drawString(prefix + line, a + 6, guiTop + 6 + y, -1, false); + fontRendererObj.drawString(line, a + 6, guiTop + 6 + y, -1, false); i++; if (i == 2) { y += 15; @@ -236,9 +258,10 @@ public class MinionHelperOverlay { LinkedHashMap renderMap ) { int neededForNextSlot = manager.getNeedForNextSlot(); - String color = showOnlyAvailable ? "§e" : "§c"; + //TODO jani + String color = "§8"; if (neededForNextSlot == -1) { - renderMap.put(color + "Next slot in: ?", new OverviewText(Collections.emptyList(), () -> {})); + renderMap.put(color + "Next slot: ?", new OverviewText(Collections.emptyList(), () -> {})); return; } @@ -250,26 +273,15 @@ public class MinionHelperOverlay { if (index == neededForNextSlot) break; } String format = manager.getPriceCalculation().formatCoins(priceNeeded); - String text = color + "Next slot in: §b" + neededForNextSlot + " §8- " + format; + //TODO jani + String text = color + "Next slot: §3" + neededForNextSlot + " minions §8(" + format + "§8)"; renderMap.put(text, new OverviewText(Collections.emptyList(), () -> {})); } private void addTitle(Map prices, LinkedHashMap renderMap) { - String name; - String hoverText; - if (prices.isEmpty()) { - name = (showOnlyAvailable ? "No minion obtainable!" : "§aAll minions collected!"); - hoverText = "No minions to craft available!"; - } else { - name = (showOnlyAvailable ? "Obtainable" : "All") + ": " + prices.size(); - if (showOnlyAvailable) { - hoverText = "There are " + prices.size() + " more minions in total!"; - } else { - hoverText = "You can craft " + prices.size() + " more minions!"; - } - } - String toggleText = "§eClick to " + (showOnlyAvailable ? "show" : "hide") + " minion upgrades without requirements"; - renderMap.put("§e" + name, new OverviewText(Arrays.asList(hoverText, "", toggleText), this::toggleShowAvailable)); + //TODO jani + String name = "§8" + prices.size() + (showOnlyAvailable ? " craftable" : "") + " minions "; + renderMap.put(name, new OverviewText(Collections.emptyList(), () -> {})); } private void addMinions(Map prices, LinkedHashMap renderMap) { @@ -289,9 +301,9 @@ public class MinionHelperOverlay { displayName = displayName.replace(" Minion", ""); String format = manager.getPriceCalculation().calculateUpgradeCostsFormat(minion, true); format = format.replace(" coins", ""); - String requirementFormat = !minion.doesMeetRequirements() ? "§7§o" : ""; + String requirementFormat = minion.doesMeetRequirements() ? "§9" : "§c"; renderMap.put( - requirementFormat + displayName + " " + minion.getTier() + " §r§8- " + format, + requirementFormat + displayName + " " + minion.getTier() + " §8- " + format, minion ); } @@ -369,4 +381,8 @@ public class MinionHelperOverlay { public void setTopLeft(int[] topLeft) { this.topLeft = topLeft; } + + public boolean isShowOnlyAvailable() { + return showOnlyAvailable; + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlayHover.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlayHover.java index 5cfa14ae..249c0324 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlayHover.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlayHover.java @@ -32,8 +32,10 @@ import io.github.moulberry.notenoughupdates.miscgui.minionhelper.requirements.Re import io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources.CraftingSource; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources.MinionSource; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources.NpcSource; +import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.gui.inventory.GuiChest; import net.minecraft.client.renderer.GlStateManager; @@ -49,7 +51,6 @@ public class MinionHelperOverlayHover { private final MinionHelperOverlay overlay; private final MinionHelperManager manager; - private Minion lastHovered = null; public MinionHelperOverlayHover(MinionHelperOverlay overlay, MinionHelperManager manager) { this.overlay = overlay; @@ -57,8 +58,6 @@ public class MinionHelperOverlayHover { } void renderHover(LinkedHashMap renderMap) { - lastHovered = null; - if (!(Minecraft.getMinecraft().currentScreen instanceof GuiChest)) return; final ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); @@ -79,6 +78,57 @@ public class MinionHelperOverlayHover { ); GlStateManager.popMatrix(); } + + renderToggleButton(); + } + + private void renderToggleButton() { + GuiScreen gui = Minecraft.getMinecraft().currentScreen; + if (!(gui instanceof GuiChest)) return; + + int xSize = ((AccessorGuiContainer) gui).getXSize(); + int guiLeft = ((AccessorGuiContainer) gui).getGuiLeft(); + int guiTop = ((AccessorGuiContainer) gui).getGuiTop(); + + int x = guiLeft + xSize + 4 + 149 - 3; + int y = guiTop + 109 - 3; + + 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; + boolean showOnlyAvailable = overlay.isShowOnlyAvailable(); + + List list = new ArrayList<>(); + + //TODO jani + if (showOnlyAvailable) { + list.add("§aFilter enabled!"); + list.add("§7Only show minions that can be"); + list.add("§7crafted and meet requirements"); + } else { + list.add("§cFilter disabled!"); + list.add("§7Show all minions. §cRed ones §7have"); + list.add("§7missing requirements "); + } + + list.add(""); + list.add("§eClick to toggle!"); + + if (mouseX > x && mouseX < x + 16 && + mouseY > y && mouseY < y + 16) { + + GlStateManager.pushMatrix(); + GlStateManager.scale(2f / scaledresolution.getScaleFactor(), 2f / scaledresolution.getScaleFactor(), 1); + Utils.drawHoveringText(list, + mouseX * scaledresolution.getScaleFactor() / 2, + mouseY * scaledresolution.getScaleFactor() / 2, + scaledWidth * scaledresolution.getScaleFactor() / 2, + scaledHeight * scaledresolution.getScaleFactor() / 2, -1, Minecraft.getMinecraft().fontRendererObj + ); + GlStateManager.popMatrix(); + } } private List getTooltip(OverviewLine overviewLine) { @@ -94,7 +144,6 @@ public class MinionHelperOverlayHover { if (minion.getCustomSource() != null) { minionSource = minion.getCustomSource(); } - lastHovered = minion; String displayName = minion.getDisplayName(); lines.add("§9" + displayName + " " + minion.getTier()); List requirements = manager.getRequirementsManager().getRequirements(minion); @@ -134,7 +183,7 @@ public class MinionHelperOverlayHover { } lines.add(""); - lines.add("§eClick to view recipe"); + lines.add("§eClick to view recipe!"); } return lines; } @@ -168,7 +217,7 @@ public class MinionHelperOverlayHover { String reputationName = StringUtils.firstUpperLetter(reputationType.toLowerCase()); String havingFormat = Utils.formatNumberWithDots(having); String needFormat = Utils.formatNumberWithDots(need); - description = "Reputation: §c" + havingFormat + "§8/§c" + needFormat + " §7" + reputationName + " Reputation"; + description = "Reputation: §c" + havingFormat + "§8/§c" + needFormat + " §7" + reputationName + " Reputation"; } } @@ -205,8 +254,4 @@ public class MinionHelperOverlayHover { } return allItems; } - - public Minion getLastHovered() { - return lastHovered; - } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/util/MinionHelperPriceCalculation.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/util/MinionHelperPriceCalculation.java index 1e608a00..28ef0397 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/util/MinionHelperPriceCalculation.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/util/MinionHelperPriceCalculation.java @@ -67,7 +67,7 @@ public class MinionHelperPriceCalculation { if (upgradeOnly) { if (minion.getCustomSource() != null) { - return "§f" + (minion.getCustomSource()).getSourceName(); + return (minion.getCustomSource()).getSourceName(); } } diff --git a/src/main/resources/assets/notenoughupdates/minion_overlay.png b/src/main/resources/assets/notenoughupdates/minion_overlay.png index d5d846a2..47fe386c 100644 Binary files a/src/main/resources/assets/notenoughupdates/minion_overlay.png and b/src/main/resources/assets/notenoughupdates/minion_overlay.png differ -- cgit