diff options
author | isXander <xander@isxander.dev> | 2023-05-27 21:32:41 +0100 |
---|---|---|
committer | isXander <xander@isxander.dev> | 2023-05-27 21:32:41 +0100 |
commit | 42cce53d6b5eccd1218c0fe0ea576417cb5e0119 (patch) | |
tree | a6cfad07f7f06f3c4a7b1e05d7888ab1b99cd596 /common/src/main/java/dev/isxander/yacl | |
parent | d014d66e3aeda3399b86294119c13501cab5b8c1 (diff) | |
download | YetAnotherConfigLib-42cce53d6b5eccd1218c0fe0ea576417cb5e0119.tar.gz YetAnotherConfigLib-42cce53d6b5eccd1218c0fe0ea576417cb5e0119.tar.bz2 YetAnotherConfigLib-42cce53d6b5eccd1218c0fe0ea576417cb5e0119.zip |
reimplement category tooltips
Diffstat (limited to 'common/src/main/java/dev/isxander/yacl')
-rw-r--r-- | common/src/main/java/dev/isxander/yacl/gui/ImageRenderer.java | 2 | ||||
-rw-r--r-- | common/src/main/java/dev/isxander/yacl/gui/YACLScreen.java | 32 | ||||
-rw-r--r-- | common/src/main/java/dev/isxander/yacl/gui/tab/ListHolderWidget.java (renamed from common/src/main/java/dev/isxander/yacl/gui/TabListWidget.java) | 11 | ||||
-rw-r--r-- | common/src/main/java/dev/isxander/yacl/gui/tab/ScrollableNavigationBar.java (renamed from common/src/main/java/dev/isxander/yacl/gui/ScrollableNavigationBar.java) | 14 | ||||
-rw-r--r-- | common/src/main/java/dev/isxander/yacl/gui/tab/TabExt.java | 9 |
5 files changed, 48 insertions, 20 deletions
diff --git a/common/src/main/java/dev/isxander/yacl/gui/ImageRenderer.java b/common/src/main/java/dev/isxander/yacl/gui/ImageRenderer.java index 25be791..5a48f5f 100644 --- a/common/src/main/java/dev/isxander/yacl/gui/ImageRenderer.java +++ b/common/src/main/java/dev/isxander/yacl/gui/ImageRenderer.java @@ -32,7 +32,7 @@ import java.util.function.Supplier; import java.util.stream.IntStream; public interface ImageRenderer { - int render(GuiGraphics graphics, int x, int y, int width); + int render(GuiGraphics graphics, int x, int y, int renderWidth); void close(); diff --git a/common/src/main/java/dev/isxander/yacl/gui/YACLScreen.java b/common/src/main/java/dev/isxander/yacl/gui/YACLScreen.java index d225d7e..1e52cde 100644 --- a/common/src/main/java/dev/isxander/yacl/gui/YACLScreen.java +++ b/common/src/main/java/dev/isxander/yacl/gui/YACLScreen.java @@ -6,6 +6,9 @@ import dev.isxander.yacl.api.*; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.api.utils.MutableDimension; import dev.isxander.yacl.api.utils.OptionUtils; +import dev.isxander.yacl.gui.tab.ScrollableNavigationBar; +import dev.isxander.yacl.gui.tab.ListHolderWidget; +import dev.isxander.yacl.gui.tab.TabExt; import dev.isxander.yacl.gui.utils.GuiUtils; import dev.isxander.yacl.impl.utils.YACLConstants; import net.minecraft.ChatFormatting; @@ -15,7 +18,6 @@ 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.events.GuiEventListener; import net.minecraft.client.gui.components.tabs.Tab; import net.minecraft.client.gui.components.tabs.TabManager; import net.minecraft.client.gui.components.tabs.TabNavigationBar; @@ -25,13 +27,10 @@ import net.minecraft.client.gui.screens.inventory.tooltip.TooltipRenderUtil; 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.io.*; import java.util.HashSet; -import java.util.Optional; import java.util.Set; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Consumer; @@ -213,10 +212,11 @@ public class YACLScreen extends Screen { } } - private class CategoryTab implements Tab { + private class CategoryTab implements TabExt { private final ConfigCategory category; + private final Tooltip tooltip; - private TabListWidget<OptionListWidget> optionList; + private ListHolderWidget<OptionListWidget> optionList; private final Button saveFinishedButton; private final Button cancelResetButton; private final Button undoButton; @@ -225,6 +225,7 @@ public class YACLScreen extends Screen { public CategoryTab(ConfigCategory category) { this.category = category; + this.tooltip = Tooltip.create(category.tooltip()); int columnWidth = width / 3; int padding = columnWidth / 20; @@ -261,7 +262,7 @@ public class YACLScreen extends Screen { searchQuery -> optionList.getList().updateSearchQuery(searchQuery) ); - this.optionList = new TabListWidget<>( + this.optionList = new ListHolderWidget<>( () -> new ScreenRectangle(tabArea.position(), tabArea.width() / 3 * 2 + 1, tabArea.height()), new OptionListWidget(YACLScreen.this, category, minecraft, 0, 0, width / 3 * 2 + 1, height, desc -> { descriptionWidget.setOptionDescription(desc); @@ -308,6 +309,12 @@ public class YACLScreen extends Screen { descriptionWidget.tick(); } + @Nullable + @Override + public Tooltip getTooltip() { + return tooltip; + } + private void updateButtons() { boolean pendingChanges = pendingChanges(); @@ -319,11 +326,13 @@ public class YACLScreen extends Screen { } } - private class PlaceholderTab implements Tab { + private class PlaceholderTab implements TabExt { private final PlaceholderCategory category; + private final Tooltip tooltip; public PlaceholderTab(PlaceholderCategory category) { this.category = category; + this.tooltip = Tooltip.create(category.tooltip()); } @Override @@ -340,5 +349,10 @@ public class YACLScreen extends Screen { public void doLayout(ScreenRectangle screenRectangle) { minecraft.setScreen(category.screen().apply(minecraft, YACLScreen.this)); } + + @Override + public @Nullable Tooltip getTooltip() { + return this.tooltip; + } } } diff --git a/common/src/main/java/dev/isxander/yacl/gui/TabListWidget.java b/common/src/main/java/dev/isxander/yacl/gui/tab/ListHolderWidget.java index 041c06a..84aba61 100644 --- a/common/src/main/java/dev/isxander/yacl/gui/TabListWidget.java +++ b/common/src/main/java/dev/isxander/yacl/gui/tab/ListHolderWidget.java @@ -1,6 +1,7 @@ -package dev.isxander.yacl.gui; +package dev.isxander.yacl.gui.tab; import com.google.common.collect.ImmutableList; +import dev.isxander.yacl.gui.ElementListWidgetExt; import net.minecraft.client.gui.ComponentPath; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.AbstractWidget; @@ -15,15 +16,11 @@ import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.function.Supplier; -/** - * Author: MrCrayfish - */ -public class TabListWidget<T extends ElementListWidgetExt<?>> extends AbstractWidget implements ContainerEventHandler -{ +public class ListHolderWidget<T extends ElementListWidgetExt<?>> extends AbstractWidget implements ContainerEventHandler { private final Supplier<ScreenRectangle> dimensions; private final T list; - public TabListWidget(Supplier<ScreenRectangle> dimensions, T list) { + public ListHolderWidget(Supplier<ScreenRectangle> dimensions, T list) { super(0, 0, 100, 0, CommonComponents.EMPTY); this.dimensions = dimensions; this.list = list; diff --git a/common/src/main/java/dev/isxander/yacl/gui/ScrollableNavigationBar.java b/common/src/main/java/dev/isxander/yacl/gui/tab/ScrollableNavigationBar.java index 62c63db..17d53b8 100644 --- a/common/src/main/java/dev/isxander/yacl/gui/ScrollableNavigationBar.java +++ b/common/src/main/java/dev/isxander/yacl/gui/tab/ScrollableNavigationBar.java @@ -1,5 +1,6 @@ -package dev.isxander.yacl.gui; +package dev.isxander.yacl.gui.tab; +import com.google.common.collect.ImmutableList; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; import net.minecraft.client.gui.components.AbstractWidget; @@ -19,8 +20,15 @@ public class ScrollableNavigationBar extends TabNavigationBar { private int scrollOffset; private int maxScrollOffset; - public ScrollableNavigationBar(int i, TabManager tabManager, Iterable<Tab> iterable) { - super(i, tabManager, iterable); + public ScrollableNavigationBar(int width, TabManager tabManager, Iterable<? extends Tab> tabs) { + super(width, tabManager, ImmutableList.copyOf(tabs)); + + // add tab tooltips to the tab buttons + for (TabButton tabButton : this.tabButtons) { + if (tabButton.tab() instanceof TabExt tab) { + tabButton.setTooltip(tab.getTooltip()); + } + } } @Override diff --git a/common/src/main/java/dev/isxander/yacl/gui/tab/TabExt.java b/common/src/main/java/dev/isxander/yacl/gui/tab/TabExt.java new file mode 100644 index 0000000..7462a2c --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl/gui/tab/TabExt.java @@ -0,0 +1,9 @@ +package dev.isxander.yacl.gui.tab; + +import net.minecraft.client.gui.components.Tooltip; +import net.minecraft.client.gui.components.tabs.Tab; +import org.jetbrains.annotations.Nullable; + +public interface TabExt extends Tab { + @Nullable Tooltip getTooltip(); +} |