diff options
author | isXander <xander@isxander.dev> | 2024-03-02 14:54:11 +0000 |
---|---|---|
committer | isXander <xander@isxander.dev> | 2024-03-02 14:54:11 +0000 |
commit | 831b894fdb7fe3e173d81387c8f6a2402b8ccfa9 (patch) | |
tree | 06180855a8b9d9b604dfbd615154f8529e585f39 | |
parent | e0fac3798200c9c718281c2b9bb6cc5da04a47d1 (diff) | |
download | YetAnotherConfigLib-831b894fdb7fe3e173d81387c8f6a2402b8ccfa9.tar.gz YetAnotherConfigLib-831b894fdb7fe3e173d81387c8f6a2402b8ccfa9.tar.bz2 YetAnotherConfigLib-831b894fdb7fe3e173d81387c8f6a2402b8ccfa9.zip |
Looks pretty now
5 files changed, 80 insertions, 13 deletions
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 a9a978f..02fc6ad 100644 --- a/common/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java +++ b/common/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java @@ -14,9 +14,12 @@ import org.jetbrains.annotations.Nullable; import java.util.function.Consumer; public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> extends ContainerObjectSelectionList<E> implements LayoutElement { + protected static final int SCROLLBAR_WIDTH = 6; + private double smoothScrollAmount = getScrollAmount(); private boolean returnSmoothAmount = false; private final boolean doSmoothScrolling; + private boolean usingScrollbar; public ElementListWidgetExt(Minecraft client, int x, int y, int width, int height, boolean smoothScrolling) { super(client, x, y, width, height); @@ -34,11 +37,15 @@ public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> exten @Override protected int getScrollbarPosition() { // default implementation does not respect left/right - return this.getX() + this.getWidth() - 2; + return this.getRight() - SCROLLBAR_WIDTH; } @Override public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float delta) { + if (usingScrollbar) { + resetSmoothScrolling(); + } + smoothScrollAmount = Mth.lerp(Minecraft.getInstance().getDeltaFrameTime() * 0.5, smoothScrollAmount, getScrollAmount()); returnSmoothAmount = true; @@ -51,6 +58,24 @@ public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> exten returnSmoothAmount = false; } + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + if (button == 0 && mouseX >= getScrollbarPosition() && mouseX < getScrollbarPosition() + SCROLLBAR_WIDTH) { + usingScrollbar = true; + } + + return super.mouseClicked(mouseX, mouseY, button); + } + + @Override + public boolean mouseReleased(double mouseX, double mouseY, int button) { + if (button == 0) { + usingScrollbar = false; + } + + return super.mouseReleased(mouseX, mouseY, button); + } + public void updateDimensions(ScreenRectangle rectangle) { this.setX(rectangle.left()); this.setY(rectangle.top()); @@ -71,7 +96,7 @@ public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> exten } protected void resetSmoothScrolling() { - this.smoothScrollAmount = getScrollAmount(); + this.smoothScrollAmount = super.getScrollAmount(); } @Nullable 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 20604ef..9e1931f 100644 --- a/common/src/main/java/dev/isxander/yacl3/gui/OptionListWidget.java +++ b/common/src/main/java/dev/isxander/yacl3/gui/OptionListWidget.java @@ -135,8 +135,13 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr } @Override + public int getRowLeft() { + return super.getRowLeft() - SCROLLBAR_WIDTH; + } + + @Override public int getRowWidth() { - return Math.min(396, (int)(width / 1.3f)); + return getWidth() - SCROLLBAR_WIDTH - 20; } @Override @@ -181,11 +186,6 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr return super.charTyped(chr, modifiers); } - @Override - protected int getScrollbarPosition() { - return getX() + getWidth() - (int)(width * 0.05f); - } - public void recacheViewableChildren() { this.viewableChildren = ImmutableList.copyOf(super.children().stream().filter(Entry::isViewable).toList()); @@ -246,6 +246,7 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr @Override protected void renderListBackground(GuiGraphics guiGraphics) { + //super.renderListBackground(); } public abstract class Entry extends ElementListWidgetExt.Entry<Entry> { 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 a24b87a..01c5d99 100644 --- a/common/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java +++ b/common/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java @@ -2,6 +2,7 @@ package dev.isxander.yacl3.gui; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.*; +import com.mojang.math.Axis; import dev.isxander.yacl3.api.*; import dev.isxander.yacl3.api.utils.Dimension; import dev.isxander.yacl3.api.utils.MutableDimension; @@ -18,23 +19,25 @@ import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.MultiLineLabel; import net.minecraft.client.gui.components.Tooltip; -import net.minecraft.client.gui.components.tabs.Tab; import net.minecraft.client.gui.components.tabs.TabManager; import net.minecraft.client.gui.components.tabs.TabNavigationBar; import net.minecraft.client.gui.navigation.ScreenRectangle; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.tooltip.TooltipRenderUtil; +import net.minecraft.client.gui.screens.worldselection.CreateWorldScreen; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.Nullable; import java.util.HashSet; import java.util.Set; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Consumer; public class YACLScreen extends Screen { + private static final ResourceLocation DARKER_BG = new ResourceLocation("textures/gui/menu_list_background.png"); + public final YetAnotherConfigLib config; private final Screen parent; @@ -61,6 +64,8 @@ public class YACLScreen extends Screen { @Override protected void init() { + tabArea = new ScreenRectangle(0, 24 - 1, this.width, this.height - 24 + 1); + int currentTab = tabNavigationBar != null ? tabNavigationBar.tabs.indexOf(tabManager.getCurrentTab()) : 0; @@ -76,14 +81,21 @@ public class YACLScreen extends Screen { }).toList()); tabNavigationBar.selectTab(currentTab, false); tabNavigationBar.arrangeElements(); - ScreenRectangle navBarArea = tabNavigationBar.getRectangle(); - tabArea = new ScreenRectangle(0, navBarArea.height() - 1, this.width, this.height - navBarArea.height() + 1); tabManager.setTabArea(tabArea); addRenderableWidget(tabNavigationBar); config.initConsumer().accept(this); } + @Override + public void renderBackground(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) { + super.renderBackground(guiGraphics, mouseX, mouseY, partialTick); + + if (tabManager.getCurrentTab() instanceof TabExt tab) { + tab.renderBackground(guiGraphics); + } + } + protected void finishOrSave() { saveButtonMessage = null; @@ -247,6 +259,8 @@ public class YACLScreen extends Screen { private final SearchFieldWidget searchField; private OptionDescriptionWidget descriptionWidget; + private final ScreenRectangle rightPaneDim; + public CategoryTab(ConfigCategory category) { this.category = category; this.tooltip = Tooltip.create(category.tooltip()); @@ -255,6 +269,7 @@ public class YACLScreen extends Screen { int padding = columnWidth / 20; columnWidth = Math.min(columnWidth, 400); int paddedWidth = columnWidth - padding * 2; + rightPaneDim = new ScreenRectangle(width / 3 * 2, tabArea.top() + 1, width / 3, tabArea.height()); MutableDimension<Integer> actionDim = Dimension.ofInt(width / 3 * 2 + width / 6, height - padding - 20, paddedWidth, 20); saveFinishedButton = Button.builder(Component.literal("Done"), btn -> finishOrSave()) @@ -287,7 +302,7 @@ public class YACLScreen extends Screen { ); this.optionList = new ListHolderWidget<>( - () -> new ScreenRectangle(tabArea.position(), tabArea.width() / 3 * 2 + 1, tabArea.height()), + () -> new ScreenRectangle(tabArea.position(), tabArea.width() / 3 * 2, tabArea.height()), new OptionListWidget(YACLScreen.this, category, minecraft, 0, 0, width / 3 * 2 + 1, height, desc -> { descriptionWidget.setOptionDescription(desc); }) @@ -322,6 +337,28 @@ public class YACLScreen extends Screen { } @Override + public void renderBackground(GuiGraphics graphics) { + RenderSystem.enableBlend(); + // right pane darker db + graphics.blit(DARKER_BG, rightPaneDim.left(), rightPaneDim.top(), rightPaneDim.right() + 2, rightPaneDim.bottom() + 2, rightPaneDim.width() + 2, rightPaneDim.height() + 2, 32, 32); + + // top separator for right pane + graphics.pose().pushPose(); + graphics.pose().translate(0, 0, 10); + graphics.blit(CreateWorldScreen.HEADER_SEPARATOR, rightPaneDim.left() - 1, rightPaneDim.top() - 2, 0.0F, 0.0F, rightPaneDim.width() + 1, 2, 32, 2); + graphics.pose().popPose(); + + // left separator for right pane + graphics.pose().pushPose(); + graphics.pose().translate(rightPaneDim.left(), rightPaneDim.top() - 1, 0); + graphics.pose().rotateAround(Axis.ZP.rotationDegrees(90), 0, 0, 1); + graphics.blit(CreateWorldScreen.FOOTER_SEPARATOR, 0, 0, 0f, 0f, rightPaneDim.height() + 1, 2, 32, 2); + graphics.pose().popPose(); + + RenderSystem.disableBlend(); + } + + @Override public void doLayout(ScreenRectangle screenRectangle) { } 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 8ddc5c7..1b4b3e5 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 @@ -1,5 +1,6 @@ package dev.isxander.yacl3.gui.tab; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Tooltip; import net.minecraft.client.gui.components.tabs.Tab; import org.jetbrains.annotations.Nullable; @@ -8,4 +9,6 @@ public interface TabExt extends Tab { @Nullable Tooltip getTooltip(); default void tick() {} + + default void renderBackground(GuiGraphics graphics) {} } diff --git a/common/src/main/resources/yacl.accesswidener b/common/src/main/resources/yacl.accesswidener index 39e8981..54b0c13 100644 --- a/common/src/main/resources/yacl.accesswidener +++ b/common/src/main/resources/yacl.accesswidener @@ -10,3 +10,4 @@ accessible field net/minecraft/client/gui/components/tabs/TabNavigationBar tabMa accessible field net/minecraft/client/gui/components/tabs/TabNavigationBar tabs Lcom/google/common/collect/ImmutableList; accessible field net/minecraft/client/gui/components/tabs/TabNavigationBar tabButtons Lcom/google/common/collect/ImmutableList; accessible method net/minecraft/client/gui/components/Tooltip <init> (Lnet/minecraft/network/chat/Component;Lnet/minecraft/network/chat/Component;)V +accessible field net/minecraft/client/gui/components/AbstractSelectionList scrolling Z |