Fixed clicking sometimes switching two pages in the booklet

This commit is contained in:
Ellpeck 2015-08-31 02:05:41 +02:00
parent e5926265f8
commit 0a77476470
8 changed files with 28 additions and 32 deletions

View file

@ -24,7 +24,6 @@ import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField; import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
@ -66,12 +65,11 @@ public class GuiBooklet extends GuiScreen{
private static final int BUTTONS_PER_PAGE = 15; private static final int BUTTONS_PER_PAGE = 15;
private EntityPlayer player; private boolean mouseClicked;
public GuiBooklet(EntityPlayer player){ public GuiBooklet(){
this.xSize = 146; this.xSize = 146;
this.ySize = 180; this.ySize = 180;
this.player = player;
} }
@Override @Override
@ -116,6 +114,9 @@ public class GuiBooklet extends GuiScreen{
@Override @Override
protected void mouseClicked(int par1, int par2, int par3){ protected void mouseClicked(int par1, int par2, int par3){
this.searchField.mouseClicked(par1, par2, par3); this.searchField.mouseClicked(par1, par2, par3);
if(par3 == 0){
this.mouseClicked = true;
}
super.mouseClicked(par1, par2, par3); super.mouseClicked(par1, par2, par3);
} }
@ -197,7 +198,7 @@ public class GuiBooklet extends GuiScreen{
if(this.currentIndexEntry != null){ if(this.currentIndexEntry != null){
if(this.currentChapter != null && this.currentPage != 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.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{ else{
this.drawCenteredString(this.unicodeRenderer, this.pageOpenInIndex+"/"+this.indexPageAmount, this.guiLeft+this.xSize/2, this.guiTop+172, StringUtil.DECIMAL_COLOR_WHITE); 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){ 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){ private IBookletPage getNextPage(BookletChapter chapter, IBookletPage currentPage){

View file

@ -22,7 +22,6 @@ import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12; import org.lwjgl.opengl.GL12;
@ -33,8 +32,6 @@ public class BookletPage implements IBookletPage{
protected int id; protected int id;
protected BookletChapter chapter; protected BookletChapter chapter;
private boolean mouseWasDown;
public BookletPage(int id){ public BookletPage(int id){
this.id = id; this.id = id;
} }
@ -60,12 +57,12 @@ public class BookletPage implements IBookletPage{
} }
@Override @Override
public void renderPre(GuiBooklet gui, int mouseX, int mouseY){ public void renderPre(GuiBooklet gui, int mouseX, int mouseY, boolean mouseClick){
} }
@Override @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") @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); List list = stack.getTooltip(gui.mc.thePlayer, gui.mc.gameSettings.advancedItemTooltips);
for(int k = 0; k < list.size(); ++k){ 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)){ if(page.getItemStackForPage() != null && page.getItemStackForPage().isItemEqual(stack)){
list.add(EnumChatFormatting.GOLD+StringUtil.localize("booklet."+ModUtil.MOD_ID_LOWER+".clickToSeeRecipe")); list.add(EnumChatFormatting.GOLD+StringUtil.localize("booklet."+ModUtil.MOD_ID_LOWER+".clickToSeeRecipe"));
boolean isDown = Mouse.isButtonDown(0); if(mouseClick){
if(!this.mouseWasDown){ gui.openChapter(page.getChapter(), page);
if(isDown){ Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
gui.openChapter(page.getChapter(), page);
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
}
} }
this.mouseWasDown = isDown;
break; break;
} }

View file

@ -24,9 +24,9 @@ public interface IBookletPage{
String getText(); 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(); ItemStack getItemStackForPage();
} }

View file

@ -41,7 +41,7 @@ public class PageCrafting extends BookletPage{
} }
@Override @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){ if(this.recipe != null){
gui.mc.getTextureManager().bindTexture(GuiBooklet.resLoc); gui.mc.getTextureManager().bindTexture(GuiBooklet.resLoc);
gui.drawTexturedModalRect(gui.guiLeft+27, gui.guiTop+20, 146, 20, 99, 60); gui.drawTexturedModalRect(gui.guiLeft+27, gui.guiTop+20, 146, 20, 99, 60);
@ -50,7 +50,7 @@ public class PageCrafting extends BookletPage{
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @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){ if(this.recipe == null){
gui.unicodeRenderer.drawSplitString(StringUtil.localize("booklet."+ModUtil.MOD_ID_LOWER+".recipeDisabled"), gui.guiLeft+14, gui.guiTop+15, 115, 0); 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{ else{
if(mouseX >= xShow && mouseX <= xShow+16 && mouseY >= yShow && mouseY <= yShow+16){ 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);
} }
} }
} }

View file

@ -29,7 +29,7 @@ public class PageCrusherRecipe extends BookletPage{
} }
@Override @Override
public void renderPre(GuiBooklet gui, int mouseX, int mouseY){ public void renderPre(GuiBooklet gui, int mouseX, int mouseY, boolean mouseClick){
if(recipe != null){ if(recipe != null){
gui.mc.getTextureManager().bindTexture(GuiBooklet.resLoc); gui.mc.getTextureManager().bindTexture(GuiBooklet.resLoc);
gui.drawTexturedModalRect(gui.guiLeft+37, gui.guiTop+20, 60, 180, 60, 60); gui.drawTexturedModalRect(gui.guiLeft+37, gui.guiTop+20, 60, 180, 60, 60);
@ -43,7 +43,7 @@ public class PageCrusherRecipe extends BookletPage{
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public void render(GuiBooklet gui, int mouseX, int mouseY){ public void render(GuiBooklet gui, int mouseX, int mouseY, boolean mouseClick){
if(recipe == null){ if(recipe == null){
gui.unicodeRenderer.drawSplitString(StringUtil.localize("booklet."+ModUtil.MOD_ID_LOWER+".recipeDisabled"), gui.guiLeft+14, gui.guiTop+15, 115, 0); 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{ else{
if(mouseX >= xShow && mouseX <= xShow+16 && mouseY >= yShow && mouseY <= yShow+16){ 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);
} }
} }
} }

View file

@ -41,7 +41,7 @@ public class PageFurnace extends BookletPage{
} }
@Override @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){ if(this.input != null || this.getInputForOutput(this.result) != null){
gui.mc.getTextureManager().bindTexture(GuiBooklet.resLoc); gui.mc.getTextureManager().bindTexture(GuiBooklet.resLoc);
gui.drawTexturedModalRect(gui.guiLeft+37, gui.guiTop+20, 0, 180, 60, 60); gui.drawTexturedModalRect(gui.guiLeft+37, gui.guiTop+20, 0, 180, 60, 60);
@ -50,7 +50,7 @@ public class PageFurnace extends BookletPage{
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @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); ItemStack input = this.input != null ? this.input : this.getInputForOutput(this.result);
if(input == null){ if(input == null){
gui.unicodeRenderer.drawSplitString(StringUtil.localize("booklet."+ModUtil.MOD_ID_LOWER+".recipeDisabled"), gui.guiLeft+14, gui.guiTop+15, 115, 0); 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{ else{
if(mouseX >= xShow && mouseX <= xShow+16 && mouseY >= yShow && mouseY <= yShow+16){ 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);
} }
} }
} }

View file

@ -19,7 +19,7 @@ public class PageText extends BookletPage{
} }
@Override @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(); String text = gui.currentPage.getText();
if(text != null && !text.isEmpty() && !text.contains("booklet.")){ if(text != null && !text.isEmpty() && !text.contains("booklet.")){
gui.unicodeRenderer.drawSplitString(text.replace("<n>", "\n"), gui.guiLeft+14, gui.guiTop+11, 115, 0); gui.unicodeRenderer.drawSplitString(text.replace("<n>", "\n"), gui.guiLeft+14, gui.guiTop+11, 115, 0);

View file

@ -140,7 +140,7 @@ public class GuiHandler implements IGuiHandler{
case CLOUD: case CLOUD:
return new GuiSmileyCloud(tile, x, y, z, world); return new GuiSmileyCloud(tile, x, y, z, world);
case BOOK: case BOOK:
return new GuiBooklet(entityPlayer); return new GuiBooklet();
default: default:
return null; return null;
} }