diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2022-08-07 16:50:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-07 16:50:30 +0200 |
commit | fe37f119bb381f3e8ad7cd8afb44739efcfc7e59 (patch) | |
tree | 9b333ce5cd1b64f2fae82bc9c6a1d5f91bf0aea5 /src | |
parent | 6d2c47744663309c4297a93ff9311e9074251fa1 (diff) | |
download | NotEnoughUpdates-fe37f119bb381f3e8ad7cd8afb44739efcfc7e59.tar.gz NotEnoughUpdates-fe37f119bb381f3e8ad7cd8afb44739efcfc7e59.tar.bz2 NotEnoughUpdates-fe37f119bb381f3e8ad7cd8afb44739efcfc7e59.zip |
added abiphone warning (#202)
Diffstat (limited to 'src')
4 files changed, 245 insertions, 0 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java index 35a3581a..02c25333 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java @@ -34,6 +34,7 @@ import io.github.moulberry.notenoughupdates.commands.profile.ViewProfileCommand; import io.github.moulberry.notenoughupdates.core.GuiScreenElementWrapper; import io.github.moulberry.notenoughupdates.dungeons.DungeonWin; import io.github.moulberry.notenoughupdates.itemeditor.NEUItemEditor; +import io.github.moulberry.notenoughupdates.miscfeatures.AbiphoneWarning; import io.github.moulberry.notenoughupdates.miscfeatures.AuctionBINWarning; import io.github.moulberry.notenoughupdates.miscfeatures.AuctionProfit; import io.github.moulberry.notenoughupdates.miscfeatures.BetterContainers; @@ -681,6 +682,10 @@ public class RenderListener { if (AuctionBINWarning.getInstance().shouldShow()) { AuctionBINWarning.getInstance().render(); } + + if (AbiphoneWarning.getInstance().shouldShow()) { + AbiphoneWarning.getInstance().render(); + } } private void renderDungeonChestOverlay(GuiScreen gui) { @@ -922,6 +927,11 @@ public class RenderListener { event.setCanceled(true); return; } + if (AbiphoneWarning.getInstance().shouldShow()) { + AbiphoneWarning.getInstance().mouseInput(mouseX, mouseY); + event.setCanceled(true); + return; + } if (!event.isCanceled()) { Utils.scrollTooltip(Mouse.getEventDWheel()); @@ -1390,6 +1400,11 @@ public class RenderListener { event.setCanceled(true); return; } + if (AbiphoneWarning.getInstance().shouldShow()) { + AbiphoneWarning.getInstance().keyboardInput(); + event.setCanceled(true); + return; + } if (AuctionSearchOverlay.shouldReplace()) { AuctionSearchOverlay.keyEvent(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneWarning.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneWarning.java new file mode 100644 index 00000000..c806feeb --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneWarning.java @@ -0,0 +1,215 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.miscfeatures; + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.core.GuiElement; +import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; +import io.github.moulberry.notenoughupdates.core.util.render.TextRenderUtils; +import io.github.moulberry.notenoughupdates.util.ItemUtils; +import io.github.moulberry.notenoughupdates.util.SBInfo; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.gui.inventory.GuiChest; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.List; + +public class AbiphoneWarning extends GuiElement { + private static final AbiphoneWarning INSTANCE = new AbiphoneWarning(); + + private boolean showWarning = false; + private String contactName = null; + private int contactSlot = -1; + + public static AbiphoneWarning getInstance() { + return INSTANCE; + } + + private boolean shouldPerformCheck() { + if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) { + showWarning = false; + return false; + } + + if (Minecraft.getMinecraft().currentScreen instanceof GuiChest && + SBInfo.getInstance().lastOpenContainerName.startsWith("Abiphone ")) { + return true; + } else { + showWarning = false; + return false; + } + } + + public boolean shouldShow() { + return shouldPerformCheck() && showWarning; + } + + public boolean onMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType) { + if (!shouldPerformCheck()) return false; + if (!NotEnoughUpdates.INSTANCE.config.misc.abiphoneWarning) return false; + if (slotId == -999) return false; + if (clickedButton == 0) return false; + + GuiChest chest = (GuiChest) Minecraft.getMinecraft().currentScreen; + + ItemStack clickedContact = chest.inventorySlots.getSlot(slotId).getStack(); + if (clickedContact == null) return false; + + List<String> list = ItemUtils.getLore(clickedContact); + if (list.isEmpty()) return false; + + String last = list.get(list.size() - 1); + if (last.contains("Right-click to remove contact!")) { + showWarning = true; + contactName = clickedContact.getDisplayName(); + contactSlot = slotId; + return true; + } + + return false; + } + + public void overrideIsMouseOverSlot(Slot slot, int mouseX, int mouseY, CallbackInfoReturnable<Boolean> cir) { + if (shouldShow()) { + cir.setReturnValue(false); + } + } + + @Override + public void render() { + final ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + final int width = scaledResolution.getScaledWidth(); + final int height = scaledResolution.getScaledHeight(); + + GlStateManager.disableLighting(); + + GlStateManager.pushMatrix(); + GlStateManager.translate(0, 0, 500); + + Gui.drawRect(0, 0, width, height, 0x80000000); + + RenderUtils.drawFloatingRectDark(width / 2 - 90, height / 2 - 45, 180, 90); + + int neuLength = Minecraft.getMinecraft().fontRendererObj.getStringWidth("\u00a7lNEU"); + Minecraft.getMinecraft().fontRendererObj.drawString( + "\u00a7lNEU", + width / 2 + 90 - neuLength - 3, + height / 2 - 45 + 4, + 0xff000000 + ); + + TextRenderUtils.drawStringCenteredScaledMaxWidth("Are you SURE?", Minecraft.getMinecraft().fontRendererObj, + width / 2, height / 2 - 45 + 10, false, 170, 0xffff4040 + ); + + String sellLine = "\u00a77[ \u00a7r" + contactName + "\u00a77 ]"; + + TextRenderUtils.drawStringCenteredScaledMaxWidth(sellLine, Minecraft.getMinecraft().fontRendererObj, + width / 2, height / 2 - 45 + 25, false, 170, 0xffffffff + ); + + TextRenderUtils.drawStringCenteredScaledMaxWidth( + "Continue removing the contact?", + Minecraft.getMinecraft().fontRendererObj, + width / 2, + height / 2 - 45 + 50, + false, + 170, + 0xffa0a0a0 + ); + + RenderUtils.drawFloatingRectDark(width / 2 - 43, height / 2 + 23, 40, 16, false); + RenderUtils.drawFloatingRectDark(width / 2 + 3, height / 2 + 23, 40, 16, false); + + TextRenderUtils.drawStringCenteredScaledMaxWidth( + EnumChatFormatting.GREEN + "[Y]es", + Minecraft.getMinecraft().fontRendererObj, + width / 2 - 23, + height / 2 + 31, + true, + 36, + 0xff00ff00 + ); + TextRenderUtils.drawStringCenteredScaledMaxWidth( + EnumChatFormatting.RED + "[N]o", + Minecraft.getMinecraft().fontRendererObj, + width / 2 + 23, + height / 2 + 31, + true, + 36, + 0xffff0000 + ); + + GlStateManager.popMatrix(); + } + + @Override + public boolean mouseInput(int mouseX, int mouseY) { + final ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + final int width = scaledResolution.getScaledWidth(); + final int height = scaledResolution.getScaledHeight(); + + if (Mouse.getEventButtonState()) { + if (mouseY >= height / 2 + 23 && mouseY <= height / 2 + 23 + 16) { + if (mouseX >= width / 2 - 43 && mouseX <= width / 2 - 3) { + makeClick(); + } + showWarning = false; + } + + if (mouseX < width / 2 - 90 || mouseX > width / 2 + 90 || + mouseY < height / 2 - 45 || mouseY > height / 2 + 45) { + showWarning = false; + } + } + + return false; + } + + @Override + public boolean keyboardInput() { + if (!Keyboard.getEventKeyState()) { + if (Keyboard.getEventKey() == Keyboard.KEY_Y || Keyboard.getEventKey() == Keyboard.KEY_RETURN) { + makeClick(); + } + showWarning = false; + } + + return false; + } + + private void makeClick() { + if (contactSlot != -1) { + GuiChest chest = (GuiChest) Minecraft.getMinecraft().currentScreen; + Minecraft.getMinecraft().playerController.windowClick(chest.inventorySlots.windowId, + contactSlot, 1, 0, Minecraft.getMinecraft().thePlayer + ); + contactSlot = -1; + } + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java index e3741ac7..3bc92a9c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java @@ -22,6 +22,7 @@ package io.github.moulberry.notenoughupdates.mixins; import io.github.moulberry.notenoughupdates.NEUOverlay; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.listener.RenderListener; +import io.github.moulberry.notenoughupdates.miscfeatures.AbiphoneWarning; import io.github.moulberry.notenoughupdates.miscfeatures.AuctionBINWarning; import io.github.moulberry.notenoughupdates.miscfeatures.AuctionSortModeWarning; import io.github.moulberry.notenoughupdates.miscfeatures.BetterContainers; @@ -189,6 +190,7 @@ public abstract class MixinGuiContainer extends GuiScreen { StorageOverlay.getInstance().overrideIsMouseOverSlot(slotIn, mouseX, mouseY, cir); GuiCustomEnchant.getInstance().overrideIsMouseOverSlot(slotIn, mouseX, mouseY, cir); AuctionBINWarning.getInstance().overrideIsMouseOverSlot(slotIn, mouseX, mouseY, cir); + AbiphoneWarning.getInstance().overrideIsMouseOverSlot(slotIn, mouseX, mouseY, cir); } @Redirect(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/inventory/GuiContainer;drawGradientRect(IIIIII)V")) @@ -305,6 +307,11 @@ public abstract class MixinGuiContainer extends GuiScreen { return; } + if (AbiphoneWarning.getInstance().onMouseClick(slotIn, slotId, clickedButton, clickType)) { + ci.cancel(); + return; + } + AtomicBoolean ret = new AtomicBoolean(false); SlotLocking.getInstance().onWindowClick(slotIn, slotId, clickedButton, clickType, (tuple) -> { ci.cancel(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java index b0e4c60b..c0033cde 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java @@ -223,4 +223,12 @@ public class Misc { @ConfigEditorDropdown(values = {"Off", "Enabled with ! Prefix", "Always enabled"}) public int calculationMode = 2; + @Expose + @ConfigOption( + name = "Enable Abiphone Warning", + desc = "Asks for confirmation when removing a contact in the abiphone" + ) + @ConfigEditorBoolean + public boolean abiphoneWarning = true; + } |