stringsetting fully functional
This commit is contained in:
parent
72eb688172
commit
4b1e0b4fa9
4 changed files with 432 additions and 34 deletions
|
@ -19,9 +19,9 @@ public class BooleanSetting extends Setting
|
|||
{
|
||||
super.render(drawContext, x, y, mouseX, mouseY, textRenderer);
|
||||
drawContext.drawTextWithShadow(textRenderer, Text.literal(name), x+2, y+8, 0xFFFFFF);
|
||||
drawContext.fill(x+175, y+7, x+185, y+17, 0xFFFFFFFF);
|
||||
drawContext.fill(x+176, y+8, x+184, y+16, 0xFF222222);
|
||||
drawContext.fill(x+177, y+9, x+183, y+15, value ? 0xFF55FFFF : 0xFF222222);
|
||||
drawContext.fill(x+180, y+7, x+190, y+17, 0xFFFFFFFF);
|
||||
drawContext.fill(x+181, y+8, x+189, y+16, 0xFF222222);
|
||||
drawContext.fill(x+182, y+9, x+188, y+15, value ? 0xFF55FFFF : 0xFF222222);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -26,7 +26,7 @@ public class DoubleSetting extends Setting
|
|||
public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY, TextRenderer textRenderer)
|
||||
{
|
||||
super.render(drawContext, x, y, mouseX, mouseY, textRenderer);
|
||||
drawContext.drawTextWithShadow(textRenderer, Text.literal(name), x+2, y+2, 0xFFFFFF);
|
||||
drawContext.drawTextWithShadow(textRenderer, Text.literal(name), x+2, y+4, 0xFFFFFF);
|
||||
double diff = Math.min(100, Math.max(0, (mouseX - x)/1.9));
|
||||
|
||||
if (sliding)
|
||||
|
@ -43,7 +43,7 @@ public class DoubleSetting extends Setting
|
|||
}
|
||||
|
||||
String valueString = ""+MathUtils.round(value, roundingPlace);
|
||||
drawContext.drawTextWithShadow(textRenderer, Text.literal(valueString), (x+190)-textRenderer.getWidth(valueString), y+2, 0xFFFFFF);
|
||||
drawContext.drawTextWithShadow(textRenderer, Text.literal(valueString), (x+190)-textRenderer.getWidth(valueString), y+4, 0xFFFFFF);
|
||||
drawContext.fill(x+2, y+16, x+190, y+18, 0xFF666666);
|
||||
int scaledValue = (int)((value/max)*190);
|
||||
drawContext.fill(x+2, y+16, (x+2)+scaledValue, y+18, 0xFF55FFFF);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package me.kawaiizenbo.moonlight.module.settings;
|
||||
|
||||
import me.kawaiizenbo.moonlight.util.KeycodeUtils;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.text.Text;
|
||||
|
@ -7,6 +8,7 @@ import net.minecraft.text.Text;
|
|||
public class StringSetting extends Setting
|
||||
{
|
||||
public String value;
|
||||
private boolean focused = false;
|
||||
|
||||
public StringSetting(String name, String value)
|
||||
{
|
||||
|
@ -18,9 +20,52 @@ public class StringSetting extends Setting
|
|||
public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY, TextRenderer textRenderer)
|
||||
{
|
||||
super.render(drawContext, x, y, mouseX, mouseY, textRenderer);
|
||||
drawContext.drawTextWithShadow(textRenderer, Text.literal(name), x+2, y+4, 0xFFFFFF);
|
||||
drawContext.drawTextWithShadow(textRenderer, Text.literal(name), x+2, y+8, 0xFFFFFF);
|
||||
int twidth = textRenderer.getWidth(value);
|
||||
drawContext.drawTextWithShadow(textRenderer, value, x+190-twidth, y+4, 0xFFFFFF);
|
||||
drawContext.drawTextWithShadow(textRenderer, "WIP, please use the .setting command", x+2, y+14, 0xFFFFFF);
|
||||
drawContext.fill(x+96, y+5, x+190, y+19, 0xFFFFFFFF);
|
||||
drawContext.fill(x+97, y+6, x+189, y+18, 0xFF222222);
|
||||
int cursorPos = x+98+twidth;
|
||||
if (focused) drawContext.fill(cursorPos, y+7, cursorPos+1, y+17, 0xFF55FFFF);
|
||||
drawContext.drawTextWithShadow(textRenderer, value, x+98, y+8, 0xFFFFFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(double mouseX, double mouseY, int button)
|
||||
{
|
||||
if (focused)
|
||||
{
|
||||
focused = false;
|
||||
return;
|
||||
}
|
||||
if (hovered((int)mouseX, (int)mouseY) && button == 0)
|
||||
{
|
||||
focused = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(int keyCode, int scanCode, int modifiers)
|
||||
{
|
||||
if (focused)
|
||||
{
|
||||
if (keyCode == 256 || keyCode == 257)
|
||||
{
|
||||
// escape or enter was pressed, exit safely
|
||||
focused = false;
|
||||
return;
|
||||
}
|
||||
if (keyCode == 259)
|
||||
{
|
||||
// backspace, remove a character
|
||||
if (value.length() > 0) value = value.substring(0, value.length() - 1);
|
||||
return;
|
||||
}
|
||||
if (keyCode > 96) return; // not a typing key
|
||||
String append = KeycodeUtils.keyTable[keyCode];
|
||||
if (modifiers == 1) append = KeycodeUtils.shiftedKeyTable[keyCode];
|
||||
if (append == "Unknown") return;
|
||||
if (append == "Space") append = " ";
|
||||
value += append;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue