LiteLoaderPanelManager.java
9.28 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
283
package com.mumfrey.liteloader.client;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiIngameMenu;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.gui.GuiOptions;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
import org.lwjgl.input.Keyboard;
import com.mumfrey.liteloader.client.gui.GuiLiteLoaderPanel;
import com.mumfrey.liteloader.common.GameEngine;
import com.mumfrey.liteloader.core.LiteLoaderMods;
import com.mumfrey.liteloader.core.LiteLoaderUpdateSite;
import com.mumfrey.liteloader.core.LiteLoaderVersion;
import com.mumfrey.liteloader.interfaces.PanelManager;
import com.mumfrey.liteloader.launch.LoaderEnvironment;
import com.mumfrey.liteloader.launch.LoaderProperties;
import com.mumfrey.liteloader.modconfig.ConfigManager;
import com.mumfrey.liteloader.util.log.LiteLoaderLogger;
/**
* Observer which handles the display of the mod panel
*
* @author Adam Mummery-Smith
*/
public class LiteLoaderPanelManager implements PanelManager<GuiScreen>
{
private final LoaderEnvironment environment;
/**
* Loader Properties adapter
*/
private final LoaderProperties properties;
private LiteLoaderMods mods;
private ConfigManager configManager;
private Minecraft minecraft;
/**
* Setting which determines whether we show the "mod info" screen tab in the main menu
*/
private boolean displayModInfoScreenTab = true;
/**
* Don't hide t
*/
private boolean tabAlwaysExpanded = false;
/**
* Override for the "mod info" tab setting, so that mods which want to handle the mod info themselves
* can temporarily disable the function without having to change the underlying property
*/
private boolean hideModInfoScreenTab = false;
private boolean checkForUpdate = false;
private String notification;
/**
* Active "mod info" screen, drawn as an overlay when in the main menu and made the active screen if
* the user clicks the tab
*/
private GuiLiteLoaderPanel panelHost;
/**
* @param environment
* @param properties
*/
@SuppressWarnings("unchecked")
public LiteLoaderPanelManager(GameEngine<?, ?> engine, LoaderEnvironment environment, LoaderProperties properties)
{
this.environment = environment;
this.properties = properties;
this.minecraft = ((GameEngine<Minecraft, ?>)engine).getClient();
this.displayModInfoScreenTab = this.properties.getAndStoreBooleanProperty(LoaderProperties.OPTION_MOD_INFO_SCREEN, true);
this.tabAlwaysExpanded = this.properties.getAndStoreBooleanProperty(LoaderProperties.OPTION_NO_HIDE_TAB, false);
if (this.properties.getAndStoreBooleanProperty(LoaderProperties.OPTION_FORCE_UPDATE, false))
{
int updateCheckInterval = this.properties.getIntegerProperty(LoaderProperties.OPTION_UPDATE_CHECK_INTR) + 1;
LiteLoaderLogger.debug("Force update is TRUE, updateCheckInterval = %d", updateCheckInterval);
if (updateCheckInterval > 10)
{
LiteLoaderLogger.debug("Forcing update check!");
this.checkForUpdate = true;
updateCheckInterval = 0;
}
this.properties.setIntegerProperty(LoaderProperties.OPTION_UPDATE_CHECK_INTR, updateCheckInterval);
this.properties.writeProperties();
}
}
@Override
public void init(LiteLoaderMods mods, ConfigManager configManager)
{
this.mods = mods;
this.configManager = configManager;
}
@Override
public void onStartupComplete()
{
if (this.checkForUpdate)
{
LiteLoaderVersion.getUpdateSite().beginUpdateCheck();
}
}
/* (non-Javadoc)
* @see com.mumfrey.liteloader.api.TickObserver#onTick(boolean, float, boolean)
*/
@Override
public void onTick(boolean clock, float partialTicks, boolean inGame)
{
if (clock && this.panelHost != null && this.minecraft.currentScreen != this.panelHost)
{
this.panelHost.updateScreen();
}
if (clock && this.checkForUpdate)
{
LiteLoaderUpdateSite updateSite = LiteLoaderVersion.getUpdateSite();
if (!updateSite.isCheckInProgress() && updateSite.isCheckComplete())
{
LiteLoaderLogger.debug("Scheduled update check completed, success=%s", updateSite.isCheckSucceess());
this.checkForUpdate = false;
if (updateSite.isCheckSucceess() && updateSite.isUpdateAvailable())
{
this.setNotification(I18n.format("gui.notifications.updateavailable"));
}
}
}
}
/* (non-Javadoc)
* @see com.mumfrey.liteloader.api.PostRenderObserver#onPostRender(int, int, float)
*/
@Override
public void onPostRender(int mouseX, int mouseY, float partialTicks)
{
if (this.mods == null) return;
boolean tabHidden = this.isTabHidden() && this.minecraft.currentScreen instanceof GuiMainMenu;
if (this.isPanelSupportedOnScreen(this.minecraft.currentScreen) && ((this.displayModInfoScreenTab && !tabHidden) || (this.panelHost != null && this.panelHost.isOpen())))
{
// If we're at the main menu, prepare the overlay
if (this.panelHost == null || this.panelHost.getScreen() != this.minecraft.currentScreen)
{
this.panelHost = new GuiLiteLoaderPanel(this.minecraft, this.minecraft.currentScreen, this.mods, this.environment, this.properties, this.configManager, !tabHidden);
if (this.notification != null)
{
this.panelHost.setNotification(this.notification);
}
}
this.minecraft.entityRenderer.setupOverlayRendering();
this.panelHost.drawScreen(mouseX, mouseY, partialTicks, this.tabAlwaysExpanded);
}
else if (this.minecraft.currentScreen != this.panelHost && this.panelHost != null)
{
// If we're in any other screen, kill the overlay
this.panelHost.release();
this.panelHost = null;
}
else if (this.isPanelSupportedOnScreen(this.minecraft.currentScreen) && Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) && Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) && Keyboard.isKeyDown(Keyboard.KEY_TAB))
{
this.displayLiteLoaderPanel(this.minecraft.currentScreen);
}
}
/**
* Set the "mod info" screen tab to hidden, regardless of the property setting
*/
@Override
public void hideTab()
{
this.hideModInfoScreenTab = true;
}
private boolean isTabHidden()
{
return this.hideModInfoScreenTab && this.getStartupErrorCount() == 0 && this.notification == null;
}
/**
* Set whether the "mod info" screen tab should be shown in the main menu
*/
@Override
public void setTabVisible(boolean show)
{
this.displayModInfoScreenTab = show;
this.properties.setBooleanProperty(LoaderProperties.OPTION_MOD_INFO_SCREEN, show);
this.properties.writeProperties();
}
/**
* Get whether the "mod info" screen tab is shown in the main menu
*/
@Override
public boolean isTabVisible()
{
return this.displayModInfoScreenTab;
}
@Override
public void setTabAlwaysExpanded(boolean expand)
{
this.tabAlwaysExpanded = expand;
this.properties.setBooleanProperty(LoaderProperties.OPTION_NO_HIDE_TAB, expand);
this.properties.writeProperties();
}
@Override
public boolean isTabAlwaysExpanded()
{
return this.tabAlwaysExpanded;
}
@Override
public void setForceUpdateEnabled(boolean forceUpdate)
{
this.properties.setBooleanProperty(LoaderProperties.OPTION_FORCE_UPDATE, forceUpdate);
this.properties.writeProperties();
}
@Override
public boolean isForceUpdateEnabled()
{
return this.properties.getBooleanProperty(LoaderProperties.OPTION_FORCE_UPDATE);
}
/**
* Display the liteloader panel over the specified GUI
*
* @param parentScreen
*/
@Override
public void displayLiteLoaderPanel(GuiScreen parentScreen)
{
if (this.isPanelSupportedOnScreen(parentScreen))
{
this.panelHost = new GuiLiteLoaderPanel(this.minecraft, parentScreen, this.mods, this.environment, this.properties, this.configManager, !this.isTabHidden());
this.minecraft.displayGuiScreen(this.panelHost);
}
}
@Override
public int getStartupErrorCount()
{
return this.mods.getStartupErrorCount();
}
@Override
public int getCriticalErrorCount()
{
return this.mods.getCriticalErrorCount();
}
@Override
public void setNotification(String notification)
{
LiteLoaderLogger.debug("Setting notification: " + notification);
this.notification = notification;
if (this.panelHost != null)
{
this.panelHost.setNotification(notification);
}
}
private boolean isPanelSupportedOnScreen(GuiScreen guiScreen)
{
return (guiScreen instanceof GuiMainMenu || guiScreen instanceof GuiIngameMenu || guiScreen instanceof GuiOptions);
}
}