Commit 825f38a2c094298ed8da80387bcc07ce15ff3e7e
1 parent
267d4cea
Fix visual bug with disabled containers when using --mods, fixes #28
Showing
2 changed files
with
49 additions
and
15 deletions
src/client/java/com/mumfrey/liteloader/client/gui/modlist/ModList.java
@@ -15,6 +15,7 @@ import org.lwjgl.input.Keyboard; | @@ -15,6 +15,7 @@ import org.lwjgl.input.Keyboard; | ||
15 | import com.mumfrey.liteloader.LiteMod; | 15 | import com.mumfrey.liteloader.LiteMod; |
16 | import com.mumfrey.liteloader.api.ModInfoDecorator; | 16 | import com.mumfrey.liteloader.api.ModInfoDecorator; |
17 | import com.mumfrey.liteloader.client.gui.GuiLiteLoaderPanel; | 17 | import com.mumfrey.liteloader.client.gui.GuiLiteLoaderPanel; |
18 | +import com.mumfrey.liteloader.core.EnabledModsList.Enabled; | ||
18 | import com.mumfrey.liteloader.core.LiteLoaderMods; | 19 | import com.mumfrey.liteloader.core.LiteLoaderMods; |
19 | import com.mumfrey.liteloader.core.ModInfo; | 20 | import com.mumfrey.liteloader.core.ModInfo; |
20 | import com.mumfrey.liteloader.interfaces.Loadable; | 21 | import com.mumfrey.liteloader.interfaces.Loadable; |
@@ -75,9 +76,12 @@ public class ModList | @@ -75,9 +76,12 @@ public class ModList | ||
75 | // Disabled mods | 76 | // Disabled mods |
76 | for (ModInfo<?> disabledMod : mods.getDisabledMods()) | 77 | for (ModInfo<?> disabledMod : mods.getDisabledMods()) |
77 | { | 78 | { |
78 | - ModListEntry modListEntry = new ModListEntry(this, mods, environment, minecraft.fontRendererObj, brandColour, decorators, disabledMod); | 79 | + if (environment.getEnabledModsList().getEnabled(environment.getProfile(), disabledMod.getIdentifier()) == Enabled.DISABLED) |
80 | + { | ||
81 | + ModListEntry modListEntry = new ModListEntry(this, mods, environment, minecraft.fontRendererObj, brandColour, decorators, disabledMod); | ||
79 | sortedMods.put(modListEntry.getKey(), modListEntry); | 82 | sortedMods.put(modListEntry.getKey(), modListEntry); |
80 | } | 83 | } |
84 | + } | ||
81 | 85 | ||
82 | // Show bad containers if no other containers are found, should help users realise they have the wrong mod version! | 86 | // Show bad containers if no other containers are found, should help users realise they have the wrong mod version! |
83 | if (sortedMods.size() == 0) | 87 | if (sortedMods.size() == 0) |
src/main/java/com/mumfrey/liteloader/core/EnabledModsList.java
@@ -24,6 +24,34 @@ import com.google.gson.GsonBuilder; | @@ -24,6 +24,34 @@ import com.google.gson.GsonBuilder; | ||
24 | */ | 24 | */ |
25 | public final class EnabledModsList | 25 | public final class EnabledModsList |
26 | { | 26 | { |
27 | + /** | ||
28 | + * Tristate for enablement which allows us to determine whether mod is | ||
29 | + * forcibly disabled by user or passively disabled by mod name filter | ||
30 | + */ | ||
31 | + public enum Enabled | ||
32 | + { | ||
33 | + ENABLED(true), | ||
34 | + DISABLED(false), | ||
35 | + FILTERED(false); | ||
36 | + | ||
37 | + private final boolean value; | ||
38 | + | ||
39 | + private Enabled(boolean value) | ||
40 | + { | ||
41 | + this.value = value; | ||
42 | + } | ||
43 | + | ||
44 | + public boolean booleanValue() | ||
45 | + { | ||
46 | + return this.value; | ||
47 | + } | ||
48 | + | ||
49 | + public static Enabled of(Boolean value) | ||
50 | + { | ||
51 | + return value == null ? Enabled.FILTERED : (value ? Enabled.ENABLED : Enabled.DISABLED); | ||
52 | + } | ||
53 | + } | ||
54 | + | ||
27 | @SuppressWarnings("unused") | 55 | @SuppressWarnings("unused") |
28 | private static final transient long serialVersionUID = -6449451105617763769L; | 56 | private static final transient long serialVersionUID = -6449451105617763769L; |
29 | 57 | ||
@@ -45,7 +73,7 @@ public final class EnabledModsList | @@ -45,7 +73,7 @@ public final class EnabledModsList | ||
45 | * the mods list because the command line is supposed to be an override | 73 | * the mods list because the command line is supposed to be an override |
46 | * rather than a new mask. These two values provide this behaviour. | 74 | * rather than a new mask. These two values provide this behaviour. |
47 | */ | 75 | */ |
48 | - private transient Boolean defaultEnabledValue = Boolean.TRUE; | 76 | + private transient Enabled defaultEnabledValue = Enabled.ENABLED; |
49 | private transient boolean allowSave = true; | 77 | private transient boolean allowSave = true; |
50 | 78 | ||
51 | /** | 79 | /** |
@@ -59,22 +87,27 @@ public final class EnabledModsList | @@ -59,22 +87,27 @@ public final class EnabledModsList | ||
59 | } | 87 | } |
60 | 88 | ||
61 | /** | 89 | /** |
62 | - * Check whether a particular mod is enabled | 90 | + * Check whether a particular container is enabled |
63 | * | 91 | * |
64 | * @param profileName | 92 | * @param profileName |
65 | * @param identifier | 93 | * @param identifier |
66 | */ | 94 | */ |
67 | public boolean isEnabled(String profileName, String identifier) | 95 | public boolean isEnabled(String profileName, String identifier) |
68 | { | 96 | { |
97 | + return this.getEnabled(profileName, identifier).booleanValue(); | ||
98 | + } | ||
99 | + | ||
100 | + public Enabled getEnabled(String profileName, String identifier) | ||
101 | + { | ||
69 | Map<String, Boolean> profile = this.getProfile(profileName); | 102 | Map<String, Boolean> profile = this.getProfile(profileName); |
70 | identifier = identifier.toLowerCase().trim(); | 103 | identifier = identifier.toLowerCase().trim(); |
71 | 104 | ||
72 | - if (!profile.containsKey(identifier)) | 105 | + if (!profile.containsKey(identifier) && this.defaultEnabledValue != Enabled.FILTERED) |
73 | { | 106 | { |
74 | - profile.put(identifier, this.defaultEnabledValue); | 107 | + profile.put(identifier, this.defaultEnabledValue.booleanValue()); |
75 | } | 108 | } |
76 | 109 | ||
77 | - return profile.get(identifier); | 110 | + return Enabled.of(profile.get(identifier)); |
78 | } | 111 | } |
79 | 112 | ||
80 | /** | 113 | /** |
@@ -87,7 +120,7 @@ public final class EnabledModsList | @@ -87,7 +120,7 @@ public final class EnabledModsList | ||
87 | public void setEnabled(String profileName, String identifier, boolean enabled) | 120 | public void setEnabled(String profileName, String identifier, boolean enabled) |
88 | { | 121 | { |
89 | Map<String, Boolean> profile = this.getProfile(profileName); | 122 | Map<String, Boolean> profile = this.getProfile(profileName); |
90 | - profile.put(identifier.toLowerCase().trim(), Boolean.valueOf(enabled)); | 123 | + profile.put(identifier.toLowerCase().trim(), enabled ? Boolean.TRUE : Boolean.FALSE); |
91 | 124 | ||
92 | this.allowSave = true; | 125 | this.allowSave = true; |
93 | } | 126 | } |
@@ -106,12 +139,9 @@ public final class EnabledModsList | @@ -106,12 +139,9 @@ public final class EnabledModsList | ||
106 | { | 139 | { |
107 | if (modNameFilter != null) | 140 | if (modNameFilter != null) |
108 | { | 141 | { |
109 | - for (String modName : profile.keySet()) | ||
110 | - { | ||
111 | - profile.put(modName, Boolean.FALSE); | ||
112 | - } | 142 | + profile.clear(); |
113 | 143 | ||
114 | - this.defaultEnabledValue = Boolean.FALSE; | 144 | + this.defaultEnabledValue = Enabled.FILTERED; |
115 | this.allowSave = false; | 145 | this.allowSave = false; |
116 | 146 | ||
117 | for (String filterEntry : modNameFilter) | 147 | for (String filterEntry : modNameFilter) |
@@ -122,8 +152,8 @@ public final class EnabledModsList | @@ -122,8 +152,8 @@ public final class EnabledModsList | ||
122 | } | 152 | } |
123 | catch (Exception ex) | 153 | catch (Exception ex) |
124 | { | 154 | { |
125 | - this.defaultEnabledValue = Boolean.TRUE; | ||
126 | - this.allowSave = true; | 155 | + this.defaultEnabledValue = Enabled.ENABLED; |
156 | +// this.allowSave = true; | ||
127 | } | 157 | } |
128 | } | 158 | } |
129 | 159 | ||
@@ -135,7 +165,7 @@ public final class EnabledModsList | @@ -135,7 +165,7 @@ public final class EnabledModsList | ||
135 | private Map<String, Boolean> getProfile(String profileName) | 165 | private Map<String, Boolean> getProfile(String profileName) |
136 | { | 166 | { |
137 | if (profileName == null) profileName = "default"; | 167 | if (profileName == null) profileName = "default"; |
138 | - if (this.mods == null) this.mods = new TreeMap<String, TreeMap<String,Boolean>>(); | 168 | + if (this.mods == null) this.mods = new TreeMap<String, TreeMap<String, Boolean>>(); |
139 | 169 | ||
140 | if (!this.mods.containsKey(profileName)) | 170 | if (!this.mods.containsKey(profileName)) |
141 | { | 171 | { |