diff options
| author | BuildTools <james.jenour@protonmail.com> | 2021-02-10 20:11:57 +0800 |
|---|---|---|
| committer | BuildTools <james.jenour@protonmail.com> | 2021-02-10 20:11:57 +0800 |
| commit | 52c6dabe58005aa5a7fc5809512bd8cf4ad4f97f (patch) | |
| tree | 9b71dd6e3e1478faceadf23dcfb359133cc7fe4e /src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java | |
| parent | a2292c332c22646bd177eaf3123ce31a74991e36 (diff) | |
| download | notenoughupdates-52c6dabe58005aa5a7fc5809512bd8cf4ad4f97f.tar.gz notenoughupdates-52c6dabe58005aa5a7fc5809512bd8cf4ad4f97f.tar.bz2 notenoughupdates-52c6dabe58005aa5a7fc5809512bd8cf4ad4f97f.zip | |
PRE18.1
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java')
| -rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java | 271 |
1 files changed, 183 insertions, 88 deletions
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 33322f8a..3401bb21 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java @@ -4,7 +4,9 @@ import com.google.common.base.Splitter; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.GuiElementTextField; +import io.github.moulberry.notenoughupdates.core.GuiScreenElementWrapper; import io.github.moulberry.notenoughupdates.mixins.GuiEditSignAccessor; +import io.github.moulberry.notenoughupdates.options.NEUConfigEditor; import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; @@ -13,15 +15,26 @@ import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.gui.inventory.GuiEditSign; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.item.ItemStack; +import net.minecraft.network.play.client.C0DPacketCloseWindow; import net.minecraft.tileentity.TileEntitySign; import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.ResourceLocation; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.text.WordUtils; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; import java.util.*; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicInteger; public class AuctionSearchOverlay { + private static final ResourceLocation SEARCH_OVERLAY_TEXTURE = new ResourceLocation("notenoughupdates:ah_search_overlay.png"); + private static GuiElementTextField textField = new GuiElementTextField("", 200, 20, 0); private static boolean searchFieldClicked = false; private static String searchString = ""; @@ -29,7 +42,7 @@ public class AuctionSearchOverlay { private static final int AUTOCOMPLETE_HEIGHT = 118; - private static Set<String> autocompletedItems = new LinkedHashSet<>(); + private static final Set<String> autocompletedItems = new LinkedHashSet<>(); private static final Comparator<String> salesComparator = (o1, o2) -> { JsonObject auctionInfo1 = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfo(o1); @@ -51,14 +64,21 @@ public class AuctionSearchOverlay { }; public static boolean shouldReplace() { - if(!(Minecraft.getMinecraft().currentScreen instanceof GuiEditSign)) return false; + if(!NotEnoughUpdates.INSTANCE.config.auctionHouseSearch.enableSearchOverlay) return false; + + if(!(Minecraft.getMinecraft().currentScreen instanceof GuiEditSign)) { + if(!NotEnoughUpdates.INSTANCE.config.auctionHouseSearch.keepPreviousSearch) searchString = ""; + return false; + } String lastContainer = SBInfo.getInstance().lastOpenContainerName; + if(lastContainer == null) return false; if(!lastContainer.equals("Auctions Browser") && !lastContainer.startsWith("Auctions: ")) return false; TileEntitySign tes = ((GuiEditSignAccessor)Minecraft.getMinecraft().currentScreen).getTileSign(); + if(tes == null) return false; if(tes.getPos().getY() != 0) return false; if(!tes.signText[2].getUnformattedText().equals("^^^^^^^^^^^^^^^")) return false; if(!tes.signText[3].getUnformattedText().equals("Enter query")) return false; @@ -75,55 +95,76 @@ public class AuctionSearchOverlay { Utils.drawGradientRect(0, 0, width, height, -1072689136, -804253680); - Minecraft.getMinecraft().fontRendererObj.drawString("Enter Query:", width/2-100, height/4-10, 0xdddddd, true); + int h = NotEnoughUpdates.INSTANCE.config.auctionHouseSearch.showPastSearches ? 219 : 145; + + int topY = height/4; + if(scaledResolution.getScaleFactor() >= 4) { + topY = height/2 - h/2 + 5; + } + + Minecraft.getMinecraft().getTextureManager().bindTexture(SEARCH_OVERLAY_TEXTURE); + Utils.drawTexturedRect(width/2-100, topY-1, 203, h, 0, 203/512f, 0, h/256f, GL11.GL_NEAREST); + + Minecraft.getMinecraft().fontRendererObj.drawString("Enter Query:", width/2-100, topY-10, 0xdddddd, true); textField.setText(searchString); - textField.render(width/2-100, height/4); + 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); + //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; - for(String str : autocompletedItems) { - JsonObject obj = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(str); - if(obj != null) { - ItemStack stack = NotEnoughUpdates.INSTANCE.manager.jsonToStack(obj); - Gui.drawRect(width/2-96, height/4+30+num*22, width/2+96, height/4+30+num*22+20, 0xff505050); - Minecraft.getMinecraft().fontRendererObj.drawString(Utils.trimIgnoreColour(stack.getDisplayName().replaceAll("\\[.+]", "")), - width/2-74, height/4+35+num*22, 0xdddddd, true); - - GlStateManager.enableDepth(); - Utils.drawItemStack(stack, width/2-94, height/4+32+num*22); - - if(mouseX > width/2-96 && mouseX < width/2+96 && mouseY > height/4+30+num*22 && mouseY < height/4+30+num*22+20) { - tooltipToDisplay = stack.getTooltip(Minecraft.getMinecraft().thePlayer, false); - } + synchronized(autocompletedItems) { + for(String str : autocompletedItems) { + JsonObject obj = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(str); + if(obj != null) { + ItemStack stack = NotEnoughUpdates.INSTANCE.manager.jsonToStack(obj); + //Gui.drawRect(width/2-96, height/4+30+num*22, width/2+96, height/4+30+num*22+20, 0xff505050); + + 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(";")) { + itemName = EnumChatFormatting.BLUE+WordUtils.capitalizeFully(str.split(";")[0].replace("_", " ")); + } + 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); + + 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); + } - if(++num >= 5) break; + if(++num >= 5) break; + } } } - Minecraft.getMinecraft().fontRendererObj.drawString("Past Searches:", width/2-100, height/4+25+ AUTOCOMPLETE_HEIGHT +5, 0xdddddd, true); - - int pastSearchHeight = 9 + 10 * Math.min(5, NotEnoughUpdates.INSTANCE.config.hidden.previousAuctionSearches.size()); + if(NotEnoughUpdates.INSTANCE.config.auctionHouseSearch.showPastSearches) { + Minecraft.getMinecraft().fontRendererObj.drawString("Past Searches:", width/2-100, topY+25+ AUTOCOMPLETE_HEIGHT +5, 0xdddddd, true); - Gui.drawRect(width/2-101, height/4+ AUTOCOMPLETE_HEIGHT +40, width/2+101, height/4+ AUTOCOMPLETE_HEIGHT +40+pastSearchHeight, 0xffffffff); - Gui.drawRect(width/2-100, height/4+ AUTOCOMPLETE_HEIGHT +40+1, width/2+100, height/4+ AUTOCOMPLETE_HEIGHT +40-1+pastSearchHeight, 0xff000000); + for(int i=0; i<5; i++) { + if(i >= NotEnoughUpdates.INSTANCE.config.hidden.previousAuctionSearches.size()) break; - for(int i=0; i<5; i++) { - if(i >= NotEnoughUpdates.INSTANCE.config.hidden.previousAuctionSearches.size()) break; + 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); + } - String s = NotEnoughUpdates.INSTANCE.config.hidden.previousAuctionSearches.get(i); - Minecraft.getMinecraft().fontRendererObj.drawString(s, width/2-95, height/4+45+ AUTOCOMPLETE_HEIGHT +i*10, 0xdddddd, true); + if(tooltipToDisplay != null) { + Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1, Minecraft.getMinecraft().fontRendererObj); + } } - if(tooltipToDisplay != null) { - Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1, Minecraft.getMinecraft().fontRendererObj); - } } public static void close() { @@ -189,45 +230,70 @@ public class AuctionSearchOverlay { } } + private static ExecutorService searchES = Executors.newSingleThreadExecutor(); + private static AtomicInteger searchId = new AtomicInteger(0); + public static void keyEvent() { - if(Keyboard.getEventKey() == Keyboard.KEY_ESCAPE || Keyboard.getEventKey() == Keyboard.KEY_RETURN) { + if(Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) { + close(); + if(NotEnoughUpdates.INSTANCE.config.auctionHouseSearch.escFullClose) { + Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(new C0DPacketCloseWindow(Minecraft.getMinecraft().thePlayer.openContainer.windowId)); + } + } else if(Keyboard.getEventKey() == Keyboard.KEY_RETURN) { close(); } else if(Keyboard.getEventKeyState()) { textField.setText(searchString); textField.keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey()); searchString = textField.getText(); - autocompletedItems.clear(); + 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(!searchString.trim().contains(" ")) { - StringBuilder sb = new StringBuilder(); - for(char c : searchString.toCharArray()) { - sb.append(c).append(" "); + 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())); } - title.addAll(NotEnoughUpdates.INSTANCE.manager.search("title:"+sb.toString().trim())); - } - List<String> desc = new ArrayList<>(NotEnoughUpdates.INSTANCE.manager.search("desc:"+searchString.trim())); - desc.removeAll(title); - Set<String> auctionableItems = NotEnoughUpdates.INSTANCE.manager.auctionManager.getLowestBinKeySet(); - auctionableItems.addAll(NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfoKeySet()); + if(thisSearchId != searchId.get()) return; - if(!auctionableItems.isEmpty()) { - title.retainAll(auctionableItems); - desc.retainAll(auctionableItems); + List<String> desc = new ArrayList<>(NotEnoughUpdates.INSTANCE.manager.search("desc:"+searchString.trim())); + desc.removeAll(title); - title.sort(salesComparator); - desc.sort(salesComparator); - } else { - Set<String> bazaarItems = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarKeySet(); + if(thisSearchId != searchId.get()) return; - title.removeAll(bazaarItems); - desc.removeAll(bazaarItems); - } + 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); + } - autocompletedItems.addAll(title); - autocompletedItems.addAll(desc); + if(thisSearchId != searchId.get()) return; + + synchronized(autocompletedItems) { + autocompletedItems.clear(); + autocompletedItems.addAll(title); + autocompletedItems.addAll(desc); + } + }); } } @@ -238,51 +304,80 @@ public class AuctionSearchOverlay { int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; + int h = NotEnoughUpdates.INSTANCE.config.auctionHouseSearch.showPastSearches ? 219 : 145; + + int topY = height/4; + if(scaledResolution.getScaleFactor() >= 4) { + topY = height/2 - h/2 + 5; + } + if(!Mouse.getEventButtonState() && Mouse.getEventButton() == -1 && searchFieldClicked) { - textField.mouseClickMove(mouseX-2, height/4+10, 0, 0); + textField.mouseClickMove(mouseX-2, topY+10, 0, 0); } if(Mouse.getEventButton() != -1) { searchFieldClicked = false; } - if(mouseX > width/2-100 && mouseX < width/2+100 && mouseY > height/4 && mouseY < height/4+20) { - if(Mouse.getEventButtonState()) { - searchFieldClicked = true; - textField.mouseClicked(mouseX-2, mouseY, Mouse.getEventButton()); - - if(Mouse.getEventButton() == 1) { - searchString = ""; - autocompletedItems.clear(); - } - } - } else if(Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { - int num = 0; - 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 >= height/4+30+num*22 && mouseY <= height/4+30+num*22+20) { - searchString = Utils.cleanColour(stack.getDisplayName().replaceAll("\\[.+]", "")).trim(); + 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) { close(); - return; + } else if(mouseX < width/2+100) { + close(); + Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(new C0DPacketCloseWindow(Minecraft.getMinecraft().thePlayer.openContainer.windowId)); + NotEnoughUpdates.INSTANCE.openGui = new GuiScreenElementWrapper(new NEUConfigEditor( + NotEnoughUpdates.INSTANCE.config, "AH Search GUI")); + } + } + } 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(";")) { + searchString = WordUtils.capitalizeFully(str.split(";")[0].replace("_", " ")); + } + close(); + return; + } + + if(++num >= 5) break; + } } - - if(++num >= 5) break; } - } - for(int i=0; i<5; i++) { - if(i >= NotEnoughUpdates.INSTANCE.config.hidden.previousAuctionSearches.size()) break; + if(NotEnoughUpdates.INSTANCE.config.auctionHouseSearch.showPastSearches) { + for(int i=0; i<5; i++) { + if(i >= NotEnoughUpdates.INSTANCE.config.hidden.previousAuctionSearches.size()) break; - String s = NotEnoughUpdates.INSTANCE.config.hidden.previousAuctionSearches.get(i); - if(mouseX >= width/2-95 && mouseX <= width/2+95 && mouseY >= height/4+45+AUTOCOMPLETE_HEIGHT+i*10 && mouseY <= height/4+45+AUTOCOMPLETE_HEIGHT+i*10+10) { - searchString = s; - close(); - return; + 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; + close(); + return; + } + } } } } + + } } |
