From 3c477d1fe12d959fd0c6578bdb4ed1e3726e5d0b Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 30 Jul 2022 23:01:24 +0200 Subject: moved packages --- .../notenoughupdates/NotEnoughUpdates.java | 6 - .../miscgui/minionhelper/MinionHelperManager.java | 4 + .../miscgui/minionhelper/MinionHelperOverlay.java | 241 -------------------- .../minionhelper/MinionHelperOverlayHover.java | 161 -------------- .../minionhelper/MinionHelperPriceCalculation.java | 164 -------------- .../MinionHelperRequirementsManager.java | 117 ---------- .../miscgui/minionhelper/MinionHelperTooltips.java | 88 -------- .../loaders/MinionHelperChatLoader.java | 1 - .../loaders/MinionHelperInventoryLoader.java | 2 - .../minionhelper/render/MinionHelperOverlay.java | 243 +++++++++++++++++++++ .../render/MinionHelperOverlayHover.java | 163 ++++++++++++++ .../minionhelper/render/MinionHelperTooltips.java | 89 ++++++++ .../render/renderables/RenderableObject.java | 23 ++ .../render/renderables/RenderableText.java | 40 ++++ .../minionhelper/renderables/RenderableObject.java | 23 -- .../minionhelper/renderables/RenderableText.java | 40 ---- .../miscgui/minionhelper/sources/MinionSource.java | 2 +- .../util/MinionHelperPriceCalculation.java | 166 ++++++++++++++ .../util/MinionHelperRequirementsManager.java | 120 ++++++++++ 19 files changed, 849 insertions(+), 844 deletions(-) delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperOverlay.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperOverlayHover.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperPriceCalculation.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperRequirementsManager.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperTooltips.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlay.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlayHover.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperTooltips.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/renderables/RenderableObject.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/renderables/RenderableText.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/renderables/RenderableObject.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/renderables/RenderableText.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/util/MinionHelperPriceCalculation.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/util/MinionHelperRequirementsManager.java (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index 17886a04..37bf160f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -61,12 +61,6 @@ import io.github.moulberry.notenoughupdates.miscgui.InventoryStorageSelector; import io.github.moulberry.notenoughupdates.miscgui.SignCalculator; import io.github.moulberry.notenoughupdates.miscgui.TrophyRewardOverlay; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.loaders.MinionHelperApiLoader; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.loaders.MinionHelperChatLoader; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.loaders.MinionHelperInventoryLoader; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperOverlay; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.loaders.MinionHelperRepoLoader; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperTooltips; import io.github.moulberry.notenoughupdates.mixins.AccessorMinecraft; import io.github.moulberry.notenoughupdates.options.NEUConfig; import io.github.moulberry.notenoughupdates.overlays.FuelBar; 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 53fb06d3..096a217b 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 @@ -24,6 +24,10 @@ import io.github.moulberry.notenoughupdates.miscgui.minionhelper.loaders.MinionH import io.github.moulberry.notenoughupdates.miscgui.minionhelper.loaders.MinionHelperChatLoader; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.loaders.MinionHelperInventoryLoader; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.loaders.MinionHelperRepoLoader; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.render.MinionHelperOverlay; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.render.MinionHelperTooltips; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.util.MinionHelperPriceCalculation; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.util.MinionHelperRequirementsManager; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.inventory.Container; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperOverlay.java deleted file mode 100644 index b0daad9d..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperOverlay.java +++ /dev/null @@ -1,241 +0,0 @@ -/* - * 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 . - */ - -package io.github.moulberry.notenoughupdates.miscgui.minionhelper; - -import com.google.common.collect.Lists; -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.miscgui.TrophyRewardOverlay; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.renderables.RenderableObject; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.renderables.RenderableText; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources.MinionSource; -import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer; -import io.github.moulberry.notenoughupdates.util.NotificationHandler; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.Gui; -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; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.client.event.GuiOpenEvent; -import net.minecraftforge.client.event.GuiScreenEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.GL11; - -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; - -public class MinionHelperOverlay { - private final MinionHelperManager manager; - private final MinionHelperOverlayHover hover; - - private LinkedHashMap cacheRenderMapShift = null; - private LinkedHashMap cacheRenderMapNoShift = null; - - public MinionHelperOverlay(MinionHelperManager manager) { - this.manager = manager; - hover = new MinionHelperOverlayHover(this, manager); - } - - @SubscribeEvent - public void onGuiOpen(GuiOpenEvent event) { - resetCache(); - } - - public void resetCache() { - cacheRenderMapShift = null; - cacheRenderMapNoShift = null; - } - - //TODO use different texture - public final ResourceLocation auctionProfitImage = new ResourceLocation("notenoughupdates:auction_profit.png"); - - @SubscribeEvent - public void onDrawBackground(GuiScreenEvent.BackgroundDrawnEvent event) { - if (!manager.inCraftedMinionsInventory()) return; - if (!manager.isReadyToUse()) return; - - if (manager.getApi().isNotifyNoCollectionApi()) { - NotificationHandler.displayNotification(Lists.newArrayList( - "", - "§cCollection API is disabled!", - "§cMinion Helper will not filter minions that", - "§cdo not meet the collection requirements!" - ), false, true); - //TODO add tutorial how to enable collection api - manager.getApi().setNotifyNoCollectionApi(false); - } - - LinkedHashMap renderMap = getRenderMap(); - - hover.renderHover(renderMap); - render(event, renderMap); - } - - @SubscribeEvent - public void onMouseClick(GuiScreenEvent.MouseInputEvent.Pre event) { - if (!manager.inCraftedMinionsInventory()) return; - if (!manager.isReadyToUse()) return; - if (!Mouse.getEventButtonState()) return; - - RenderableObject mouseObject = getObjectOverMouse(getRenderMap()); - - if (mouseObject != null) { - if (mouseObject instanceof MinionSource) { - event.setCanceled(true); - Minion minion = ((MinionSource) mouseObject).getMinion(); - NotEnoughUpdates.INSTANCE.manager.displayGuiItemRecipe(minion.getInternalName()); - } - } - } - - private Map getMissing(boolean shift) { - Map prices = new HashMap<>(); - for (Minion minion : manager.getAllMinions().values()) { - - if (!minion.doesMeetRequirements() && !shift) continue; - if (!minion.isCrafted()) { - long price = manager.getPriceCalculation().calculateUpgradeCosts(minion.getMinionSource(), true); - prices.put(minion, price); - } - } - return prices; - } - - private void render(GuiScreenEvent.BackgroundDrawnEvent event, Map renderMap) { - Minecraft minecraft = Minecraft.getMinecraft(); - if (!(Minecraft.getMinecraft().currentScreen instanceof GuiChest)) return; - Gui gui = event.gui; - int xSize = ((AccessorGuiContainer) gui).getXSize(); - int guiLeft = ((AccessorGuiContainer) gui).getGuiLeft(); - int guiTop = ((AccessorGuiContainer) gui).getGuiTop(); - minecraft.getTextureManager().bindTexture(auctionProfitImage); - GL11.glColor4f(1, 1, 1, 1); - GlStateManager.disableLighting(); - Utils.drawTexturedRect(guiLeft + xSize + 4, guiTop, 180, 101, 0, 180 / 256f, 0, 101 / 256f, GL11.GL_NEAREST); - - int a = guiLeft + xSize + 4; - FontRenderer fontRendererObj = minecraft.fontRendererObj; - - int extra = 0; - for (Map.Entry entry : renderMap.entrySet()) { - String line = entry.getKey(); - RenderableObject renderableObject = entry.getValue(); - String prefix = ""; - if (renderableObject instanceof MinionSource) { - Minion minion = ((MinionSource) renderableObject).getMinion(); - if (minion == hover.getLastHovered()) { - prefix = "§e"; - } - } - fontRendererObj.drawString(prefix + line, a + 6, guiTop + 6 + extra, -1, false); - extra += 10; - } - } - - private LinkedHashMap getRenderMap() { - boolean shift = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT); - if (!shift) { - if (cacheRenderMapNoShift != null) return cacheRenderMapNoShift; - } else { - if (cacheRenderMapShift != null) return cacheRenderMapShift; - } - Map prices = getMissing(shift); - - LinkedHashMap renderMap = new LinkedHashMap<>(); - if (prices.isEmpty()) { - renderMap.put("all minions collected!", new RenderableText("You have all the minions available collected! :)")); - } else { - renderMap.put( - "To craft: " + prices.size(), - //TODO formulierung - new RenderableText("you can craft that many more minions!") - ); - int i = 0; - - //TODO change - int max = 20; - - Map 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()); - } - continue; - } - displayName = displayName.replace(" Minion", ""); - String format = manager.getPriceCalculation().calculateUpgradeCostsFormat(minion.getMinionSource(), true); - String requirementFormat = !minion.doesMeetRequirements() ? "§7§o" : ""; - renderMap.put( - requirementFormat + displayName + "§r " + requirementFormat + minion.getTier() + " §r§8- " + format, - minion.getMinionSource() - ); - - i++; - if (i == max) break; - } - } - - if (shift) { - cacheRenderMapShift = renderMap; - } else { - cacheRenderMapNoShift = renderMap; - } - - return renderMap; - } - - RenderableObject getObjectOverMouse(LinkedHashMap renderMap) { - GuiScreen gui = Minecraft.getMinecraft().currentScreen; - if (!(gui instanceof GuiChest)) return null; - - int xSize = ((AccessorGuiContainer) gui).getXSize(); - int guiLeft = ((AccessorGuiContainer) gui).getGuiLeft(); - int guiTop = ((AccessorGuiContainer) gui).getGuiTop(); - - int x = guiLeft + xSize + 4; - int y = guiTop; - - 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 index = 0; - for (RenderableObject renderableObject : renderMap.values()) { - - if (mouseX > x && mouseX < x + 130 && - mouseY > y + index && mouseY < y + 13 + index) { - return renderableObject; - } - index += 10; - } - - return null; - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperOverlayHover.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperOverlayHover.java deleted file mode 100644 index 8bc04731..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperOverlayHover.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * 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 . - */ - -package io.github.moulberry.notenoughupdates.miscgui.minionhelper; - -import com.google.common.collect.ArrayListMultimap; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.renderables.RenderableObject; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.renderables.RenderableText; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.requirements.CollectionRequirement; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.requirements.MinionRequirement; -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.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.client.gui.inventory.GuiChest; -import net.minecraft.client.renderer.GlStateManager; -import org.lwjgl.input.Mouse; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -public class MinionHelperOverlayHover { - - private final MinionHelperOverlay overlay; - private final MinionHelperManager manager; - private Minion lastHovered = null; - - public MinionHelperOverlayHover(MinionHelperOverlay overlay, MinionHelperManager manager) { - this.overlay = overlay; - this.manager = manager; - } - - void renderHover(LinkedHashMap renderMap) { - lastHovered = null; - - if (!(Minecraft.getMinecraft().currentScreen instanceof GuiChest)) 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; - - RenderableObject mouseObject = overlay.getObjectOverMouse(renderMap); - if (mouseObject != null) { - GlStateManager.pushMatrix(); - GlStateManager.scale(2f / scaledresolution.getScaleFactor(), 2f / scaledresolution.getScaleFactor(), 1); - Utils.drawHoveringText(getTooltip(mouseObject), - 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(RenderableObject renderableObject) { - List lines = new ArrayList<>(); - - if (renderableObject instanceof RenderableText) { - RenderableText renderableText = (RenderableText) renderableObject; - lines.addAll(renderableText.getLines()); - } else if (renderableObject instanceof MinionSource) { - MinionSource minionSource = (MinionSource) renderableObject; - - Minion minion = minionSource.getMinion(); - lastHovered = minion; - String displayName = minion.getDisplayName(); - lines.add("§9" + displayName + " " + minion.getTier()); - List requirements = manager.getRequirementsManager().getRequirements(minionSource.getMinion()); - if (!requirements.isEmpty()) { - for (MinionRequirement requirement : requirements) { - //TODO maybe change the §7 color - String color = manager.getRequirementsManager().meetRequirement(minion, requirement) ? "§a" : "§7"; - if (requirement instanceof CollectionRequirement && manager.getApi().isCollectionApiDisabled()) { - color = "§cAPI DISABLED! §7"; - } - lines.add(" §8- " + color + requirement.printDescription()); - } - } else { - lines.add("§cNo requirements loaded!"); - } - - if (minionSource instanceof CraftingSource) { - CraftingSource craftingSource = (CraftingSource) minionSource; - lines.add(""); - String format = manager.getPriceCalculation().calculateUpgradeCostsFormat(craftingSource, true); - if (minion.getTier() == 1) { - lines.add("§7Full crafting costs: " + format); - } else { - lines.add("§7Upgrade costs: " + format); - } - formatItems(lines, grabAllItems(craftingSource.getItems())); - - } else if (minionSource instanceof NpcSource) { - NpcSource npcSource = (NpcSource) minionSource; - String npcName = npcSource.getNpcName(); - lines.add(""); - lines.add("§7Buy from: §9" + npcName + " (NPC)"); - lines.add(""); - lines.add("§7Buy costs: " + manager.getPriceCalculation().calculateUpgradeCostsFormat(npcSource, true)); - lines.add(" §8- " + manager.getPriceCalculation().formatCoins(npcSource.getCoins())); - formatItems(lines, grabAllItems(npcSource.getItems())); - } - - lines.add(""); - lines.add("§eClick to view recipe"); - } - return lines; - } - - private void formatItems(List lines, Map allItems) { - for (Map.Entry entry : allItems.entrySet()) { - String internalName = entry.getKey(); - String name = manager.getRepo().getDisplayName(internalName); - - int amount = entry.getValue(); - String amountText = amount != 1 ? amount + "§7x " : ""; - String price = manager.getPriceCalculation().formatCoins( - manager.getPriceCalculation().getPrice(internalName) * amount); - lines.add(" §8- §a" + amountText + "§f" + name + " " + price); - } - } - - private Map grabAllItems(ArrayListMultimap multimap) { - Map allItems = new HashMap<>(); - for (Map.Entry entry : multimap.entries()) { - String name = entry.getKey(); - int amount = entry.getValue(); - amount = allItems.getOrDefault(name, 0) + amount; - allItems.put(name, amount); - } - return allItems; - } - - public Minion getLastHovered() { - return lastHovered; - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperPriceCalculation.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperPriceCalculation.java deleted file mode 100644 index 8505ab0b..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperPriceCalculation.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * 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 . - */ - -package io.github.moulberry.notenoughupdates.miscgui.minionhelper; - -import com.google.common.collect.ArrayListMultimap; -import com.google.gson.JsonObject; -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources.CraftingSource; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources.CustomSource; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources.MinionSource; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources.NpcSource; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraftforge.client.event.GuiOpenEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class MinionHelperPriceCalculation { - - private final MinionHelperManager manager; - private final Map upgradeCostFormatCache = new HashMap<>(); - private final Map fullCostFormatCache = new HashMap<>(); - //TODO maybe change logic with 0 coins later or stuff - private final List cheapItems = Arrays.asList( - "WOOD_SWORD", - "WOOD_HOE", - "WOOD_AXE", - "WOOD_PICKAXE", - "WOOD_SPADE", - "FISHING_ROD", - "SKYBLOCK_PELT" - ); - - public MinionHelperPriceCalculation(MinionHelperManager manager) { - this.manager = manager; - } - - @SubscribeEvent - public void onGuiOpen(GuiOpenEvent event) { - upgradeCostFormatCache.clear(); - fullCostFormatCache.clear(); - } - - public String calculateUpgradeCostsFormat(MinionSource source, boolean upgradeOnly) { - if (source == null) return "§c?"; - String internalName = source.getMinion().getInternalName(); - if (upgradeOnly) { - if (upgradeCostFormatCache.containsKey(internalName)) { - upgradeCostFormatCache.get(internalName); - } - } else { - if (fullCostFormatCache.containsKey(internalName)) { - fullCostFormatCache.get(internalName); - } - } - - if (source instanceof CustomSource) { - return "§f" + ((CustomSource) source).getCustomSource(); - } - - long costs = calculateUpgradeCosts(source, upgradeOnly); - String result = formatCoins(costs, !upgradeOnly ? "§o" : ""); - - if (source instanceof NpcSource) { - ArrayListMultimap items = ((NpcSource) source).getItems(); - if (items.containsKey("SKYBLOCK_PELT")) { - int amount = items.get("SKYBLOCK_PELT").get(0); - result += " §7+ §5" + amount + " Pelts"; - } - } - - if (upgradeOnly) { - upgradeCostFormatCache.put(internalName, result); - } else { - fullCostFormatCache.put(internalName, result); - } - - return result; - } - - public long calculateUpgradeCosts(MinionSource source, boolean upgradeOnly) { - if (source instanceof CraftingSource) { - CraftingSource craftingSource = (CraftingSource) source; - return getCosts(source, upgradeOnly, craftingSource.getItems()); - - } else if (source instanceof NpcSource) { - NpcSource npcSource = (NpcSource) source; - long upgradeCost = getCosts(source, upgradeOnly, npcSource.getItems()); - long coins = npcSource.getCoins(); - upgradeCost += coins; - - return upgradeCost; - } - - return 0; - } - - private long getCosts(MinionSource source, boolean upgradeOnly, ArrayListMultimap items) { - long upgradeCost = 0; - for (Map.Entry entry : items.entries()) { - String internalName = entry.getKey(); - long price = getPrice(internalName); - int amount = entry.getValue(); - upgradeCost += price * amount; - } - if (!upgradeOnly) { - Minion parent = source.getMinion().getParent(); - if (parent != null) { - upgradeCost += calculateUpgradeCosts(parent.getMinionSource(), false); - } - } - return upgradeCost; - } - - public long getPrice(String internalName) { - JsonObject bazaarInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalName); - if (bazaarInfo == null) { - if (internalName.contains("_GENERATOR_")) { - return calculateUpgradeCosts(manager.getMinionById(internalName).getMinionSource(), false); - } else { - if (!cheapItems.contains(internalName)) { - return (long) NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAvgBin(internalName); - } - } - return 0; - } - - //TODO use average bazaar price? - if (!bazaarInfo.has("curr_sell")) { - System.err.println("curr_sell does not exist for '" + internalName + "'"); - return 0; - } - return (long) bazaarInfo.get("curr_sell").getAsDouble(); - } - - public String formatCoins(long coins) { - return formatCoins(coins, ""); - } - - public String formatCoins(long coins, String extraFormat) { - String format = Utils.shortNumberFormat(coins, 0); - return "§6" + extraFormat + format + " coins"; - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperRequirementsManager.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperRequirementsManager.java deleted file mode 100644 index 4dc1f578..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperRequirementsManager.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * 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 . - */ - -package io.github.moulberry.notenoughupdates.miscgui.minionhelper; - -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.requirements.CollectionRequirement; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.requirements.CustomRequirement; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.requirements.MinionRequirement; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.requirements.ReputationRequirement; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.requirements.SlayerRequirement; -import io.github.moulberry.notenoughupdates.util.Utils; - -import java.util.Collections; -import java.util.List; -import java.util.Map; - -public class MinionHelperRequirementsManager { - - private final MinionHelperManager manager; - - public MinionHelperRequirementsManager(MinionHelperManager manager) { - this.manager = manager; - } - - public List getRequirements(Minion minion) { - if (!minion.getRequirements().isEmpty()) { - return minion.getRequirements(); - } - - Minion parent = minion.getParent(); - if (parent != null) { - return getRequirements(parent); - } - - return Collections.emptyList(); - } - - public boolean meetAllRequirements(Minion minion) { - List list = getRequirements(minion); - for (MinionRequirement requirement : list) { - if (!meetRequirement(minion, requirement)) { - return false; - } - } - - return true; - } - - public boolean meetRequirement(Minion minion, MinionRequirement requirement) { - ApiData apiData = manager.getApi().getApiData(); - if (apiData == null) return false; - - if (requirement instanceof CollectionRequirement) { - if (apiData.isCollectionApiDisabled()) return true; - - CollectionRequirement collectionRequirement = (CollectionRequirement) requirement; - String collection = collectionRequirement.getCollection(); - String internalName = manager.formatInternalName(collection); - - int need = collectionRequirement.getLevel(); - Map highestCollectionTier = apiData.getHighestCollectionTier(); - if (highestCollectionTier.containsKey(internalName)) { - int has = highestCollectionTier.get(internalName); - - return has >= need; - } - - } else if (requirement instanceof SlayerRequirement) { - SlayerRequirement slayerRequirement = (SlayerRequirement) requirement; - String slayer = slayerRequirement.getSlayer(); - int need = slayerRequirement.getLevel(); - Map slayerTiers = apiData.getSlayerTiers(); - if (slayerTiers.containsKey(slayer)) { - return slayerTiers.get(slayer) >= need; - } - - } else if (requirement instanceof ReputationRequirement) { - ReputationRequirement reputationRequirement = (ReputationRequirement) requirement; - int need = reputationRequirement.getReputation(); - String reputationType = reputationRequirement.getReputationType(); - if (reputationType.equals("BARBARIAN")) { - return apiData.getBarbariansReputation() >= need; - } else if (reputationType.equals("MAGE")) { - return apiData.getMagesReputation() >= need; - } else { - Utils.addChatMessage("§c[NEU] Minion Helper: Unknown reputation type: '" + reputationType + "'"); - return false; - } - } else if (requirement instanceof CustomRequirement) { - return minion.isCrafted(); - } - - return false; - } - - public void reloadRequirements() { - for (Minion minion : manager.getAllMinions().values()) { - minion.setMeetRequirements(meetAllRequirements(minion)); - } - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperTooltips.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperTooltips.java deleted file mode 100644 index ee250b89..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperTooltips.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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 . - */ - -package io.github.moulberry.notenoughupdates.miscgui.minionhelper; - -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.core.util.StringUtils; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources.MinionSource; -import io.github.moulberry.notenoughupdates.util.ItemUtils; -import net.minecraft.item.ItemStack; -import net.minecraftforge.event.entity.player.ItemTooltipEvent; -import net.minecraftforge.fml.common.eventhandler.EventPriority; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import org.lwjgl.input.Keyboard; - -import java.util.List; - -public class MinionHelperTooltips { - private final MinionHelperManager manager; - private boolean pressedShiftLast = false; - private boolean showFullCost = false; - - public MinionHelperTooltips(MinionHelperManager manager) { - this.manager = manager; - } - - @SubscribeEvent(priority = EventPriority.LOW) - public void onItemTooltip(ItemTooltipEvent event) { - if (!manager.inCraftedMinionsInventory()) return; - if (!manager.isReadyToUse()) return; - - boolean shift = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT); - if (!pressedShiftLast && shift) { - showFullCost = !showFullCost; - } - pressedShiftLast = shift; - - ItemStack itemStack = event.itemStack; - if (itemStack == null) return; - String displayName = itemStack.getDisplayName(); - if (!displayName.endsWith(" Minion")) return; - displayName = StringUtils.cleanColour(displayName); - - List lore = ItemUtils.getLore(itemStack); - if (lore.get(0).equals("§7You haven't crafted this minion.")) return; - - int index = 0; - for (String line : lore) { - index++; - if (!line.contains("Tier")) continue; - - Minion minion = manager.getMinionByName(displayName, index); - if (minion == null) { - System.err.println("minion is null for displayName '" + displayName + "' and tier " + index); - continue; - } - MinionSource minionSource = minion.getMinionSource(); - if (minionSource == null) { - System.err.println("minionSource is null for " + minion.getInternalName()); - continue; - } - String format = manager.getPriceCalculation().calculateUpgradeCostsFormat(minionSource, !showFullCost); - event.toolTip.set(index, line + " §8- " + format); - } - - if (showFullCost) { - event.toolTip.add("§8[Press SHIFT to show upgrade costs]"); - } else { - event.toolTip.add("§8[Press SHIFT to show full costs]"); - } - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperChatLoader.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperChatLoader.java index 36f6b515..e3189fb3 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperChatLoader.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperChatLoader.java @@ -22,7 +22,6 @@ package io.github.moulberry.notenoughupdates.miscgui.minionhelper.loaders; import io.github.moulberry.notenoughupdates.core.util.StringUtils; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.Minion; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperOverlay; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraftforge.client.event.ClientChatReceivedEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; 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 b8943c38..5e495889 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 @@ -23,9 +23,7 @@ import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.util.StringUtils; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.Minion; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperOverlay; import io.github.moulberry.notenoughupdates.util.ItemUtils; -import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.inventory.Container; import net.minecraft.inventory.ContainerChest; 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 new file mode 100644 index 00000000..b1d12fe0 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlay.java @@ -0,0 +1,243 @@ +/* + * 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 . + */ + +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.miscgui.TrophyRewardOverlay; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.Minion; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.render.renderables.RenderableObject; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.render.renderables.RenderableText; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources.MinionSource; +import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer; +import io.github.moulberry.notenoughupdates.util.NotificationHandler; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; +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; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.event.GuiOpenEvent; +import net.minecraftforge.client.event.GuiScreenEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +public class MinionHelperOverlay { + private final MinionHelperManager manager; + private final MinionHelperOverlayHover hover; + + private LinkedHashMap cacheRenderMapShift = null; + private LinkedHashMap cacheRenderMapNoShift = null; + + public MinionHelperOverlay(MinionHelperManager manager) { + this.manager = manager; + hover = new MinionHelperOverlayHover(this, manager); + } + + @SubscribeEvent + public void onGuiOpen(GuiOpenEvent event) { + resetCache(); + } + + public void resetCache() { + cacheRenderMapShift = null; + cacheRenderMapNoShift = null; + } + + //TODO use different texture + public final ResourceLocation auctionProfitImage = new ResourceLocation("notenoughupdates:auction_profit.png"); + + @SubscribeEvent + public void onDrawBackground(GuiScreenEvent.BackgroundDrawnEvent event) { + if (!manager.inCraftedMinionsInventory()) return; + if (!manager.isReadyToUse()) return; + + if (manager.getApi().isNotifyNoCollectionApi()) { + NotificationHandler.displayNotification(Lists.newArrayList( + "", + "§cCollection API is disabled!", + "§cMinion Helper will not filter minions that", + "§cdo not meet the collection requirements!" + ), false, true); + //TODO add tutorial how to enable collection api + manager.getApi().setNotifyNoCollectionApi(false); + } + + LinkedHashMap renderMap = getRenderMap(); + + hover.renderHover(renderMap); + render(event, renderMap); + } + + @SubscribeEvent + public void onMouseClick(GuiScreenEvent.MouseInputEvent.Pre event) { + if (!manager.inCraftedMinionsInventory()) return; + if (!manager.isReadyToUse()) return; + if (!Mouse.getEventButtonState()) return; + + RenderableObject mouseObject = getObjectOverMouse(getRenderMap()); + + if (mouseObject != null) { + if (mouseObject instanceof MinionSource) { + event.setCanceled(true); + Minion minion = ((MinionSource) mouseObject).getMinion(); + NotEnoughUpdates.INSTANCE.manager.displayGuiItemRecipe(minion.getInternalName()); + } + } + } + + private Map getMissing(boolean shift) { + Map prices = new HashMap<>(); + for (Minion minion : manager.getAllMinions().values()) { + + if (!minion.doesMeetRequirements() && !shift) continue; + if (!minion.isCrafted()) { + long price = manager.getPriceCalculation().calculateUpgradeCosts(minion.getMinionSource(), true); + prices.put(minion, price); + } + } + return prices; + } + + private void render(GuiScreenEvent.BackgroundDrawnEvent event, Map renderMap) { + Minecraft minecraft = Minecraft.getMinecraft(); + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiChest)) return; + Gui gui = event.gui; + int xSize = ((AccessorGuiContainer) gui).getXSize(); + int guiLeft = ((AccessorGuiContainer) gui).getGuiLeft(); + int guiTop = ((AccessorGuiContainer) gui).getGuiTop(); + minecraft.getTextureManager().bindTexture(auctionProfitImage); + GL11.glColor4f(1, 1, 1, 1); + GlStateManager.disableLighting(); + Utils.drawTexturedRect(guiLeft + xSize + 4, guiTop, 180, 101, 0, 180 / 256f, 0, 101 / 256f, GL11.GL_NEAREST); + + int a = guiLeft + xSize + 4; + FontRenderer fontRendererObj = minecraft.fontRendererObj; + + int extra = 0; + for (Map.Entry entry : renderMap.entrySet()) { + String line = entry.getKey(); + RenderableObject renderableObject = entry.getValue(); + String prefix = ""; + if (renderableObject instanceof MinionSource) { + Minion minion = ((MinionSource) renderableObject).getMinion(); + if (minion == hover.getLastHovered()) { + prefix = "§e"; + } + } + fontRendererObj.drawString(prefix + line, a + 6, guiTop + 6 + extra, -1, false); + extra += 10; + } + } + + private LinkedHashMap getRenderMap() { + boolean shift = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT); + if (!shift) { + if (cacheRenderMapNoShift != null) return cacheRenderMapNoShift; + } else { + if (cacheRenderMapShift != null) return cacheRenderMapShift; + } + Map prices = getMissing(shift); + + LinkedHashMap renderMap = new LinkedHashMap<>(); + if (prices.isEmpty()) { + renderMap.put("all minions collected!", new RenderableText("You have all the minions available collected! :)")); + } else { + renderMap.put( + "To craft: " + prices.size(), + //TODO formulierung + new RenderableText("you can craft that many more minions!") + ); + int i = 0; + + //TODO change + int max = 20; + + Map 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()); + } + continue; + } + displayName = displayName.replace(" Minion", ""); + String format = manager.getPriceCalculation().calculateUpgradeCostsFormat(minion.getMinionSource(), true); + String requirementFormat = !minion.doesMeetRequirements() ? "§7§o" : ""; + renderMap.put( + requirementFormat + displayName + "§r " + requirementFormat + minion.getTier() + " §r§8- " + format, + minion.getMinionSource() + ); + + i++; + if (i == max) break; + } + } + + if (shift) { + cacheRenderMapShift = renderMap; + } else { + cacheRenderMapNoShift = renderMap; + } + + return renderMap; + } + + RenderableObject getObjectOverMouse(LinkedHashMap renderMap) { + GuiScreen gui = Minecraft.getMinecraft().currentScreen; + if (!(gui instanceof GuiChest)) return null; + + int xSize = ((AccessorGuiContainer) gui).getXSize(); + int guiLeft = ((AccessorGuiContainer) gui).getGuiLeft(); + int guiTop = ((AccessorGuiContainer) gui).getGuiTop(); + + int x = guiLeft + xSize + 4; + int y = guiTop; + + 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 index = 0; + for (RenderableObject renderableObject : renderMap.values()) { + + if (mouseX > x && mouseX < x + 130 && + mouseY > y + index && mouseY < y + 13 + index) { + return renderableObject; + } + index += 10; + } + + return null; + } +} 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 new file mode 100644 index 00000000..f04b5200 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlayHover.java @@ -0,0 +1,163 @@ +/* + * 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 . + */ + +package io.github.moulberry.notenoughupdates.miscgui.minionhelper.render; + +import com.google.common.collect.ArrayListMultimap; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.Minion; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.render.renderables.RenderableObject; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.render.renderables.RenderableText; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.requirements.CollectionRequirement; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.requirements.MinionRequirement; +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.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.gui.inventory.GuiChest; +import net.minecraft.client.renderer.GlStateManager; +import org.lwjgl.input.Mouse; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +public class MinionHelperOverlayHover { + + private final MinionHelperOverlay overlay; + private final MinionHelperManager manager; + private Minion lastHovered = null; + + public MinionHelperOverlayHover(MinionHelperOverlay overlay, MinionHelperManager manager) { + this.overlay = overlay; + this.manager = manager; + } + + void renderHover(LinkedHashMap renderMap) { + lastHovered = null; + + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiChest)) 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; + + RenderableObject mouseObject = overlay.getObjectOverMouse(renderMap); + if (mouseObject != null) { + GlStateManager.pushMatrix(); + GlStateManager.scale(2f / scaledresolution.getScaleFactor(), 2f / scaledresolution.getScaleFactor(), 1); + Utils.drawHoveringText(getTooltip(mouseObject), + 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(RenderableObject renderableObject) { + List lines = new ArrayList<>(); + + if (renderableObject instanceof RenderableText) { + RenderableText renderableText = (RenderableText) renderableObject; + lines.addAll(renderableText.getLines()); + } else if (renderableObject instanceof MinionSource) { + MinionSource minionSource = (MinionSource) renderableObject; + + Minion minion = minionSource.getMinion(); + lastHovered = minion; + String displayName = minion.getDisplayName(); + lines.add("§9" + displayName + " " + minion.getTier()); + List requirements = manager.getRequirementsManager().getRequirements(minionSource.getMinion()); + if (!requirements.isEmpty()) { + for (MinionRequirement requirement : requirements) { + //TODO maybe change the §7 color + String color = manager.getRequirementsManager().meetRequirement(minion, requirement) ? "§a" : "§7"; + if (requirement instanceof CollectionRequirement && manager.getApi().isCollectionApiDisabled()) { + color = "§cAPI DISABLED! §7"; + } + lines.add(" §8- " + color + requirement.printDescription()); + } + } else { + lines.add("§cNo requirements loaded!"); + } + + if (minionSource instanceof CraftingSource) { + CraftingSource craftingSource = (CraftingSource) minionSource; + lines.add(""); + String format = manager.getPriceCalculation().calculateUpgradeCostsFormat(craftingSource, true); + if (minion.getTier() == 1) { + lines.add("§7Full crafting costs: " + format); + } else { + lines.add("§7Upgrade costs: " + format); + } + formatItems(lines, grabAllItems(craftingSource.getItems())); + + } else if (minionSource instanceof NpcSource) { + NpcSource npcSource = (NpcSource) minionSource; + String npcName = npcSource.getNpcName(); + lines.add(""); + lines.add("§7Buy from: §9" + npcName + " (NPC)"); + lines.add(""); + lines.add("§7Buy costs: " + manager.getPriceCalculation().calculateUpgradeCostsFormat(npcSource, true)); + lines.add(" §8- " + manager.getPriceCalculation().formatCoins(npcSource.getCoins())); + formatItems(lines, grabAllItems(npcSource.getItems())); + } + + lines.add(""); + lines.add("§eClick to view recipe"); + } + return lines; + } + + private void formatItems(List lines, Map allItems) { + for (Map.Entry entry : allItems.entrySet()) { + String internalName = entry.getKey(); + String name = manager.getRepo().getDisplayName(internalName); + + int amount = entry.getValue(); + String amountText = amount != 1 ? amount + "§7x " : ""; + String price = manager.getPriceCalculation().formatCoins( + manager.getPriceCalculation().getPrice(internalName) * amount); + lines.add(" §8- §a" + amountText + "§f" + name + " " + price); + } + } + + private Map grabAllItems(ArrayListMultimap multimap) { + Map allItems = new HashMap<>(); + for (Map.Entry entry : multimap.entries()) { + String name = entry.getKey(); + int amount = entry.getValue(); + amount = allItems.getOrDefault(name, 0) + amount; + allItems.put(name, amount); + } + return allItems; + } + + public Minion getLastHovered() { + return lastHovered; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperTooltips.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperTooltips.java new file mode 100644 index 00000000..f18c6edc --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperTooltips.java @@ -0,0 +1,89 @@ +/* + * 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 . + */ + +package io.github.moulberry.notenoughupdates.miscgui.minionhelper.render; + +import io.github.moulberry.notenoughupdates.core.util.StringUtils; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.Minion; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources.MinionSource; +import io.github.moulberry.notenoughupdates.util.ItemUtils; +import net.minecraft.item.ItemStack; +import net.minecraftforge.event.entity.player.ItemTooltipEvent; +import net.minecraftforge.fml.common.eventhandler.EventPriority; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import org.lwjgl.input.Keyboard; + +import java.util.List; + +public class MinionHelperTooltips { + private final MinionHelperManager manager; + private boolean pressedShiftLast = false; + private boolean showFullCost = false; + + public MinionHelperTooltips(MinionHelperManager manager) { + this.manager = manager; + } + + @SubscribeEvent(priority = EventPriority.LOW) + public void onItemTooltip(ItemTooltipEvent event) { + if (!manager.inCraftedMinionsInventory()) return; + if (!manager.isReadyToUse()) return; + + boolean shift = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT); + if (!pressedShiftLast && shift) { + showFullCost = !showFullCost; + } + pressedShiftLast = shift; + + ItemStack itemStack = event.itemStack; + if (itemStack == null) return; + String displayName = itemStack.getDisplayName(); + if (!displayName.endsWith(" Minion")) return; + displayName = StringUtils.cleanColour(displayName); + + List lore = ItemUtils.getLore(itemStack); + if (lore.get(0).equals("§7You haven't crafted this minion.")) return; + + int index = 0; + for (String line : lore) { + index++; + if (!line.contains("Tier")) continue; + + Minion minion = manager.getMinionByName(displayName, index); + if (minion == null) { + System.err.println("minion is null for displayName '" + displayName + "' and tier " + index); + continue; + } + MinionSource minionSource = minion.getMinionSource(); + if (minionSource == null) { + System.err.println("minionSource is null for " + minion.getInternalName()); + continue; + } + String format = manager.getPriceCalculation().calculateUpgradeCostsFormat(minionSource, !showFullCost); + event.toolTip.set(index, line + " §8- " + format); + } + + if (showFullCost) { + event.toolTip.add("§8[Press SHIFT to show upgrade costs]"); + } else { + event.toolTip.add("§8[Press SHIFT to show full costs]"); + } + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/renderables/RenderableObject.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/renderables/RenderableObject.java new file mode 100644 index 00000000..2ba6ca76 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/renderables/RenderableObject.java @@ -0,0 +1,23 @@ +/* + * 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 . + */ + +package io.github.moulberry.notenoughupdates.miscgui.minionhelper.render.renderables; + +public abstract class RenderableObject { +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/renderables/RenderableText.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/renderables/RenderableText.java new file mode 100644 index 00000000..b2269b4f --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/renderables/RenderableText.java @@ -0,0 +1,40 @@ +/* + * 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 . + */ + +package io.github.moulberry.notenoughupdates.miscgui.minionhelper.render.renderables; + +import java.util.Arrays; +import java.util.List; + +public class RenderableText extends RenderableObject { + + private final List lines; + + public RenderableText(List lines) { + this.lines = lines; + } + + public RenderableText(String... lines) { + this(Arrays.asList(lines)); + } + + public List getLines() { + return lines; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/renderables/RenderableObject.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/renderables/RenderableObject.java deleted file mode 100644 index c390138a..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/renderables/RenderableObject.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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 . - */ - -package io.github.moulberry.notenoughupdates.miscgui.minionhelper.renderables; - -public abstract class RenderableObject { -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/renderables/RenderableText.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/renderables/RenderableText.java deleted file mode 100644 index 413cf754..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/renderables/RenderableText.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 . - */ - -package io.github.moulberry.notenoughupdates.miscgui.minionhelper.renderables; - -import java.util.Arrays; -import java.util.List; - -public class RenderableText extends RenderableObject { - - private final List lines; - - public RenderableText(List lines) { - this.lines = lines; - } - - public RenderableText(String... lines) { - this(Arrays.asList(lines)); - } - - public List getLines() { - return lines; - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/sources/MinionSource.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/sources/MinionSource.java index fcb4a3c3..fcc6018c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/sources/MinionSource.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/sources/MinionSource.java @@ -20,7 +20,7 @@ package io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.Minion; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.renderables.RenderableObject; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.render.renderables.RenderableObject; public abstract class MinionSource extends RenderableObject { private final Minion minion; 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 new file mode 100644 index 00000000..32131251 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/util/MinionHelperPriceCalculation.java @@ -0,0 +1,166 @@ +/* + * 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 . + */ + +package io.github.moulberry.notenoughupdates.miscgui.minionhelper.util; + +import com.google.common.collect.ArrayListMultimap; +import com.google.gson.JsonObject; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.Minion; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources.CraftingSource; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources.CustomSource; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources.MinionSource; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources.NpcSource; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraftforge.client.event.GuiOpenEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class MinionHelperPriceCalculation { + + private final MinionHelperManager manager; + private final Map upgradeCostFormatCache = new HashMap<>(); + private final Map fullCostFormatCache = new HashMap<>(); + //TODO maybe change logic with 0 coins later or stuff + private final List cheapItems = Arrays.asList( + "WOOD_SWORD", + "WOOD_HOE", + "WOOD_AXE", + "WOOD_PICKAXE", + "WOOD_SPADE", + "FISHING_ROD", + "SKYBLOCK_PELT" + ); + + public MinionHelperPriceCalculation(MinionHelperManager manager) { + this.manager = manager; + } + + @SubscribeEvent + public void onGuiOpen(GuiOpenEvent event) { + upgradeCostFormatCache.clear(); + fullCostFormatCache.clear(); + } + + public String calculateUpgradeCostsFormat(MinionSource source, boolean upgradeOnly) { + if (source == null) return "§c?"; + String internalName = source.getMinion().getInternalName(); + if (upgradeOnly) { + if (upgradeCostFormatCache.containsKey(internalName)) { + upgradeCostFormatCache.get(internalName); + } + } else { + if (fullCostFormatCache.containsKey(internalName)) { + fullCostFormatCache.get(internalName); + } + } + + if (source instanceof CustomSource) { + return "§f" + ((CustomSource) source).getCustomSource(); + } + + long costs = calculateUpgradeCosts(source, upgradeOnly); + String result = formatCoins(costs, !upgradeOnly ? "§o" : ""); + + if (source instanceof NpcSource) { + ArrayListMultimap items = ((NpcSource) source).getItems(); + if (items.containsKey("SKYBLOCK_PELT")) { + int amount = items.get("SKYBLOCK_PELT").get(0); + result += " §7+ §5" + amount + " Pelts"; + } + } + + if (upgradeOnly) { + upgradeCostFormatCache.put(internalName, result); + } else { + fullCostFormatCache.put(internalName, result); + } + + return result; + } + + public long calculateUpgradeCosts(MinionSource source, boolean upgradeOnly) { + if (source instanceof CraftingSource) { + CraftingSource craftingSource = (CraftingSource) source; + return getCosts(source, upgradeOnly, craftingSource.getItems()); + + } else if (source instanceof NpcSource) { + NpcSource npcSource = (NpcSource) source; + long upgradeCost = getCosts(source, upgradeOnly, npcSource.getItems()); + long coins = npcSource.getCoins(); + upgradeCost += coins; + + return upgradeCost; + } + + return 0; + } + + private long getCosts(MinionSource source, boolean upgradeOnly, ArrayListMultimap items) { + long upgradeCost = 0; + for (Map.Entry entry : items.entries()) { + String internalName = entry.getKey(); + long price = getPrice(internalName); + int amount = entry.getValue(); + upgradeCost += price * amount; + } + if (!upgradeOnly) { + Minion parent = source.getMinion().getParent(); + if (parent != null) { + upgradeCost += calculateUpgradeCosts(parent.getMinionSource(), false); + } + } + return upgradeCost; + } + + public long getPrice(String internalName) { + JsonObject bazaarInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalName); + if (bazaarInfo == null) { + if (internalName.contains("_GENERATOR_")) { + return calculateUpgradeCosts(manager.getMinionById(internalName).getMinionSource(), false); + } else { + if (!cheapItems.contains(internalName)) { + return (long) NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAvgBin(internalName); + } + } + return 0; + } + + //TODO use average bazaar price? + if (!bazaarInfo.has("curr_sell")) { + System.err.println("curr_sell does not exist for '" + internalName + "'"); + return 0; + } + return (long) bazaarInfo.get("curr_sell").getAsDouble(); + } + + public String formatCoins(long coins) { + return formatCoins(coins, ""); + } + + public String formatCoins(long coins, String extraFormat) { + String format = Utils.shortNumberFormat(coins, 0); + return "§6" + extraFormat + format + " coins"; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/util/MinionHelperRequirementsManager.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/util/MinionHelperRequirementsManager.java new file mode 100644 index 00000000..adc30a53 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/util/MinionHelperRequirementsManager.java @@ -0,0 +1,120 @@ +/* + * 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 . + */ + +package io.github.moulberry.notenoughupdates.miscgui.minionhelper.util; + +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.ApiData; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.Minion; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.requirements.CollectionRequirement; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.requirements.CustomRequirement; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.requirements.MinionRequirement; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.requirements.ReputationRequirement; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.requirements.SlayerRequirement; +import io.github.moulberry.notenoughupdates.util.Utils; + +import java.util.Collections; +import java.util.List; +import java.util.Map; + +public class MinionHelperRequirementsManager { + + private final MinionHelperManager manager; + + public MinionHelperRequirementsManager(MinionHelperManager manager) { + this.manager = manager; + } + + public List getRequirements(Minion minion) { + if (!minion.getRequirements().isEmpty()) { + return minion.getRequirements(); + } + + Minion parent = minion.getParent(); + if (parent != null) { + return getRequirements(parent); + } + + return Collections.emptyList(); + } + + public boolean meetAllRequirements(Minion minion) { + List list = getRequirements(minion); + for (MinionRequirement requirement : list) { + if (!meetRequirement(minion, requirement)) { + return false; + } + } + + return true; + } + + public boolean meetRequirement(Minion minion, MinionRequirement requirement) { + ApiData apiData = manager.getApi().getApiData(); + if (apiData == null) return false; + + if (requirement instanceof CollectionRequirement) { + if (apiData.isCollectionApiDisabled()) return true; + + CollectionRequirement collectionRequirement = (CollectionRequirement) requirement; + String collection = collectionRequirement.getCollection(); + String internalName = manager.formatInternalName(collection); + + int need = collectionRequirement.getLevel(); + Map highestCollectionTier = apiData.getHighestCollectionTier(); + if (highestCollectionTier.containsKey(internalName)) { + int has = highestCollectionTier.get(internalName); + + return has >= need; + } + + } else if (requirement instanceof SlayerRequirement) { + SlayerRequirement slayerRequirement = (SlayerRequirement) requirement; + String slayer = slayerRequirement.getSlayer(); + int need = slayerRequirement.getLevel(); + Map slayerTiers = apiData.getSlayerTiers(); + if (slayerTiers.containsKey(slayer)) { + return slayerTiers.get(slayer) >= need; + } + + } else if (requirement instanceof ReputationRequirement) { + ReputationRequirement reputationRequirement = (ReputationRequirement) requirement; + int need = reputationRequirement.getReputation(); + String reputationType = reputationRequirement.getReputationType(); + if (reputationType.equals("BARBARIAN")) { + return apiData.getBarbariansReputation() >= need; + } else if (reputationType.equals("MAGE")) { + return apiData.getMagesReputation() >= need; + } else { + Utils.addChatMessage("§c[NEU] Minion Helper: Unknown reputation type: '" + reputationType + "'"); + return false; + } + } else if (requirement instanceof CustomRequirement) { + return minion.isCrafted(); + } + + return false; + } + + public void reloadRequirements() { + for (Minion minion : manager.getAllMinions().values()) { + minion.setMeetRequirements(meetAllRequirements(minion)); + } + } +} -- cgit