Commit 1bc2d41a37eb71e134d515ec76e45048828e26c6

Authored by Mumfrey
1 parent 12a6cba5

show a list of invalid containers if no valid containers are found

java/client/com/mumfrey/liteloader/client/gui/modlist/GuiModListPanel.java
... ... @@ -41,18 +41,18 @@ public class GuiModListPanel extends Gui
41 41 static final int PANEL_HEIGHT = 32;
42 42 static final int PANEL_SPACING = 3;
43 43  
44   - private ModListEntry owner;
  44 + protected ModListEntry owner;
45 45  
46 46 /**
47 47 * For text display
48 48 */
49   - private final FontRenderer fontRenderer;
  49 + protected final FontRenderer fontRenderer;
50 50  
51   - private final int brandColour;
  51 + protected final int brandColour;
52 52  
53   - private final List<ModInfoDecorator> decorators;
  53 + protected final List<ModInfoDecorator> decorators;
54 54  
55   - private final ModInfo<?> modInfo;
  55 + protected final ModInfo<?> modInfo;
56 56  
57 57 /**
58 58 * True if the mouse was over this mod on the last render
... ... @@ -65,11 +65,11 @@ public class GuiModListPanel extends Gui
65 65  
66 66 public GuiModListPanel(ModListEntry owner, FontRenderer fontRenderer, int brandColour, ModInfo<?> modInfo, List<ModInfoDecorator> decorators)
67 67 {
68   - this.owner = owner;
  68 + this.owner = owner;
69 69 this.fontRenderer = fontRenderer;
70   - this.brandColour = brandColour;
71   - this.modInfo = modInfo;
72   - this.decorators = decorators;
  70 + this.brandColour = brandColour;
  71 + this.modInfo = modInfo;
  72 + this.decorators = decorators;
73 73  
74 74 for (ModInfoDecorator decorator : this.decorators)
75 75 {
... ... @@ -122,7 +122,7 @@ public class GuiModListPanel extends Gui
122 122 this.fontRenderer.drawString(versionText, xPosition + 5, yPosition + 12, GuiModListPanel.VERSION_TEXT_COLOUR);
123 123 this.fontRenderer.drawString(statusText, xPosition + 5, yPosition + 22, statusColour);
124 124  
125   - this.mouseOver = this.isMouseOver(mouseX, mouseY, xPosition, yPosition, width, PANEL_HEIGHT);
  125 + this.updateMouseOver(mouseX, mouseY, xPosition, yPosition, width);
126 126 int hangerColour = this.mouseOver ? GuiModListPanel.HANGER_COLOUR_MOUSEOVER : GuiModListPanel.HANGER_COLOUR;
127 127 drawRect(xPosition, yPosition, xPosition + 1, yPosition + PANEL_HEIGHT, hangerColour);
128 128  
... ... @@ -131,6 +131,18 @@ public class GuiModListPanel extends Gui
131 131 decorator.onDrawListEntry(mouseX, mouseY, partialTicks, xPosition, yPosition, width, GuiModListPanel.PANEL_HEIGHT, selected, this.modInfo, gradientColour, titleColour, statusColour);
132 132 }
133 133 }
  134 +
  135 + /**
  136 + * @param mouseX
  137 + * @param mouseY
  138 + * @param xPosition
  139 + * @param yPosition
  140 + * @param width
  141 + */
  142 + protected void updateMouseOver(int mouseX, int mouseY, int xPosition, int yPosition, int width)
  143 + {
  144 + this.mouseOver = this.isMouseOver(mouseX, mouseY, xPosition, yPosition, width, PANEL_HEIGHT);
  145 + }
134 146  
135 147 protected void postRender(int mouseX, int mouseY, float partialTicks, int xPosition, int yPosition, int width, boolean selected)
136 148 {
... ... @@ -218,7 +230,7 @@ public class GuiModListPanel extends Gui
218 230 return GuiModListPanel.PANEL_HEIGHT + GuiModListPanel.PANEL_SPACING;
219 231 }
220 232  
221   - private boolean isMouseOver(int mouseX, int mouseY, int x, int y, int width, int height)
  233 + protected boolean isMouseOver(int mouseX, int mouseY, int x, int y, int width, int height)
