diff options
Diffstat (limited to 'src/main/java')
3 files changed, 40 insertions, 10 deletions
diff --git a/src/main/java/dev/isxander/yacl/gui/LowProfileButtonWidget.java b/src/main/java/dev/isxander/yacl/gui/LowProfileButtonWidget.java new file mode 100644 index 0000000..240cfb2 --- /dev/null +++ b/src/main/java/dev/isxander/yacl/gui/LowProfileButtonWidget.java @@ -0,0 +1,27 @@ +package dev.isxander.yacl.gui; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.widget.ButtonWidget; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.text.Text; +import net.minecraft.util.math.MathHelper; + +public class LowProfileButtonWidget extends ButtonWidget { + public LowProfileButtonWidget(int x, int y, int width, int height, Text message, PressAction onPress) { + super(x, y, width, height, message, onPress); + } + + public LowProfileButtonWidget(int x, int y, int width, int height, Text message, PressAction onPress, TooltipSupplier tooltipSupplier) { + super(x, y, width, height, message, onPress, tooltipSupplier); + } + + @Override + public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta) { + if (!isHovered()) { + int j = this.active ? 0xFFFFFF : 0xA0A0A0; + drawCenteredText(matrices, MinecraftClient.getInstance().textRenderer, this.getMessage(), this.x + this.width / 2, this.y + (this.height - 8) / 2, j | MathHelper.ceil(this.alpha * 255.0F) << 24); + } else { + super.renderButton(matrices, mouseX, mouseY, delta); + } + } +} diff --git a/src/main/java/dev/isxander/yacl/gui/OptionListWidget.java b/src/main/java/dev/isxander/yacl/gui/OptionListWidget.java index 804592d..f243778 100644 --- a/src/main/java/dev/isxander/yacl/gui/OptionListWidget.java +++ b/src/main/java/dev/isxander/yacl/gui/OptionListWidget.java @@ -22,8 +22,8 @@ import net.minecraft.text.Text; import net.minecraft.util.math.MathHelper; import org.jetbrains.annotations.Nullable; -import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.function.Supplier; public class OptionListWidget extends ElementListWidget<OptionListWidget.Entry> { @@ -180,6 +180,10 @@ public class OptionListWidget extends ElementListWidget<OptionListWidget.Entry> public int getItemHeight() { return 22; } + + protected boolean isHovered() { + return Objects.equals(getHoveredEntry(), this); + } } private class OptionEntry extends Entry { @@ -239,7 +243,7 @@ public class OptionListWidget extends ElementListWidget<OptionListWidget.Entry> private final MultilineText wrappedName; private final List<OrderedText> wrappedTooltip; - private final ButtonWidget expandMinimizeButton; + private final LowProfileButtonWidget expandMinimizeButton; private float hoveredTicks = 0; private int prevMouseX, prevMouseY; @@ -253,10 +257,9 @@ public class OptionListWidget extends ElementListWidget<OptionListWidget.Entry> this.group = group; this.screen = screen; this.wrappedName = MultilineText.create(textRenderer, group.name(), getRowWidth() - 45); - //this.wrappedName = textRenderer.wrapLines(group.name(), getRowWidth() - 45); this.wrappedTooltip = textRenderer.wrapLines(group.tooltip(), screen.width / 2); this.groupExpanded = !group.collapsed(); - this.expandMinimizeButton = new ButtonWidget(0, 0, 20, 20, Text.empty(), btn -> { + this.expandMinimizeButton = new LowProfileButtonWidget(0, 0, 20, 20, Text.empty(), btn -> { groupExpanded = !groupExpanded; updateExpandMinimizeText(); }); @@ -265,10 +268,9 @@ public class OptionListWidget extends ElementListWidget<OptionListWidget.Entry> @Override public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { - expandMinimizeButton.x = x + entryWidth - expandMinimizeButton.getWidth(); + expandMinimizeButton.x = x; expandMinimizeButton.y = y + entryHeight / 2 - expandMinimizeButton.getHeight() / 2; - if (hovered) - expandMinimizeButton.render(matrices, mouseX, mouseY, tickDelta); + expandMinimizeButton.render(matrices, mouseX, mouseY, tickDelta); hovered &= !expandMinimizeButton.isMouseOver(mouseX, mouseY); if (hovered && (!YACLConstants.HOVER_MOUSE_RESET || (mouseX == prevMouseX && mouseY == prevMouseY))) @@ -291,7 +293,8 @@ public class OptionListWidget extends ElementListWidget<OptionListWidget.Entry> } private void updateExpandMinimizeText() { - expandMinimizeButton.setMessage(Text.of(isExpanded() ? "\u25BC" : "\u25C0")); +// expandMinimizeButton.setMessage(Text.of(isExpanded() ? "\u25BC" : "\u25C0")); + expandMinimizeButton.setMessage(Text.of(isExpanded() ? "\u25BC" : "\u25B6")); } @Override diff --git a/src/main/java/dev/isxander/yacl/gui/YACLScreen.java b/src/main/java/dev/isxander/yacl/gui/YACLScreen.java index 90bcea7..01d9bcb 100644 --- a/src/main/java/dev/isxander/yacl/gui/YACLScreen.java +++ b/src/main/java/dev/isxander/yacl/gui/YACLScreen.java @@ -77,7 +77,7 @@ public class YACLScreen extends Screen { }); OptionUtils.forEachOptions(config, option -> { if (option.changed()) { - YACLConstants.LOGGER.error("Option '{}' was saved as '{}' but the changes don't seem to have applied.", option.name().getString(), option.pendingValue()); + YACLConstants.LOGGER.error("'{}' was saved as '{}' but the changes don't seem to have applied. (Maybe binding is immutable?)", option.name().getString(), option.pendingValue()); setSaveButtonMessage(Text.translatable("yacl.gui.fail_apply").formatted(Formatting.RED), Text.translatable("yacl.gui.fail_apply.tooltip")); } }); @@ -156,7 +156,7 @@ public class YACLScreen extends Screen { boolean pendingChanges = pendingChanges(); undoButton.active = pendingChanges; - finishedSaveButton.setMessage(pendingChanges ? Text.translatable("yacl.gui.save") : Text.translatable("multiplayer.status.finished")); + finishedSaveButton.setMessage(pendingChanges ? Text.translatable("yacl.gui.save") : Text.translatable("gui.done")); finishedSaveButton.setTooltip(pendingChanges ? Text.translatable("yacl.gui.save.tooltip") : Text.translatable("yacl.gui.finished.tooltip")); cancelResetButton.setMessage(pendingChanges ? Text.translatable("gui.cancel") : Text.translatable("controls.reset")); cancelResetButton.setTooltip(pendingChanges ? Text.translatable("yacl.gui.cancel.tooltip") : Text.translatable("yacl.gui.reset.tooltip")); |