mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-29 18:28:34 +01:00
Added KeyStates & better key handling
This commit is contained in:
parent
0d9ab3bc0f
commit
337f512afc
10 changed files with 73 additions and 29 deletions
|
@ -59,7 +59,6 @@ public class GuiBooklet extends GuiScreen{
|
|||
public GuiButton[] chapterButtons = new GuiButton[CHAPTER_BUTTONS_AMOUNT];
|
||||
private GuiTextField searchField;
|
||||
private int ticksElapsed;
|
||||
private boolean mouseClicked;
|
||||
|
||||
private GuiScreen parentScreen;
|
||||
|
||||
|
@ -104,7 +103,7 @@ public class GuiBooklet extends GuiScreen{
|
|||
if(this.currentIndexEntry != null){
|
||||
if(this.currentChapter != null && this.currentPage != null){
|
||||
this.drawCenteredString(this.fontRendererObj, 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.mouseClicked, this.ticksElapsed);
|
||||
this.currentPage.renderPre(this, x, y, this.ticksElapsed);
|
||||
}
|
||||
else{
|
||||
this.drawCenteredString(this.fontRendererObj, this.pageOpenInIndex+"/"+this.indexPageAmount, this.guiLeft+this.xSize/2, this.guiTop+172, StringUtil.DECIMAL_COLOR_WHITE);
|
||||
|
@ -127,7 +126,7 @@ public class GuiBooklet extends GuiScreen{
|
|||
this.searchField.drawTextBox();
|
||||
|
||||
if(this.currentIndexEntry != null && this.currentChapter != null && this.currentPage != null){
|
||||
this.currentPage.render(this, x, y, this.mouseClicked, this.ticksElapsed);
|
||||
this.currentPage.render(this, x, y, this.ticksElapsed);
|
||||
}
|
||||
|
||||
this.fontRendererObj.setUnicodeFlag(false);
|
||||
|
@ -163,10 +162,6 @@ public class GuiBooklet extends GuiScreen{
|
|||
}
|
||||
}
|
||||
|
||||
if(this.mouseClicked){
|
||||
this.mouseClicked = false;
|
||||
}
|
||||
|
||||
this.fontRendererObj.setUnicodeFlag(unicodeBefore);
|
||||
}
|
||||
|
||||
|
@ -201,9 +196,6 @@ 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.currentChapter != null){
|
||||
this.mouseClicked = true;
|
||||
}
|
||||
super.mouseClicked(par1, par2, par3);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ package ellpeck.actuallyadditions.booklet.page;
|
|||
import ellpeck.actuallyadditions.booklet.BookletChapter;
|
||||
import ellpeck.actuallyadditions.booklet.GuiBooklet;
|
||||
import ellpeck.actuallyadditions.booklet.InitBooklet;
|
||||
import ellpeck.actuallyadditions.event.KeyStates;
|
||||
import ellpeck.actuallyadditions.util.ItemUtil;
|
||||
import ellpeck.actuallyadditions.util.ModUtil;
|
||||
import ellpeck.actuallyadditions.util.StringUtil;
|
||||
|
@ -95,11 +96,11 @@ public class BookletPage{
|
|||
return this;
|
||||
}
|
||||
|
||||
public void renderPre(GuiBooklet gui, int mouseX, int mouseY, boolean mouseClick, int ticksElapsed){
|
||||
public void renderPre(GuiBooklet gui, int mouseX, int mouseY, int ticksElapsed){
|
||||
|
||||
}
|
||||
|
||||
public void render(GuiBooklet gui, int mouseX, int mouseY, boolean mouseClick, int ticksElapsed){
|
||||
public void render(GuiBooklet gui, int mouseX, int mouseY, int ticksElapsed){
|
||||
|
||||
}
|
||||
|
||||
|
@ -108,7 +109,7 @@ public class BookletPage{
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void renderTooltipAndTransfer(GuiBooklet gui, ItemStack stack, int x, int y, boolean checkAndTransfer, boolean mouseClick){
|
||||
protected void renderTooltipAndTransfer(GuiBooklet gui, ItemStack stack, int x, int y, boolean checkAndTransfer){
|
||||
boolean flagBefore = gui.mc.fontRenderer.getUnicodeFlag();
|
||||
gui.mc.fontRenderer.setUnicodeFlag(false);
|
||||
|
||||
|
@ -128,7 +129,7 @@ public class BookletPage{
|
|||
if(ItemUtil.contains(page.getItemStacksForPage(), stack, true)){
|
||||
list.add(EnumChatFormatting.GOLD+StringUtil.localize("booklet."+ModUtil.MOD_ID_LOWER+".clickToSeeRecipe"));
|
||||
|
||||
if(mouseClick){
|
||||
if(KeyStates.mouseButtonState.isPressed()){
|
||||
gui.openIndexEntry(page.getChapter().entry, InitBooklet.entries.indexOf(page.getChapter().entry)/GuiBooklet.CHAPTER_BUTTONS_AMOUNT+1, true);
|
||||
gui.openChapter(page.getChapter(), page);
|
||||
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
|
||||
|
|
|
@ -27,14 +27,14 @@ public class PageCoffeeRecipe extends BookletPage{
|
|||
}
|
||||
|
||||
@Override
|
||||
public void renderPre(GuiBooklet gui, int mouseX, int mouseY, boolean mouseClick, int ticksElapsed){
|
||||
public void renderPre(GuiBooklet gui, int mouseX, int mouseY, int ticksElapsed){
|
||||
gui.mc.getTextureManager().bindTexture(GuiBooklet.resLoc);
|
||||
gui.drawTexturedModalRect(gui.guiLeft+19, gui.guiTop+20, 146, 94, 99, 60);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void render(GuiBooklet gui, int mouseX, int mouseY, boolean mouseClick, int ticksElapsed){
|
||||
public void render(GuiBooklet gui, int mouseX, int mouseY, int ticksElapsed){
|
||||
String strg = "Coffee Machine Recipe";
|
||||
gui.mc.fontRenderer.drawString(strg, gui.guiLeft+gui.xSize/2-gui.mc.fontRenderer.getStringWidth(strg)/2, gui.guiTop+10, 0);
|
||||
|
||||
|
@ -91,7 +91,7 @@ public class PageCoffeeRecipe extends BookletPage{
|
|||
}
|
||||
else{
|
||||
if(mouseX >= xShow && mouseX <= xShow+16 && mouseY >= yShow && mouseY <= yShow+16){
|
||||
this.renderTooltipAndTransfer(gui, stack, mouseX, mouseY, j != 2, mouseClick);
|
||||
this.renderTooltipAndTransfer(gui, stack, mouseX, mouseY, j != 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ public class PageCrafting extends BookletPage{
|
|||
}
|
||||
|
||||
@Override
|
||||
public void renderPre(GuiBooklet gui, int mouseX, int mouseY, boolean mouseClick, int ticksElapsed){
|
||||
public void renderPre(GuiBooklet gui, int mouseX, int mouseY, int ticksElapsed){
|
||||
if(this.recipes[this.recipePos] != null){
|
||||
gui.mc.getTextureManager().bindTexture(GuiBooklet.resLoc);
|
||||
gui.drawTexturedModalRect(gui.guiLeft+27, gui.guiTop+20, 146, 20, 99, 60);
|
||||
|
@ -52,7 +52,7 @@ public class PageCrafting extends BookletPage{
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void render(GuiBooklet gui, int mouseX, int mouseY, boolean mouseClick, int ticksElapsed){
|
||||
public void render(GuiBooklet gui, int mouseX, int mouseY, int ticksElapsed){
|
||||
IRecipe recipe = this.recipes[this.recipePos];
|
||||
|
||||
if(recipe == null){
|
||||
|
@ -124,7 +124,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, mouseClick);
|
||||
this.renderTooltipAndTransfer(gui, stack, mouseX, mouseY, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ public class PageCrafting extends BookletPage{
|
|||
}
|
||||
}
|
||||
if(mouseX >= xShowOutput && mouseX <= xShowOutput+16 && mouseY >= yShowOutput && mouseY <= yShowOutput+16){
|
||||
this.renderTooltipAndTransfer(gui, recipe.getRecipeOutput(), mouseX, mouseY, false, mouseClick);
|
||||
this.renderTooltipAndTransfer(gui, recipe.getRecipeOutput(), mouseX, mouseY, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ public class PageCrusherRecipe extends BookletPage{
|
|||
}
|
||||
|
||||
@Override
|
||||
public void renderPre(GuiBooklet gui, int mouseX, int mouseY, boolean mouseClick, int ticksElapsed){
|
||||
public void renderPre(GuiBooklet gui, int mouseX, int mouseY, int ticksElapsed){
|
||||
if(recipe != null){
|
||||
gui.mc.getTextureManager().bindTexture(GuiBooklet.resLoc);
|
||||
gui.drawTexturedModalRect(gui.guiLeft+37, gui.guiTop+20, 60, 180, 60, 60);
|
||||
|
@ -44,7 +44,7 @@ public class PageCrusherRecipe extends BookletPage{
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void render(GuiBooklet gui, int mouseX, int mouseY, boolean mouseClick, int ticksElapsed){
|
||||
public void render(GuiBooklet gui, int mouseX, int mouseY, int ticksElapsed){
|
||||
if(recipe == null){
|
||||
gui.mc.fontRenderer.drawSplitString(EnumChatFormatting.DARK_RED+StringUtil.localize("booklet."+ModUtil.MOD_ID_LOWER+".recipeDisabled"), gui.guiLeft+14, gui.guiTop+15, 115, 0);
|
||||
}
|
||||
|
@ -92,7 +92,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, mouseClick);
|
||||
this.renderTooltipAndTransfer(gui, stack, mouseX, mouseY, j == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ public class PageFurnace extends BookletPage{
|
|||
}
|
||||
|
||||
@Override
|
||||
public void renderPre(GuiBooklet gui, int mouseX, int mouseY, boolean mouseClick, int ticksElapsed){
|
||||
public void renderPre(GuiBooklet gui, int mouseX, int mouseY, int ticksElapsed){
|
||||
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);
|
||||
|
@ -47,7 +47,7 @@ public class PageFurnace extends BookletPage{
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void render(GuiBooklet gui, int mouseX, int mouseY, boolean mouseClick, int ticksElapsed){
|
||||
public void render(GuiBooklet gui, int mouseX, int mouseY, int ticksElapsed){
|
||||
ItemStack input = this.input != null ? this.input : this.getInputForOutput(this.result);
|
||||
if(input == null){
|
||||
gui.mc.fontRenderer.drawSplitString(EnumChatFormatting.DARK_RED+StringUtil.localize("booklet."+ModUtil.MOD_ID_LOWER+".recipeDisabled"), gui.guiLeft+14, gui.guiTop+15, 115, 0);
|
||||
|
@ -78,7 +78,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, mouseClick);
|
||||
this.renderTooltipAndTransfer(gui, stack, mouseX, mouseY, x == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ public class PageTextOnly extends BookletPage{
|
|||
}
|
||||
|
||||
@Override
|
||||
public void renderPre(GuiBooklet gui, int mouseX, int mouseY, boolean mouseClick, int ticksElapsed){
|
||||
public void renderPre(GuiBooklet gui, int mouseX, int mouseY, int ticksElapsed){
|
||||
String text = gui.currentPage.getText();
|
||||
if(text != null && !text.isEmpty()){
|
||||
gui.mc.fontRenderer.drawSplitString(text, gui.guiLeft+14, gui.guiTop+9, 115, 0);
|
||||
|
|
|
@ -37,6 +37,7 @@ public class InitEvents{
|
|||
public static void initClient(){
|
||||
Util.registerEvent(new TooltipEvent());
|
||||
Util.registerEvent(new RenderPlayerEventAA());
|
||||
Util.registerEvent(new KeyStates());
|
||||
|
||||
if(Loader.isModLoaded("NotEnoughItems")){
|
||||
Util.registerEvent(new NeiScreenEvents());
|
||||
|
|
50
src/main/java/ellpeck/actuallyadditions/event/KeyStates.java
Normal file
50
src/main/java/ellpeck/actuallyadditions/event/KeyStates.java
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* This file ("KeyStates.java") is part of the Actually Additions Mod for Minecraft.
|
||||
* It is created and owned by Ellpeck and distributed
|
||||
* under the Actually Additions License to be found at
|
||||
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
|
||||
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
||||
*
|
||||
* © 2015 Ellpeck
|
||||
*/
|
||||
|
||||
package ellpeck.actuallyadditions.event;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import ellpeck.actuallyadditions.util.KeyBinds;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
public class KeyStates{
|
||||
|
||||
public static KeyState mouseButtonState = new KeyState();
|
||||
public static KeyState infoButtonState = new KeyState();
|
||||
|
||||
@SubscribeEvent
|
||||
public void onClientTick(TickEvent.ClientTickEvent event){
|
||||
if(event.phase != TickEvent.Phase.END){
|
||||
mouseButtonState.tick(Mouse.isButtonDown(0));
|
||||
infoButtonState.tick(Keyboard.isKeyDown(KeyBinds.keybindOpenBooklet.getKeyCode()));
|
||||
}
|
||||
}
|
||||
|
||||
public static class KeyState{
|
||||
|
||||
private boolean pressed;
|
||||
private boolean pressedLastTime;
|
||||
private boolean recentlyCheckedPress;
|
||||
|
||||
public void tick(boolean pressed){
|
||||
this.pressed = pressed && !this.pressedLastTime;
|
||||
this.pressedLastTime = pressed;
|
||||
this.recentlyCheckedPress = false;
|
||||
}
|
||||
|
||||
public boolean isPressed(){
|
||||
boolean isPressed = this.pressed && !this.recentlyCheckedPress;
|
||||
this.recentlyCheckedPress = true;
|
||||
return isPressed;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -41,7 +41,7 @@ public class TooltipEvent{
|
|||
int keyCode = KeyBinds.keybindOpenBooklet.getKeyCode();
|
||||
event.toolTip.add(EnumChatFormatting.GOLD+StringUtil.localizeFormatted("booklet."+ModUtil.MOD_ID_LOWER+".keyToSeeRecipe", keyCode > 0 && keyCode < Keyboard.KEYBOARD_SIZE ? "'"+Keyboard.getKeyName(keyCode)+"'" : "[NONE]"));
|
||||
}
|
||||
if(Keyboard.isKeyDown(KeyBinds.keybindOpenBooklet.getKeyCode())){
|
||||
if(KeyStates.infoButtonState.isPressed()){
|
||||
GuiBooklet book = new GuiBooklet(Minecraft.getMinecraft().currentScreen);
|
||||
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
|
||||
Minecraft.getMinecraft().displayGuiScreen(book);
|
||||
|
|
Loading…
Reference in a new issue