From a10012144f8e0bea64d4dfc58463fc24295b9ea4 Mon Sep 17 00:00:00 2001 From: lukflug Date: Tue, 1 Dec 2020 20:20:27 +0100 Subject: [PATCH 01/12] Started messing with minecraft-dependent source library --- build.gradle | 6 + panelstudio-mc/build.gradle | 13 ++ .../lukflug/panelstudio/mc/GLInterface.java | 198 ++++++++++++++++++ settings.gradle | 2 + 4 files changed, 219 insertions(+) create mode 100644 panelstudio-mc/build.gradle create mode 100644 panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/GLInterface.java diff --git a/build.gradle b/build.gradle index 5ec7c31..6690803 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,13 @@ + plugins { id 'java-library' } +sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8 +compileJava { + sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8 +} + allprojects { group = 'com.lukflug' version = '0.1.0' diff --git a/panelstudio-mc/build.gradle b/panelstudio-mc/build.gradle new file mode 100644 index 0000000..83c3b96 --- /dev/null +++ b/panelstudio-mc/build.gradle @@ -0,0 +1,13 @@ + +plugins { + id 'java-library' +} + +sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8 +compileJava { + sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8 +} + +task packageDistribution(type: Jar) { + from "$projectDir/src/main/java" +} diff --git a/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/GLInterface.java b/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/GLInterface.java new file mode 100644 index 0000000..f113cce --- /dev/null +++ b/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/GLInterface.java @@ -0,0 +1,198 @@ +package com.lukflug.panelstudio.mc; + +import java.awt.Color; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.InputStream; + +import javax.imageio.ImageIO; + +import org.lwjgl.opengl.GL11; +import org.lwjgl.util.glu.GLU; + +import com.lukflug.panelstudio.Interface; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.TextureUtil; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.util.ResourceLocation; + +/** + * Implementation of Interface for OpenGL in minecraft. + * @author lukflug + */ +public class GLInterface implements Interface { + @Override + public void fillTriangle(Point pos1, Point pos2, Point pos3, Color c1, Color c2, Color c3) { + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder bufferbuilder = tessellator.getBuffer(); + bufferbuilder.begin(GL11.GL_TRIANGLES,DefaultVertexFormats.POSITION_COLOR); + bufferbuilder.pos(pos1.x,pos1.y,zLevel).color(c1.getRed()/255.0f,c1.getGreen()/255.0f,c1.getBlue()/255.0f,c1.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(pos2.x,pos2.y,zLevel).color(c2.getRed()/255.0f,c2.getGreen()/255.0f,c2.getBlue()/255.0f,c2.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(pos3.x,pos3.y,zLevel).color(c3.getRed()/255.0f,c3.getGreen()/255.0f,c3.getBlue()/255.0f,c3.getAlpha()/255.0f).endVertex(); + tessellator.draw(); + } + + @Override + public void drawLine(Point a, Point b, Color c1, Color c2) { + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder bufferbuilder = tessellator.getBuffer(); + bufferbuilder.begin(GL11.GL_LINES,DefaultVertexFormats.POSITION_COLOR); + bufferbuilder.pos(a.x,a.y,zLevel).color(c1.getRed()/255.0f,c1.getGreen()/255.0f,c1.getBlue()/255.0f,c1.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(b.x,b.y,zLevel).color(c2.getRed()/255.0f,c2.getGreen()/255.0f,c2.getBlue()/255.0f,c2.getAlpha()/255.0f).endVertex(); + tessellator.draw(); + } + + @Override + public void fillRect(Rectangle r, Color c1, Color c2, Color c3, Color c4) { + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder bufferbuilder = tessellator.getBuffer(); + bufferbuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR); + bufferbuilder.pos(r.x,r.y+r.height,zLevel).color(c4.getRed()/255.0f,c4.getGreen()/255.0f,c4.getBlue()/255.0f,c4.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(r.x+r.width,r.y+r.height,zLevel).color(c3.getRed()/255.0f,c3.getGreen()/255.0f,c3.getBlue()/255.0f,c3.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(r.x+r.width,r.y,zLevel).color(c2.getRed()/255.0f,c2.getGreen()/255.0f,c2.getBlue()/255.0f,c2.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(r.x,r.y,zLevel).color(c1.getRed()/255.0f,c1.getGreen()/255.0f,c1.getBlue()/255.0f,c1.getAlpha()/255.0f).endVertex(); + tessellator.draw(); + } + + @Override + public void drawRect(Rectangle r, Color c1, Color c2, Color c3, Color c4) { + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder bufferbuilder = tessellator.getBuffer(); + bufferbuilder.begin(GL11.GL_LINE_LOOP, DefaultVertexFormats.POSITION_COLOR); + bufferbuilder.pos(r.x,r.y+r.height,zLevel).color(c4.getRed()/255.0f,c4.getGreen()/255.0f,c4.getBlue()/255.0f,c4.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(r.x+r.width,r.y+r.height,zLevel).color(c3.getRed()/255.0f,c3.getGreen()/255.0f,c3.getBlue()/255.0f,c3.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(r.x+r.width,r.y,zLevel).color(c2.getRed()/255.0f,c2.getGreen()/255.0f,c2.getBlue()/255.0f,c2.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(r.x,r.y,zLevel).color(c1.getRed()/255.0f,c1.getGreen()/255.0f,c1.getBlue()/255.0f,c1.getAlpha()/255.0f).endVertex(); + tessellator.draw(); + } + + @Override + public synchronized int loadImage(String name) { + try { + ResourceLocation rl=new ResourceLocation("gamesense:gui/"+name); + InputStream stream=Minecraft.getMinecraft().resourceManager.getResource(rl).getInputStream(); + BufferedImage image=ImageIO.read(stream); + int texture=TextureUtil.glGenTextures(); + TextureUtil.uploadTextureImage(texture,image); + return texture; + } catch (IOException e) { + e.printStackTrace(); + return 0; + } + } + + @Override + public void drawImage(Rectangle r, int rotation, boolean parity, int image) { + if (image==0) return; + int texCoords[][]={{0,1},{1,1},{1,0},{0,0}}; + for (int i=0;ix1 && y2>y1) { + Rectangle rect=new Rectangle(x1,y1,x2-x1,y2-y1); + scissor(rect); + clipRect.push(rect); + } else { + scissor(null); + clipRect.push(null); + } + } + } + } + + @Override + public void restore() { + if (!clipRect.isEmpty()) { + clipRect.pop(); + if (clipRect.isEmpty()) GL11.glDisable(GL11.GL_SCISSOR_TEST); + else scissor(clipRect.peek()); + } + } + + protected static void begin() { + GlStateManager.enableBlend(); + GlStateManager.disableTexture2D(); + GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); + GlStateManager.shadeModel(GL11.GL_SMOOTH); + GlStateManager.glLineWidth(2); + } + + protected static void end() { + GlStateManager.shadeModel(GL11.GL_FLAT); + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); + } +} diff --git a/settings.gradle b/settings.gradle index f54f6d2..4cf003d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1,3 @@ + rootProject.name='panelstudio' +include 'panelstudio-mc' From 49b5f6d0e96feaaa716283cc200ea671a07d9239 Mon Sep 17 00:00:00 2001 From: lukflug Date: Sun, 13 Dec 2020 19:07:21 +0100 Subject: [PATCH 02/12] Implemented Interface and GuiScreen base class --- .../lukflug/panelstudio/mc/GLInterface.java | 77 +++++++++---- .../lukflug/panelstudio/mc/MinecraftGUI.java | 101 ++++++++++++++++++ .../panelstudio/mc/MinecraftHUDGUI.java | 26 +++++ 3 files changed, 182 insertions(+), 22 deletions(-) create mode 100644 panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftGUI.java create mode 100644 panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftHUDGUI.java diff --git a/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/GLInterface.java b/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/GLInterface.java index f113cce..c817451 100644 --- a/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/GLInterface.java +++ b/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/GLInterface.java @@ -6,6 +6,9 @@ import java.awt.image.BufferedImage; import java.io.IOException; import java.io.InputStream; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; +import java.util.Stack; import javax.imageio.ImageIO; @@ -16,6 +19,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.GLAllocation; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.texture.TextureUtil; @@ -26,15 +30,36 @@ * Implementation of Interface for OpenGL in minecraft. * @author lukflug */ -public class GLInterface implements Interface { +public abstract class GLInterface implements Interface { + /** + * Buffer to store current modelview matrix. + */ + private static final FloatBuffer MODELVIEW = GLAllocation.createDirectFloatBuffer(16); + /** + * Buffer to store current projection matrix. + */ + private static final FloatBuffer PROJECTION = GLAllocation.createDirectFloatBuffer(16); + /** + * Buffer to store current viewport. + */ + private static final IntBuffer VIEWPORT = GLAllocation.createDirectIntBuffer(16); + /** + * Buffer used to calculate coordinates using gluProject. + */ + private static final FloatBuffer COORDS = GLAllocation.createDirectFloatBuffer(3); + /** + * Clipping rectangle stack. + */ + private Stack clipRect=new Stack(); + @Override public void fillTriangle(Point pos1, Point pos2, Point pos3, Color c1, Color c2, Color c3) { Tessellator tessellator = Tessellator.getInstance(); BufferBuilder bufferbuilder = tessellator.getBuffer(); bufferbuilder.begin(GL11.GL_TRIANGLES,DefaultVertexFormats.POSITION_COLOR); - bufferbuilder.pos(pos1.x,pos1.y,zLevel).color(c1.getRed()/255.0f,c1.getGreen()/255.0f,c1.getBlue()/255.0f,c1.getAlpha()/255.0f).endVertex(); - bufferbuilder.pos(pos2.x,pos2.y,zLevel).color(c2.getRed()/255.0f,c2.getGreen()/255.0f,c2.getBlue()/255.0f,c2.getAlpha()/255.0f).endVertex(); - bufferbuilder.pos(pos3.x,pos3.y,zLevel).color(c3.getRed()/255.0f,c3.getGreen()/255.0f,c3.getBlue()/255.0f,c3.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(pos1.x,pos1.y,getZLevel()).color(c1.getRed()/255.0f,c1.getGreen()/255.0f,c1.getBlue()/255.0f,c1.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(pos2.x,pos2.y,getZLevel()).color(c2.getRed()/255.0f,c2.getGreen()/255.0f,c2.getBlue()/255.0f,c2.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(pos3.x,pos3.y,getZLevel()).color(c3.getRed()/255.0f,c3.getGreen()/255.0f,c3.getBlue()/255.0f,c3.getAlpha()/255.0f).endVertex(); tessellator.draw(); } @@ -43,8 +68,8 @@ public void drawLine(Point a, Point b, Color c1, Color c2) { Tessellator tessellator = Tessellator.getInstance(); BufferBuilder bufferbuilder = tessellator.getBuffer(); bufferbuilder.begin(GL11.GL_LINES,DefaultVertexFormats.POSITION_COLOR); - bufferbuilder.pos(a.x,a.y,zLevel).color(c1.getRed()/255.0f,c1.getGreen()/255.0f,c1.getBlue()/255.0f,c1.getAlpha()/255.0f).endVertex(); - bufferbuilder.pos(b.x,b.y,zLevel).color(c2.getRed()/255.0f,c2.getGreen()/255.0f,c2.getBlue()/255.0f,c2.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(a.x,a.y,getZLevel()).color(c1.getRed()/255.0f,c1.getGreen()/255.0f,c1.getBlue()/255.0f,c1.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(b.x,b.y,getZLevel()).color(c2.getRed()/255.0f,c2.getGreen()/255.0f,c2.getBlue()/255.0f,c2.getAlpha()/255.0f).endVertex(); tessellator.draw(); } @@ -53,10 +78,10 @@ public void fillRect(Rectangle r, Color c1, Color c2, Color c3, Color c4) { Tessellator tessellator = Tessellator.getInstance(); BufferBuilder bufferbuilder = tessellator.getBuffer(); bufferbuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR); - bufferbuilder.pos(r.x,r.y+r.height,zLevel).color(c4.getRed()/255.0f,c4.getGreen()/255.0f,c4.getBlue()/255.0f,c4.getAlpha()/255.0f).endVertex(); - bufferbuilder.pos(r.x+r.width,r.y+r.height,zLevel).color(c3.getRed()/255.0f,c3.getGreen()/255.0f,c3.getBlue()/255.0f,c3.getAlpha()/255.0f).endVertex(); - bufferbuilder.pos(r.x+r.width,r.y,zLevel).color(c2.getRed()/255.0f,c2.getGreen()/255.0f,c2.getBlue()/255.0f,c2.getAlpha()/255.0f).endVertex(); - bufferbuilder.pos(r.x,r.y,zLevel).color(c1.getRed()/255.0f,c1.getGreen()/255.0f,c1.getBlue()/255.0f,c1.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(r.x,r.y+r.height,getZLevel()).color(c4.getRed()/255.0f,c4.getGreen()/255.0f,c4.getBlue()/255.0f,c4.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(r.x+r.width,r.y+r.height,getZLevel()).color(c3.getRed()/255.0f,c3.getGreen()/255.0f,c3.getBlue()/255.0f,c3.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(r.x+r.width,r.y,getZLevel()).color(c2.getRed()/255.0f,c2.getGreen()/255.0f,c2.getBlue()/255.0f,c2.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(r.x,r.y,getZLevel()).color(c1.getRed()/255.0f,c1.getGreen()/255.0f,c1.getBlue()/255.0f,c1.getAlpha()/255.0f).endVertex(); tessellator.draw(); } @@ -65,10 +90,10 @@ public void drawRect(Rectangle r, Color c1, Color c2, Color c3, Color c4) { Tessellator tessellator = Tessellator.getInstance(); BufferBuilder bufferbuilder = tessellator.getBuffer(); bufferbuilder.begin(GL11.GL_LINE_LOOP, DefaultVertexFormats.POSITION_COLOR); - bufferbuilder.pos(r.x,r.y+r.height,zLevel).color(c4.getRed()/255.0f,c4.getGreen()/255.0f,c4.getBlue()/255.0f,c4.getAlpha()/255.0f).endVertex(); - bufferbuilder.pos(r.x+r.width,r.y+r.height,zLevel).color(c3.getRed()/255.0f,c3.getGreen()/255.0f,c3.getBlue()/255.0f,c3.getAlpha()/255.0f).endVertex(); - bufferbuilder.pos(r.x+r.width,r.y,zLevel).color(c2.getRed()/255.0f,c2.getGreen()/255.0f,c2.getBlue()/255.0f,c2.getAlpha()/255.0f).endVertex(); - bufferbuilder.pos(r.x,r.y,zLevel).color(c1.getRed()/255.0f,c1.getGreen()/255.0f,c1.getBlue()/255.0f,c1.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(r.x,r.y+r.height,getZLevel()).color(c4.getRed()/255.0f,c4.getGreen()/255.0f,c4.getBlue()/255.0f,c4.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(r.x+r.width,r.y+r.height,getZLevel()).color(c3.getRed()/255.0f,c3.getGreen()/255.0f,c3.getBlue()/255.0f,c3.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(r.x+r.width,r.y,getZLevel()).color(c2.getRed()/255.0f,c2.getGreen()/255.0f,c2.getBlue()/255.0f,c2.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(r.x,r.y,getZLevel()).color(c1.getRed()/255.0f,c1.getGreen()/255.0f,c1.getBlue()/255.0f,c1.getAlpha()/255.0f).endVertex(); tessellator.draw(); } @@ -120,10 +145,10 @@ public void drawImage(Rectangle r, int rotation, boolean parity, int image) { GlStateManager.bindTexture(image); GlStateManager.enableTexture2D(); bufferbuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); - bufferbuilder.pos(r.x,r.y+r.height,zLevel).tex(texCoords[0][0],texCoords[0][1]).endVertex(); - bufferbuilder.pos(r.x+r.width,r.y+r.height,zLevel).tex(texCoords[1][0],texCoords[1][1]).endVertex(); - bufferbuilder.pos(r.x+r.width,r.y,zLevel).tex(texCoords[2][0],texCoords[2][1]).endVertex(); - bufferbuilder.pos(r.x,r.y,zLevel).tex(texCoords[3][0],texCoords[3][1]).endVertex(); + bufferbuilder.pos(r.x,r.y+r.height,getZLevel()).tex(texCoords[0][0],texCoords[0][1]).endVertex(); + bufferbuilder.pos(r.x+r.width,r.y+r.height,getZLevel()).tex(texCoords[1][0],texCoords[1][1]).endVertex(); + bufferbuilder.pos(r.x+r.width,r.y,getZLevel()).tex(texCoords[2][0],texCoords[2][1]).endVertex(); + bufferbuilder.pos(r.x,r.y,getZLevel()).tex(texCoords[3][0],texCoords[3][1]).endVertex(); tessellator.draw(); GlStateManager.disableTexture2D(); } @@ -135,10 +160,10 @@ protected void scissor (Rectangle r) { return; } float x1,y1,x2,y2; - GLU.gluProject(r.x,r.y,zLevel,MODELVIEW,PROJECTION,VIEWPORT,COORDS); + GLU.gluProject(r.x,r.y,getZLevel(),MODELVIEW,PROJECTION,VIEWPORT,COORDS); x1=COORDS.get(0); y1=COORDS.get(1); - GLU.gluProject(r.x+r.width,r.y+r.height,zLevel,MODELVIEW,PROJECTION,VIEWPORT,COORDS); + GLU.gluProject(r.x+r.width,r.y+r.height,getZLevel(),MODELVIEW,PROJECTION,VIEWPORT,COORDS); x2=COORDS.get(0); y2=COORDS.get(1); GL11.glScissor(Math.round(Math.min(x1,x2)),Math.round(Math.min(y1,y2)),Math.round(Math.abs(x2-x1)),Math.round(Math.abs(y2-y1))); @@ -182,7 +207,13 @@ public void restore() { } } - protected static void begin() { + public void getMatrices() { + GlStateManager.getFloat(GL11.GL_MODELVIEW_MATRIX,MODELVIEW); + GlStateManager.getFloat(GL11.GL_PROJECTION_MATRIX,PROJECTION); + GlStateManager.glGetInteger(GL11.GL_VIEWPORT,VIEWPORT); + } + + public static void begin() { GlStateManager.enableBlend(); GlStateManager.disableTexture2D(); GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); @@ -190,9 +221,11 @@ protected static void begin() { GlStateManager.glLineWidth(2); } - protected static void end() { + public static void end() { GlStateManager.shadeModel(GL11.GL_FLAT); GlStateManager.enableTexture2D(); GlStateManager.disableBlend(); } + + protected abstract float getZLevel(); } diff --git a/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftGUI.java b/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftGUI.java new file mode 100644 index 0000000..1de0d19 --- /dev/null +++ b/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftGUI.java @@ -0,0 +1,101 @@ +package com.lukflug.panelstudio.mc; + +import java.awt.Point; + +import org.lwjgl.input.Mouse; + +import com.lukflug.panelstudio.ClickGUI; +import com.lukflug.panelstudio.Interface; + +import net.minecraft.client.gui.GuiScreen; + +public abstract class MinecraftGUI extends GuiScreen { + private Point mouse=new Point(); + private boolean lButton=false,rButton=false; + + protected void renderGUI() { + getInterface().getMatrices(); + GLInterface.begin(); + getGUI().render(); + GLInterface.end(); + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + renderGUI(); + mouse=new Point(mouseX,mouseY); + int scroll=Mouse.getDWheel(); + if (scroll!=0) { + if (scroll>0) getGUI().handleScroll(-getScrollSpeed()); + else getGUI().handleScroll(getScrollSpeed()); + } + } + + @Override + public void mouseClicked(int mouseX, int mouseY, int clickedButton) { + mouse=new Point(mouseX,mouseY); + switch (clickedButton) { + case Interface.LBUTTON: + lButton=true; + break; + case Interface.RBUTTON: + rButton=true; + break; + } + getGUI().handleButton(clickedButton); + } + + @Override + public void mouseReleased(int mouseX, int mouseY, int releaseButton) { + mouse=new Point(mouseX,mouseY); + switch (releaseButton) { + case Interface.LBUTTON: + lButton=false; + break; + case Interface.RBUTTON: + rButton=false; + break; + } + getGUI().handleButton(releaseButton); + } + + @Override + protected void keyTyped(final char typedChar, final int keyCode) { + if (keyCode == 1) { + getGUI().exit(); + this.mc.displayGuiScreen(null); + } else getGUI().handleKey(keyCode); + } + + @Override + public boolean doesGuiPauseGame() { + return false; + } + + protected abstract ClickGUI getGUI(); + protected abstract GUIInterface getInterface(); + protected abstract int getScrollSpeed(); + + public abstract class GUIInterface extends GLInterface { + @Override + public boolean getButton(int button) { + switch (button) { + case Interface.LBUTTON: + return lButton; + case Interface.RBUTTON: + return rButton; + } + return false; + } + + @Override + public Point getMouse() { + return new Point(mouse); + } + + @Override + protected float getZLevel() { + return zLevel; + } + } +} diff --git a/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftHUDGUI.java b/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftHUDGUI.java new file mode 100644 index 0000000..519d028 --- /dev/null +++ b/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftHUDGUI.java @@ -0,0 +1,26 @@ +package com.lukflug.panelstudio.mc; + +import com.lukflug.panelstudio.ClickGUI; +import com.lukflug.panelstudio.hud.HUDClickGUI; + +public abstract class MinecraftHUDGUI extends MinecraftGUI { + public void render() { + if (!getHUDGUI().isOn()) renderGUI(); + } + + public void handleKeyEvent (int scancode) { + if (scancode!=1 && !getHUDGUI().isOn()) getHUDGUI().handleKey(scancode); + } + + @Override + protected void keyTyped(final char typedChar, final int keyCode) { + if (keyCode==1 && getHUDGUI().isOn()) getHUDGUI().toggle(); + } + + protected abstract HUDClickGUI getHUDGUI(); + + @Override + protected ClickGUI getGUI() { + return getHUDGUI(); + } +} From 5e928bc966acdbea421817f6bfadd213f721b609 Mon Sep 17 00:00:00 2001 From: lukflug Date: Sun, 13 Dec 2020 19:59:23 +0100 Subject: [PATCH 03/12] Added javadoc and added EnterGUI method --- .../lukflug/panelstudio/mc/GLInterface.java | 26 +++++++- .../lukflug/panelstudio/mc/MinecraftGUI.java | 60 ++++++++++++++++++- .../panelstudio/mc/MinecraftHUDGUI.java | 22 +++++++ 3 files changed, 105 insertions(+), 3 deletions(-) diff --git a/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/GLInterface.java b/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/GLInterface.java index c817451..e860b0a 100644 --- a/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/GLInterface.java +++ b/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/GLInterface.java @@ -100,7 +100,7 @@ public void drawRect(Rectangle r, Color c1, Color c2, Color c3, Color c4) { @Override public synchronized int loadImage(String name) { try { - ResourceLocation rl=new ResourceLocation("gamesense:gui/"+name); + ResourceLocation rl=new ResourceLocation(getResourcePrefix()+name); InputStream stream=Minecraft.getMinecraft().resourceManager.getResource(rl).getInputStream(); BufferedImage image=ImageIO.read(stream); int texture=TextureUtil.glGenTextures(); @@ -153,6 +153,10 @@ public void drawImage(Rectangle r, int rotation, boolean parity, int image) { GlStateManager.disableTexture2D(); } + /** + * Utility function to set clipping rectangle by projecting the coordinates using gluProject. + * @param r the clipping rectangle + */ protected void scissor (Rectangle r) { if (r==null) { GL11.glScissor(0,0,0,0); @@ -207,12 +211,19 @@ public void restore() { } } + /** + * Update the matrix buffers. + */ public void getMatrices() { GlStateManager.getFloat(GL11.GL_MODELVIEW_MATRIX,MODELVIEW); GlStateManager.getFloat(GL11.GL_PROJECTION_MATRIX,PROJECTION); GlStateManager.glGetInteger(GL11.GL_VIEWPORT,VIEWPORT); } + /** + * Set OpenGL to the state used by the rendering methods. + * Should be called before rendering. + */ public static void begin() { GlStateManager.enableBlend(); GlStateManager.disableTexture2D(); @@ -221,11 +232,24 @@ public static void begin() { GlStateManager.glLineWidth(2); } + /** + * Restore OpenGL to the state expected by Minecraft. + * Should be called after rendering. + */ public static void end() { GlStateManager.shadeModel(GL11.GL_FLAT); GlStateManager.enableTexture2D(); GlStateManager.disableBlend(); } + /** + * Get the z-coordinate to render everything. + * @return the z-level + */ protected abstract float getZLevel(); + /** + * Get the Minecraft resource location string. + * @return + */ + protected abstract String getResourcePrefix(); } diff --git a/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftGUI.java b/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftGUI.java index 1de0d19..f293cf1 100644 --- a/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftGUI.java +++ b/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftGUI.java @@ -7,12 +7,37 @@ import com.lukflug.panelstudio.ClickGUI; import com.lukflug.panelstudio.Interface; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; +/** + * Implementation of Minecraft's GuiScreen that renders a PanelStudio GUI. + * @author lukflug + */ public abstract class MinecraftGUI extends GuiScreen { + /** + * The current mouse position. + */ private Point mouse=new Point(); - private boolean lButton=false,rButton=false; + /** + * Current left mouse button state. + */ + private boolean lButton=false; + /** + * Current right mouse button state. + */ + private boolean rButton=false; + /** + * Displays the GUI. + */ + public void enterGUI() { + Minecraft.getMinecraft().displayGuiScreen(this); + } + + /** + * Updates the matrix buffers and renders the GUI. + */ protected void renderGUI() { getInterface().getMatrices(); GLInterface.begin(); @@ -20,6 +45,9 @@ protected void renderGUI() { GLInterface.end(); } + /** + * Draws the screen, updates the mouse position and handles scroll events. + */ @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { renderGUI(); @@ -31,6 +59,9 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) { } } + /** + * Updates {@link #lButton} and {@link #rButton}. + */ @Override public void mouseClicked(int mouseX, int mouseY, int clickedButton) { mouse=new Point(mouseX,mouseY); @@ -45,6 +76,9 @@ public void mouseClicked(int mouseX, int mouseY, int clickedButton) { getGUI().handleButton(clickedButton); } + /** + * Updates {@link #lButton} and {@link #rButton}. + */ @Override public void mouseReleased(int mouseX, int mouseY, int releaseButton) { mouse=new Point(mouseX,mouseY); @@ -59,23 +93,45 @@ public void mouseReleased(int mouseX, int mouseY, int releaseButton) { getGUI().handleButton(releaseButton); } + /** + * Handles the current keys being typed. + */ @Override protected void keyTyped(final char typedChar, final int keyCode) { if (keyCode == 1) { getGUI().exit(); - this.mc.displayGuiScreen(null); + Minecraft.getMinecraft().displayGuiScreen(null); } else getGUI().handleKey(keyCode); } + /** + * Returns false. + */ @Override public boolean doesGuiPauseGame() { return false; } + /** + * Get the {@link ClickGUI} to be rendered. + * @return current ClickGUI + */ protected abstract ClickGUI getGUI(); + /** + * Get current {@link GUIInterface}. + * @return the current interface + */ protected abstract GUIInterface getInterface(); + /** + * Get current scroll speed. + * @return the scroll speed + */ protected abstract int getScrollSpeed(); + /** + * Implementation of {@link GLInterface} to be used with {@link MinecraftGUI} + * @author lukflug + */ public abstract class GUIInterface extends GLInterface { @Override public boolean getButton(int button) { diff --git a/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftHUDGUI.java b/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftHUDGUI.java index 519d028..1e4727a 100644 --- a/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftHUDGUI.java +++ b/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftHUDGUI.java @@ -3,20 +3,42 @@ import com.lukflug.panelstudio.ClickGUI; import com.lukflug.panelstudio.hud.HUDClickGUI; +/** + * Class designed for GUIs with HUDs. + * @author lukflug + */ public abstract class MinecraftHUDGUI extends MinecraftGUI { + @Override + public void enterGUI() { + super.enterGUI(); + if (!getHUDGUI().isOn()) getHUDGUI().toggle(); + } + + /** + * Render function to be called when the GUI is closed to render the HUD. + */ public void render() { if (!getHUDGUI().isOn()) renderGUI(); } + /** + * Key event function to be called when the GUI is closed. + * @param scancode the key scancode + */ public void handleKeyEvent (int scancode) { if (scancode!=1 && !getHUDGUI().isOn()) getHUDGUI().handleKey(scancode); } @Override protected void keyTyped(final char typedChar, final int keyCode) { + super.keyTyped(typedChar,keyCode); if (keyCode==1 && getHUDGUI().isOn()) getHUDGUI().toggle(); } + /** + * Get the {@link HUDClickGUI} to be rendered. + * @return current ClickGUI + */ protected abstract HUDClickGUI getHUDGUI(); @Override From 1b3eb5191ce1587929282ada756f54b0e2f68b85 Mon Sep 17 00:00:00 2001 From: lukflug Date: Mon, 14 Dec 2020 18:57:21 +0100 Subject: [PATCH 04/12] Added concrete Animation and ColorScheme --- .../panelstudio/SettingsAnimation.java | 27 ++++++ .../theme/SettingsColorScheme.java | 86 +++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 src/main/java/com/lukflug/panelstudio/SettingsAnimation.java create mode 100644 src/main/java/com/lukflug/panelstudio/theme/SettingsColorScheme.java diff --git a/src/main/java/com/lukflug/panelstudio/SettingsAnimation.java b/src/main/java/com/lukflug/panelstudio/SettingsAnimation.java new file mode 100644 index 0000000..aa5a1b6 --- /dev/null +++ b/src/main/java/com/lukflug/panelstudio/SettingsAnimation.java @@ -0,0 +1,27 @@ +package com.lukflug.panelstudio; + +import com.lukflug.panelstudio.settings.NumberSetting; + +/** + * Implementation of {@link Animation} using {@link NumberSetting}. + * @author lukflug + */ +public class SettingsAnimation extends Animation { + /** + * Setting to be used for {@link #getSpeed()}. + */ + protected final NumberSetting speed; + + /** + * Constructor. + * @param speed speed setting + */ + public SettingsAnimation (NumberSetting speed) { + this.speed=speed; + } + + @Override + protected int getSpeed() { + return (int)speed.getNumber(); + } +} diff --git a/src/main/java/com/lukflug/panelstudio/theme/SettingsColorScheme.java b/src/main/java/com/lukflug/panelstudio/theme/SettingsColorScheme.java new file mode 100644 index 0000000..86440e8 --- /dev/null +++ b/src/main/java/com/lukflug/panelstudio/theme/SettingsColorScheme.java @@ -0,0 +1,86 @@ +package com.lukflug.panelstudio.theme; + +import java.awt.Color; + +import com.lukflug.panelstudio.settings.ColorSetting; +import com.lukflug.panelstudio.settings.NumberSetting; + +/** + * Implementation of {@link ColorScheme} using {@link ColorSetting} and {@link NumberSetting}. + * @author lukflug + */ +public class SettingsColorScheme implements ColorScheme { + /** + * Setting to be used for {@link #getActiveColor()}. + */ + protected final ColorSetting activeColor; + /** + * Setting to be used for {@link #getInactiveColor()}. + */ + protected final ColorSetting inactiveColor; + /** + * Setting to be used for {@link #getBackgroundColor()}. + */ + protected final ColorSetting backgroundColor; + /** + * Setting to be used for {@link #getOutlineColor()}. + */ + protected final ColorSetting outlineColor; + /** + * Setting to be used for {@link #getFontColor()}. + */ + protected final ColorSetting fontColor; + /** + * Setting to be used for {@link #getOpacity()}. + */ + protected final NumberSetting opacity; + + /** + * Constructor. + * @param activeColor active color setting + * @param inactiveColor inactive color setting + * @param backgroundColor background color setting + * @param outlineColor outline color setting + * @param fontColor font color setting + * @param opacity opacity setting + */ + public SettingsColorScheme (ColorSetting activeColor, ColorSetting inactiveColor, ColorSetting backgroundColor, ColorSetting outlineColor, ColorSetting fontColor, NumberSetting opacity) { + this.activeColor=activeColor; + this.inactiveColor=inactiveColor; + this.backgroundColor=backgroundColor; + this.outlineColor=outlineColor; + this.fontColor=fontColor; + this.opacity=opacity; + } + + @Override + public Color getActiveColor() { + return activeColor.getValue(); + } + + @Override + public Color getInactiveColor() { + return inactiveColor.getValue(); + } + + @Override + public Color getBackgroundColor() { + return backgroundColor.getValue(); + } + + @Override + public Color getOutlineColor() { + return outlineColor.getValue(); + } + + @Override + public Color getFontColor() { + return fontColor.getValue(); + } + + @Override + public int getOpacity() { + return (int)opacity.getNumber(); + } + +} From 7c7788601ee2631afe2f9026fcfaaee5361f68ed Mon Sep 17 00:00:00 2001 From: lukflug Date: Tue, 15 Dec 2020 19:47:48 +0100 Subject: [PATCH 05/12] Added configuration Interface --- .../com/lukflug/panelstudio/ClickGUI.java | 20 +++++++++++ .../com/lukflug/panelstudio/ConfigList.java | 21 ++++++++++++ .../panelstudio/DraggableContainer.java | 12 +++++++ .../lukflug/panelstudio/FixedComponent.java | 14 ++++++++ .../com/lukflug/panelstudio/PanelConfig.java | 33 +++++++++++++++++++ .../lukflug/panelstudio/hud/HUDClickGUI.java | 2 +- .../lukflug/panelstudio/hud/HUDComponent.java | 11 +++++++ .../com/lukflug/panelstudio/hud/HUDPanel.java | 13 ++++++++ .../lukflug/panelstudio/tabgui/TabGUI.java | 11 +++++++ 9 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/lukflug/panelstudio/ConfigList.java create mode 100644 src/main/java/com/lukflug/panelstudio/PanelConfig.java diff --git a/src/main/java/com/lukflug/panelstudio/ClickGUI.java b/src/main/java/com/lukflug/panelstudio/ClickGUI.java index bbd60d8..95f78a8 100644 --- a/src/main/java/com/lukflug/panelstudio/ClickGUI.java +++ b/src/main/java/com/lukflug/panelstudio/ClickGUI.java @@ -148,4 +148,24 @@ public void exit() { components.add(focusComponent); } } + + /** + * Store the GUI state. + * @param config the configuration list to be used + */ + public void saveConfig (ConfigList config) { + for (FixedComponent component: getComponents()) { + component.saveConfig(inter,config.addPanel(component.getTitle())); + } + } + + /** + * Load the GUI state. + * @param config the configuration list to be used + */ + public void loadConfig (ConfigList config) { + for (FixedComponent component: getComponents()) { + component.loadConfig(inter,config.getPanel(component.getTitle())); + } + } } diff --git a/src/main/java/com/lukflug/panelstudio/ConfigList.java b/src/main/java/com/lukflug/panelstudio/ConfigList.java new file mode 100644 index 0000000..fb8d054 --- /dev/null +++ b/src/main/java/com/lukflug/panelstudio/ConfigList.java @@ -0,0 +1,21 @@ +package com.lukflug.panelstudio; + +/** + * Object consisting of the configuration of all panels. + * @author lukflug + */ +public interface ConfigList { + /** + * Add panel to the configuration. + * @param title the title + * @return the new panel configuration to be populated by the panel + */ + public PanelConfig addPanel (String title); + + /** + * Get panel configuration. + * @param title the title + * @return the panel configuration corresponding to the respective panel + */ + public PanelConfig getPanel (String title); +} diff --git a/src/main/java/com/lukflug/panelstudio/DraggableContainer.java b/src/main/java/com/lukflug/panelstudio/DraggableContainer.java index 6d9ee2e..6161281 100644 --- a/src/main/java/com/lukflug/panelstudio/DraggableContainer.java +++ b/src/main/java/com/lukflug/panelstudio/DraggableContainer.java @@ -99,4 +99,16 @@ public int getWidth (Interface inter) { protected void handleFocus (Context context, boolean focus) { if (focus) context.requestFocus(); } + + @Override + public void saveConfig(Interface inter, PanelConfig config) { + config.savePositon(position); + config.saveState(open.isOn()); + } + + @Override + public void loadConfig(Interface inter, PanelConfig config) { + position=config.loadPosition(); + if (open.isOn()!=config.loadState()) open.toggle(); + } } diff --git a/src/main/java/com/lukflug/panelstudio/FixedComponent.java b/src/main/java/com/lukflug/panelstudio/FixedComponent.java index 5a7dac6..104d194 100644 --- a/src/main/java/com/lukflug/panelstudio/FixedComponent.java +++ b/src/main/java/com/lukflug/panelstudio/FixedComponent.java @@ -28,4 +28,18 @@ public interface FixedComponent extends Component { * @return component width */ public int getWidth (Interface inter); + + /** + * Saves the component state + * @param inter current interface + * @param config configuration to use + */ + public void saveConfig (Interface inter, PanelConfig config); + + /** + * Loads the component state + * @param inter current interface + * @param config configuration to use + */ + public void loadConfig (Interface inter, PanelConfig config); } diff --git a/src/main/java/com/lukflug/panelstudio/PanelConfig.java b/src/main/java/com/lukflug/panelstudio/PanelConfig.java new file mode 100644 index 0000000..eda537e --- /dev/null +++ b/src/main/java/com/lukflug/panelstudio/PanelConfig.java @@ -0,0 +1,33 @@ +package com.lukflug.panelstudio; + +import java.awt.Point; + +/** + * Interface representing a single panel configuration state. + * @author lukflug + */ +public interface PanelConfig { + /** + * Store the position of the panel. + * @param position the current position of the panel + */ + public void savePositon (Point position); + + /** + * Load the position of the point. + * @return the stored position + */ + public Point loadPosition(); + + /** + * Store the state of the panel. + * @param state whether the panel is open + */ + public void saveState (boolean state); + + /** + * Load the state of the panel. + * @return the stored panel state + */ + public boolean loadState(); +} diff --git a/src/main/java/com/lukflug/panelstudio/hud/HUDClickGUI.java b/src/main/java/com/lukflug/panelstudio/hud/HUDClickGUI.java index 7a61605..8d96534 100644 --- a/src/main/java/com/lukflug/panelstudio/hud/HUDClickGUI.java +++ b/src/main/java/com/lukflug/panelstudio/hud/HUDClickGUI.java @@ -24,7 +24,7 @@ public class HUDClickGUI extends ClickGUI implements Toggleable { */ protected Set hudComponents; /** - * + * Whether the GUI components are shown or not. */ protected boolean guiOpen=false; diff --git a/src/main/java/com/lukflug/panelstudio/hud/HUDComponent.java b/src/main/java/com/lukflug/panelstudio/hud/HUDComponent.java index 5ee1d05..98d0759 100644 --- a/src/main/java/com/lukflug/panelstudio/hud/HUDComponent.java +++ b/src/main/java/com/lukflug/panelstudio/hud/HUDComponent.java @@ -5,6 +5,7 @@ import com.lukflug.panelstudio.Context; import com.lukflug.panelstudio.FixedComponent; import com.lukflug.panelstudio.Interface; +import com.lukflug.panelstudio.PanelConfig; import com.lukflug.panelstudio.theme.Renderer; /** @@ -98,4 +99,14 @@ public Point getPosition(Interface inter) { public void setPosition(Interface inter, Point position) { this.position=position; } + + @Override + public void saveConfig(Interface inter, PanelConfig config) { + config.savePositon(position); + } + + @Override + public void loadConfig(Interface inter, PanelConfig config) { + position=config.loadPosition(); + } } diff --git a/src/main/java/com/lukflug/panelstudio/hud/HUDPanel.java b/src/main/java/com/lukflug/panelstudio/hud/HUDPanel.java index 4ae420a..710d027 100644 --- a/src/main/java/com/lukflug/panelstudio/hud/HUDPanel.java +++ b/src/main/java/com/lukflug/panelstudio/hud/HUDPanel.java @@ -9,6 +9,7 @@ import com.lukflug.panelstudio.DraggableContainer; import com.lukflug.panelstudio.FixedComponent; import com.lukflug.panelstudio.Interface; +import com.lukflug.panelstudio.PanelConfig; import com.lukflug.panelstudio.settings.Toggleable; import com.lukflug.panelstudio.theme.ColorScheme; import com.lukflug.panelstudio.theme.Renderer; @@ -94,6 +95,18 @@ protected Rectangle getClipRect (Context context, int height) { if (open.getValue()!=1) return super.getClipRect(context,height); else return null; } + + @Override + public void saveConfig(Interface inter, PanelConfig config) { + component.saveConfig(inter,config); + config.saveState(open.isOn()); + } + + @Override + public void loadConfig(Interface inter, PanelConfig config) { + component.loadConfig(inter,config); + if (open.isOn()!=config.loadState()) open.toggle(); + } /** diff --git a/src/main/java/com/lukflug/panelstudio/tabgui/TabGUI.java b/src/main/java/com/lukflug/panelstudio/tabgui/TabGUI.java index d7ce3bc..7c604e9 100644 --- a/src/main/java/com/lukflug/panelstudio/tabgui/TabGUI.java +++ b/src/main/java/com/lukflug/panelstudio/tabgui/TabGUI.java @@ -5,6 +5,7 @@ import com.lukflug.panelstudio.Animation; import com.lukflug.panelstudio.FixedComponent; import com.lukflug.panelstudio.Interface; +import com.lukflug.panelstudio.PanelConfig; /** * A {@link TabGUIContainer} that is also a {@link FixedComponent}. @@ -55,4 +56,14 @@ public void setPosition(Interface inter, Point position) { public int getWidth (Interface inter) { return width; } + + @Override + public void saveConfig(Interface inter, PanelConfig config) { + config.savePositon(position); + } + + @Override + public void loadConfig(Interface inter, PanelConfig config) { + position=config.loadPosition(); + } } From 004aeaeb610f005d229f82cf78babc6836953114 Mon Sep 17 00:00:00 2001 From: lukflug Date: Tue, 15 Dec 2020 20:17:57 +0100 Subject: [PATCH 06/12] Still need to finish config --- .../lukflug/panelstudio/mc/GLInterface.java | 30 +++++++++---------- .../lukflug/panelstudio/mc/MinecraftGUI.java | 8 ++--- .../com/lukflug/panelstudio/ClickGUI.java | 4 +++ .../com/lukflug/panelstudio/ConfigList.java | 12 ++++++++ 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/GLInterface.java b/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/GLInterface.java index e860b0a..450f847 100644 --- a/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/GLInterface.java +++ b/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/GLInterface.java @@ -38,29 +38,29 @@ public abstract class GLInterface implements Interface { /** * Buffer to store current projection matrix. */ - private static final FloatBuffer PROJECTION = GLAllocation.createDirectFloatBuffer(16); - /** - * Buffer to store current viewport. - */ + private static final FloatBuffer PROJECTION = GLAllocation.createDirectFloatBuffer(16); + /** + * Buffer to store current viewport. + */ private static final IntBuffer VIEWPORT = GLAllocation.createDirectIntBuffer(16); /** * Buffer used to calculate coordinates using gluProject. */ - private static final FloatBuffer COORDS = GLAllocation.createDirectFloatBuffer(3); - /** - * Clipping rectangle stack. - */ - private Stack clipRect=new Stack(); - + private static final FloatBuffer COORDS = GLAllocation.createDirectFloatBuffer(3); + /** + * Clipping rectangle stack. + */ + private Stack clipRect=new Stack(); + @Override public void fillTriangle(Point pos1, Point pos2, Point pos3, Color c1, Color c2, Color c3) { Tessellator tessellator = Tessellator.getInstance(); BufferBuilder bufferbuilder = tessellator.getBuffer(); - bufferbuilder.begin(GL11.GL_TRIANGLES,DefaultVertexFormats.POSITION_COLOR); - bufferbuilder.pos(pos1.x,pos1.y,getZLevel()).color(c1.getRed()/255.0f,c1.getGreen()/255.0f,c1.getBlue()/255.0f,c1.getAlpha()/255.0f).endVertex(); - bufferbuilder.pos(pos2.x,pos2.y,getZLevel()).color(c2.getRed()/255.0f,c2.getGreen()/255.0f,c2.getBlue()/255.0f,c2.getAlpha()/255.0f).endVertex(); - bufferbuilder.pos(pos3.x,pos3.y,getZLevel()).color(c3.getRed()/255.0f,c3.getGreen()/255.0f,c3.getBlue()/255.0f,c3.getAlpha()/255.0f).endVertex(); - tessellator.draw(); + bufferbuilder.begin(GL11.GL_TRIANGLES,DefaultVertexFormats.POSITION_COLOR); + bufferbuilder.pos(pos1.x,pos1.y,getZLevel()).color(c1.getRed()/255.0f,c1.getGreen()/255.0f,c1.getBlue()/255.0f,c1.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(pos2.x,pos2.y,getZLevel()).color(c2.getRed()/255.0f,c2.getGreen()/255.0f,c2.getBlue()/255.0f,c2.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(pos3.x,pos3.y,getZLevel()).color(c3.getRed()/255.0f,c3.getGreen()/255.0f,c3.getBlue()/255.0f,c3.getAlpha()/255.0f).endVertex(); + tessellator.draw(); } @Override diff --git a/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftGUI.java b/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftGUI.java index f293cf1..5d0b6f1 100644 --- a/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftGUI.java +++ b/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftGUI.java @@ -40,16 +40,16 @@ public void enterGUI() { */ protected void renderGUI() { getInterface().getMatrices(); - GLInterface.begin(); - getGUI().render(); - GLInterface.end(); + GLInterface.begin(); + getGUI().render(); + GLInterface.end(); } /** * Draws the screen, updates the mouse position and handles scroll events. */ @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks) { + public void drawScreen(int mouseX, int mouseY, float partialTicks) { renderGUI(); mouse=new Point(mouseX,mouseY); int scroll=Mouse.getDWheel(); diff --git a/src/main/java/com/lukflug/panelstudio/ClickGUI.java b/src/main/java/com/lukflug/panelstudio/ClickGUI.java index 95f78a8..cd7e891 100644 --- a/src/main/java/com/lukflug/panelstudio/ClickGUI.java +++ b/src/main/java/com/lukflug/panelstudio/ClickGUI.java @@ -154,9 +154,11 @@ public void exit() { * @param config the configuration list to be used */ public void saveConfig (ConfigList config) { + config.begin(false); for (FixedComponent component: getComponents()) { component.saveConfig(inter,config.addPanel(component.getTitle())); } + config.end(false); } /** @@ -164,8 +166,10 @@ public void saveConfig (ConfigList config) { * @param config the configuration list to be used */ public void loadConfig (ConfigList config) { + config.begin(true); for (FixedComponent component: getComponents()) { component.loadConfig(inter,config.getPanel(component.getTitle())); } + config.end(true); } } diff --git a/src/main/java/com/lukflug/panelstudio/ConfigList.java b/src/main/java/com/lukflug/panelstudio/ConfigList.java index fb8d054..65c6e80 100644 --- a/src/main/java/com/lukflug/panelstudio/ConfigList.java +++ b/src/main/java/com/lukflug/panelstudio/ConfigList.java @@ -5,6 +5,18 @@ * @author lukflug */ public interface ConfigList { + /** + * Begin loading/storing configuration. + * @param loading set if loading + */ + public void begin (boolean loading); + + /** + * End loading/storing configuration. + * @param loading set if loading + */ + public void end (boolean loading); + /** * Add panel to the configuration. * @param title the title From 31556c581ff7b192192bf4088998b156fcece4b8 Mon Sep 17 00:00:00 2001 From: lukflug Date: Wed, 16 Dec 2020 15:31:08 +0100 Subject: [PATCH 07/12] Finished config interfaces --- .../lukflug/panelstudio/mc/GLInterface.java | 62 ++++---- .../lukflug/panelstudio/mc/MinecraftGUI.java | 148 +++++++++--------- .../panelstudio/mc/MinecraftHUDGUI.java | 10 +- .../com/lukflug/panelstudio/ClickGUI.java | 6 +- .../panelstudio/DraggableContainer.java | 3 +- .../lukflug/panelstudio/hud/HUDComponent.java | 3 +- .../lukflug/panelstudio/tabgui/TabGUI.java | 3 +- 7 files changed, 120 insertions(+), 115 deletions(-) diff --git a/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/GLInterface.java b/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/GLInterface.java index 450f847..499d011 100644 --- a/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/GLInterface.java +++ b/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/GLInterface.java @@ -75,26 +75,26 @@ public void drawLine(Point a, Point b, Color c1, Color c2) { @Override public void fillRect(Rectangle r, Color c1, Color c2, Color c3, Color c4) { - Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder bufferbuilder = tessellator.getBuffer(); - bufferbuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR); - bufferbuilder.pos(r.x,r.y+r.height,getZLevel()).color(c4.getRed()/255.0f,c4.getGreen()/255.0f,c4.getBlue()/255.0f,c4.getAlpha()/255.0f).endVertex(); - bufferbuilder.pos(r.x+r.width,r.y+r.height,getZLevel()).color(c3.getRed()/255.0f,c3.getGreen()/255.0f,c3.getBlue()/255.0f,c3.getAlpha()/255.0f).endVertex(); - bufferbuilder.pos(r.x+r.width,r.y,getZLevel()).color(c2.getRed()/255.0f,c2.getGreen()/255.0f,c2.getBlue()/255.0f,c2.getAlpha()/255.0f).endVertex(); - bufferbuilder.pos(r.x,r.y,getZLevel()).color(c1.getRed()/255.0f,c1.getGreen()/255.0f,c1.getBlue()/255.0f,c1.getAlpha()/255.0f).endVertex(); - tessellator.draw(); + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder bufferbuilder = tessellator.getBuffer(); + bufferbuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR); + bufferbuilder.pos(r.x,r.y+r.height,getZLevel()).color(c4.getRed()/255.0f,c4.getGreen()/255.0f,c4.getBlue()/255.0f,c4.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(r.x+r.width,r.y+r.height,getZLevel()).color(c3.getRed()/255.0f,c3.getGreen()/255.0f,c3.getBlue()/255.0f,c3.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(r.x+r.width,r.y,getZLevel()).color(c2.getRed()/255.0f,c2.getGreen()/255.0f,c2.getBlue()/255.0f,c2.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(r.x,r.y,getZLevel()).color(c1.getRed()/255.0f,c1.getGreen()/255.0f,c1.getBlue()/255.0f,c1.getAlpha()/255.0f).endVertex(); + tessellator.draw(); } @Override public void drawRect(Rectangle r, Color c1, Color c2, Color c3, Color c4) { Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder bufferbuilder = tessellator.getBuffer(); - bufferbuilder.begin(GL11.GL_LINE_LOOP, DefaultVertexFormats.POSITION_COLOR); - bufferbuilder.pos(r.x,r.y+r.height,getZLevel()).color(c4.getRed()/255.0f,c4.getGreen()/255.0f,c4.getBlue()/255.0f,c4.getAlpha()/255.0f).endVertex(); - bufferbuilder.pos(r.x+r.width,r.y+r.height,getZLevel()).color(c3.getRed()/255.0f,c3.getGreen()/255.0f,c3.getBlue()/255.0f,c3.getAlpha()/255.0f).endVertex(); - bufferbuilder.pos(r.x+r.width,r.y,getZLevel()).color(c2.getRed()/255.0f,c2.getGreen()/255.0f,c2.getBlue()/255.0f,c2.getAlpha()/255.0f).endVertex(); - bufferbuilder.pos(r.x,r.y,getZLevel()).color(c1.getRed()/255.0f,c1.getGreen()/255.0f,c1.getBlue()/255.0f,c1.getAlpha()/255.0f).endVertex(); - tessellator.draw(); + BufferBuilder bufferbuilder = tessellator.getBuffer(); + bufferbuilder.begin(GL11.GL_LINE_LOOP, DefaultVertexFormats.POSITION_COLOR); + bufferbuilder.pos(r.x,r.y+r.height,getZLevel()).color(c4.getRed()/255.0f,c4.getGreen()/255.0f,c4.getBlue()/255.0f,c4.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(r.x+r.width,r.y+r.height,getZLevel()).color(c3.getRed()/255.0f,c3.getGreen()/255.0f,c3.getBlue()/255.0f,c3.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(r.x+r.width,r.y,getZLevel()).color(c2.getRed()/255.0f,c2.getGreen()/255.0f,c2.getBlue()/255.0f,c2.getAlpha()/255.0f).endVertex(); + bufferbuilder.pos(r.x,r.y,getZLevel()).color(c1.getRed()/255.0f,c1.getGreen()/255.0f,c1.getBlue()/255.0f,c1.getAlpha()/255.0f).endVertex(); + tessellator.draw(); } @Override @@ -141,16 +141,16 @@ public void drawImage(Rectangle r, int rotation, boolean parity, int image) { texCoords[1][1]=temp2; } Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder bufferbuilder = tessellator.getBuffer(); - GlStateManager.bindTexture(image); - GlStateManager.enableTexture2D(); - bufferbuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); - bufferbuilder.pos(r.x,r.y+r.height,getZLevel()).tex(texCoords[0][0],texCoords[0][1]).endVertex(); - bufferbuilder.pos(r.x+r.width,r.y+r.height,getZLevel()).tex(texCoords[1][0],texCoords[1][1]).endVertex(); - bufferbuilder.pos(r.x+r.width,r.y,getZLevel()).tex(texCoords[2][0],texCoords[2][1]).endVertex(); - bufferbuilder.pos(r.x,r.y,getZLevel()).tex(texCoords[3][0],texCoords[3][1]).endVertex(); - tessellator.draw(); - GlStateManager.disableTexture2D(); + BufferBuilder bufferbuilder = tessellator.getBuffer(); + GlStateManager.bindTexture(image); + GlStateManager.enableTexture2D(); + bufferbuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); + bufferbuilder.pos(r.x,r.y+r.height,getZLevel()).tex(texCoords[0][0],texCoords[0][1]).endVertex(); + bufferbuilder.pos(r.x+r.width,r.y+r.height,getZLevel()).tex(texCoords[1][0],texCoords[1][1]).endVertex(); + bufferbuilder.pos(r.x+r.width,r.y,getZLevel()).tex(texCoords[2][0],texCoords[2][1]).endVertex(); + bufferbuilder.pos(r.x,r.y,getZLevel()).tex(texCoords[3][0],texCoords[3][1]).endVertex(); + tessellator.draw(); + GlStateManager.disableTexture2D(); } /** @@ -226,10 +226,10 @@ public void getMatrices() { */ public static void begin() { GlStateManager.enableBlend(); - GlStateManager.disableTexture2D(); - GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); - GlStateManager.shadeModel(GL11.GL_SMOOTH); - GlStateManager.glLineWidth(2); + GlStateManager.disableTexture2D(); + GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); + GlStateManager.shadeModel(GL11.GL_SMOOTH); + GlStateManager.glLineWidth(2); } /** @@ -238,8 +238,8 @@ public static void begin() { */ public static void end() { GlStateManager.shadeModel(GL11.GL_FLAT); - GlStateManager.enableTexture2D(); - GlStateManager.disableBlend(); + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); } /** diff --git a/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftGUI.java b/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftGUI.java index 5d0b6f1..d4cb363 100644 --- a/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftGUI.java +++ b/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftGUI.java @@ -51,87 +51,87 @@ protected void renderGUI() { @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { renderGUI(); - mouse=new Point(mouseX,mouseY); - int scroll=Mouse.getDWheel(); - if (scroll!=0) { - if (scroll>0) getGUI().handleScroll(-getScrollSpeed()); - else getGUI().handleScroll(getScrollSpeed()); - } - } + mouse=new Point(mouseX,mouseY); + int scroll=Mouse.getDWheel(); + if (scroll!=0) { + if (scroll>0) getGUI().handleScroll(-getScrollSpeed()); + else getGUI().handleScroll(getScrollSpeed()); + } + } /** * Updates {@link #lButton} and {@link #rButton}. */ - @Override - public void mouseClicked(int mouseX, int mouseY, int clickedButton) { - mouse=new Point(mouseX,mouseY); - switch (clickedButton) { - case Interface.LBUTTON: - lButton=true; - break; - case Interface.RBUTTON: - rButton=true; - break; - } - getGUI().handleButton(clickedButton); - } + @Override + public void mouseClicked(int mouseX, int mouseY, int clickedButton) { + mouse=new Point(mouseX,mouseY); + switch (clickedButton) { + case Interface.LBUTTON: + lButton=true; + break; + case Interface.RBUTTON: + rButton=true; + break; + } + getGUI().handleButton(clickedButton); + } - /** - * Updates {@link #lButton} and {@link #rButton}. - */ - @Override - public void mouseReleased(int mouseX, int mouseY, int releaseButton) { - mouse=new Point(mouseX,mouseY); - switch (releaseButton) { - case Interface.LBUTTON: - lButton=false; - break; - case Interface.RBUTTON: - rButton=false; - break; - } - getGUI().handleButton(releaseButton); - } - - /** - * Handles the current keys being typed. - */ - @Override - protected void keyTyped(final char typedChar, final int keyCode) { - if (keyCode == 1) { - getGUI().exit(); - Minecraft.getMinecraft().displayGuiScreen(null); - } else getGUI().handleKey(keyCode); - } + /** + * Updates {@link #lButton} and {@link #rButton}. + */ + @Override + public void mouseReleased(int mouseX, int mouseY, int releaseButton) { + mouse=new Point(mouseX,mouseY); + switch (releaseButton) { + case Interface.LBUTTON: + lButton=false; + break; + case Interface.RBUTTON: + rButton=false; + break; + } + getGUI().handleButton(releaseButton); + } + + /** + * Handles the current keys being typed. + */ + @Override + protected void keyTyped(final char typedChar, final int keyCode) { + if (keyCode == 1) { + getGUI().exit(); + Minecraft.getMinecraft().displayGuiScreen(null); + } else getGUI().handleKey(keyCode); + } - /** - * Returns false. - */ - @Override - public boolean doesGuiPauseGame() { - return false; - } - - /** - * Get the {@link ClickGUI} to be rendered. - * @return current ClickGUI - */ - protected abstract ClickGUI getGUI(); - /** - * Get current {@link GUIInterface}. - * @return the current interface - */ - protected abstract GUIInterface getInterface(); - /** - * Get current scroll speed. - * @return the scroll speed - */ - protected abstract int getScrollSpeed(); + /** + * Returns false. + */ + @Override + public boolean doesGuiPauseGame() { + return false; + } + + /** + * Get the {@link ClickGUI} to be rendered. + * @return current ClickGUI + */ + protected abstract ClickGUI getGUI(); + /** + * Get current {@link GUIInterface}. + * @return the current interface + */ + protected abstract GUIInterface getInterface(); + /** + * Get current scroll speed. + * @return the scroll speed + */ + protected abstract int getScrollSpeed(); - /** - * Implementation of {@link GLInterface} to be used with {@link MinecraftGUI} - * @author lukflug - */ + /** + * Implementation of {@link GLInterface} to be used with {@link MinecraftGUI} + * @author lukflug + */ public abstract class GUIInterface extends GLInterface { @Override public boolean getButton(int button) { diff --git a/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftHUDGUI.java b/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftHUDGUI.java index 1e4727a..275254c 100644 --- a/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftHUDGUI.java +++ b/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftHUDGUI.java @@ -26,8 +26,8 @@ public void render() { * @param scancode the key scancode */ public void handleKeyEvent (int scancode) { - if (scancode!=1 && !getHUDGUI().isOn()) getHUDGUI().handleKey(scancode); - } + if (scancode!=1 && !getHUDGUI().isOn()) getHUDGUI().handleKey(scancode); + } @Override protected void keyTyped(final char typedChar, final int keyCode) { @@ -36,9 +36,9 @@ protected void keyTyped(final char typedChar, final int keyCode) { } /** - * Get the {@link HUDClickGUI} to be rendered. - * @return current ClickGUI - */ + * Get the {@link HUDClickGUI} to be rendered. + * @return current ClickGUI + */ protected abstract HUDClickGUI getHUDGUI(); @Override diff --git a/src/main/java/com/lukflug/panelstudio/ClickGUI.java b/src/main/java/com/lukflug/panelstudio/ClickGUI.java index cd7e891..a9d89ea 100644 --- a/src/main/java/com/lukflug/panelstudio/ClickGUI.java +++ b/src/main/java/com/lukflug/panelstudio/ClickGUI.java @@ -156,7 +156,8 @@ public void exit() { public void saveConfig (ConfigList config) { config.begin(false); for (FixedComponent component: getComponents()) { - component.saveConfig(inter,config.addPanel(component.getTitle())); + PanelConfig cf=config.getPanel(component.getTitle()); + if (cf!=null) component.saveConfig(inter,cf); } config.end(false); } @@ -168,7 +169,8 @@ public void saveConfig (ConfigList config) { public void loadConfig (ConfigList config) { config.begin(true); for (FixedComponent component: getComponents()) { - component.loadConfig(inter,config.getPanel(component.getTitle())); + PanelConfig cf=config.getPanel(component.getTitle()); + if (cf!=null) component.loadConfig(inter,cf); } config.end(true); } diff --git a/src/main/java/com/lukflug/panelstudio/DraggableContainer.java b/src/main/java/com/lukflug/panelstudio/DraggableContainer.java index 6161281..888d44b 100644 --- a/src/main/java/com/lukflug/panelstudio/DraggableContainer.java +++ b/src/main/java/com/lukflug/panelstudio/DraggableContainer.java @@ -108,7 +108,8 @@ public void saveConfig(Interface inter, PanelConfig config) { @Override public void loadConfig(Interface inter, PanelConfig config) { - position=config.loadPosition(); + Point pos=config.loadPosition(); + if (pos!=null) position=pos; if (open.isOn()!=config.loadState()) open.toggle(); } } diff --git a/src/main/java/com/lukflug/panelstudio/hud/HUDComponent.java b/src/main/java/com/lukflug/panelstudio/hud/HUDComponent.java index 98d0759..0f9a1c0 100644 --- a/src/main/java/com/lukflug/panelstudio/hud/HUDComponent.java +++ b/src/main/java/com/lukflug/panelstudio/hud/HUDComponent.java @@ -107,6 +107,7 @@ public void saveConfig(Interface inter, PanelConfig config) { @Override public void loadConfig(Interface inter, PanelConfig config) { - position=config.loadPosition(); + Point pos=config.loadPosition(); + if (pos!=null) position=pos; } } diff --git a/src/main/java/com/lukflug/panelstudio/tabgui/TabGUI.java b/src/main/java/com/lukflug/panelstudio/tabgui/TabGUI.java index 7c604e9..aa9d1bd 100644 --- a/src/main/java/com/lukflug/panelstudio/tabgui/TabGUI.java +++ b/src/main/java/com/lukflug/panelstudio/tabgui/TabGUI.java @@ -64,6 +64,7 @@ public void saveConfig(Interface inter, PanelConfig config) { @Override public void loadConfig(Interface inter, PanelConfig config) { - position=config.loadPosition(); + Point pos=config.loadPosition(); + if (pos!=null) position=pos; } } From 2eda3b37e69555177669dc3475084194c3392d53 Mon Sep 17 00:00:00 2001 From: lukflug Date: Wed, 16 Dec 2020 15:51:18 +0100 Subject: [PATCH 08/12] Fixed config bug --- src/main/java/com/lukflug/panelstudio/ClickGUI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/lukflug/panelstudio/ClickGUI.java b/src/main/java/com/lukflug/panelstudio/ClickGUI.java index a9d89ea..6a33c78 100644 --- a/src/main/java/com/lukflug/panelstudio/ClickGUI.java +++ b/src/main/java/com/lukflug/panelstudio/ClickGUI.java @@ -156,7 +156,7 @@ public void exit() { public void saveConfig (ConfigList config) { config.begin(false); for (FixedComponent component: getComponents()) { - PanelConfig cf=config.getPanel(component.getTitle()); + PanelConfig cf=config.addPanel(component.getTitle()); if (cf!=null) component.saveConfig(inter,cf); } config.end(false); From 00fee96bd74bba336037af1cad1816b2e8262cd9 Mon Sep 17 00:00:00 2001 From: lukflug Date: Wed, 16 Dec 2020 16:12:23 +0100 Subject: [PATCH 09/12] Added HUD lists --- .../com/lukflug/panelstudio/hud/HUDList.java | 37 ++++++++ .../panelstudio/hud/ListComponent.java | 93 +++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 src/main/java/com/lukflug/panelstudio/hud/HUDList.java create mode 100644 src/main/java/com/lukflug/panelstudio/hud/ListComponent.java diff --git a/src/main/java/com/lukflug/panelstudio/hud/HUDList.java b/src/main/java/com/lukflug/panelstudio/hud/HUDList.java new file mode 100644 index 0000000..15e85c2 --- /dev/null +++ b/src/main/java/com/lukflug/panelstudio/hud/HUDList.java @@ -0,0 +1,37 @@ +package com.lukflug.panelstudio.hud; + +import java.awt.Color; + +/** + * Interface representing a list for {@link ListComponent} + * @author lukas_ghdqwsr + */ +public interface HUDList { + /** + * Get the number of elements in the list + * @return list size + */ + public int getSize(); + /** + * Get the item at the given index. + * @param index index of item + * @return the item corresponding to the index + */ + public String getItem (int index); + /** + * Get the color the string should have. + * @param index index of item + * @return the color of the item + */ + public Color getItemColor (int index); + /** + * Whether to align the list downwards. + * @return align down + */ + public boolean sortUp(); + /** + * Whether to align the list to the right. + * @return align right + */ + public boolean sortRight(); +} diff --git a/src/main/java/com/lukflug/panelstudio/hud/ListComponent.java b/src/main/java/com/lukflug/panelstudio/hud/ListComponent.java new file mode 100644 index 0000000..38a9738 --- /dev/null +++ b/src/main/java/com/lukflug/panelstudio/hud/ListComponent.java @@ -0,0 +1,93 @@ +package com.lukflug.panelstudio.hud; + +import java.awt.Point; + +import com.lukflug.panelstudio.Context; +import com.lukflug.panelstudio.Interface; +import com.lukflug.panelstudio.PanelConfig; +import com.lukflug.panelstudio.theme.Renderer; + +/** + * HUD component that consists of a list of strings. + * @author lukflug + */ +public class ListComponent extends HUDComponent { + /** + * The list to be rendered. + */ + protected HUDList list; + /** + * Flag saving the state of whether to sort up. + */ + protected boolean lastUp=false; + + /** + * Constructor. + * @param name the title of the component + * @param theme the theme for the component + * @param position the initial position + * @param list the list to be rendered + */ + public ListComponent (String name, Renderer renderer, Point position, HUDList list) { + super(name,renderer,position); + this.list=list; + } + + @Override + public void render (Context context) { + super.render(context); + for (int i=0;i Date: Wed, 16 Dec 2020 22:31:58 +0100 Subject: [PATCH 10/12] Wrapping up build config and readme, still need to finish readme --- README.md | 102 ++++++++++++------ build.gradle | 11 +- panelstudio-mc/build.gradle | 4 - pom.xml | 8 -- .../panelstudio/hud/ListComponent.java | 2 +- 5 files changed, 74 insertions(+), 53 deletions(-) delete mode 100644 pom.xml diff --git a/README.md b/README.md index ed7fec0..faa9cc0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # PanelStudio -A simple yet flexible library to create ClickGUIs designed for use in Minecraft utility mods. It was originally designed for a private client, but made open source, so that it could be used for [GameSense](https://github.com/IUDevman/gamesense-client). Here are some screenshots of what is possible with this library: +A simple yet flexible library to create ClickGUIs designed for use in Minecraft utility mods. It was originally designed for a private client, but made open source, so that it could be used for [GameSense](https://github.com/IUDevman/gamesense-client). Here are some screenshots of what is possible with this library (note that these themes are examples and that one can make the GUI look like basically anything): * CyberHack Theme: ![cyberhack](https://cdn.discordapp.com/attachments/747111616407011389/779996603510947870/2020-11-21_20.23.26.png) * GameSense 2.0 Theme: @@ -22,6 +22,7 @@ This library contains following packages: * `com.lukflug.panelstudio.theme`: contains base classes for themes and GameSense themes. * `com.lukflug.panelstudio.tabgui`: TabGUI. * `com.lukflug.panelstudio.hud`: HUD panels. +In addition to the core PanelStudio library, there is the PanelStudio-MC library (`com.lukflug.panelstudio.mc` package), which is a source code library that includes Minecraft depedencies. It was tested on Minecraft Forge 1.12.2, but probably works on Fabric and may or may not work on other Minecraft versions. The PanelStudio core library works on any Minecraft version (and even on any non-Minecraft application). ## Features * Ability to easily create new themes/skins. @@ -32,21 +33,7 @@ This library contains following packages: ## Implementation in Minecraft clients A jar of this library is available in the Maven repository at https://lukflug.github.io/maven/ as `com.lukflug.panelstudio`. -### ClickGUI -To use the ClickGUI, following interfaces need to be implemented -* `Interface` -* `ColorScheme` -In addition: -* Use one of the supplied Themes or implement one yourself, to have a different look from GameSense (see `ClearTheme` and `GameSenseTheme` for reference). -* Populate the `ClickGUI` object with the desired components (i.e. adding a `DraggableContainer` for each category, adding a `CollapsibleContainer` for each module, and adding a settings component for each setting, this probably requires marking your settings objects with the interfaces in the `settings` package). -* It is recommended to have a class extending Minecraft's `GuiScreen` and implementing `Interface`, that has `ClickGUI` as a field, which gets populates in the constructor. -* For reference, consult the [javadoc](https://lukflug.github.io/javadoc/panelstudio/0.1.0/) and see the implementation in GameSense. -* Some custom classes may need to be created, for specific behaviour. - -### HUD -Use `HUDClickGUI` instead of `ClickGUI`. Requries calling rendering functions even when the ClickGUI is closed, in order to render the HUD panels. HUD componets have to be `FixedComponent` (use `HUDComponent` as base class) and have to be added to the `HUDClickGUI` via a `HUDPanel`. This will make the HUD component a draggable panel when the ClickGUI is open. PanelStuudio provides `TabGUI` as a stock HUD component. The `TabGUI` requires passing key events when the ClickGUI is closed and has to be populated with categories and modules. - -## Use in Gradle +### Use in Gradle Add following to your `build.gradle`: ``` repositories { @@ -57,7 +44,7 @@ repositories { } dependencies { - compile("com.lukflug:panelstudio:0.1.0") + compile("com.lukflug:panelstudio:0.1.1") } shadowJar { @@ -66,30 +53,79 @@ shadowJar { } } ``` - -## Use as Gradle source dependency -To include the newest version in this repository in your gradle build, you have to add following to your `settings.gradle`: +If you're planning to use PanelStudio-MC you have to also add this: ``` -sourceControl { - gitRepository("https://github.com/lukflug/PanelStudio.git") { - producesModule("com.lukflug:panelstudio") +sourceSets { + main { + java { + srcDir 'src/main/java' + srcDir 'build/panelstudio' + } } } + +task downloadPanelstudio { + new URL("https://github.com/lukflug/PanelStudio/releases/download/v0.1.1/panelstudio-mc-0.1.1.jar").withInputStream{i->new File("${buildDir}/panelstudio-mc-0.1.1.jar").withOutputStream{it< - 4.0.0 - com.lukflug - panelstudio - 0.1.0 - PanelStudio - A simple yet flexible library to create ClickGUIs designed for use in Minecraft utility mods. - diff --git a/src/main/java/com/lukflug/panelstudio/hud/ListComponent.java b/src/main/java/com/lukflug/panelstudio/hud/ListComponent.java index 38a9738..c23a033 100644 --- a/src/main/java/com/lukflug/panelstudio/hud/ListComponent.java +++ b/src/main/java/com/lukflug/panelstudio/hud/ListComponent.java @@ -24,7 +24,7 @@ public class ListComponent extends HUDComponent { /** * Constructor. * @param name the title of the component - * @param theme the theme for the component + * @param renderer the renderer for the component * @param position the initial position * @param list the list to be rendered */ From bebb33b31a6f7e6200954d2aeb6718a915d09ab9 Mon Sep 17 00:00:00 2001 From: lukflug Date: Thu, 17 Dec 2020 12:49:23 +0100 Subject: [PATCH 11/12] Rewrote readme --- README.md | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index faa9cc0..ddf765a 100644 --- a/README.md +++ b/README.md @@ -85,11 +85,32 @@ public class CoolGUI extends MinecraftGUI { private final ClickGUI gui; public CoolGUI() { + // Intialize necessary fields colorToggle=CoolSettings.colorModel // <-- Toggleable indicating whether to use the RGB or HSB model for color settings - theme=new GameSenseTheme(new SettingsColorScheme(CoolSettings.activeColor,CoolSettings.inactiveColor,CoolSettings.backgroundColor,CoolSettings.outlineColor,CoolSettings.fontColor,CoolSettings.opacity),height,2); // <-- Can be replaced by another theme (could be a custom one) guiInterface=new GuiInterface() { - // TODO: implement methods + @Override + protected String getResourcePrefix() { + return "coolhack:gui/"; + } + + @Override + public void drawString(Point pos, String s, Color c) { + end(); + CoolFont.drawString(s,pos.x,pos.y,c); + begin(); + } + + @Override + public int getFontWidth(String s) { + return CoolFont.getFontWidth(s); + } + + @Override + public int getFontHeight() { + return CoolFont.getFontHeight(); + } }; + theme=new GameSenseTheme(new SettingsColorScheme(CoolSettings.activeColor,CoolSettings.inactiveColor,CoolSettings.backgroundColor,CoolSettings.outlineColor,CoolSettings.fontColor,CoolSettings.opacity),height,2); // <-- Can be replaced by another theme (could be a custom one) gui=new ClickGUI(guiInterface); // Populate the ClickGUI with modules and settings for (CoolCategory category: categories) { @@ -106,7 +127,6 @@ public class CoolGUI extends MinecraftGUI { } } } - CoolSettings.loadGUISettings(); } @Override @@ -125,7 +145,38 @@ public class CoolGUI extends MinecraftGUI { } } ``` -TODO: Add explanation of Cool-- classes and settings +The loops and methods involving `CoolCategory`, `CoolModule` and `CoolSetting` have to be replaced with the appropriate components of your module and settings manager. The fields in `CoolSettings` have to be replaced by appropriate settings object implementing the required PanelStudio interfaces. The methods in `CoolFont` have to be replaced by methods in your font manager. + +In addition, if you want to save the GUI panel positions, the `gui.loadConfig` should be called after initializing the ClickGUI and `gui.saveConfig` should be called before closing the game. The `ConfigList` interface will need to be implemented. + +To allow the user to open the GUI, a ClickGUI module can be created, which calls the `enterGUI` method when called. ### HUD -Use `HUDClickGUI` instead of `ClickGUI`. Requries calling rendering functions even when the ClickGUI is closed, in order to render the HUD panels. HUD components have to be `FixedComponent` (use `HUDComponent` as base class) and have to be added to the `HUDClickGUI` via a `HUDPanel`. This will make the HUD component a draggable panel when the ClickGUI is open. PanelStudio provides `TabGUI` as a stock HUD component. The `TabGUI` requires passing key events when the ClickGUI is closed and has to be populated with categories and modules. +Use `MinecraftHUDGUI` instead of `MinecraftGUI` and `HUDClickGUI` instead of `ClickGUI` (override `getHUDGUI` instead of `getGUI`). Requries calling `render` and `handleKeyEvent` (provided HUD components have to react to keystrokes) when the ClickGUI is closed. HUD components have to be `FixedComponent` (use `HUDComponent` as base class) and have to be added to `HUDClickGUI` via a `HUDPanel`. This will make the HUD component a draggable panel when the ClickGUI is open. PanelStudio provides `TabGUI` as a stock HUD component. + +It is recommended to have hud modules with a function that intitializes and returns a `FixedComponent` which is added in the constructor of the ClickGUI, just before populating the settings panels: +``` +for (HUDModule hudModule: hudModules) { + gui.addHUDComponent(new HUDPanel(hudModule.getComponent(),theme.getPanelRenderer(),module,new SettingsAnimation(CoolSettings.animationSpeed),hudToggle,border)); + +} +``` +The `hudToggle` toggleable can be the `gui` (instance of `HUDClickGUI`) or, if you want to disable showing the HUD panel frames when the GUI is open you can have something like this: +``` +Toggleable hudToggle=new Toggleable() { + @Override + public void toggle() { + } + + @Override + public boolean isOn() { + return gui.isOn() && CoolSettings.showHUDPanels.isOn(); + } +} +``` + +## Reference +For a list of classes and methods, consult the [javadoc](https://lukflug.github.io/javadoc/panelstudio/0.1.0/). For an example implementation, consult the GameSense source code. + +## Creating custom themes +The components provided by PanelStudio use the methods in the `Renderer` interface to render. A `Theme` consist of three renderers: one for the single components (settings), one for the containers (modules) and one for the panels (categories). To see how themes are implemented, consult the package `com.lukflug.panelstudio.theme`. From c6a3aeda13db03190f66601cf26e9c11a8037e0f Mon Sep 17 00:00:00 2001 From: lukflug Date: Thu, 17 Dec 2020 13:03:02 +0100 Subject: [PATCH 12/12] Readme corrections --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ddf765a..e4b6c7c 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ This library contains following packages: * `com.lukflug.panelstudio.theme`: contains base classes for themes and GameSense themes. * `com.lukflug.panelstudio.tabgui`: TabGUI. * `com.lukflug.panelstudio.hud`: HUD panels. + In addition to the core PanelStudio library, there is the PanelStudio-MC library (`com.lukflug.panelstudio.mc` package), which is a source code library that includes Minecraft depedencies. It was tested on Minecraft Forge 1.12.2, but probably works on Fabric and may or may not work on other Minecraft versions. The PanelStudio core library works on any Minecraft version (and even on any non-Minecraft application). ## Features @@ -149,7 +150,7 @@ The loops and methods involving `CoolCategory`, `CoolModule` and `CoolSetting` h In addition, if you want to save the GUI panel positions, the `gui.loadConfig` should be called after initializing the ClickGUI and `gui.saveConfig` should be called before closing the game. The `ConfigList` interface will need to be implemented. -To allow the user to open the GUI, a ClickGUI module can be created, which calls the `enterGUI` method when called. +To allow the user to open the GUI, a ClickGUI module can be created, which calls the `enterGUI` method when enabled. ### HUD Use `MinecraftHUDGUI` instead of `MinecraftGUI` and `HUDClickGUI` instead of `ClickGUI` (override `getHUDGUI` instead of `getGUI`). Requries calling `render` and `handleKeyEvent` (provided HUD components have to react to keystrokes) when the ClickGUI is closed. HUD components have to be `FixedComponent` (use `HUDComponent` as base class) and have to be added to `HUDClickGUI` via a `HUDPanel`. This will make the HUD component a draggable panel when the ClickGUI is open. PanelStudio provides `TabGUI` as a stock HUD component. @@ -176,7 +177,7 @@ Toggleable hudToggle=new Toggleable() { ``` ## Reference -For a list of classes and methods, consult the [javadoc](https://lukflug.github.io/javadoc/panelstudio/0.1.0/). For an example implementation, consult the GameSense source code. +For a list of classes and methods, consult the [javadoc](https://lukflug.github.io/javadoc/panelstudio/0.1.1/). For an example implementation, consult the GameSense source code. ## Creating custom themes The components provided by PanelStudio use the methods in the `Renderer` interface to render. A `Theme` consist of three renderers: one for the single components (settings), one for the containers (modules) and one for the panels (categories). To see how themes are implemented, consult the package `com.lukflug.panelstudio.theme`.