diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java index 96b0fc385..f9a923f60 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java @@ -86,6 +86,7 @@ public abstract class GuiNPCInterface extends GuiScreen topbuttons.clear(); scrolls.clear(); sliders.clear(); + scrollableGuiInserts.clear(); Keyboard.enableRepeatEvents(true); } @Override @@ -236,6 +237,8 @@ public abstract class GuiNPCInterface extends GuiScreen drawBackground(); } + int scrolled = Mouse.getDWheel(); + boolean subGui = hasSubGui(); drawCenteredString(fontRendererObj, title, width / 2, guiTop + 4, 0xffffff); for(GuiNpcLabel label : labels.values()) @@ -245,7 +248,7 @@ public abstract class GuiNPCInterface extends GuiScreen } for(GuiCustomScroll scroll : scrolls.values()){ scroll.updateSubGUI(subGui); - scroll.drawScreen(i, j, f, !subGui && scroll.isMouseOver(i, j)?Mouse.getDWheel():0); + scroll.drawScreen(i, j, f, !subGui && scroll.isMouseOver(i, j)?scrolled:0); } for(GuiScreen gui : extra.values()) gui.drawScreen(i, j, f); @@ -261,7 +264,7 @@ public abstract class GuiNPCInterface extends GuiScreen } } for(GuiScrollable guiScrollable : scrollableGuiInserts.values()){ - guiScrollable.drawScreen(i, j, f, guiScrollable.isMouseOver(i,j)?Mouse.getDWheel():0); + guiScrollable.drawScreen(i, j, f, guiScrollable.isMouseOver(i,j)?scrolled:0); } if(subgui != null) diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiScrollable.java b/src/main/java/noppes/npcs/client/gui/util/GuiScrollable.java index da03b96fb..0674ee5ba 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiScrollable.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiScrollable.java @@ -1,6 +1,8 @@ package noppes.npcs.client.gui.util; +import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.util.ChatComponentText; import noppes.npcs.entity.EntityNPCInterface; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; @@ -11,6 +13,9 @@ public class GuiScrollable extends GuiNPCInterface{ public int clipWidth; public int clipHeight; + protected int xPos = 0; + protected int yPos = 0; + protected int maxScrollY = 0; protected float scrollY = 0; protected float nextScrollY = 0; @@ -21,8 +26,8 @@ public class GuiScrollable extends GuiNPCInterface{ public GuiScrollable(EntityNPCInterface npc, int posX, int posY, int clipWidth, int clipHeight, int maxScroll){ super(npc); - this.guiLeft = posX; - this.guiTop = posY; + this.xPos = posX; + this.yPos = posY; this.clipWidth = clipWidth; this.clipHeight = clipHeight; this.maxScrollY = maxScroll; @@ -36,8 +41,9 @@ public class GuiScrollable extends GuiNPCInterface{ @Override public void initGui(){ super.initGui(); + scaledResolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); - + addButton(new GuiNpcButton(0, 0, 0, "Testtt")); float scrollPerc = 0; if((guiTop+clipHeight) != 0){ @@ -65,8 +71,8 @@ public class GuiScrollable extends GuiNPCInterface{ if(drawBackground) this.drawDefaultBackground(); - GL11.glTranslatef(guiLeft, guiTop+scrollY, 0); - super.drawScreen(mouseX-guiLeft, (int) (mouseY-scrollY-guiTop), partialTicks); + GL11.glTranslatef(xPos, yPos+scrollY, 0); + super.drawScreen(mouseX-xPos, (int) (mouseY-scrollY-yPos), partialTicks); this.drawDefaultBackground = drawBackground; @@ -78,39 +84,43 @@ public class GuiScrollable extends GuiNPCInterface{ } public void drawScreen(int mouseX, int mouseY, float partialTicks, int mouseScroll){ + adjustScroll(mouseScroll); + + this.drawScreen(mouseX, mouseY, partialTicks); + } + + public void adjustScroll(int mouseScroll) { nextScrollY -= (float) mouseScroll/25; if(nextScrollY < 0) nextScrollY = 0; - if(nextScrollY > clipHeight) { - nextScrollY = clipHeight; + if(nextScrollY > maxScrollY) { + nextScrollY = maxScrollY; } - this.drawScreen(mouseX, mouseY, partialTicks); + } + + @Override + public void buttonEvent(GuiButton button){ + mc.thePlayer.addChatMessage(new ChatComponentText("LOL")); } @Override public void mouseClicked(int mouseX, int mouseY, int mouseButton){ - super.mouseClicked(mouseX-guiLeft, (int) (mouseY-scrollY-guiTop), mouseButton); + super.mouseClicked(mouseX-xPos, (int) (mouseY-yPos-scrollY), mouseButton); } @Override public void handleMouseInput(){ super.handleMouseInput(); - nextScrollY -= (float) Mouse.getEventDWheel()/25; - if(nextScrollY < 0) - nextScrollY = 0; - if(nextScrollY > maxScrollY){ - nextScrollY = maxScrollY; - } - + adjustScroll(Mouse.getEventDWheel()); } public boolean isMouseOver(int mouseX, int mouseY){ - return mouseX >= guiLeft && mouseX <= xSize && mouseY >= guiTop && mouseY <= ySize; + return mouseX >= xPos && mouseX <= clipWidth+xPos && mouseY >= yPos && mouseY <= clipHeight+yPos; } protected void setClip(){ - setClip(guiLeft, guiTop, clipWidth, clipHeight); + setClip(xPos, yPos, clipWidth, clipHeight); } protected void setClip(int x, int y, int width, int height){