222 234 {
223 235 return mouseX > x && mouseX < x + width && mouseY > y && mouseY < y + height;
224 236 }
... ...
java/client/com/mumfrey/liteloader/client/gui/modlist/GuiModListPanelInvalid.java 0 → 100644
  1 +package com.mumfrey.liteloader.client.gui.modlist;
  2 +
  3 +import java.util.List;
  4 +
  5 +import net.minecraft.client.gui.FontRenderer;
  6 +
  7 +import com.mumfrey.liteloader.api.ModInfoDecorator;
  8 +import com.mumfrey.liteloader.core.ModInfo;
  9 +
  10 +public class GuiModListPanelInvalid extends GuiModListPanel
  11 +{
  12 + private static final int BAD_PANEL_HEIGHT = 22;
  13 +
  14 + public GuiModListPanelInvalid(ModListEntry owner, FontRenderer fontRenderer, int brandColour, ModInfo<?> modInfo, List<ModInfoDecorator> decorators)
  15 + {
  16 + super(owner, fontRenderer, brandColour, modInfo, decorators);
  17 + }
  18 +
  19 + @Override
  20 + protected void render(int mouseX, int mouseY, float partialTicks, int xPosition, int yPosition, int width, boolean selected)
  21 + {
  22 + int gradientColour = selected ? ERROR_GRADIENT_COLOUR : ERROR_GRADIENT_COLOUR2;
  23 +
  24 + this.drawGradientRect(xPosition, yPosition, xPosition + width, yPosition + 22, gradientColour, GuiModListPanel.GRADIENT_COLOUR2);
  25 +
  26 + String titleText = this.owner.getTitleText();
  27 + String reasonText = this.modInfo.getDescription();
  28 +
  29 + this.fontRenderer.drawString(titleText, xPosition + 5, yPosition + 2, 0xFF8888);
  30 + this.fontRenderer.drawString(reasonText, xPosition + 5, yPosition + 12, GuiModListPanel.ERROR_GRADIENT_COLOUR);
  31 +
  32 + this.updateMouseOver(mouseX, mouseY, xPosition, yPosition, width);
  33 + drawRect(xPosition, yPosition, xPosition + 1, yPosition + 22, ERROR_COLOUR);
  34 + }
  35 +
  36 + @Override
  37 + protected void postRender(int mouseX, int mouseY, float partialTicks, int xPosition, int yPosition, int width, boolean selected)
  38 + {
  39 + }
  40 +
  41 + @Override
  42 + public int getHeight()
  43 + {
  44 + return GuiModListPanelInvalid.BAD_PANEL_HEIGHT;
  45 + }
  46 +
  47 + @Override
  48 + public int getTotalHeight()
  49 + {
  50 + return GuiModListPanelInvalid.BAD_PANEL_HEIGHT + GuiModListPanel.PANEL_SPACING;
  51 + }
  52 +}
... ...
java/client/com/mumfrey/liteloader/client/gui/modlist/ModList.java
... ... @@ -71,6 +71,16 @@ public class ModList
71 71 ModListEntry modListEntry = new ModListEntry(this, mods, environment, minecraft.fontRendererObj, brandColour, decorators, disabledMod);
72 72 sortedMods.put(modListEntry.getKey(), modListEntry);
73 73 }
  74 +
  75 + // Show bad containers if no other containers are found, should help users realise they have the wrong mod version!
  76 + if (sortedMods.size() == 0)
  77 + {
  78 + for (ModInfo<?> badMod : mods.getBadContainers())
  79 + {
  80 + ModListEntry modListEntry = new ModListEntry(this, mods, environment, minecraft.fontRendererObj, brandColour, decorators, badMod);
  81 + sortedMods.put(modListEntry.getKey(), modListEntry);
  82 + }
  83 + }
74 84  
75 85 // Injected tweaks
76 86 for (ModInfo<Loadable<?>> injectedTweak : mods.getInjectedTweaks())
... ...
java/client/com/mumfrey/liteloader/client/gui/modlist/ModListEntry.java
... ... @@ -37,6 +37,8 @@ public class ModListEntry
37 37 */
38 38 private boolean isActive;
39 39  
  40 + private boolean isValid;
  41 +
40 42 private boolean isMissingDependencies;
41 43  
42 44 private boolean isMissingAPIs;
... ... @@ -90,12 +92,13 @@ public class ModListEntry
90 92 this.modInfo = modInfo;
91 93  
92 94 this.isActive = modInfo.isActive();
  95 + this.isValid = modInfo.isValid();
93 96 this.canBeToggled = modInfo.isToggleable() && mods.getEnabledModsList().saveAllowed();
94 97 this.willBeEnabled = mods.isModEnabled(this.modInfo.getIdentifier());;
95 98 this.isExternal = modInfo.getContainer().isExternalJar();
96 99 this.isErrored = modInfo.getStartupErrors() != null && modInfo.getStartupErrors().size() > 0;
97 100  
98   - if (!modInfo.isActive())
  101 + if (!modInfo.isActive() && this.isValid)
99 102 {
100 103 this.isActive = modInfo.getContainer().isEnabled(environment);
101 104  
... ... @@ -123,7 +126,15 @@ public class ModListEntry
123 126 protected void initPanels(FontRenderer fontRenderer, int brandColour, List<ModInfoDecorator> decorators, ModInfo<?> modInfo)
124 127 {
125 128 this.infoPanel = new GuiModInfoPanel(this, fontRenderer, brandColour, modInfo);
126   - this.listPanel = new GuiModListPanel(this, fontRenderer, brandColour, modInfo, decorators);
  129 +
  130 + if (this.isValid)
  131 + {
  132 + this.listPanel = new GuiModListPanel(this, fontRenderer, brandColour, modInfo, decorators);
  133 + }
  134 + else
  135 + {
  136 + this.listPanel = new GuiModListPanelInvalid(this, fontRenderer, brandColour, modInfo, decorators);
  137 + }
127 138 }
128 139  
129 140 public void onTick()
... ...
java/common/com/mumfrey/liteloader/core/BadContainerInfo.java 0 → 100644
  1 +package com.mumfrey.liteloader.core;
  2 +
  3 +import com.mumfrey.liteloader.core.api.LoadableModFile;
  4 +import com.mumfrey.liteloader.interfaces.Loadable;
  5 +
  6 +/**
  7 + * ModInfo for invalid containers
  8 + *
  9 + * @author Adam Mummery-Smith
  10 + */
  11 +public class BadContainerInfo extends NonMod
  12 +{
  13 + /**
  14 + * Reason the container could not be loaded
  15 + */
  16 + private final String reason;
  17 +
  18 + public BadContainerInfo(Loadable<?> container, String reason)
  19 + {
  20 + super(container, false);
  21 + this.reason = reason;
  22 + }
  23 +
  24 + /* (non-Javadoc)
  25 + * @see com.mumfrey.liteloader.core.ModInfo#isToggleable()
  26 + */
  27 + @Override
  28 + public boolean isToggleable()
  29 + {
  30 + return false;
  31 + }
  32 +
  33 + /* (non-Javadoc)
  34 + * @see com.mumfrey.liteloader.core.ModInfo#isValid()
  35 + */
  36 + @Override
  37 + public boolean isValid()
  38 + {
  39 + return false;
  40 + }
  41 +
  42 + /* (non-Javadoc)
  43 + * @see com.mumfrey.liteloader.core.ModInfo#getDescription()
  44 + */
  45 + @Override
  46 + public String getDescription()
  47 + {
  48 + return "\247c" + this.reason;
  49 + }
  50 +
  51 + /* (non-Javadoc)
  52 + * @see com.mumfrey.liteloader.core.ModInfo#getVersion()
  53 + */
  54 + @Override
  55 + public String getVersion()
  56 + {
  57 + if (this.container instanceof LoadableModFile)
  58 + {
  59 + return "supported: \247c" + ((LoadableModFile)this.container).getTargetVersion() + "\247r";
  60 + }
  61 +
  62 + return "supported: \247cUnknown";
  63 + }
  64 +}
... ...
java/common/com/mumfrey/liteloader/core/LiteLoaderEnumerator.java
... ... @@ -94,6 +94,11 @@ public class LiteLoaderEnumerator implements LoaderEnumerator
94 94 * Mapping of identifiers to mod containers
95 95 */
96 96 private final Map<String, LoadableMod<?>> enabledContainers = new HashMap<String, LoadableMod<?>>();
  97 +
  98 + /**
  99 + * Map of containers which cannot be loaded to reasons
  100 + */
  101 + private final Set<ModInfo<Loadable<?>>> badContainers = new HashSet<ModInfo<Loadable<?>>>();
97 102  
98 103 /**
99 104 * Containers which have already been checked for potential mod candidates
... ... @@ -259,6 +264,14 @@ public class LiteLoaderEnumerator implements LoaderEnumerator
259 264 return this.disabledContainers.values();
260 265 }
261 266  
  267 + @Override
  268 + public Collection<? extends ModInfo<Loadable<?>>> getBadContainers()
  269 + {
  270 + this.checkState(EnumeratorState.FINALISED, "getBadContainers");
  271 +
  272 + return this.badContainers;
  273 + }
  274 +
262 275 /**
263 276 * Get the list of injected tweak containers
264 277 */
... ... @@ -446,7 +459,7 @@ public class LiteLoaderEnumerator implements LoaderEnumerator
446 459 }
447 460  
448 461 /* (non-Javadoc)
449   - * @see com.mumfrey.liteloader.interfaces.PluggableEnumerator#registerModContainer(com.mumfrey.liteloader.interfaces.LoadableMod)
  462 + * @see com.mumfrey.liteloader.interfaces.ModularEnumerator#registerModContainer(com.mumfrey.liteloader.interfaces.LoadableMod)
450 463 */
451 464 @Override
452 465 public final boolean registerModContainer(LoadableMod<?> container)
... ... @@ -478,6 +491,15 @@ public class LiteLoaderEnumerator implements LoaderEnumerator
478 491  
479 492 return true;
480 493 }
  494 +
  495 + @Override
  496 + public void registerBadContainer(Loadable<?> container, String reason)
  497 + {
  498 + this.checkState(EnumeratorState.DISCOVER, "registerBadContainer");
  499 +
  500 + BadContainerInfo badMod = new BadContainerInfo(container, reason);
  501 + this.badContainers.add(badMod);
  502 + }
