start of settings, slightly broken
This commit is contained in:
parent
411790540a
commit
0ebc2f3512
10 changed files with 206 additions and 8 deletions
|
@ -14,7 +14,8 @@ public class ModuleManager
|
|||
registerModules(
|
||||
new Fly(),
|
||||
new NoFall(),
|
||||
new HUDModule()
|
||||
new HUDModule(),
|
||||
new TestDisplay()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Setting> 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() {}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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) { }
|
||||
}
|
43
src/main/java/me/kawaiizenbo/moonlight/ui/TextButton.java
Normal file
43
src/main/java/me/kawaiizenbo/moonlight/ui/TextButton.java
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
@ -12,4 +13,10 @@ public class AltManagerScreen extends Screen
|
|||
super(Text.literal("Alt Manager"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta)
|
||||
{
|
||||
renderBackgroundTexture(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
|
@ -36,8 +36,15 @@ public class ModuleButton
|
|||
public void mouseClicked(int mouseX, int mouseY, int button)
|
||||
{
|
||||
if (hovered(mouseX, mouseY))
|
||||
{
|
||||
if (button == 0)
|
||||
{
|
||||
module.toggle();
|
||||
}
|
||||
else if (button == 1)
|
||||
{
|
||||
MinecraftClient.getInstance().setScreen(new SettingsScreen(module));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue