Mod list GUI detail pass

- Make padding consistent on all elements
- Properly horizontally center the "Search" text
- Update and resize forge/mcp logos
- Enable linear filtering on logo rendering by default
  - Can be disabled with the "logoBlur" mods.toml property
This commit is contained in:
tterrag 2019-12-17 20:58:26 -05:00
parent 5df687dddc
commit 49596dcacc
5 changed files with 71 additions and 44 deletions

View file

@ -51,6 +51,7 @@ public class ModInfo implements IModInfo
private final String displayName; private final String displayName;
private final String description; private final String description;
private final Optional<String> logoFile; private final Optional<String> logoFile;
private final boolean logoBlur;
private final URL updateJSONURL; private final URL updateJSONURL;
private final List<IModInfo.ModVersion> dependencies; private final List<IModInfo.ModVersion> dependencies;
private final Map<String,Object> properties; private final Map<String,Object> properties;
@ -81,6 +82,10 @@ public class ModInfo implements IModInfo
tmp = this.owningFile.getConfig().getOptional("logoFile"); tmp = this.owningFile.getConfig().getOptional("logoFile");
} }
this.logoFile = tmp; this.logoFile = tmp;
this.logoBlur = modConfig.<Boolean>getOptional("logoBlur").
orElseGet(() -> Optional.ofNullable(this.owningFile).
flatMap(f -> f.getConfig().<Boolean>getOptional("logoBlur")).
orElse(true));
this.updateJSONURL = modConfig.<String>getOptional("updateJSONURL").map(StringUtils::toURL).orElse(null); this.updateJSONURL = modConfig.<String>getOptional("updateJSONURL").map(StringUtils::toURL).orElse(null);
if (owningFile != null) { if (owningFile != null) {
@ -151,6 +156,11 @@ public class ModInfo implements IModInfo
return this.logoFile; return this.logoFile;
} }
public boolean getLogoBlur()
{
return this.logoBlur;
}
/** /**
* This is no longer used. The Mods List GUI currently directly checks whether there is an EntryPoint registered. * This is no longer used. The Mods List GUI currently directly checks whether there is an EntryPoint registered.
*/ */

View file

