-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathCustomLoadingScreen.java
More file actions
299 lines (266 loc) · 12.4 KB
/
CustomLoadingScreen.java
File metadata and controls
299 lines (266 loc) · 12.4 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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
package alexiil.mc.mod.load;
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.Random;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLConstructionEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import alexiil.mc.mod.load.frame.FrameDisplayer;
import alexiil.mc.mod.load.render.MainSplashRenderer;
@Mod(
//
modid = Lib.Mod.ID, //
guiFactory = "alexiil.mc.mod.load.ConfigGuiFactory", //
acceptableRemoteVersions = "*", //
clientSideOnly = true//
)
public class CustomLoadingScreen {
public static final Configuration CONFIG;
private static final Property PROP_FRAME;
private static final Property PROP_USE_CUSTOM;
// private static final Property PROP_DARK_MODE;
private static final Property PROP_CONFIG;
private static final Property PROP_CONFIG_RANDOMS;
private static final Property PROP_WAIT;
private static final Property PROP_FPS_LIMIT;
private static final Property PROP_DEBUG_RESOURCE_LOADING;
public static final boolean shouldWait;
public static final boolean useFrame;
public static final boolean useCustom;
public static final boolean darkMode;
public static final boolean debugResourceLoading;
public static final String customConfigPath;
public static final int fpsLimit;
private static FrameDisplayer displayer;
static {
CONFIG = new Configuration(new File("./config/customloadingscreen.cfg"));
PROP_FRAME = CONFIG.get("general", "use_frame", false);
PROP_USE_CUSTOM = CONFIG.get("general", "use_custom", true);
PROP_CONFIG = CONFIG.get("general", "screen_config", "builtin/random");
PROP_CONFIG.setComment(
"Sets the config to use for the custom loading screen. Use 'builtin/random' for a random loading screen on each load."
+ "\nAlternatively you can prefix this with 'config/' to load from the 'config/customloadingscreen/' directory."
+ "\nOr you can use 'sample/slideshow' to display images from config/customloadingscreen/slideshow_#.png."
+ "\nOr you can set this to 'config/example' to use the default example config."
);
String[] defaultRandoms = { "sample/default", "sample/white", "sample/scrolling", "sample/panorama_lower" };
PROP_CONFIG_RANDOMS = CONFIG.get("general", "random_configs", defaultRandoms);
PROP_WAIT = CONFIG.get("general", "smooth_init", true);
PROP_WAIT.setComment(
"Sleep for a tiny amount of time each mod progress stage to make configs that rely on receiving all mod load stages work a bit better."
);
// PROP_DARK_MODE = CONFIG.get("general", "dark_mode", false);
// PROP_DARK_MODE.setComment("Use dark-mode for loading screens rather than light.");
darkMode = false;// PROP_DARK_MODE.getBoolean();
PROP_DEBUG_RESOURCE_LOADING = CONFIG.get("debug", "resource_loading", false);
debugResourceLoading = PROP_DEBUG_RESOURCE_LOADING.getBoolean();
PROP_FPS_LIMIT = CONFIG.get("general", "fps_limit", 75);
PROP_FPS_LIMIT.setComment(
"The maximum fps to target for the loading screen. The default is 75. Values between 2 and 300 are allowed."
);
PROP_FPS_LIMIT.setMinValue(2);
PROP_FPS_LIMIT.setMaxValue(300);
fpsLimit = Math.max(2, Math.min(300, PROP_FPS_LIMIT.getInt()));
useCustom = PROP_USE_CUSTOM.getBoolean();
String customName = PROP_CONFIG.getString();
if ("builtin/random".equals(customName)) {
String[] possible = PROP_CONFIG_RANDOMS.getStringList();
if (possible.length == 0) {
CLSLog.info("No randoms! Defaulting to sample/generic_error...");
customConfigPath = "sample/generic_error";
} else {
customConfigPath = possible[new Random().nextInt(possible.length)];
}
} else {
customConfigPath = customName == null ? "" : customName;
}
useFrame = PROP_FRAME.getBoolean();
if (useFrame) {
displayer = new FrameDisplayer();
displayer.start();
}
shouldWait = PROP_WAIT.getBoolean();
if (CONFIG.hasChanged()) {
CONFIG.save();
}
File clsRoot = new File("./config/customloadingscreen/");
if (!clsRoot.exists()) {
clsRoot.mkdir();
}
File clsExample = new File(clsRoot, "example.json");
if (!clsExample.exists()) {
try (OutputStream out = new FileOutputStream(clsExample)) {
BufferedOutputStream bos = new BufferedOutputStream(out);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(bos));
writeExampleCfg(bw);
bw.flush();
} catch (IOException e) {
CLSLog.warn("Failed to write the example config file!", e);
}
}
}
public static void finish() {
if (displayer != null) {
displayer.finish();
}
}
@EventHandler
public static void construct(FMLConstructionEvent event) {
ModLoadingListener.setup();
MainSplashRenderer.onReachConstruct();
}
@EventHandler
public static void preInit(FMLPreInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(CustomLoadingScreen.class);
}
@SubscribeEvent
public static void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) {
if (CONFIG.hasChanged()) {
CONFIG.save();
}
}
private static void ln(BufferedWriter bw, String str) throws IOException {
bw.write(str.replace('#', '"'));
bw.newLine();
}
private static void writeExampleCfg(BufferedWriter bw) throws IOException {
// Exploded copy of "sample/config/default.json"
ln(bw, "{");
ln(bw, " #renders#: [");
ln(bw, " {");
ln(bw, " #image#: {");
ln(bw, " #parent#: #builtin/panorama#,");
ln(bw, " #image#: #textures/gui/title/background/panorama_x.png#");
ln(bw, " }");
ln(bw, " },");
ln(bw, " {");
ln(bw, " #image#: {");
ln(bw, " #parent#: #builtin/image#,");
ln(bw, " #image#: #customloadingscreen:textures/generic/darkened_blur_horizontal_strip.png#,");
ln(bw, " #position_type#: #CENTER#,");
ln(bw, " #offset_pos#: #CENTER#,");
ln(bw, " #position#: {");
ln(bw, " #x#: #0#,");
ln(bw, " #y#: #0#,");
ln(bw, " #width#: #screen_width#,");
ln(bw, " #height#: #100#");
ln(bw, " },");
ln(bw, " #texture#: {");
ln(bw, " #x#: #0#,");
ln(bw, " #y#: #0#,");
ln(bw, " #width#: #1#,");
ln(bw, " #height#: #1#");
ln(bw, " }");
ln(bw, " }");
ln(bw, " },");
ln(bw, " {");
ln(bw, " #image#: {");
ln(bw, " #parent#:#builtin/image#,");
ln(bw, " #image#: #customloadingscreen:textures/progress_bars.png#,");
ln(bw, " #position_type#: #CENTER#,");
ln(bw, " #offset_pos#: #CENTER#,");
ln(bw, " #position#:{");
ln(bw, " #x#: #0#,");
ln(bw, " #y#:#20#,");
ln(bw, " #width#:#182 * 2#,");
ln(bw, " #height#:#20#");
ln(bw, " },");
ln(bw, " #texture#:{");
ln(bw, " #x#: #0#,");
ln(bw, " #y#: #70 / 256.0#,");
ln(bw, " #width#: #182 / 256.0#,");
ln(bw, " #height#: #10 / 256.0#");
ln(bw, " }");
ln(bw, " }");
ln(bw, " },");
ln(bw, " {");
ln(bw, " #image#: {");
ln(bw, " #parent#: #builtin/image#,");
ln(bw, " #image#: #customloadingscreen:textures/progress_bars.png#,");
ln(bw, " #position_type#: #CENTER#,");
ln(bw, " #offset_pos#: #CENTER#,");
ln(bw, " #position#:{");
ln(bw, " #x#:#percentage * 182 - 182#,");
ln(bw, " #y#:#20#,");
ln(bw, " #width#:#percentage * 182 * 2#,");
ln(bw, " #height#:#20#");
ln(bw, " },");
ln(bw, " #texture#:{");
ln(bw, " #x#:#0#,");
ln(bw, " #y#:#80 / 256.0#,");
ln(bw, " #width#: #percentage * 182 / 256.0#,");
ln(bw, " #height#:#10 / 256.0#");
ln(bw, " }");
ln(bw, " }");
ln(bw, " },");
ln(bw, " {");
ln(bw, " #image#: {");
ln(bw, " #parent#: #builtin/text#,");
ln(bw, " #image#: #textures/font/ascii.png#,");
ln(bw, " #position_type#: #CENTER#,");
ln(bw, " #offset_pos#: #CENTER#,");
ln(bw, " #text#: #is_reloading ? status : (status + ': ' + sub_status)#,");
ln(bw, " #position#: {");
ln(bw, " #x#: #0#,");
ln(bw, " #y#: #-20#,");
ln(bw, " #width#: #0#,");
ln(bw, " #height#: #0#");
ln(bw, " },");
ln(bw, " #colour#:#0xFF_FF_FF_FF#");
ln(bw, " }");
ln(bw, " },");
ln(bw, " {");
ln(bw, " #image#: {");
ln(bw, " #parent#: #builtin/text#,");
ln(bw, " #image#: #textures/font/ascii.png#,");
ln(bw, " #position_type#: #CENTER#,");
ln(bw, " #offset_pos#: #CENTER#,");
ln(bw, " #text#: #is_reloading ? sub_status : ''#,");
ln(bw, " #position#: {");
ln(bw, " #x#: #0#,");
ln(bw, " #y#: #0#,");
ln(bw, " #width#: #0#,");
ln(bw, " #height#: #0#");
ln(bw, " },");
ln(bw, " #colour#:#0xFF_FF_FF_FF#");
ln(bw, " }");
ln(bw, " },");
ln(bw, " {");
ln(bw, " #image#: {");
ln(bw, " #parent#: #builtin/text#,");
ln(bw, " #image#: #textures/font/ascii.png#,");
ln(bw, " #position_type#: #CENTER#,");
ln(bw, " #offset_pos#: #CENTER#,");
ln(bw, " #text#: #(floor(percentage * 100)) + '%'#,");
ln(bw, " #position#: {");
ln(bw, " #x#: #0#,");
ln(bw, " #y#: #-10#,");
ln(bw, " #width#: #0#,");
ln(bw, " #height#: #0#");
ln(bw, " },");
ln(bw, " #colour#:#0xFF_FF_FF_FF#");
ln(bw, " }");
ln(bw, " }");
ln(bw, " ],");
ln(bw, " #functions#:[");
ln(bw, " ],");
ln(bw, " #factories#:[");
ln(bw, " ],");
ln(bw, " #actions#:[");
ln(bw, " ],");
ln(bw, " #variables#:{");
ln(bw, " }");
ln(bw, "}");
}
}