Fix Mod List Screen's render layout and scroll bars.

This commit is contained in:
LexManos committed 2025-03-26 18:54:11 -07:00
1 parent d50a3b5ab7
commit b4b6e48a7a
3 files changed
+52 -57

No files matched your search

@@ -33,7 +33,8 @@ import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.components.EditBox;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.ObjectSelectionList;
import com.mojang.blaze3d.vertex.Tesselator;
import net.minecraft.client.gui.components.StringWidget;
import net.minecraft.client.renderer.texture.DynamicTexture;
import com.mojang.blaze3d.platform.NativeImage;
import net.minecraft.client.renderer.texture.TextureManager;
@@ -82,6 +83,7 @@ public class ModListScreen extends Screen {
private static final int PADDING = 6;
private static final int BUTTON_MARGIN = 1;
private static final int NUM_BUTTONS = SortType.values().length;
private static final int BUTTON_HEIGHT = 20;
private final Screen parentScreen;
@@ -95,6 +97,7 @@ public class ModListScreen extends Screen {
private String lastFilterText = "";
private StringWidget searchText;
private EditBox search;
private boolean sorted = false;
@@ -161,7 +164,6 @@ public class ModListScreen extends Screen {
@Override
protected void drawPanel(GuiGraphics guiGraphics, int entryRight, int relativeY, int mouseX, int mouseY) {
if (logoPath != null) {
//RenderSystem.enableBlend();
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
// Draw the logo image inscribed in a rectangle with width entryWidth (minus some padding) and height 50
int headerHeight = 50;
@@ -170,11 +172,8 @@ public class ModListScreen extends Screen {
}
for (FormattedCharSequence line : lines) {
if (line != null) {
//RenderSystem.enableBlend();
if (line != null)
guiGraphics.drawString(ModListScreen.this.font, line, left + PADDING, relativeY, 0xFFFFFF);
//RenderSystem.disableBlend();
}
relativeY += font.lineHeight;
}
@@ -225,40 +224,49 @@ public class ModListScreen extends Screen {
@Override
public void init() {
var font = getFontRenderer();
for (IModInfo mod : mods) {
listWidth = Math.max(listWidth,getFontRenderer().width(mod.getDisplayName()) + 10);
listWidth = Math.max(listWidth,getFontRenderer().width(MavenVersionStringHelper.artifactVersionToString(mod.getVersion())) + 5);
listWidth = Math.max(listWidth, font.width(mod.getDisplayName()) + 10);
listWidth = Math.max(listWidth, font.width(MavenVersionStringHelper.artifactVersionToString(mod.getVersion())) + 5);
}
listWidth = Math.max(Math.min(listWidth, width / 3), 100);
listWidth += listWidth % NUM_BUTTONS != 0 ? (NUM_BUTTONS - listWidth % NUM_BUTTONS) : 0;
int modInfoWidth = this.width - this.listWidth - (PADDING * 3);
int doneButtonWidth = Math.min(modInfoWidth, 200);
int y = this.height - 20 - PADDING;
int fullButtonHeight = PADDING + 20 + PADDING;
final int fullButtonHeight = PADDING + BUTTON_HEIGHT + PADDING;
final int modInfoWidth = this.width - this.listWidth - (PADDING * 3);
final int doneButtonWidth = Math.min(modInfoWidth, 200);
int y = this.height - BUTTON_HEIGHT - PADDING;
doneButton = Button.builder(Component.translatable("gui.done"), b -> ModListScreen.this.onClose())
.bounds(((listWidth + PADDING + this.width - doneButtonWidth) / 2), y, doneButtonWidth, 20)
.bounds(((listWidth + PADDING + this.width - doneButtonWidth) / 2), y, doneButtonWidth, BUTTON_HEIGHT)
.build();
openModsFolderButton = Button.builder(Component.translatable("fml.menu.mods.openmodsfolder"), b -> Util.getPlatform().openFile(FMLPaths.MODSDIR.get().toFile()))
.bounds(6, y, this.listWidth, 20)
.bounds(6, y, this.listWidth, BUTTON_HEIGHT)
.build();
y -= 20 + PADDING;
y -= BUTTON_HEIGHT + PADDING;
configButton = Button.builder(Component.translatable("fml.menu.mods.config"), b -> ModListScreen.this.displayModConfig())
.bounds(6, y, this.listWidth, 20)
.bounds(6, y, this.listWidth, BUTTON_HEIGHT)
.build();
y -= 14 + PADDING;
search = new EditBox(getFontRenderer(), PADDING + 1, y, listWidth - 2, 14, Component.translatable("fml.menu.mods.search"));
this.modList = new ModListWidget(this, listWidth, fullButtonHeight, search.getY() - getFontRenderer().lineHeight * 4 - PADDING);
y -= font.lineHeight;
int width = font.width(search.getMessage().getVisualOrderText());
searchText = new StringWidget(search.getX() + (search.getWidth() /2) - (width / 2), y, width, font.lineHeight, search.getMessage(), font);
int height = y - (PADDING + BUTTON_HEIGHT + PADDING) - PADDING;
this.modList = new ModListWidget(this, listWidth, fullButtonHeight, height);
this.modList.setX(6);
this.modInfo = new InfoPanel(this.minecraft, modInfoWidth, this.height - PADDING - fullButtonHeight, PADDING);
this.addRenderableWidget(modList);
this.addRenderableWidget(modInfo);
this.addRenderableWidget(searchText);
this.addRenderableWidget(search);
this.addRenderableWidget(doneButton);
this.addRenderableWidget(configButton);
@@ -268,20 +276,20 @@ public class ModListScreen extends Screen {
search.setCanLoseFocus(true);
configButton.active = false;
final int width = listWidth / NUM_BUTTONS;
width = listWidth / NUM_BUTTONS;
int x = PADDING;
addRenderableWidget(SortType.NORMAL.button = Button.builder(SortType.NORMAL.getButtonText(), b -> resortMods(SortType.NORMAL))
.bounds(x, PADDING, width - BUTTON_MARGIN, 20)
.bounds(x, PADDING, width - BUTTON_MARGIN, BUTTON_HEIGHT)
.build());
x += width + BUTTON_MARGIN;
addRenderableWidget(SortType.A_TO_Z.button = Button.builder(SortType.A_TO_Z.getButtonText(), b -> resortMods(SortType.A_TO_Z))
.bounds(x, PADDING, width - BUTTON_MARGIN, 20)
.bounds(x, PADDING, width - BUTTON_MARGIN, BUTTON_HEIGHT)
.build());
x += width + BUTTON_MARGIN;
addRenderableWidget(SortType.Z_TO_A.button = Button.builder(SortType.Z_TO_A.getButtonText(), b -> resortMods(SortType.Z_TO_A))
.bounds(x, PADDING, width - BUTTON_MARGIN, 20)
.bounds(x, PADDING, width - BUTTON_MARGIN, BUTTON_HEIGHT)
.build());
resortMods(SortType.NORMAL);
@@ -354,15 +362,10 @@ public class ModListScreen extends Screen {
@Override
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
this.modList.render(guiGraphics, mouseX, mouseY, partialTick);
if (this.modInfo != null)
this.modInfo.render(guiGraphics, mouseX, mouseY, partialTick);
Component text = Component.translatable("fml.menu.mods.search");
int x = modList.getX() + (modList.getWidth() / 2) - (getFontRenderer().width(text) / 2);
this.search.render(guiGraphics, mouseX , mouseY, partialTick);
super.render(guiGraphics, mouseX, mouseY, partialTick);
guiGraphics.drawString(getFontRenderer(), text.getVisualOrderText(), x, search.getY() - getFontRenderer().lineHeight, 0xFFFFFF, false);
}
public Minecraft getMinecraftInstance() {
@@ -40,19 +40,25 @@ public class ModListWidget extends ObjectSelectionList<ModListWidget.ModEntry> {
return this.listWidth;
}
@Override
protected int scrollBarX() {
return this.getRowRight() - 8;
}
@Override
protected void renderSelection(GuiGraphics gui, int top, int rowWidth, int height, int borderColor, int backgroundColor) {
int barOffset = this.scrollbarVisible() ? 6 : 0;
int left = this.getX() + (this.width - rowWidth) / 2;
int right = this.getX() + (this.width + rowWidth) / 2 - barOffset;
gui.fill(left, top - 2, right, top + height + 2, borderColor);
gui.fill(left + 1, top - 1, right - 1, top + height + 1, backgroundColor);
}
public void refreshList() {
this.clearEntries();
parent.buildModList(this::addEntry, mod->new ModEntry(mod, this.parent));
}
/*
@Override
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
this.parent.renderBackground(guiGraphics, mouseX, mouseY, partialTicks);
super.render(guiGraphics, mouseX, mouseY, partialTicks);
}
*/
public class ModEntry extends ObjectSelectionList.Entry<ModEntry> {
private final IModInfo modInfo;
private final ModListScreen parent;
@@ -68,20 +74,21 @@ public class ModListWidget extends ObjectSelectionList<ModListWidget.ModEntry> {
}
@Override
public void render(GuiGraphics guiGraphics, int entryIdx, int top, int left, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isMouseOver, float partialTick)
{
public void render(GuiGraphics guiGraphics, int entryIdx, int top, int left, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isMouseOver, float partialTick) {
Component name = Component.literal(stripControlCodes(modInfo.getDisplayName()));
Component version = Component.literal(stripControlCodes(MavenVersionStringHelper.artifactVersionToString(modInfo.getVersion())));
VersionChecker.CheckResult vercheck = VersionChecker.getResult(modInfo);
Font font = this.parent.getFontRenderer();
guiGraphics.drawString(font, Language.getInstance().getVisualOrder(FormattedText.composite(font.substrByWidth(name, listWidth))), left + 3, top + 2, 0xFFFFFF, false);
guiGraphics.drawString(font, Language.getInstance().getVisualOrder(FormattedText.composite(font.substrByWidth(version, listWidth))), left + 3, top + 2 + font.lineHeight, 0xCCCCCC, false);
var barOffset = ModListWidget.this.scrollbarVisible() ? 6 : 0;
guiGraphics.drawString(font, Language.getInstance().getVisualOrder(FormattedText.composite(font.substrByWidth(name, listWidth - 6 - barOffset))), left + 3, top + 2, 0xFFFFFF, false);
guiGraphics.drawString(font, Language.getInstance().getVisualOrder(FormattedText.composite(font.substrByWidth(version, listWidth - 6 - barOffset))), left + 3, top + 2 + font.lineHeight, 0xCCCCCC, false);
if (vercheck.status().shouldDraw()) {
//TODO: Consider adding more icons for visualization
//TODO: [Forge][ModList] Consider adding more icons for visualization
RenderSystem.setShaderColor(1, 1, 1, 1);
guiGraphics.pose().pushPose();
guiGraphics.blit(RenderType::guiTextured, VERSION_CHECK_ICONS, getX() + width - 12, top + entryHeight / 4, vercheck.status().getSheetOffset() * 8, (vercheck.status().isAnimated() && ((System.currentTimeMillis() / 800 & 1)) == 1) ? 8 : 0, 8, 8, 64, 16);
guiGraphics.blit(RenderType::guiTextured, VERSION_CHECK_ICONS, getX() + width - 12 - barOffset, top + entryHeight / 4, vercheck.status().getSheetOffset() * 8, (vercheck.status().isAnimated() && ((System.currentTimeMillis() / 800 & 1)) == 1) ? 8 : 0, 8, 8, 64, 16);
guiGraphics.pose().popPose();
}
}
@@ -18,7 +18,6 @@ import java.util.List;
/**
* Abstract scroll panel class.
* TODO: [Forge][Rendering] ScrollPanel could potentially be replaced by AbstractScrollArea
*/
public abstract class ScrollPanel extends AbstractContainerEventHandler implements Renderable, NarratableEntry {
private final Minecraft client;
@@ -146,22 +145,8 @@ public abstract class ScrollPanel extends AbstractContainerEventHandler implemen
* Draws the background of the scroll panel. This runs AFTER Scissors are enabled.
*/
protected void drawBackground(GuiGraphics guiGraphics, float partialTick) {
// BufferBuilder worldr = tess.getBuilder();
if (this.client.level != null) {
if (this.client.level != null)
this.drawGradientRect(guiGraphics, this.left, this.top, this.right, this.bottom, bgColorFrom, bgColorTo);
} /* else { // Draw dark dirt background
RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
RenderSystem.setShaderTexture(0, Screen.BACKGROUND_LOCATION);
final float texScale = 32.0F;
worldr.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
worldr.vertex(this.left, this.bottom, 0.0D).uv(this.left / texScale, (this.bottom + (int)this.scrollDistance) / texScale).color(0x20, 0x20, 0x20, 0xFF).endVertex();
worldr.vertex(this.right, this.bottom, 0.0D).uv(this.right / texScale, (this.bottom + (int)this.scrollDistance) / texScale).color(0x20, 0x20, 0x20, 0xFF).endVertex();
worldr.vertex(this.right, this.top, 0.0D).uv(this.right / texScale, (this.top + (int)this.scrollDistance) / texScale).color(0x20, 0x20, 0x20, 0xFF).endVertex();
worldr.vertex(this.left, this.top, 0.0D).uv(this.left / texScale, (this.top + (int)this.scrollDistance) / texScale).color(0x20, 0x20, 0x20, 0xFF).endVertex();
tess.end();
}
*/
}
/**
@@ -262,7 +247,7 @@ public abstract class ScrollPanel extends AbstractContainerEventHandler implemen
@Override
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
guiGraphics.enableScissor(left, top, width, height);
guiGraphics.enableScissor(left, top, left + width, top + height);
this.drawBackground(guiGraphics, partialTick);