Added support for Forge in-game gui config.

This commit is contained in:
GirafiStudios 2016-02-07 19:09:23 +01:00
parent ad5d266950
commit bcd50892d9
6 changed files with 128 additions and 26 deletions

View file

@ -0,0 +1,36 @@
package biomesoplenty.client.gui;
import biomesoplenty.common.config.GameplayConfigurationHandler;
import biomesoplenty.common.config.MiscConfigurationHandler;
import biomesoplenty.core.BiomesOPlenty;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.common.config.ConfigElement;
import net.minecraftforge.fml.client.config.DummyConfigElement;
import net.minecraftforge.fml.client.config.GuiConfig;
import net.minecraftforge.fml.client.config.IConfigElement;
import java.util.ArrayList;
import java.util.List;
public class GuiBOPConfig extends GuiConfig
{
public GuiBOPConfig(GuiScreen parentScreen)
{
super(parentScreen, GuiBOPConfig.getConfigElements(), BiomesOPlenty.MOD_ID, false, false, "/biomesoplenty");
}
private static List<IConfigElement> getConfigElements()
{
List<IConfigElement> list = new ArrayList<IConfigElement>();
List<IConfigElement> convenienceSettings = new ConfigElement(GameplayConfigurationHandler.config.getCategory(GameplayConfigurationHandler.convenienceSettings.toLowerCase())).getChildElements();
List<IConfigElement> guiSettings = new ConfigElement(MiscConfigurationHandler.config.getCategory(MiscConfigurationHandler.guiSettings.toLowerCase())).getChildElements();
List<IConfigElement> textureSettings = new ConfigElement(MiscConfigurationHandler.config.getCategory(MiscConfigurationHandler.textureSettings.toLowerCase())).getChildElements();
list.add(new DummyConfigElement.DummyCategoryElement(GameplayConfigurationHandler.convenienceSettings, BiomesOPlenty.MOD_ID.toLowerCase() + ".config.category.convenienceSettings", convenienceSettings));
list.add(new DummyConfigElement.DummyCategoryElement(MiscConfigurationHandler.guiSettings, BiomesOPlenty.MOD_ID.toLowerCase() + ".config.category.guiSettings", guiSettings));
list.add(new DummyConfigElement.DummyCategoryElement(MiscConfigurationHandler.textureSettings, BiomesOPlenty.MOD_ID.toLowerCase() + ".config.category.textureSettings", textureSettings));
return list;
}
}

View file

@ -0,0 +1,25 @@
package biomesoplenty.client.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.fml.client.IModGuiFactory;
import java.util.Set;
public class GuiFactory implements IModGuiFactory {
@Override
public void initialize(Minecraft minecraftInstance) { }
@Override
public Class<? extends GuiScreen> mainConfigGuiClass()
{
return GuiBOPConfig.class;
}
@Override
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() { return null; }
@Override
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) { return null; }
}

View file

@ -7,26 +7,35 @@
******************************************************************************/
package biomesoplenty.common.config;
import java.io.File;
import biomesoplenty.core.BiomesOPlenty;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import java.io.File;
public class GameplayConfigurationHandler
{
public static Configuration config;
public static String convenienceSettings = "Convenience Settings";
public static boolean flowerDropsNeedShears;
public static void init(File configFile)
{
if (config == null)
{
config = new Configuration(configFile);
loadConfiguration();
}
}
private static void loadConfiguration()
{
try
{
config.load();
flowerDropsNeedShears = config.getBoolean("Flower Drops Need Shears", "Convenience Settings", false, "Require shears to be used to collect flower drops.");
flowerDropsNeedShears = config.getBoolean("Flower Drops Need Shears", convenienceSettings, false, "Require shears to be used to collect flower drops.");
}
catch (Exception e)
{
@ -37,4 +46,13 @@ public class GameplayConfigurationHandler
if (config.hasChanged()) config.save();
}
}
@SubscribeEvent
public void onConfigurationChangedEvent(ConfigChangedEvent.OnConfigChangedEvent event)
{
if (event.modID.equalsIgnoreCase(BiomesOPlenty.MOD_ID))
{
loadConfiguration();
}
}
}

View file

