diff options
| author | unknown <james.jenour@protonmail.com> | 2020-06-14 21:54:45 +1000 |
|---|---|---|
| committer | unknown <james.jenour@protonmail.com> | 2020-06-14 21:54:45 +1000 |
| commit | fcf1a7b2b39b03b726e4c356bc265b7341217602 (patch) | |
| tree | e9e95c68ee5b7448bb2d100b4cc010abb6609040 /src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java | |
| parent | 2e41811a26d3abf205506ba9ad54c0d4fe52bebd (diff) | |
| download | notenoughupdates-fcf1a7b2b39b03b726e4c356bc265b7341217602.tar.gz notenoughupdates-fcf1a7b2b39b03b726e4c356bc265b7341217602.tar.bz2 notenoughupdates-fcf1a7b2b39b03b726e4c356bc265b7341217602.zip | |
BETA-1.6 but for real this time
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java')
| -rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java | 799 |
1 files changed, 479 insertions, 320 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java index e60ca14f..59233882 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java @@ -6,7 +6,6 @@ import io.github.moulberry.notenoughupdates.infopanes.*; import io.github.moulberry.notenoughupdates.itemeditor.NEUItemEditor; import io.github.moulberry.notenoughupdates.util.LerpingFloat; import io.github.moulberry.notenoughupdates.util.LerpingInteger; -import io.github.moulberry.notenoughupdates.util.TexLoc; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.*; import net.minecraft.client.gui.inventory.GuiContainer; @@ -17,14 +16,15 @@ import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.client.resources.model.IBakedModel; import net.minecraft.client.shader.Framebuffer; import net.minecraft.client.shader.Shader; -import net.minecraft.client.shader.ShaderGroup; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.inventory.Slot; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.EnumFacing; import net.minecraft.util.Matrix4f; @@ -34,9 +34,9 @@ import org.apache.commons.lang3.StringUtils; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL14; import java.awt.*; -import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.text.NumberFormat; @@ -68,23 +68,19 @@ public class NEUOverlay extends Gui { order_alphabetical_active, order_rarity_active }; + //Various constants used for GUI structure private int searchBarXSize = 200; private final int searchBarYOffset = 10; private final int searchBarYSize = 40; private final int searchBarPadding = 2; - public static final int BOX_PADDING = 15; + private static final int BOX_PADDING = 15; public static final int ITEM_PADDING = 4; public static final int ITEM_SIZE = 16; private Color bg = new Color(90, 90, 140, 50); private Color fg = new Color(100,100,100, 255); - //private String informationPaneTitle; - //private ResourceLocation informationPaneImage = null; - //private String[] informationPane; - //private AtomicInteger webpageAwaitID = new AtomicInteger(-1); - //private boolean configOpen = false; private InfoPane activeInfoPane = null; private TreeSet<JsonObject> searchedItems = null; @@ -121,12 +117,17 @@ public class NEUOverlay extends Gui { private ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); + private boolean disabled = false; + public NEUOverlay(NEUManager manager) { this.manager = manager; textField.setFocused(true); textField.setCanLoseFocus(false); } + /** + * Disables searchBarFocus and resets the item pane position. Called whenever NEUOverlay is opened. + */ public void reset() { searchBarHasFocus = false; if(!(searchMode || (manager.config.keepopen.value && itemPaneOpen))) { @@ -136,6 +137,9 @@ public class NEUOverlay extends Gui { } } + /** + * Calls #displayInformationPane with a HTMLInfoPane created from item.info and item.infoType. + */ public void showInfo(JsonObject item) { if(item.has("info") && item.has("infoType")) { JsonArray lore = item.get("info").getAsJsonArray(); @@ -163,6 +167,10 @@ public class NEUOverlay extends Gui { * Handles the mouse input, cancelling the forge event if a NEU gui element is clicked. */ public boolean mouseInput() { + if(disabled) { + return false; + } + int width = scaledresolution.getScaledWidth(); int height = scaledresolution.getScaledHeight(); @@ -208,8 +216,8 @@ public class NEUOverlay extends Gui { if(!clickedItem.get()) { int paneWidth = (int)(width/3*getWidthMult()); int leftSide = (int)(width*getItemPaneOffsetFactor()); - int rightSide = leftSide+paneWidth-BOX_PADDING-getItemBoxXPadding(); - leftSide = leftSide+BOX_PADDING+getItemBoxXPadding(); + int rightSide = leftSide+paneWidth-getBoxPadding()-getItemBoxXPadding(); + leftSide = leftSide+getBoxPadding()+getItemBoxXPadding(); FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; int maxPages = getMaxPages(); @@ -219,7 +227,7 @@ public class NEUOverlay extends Gui { int buttonXSize = (int)Math.min(maxButtonXSize, getSearchBarYSize()*480/160f); int ySize = (int)(buttonXSize/480f*160); int yOffset = (int)((getSearchBarYSize()-ySize)/2f); - int top = BOX_PADDING+yOffset; + int top = getBoxPadding()+yOffset; if(mouseY >= top && mouseY <= top+ySize) { int leftPrev = leftSide-1; @@ -233,16 +241,16 @@ public class NEUOverlay extends Gui { } float sortIconsMinX = (sortIcons.length+orderIcons.length)*(ITEM_SIZE+ITEM_PADDING)+ITEM_SIZE; - float availableX = rightSide-(leftSide+BOX_PADDING+getItemBoxXPadding()); + float availableX = rightSide-leftSide; float sortOrderScaleFactor = Math.min(1, availableX / sortIconsMinX); int scaledITEM_SIZE = (int)(ITEM_SIZE*sortOrderScaleFactor); int scaledItemPaddedSize = (int)((ITEM_SIZE+ITEM_PADDING)*sortOrderScaleFactor); - int iconTop = height-BOX_PADDING-(ITEM_SIZE+scaledITEM_SIZE)/2-1; + int iconTop = height-getBoxPadding()-(ITEM_SIZE+scaledITEM_SIZE)/2-1; if(mouseY >= iconTop && mouseY <= iconTop+scaledITEM_SIZE) { for(int i=0; i<orderIcons.length; i++) { - int orderIconX = leftSide+BOX_PADDING+getItemBoxXPadding()+i*scaledItemPaddedSize; + int orderIconX = leftSide+i*scaledItemPaddedSize; if(mouseX >= orderIconX && mouseX <= orderIconX+scaledITEM_SIZE) { if(Mouse.getEventButton() == 0) { manager.config.compareMode.value = new Double(i); @@ -289,6 +297,39 @@ public class NEUOverlay extends Gui { } } + + //Quickcommands + int paddingUnscaled = searchBarPadding/scaledresolution.getScaleFactor(); + if(paddingUnscaled < 1) paddingUnscaled = 1; + int topTextBox = height - searchBarYOffset - getSearchBarYSize(); + + if(Mouse.getEventButtonState() && manager.config.showQuickCommands.value) { + ArrayList<String> quickCommands = manager.config.quickCommands.value; + int bigItemSize = getSearchBarYSize(); + int bigItemPadding = paddingUnscaled*4; + int xStart = width/2 + bigItemPadding/2 - (bigItemSize+bigItemPadding)*quickCommands.size()/2; + int xEnd = width/2 - bigItemPadding/2 + (bigItemSize+bigItemPadding)*quickCommands.size()/2; + int y = topTextBox - bigItemSize - bigItemPadding - paddingUnscaled*2; + + if(mouseY >= y && mouseY <= topTextBox-paddingUnscaled*2) { + if(mouseX > xStart && mouseX < xEnd) { + if((mouseX - xStart)%(bigItemSize+bigItemPadding) < bigItemSize) { + int index = (mouseX - xStart)/(bigItemSize+bigItemPadding); + if(index >= 0 && index < quickCommands.size()) { + String quickCommand = quickCommands.get(index); + if(quickCommand.contains(":")) { + String command = quickCommand.split(":")[0].trim(); + if(command.startsWith("/")) { + NotEnoughUpdates.INSTANCE.sendChatMessage(command); + return true; + } + } + } + } + } + } + } + //Search bar if(mouseX >= width/2 - getSearchBarXSize()/2 && mouseX <= width/2 + getSearchBarXSize()/2) { if(mouseY >= height - searchBarYOffset - getSearchBarYSize() && @@ -310,10 +351,7 @@ public class NEUOverlay extends Gui { } } - int paddingUnscaled = searchBarPadding/scaledresolution.getScaleFactor(); - int topTextBox = height - searchBarYOffset - getSearchBarYSize(); int iconSize = getSearchBarYSize()+paddingUnscaled*2; - if(paddingUnscaled < 1) paddingUnscaled = 1; if(mouseY > topTextBox - paddingUnscaled && mouseY < topTextBox - paddingUnscaled + iconSize) { if(mouseX > width/2 + getSearchBarXSize()/2 + paddingUnscaled*6 && @@ -344,11 +382,17 @@ public class NEUOverlay extends Gui { return false; } + /** + * Returns searchBarXSize, scaled by 0.8 if gui scale == AUTO. + */ public int getSearchBarXSize() { if(scaledresolution.getScaleFactor()==4) return (int)(searchBarXSize*0.8); return searchBarXSize; } + /** + * Sets the activeInfoPane and sets the target of the infoPaneOffsetFactor to make the infoPane "slide" out. + */ public void displayInformationPane(InfoPane pane) { if(pane == null) { infoPaneOffsetFactor.setTarget(0); @@ -363,79 +407,9 @@ public class NEUOverlay extends Gui { return activeInfoPane; } - /*public void displayInformationPane(String title, String infoType, String[] info) { - scrollHeight.setValue(0); - informationPaneTitle = title; - informationPaneImage = null; - informationPane = null; - - configOpen = false; - - infoPaneOffsetFactor.setTarget(1/3f); - infoPaneOffsetFactor.resetTimer(); - - webpageAwaitID.incrementAndGet(); - - if(info == null || info.length == 0) { - informationPane = new String[]{"\u00A77No additional information."}; - } else { - String joined = StringUtils.join(info, "\n"); - String wiki = null; - String html = null; - if(infoType.equals("TEXT")) { - informationPane = info; - return; - } else if(infoType.equals("WIKI_URL")) { - File f = manager.getWebFile(joined); - if(f == null) { - informationPane = new String[] { EnumChatFormatting.RED+"Failed to load wiki url: "+joined }; - return; - }; - - StringBuilder sb = new StringBuilder(); - try(BufferedReader br = new BufferedReader(new InputStreamReader( - new FileInputStream(f), StandardCharsets.UTF_8))) { - String l; - while((l = br.readLine()) != null){ - sb.append(l).append("\n"); - } - } catch(IOException e) { - informationPane = new String[] { EnumChatFormatting.RED+"Failed to load wiki url: "+joined }; - return; - } - wiki = sb.toString(); - } - - if(infoType.equals("WIKI") || wiki != null) { - if(wiki == null) wiki = joined; - try { - String[] split = wiki.split("</infobox>"); - wiki = split[split.length - 1]; //Remove everything before infobox - wiki = wiki.split("<span class=\"navbox-vde\">")[0]; //Remove navbox - wiki = wiki.split("<table class=\"navbox mw-collapsible\"")[0]; - wiki = "__NOTOC__\n" + wiki; //Remove TOC - try (PrintWriter out = new PrintWriter(new File(manager.configLocation, "debug/parsed.txt"))) { - out.println(wiki); - } catch (IOException e) { - } - html = wikiModel.render(wiki); - try (PrintWriter out = new PrintWriter(new File(manager.configLocation, "debug/html.txt"))) { - out.println(html); - } catch (IOException e) { - } - } catch (Exception e) { - informationPane = new String[]{EnumChatFormatting.RED + "Failed to parse wiki: " + joined}; - return; - } - } - - if(infoType.equals("HTML") || html != null) { - if(html == null) html = joined; - processAndSetWebpageImage(html, title); - } - } - }*/ - + /** + * Finds the index of the character inside the search bar that was clicked, used to set the caret. + */ public int getClickedIndex(int mouseX, int mouseY) { int width = scaledresolution.getScaledWidth(); int height = scaledresolution.getScaledHeight(); @@ -469,23 +443,46 @@ public class NEUOverlay extends Gui { if(Minecraft.getMinecraft().currentScreen == null) return false; Keyboard.enableRepeatEvents(true); - if(Keyboard.isKeyDown(Keyboard.KEY_Y)) { + int keyPressed = Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter() : Keyboard.getEventKey(); + + if(disabled) { + if(Keyboard.getEventKeyState() && keyPressed == manager.keybindToggleDisplay.getKeyCode()) { + disabled = !disabled; + } + return false; + } + + if(Keyboard.isKeyDown(Keyboard.KEY_Y) && manager.config.dev.value) { displayInformationPane(new DevInfoPane(this, manager)); //displayInformationPane(new QOLInfoPane(this, manager)); } if(Keyboard.getEventKeyState()) { if(searchBarHasFocus) { - if(Keyboard.getEventKey() == 1) { + if(keyPressed == 1) { searchBarHasFocus = false; } else { - if(textField.textboxKeyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey())) { + if(textField.textboxKeyTyped(Keyboard.getEventCharacter(), keyPressed)) { updateSearch(); } } } else { if(activeInfoPane != null) { - activeInfoPane.keyboardInput(); + if(activeInfoPane.keyboardInput()) { + return true; + } + } + + if(keyPressed == manager.keybindClosePanes.getKeyCode()) { + itemPaneOffsetFactor.setValue(1); + itemPaneTabOffset.setValue(20); + itemPaneOpen = false; + displayInformationPane(null); + } + + if(keyPressed == manager.keybindToggleDisplay.getKeyCode()) { + disabled = !disabled; + return true; } AtomicReference<String> internalname = new AtomicReference<>(null); @@ -524,16 +521,16 @@ public class NEUOverlay extends Gui { } JsonObject item = manager.getItemInformation().get(internalname.get()); if(item != null) { - if(Keyboard.getEventCharacter() == 'u') { + if(keyPressed == manager.keybindViewUsages.getKeyCode()) { manager.displayGuiItemUsages(internalname.get(), ""); return true; - } else if(Keyboard.getEventCharacter() == 'f') { - toggleRarity(item.get("internalname").getAsString()); + } else if(keyPressed == manager.keybindFavourite.getKeyCode()) { + toggleFavourite(item.get("internalname").getAsString()); return true; - } else if(Keyboard.getEventCharacter() == 'r') { + } else if(keyPressed == manager.keybindViewRecipe.getKeyCode()) { manager.showRecipe(item); return true; - } else if(Keyboard.getEventCharacter() == 'l') { + } else if(keyPressed == manager.keybindGive.getKeyCode()) { if(Minecraft.getMinecraft().thePlayer.capabilities.isCreativeMode) { Minecraft.getMinecraft().thePlayer.inventory.addItemStackToInventory( manager.jsonToStack(item)); @@ -551,7 +548,7 @@ public class NEUOverlay extends Gui { return searchBarHasFocus; //Cancels keyboard events if the search bar has focus } - public void toggleRarity(String internalname) { + public void toggleFavourite(String internalname) { if(getFavourites().contains(internalname)) { getFavourites().remove(internalname); } else { @@ -568,6 +565,17 @@ public class NEUOverlay extends Gui { EnumChatFormatting.GOLD+EnumChatFormatting.BOLD.toString()+"LEGENDARY", EnumChatFormatting.LIGHT_PURPLE+EnumChatFormatting.BOLD.toString()+"SPECIAL", }; + + /** + * Finds the rarity from the lore of an item. + * -1 = UNKNOWN + * 0 = COMMON + * 1 = UNCOMMON + * 2 = RARE + * 3 = EPIC + * 4 = LEGENDARY + * 5 = SPECIAL + */ public int getRarity(JsonArray lore) { for(int i=lore.size()-1; i>=0; i--) { String line = lore.get(i).getAsString(); @@ -581,6 +589,9 @@ public class NEUOverlay extends Gui { return -1; } + /** + * Convenience functions that get various compare/sort modes from the config. + */ private int getCompareMode() { return manager.config.compareMode.value.intValue(); } @@ -594,6 +605,10 @@ public class NEUOverlay extends Gui { return manager.config.favourites.value; } + /** + * Creates an item comparator used to sort the list of items according to the favourite set then compare mode. + * Defaults to alphabetical sorting if the above factors cannot distinguish between two items. + */ private Comparator<JsonObject> getItemComparator() { return (o1, o2) -> { //1 (mult) if o1 should appear after o2 @@ -644,6 +659,11 @@ public class NEUOverlay extends Gui { }; } + /** + * Checks whether an item matches a certain type, i.e. whether the item lore ends in "{rarity} {item type}" + * eg. "SHOVEL" will return >0 for "COMMON SHOVEL", "EPIC SHOVEL", etc. + * @return the index of the type that matched, or -1 otherwise. + */ public int checkItemType(JsonArray lore, String... typeMatches) { for(int i=lore.size()-1; i>=0; i--) { String line = lore.get(i).getAsString(); @@ -659,6 +679,9 @@ public class NEUOverlay extends Gui { return -1; } + /** + * Checks whether an item matches the current sort mode. + */ public boolean checkMatchesSort(String internalname, JsonObject item) { if(getSortMode() == SORT_MODE_ALL) { return !internalname.matches(mobRegex); @@ -677,20 +700,44 @@ public class NEUOverlay extends Gui { return true; } + /** + * Clears the current item list, creating a new TreeSet if necessary. + * Adds all items that match the search AND match the sort mode to the current item list. + * Also adds some easter egg items. (Also I'm very upset if you came here to find them :'( ) + */ public void updateSearch() { if(searchedItems==null) searchedItems = new TreeSet<>(getItemComparator()); searchedItems.clear(); searchedItemsArr = null; redrawItems = true; - Set<String> itemsMatch = manager.search(textField.getText()); + Set<String> itemsMatch = manager.search(textField.getText(), true); for(String itemname : itemsMatch) { JsonObject item = manager.getItemInformation().get(itemname); if(checkMatchesSort(itemname, item)) { searchedItems.add(item); } } + switch(textField.getText().toLowerCase().trim()) { + case "nullzee": + searchedItems.add(CustomItems.NULLZEE); + break; + case "rune": + searchedItems.add(CustomItems.RUNE); + break; + case "2b2t": + searchedItems.add(CustomItems.TWOBEETWOTEE); + break; + case "ducttape": + case "ducttapedigger": + searchedItems.add(CustomItems.DUCTTAPE); + break; + } } + /** + * Returns an index-able array containing the elements in searchedItems. + * Whenever searchedItems is updated via the above method, the array is recreated here. + */ public JsonObject[] getSearchedItems() { if(searchedItems==null) { updateSearch(); @@ -706,6 +753,10 @@ public class NEUOverlay extends Gui { return searchedItemsArr; } + /** + * Gets the item in searchedItemArr corresponding to the certain index on the current page. + * @return item, if the item exists. null, otherwise. + */ public JsonObject getSearchedItemPage(int index) { if(index < getSlotsXSize()*getSlotsYSize()) { int actualIndex = index + getSlotsXSize()*getSlotsYSize()*page; @@ -721,7 +772,11 @@ public class NEUOverlay extends Gui { public int getItemBoxXPadding() { int width = scaledresolution.getScaledWidth(); - return (((int)(width/3*getWidthMult())-2*BOX_PADDING)%(ITEM_SIZE+ITEM_PADDING)+ITEM_PADDING)/2; + return (((int)(width/3*getWidthMult())-2*getBoxPadding())%(ITEM_SIZE+ITEM_PADDING)+ITEM_PADDING)/2; + } + + public int getBoxPadding() { + return (BOX_PADDING-5)*2/scaledresolution.getScaleFactor()+5; } private abstract class ItemSlotConsumer { @@ -731,7 +786,7 @@ public class NEUOverlay extends Gui { public void iterateItemSlots(ItemSlotConsumer itemSlotConsumer) { int width = scaledresolution.getScaledWidth(); int itemBoxXPadding = getItemBoxXPadding(); - iterateItemSlots(itemSlotConsumer, (int)(width*getItemPaneOffsetFactor())+BOX_PADDING+itemBoxXPadding); + iterateItemSlots(itemSlotConsumer, (int)(width*getItemPaneOffsetFactor())+getBoxPadding()+itemBoxXPadding); } /** @@ -744,12 +799,12 @@ public class NEUOverlay extends Gui { int height = scaledresolution.getScaledHeight(); int paneWidth = (int)(width/3*getWidthMult()); - int itemBoxYPadding = ((height-getSearchBarYSize()-2*BOX_PADDING-ITEM_SIZE-2)%(ITEM_SIZE+ITEM_PADDING)+ITEM_PADDING)/2; + int itemBoxYPadding = ((height-getSearchBarYSize()-2*getBoxPadding()-ITEM_SIZE-2)%(ITEM_SIZE+ITEM_PADDING)+ITEM_PADDING)/2; - int yStart = BOX_PADDING+getSearchBarYSize()+itemBoxYPadding; + int yStart = getBoxPadding()+getSearchBarYSize()+itemBoxYPadding; int itemBoxXPadding = getItemBoxXPadding(); - int xEnd = xStart+paneWidth-BOX_PADDING*2-ITEM_SIZE-itemBoxXPadding; - int yEnd = height-BOX_PADDING-ITEM_SIZE-2-itemBoxYPadding; + int xEnd = xStart+paneWidth-getBoxPadding()*2-ITEM_SIZE-itemBoxXPadding; + int yEnd = height-getBoxPadding()-ITEM_SIZE-2-itemBoxYPadding; //Render the items, displaying the tooltip if the cursor is over the item int id = 0; @@ -773,9 +828,9 @@ public class NEUOverlay extends Gui { int width = scaledresolution.getScaledWidth(); int paneWidth = (int)(width/3*getWidthMult()); - int itemBoxXPadding = (((int)(width-width*getItemPaneOffsetFactor())-2*BOX_PADDING)%(ITEM_SIZE+ITEM_PADDING)+ITEM_PADDING)/2; - int xStart = (int)(width*getItemPaneOffsetFactor())+BOX_PADDING+itemBoxXPadding; - int xEnd = (int)(width*getItemPaneOffsetFactor())+paneWidth-BOX_PADDING-ITEM_SIZE; + int itemBoxXPadding = (((int)(width-width*getItemPaneOffsetFactor())-2*getBoxPadding())%(ITEM_SIZE+ITEM_PADDING)+ITEM_PADDING)/2; + int xStart = (int)(width*getItemPaneOffsetFactor())+getBoxPadding()+itemBoxXPadding; + int xEnd = (int)(width*getItemPaneOffsetFactor())+paneWidth-getBoxPadding()-ITEM_SIZE; return (int)Math.ceil((xEnd - xStart)/((float)(ITEM_SIZE+ITEM_PADDING))); } @@ -786,9 +841,9 @@ public class NEUOverlay extends Gui { public int getSlotsYSize() { int height = scaledresolution.getScaledHeight(); - int itemBoxYPadding = ((height-getSearchBarYSize()-2*BOX_PADDING-ITEM_SIZE-2)%(ITEM_SIZE+ITEM_PADDING)+ITEM_PADDING)/2; - int yStart = BOX_PADDING+getSearchBarYSize()+itemBoxYPadding; - int yEnd = height-BOX_PADDING-ITEM_SIZE-2-itemBoxYPadding; + int itemBoxYPadding = ((height-getSearchBarYSize()-2*getBoxPadding()-ITEM_SIZE-2)%(ITEM_SIZE+ITEM_PADDING)+ITEM_PADDING)/2; + int yStart = getBoxPadding()+getSearchBarYSize()+itemBoxYPadding; + int yEnd = height-getBoxPadding()-ITEM_SIZE-2-itemBoxYPadding; return (int)Math.ceil((yEnd - yStart)/((float)(ITEM_SIZE+ITEM_PADDING))); } @@ -798,28 +853,14 @@ public class NEUOverlay extends Gui { return (int)Math.ceil(getSearchedItems().length/(float)getSlotsYSize()/getSlotsXSize()); } - /** - * Takes in the x and y coordinates of a slot and returns the id of that slot. - */ - /*public int getSlotId(int x, int y) { - int width = scaledresolution.getScaledWidth(); - int height = scaledresolution.getScaledHeight(); - - int itemBoxXPadding = (((int)(width-width*getItemPaneOffsetFactor())-2*BOX_PADDING)%(ITEM_SIZE+ITEM_PADDING)+ITEM_PADDING)/2; - int itemBoxYPadding = ((height-getSearchBarYSize()-2*BOX_PADDING-ITEM_SIZE-2)%(ITEM_SIZE+ITEM_PADDING)+ITEM_PADDING)/2; - - int xStart = (int)(width*getItemPaneOffsetFactor())+BOX_PADDING+itemBoxXPadding; - int yStart = BOX_PADDING+getSearchBarYSize()+itemBoxYPadding; - - int xIndex = (x-xStart)/(ITEM_SIZE+ITEM_PADDING); - int yIndex = (y-yStart)/(ITEM_SIZE+ITEM_PADDING); - return xIndex + yIndex*getSlotsXSize(); - }*/ - public int getSearchBarYSize() { return Math.max(searchBarYSize/scaledresolution.getScaleFactor(), ITEM_SIZE); } + /** + * Renders the top navigation bar, can be used by InfoPane implementations (such as SettingsInfoPane). + * Renders "prev" button, index/maxIndex string, "next" button. + */ public void renderNavElement(int leftSide, int rightSide, int maxPages, int page, String name) { FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; @@ -830,11 +871,7 @@ public class NEUOverlay extends Gui { int buttonXSize = (int)Math.min(maxButtonXSize, getSearchBarYSize()*480/160f); int ySize = (int)(buttonXSize/480f*160); int yOffset = (int)((getSearchBarYSize()-ySize)/2f); - int top = BOX_PADDING+yOffset; - - /*drawRect(leftSide-1, top, - rightSide+1, - top+ySize, fg.getRGB());*/ + int top = getBoxPadding()+yOffset; int leftPressed = 0; int rightPressed = 0; @@ -907,6 +944,9 @@ public class NEUOverlay extends Gui { public float yaw = 0; public float pitch = 20; + /** + * Renders an entity onto the GUI at a certain x and y position. + */ private void renderEntity(float posX, float posY, float scale, String name, Class<? extends EntityLivingBase>... classes) { EntityLivingBase[] entities = new EntityLivingBase[classes.length]; try { @@ -972,6 +1012,10 @@ public class NEUOverlay extends Gui { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); } + /** + * Renders black squares over the inventory to indicate items that do not match a specific search. (When searchMode + * is enabled) + */ public void renderOverlay(int mouseX, int mouseY) { if(searchMode && textField.getText().length() > 0) { GuiContainer inv = (GuiContainer) Minecraft.getMinecraft().currentScreen; @@ -1008,6 +1052,13 @@ public class NEUOverlay extends Gui { Shader blurShaderVert = null; Framebuffer blurOutputVert = null; + /** + * Creates a projection matrix that projects from our coordinate space [0->width; 0->height] to OpenGL coordinate + * space [-1 -> 1; 1 -> -1] (Note: flipped y-axis). + * + * This is so that we can render to and from the framebuffer in a way that is familiar to us, instead of needing to + * apply scales and translations manually. + */ private Matrix4f createProjectionMatrix(int width, int height) { Matrix4f projMatrix = new Matrix4f(); projMatrix.setIdentity(); @@ -1021,12 +1072,18 @@ public class NEUOverlay extends Gui { return projMatrix; } + /** + * Renders whatever is currently in the Minecraft framebuffer to our two framebuffers, applying a horizontal + * and vertical blur separately in order to significantly save computation time. + * This is only possible if framebuffers are supported by the system, so this method will exit prematurely + * if framebuffers are not available. (Apple machines, for example, have poor framebuffer support). + */ private double lastBgBlurFactor = 5; private void blurBackground() { int width = Minecraft.getMinecraft().displayWidth; int height = Minecraft.getMinecraft().displayHeight; - if(manager.config.bgBlurFactor.value <= 0) return; + if(manager.config.bgBlurFactor.value <= 0 || !OpenGlHelper.isFramebufferEnabled()) return; if(blurOutputHorz == null) { blurOutputHorz = new Framebuffer(width, height, false); @@ -1079,8 +1136,12 @@ public class NEUOverlay extends Gui { } } + /** + * Renders a subsection of the blurred framebuffer on to the corresponding section of the screen. + * Essentially, this method will "blur" the background inside the bounds specified by [x->x+blurWidth, y->y+blurHeight] + */ public void renderBlurredBackground(int width, int height, int x, int y, int blurWidth, int blurHeight) { - if(manager.config.bgBlurFactor.value <= 0) return; + if(manager.config.bgBlurFactor.value <= 0 || !OpenGlHelper.isFramebufferEnabled()) return; int f = scaledresolution.getScaleFactor(); float uMin = x/(float)width; @@ -1099,9 +1160,12 @@ public class NEUOverlay extends Gui { int guiScaleLast = 0; /** - * Renders the search bar, item selection (right) and item info (left) gui elements. + * Renders the search bar, quick commands, item selection (right) and item info (left) gui elements. */ public void render(int mouseX, int mouseY, boolean hoverInv) { + if(disabled) { + return; + } FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); int width = scaledresolution.getScaledWidth(); @@ -1163,108 +1227,11 @@ public class NEUOverlay extends Gui { GlStateManager.disableLighting(); /** - * Search bar - */ - int paddingUnscaled = searchBarPadding/scaledresolution.getScaleFactor(); - if(paddingUnscaled < 1) paddingUnscaled = 1; - - int topTextBox = height - searchBarYOffset - getSearchBarYSize(); - - /*Minecraft.getMinecraft().getTextureManager().bindTexture(logo_bg); - GlStateManager.color(1f, 1f, 1f, 1f); - Utils.drawTexturedRect((width)/2-37, - height - searchBarYOffset - getSearchBarYSize()-30, - 74, 54); - GlStateManager.bindTexture(0);*/ - - //Search bar background - drawRect(width/2 - getSearchBarXSize()/2 - paddingUnscaled, - topTextBox - paddingUnscaled, - width/2 + getSearchBarXSize()/2 + paddingUnscaled, - height - searchBarYOffset + paddingUnscaled, searchMode ? Color.YELLOW.getRGB() : Color.WHITE.getRGB()); - drawRect(width/2 - getSearchBarXSize()/2, - topTextBox, - width/2 + getSearchBarXSize()/2, - height - searchBarYOffset, Color.BLACK.getRGB()); - - /*Minecraft.getMinecraft().getTextureManager().bindTexture(logo_fg); - GlStateManager.color(1f, 1f, 1f, 1f); - Utils.drawTexturedRect((width)/2-37, - height - searchBarYOffset - getSearchBarYSize()-27, - 74, 54); - GlStateManager.bindTexture(0);*/ - - //Settings - int iconSize = getSearchBarYSize()+paddingUnscaled*2; - Minecraft.getMinecraft().getTextureManager().bindTexture(settings); - drawRect(width/2 - getSearchBarXSize()/2 - paddingUnscaled*6 - iconSize, - topTextBox - paddingUnscaled, - width/2 - getSearchBarXSize()/2 - paddingUnscaled*6, - topTextBox - paddingUnscaled + iconSize, Color.WHITE.getRGB()); - - drawRect(width/2 - getSearchBarXSize()/2 - paddingUnscaled*5 - iconSize, - topTextBox, - width/2 - getSearchBarXSize()/2 - paddingUnscaled*7, - topTextBox - paddingUnscaled*2 + iconSize, Color.GRAY.getRGB()); - GlStateManager.color(1f, 1f, 1f, 1f); - Utils.drawTexturedRect(width/2 - getSearchBarXSize()/2 - paddingUnscaled*6 - iconSize, topTextBox - paddingUnscaled, iconSize, iconSize); - GlStateManager.bindTexture(0); - - //Help - Minecraft.getMinecraft().getTextureManager().bindTexture(help); - drawRect(width/2 + getSearchBarXSize()/2 + paddingUnscaled*6, - topTextBox - paddingUnscaled, - width/2 + getSearchBarXSize()/2 + paddingUnscaled*6 + iconSize, - topTextBox - paddingUnscaled + iconSize, Color.WHITE.getRGB()); - - drawRect(width/2 + getSearchBarXSize()/2 + paddingUnscaled*7, - topTextBox, - width/2 + getSearchBarXSize()/2 + paddingUnscaled*5 + iconSize, - topTextBox - paddingUnscaled*2 + iconSize, Color.GRAY.getRGB()); - GlStateManager.color(1f, 1f, 1f, 1f); - Utils.drawTexturedRect(width/2 + getSearchBarXSize()/2 + paddingUnscaled*7, topTextBox, - iconSize-paddingUnscaled*2, iconSize-paddingUnscaled*2); - GlStateManager.bindTexture(0); - - //Search bar text - fr.drawString(textField.getText(), width/2 - getSearchBarXSize()/2 + 5, - topTextBox+(getSearchBarYSize()-8)/2, Color.WHITE.getRGB()); - - //Determines position of cursor. Cursor blinks on and off every 500ms. - if(searchBarHasFocus && System.currentTimeMillis()%1000>500) { - String textBeforeCursor = textField.getText().substring(0, textField.getCursorPosition()); - int textBeforeCursorWidth = fr.getStringWidth(textBeforeCursor); - drawRect(width/2 - getSearchBarXSize()/2 + 5 + textBeforeCursorWidth, - topTextBox+(getSearchBarYSize()-8)/2-1, - width/2 - getSearchBarXSize()/2 + 5 + textBeforeCursorWidth+1, - topTextBox+(getSearchBarYSize()-8)/2+9, Color.WHITE.getRGB()); - } - - String selectedText = textField.getSelectedText(); - if(!selectedText.isEmpty()) { - int selectionWidth = fr.getStringWidth(selectedText); - - int leftIndex = Math.min(textField.getCursorPosition(), textField.getSelectionEnd()); - String textBeforeSelection = textField.getText().substring(0, leftIndex); - int textBeforeSelectionWidth = fr.getStringWidth(textBeforeSelection); - - drawRect(width/2 - getSearchBarXSize()/2 + 5 + textBeforeSelectionWidth, - topTextBox+(getSearchBarYSize()-8)/2-1, - width/2 - getSearchBarXSize()/2 + 5 + textBeforeSelectionWidth + selectionWidth, - topTextBox+(getSearchBarYSize()-8)/2+9, Color.LIGHT_GRAY.getRGB()); - - fr.drawString(selectedText, - width/2 - getSearchBarXSize()/2 + 5 + textBeforeSelectionWidth, - topTextBox+(getSearchBarYSize()-8)/2, Color.BLACK.getRGB()); - } - - - /** * Item selection (right) gui element rendering */ int paneWidth = (int)(width/3*getWidthMult()); int leftSide = (int)(width*getItemPaneOffsetFactor()); - int rightSide = leftSide+paneWidth-BOX_PADDING-getItemBoxXPadding(); + int rightSide = leftSide+paneWidth-getBoxPadding()-getItemBoxXPadding(); //Tab @@ -1288,31 +1255,31 @@ public class NEUOverlay extends Gui { if(itemPaneOffsetFactor.getValue() < 1) { renderBlurredBackground(width, height, - leftSide+BOX_PADDING-5, BOX_PADDING-5, - paneWidth-BOX_PADDING*2+10, height-BOX_PADDING*2+10); + leftSide+getBoxPadding()-5, getBoxPadding()-5, + paneWidth-getBoxPadding()*2+10, height-getBoxPadding()*2+10); - drawRect(leftSide+BOX_PADDING-5, BOX_PADDING-5, - leftSide+paneWidth-BOX_PADDING+5, height-BOX_PADDING+5, bg.getRGB()); + drawRect(leftSide+getBoxPadding()-5, getBoxPadding()-5, + leftSide+paneWidth-getBoxPadding()+5, height-getBoxPadding()+5, bg.getRGB()); - |
