aboutsummaryrefslogtreecommitdiff
path: root/src/client/java
diff options
context:
space:
mode:
authorisXander <xandersmith2008@gmail.com>2023-03-15 18:07:44 +0000
committerisXander <xandersmith2008@gmail.com>2023-03-15 18:07:44 +0000
commitc02229186aa13b1d699e2d00d24865260f158a54 (patch)
tree253a1b6adb72ef4299bc256b03482dd4b79d41c1 /src/client/java
parentc8a86cff89aa9072b6917c628406d3a06f4934ae (diff)
parente51e9bc95e2e271c8d55b063f9117eda0a100ab0 (diff)
downloadYetAnotherConfigLib-c02229186aa13b1d699e2d00d24865260f158a54.tar.gz
YetAnotherConfigLib-c02229186aa13b1d699e2d00d24865260f158a54.tar.bz2
YetAnotherConfigLib-c02229186aa13b1d699e2d00d24865260f158a54.zip
Merge branch 'update/1.19.4' into 1.19.x/dev
# Conflicts: # build.gradle.kts
Diffstat (limited to 'src/client/java')
-rw-r--r--src/client/java/dev/isxander/yacl/gui/CategoryWidget.java11
-rw-r--r--src/client/java/dev/isxander/yacl/gui/LowProfileButtonWidget.java6
-rw-r--r--src/client/java/dev/isxander/yacl/gui/SearchFieldWidget.java4
-rw-r--r--src/client/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java16
-rw-r--r--src/client/java/dev/isxander/yacl/gui/YACLScreen.java2
-rw-r--r--src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java22
-rw-r--r--src/client/java/dev/isxander/yacl/gui/controllers/LabelController.java42
-rw-r--r--src/client/java/dev/isxander/yacl/gui/controllers/cycling/CyclingControllerElement.java4
-rw-r--r--src/client/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java6
-rw-r--r--src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java5
-rw-r--r--src/client/java/dev/isxander/yacl/mixin/client/AbstractSelectionListMixin.java26
11 files changed, 110 insertions, 34 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/LowProfileButtonWidget.java b/src/client/java/dev/isxander/yacl/gui/LowProfileButtonWidget.java
index 3b66b6a..7e17aac 100644
--- a/src/client/java/dev/isxander/yacl/gui/LowProfileButtonWidget.java
+++ b/src/client/java/dev/isxander/yacl/gui/LowProfileButtonWidget.java
@@ -18,12 +18,12 @@ public class LowProfileButtonWidget extends Button {
}
@Override
- public void renderButton(PoseStack matrices, int mouseX, int mouseY, float delta) {
+ public void renderWidget(PoseStack matrices, int mouseX, int mouseY, float deltaTicks) {
if (!isHoveredOrFocused() || !active) {
int j = this.active ? 0xFFFFFF : 0xA0A0A0;
- drawCenteredString(matrices, Minecraft.getInstance().font, this.getMessage(), this.getX() + this.width / 2, this.getY() + (this.height - 8) / 2, j | Mth.ceil(this.alpha * 255.0F) << 24);
+ this.renderString(matrices, Minecraft.getInstance().font, j);
} else {
- super.renderButton(matrices, mouseX, mouseY, delta);
+ super.renderWidget(matrices, mouseX, mouseY, deltaTicks);
}
}
}
diff --git a/src/client/java/dev/isxander/yacl/gui/SearchFieldWidget.java b/src/client/java/dev/isxander/yacl/gui/SearchFieldWidget.java
index 1277c21..5cf38e0 100644
--- a/src/client/java/dev/isxander/yacl/gui/SearchFieldWidget.java
+++ b/src/client/java/dev/isxander/yacl/gui/SearchFieldWidget.java
@@ -22,8 +22,8 @@ public class SearchFieldWidget extends EditBox {
}
@Override
- public void renderButton(PoseStack matrices, int mouseX, int mouseY, float delta) {
- super.renderButton(matrices, mouseX, mouseY, delta);
+ public void renderWidget(PoseStack matrices, int mouseX, int mouseY, float delta) {
+ super.renderWidget(matrices, mouseX, mouseY, delta);
if (isVisible() && isEmpty()) {
font.drawShadow(matrices, emptyText, getX() + 4, this.getY() + (this.height - 8) / 2f, 0x707070);
}
diff --git a/src/client/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java b/src/client/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java
index 76ba14f..b955912 100644
--- a/src/client/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java
+++ b/src/client/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java
@@ -6,7 +6,6 @@ import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.network.chat.Component;
-import net.minecraft.util.FormattedCharSequence;
import net.minecraft.util.Mth;
public class TextScaledButtonWidget extends Button {
@@ -23,22 +22,13 @@ public class TextScaledButtonWidget extends Button {
}
@Override
- public void renderButton(PoseStack matrices, int mouseX, int mouseY, float delta) {
- // prevents super from rendering text
- Component message = getMessage();
- setMessage(Component.empty());
-
- super.renderButton(matrices, mouseX, mouseY, delta);
-
- setMessage(message);
- int j = this.active ? 16777215 : 10526880;
- FormattedCharSequence orderedText = getMessage().getVisualOrderText();
+ public void renderString(PoseStack matrices, Font textRenderer, int color) {
Font font = Minecraft.getInstance().font;
matrices.pushPose();
- matrices.translate(((this.getX() + this.width / 2f) - font.width(orderedText) * textScale / 2), (float)this.getY() + (this.height - 8 * textScale) / 2f / textScale, 0);
+ matrices.translate(((this.getX() + this.width / 2f) - font.width(getMessage()) * textScale / 2), (float)this.getY() + (this.height - 8 * textScale) / 2f / textScale, 0);
matrices.scale(textScale, textScale, 1);
- font.drawShadow(matrices, orderedText, 0, 0, j | Mth.ceil(this.alpha * 255.0F) << 24);
+ font.drawShadow(matrices, getMessage(), 0, 0, color | Mth.ceil(this.alpha * 255.0F) << 24);
matrices.popPose();
}
}
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..1dfae0b 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() - 1, getDimension().y() - 1, getDimension().xLimit() + 1, getDimension().y(), -1);
+ GuiComponent.fill(matrices, getDimension().x() - 1, getDimension().y() - 1, getDimension().x(), getDimension().yLimit() + 1, -1);
+ GuiComponent.fill(matrices, getDimension().x() - 1, getDimension().yLimit(), getDimension().xLimit() + 1, getDimension().yLimit() + 1, -1);
+ GuiComponent.fill(matrices, getDimension().xLimit(), getDimension().y() - 1, getDimension().xLimit() + 1, getDimension().yLimit() + 1, -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..d00f3d7 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;
}
@@ -158,7 +158,7 @@ public class SliderControllerElement extends ControllerWidget<ISliderController<
@Override
public void postRender(PoseStack matrices, int mouseX, int mouseY, float delta) {
- if (super.isMouseOver(mouseX, mouseY))
+ if (super.isMouseOver(mouseX, mouseY) || focused)
super.postRender(matrices, mouseX, mouseY, delta);
}
}
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
diff --git a/src/client/java/dev/isxander/yacl/mixin/client/AbstractSelectionListMixin.java b/src/client/java/dev/isxander/yacl/mixin/client/AbstractSelectionListMixin.java
new file mode 100644
index 0000000..978fd16
--- /dev/null
+++ b/src/client/java/dev/isxander/yacl/mixin/client/AbstractSelectionListMixin.java
@@ -0,0 +1,26 @@
+package dev.isxander.yacl.mixin.client;
+
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.components.AbstractSelectionList;
+import org.objectweb.asm.Opcodes;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Redirect;
+
+import java.util.List;
+
+@Mixin(AbstractSelectionList.class)
+public abstract class AbstractSelectionListMixin<E extends AbstractSelectionList.Entry<E>> {
+ @Shadow public abstract List<E> children();
+
+ /**
+ * Mojang use the field access of children to get max index to loop through keyboard navigation to find the next entry.
+ * YACL modifies these children() method to filter out hidden entries, so we need to redirect the field access to the
+ * method, so we don't get ArrayIndexOutOfBoundsException.
+ */
+ @Redirect(method = "nextEntry(Lnet/minecraft/client/gui/navigation/ScreenDirection;Ljava/util/function/Predicate;Lnet/minecraft/client/gui/components/AbstractSelectionList$Entry;)Lnet/minecraft/client/gui/components/AbstractSelectionList$Entry;", at = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/components/AbstractSelectionList;children:Ljava/util/List;", opcode = Opcodes.GETFIELD))
+ private List<E> modifyChildrenCall(AbstractSelectionList<E> instance) {
+ return children();
+ }
+}