aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com>2024-08-13 23:16:52 +1000
committerGitHub <noreply@github.com>2024-08-13 15:16:52 +0200
commit644528d058fa76c6c79c4a86be9fca78f7ce684e (patch)
tree0e2607d7e4bd2732def6a3b3f74a8543c8928150
parent0545d229754ae1b50916cad708be70d66cb5efe2 (diff)
downloadnotenoughupdates-644528d058fa76c6c79c4a86be9fca78f7ce684e.tar.gz
notenoughupdates-644528d058fa76c6c79c4a86be9fca78f7ce684e.tar.bz2
notenoughupdates-644528d058fa76c6c79c4a86be9fca78f7ce684e.zip
meta: Fix ah and bz search not working without cookie (#1307)
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiEditSign.java10
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java626
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/overlays/BazaarSearchOverlay.java509
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/overlays/RecipeSearchOverlay.java496
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/overlays/SearchOverlayScreen.java753
5 files changed, 934 insertions, 1460 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiEditSign.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiEditSign.java
index bfdf05ab..6306004a 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiEditSign.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiEditSign.java
@@ -20,6 +20,8 @@
package io.github.moulberry.notenoughupdates.mixins;
import io.github.moulberry.notenoughupdates.events.SignSubmitEvent;
+import io.github.moulberry.notenoughupdates.overlays.AuctionSearchOverlay;
+import io.github.moulberry.notenoughupdates.overlays.BazaarSearchOverlay;
import net.minecraft.client.gui.inventory.GuiEditSign;
import net.minecraft.tileentity.TileEntitySign;
import net.minecraft.util.ChatComponentText;
@@ -27,7 +29,9 @@ import net.minecraft.util.IChatComponent;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(GuiEditSign.class)
public class MixinGuiEditSign {
@@ -47,4 +51,10 @@ public class MixinGuiEditSign {
return arr;
}
+ @Inject(method = "onGuiClosed", at = @At(value = "HEAD"), cancellable = true)
+ public void onGuiClosed(CallbackInfo ci) {
+ if (AuctionSearchOverlay.isinAhSign()) ci.cancel();
+ if (BazaarSearchOverlay.isinBzSign()) ci.cancel();
+ }
+
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java
index 5c1b3b8f..c40199bd 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java
@@ -19,65 +19,26 @@
package io.github.moulberry.notenoughupdates.overlays;
-import com.google.common.base.Splitter;
import com.google.gson.JsonObject;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe;
-import io.github.moulberry.notenoughupdates.commands.help.SettingsCommand;
-import io.github.moulberry.notenoughupdates.core.GuiElementTextField;
import io.github.moulberry.notenoughupdates.events.SlotClickEvent;
-import io.github.moulberry.notenoughupdates.util.Constants;
+import io.github.moulberry.notenoughupdates.miscfeatures.CookieWarning;
+import io.github.moulberry.notenoughupdates.mixins.AccessorGuiEditSign;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.client.Minecraft;
-import net.minecraft.client.gui.Gui;
-import net.minecraft.client.gui.GuiScreen;
-import net.minecraft.client.gui.ScaledResolution;
-import net.minecraft.client.renderer.GlStateManager;
+import net.minecraft.client.gui.inventory.GuiEditSign;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
-import net.minecraft.util.ResourceLocation;
+import net.minecraft.tileentity.TileEntitySign;
+import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
-import org.apache.commons.lang3.StringUtils;
-import org.lwjgl.input.Keyboard;
-import org.lwjgl.input.Mouse;
-import org.lwjgl.opengl.GL11;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.atomic.AtomicInteger;
@NEUAutoSubscribe
-public class AuctionSearchOverlay extends GuiScreen {
- private static final ResourceLocation SEARCH_OVERLAY_TEXTURE = new ResourceLocation(
- "notenoughupdates:auc_search/ah_search_overlay.png");
- private static final ResourceLocation SEARCH_OVERLAY_TEXTURE_TAB_COMPLETED = new ResourceLocation(
- "notenoughupdates:auc_search/ah_search_overlay_tab_completed.png");
- private static final ResourceLocation STAR = new ResourceLocation("notenoughupdates:auc_search/star.png");
- private static final ResourceLocation MASTER_STAR =
- new ResourceLocation("notenoughupdates:auc_search/master_star.png");
- private static final ResourceLocation STAR_BOARD = new ResourceLocation("notenoughupdates:auc_search/star_board.png");
-
- private static final GuiElementTextField textField = new GuiElementTextField("", 200, 20, 0);
- private static boolean searchFieldClicked = false;
- private static String searchString = "";
- private static String searchStringExtra = "";
- private static final Splitter SPACE_SPLITTER = Splitter.on(" ").omitEmptyStrings().trimResults();
- private static boolean tabCompleted = false;
- private static int tabCompletionIndex = -1;
-
- private static int selectedStars = 0;
- private static boolean atLeast = true;
- private static boolean onlyLevel100 = false;
-
- private static final int AUTOCOMPLETE_HEIGHT = 118;
-
- private static final Set<String> autocompletedItems = new LinkedHashSet<>();
+public class AuctionSearchOverlay extends SearchOverlayScreen {
private static final Comparator<String> salesComparator = (o1, o2) -> {
JsonObject auctionInfo1 = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfo(o1);
@@ -99,549 +60,100 @@ public class AuctionSearchOverlay extends GuiScreen {
};
public AuctionSearchOverlay() {
- super();
+ super(new TileEntitySign());
}
- static boolean isGuiOpen = false;
- public static boolean shouldReplace() {
- return isGuiOpen; //💀
+ public AuctionSearchOverlay(TileEntitySign sign) {
+ super(sign);
+ this.tileSign = sign;
+ this.guiType = GuiType.AUCTION_HOUSE;
}
- @Override
- public void drawScreen(int mouseX, int mouseY, float partialTicks) {
- isGuiOpen = true;
- super.drawScreen(mouseX, mouseY, partialTicks);
- super.drawDefaultBackground();
-
- ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
- int width = scaledResolution.getScaledWidth();
- int height = scaledResolution.getScaledHeight();
-
- int h = NotEnoughUpdates.INSTANCE.config.ahTweaks.showPastSearches ? 219 : 145;
-
- int topY = height / 4;
- if (scaledResolution.getScaleFactor() >= 4) {
- topY = height / 2 - h / 2 + 5;
- }
-
- Minecraft.getMinecraft().getTextureManager().bindTexture(SEARCH_OVERLAY_TEXTURE);
- GlStateManager.color(1, 1, 1, 1);
- Utils.drawTexturedRect(width / 2 - 100, topY - 1, 203, 145, 0, 203 / 512f, 0, 145 / 256f, GL11.GL_NEAREST);
-
- Minecraft.getMinecraft().getTextureManager().bindTexture(STAR_BOARD);
- Utils.drawTexturedRect(width / 2 + 105, topY + 27, 105, 13, GL11.GL_NEAREST);
-
- Minecraft.getMinecraft().getTextureManager().bindTexture(STAR);
- GlStateManager.color(1, 1, 1, 1);
- int stars = atLeast && selectedStars > 0 ? 10 : selectedStars;
- for (int i = 0; i < stars; i++) {
- if (i >= 5) {
- Minecraft.getMinecraft().getTextureManager().bindTexture(MASTER_STAR);
- GlStateManager.color(1, 1, 1, 1);
- }
- if (i >= selectedStars) {
- GlStateManager.color(1, 1, 1, 0.3f);
- }
- Utils.drawTexturedRect(width / 2 + 108 + 10 * i, topY + 29, 9, 10, GL11.GL_NEAREST);
- }
-
- if (selectedStars < 6) {
- Gui.drawRect(width / 2 + 106, topY + 42, width / 2 + 115, topY + 51, 0xffffffff);
- Gui.drawRect(width / 2 + 107, topY + 43, width / 2 + 114, topY + 50, 0xff000000);
- Minecraft.getMinecraft().fontRendererObj.drawString("At Least?", width / 2 + 117, topY + 43, 0xffffff);
-
- if (atLeast) {
- Gui.drawRect(width / 2 + 108, topY + 44, width / 2 + 113, topY + 49, 0xffffffff);
- }
- }
-
- Gui.drawRect(width / 2 + 106, topY + 53, width / 2 + 115, topY + 62, 0xffffffff);
- Gui.drawRect(width / 2 + 107, topY + 54, width / 2 + 114, topY + 61, 0xff000000);
- if (onlyLevel100) {
- Gui.drawRect(width / 2 + 108, topY + 55, width / 2 + 113, topY + 60, 0xffffffff);
- }
- Minecraft.getMinecraft().fontRendererObj.drawString("Level 100 pets only?", width / 2 + 117, topY + 54, 0xffffff);
-
- Minecraft.getMinecraft().fontRendererObj.drawString("Enter Query:", width / 2 - 100, topY - 10, 0xdddddd, true);
-
- textField.setFocus(true);
- textField.setText(searchString);
- textField.setSize(149, 20);
- textField.setCustomBorderColour(0xffffff);
- textField.render(width / 2 - 100 + 1, topY + 1);
-
- if (textField.getText().trim().isEmpty()) autocompletedItems.clear();
-
- //Gui.drawRect(width/2-101, height/4+25, width/2+101, height/4+25+ AUTOCOMPLETE_HEIGHT, 0xffffffff);
- //Gui.drawRect(width/2-100, height/4+25+1, width/2+100, height/4+25-1+ AUTOCOMPLETE_HEIGHT, 0xff000000);
-
- List<String> tooltipToDisplay = null;
-
- int num = 0;
- synchronized (autocompletedItems) {
- String[] autoCompletedItemsArray = autocompletedItems.toArray(new String[0]);
- for (int i = 0; i < autoCompletedItemsArray.length; i++) {
- String str = autoCompletedItemsArray[i];
- JsonObject obj = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(str);
- if (obj != null) {
- ItemStack stack = NotEnoughUpdates.INSTANCE.manager.jsonToStack(obj, false, true);
- //Gui.drawRect(width/2-96, height/4+30+num*22, width/2+96, height/4+30+num*22+20, 0xff505050);
- if (i == tabCompletionIndex) {
- Minecraft.getMinecraft().getTextureManager().bindTexture(SEARCH_OVERLAY_TEXTURE_TAB_COMPLETED);
- GlStateManager.color(1, 1, 1, 1);
- Utils.drawTexturedRect(
- width / 2 - 96 + 1,
- topY + 30 + num * 22 + 1,
- 193,
- 21,
- 0 / 512f,
- 193 / 512f,
- 0,
- 21 / 256f,
- GL11.GL_NEAREST
- );
- } else {
- Minecraft.getMinecraft().getTextureManager().bindTexture(SEARCH_OVERLAY_TEXTURE);
- GlStateManager.color(1, 1, 1, 1);
- Utils.drawTexturedRect(
- width / 2 - 96 + 1,
- topY + 30 + num * 22 + 1,
- 193,
- 21,
- 214 / 512f,
- 407 / 512f,
- 0,
- 21 / 256f,
- GL11.GL_NEAREST
- );
-
- }
- String itemName = Utils.trimIgnoreColour(stack.getDisplayName().replaceAll("\\[.+]", ""));
- if (itemName.contains("Enchanted Book") && str.contains(";")) {
- String[] lore = NotEnoughUpdates.INSTANCE.manager.getLoreFromNBT(stack.getTagCompound());
- itemName = lore[0].trim();
- }
-
- Minecraft.getMinecraft().fontRendererObj.drawString(Minecraft.getMinecraft().fontRendererObj.trimStringToWidth(
- itemName,
- 165
- ),
- width / 2 - 74, topY + 35 + num * 22 + 1, 0xdddddd, true
- );
-
- GlStateManager.enableDepth();
- Utils.drawItemStack(stack, width / 2 - 94 + 2, topY + 32 + num * 22 + 1);
+ public static boolean shouldReplace() {
+ return Minecraft.getMinecraft().currentScreen instanceof AuctionSearchOverlay;
+ }
- if (mouseX > width / 2 - 96 && mouseX < width / 2 + 96 && mouseY > topY + 30 + num * 22 &&
- mouseY < topY + 30 + num * 22 + 20) {
- tooltipToDisplay = stack.getTooltip(Minecraft.getMinecraft().thePlayer, false);
- }
+ public static boolean isinAhSign() {
+ if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) return false;
+ if (!NotEnoughUpdates.INSTANCE.config.ahTweaks.enableSearchOverlay) return false;
- if (++num >= 5) break;
- }
- }
+ if (!(Minecraft.getMinecraft().currentScreen instanceof GuiEditSign)) {
+ if (!NotEnoughUpdates.INSTANCE.config.ahTweaks.keepPreviousSearch) searchString = "";
+ return false;
}
- if (NotEnoughUpdates.INSTANCE.config.ahTweaks.showPastSearches) {
- Minecraft.getMinecraft().fontRendererObj.drawString(
- "Past Searches:",
- width / 2 - 100,
- topY + 25 + AUTOCOMPLETE_HEIGHT + 5,
- 0xdddddd,
- true
- );
- Minecraft.getMinecraft().getTextureManager().bindTexture(SEARCH_OVERLAY_TEXTURE);
- Utils.drawTexturedRect(width / 2 - 100, topY - 1 + 160, 203, 4, 0, 203 / 512f, 160 / 256f, 163 / 256f, GL11.GL_NEAREST);
-
- for (int i = 0; i < NotEnoughUpdates.INSTANCE.config.ahTweaks.ahSearchHistorySize; i++) {
- Minecraft.getMinecraft().getTextureManager().bindTexture(SEARCH_OVERLAY_TEXTURE);
- Utils.drawTexturedRect(width / 2 - 100, topY - 1 + 160 + 4 + i * 10, 203, 10, 0, 203 / 512f, 164 / 256f, 174 / 256f, GL11.GL_NEAREST);
- if (i >= NotEnoughUpdates.INSTANCE.config.hidden.previousAuctionSearches.size()) continue;
-
- String s = NotEnoughUpdates.INSTANCE.config.hidden.previousAuctionSearches.get(i);
- Minecraft.getMinecraft().fontRendererObj.drawString(
- s,
- width / 2 - 95 + 1,
- topY + 45 + AUTOCOMPLETE_HEIGHT + i * 10 + 2,
- 0xdddddd,
- true
- );
- }
-
- int size = NotEnoughUpdates.INSTANCE.config.ahTweaks.ahSearchHistorySize;
- Minecraft.getMinecraft().getTextureManager().bindTexture(SEARCH_OVERLAY_TEXTURE);
- Utils.drawTexturedRect(width / 2 - 100, topY - 1 + 160 + 4 + size * 10, 203, 4, 0, 203 / 512f, 215 / 256f, 219 / 256f, GL11.GL_NEAREST);
+ String lastContainer = Utils.getLastOpenChestName();
+ if (!lastContainer.equals("Auctions Browser") && !lastContainer.startsWith("Auctions: ")) return false;
+ TileEntitySign tes = ((AccessorGuiEditSign) Minecraft.getMinecraft().currentScreen).getTileSign();
- if (tooltipToDisplay != null) {
- Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1);
- }
- }
-
+ if (tes == null) return false;
+ if (tes.getPos().getY() != 0) return false;
+ if (!tes.signText[2].getUnformattedText().equals("^^^^^^^^^^^^^^^")) return false;
+ return tes.signText[3].getUnformattedText().equals("Enter query");
}
- private static final ExecutorService searchES = Executors.newSingleThreadExecutor();
- private static final AtomicInteger searchId = new AtomicInteger(0);
-
- private static String getItemIdAtIndex(int i) {
- if (!autocompletedItems.isEmpty()) {
- if ((i > autocompletedItems.size() - 1) || i < 0 || i > 4) {
- return "";
- }
- String searchString = autocompletedItems.toArray()[i].toString();
- JsonObject repoObject = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(searchString);
- if (repoObject != null) {
- ItemStack stack = NotEnoughUpdates.INSTANCE.manager.jsonToStack(repoObject);
- return Utils.cleanColour(stack.getDisplayName().replaceAll("\\[.+]", ""));
- }
+ @SubscribeEvent
+ public void onSlotClick(SlotClickEvent event) {
+ if (!enableSearchOverlay()) return;
+ if (!CookieWarning.hasActiveBoosterCookie()) return;
+ if (!Utils.getOpenChestName().startsWith("Auctions")) return;
+ ItemStack stack = event.slot.getStack();
+ if (event.slot.slotNumber == 48 && stack != null && stack.hasDisplayName() && stack.getItem() == Items.sign && stack.getDisplayName().equals("§aSearch")) {
+ event.setCanceled(true);
+ NotEnoughUpdates.INSTANCE.openGui = new AuctionSearchOverlay();
}
- return null;
}
- public static void close() {
- isGuiOpen = false;
- if (tabCompleted) {
- tabCompletionIndex = -1;
- tabCompleted = false;
- }
- if (NotEnoughUpdates.INSTANCE.config.ahTweaks.keepPreviousSearch) {
- search();
- } else {
- synchronized (autocompletedItems) {
- autocompletedItems.clear();
- }
- }
-
- StringBuilder stringBuilder = new StringBuilder(searchString.trim());
- if (!searchStringExtra.isEmpty()) {
- stringBuilder.append(searchStringExtra);
- }
- if (onlyLevel100) {
- stringBuilder.insert(0, "[Lvl 100] ");
- }
-
- String search = stringBuilder.toString();
-
- if (!searchString.trim().isEmpty()) {
- List<String> previousAuctionSearches = NotEnoughUpdates.INSTANCE.config.hidden.previousAuctionSearches;
- previousAuctionSearches.remove(searchString);
- previousAuctionSearches.remove(searchString);
- previousAuctionSearches.add(0, searchString);
- while (previousAuctionSearches.size() > NotEnoughUpdates.INSTANCE.config.ahTweaks.ahSearchHistorySize) {
- previousAuctionSearches.remove(previousAuctionSearches.size() - 1);
- }
+ @SubscribeEvent
+ public void onSignDrawn(GuiScreenEvent.DrawScreenEvent.Post event) {
+ if (!isinAhSign() || !(event.gui instanceof GuiEditSign) || event.gui instanceof SearchOverlayScreen)
+ return;
+ GuiEditSign guiEditSign = (GuiEditSign) event.gui;
+ TileEntitySign tileSign = ((AccessorGuiEditSign) guiEditSign).getTileSign();
+ if (tileSign != null) {
+ Minecraft.getMinecraft().displayGuiScreen(new AuctionSearchOverlay(tileSign));
}
-
- if (!search.isEmpty()) NotEnoughUpdates.INSTANCE.sendChatMessage("/ahs " + search);
- if (!NotEnoughUpdates.INSTANCE.config.ahTweaks.keepPreviousSearch) searchString = "";
}
- private static boolean updateTabCompletedSearch(int key) {
- String id;
- if (key == Keyboard.KEY_DOWN || key == Keyboard.KEY_TAB) {
- id = getItemIdAtIndex(tabCompletionIndex + 1);
- if (id == null) {
- textField.setFocus(true);
- textField.setText(searchString);
- tabCompleted = false;
- tabCompletionIndex = -1;
- return true;
- } else if (id.equals("")) {
- tabCompletionIndex = 0;
- return true;
- } else {
- searchString = id;
- tabCompletionIndex += 1;
- return true;
- }
- } else if (key == Keyboard.KEY_UP) {
- id = getItemIdAtIndex(tabCompletionIndex - 1);
- if (id == null) {
- textField.setFocus(true);
- textField.setText(searchString);
- tabCompleted = false;
- tabCompletionIndex = -1;
- return true;
- } else if (id.equals("")) {
- if (autocompletedItems.size() > 4) tabCompletionIndex = 4;
- else tabCompletionIndex = autocompletedItems.size() - 1;
- tabCompletionIndex = autocompletedItems.size() - 1;
- return true;
- } else {
- searchString = id;
- tabCompletionIndex -= 1;
- return true;
- }
- }
- return false;
+ @Override
+ public Comparator<String> getSearchComparator() {
+ return salesComparator;
}
- public static void search() {
- final int thisSearchId = searchId.incrementAndGet();
-
- searchES.submit(() -> {
- if (thisSearchId != searchId.get()) return;
-
- List<String> title = new ArrayList<>(NotEnoughUpdates.INSTANCE.manager.search("title:" + searchString.trim()));
-
- if (thisSearchId != searchId.get()) return;
-
- if (!searchString.trim().contains(" ")) {
- StringBuilder sb = new StringBuilder();
- for (char c : searchString.toCharArray()) {
- sb.append(c).append(" ");
- }
- title.addAll(NotEnoughUpdates.INSTANCE.manager.search("title:" + sb.toString().trim()));
- }
-
- if (thisSearchId != searchId.get()) return;
-
- List<String> desc = new ArrayList<>(NotEnoughUpdates.INSTANCE.manager.search("desc:" + searchString.trim()));
- desc.removeAll(title);
-
- if (thisSearchId != searchId.get()) return;
-
- Set<String> auctionableItems = NotEnoughUpdates.INSTANCE.manager.auctionManager.getLowestBinKeySet();
- auctionableItems.addAll(NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfoKeySet());
-
- if (!auctionableItems.isEmpty()) {
- title.retainAll(auctionableItems);
- desc.retainAll(auctionableItems);
-
- title.sort(salesComparator);
- desc.sort(salesComparator);
- } else {
- Set<String> bazaarItems = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarKeySet();
-
- title.removeAll(bazaarItems);
- desc.removeAll(bazaarItems);
- }
-
- if (thisSearchId != searchId.get()) return;
-
- synchronized (autocompletedItems) {
- autocompletedItems.clear();
- autocompletedItems.addAll(title);
- autocompletedItems.addAll(desc);
- }
- });
+ @Override
+ public boolean enableSearchOverlay() {
+ return NotEnoughUpdates.INSTANCE.config.ahTweaks.enableSearchOverlay;
}
@Override
- protected void keyTyped(char typedChar, int keyCode) throws IOException {
- super.keyTyped(typedChar, keyCode);
- boolean ignoreKey = false;
-
- if (keyCode == Keyboard.KEY_ESCAPE) {
- searchStringExtra = "";
- if (NotEnoughUpdates.INSTANCE.config.ahTweaks.escFullClose) {
- Minecraft.getMinecraft().displayGuiScreen(null);
- } else {
- close();
- }
- return;
- } else if (keyCode == Keyboard.KEY_RETURN) {
- searchStringExtra = "";
- close();
- return;
- } else if (keyCode == Keyboard.KEY_TAB) {
- //autocomplete to first item in the list
- if (!tabCompleted) {
- tabCompleted = true;
- ignoreKey = true;
- String id = getItemIdAtIndex(0);
- if (id == null) {
- tabCompleted = false;
- textField.setFocus(true);
- textField.setText(searchString);
- } else {
- tabCompletionIndex = 0;
- searchString = id;
- }
- }
- }
-
- if (Keyboard.getEventKeyState()) {
- if (tabCompleted) {
- if (!ignoreKey) {
- boolean success = updateTabCompletedSearch(keyCode);
- if (success) return;
- textField.setFocus(true);
- textField.setText(searchString);
- tabCompleted = false;
- tabCompletionIndex = -1;
- } else return;
-
- }
- textField.setFocus(true);
- textField.setText(searchString);
- textField.keyTyped(Keyboard.getEventCharacter(), keyCode);
- searchString = textField.getText();
-
- search();
- }
+ public ArrayList<String> previousSearches() {
+ return NotEnoughUpdates.INSTANCE.config.hidden.previousAuctionSearches;
}
@Override
- public void handleMouseInput() throws IOException {
- ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
- int width = scaledResolution.getScaledWidth();
- int height = scaledResolution.getScaledHeight();
- int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth;
- int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1;
-
- int h = NotEnoughUpdates.INSTANCE.config.ahTweaks.showPastSearches ? 219 : 145;
-
- int topY = height / 4;
- if (scaledResolution.getScaleFactor() >= 4) {
- topY = height / 2 - h / 2 + 5;
- }
-
- if (Mouse.getEventButtonState() && mouseX > width / 2 + 105 && mouseX < width / 2 + 105 + 105 &&
- mouseY > topY + 27 && mouseY < topY + 40) {
- int starClicked = 10;
- for (int i = 1; i <= 10; i++) {
- if (mouseX < width / 2 + 108 + 10 * i) {
- starClicked = i;
- break;
- }
- }
- if (selectedStars == starClicked) {
- selectedStars = 0;
- } else {
- selectedStars = starClicked;
- }
- return;
- }
-
- if (Mouse.getEventButtonState() && mouseX >= width / 2 + 106 && mouseX <= width / 2 + 116 &&
- mouseY >= topY + 42 && mouseY <= topY + 50) {
- atLeast = !atLeast;
- return;
- }
-
- if (Mouse.getEventButtonState() && mouseX >= width / 2 + 106 && mouseX <= width / 2 + 116 &&
- mouseY >= topY + 53 && mouseY <= topY + 62) {
- onlyLevel100 = !onlyLevel100;
- return;
- }
-
- if (!Mouse.getEventButtonState() && Mouse.getEventButton() == -1 && searchFieldClicked) {
- textField.mouseClickMove(mouseX - 2, topY + 10, 0, 0);
- }
-
- if (Mouse.getEventButton() != -1) {
- searchFieldClicked = false;
- }
-
- if (Mouse.getEventButtonState()) {
- if (mouseY > topY && mouseY < topY + 20) {
- if (mouseX > width / 2 - 100) {
- if (mouseX < width / 2 + 49) {
- searchFieldClicked = true;
- textField.mouseClicked(mouseX - 2, mouseY, Mouse.getEventButton());
-
- if (Mouse.getEventButton() == 1) {
- searchString = "";
- synchronized (autocompletedItems) {
- autocompletedItems.clear();
- }
- }
- } else if (mouseX < width / 2 + 75) {
- searchStringExtra = "";
- close();
- } else if (mouseX < width / 2 + 100) {
- searchString = "";
- searchStringExtra = "";
- close();
- NotEnoughUpdates.INSTANCE.openGui = SettingsCommand.INSTANCE.createConfigScreen("AH Tweaks");
- }
- }
- } else if (Mouse.getEventButton() == 0) {
- int num = 0;
- synchronized (autocompletedItems) {
- for (String str : autocompletedItems) {
- JsonObject obj = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(str);
- if (obj != null) {
- ItemStack stack = NotEnoughUpdates.INSTANCE.manager.jsonToStack(obj);
- if (mouseX >= width / 2 - 96 && mouseX <= width / 2 + 96 && mouseY >= topY + 30 + num * 22 &&
- mouseY <= topY + 30 + num * 22 + 20) {
- searchString = Utils.cleanColour(stack.getDisplayName().replaceAll("\\[.+]", "")).trim();
- if (searchString.contains("Enchanted Book") && str.contains(";")) {
- String[] lore = NotEnoughUpdates.INSTANCE.manager.getLoreFromNBT(stack.getTagCompound());
- String[] split = Utils.cleanColour(lore[0]).trim().split(" ");
- split[split.length - 1] = "";
-
- searchString = StringUtils.join(split, " ").trim();
- }
-
- JsonObject essenceCosts = Constants.ESSENCECOSTS;
- searchStringExtra = " ";
- if (essenceCosts != null && essenceCosts.has(str) && selectedStars > 0) {
- for (int i = 0; i < selectedStars; i++) {
- if (i > 4) break;
- searchStringExtra += "\u272A";
- }
- switch (selectedStars) {
- case 6:
- searchStringExtra += "\u278A";
- break;
- case 7:
- searchStringExtra += "\u278B";
- break;
- case 8:
- searchStringExtra += "\u278C";
- break;
- case 9:
- searchStringExtra += "\u278D";
- break;
- case 10:
- searchStringExtra += "\u278E";
- break;
- }
- if (selectedStars < 6 && !atLeast) {
- searchStringExtra += " ";
- searchStringExtra += stack.getItem().getItemStackDisplayName(stack).substring(0, 1);
- }
- }
-
- close();
- return;
- }
+ public int searchHistorySize() {
+ return NotEnoughUpdates.INSTANCE.config.ahTweaks.ahSearchHistorySize;
+ }
- if (++num >= 5) break;
- }
- }
- }
+ @Override
+ public boolean showPastSearches() {
+ return NotEnoughUpdates.INSTANCE.config.ahTweaks.showPastSearches;
+ }
- if (NotEnoughUpdates.INSTANCE.config.ahTweaks.showPastSearches) {
- for (int i = 0; i < NotEnoughUpdates.INSTANCE.config.ahTweaks.ahSearchHistorySize; i++) {
- if (i >= NotEnoughUpdates.INSTANCE.config.hidden.previousAuctionSearches.size()) break;
+ @Override
+ public boolean escFullClose() {
+ return NotEnoughUpdates.INSTANCE.config.ahTweaks.escFullClose;
+ }
- String s = NotEnoughUpdates.INSTANCE.config.hidden.previousAuctionSearches.get(i);
- if (mouseX >= width / 2 - 95 && mouseX <= width / 2 + 95 &&
- mouseY >= topY + 45 + AUTOCOMPLETE_HEIGHT + i * 10 &&
- mouseY <= topY + 45 + AUTOCOMPLETE_HEIGHT + i * 10 + 10) {
- searchString = s;
- searchStringExtra = "";
- close();
- return;
- }
- }
- }
- }
- }
+ @Override
+ public boolean keepPreviousSearch() {
+ return NotEnoughUpdates.INSTANCE.config.ahTweaks.keepPreviousSearch;
}
- @SubscribeEvent
- public void onSlotClick(SlotClickEvent event) {
- if (!NotEnoughUpdates.INSTANCE.config.ahTweaks.enableSearchOverlay) return;
- if (!Utils.getOpenChestName().startsWith("Auctions")) return;
- ItemStack stack = event.slot.getStack();
- if (event.slot.slotNumber == 48 && stack != null && stack.hasDisplayName() && stack.getItem() == Items.sign && stack.getDisplayName().equals("§aSearch")) {
- event.setCanceled(true);
- NotEnoughUpdates.INSTANCE.openGui = new AuctionSearchOverlay();
- }
+ @Override
+ public GuiType currentGuiType() {
+ return GuiType.AUCTION_HOUSE;
}
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/BazaarSearchOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/BazaarSearchOverlay.java
index d4643409..343ba156 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/BazaarSearchOverlay.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/BazaarSearchOverlay.java
@@ -19,54 +19,26 @@
package io.github.moulberry.notenoughupdates.overlays;
-import com.google.common.base.Splitter;
import com.google.gson.JsonObject;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe;
-import io.github.moulberry.notenoughupdates.commands.help.SettingsCommand;
-import io.github.moulberry.notenoughupdates.core.GuiElementTextField;
import io.github.moulberry.notenoughupdates.events.SlotClickEvent;
+import io.github.moulberry.notenoughupdates.miscfeatures.CookieWarning;
+import io.github.moulberry.notenoughupdates.mixins.AccessorGuiEditSign;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.client.Minecraft;
-import net.minecraft.client.gui.GuiScreen;
-import net.minecraft.client.gui.ScaledResolution;
-import net.minecraft.client.renderer.GlStateManager;
+import net.minecraft.client.gui.inventory.GuiEditSign;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
-import net.minecraft.util.ResourceLocation;
+import net.minecraft.tileentity.TileEntitySign;
+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.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.atomic.AtomicInteger;
@NEUAutoSubscribe
-public class BazaarSearchOverlay extends GuiScreen {
- private static final ResourceLocation SEARCH_OVERLAY_TEXTURE = new ResourceLocation(
- "notenoughupdates:auc_search/ah_search_overlay.png");
- private static final ResourceLocation SEARCH_OVERLAY_TEXTURE_TAB_COMPLETED = new ResourceLocation(
- "notenoughupdates:auc_search/ah_search_overlay_tab_completed.png");
-
- private static final GuiElementTextField textField = new GuiElementTextField("", 200, 20, 0);
- private static boolean searchFieldClicked = false;
- private static String searchString = "";
- private static String searchStringExtra = "";
- private static final Splitter SPACE_SPLITTER = Splitter.on(" ").omitEmptyStrings().trimResults();
- private static boolean tabCompleted = false;
- private static int tabCompletionIndex = -1;
-
- private static final int AUTOCOMPLETE_HEIGHT = 118;
-
- private static final Set<String> autocompletedItems = new LinkedHashSet<>();
+public class BazaarSearchOverlay extends SearchOverlayScreen {
private static final Comparator<String> salesComparator = (o1, o2) -> {
JsonObject bazaarInfo1 = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(o1);
@@ -88,442 +60,99 @@ public class BazaarSearchOverlay extends GuiScreen {
};
public BazaarSearchOverlay() {
- super();
+ super(new TileEntitySign());
}
- static boolean isGuiOpen = false;
- public static boolean shouldReplace() {
- return isGuiOpen; //this whole method is just so skyhanni doesnt crash 💀
+ public BazaarSearchOverlay(TileEntitySign tes) {
+ super(tes);
+ this.tileSign = tes;
+ this.guiType = GuiType.BAZAAR;
}
- @Override
- public void drawScreen(int mouseX, int mouseY, float partialTicks) {
- isGuiOpen = true;
- super.drawScreen(mouseX, mouseY, partialTicks);
- super.drawDefaultBackground();
-
- ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
- int width = scaledResolution.getScaledWidth();
- int height = scaledResolution.getScaledHeight();
-
- int h = NotEnoughUpdates.INSTANCE.config.bazaarTweaks.showPastSearches ? 219 : 145;
-
- int topY = height / 4;
- if (scaledResolution.getScaleFactor() >= 4) {
- topY = height / 2 - h / 2 + 5;
- }
-
- Minecraft.getMinecraft().getTextureManager().bindTexture(SEARCH_OVERLAY_TEXTURE);
- GlStateManager.color(1, 1, 1, 1);
- Utils.drawTexturedRect(width / 2 - 100, topY - 1, 203, 145, 0, 203 / 512f, 0, 145 / 256f, GL11.GL_NEAREST);
-
- Minecraft.getMinecraft().fontRendererObj.drawString("Enter Query:", width / 2 - 100, topY - 10, 0xdddddd, true);
-
- textField.setFocus(true);
- textField.setText(searchString);
- textField.setSize(149, 20);
- textField.setCustomBorderColour(0xffffff);
- textField.render(width / 2 - 100 + 1, topY + 1);
-
- if (textField.getText().trim().isEmpty()) autocompletedItems.clear();
-
- List<String> tooltipToDisplay = null;
-
- int num = 0;
- synchronized (autocompletedItems) {
- String[] autoCompletedItemsArray = autocompletedItems.toArray(new String[0]);
- for (int i = 0; i < autoCompletedItemsArray.length; i++) {
- String str = autoCompletedItemsArray[i];
- JsonObject obj = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(str);
- if (obj != null) {
- ItemStack stack = NotEnoughUpdates.INSTANCE.manager.jsonToStack(obj, false, true);
- if (i == tabCompletionIndex) {
- Minecraft.getMinecraft().getTextureManager().bindTexture(SEARCH_OVERLAY_TEXTURE_TAB_COMPLETED);
- GlStateManager.color(1, 1, 1, 1);
- Utils.drawTexturedRect(
- width / 2 - 96 + 1,
- topY + 30 + num * 22 + 1,
- 193,
- 21,
- 0 / 512f,
- 193 / 512f,
- 0,
- 21 / 256f,
- GL11.GL_NEAREST
- );
- } else {
- Minecraft.getMinecraft().getTextureManager().bindTexture(SEARCH_OVERLAY_TEXTURE);
- GlStateManager.color(1, 1, 1, 1);
- Utils.drawTexturedRect(
- width / 2 - 96 + 1,
- topY + 30 + num * 22 + 1,
- 193,
- 21,
- 214 / 512f,
- 407 / 512f,
- 0,
- 21 / 256f,
- GL11.GL_NEAREST
- );
-
- }
- String itemName = Utils.trimIgnoreColour(stack.getDisplayName().replaceAll("\\[.+]", ""));
- if (itemName.contains("Enchanted Book") && str.contains(";")) {
- String[] lore = NotEnoughUpdates.INSTANCE.manager.getLoreFromNBT(stack.getTagCompound());
- itemName = lore[0].trim();
- }
-
- Minecraft.getMinecraft().fontRendererObj.drawString(Minecraft.getMinecraft().fontRendererObj.trimStringToWidth(
- itemName,
- 165
- ),
- width / 2 - 74, topY + 35 + num * 22 + 1, 0xdddddd, true
- );
-
- GlStateManager.enableDepth();
- Utils.drawItemStack(stack, width / 2 - 94 + 2, topY + 32 + num * 22 + 1);
+ public static boolean shouldReplace() {
+ return Minecraft.getMinecraft().currentScreen instanceof BazaarSearchOverlay;
+ }
- if (mouseX > width / 2 - 96 && mouseX < width / 2 + 96 && mouseY > topY + 30 + num * 22 &&
- mouseY < topY + 30 + num * 22 + 20) {
- tooltipToDisplay = stack.getTooltip(Minecraft.getMinecraft().thePlayer, false);
- }
+ public static boolean isinBzSign() {
+ if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) return false;
+ if (!NotEnoughUpdates.INSTANCE.config.bazaarTweaks.enableSearchOverlay) return false;
- if (++num >= 5) break;
- }
- }
+ if (!(Minecraft.getMinecraft().currentScreen instanceof GuiEditSign)) {
+ if (!NotEnoughUpdates.INSTANCE.config.bazaarTweaks.keepPreviousSearch) searchString = "";
+ return false;
}
- if (NotEnoughUpdates.INSTANCE.config.bazaarTweaks.showPastSearches) {
- Minecraft.getMinecraft(