aboutsummaryrefslogtreecommitdiff
path: root/common/src/main
diff options
context:
space:
mode:
authorisXander <xandersmith2008@gmail.com>2023-09-24 15:48:15 +0100
committerisXander <xandersmith2008@gmail.com>2023-09-24 15:48:15 +0100
commitd2b67633c1d3ca0c46682b05955dafafd3597f1d (patch)
tree7e7ae123d0cb945a45eb940a12eb03a4d4e04d80 /common/src/main
parent554646dbd857e2fab1be8339ce8d0231ef2dbb4c (diff)
downloadYetAnotherConfigLib-d2b67633c1d3ca0c46682b05955dafafd3597f1d.tar.gz
YetAnotherConfigLib-d2b67633c1d3ca0c46682b05955dafafd3597f1d.tar.bz2
YetAnotherConfigLib-d2b67633c1d3ca0c46682b05955dafafd3597f1d.zip
1.20.2
Diffstat (limited to 'common/src/main')
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java17
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java13
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/OptionDescriptionWidget.java4
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/OptionListWidget.java10
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java36
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/controllers/slider/SliderControllerElement.java4
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/tab/ListHolderWidget.java4
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/tab/ScrollableNavigationBar.java4
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/tab/TabExt.java2
-rw-r--r--common/src/main/java/dev/isxander/yacl3/mixin/ContainerEventHandlerMixin.java31
-rw-r--r--common/src/main/resources/yacl.accesswidener1
-rw-r--r--common/src/main/resources/yacl.mixins.json1
12 files changed, 49 insertions, 78 deletions
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java b/common/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java
index a34329a..0c3afdd 100644
--- a/common/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java
+++ b/common/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java
@@ -5,15 +5,24 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Renderable;
+import net.minecraft.client.gui.components.WidgetSprites;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.narration.NarratableEntry;
import net.minecraft.client.gui.narration.NarrationElementOutput;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
+import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import java.awt.*;
public abstract class AbstractWidget implements GuiEventListener, Renderable, NarratableEntry {
+ private static final WidgetSprites SPRITES = new WidgetSprites(
+ new ResourceLocation("widget/button"), // normal
+ new ResourceLocation("widget/button_disabled"), // disabled & !focused
+ new ResourceLocation("widget/button_highlighted"), // !disabled & focused
+ new ResourceLocation("widget/slider_highlighted") // disabled & focused
+ );
+
protected final Minecraft client = Minecraft.getInstance();
protected final Font textRenderer = client.font;
protected final int inactiveColor = 0xFFA0A0A0;
@@ -74,13 +83,7 @@ public abstract class AbstractWidget implements GuiEventListener, Renderable, Na
int width = x2 - x1;
int height = y2 - y1;
- int i = !enabled ? 0 : hovered ? 2 : 1;
- graphics.blit(net.minecraft.client.gui.components.AbstractWidget.WIDGETS_LOCATION, x1, y1, 0, 0, 46 + i * 20, width / 2, height, 256, 256);
- graphics.blit(net.minecraft.client.gui.components.AbstractWidget.WIDGETS_LOCATION, x1 + width / 2, y1, 0, 200 - width / 2f, 46 + i * 20, width / 2, height, 256, 256);
-
- if (hovered && !enabled) {
- drawOutline(graphics, x1, y1, x2, y2, 1, 0xFFD0D0D0);
- }
+ graphics.blitSprite(SPRITES.get(enabled, hovered), x1, y1, width, height);
}
protected void drawOutline(GuiGraphics graphics, int x1, int y1, int x2, int y2, int width, int color) {
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java b/common/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java
index e3944ee..a36bd5e 100644
--- a/common/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java
+++ b/common/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java
@@ -26,23 +26,18 @@ public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> exten
this.y = y;
this.x1 = this.x0 + width;
this.doSmoothScrolling = smoothScrolling;
+ setRenderBackground(true);
+ setRenderHeader(false, 0);
}
@Override
- public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
+ public boolean mouseScrolled(double mouseX, double mouseY, double horizontal, double vertical) {
// default implementation bases scroll step from total height of entries, this is constant
- this.setScrollAmount(this.getScrollAmount() - amount * 20);
+ this.setScrollAmount(this.getScrollAmount() - (vertical + horizontal) * 20);
return true;
}
@Override
- protected void renderBackground(GuiGraphics graphics) {
- // render transparent background if in-game.
- setRenderBackground(true);
- setRenderTopAndBottom(false);
- }
-
- @Override
protected int getScrollbarPosition() {
// default implementation does not respect left/right
return this.x1 - 2;
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/OptionDescriptionWidget.java b/common/src/main/java/dev/isxander/yacl3/gui/OptionDescriptionWidget.java
index 0732c5f..7aa3715 100644
--- a/common/src/main/java/dev/isxander/yacl3/gui/OptionDescriptionWidget.java
+++ b/common/src/main/java/dev/isxander/yacl3/gui/OptionDescriptionWidget.java
@@ -122,9 +122,9 @@ public class OptionDescriptionWidget extends AbstractWidget {
}
@Override
- public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
+ public boolean mouseScrolled(double mouseX, double mouseY, double horizontal, double vertical) {
if (isMouseOver(mouseX, mouseY)) {
- targetScrollAmount = Mth.clamp(targetScrollAmount - (int) amount * 10, 0, maxScrollAmount);
+ targetScrollAmount = Mth.clamp(targetScrollAmount - (int) vertical * 10, 0, maxScrollAmount);
lastInteractionTime = currentTimeMS();
return true;
}
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/OptionListWidget.java b/common/src/main/java/dev/isxander/yacl3/gui/OptionListWidget.java
index 3197c44..666c3c8 100644
--- a/common/src/main/java/dev/isxander/yacl3/gui/OptionListWidget.java
+++ b/common/src/main/java/dev/isxander/yacl3/gui/OptionListWidget.java
@@ -150,11 +150,11 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr
}
@Override
- public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
- super.mouseScrolled(mouseX, mouseY, amount);
+ public boolean mouseScrolled(double mouseX, double mouseY, double horizontal, double vertical) {
+ super.mouseScrolled(mouseX, mouseY, horizontal, vertical);
for (Entry child : children()) {
- if (child.mouseScrolled(mouseX, mouseY, amount))
+ if (child.mouseScrolled(mouseX, mouseY, horizontal, vertical))
break;
}
@@ -305,8 +305,8 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr
}
@Override
- public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
- return widget.mouseScrolled(mouseX, mouseY, amount);
+ public boolean mouseScrolled(double mouseX, double mouseY, double horizontal, double vertical) {
+ return widget.mouseScrolled(mouseX, mouseY, horizontal, vertical);
}
@Override
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java b/common/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java
index b363ada..0bf9c65 100644
--- a/common/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java
+++ b/common/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java
@@ -43,7 +43,8 @@ public class YACLScreen extends Screen {
public TabNavigationBar tabNavigationBar;
public ScreenRectangle tabArea;
- public Component saveButtonMessage, saveButtonTooltipMessage;
+ public Component saveButtonMessage;
+ public Tooltip saveButtonTooltipMessage;
private int saveButtonMessageTime;
public YACLScreen(YetAnotherConfigLib config, Screen parent) {
@@ -122,18 +123,22 @@ public class YACLScreen extends Screen {
@Override
public void tick() {
- tabManager.tickCurrent();
-
- if (saveButtonMessage != null) {
- if (saveButtonMessageTime > 140) {
- saveButtonMessage = null;
- saveButtonTooltipMessage = null;
- saveButtonMessageTime = 0;
- } else {
- saveButtonMessageTime++;
- //finishedSaveButton.setMessage(saveButtonMessage);
- if (saveButtonTooltipMessage != null) {
- //finishedSaveButton.setTooltip(saveButtonTooltipMessage);
+ if (tabManager.getCurrentTab() instanceof TabExt tabExt) {
+ tabExt.tick();
+ }
+
+ if (tabManager.getCurrentTab() instanceof CategoryTab categoryTab) {
+ if (saveButtonMessage != null) {
+ if (saveButtonMessageTime > 140) {
+ saveButtonMessage = null;
+ saveButtonTooltipMessage = null;
+ saveButtonMessageTime = 0;
+ } else {
+ saveButtonMessageTime++;
+ categoryTab.saveFinishedButton.setMessage(saveButtonMessage);
+ if (saveButtonTooltipMessage != null) {
+ categoryTab.saveFinishedButton.setTooltip(saveButtonTooltipMessage);
+ }
}
}
}
@@ -141,7 +146,7 @@ public class YACLScreen extends Screen {
private void setSaveButtonMessage(Component message, Component tooltip) {
saveButtonMessage = message;
- saveButtonTooltipMessage = tooltip;
+ saveButtonTooltipMessage = Tooltip.create(tooltip);
saveButtonMessageTime = 0;
}
@@ -222,7 +227,7 @@ public class YACLScreen extends Screen {
private final Tooltip tooltip;
private ListHolderWidget<OptionListWidget> optionList;
- private final Button saveFinishedButton;
+ public final Button saveFinishedButton;
private final Button cancelResetButton;
private final Button undoButton;
private final SearchFieldWidget searchField;
@@ -310,7 +315,6 @@ public class YACLScreen extends Screen {
@Override
public void tick() {
updateButtons();
- searchField.tick();
descriptionWidget.tick();
}
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/controllers/slider/SliderControllerElement.java b/common/src/main/java/dev/isxander/yacl3/gui/controllers/slider/SliderControllerElement.java
index 5590dbf..32d7561 100644
--- a/common/src/main/java/dev/isxander/yacl3/gui/controllers/slider/SliderControllerElement.java
+++ b/common/src/main/java/dev/isxander/yacl3/gui/controllers/slider/SliderControllerElement.java
@@ -80,11 +80,11 @@ public class SliderControllerElement extends ControllerWidget<ISliderController<
}
@Override
- public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
+ public boolean mouseScrolled(double mouseX, double mouseY, double horizontal, double vertical) {
if (!isAvailable() || (!isMouseOver(mouseX, mouseY)) || (!Screen.hasShiftDown() && !Screen.hasControlDown()))
return false;
- incrementValue(amount);
+ incrementValue(vertical);
return true;
}
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/tab/ListHolderWidget.java b/common/src/main/java/dev/isxander/yacl3/gui/tab/ListHolderWidget.java
index 5059874..df28d27 100644
--- a/common/src/main/java/dev/isxander/yacl3/gui/tab/ListHolderWidget.java
+++ b/common/src/main/java/dev/isxander/yacl3/gui/tab/ListHolderWidget.java
@@ -67,8 +67,8 @@ public class ListHolderWidget<T extends ElementListWidgetExt<?>> extends Abstrac
}
@Override
- public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
- return this.list.mouseScrolled(mouseX, mouseY, amount);
+ public boolean mouseScrolled(double mouseX, double mouseY, double horizontal, double vertical) {
+ return this.list.mouseScrolled(mouseX, mouseY, horizontal, vertical);
}
@Override
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/tab/ScrollableNavigationBar.java b/common/src/main/java/dev/isxander/yacl3/gui/tab/ScrollableNavigationBar.java
index da1965f..66ba6a3 100644
--- a/common/src/main/java/dev/isxander/yacl3/gui/tab/ScrollableNavigationBar.java
+++ b/common/src/main/java/dev/isxander/yacl3/gui/tab/ScrollableNavigationBar.java
@@ -77,8 +77,8 @@ public class ScrollableNavigationBar extends TabNavigationBar {
}
@Override
- public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
- this.setScrollOffset(this.scrollOffset - (int)(amount*10));
+ public boolean mouseScrolled(double mouseX, double mouseY, double horizontal, double vertical) {
+ this.setScrollOffset(this.scrollOffset - (int)(vertical*15));
return true;
}
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/tab/TabExt.java b/common/src/main/java/dev/isxander/yacl3/gui/tab/TabExt.java
index 3b29594..8ddc5c7 100644
--- a/common/src/main/java/dev/isxander/yacl3/gui/tab/TabExt.java
+++ b/common/src/main/java/dev/isxander/yacl3/gui/tab/TabExt.java
@@ -6,4 +6,6 @@ import org.jetbrains.annotations.Nullable;
public interface TabExt extends Tab {
@Nullable Tooltip getTooltip();
+
+ default void tick() {}
}
diff --git a/common/src/main/java/dev/isxander/yacl3/mixin/ContainerEventHandlerMixin.java b/common/src/main/java/dev/isxander/yacl3/mixin/ContainerEventHandlerMixin.java
deleted file mode 100644
index 9fe8c58..0000000
--- a/common/src/main/java/dev/isxander/yacl3/mixin/ContainerEventHandlerMixin.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package dev.isxander.yacl3.mixin;
-
-import net.minecraft.client.gui.components.events.ContainerEventHandler;
-import net.minecraft.client.gui.components.events.GuiEventListener;
-import net.minecraft.client.gui.components.tabs.TabNavigationBar;
-import net.minecraft.client.gui.navigation.FocusNavigationEvent;
-import net.minecraft.client.gui.navigation.ScreenAxis;
-import net.minecraft.client.gui.navigation.ScreenDirection;
-import net.minecraft.client.gui.navigation.ScreenRectangle;
-import org.jetbrains.annotations.Nullable;
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.injection.At;
-import org.spongepowered.asm.mixin.injection.Redirect;
-
-import java.util.List;
-
-@Mixin(ContainerEventHandler.class)
-public interface ContainerEventHandlerMixin {
- /**
- * This mixin is used to prevent the tab bar from being focused when navigating left or right
- * through the YACL options screen. This can also apply to vanilla as navigating left or right
- * should never result in focusing the always-at-the-top tab bar.
- * Without this, navigating right from the option list focuses the tab bar, not the action buttons/description.
- */
- @Redirect(method = {"nextFocusPathVaguelyInDirection", "nextFocusPathInDirection"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/components/events/ContainerEventHandler;children()Ljava/util/List;"))
- default List<?> modifyFocusCandidates(ContainerEventHandler instance, ScreenRectangle screenArea, ScreenDirection direction, @Nullable GuiEventListener focused, FocusNavigationEvent event) {
- if (direction.getAxis() == ScreenAxis.HORIZONTAL)
- return instance.children().stream().filter(child -> !(child instanceof TabNavigationBar)).toList();
- return instance.children();
- }
-}
diff --git a/common/src/main/resources/yacl.accesswidener b/common/src/main/resources/yacl.accesswidener
index 303b57a..286b6ab 100644
--- a/common/src/main/resources/yacl.accesswidener
+++ b/common/src/main/resources/yacl.accesswidener
@@ -3,7 +3,6 @@ accessWidener v2 named
extendable method net/minecraft/client/gui/components/AbstractSelectionList children ()Ljava/util/List;
extendable method net/minecraft/client/gui/components/AbstractSelectionList getEntryAtPosition (DD)Lnet/minecraft/client/gui/components/AbstractSelectionList$Entry;
accessible class net/minecraft/client/gui/components/AbstractSelectionList$Entry
-extendable method net/minecraft/client/gui/components/AbstractButton getTextureY ()I
accessible method net/minecraft/client/gui/components/tabs/TabNavigationBar <init> (ILnet/minecraft/client/gui/components/tabs/TabManager;Ljava/lang/Iterable;)V
accessible field net/minecraft/client/gui/components/tabs/TabNavigationBar layout Lnet/minecraft/client/gui/layouts/GridLayout;
accessible field net/minecraft/client/gui/components/tabs/TabNavigationBar width I
diff --git a/common/src/main/resources/yacl.mixins.json b/common/src/main/resources/yacl.mixins.json
index 3b67b21..0225b44 100644
--- a/common/src/main/resources/yacl.mixins.json
+++ b/common/src/main/resources/yacl.mixins.json
@@ -7,7 +7,6 @@
},
"client": [
"AbstractSelectionListMixin",
- "ContainerEventHandlerMixin",
"MinecraftMixin",
"OptionInstanceAccessor"
]