DoubleSetting working, new icon
This commit is contained in:
parent
0ebc2f3512
commit
95ed46fff0
6 changed files with 94 additions and 23 deletions
|
@ -14,8 +14,7 @@ public class ModuleManager
|
|||
registerModules(
|
||||
new Fly(),
|
||||
new NoFall(),
|
||||
new HUDModule(),
|
||||
new TestDisplay()
|
||||
new HUDModule()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue