Dissallow color codes in mod names displayed in Mod gui list. And code formatting.
This commit is contained in:
parent
5a5ef86da9
commit
c5f22f56d8
2 changed files with 73 additions and 81 deletions
|
@ -54,53 +54,39 @@ import com.google.common.base.Strings;
|
||||||
*/
|
*/
|
||||||
public class GuiModList extends GuiScreen
|
public class GuiModList extends GuiScreen
|
||||||
{
|
{
|
||||||
private enum SortType
|
private enum SortType implements Comparator<ModContainer>
|
||||||
{
|
{
|
||||||
NORMAL(24), A_TO_Z(25), Z_TO_A(26);
|
NORMAL(24),
|
||||||
|
A_TO_Z(25){ @Override protected int compare(String name1, String name2){ return name1.compareTo(name2); }},
|
||||||
|
Z_TO_A(26){ @Override protected int compare(String name1, String name2){ return name2.compareTo(name1); }};
|
||||||
|
|
||||||
private int buttonID;
|
private int buttonID;
|
||||||
|
|
||||||
private SortType(int buttonID)
|
private SortType(int buttonID)
|
||||||
{
|
{
|
||||||
this.buttonID = buttonID;
|
this.buttonID = buttonID;
|
||||||
this.comparator = new ModComparator(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ModComparator comparator;
|
|
||||||
|
|
||||||
public static SortType getTypeForButton(GuiButton button)
|
public static SortType getTypeForButton(GuiButton button)
|
||||||
{
|
{
|
||||||
for (SortType t : values()) {
|
for (SortType t : values())
|
||||||
if (t.buttonID == button.id) {
|
{
|
||||||
|
if (t.buttonID == button.id)
|
||||||
|
{
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static class ModComparator implements Comparator<ModContainer>
|
protected int compare(String name1, String name2){ return 0; }
|
||||||
{
|
|
||||||
private SortType type;
|
|
||||||
private ModComparator(SortType type)
|
|
||||||
{
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(ModContainer o1, ModContainer o2)
|
public int compare(ModContainer o1, ModContainer o2)
|
||||||
{
|
{
|
||||||
String name1 = StringUtils.stripControlCodes(o1.getName()).toLowerCase();
|
String name1 = StringUtils.stripControlCodes(o1.getName()).toLowerCase();
|
||||||
String name2 = StringUtils.stripControlCodes(o2.getName()).toLowerCase();
|
String name2 = StringUtils.stripControlCodes(o2.getName()).toLowerCase();
|
||||||
switch(type)
|
return compare(name1, name2);
|
||||||
{
|
|
||||||
case A_TO_Z:
|
|
||||||
return name1.compareTo(name2);
|
|
||||||
case Z_TO_A:
|
|
||||||
return name2.compareTo(name1);
|
|
||||||
default:
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,12 +115,14 @@ public class GuiModList extends GuiScreen
|
||||||
*/
|
*/
|
||||||
public GuiModList(GuiScreen mainMenu)
|
public GuiModList(GuiScreen mainMenu)
|
||||||
{
|
{
|
||||||
this.mainMenu=mainMenu;
|
this.mainMenu = mainMenu;
|
||||||
this.mods=new ArrayList<ModContainer>();
|
this.mods = new ArrayList<ModContainer>();
|
||||||
FMLClientHandler.instance().addSpecialModEntries(mods);
|
FMLClientHandler.instance().addSpecialModEntries(mods);
|
||||||
// Add child mods to their parent's list
|
// Add child mods to their parent's list
|
||||||
for (ModContainer mod : Loader.instance().getModList()) {
|
for (ModContainer mod : Loader.instance().getModList())
|
||||||
if (mod.getMetadata()!=null && mod.getMetadata().parentMod==null && !Strings.isNullOrEmpty(mod.getMetadata().parent)) {
|
{
|
||||||
|
if (mod.getMetadata() != null && mod.getMetadata().parentMod == null && !Strings.isNullOrEmpty(mod.getMetadata().parent))
|
||||||
|
{
|
||||||
String parentMod = mod.getMetadata().parent;
|
String parentMod = mod.getMetadata().parent;
|
||||||
ModContainer parentContainer = Loader.instance().getIndexedModList().get(parentMod);
|
ModContainer parentContainer = Loader.instance().getIndexedModList().get(parentMod);
|
||||||
if (parentContainer != null)
|
if (parentContainer != null)
|
||||||
|
@ -144,7 +132,7 @@ public class GuiModList extends GuiScreen
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (mod.getMetadata()!=null && mod.getMetadata().parentMod!=null)
|
else if (mod.getMetadata() != null && mod.getMetadata().parentMod != null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -156,12 +144,13 @@ public class GuiModList extends GuiScreen
|
||||||
@Override
|
@Override
|
||||||
public void initGui()
|
public void initGui()
|
||||||
{
|
{
|
||||||
for (ModContainer mod : mods) {
|
for (ModContainer mod : mods)
|
||||||
listWidth=Math.max(listWidth,getFontRenderer().getStringWidth(mod.getName()) + 10);
|
{
|
||||||
listWidth=Math.max(listWidth,getFontRenderer().getStringWidth(mod.getVersion()) + 10);
|
listWidth = Math.max(listWidth,getFontRenderer().getStringWidth(mod.getName()) + 10);
|
||||||
|
listWidth = Math.max(listWidth,getFontRenderer().getStringWidth(mod.getVersion()) + 10);
|
||||||
}
|
}
|
||||||
listWidth=Math.min(listWidth, 150);
|
listWidth = Math.min(listWidth, 150);
|
||||||
this.modList=new GuiSlotModList(this, mods, listWidth);
|
this.modList = new GuiSlotModList(this, mods, listWidth);
|
||||||
this.modList.registerScrollButtons(this.buttonList, 7, 8);
|
this.modList.registerScrollButtons(this.buttonList, 7, 8);
|
||||||
|
|
||||||
this.buttonList.add(new GuiButton(6, ((modList.right + this.width) / 2) - 100, this.height - 38, I18n.format("gui.done")));
|
this.buttonList.add(new GuiButton(6, ((modList.right + this.width) / 2) - 100, this.height - 38, I18n.format("gui.done")));
|
||||||
|
@ -217,7 +206,7 @@ public class GuiModList extends GuiScreen
|
||||||
if (!sorted)
|
if (!sorted)
|
||||||
{
|
{
|
||||||
reloadMods();
|
reloadMods();
|
||||||
Collections.sort(mods, sortType.comparator);
|
Collections.sort(mods, sortType);
|
||||||
selected = modList.selectedIndex = mods.indexOf(selectedMod);
|
selected = modList.selectedIndex = mods.indexOf(selectedMod);
|
||||||
sorted = true;
|
sorted = true;
|
||||||
}
|
}
|
||||||
|
@ -263,22 +252,22 @@ public class GuiModList extends GuiScreen
|
||||||
{
|
{
|
||||||
switch (button.id)
|
switch (button.id)
|
||||||
{
|
{
|
||||||
case 6:
|
case 6:
|
||||||
this.mc.displayGuiScreen(this.mainMenu);
|
this.mc.displayGuiScreen(this.mainMenu);
|
||||||
return;
|
return;
|
||||||
case 20:
|
case 20:
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IModGuiFactory guiFactory = FMLClientHandler.instance().getGuiFactoryFor(selectedMod);
|
IModGuiFactory guiFactory = FMLClientHandler.instance().getGuiFactoryFor(selectedMod);
|
||||||
GuiScreen newScreen = guiFactory.mainConfigGuiClass().getConstructor(GuiScreen.class).newInstance(this);
|
GuiScreen newScreen = guiFactory.mainConfigGuiClass().getConstructor(GuiScreen.class).newInstance(this);
|
||||||
this.mc.displayGuiScreen(newScreen);
|
this.mc.displayGuiScreen(newScreen);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
FMLLog.log(Level.ERROR, e, "There was a critical issue trying to build the config GUI for %s", selectedMod.getModId());
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
FMLLog.log(Level.ERROR, e, "There was a critical issue trying to build the config GUI for %s", selectedMod.getModId());
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
super.actionPerformed(button);
|
super.actionPerformed(button);
|
||||||
|
@ -296,9 +285,11 @@ public class GuiModList extends GuiScreen
|
||||||
this.modList.drawScreen(p_571_1_, p_571_2_, p_571_3_);
|
this.modList.drawScreen(p_571_1_, p_571_2_, p_571_3_);
|
||||||
this.drawCenteredString(this.fontRendererObj, "Mod List", this.width / 2, 16, 0xFFFFFF);
|
this.drawCenteredString(this.fontRendererObj, "Mod List", this.width / 2, 16, 0xFFFFFF);
|
||||||
int offset = this.listWidth + 20;
|
int offset = this.listWidth + 20;
|
||||||
if (selectedMod != null) {
|
if (selectedMod != null)
|
||||||
|
{
|
||||||
GL11.glEnable(GL11.GL_BLEND);
|
GL11.glEnable(GL11.GL_BLEND);
|
||||||
if (!selectedMod.getMetadata().autogenerated) {
|
if (!selectedMod.getMetadata().autogenerated)
|
||||||
|
{
|
||||||
configModButton.visible = true;
|
configModButton.visible = true;
|
||||||
disableModButton.visible = true;
|
disableModButton.visible = true;
|
||||||
disableModButton.packedFGColour = 0xFF3377;
|
disableModButton.packedFGColour = 0xFF3377;
|
||||||
|
@ -368,7 +359,8 @@ public class GuiModList extends GuiScreen
|
||||||
|
|
||||||
shifty = drawLine(String.format("Version: %s (%s)", selectedMod.getDisplayVersion(), selectedMod.getVersion()), offset, shifty);
|
shifty = drawLine(String.format("Version: %s (%s)", selectedMod.getDisplayVersion(), selectedMod.getVersion()), offset, shifty);
|
||||||
shifty = drawLine(String.format("Mod ID: '%s' Mod State: %s", selectedMod.getModId(), Loader.instance().getModState(selectedMod)), offset, shifty);
|
shifty = drawLine(String.format("Mod ID: '%s' Mod State: %s", selectedMod.getModId(), Loader.instance().getModState(selectedMod)), offset, shifty);
|
||||||
if (!selectedMod.getMetadata().credits.isEmpty()) {
|
if (!selectedMod.getMetadata().credits.isEmpty())
|
||||||
|
{
|
||||||
shifty = drawLine(String.format("Credits: %s", selectedMod.getMetadata().credits), offset, shifty);
|
shifty = drawLine(String.format("Credits: %s", selectedMod.getMetadata().credits), offset, shifty);
|
||||||
}
|
}
|
||||||
shifty = drawLine(String.format("Authors: %s", selectedMod.getMetadata().getAuthorList()), offset, shifty);
|
shifty = drawLine(String.format("Authors: %s", selectedMod.getMetadata().getAuthorList()), offset, shifty);
|
||||||
|
@ -409,7 +401,9 @@ public class GuiModList extends GuiScreen
|
||||||
configModButton.visible = true;
|
configModButton.visible = true;
|
||||||
configModButton.enabled = true;
|
configModButton.enabled = true;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
offset = ( this.listWidth + this.width ) / 2;
|
offset = ( this.listWidth + this.width ) / 2;
|
||||||
this.drawCenteredString(this.fontRendererObj, selectedMod.getName(), offset, 35, 0xFFFFFF);
|
this.drawCenteredString(this.fontRendererObj, selectedMod.getName(), offset, 35, 0xFFFFFF);
|
||||||
this.drawCenteredString(this.fontRendererObj, String.format("Version: %s",selectedMod.getVersion()), offset, 45, 0xFFFFFF);
|
this.drawCenteredString(this.fontRendererObj, String.format("Version: %s",selectedMod.getVersion()), offset, 45, 0xFFFFFF);
|
||||||
|
@ -434,30 +428,25 @@ public class GuiModList extends GuiScreen
|
||||||
search.drawTextBox();
|
search.drawTextBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
Minecraft getMinecraftInstance() {
|
Minecraft getMinecraftInstance()
|
||||||
|
{
|
||||||
return mc;
|
return mc;
|
||||||
}
|
}
|
||||||
|
|
||||||
FontRenderer getFontRenderer() {
|
FontRenderer getFontRenderer()
|
||||||
|
{
|
||||||
return fontRendererObj;
|
return fontRendererObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void selectModIndex(int index)
|
||||||
* @param var1
|
|
||||||
*/
|
|
||||||
public void selectModIndex(int var1)
|
|
||||||
{
|
{
|
||||||
this.selected=var1;
|
this.selected = index;
|
||||||
if (var1>=0 && var1<=mods.size()) {
|
this.selectedMod = (index >= 0 && index <= mods.size()) ? mods.get(selected) : null;
|
||||||
this.selectedMod=mods.get(selected);
|
|
||||||
} else {
|
|
||||||
this.selectedMod=null;
|
|
||||||
}
|
|
||||||
cachedLogo = null;
|
cachedLogo = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean modIndexSelected(int var1)
|
public boolean modIndexSelected(int index)
|
||||||
{
|
{
|
||||||
return var1==selected;
|
return index == selected;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ package net.minecraftforge.fml.client;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
|
import net.minecraft.util.StringUtils;
|
||||||
import net.minecraftforge.fml.common.Loader;
|
import net.minecraftforge.fml.common.Loader;
|
||||||
import net.minecraftforge.fml.common.LoaderState.ModState;
|
import net.minecraftforge.fml.common.LoaderState.ModState;
|
||||||
import net.minecraftforge.fml.common.ModContainer;
|
import net.minecraftforge.fml.common.ModContainer;
|
||||||
|
@ -74,16 +75,18 @@ public class GuiSlotModList extends GuiScrollingList
|
||||||
protected void drawSlot(int listIndex, int var2, int var3, int var4, Tessellator var5)
|
protected void drawSlot(int listIndex, int var2, int var3, int var4, Tessellator var5)
|
||||||
{
|
{
|
||||||
ModContainer mc=mods.get(listIndex);
|
ModContainer mc=mods.get(listIndex);
|
||||||
|
String name = StringUtils.stripControlCodes(mc.getName());
|
||||||
|
String version = StringUtils.stripControlCodes(mc.getDisplayVersion());
|
||||||
if (Loader.instance().getModState(mc)==ModState.DISABLED)
|
if (Loader.instance().getModState(mc)==ModState.DISABLED)
|
||||||
{
|
{
|
||||||
this.parent.getFontRenderer().drawString(this.parent.getFontRenderer().trimStringToWidth(mc.getName(), listWidth - 10), this.left + 3 , var3 + 2, 0xFF2222);
|
this.parent.getFontRenderer().drawString(this.parent.getFontRenderer().trimStringToWidth(name, listWidth - 10), this.left + 3 , var3 + 2, 0xFF2222);
|
||||||
this.parent.getFontRenderer().drawString(this.parent.getFontRenderer().trimStringToWidth(mc.getDisplayVersion(), listWidth - 10), this.left + 3 , var3 + 12, 0xFF2222);
|
this.parent.getFontRenderer().drawString(this.parent.getFontRenderer().trimStringToWidth(version, listWidth - 10), this.left + 3 , var3 + 12, 0xFF2222);
|
||||||
this.parent.getFontRenderer().drawString(this.parent.getFontRenderer().trimStringToWidth("DISABLED", listWidth - 10), this.left + 3 , var3 + 22, 0xFF2222);
|
this.parent.getFontRenderer().drawString(this.parent.getFontRenderer().trimStringToWidth("DISABLED", listWidth - 10), this.left + 3 , var3 + 22, 0xFF2222);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.parent.getFontRenderer().drawString(this.parent.getFontRenderer().trimStringToWidth(mc.getName(), listWidth - 10), this.left + 3 , var3 + 2, 0xFFFFFF);
|
this.parent.getFontRenderer().drawString(this.parent.getFontRenderer().trimStringToWidth(name, listWidth - 10), this.left + 3 , var3 + 2, 0xFFFFFF);
|
||||||
this.parent.getFontRenderer().drawString(this.parent.getFontRenderer().trimStringToWidth(mc.getDisplayVersion(), listWidth - 10), this.left + 3 , var3 + 12, 0xCCCCCC);
|
this.parent.getFontRenderer().drawString(this.parent.getFontRenderer().trimStringToWidth(version, listWidth - 10), this.left + 3 , var3 + 12, 0xCCCCCC);
|
||||||
this.parent.getFontRenderer().drawString(this.parent.getFontRenderer().trimStringToWidth(mc.getMetadata() !=null ? mc.getMetadata().getChildModCountString() : "Metadata not found", listWidth - 10), this.left + 3 , var3 + 22, 0xCCCCCC);
|
this.parent.getFontRenderer().drawString(this.parent.getFontRenderer().trimStringToWidth(mc.getMetadata() !=null ? mc.getMetadata().getChildModCountString() : "Metadata not found", listWidth - 10), this.left + 3 , var3 + 22, 0xCCCCCC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue