Skip to content

Commit

Permalink
1.0.4
Browse files Browse the repository at this point in the history
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
  • Loading branch information
BlazingTwist committed Mar 20, 2021
1 parent f2706ed commit 4de40e3
Show file tree
Hide file tree
Showing 16 changed files with 322 additions and 202 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ dependencies {
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
minecraft 'net.minecraftforge:forge:1.15.2-31.2.47'

provided name: 'JumperCommons', version: '1.1'
provided name: 'JumperCommons', version: '1.0.4'

// You may put jars on which you depend on in ./libs or you may define them like so..
// compile "some.group:artifact:version:classifier"
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/the_dark_jumper/cannontracer/gui/ConfigGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ public void generateSingleplayerScreenComponents() {
guiComponents.add(new BasicTextFrame(this, "Keybinds", config.duplicate(), headerColors));
config.init(80, 35, 94, 39, 8);
guiComponents.add(new ButtonFrame(this, "open Hotkey Menu", config.duplicate(), colors, this::openHotkeyScreen));
config.init(6, 40, 94, 59, 8);
config.init(6, 40, 94, 59, 4);
generateModuleKeybindTable(config, colors, Main.getInstance().moduleManager.singlePlayerModules);

//tracing entries
config.init(8, 65, 21, 69, 8);
guiComponents.add(new BasicTextFrame(this, "Tracked Entities", config.duplicate(), headerColors));
config.init(80, 65, 94, 69, 8);
guiComponents.add(new ButtonFrame(this, "add entity", config.duplicate(), colors, this::addTrackingEntity));
config.init(6, 70, 94, 94, 8);
config.init(6, 70, 94, 94, 4);
generateTrackingTable(Main.getInstance().dataManager.getTrackingDataSP(), config, colors);
//generateTrackingScreenComponents(guiManager.main.entityTracker.observedEntityIDSP, config, colors, 6, 70, 94, 5, 8);
}
Expand Down Expand Up @@ -171,15 +171,15 @@ public void generateMultiplayerScreenComponents() {
guiComponents.add(new BasicTextFrame(this, "Keybinds", config.duplicate(), headerColors));
config.init(80, 35, 94, 39, 8);
guiComponents.add(new ButtonFrame(this, "open Hotkey Menu", config.duplicate(), colors, this::openHotkeyScreen));
config.init(6, 40, 94, 59, 8);
config.init(6, 40, 94, 59, 4);
generateModuleKeybindTable(config, colors, Main.getInstance().moduleManager.multiPlayerModules);

//tracing entries
config.init(8, 65, 21, 69, 8);
guiComponents.add(new BasicTextFrame(this, "Tracked Entities", config.duplicate(), headerColors));
config.init(80, 65, 94, 69, 8);
guiComponents.add(new ButtonFrame(this, "add entity", config.duplicate(), colors, this::addTrackingEntity));
config.init(6, 70, 94, 94, 8);
config.init(6, 70, 94, 94, 4);
generateTrackingTable(Main.getInstance().dataManager.getTrackingDataMP(), config, colors);
//generateTrackingScreenComponents(guiManager.main.entityTracker.observedEntityIDMP, config, colors, 6, 70, 94, 5, 8);
}
Expand Down
43 changes: 24 additions & 19 deletions src/main/java/the_dark_jumper/cannontracer/gui/TestCannonGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import the_dark_jumper.cannontracer.Main;
import the_dark_jumper.cannontracer.gui.guielements.BasicTextFrame;
import the_dark_jumper.cannontracer.gui.guielements.ButtonFrame;
import the_dark_jumper.cannontracer.gui.guielements.CompactToggleValueFrame;
import the_dark_jumper.cannontracer.gui.guielements.ScrollableTable;
import the_dark_jumper.cannontracer.gui.guielements.ValueFrame;
import the_dark_jumper.cannontracer.gui.guielements.interfaces.IClickableFrame;
Expand Down Expand Up @@ -82,6 +83,13 @@ public void closeButtonPressed(boolean isPressed) {
}
}

private void cancelButtonPressed(boolean isPressed){
if(isPressed){
cancelCannonData = true;
shouldClose = true;
}
}

