Skip to content

Commit

Permalink
Merge pull request #1 from lukflug/dev
Browse files Browse the repository at this point in the history
Version 0.1.0
  • Loading branch information
lukflug authored Nov 22, 2020
2 parents 80245c0 + 0be2c52 commit 5a31cd4
Show file tree
Hide file tree
Showing 26 changed files with 1,415 additions and 80 deletions.
38 changes: 25 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
# 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:
* CyberHack Theme:
![cyberhack](https://cdn.discordapp.com/attachments/755077474861449277/770697901499744286/2020-10-27_18.16.50.png)
![cyberhack](https://cdn.discordapp.com/attachments/747111616407011389/779996603510947870/2020-11-21_20.23.26.png)
* GameSense 2.0 Theme:
![gamesense20](https://cdn.discordapp.com/attachments/755077474861449277/770697937234821170/2020-10-27_18.16.59.png)
![gamesense20](https://cdn.discordapp.com/attachments/747111616407011389/779996468730920960/2020-11-21_20.13.36.png)
* GameSense 2.1 Theme:
![gamesense21](https://cdn.discordapp.com/attachments/755077474861449277/770697959947239424/2020-10-27_18.17.12.png)
![gamesense21](https://cdn.discordapp.com/attachments/747111616407011389/779996509717659658/2020-11-21_20.16.09.png)
* PepsiMod Theme:
![pepsimod](https://cdn.discordapp.com/attachments/755077474861449277/770698000129327124/2020-10-27_18.17.22.png)
![pepsimod](https://cdn.discordapp.com/attachments/747111616407011389/779996535366090772/2020-11-21_20.20.43.png)
* GameSense 2.2 Theme:
![gamesense22](https://cdn.discordapp.com/attachments/767021200685400075/772018964414857246/unknown.png)
![gamesense22](https://cdn.discordapp.com/attachments/747111616407011389/779996442285834240/2020-11-21_19.57.25.png)
* Future Theme:
![future](https://cdn.discordapp.com/attachments/755077474861449277/771799117998718986/unknown.png)
![future](https://cdn.discordapp.com/attachments/747111616407011389/779996632334073896/2020-11-21_20.25.30.png)

This repostiory only includes the GameSense themes, however, since Cyber didn't want me to publish the other themes. The library has no depedencies (aside from the JRE itself), so it can be easily used for other purposes, aside from Minecraft utility mods. Thanks to Go_Hoosiers, for suggesting the name of this library. If you use this library, some attribution would be greatly appreciated.

## Features
* Ability to easily create new themes/skins.
* Overlapping Panels.
* Smooth animations and scrolling.
* Ability to have HUD components in panels.

## 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`.

To use this library in your Minecraft clients, you have to do following things:
* Implement the `Interface` interface.
* Implement the `ColorScheme` interface.
### 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 (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 and populates it in the constructor.
* For reference, consult the [javadoc](https://lukflug.github.io/javadoc/panelstudio/0.0.3/) and see the implementation in GameSense.
* 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
Add following to your `build.gradle`:
Expand All @@ -37,7 +49,7 @@ repositories {
}
dependencies {
compile("com.lukflug:panelstudio:0.0.3")
compile("com.lukflug:panelstudio:0.1.0")
}
shadowJar {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ plugins {

allprojects {
group = 'com.lukflug'
version = '0.0.3'
version = '0.1.0'
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.lukflug</groupId>
<artifactId>panelstudio</artifactId>
<version>0.0.3</version>
<version>0.1.0</version>
<name>PanelStudio</name>
<description>A simple yet flexible library to create ClickGUIs designed for use in Minecraft utility mods.</description>
</project>
65 changes: 65 additions & 0 deletions src/main/java/com/lukflug/panelstudio/Animation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.lukflug.panelstudio;

/**
* Class representing an animation.
* @author lukflug
*/
public abstract class Animation {
/**
* Current value.
*/
protected double value;
/**
* Past value.
*/
protected double lastValue;
/**
* Time of last value transition.
*/
protected long lastTime=System.currentTimeMillis();

/**
* Set a value immediately, without an transition animation.
* @param value the new value
*/
public void initValue(double value) {
this.value=value;
lastValue=value;
}

/**
* The the current value.
* @return an interpolated value between {@link #value} and {@link #lastValue} depending on the current time
*/
public double getValue() {
if (getSpeed()==0) return value;
double weight=(System.currentTimeMillis()-lastTime)/(double)getSpeed();
if (weight>=1) return value;
else if (weight<=0) return lastValue;
return value*weight+lastValue*(1-weight);
}

/**
* Get the target value.
* @return the current {@link #value}
*/
public double getTarget() {
return value;
}

/**
* Set the value, with a transition between the old and new value.
* @param value the new value
*/
public void setValue(double value) {
lastValue=getValue();
this.value=value;
lastTime=System.currentTimeMillis();
}

/**
* Used to obtain the animation speed.
* @return time a transition should take in milliseconds
*/
protected abstract int getSpeed();
}
37 changes: 25 additions & 12 deletions src/main/java/com/lukflug/panelstudio/ClickGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,13 @@ public class ClickGUI {
* The {@link Interface} to be used by the GUI.
*/
protected Interface inter;
/**
* The width of the panels.
*/
protected final int width;

/**
* Constructor for the GUI.
* @param inter the {@link Interface} to be used by the GUI
* @param width the width of the panels.
*/
public ClickGUI (Interface inter, int width) {
public ClickGUI (Interface inter) {
this.inter=inter;
this.width=width;
components=new ArrayList<FixedComponent>();
}

Expand Down Expand Up @@ -58,7 +52,7 @@ public void render() {
FixedComponent focusComponent=null;
for (int i=components.size()-1;i>=0;i--) {
FixedComponent component=components.get(i);
Context context=new Context(inter,width,component.getPosition(inter),true,true);
Context context=new Context(inter,component.getWidth(inter),component.getPosition(inter),true,true);
component.getHeight(context);
if (context.isHovered()) {
highest=i;
Expand All @@ -67,7 +61,7 @@ public void render() {
}
for (int i=0;i<components.size();i++) {
FixedComponent component=components.get(i);
Context context=new Context(inter,width,component.getPosition(inter),true,i>=highest);
Context context=new Context(inter,component.getWidth(inter),component.getPosition(inter),true,i>=highest);
component.render(context);
if (context.foucsRequested()) focusComponent=component;
}
Expand All @@ -88,7 +82,7 @@ public void handleButton (int button) {
FixedComponent focusComponent=null;
for (int i=components.size()-1;i>=0;i--) {
FixedComponent component=components.get(i);
Context context=new Context(inter,width,component.getPosition(inter),true,highest);
Context context=new Context(inter,component.getWidth(inter),component.getPosition(inter),true,highest);
component.handleButton(context,button);
if (context.isHovered()) highest=false;
if (context.foucsRequested()) focusComponent=component;
Expand All @@ -107,7 +101,7 @@ public void handleKey (int scancode) {
boolean highest=true;
FixedComponent focusComponent=null;
for (FixedComponent component: components) {
Context context=new Context(inter,width,component.getPosition(inter),true,highest);
Context context=new Context(inter,component.getWidth(inter),component.getPosition(inter),true,highest);
component.handleKey(context,scancode);
if (context.isHovered()) highest=false;
if (context.foucsRequested()) focusComponent=component;
Expand All @@ -118,14 +112,33 @@ public void handleKey (int scancode) {
}
}

/**
* Handle the mouse wheel being scrolled
* @param diff the amount by which the wheel was moved
*/
public void handleScroll (int diff) {
boolean highest=true;
FixedComponent focusComponent=null;
for (FixedComponent component: components) {
Context context=new Context(inter,component.getWidth(inter),component.getPosition(inter),true,highest);
component.handleScroll(context,diff);
if (context.isHovered()) highest=false;
if (context.foucsRequested()) focusComponent=component;
}
if (focusComponent!=null) {
components.remove(focusComponent);
components.add(focusComponent);
}
}

/**
* Handle the GUI being closed.
*/
public void exit() {
boolean highest=true;
FixedComponent focusComponent=null;
for (FixedComponent component: components) {
Context context=new Context(inter,width,component.getPosition(inter),true,highest);
Context context=new Context(inter,component.getWidth(inter),component.getPosition(inter),true,highest);
component.exit(context);
if (context.isHovered()) highest=false;
if (context.foucsRequested()) focusComponent=component;
Expand Down
Loading

0 comments on commit 5a31cd4

Please sign in to comment.