diff --git a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java index 2eca4233..d9742ff2 100644 --- a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java +++ b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java @@ -1711,6 +1711,10 @@ public static class AdvancementsCategory @Config.Name("[09] Add Advancement Tab Title to Header") @Config.Comment("Makes the focused Advancement Tab Title be added to the header, which otherwise is just 'Advancements' for every tab") public boolean utAddFocusedTabTitleToHeader = true; + + @Config.Name("[10] Remember Tab Scroll Position") + @Config.Comment("Remembers and restores the last advancement tab scroll position") + public boolean utRememberTabScrollPosition = false; } public static class ArmorCurveCategory diff --git a/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/advancements/guisize/UTAdvancementInfo.java b/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/advancements/guisize/UTAdvancementInfo.java index 3d41c8f9..efc6c45c 100644 --- a/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/advancements/guisize/UTAdvancementInfo.java +++ b/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/advancements/guisize/UTAdvancementInfo.java @@ -11,6 +11,10 @@ public class UTAdvancementInfo private static final int HEIGHT_MULT = 28; private static final int WIDTH_MULT = 32; + public static int lastScrollX = -1; + public static int lastScrollY = -1; + public static int lastSelectedTabIndex; + public static int utPageWidth(int externalWidth) { return utStepwiseWidth(utClampWidth(externalWidth - UTConfigTweaks.MISC.ADVANCEMENTS.utHorizontalMargin * 2)); diff --git a/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/advancements/guisize/mixin/UTGuiAdvancementTabAccessor.java b/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/advancements/guisize/mixin/UTGuiAdvancementTabAccessor.java new file mode 100644 index 00000000..93793538 --- /dev/null +++ b/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/advancements/guisize/mixin/UTGuiAdvancementTabAccessor.java @@ -0,0 +1,19 @@ +package mod.acgaming.universaltweaks.tweaks.misc.advancements.guisize.mixin; + +import net.minecraft.client.gui.advancements.GuiAdvancementTab; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(GuiAdvancementTab.class) +public interface UTGuiAdvancementTabAccessor +{ + @Accessor("scrollX") + int getScrollX(); + + @Accessor("scrollY") + int getScrollY(); + + @Accessor("index") + int getIndex(); +} diff --git a/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/advancements/guisize/mixin/UTGuiAdvancementTabMixin.java b/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/advancements/guisize/mixin/UTGuiAdvancementTabMixin.java index b5dc6193..8d8fe707 100644 --- a/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/advancements/guisize/mixin/UTGuiAdvancementTabMixin.java +++ b/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/advancements/guisize/mixin/UTGuiAdvancementTabMixin.java @@ -15,7 +15,9 @@ import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Constant; +import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyConstant; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; // Courtesy of WaitingIdly @Mixin(GuiAdvancementTab.class) @@ -39,6 +41,16 @@ private static int utAdjustIndividualMaxTabs(AdvancementTabType instance, Operat @Final private GuiScreenAdvancements screen; + @Shadow + private int scrollX; + @Shadow + private int scrollY; + @Shadow + @Final + private int index; + @Shadow + private boolean centered; + // update the size @ModifyConstant(method = {"drawContents", "scroll", "drawToolTips"}, constant = @Constant(intValue = UTAdvancementInfo.DEFAULT_WIDTH - 18)) private int utDrawWidth(int original) @@ -91,4 +103,19 @@ private float utRemoveFade(float original) if (!UTConfigTweaks.MISC.ADVANCEMENTS.utAdvancementsToggle || !UTConfigTweaks.MISC.ADVANCEMENTS.utDisableFadeOnHover) return original; return 0; } + + /** + * @reason restore the last tab scroll position + */ + @Inject(method = "drawContents", at = @At("HEAD")) + private void utRestoreTabScrollPosition(CallbackInfo ci) + { + if (!UTConfigTweaks.MISC.ADVANCEMENTS.utAdvancementsToggle || !UTConfigTweaks.MISC.ADVANCEMENTS.utRememberTabScrollPosition || UTAdvancementInfo.lastScrollX == -1 || UTAdvancementInfo.lastScrollY == -1 || UTAdvancementInfo.lastSelectedTabIndex != index || centered) + { + return; + } + scrollX = UTAdvancementInfo.lastScrollX; + scrollY = UTAdvancementInfo.lastScrollY; + centered = true; + } } diff --git a/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/advancements/guisize/mixin/UTGuiScreenAdvancementsMixin.java b/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/advancements/guisize/mixin/UTGuiScreenAdvancementsMixin.java index c5ffab25..111588e3 100644 --- a/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/advancements/guisize/mixin/UTGuiScreenAdvancementsMixin.java +++ b/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/advancements/guisize/mixin/UTGuiScreenAdvancementsMixin.java @@ -44,7 +44,6 @@ public abstract class UTGuiScreenAdvancementsMixin extends GuiScreen @Unique private GuiButton buttonRight; - /** * @reason ensure the maxPages field is set to 0 on gui size update, otherwise it is only updated if >0, meaning it will always linger at 1+ */ @@ -315,6 +314,21 @@ private void utRenderLargerWindow(GuiScreenAdvancements instance, int left, int utRenderTextureRepeating(left, top + texture_corner, texture_corner, bottom - top - texture_corner * 2, 0, texture_corner, texture_corner, texture_height - texture_corner * 2); } + /** + * @reason remember the current tab scroll position + */ + @Inject(method = "onGuiClosed", at = @At("HEAD")) + private void utRememberTabScrollPosition(CallbackInfo ci) + { + if (!UTConfigTweaks.MISC.ADVANCEMENTS.utAdvancementsToggle || !UTConfigTweaks.MISC.ADVANCEMENTS.utRememberTabScrollPosition || selectedTab == null) + { + return; + } + UTAdvancementInfo.lastScrollX = (((UTGuiAdvancementTabAccessor) selectedTab).getScrollX()); + UTAdvancementInfo.lastScrollY = (((UTGuiAdvancementTabAccessor) selectedTab).getScrollY()); + UTAdvancementInfo.lastSelectedTabIndex = (((UTGuiAdvancementTabAccessor) selectedTab).getIndex()); + } + @Unique private void utRenderTextureRepeating(int x, int y, int width, int height, int textureX, int textureY, int textureWidth, int textureHeight) { @@ -330,5 +344,4 @@ private void utRenderTextureRepeating(int x, int y, int width, int height, int t } } } - } diff --git a/src/main/resources/mixins.tweaks.misc.advancements.guisize.json b/src/main/resources/mixins.tweaks.misc.advancements.guisize.json index 1585536c..feadb0d8 100644 --- a/src/main/resources/mixins.tweaks.misc.advancements.guisize.json +++ b/src/main/resources/mixins.tweaks.misc.advancements.guisize.json @@ -3,5 +3,5 @@ "refmap": "universaltweaks.refmap.json", "minVersion": "0.8", "compatibilityLevel": "JAVA_8", - "client": ["UTAdvancementTabTypeMixin", "UTGuiAdvancementTabMixin", "UTGuiScreenAdvancementsMixin"] + "client": ["UTAdvancementTabTypeMixin", "UTGuiAdvancementTabMixin", "UTGuiAdvancementTabAccessor", "UTGuiScreenAdvancementsMixin"] } \ No newline at end of file