Skip to content

Commit

Permalink
feat: scrollable SettingsGui
Browse files Browse the repository at this point in the history
This feature improves accessibility by making settings easier to access, especially on low-resolution screens, as the number of FeatureSettings increases over time (e.g. Backpack Preview).
  • Loading branch information
Fix3dll committed Jan 27, 2025
1 parent 1cfe6ea commit 358829f
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,12 @@ public static void drawDungeonsMap(Minecraft mc, float scale, ButtonLocation but
int minecraftScale = new ScaledResolution(mc).getScaleFactor();
GL11.glEnable(GL11.GL_SCISSOR_TEST);
// Scissor is in screen coordinates...
GL11.glScissor(Math.round((x - size / 2f * scale) * minecraftScale),
mc.displayHeight - Math.round((y + size / 2F * scale) * minecraftScale), Math.round(size * minecraftScale * scale), Math.round(size * minecraftScale * scale));
GL11.glScissor(
Math.round((x - size / 2f * scale) * minecraftScale),
mc.displayHeight - Math.round((y + size / 2F * scale) * minecraftScale),
Math.round(size * minecraftScale * scale),
Math.round(size * minecraftScale * scale)
);

x = transformXY(x, size, scale);
y = transformXY(y, size, scale);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public void initGui() {
addChromaSliders();
}

addSocials();
addSocials(buttonList);
Keyboard.enableRepeatEvents(true);
super.initGui();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ public EnchantmentSettingsGui(int page, int lastPage, EnumUtils.GuiTab lastTab)
@Override
public void initGui() {
Keyboard.enableRepeatEvents(true);
scrollValue = 0;
maxScrollValue = mc.displayHeight / 2;
row = 1;
column = 1;
buttonList.clear();
scrollIgnoredButtons.clear();
for (FeatureSetting setting : feature.getFeatureData().getSettings().keySet()) {
switch (page) {
case 0:
Expand All @@ -72,9 +75,9 @@ public void initGui() {
}
}
row += .4F;
buttonList.add(new ButtonArrow(width / 2D - 15 - 150, height - 70, ButtonArrow.ArrowType.LEFT, page == 0));
buttonList.add(new ButtonArrow(width / 2D - 15 + 150, height - 70, ButtonArrow.ArrowType.RIGHT, page == maxPage));
addSocials();
addScrollIgnoredButton(new ButtonArrow(width / 2D - 15 - 150, height - 70, ButtonArrow.ArrowType.LEFT, page == 0));
addScrollIgnoredButton(new ButtonArrow(width / 2D - 15 + 150, height - 70, ButtonArrow.ArrowType.RIGHT, page == maxPage));
addSocials(scrollIgnoredButtons);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,21 @@
import codes.biscuit.skyblockaddons.utils.data.DataUtils;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;

public class SettingsGui extends SkyblockAddonsScreen {

final ArrayList<GuiButton> scrollIgnoredButtons = new ArrayList<>();
@Getter final Feature feature;
@Getter final int lastPage;
@Getter final EnumUtils.GuiTab lastTab;
Expand All @@ -33,6 +38,9 @@ public class SettingsGui extends SkyblockAddonsScreen {
@Setter boolean closingGui;
boolean reInit = false;

int scrollValue;
int maxScrollValue;

/**
* The main gui, opened with /sba.
*/
Expand All @@ -47,9 +55,12 @@ public SettingsGui(Feature feature, int page, int lastPage, EnumUtils.GuiTab las
@Override
public void initGui() {
Keyboard.enableRepeatEvents(true);
scrollValue = 0;
maxScrollValue = mc.displayHeight / 2;
row = 1;
column = 1;
buttonList.clear();
scrollIgnoredButtons.clear();
if (feature == Feature.LANGUAGE) {
Language currentLanguage = (Language) feature.getFeatureData().getValue();

Expand All @@ -58,9 +69,9 @@ public void initGui() {
int skip = (page - 1) * displayCount;

boolean max = page == 1;
buttonList.add(new ButtonArrow(width / 2 - 15 - 50, height - 70, ButtonArrow.ArrowType.LEFT, max));
addScrollIgnoredButton(new ButtonArrow(width / 2 - 15 - 50, height - 70, ButtonArrow.ArrowType.LEFT, max));
max = Language.values().length - skip - displayCount <= 0;
buttonList.add(new ButtonArrow(width / 2 - 15 + 50, height - 70, ButtonArrow.ArrowType.RIGHT, max));
addScrollIgnoredButton(new ButtonArrow(width / 2 - 15 + 50, height - 70, ButtonArrow.ArrowType.RIGHT, max));

for (Language language : Language.values()) {
if (skip == 0) {
Expand All @@ -84,7 +95,7 @@ public void initGui() {
}
addUniversalButton();
}
addSocials();
addSocials(scrollIgnoredButtons);
}

private int findDisplayCount() {
Expand All @@ -106,6 +117,12 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
reInit = false;
initGui();
}
int scroll = Mouse.getDWheel() / 10;
if (Math.abs(scrollValue + scroll) <= maxScrollValue) {
scrollValue += scroll;
} else {
scroll = 0;
}

float alphaMultiplier = calculateAlphaMultiplier();
// Alpha of the text will increase from 0 to 127 over 500ms.
Expand All @@ -126,10 +143,29 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
float numberOfRow = row - 1;
int height = (int) (getRowHeightSetting(numberOfRow) - 70);
int y = (int) getRowHeight(1);
this.maxScrollValue = height - 35; // - 35 because we don't want it to be completely invisible
DrawUtils.drawRect(x, y, width, height, ColorUtils.getDummySkyblockColor(28, 29, 41, 230), 4);
drawScaledString(this, Translations.getMessage("settings.settings"), 110, defaultBlue, 1.5, 0);
// Scroll ability with scissor
GL11.glEnable(GL11.GL_SCISSOR_TEST);
ScaledResolution sr = new ScaledResolution(mc);
int scaleFactor = sr.getScaleFactor();
GL11.glScissor(
x * scaleFactor,
(sr.getScaledHeight() - (y + height)) * scaleFactor,
width * scaleFactor,
height * scaleFactor
);
drawScaledString(this, Translations.getMessage("settings.settings"), 110 + scrollValue, defaultBlue, 1.5, 0);
}
final int finalScroll = scroll;
buttonList.forEach(guiButton -> {
if (!scrollIgnoredButtons.contains(guiButton)) {
guiButton.yPosition += finalScroll;
}
});
super.drawScreen(mouseX, mouseY, partialTicks); // Draw buttons.
GL11.glDisable(GL11.GL_SCISSOR_TEST);
scrollIgnoredButtons.forEach(guiButton -> guiButton.drawButton(mc, mouseX, mouseY));
GlStateManager.disableBlend();
}

Expand Down Expand Up @@ -377,6 +413,11 @@ protected double getRowHeightSetting(double row) {
return 140 + (row * 35); //height*(0.18+(row*0.08));
}

protected void addScrollIgnoredButton(GuiButton button) {
scrollIgnoredButtons.add(button);
buttonList.add(button);
}

@Override
public void onGuiClosed() {
if (!closingGui) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void initGui() {
buttonList.add(new ButtonArrow(width / 2D - 15 - 50, height - 70, ButtonArrow.ArrowType.LEFT, max));
max = features.size() - skip - displayCount <= 0;
buttonList.add(new ButtonArrow(width / 2D - 15 + 50, height - 70, ButtonArrow.ArrowType.RIGHT, max));
addSocials();
addSocials(buttonList);

for (Feature feature : features) {
if (skip == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
import codes.biscuit.skyblockaddons.utils.DrawUtils;
import codes.biscuit.skyblockaddons.utils.EnumUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.util.ResourceLocation;

import java.awt.Color;
import java.util.List;

public class SkyblockAddonsScreen extends GuiScreen {

Expand Down Expand Up @@ -120,7 +122,7 @@ static void drawScaledString(GuiScreen guiScreen, String text, int y, int color,
GlStateManager.disableBlend();
}

public void addSocials() {
public void addSocials(List<GuiButton> buttonList) {
//buttonList.add(new ButtonSocial(width / 2 + 175, 30, EnumUtils.Social.DISCORD));
buttonList.add(new ButtonSocial(width / 2D + 125, 30, EnumUtils.Social.MODRINTH));
buttonList.add(new ButtonSocial(width / 2D + 150, 30, EnumUtils.Social.GITHUB));
Expand Down

0 comments on commit 358829f

Please sign in to comment.