diff --git a/src/main/java/me/kawaiizenbo/moonlight/module/ModuleManager.java b/src/main/java/me/kawaiizenbo/moonlight/module/ModuleManager.java index e6f53e3..2c44331 100644 --- a/src/main/java/me/kawaiizenbo/moonlight/module/ModuleManager.java +++ b/src/main/java/me/kawaiizenbo/moonlight/module/ModuleManager.java @@ -14,7 +14,8 @@ public class ModuleManager registerModules( new Fly(), new NoFall(), - new HUDModule() + new HUDModule(), + new TestDisplay() ); } diff --git a/src/main/java/me/kawaiizenbo/moonlight/module/Module_.java b/src/main/java/me/kawaiizenbo/moonlight/module/Module_.java index 6e36f8c..41fd06a 100644 --- a/src/main/java/me/kawaiizenbo/moonlight/module/Module_.java +++ b/src/main/java/me/kawaiizenbo/moonlight/module/Module_.java @@ -1,5 +1,8 @@ package me.kawaiizenbo.moonlight.module; +import java.util.ArrayList; + +import me.kawaiizenbo.moonlight.module.settings.Setting; import net.minecraft.client.MinecraftClient; public abstract class Module_ @@ -9,12 +12,15 @@ public abstract class Module_ public String description; public Category category; public boolean enabled; + public ArrayList settings; + public int keyBind; public Module_(String name, String description, Category category) { this.name = name; this.description = description; this.category = category; + settings = new ArrayList<>(); } public void onEnable() {} diff --git a/src/main/java/me/kawaiizenbo/moonlight/module/modules/TestDisplay.java b/src/main/java/me/kawaiizenbo/moonlight/module/modules/TestDisplay.java new file mode 100644 index 0000000..6e85441 --- /dev/null +++ b/src/main/java/me/kawaiizenbo/moonlight/module/modules/TestDisplay.java @@ -0,0 +1,18 @@ +package me.kawaiizenbo.moonlight.module.modules; + +import me.kawaiizenbo.moonlight.module.Category; +import me.kawaiizenbo.moonlight.module.Module_; +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); + + public TestDisplay() + { + super("TestDisplay", "Test of settings window", Category.RENDER); + this.settings.add(test1); + this.settings.add(test2); + } +} diff --git a/src/main/java/me/kawaiizenbo/moonlight/module/settings/DoubleSetting.java b/src/main/java/me/kawaiizenbo/moonlight/module/settings/DoubleSetting.java new file mode 100644 index 0000000..1cd65d2 --- /dev/null +++ b/src/main/java/me/kawaiizenbo/moonlight/module/settings/DoubleSetting.java @@ -0,0 +1,50 @@ +package me.kawaiizenbo.moonlight.module.settings; + +import java.math.BigDecimal; +import java.math.RoundingMode; + +import net.minecraft.client.gui.DrawableHelper; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.text.Text; + +public class DoubleSetting extends Setting +{ + public double value; + private double min, max, increment; + + public DoubleSetting(String name, double value, double min, double max, double increment) + { + this.name = name; + this.value = value; + this.min = min; + this.max = max; + this.increment = increment; + } + + @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); + 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); + DrawableHelper.fill(matrices, x+2, y+16, (x+2)+scaledValue, y+18, 0xFF55FFFF); + 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(); + + BigDecimal bd = new BigDecimal(Double.toString(value)); + bd = bd.setScale(places, RoundingMode.HALF_UP); + return bd.doubleValue(); + } +} diff --git a/src/main/java/me/kawaiizenbo/moonlight/module/settings/Setting.java b/src/main/java/me/kawaiizenbo/moonlight/module/settings/Setting.java new file mode 100644 index 0000000..f8a5b9b --- /dev/null +++ b/src/main/java/me/kawaiizenbo/moonlight/module/settings/Setting.java @@ -0,0 +1,13 @@ +package me.kawaiizenbo.moonlight.module.settings; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.util.math.MatrixStack; + +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) { } +} diff --git a/src/main/java/me/kawaiizenbo/moonlight/ui/TextButton.java b/src/main/java/me/kawaiizenbo/moonlight/ui/TextButton.java new file mode 100644 index 0000000..14a4ddd --- /dev/null +++ b/src/main/java/me/kawaiizenbo/moonlight/ui/TextButton.java @@ -0,0 +1,43 @@ +package me.kawaiizenbo.moonlight.ui; + +import me.kawaiizenbo.moonlight.ui.clickgui.ClickGUIScreen; +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 TextButton +{ + String text; + int x, y, color, width; + + public TextButton(String text, int x, int y, int color) + { + this.text = text; + this.x = x; + this.y = y; + this.color = color; + } + + public void render(MatrixStack matrices, TextRenderer textRenderer, int mouseX, int mouseY) + { + width = textRenderer.getWidth(text); + DrawableHelper.fill(matrices, x-1, y-1, x + width + 1, y + 10, hovered(mouseX, mouseY) ? 0xFF444444 : 0xFF222222); + DrawableHelper.drawTextWithShadow(matrices, textRenderer, Text.literal(text), x, y, color); + } + + public boolean hovered(int mouseX, int mouseY) + { + return mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + 10; + } + + public void mouseClicked(int mouseX, int mouseY) + { + if (hovered(mouseX, mouseY)) + { + // i have no clue how to pass a method so this is kind of stupid + MinecraftClient.getInstance().setScreen(ClickGUIScreen.INSTANCE); + } + } +} diff --git a/src/main/java/me/kawaiizenbo/moonlight/ui/altmanager/AltManagerScreen.java b/src/main/java/me/kawaiizenbo/moonlight/ui/altmanager/AltManagerScreen.java index 42486ab..28b8f91 100644 --- a/src/main/java/me/kawaiizenbo/moonlight/ui/altmanager/AltManagerScreen.java +++ b/src/main/java/me/kawaiizenbo/moonlight/ui/altmanager/AltManagerScreen.java @@ -1,6 +1,7 @@ package me.kawaiizenbo.moonlight.ui.altmanager; import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; public class AltManagerScreen extends Screen @@ -11,5 +12,11 @@ public class AltManagerScreen extends Screen { super(Text.literal("Alt Manager")); } + + @Override + public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) + { + renderBackgroundTexture(0); + } } diff --git a/src/main/java/me/kawaiizenbo/moonlight/ui/clickgui/ClickGUIScreen.java b/src/main/java/me/kawaiizenbo/moonlight/ui/clickgui/ClickGUIScreen.java index 2fbd184..4bb014e 100644 --- a/src/main/java/me/kawaiizenbo/moonlight/ui/clickgui/ClickGUIScreen.java +++ b/src/main/java/me/kawaiizenbo/moonlight/ui/clickgui/ClickGUIScreen.java @@ -24,8 +24,8 @@ public class ClickGUIScreen extends Screen yOffset = 25; for (Module_ module : ModuleManager.INSTANCE.getModulesByCategory(category)) { - moduleButtons.add(new ModuleButton(module, 9+(module.category.ordinal()*65), yOffset)); - yOffset += 10; + moduleButtons.add(new ModuleButton(module, 9+(module.category.ordinal()*70), yOffset)); + yOffset += 14; } } @@ -39,7 +39,7 @@ public class ClickGUIScreen extends Screen for (Category category : Category.values()) { textRenderer.draw(matrices, category.name, categoryLabelXOffset, 10, 0xFFFFFF); - categoryLabelXOffset += 65; + categoryLabelXOffset += 70; } for (ModuleButton moduleButton : moduleButtons) { diff --git a/src/main/java/me/kawaiizenbo/moonlight/ui/clickgui/ModuleButton.java b/src/main/java/me/kawaiizenbo/moonlight/ui/clickgui/ModuleButton.java index 41a8133..0eeba92 100644 --- a/src/main/java/me/kawaiizenbo/moonlight/ui/clickgui/ModuleButton.java +++ b/src/main/java/me/kawaiizenbo/moonlight/ui/clickgui/ModuleButton.java @@ -17,15 +17,15 @@ public class ModuleButton this.module = module; this.x = x; this.y = y; - this.width = 60; - this.height = 10; + this.width = 70; + this.height = 14; } public void render(MatrixStack matrices, int mouseX, int mouseY) { TextRenderer textRenderer = mc.textRenderer; DrawableHelper.fill(matrices, x, y, x + width, y + height, hovered(mouseX, mouseY) ? 0xFF333333 : 0xFF222222); - textRenderer.draw(matrices, module.name, x+1, y+1, module.enabled ? 0x55FFFF : 0xFFFFFF); + textRenderer.draw(matrices, module.name, x+3, y+3, module.enabled ? 0x55FFFF : 0xFFFFFF); } public boolean hovered(int mouseX, int mouseY) @@ -37,7 +37,14 @@ public class ModuleButton { if (hovered(mouseX, mouseY)) { - module.toggle(); + if (button == 0) + { + module.toggle(); + } + else if (button == 1) + { + MinecraftClient.getInstance().setScreen(new SettingsScreen(module)); + } } } } diff --git a/src/main/java/me/kawaiizenbo/moonlight/ui/clickgui/SettingsScreen.java b/src/main/java/me/kawaiizenbo/moonlight/ui/clickgui/SettingsScreen.java new file mode 100644 index 0000000..a4f5e73 --- /dev/null +++ b/src/main/java/me/kawaiizenbo/moonlight/ui/clickgui/SettingsScreen.java @@ -0,0 +1,53 @@ +package me.kawaiizenbo.moonlight.ui.clickgui; + +import me.kawaiizenbo.moonlight.module.Module_; +import me.kawaiizenbo.moonlight.module.settings.Setting; +import me.kawaiizenbo.moonlight.ui.TextButton; +import me.kawaiizenbo.moonlight.util.ColorUtils; +import net.minecraft.client.gui.DrawableHelper; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.text.Text; + +public class SettingsScreen extends Screen +{ + private Module_ module; + private TextButton backButton; + + protected SettingsScreen(Module_ module) + { + super(Text.literal("Settings")); + this.module = module; + backButton = new TextButton(ColorUtils.underline + "< Back", 112, 32, 0xFFFFFF); + } + + @Override + public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) + { + 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); + backButton.render(matrices, textRenderer, mouseX, mouseY); + int yOffset = 64; + for (Setting setting : module.settings) + { + setting.render(matrices, 117, yOffset, mouseX, mouseY); + yOffset += 32; + } + // add keybind setting here eventually + } + + @Override + public boolean shouldPause() + { + return false; + } + + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) + { + backButton.mouseClicked((int)mouseX, (int)mouseY); + return super.mouseClicked(mouseX, mouseY, button); + } +}