Merge pull request #660 from GirafiStudios/in-game-config
Added support for Forge in-game gui config. Closes #637
This commit is contained in:
commit
d583bfa00b
7 changed files with 136 additions and 26 deletions
37
src/main/java/biomesoplenty/client/gui/GuiBOPConfig.java
Normal file
37
src/main/java/biomesoplenty/client/gui/GuiBOPConfig.java
Normal file
|
@ -0,0 +1,37 @@
|
|||
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.minecraft.util.StatCollector;
|
||||
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(StatCollector.translateToLocal("config.category.convenienceSettings.title"), "config.category.convenienceSettings", convenienceSettings));
|
||||
list.add(new DummyConfigElement.DummyCategoryElement(StatCollector.translateToLocal("config.category.guiSettings.title"), "config.category.guiSettings", guiSettings));
|
||||
list.add(new DummyConfigElement.DummyCategoryElement(StatCollector.translateToLocal("config.category.textureSettings.title"), "config.category.textureSettings", textureSettings));
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
25
src/main/java/biomesoplenty/client/gui/GuiFactory.java
Normal file
25
src/main/java/biomesoplenty/client/gui/GuiFactory.java
Normal 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; }
|
||||
}
|
|
@ -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;
|
||||
|
||||
public class GameplayConfigurationHandler
|
||||
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)
|
||||
{
|
||||
config = new Configuration(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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,40 +8,50 @@
|
|||
|
||||
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;
|
||||
|
||||
|
||||
//Client-side only
|
||||
public static TrailVisibilityMode trailVisbilityMode;
|
||||
|
||||
public static void init(File configFile)
|
||||
{
|
||||
config = new Configuration(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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -39,12 +39,13 @@ 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;
|
||||
|
||||
|
|
|
@ -51,6 +51,13 @@ biome_finder.searching=Searching for %s
|
|||
biome_finder.found=Found %s!
|
||||
biome_finder.not_found=Not found, maybe %s is too far away
|
||||
|
||||
config.category.convenienceSettings.title=Convenience Settings
|
||||
config.category.guiSettings.title=GUI Settings
|
||||
config.category.textureSettings.title=Texture Settings
|
||||
config.category.convenienceSettings.tooltip=Require shears to be used to collect flower drops.
|
||||
config.category.guiSettings.tooltip=Use the Biomes O' Plenty World Type by default when selecting a world.
|
||||
config.category.textureSettings.tooltip=Override the Forge bucket texture and use ours instead (It's nicer!)
|
||||
|
||||
commands.biomesoplenty.usage=/biomesoplenty <tpbiome|biomename|stripchunk> [args]
|
||||
commands.biomesoplenty.biomename.usage=/biomesoplenty biomename [biomeId]
|
||||
commands.biomesoplenty.biomename.success=Biome ID %s is associated with %s
|
||||
|
|
Loading…
Reference in a new issue