diff --git a/README.md b/README.md index ed7fec0..e4b6c7c 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: @@ -23,6 +23,8 @@ This library contains following packages: * `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. * Overlapping Panels. @@ -32,21 +34,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 +45,7 @@ repositories { } dependencies { - compile("com.lukflug:panelstudio:0.1.0") + compile("com.lukflug:panelstudio:0.1.1") } shadowJar { @@ -66,30 +54,130 @@ 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< 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(); + } + + @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,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(); + } + + @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(); + } + + @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(); + } + + @Override + public synchronized int loadImage(String name) { + try { + ResourceLocation rl=new ResourceLocation(getResourcePrefix()+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()); + } + } + + /** + * 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(); + 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); + } + + /** + * 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 new file mode 100644 index 0000000..d4cb363 --- /dev/null +++ b/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftGUI.java @@ -0,0 +1,157 @@ +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.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(); + /** + * 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(); + 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) { + renderGUI(); + 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); + } + + /** + * 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(); + + /** + * Implementation of {@link GLInterface} to be used with {@link MinecraftGUI} + * @author lukflug + */ + 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..275254c --- /dev/null +++ b/panelstudio-mc/src/main/java/com/lukflug/panelstudio/mc/MinecraftHUDGUI.java @@ -0,0 +1,48 @@ +package com.lukflug.panelstudio.mc; + +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 + protected ClickGUI getGUI() { + return getHUDGUI(); + } +} diff --git a/pom.xml b/pom.xml deleted file mode 100644 index d4e698f..0000000 --- a/pom.xml +++ /dev/null @@ -1,8 +0,0 @@ - - 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/settings.gradle b/settings.gradle index f54f6d2..4cf003d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1,3 @@ + rootProject.name='panelstudio' +include 'panelstudio-mc' diff --git a/src/main/java/com/lukflug/panelstudio/ClickGUI.java b/src/main/java/com/lukflug/panelstudio/ClickGUI.java index bbd60d8..6a33c78 100644 --- a/src/main/java/com/lukflug/panelstudio/ClickGUI.java +++ b/src/main/java/com/lukflug/panelstudio/ClickGUI.java @@ -148,4 +148,30 @@ public void exit() { components.add(focusComponent); } } + + /** + * Store the GUI state. + * @param config the configuration list to be used + */ + public void saveConfig (ConfigList config) { + config.begin(false); + for (FixedComponent component: getComponents()) { + PanelConfig cf=config.addPanel(component.getTitle()); + if (cf!=null) component.saveConfig(inter,cf); + } + config.end(false); + } + + /** + * Load the GUI state. + * @param config the configuration list to be used + */ + public void loadConfig (ConfigList config) { + config.begin(true); + for (FixedComponent component: getComponents()) { + 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/ConfigList.java b/src/main/java/com/lukflug/panelstudio/ConfigList.java new file mode 100644 index 0000000..65c6e80 --- /dev/null +++ b/src/main/java/com/lukflug/panelstudio/ConfigList.java @@ -0,0 +1,33 @@ +package com.lukflug.panelstudio; + +/** + * Object consisting of the configuration of all panels. + * @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 + * @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..888d44b 100644 --- a/src/main/java/com/lukflug/panelstudio/DraggableContainer.java +++ b/src/main/java/com/lukflug/panelstudio/DraggableContainer.java @@ -99,4 +99,17 @@ 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) { + 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/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/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/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..0f9a1c0 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,15 @@ 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) { + Point pos=config.loadPosition(); + if (pos!=null) position=pos; + } } 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/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/hud/ListComponent.java b/src/main/java/com/lukflug/panelstudio/hud/ListComponent.java new file mode 100644 index 0000000..c23a033 --- /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 renderer the renderer 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