ModList.java
9.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/*
* This file is part of LiteLoader.
* Copyright (C) 2012-16 Adam Mummery-Smith
* All Rights Reserved.
*/
package com.mumfrey.liteloader.client.gui.modlist;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.lwjgl.input.Keyboard;
import com.mumfrey.liteloader.LiteMod;
import com.mumfrey.liteloader.api.ModInfoDecorator;
import com.mumfrey.liteloader.client.gui.GuiLiteLoaderPanel;
import com.mumfrey.liteloader.core.EnabledModsList.Enabled;
import com.mumfrey.liteloader.core.LiteLoaderMods;
import com.mumfrey.liteloader.core.ModInfo;
import com.mumfrey.liteloader.interfaces.Loadable;
import com.mumfrey.liteloader.interfaces.LoadableMod;
import com.mumfrey.liteloader.launch.LoaderEnvironment;
import com.mumfrey.liteloader.modconfig.ConfigManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.I18n;
public class ModList
{
private final ModListContainer container;
private final ConfigManager configManager;
/**
* List of enumerated mods
*/
private final List<ModListEntry> mods = new ArrayList<ModListEntry>();
/**
* Currently selected mod
*/
private ModListEntry selectedMod = null;
private boolean hasConfig = false;
public ModList(ModListContainer container, Minecraft minecraft, LiteLoaderMods mods, LoaderEnvironment environment, ConfigManager configManager,
int brandColour, List<ModInfoDecorator> decorators)
{
this.container = container;
this.configManager = configManager;
this.populate(minecraft, mods, environment, brandColour, decorators);
}
/**
* @param minecraft
* @param mods
* @param environment
* @param brandColour
* @param decorators
*/
protected void populate(Minecraft minecraft, LiteLoaderMods mods, LoaderEnvironment environment, int brandColour,
List<ModInfoDecorator> decorators)
{
// Add mods to this treeset first, in order to sort them
Map<String, ModListEntry> sortedMods = new TreeMap<String, ModListEntry>();
// Active mods
for (ModInfo<LoadableMod<?>> mod : mods.getLoadedMods())
{
ModListEntry modListEntry = new ModListEntry(this, mods, environment, minecraft.fontRenderer, brandColour, decorators, mod);
sortedMods.put(modListEntry.getKey(), modListEntry);
}
// Disabled mods
for (ModInfo<?> disabledMod : mods.getDisabledMods())
{
if (environment.getEnabledModsList().getEnabled(environment.getProfile(), disabledMod.getIdentifier()) != Enabled.FILTERED)
{
ModListEntry modListEntry = new ModListEntry(this, mods, environment, minecraft.fontRenderer, brandColour, decorators, disabledMod);
sortedMods.put(modListEntry.getKey(), modListEntry);
}
}
// Show bad containers if no other containers are found, should help users realise they have the wrong mod version!
if (sortedMods.size() == 0)
{
for (ModInfo<?> badMod : mods.getBadContainers())
{
ModListEntry modListEntry = new ModListEntry(this, mods, environment, minecraft.fontRenderer, brandColour, decorators, badMod);
sortedMods.put(modListEntry.getKey(), modListEntry);
}
}
// Injected tweaks
for (ModInfo<Loadable<?>> injectedTweak : mods.getInjectedTweaks())
{
ModListEntry modListEntry = new ModListEntry(this, mods, environment, minecraft.fontRenderer, brandColour, decorators, injectedTweak);
sortedMods.put(modListEntry.getKey(), modListEntry);
}
// Add the sorted mods to the mods list
this.mods.addAll(sortedMods.values());
// Select the first mod in the list
if (this.mods.size() > 0)
{
this.selectedMod = this.mods.get(0);
}
}
public GuiLiteLoaderPanel getParentScreen()
{
return this.container.getParentScreen();
}
public LiteMod getSelectedModInstance()
{
return this.selectedMod != null ? this.selectedMod.getModInstance() : null;
}
public Class<? extends LiteMod> getSelectedModClass()
{
return this.selectedMod != null ? this.selectedMod.getModClass() : null;
}
public void setSize(int width, int height)
{
this.selectMod(this.selectedMod);
}
public void onTick()
{
for (ModListEntry mod : this.mods)
{
mod.onTick();
}
}
public void mousePressed(int mouseX, int mouseY, int mouseButton)
{
ModListEntry lastSelectedMod = this.selectedMod;
for (ModListEntry mod : this.mods)
{
mod.mousePressed(mouseX, mouseY, mouseButton);
}
if (this.selectedMod != null && this.selectedMod == lastSelectedMod)
{
this.selectedMod.getInfoPanel().mousePressed();
}
}
public boolean keyPressed(char keyChar, int keyCode)
{
if (keyCode == Keyboard.KEY_UP)
{
int selectedIndex = this.mods.indexOf(this.selectedMod) - 1;
if (selectedIndex > -1) this.selectMod(this.mods.get(selectedIndex));
this.scrollSelectedModIntoView();
return true;
}
else if (keyCode == Keyboard.KEY_DOWN)
{
int selectedIndex = this.mods.indexOf(this.selectedMod);
if (selectedIndex > -1 && selectedIndex < this.mods.size() - 1) this.selectMod(this.mods.get(selectedIndex + 1));
this.scrollSelectedModIntoView();
return true;
}
else if (keyCode == Keyboard.KEY_SPACE
|| keyCode == Keyboard.KEY_RETURN
|| keyCode == Keyboard.KEY_NUMPADENTER
|| keyCode == Keyboard.KEY_RIGHT)
{
this.toggleSelectedMod();
return true;
}
return false;
}
public void mouseReleased(int mouseX, int mouseY, int mouseButton)
{
if (this.selectedMod != null)
{
this.selectedMod.getInfoPanel().mouseReleased();
}
}
public boolean mouseWheelScrolled(int mouseWheelDelta)
{
return this.selectedMod != null && this.selectedMod.getInfoPanel().mouseWheelScrolled(mouseWheelDelta);
}
public int drawModList(int mouseX, int mouseY, float partialTicks, int left, int top, int width, int height)
{
this.drawModListPass(mouseX, mouseY, partialTicks, left, top, width, 0);
return this.drawModListPass(mouseX, mouseY, partialTicks, left, top, width, 1);
}
protected int drawModListPass(int mouseX, int mouseY, float partialTicks, int left, int top, int width, int pass)
{
int yPos = top;
for (ModListEntry mod : this.mods)
{
GuiModListPanel panel = mod.getListPanel();
if (panel.isVisible())
{
if (yPos > 0) yPos += panel.getSpacing();
panel.draw(mouseX, mouseY, partialTicks, left, yPos, width, mod == this.selectedMod, pass);
yPos += panel.getHeight();
}
}
return yPos;
}
public void drawModPanel(int mouseX, int mouseY, float partialTicks, int left, int top, int width, int height)
{
if (this.selectedMod != null)
{
this.selectedMod.getInfoPanel().draw(mouseX, mouseY, partialTicks, left, top, width, height);
}
}
/**
* @param mod Mod list entry to select
*/
void selectMod(ModListEntry mod)
{
if (this.selectedMod != null)
{
this.selectedMod.getInfoPanel().mouseReleased();
}
this.selectedMod = mod;
this.hasConfig = false;
this.container.setEnableButtonVisible(false);
this.container.setConfigButtonVisible(false);
if (this.selectedMod != null && this.selectedMod.canBeToggled())
{
this.container.setEnableButtonVisible(true);
this.container.setEnableButtonText(this.selectedMod.willBeEnabled() ? I18n.format("gui.disablemod") : I18n.format("gui.enablemod"));
this.hasConfig = this.configManager.hasPanel(this.selectedMod.getModClass());
this.container.setConfigButtonVisible(this.hasConfig);
}
}
/**
* Toggle the selected mod's enabled status
*/
public void toggleSelectedMod()
{
if (this.selectedMod != null)
{
this.selectedMod.toggleEnabled();
this.selectMod(this.selectedMod);
}
}
private void scrollSelectedModIntoView()
{
if (this.selectedMod == null) return;
int yPos = 0;
for (ModListEntry mod : this.mods)
{
if (mod == this.selectedMod) break;
yPos += mod.getListPanel().getTotalHeight();
}
int modHeight = this.selectedMod.getListPanel().getTotalHeight();
this.container.scrollTo(yPos, yPos + modHeight);
}
public void showConfig(ModListEntry modListEntry)
{
this.container.showConfig();
}
}