Skip to content

Commit 4de40e3

Browse files
committed
1.0.4
added notes to testCannonCharges testCannonData of fields gets saved when closing while focused changed FrameConfig from int to float, more accurate, but using a lot of rounding calls
1 parent f2706ed commit 4de40e3

16 files changed

+322
-202
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ dependencies {
108108
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
109109
minecraft 'net.minecraftforge:forge:1.15.2-31.2.47'
110110

111-
provided name: 'JumperCommons', version: '1.1'
111+
provided name: 'JumperCommons', version: '1.0.4'
112112

113113
// You may put jars on which you depend on in ./libs or you may define them like so..
114114
// compile "some.group:artifact:version:classifier"

src/main/java/the_dark_jumper/cannontracer/gui/ConfigGUI.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@ public void generateSingleplayerScreenComponents() {
130130
guiComponents.add(new BasicTextFrame(this, "Keybinds", config.duplicate(), headerColors));
131131
config.init(80, 35, 94, 39, 8);
132132
guiComponents.add(new ButtonFrame(this, "open Hotkey Menu", config.duplicate(), colors, this::openHotkeyScreen));
133-
config.init(6, 40, 94, 59, 8);
133+
config.init(6, 40, 94, 59, 4);
134134
generateModuleKeybindTable(config, colors, Main.getInstance().moduleManager.singlePlayerModules);
135135

136136
//tracing entries
137137
config.init(8, 65, 21, 69, 8);
138138
guiComponents.add(new BasicTextFrame(this, "Tracked Entities", config.duplicate(), headerColors));
139139
config.init(80, 65, 94, 69, 8);
140140
guiComponents.add(new ButtonFrame(this, "add entity", config.duplicate(), colors, this::addTrackingEntity));
141-
config.init(6, 70, 94, 94, 8);
141+
config.init(6, 70, 94, 94, 4);
142142
generateTrackingTable(Main.getInstance().dataManager.getTrackingDataSP(), config, colors);
143143
//generateTrackingScreenComponents(guiManager.main.entityTracker.observedEntityIDSP, config, colors, 6, 70, 94, 5, 8);
144144
}
@@ -171,15 +171,15 @@ public void generateMultiplayerScreenComponents() {
171171
guiComponents.add(new BasicTextFrame(this, "Keybinds", config.duplicate(), headerColors));
172172
config.init(80, 35, 94, 39, 8);
173173
guiComponents.add(new ButtonFrame(this, "open Hotkey Menu", config.duplicate(), colors, this::openHotkeyScreen));
174-
config.init(6, 40, 94, 59, 8);
174+
config.init(6, 40, 94, 59, 4);
175175
generateModuleKeybindTable(config, colors, Main.getInstance().moduleManager.multiPlayerModules);
176176

177177
//tracing entries
178178
config.init(8, 65, 21, 69, 8);
179179
guiComponents.add(new BasicTextFrame(this, "Tracked Entities", config.duplicate(), headerColors));
180180
config.init(80, 65, 94, 69, 8);
181181
guiComponents.add(new ButtonFrame(this, "add entity", config.duplicate(), colors, this::addTrackingEntity));
182-
config.init(6, 70, 94, 94, 8);
182+
config.init(6, 70, 94, 94, 4);
183183
generateTrackingTable(Main.getInstance().dataManager.getTrackingDataMP(), config, colors);
184184
//generateTrackingScreenComponents(guiManager.main.entityTracker.observedEntityIDMP, config, colors, 6, 70, 94, 5, 8);
185185
}

src/main/java/the_dark_jumper/cannontracer/gui/TestCannonGUI.java

+24-19
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import the_dark_jumper.cannontracer.Main;
1818
import the_dark_jumper.cannontracer.gui.guielements.BasicTextFrame;
1919
import the_dark_jumper.cannontracer.gui.guielements.ButtonFrame;
20+
import the_dark_jumper.cannontracer.gui.guielements.CompactToggleValueFrame;
2021
import the_dark_jumper.cannontracer.gui.guielements.ScrollableTable;
2122
import the_dark_jumper.cannontracer.gui.guielements.ValueFrame;
2223
import the_dark_jumper.cannontracer.gui.guielements.interfaces.IClickableFrame;
@@ -82,6 +83,13 @@ public void closeButtonPressed(boolean isPressed) {
8283
}
8384
}
8485

