From 0a77476470f013ffa5a9b14fac00860b0ec40300 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 31 Aug 2015 02:05:41 +0200 Subject: [PATCH] Fixed clicking sometimes switching two pages in the booklet --- .../actuallyadditions/booklet/GuiBooklet.java | 15 +++++++++------ .../booklet/page/BookletPage.java | 19 ++++++------------- .../booklet/page/IBookletPage.java | 4 ++-- .../booklet/page/PageCrafting.java | 6 +++--- .../booklet/page/PageCrusherRecipe.java | 6 +++--- .../booklet/page/PageFurnace.java | 6 +++--- .../booklet/page/PageText.java | 2 +- .../inventory/GuiHandler.java | 2 +- 8 files changed, 28 insertions(+), 32 deletions(-) diff --git a/src/main/java/ellpeck/actuallyadditions/booklet/GuiBooklet.java b/src/main/java/ellpeck/actuallyadditions/booklet/GuiBooklet.java index adfe84cf7..3253a3115 100644 --- a/src/main/java/ellpeck/actuallyadditions/booklet/GuiBooklet.java +++ b/src/main/java/ellpeck/actuallyadditions/booklet/GuiBooklet.java @@ -24,7 +24,6 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiTextField; import net.minecraft.client.renderer.OpenGlHelper; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; @@ -66,12 +65,11 @@ public class GuiBooklet extends GuiScreen{ private static final int BUTTONS_PER_PAGE = 15; - private EntityPlayer player; + private boolean mouseClicked; - public GuiBooklet(EntityPlayer player){ + public GuiBooklet(){ this.xSize = 146; this.ySize = 180; - this.player = player; } @Override @@ -116,6 +114,9 @@ public class GuiBooklet extends GuiScreen{ @Override protected void mouseClicked(int par1, int par2, int par3){ this.searchField.mouseClicked(par1, par2, par3); + if(par3 == 0){ + this.mouseClicked = true; + } super.mouseClicked(par1, par2, par3); } @@ -197,7 +198,7 @@ public class GuiBooklet extends GuiScreen{ if(this.currentIndexEntry != null){ if(this.currentChapter != null && this.currentPage != null){ this.drawCenteredString(this.unicodeRenderer, this.currentPage.getID()+"/"+this.currentChapter.pages.length, this.guiLeft+this.xSize/2, this.guiTop+172, StringUtil.DECIMAL_COLOR_WHITE); - this.currentPage.renderPre(this, x, y); + this.currentPage.renderPre(this, x, y, this.mouseClicked); } else{ this.drawCenteredString(this.unicodeRenderer, this.pageOpenInIndex+"/"+this.indexPageAmount, this.guiLeft+this.xSize/2, this.guiTop+172, StringUtil.DECIMAL_COLOR_WHITE); @@ -225,8 +226,10 @@ public class GuiBooklet extends GuiScreen{ } if(this.currentIndexEntry != null && this.currentChapter != null && this.currentPage != null){ - this.currentPage.render(this, x, y); + this.currentPage.render(this, x, y, this.mouseClicked); } + + if(this.mouseClicked) this.mouseClicked = false; } private IBookletPage getNextPage(BookletChapter chapter, IBookletPage currentPage){ diff --git a/src/main/java/ellpeck/actuallyadditions/booklet/page/BookletPage.java b/src/main/java/ellpeck/actuallyadditions/booklet/page/BookletPage.java index a65f507fe..177702c48 100644 --- a/src/main/java/ellpeck/actuallyadditions/booklet/page/BookletPage.java +++ b/src/main/java/ellpeck/actuallyadditions/booklet/page/BookletPage.java @@ -22,7 +22,6 @@ import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; -import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; @@ -33,8 +32,6 @@ public class BookletPage implements IBookletPage{ protected int id; protected BookletChapter chapter; - private boolean mouseWasDown; - public BookletPage(int id){ this.id = id; } @@ -60,12 +57,12 @@ public class BookletPage implements IBookletPage{ } @Override - public void renderPre(GuiBooklet gui, int mouseX, int mouseY){ + public void renderPre(GuiBooklet gui, int mouseX, int mouseY, boolean mouseClick){ } @Override - public void render(GuiBooklet gui, int mouseX, int mouseY){ + public void render(GuiBooklet gui, int mouseX, int mouseY, boolean mouseClick){ } @@ -75,7 +72,7 @@ public class BookletPage implements IBookletPage{ } @SuppressWarnings("unchecked") - protected void renderTooltipAndTransfer(GuiBooklet gui, ItemStack stack, int x, int y, boolean checkAndTransfer){ + protected void renderTooltipAndTransfer(GuiBooklet gui, ItemStack stack, int x, int y, boolean checkAndTransfer, boolean mouseClick){ List list = stack.getTooltip(gui.mc.thePlayer, gui.mc.gameSettings.advancedItemTooltips); for(int k = 0; k < list.size(); ++k){ @@ -92,14 +89,10 @@ public class BookletPage implements IBookletPage{ if(page.getItemStackForPage() != null && page.getItemStackForPage().isItemEqual(stack)){ list.add(EnumChatFormatting.GOLD+StringUtil.localize("booklet."+ModUtil.MOD_ID_LOWER+".clickToSeeRecipe")); - boolean isDown = Mouse.isButtonDown(0); - if(!this.mouseWasDown){ - if(isDown){ - gui.openChapter(page.getChapter(), page); - Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); - } + if(mouseClick){ + gui.openChapter(page.getChapter(), page); + Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); } - this.mouseWasDown = isDown; break; } diff --git a/src/main/java/ellpeck/actuallyadditions/booklet/page/IBookletPage.java b/src/main/java/ellpeck/actuallyadditions/booklet/page/IBookletPage.java index c864a5652..07d357c96 100644 --- a/src/main/java/ellpeck/actuallyadditions/booklet/page/IBookletPage.java +++ b/src/main/java/ellpeck/actuallyadditions/booklet/page/IBookletPage.java @@ -24,9 +24,9 @@ public interface IBookletPage{ String getText(); - void renderPre(GuiBooklet gui, int mouseX, int mouseY); + void renderPre(GuiBooklet gui, int mouseX, int mouseY, boolean mouseClick); - void render(GuiBooklet gui, int mouseX, int mouseY); + void render(GuiBooklet gui, int mouseX, int mouseY, boolean mouseClick); ItemStack getItemStackForPage(); } diff --git a/src/main/java/ellpeck/actuallyadditions/booklet/page/PageCrafting.java b/src/main/java/ellpeck/actuallyadditions/booklet/page/PageCrafting.java index cfba09e73..50107603f 100644 --- a/src/main/java/ellpeck/actuallyadditions/booklet/page/PageCrafting.java +++ b/src/main/java/ellpeck/actuallyadditions/booklet/page/PageCrafting.java @@ -41,7 +41,7 @@ public class PageCrafting extends BookletPage{ } @Override - public void renderPre(GuiBooklet gui, int mouseX, int mouseY){ + public void renderPre(GuiBooklet gui, int mouseX, int mouseY, boolean mouseClick){ if(this.recipe != null){ gui.mc.getTextureManager().bindTexture(GuiBooklet.resLoc); gui.drawTexturedModalRect(gui.guiLeft+27, gui.guiTop+20, 146, 20, 99, 60); @@ -50,7 +50,7 @@ public class PageCrafting extends BookletPage{ @SuppressWarnings("unchecked") @Override - public void render(GuiBooklet gui, int mouseX, int mouseY){ + public void render(GuiBooklet gui, int mouseX, int mouseY, boolean mouseClick){ if(this.recipe == null){ gui.unicodeRenderer.drawSplitString(StringUtil.localize("booklet."+ModUtil.MOD_ID_LOWER+".recipeDisabled"), gui.guiLeft+14, gui.guiTop+15, 115, 0); } @@ -114,7 +114,7 @@ public class PageCrafting extends BookletPage{ } else{ if(mouseX >= xShow && mouseX <= xShow+16 && mouseY >= yShow && mouseY <= yShow+16){ - this.renderTooltipAndTransfer(gui, stack, mouseX, mouseY, true); + this.renderTooltipAndTransfer(gui, stack, mouseX, mouseY, true, mouseClick); } } } diff --git a/src/main/java/ellpeck/actuallyadditions/booklet/page/PageCrusherRecipe.java b/src/main/java/ellpeck/actuallyadditions/booklet/page/PageCrusherRecipe.java index 289e7df38..183455fbc 100644 --- a/src/main/java/ellpeck/actuallyadditions/booklet/page/PageCrusherRecipe.java +++ b/src/main/java/ellpeck/actuallyadditions/booklet/page/PageCrusherRecipe.java @@ -29,7 +29,7 @@ public class PageCrusherRecipe extends BookletPage{ } @Override - public void renderPre(GuiBooklet gui, int mouseX, int mouseY){ + public void renderPre(GuiBooklet gui, int mouseX, int mouseY, boolean mouseClick){ if(recipe != null){ gui.mc.getTextureManager().bindTexture(GuiBooklet.resLoc); gui.drawTexturedModalRect(gui.guiLeft+37, gui.guiTop+20, 60, 180, 60, 60); @@ -43,7 +43,7 @@ public class PageCrusherRecipe extends BookletPage{ @SuppressWarnings("unchecked") @Override - public void render(GuiBooklet gui, int mouseX, int mouseY){ + public void render(GuiBooklet gui, int mouseX, int mouseY, boolean mouseClick){ if(recipe == null){ gui.unicodeRenderer.drawSplitString(StringUtil.localize("booklet."+ModUtil.MOD_ID_LOWER+".recipeDisabled"), gui.guiLeft+14, gui.guiTop+15, 115, 0); } @@ -74,7 +74,7 @@ public class PageCrusherRecipe extends BookletPage{ } else{ if(mouseX >= xShow && mouseX <= xShow+16 && mouseY >= yShow && mouseY <= yShow+16){ - this.renderTooltipAndTransfer(gui, stack, mouseX, mouseY, j == 0); + this.renderTooltipAndTransfer(gui, stack, mouseX, mouseY, j == 0, mouseClick); } } } diff --git a/src/main/java/ellpeck/actuallyadditions/booklet/page/PageFurnace.java b/src/main/java/ellpeck/actuallyadditions/booklet/page/PageFurnace.java index f068e8eca..75b2f1cc4 100644 --- a/src/main/java/ellpeck/actuallyadditions/booklet/page/PageFurnace.java +++ b/src/main/java/ellpeck/actuallyadditions/booklet/page/PageFurnace.java @@ -41,7 +41,7 @@ public class PageFurnace extends BookletPage{ } @Override - public void renderPre(GuiBooklet gui, int mouseX, int mouseY){ + public void renderPre(GuiBooklet gui, int mouseX, int mouseY, boolean mouseClick){ if(this.input != null || this.getInputForOutput(this.result) != null){ gui.mc.getTextureManager().bindTexture(GuiBooklet.resLoc); gui.drawTexturedModalRect(gui.guiLeft+37, gui.guiTop+20, 0, 180, 60, 60); @@ -50,7 +50,7 @@ public class PageFurnace extends BookletPage{ @SuppressWarnings("unchecked") @Override - public void render(GuiBooklet gui, int mouseX, int mouseY){ + public void render(GuiBooklet gui, int mouseX, int mouseY, boolean mouseClick){ ItemStack input = this.input != null ? this.input : this.getInputForOutput(this.result); if(input == null){ gui.unicodeRenderer.drawSplitString(StringUtil.localize("booklet."+ModUtil.MOD_ID_LOWER+".recipeDisabled"), gui.guiLeft+14, gui.guiTop+15, 115, 0); @@ -75,7 +75,7 @@ public class PageFurnace extends BookletPage{ } else{ if(mouseX >= xShow && mouseX <= xShow+16 && mouseY >= yShow && mouseY <= yShow+16){ - this.renderTooltipAndTransfer(gui, stack, mouseX, mouseY, x == 0); + this.renderTooltipAndTransfer(gui, stack, mouseX, mouseY, x == 0, mouseClick); } } } diff --git a/src/main/java/ellpeck/actuallyadditions/booklet/page/PageText.java b/src/main/java/ellpeck/actuallyadditions/booklet/page/PageText.java index dc9f5ef5c..500976e01 100644 --- a/src/main/java/ellpeck/actuallyadditions/booklet/page/PageText.java +++ b/src/main/java/ellpeck/actuallyadditions/booklet/page/PageText.java @@ -19,7 +19,7 @@ public class PageText extends BookletPage{ } @Override - public void render(GuiBooklet gui, int mouseX, int mouseY){ + public void render(GuiBooklet gui, int mouseX, int mouseY, boolean mouseClick){ String text = gui.currentPage.getText(); if(text != null && !text.isEmpty() && !text.contains("booklet.")){ gui.unicodeRenderer.drawSplitString(text.replace("", "\n"), gui.guiLeft+14, gui.guiTop+11, 115, 0); diff --git a/src/main/java/ellpeck/actuallyadditions/inventory/GuiHandler.java b/src/main/java/ellpeck/actuallyadditions/inventory/GuiHandler.java index 843938b3e..47601fe71 100644 --- a/src/main/java/ellpeck/actuallyadditions/inventory/GuiHandler.java +++ b/src/main/java/ellpeck/actuallyadditions/inventory/GuiHandler.java @@ -140,7 +140,7 @@ public class GuiHandler implements IGuiHandler{ case CLOUD: return new GuiSmileyCloud(tile, x, y, z, world); case BOOK: - return new GuiBooklet(entityPlayer); + return new GuiBooklet(); default: return null; }