From a373c31ba136020d088c569c76008ecdc7744c3d Mon Sep 17 00:00:00 2001 From: Lulonaut Date: Tue, 7 Sep 2021 21:19:58 +0200 Subject: ah search overlay tab completion --- .../notenoughupdates/overlays/AuctionSearchOverlay.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/main/java/io') 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 816a6c63..2cfe176b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java @@ -20,6 +20,7 @@ import net.minecraft.tileentity.TileEntitySign; import net.minecraft.util.ChatComponentText; 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; @@ -334,6 +335,17 @@ public class AuctionSearchOverlay { } else if(Keyboard.getEventKey() == Keyboard.KEY_RETURN) { searchStringExtra = ""; close(); + } else if(Keyboard.getEventKey() == Keyboard.KEY_TAB){ + searchString = autocompletedItems.iterator().next(); + JsonObject repoObject = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(autocompletedItems.iterator().next()); + String displayname = repoObject.get("displayname").getAsString(); + if (displayname.contains("Enchanted Book")){ + String lore = repoObject.get("lore").getAsJsonArray().iterator().next().getAsString(); + String name = lore.substring(0, lore.lastIndexOf(" ")); + searchString = Utils.cleanColour(name); + } else { + searchString = Utils.cleanColour(displayname); + } } else if(Keyboard.getEventKeyState()) { textField.setFocus(true); textField.setText(searchString); -- cgit From 4886341cbc1009c1f6a67807f6ed24c28a124884 Mon Sep 17 00:00:00 2001 From: Lulonaut Date: Tue, 7 Sep 2021 21:21:31 +0200 Subject: unused import --- .../github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java | 1 - 1 file changed, 1 deletion(-) (limited to 'src/main/java/io') 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 2cfe176b..641f8a93 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java @@ -20,7 +20,6 @@ import net.minecraft.tileentity.TileEntitySign; import net.minecraft.util.ChatComponentText; 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; -- cgit From 818dc8f0d7711a4036d83db1304f7f776ce47f39 Mon Sep 17 00:00:00 2001 From: Lulonaut Date: Wed, 8 Sep 2021 14:17:55 +0200 Subject: make sure there are autocompleted items --- .../overlays/AuctionSearchOverlay.java | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/main/java/io') 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 641f8a93..8b3b21f0 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java @@ -335,15 +335,17 @@ public class AuctionSearchOverlay { searchStringExtra = ""; close(); } else if(Keyboard.getEventKey() == Keyboard.KEY_TAB){ - searchString = autocompletedItems.iterator().next(); - JsonObject repoObject = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(autocompletedItems.iterator().next()); - String displayname = repoObject.get("displayname").getAsString(); - if (displayname.contains("Enchanted Book")){ - String lore = repoObject.get("lore").getAsJsonArray().iterator().next().getAsString(); - String name = lore.substring(0, lore.lastIndexOf(" ")); - searchString = Utils.cleanColour(name); - } else { - searchString = Utils.cleanColour(displayname); + if (!autocompletedItems.isEmpty()) { + searchString = autocompletedItems.iterator().next(); + JsonObject repoObject = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(autocompletedItems.iterator().next()); + String displayname = repoObject.get("displayname").getAsString(); + if (displayname.contains("Enchanted Book")){ + String lore = repoObject.get("lore").getAsJsonArray().iterator().next().getAsString(); + String name = lore.substring(0, lore.lastIndexOf(" ")); + searchString = Utils.cleanColour(name); + } else { + searchString = Utils.cleanColour(displayname); + } } } else if(Keyboard.getEventKeyState()) { textField.setFocus(true); -- cgit From fc71a87b8d5a04e9252fede85cacb1de4ac92612 Mon Sep 17 00:00:00 2001 From: Lulonaut <67191924+Lulonaut@users.noreply.github.com> Date: Sun, 26 Sep 2021 21:02:18 +0200 Subject: Java not rust --- .../notenoughupdates/overlays/AuctionSearchOverlay.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/main/java/io') 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 8b3b21f0..dc31c686 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java @@ -334,17 +334,17 @@ public class AuctionSearchOverlay { } else if(Keyboard.getEventKey() == Keyboard.KEY_RETURN) { searchStringExtra = ""; close(); - } else if(Keyboard.getEventKey() == Keyboard.KEY_TAB){ + } else if(Keyboard.getEventKey() == Keyboard.KEY_TAB) { if (!autocompletedItems.isEmpty()) { - searchString = autocompletedItems.iterator().next(); + searchString = autocompletedItems.get(0); JsonObject repoObject = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(autocompletedItems.iterator().next()); - String displayname = repoObject.get("displayname").getAsString(); - if (displayname.contains("Enchanted Book")){ - String lore = repoObject.get("lore").getAsJsonArray().iterator().next().getAsString(); + String displayName = repoObject.get("displayname").getAsString(); + if (displayName.contains("Enchanted Book")){ + String lore = repoObject.get("lore").getAsJsonArray().get(0).getAsString(); String name = lore.substring(0, lore.lastIndexOf(" ")); searchString = Utils.cleanColour(name); } else { - searchString = Utils.cleanColour(displayname); + searchString = Utils.cleanColour(displayName); } } } else if(Keyboard.getEventKeyState()) { -- cgit From 60a33198da29aee56237853563860ff0320c6231 Mon Sep 17 00:00:00 2001 From: Lulonaut <67191924+Lulonaut@users.noreply.github.com> Date: Sun, 26 Sep 2021 21:06:37 +0200 Subject: Set still requires iterator --- .../moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/main/java/io') 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 dc31c686..ca7abc01 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java @@ -336,10 +336,10 @@ public class AuctionSearchOverlay { close(); } else if(Keyboard.getEventKey() == Keyboard.KEY_TAB) { if (!autocompletedItems.isEmpty()) { - searchString = autocompletedItems.get(0); + searchString = autocompletedItems.iterator().next(); JsonObject repoObject = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(autocompletedItems.iterator().next()); - String displayName = repoObject.get("displayname").getAsString(); - if (displayName.contains("Enchanted Book")){ + String displayname = repoObject.get("displayname").getAsString(); + if (displayname.contains("Enchanted Book")){ String lore = repoObject.get("lore").getAsJsonArray().get(0).getAsString(); String name = lore.substring(0, lore.lastIndexOf(" ")); searchString = Utils.cleanColour(name); -- cgit From d1f07c3b8bed9d2809ddc2177be1bd7acb9157a1 Mon Sep 17 00:00:00 2001 From: Lulonaut <67191924+Lulonaut@users.noreply.github.com> Date: Sun, 26 Sep 2021 21:08:45 +0200 Subject: forgot to change one name back please work now --- .../moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/io') 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 ca7abc01..f11c7974 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java @@ -344,7 +344,7 @@ public class AuctionSearchOverlay { String name = lore.substring(0, lore.lastIndexOf(" ")); searchString = Utils.cleanColour(name); } else { - searchString = Utils.cleanColour(displayName); + searchString = Utils.cleanColour(displayname); } } } else if(Keyboard.getEventKeyState()) { -- cgit From e598793adf941238928b69b0d7bcdb5a5e9c3a9c Mon Sep 17 00:00:00 2001 From: Lulonaut Date: Wed, 29 Sep 2021 20:10:51 +0200 Subject: added ability to go through the results with arrow keys --- .../overlays/AuctionSearchOverlay.java | 88 ++++++++++++++++++---- 1 file changed, 74 insertions(+), 14 deletions(-) (limited to 'src/main/java/io') 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 f11c7974..e900321d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java @@ -40,6 +40,8 @@ public class AuctionSearchOverlay { private static String searchString = ""; private static String searchStringExtra = ""; private static Splitter SPACE_SPLITTER = Splitter.on(" ").omitEmptyStrings().trimResults(); + private static boolean tabCompleted = false; + private static int tabCompletionIndex = 0; private static int selectedStars = 0; private static boolean atLeast = true; @@ -273,15 +275,35 @@ public class AuctionSearchOverlay { private static ExecutorService searchES = Executors.newSingleThreadExecutor(); private static AtomicInteger searchId = new AtomicInteger(0); + private static String getItemIdAtIndex(int i) { + if (!autocompletedItems.isEmpty()) { + if ((i > autocompletedItems.size() - 1) || i < 0) { + return ""; + } + String searchString = autocompletedItems.toArray()[i].toString(); + JsonObject repoObject = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(searchString); + String displayname = repoObject.get("displayname").getAsString(); + if (displayname.contains("Enchanted Book")) { + String lore = repoObject.get("lore").getAsJsonArray().get(0).getAsString(); + String name = lore.substring(0, lore.lastIndexOf(" ")); + return Utils.cleanColour(name); + } else { + return Utils.cleanColour(displayname); + } + } else { + return null; + } + } + public static void search() { final int thisSearchId = searchId.incrementAndGet(); searchES.submit(() -> { - if(thisSearchId != searchId.get()) return; + if (thisSearchId != searchId.get()) return; - List title = new ArrayList<>(NotEnoughUpdates.INSTANCE.manager.search("title:"+searchString.trim())); + List title = new ArrayList<>(NotEnoughUpdates.INSTANCE.manager.search("title:" + searchString.trim())); - if(thisSearchId != searchId.get()) return; + if (thisSearchId != searchId.get()) return; if(!searchString.trim().contains(" ")) { StringBuilder sb = new StringBuilder(); @@ -335,19 +357,57 @@ public class AuctionSearchOverlay { searchStringExtra = ""; close(); } else if(Keyboard.getEventKey() == Keyboard.KEY_TAB) { - if (!autocompletedItems.isEmpty()) { - searchString = autocompletedItems.iterator().next(); - JsonObject repoObject = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(autocompletedItems.iterator().next()); - String displayname = repoObject.get("displayname").getAsString(); - if (displayname.contains("Enchanted Book")){ - String lore = repoObject.get("lore").getAsJsonArray().get(0).getAsString(); - String name = lore.substring(0, lore.lastIndexOf(" ")); - searchString = Utils.cleanColour(name); - } else { - searchString = Utils.cleanColour(displayname); - } + //autocomplete to first item in the list + tabCompleted = true; + String id = getItemIdAtIndex(0); + if (id == null) { + tabCompleted = false; + textField.setFocus(true); + textField.setText(searchString); + } else { + searchString = id; } } else if(Keyboard.getEventKeyState()) { + if (tabCompleted) { + String id; + switch (Keyboard.getEventKey()) { + case Keyboard.KEY_DOWN: + id = getItemIdAtIndex(tabCompletionIndex + 1); + if (id == null) { + textField.setFocus(true); + textField.setText(searchString); + tabCompleted = false; + tabCompletionIndex = 0; + } else if (id.equals("")) { + //At the end of the autocompletion List, do nothing + return; + } else { + searchString = id; + tabCompletionIndex += 1; + return; + } + break; + case Keyboard.KEY_UP: + id = getItemIdAtIndex(tabCompletionIndex - 1); + if (id == null) { + textField.setFocus(true); + textField.setText(searchString); + tabCompleted = false; + tabCompletionIndex = 0; + } else if (id.equals("")) { + //At the end of the autocompletion List, do nothing + return; + } else { + searchString = id; + tabCompletionIndex -= 1; + return; + } + break; + default: + tabCompletionIndex = 0; + tabCompleted = false; + } + } textField.setFocus(true); textField.setText(searchString); textField.keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey()); -- cgit From 215e4a84802b9e02078ff0938cb1651bda673bc3 Mon Sep 17 00:00:00 2001 From: Lulonaut Date: Thu, 30 Sep 2021 15:55:14 +0200 Subject: highlight selected item with texture --- .../overlays/AuctionSearchOverlay.java | 35 +++++++++++++-------- .../auc_search/ah_search_overlay_tab_completed.png | Bin 0 -> 6969 bytes 2 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 src/main/resources/assets/notenoughupdates/auc_search/ah_search_overlay_tab_completed.png (limited to 'src/main/java/io') 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 e900321d..016e638b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java @@ -32,6 +32,7 @@ import java.util.concurrent.atomic.AtomicInteger; public class AuctionSearchOverlay { 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 STAR_BOARD = new ResourceLocation("notenoughupdates:auc_search/star_board.png"); @@ -41,7 +42,7 @@ public class AuctionSearchOverlay { private static String searchStringExtra = ""; private static Splitter SPACE_SPLITTER = Splitter.on(" ").omitEmptyStrings().trimResults(); private static boolean tabCompleted = false; - private static int tabCompletionIndex = 0; + private static int tabCompletionIndex = -1; private static int selectedStars = 0; private static boolean atLeast = true; @@ -148,24 +149,31 @@ public class AuctionSearchOverlay { int num = 0; synchronized(autocompletedItems) { - for(String str : autocompletedItems) { + String[] autoCompletedItemsArray = autocompletedItems.toArray(new String[0]); + for (int i = 0; i < autocompletedItems.size(); i++) { + String str = autoCompletedItemsArray[i]; JsonObject obj = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(str); - if(obj != null) { + 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); + 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); - 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(";")) { + 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); + width / 2 - 74, topY + 35 + num * 22 + 1, 0xdddddd, true); GlStateManager.enableDepth(); Utils.drawItemStack(stack, width/2-94+2, topY+32+num*22+1); @@ -277,7 +285,7 @@ public class AuctionSearchOverlay { private static String getItemIdAtIndex(int i) { if (!autocompletedItems.isEmpty()) { - if ((i > autocompletedItems.size() - 1) || i < 0) { + if ((i > autocompletedItems.size() - 1) || i < 0 || i > 4) { return ""; } String searchString = autocompletedItems.toArray()[i].toString(); @@ -365,6 +373,7 @@ public class AuctionSearchOverlay { textField.setFocus(true); textField.setText(searchString); } else { + tabCompletionIndex = 0; searchString = id; } } else if(Keyboard.getEventKeyState()) { @@ -377,7 +386,7 @@ public class AuctionSearchOverlay { textField.setFocus(true); textField.setText(searchString); tabCompleted = false; - tabCompletionIndex = 0; + tabCompletionIndex = -1; } else if (id.equals("")) { //At the end of the autocompletion List, do nothing return; @@ -393,7 +402,7 @@ public class AuctionSearchOverlay { textField.setFocus(true); textField.setText(searchString); tabCompleted = false; - tabCompletionIndex = 0; + tabCompletionIndex = -1; } else if (id.equals("")) { //At the end of the autocompletion List, do nothing return; @@ -404,7 +413,7 @@ public class AuctionSearchOverlay { } break; default: - tabCompletionIndex = 0; + tabCompletionIndex = -1; tabCompleted = false; } } diff --git a/src/main/resources/assets/notenoughupdates/auc_search/ah_search_overlay_tab_completed.png b/src/main/resources/assets/notenoughupdates/auc_search/ah_search_overlay_tab_completed.png new file mode 100644 index 00000000..b5cf62c0 Binary files /dev/null and b/src/main/resources/assets/notenoughupdates/auc_search/ah_search_overlay_tab_completed.png differ -- cgit