aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java15
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PresetWarning.java217
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java2
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Garden.java8
4 files changed, 242 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 f15a26a7..5ccd6767 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java
@@ -36,6 +36,7 @@ import io.github.moulberry.notenoughupdates.miscfeatures.BetterContainers;
import io.github.moulberry.notenoughupdates.miscfeatures.CrystalMetalDetectorSolver;
import io.github.moulberry.notenoughupdates.miscfeatures.DungeonNpcProfitOverlay;
import io.github.moulberry.notenoughupdates.miscfeatures.EnchantingSolvers;
+import io.github.moulberry.notenoughupdates.miscfeatures.PresetWarning;
import io.github.moulberry.notenoughupdates.miscfeatures.StorageManager;
import io.github.moulberry.notenoughupdates.miscfeatures.dev.RepoExporters;
import io.github.moulberry.notenoughupdates.miscgui.AccessoryBagOverlay;
@@ -727,6 +728,10 @@ public class RenderListener {
if (AbiphoneWarning.getInstance().shouldShow()) {
AbiphoneWarning.getInstance().render();
}
+
+ if (PresetWarning.getInstance().shouldShow()) {
+ PresetWarning.getInstance().render();
+ }
}
private void renderDungKuudraChestOverlay(GuiScreen gui) {
@@ -1012,6 +1017,11 @@ public class RenderListener {
event.setCanceled(true);
return;
}
+ if (PresetWarning.getInstance().shouldShow()) {
+ PresetWarning.getInstance().mouseInput(mouseX, mouseY);
+ event.setCanceled(true);
+ return;
+ }
if (!event.isCanceled()) {
Utils.scrollTooltip(Mouse.getEventDWheel());
@@ -1246,6 +1256,11 @@ public class RenderListener {
event.setCanceled(true);
return;
}
+ if (PresetWarning.getInstance().shouldShow()) {
+ PresetWarning.getInstance().keyboardInput();
+ event.setCanceled(true);
+ return;
+ }
if (AuctionSearchOverlay.shouldReplace()) {
AuctionSearchOverlay.keyEvent();
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PresetWarning.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PresetWarning.java
new file mode 100644
index 00000000..5e57744b
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PresetWarning.java
@@ -0,0 +1,217 @@
+/*
+ * Copyright (C) 2023 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.autosubscribe.NEUAutoSubscribe;
+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.events.SlotClickEvent;
+import io.github.moulberry.notenoughupdates.util.ItemUtils;
+import io.github.moulberry.notenoughupdates.util.Utils;
+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 net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+import org.lwjgl.input.Keyboard;
+import org.lwjgl.input.Mouse;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
+
+import java.util.List;
+
+@NEUAutoSubscribe
+public class PresetWarning extends GuiElement {
+ private static final PresetWarning INSTANCE = new PresetWarning();
+
+ private boolean showWarning = false;
+ private String presetName = null;
+ private int presetSlot = -1;
+
+ public static PresetWarning getInstance() {
+ return INSTANCE;
+ }
+
+ private boolean shouldPerformCheck() {
+ if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) {
+ showWarning = false;
+ return false;
+ }
+
+ if (Utils.getOpenChestName().startsWith("Plot Modification: ")) {
+ return true;
+ } else {
+ showWarning = false;
+ return false;
+ }
+ }
+
+ public boolean shouldShow() {
+ return shouldPerformCheck() && showWarning;
+ }
+
+ @SubscribeEvent
+ public void onMouseClick(SlotClickEvent event) {
+ if (!shouldPerformCheck()) return;
+ if (!NotEnoughUpdates.INSTANCE.config.garden.presetDeleteWarning) return;
+ if (event.slotId == -999) return;
+ if (event.clickedButton == 0) return;
+
+ GuiChest chest = (GuiChest) Minecraft.getMinecraft().currentScreen;
+
+ ItemStack clickedPreset = chest.inventorySlots.getSlot(event.slotId).getStack();
+ if (clickedPreset == null) return;
+
+ List<String> list = ItemUtils.getLore(clickedPreset);
+ if (list.isEmpty()) return;
+
+ String last = list.get(list.size() - 1);
+ if (last.contains("Right-Click to delete!")) {
+ showWarning = true;
+ presetName = clickedPreset.getDisplayName();
+ presetSlot = event.slotId;
+ event.setCanceled(true);
+ }
+ }
+
+ 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" + presetName + "\u00a77 ]";
+
+ TextRenderUtils.drawStringCenteredScaledMaxWidth(sellLine, Minecraft.getMinecraft().fontRendererObj,
+ width / 2, height / 2 - 45 + 25, false, 170, 0xffffffff
+ );
+
+ TextRenderUtils.drawStringCenteredScaledMaxWidth(
+ "Continue removing this preset?",
+ 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 (presetSlot != -1) {
+ GuiChest chest = (GuiChest) Minecraft.getMinecraft().currentScreen;
+ Minecraft.getMinecraft().playerController.windowClick(chest.inventorySlots.windowId,
+ presetSlot, 1, 0, Minecraft.getMinecraft().thePlayer
+ );
+ presetSlot = -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 8aca73d1..2c7cf0ee 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java
@@ -31,6 +31,7 @@ import io.github.moulberry.notenoughupdates.miscfeatures.AuctionSortModeWarning;
import io.github.moulberry.notenoughupdates.miscfeatures.BetterContainers;
import io.github.moulberry.notenoughupdates.miscfeatures.DungeonNpcProfitOverlay;
import io.github.moulberry.notenoughupdates.miscfeatures.EnchantingSolvers;
+import io.github.moulberry.notenoughupdates.miscfeatures.PresetWarning;
import io.github.moulberry.notenoughupdates.miscfeatures.SlotLocking;
import io.github.moulberry.notenoughupdates.miscgui.GuiCustomEnchant;
import io.github.moulberry.notenoughupdates.miscgui.StorageOverlay;
@@ -202,6 +203,7 @@ public abstract class MixinGuiContainer extends GuiScreen {
GuiCustomHex.getInstance().overrideIsMouseOverSlot(slotIn, mouseX, mouseY, cir);
AuctionBINWarning.getInstance().overrideIsMouseOverSlot(slotIn, mouseX, mouseY, cir);
AbiphoneWarning.getInstance().overrideIsMouseOverSlot(slotIn, mouseX, mouseY, cir);
+ PresetWarning.getInstance().overrideIsMouseOverSlot(slotIn, mouseX, mouseY, cir);
}
@Redirect(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/inventory/GuiContainer;drawGradientRect(IIIIII)V"))
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Garden.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Garden.java
index 8d0e564c..b5f11906 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Garden.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Garden.java
@@ -31,4 +31,12 @@ public class Garden {
)
@ConfigEditorBoolean
public boolean muteComposterSounds = false;
+
+ @Expose
+ @ConfigOption(
+ name = "Enable Preset Delete Warning",
+ desc = "Asks for confirmation when deleting a preset"
+ )
+ @ConfigEditorBoolean
+ public boolean presetDeleteWarning = true;
}