diff --git a/src/main/java/me/kawaiizenbo/moonlight/module/ModuleManager.java b/src/main/java/me/kawaiizenbo/moonlight/module/ModuleManager.java index 2c44331..e6f53e3 100644 --- a/src/main/java/me/kawaiizenbo/moonlight/module/ModuleManager.java +++ b/src/main/java/me/kawaiizenbo/moonlight/module/ModuleManager.java @@ -14,8 +14,7 @@ public class ModuleManager registerModules( new Fly(), new NoFall(), - new HUDModule(), - new TestDisplay() + new HUDModule() ); } diff --git a/src/main/java/me/kawaiizenbo/moonlight/module/modules/TestDisplay.java b/src/main/java/me/kawaiizenbo/moonlight/module/modules/TestDisplay.java index 6e85441..7b7230f 100644 --- a/src/main/java/me/kawaiizenbo/moonlight/module/modules/TestDisplay.java +++ b/src/main/java/me/kawaiizenbo/moonlight/module/modules/TestDisplay.java @@ -6,8 +6,8 @@ import me.kawaiizenbo.moonlight.module.settings.DoubleSetting; public class TestDisplay extends Module_ { - DoubleSetting test1 = new DoubleSetting("test1", 1, 0, 20, 1); - DoubleSetting test2 = new DoubleSetting("test2", 0, 0, 1, 0.1); + DoubleSetting test1 = new DoubleSetting("test1", 1, 0, 20, 0); + DoubleSetting test2 = new DoubleSetting("test2", 0, 0, 1, 1); public TestDisplay() { diff --git a/src/main/java/me/kawaiizenbo/moonlight/module/settings/DoubleSetting.java b/src/main/java/me/kawaiizenbo/moonlight/module/settings/DoubleSetting.java index 1cd65d2..003b900 100644 --- a/src/main/java/me/kawaiizenbo/moonlight/module/settings/DoubleSetting.java +++ b/src/main/java/me/kawaiizenbo/moonlight/module/settings/DoubleSetting.java @@ -10,23 +10,40 @@ import net.minecraft.text.Text; public class DoubleSetting extends Setting { public double value; - private double min, max, increment; + private double min, max; + private int roundingPlace; - public DoubleSetting(String name, double value, double min, double max, double increment) + boolean sliding = false; + + public DoubleSetting(String name, double value, double min, double max, int roundingPlace) { this.name = name; this.value = value; this.min = min; this.max = max; - this.increment = increment; + this.roundingPlace = roundingPlace; } @Override public void render(MatrixStack matrices, int x, int y, int mouseX, int mouseY) - { - DrawableHelper.fill(matrices, x, y, x+192, y+24, hovered(mouseX, mouseY, x, y) ? 0xFF444444: 0xFF222222); - DrawableHelper.drawTextWithShadow(matrices, textRenderer, Text.literal(name), x+2, y+2, 0xFFFFFF); - String valueString = ""+round(value, 1); + { + super.render(matrices, x, y, mouseX, mouseY); + double diff = Math.min(100, Math.max(0, (mouseX - x)/1.9)); + + if (sliding) + { + if (diff == 0) + { + value = min; + } + else + { + double newValue = round(((diff / 100) * (max - min) + min), roundingPlace); + value = newValue; + } + } + + String valueString = ""+round(value, roundingPlace); DrawableHelper.drawTextWithShadow(matrices, textRenderer, Text.literal(valueString), (x+190)-textRenderer.getWidth(valueString), y+2, 0xFFFFFF); DrawableHelper.fill(matrices, x+2, y+16, x+190, y+18, 0xFF666666); int scaledValue = (int)((value/max)*190); @@ -34,11 +51,6 @@ public class DoubleSetting extends Setting DrawableHelper.fill(matrices, x+2+(scaledValue-1), y+14, x+2+(scaledValue+1), y+20, 0xFFFFFFFF); } - public boolean hovered(int mouseX, int mouseY, int x, int y) - { - return mouseX >= x && mouseX <= x + 192 && mouseY >= y && mouseY <= y + 24; - } - private static double round(double value, int places) { if (places < 0) throw new IllegalArgumentException(); @@ -47,4 +59,20 @@ public class DoubleSetting extends Setting bd = bd.setScale(places, RoundingMode.HALF_UP); return bd.doubleValue(); } + + @Override + public void mouseClicked(double mouseX, double mouseY, int button) + { + if (hovered((int)mouseX, (int)mouseY) && button == 0) + { + this.sliding = true; + } + } + + @Override + public void mouseReleased(double mouseX, double mouseY, int button) + { + sliding = false; + } + } diff --git a/src/main/java/me/kawaiizenbo/moonlight/module/settings/Setting.java b/src/main/java/me/kawaiizenbo/moonlight/module/settings/Setting.java index f8a5b9b..5eb9f89 100644 --- a/src/main/java/me/kawaiizenbo/moonlight/module/settings/Setting.java +++ b/src/main/java/me/kawaiizenbo/moonlight/module/settings/Setting.java @@ -2,12 +2,32 @@ package me.kawaiizenbo.moonlight.module.settings; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.DrawableHelper; import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.text.Text; public class Setting { public String name; protected TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer; - public void render(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { } + int x = 0, y = 0; + public void render(MatrixStack matrices, int x, int y, int mouseX, int mouseY) + { + this.x = x; + this.y = y; + DrawableHelper.fill(matrices, x, y, x+192, y+24, hovered(mouseX, mouseY) ? 0xFF444444: 0xFF222222); + DrawableHelper.drawTextWithShadow(matrices, textRenderer, Text.literal(name), x+2, y+2, 0xFFFFFF); + } + + public void mouseClicked(double mouseX, double mouseY, int button) { } + + public void mouseReleased(double mouseX, double mouseY, int button) { } + + public void keyPressed(int keyCode, int scanCode, int modifiers) { } + + protected boolean hovered(int mouseX, int mouseY) + { + return mouseX >= x && mouseX <= x + 192 && mouseY >= y && mouseY <= y + 24; + } } diff --git a/src/main/java/me/kawaiizenbo/moonlight/ui/clickgui/SettingsScreen.java b/src/main/java/me/kawaiizenbo/moonlight/ui/clickgui/SettingsScreen.java index a4f5e73..4e9a4d6 100644 --- a/src/main/java/me/kawaiizenbo/moonlight/ui/clickgui/SettingsScreen.java +++ b/src/main/java/me/kawaiizenbo/moonlight/ui/clickgui/SettingsScreen.java @@ -18,7 +18,6 @@ public class SettingsScreen extends Screen { super(Text.literal("Settings")); this.module = module; - backButton = new TextButton(ColorUtils.underline + "< Back", 112, 32, 0xFFFFFF); } @Override @@ -26,14 +25,15 @@ public class SettingsScreen extends Screen { this.renderBackground(matrices); DrawableHelper.fill(matrices, (width/2)-112, (height/2)-96, (width/2)+112, (height/2)+96, 0xFF222222); - DrawableHelper.drawCenteredText(matrices, textRenderer, module.name, width/2, 32, 0xFFFFFF); - DrawableHelper.drawTextWithShadow(matrices, textRenderer, Text.literal(module.description), 112, 48, 0xFFFFFF); + DrawableHelper.drawCenteredText(matrices, textRenderer, module.name, width/2, (height/2)-88, 0xFFFFFF); + DrawableHelper.drawTextWithShadow(matrices, textRenderer, Text.literal(module.description), (width/2)-104, (height/2)-72, 0xFFFFFF); + backButton = new TextButton(ColorUtils.underline + "< Back", (width/2)-104, (height/2)-88, 0xFFFFFF); backButton.render(matrices, textRenderer, mouseX, mouseY); - int yOffset = 64; + int yOffset = (height/2)-56; for (Setting setting : module.settings) { - setting.render(matrices, 117, yOffset, mouseX, mouseY); - yOffset += 32; + setting.render(matrices, (width/2)-96, yOffset, mouseX, mouseY); + yOffset += 25; } // add keybind setting here eventually } @@ -48,6 +48,30 @@ public class SettingsScreen extends Screen public boolean mouseClicked(double mouseX, double mouseY, int button) { backButton.mouseClicked((int)mouseX, (int)mouseY); + for (Setting setting : module.settings) + { + setting.mouseClicked(mouseX, mouseY, button); + } return super.mouseClicked(mouseX, mouseY, button); } + + @Override + public boolean mouseReleased(double mouseX, double mouseY, int button) + { + for (Setting setting : module.settings) + { + setting.mouseReleased(mouseX, mouseY, button); + } + return super.mouseReleased(mouseX, mouseY, button); + } + + @Override + public boolean keyPressed(int keyCode, int scanCode, int modifiers) + { + for (Setting setting : module.settings) + { + setting.keyPressed(keyCode, scanCode, modifiers); + } + return super.keyPressed(keyCode, scanCode, modifiers); + } } diff --git a/src/main/resources/assets/moonlight/icon.png b/src/main/resources/assets/moonlight/icon.png index 7ef1bf4..0673fd9 100644 Binary files a/src/main/resources/assets/moonlight/icon.png and b/src/main/resources/assets/moonlight/icon.png differ