DoubleSetting working, new icon
This commit is contained in:
parent
0ebc2f3512
commit
95ed46fff0
6 changed files with 94 additions and 23 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue