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(
|
registerModules(
|
||||||
new Fly(),
|
new Fly(),
|
||||||
new NoFall(),
|
new NoFall(),
|
||||||
new HUDModule(),
|
new HUDModule()
|
||||||
new TestDisplay()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@ import me.kawaiizenbo.moonlight.module.settings.DoubleSetting;
|
||||||
|
|
||||||
public class TestDisplay extends Module_
|
public class TestDisplay extends Module_
|
||||||
{
|
{
|
||||||
DoubleSetting test1 = new DoubleSetting("test1", 1, 0, 20, 1);
|
DoubleSetting test1 = new DoubleSetting("test1", 1, 0, 20, 0);
|
||||||
DoubleSetting test2 = new DoubleSetting("test2", 0, 0, 1, 0.1);
|
DoubleSetting test2 = new DoubleSetting("test2", 0, 0, 1, 1);
|
||||||
|
|
||||||
public TestDisplay()
|
public TestDisplay()
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,23 +10,40 @@ import net.minecraft.text.Text;
|
||||||
public class DoubleSetting extends Setting
|
public class DoubleSetting extends Setting
|
||||||
{
|
{
|
||||||
public double value;
|
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.name = name;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.min = min;
|
this.min = min;
|
||||||
this.max = max;
|
this.max = max;
|
||||||
this.increment = increment;
|
this.roundingPlace = roundingPlace;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(MatrixStack matrices, int x, int y, int mouseX, int mouseY)
|
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);
|
super.render(matrices, x, y, mouseX, mouseY);
|
||||||
DrawableHelper.drawTextWithShadow(matrices, textRenderer, Text.literal(name), x+2, y+2, 0xFFFFFF);
|
double diff = Math.min(100, Math.max(0, (mouseX - x)/1.9));
|
||||||
String valueString = ""+round(value, 1);
|
|
||||||
|
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.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);
|
DrawableHelper.fill(matrices, x+2, y+16, x+190, y+18, 0xFF666666);
|
||||||
int scaledValue = (int)((value/max)*190);
|
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);
|
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)
|
private static double round(double value, int places)
|
||||||
{
|
{
|
||||||
if (places < 0) throw new IllegalArgumentException();
|
if (places < 0) throw new IllegalArgumentException();
|
||||||
|
@ -47,4 +59,20 @@ public class DoubleSetting extends Setting
|
||||||
bd = bd.setScale(places, RoundingMode.HALF_UP);
|
bd = bd.setScale(places, RoundingMode.HALF_UP);
|
||||||
return bd.doubleValue();
|
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.MinecraftClient;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
import net.minecraft.client.font.TextRenderer;
|
||||||
|
import net.minecraft.client.gui.DrawableHelper;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
public class Setting
|
public class Setting
|
||||||
{
|
{
|
||||||
public String name;
|
public String name;
|
||||||
protected TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ public class SettingsScreen extends Screen
|
||||||
{
|
{
|
||||||
super(Text.literal("Settings"));
|
super(Text.literal("Settings"));
|
||||||
this.module = module;
|
this.module = module;
|
||||||
backButton = new TextButton(ColorUtils.underline + "< Back", 112, 32, 0xFFFFFF);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -26,14 +25,15 @@ public class SettingsScreen extends Screen
|
||||||
{
|
{
|
||||||
this.renderBackground(matrices);
|
this.renderBackground(matrices);
|
||||||
DrawableHelper.fill(matrices, (width/2)-112, (height/2)-96, (width/2)+112, (height/2)+96, 0xFF222222);
|
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.drawCenteredText(matrices, textRenderer, module.name, width/2, (height/2)-88, 0xFFFFFF);
|
||||||
DrawableHelper.drawTextWithShadow(matrices, textRenderer, Text.literal(module.description), 112, 48, 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);
|
backButton.render(matrices, textRenderer, mouseX, mouseY);
|
||||||
int yOffset = 64;
|
int yOffset = (height/2)-56;
|
||||||
for (Setting setting : module.settings)
|
for (Setting setting : module.settings)
|
||||||
{
|
{
|
||||||
setting.render(matrices, 117, yOffset, mouseX, mouseY);
|
setting.render(matrices, (width/2)-96, yOffset, mouseX, mouseY);
|
||||||
yOffset += 32;
|
yOffset += 25;
|
||||||
}
|
}
|
||||||
// add keybind setting here eventually
|
// add keybind setting here eventually
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,30 @@ public class SettingsScreen extends Screen
|
||||||
public boolean mouseClicked(double mouseX, double mouseY, int button)
|
public boolean mouseClicked(double mouseX, double mouseY, int button)
|
||||||
{
|
{
|
||||||
backButton.mouseClicked((int)mouseX, (int)mouseY);
|
backButton.mouseClicked((int)mouseX, (int)mouseY);
|
||||||
|
for (Setting setting : module.settings)
|
||||||
|
{
|
||||||
|
setting.mouseClicked(mouseX, mouseY, button);
|
||||||
|
}
|
||||||
return super.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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 16 KiB |
Loading…
Add table
Reference in a new issue