From 82d3d7e3a705b0c706e4e87b14d2bbfab1b00b23 Mon Sep 17 00:00:00 2001 From: Kino Date: Tue, 21 Nov 2017 22:57:11 -0500 Subject: [PATCH] Book of Lore pages added --- .../com/legacy/aether/client/gui/GuiLore.java | 133 +++++++++--------- .../client/gui/button/GuiLoreButton.java | 60 ++++++++ .../textures/gui/lore_widgets.png | Bin 0 -> 1708 bytes 3 files changed, 123 insertions(+), 70 deletions(-) create mode 100644 src/main/java/com/legacy/aether/client/gui/button/GuiLoreButton.java create mode 100644 src/main/resources/assets/aether_legacy/textures/gui/lore_widgets.png diff --git a/src/main/java/com/legacy/aether/client/gui/GuiLore.java b/src/main/java/com/legacy/aether/client/gui/GuiLore.java index efd6912..c538b2e 100644 --- a/src/main/java/com/legacy/aether/client/gui/GuiLore.java +++ b/src/main/java/com/legacy/aether/client/gui/GuiLore.java @@ -1,26 +1,19 @@ package com.legacy.aether.client.gui; -import java.util.HashMap; -import java.util.Iterator; +import java.io.IOException; import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; +import com.legacy.aether.client.gui.button.GuiLoreButton; import com.legacy.aether.common.containers.ContainerLore; import com.legacy.aether.common.registry.AetherLore; -import com.legacy.aether.common.registry.lore.AetherLoreEntry; -import com.legacy.aether.common.registry.lore.EndLoreEntry; -import com.legacy.aether.common.registry.lore.NetherLoreEntry; -import com.legacy.aether.common.registry.lore.OverworldLoreEntry; -import com.legacy.aether.common.registry.objects.EntryInformation; -import com.legacy.aether.common.registry.objects.LoreEntry; public class GuiLore extends GuiContainer { @@ -29,7 +22,13 @@ public class GuiLore extends GuiContainer private static final ResourceLocation TEXTURE_LORE_BOOK = new ResourceLocation("aether_legacy", "textures/gui/lore_book.png"); - private HashMap lore_pages = new HashMap(); + private String stringToLoad; + + private ItemStack currentItem; + + private GuiButton previousPage, nextPage; + + private int pageNumber; public GuiLore(InventoryPlayer inventoryplayer) { @@ -41,27 +40,35 @@ public class GuiLore extends GuiContainer public void initGui() { super.initGui(); - registerSection("Overworld Lore", new OverworldLoreEntry().initEntries()); //199 Complete - registerSection("Nether Lore", new NetherLoreEntry().initEntries()); // 22 Complete - registerSection("End Lore", new EndLoreEntry().initEntries()); //11 Complete - registerSection("Aether Lore", new AetherLoreEntry().initEntries()); //157 Complete + + this.previousPage = new GuiLoreButton(19, this.width / 2 - 110, this.height / 2 + 72, 20, 20, "<"); + this.nextPage = new GuiLoreButton(20, this.width / 2 + 90, this.height / 2 + 72, 20, 20, ">"); + + this.addButton(this.previousPage); + this.addButton(this.nextPage); } - public void registerSection(String name, LoreEntry lore) - { - lore_pages.put(name, lore); - } - - public LoreEntry getSection(String name) - { - return lore_pages.get(name); - } + @Override + protected void actionPerformed(GuiButton button) throws IOException + { + if (this.previousPage == button) + { + --this.pageNumber; + } + else if (this.nextPage == button) + { + ++this.pageNumber; + } + } + @Override protected void drawGuiContainerForegroundLayer(int par1, int par2) { + this.fontRendererObj.drawString("Prev.", 16, 160, 4210752); + this.fontRendererObj.drawString("Next", 218, 160, 4210752); + this.fontRendererObj.drawString("Book", 32, -5, 4210752); this.fontRendererObj.drawString("of Lore:", 24, 4, 4210752); - //this.fontRendererObj.drawString("Add Object", 70, 0, 4210752); this.fontRendererObj.drawString("Item :", 75, 0, 4210752); @@ -69,62 +76,48 @@ public class GuiLore extends GuiContainer if (searchedStack != null) { - this.drawCenteredString(this.fontRendererObj, searchedStack.getRarity().rarityColor.toString() + searchedStack.getItem().getItemStackDisplayName(searchedStack), 71, 18, 4210752); + if (this.currentItem == null || (searchedStack.getItem() != this.currentItem.getItem() || searchedStack.getMetadata() != this.currentItem.getMetadata())) + { + this.pageNumber = 0; + this.stringToLoad = AetherLore.getLoreEntry(searchedStack); + this.currentItem = searchedStack; + } + + int nameSize = 0; + + for (String name : this.fontRendererObj.listFormattedStringToWidth(searchedStack.getItem().getItemStackDisplayName(searchedStack), 109)) + { + this.drawCenteredString(this.fontRendererObj, searchedStack.getRarity().rarityColor.toString() + name, 71, 18 + (10 * nameSize), 4210752); + + ++nameSize; + } int size = 0; - for (String lore : this.fontRendererObj.listFormattedStringToWidth(AetherLore.getLoreEntry(searchedStack), 111)) + for (String lore : this.fontRendererObj.listFormattedStringToWidth(this.stringToLoad, 109)) { - this.fontRendererObj.drawString(lore, ((size >= 6 ? 184 : 71) - this.fontRendererObj.getStringWidth(lore) / 2), (size >= 6 ? -68 : 28) + (10 * size), 4210752); - //this.drawCenteredString(this.fontRendererObj, lore, size >= 6 ? 182 : 71, (size >= 6 ? -70 : 28) + (10 * size), 4210752); + if (size >= 15 * this.pageNumber && size + (nameSize - 1) <= 15 * (this.pageNumber + 1)) + { + int actualSize = this.pageNumber >= 1 ? size - ((15 - (nameSize - 1)) * this.pageNumber) : size + (nameSize - 1); + + this.fontRendererObj.drawString(lore, (((actualSize >= 6 ? 184 : 71)) - this.fontRendererObj.getStringWidth(lore) / 2), (actualSize >= 6 ? -68 : 28) + (10 * actualSize), 4210752); + } size++; } - //this.fontRendererObj.drawSplitString(str, x, y, wrapWidth, textColor); + this.previousPage.enabled = this.pageNumber != 0; + this.nextPage.enabled = size > (15 * (this.pageNumber + 1)); } - /*ItemStack searchedStack = ((ContainerLore)this.inventorySlots).loreSlot.getStackInSlot(0); - - if (searchedStack != null) + else { - Iterator entries = this.lore_pages.values().iterator(); - - while(entries.hasNext()) - { - Iterator entry_contents = entries.next().EntryInformation().iterator(); - - while (entry_contents.hasNext()) - { - EntryInformation information = entry_contents.next(); - Item loreItem = information.base.getItem(); - - if (loreItem != null && (information.base.getItemDamage() == searchedStack.getItemDamage() || information.base.isItemStackDamageable()) && loreItem == searchedStack.getItem()) - { - //GlStateManager.pushMatrix(); - - this.drawCenteredString(this.fontRendererObj, information.base.getRarity().rarityColor.toString() + information.s, 71, 18, 4210752); - - this.fontRendererObj.drawSplitString(information.s1 + " " + information.s2 + " " + information.s3 + " " + information.s4, 18, 30, 120, 4210752); - //this.fontRendererObj.drawStringWithShadow(information.base.getRarity().rarityColor.toString() + information.s, 18, 18, 4210752); - //this.fontRendererObj.drawString(information.s1, 134, 28, 4210752); - //this.fontRendererObj.drawString(information.s2, 134, 38, 4210752); - //this.fontRendererObj.drawString(information.s3, 134, 48, 4210752); - //this.fontRendererObj.drawString(information.s4, 134, 58, 4210752); - //this.fontRendererObj.drawString(information.s5, 134, 68, 4210752); - //this.fontRendererObj.drawString(information.s6, 134, 78, 4210752); - - //GlStateManager.popMatrix(); - } - } - } - }*/ - } - - public void onGuiClosed() - { - super.onGuiClosed(); + this.pageNumber = 0; + this.stringToLoad = ""; + this.currentItem = null; + } } + @Override protected void drawGuiContainerBackgroundLayer(float f, int i1, int i2) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); @@ -138,6 +131,6 @@ public class GuiLore extends GuiContainer this.mc.renderEngine.bindTexture(TEXTURE_LORE_BOOK); Gui.drawModalRectWithCustomSizedTexture(j - 1, k - 20, 0, 0, this.xSize + 20, this.ySize - 60, 275, 315); Gui.drawModalRectWithCustomSizedTexture(j + 90, k - 5, 0, 225, this.xSize + 20, this.ySize - 177, 500, 500); - //Gui.drawScaledCustomSizeModalRect(j - 1, k - 20, 200, 200, 100, 100, this.xSize + 20, this.ySize + 120, 100, 100); } + } \ No newline at end of file diff --git a/src/main/java/com/legacy/aether/client/gui/button/GuiLoreButton.java b/src/main/java/com/legacy/aether/client/gui/button/GuiLoreButton.java new file mode 100644 index 0000000..74c2cfd --- /dev/null +++ b/src/main/java/com/legacy/aether/client/gui/button/GuiLoreButton.java @@ -0,0 +1,60 @@ +package com.legacy.aether.client.gui.button; + +import com.legacy.aether.common.Aether; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.util.ResourceLocation; + +public class GuiLoreButton extends GuiButton +{ + + protected static final ResourceLocation BUTTON_TEXTURES = Aether.locate("textures/gui/lore_widgets.png"); + + public GuiLoreButton(int buttonId, int x, int y, int widthIn, int heightIn, String buttonText) + { + super(buttonId, x, y, widthIn, heightIn, buttonText); + } + + /** + * Draws this button to the screen. + */ + @Override + public void drawButton(Minecraft mc, int mouseX, int mouseY) + { + if (this.visible) + { + FontRenderer fontrenderer = mc.fontRendererObj; + mc.getTextureManager().bindTexture(BUTTON_TEXTURES); + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + this.hovered = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; + int i = this.getHoverState(this.hovered); + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); + GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); + this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 46 + i * 20, this.width / 2, this.height); + this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition, 200 - this.width / 2, 46 + i * 20, this.width / 2, this.height); + this.mouseDragged(mc, mouseX, mouseY); + int j = 14737632; + + if (this.packedFGColour != 0) + { + j = this.packedFGColour; + } + else + if (!this.enabled) + { + j = 10526880; + } + else if (this.hovered) + { + j = 16777120; + } + + this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, j); + } + } + +} \ No newline at end of file diff --git a/src/main/resources/assets/aether_legacy/textures/gui/lore_widgets.png b/src/main/resources/assets/aether_legacy/textures/gui/lore_widgets.png new file mode 100644 index 0000000000000000000000000000000000000000..ddc169e956048fed92732e60a46bcf6da687694e GIT binary patch literal 1708 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K58911MRQ8&P5Fo{p?&#~tz_78O`%fY(0|PTd zfKP}kP+U<_(HsOKf`fzGYXZ8vyJyav+1G+V}U33(ngdxGq_@<9RcKz59bXOd<`n(O_d9 z&tZZXV|i|-wgcmj#Ns)|;SEe54nMO