@ -8,20 +8,25 @@
package biomesoplenty.common.config;
import java.io.File;
import biomesoplenty.common.remote.TrailManager;
import biomesoplenty.common.remote.TrailManager.TrailVisibilityMode;
import biomesoplenty.common.util.entity.PlayerUtil;
import biomesoplenty.core.BiomesOPlenty;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import java.io.File;
public class MiscConfigurationHandler
{
public static Configuration config;
public static String guiSettings = "GUI Settings";
public static String textureSettings = "Texture Settings";
public static boolean useBoPWorldTypeDefault;
public static boolean overrideTitlePanorama;
public static boolean overrideForgeBuckets;
@ -30,17 +35,22 @@ public class MiscConfigurationHandler
public static TrailVisibilityMode trailVisbilityMode;
public static void init(File configFile)
{
if (config == null)
{
config = new Configuration(configFile);
loadConfiguration();
}
}
private static void loadConfiguration()
{
try
{
config.load();
//TODO: Make this default to true once all biomes have been implemented
useBoPWorldTypeDefault = config.getBoolean("Default to BoP World Type", "GUI Settings", false, "Use the Biomes O' Plenty World Type by default when selecting a world.");
overrideTitlePanorama = config.getBoolean("Enable Biomes O\' Plenty Main Menu Panorama", "Texture Settings", true, "Override the main menu panorama and use ours instead (It\'s nicer!)");
overrideForgeBuckets = config.getBoolean("Enable Biomes O\' Plenty Bucket Textures", "Texture Settings", true, "Override the Forge bucket texture and use ours instead (It\'s nicer!)");
useBoPWorldTypeDefault = config.getBoolean("Default to BoP World Type", guiSettings, false, "Use the Biomes O' Plenty World Type by default when selecting a world.");
overrideTitlePanorama = config.getBoolean("Enable Biomes O\' Plenty Main Menu Panorama", textureSettings, true, "Override the main menu panorama and use ours instead (It\'s nicer!)");
overrideForgeBuckets = config.getBoolean("Enable Biomes O\' Plenty Bucket Textures", textureSettings, true, "Override the Forge bucket texture and use ours instead (It\'s nicer!)");
//Client-side only options
if (FMLCommonHandler.instance().getSide() == Side.CLIENT)
@ -61,4 +71,13 @@ public class MiscConfigurationHandler
if (config.hasChanged()) config.save();
}
}
@SubscribeEvent
public void onConfigurationChangedEvent(ConfigChangedEvent.OnConfigChangedEvent event)
{
if (event.modID.equalsIgnoreCase(BiomesOPlenty.MOD_ID))
{
loadConfiguration();
}
}
}

View file

@ -8,16 +8,19 @@
package biomesoplenty.common.init;
import java.io.File;
import biomesoplenty.common.config.GameplayConfigurationHandler;
import biomesoplenty.common.config.MiscConfigurationHandler;
import net.minecraftforge.common.MinecraftForge;
import java.io.File;
public class ModConfiguration
{
public static void init(File configDirectory)
{
GameplayConfigurationHandler.init(new File(configDirectory, "gameplay.cfg"));
MinecraftForge.EVENT_BUS.register(new GameplayConfigurationHandler());
MiscConfigurationHandler.init(new File(configDirectory, "misc.cfg"));
MinecraftForge.EVENT_BUS.register(new MiscConfigurationHandler());
}
}

View file

@ -39,11 +39,12 @@ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
@Mod(modid = BiomesOPlenty.MOD_ID, name = BiomesOPlenty.MOD_NAME, dependencies = "required-after:Forge@[11.14.3.1468,)")
@Mod(modid = BiomesOPlenty.MOD_ID, name = BiomesOPlenty.MOD_NAME, dependencies = "required-after:Forge@[11.14.3.1468,)", guiFactory = BiomesOPlenty.GUI_FACTORY)
public class BiomesOPlenty
{
public static final String MOD_NAME = "Biomes O' Plenty";
public static final String MOD_ID = "BiomesOPlenty";
public static final String GUI_FACTORY = "biomesoplenty.client.gui.GuiFactory";
@Instance(MOD_ID)
public static BiomesOPlenty instance;