From 3c464c52fdebcee5331388e6fa77c45b50178324 Mon Sep 17 00:00:00 2001 From: somehussar <148253652+somehussar@users.noreply.github.com> Date: Sun, 19 May 2024 02:27:03 +0200 Subject: [PATCH 1/8] Port over scrollable GUIs --- .../npcs/client/gui/util/GuiNPCInterface.java | 35 ++++- .../npcs/client/gui/util/GuiScrollable.java | 133 ++++++++++++++++++ 2 files changed, 161 insertions(+), 7 deletions(-) create mode 100644 src/main/java/noppes/npcs/client/gui/util/GuiScrollable.java 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 a2144bc81..1ee84436d 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java @@ -29,13 +29,15 @@ public abstract class GuiNPCInterface extends GuiScreen public boolean drawDefaultBackground = true; public EntityNPCInterface npc; protected HashMap buttons = new HashMap(); - private HashMap topbuttons = new HashMap(); - private HashMap sidebuttons = new HashMap(); - private HashMap textfields = new HashMap(); - private HashMap labels = new HashMap(); - private HashMap scrolls = new HashMap(); - private HashMap sliders = new HashMap(); - private HashMap extra = new HashMap(); + protected HashMap topbuttons = new HashMap(); + protected HashMap sidebuttons = new HashMap(); + protected HashMap textfields = new HashMap(); + protected HashMap labels = new HashMap(); + protected HashMap scrolls = new HashMap(); + protected HashMap sliders = new HashMap(); + protected HashMap extra = new HashMap(); + protected HashMap scrollableGuiInserts = new HashMap<>(); + public String title; private ResourceLocation background = null; public boolean closeOnEsc = false; @@ -105,6 +107,11 @@ public abstract class GuiNPCInterface extends GuiScreen extra.put(gui.id, gui); } + public void addScrollableGui(int id, GuiScrollable gui){ + gui.setWorldAndResolution(mc, width, height); + extra.put(id, gui); + } + public void mouseClicked(int i, int j, int k) { if(subgui != null) @@ -113,6 +120,12 @@ public abstract class GuiNPCInterface extends GuiScreen for(GuiNpcTextField tf : new ArrayList(textfields.values())) if(tf.enabled) tf.mouseClicked(i, j, k); + + for(GuiScrollable guiScrollable : scrollableGuiInserts.values()) { + if(guiScrollable.isMouseOver(i, j)) + guiScrollable.mouseClicked(i, j, k); + } + if (k == 0){ for(GuiCustomScroll scroll : new ArrayList(scrolls.values())){ scroll.mouseClicked(i, j, k); @@ -189,6 +202,11 @@ public abstract class GuiNPCInterface extends GuiScreen return labels.get(i); } + public GuiScrollable getScrollableGui(int i) { + return scrollableGuiInserts.get(i); + } + + public void addSlider(GuiNpcSlider slider){ sliders.put(slider.id,slider); buttonList.add(slider); @@ -241,6 +259,9 @@ public abstract class GuiNPCInterface extends GuiScreen button.drawHover(i, j, subGui); } } + for(GuiScrollable guiScrollable : scrollableGuiInserts.values()){ + guiScrollable.drawScreen(i, j, f, guiScrollable.isMouseOver(i,j)?Mouse.getDWheel():0); + } if(subgui != null) subgui.drawScreen(i,j,f); diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiScrollable.java b/src/main/java/noppes/npcs/client/gui/util/GuiScrollable.java new file mode 100644 index 000000000..da03b96fb --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/util/GuiScrollable.java @@ -0,0 +1,133 @@ +package noppes.npcs.client.gui.util; + +import net.minecraft.client.gui.ScaledResolution; +import noppes.npcs.entity.EntityNPCInterface; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; + +public class GuiScrollable extends GuiNPCInterface{ + + protected ScaledResolution scaledResolution; + public int clipWidth; + public int clipHeight; + + protected int maxScrollY = 0; + protected float scrollY = 0; + protected float nextScrollY = 0; + + private double lerp(double a, double b, double lambda){ + return a + lambda * (b - a); + } + + public GuiScrollable(EntityNPCInterface npc, int posX, int posY, int clipWidth, int clipHeight, int maxScroll){ + super(npc); + this.guiLeft = posX; + this.guiTop = posY; + this.clipWidth = clipWidth; + this.clipHeight = clipHeight; + this.maxScrollY = maxScroll; + } + + @Override + public void save() { + + } + + @Override + public void initGui(){ + super.initGui(); + + + + float scrollPerc = 0; + if((guiTop+clipHeight) != 0){ + scrollPerc = (nextScrollY) / (clipHeight); + } + + nextScrollY = scrollPerc * (clipHeight); + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks){ + scrollY = (float) lerp(scrollY, nextScrollY, partialTicks); + if(Float.isNaN(scrollY)) + scrollY = 0; + + boolean drawBackground = this.drawDefaultBackground; + + GL11.glPushMatrix(); + + //Enable clipping + GL11.glEnable(GL11.GL_SCISSOR_TEST); + setClip(); + + this.drawDefaultBackground = false; + if(drawBackground) + this.drawDefaultBackground(); + + GL11.glTranslatef(guiLeft, guiTop+scrollY, 0); + super.drawScreen(mouseX-guiLeft, (int) (mouseY-scrollY-guiTop), partialTicks); + + this.drawDefaultBackground = drawBackground; + + //Disable clipping (VERY IMPORTANT) + GL11.glDisable(GL11.GL_SCISSOR_TEST); + GL11.glTranslatef(0, 0, 0); + + GL11.glPopMatrix(); + } + + public void drawScreen(int mouseX, int mouseY, float partialTicks, int mouseScroll){ + nextScrollY -= (float) mouseScroll/25; + if(nextScrollY < 0) + nextScrollY = 0; + if(nextScrollY > clipHeight) { + nextScrollY = clipHeight; + } + this.drawScreen(mouseX, mouseY, partialTicks); + } + + @Override + public void mouseClicked(int mouseX, int mouseY, int mouseButton){ + super.mouseClicked(mouseX-guiLeft, (int) (mouseY-scrollY-guiTop), mouseButton); + } + + @Override + public void handleMouseInput(){ + super.handleMouseInput(); + + nextScrollY -= (float) Mouse.getEventDWheel()/25; + if(nextScrollY < 0) + nextScrollY = 0; + if(nextScrollY > maxScrollY){ + nextScrollY = maxScrollY; + } + + } + + public boolean isMouseOver(int mouseX, int mouseY){ + return mouseX >= guiLeft && mouseX <= xSize && mouseY >= guiTop && mouseY <= ySize; + } + + protected void setClip(){ + setClip(guiLeft, guiTop, clipWidth, clipHeight); + } + + protected void setClip(int x, int y, int width, int height){ + if(scaledResolution == null) + return; + int scaleFactor = scaledResolution.getScaleFactor(); + + //Correct the positions for Screen Space in OpenGL + x*=scaleFactor; + y*=scaleFactor; + width*=scaleFactor; + height*=scaleFactor; + + //Adjust position to Top-Left origin (OpenGL window/screen space uses bottom-left origin) + y=mc.displayHeight-y; + + //Set clip + GL11.glScissor(x, y-height, width, height); + } +} From 223e3216da40d6538da7c1b6dfe27ac169765a96 Mon Sep 17 00:00:00 2001 From: somehussar <148253652+somehussar@users.noreply.github.com> Date: Sun, 19 May 2024 02:31:37 +0200 Subject: [PATCH 2/8] Fix adding scrollable GUIs --- src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 1ee84436d..96b0fc385 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java @@ -109,7 +109,8 @@ public abstract class GuiNPCInterface extends GuiScreen public void addScrollableGui(int id, GuiScrollable gui){ gui.setWorldAndResolution(mc, width, height); - extra.put(id, gui); + gui.initGui(); + scrollableGuiInserts.put(id, gui); } public void mouseClicked(int i, int j, int k) From a42d0ac6e8650af0f650c175300a52f13644bfa6 Mon Sep 17 00:00:00 2001 From: somehussar <148253652+somehussar@users.noreply.github.com> Date: Sun, 19 May 2024 03:28:35 +0200 Subject: [PATCH 3/8] Fix misalignment --- .../npcs/client/gui/util/GuiNPCInterface.java | 7 ++- .../npcs/client/gui/util/GuiScrollable.java | 46 +++++++++++-------- 2 files changed, 33 insertions(+), 20 deletions(-) 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){ From b2303dcaac53c21adb3b601da07d55c8217e026c Mon Sep 17 00:00:00 2001 From: somehussar <148253652+somehussar@users.noreply.github.com> Date: Tue, 21 May 2024 02:16:25 +0200 Subject: [PATCH 4/8] Rename class appropriately --- .../npcs/client/gui/util/GuiNPCInterface.java | 16 ++++++++-------- ...rollable.java => GuiScrollableComponent.java} | 10 ++++++++-- 2 files changed, 16 insertions(+), 10 deletions(-) rename src/main/java/noppes/npcs/client/gui/util/{GuiScrollable.java => GuiScrollableComponent.java} (90%) 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 f9a923f60..bd95eee9e 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java @@ -36,7 +36,7 @@ public abstract class GuiNPCInterface extends GuiScreen protected HashMap scrolls = new HashMap(); protected HashMap sliders = new HashMap(); protected HashMap extra = new HashMap(); - protected HashMap scrollableGuiInserts = new HashMap<>(); + protected HashMap scrollableGuiInserts = new HashMap<>(); public String title; private ResourceLocation background = null; @@ -108,7 +108,7 @@ public abstract class GuiNPCInterface extends GuiScreen extra.put(gui.id, gui); } - public void addScrollableGui(int id, GuiScrollable gui){ + public void addScrollableGui(int id, GuiScrollableComponent gui){ gui.setWorldAndResolution(mc, width, height); gui.initGui(); scrollableGuiInserts.put(id, gui); @@ -123,9 +123,9 @@ public abstract class GuiNPCInterface extends GuiScreen if(tf.enabled) tf.mouseClicked(i, j, k); - for(GuiScrollable guiScrollable : scrollableGuiInserts.values()) { - if(guiScrollable.isMouseOver(i, j)) - guiScrollable.mouseClicked(i, j, k); + for(GuiScrollableComponent guiScrollableComponent : scrollableGuiInserts.values()) { + if(guiScrollableComponent.isMouseOver(i, j)) + guiScrollableComponent.mouseClicked(i, j, k); } if (k == 0){ @@ -204,7 +204,7 @@ public abstract class GuiNPCInterface extends GuiScreen return labels.get(i); } - public GuiScrollable getScrollableGui(int i) { + public GuiScrollableComponent getScrollableGui(int i) { return scrollableGuiInserts.get(i); } @@ -263,8 +263,8 @@ public abstract class GuiNPCInterface extends GuiScreen button.drawHover(i, j, subGui); } } - for(GuiScrollable guiScrollable : scrollableGuiInserts.values()){ - guiScrollable.drawScreen(i, j, f, guiScrollable.isMouseOver(i,j)?scrolled:0); + for(GuiScrollableComponent guiScrollableComponent : scrollableGuiInserts.values()){ + guiScrollableComponent.drawScreen(i, j, f, guiScrollableComponent.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/GuiScrollableComponent.java similarity index 90% rename from src/main/java/noppes/npcs/client/gui/util/GuiScrollable.java rename to src/main/java/noppes/npcs/client/gui/util/GuiScrollableComponent.java index 0674ee5ba..38cc087e0 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiScrollable.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiScrollableComponent.java @@ -4,10 +4,11 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.util.ChatComponentText; import noppes.npcs.entity.EntityNPCInterface; +import noppes.npcs.scripted.CustomNPCsException; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; -public class GuiScrollable extends GuiNPCInterface{ +public class GuiScrollableComponent extends GuiNPCInterface{ protected ScaledResolution scaledResolution; public int clipWidth; @@ -24,7 +25,7 @@ public class GuiScrollable extends GuiNPCInterface{ return a + lambda * (b - a); } - public GuiScrollable(EntityNPCInterface npc, int posX, int posY, int clipWidth, int clipHeight, int maxScroll){ + public GuiScrollableComponent(EntityNPCInterface npc, int posX, int posY, int clipWidth, int clipHeight, int maxScroll){ super(npc); this.xPos = posX; this.yPos = posY; @@ -98,6 +99,11 @@ public class GuiScrollable extends GuiNPCInterface{ } } + @Override + public void addScrollableGui(int id, GuiScrollableComponent d){ + throw new CustomNPCsException("You can't put scrollable GUIs into a scrollable GUI"); + } + @Override public void buttonEvent(GuiButton button){ mc.thePlayer.addChatMessage(new ChatComponentText("LOL")); From fcf74094f023408c683ac94fb4d99fc4e8a1fdb2 Mon Sep 17 00:00:00 2001 From: somehussar <148253652+somehussar@users.noreply.github.com> Date: Tue, 21 May 2024 03:28:25 +0200 Subject: [PATCH 5/8] Add scrollbars --- .../gui/util/GuiScrollableComponent.java | 39 ++++++++++++++++--- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiScrollableComponent.java b/src/main/java/noppes/npcs/client/gui/util/GuiScrollableComponent.java index 38cc087e0..48ce510cf 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiScrollableComponent.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiScrollableComponent.java @@ -3,6 +3,7 @@ package noppes.npcs.client.gui.util; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.util.ChatComponentText; +import net.minecraft.util.ResourceLocation; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.scripted.CustomNPCsException; import org.lwjgl.input.Mouse; @@ -10,6 +11,7 @@ import org.lwjgl.opengl.GL11; public class GuiScrollableComponent extends GuiNPCInterface{ + public static final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/misc.png"); protected ScaledResolution scaledResolution; public int clipWidth; public int clipHeight; @@ -66,12 +68,16 @@ public class GuiScrollableComponent extends GuiNPCInterface{ //Enable clipping GL11.glEnable(GL11.GL_SCISSOR_TEST); - setClip(); + setClip(xPos, yPos, clipWidth, clipHeight); this.drawDefaultBackground = false; if(drawBackground) this.drawDefaultBackground(); + + if(maxScrollY > clipHeight/2) + setClip(xPos, yPos, clipWidth-13, clipHeight); + GL11.glTranslatef(xPos, yPos+scrollY, 0); super.drawScreen(mouseX-xPos, (int) (mouseY-scrollY-yPos), partialTicks); @@ -79,7 +85,13 @@ public class GuiScrollableComponent extends GuiNPCInterface{ //Disable clipping (VERY IMPORTANT) GL11.glDisable(GL11.GL_SCISSOR_TEST); - GL11.glTranslatef(0, 0, 0); + GL11.glTranslatef(-xPos, -yPos-scrollY, 0); + + + + if(maxScrollY > clipHeight/2){ + drawScrollBar(); + } GL11.glPopMatrix(); } @@ -90,6 +102,22 @@ public class GuiScrollableComponent extends GuiNPCInterface{ this.drawScreen(mouseX, mouseY, partialTicks); } + private void drawScrollBar() + { + mc.renderEngine.bindTexture(resource); + GL11.glColor4f(1, 1, 1, 1); + + int maxSize = (int) ((clipHeight) * ( (double) (clipHeight)/ maxScrollY))/2; + + int x = xPos + clipWidth - 9; + int y = (int) (yPos + 4 + (scrollY/maxScrollY * (clipHeight-maxSize-8))); + + for(int k = y; k < y+maxSize && k-clipHeight+maxSize < clipHeight;k++){ + drawTexturedModalRect(x, k, 176, 9, 5, 1); + } + + } + public void adjustScroll(int mouseScroll) { nextScrollY -= (float) mouseScroll/25; if(nextScrollY < 0) @@ -125,15 +153,14 @@ public class GuiScrollableComponent extends GuiNPCInterface{ return mouseX >= xPos && mouseX <= clipWidth+xPos && mouseY >= yPos && mouseY <= clipHeight+yPos; } - protected void setClip(){ - setClip(xPos, yPos, clipWidth, clipHeight); - } - protected void setClip(int x, int y, int width, int height){ if(scaledResolution == null) return; int scaleFactor = scaledResolution.getScaleFactor(); +// if(drawingScrollbar) +// width-=10; + //Correct the positions for Screen Space in OpenGL x*=scaleFactor; y*=scaleFactor; From c781c6910092dd9c55c9492475bd6990eaffec17 Mon Sep 17 00:00:00 2001 From: somehussar <148253652+somehussar@users.noreply.github.com> Date: Tue, 21 May 2024 03:30:22 +0200 Subject: [PATCH 6/8] Fix scroll display condition --- .../client/gui/util/GuiScrollableComponent.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiScrollableComponent.java b/src/main/java/noppes/npcs/client/gui/util/GuiScrollableComponent.java index 48ce510cf..cf09bef4e 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiScrollableComponent.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiScrollableComponent.java @@ -27,6 +27,15 @@ public class GuiScrollableComponent extends GuiNPCInterface{ return a + lambda * (b - a); } + /** + * Scrollable GUI component :P? + * @param npc npc + * @param posX the X Position of the gui element on the screen + * @param posY the Y Position of the GUI element on the screen + * @param clipWidth width of the element + * @param clipHeight height of the element + * @param maxScroll extra Y area displayed through the scrollbar. + */ public GuiScrollableComponent(EntityNPCInterface npc, int posX, int posY, int clipWidth, int clipHeight, int maxScroll){ super(npc); this.xPos = posX; @@ -75,7 +84,7 @@ public class GuiScrollableComponent extends GuiNPCInterface{ this.drawDefaultBackground(); - if(maxScrollY > clipHeight/2) + if(maxScrollY > 0) setClip(xPos, yPos, clipWidth-13, clipHeight); GL11.glTranslatef(xPos, yPos+scrollY, 0); @@ -89,7 +98,7 @@ public class GuiScrollableComponent extends GuiNPCInterface{ - if(maxScrollY > clipHeight/2){ + if(maxScrollY > 0){ drawScrollBar(); } From 767ebc5131f1d96d540e948adca59fefbcd41c2f Mon Sep 17 00:00:00 2001 From: somehussar <148253652+somehussar@users.noreply.github.com> Date: Tue, 21 May 2024 03:32:10 +0200 Subject: [PATCH 7/8] Fix scroll direction :P --- .../client/gui/util/GuiScrollableComponent.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiScrollableComponent.java b/src/main/java/noppes/npcs/client/gui/util/GuiScrollableComponent.java index cf09bef4e..7d410bad2 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiScrollableComponent.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiScrollableComponent.java @@ -4,11 +4,14 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.util.ChatComponentText; import net.minecraft.util.ResourceLocation; +import noppes.npcs.client.gui.custom.GuiCustom; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.scripted.CustomNPCsException; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; +import java.util.Arrays; + public class GuiScrollableComponent extends GuiNPCInterface{ public static final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/misc.png"); @@ -56,6 +59,11 @@ public class GuiScrollableComponent extends GuiNPCInterface{ scaledResolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); addButton(new GuiNpcButton(0, 0, 0, "Testtt")); + GuiCustomScroll scroll = new GuiCustomScroll(this, 0); + scroll.setList(Arrays.asList("Test", "Testing2", "testing 3")); + scroll.guiTop = 10; + scroll.guiLeft = 30; + addScroll(scroll); float scrollPerc = 0; if((guiTop+clipHeight) != 0){ @@ -87,14 +95,14 @@ public class GuiScrollableComponent extends GuiNPCInterface{ if(maxScrollY > 0) setClip(xPos, yPos, clipWidth-13, clipHeight); - GL11.glTranslatef(xPos, yPos+scrollY, 0); + GL11.glTranslatef(xPos, yPos-scrollY, 0); super.drawScreen(mouseX-xPos, (int) (mouseY-scrollY-yPos), partialTicks); this.drawDefaultBackground = drawBackground; //Disable clipping (VERY IMPORTANT) GL11.glDisable(GL11.GL_SCISSOR_TEST); - GL11.glTranslatef(-xPos, -yPos-scrollY, 0); + GL11.glTranslatef(-xPos, -yPos+scrollY, 0); @@ -148,7 +156,7 @@ public class GuiScrollableComponent extends GuiNPCInterface{ @Override public void mouseClicked(int mouseX, int mouseY, int mouseButton){ - super.mouseClicked(mouseX-xPos, (int) (mouseY-yPos-scrollY), mouseButton); + super.mouseClicked(mouseX-xPos, (int) (mouseY-yPos+scrollY), mouseButton); } @Override From f9483b829242a3330248815434ec12e5e87507b4 Mon Sep 17 00:00:00 2001 From: somehussar <148253652+somehussar@users.noreply.github.com> Date: Tue, 21 May 2024 04:08:48 +0200 Subject: [PATCH 8/8] Failed attempts at fixing scroll lists within scrolls --- .../npcs/client/gui/util/GuiNPCInterface.java | 11 +++++++---- .../client/gui/util/GuiScrollableComponent.java | 15 ++++----------- 2 files changed, 11 insertions(+), 15 deletions(-) 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 bd95eee9e..158950ad5 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java @@ -43,7 +43,8 @@ public abstract class GuiNPCInterface extends GuiScreen public boolean closeOnEsc = false; public int guiLeft,guiTop,xSize,ySize; private SubGuiInterface subgui; - public int mouseX, mouseY; + public int mouseX, mouseY, mouseScroll; + public static boolean recordScroll = true; public float bgScale = 1; public float bgScaleX = 1; @@ -237,7 +238,9 @@ public abstract class GuiNPCInterface extends GuiScreen drawBackground(); } - int scrolled = Mouse.getDWheel(); + if(recordScroll) { + mouseScroll = Mouse.getDWheel(); + } boolean subGui = hasSubGui(); drawCenteredString(fontRendererObj, title, width / 2, guiTop + 4, 0xffffff); @@ -248,7 +251,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)?scrolled:0); + scroll.drawScreen(i, j, f, !subGui && scroll.isMouseOver(i, j)?mouseScroll:0); } for(GuiScreen gui : extra.values()) gui.drawScreen(i, j, f); @@ -264,7 +267,7 @@ public abstract class GuiNPCInterface extends GuiScreen } } for(GuiScrollableComponent guiScrollableComponent : scrollableGuiInserts.values()){ - guiScrollableComponent.drawScreen(i, j, f, guiScrollableComponent.isMouseOver(i,j)?scrolled:0); + guiScrollableComponent.drawScreen(i, j, f, guiScrollableComponent.isMouseOver(i,j)?mouseScroll:0); } if(subgui != null) diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiScrollableComponent.java b/src/main/java/noppes/npcs/client/gui/util/GuiScrollableComponent.java index 7d410bad2..91798303e 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiScrollableComponent.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiScrollableComponent.java @@ -58,13 +58,6 @@ public class GuiScrollableComponent extends GuiNPCInterface{ super.initGui(); scaledResolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); - addButton(new GuiNpcButton(0, 0, 0, "Testtt")); - GuiCustomScroll scroll = new GuiCustomScroll(this, 0); - scroll.setList(Arrays.asList("Test", "Testing2", "testing 3")); - scroll.guiTop = 10; - scroll.guiLeft = 30; - addScroll(scroll); - float scrollPerc = 0; if((guiTop+clipHeight) != 0){ scrollPerc = (nextScrollY) / (clipHeight); @@ -96,7 +89,7 @@ public class GuiScrollableComponent extends GuiNPCInterface{ setClip(xPos, yPos, clipWidth-13, clipHeight); GL11.glTranslatef(xPos, yPos-scrollY, 0); - super.drawScreen(mouseX-xPos, (int) (mouseY-scrollY-yPos), partialTicks); + super.drawScreen(mouseX-xPos, (int) (mouseY+scrollY-yPos), partialTicks); this.drawDefaultBackground = drawBackground; @@ -116,7 +109,9 @@ public class GuiScrollableComponent extends GuiNPCInterface{ public void drawScreen(int mouseX, int mouseY, float partialTicks, int mouseScroll){ adjustScroll(mouseScroll); + GuiNPCInterface.recordScroll = false; this.drawScreen(mouseX, mouseY, partialTicks); + GuiNPCInterface.recordScroll = true; } private void drawScrollBar() @@ -156,7 +151,7 @@ public class GuiScrollableComponent extends GuiNPCInterface{ @Override public void mouseClicked(int mouseX, int mouseY, int mouseButton){ - super.mouseClicked(mouseX-xPos, (int) (mouseY-yPos+scrollY), mouseButton); + super.mouseClicked(mouseX-xPos, (int) (mouseY-yPos+scrollY), mouseButton); } @Override @@ -175,8 +170,6 @@ public class GuiScrollableComponent extends GuiNPCInterface{ return; int scaleFactor = scaledResolution.getScaleFactor(); -// if(drawingScrollbar) -// width-=10; //Correct the positions for Screen Space in OpenGL x*=scaleFactor;