aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz <lo.scherf@gmail.com>2022-08-10 16:50:57 +0200
committerLorenz <lo.scherf@gmail.com>2022-08-10 16:50:57 +0200
commite010b58d8a423e86da4957dd816813a4ce5d18dd (patch)
tree775e71758aaefaa1d1e3148eb4b4ee96f5e275c1
parent912c1d993f40936c3441e4dfe77c088bc89387aa (diff)
downloadNotEnoughUpdates-e010b58d8a423e86da4957dd816813a4ce5d18dd.tar.gz
NotEnoughUpdates-e010b58d8a423e86da4957dd816813a4ce5d18dd.tar.bz2
NotEnoughUpdates-e010b58d8a423e86da4957dd816813a4ce5d18dd.zip
fixing white spaces after merges
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/core/util/ArrowPagesUtils.java (renamed from src/main/java/io/github/moulberry/notenoughupdates/core/util/PageArrowsUtils.java)39
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java20
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java20
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlay.java23
4 files changed, 91 insertions, 11 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/util/PageArrowsUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/core/util/ArrowPagesUtils.java
index 1207cfa9..f51a669d 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/core/util/PageArrowsUtils.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/core/util/ArrowPagesUtils.java
@@ -25,13 +25,14 @@ import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
+import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import java.awt.*;
import java.util.function.Consumer;
-public class PageArrowsUtils {
+public class ArrowPagesUtils {
public static final int BUTTON_POSITION_RIGHT_OFFSET_X = 37;
public static final int PAGE_STRING_OFFSET_X = 22;
@@ -97,7 +98,28 @@ public class PageArrowsUtils {
);
}
- public static boolean onPageSwitch(
+ public static boolean onPageSwitchKey(
+ int currentPage,
+ int totalPages,
+ Consumer<Integer> pageChange
+ ) {
+
+ int keyPressed = Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter() + 256 : Keyboard.getEventKey();
+ if (Keyboard.getEventKeyState() && keyPressed == Keyboard.KEY_LEFT) {
+ int newPage = currentPage - 1;
+ pageChange.accept(MathHelper.clamp_int(newPage, 0, totalPages - 1));
+ return true;
+ }
+ if (Keyboard.getEventKeyState() && keyPressed == Keyboard.KEY_RIGHT) {
+ int newPage = currentPage + 1;
+ pageChange.accept(MathHelper.clamp_int(newPage, 0, totalPages - 1));
+ return true;
+ }
+
+ return false;
+ }
+
+ public static boolean onPageSwitchMouse(
int guiLeft,
int guiTop,
int[] topLeft,
@@ -105,6 +127,19 @@ public class PageArrowsUtils {
int totalPages,
Consumer<Integer> pageChange
) {
+
+ int keyPressed = Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter() + 256 : Keyboard.getEventKey();
+ if (Keyboard.getEventKeyState() && keyPressed == Keyboard.KEY_LEFT) {
+ int newPage = currentPage - 1;
+ pageChange.accept(MathHelper.clamp_int(newPage, 0, totalPages - 1));
+ return true;
+ }
+ if (Keyboard.getEventKeyState() && keyPressed == Keyboard.KEY_RIGHT) {
+ int newPage = currentPage + 1;
+ pageChange.accept(MathHelper.clamp_int(newPage, 0, totalPages - 1));
+ return true;
+ }
+
final ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft());
final int scaledWidth = scaledresolution.getScaledWidth();
final int scaledHeight = scaledresolution.getScaledHeight();
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 dc836a01..b6d89dd1 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java
@@ -1619,4 +1619,24 @@ public class RenderListener {
public void onRenderLast(RenderWorldLastEvent event) {
CrystalMetalDetectorSolver.render(event.partialTicks);
}
+
+ /**
+ * Support for switching between different pages in the RecipeView gui via right and left arrow key
+ * @param event
+ */
+ //Because GuiScreen.keyTyped does not fire the KEY_LEFT and KEY_RIGHT keys. Maybe some event cancelled it?
+ @SubscribeEvent
+ public void onMouseClick(GuiScreenEvent.KeyboardInputEvent.Post event) {
+
+ if (!NotEnoughUpdates.INSTANCE.isOnSkyblock()) return;
+
+ Minecraft minecraft = Minecraft.getMinecraft();
+ if (minecraft == null || minecraft.thePlayer == null) return;
+
+ GuiScreen screen = minecraft.currentScreen;
+ if (screen instanceof GuiItemRecipe) {
+ GuiItemRecipe itemRecipe = (GuiItemRecipe) screen;
+ itemRecipe.arrowKeyboardInput();
+ }
+ }
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java
index 8d075bd4..7bd11ecf 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java
@@ -21,7 +21,7 @@ package io.github.moulberry.notenoughupdates.miscgui;
import com.google.common.collect.ImmutableList;
import io.github.moulberry.notenoughupdates.NEUManager;
-import io.github.moulberry.notenoughupdates.core.util.PageArrowsUtils;
+import io.github.moulberry.notenoughupdates.core.util.ArrowPagesUtils;
import io.github.moulberry.notenoughupdates.recipes.NeuRecipe;
import io.github.moulberry.notenoughupdates.recipes.RecipeSlot;
import io.github.moulberry.notenoughupdates.recipes.RecipeType;
@@ -142,7 +142,7 @@ public class GuiItemRecipe extends GuiScreen {
}
int[] topLeft = currentRecipe.getPageFlipPositionLeftTopCorner();
- PageArrowsUtils.onDraw(guiLeft, guiTop, topLeft, currentIndex, getCurrentRecipeList().size());
+ ArrowPagesUtils.onDraw(guiLeft, guiTop, topLeft, currentIndex, getCurrentRecipeList().size());
Utils.drawStringScaledMaxWidth(
currentRecipe.getTitle(),
@@ -278,8 +278,15 @@ public class GuiItemRecipe extends GuiScreen {
super.mouseClicked(mouseX, mouseY, mouseButton);
NeuRecipe currentRecipe = getCurrentRecipe();
int[] topLeft = currentRecipe.getPageFlipPositionLeftTopCorner();
- PageArrowsUtils.onPageSwitch(guiLeft, guiTop, topLeft, currentIndex, getCurrentRecipeList().size(), pageChange ->
- changeRecipe(currentTab, pageChange));
+ ArrowPagesUtils.onPageSwitchMouse(
+ guiLeft,
+ guiTop,
+ topLeft,
+ currentIndex,
+ getCurrentRecipeList().size(),
+ pageChange ->
+ changeRecipe(currentTab, pageChange)
+ );
for (RecipeSlot slot : getAllRenderedSlots()) {
if (isWithinRect(mouseX, mouseY, slot.getX(this), slot.getY(this), SLOT_SIZE, SLOT_SIZE)) {
@@ -296,4 +303,9 @@ public class GuiItemRecipe extends GuiScreen {
currentRecipe.mouseClicked(this, mouseX, mouseY, mouseButton);
}
+
+ public void arrowKeyboardInput() {
+ ArrowPagesUtils.onPageSwitchKey(currentIndex, getCurrentRecipeList().size(), pageChange ->
+ changeRecipe(currentTab, pageChange));
+ }
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlay.java
index 12a8c24d..0c1f9800 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlay.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlay.java
@@ -21,7 +21,7 @@ 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.core.util.PageArrowsUtils;
+import io.github.moulberry.notenoughupdates.core.util.ArrowPagesUtils;
import io.github.moulberry.notenoughupdates.core.util.StringUtils;
import io.github.moulberry.notenoughupdates.miscgui.TrophyRewardOverlay;
import io.github.moulberry.notenoughupdates.miscgui.minionhelper.Minion;
@@ -45,12 +45,10 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
-import java.util.List;
import java.util.Map;
public class MinionHelperOverlay {
@@ -121,7 +119,7 @@ public class MinionHelperOverlay {
int guiLeft = container.getGuiLeft();
int guiTop = container.getGuiTop();
int totalPages = getTotalPages();
- PageArrowsUtils.onDraw(guiLeft, guiTop, topLeft, currentPage, totalPages);
+ ArrowPagesUtils.onDraw(guiLeft, guiTop, topLeft, currentPage, totalPages);
}
}
@@ -142,7 +140,7 @@ public class MinionHelperOverlay {
if (event.gui instanceof AccessorGuiContainer) {
int guiLeft = ((AccessorGuiContainer) event.gui).getGuiLeft();
int guiTop = ((AccessorGuiContainer) event.gui).getGuiTop();
- if (PageArrowsUtils.onPageSwitch(guiLeft, guiTop, topLeft, currentPage, totalPages, pageChange -> {
+ if (ArrowPagesUtils.onPageSwitchMouse(guiLeft, guiTop, topLeft, currentPage, totalPages, pageChange -> {
currentPage = pageChange;
resetCache();
})) {
@@ -151,6 +149,21 @@ public class MinionHelperOverlay {
}
}
+ @SubscribeEvent
+ public void onMouseClick(GuiScreenEvent.KeyboardInputEvent.Pre event) {
+ if (!manager.inCraftedMinionsInventory()) return;
+ if (!NotEnoughUpdates.INSTANCE.config.minionHelper.gui) return;
+ if (!manager.isReadyToUse()) return;
+
+ int totalPages = getTotalPages();
+ if (ArrowPagesUtils.onPageSwitchKey(currentPage, totalPages, pageChange -> {
+ currentPage = pageChange;
+ resetCache();
+ })) {
+ event.setCanceled(true);
+ }
+ }
+
private Map<Minion, Long> getMissing() {
Map<Minion, Long> prices = new HashMap<>();
for (Minion minion : manager.getAllMinions().values()) {