public void addChargeButtonPressed(boolean isPressed) {
if (isPressed) {
testCannon.getCharges().add(new TestCannonCharge());
Expand Down Expand Up @@ -118,7 +126,7 @@ public void generateScreenComponents() {
config.init(6, 10, 60, 14, 8);
guiComponents.add(new BasicTextFrame(this, "Cannon Tester", config.duplicate(), colors));
config.init(80, 10, 89, 14, 8);
guiComponents.add(new ButtonFrame(this, "cancel", config.duplicate(), colors, this::closeWithoutSend));
guiComponents.add(new ButtonFrame(this, "cancel", config.duplicate(), colors, this::cancelButtonPressed));
config.init(90, 10, 94, 14, 8);
guiComponents.add(new ButtonFrame(this, "X", config.duplicate(), colors, this::closeButtonPressed));

Expand Down Expand Up @@ -153,17 +161,19 @@ public void generateScreenComponents() {
guiComponents.add(new BasicTextFrame(this, "Charges", config.duplicate(), headerColors));
config.init(23, 40, 25, 44, 8);
guiComponents.add(new ButtonFrame(this, "+", config.duplicate(), colors, this::addChargeButtonPressed));
config.init(10, 45, 63, 94, 8);
config.init(10, 45, 63, 94, 4);
chargesTable = new ScrollableTable(this, config.duplicate(), colors);
chargesTable.setUniformColFormat(false, 9, 1); // fallback value, shouldn't be needed
chargesTable.setColFormat(false,
new FormatData(2, 1), // delete button
new FormatData(9, 0), // amount text field
new FormatData(2, 0), // increment button
new FormatData(2, 1), // decrement button
new FormatData(9, 0), // delay text field
new FormatData(2, 0), // increment button
new FormatData(2, 1));// decrement button
chargesTable.setColFormat(true,
new FormatData(4, 1), // delete button
new FormatData(10, 1), // enabled/disabled
new FormatData(15, 0), // amount text field
new FormatData(4, 0), // increment button
new FormatData(4, 1), // decrement button
new FormatData(15, 0), // delay text field
new FormatData(4, 0), // increment button
new FormatData(4, 1), // decrement button
new FormatData(35, 1));// notes text field
chargesTable.setUniformRowFormat(false, 4, 1);
chargesTable.generateScrollbars(false, 0, true, chargesTable.matchHeightToWidth(1));
generateChargesTable();
Expand All @@ -184,12 +194,14 @@ private void generateChargesTable() {

chargesTable.addRow(
new ButtonFrame(this, "X", null, colors, new DeleteChargeCallback(i, this::removeCharge)::onPressed),
new CompactToggleValueFrame(this, null, colors, "enabled", "disabled", charge.getEnabledGNS()),
amountValueFrame,
new ButtonFrame(this, "+", null, colors, amountIncrementer::onIncrement),
new ButtonFrame(this, "-", null, colors, amountIncrementer::onDecrement),
delayValueFrame,
new ButtonFrame(this, "+", null, colors, delayIncrementer::onIncrement),
new ButtonFrame(this, "-", null, colors, delayIncrementer::onDecrement)
new ButtonFrame(this, "-", null, colors, delayIncrementer::onDecrement),
new ValueFrame<>(this, null, colors, "note", charge.getNoteGNS(), String.class, true)
);
}

Expand Down Expand Up @@ -266,6 +278,7 @@ public void render(int mouseX, int mouseY, float partialTicks) {
if (shouldClose) {
onClose();
shouldClose = false;
cancelCannonData = false;
}
}

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

private void closeWithoutSend(boolean isPressed){
if(isPressed){
cancelCannonData = true;
onClose();
cancelCannonData = false;
}
}

@Override
public void onClose() {
guiManager.main.moduleManager.focusReleaseAllFrames();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,30 @@
import the_dark_jumper.cannontracer.gui.utils.FrameColors;
import the_dark_jumper.cannontracer.gui.utils.FrameConfig;

public class BasicTextFrame implements IRenderableFrame{
public class BasicTextFrame implements IRenderableFrame {
public final IJumperGUI parent;
public final Minecraft minecraft;
public String text;

public FrameConfig config;
@Override public FrameConfig getConfig() {return config;}
@Override public void setConfig(FrameConfig config) {this.config = config;}


@Override
public FrameConfig getConfig() {
return config;
}

@Override
public void setConfig(FrameConfig config) {
this.config = config;
}

public FrameColors colors;
@Override public FrameColors getColors() {return colors;}


@Override
public FrameColors getColors() {
return colors;
}

//all values are percentages of the full screen
public BasicTextFrame(IJumperGUI parent, String text, FrameConfig config, FrameColors colors) {
this.parent = parent;
Expand All @@ -26,22 +38,24 @@ public BasicTextFrame(IJumperGUI parent, String text, FrameConfig config, FrameC
this.config = config;
this.colors = colors;
}

@Override
public void render(int scaledScreenWidth, int scaledScreenHeight, int guiScale) {
//outer corners
int x1 = getPercentValue(scaledScreenWidth, this.config.x);
int x2 = getPercentValue(scaledScreenWidth, this.config.xEnd);
int y1 = getPercentValue(scaledScreenHeight, this.config.y);
int y2 = getPercentValue(scaledScreenHeight, this.config.yEnd);
float x1 = getPercentValue(scaledScreenWidth, this.config.x);
float x2 = getPercentValue(scaledScreenWidth, this.config.xEnd);
float y1 = getPercentValue(scaledScreenHeight, this.config.y);
float y2 = getPercentValue(scaledScreenHeight, this.config.yEnd);
doFills(x1, y1, x2, y2, config.borderThickness / guiScale);
if(!text.equals("")) {
if (!text.equals("")) {
drawTexts(x1, y1, x2, y2);
}
}

public void drawTexts(int x1, int y1, int x2, int y2) {
int height = (y2 + y1) / 2;
parent.drawCenteredString(minecraft.fontRenderer, text, (x2 + x1) / 2, height, 0xfff1f1f1);

@Override
public void drawTexts(float x1, float y1, float x2, float y2) {
int height = Math.round((y2 + y1) / 2);
int width = Math.round((x2 + x1) / 2);
parent.drawCenteredString(minecraft.fontRenderer, text, width, height, 0xfff1f1f1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package the_dark_jumper.cannontracer.gui.guielements;

import jumpercommons.GetterAndSetter;
import the_dark_jumper.cannontracer.gui.IJumperGUI;
import the_dark_jumper.cannontracer.gui.guielements.interfaces.IClickableFrame;
import the_dark_jumper.cannontracer.gui.utils.FrameColors;
import the_dark_jumper.cannontracer.gui.utils.FrameConfig;

public class CompactToggleValueFrame extends BasicTextFrame implements IClickableFrame {
public final GetterAndSetter<Boolean> source;
public final String enabledText;
public final String disabledText;

public boolean isClicked = false;
@Override public boolean getIsClicked() {return isClicked;}
@Override
public void setIsClicked(boolean isClicked) {
if(isClicked) {
boolean result = !source.get();
source.set(result);
super.text = result ? enabledText : disabledText;
}
}

public boolean hovered = false;
@Override public boolean getHovered() {return hovered;}
@Override public void setHovered(boolean hovered) {this.hovered = hovered;}

public CompactToggleValueFrame(IJumperGUI parent, FrameConfig config, FrameColors colors, String enabledText, String disabledText, GetterAndSetter<Boolean> source) {
super(parent, source.get() ? enabledText : disabledText, config, colors);
this.source = source;
this.enabledText = enabledText;
this.disabledText = disabledText;
}

@Override
public void drawTexts(float x1, float y1, float x2, float y2) {
int height = Math.round((y2 + y1) / 2);
int width = Math.round((x2 + x1) / 2);
parent.drawCenteredString(minecraft.fontRenderer, text, width, height, source.get() ? colors.colorOn : colors.colorOff);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,68 +6,98 @@
import the_dark_jumper.cannontracer.gui.utils.FrameColors;
import the_dark_jumper.cannontracer.gui.utils.FrameConfig;

public class DoubleSegmentFrame extends BasicTextFrame implements IClickableFrame{
public class DoubleSegmentFrame extends BasicTextFrame implements IClickableFrame {
public int valueColor;

public String value;
public String getValue() {return value;}
public void setValue(String value) {this.value = value;}


public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

public boolean isClicked = false;
@Override public boolean getIsClicked() {return isClicked;}
@Override public void setIsClicked(boolean isClicked) {this.isClicked = isClicked;}


@Override
public boolean getIsClicked() {
return isClicked;
}

@Override
public void setIsClicked(boolean isClicked) {
this.isClicked = isClicked;
}

public boolean hovered = false;
@Override public boolean getHovered() {return hovered;}
@Override public void setHovered(boolean hovered) {this.hovered = hovered;}


@Override
public boolean getHovered() {
return hovered;
}

@Override
public void setHovered(boolean hovered) {
this.hovered = hovered;
}

public DoubleSegmentFrame(IJumperGUI parent, String text, String value, int valueColor, FrameConfig config, FrameColors colors) {
super(parent, text, config, colors);
init(value, valueColor);
}

public DoubleSegmentFrame(IJumperGUI parent, String text, String value, FrameConfig config, FrameColors colors) {
super(parent, text, config, colors);
init(value, colors.defaultValueColor);
}

public void init(String value, int valueColor) {
this.value = value;
this.valueColor = valueColor;
}

@Override
public void doFills(int x1, int y1, int x2, int y2, int borderPx) {
Screen.fill(x1, y1, x1 + borderPx, y2, colors.borderColor); //left edge
Screen.fill(x1 + borderPx, y1, x2 - borderPx, y1 + borderPx, colors.borderColor); //top edge
Screen.fill(x2 - borderPx, y1, x2, y2, colors.borderColor); //right edge
Screen.fill(x1 + borderPx, y2 - borderPx, x2 - borderPx, y2, colors.borderColor); //bottom edge
int valueEdge = getEstimateValueBorder(x1, x2);
Screen.fill(valueEdge, y1, valueEdge + borderPx, y2, colorToFullAlpha(colors.borderColor));
public void doFills(float x1, float y1, float x2, float y2, float borderPx) {
int x1i = Math.round(x1);
int x2i = Math.round(x2);
int y1i = Math.round(y1);
int y2i = Math.round(y2);
int borderPxi = Math.round(borderPx);

Screen.fill(x1i, y1i, x1i + borderPxi, y2i, colors.borderColor); //left edge
Screen.fill(x1i + borderPxi, y1i, x2i - borderPxi, y1i + borderPxi, colors.borderColor); //top edge
Screen.fill(x2i - borderPxi, y1i, x2i, y2i, colors.borderColor); //right edge
Screen.fill(x1i + borderPxi, y2i - borderPxi, x2i - borderPxi, y2i, colors.borderColor); //bottom edge
int valueEdge = Math.round(getEstimateValueBorder(x1i, x2i));
Screen.fill(valueEdge, y1i, valueEdge + borderPxi, y2i, colorToFullAlpha(colors.borderColor));
//fill value sections
Screen.fill(x1 + borderPx, y1 + borderPx, valueEdge, y2 - borderPx, getInnerColor());
Screen.fill(valueEdge + borderPx, y1 + borderPx, x2 - borderPx, y2 - borderPx, getInnerColor2());
Screen.fill(x1i + borderPxi, y1i + borderPxi, valueEdge, y2i - borderPxi, getInnerColor());
Screen.fill(valueEdge + borderPxi, y1i + borderPxi, x2i - borderPxi, y2i - borderPxi, getInnerColor2());
}

@Override
public void drawTexts(int x1, int y1, int x2, int y2) {
int valueEdge = getEstimateValueBorder(x1, x2);
int height = (y2 + y1) / 2;
parent.drawCenteredString(minecraft.fontRenderer, text, (x1 + valueEdge) / 2, height, 0xfff1f1f1);
parent.drawCenteredString(minecraft.fontRenderer, value, (x2 + valueEdge) / 2, height, valueColor);
public void drawTexts(float x1, float y1, float x2, float y2) {
float valueEdge = getEstimateValueBorder(x1, x2);
int height = Math.round((y2 + y1) / 2);
int width1 = Math.round((x1 + valueEdge) / 2);
int width2 = Math.round((x2 + valueEdge) / 2);
parent.drawCenteredString(minecraft.fontRenderer, text, width1, height, 0xfff1f1f1);
parent.drawCenteredString(minecraft.fontRenderer, value, width2, height, valueColor);
}
public int getEstimateValueBorder(int x1, int x2) {
double bias = ((double)text.length()) / (text.length() + value.length());
if(bias > 0.8) {
bias = 0.8;

public float getEstimateValueBorder(float x1, float x2) {
float bias = ((float) text.length()) / (text.length() + value.length());
if (bias > 0.8f) {
bias = 0.8f;
}
if(bias < 0.2){
bias = 0.2;
if (bias < 0.2f) {
bias = 0.2f;
}
return (int)(bias * (x2 - x1) + x1);
return (bias * (x2 - x1) + x1);
}

public int colorToFullAlpha(int color) {
return (0xff000000 | color);
}
Expand Down
Loading

0 comments on commit 4de40e3

Please sign in to comment.