diff options
| author | viciscat <51047087+viciscat@users.noreply.github.com> | 2025-06-23 05:43:48 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-22 23:43:48 -0400 |
| commit | be67e01bfb541de057e8b3698e6dcbc828a69fc6 (patch) | |
| tree | 72e413c900ad631084ed1dc03c2cdcf27cac8d2f /src/main/java | |
| parent | 532179ca43ae143ed9b17b707d1020026073cb9b (diff) | |
| download | Skyblocker-be67e01bfb541de057e8b3698e6dcbc828a69fc6.tar.gz Skyblocker-be67e01bfb541de057e8b3698e6dcbc828a69fc6.tar.bz2 Skyblocker-be67e01bfb541de057e8b3698e6dcbc828a69fc6.zip | |
Add collapse button to waypoint groups in Waypoints Screen (#1158)
* collapse button
* positioning + use that one RGB input i made
* changes
Diffstat (limited to 'src/main/java')
| -rw-r--r-- | src/main/java/de/hysky/skyblocker/skyblock/item/custom/screen/ColorSelectionWidget.java | 28 | ||||
| -rw-r--r-- | src/main/java/de/hysky/skyblocker/skyblock/waypoint/WaypointsListWidget.java | 95 | ||||
| -rw-r--r-- | src/main/java/de/hysky/skyblocker/utils/render/gui/ARGBTextInput.java (renamed from src/main/java/de/hysky/skyblocker/utils/render/gui/RGBTextInput.java) | 91 |
3 files changed, 126 insertions, 88 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/custom/screen/ColorSelectionWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/item/custom/screen/ColorSelectionWidget.java index a8a110e7..c60aaebd 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/custom/screen/ColorSelectionWidget.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/custom/screen/ColorSelectionWidget.java @@ -8,7 +8,7 @@ import de.hysky.skyblocker.skyblock.item.custom.CustomArmorAnimatedDyes; import de.hysky.skyblocker.utils.Formatters; import de.hysky.skyblocker.utils.ItemUtils; import de.hysky.skyblocker.utils.render.gui.ColorPickerWidget; -import de.hysky.skyblocker.utils.render.gui.RGBTextInput; +import de.hysky.skyblocker.utils.render.gui.ARGBTextInput; import it.unimi.dsi.fastutil.floats.FloatConsumer; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; @@ -42,7 +42,7 @@ public class ColorSelectionWidget extends ContainerWidget implements Closeable { private static final String DELAY_TEXT = "skyblocker.armorCustomization.delay"; private final ColorPickerWidget colorPicker; - private final RGBTextInput rgbTextInput; + private final ARGBTextInput argbTextInput; private final AnimatedDyeTimelineWidget timelineWidget; private final CheckboxWidget cycleBackCheckbox; @@ -65,12 +65,12 @@ public class ColorSelectionWidget extends ContainerWidget implements Closeable { colorPicker = new ColorPickerWidget(x + 3, y + 3, height1 * 2, height1); colorPicker.setOnColorChange(this::onPickerColorChanged); - rgbTextInput = new RGBTextInput(0, y + 3, textRenderer, true); - rgbTextInput.setX(colorPicker.getRight() + 5); - rgbTextInput.setOnChange(this::onTextInputColorChanged); + argbTextInput = new ARGBTextInput(0, y + 3, textRenderer, true); + argbTextInput.setX(colorPicker.getRight() + 5); + argbTextInput.setOnChange(this::onTextInputColorChanged); timelineWidget = new AnimatedDyeTimelineWidget(getX() + 3, getBottom() - 18, getWidth() - 6, 15, this::onTimelineFrameSelected); - resetColorButton = ButtonWidget.builder(RESET_COLOR_TEXT, this::onRemoveCustomColor).width(Math.min(150, x + width - rgbTextInput.getRight() - 5)).build(); + resetColorButton = ButtonWidget.builder(RESET_COLOR_TEXT, this::onRemoveCustomColor).width(Math.min(150, x + width - argbTextInput.getRight() - 5)).build(); resetColorButton.setPosition(getRight() - resetColorButton.getWidth() - 3, getY() + 3); @@ -126,11 +126,11 @@ public class ColorSelectionWidget extends ContainerWidget implements Closeable { }); durationSlider.setTooltip(Tooltip.of(DURATION_TOOLTIP_TEXT)); - children = List.of(colorPicker, rgbTextInput, timelineWidget, resetColorButton, animatedCheckbox, notCustomizableText, cycleBackCheckbox, delaySlider, durationSlider); + children = List.of(colorPicker, argbTextInput, timelineWidget, resetColorButton, animatedCheckbox, notCustomizableText, cycleBackCheckbox, delaySlider, durationSlider); } private void onPickerColorChanged(int argb, boolean release) { - rgbTextInput.setRGBColor(argb); + argbTextInput.setARGBColor(argb); if (!animated) { SkyblockerConfigManager.get().general.customDyeColors.put(ItemUtils.getItemUuid(currentItem), ColorHelper.fullAlpha(argb)); } else if (release) { @@ -150,7 +150,7 @@ public class ColorSelectionWidget extends ContainerWidget implements Closeable { } private void onTimelineFrameSelected(int color, float time) { - rgbTextInput.setRGBColor(color); + argbTextInput.setARGBColor(color); colorPicker.setRGBColor(color); } @@ -164,7 +164,7 @@ public class ColorSelectionWidget extends ContainerWidget implements Closeable { SkyblockerConfigManager.get().general.customAnimatedDyes.remove(itemUuid); int color = DyedColorComponent.getColor(currentItem, -1); - rgbTextInput.setRGBColor(color); + argbTextInput.setARGBColor(color); colorPicker.setRGBColor(color); } @@ -186,7 +186,7 @@ public class ColorSelectionWidget extends ContainerWidget implements Closeable { } else { int color = SkyblockerConfigManager.get().general.customDyeColors.getOrDefault(itemUuid, DyedColorComponent.getColor(currentItem, -1)); colorPicker.setRGBColor(color); - rgbTextInput.setRGBColor(color); + argbTextInput.setARGBColor(color); SkyblockerConfigManager.get().general.customAnimatedDyes.remove(itemUuid); } } @@ -205,7 +205,7 @@ public class ColorSelectionWidget extends ContainerWidget implements Closeable { private void changeVisibilities() { colorPicker.visible = customizable; - rgbTextInput.visible = customizable; + argbTextInput.visible = customizable; timelineWidget.visible = customizable && animated; cycleBackCheckbox.visible = customizable && animated; @@ -272,12 +272,12 @@ public class ColorSelectionWidget extends ContainerWidget implements Closeable { } else if (SkyblockerConfigManager.get().general.customDyeColors.containsKey(itemUuid)) { animated = false; int color = SkyblockerConfigManager.get().general.customDyeColors.getInt(itemUuid); - rgbTextInput.setRGBColor(color); + argbTextInput.setARGBColor(color); colorPicker.setRGBColor(color); } else { animated = false; int color = DyedColorComponent.getColor(currentItem, -1); - rgbTextInput.setRGBColor(color); + argbTextInput.setARGBColor(color); colorPicker.setRGBColor(color); } changeVisibilities(); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/waypoint/WaypointsListWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/waypoint/WaypointsListWidget.java index a7fc30c2..7b79cb4e 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/waypoint/WaypointsListWidget.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/waypoint/WaypointsListWidget.java @@ -2,6 +2,7 @@ package de.hysky.skyblocker.skyblock.waypoint; import de.hysky.skyblocker.mixins.accessors.CheckboxWidgetAccessor; import de.hysky.skyblocker.utils.Location; +import de.hysky.skyblocker.utils.render.gui.ARGBTextInput; import de.hysky.skyblocker.utils.waypoint.NamedWaypoint; import de.hysky.skyblocker.utils.waypoint.WaypointGroup; import it.unimi.dsi.fastutil.ints.Int2ObjectFunction; @@ -14,16 +15,15 @@ import net.minecraft.text.Text; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ColorHelper; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Optional; +import java.util.*; public class WaypointsListWidget extends ElementListWidget<WaypointsListWidget.AbstractWaypointEntry> { private final AbstractWaypointsScreen<?> screen; private Location island; private List<WaypointGroup> waypoints; + private final Set<WaypointGroup> collapsedGroups = new HashSet<>(); public WaypointsListWidget(MinecraftClient client, AbstractWaypointsScreen<?> screen, int width, int height, int y, int itemHeight) { super(client, width, height, y, itemHeight); @@ -33,7 +33,7 @@ public class WaypointsListWidget extends ElementListWidget<WaypointsListWidget.A @Override public int getRowWidth() { - return super.getRowWidth() + 100; + return super.getRowWidth() + 116; } @Override @@ -53,6 +53,8 @@ public class WaypointsListWidget extends ElementListWidget<WaypointsListWidget.A void setIsland(Location island) { this.island = island; waypoints = (List<WaypointGroup>) screen.waypoints.get(island); + collapsedGroups.clear(); + collapsedGroups.addAll(waypoints); updateEntries(); } @@ -76,8 +78,10 @@ public class WaypointsListWidget extends ElementListWidget<WaypointsListWidget.A void updateEntries() { clearEntries(); for (WaypointGroup group : waypoints) { - WaypointGroupEntry groupEntry = new WaypointGroupEntry(group); + boolean collapsed = collapsedGroups.contains(group); + WaypointGroupEntry groupEntry = new WaypointGroupEntry(group, collapsed); addEntry(groupEntry); + if (collapsed) continue; for (NamedWaypoint waypoint : group.waypoints()) { addEntry(new WaypointEntry(groupEntry, waypoint)); } @@ -109,12 +113,13 @@ public class WaypointsListWidget extends ElementListWidget<WaypointsListWidget.A private final CheckboxWidget ordered; private final ButtonWidget buttonNewWaypoint; private final ButtonWidget buttonDelete; + private final ButtonWidget collapseWaypoint; public WaypointGroupEntry() { - this(new WaypointGroup("New Group", island, new ArrayList<>())); + this(new WaypointGroup("New Group", island, new ArrayList<>()), false); } - public WaypointGroupEntry(WaypointGroup group) { + public WaypointGroupEntry(WaypointGroup group, boolean collapsed) { this.group = group; enabled = CheckboxWidget.builder(Text.literal(""), client.textRenderer).checked(shouldBeChecked()).callback((checkbox, checked) -> group.waypoints().forEach(waypoint -> screen.enabledChanged(waypoint, checked))).build(); nameField = new TextFieldWidget(client.textRenderer, 70, 20, Text.literal("Name")); @@ -122,7 +127,7 @@ public class WaypointsListWidget extends ElementListWidget<WaypointsListWidget.A nameField.setChangedListener(this::updateName); ordered = CheckboxWidget.builder(Text.literal("Ordered"), client.textRenderer).checked(group.ordered()).callback((checkbox, checked) -> updateOrdered(checked)).build(); buttonNewWaypoint = ButtonWidget.builder(Text.translatable("skyblocker.waypoints.new"), buttonNewWaypoint -> { - WaypointEntry waypointEntry = new WaypointEntry(this); + WaypointEntry waypointEntry = new WaypointEntry(this); int entryIndex; if (getSelectedOrNull() instanceof WaypointEntry selectedWaypointEntry && selectedWaypointEntry.groupEntry == this) { entryIndex = WaypointsListWidget.this.children().indexOf(selectedWaypointEntry) + 1; @@ -134,6 +139,10 @@ public class WaypointsListWidget extends ElementListWidget<WaypointsListWidget.A } group.waypoints().add(waypointEntry.waypoint); WaypointsListWidget.this.children().add(entryIndex, waypointEntry); + if (collapsed) { + collapsedGroups.remove(group); + updateEntries(); + } }).width(72).build(); buttonDelete = ButtonWidget.builder(Text.translatable("selectServer.deleteButton"), buttonDelete -> { int entryIndex = WaypointsListWidget.this.children().indexOf(this) + 1; @@ -143,7 +152,12 @@ public class WaypointsListWidget extends ElementListWidget<WaypointsListWidget.A WaypointsListWidget.this.children().remove(this); waypoints.remove(group); }).width(38).build(); - children = List.of(enabled, nameField, ordered, buttonNewWaypoint, buttonDelete); + Text arrow = Text.of(collapsed ? "▲" :"▼"); + collapseWaypoint = ButtonWidget.builder(arrow, button -> { + if (collapsed) collapsedGroups.remove(group); else collapsedGroups.add(group); + updateEntries(); + }).size(11, 11).build(); + children = List.of(enabled, nameField, ordered, buttonNewWaypoint, buttonDelete, collapseWaypoint); } @Override @@ -178,8 +192,9 @@ public class WaypointsListWidget extends ElementListWidget<WaypointsListWidget.A @Override public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { - enabled.setPosition(x, y + 1); - nameField.setPosition(x + 22, y); + collapseWaypoint.setPosition(x, y + (entryHeight - collapseWaypoint.getHeight()) / 2); + enabled.setPosition(x + 16, y + 1); + nameField.setPosition(enabled.getRight() + 5, y); ordered.setPosition(x + entryWidth - 190, y + 1); buttonNewWaypoint.setPosition(x + entryWidth - 115, y); buttonDelete.setPosition(x + entryWidth - 38, y); @@ -198,7 +213,7 @@ public class WaypointsListWidget extends ElementListWidget<WaypointsListWidget.A private final TextFieldWidget xField; private final TextFieldWidget yField; private final TextFieldWidget zField; - private final TextFieldWidget colorField; + private final ARGBTextInput colorField; private final ButtonWidget buttonDelete; public WaypointEntry(WaypointGroupEntry groupEntry) { @@ -224,9 +239,11 @@ public class WaypointsListWidget extends ElementListWidget<WaypointsListWidget.A zField.setText(Integer.toString(waypoint.pos.getZ())); zField.setTextPredicate(this::checkInt); zField.setChangedListener(this::updateZ); - colorField = new TextFieldWidget(client.textRenderer, 56, 20, Text.literal("Color")); - colorField.setText(String.format("%02X%02X%02X%02X", (int) (waypoint.alpha * 255), (int) (waypoint.colorComponents[0] * 255), (int) (waypoint.colorComponents[1] * 255), (int) (waypoint.colorComponents[2] * 255))); - colorField.setChangedListener(this::updateColor); + colorField = new ARGBTextInput(0, 0, client.textRenderer, true, true); + int color = ColorHelper.fromFloats(waypoint.alpha, waypoint.colorComponents[0], waypoint.colorComponents[1], waypoint.colorComponents[2]); + colorField.setARGBColor(color); + colorField.setHeight(20); + colorField.setOnChange(this::updateColor); buttonDelete = ButtonWidget.builder(Text.translatable("selectServer.deleteButton"), button -> { groupEntry.group.waypoints().remove(waypoint); WaypointsListWidget.this.children().remove(this); @@ -288,42 +305,32 @@ public class WaypointsListWidget extends ElementListWidget<WaypointsListWidget.A } } - private void updateColor(String colorString) { - try { - int index = groupEntry.group.waypoints().indexOf(waypoint); - int colorInt = parseEmptiableInt(colorString, 16); - float[] colorComponents = {((colorInt & 0x00FF0000) >> 16) / 255f, ((colorInt & 0x0000FF00) >> 8) / 255f, (colorInt & 0x000000FF) / 255f}; - float alpha = ((colorInt & 0xFF000000) >>> 24) / 255f; - if (Arrays.equals(waypoint.colorComponents, colorComponents) && waypoint.alpha == alpha) return; - waypoint = waypoint.withColor(colorComponents, alpha); - if (index >= 0) { - groupEntry.group.waypoints().set(index, waypoint); - } - } catch (NumberFormatException e) { - Waypoints.LOGGER.warn("[Skyblocker Waypoints] Failed to parse color: {}", colorString, e); - } + private void updateColor(int colorInt) { + int index = groupEntry.group.waypoints().indexOf(waypoint); + float[] colorComponents = {((colorInt & 0x00FF0000) >> 16) / 255f, ((colorInt & 0x0000FF00) >> 8) / 255f, (colorInt & 0x000000FF) / 255f}; + float alpha = ((colorInt & 0xFF000000) >>> 24) / 255f; + if (Arrays.equals(waypoint.colorComponents, colorComponents) && waypoint.alpha == alpha) return; + waypoint = waypoint.withColor(colorComponents, alpha); + if (index >= 0) { + groupEntry.group.waypoints().set(index, waypoint); + } } private int parseEmptiableInt(String value) throws NumberFormatException { return value.isEmpty() || value.equals("-") ? 0 : Integer.parseInt(value); } - @SuppressWarnings("SameParameterValue") - private int parseEmptiableInt(String value, int radix) throws NumberFormatException { - return value.isEmpty() || value.equals("-") ? 0 : Integer.parseInt(value, radix); - } - @Override public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { - context.drawTextWithShadow(client.textRenderer, "X:", width / 2 - 56, y + 6, 0xFFFFFF); - context.drawTextWithShadow(client.textRenderer, "Y:", width / 2 - 19, y + 6, 0xFFFFFF); - context.drawTextWithShadow(client.textRenderer, "Z:", width / 2 + 18, y + 6, 0xFFFFFF); - context.drawTextWithShadow(client.textRenderer, "#", x + entryWidth - 105, y + 6, 0xFFFFFF); - enabled.setPosition(x + 10, y + 1); - nameField.setPosition(x + 32, y); - xField.setPosition(width / 2 - 48, y); - yField.setPosition(width / 2 - 11, y); - zField.setPosition(width / 2 + 26, y); + context.drawTextWithShadow(client.textRenderer, "X:", width / 2 - 48, y + 6, 0xFF_FFFFFF); + context.drawTextWithShadow(client.textRenderer, "Y:", width / 2 - 11, y + 6, 0xFF_FFFFFF); + context.drawTextWithShadow(client.textRenderer, "Z:", width / 2 + 26, y + 6, 0xFF_FFFFFF); + context.drawTextWithShadow(client.textRenderer, "#", x + entryWidth - 105, y + 6, 0xFF_FFFFFF); + enabled.setPosition(x + 26, y + 1); + nameField.setPosition(enabled.getRight() + 5, y); + xField.setPosition(width / 2 - 40, y); + yField.setPosition(width / 2 - 3, y); + zField.setPosition(width / 2 + 34, y); colorField.setPosition(x + entryWidth - 99, y); buttonDelete.setPosition(x + entryWidth - 38, y); for (ClickableWidget child : children) { diff --git a/src/main/java/de/hysky/skyblocker/utils/render/gui/RGBTextInput.java b/src/main/java/de/hysky/skyblocker/utils/render/gui/ARGBTextInput.java index 64708ca1..67408169 100644 --- a/src/main/java/de/hysky/skyblocker/utils/render/gui/RGBTextInput.java +++ b/src/main/java/de/hysky/skyblocker/utils/render/gui/ARGBTextInput.java @@ -19,45 +19,77 @@ import java.util.Locale; import java.util.OptionalInt; import java.util.function.IntConsumer; -public class RGBTextInput extends ClickableWidget { +public class ARGBTextInput extends ClickableWidget { private static final Logger LOGGER = LogUtils.getLogger(); - private static final String SAMPLE_TEXT = "AAAAAA"; - private static final Formatting[] FORMATTINGS = new Formatting[] {Formatting.RED, Formatting.GREEN, Formatting.BLUE}; + private static final Formatting[] FORMATTINGS = new Formatting[] {Formatting.WHITE, Formatting.RED, Formatting.GREEN, Formatting.BLUE}; private static final String HEXADECIMAL_CHARS = "0123456789aAbBcCdDeEfF"; - private static final int LENGTH = 6; + /** + * Length in characters of the input + */ + private final int length; private final boolean drawBackground; private final TextRenderer textRenderer; + /** + * Whether the alpha channel can be changed + */ + private final boolean hasAlpha; + /** + * Mask to have full alpha if {@link ARGBTextInput#hasAlpha} is {@code false} + */ + private final int alphaMask; - private String input = "FFFFFF"; + private String input; int index = 0; private @Nullable IntConsumer onChange = null; /** - * Creates a new widget. - * <p> * Height and width are automatically computed to be the size of the hex number + some padding if {@code drawBackground} is true. - * If the size needs to be changed, use {@link RGBTextInput#setWidth(int)} and {@link RGBTextInput#setHeight(int)}. + * If the size needs to be changed, use {@link ARGBTextInput#setWidth(int)} and {@link ARGBTextInput#setHeight(int)}. * - * @see RGBTextInput#setOnChange(IntConsumer) + * @see ARGBTextInput#setOnChange(IntConsumer) * * @param x x position * @param y y position * @param textRenderer text renderer to render the text (duh!) * @param drawBackground draws a black background and a white border if true + * @param hasAlpha if the controller allows to change the alpha color. If false alpha is FF. * */ - public RGBTextInput(int x, int y, TextRenderer textRenderer, boolean drawBackground) { - super(x, y, textRenderer.getWidth(SAMPLE_TEXT) + (drawBackground ? 6 : 0), 10 + (drawBackground ? 4 : 0), Text.of("RGBTextInput")); + public ARGBTextInput(int x, int y, TextRenderer textRenderer, boolean drawBackground, boolean hasAlpha) { + super(x, y, textRenderer.getWidth(hasAlpha ? "AAAAAAAA" : "AAAAAA") + (drawBackground ? 6 : 0), 10 + (drawBackground ? 4 : 0), Text.of("ARGBTextInput")); this.drawBackground = drawBackground; this.textRenderer = textRenderer; + this.length = hasAlpha ? 8 : 6; + this.hasAlpha = hasAlpha; + this.alphaMask = hasAlpha ? 0 : 0xFF000000; + this.input = hasAlpha ? "FFFFFFFF" : "FFFFFF"; + } + + /** + * Constructor without alpha channel control. + * <br/> + * Height and width are automatically computed to be the size of the hex number + some padding if {@code drawBackground} is true. + * If the size needs to be changed, use {@link ARGBTextInput#setWidth(int)} and {@link ARGBTextInput#setHeight(int)}. + * + * @see ARGBTextInput#setOnChange(IntConsumer) + * + * @param x x position + * @param y y position + * @param textRenderer text renderer to render the text (duh!) + * @param drawBackground draws a black background and a white border if true + * + */ + public ARGBTextInput(int x, int y, TextRenderer textRenderer, boolean drawBackground) { + this(x, y, textRenderer, drawBackground, false); } - protected OptionalInt getOptionalRGBColor(String input) { + protected OptionalInt getOptionalARGBColor(String input) { try { - return OptionalInt.of(0xFF000000 | Integer.parseInt(input, 16)); + int i = Integer.parseUnsignedInt(input, 16); + return OptionalInt.of(alphaMask | i); } catch (NumberFormatException e) { LOGGER.error("Could not parse rgb color", e); } @@ -67,16 +99,16 @@ public class RGBTextInput extends ClickableWidget { /** * @return the color, or white if something somehow went wrong */ - public int getRGBColor() { - return getOptionalRGBColor(input).orElse(-1); + public int getARGBColor() { + return getOptionalARGBColor(input).orElse(Colors.WHITE); } - public void setRGBColor(int rgb) { - input = String.format("%06X",rgb & 0x00FFFFFF); + public void setARGBColor(int argb) { + input = String.format(hasAlpha ? "%08X" : "%06X", argb & (~alphaMask)); } /** - * Sets a consumer that will be called whenever the color is changed by the user (and not when {@link RGBTextInput#setRGBColor(int)} is called) with the new color. + * Sets a consumer that will be called whenever the color is changed by the user (and not when {@link ARGBTextInput#setARGBColor(int)} is called) with the new color. * The alpha channel will be at 255 (or FF) * @param onChange the consumer */ @@ -89,7 +121,7 @@ public class RGBTextInput extends ClickableWidget { int selectionStart = textRenderer.getWidth(input.substring(0, index)); int selectionEnd = textRenderer.getWidth(input.substring(0, index + 1)); int textX = getX() + (drawBackground ? 3 : 0); - int textY = getY() + (drawBackground ? 3 : 0); + int textY = getY() + (getHeight() - textRenderer.fontHeight) / 2; if (drawBackground) { context.fill(getX(), getY(), getRight(), getBottom(), isFocused() ? Colors.WHITE: Colors.GRAY); context.fill(getX() + 1, getY() + 1, getRight() - 1, getBottom() - 1, Colors.BLACK); @@ -101,21 +133,22 @@ public class RGBTextInput extends ClickableWidget { textY, textX + selectionEnd, textY + textRenderer.fontHeight, - 0xff00bbff + 0xFF_00_BB_FF ); context.fill( textX + selectionStart, textY + textRenderer.fontHeight - 1, textX + selectionEnd, textY + textRenderer.fontHeight, - -1 + Colors.WHITE ); } context.drawText( textRenderer, visitor -> { + int start = hasAlpha ? 0 : 1; for (int i = 0; i < input.length(); i++) { - if (!visitor.accept(i, isSelected() ? Style.EMPTY.withFormatting(FORMATTINGS[i / 2]) : Style.EMPTY, input.charAt(i))) return false; + if (!visitor.accept(i, isSelected() ? Style.EMPTY.withFormatting(FORMATTINGS[i / 2 + start]) : Style.EMPTY, input.charAt(i))) return false; } return true; }, @@ -127,9 +160,7 @@ public class RGBTextInput extends ClickableWidget { } @Override - protected void appendClickableNarrations(NarrationMessageBuilder builder) { - - } + protected void appendClickableNarrations(NarrationMessageBuilder builder) {} @Override public boolean keyPressed(int keyCode, int scanCode, int modifiers) { @@ -153,7 +184,7 @@ public class RGBTextInput extends ClickableWidget { yield true; } case GLFW.GLFW_KEY_RIGHT -> { - index = Math.min(LENGTH - 1, index + 1); + index = Math.min(length - 1, index + 1); yield true; } default -> false; @@ -168,7 +199,7 @@ public class RGBTextInput extends ClickableWidget { } else if (Screen.isPaste(keyCode)) { String clipboard = MinecraftClient.getInstance().keyboard.getClipboard(); String s = clipboard.substring(0, 6); - getOptionalRGBColor(s.toUpperCase(Locale.ENGLISH)).ifPresent(color -> { + getOptionalARGBColor(s.toUpperCase(Locale.ENGLISH)).ifPresent(color -> { input = s; callOnChange(); }); @@ -184,7 +215,7 @@ public class RGBTextInput extends ClickableWidget { if (!isFocused()) return false; if (HEXADECIMAL_CHARS.indexOf(chr) >= 0) { input = new StringBuilder(input).replace(index, index+1, String.valueOf(chr).toUpperCase(Locale.ENGLISH)).toString(); - index = Math.min(LENGTH - 1, index + 1); + index = Math.min(length - 1, index + 1); callOnChange(); return true; } @@ -194,7 +225,7 @@ public class RGBTextInput extends ClickableWidget { protected void callOnChange() { if (onChange != null) { - onChange.accept(getRGBColor()); + onChange.accept(getARGBColor()); } } @@ -211,7 +242,7 @@ public class RGBTextInput extends ClickableWidget { } private void findClickedChar(int mouseX) { - index = Math.clamp(textRenderer.trimToWidth(input, mouseX - getX() - (drawBackground ? 3 : 0)).length(), 0, LENGTH - 1); + index = Math.clamp(textRenderer.trimToWidth(input, mouseX - getX() - (drawBackground ? 3 : 0)).length(), 0, length - 1); } |
