Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/java/dev/goldforge/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public static synchronized void load(){
String key="module."+module.name+"."+field.getName();
try{
if(field.getType()==int.class&&VALUES.containsKey(key))field.setInt(module,parseInt(key,field.getInt(module)));
else if(field.getType()==float.class&&VALUES.containsKey(key))field.setFloat(module,parseFloat(key,field.getFloat(module)));
else if(field.getType()==double.class&&VALUES.containsKey(key))field.setDouble(module,parseDouble(key,field.getDouble(module)));
else if(field.getType()==boolean.class&&VALUES.containsKey(key))field.setBoolean(module,Boolean.parseBoolean(VALUES.getProperty(key)));
else if(field.getType()==String.class&&VALUES.containsKey(key))field.set(module,VALUES.getProperty(key,""));
}catch(IllegalAccessException ignored){}
Expand Down Expand Up @@ -74,6 +76,8 @@ public static synchronized void save(){
try{
String key="module."+module.name+"."+field.getName();
if(field.getType()==int.class)VALUES.setProperty(key,Integer.toString(field.getInt(module)));
else if(field.getType()==float.class)VALUES.setProperty(key,Float.toString(field.getFloat(module)));
else if(field.getType()==double.class)VALUES.setProperty(key,Double.toString(field.getDouble(module)));
else if(field.getType()==boolean.class)VALUES.setProperty(key,Boolean.toString(field.getBoolean(module)));
else if(field.getType()==String.class)VALUES.setProperty(key,(String)field.get(module));
}catch(IllegalAccessException ignored){}
Expand Down Expand Up @@ -132,5 +136,8 @@ private static Path profilePath(String name){
private static String serverProfileName(){net.minecraft.client.multiplayer.ServerData server=Minecraft.getMinecraft().getCurrentServerData();if(server==null||server.serverIP==null||server.serverIP.trim().isEmpty())return null;return "server-"+String.format(java.util.Locale.ROOT,"%08x",server.serverIP.trim().toLowerCase(java.util.Locale.ROOT).hashCode());}
private static int getInt(String key,int fallback){return parseInt(key,fallback);}
private static int parseInt(String key,int fallback){try{return Integer.parseInt(VALUES.getProperty(key));}catch(Exception ignored){return fallback;}}
private static float parseFloat(String key,float fallback){try{return Float.parseFloat(VALUES.getProperty(key));}catch(Exception ignored){return fallback;}}
private static double parseDouble(String key,double fallback){try{return Double.parseDouble(VALUES.getProperty(key));}catch(Exception ignored){return fallback;}}
private static boolean getBoolean(String key,boolean fallback){String value=VALUES.getProperty(key);return value==null?fallback:Boolean.parseBoolean(value);}
}

4 changes: 3 additions & 1 deletion src/main/java/dev/goldforge/gui/BackspaceMainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ public final class BackspaceMainMenu extends GuiScreen {
}
GlStateManager.popMatrix();
if (height >= 300) {
label("DEV 3.5 BETA", left + 2, (int)(titleY + 34F), fadeAlpha(MUTED, menuFade), 9F);
label(GoldForge.VERSION.toUpperCase(java.util.Locale.ROOT).replace('-', ' '),
left + 2, (int)(titleY + 34F), fadeAlpha(MUTED, menuFade), 9F);
label("A CLEANER WAY TO PLAY", left + 2, (int)(titleY + 54F), fadeAlpha(0xFF777A83, menuFade), 9F);
}

Expand Down Expand Up @@ -394,3 +395,4 @@ private static int blendColor(int from, int to, float amount) {
}
private static int fadeAlpha(int color, float alpha) { return (Math.max(0, Math.min(255, Math.round(((color >>> 24) & 255) * alpha))) << 24) | (color & 0x00FFFFFF); }
}

8 changes: 5 additions & 3 deletions src/main/java/dev/goldforge/gui/GuiPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public final class GuiPreferences {
public static int layout = 1;
public static int theme = 0; // gold, red, mint, blue
public static int pixelOpacity = 160;
public static int pixelTransparency = 37; // 0 is opaque; 100 reveals the world
public static final int[] panelX = new int[Category.values().length];
public static final int[] panelY = new int[Category.values().length];
public static final boolean[] collapsed = new boolean[Category.values().length];
Expand All @@ -17,7 +17,9 @@ private GuiPreferences() {}
public static void load(Properties values) {
layout = clamp(read(values, "gui.layout", layout), 0, 1);
theme = clamp(read(values, "gui.theme", theme), 0, 3);
pixelOpacity = clamp(read(values, "gui.pixel.opacity", pixelOpacity), 32, 255);
pixelTransparency = values.containsKey("gui.pixel.transparency")
? clamp(read(values, "gui.pixel.transparency", pixelTransparency), 0, 100)
: clamp(100 - Math.round(read(values, "gui.pixel.opacity", 160) * 100F / 255F), 0, 100);
for (Category category : Category.values()) {
String prefix = "gui.panel." + category.name().toLowerCase(java.util.Locale.ROOT) + ".";
int index = category.ordinal();
Expand All @@ -29,7 +31,7 @@ public static void load(Properties values) {
public static void save(Properties values) {
values.setProperty("gui.layout", Integer.toString(clamp(layout, 0, 1)));
values.setProperty("gui.theme", Integer.toString(clamp(theme, 0, 3)));
values.setProperty("gui.pixel.opacity", Integer.toString(clamp(pixelOpacity, 32, 255)));
values.setProperty("gui.pixel.transparency", Integer.toString(clamp(pixelTransparency, 0, 100)));
for (Category category : Category.values()) {
String prefix = "gui.panel." + category.name().toLowerCase(java.util.Locale.ROOT) + ".";
int index = category.ordinal();
Expand Down
86 changes: 78 additions & 8 deletions src/main/java/dev/goldforge/gui/ModernClickGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@
import dev.goldforge.module.impl.ShaderFX;
import net.minecraft.client.gui.GuiScreen;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;

import java.nio.IntBuffer;
import java.util.ArrayList;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Locale;

Expand Down Expand Up @@ -66,8 +70,18 @@ public final class ModernClickGui extends OneUIScreen {
private int settingsScroll;
private boolean inspectorHovered;
private String hoveredSettingName;
private ModuleSetting draggingSetting;
private float draggingTrackX, draggingTrackWidth;
private final IdentityHashMap<ModuleSetting, Marquee> settingMarquees = new IdentityHashMap<ModuleSetting, Marquee>();
private long lastFrame;
private float frameSeconds;
private long openedAt;

private static final class Marquee {
float offset, timer;
int phase;
}

public ModernClickGui() { this(null); }

public ModernClickGui(GuiScreen parent) {
Expand All @@ -85,7 +99,16 @@ public ModernClickGui(GuiScreen parent) {
@Override public boolean hasBackgroundBlur() { return true; }

@Override public void draw(long vg, float partialTicks, InputHandler input) {
long now = System.nanoTime();
frameSeconds = lastFrame == 0 ? 0 : Math.min(0.05F, (now - lastFrame) / 1000000000F);
lastFrame = now;
NanoVGHelper nvg = NanoVGHelper.INSTANCE;
if (draggingSetting != null) {
if (Mouse.isButtonDown(0))
draggingSetting.setFraction((Mouse.getX() * width / (double) mc.displayWidth
- draggingTrackX) / draggingTrackWidth);
else { ConfigManager.save(); draggingSetting = null; }
}
float alpha = Math.min(1F, (System.currentTimeMillis() - openedAt) / 170F);
// Keep the browser substantial without turning it into a full-screen
// overlay at lower Minecraft GUI scales.
Expand Down Expand Up @@ -156,7 +179,8 @@ private void drawBrand(long vg, float x, float y) {
float spaceX = titleX + nvg.getTextWidth(vg, "back", HEADER_TITLE_SIZE, Fonts.REGULAR);
text(vg, "back", titleX, titleY, HEADER_TITLE_SIZE, TEXT);
text(vg, "space", spaceX, titleY, HEADER_TITLE_SIZE, YELLOW);
text(vg, "DEV 3.5 BETA", titleX, titleY + HEADER_SUBTITLE_GAP, HEADER_SUBTITLE_SIZE, MUTED);
text(vg, GoldForge.VERSION.toUpperCase(java.util.Locale.ROOT).replace('-', ' '),
titleX, titleY + HEADER_SUBTITLE_GAP, HEADER_SUBTITLE_SIZE, MUTED);
}

private void drawHeader(long vg, InputHandler input, float x, float y, float width) {
Expand Down Expand Up @@ -352,19 +376,64 @@ private void drawInspector(long vg, InputHandler input, float x, float y, float
float sy = settingsY + 16F + (i - settingsScroll) * 37F;
ModuleSetting setting = settings.get(i);
nvg.drawRoundedRect(vg, x + 14F, sy, w - 28F, 31F, CARD, 9F);
if (input.isAreaHovered(x + 14F, sy, w - 28F, 31F)) hoveredSettingName = setting.name;
boolean rowHovered = input.isAreaHovered(x + 14F, sy, w - 28F, 31F);
if (rowHovered) hoveredSettingName = setting.name;
String rowLabel = selectedModule instanceof Phase && "Phase mode".equals(setting.name)
? "Mode: " + Phase.modeName(((Phase) selectedModule).mode) : setting.name;
text(vg, trim(vg, rowLabel, w - 112F, 11F), x + 24F, sy + 10F, 11F, TEXT);
text(vg, "−", x + w - 80F, sy + 7F, 16F, YELLOW);
textRight(vg, Integer.toString(setting.get()), x + w - 42F, sy + 10F, 11F, TEXT);
text(vg, "+", x + w - 30F, sy + 7F, 16F, YELLOW);
if (input.isAreaClicked(x + w - 89F, sy, 25F, 31F)) setting.adjust(-1);
else if (input.isAreaClicked(x + w - 34F, sy, 25F, 31F)) setting.adjust(1);
marqueeSetting(vg, setting, rowLabel, x + 24F, sy + 4F, w - 92F, rowHovered);
textRight(vg, setting.formattedValue(), x + w - 24F, sy + 4F, 11F, YELLOW);
float trackX = x + 24F, trackWidth = w - 48F;
nvg.drawRect(vg, trackX, sy + 23F, trackWidth, 4F, STROKE);
nvg.drawRect(vg, trackX, sy + 23F, trackWidth * (float) setting.fraction(), 4F, YELLOW);
if (input.isAreaHovered(trackX, sy + 20F, trackWidth, 11F))
nvg.drawRect(vg, trackX, sy + 20F, trackWidth, 1F, YELLOW_DARK);
if (input.isAreaClicked(trackX, sy + 18F, trackWidth, 13F)) {
draggingSetting = setting;
draggingTrackX = trackX;
draggingTrackWidth = trackWidth;
setting.setFraction((Mouse.getX() * width / (double) mc.displayWidth - trackX) / trackWidth);
}
}
popClip();
}

private void marqueeSetting(long vg, ModuleSetting setting, String label,
float x, float y, float available, boolean hovered) {
float overflow = NanoVGHelper.INSTANCE.getTextWidth(vg, label, 11F, Fonts.REGULAR) - available;
if (overflow <= 0F) { text(vg, label, x, y, 11F, TEXT); return; }
Marquee state = settingMarquees.get(setting);
if (state == null) { state = new Marquee(); settingMarquees.put(setting, state); }
state.offset = Math.min(state.offset, overflow);
if (!hovered) {
state.phase = 0; state.timer = 0;
state.offset *= (float) Math.exp(-11F * frameSeconds);
if (state.offset < 0.5F) state.offset = 0;
} else if (state.phase == 0) {
state.timer += frameSeconds;
if (state.timer >= 0.45F) { state.phase = 1; state.timer = 0; }
} else if (state.phase == 1) {
state.offset += (overflow - state.offset) * (1F - (float) Math.exp(-2.8F * frameSeconds));
if (overflow - state.offset < 0.5F) { state.offset = overflow; state.phase = 2; state.timer = 0; }
} else if (state.phase == 2) {
state.timer += frameSeconds;
if (state.timer >= 0.8F) state.phase = 3;
} else {
state.offset *= (float) Math.exp(-5F * frameSeconds);
if (state.offset < 0.5F) { state.offset = 0; state.phase = 0; state.timer = 0; }
}
IntBuffer previous = BufferUtils.createIntBuffer(4);
GL11.glGetInteger(GL11.GL_SCISSOR_BOX, previous);
float scaleX = mc.displayWidth / Math.max(1F, width);
float scaleY = mc.displayHeight / Math.max(1F, height);
int left = Math.max(previous.get(0), Math.round(x * scaleX));
int bottom = Math.max(previous.get(1), Math.round((height - y - 12F) * scaleY));
int right = Math.min(previous.get(0) + previous.get(2), Math.round((x + available) * scaleX));
int top = Math.min(previous.get(1) + previous.get(3), Math.round((height - y) * scaleY));
GL11.glScissor(left, bottom, Math.max(0, right - left), Math.max(0, top - bottom));
text(vg, label, x - state.offset, y, 11F, TEXT);
GL11.glScissor(previous.get(0), previous.get(1), previous.get(2), previous.get(3));
}

private void action(long vg, InputHandler input, float x, float y, float w, String label, String value) {
NanoVGHelper nvg = NanoVGHelper.INSTANCE;
boolean hover = input.isAreaHovered(x, y, w, 31F);
Expand Down Expand Up @@ -550,3 +619,4 @@ private void text(long vg, String value, float x, float y, float size, int color
private void textCentered(long vg, String value, float x, float y, float size, int color) { NanoVGHelper.INSTANCE.drawCenteredText(vg, value, x, y, color, size, Fonts.REGULAR); }
private void textRight(long vg, String value, float right, float y, float size, int color) { text(vg, value, right - NanoVGHelper.INSTANCE.getTextWidth(vg, value, size, Fonts.REGULAR), y, size, color); }
}

Loading
Loading