481 503  
482 504 /**
483 505 * @param container
... ...
java/common/com/mumfrey/liteloader/core/LiteLoaderMods.java
... ... @@ -2,6 +2,7 @@ package com.mumfrey.liteloader.core;
2 2  
3 3 import java.io.File;
4 4 import java.util.Collections;
  5 +import java.util.Deque;
5 6 import java.util.HashMap;
6 7 import java.util.LinkedList;
7 8 import java.util.List;
... ... @@ -79,22 +80,32 @@ public class LiteLoaderMods
79 80 /**
80 81 * Global list of mods which we can load
81 82 */
82   - protected final LinkedList<Mod> allMods = new LinkedList<Mod>();
  83 + protected final List<Mod> allMods = new LinkedList<Mod>();
83 84  
84 85 /**
85 86 * Global list of mods which are still waiting for initialisiation
86 87 */
87   - protected final LinkedList<Mod> initMods = new LinkedList<Mod>();
  88 + protected final Deque<Mod> initMods = new LinkedList<Mod>();
88 89  
89 90 /**
90 91 * Global list of mods which we have loaded
91 92 */
92   - protected final LinkedList<Mod> loadedMods = new LinkedList<Mod>();
  93 + protected final List<Mod> loadedMods = new LinkedList<Mod>();
  94 +
  95 + /**
  96 + * Global list of mods which we found but ignored (eg. outdated, invalid)
  97 + */
  98 + protected final List<Mod> badMods = new LinkedList<Mod>();
93 99  
94 100 /**
95 101 * Mods which are loaded but disabled
96 102 */
97   - protected final LinkedList<ModInfo<?>> disabledMods = new LinkedList<ModInfo<?>>();
  103 + protected final List<ModInfo<?>> disabledMods = new LinkedList<ModInfo<?>>();
  104 +
  105 + /**
  106 + * Bad containers
  107 + */
  108 + protected final List<ModInfo<?>> badContainers = new LinkedList<ModInfo<?>>();
98 109  
99 110 private int startupErrorCount, criticalErrorCount;
100 111  
... ... @@ -112,6 +123,7 @@ public class LiteLoaderMods
112 123 {
113 124 this.observers.addAll(observers);
114 125 this.disabledMods.addAll(this.enumerator.getDisabledContainers());
  126 + this.badContainers.addAll(this.enumerator.getBadContainers());
115 127 }
116 128  
117 129 void onPostInit()
... ... @@ -156,6 +168,14 @@ public class LiteLoaderMods
156 168 {
157 169 return this.disabledMods;
158 170 }
  171 +
  172 + /**
  173 + * Get a list of all bad containers
  174 + */
  175 + public List<? extends ModInfo<?>> getBadContainers()
  176 + {
  177 + return this.badContainers;
  178 + }