@ -30,8 +30,6 @@ import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import net.minecraft.util.Util;
import net.minecraftforge.fml.loading.FMLPaths;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -41,17 +39,18 @@ import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.widget.button.Button; import net.minecraft.client.gui.RenderComponentsUtil;
import net.minecraft.client.gui.widget.list.ExtendedList;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.TextFieldWidget; import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.gui.RenderComponentsUtil; import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.gui.widget.list.ExtendedList;
import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.DynamicTexture; import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.client.renderer.texture.NativeImage; import net.minecraft.client.renderer.texture.NativeImage;
import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.resources.I18n; import net.minecraft.client.resources.I18n;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Util;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.util.text.TranslationTextComponent;
@ -65,13 +64,14 @@ import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.VersionChecker; import net.minecraftforge.fml.VersionChecker;
import net.minecraftforge.fml.client.ConfigGuiHandler; import net.minecraftforge.fml.client.ConfigGuiHandler;
import net.minecraftforge.fml.client.config.GuiUtils; import net.minecraftforge.fml.client.config.GuiUtils;
import net.minecraftforge.fml.loading.FMLPaths;
import net.minecraftforge.fml.loading.StringUtils; import net.minecraftforge.fml.loading.StringUtils;
import net.minecraftforge.fml.loading.moddiscovery.ModInfo; import net.minecraftforge.fml.loading.moddiscovery.ModInfo;
import net.minecraftforge.fml.packs.ModFileResourcePack; import net.minecraftforge.fml.packs.ModFileResourcePack;
import net.minecraftforge.fml.packs.ResourcePackLoader; import net.minecraftforge.fml.packs.ResourcePackLoader;
import net.minecraftforge.forgespi.language.IModInfo; import net.minecraftforge.forgespi.language.IModInfo;
public class GuiModList extends Screen public class ModListScreen extends Screen
{ {
private static String stripControlCodes(String value) { return net.minecraft.util.StringUtils.stripControlCodes(value); } private static String stripControlCodes(String value) { return net.minecraft.util.StringUtils.stripControlCodes(value); }
private static final Logger LOGGER = LogManager.getLogger(); private static final Logger LOGGER = LogManager.getLogger();
@ -95,11 +95,13 @@ public class GuiModList extends Screen
} }
} }
private static final int PADDING = 6;
private Screen mainMenu; private Screen mainMenu;
private GuiSlotModList modList; private ModListWidget modList;
private InfoPanel modInfo; private InfoPanel modInfo;
private GuiSlotModList.ModEntry selected = null; private ModListWidget.ModEntry selected = null;
private int listWidth; private int listWidth;
private List<ModInfo> mods; private List<ModInfo> mods;
private final List<ModInfo> unsortedMods; private final List<ModInfo> unsortedMods;
@ -117,7 +119,7 @@ public class GuiModList extends Screen
/** /**
* @param mainMenu * @param mainMenu
*/ */
public GuiModList(Screen mainMenu) public ModListScreen(Screen mainMenu)
{ {
super(new TranslationTextComponent("fml.menu.mods.title")); super(new TranslationTextComponent("fml.menu.mods.title"));
this.mainMenu = mainMenu; this.mainMenu = mainMenu;
@ -132,7 +134,7 @@ public class GuiModList extends Screen
InfoPanel(Minecraft mcIn, int widthIn, int heightIn, int topIn) InfoPanel(Minecraft mcIn, int widthIn, int heightIn, int topIn)
{ {
super(mcIn, widthIn, heightIn, topIn, modList.getRight() + 10); super(mcIn, widthIn, heightIn, topIn, modList.getRight() + PADDING);
} }
void setInfo(List<String> lines, ResourceLocation logoPath, Size2i logoDims) void setInfo(List<String> lines, ResourceLocation logoPath, Size2i logoDims)
@ -164,7 +166,7 @@ public class GuiModList extends Screen
int maxTextLength = this.width - 12; int maxTextLength = this.width - 12;
if (maxTextLength >= 0) if (maxTextLength >= 0)
{ {
ret.addAll(RenderComponentsUtil.splitText(chat, maxTextLength, GuiModList.this.font, false, true)); ret.addAll(RenderComponentsUtil.splitText(chat, maxTextLength, ModListScreen.this.font, false, true));
} }
} }
return ret; return ret;
@ -195,8 +197,8 @@ public class GuiModList extends Screen
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.color4f(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 // Draw the logo image inscribed in a rectangle with width entryWidth (minus some padding) and height 50
int headerHeight = 50; int headerHeight = 50;
GuiUtils.drawInscribedRect(left, relativeY, width - 5, headerHeight, logoDims.width, logoDims.height, false, true); GuiUtils.drawInscribedRect(left + PADDING, relativeY, width - (PADDING * 2), headerHeight, logoDims.width, logoDims.height, false, true);
relativeY += headerHeight; relativeY += headerHeight + PADDING;
} }
for (ITextComponent line : lines) for (ITextComponent line : lines)
@ -204,7 +206,7 @@ public class GuiModList extends Screen
if (line != null) if (line != null)
{ {
RenderSystem.enableBlend(); RenderSystem.enableBlend();
GuiModList.this.font.drawStringWithShadow(line.getFormattedText(), left + 4, relativeY, 0xFFFFFF); ModListScreen.this.font.drawStringWithShadow(line.getFormattedText(), left + PADDING, relativeY, 0xFFFFFF);
RenderSystem.disableAlphaTest(); RenderSystem.disableAlphaTest();
RenderSystem.disableBlend(); RenderSystem.disableBlend();
} }
@ -213,7 +215,7 @@ public class GuiModList extends Screen
final ITextComponent component = findTextLine(mouseX, mouseY); final ITextComponent component = findTextLine(mouseX, mouseY);
if (component!=null) { if (component!=null) {
GuiModList.this.renderComponentHoverEffect(component, mouseX, mouseY); ModListScreen.this.renderComponentHoverEffect(component, mouseX, mouseY);
} }
} }
@ -236,7 +238,7 @@ public class GuiModList extends Screen
for (ITextComponent part : line) { for (ITextComponent part : line) {
if (!(part instanceof StringTextComponent)) if (!(part instanceof StringTextComponent))
continue; continue;
k += GuiModList.this.font.getStringWidth(((StringTextComponent)part).getText()); k += ModListScreen.this.font.getStringWidth(((StringTextComponent)part).getText());
if (k >= mouseX) if (k >= mouseX)
{ {
return part; return part;
@ -250,7 +252,7 @@ public class GuiModList extends Screen
public boolean mouseClicked(final double mouseX, final double mouseY, final int button) { public boolean mouseClicked(final double mouseX, final double mouseY, final int button) {
final ITextComponent component = findTextLine((int) mouseX, (int) mouseY); final ITextComponent component = findTextLine((int) mouseX, (int) mouseY);
if (component != null) { if (component != null) {
GuiModList.this.handleComponentClicked(component); ModListScreen.this.handleComponentClicked(component);
return true; return true;
} }
return super.mouseClicked(mouseX, mouseY, button); return super.mouseClicked(mouseX, mouseY, button);
@ -271,22 +273,28 @@ public class GuiModList extends Screen
} }
listWidth = Math.max(Math.min(listWidth, width/3), 100); listWidth = Math.max(Math.min(listWidth, width/3), 100);
listWidth += listWidth % numButtons != 0 ? (numButtons - listWidth % numButtons) : 0; listWidth += listWidth % numButtons != 0 ? (numButtons - listWidth % numButtons) : 0;
this.modList = new GuiSlotModList(this, listWidth);
this.modList.setLeftPos(6);
int modInfoWidth = this.width - this.listWidth - 20;
this.modInfo = new InfoPanel(this.minecraft, modInfoWidth, this.height - 40, 10);
int modInfoWidth = this.width - this.listWidth - (PADDING * 3);
int doneButtonWidth = Math.min(modInfoWidth, 200); int doneButtonWidth = Math.min(modInfoWidth, 200);
this.addButton(new Button(((modList.getWidth() + 8 + this.width - doneButtonWidth) / 2), this.height - 24, doneButtonWidth, 20, int y = this.height - 20 - PADDING;
I18n.format("gui.done"), b -> GuiModList.this.minecraft.displayGuiScreen(GuiModList.this.mainMenu))); this.addButton(new Button(((listWidth + PADDING + this.width - doneButtonWidth) / 2), y, doneButtonWidth, 20,
this.addButton(this.openModsFolderButton = new Button(6, this.height - 24, this.listWidth, 20, I18n.format("gui.done"), b -> ModListScreen.this.minecraft.displayGuiScreen(ModListScreen.this.mainMenu)));
this.addButton(this.openModsFolderButton = new Button(6, y, this.listWidth, 20,
I18n.format("fml.menu.mods.openmodsfolder"), b -> Util.getOSType().openFile(FMLPaths.MODSDIR.get().toFile()))); I18n.format("fml.menu.mods.openmodsfolder"), b -> Util.getOSType().openFile(FMLPaths.MODSDIR.get().toFile())));
this.addButton(this.configButton = new Button(6, this.height - 48, this.listWidth, 20, y -= 20 + PADDING;
I18n.format("fml.menu.mods.config"), b -> GuiModList.this.displayModConfig())); this.addButton(this.configButton = new Button(6, y, this.listWidth, 20,
I18n.format("fml.menu.mods.config"), b -> ModListScreen.this.displayModConfig()));
this.configButton.active = false; this.configButton.active = false;
search = new TextFieldWidget(getFontRenderer(), 8, modList.getBottom() + 17, listWidth - 4, 14, I18n.format("fml.menu.mods.search")); y -= 14 + PADDING + 1;
search = new TextFieldWidget(getFontRenderer(), PADDING + 1, y, listWidth - 2, 14, I18n.format("fml.menu.mods.search"));
int fullButtonHeight = PADDING + 20 + PADDING;
this.modList = new ModListWidget(this, listWidth, fullButtonHeight, search.y - getFontRenderer().FONT_HEIGHT - PADDING);
this.modList.setLeftPos(6);
this.modInfo = new InfoPanel(this.minecraft, modInfoWidth, this.height - PADDING - fullButtonHeight, PADDING);
children.add(search); children.add(search);
children.add(modList); children.add(modList);
children.add(modInfo); children.add(modInfo);
@ -294,12 +302,12 @@ public class GuiModList extends Screen
search.setCanLoseFocus(true); search.setCanLoseFocus(true);
final int width = listWidth / numButtons; final int width = listWidth / numButtons;
int x = 6, y = 10; int x = PADDING;
addButton(SortType.NORMAL.button = new Button(x, y, width - buttonMargin, 20, SortType.NORMAL.getButtonText(), b -> resortMods(SortType.NORMAL))); addButton(SortType.NORMAL.button = new Button(x, PADDING, width - buttonMargin, 20, SortType.NORMAL.getButtonText(), b -> resortMods(SortType.NORMAL)));
x += width + buttonMargin; x += width + buttonMargin;
addButton(SortType.A_TO_Z.button = new Button(x, y, width - buttonMargin, 20, SortType.A_TO_Z.getButtonText(), b -> resortMods(SortType.A_TO_Z))); addButton(SortType.A_TO_Z.button = new Button(x, PADDING, width - buttonMargin, 20, SortType.A_TO_Z.getButtonText(), b -> resortMods(SortType.A_TO_Z)));
x += width + buttonMargin; x += width + buttonMargin;
addButton(SortType.Z_TO_A.button = new Button(x, y, width - buttonMargin, 20, SortType.Z_TO_A.getButtonText(), b -> resortMods(SortType.Z_TO_A))); addButton(SortType.Z_TO_A.button = new Button(x, PADDING, width - buttonMargin, 20, SortType.Z_TO_A.getButtonText(), b -> resortMods(SortType.Z_TO_A)));
resortMods(SortType.NORMAL); resortMods(SortType.NORMAL);
updateCache(); updateCache();
} }
@ -375,8 +383,8 @@ public class GuiModList extends Screen
this.modInfo.render(mouseX, mouseY, partialTicks); this.modInfo.render(mouseX, mouseY, partialTicks);
String text = I18n.format("fml.menu.mods.search"); String text = I18n.format("fml.menu.mods.search");
int x = ((modList.getRight()) / 2) - (getFontRenderer().getStringWidth(text) / 2); int x = modList.getLeft() + ((modList.getRight() - modList.getLeft()) / 2) - (getFontRenderer().getStringWidth(text) / 2);
getFontRenderer().drawString(text, x, modList.getBottom() + 5, 0xFFFFFF); getFontRenderer().drawString(text, x, search.y - getFontRenderer().FONT_HEIGHT, 0xFFFFFF);
this.search.render(mouseX, mouseY, partialTicks); this.search.render(mouseX, mouseY, partialTicks);
super.render(mouseX, mouseY, partialTicks); super.render(mouseX, mouseY, partialTicks);
} }
@ -391,7 +399,7 @@ public class GuiModList extends Screen
return font; return font;
} }
public void setSelected(GuiSlotModList.ModEntry entry) public void setSelected(ModListWidget.ModEntry entry)
{ {
this.selected = entry == this.selected ? null : entry; this.selected = entry == this.selected ? null : entry;
updateCache(); updateCache();
@ -424,7 +432,16 @@ public class GuiModList extends Screen
if (logo != null) if (logo != null)
{ {
return Pair.of(tm.getDynamicTextureLocation("modlogo", new DynamicTexture(logo)), new Size2i(logo.getWidth(), logo.getHeight())); return Pair.of(tm.getDynamicTextureLocation("modlogo", new DynamicTexture(logo) {
@Override
public void updateDynamicTexture() {
this.func_229148_d_();
NativeImage td = this.getTextureData();
// Use custom "blur" value which controls texture filtering (nearest-neighbor vs linear)
this.getTextureData().func_227789_a_(0, 0, 0, 0, 0, td.getWidth(), td.getHeight(), selectedMod.getLogoBlur(), false, false, false);
}
}), new Size2i(logo.getWidth(), logo.getHeight()));
} }
} }
catch (IOException e) { } catch (IOException e) { }
@ -473,7 +490,7 @@ public class GuiModList extends Screen
{ {
String s = this.search.getText(); String s = this.search.getText();
SortType sort = this.sortType; SortType sort = this.sortType;
GuiSlotModList.ModEntry selected = this.selected; ModListWidget.ModEntry selected = this.selected;
this.init(mc, width, height); this.init(mc, width, height);
this.search.setText(s); this.search.setText(s);
this.selected = selected; this.selected = selected;

View file

@ -31,17 +31,17 @@ import net.minecraftforge.fml.loading.moddiscovery.ModInfo;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
public class GuiSlotModList extends ExtendedList<GuiSlotModList.ModEntry> public class ModListWidget extends ExtendedList<ModListWidget.ModEntry>
{ {
private static String stripControlCodes(String value) { return net.minecraft.util.StringUtils.stripControlCodes(value); } private static String stripControlCodes(String value) { return net.minecraft.util.StringUtils.stripControlCodes(value); }
private static final ResourceLocation VERSION_CHECK_ICONS = new ResourceLocation(ForgeVersion.MOD_ID, "textures/gui/version_check_icons.png"); private static final ResourceLocation VERSION_CHECK_ICONS = new ResourceLocation(ForgeVersion.MOD_ID, "textures/gui/version_check_icons.png");
private final int listWidth; private final int listWidth;
private GuiModList parent; private ModListScreen parent;
public GuiSlotModList(GuiModList parent, int listWidth) public ModListWidget(ModListScreen parent, int listWidth, int top, int bottom)
{ {
super(parent.getMinecraftInstance(), listWidth, parent.height, 32, parent.height - 91 + 4, parent.getFontRenderer().FONT_HEIGHT * 2 + 8); super(parent.getMinecraftInstance(), listWidth, parent.height, top, bottom, parent.getFontRenderer().FONT_HEIGHT * 2 + 8);
this.parent = parent; this.parent = parent;
this.listWidth = listWidth; this.listWidth = listWidth;
this.refreshList(); this.refreshList();
@ -72,9 +72,9 @@ public class GuiSlotModList extends ExtendedList<GuiSlotModList.ModEntry>
class ModEntry extends ExtendedList.AbstractListEntry<ModEntry> { class ModEntry extends ExtendedList.AbstractListEntry<ModEntry> {
private final ModInfo modInfo; private final ModInfo modInfo;
private final GuiModList parent; private final ModListScreen parent;
ModEntry(ModInfo info, GuiModList parent) { ModEntry(ModInfo info, ModListScreen parent) {
this.modInfo = info; this.modInfo = info;
this.parent = parent; this.parent = parent;
} }
@ -103,7 +103,7 @@ public class GuiSlotModList extends ExtendedList<GuiSlotModList.ModEntry>
public boolean mouseClicked(double p_mouseClicked_1_, double p_mouseClicked_3_, int p_mouseClicked_5_) public boolean mouseClicked(double p_mouseClicked_1_, double p_mouseClicked_3_, int p_mouseClicked_5_)
{ {
parent.setSelected(this); parent.setSelected(this);
GuiSlotModList.this.setSelected(this); ModListWidget.this.setSelected(this);
return false; return false;
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 18 KiB