Fix slightly offset mods screen link positioning (#9860)

Co-authored-by: Dennis C <11262040+XFactHD@users.noreply.github.com>
This commit is contained in:
Paint_NinjaandDennis C authored and GitHub committed 2024-02-15 14:04:05 -08:00
1 parent c243adf6aa
commit 3e358acbe1
1 file changed
+16 -16
@@ -80,8 +80,10 @@ 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 Screen parentScreen;
private final Screen parentScreen;
private ModListWidget modList;
private InfoPanel modInfo;
@@ -91,8 +93,6 @@ public class ModListScreen extends Screen {
private final List<IModInfo> unsortedMods;
private Button configButton, openModsFolderButton, doneButton;
private int buttonMargin = 1;
private int numButtons = SortType.values().length;
private String lastFilterText = "";
private EditBox search;
@@ -103,8 +103,8 @@ public class ModListScreen extends Screen {
public ModListScreen(Screen parentScreen) {
super(Component.translatable("fml.menu.mods.title"));
this.parentScreen = parentScreen;
this.mods = Collections.unmodifiableList(ModList.get().getMods());
this.unsortedMods = Collections.unmodifiableList(this.mods);
this.mods = ModList.get().getMods();
this.unsortedMods = List.copyOf(this.mods);
}
class InfoPanel extends ScrollPanel {
@@ -187,17 +187,17 @@ public class ModListScreen extends Screen {
if (!isMouseOver(mouseX, mouseY))
return null;
double offset = (mouseY - top) + border + scrollDistance + 1;
double offset = (mouseY - top - PADDING - border) + scrollDistance;
if (logoPath != null)
offset -= 50;
if (offset <= 0)
return null;
int lineIdx = (int) (offset / font.lineHeight);
if (lineIdx >= lines.size() || lineIdx < 1)
if (lineIdx >= lines.size() || lineIdx < 0)
return null;
FormattedCharSequence line = lines.get(lineIdx-1);
FormattedCharSequence line = lines.get(lineIdx);
if (line != null)
return font.getSplitter().componentStyleAtWidth(line, mouseX - left - border);
return null;
@@ -230,7 +230,7 @@ public class ModListScreen extends Screen {
listWidth = Math.max(listWidth,getFontRenderer().width(MavenVersionStringHelper.artifactVersionToString(mod.getVersion())) + 5);
}
listWidth = Math.max(Math.min(listWidth, width/3), 100);
listWidth += listWidth % numButtons != 0 ? (numButtons - listWidth % numButtons) : 0;
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);
@@ -259,13 +259,13 @@ public class ModListScreen extends Screen {
search.setCanLoseFocus(true);
configButton.active = false;
final int width = listWidth / numButtons;
final int width = listWidth / NUM_BUTTONS;
int x = PADDING;
addRenderableWidget(SortType.NORMAL.button = Button.builder(SortType.NORMAL.getButtonText(), b -> resortMods(SortType.NORMAL)).bounds(x, PADDING, width - buttonMargin, 20).build());
x += width + buttonMargin;
addRenderableWidget(SortType.A_TO_Z.button = Button.builder(SortType.A_TO_Z.getButtonText(), b -> resortMods(SortType.A_TO_Z)).bounds(x, PADDING, width - buttonMargin, 20).build());
x += width + buttonMargin;
addRenderableWidget(SortType.Z_TO_A.button = Button.builder(SortType.Z_TO_A.getButtonText(), b -> resortMods(SortType.Z_TO_A)).bounds(x, PADDING, width - buttonMargin, 20).build());
addRenderableWidget(SortType.NORMAL.button = Button.builder(SortType.NORMAL.getButtonText(), b -> resortMods(SortType.NORMAL)).bounds(x, PADDING, width - BUTTON_MARGIN, 20).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).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).build());
resortMods(SortType.NORMAL);
updateCache();
}
@@ -426,7 +426,7 @@ public class ModListScreen extends Screen {
}
*/
if ((vercheck.status() == VersionChecker.Status.OUTDATED || vercheck.status() == VersionChecker.Status.BETA_OUTDATED) && vercheck.changes().size() > 0) {
if ((vercheck.status() == VersionChecker.Status.OUTDATED || vercheck.status() == VersionChecker.Status.BETA_OUTDATED) && !vercheck.changes().isEmpty()) {
lines.add(null);
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.changelogheader"));
for (Entry<ComparableVersion, String> entry : vercheck.changes().entrySet()) {