start of settings, slightly broken

This commit is contained in:
kawaiizenbo 2022-12-07 22:10:48 -07:00
parent 411790540a
commit 0ebc2f3512
10 changed files with 206 additions and 8 deletions

View file

@ -14,7 +14,8 @@ public class ModuleManager
registerModules(
new Fly(),
new NoFall(),
new HUDModule()
new HUDModule(),
new TestDisplay()
);
}

View file

@ -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() {}

View file

@ -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);
}
}

View file

@ -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();
}
}

View file

@ -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) { }
}