86+
private void cancelButtonPressed(boolean isPressed){
87+
if(isPressed){
88+
cancelCannonData = true;
89+
shouldClose = true;
90+
}
91+
}
92+
8593
public void addChargeButtonPressed(boolean isPressed) {
8694
if (isPressed) {
8795
testCannon.getCharges().add(new TestCannonCharge());
@@ -118,7 +126,7 @@ public void generateScreenComponents() {
118126
config.init(6, 10, 60, 14, 8);
119127
guiComponents.add(new BasicTextFrame(this, "Cannon Tester", config.duplicate(), colors));
120128
config.init(80, 10, 89, 14, 8);
121-
guiComponents.add(new ButtonFrame(this, "cancel", config.duplicate(), colors, this::closeWithoutSend));
129+
guiComponents.add(new ButtonFrame(this, "cancel", config.duplicate(), colors, this::cancelButtonPressed));
122130
config.init(90, 10, 94, 14, 8);
123131
guiComponents.add(new ButtonFrame(this, "X", config.duplicate(), colors, this::closeButtonPressed));
124132

@@ -153,17 +161,19 @@ public void generateScreenComponents() {
153161
guiComponents.add(new BasicTextFrame(this, "Charges", config.duplicate(), headerColors));
154162
config.init(23, 40, 25, 44, 8);
155163
guiComponents.add(new ButtonFrame(this, "+", config.duplicate(), colors, this::addChargeButtonPressed));
156-
config.init(10, 45, 63, 94, 8);
164+
config.init(10, 45, 63, 94, 4);
157165
chargesTable = new ScrollableTable(this, config.duplicate(), colors);
158166
chargesTable.setUniformColFormat(false, 9, 1); // fallback value, shouldn't be needed
159-
chargesTable.setColFormat(false,
160-
new FormatData(2, 1), // delete button
161-
new FormatData(9, 0), // amount text field
162-
new FormatData(2, 0), // increment button
163-
new FormatData(2, 1), // decrement button
164-
new FormatData(9, 0), // delay text field
165-
new FormatData(2, 0), // increment button
166-
new FormatData(2, 1));// decrement button
167+
chargesTable.setColFormat(true,
168+
new FormatData(4, 1), // delete button
169+
new FormatData(10, 1), // enabled/disabled
170+
new FormatData(15, 0), // amount text field
171+
new FormatData(4, 0), // increment button
172+
new FormatData(4, 1), // decrement button
173+
new FormatData(15, 0), // delay text field
174+
new FormatData(4, 0), // increment button
175+
new FormatData(4, 1), // decrement button
176+
new FormatData(35, 1));// notes text field
167177
chargesTable.setUniformRowFormat(false, 4, 1);
168178
chargesTable.generateScrollbars(false, 0, true, chargesTable.matchHeightToWidth(1));
169179
generateChargesTable();
@@ -184,12 +194,14 @@ private void generateChargesTable() {
184194

185195
chargesTable.addRow(
186196
new ButtonFrame(this, "X", null, colors, new DeleteChargeCallback(i, this::removeCharge)::onPressed),
197+
new CompactToggleValueFrame(this, null, colors, "enabled", "disabled", charge.getEnabledGNS()),
187198
amountValueFrame,
188199
new ButtonFrame(this, "+", null, colors, amountIncrementer::onIncrement),
189200
new ButtonFrame(this, "-", null, colors, amountIncrementer::onDecrement),
190201
delayValueFrame,
191202
new ButtonFrame(this, "+", null, colors, delayIncrementer::onIncrement),
192-
new ButtonFrame(this, "-", null, colors, delayIncrementer::onDecrement)
203+
new ButtonFrame(this, "-", null, colors, delayIncrementer::onDecrement),
204+
new ValueFrame<>(this, null, colors, "note", charge.getNoteGNS(), String.class, true)
193205
);
194206
}
195207

@@ -266,6 +278,7 @@ public void render(int mouseX, int mouseY, float partialTicks) {
266278
if (shouldClose) {
267279
onClose();
268280
shouldClose = false;
281+
cancelCannonData = false;
269282
}
270283
}
271284

@@ -315,14 +328,6 @@ public void drawCenteredString(FontRenderer fontRenderer, String text, int xPos,
315328
GL11.glPopMatrix();
316329
}
317330

318-
private void closeWithoutSend(boolean isPressed){
319-
if(isPressed){
320-
cancelCannonData = true;
321-
onClose();
322-
cancelCannonData = false;
323-
}
324-
}
325-
326331
@Override
327332
public void onClose() {
328333
guiManager.main.moduleManager.focusReleaseAllFrames();

src/main/java/the_dark_jumper/cannontracer/gui/guielements/BasicTextFrame.java

+31-17
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,30 @@
66
import the_dark_jumper.cannontracer.gui.utils.FrameColors;
77
import the_dark_jumper.cannontracer.gui.utils.FrameConfig;
88

9-
public class BasicTextFrame implements IRenderableFrame{
9+
public class BasicTextFrame implements IRenderableFrame {
1010
public final IJumperGUI parent;
1111
public final Minecraft minecraft;
1212
public String text;
13-
13+
1414
public FrameConfig config;
15-
@Override public FrameConfig getConfig() {return config;}
16-
@Override public void setConfig(FrameConfig config) {this.config = config;}
17-
15+
16+
@Override
17+
public FrameConfig getConfig() {
18+
return config;
19+
}
20+
21+
@Override
22+
public void setConfig(FrameConfig config) {
23+
this.config = config;
24+
}
25+
1826
public FrameColors colors;
19-
@Override public FrameColors getColors() {return colors;}
20-
27+
28+
@Override
29+
public FrameColors getColors() {
30+
return colors;
31+
}
32+
2133
//all values are percentages of the full screen
2234
public BasicTextFrame(IJumperGUI parent, String text, FrameConfig config, FrameColors colors) {
2335
this.parent = parent;
@@ -26,22 +38,24 @@ public BasicTextFrame(IJumperGUI parent, String text, FrameConfig config, FrameC
2638
this.config = config;
2739
this.colors = colors;
2840
}
29-
41+
3042
@Override
3143
public void render(int scaledScreenWidth, int scaledScreenHeight, int guiScale) {
3244
//outer corners
33-
int x1 = getPercentValue(scaledScreenWidth, this.config.x);
34-
int x2 = getPercentValue(scaledScreenWidth, this.config.xEnd);
35-
int y1 = getPercentValue(scaledScreenHeight, this.config.y);
36-
int y2 = getPercentValue(scaledScreenHeight, this.config.yEnd);
45+
float x1 = getPercentValue(scaledScreenWidth, this.config.x);
46+
float x2 = getPercentValue(scaledScreenWidth, this.config.xEnd);
47+
float y1 = getPercentValue(scaledScreenHeight, this.config.y);
48+
float y2 = getPercentValue(scaledScreenHeight, this.config.yEnd);
3749
doFills(x1, y1, x2, y2, config.borderThickness / guiScale);
38-
if(!text.equals("")) {
50+
if (!text.equals("")) {
3951
drawTexts(x1, y1, x2, y2);
4052
}
4153
}
42-
43-
public void drawTexts(int x1, int y1, int x2, int y2) {
44-
int height = (y2 + y1) / 2;
45-
parent.drawCenteredString(minecraft.fontRenderer, text, (x2 + x1) / 2, height, 0xfff1f1f1);
54+
55+
@Override
56+
public void drawTexts(float x1, float y1, float x2, float y2) {
57+
int height = Math.round((y2 + y1) / 2);
58+
int width = Math.round((x2 + x1) / 2);
59+
parent.drawCenteredString(minecraft.fontRenderer, text, width, height, 0xfff1f1f1);
4660
}
4761
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package the_dark_jumper.cannontracer.gui.guielements;
2+
3+
import jumpercommons.GetterAndSetter;
4+
import the_dark_jumper.cannontracer.gui.IJumperGUI;
5+
import the_dark_jumper.cannontracer.gui.guielements.interfaces.IClickableFrame;
6+
import the_dark_jumper.cannontracer.gui.utils.FrameColors;
7+
import the_dark_jumper.cannontracer.gui.utils.FrameConfig;
8+
9+
public class CompactToggleValueFrame extends BasicTextFrame implements IClickableFrame {
10+
public final GetterAndSetter<Boolean> source;
11+
public final String enabledText;
12+
public final String disabledText;
13+
14+
public boolean isClicked = false;
15+
@Override public boolean getIsClicked() {return isClicked;}
16+
@Override
17+
public void setIsClicked(boolean isClicked) {
18+
if(isClicked) {
19+
boolean result = !source.get();
20+
source.set(result);
21+
super.text = result ? enabledText : disabledText;
22+
}
23+
}
24+
25+
public boolean hovered = false;
26+
@Override public boolean getHovered() {return hovered;}
27+
@Override public void setHovered(boolean hovered) {this.hovered = hovered;}
28+
29+
public CompactToggleValueFrame(IJumperGUI parent, FrameConfig config, FrameColors colors, String enabledText, String disabledText, GetterAndSetter<Boolean> source) {
30+
super(parent, source.get() ? enabledText : disabledText, config, colors);
31+
this.source = source;
32+
this.enabledText = enabledText;
33+
this.disabledText = disabledText;
34+
}
35+
36+
@Override
37+
public void drawTexts(float x1, float y1, float x2, float y2) {
38+
int height = Math.round((y2 + y1) / 2);
39+
int width = Math.round((x2 + x1) / 2);
40+
parent.drawCenteredString(minecraft.fontRenderer, text, width, height, source.get() ? colors.colorOn : colors.colorOff);
41+
}
42+
}

src/main/java/the_dark_jumper/cannontracer/gui/guielements/DoubleSegmentFrame.java

+68-38
Original file line numberDiff line numberDiff line change
@@ -6,68 +6,98 @@
66
import the_dark_jumper.cannontracer.gui.utils.FrameColors;
77
import the_dark_jumper.cannontracer.gui.utils.FrameConfig;
88

9-
public class DoubleSegmentFrame extends BasicTextFrame implements IClickableFrame{
9+
public class DoubleSegmentFrame extends BasicTextFrame implements IClickableFrame {
1010
public int valueColor;
11-
11+
1212
public String value;
13-
public String getValue() {return value;}
14-
public void setValue(String value) {this.value = value;}
15-
13+
14+
public String getValue() {
15+
return value;
16+
}
17+
18+
public void setValue(String value) {
19+
this.value = value;
20+
}
21+
1622
public boolean isClicked = false;
17-
@Override public boolean getIsClicked() {return isClicked;}
18-
@Override public void setIsClicked(boolean isClicked) {this.isClicked = isClicked;}
19-
23+
24+
@Override
25+
public boolean getIsClicked() {
26+
return isClicked;
27+
}
28+
29+
@Override
30+
public void setIsClicked(boolean isClicked) {
31+
this.isClicked = isClicked;
32+
}
33+
2034
public boolean hovered = false;
21-
@Override public boolean getHovered() {return hovered;}
22-
@Override public void setHovered(boolean hovered) {this.hovered = hovered;}
23-
35+
36+
@Override
37+
public boolean getHovered() {
38+
return hovered;
39+
}
40+
41+
@Override
42+
public void setHovered(boolean hovered) {
43+
this.hovered = hovered;
44+
}
45+
2446
public DoubleSegmentFrame(IJumperGUI parent, String text, String value, int valueColor, FrameConfig config, FrameColors colors) {
2547
super(parent, text, config, colors);
2648
init(value, valueColor);
2749
}
28-
50+
2951
public DoubleSegmentFrame(IJumperGUI parent, String text, String value, FrameConfig config, FrameColors colors) {
3052
super(parent, text, config, colors);
3153
init(value, colors.defaultValueColor);
3254
}
33-
55+
3456
public void init(String value, int valueColor) {
3557
this.value = value;
3658
this.valueColor = valueColor;
3759
}
38-
60+
3961
@Override
40-
public void doFills(int x1, int y1, int x2, int y2, int borderPx) {
41-
Screen.fill(x1, y1, x1 + borderPx, y2, colors.borderColor); //left edge
42-
Screen.fill(x1 + borderPx, y1, x2 - borderPx, y1 + borderPx, colors.borderColor); //top edge
43-
Screen.fill(x2 - borderPx, y1, x2, y2, colors.borderColor); //right edge
44-
Screen.fill(x1 + borderPx, y2 - borderPx, x2 - borderPx, y2, colors.borderColor); //bottom edge
45-
int valueEdge = getEstimateValueBorder(x1, x2);
46-
Screen.fill(valueEdge, y1, valueEdge + borderPx, y2, colorToFullAlpha(colors.borderColor));
62+
public void doFills(float x1, float y1, float x2, float y2, float borderPx) {
63+
int x1i = Math.round(x1);
64+
int x2i = Math.round(x2);
65+
int y1i = Math.round(y1);
66+
int y2i = Math.round(y2);
67+
int borderPxi = Math.round(borderPx);
68+
69+
Screen.fill(x1i, y1i, x1i + borderPxi, y2i, colors.borderColor); //left edge
70+
Screen.fill(x1i + borderPxi, y1i, x2i - borderPxi, y1i + borderPxi, colors.borderColor); //top edge
71+
Screen.fill(x2i - borderPxi, y1i, x2i, y2i, colors.borderColor); //right edge
72+
Screen.fill(x1i + borderPxi, y2i - borderPxi, x2i - borderPxi, y2i, colors.borderColor); //bottom edge
73+
int valueEdge = Math.round(getEstimateValueBorder(x1i, x2i));
74+
Screen.fill(valueEdge, y1i, valueEdge + borderPxi, y2i, colorToFullAlpha(colors.borderColor));
4775
//fill value sections
48-
Screen.fill(x1 + borderPx, y1 + borderPx, valueEdge, y2 - borderPx, getInnerColor());
49-
Screen.fill(valueEdge + borderPx, y1 + borderPx, x2 - borderPx, y2 - borderPx, getInnerColor2());
76+
Screen.fill(x1i + borderPxi, y1i + borderPxi, valueEdge, y2i - borderPxi, getInnerColor());
77+
Screen.fill(valueEdge + borderPxi, y1i + borderPxi, x2i - borderPxi, y2i - borderPxi, getInnerColor2());
5078
}
51-
79+
5280
@Override
53-
public void drawTexts(int x1, int y1, int x2, int y2) {
54-
int valueEdge = getEstimateValueBorder(x1, x2);
55-
int height = (y2 + y1) / 2;
56-
parent.drawCenteredString(minecraft.fontRenderer, text, (x1 + valueEdge) / 2, height, 0xfff1f1f1);
57-
parent.drawCenteredString(minecraft.fontRenderer, value, (x2 + valueEdge) / 2, height, valueColor);
81+
public void drawTexts(float x1, float y1, float x2, float y2) {
82+
float valueEdge = getEstimateValueBorder(x1, x2);
83+
int height = Math.round((y2 + y1) / 2);
84+
int width1 = Math.round((x1 + valueEdge) / 2);
85+
int width2 = Math.round((x2 + valueEdge) / 2);
86+
parent.drawCenteredString(minecraft.fontRenderer, text, width1, height, 0xfff1f1f1);
87+
parent.drawCenteredString(minecraft.fontRenderer, value, width2, height, valueColor);
5888
}
59-
60-
public int getEstimateValueBorder(int x1, int x2) {
61-
double bias = ((double)text.length()) / (text.length() + value.length());
62-
if(bias > 0.8) {
63-
bias = 0.8;
89+
90+
public float getEstimateValueBorder(float x1, float x2) {
91+
float bias = ((float) text.length()) / (text.length() + value.length());
92+
if (bias > 0.8f) {
93+
bias = 0.8f;
6494
}
65-
if(bias < 0.2){
66-
bias = 0.2;
95+
if (bias < 0.2f) {
96+
bias = 0.2f;
6797
}
68-
return (int)(bias * (x2 - x1) + x1);
98+
return (bias * (x2 - x1) + x1);
6999
}
70-
100+
71101
public int colorToFullAlpha(int color) {
72102
return (0xff000000 | color);
73103
}

0 commit comments

Comments
 (0)