mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 01:27:27 +00:00
Add scrollbars
This commit is contained in:
1 parent
b2303dcaac
commit
fcf74094f0
1 file changed
+33
-6
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user