diff options
author | isXander <xandersmith2008@gmail.com> | 2023-01-19 22:06:13 +0000 |
---|---|---|
committer | isXander <xandersmith2008@gmail.com> | 2023-01-19 22:06:13 +0000 |
commit | f4a890749e07123b5b7db8200b53c943a93ede01 (patch) | |
tree | 9d8a7b3b905c5b5b96f8048a59acbf757a12c406 /src | |
parent | ee53b51a1e8d88085c75f227f4710b68c03b19c8 (diff) | |
download | YetAnotherConfigLib-f4a890749e07123b5b7db8200b53c943a93ede01.tar.gz YetAnotherConfigLib-f4a890749e07123b5b7db8200b53c943a93ede01.tar.bz2 YetAnotherConfigLib-f4a890749e07123b5b7db8200b53c943a93ede01.zip |
22w03a - now with better navigation!
Diffstat (limited to 'src')
7 files changed, 75 insertions, 15 deletions
diff --git a/src/client/java/dev/isxander/yacl/gui/CategoryWidget.java b/src/client/java/dev/isxander/yacl/gui/CategoryWidget.java index f47a09b..60817a2 100644 --- a/src/client/java/dev/isxander/yacl/gui/CategoryWidget.java +++ b/src/client/java/dev/isxander/yacl/gui/CategoryWidget.java @@ -19,8 +19,15 @@ public class CategoryWidget extends TooltipButtonWidget { } @Override - protected int getYImage(boolean hovered) { - return super.getYImage(hovered || isCurrentCategory()); + protected int getTextureY() { + int i = 1; + if (!this.active) { + i = 0; + } else if (this.isHoveredOrFocused() || isCurrentCategory()) { + i = 2; + } + + return 46 + i * 20; } @Override diff --git a/src/client/java/dev/isxander/yacl/gui/YACLScreen.java b/src/client/java/dev/isxander/yacl/gui/YACLScreen.java index ee5c7dd..3b14544 100644 --- a/src/client/java/dev/isxander/yacl/gui/YACLScreen.java +++ b/src/client/java/dev/isxander/yacl/gui/YACLScreen.java @@ -302,12 +302,10 @@ public class YACLScreen extends Screen { 400 ); RenderSystem.enableDepthTest(); - RenderSystem.disableTexture(); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); BufferUploader.drawWithShader(bufferBuilder.end()); RenderSystem.disableBlend(); - RenderSystem.enableTexture(); matrices.translate(0.0, 0.0, 400.0); text.renderLeftAligned(matrices, drawX, drawY, lineHeight, -1); diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java b/src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java index 90c0e20..22c469d 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java @@ -7,11 +7,14 @@ import dev.isxander.yacl.gui.AbstractWidget; import dev.isxander.yacl.gui.YACLScreen; import dev.isxander.yacl.gui.utils.GuiUtils; import net.minecraft.ChatFormatting; +import net.minecraft.client.gui.ComponentPath; import net.minecraft.client.gui.GuiComponent; import net.minecraft.client.gui.components.MultiLineLabel; import net.minecraft.client.gui.narration.NarratedElementType; import net.minecraft.client.gui.narration.NarrationElementOutput; +import net.minecraft.client.gui.navigation.FocusNavigationEvent; import net.minecraft.network.chat.Component; +import org.jetbrains.annotations.Nullable; public abstract class ControllerWidget<T extends Controller<?>> extends AbstractWidget { protected final T control; @@ -126,13 +129,22 @@ public abstract class ControllerWidget<T extends Controller<?>> extends Abstract return getDimension().y() + getDimension().height() / 2f - textRenderer.lineHeight / 2f; } + @Nullable @Override - public boolean changeFocus(boolean lookForwards) { - if (!isAvailable()) - return false; + public ComponentPath nextFocusPath(FocusNavigationEvent focusNavigationEvent) { + if (!this.isAvailable()) + return null; + return !this.isFocused() ? ComponentPath.leaf(this) : null; + } - this.focused = !this.focused; - return this.focused; + @Override + public boolean isFocused() { + return focused; + } + + @Override + public void setFocused(boolean focused) { + this.focused = focused; } @Override diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/LabelController.java b/src/client/java/dev/isxander/yacl/gui/controllers/LabelController.java index 0017b59..dd0048d 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/LabelController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/LabelController.java @@ -6,12 +6,18 @@ import dev.isxander.yacl.api.Option; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.gui.AbstractWidget; import dev.isxander.yacl.gui.YACLScreen; +import net.minecraft.client.gui.ComponentPath; +import net.minecraft.client.gui.GuiComponent; import net.minecraft.client.gui.components.MultiLineLabel; +import net.minecraft.client.gui.narration.NarratedElementType; +import net.minecraft.client.gui.narration.NarrationElementOutput; +import net.minecraft.client.gui.navigation.FocusNavigationEvent; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.HoverEvent; import net.minecraft.network.chat.Style; import net.minecraft.util.FormattedCharSequence; import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -50,6 +56,7 @@ public class LabelController implements Controller<Component> { public class LabelControllerElement extends AbstractWidget { private List<FormattedCharSequence> wrappedText; protected MultiLineLabel wrappedTooltip; + protected boolean focused; protected final YACLScreen screen; @@ -70,6 +77,13 @@ public class LabelController implements Controller<Component> { textRenderer.drawShadow(matrices, text, getDimension().x() + getXPadding(), y + getYPadding(), option().available() ? -1 : 0xFFA0A0A0); y += textRenderer.lineHeight; } + + if (isFocused()) { + GuiComponent.fill(matrices, getDimension().x() - 2, getDimension().y() - 2, getDimension().xLimit() + 2, getDimension().y(), -1); + GuiComponent.fill(matrices, getDimension().x() - 2, getDimension().y() - 2, getDimension().x(), getDimension().yLimit() + 2, -1); + GuiComponent.fill(matrices, getDimension().x() - 2, getDimension().yLimit(), getDimension().xLimit() + 2, getDimension().yLimit() + 2, -1); + GuiComponent.fill(matrices, getDimension().xLimit(), getDimension().y() - 2, getDimension().xLimit() + 2, getDimension().yLimit() + 2, -1); + } } @Override @@ -147,5 +161,33 @@ public class LabelController implements Controller<Component> { public boolean matchesSearch(String query) { return formatValue().getString().toLowerCase().contains(query.toLowerCase()); } + + @Nullable + @Override + public ComponentPath nextFocusPath(FocusNavigationEvent focusNavigationEvent) { + if (!option().available()) + return null; + return !this.isFocused() ? ComponentPath.leaf(this) : null; + } + + @Override + public boolean isFocused() { + return focused; + } + + @Override + public void setFocused(boolean focused) { + this.focused = focused; + } + + @Override + public void updateNarration(NarrationElementOutput builder) { + builder.add(NarratedElementType.TITLE, formatValue()); + } + + @Override + public NarrationPriority narrationPriority() { + return NarrationPriority.FOCUSED; + } } } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/cycling/CyclingControllerElement.java b/src/client/java/dev/isxander/yacl/gui/controllers/cycling/CyclingControllerElement.java index b2fa776..ff20039 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/cycling/CyclingControllerElement.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/cycling/CyclingControllerElement.java @@ -39,9 +39,9 @@ public class CyclingControllerElement extends ControllerWidget<ICyclingControlle return false; switch (keyCode) { - case InputConstants.KEY_LEFT, InputConstants.KEY_DOWN -> + case InputConstants.KEY_LEFT -> cycleValue(-1); - case InputConstants.KEY_RIGHT, InputConstants.KEY_UP -> + case InputConstants.KEY_RIGHT -> cycleValue(1); case InputConstants.KEY_RETURN, InputConstants.KEY_SPACE, InputConstants.KEY_NUMPADENTER -> cycleValue(Screen.hasControlDown() || Screen.hasShiftDown() ? -1 : 1); diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java b/src/client/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java index ddfdd4d..2d6f1ea 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java @@ -104,8 +104,8 @@ public class SliderControllerElement extends ControllerWidget<ISliderController< return false; switch (keyCode) { - case InputConstants.KEY_LEFT, InputConstants.KEY_DOWN -> incrementValue(-1); - case InputConstants.KEY_RIGHT, InputConstants.KEY_UP -> incrementValue(1); + case InputConstants.KEY_LEFT -> incrementValue(-1); + case InputConstants.KEY_RIGHT -> incrementValue(1); default -> { return false; } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java b/src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java index 2723089..ce9d252 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java @@ -355,8 +355,9 @@ public class StringControllerElement extends ControllerWidget<IStringController< } @Override - public boolean changeFocus(boolean lookForwards) { - return inputFieldFocused = super.changeFocus(lookForwards); + public void setFocused(boolean focused) { + super.setFocused(focused); + inputFieldFocused = focused; } @Override |