Skip to content

Commit 5a31cd4

Browse files
authored
Merge pull request #1 from lukflug/dev
Version 0.1.0
2 parents 80245c0 + 0be2c52 commit 5a31cd4

26 files changed

+1415
-80
lines changed

README.md

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,42 @@
11
# PanelStudio
22
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:
33
* CyberHack Theme:
4-
![cyberhack](https://cdn.discordapp.com/attachments/755077474861449277/770697901499744286/2020-10-27_18.16.50.png)
4+
![cyberhack](https://cdn.discordapp.com/attachments/747111616407011389/779996603510947870/2020-11-21_20.23.26.png)
55
* GameSense 2.0 Theme:
6-
![gamesense20](https://cdn.discordapp.com/attachments/755077474861449277/770697937234821170/2020-10-27_18.16.59.png)
6+
![gamesense20](https://cdn.discordapp.com/attachments/747111616407011389/779996468730920960/2020-11-21_20.13.36.png)
77
* GameSense 2.1 Theme:
8-
![gamesense21](https://cdn.discordapp.com/attachments/755077474861449277/770697959947239424/2020-10-27_18.17.12.png)
8+
![gamesense21](https://cdn.discordapp.com/attachments/747111616407011389/779996509717659658/2020-11-21_20.16.09.png)
99
* PepsiMod Theme:
10-
![pepsimod](https://cdn.discordapp.com/attachments/755077474861449277/770698000129327124/2020-10-27_18.17.22.png)
10+
![pepsimod](https://cdn.discordapp.com/attachments/747111616407011389/779996535366090772/2020-11-21_20.20.43.png)
1111
* GameSense 2.2 Theme:
12-
![gamesense22](https://cdn.discordapp.com/attachments/767021200685400075/772018964414857246/unknown.png)
12+
![gamesense22](https://cdn.discordapp.com/attachments/747111616407011389/779996442285834240/2020-11-21_19.57.25.png)
1313
* Future Theme:
14-
![future](https://cdn.discordapp.com/attachments/755077474861449277/771799117998718986/unknown.png)
14+
![future](https://cdn.discordapp.com/attachments/747111616407011389/779996632334073896/2020-11-21_20.25.30.png)
1515

1616
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.
1717

18+
## Features
19+
* Ability to easily create new themes/skins.
20+
* Overlapping Panels.
21+
* Smooth animations and scrolling.
22+
* Ability to have HUD components in panels.
23+
1824
## Implementation in Minecraft clients
1925
A jar of this library is available in the Maven repository at https://lukflug.github.io/maven/ as `com.lukflug.panelstudio`.
2026

21-
To use this library in your Minecraft clients, you have to do following things:
22-
* Implement the `Interface` interface.
23-
* Implement the `ColorScheme` interface.
27+
### ClickGUI
28+
To use the ClickGUI, following interfaces need to be implemented
29+
* `Interface`
30+
* `ColorScheme`
31+
In addition:
2432
* Use one of the supplied Themes or implement one yourself, to have a different look from GameSense (see `ClearTheme` and `GameSenseTheme` for reference).
25-
* Populate the `ClickGUI` object with the desired components (probably requires marking your settings objects with the interfaces in the `settings` package).
26-
* 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.
27-
* For reference, consult the [javadoc](https://lukflug.github.io/javadoc/panelstudio/0.0.3/) and see the implementation in GameSense.
33+
* 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).
34+
* 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.
35+
* For reference, consult the [javadoc](https://lukflug.github.io/javadoc/panelstudio/0.1.0/) and see the implementation in GameSense.
36+
* Some custom classes may need to be created, for specific behaviour.
37+
38+
### HUD
39+
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.
2840

2941
## Use in Gradle
3042
Add following to your `build.gradle`:
@@ -37,7 +49,7 @@ repositories {
3749
}
3850
3951
dependencies {
40-
compile("com.lukflug:panelstudio:0.0.3")
52+
compile("com.lukflug:panelstudio:0.1.0")
4153
}
4254
4355
shadowJar {

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ plugins {
44

55
allprojects {
66
group = 'com.lukflug'
7-
version = '0.0.3'
7+
version = '0.1.0'
88
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>com.lukflug</groupId>
44
<artifactId>panelstudio</artifactId>
5-
<version>0.0.3</version>
5+
<version>0.1.0</version>
66
<name>PanelStudio</name>
77
<description>A simple yet flexible library to create ClickGUIs designed for use in Minecraft utility mods.</description>
88
</project>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.lukflug.panelstudio;
2+
3+
/**
4+
* Class representing an animation.
5+
* @author lukflug
6+
*/
7+
public abstract class Animation {
8+
/**
9+
* Current value.
10+
*/
11+
protected double value;
12+
/**
13+
* Past value.
14+
*/
15+
protected double lastValue;
16+
/**
17+
* Time of last value transition.
18+
*/
19+
protected long lastTime=System.currentTimeMillis();
20+
21+
/**
22+
* Set a value immediately, without an transition animation.
23+
* @param value the new value
24+
*/
25+
public void initValue(double value) {
26+
this.value=value;
27+
lastValue=value;
28+
}
29+
30+
/**
31+
* The the current value.
32+
* @return an interpolated value between {@link #value} and {@link #lastValue} depending on the current time
33+
*/
34+
public double getValue() {
35+
if (getSpeed()==0) return value;
36+
double weight=(System.currentTimeMillis()-lastTime)/(double)getSpeed();
37+
if (weight>=1) return value;
38+
else if (weight<=0) return lastValue;
39+
return value*weight+lastValue*(1-weight);
40+
}
41+
42+
/**
43+
* Get the target value.
44+
* @return the current {@link #value}
45+
*/
46+
public double getTarget() {
47+
return value;
48+
}
49+
50+
/**
51+
* Set the value, with a transition between the old and new value.
52+
* @param value the new value
53+
*/
54+
public void setValue(double value) {
55+
lastValue=getValue();
56+
this.value=value;
57+
lastTime=System.currentTimeMillis();
58+
}
59+
60+
/**
61+
* Used to obtain the animation speed.
62+
* @return time a transition should take in milliseconds
63+
*/
64+
protected abstract int getSpeed();
65+
}

src/main/java/com/lukflug/panelstudio/ClickGUI.java

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,13 @@ public class ClickGUI {
1818
* The {@link Interface} to be used by the GUI.
1919
*/
2020
protected Interface inter;
21-
/**
22-
* The width of the panels.
23-
*/
24-
protected final int width;
2521

2622
/**
2723
* Constructor for the GUI.
2824
* @param inter the {@link Interface} to be used by the GUI
29-
* @param width the width of the panels.
3025
*/
31-
public ClickGUI (Interface inter, int width) {
26+
public ClickGUI (Interface inter) {
3227
this.inter=inter;
33-
this.width=width;
3428
components=new ArrayList<FixedComponent>();
3529
}
3630

@@ -58,7 +52,7 @@ public void render() {
5852
FixedComponent focusComponent=null;
5953
for (int i=components.size()-1;i>=0;i--) {
6054
FixedComponent component=components.get(i);
61-
Context context=new Context(inter,width,component.getPosition(inter),true,true);
55+
Context context=new Context(inter,component.getWidth(inter),component.getPosition(inter),true,true);
6256
component.getHeight(context);
6357
if (context.isHovered()) {
6458
highest=i;
@@ -67,7 +61,7 @@ public void render() {
6761
}
6862
for (int i=0;i<components.size();i++) {
6963
FixedComponent component=components.get(i);
70-
Context context=new Context(inter,width,component.getPosition(inter),true,i>=highest);
64+
Context context=new Context(inter,component.getWidth(inter),component.getPosition(inter),true,i>=highest);
7165
component.render(context);
7266
if (context.foucsRequested()) focusComponent=component;
7367
}
@@ -88,7 +82,7 @@ public void handleButton (int button) {
8882
FixedComponent focusComponent=null;
8983
for (int i=components.size()-1;i>=0;i--) {
9084
FixedComponent component=components.get(i);
91-
Context context=new Context(inter,width,component.getPosition(inter),true,highest);
85+
Context context=new Context(inter,component.getWidth(inter),component.getPosition(inter),true,highest);
9286
component.handleButton(context,button);
9387
if (context.isHovered()) highest=false;
9488
if (context.foucsRequested()) focusComponent=component;
@@ -107,7 +101,7 @@ public void handleKey (int scancode) {
107101
boolean highest=true;
108102
FixedComponent focusComponent=null;
109103
for (FixedComponent component: components) {
110-
Context context=new Context(inter,width,component.getPosition(inter),true,highest);
104+
Context context=new Context(inter,component.getWidth(inter),component.getPosition(inter),true,highest);
111105
component.handleKey(context,scancode);
112106
if (context.isHovered()) highest=false;
113107
if (context.foucsRequested()) focusComponent=component;
@@ -118,14 +112,33 @@ public void handleKey (int scancode) {
118112
}
119113
}
120114

115+
/**
116+
* Handle the mouse wheel being scrolled
117+
* @param diff the amount by which the wheel was moved
118+
*/
119+
public void handleScroll (int diff) {
120+
boolean highest=true;
121+
FixedComponent focusComponent=null;
122+
for (FixedComponent component: components) {
123+
Context context=new Context(inter,component.getWidth(inter),component.getPosition(inter),true,highest);
124+
component.handleScroll(context,diff);
125+
if (context.isHovered()) highest=false;
126+
if (context.foucsRequested()) focusComponent=component;
127+
}
128+
if (focusComponent!=null) {
129+
components.remove(focusComponent);
130+
components.add(focusComponent);
131+
}
132+
}
133+
121134
/**
122135
* Handle the GUI being closed.
123136
*/
124137
public void exit() {
125138
boolean highest=true;
126139
FixedComponent focusComponent=null;
127140
for (FixedComponent component: components) {
128-
Context context=new Context(inter,width,component.getPosition(inter),true,highest);
141+
Context context=new Context(inter,component.getWidth(inter),component.getPosition(inter),true,highest);
129142
component.exit(context);
130143
if (context.isHovered()) highest=false;
131144
if (context.foucsRequested()) focusComponent=component;

0 commit comments

Comments
 (0)