mirror of
https://github.com/Shiewk/Widgets.git
synced 2026-04-28 11:34:17 +02:00
Add direction to Coordinates widget & new short direction modes (#7)
This commit is contained in:
@@ -2,6 +2,7 @@ package de.shiewk.widgets.widgets;
|
|||||||
|
|
||||||
import de.shiewk.widgets.WidgetSettings;
|
import de.shiewk.widgets.WidgetSettings;
|
||||||
import de.shiewk.widgets.color.GradientOptions;
|
import de.shiewk.widgets.color.GradientOptions;
|
||||||
|
import de.shiewk.widgets.widgets.settings.EnumWidgetSetting;
|
||||||
import de.shiewk.widgets.widgets.settings.GradientWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.GradientWidgetSetting;
|
||||||
import de.shiewk.widgets.widgets.settings.IntSliderWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.IntSliderWidgetSetting;
|
||||||
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
||||||
@@ -15,82 +16,98 @@ import net.minecraft.util.Identifier;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static net.minecraft.text.Text.translatable;
|
||||||
|
|
||||||
public class CoordinatesWidget extends ResizableWidget {
|
public class CoordinatesWidget extends ResizableWidget {
|
||||||
public CoordinatesWidget(Identifier id) {
|
public CoordinatesWidget(Identifier id) {
|
||||||
super(id, List.of(
|
super(id, List.of(
|
||||||
new ToggleWidgetSetting("x", Text.translatable("widgets.widgets.coordinates.showX"), true),
|
new ToggleWidgetSetting("x", translatable("widgets.widgets.coordinates.showX"), true),
|
||||||
new ToggleWidgetSetting("y", Text.translatable("widgets.widgets.coordinates.showY"), true),
|
new ToggleWidgetSetting("y", translatable("widgets.widgets.coordinates.showY"), true),
|
||||||
new ToggleWidgetSetting("z", Text.translatable("widgets.widgets.coordinates.showZ"), true),
|
new ToggleWidgetSetting("z", translatable("widgets.widgets.coordinates.showZ"), true),
|
||||||
new GradientWidgetSetting("backgroundcolor", Text.translatable("widgets.widgets.basictext.background"), 0x50_00_00_00),
|
new ToggleWidgetSetting("direction", translatable("widgets.widgets.coordinates.showDirection"), false),
|
||||||
new GradientWidgetSetting("textcolor", Text.translatable("widgets.widgets.basictext.textcolor"), 0xffffffff),
|
new EnumWidgetSetting<>(
|
||||||
new IntSliderWidgetSetting("width", Text.translatable("widgets.widgets.basictext.width"), 10, WIDTH, 80*3),
|
"directionFormat",
|
||||||
new IntSliderWidgetSetting("paddingX", Text.translatable("widgets.widgets.basictext.paddingX"), 0, 5, 20),
|
translatable("widgets.widgets.coordinates.directionFormat"),
|
||||||
new IntSliderWidgetSetting("paddingY", Text.translatable("widgets.widgets.basictext.paddingY"), 0, 5, 20),
|
DirectionWidget.DisplayFormat.class,
|
||||||
new ToggleWidgetSetting("shadow", Text.translatable("widgets.widgets.basictext.textshadow"), true)
|
DirectionWidget.DisplayFormat.DIRECTION_YAW,
|
||||||
|
DirectionWidget.DisplayFormat::format
|
||||||
|
),
|
||||||
|
new GradientWidgetSetting("backgroundcolor", translatable("widgets.widgets.basictext.background"), 0x50_00_00_00),
|
||||||
|
new GradientWidgetSetting("textcolor", translatable("widgets.widgets.basictext.textcolor"), 0xffffffff),
|
||||||
|
new IntSliderWidgetSetting("width", translatable("widgets.widgets.basictext.width"), 10, WIDTH, 80*3),
|
||||||
|
new IntSliderWidgetSetting("paddingX", translatable("widgets.widgets.basictext.paddingX"), 0, 5, 20),
|
||||||
|
new IntSliderWidgetSetting("paddingY", translatable("widgets.widgets.basictext.paddingY"), 0, 5, 20),
|
||||||
|
new ToggleWidgetSetting("shadow", translatable("widgets.widgets.basictext.textshadow"), true)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String textX = "X", textY = "Y", textZ = "Z";
|
protected String textX = "X", textY = "Y", textZ = "Z", textDirection = "direction";
|
||||||
private int txc = 0, tyc = 0, tzc = 0;
|
protected int txc = 0, tyc = 0, tzc = 0, tdc = 0;
|
||||||
private boolean shadow = true;
|
protected boolean shadow = true;
|
||||||
|
protected DirectionWidget.DisplayFormat directionFormat;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderScaled(DrawContext context, long mt, TextRenderer textRenderer, int posX, int posY) {
|
public void renderScaled(DrawContext context, long mt, TextRenderer textRenderer, int posX, int posY) {
|
||||||
this.backgroundColor.fillHorizontal(context, mt, posX, posY, posX + width(), posY + height());
|
this.backgroundColor.fillHorizontal(context, mt, posX, posY, posX + width(), posY + height());
|
||||||
int y = this.paddingY;
|
int y = this.paddingY + 1;
|
||||||
if (showX){
|
if (showX){
|
||||||
y++;
|
|
||||||
this.textColor.drawText(context, textRenderer, mt, "X:", posX + paddingX, posY + y, shadow);
|
this.textColor.drawText(context, textRenderer, mt, "X:", posX + paddingX, posY + y, shadow);
|
||||||
this.textColor.drawText(context, textRenderer, mt, textX, posX + txc, posY + y, shadow);
|
this.textColor.drawText(context, textRenderer, mt, textX, posX + txc, posY + y, shadow);
|
||||||
y += textRenderer.fontHeight + 1;
|
y += 11;
|
||||||
}
|
}
|
||||||
if (showY){
|
if (showY){
|
||||||
y++;
|
|
||||||
this.textColor.drawText(context, textRenderer, mt, "Y:", posX + paddingX, posY + y, shadow);
|
this.textColor.drawText(context, textRenderer, mt, "Y:", posX + paddingX, posY + y, shadow);
|
||||||
this.textColor.drawText(context, textRenderer, mt, textY, posX + tyc, posY + y, shadow);
|
this.textColor.drawText(context, textRenderer, mt, textY, posX + tyc, posY + y, shadow);
|
||||||
y += textRenderer.fontHeight + 1;
|
y += 11;
|
||||||
}
|
}
|
||||||
if (showZ){
|
if (showZ){
|
||||||
y++;
|
|
||||||
this.textColor.drawText(context, textRenderer, mt, "Z:", posX + paddingX, posY + y, shadow);
|
this.textColor.drawText(context, textRenderer, mt, "Z:", posX + paddingX, posY + y, shadow);
|
||||||
this.textColor.drawText(context, textRenderer, mt, textZ, posX + tzc, posY + y, shadow);
|
this.textColor.drawText(context, textRenderer, mt, textZ, posX + tzc, posY + y, shadow);
|
||||||
|
y += 11;
|
||||||
|
}
|
||||||
|
if (showDirection){
|
||||||
|
this.textColor.drawText(context, textRenderer, mt, "D:", posX + paddingX, posY + y, shadow);
|
||||||
|
this.textColor.drawText(context, textRenderer, mt, textDirection, posX + tdc, posY + y, shadow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
|
final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
|
||||||
txc = width() - textRenderer.getWidth(textX) - paddingX;
|
|
||||||
tyc = width() - textRenderer.getWidth(textY) - paddingX;
|
|
||||||
tzc = width() - textRenderer.getWidth(textZ) - paddingX;
|
|
||||||
|
|
||||||
final ClientPlayerEntity player = MinecraftClient.getInstance().player;
|
final ClientPlayerEntity player = MinecraftClient.getInstance().player;
|
||||||
if (player == null){
|
if (player == null){
|
||||||
textX = "?";
|
textX = "?";
|
||||||
textY = "?";
|
textY = "?";
|
||||||
textZ = "?";
|
textZ = "?";
|
||||||
|
textDirection = "?";
|
||||||
} else {
|
} else {
|
||||||
textX = String.valueOf(player.getBlockX());
|
textX = String.valueOf(player.getBlockX());
|
||||||
textY = String.valueOf(player.getBlockY());
|
textY = String.valueOf(player.getBlockY());
|
||||||
textZ = String.valueOf(player.getBlockZ());
|
textZ = String.valueOf(player.getBlockZ());
|
||||||
|
textDirection = directionFormat.format().getString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
txc = width() - textRenderer.getWidth(textX) - paddingX;
|
||||||
|
tyc = width() - textRenderer.getWidth(textY) - paddingX;
|
||||||
|
tzc = width() - textRenderer.getWidth(textZ) - paddingX;
|
||||||
|
tdc = width() - textRenderer.getWidth(textDirection) - paddingX;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getName() {
|
public Text getName() {
|
||||||
return Text.translatable("widgets.widgets.coordinates");
|
return translatable("widgets.widgets.coordinates");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getDescription() {
|
public Text getDescription() {
|
||||||
return Text.translatable("widgets.widgets.coordinates.description");
|
return translatable("widgets.widgets.coordinates.description");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static final int WIDTH = 80, PADDING = 6;
|
protected static final int WIDTH = 80, PADDING = 6;
|
||||||
|
|
||||||
protected GradientOptions backgroundColor, textColor;
|
protected GradientOptions backgroundColor, textColor;
|
||||||
protected int paddingX = PADDING, paddingY = PADDING, width = WIDTH;
|
protected int paddingX = PADDING, paddingY = PADDING, width = WIDTH;
|
||||||
protected boolean showX = true, showY = true, showZ = true;
|
protected boolean showX = true, showY = true, showZ = true, showDirection = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSettingsChanged(WidgetSettings settings) {
|
public void onSettingsChanged(WidgetSettings settings) {
|
||||||
@@ -100,6 +117,8 @@ public class CoordinatesWidget extends ResizableWidget {
|
|||||||
this.showX = (boolean) settings.optionById("x").getValue();
|
this.showX = (boolean) settings.optionById("x").getValue();
|
||||||
this.showY = (boolean) settings.optionById("y").getValue();
|
this.showY = (boolean) settings.optionById("y").getValue();
|
||||||
this.showZ = (boolean) settings.optionById("z").getValue();
|
this.showZ = (boolean) settings.optionById("z").getValue();
|
||||||
|
this.showDirection = (boolean) settings.optionById("direction").getValue();
|
||||||
|
this.directionFormat = (DirectionWidget.DisplayFormat) settings.optionById("directionFormat").getValue();
|
||||||
this.paddingX = (int) settings.optionById("paddingX").getValue();
|
this.paddingX = (int) settings.optionById("paddingX").getValue();
|
||||||
this.paddingY = (int) settings.optionById("paddingY").getValue();
|
this.paddingY = (int) settings.optionById("paddingY").getValue();
|
||||||
this.width = (int) settings.optionById("width").getValue();
|
this.width = (int) settings.optionById("width").getValue();
|
||||||
@@ -117,6 +136,7 @@ public class CoordinatesWidget extends ResizableWidget {
|
|||||||
if (showX) height += 11;
|
if (showX) height += 11;
|
||||||
if (showY) height += 11;
|
if (showY) height += 11;
|
||||||
if (showZ) height += 11;
|
if (showZ) height += 11;
|
||||||
|
if (showDirection) height += 11;
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import net.minecraft.client.MinecraftClient;
|
|||||||
import net.minecraft.client.font.TextRenderer;
|
import net.minecraft.client.font.TextRenderer;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.DrawContext;
|
||||||
import net.minecraft.client.network.ClientPlayerEntity;
|
import net.minecraft.client.network.ClientPlayerEntity;
|
||||||
import net.minecraft.text.MutableText;
|
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
@@ -17,7 +16,8 @@ import net.minecraft.util.math.MathHelper;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import static net.minecraft.text.Text.*;
|
import static net.minecraft.text.Text.literal;
|
||||||
|
import static net.minecraft.text.Text.translatable;
|
||||||
|
|
||||||
public class DirectionWidget extends BasicTextWidget {
|
public class DirectionWidget extends BasicTextWidget {
|
||||||
|
|
||||||
@@ -25,7 +25,10 @@ public class DirectionWidget extends BasicTextWidget {
|
|||||||
YAW_ONLY(true),
|
YAW_ONLY(true),
|
||||||
DIRECTION_ONLY(false),
|
DIRECTION_ONLY(false),
|
||||||
YAW_DIRECTION(true),
|
YAW_DIRECTION(true),
|
||||||
DIRECTION_YAW(true);
|
DIRECTION_YAW(true),
|
||||||
|
DIRECTION_SHORT(false),
|
||||||
|
DIRECTION_SHORT_YAW(true),
|
||||||
|
YAW_DIRECTION_SHORT(true);
|
||||||
|
|
||||||
public final boolean showsYaw;
|
public final boolean showsYaw;
|
||||||
|
|
||||||
@@ -35,17 +38,20 @@ public class DirectionWidget extends BasicTextWidget {
|
|||||||
|
|
||||||
public Text format(int digits) {
|
public Text format(int digits) {
|
||||||
String yaw = "0";
|
String yaw = "0";
|
||||||
MutableText direction = literal("Direction");
|
String direction = "???";
|
||||||
ClientPlayerEntity player = MinecraftClient.getInstance().player;
|
ClientPlayerEntity player = MinecraftClient.getInstance().player;
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
yaw = WidgetUtils.reduceDigits(MathHelper.wrapDegrees(player.getYaw()), digits);
|
yaw = WidgetUtils.reduceDigits(MathHelper.wrapDegrees(player.getYaw()), digits);
|
||||||
direction = translatable("widgets.widgets.direction." + player.getHorizontalFacing().name().toLowerCase(Locale.ROOT));
|
direction = player.getHorizontalFacing().name().toLowerCase(Locale.ROOT);
|
||||||
}
|
}
|
||||||
return switch (this){
|
return switch (this){
|
||||||
case YAW_ONLY -> literal(yaw);
|
case YAW_ONLY -> literal(yaw);
|
||||||
case DIRECTION_ONLY -> direction;
|
case DIRECTION_ONLY -> translatable("widgets.widgets.direction." + direction);
|
||||||
case YAW_DIRECTION -> literal(yaw+" (").append(direction).append(")");
|
case YAW_DIRECTION -> literal(yaw+" (").append(translatable("widgets.widgets.direction." + direction)).append(")");
|
||||||
case DIRECTION_YAW -> direction.append(" ("+yaw+")");
|
case DIRECTION_YAW -> translatable("widgets.widgets.direction." + direction).append(" ("+yaw+")");
|
||||||
|
case DIRECTION_SHORT -> translatable("widgets.widgets.direction.short." + direction);
|
||||||
|
case DIRECTION_SHORT_YAW -> translatable("widgets.widgets.direction.short." + direction).append(" ("+yaw+")");
|
||||||
|
case YAW_DIRECTION_SHORT -> literal(yaw+" (").append(translatable("widgets.widgets.direction.short." + direction)).append(")");
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +73,7 @@ public class DirectionWidget extends BasicTextWidget {
|
|||||||
DisplayFormat.DIRECTION_YAW,
|
DisplayFormat.DIRECTION_YAW,
|
||||||
DisplayFormat::format
|
DisplayFormat::format
|
||||||
),
|
),
|
||||||
new IntSliderWidgetSetting("digits", Text.translatable("widgets.widgets.direction.digits"), 0, 1, 3),
|
new IntSliderWidgetSetting("digits", translatable("widgets.widgets.direction.digits"), 0, 1, 3),
|
||||||
new ToggleWidgetSetting("realtime", translatable("widgets.widgets.common.realtime"), false)
|
new ToggleWidgetSetting("realtime", translatable("widgets.widgets.common.realtime"), false)
|
||||||
));
|
));
|
||||||
getSettings().optionById("digits").setShowCondition(() -> displayFormat.showsYaw);
|
getSettings().optionById("digits").setShowCondition(() -> displayFormat.showsYaw);
|
||||||
|
|||||||
@@ -95,6 +95,8 @@
|
|||||||
"widgets.widgets.common.sizePercent": "Widgetgröße (%)",
|
"widgets.widgets.common.sizePercent": "Widgetgröße (%)",
|
||||||
"widgets.widgets.coordinates": "Koordinaten",
|
"widgets.widgets.coordinates": "Koordinaten",
|
||||||
"widgets.widgets.coordinates.description": "Zeigt deine aktuellen Koordinaten an",
|
"widgets.widgets.coordinates.description": "Zeigt deine aktuellen Koordinaten an",
|
||||||
|
"widgets.widgets.coordinates.directionFormat": "Richtungsformat",
|
||||||
|
"widgets.widgets.coordinates.showDirection": "Blickrichtung anzeigen:",
|
||||||
"widgets.widgets.coordinates.showX": "X-Koordinate anzeigen:",
|
"widgets.widgets.coordinates.showX": "X-Koordinate anzeigen:",
|
||||||
"widgets.widgets.coordinates.showY": "Y-Koordinate anzeigen:",
|
"widgets.widgets.coordinates.showY": "Y-Koordinate anzeigen:",
|
||||||
"widgets.widgets.coordinates.showZ": "Z-Koordinate anzeigen:",
|
"widgets.widgets.coordinates.showZ": "Z-Koordinate anzeigen:",
|
||||||
@@ -113,6 +115,10 @@
|
|||||||
"widgets.widgets.direction.display": "Format",
|
"widgets.widgets.direction.display": "Format",
|
||||||
"widgets.widgets.direction.east": "Osten",
|
"widgets.widgets.direction.east": "Osten",
|
||||||
"widgets.widgets.direction.north": "Norden",
|
"widgets.widgets.direction.north": "Norden",
|
||||||
|
"widgets.widgets.direction.short.east": "O",
|
||||||
|
"widgets.widgets.direction.short.north": "N",
|
||||||
|
"widgets.widgets.direction.short.south": "S",
|
||||||
|
"widgets.widgets.direction.short.west": "W",
|
||||||
"widgets.widgets.direction.south": "Süden",
|
"widgets.widgets.direction.south": "Süden",
|
||||||
"widgets.widgets.direction.west": "Westen",
|
"widgets.widgets.direction.west": "Westen",
|
||||||
"widgets.widgets.fps": "FPS",
|
"widgets.widgets.fps": "FPS",
|
||||||
|
|||||||
@@ -95,9 +95,11 @@
|
|||||||
"widgets.widgets.common.sizePercent": "Widget size (%)",
|
"widgets.widgets.common.sizePercent": "Widget size (%)",
|
||||||
"widgets.widgets.coordinates": "Coordinates",
|
"widgets.widgets.coordinates": "Coordinates",
|
||||||
"widgets.widgets.coordinates.description": "Shows your current coordinates.",
|
"widgets.widgets.coordinates.description": "Shows your current coordinates.",
|
||||||
"widgets.widgets.coordinates.showX": "Show X coordinate:",
|
"widgets.widgets.coordinates.directionFormat": "Direction format",
|
||||||
"widgets.widgets.coordinates.showY": "Show Y coordinate:",
|
"widgets.widgets.coordinates.showDirection": "Show view direction",
|
||||||
"widgets.widgets.coordinates.showZ": "Show Z coordinate:",
|
"widgets.widgets.coordinates.showX": "Show X coordinate",
|
||||||
|
"widgets.widgets.coordinates.showY": "Show Y coordinate",
|
||||||
|
"widgets.widgets.coordinates.showZ": "Show Z coordinate",
|
||||||
"widgets.widgets.cps": "CPS",
|
"widgets.widgets.cps": "CPS",
|
||||||
"widgets.widgets.cps.appearance": "Appearance",
|
"widgets.widgets.cps.appearance": "Appearance",
|
||||||
"widgets.widgets.cps.appearance.pipe": "Split (Pipe)",
|
"widgets.widgets.cps.appearance.pipe": "Split (Pipe)",
|
||||||
@@ -113,6 +115,10 @@
|
|||||||
"widgets.widgets.direction.display": "Format",
|
"widgets.widgets.direction.display": "Format",
|
||||||
"widgets.widgets.direction.east": "East",
|
"widgets.widgets.direction.east": "East",
|
||||||
"widgets.widgets.direction.north": "North",
|
"widgets.widgets.direction.north": "North",
|
||||||
|
"widgets.widgets.direction.short.east": "E",
|
||||||
|
"widgets.widgets.direction.short.north": "N",
|
||||||
|
"widgets.widgets.direction.short.south": "S",
|
||||||
|
"widgets.widgets.direction.short.west": "W",
|
||||||
"widgets.widgets.direction.south": "South",
|
"widgets.widgets.direction.south": "South",
|
||||||
"widgets.widgets.direction.west": "West",
|
"widgets.widgets.direction.west": "West",
|
||||||
"widgets.widgets.fps": "FPS",
|
"widgets.widgets.fps": "FPS",
|
||||||
|
|||||||
Reference in New Issue
Block a user