From 626a192ce6dd86768109ecafe88fba60f154d5a7 Mon Sep 17 00:00:00 2001 From: RainWarrior Date: Sun, 26 Apr 2015 00:11:29 +0300 Subject: [PATCH] Loading screen: moved config file to the standard config directory; added the option to load textures from the custom resource pack --- .../cpw/mods/fml/client/SplashProgress.java | 155 ++++++++++++------ .../resources/assets/fml/splash.properties | 10 -- 2 files changed, 108 insertions(+), 57 deletions(-) delete mode 100644 fml/src/main/resources/assets/fml/splash.properties diff --git a/fml/src/main/java/cpw/mods/fml/client/SplashProgress.java b/fml/src/main/java/cpw/mods/fml/client/SplashProgress.java index defb8dfe75..2e6dd0e060 100644 --- a/fml/src/main/java/cpw/mods/fml/client/SplashProgress.java +++ b/fml/src/main/java/cpw/mods/fml/client/SplashProgress.java @@ -4,6 +4,9 @@ import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.opengl.GL12.*; import java.awt.image.BufferedImage; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.lang.Thread.UncaughtExceptionHandler; @@ -39,6 +42,7 @@ import org.lwjgl.util.glu.GLU; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.common.ICrashCallable; +import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.ProgressManager; import cpw.mods.fml.common.ProgressManager.ProgressBar; import cpw.mods.fml.common.asm.FMLSanityChecker; @@ -59,26 +63,97 @@ public class SplashProgress private static SplashFontRenderer fontRenderer; private static final IResourcePack mcPack = Minecraft.getMinecraft().mcDefaultResourcePack; - private static final IResourcePack fmlPack = createFmlResourcePack(); + private static final IResourcePack fmlPack = createResourcePack(FMLSanityChecker.fmlLocation); + private static IResourcePack miscPack; private static Texture fontTexture; private static Texture logoTexture; private static Texture forgeTexture; - private static ResourceLocation configLocation = new ResourceLocation("fml", "splash.properties"); - private static final Properties config = loadConfig(); + private static Properties config; - private static final boolean enabled = Boolean.parseBoolean(config.getProperty("enabled")) && ! FMLClientHandler.instance().hasOptifine(); - private static final boolean rotate = Boolean.parseBoolean(config.getProperty("rotate")); - private static final int logoOffset = getInt("logoOffset"); - private static final int backgroundColor = getInt("background"); - private static final int fontColor = getInt("font"); - private static final int barBorderColor = getInt("barBorder"); - private static final int barColor = getInt("bar"); - private static final int barBackgroundColor = getInt("barBackground"); + private static boolean enabled; + private static boolean rotate; + private static int logoOffset; + private static int backgroundColor; + private static int fontColor; + private static int barBorderColor; + private static int barColor; + private static int barBackgroundColor; + + private static String getString(String name, String def) + { + String value = config.getProperty(name, def); + config.setProperty(name, value); + return value; + } + + private static boolean getBool(String name, boolean def) + { + return Boolean.parseBoolean(getString(name, Boolean.toString(def))); + } + + private static int getInt(String name, int def) + { + return Integer.decode(getString(name, Integer.toString(def))); + } + + private static int getHex(String name, int def) + { + return Integer.decode(getString(name, "0x" + Integer.toString(def, 16).toUpperCase())); + } public static void start() { + File configFile = new File(Minecraft.getMinecraft().mcDataDir, "config/splash.properties"); + FileReader r = null; + config = new Properties(); + try + { + r = new FileReader(configFile); + config.load(r); + } + catch(IOException e) + { + FMLLog.info("Could not load splash.properties, will create a default one"); + } + finally + { + IOUtils.closeQuietly(r); + } + + enabled = getBool("enabled", true) && !FMLClientHandler.instance().hasOptifine(); + rotate = getBool("rotate", true); + logoOffset = getInt("logoOffset", 10); + backgroundColor = getHex("background", 0xFFFFFF); + fontColor = getHex("font", 0x000000); + barBorderColor = getHex("barBorder", 0xC0C0C0); + barColor = getHex("bar", 0xCB3D35); + barBackgroundColor = getHex("barBackground", 0xFFFFFF); + + final ResourceLocation fontLoc = new ResourceLocation(getString("fontTexture", "textures/font/ascii.png")); + final ResourceLocation logoLoc = new ResourceLocation(getString("logoTexture", "textures/gui/title/mojang.png")); + final ResourceLocation forgeLoc = new ResourceLocation(getString("forgeTexture", "fml:textures/gui/forge.png")); + + File miscPackFile = new File(Minecraft.getMinecraft().mcDataDir, getString("resourcePackPath", "resources")); + + FileWriter w = null; + try + { + w = new FileWriter(configFile); + config.store(w, "Splash screen properties"); + } + catch(IOException e) + { + FMLLog.log(Level.ERROR, e, "Could not save the splash.properties file"); + } + finally + { + IOUtils.closeQuietly(w); + } + + miscPack = createResourcePack(miscPackFile); + if(!enabled) return; // getting debug info out of the way, while we still can FMLCommonHandler.instance().registerCrashCallable(new ICrashCallable() @@ -121,9 +196,9 @@ public class SplashProgress public void run() { setGL(); - fontTexture = new Texture(mcPack, new ResourceLocation("textures/font/ascii.png")); - logoTexture = new Texture(mcPack, new ResourceLocation("textures/gui/title/mojang.png")); - forgeTexture = new Texture(fmlPack, new ResourceLocation(config.getProperty("forgeTexture"))); + fontTexture = new Texture(fontLoc); + logoTexture = new Texture(logoLoc); + forgeTexture = new Texture(forgeLoc); glEnable(GL_TEXTURE_2D); fontRenderer = new SplashFontRenderer(); glDisable(GL_TEXTURE_2D); @@ -409,44 +484,18 @@ public class SplashProgress } } - private static IResourcePack createFmlResourcePack() + private static IResourcePack createResourcePack(File file) { - if(FMLSanityChecker.fmlLocation.isDirectory()) + if(file.isDirectory()) { - return new FolderResourcePack(FMLSanityChecker.fmlLocation); + return new FolderResourcePack(file); } else { - return new FileResourcePack(FMLSanityChecker.fmlLocation); + return new FileResourcePack(file); } } - private static Properties loadConfig() - { - InputStream s = null; - try - { - s = fmlPack.getInputStream(configLocation); - Properties config = new Properties(); - config.load(s); - return config; - } - catch(IOException e) - { - e.printStackTrace(); - throw new RuntimeException(e); - } - finally - { - IOUtils.closeQuietly(s); - } - } - - private static int getInt(String name) - { - return Integer.decode(config.getProperty(name)); - } - private static final IntBuffer buf = BufferUtils.createIntBuffer(4 * 1024 * 1024); private static class Texture @@ -458,13 +507,13 @@ public class SplashProgress private final int frames; private final int size; - public Texture(IResourcePack pack, ResourceLocation location) + public Texture(ResourceLocation location) { InputStream s = null; try { this.location = location; - s = pack.getInputStream(location); + s = open(location); ImageInputStream stream = ImageIO.createImageInputStream(s); Iterator readers = ImageIO.getImageReaders(stream); if(!readers.hasNext()) throw new IOException("No suitable reader found for image" + location); @@ -493,7 +542,6 @@ public class SplashProgress { for(int j = 0; i * (size / width) + j < frames && j < size / width; j++) { - FMLLog.info("loc: %s, i: %s, j: %s, size: %s, width: %s, height: %s", location, i, j, size, width, height); buf.clear(); BufferedImage image = images[i * (size / width) + j]; for(int k = 0; k < height; k++) @@ -624,4 +672,17 @@ public class SplashProgress throw new IllegalStateException(where + ": " + GLU.gluErrorString(err)); } } + + private static InputStream open(ResourceLocation loc) throws IOException + { + if(miscPack.resourceExists(loc)) + { + return miscPack.getInputStream(loc); + } + else if(fmlPack.resourceExists(loc)) + { + return fmlPack.getInputStream(loc); + } + return mcPack.getInputStream(loc); + } } diff --git a/fml/src/main/resources/assets/fml/splash.properties b/fml/src/main/resources/assets/fml/splash.properties deleted file mode 100644 index 4cfb4f5d85..0000000000 --- a/fml/src/main/resources/assets/fml/splash.properties +++ /dev/null @@ -1,10 +0,0 @@ -enabled = true -rotate = true - -forgeTexture = fml:textures/gui/forge.png -logoOffset = 10 -background = 0xFFFFFF -font = 0x000000 -barBorder = 0xC0C0C0 -bar = 0xCB3D35 -barBackground = 0xFFFFFF