-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #498 from WaitingIdly/advancement-gui
Advancement GUI
- Loading branch information
Showing
10 changed files
with
622 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...java/mod/acgaming/universaltweaks/tweaks/misc/advancements/guisize/UTAdvancementInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package mod.acgaming.universaltweaks.tweaks.misc.advancements.guisize; | ||
|
||
import mod.acgaming.universaltweaks.config.UTConfigTweaks; | ||
|
||
// Courtesy of WaitingIdly | ||
public class UTAdvancementInfo | ||
{ | ||
public static final int DEFAULT_WIDTH = 252; | ||
public static final int DEFAULT_HEIGHT = 140; | ||
private static final int PADDING = 9; | ||
private static final int HEIGHT_MULT = 28; | ||
private static final int WIDTH_MULT = 32; | ||
|
||
private static int utStepwiseWidth(int width) | ||
{ | ||
return width / WIDTH_MULT * WIDTH_MULT; | ||
} | ||
|
||
private static int utStepwiseHeight(int height) | ||
{ | ||
return height / HEIGHT_MULT * HEIGHT_MULT; | ||
} | ||
|
||
private static int utClampWidth(int width) | ||
{ | ||
return Math.max(width, DEFAULT_WIDTH); | ||
} | ||
|
||
private static int utClampHeight(int height) | ||
{ | ||
return Math.max(height, DEFAULT_HEIGHT); | ||
} | ||
|
||
public static int utPageWidth(int externalWidth) | ||
{ | ||
return utStepwiseWidth(utClampWidth(externalWidth - UTConfigTweaks.MISC.ADVANCEMENTS.utHorizontalMargin * 2)); | ||
} | ||
|
||
public static int utPageWidth(int externalWidth, int padding) | ||
{ | ||
return utPageWidth(externalWidth) - padding * PADDING; | ||
} | ||
|
||
public static int utPageHeight(int externalHeight) | ||
{ | ||
return utStepwiseHeight(utClampHeight(externalHeight - UTConfigTweaks.MISC.ADVANCEMENTS.utVerticalMargin * 2)); | ||
} | ||
|
||
public static int utPageHeight(int externalHeight, int padding) | ||
{ | ||
return utPageHeight(externalHeight) - padding * PADDING; | ||
} | ||
|
||
private static int utTabCountForWidth(int width) | ||
{ | ||
return utPageWidth(width) / WIDTH_MULT; | ||
} | ||
|
||
private static int utTabCountForHeight(int height) | ||
{ | ||
return utPageHeight(height) / HEIGHT_MULT; | ||
} | ||
|
||
public static int utTabCountForSide(int width, int height, boolean isVertical) | ||
{ | ||
return isVertical ? utTabCountForHeight(height) : utTabCountForWidth(width); | ||
} | ||
|
||
public static int utMaximumTabCountPerPage(int width, int height) | ||
{ | ||
return (utTabCountForWidth(width) + utTabCountForHeight(height)) * 2; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...ing/universaltweaks/tweaks/misc/advancements/guisize/mixin/UTAdvancementTabTypeMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package mod.acgaming.universaltweaks.tweaks.misc.advancements.guisize.mixin; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.advancements.AdvancementTabType; | ||
|
||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import com.llamalad7.mixinextras.sugar.Local; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Constant; | ||
import org.spongepowered.asm.mixin.injection.ModifyConstant; | ||
|
||
import mod.acgaming.universaltweaks.config.UTConfigTweaks; | ||
import mod.acgaming.universaltweaks.tweaks.misc.advancements.guisize.UTAdvancementInfo; | ||
|
||
// Courtesy of WaitingIdly | ||
@Mixin(value = AdvancementTabType.class) | ||
public abstract class UTAdvancementTabTypeMixin | ||
{ | ||
@WrapOperation(method = "draw", at = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/advancements/AdvancementTabType;max:I")) | ||
private int utIndex(AdvancementTabType instance, Operation<Integer> original, @Local(argsOnly = true, ordinal = 2) int index) | ||
{ | ||
if (!UTConfigTweaks.MISC.ADVANCEMENTS.utAdvancementsToggle || !UTConfigTweaks.MISC.ADVANCEMENTS.utSizeToggle || Minecraft.getMinecraft().currentScreen == null) | ||
{ | ||
return original.call(instance); | ||
} | ||
return UTAdvancementInfo.utTabCountForSide(Minecraft.getMinecraft().currentScreen.width, Minecraft.getMinecraft().currentScreen.height, instance == AdvancementTabType.LEFT || instance == AdvancementTabType.RIGHT); | ||
} | ||
|
||
@ModifyConstant(method = "getX", constant = @Constant(intValue = UTAdvancementInfo.DEFAULT_WIDTH - 4)) | ||
private int utOverrideX(int original) | ||
{ | ||
if (!UTConfigTweaks.MISC.ADVANCEMENTS.utAdvancementsToggle || !UTConfigTweaks.MISC.ADVANCEMENTS.utSizeToggle || Minecraft.getMinecraft().currentScreen == null) | ||
{ | ||
return original; | ||
} | ||
return UTAdvancementInfo.utPageWidth(Minecraft.getMinecraft().currentScreen.width) - 8; | ||
} | ||
|
||
@ModifyConstant(method = "getY", constant = @Constant(intValue = UTAdvancementInfo.DEFAULT_HEIGHT - 4)) | ||
private int utOverrideY(int original) | ||
{ | ||
if (!UTConfigTweaks.MISC.ADVANCEMENTS.utAdvancementsToggle || !UTConfigTweaks.MISC.ADVANCEMENTS.utSizeToggle || Minecraft.getMinecraft().currentScreen == null) | ||
{ | ||
return original; | ||
} | ||
return UTAdvancementInfo.utPageHeight(Minecraft.getMinecraft().currentScreen.height) - 4; | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
...ming/universaltweaks/tweaks/misc/advancements/guisize/mixin/UTGuiAdvancementTabMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package mod.acgaming.universaltweaks.tweaks.misc.advancements.guisize.mixin; | ||
|
||
import net.minecraft.client.gui.advancements.AdvancementTabType; | ||
import net.minecraft.client.gui.advancements.GuiAdvancementTab; | ||
import net.minecraft.client.gui.advancements.GuiScreenAdvancements; | ||
|
||
import com.llamalad7.mixinextras.injector.ModifyExpressionValue; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import com.llamalad7.mixinextras.sugar.Local; | ||
import org.spongepowered.asm.mixin.Final; | ||
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.Constant; | ||
import org.spongepowered.asm.mixin.injection.ModifyConstant; | ||
|
||
import mod.acgaming.universaltweaks.config.UTConfigTweaks; | ||
import mod.acgaming.universaltweaks.tweaks.misc.advancements.guisize.UTAdvancementInfo; | ||
|
||
// Courtesy of WaitingIdly | ||
@Mixin(GuiAdvancementTab.class) | ||
public abstract class UTGuiAdvancementTabMixin | ||
{ | ||
@Shadow | ||
@Final | ||
private GuiScreenAdvancements screen; | ||
|
||
@WrapOperation(method = "create", at = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/advancements/AdvancementTabType;MAX_TABS:I")) | ||
private static int utAdjustMaxTabs(Operation<Integer> original, @Local(argsOnly = true) GuiScreenAdvancements screen) | ||
{ | ||
if (!UTConfigTweaks.MISC.ADVANCEMENTS.utAdvancementsToggle || !UTConfigTweaks.MISC.ADVANCEMENTS.utSizeToggle) return original.call(); | ||
return UTAdvancementInfo.utMaximumTabCountPerPage(screen.width, screen.height); | ||
} | ||
|
||
@WrapOperation(method = "create", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/advancements/AdvancementTabType;getMax()I")) | ||
private static int utAdjustIndividualMaxTabs(AdvancementTabType instance, Operation<Integer> original, @Local(argsOnly = true) GuiScreenAdvancements screen) | ||
{ | ||
if (!UTConfigTweaks.MISC.ADVANCEMENTS.utAdvancementsToggle || !UTConfigTweaks.MISC.ADVANCEMENTS.utSizeToggle) return original.call(instance); | ||
return UTAdvancementInfo.utTabCountForSide(screen.width, screen.height, instance == AdvancementTabType.LEFT || instance == AdvancementTabType.RIGHT); | ||
} | ||
|
||
// update the size | ||
@ModifyConstant(method = {"drawContents", "scroll", "drawToolTips"}, constant = @Constant(intValue = UTAdvancementInfo.DEFAULT_WIDTH - 18)) | ||
private int utDrawWidth(int original) | ||
{ | ||
if (!UTConfigTweaks.MISC.ADVANCEMENTS.utAdvancementsToggle || !UTConfigTweaks.MISC.ADVANCEMENTS.utSizeToggle) return original; | ||
return UTAdvancementInfo.utPageWidth(screen.width, 2) - 4; | ||
} | ||
|
||
@ModifyConstant(method = {"drawContents", "scroll", "drawToolTips"}, constant = @Constant(intValue = UTAdvancementInfo.DEFAULT_HEIGHT - 27)) | ||
private int utDrawHeight(int original) | ||
{ | ||
if (!UTConfigTweaks.MISC.ADVANCEMENTS.utAdvancementsToggle || !UTConfigTweaks.MISC.ADVANCEMENTS.utSizeToggle) return original; | ||
return UTAdvancementInfo.utPageHeight(screen.height, 3); | ||
} | ||
|
||
// origin of the shown tree within the scrollable space | ||
@ModifyConstant(method = "drawContents", constant = @Constant(intValue = (UTAdvancementInfo.DEFAULT_WIDTH - 18) / 2)) | ||
private int utDrawContentsWidth(int original) | ||
{ | ||
if (!UTConfigTweaks.MISC.ADVANCEMENTS.utAdvancementsToggle || !UTConfigTweaks.MISC.ADVANCEMENTS.utSizeToggle) return original; | ||
return (UTAdvancementInfo.utPageWidth(screen.width, 2) - 4) / 2; | ||
} | ||
|
||
@ModifyConstant(method = "drawContents", constant = @Constant(intValue = (UTAdvancementInfo.DEFAULT_HEIGHT - 27) / 2)) | ||
private int utDrawContentsHeight(int original) | ||
{ | ||
if (!UTConfigTweaks.MISC.ADVANCEMENTS.utAdvancementsToggle || !UTConfigTweaks.MISC.ADVANCEMENTS.utSizeToggle) return original; | ||
return UTAdvancementInfo.utPageHeight(screen.height, 3) / 2; | ||
} | ||
|
||
// repeat the texture to fill up the drawn space | ||
@ModifyConstant(method = "drawContents", constant = @Constant(intValue = 15)) | ||
private int utRepeatingTextureWidth(int original) | ||
{ | ||
if (!UTConfigTweaks.MISC.ADVANCEMENTS.utAdvancementsToggle || !UTConfigTweaks.MISC.ADVANCEMENTS.utSizeToggle) return original; | ||
return (UTAdvancementInfo.utPageWidth(screen.width) - 4) / 16 + 1; | ||
} | ||
|
||
@ModifyConstant(method = "drawContents", constant = @Constant(intValue = 8)) | ||
private int utRepeatingTextureHeight(int original) | ||
{ | ||
if (!UTConfigTweaks.MISC.ADVANCEMENTS.utAdvancementsToggle || !UTConfigTweaks.MISC.ADVANCEMENTS.utSizeToggle) return original; | ||
return UTAdvancementInfo.utPageHeight(screen.height) / 16 + 1; | ||
} | ||
|
||
// prevents changing the fade value from 0 | ||
@ModifyExpressionValue(method = "drawToolTips", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;clamp(FFF)F")) | ||
private float utRemoveFade(float original) | ||
{ | ||
if (!UTConfigTweaks.MISC.ADVANCEMENTS.utAdvancementsToggle || !UTConfigTweaks.MISC.ADVANCEMENTS.utDisableFadeOnHover) return original; | ||
return 0; | ||
} | ||
} |
Oops, something went wrong.