159 179  
160 180 /**
161 181 * Get the list of injected tweak containers
... ...
java/common/com/mumfrey/liteloader/core/ModInfo.java
... ... @@ -60,6 +60,14 @@ public abstract class ModInfo&lt;TContainer extends Loadable&lt;?&gt;&gt;
60 60 }
61 61  
62 62 /**
  63 + * Get whether this mod is valid
  64 + */
  65 + public boolean isValid()
  66 + {
  67 + return true;
  68 + }
  69 +
  70 + /**
63 71 * Get whether this mod can be toggled
64 72 */
65 73 public boolean isToggleable()
... ...
java/common/com/mumfrey/liteloader/core/api/EnumeratorModuleFolder.java
... ... @@ -117,6 +117,7 @@ public class EnumeratorModuleFolder implements FilenameFilter, EnumeratorModule
117 117 if (fileName.endsWith(".litemod.zip"))
118 118 {
119 119 LiteLoaderLogger.warning("Found %s with unsupported extension .litemod.zip. Please change file extension to .litemod to allow this file to be loaded!", fileName);
  120 + return true;
120 121 }
121 122  
122 123 return fileName.endsWith(".litemod") || fileName.endsWith(".jar");
... ... @@ -164,7 +165,7 @@ public class EnumeratorModuleFolder implements FilenameFilter, EnumeratorModule
164 165 */
165 166 protected void inspectFile(ModularEnumerator enumerator, LoadableFile candidateFile)
166 167 {
167   - if (this.isValidFile(candidateFile))
  168 + if (this.isValidFile(enumerator, candidateFile))
168 169 {
169 170 String metaData = candidateFile.getFileContents(LoadableMod.METADATA_FILENAME, Charsets.UTF_8);
170 171 if (metaData != null)
... ... @@ -182,19 +183,30 @@ public class EnumeratorModuleFolder implements FilenameFilter, EnumeratorModule
182 183 else
183 184 {
184 185 LiteLoaderLogger.info("Ignoring %s", candidateFile);
  186 +// enumerator.registerBadContainer(candidateFile, "No metadata");
185 187 }
186 188 }
  189 +// else
  190 +// {
  191 +// enumerator.registerBadContainer(candidateFile, "Not a valid file");
  192 +// }
187 193 }
188 194  
189 195 /**
190 196 * Check whether the specified file is a valid mod container
191 197 *
  198 + * @param enumerator
192 199 * @param candidateFile
193 200 */
194   - protected boolean isValidFile(LoadableFile candidateFile)
  201 + protected boolean isValidFile(ModularEnumerator enumerator, LoadableFile candidateFile)
195 202 {
196 203 String filename = candidateFile.getName().toLowerCase();
197   - if (filename.endsWith(".litemod"))
  204 + if (filename.endsWith(".litemod.zip"))
  205 + {
  206 + enumerator.registerBadContainer(candidateFile, "Invalid file extension .litemod.zip");
  207 + return false;
  208 + }
  209 + else if (filename.endsWith(".litemod"))
198 210 {
199 211 return true;
200 212 }
... ... @@ -281,6 +293,7 @@ public class EnumeratorModuleFolder implements FilenameFilter, EnumeratorModule
281 293 else
282 294 {
283 295 LiteLoaderLogger.info("Not adding invalid or version-mismatched mod file: %s", modFile);
  296 + enumerator.registerBadContainer(modFile, "Version not supported");
284 297 }
285 298 }
286 299 }
... ...
java/common/com/mumfrey/liteloader/core/api/LoadableModFile.java
... ... @@ -173,7 +173,7 @@ public class LoadableModFile extends LoadableFile implements LoadableMod&lt;File&gt;
173 173 try
174 174 {
175 175 this.modName = this.getMetaValue("name", this.getDefaultName());
176   - this.displayName = this.getMetaValue("displayName", null);
  176 + this.displayName = this.getMetaValue("displayName", this.modName);
177 177 this.version = this.getMetaValue("version", "Unknown");
178 178 this.author = this.getMetaValue("author", "Unknown");
179 179  
... ...
java/common/com/mumfrey/liteloader/interfaces/LoaderEnumerator.java
... ... @@ -85,6 +85,11 @@ public interface LoaderEnumerator extends ModularEnumerator
85 85 public abstract Collection<? extends ModInfo<Loadable<?>>> getDisabledContainers();
86 86  
87 87 /**
  88 + * Get all bad containers
  89 + */
  90 + public abstract Collection<? extends ModInfo<Loadable<?>>> getBadContainers();
  91 +
  92 + /**
88 93 * @param modClass
89 94 * @param metaDataKey
90 95 * @param defaultValue
... ...
java/common/com/mumfrey/liteloader/interfaces/ModularEnumerator.java
... ... @@ -23,6 +23,12 @@ public interface ModularEnumerator
23 23 * @param container
24 24 */
25 25 public abstract boolean registerModContainer(LoadableMod<?> container);
  26 +
  27 + /**
  28 + * @param container
  29 + * @param reason
  30 + */
  31 + public abstract void registerBadContainer(Loadable<?> container, String reason);
26 32  
27 33 /**
28 34 * @param container
... ...