Added config and GuiConfig
This commit is contained in:
parent
b3d6ea1358
commit
a054ac6eba
8 changed files with 242 additions and 19 deletions
61
src/main/java/techreborn/config/ConfigTechReborn.java
Normal file
61
src/main/java/techreborn/config/ConfigTechReborn.java
Normal file
|
@ -0,0 +1,61 @@
|
|||
package techreborn.config;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
|
||||
public class ConfigTechReborn {
|
||||
private static ConfigTechReborn instance = null;
|
||||
public static String CATEGORY_WORLD = "world";
|
||||
|
||||
//WORLDGEN
|
||||
public static boolean GalenaOreTrue;
|
||||
|
||||
public static Configuration config;
|
||||
|
||||
private ConfigTechReborn(File configFile)
|
||||
{
|
||||
config = new Configuration(configFile);
|
||||
config.load();
|
||||
|
||||
ConfigTechReborn.Configs();
|
||||
|
||||
config.save();
|
||||
|
||||
}
|
||||
|
||||
public static ConfigTechReborn initialize(File configFile)
|
||||
{
|
||||
|
||||
if (instance == null)
|
||||
instance = new ConfigTechReborn(configFile);
|
||||
else
|
||||
throw new IllegalStateException(
|
||||
"Cannot initialize TechReborn Config twice");
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static ConfigTechReborn instance()
|
||||
{
|
||||
if (instance == null) {
|
||||
|
||||
throw new IllegalStateException(
|
||||
"Instance of TechReborn Config requested before initialization");
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static void Configs()
|
||||
{
|
||||
GalenaOreTrue = config.get(CATEGORY_WORLD,
|
||||
"Allow GalenaOre", true,
|
||||
"Allow GalenaOre to be generated in your world.")
|
||||
.getBoolean(true);
|
||||
|
||||
if (config.hasChanged())
|
||||
config.save();
|
||||
}
|
||||
|
||||
|
||||
}
|
78
src/main/java/techreborn/config/TechRebornConfigGui.java
Normal file
78
src/main/java/techreborn/config/TechRebornConfigGui.java
Normal file
|
@ -0,0 +1,78 @@
|
|||
package techreborn.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraftforge.common.config.ConfigElement;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import cpw.mods.fml.client.config.DummyConfigElement;
|
||||
import cpw.mods.fml.client.config.GuiConfig;
|
||||
import cpw.mods.fml.client.config.GuiConfigEntries;
|
||||
import cpw.mods.fml.client.config.IConfigElement;
|
||||
import cpw.mods.fml.client.config.GuiConfigEntries.CategoryEntry;
|
||||
|
||||
public class TechRebornConfigGui extends GuiConfig{
|
||||
public TechRebornConfigGui(GuiScreen top)
|
||||
{
|
||||
super(top, getConfigCategories(), "TechReborn", false, false,
|
||||
GuiConfig.getAbridgedConfigPath(ConfigTechReborn.config
|
||||
.toString()));
|
||||
}
|
||||
|
||||
private static List<IConfigElement> getConfigCategories()
|
||||
{
|
||||
List<IConfigElement> list = new ArrayList<IConfigElement>();
|
||||
list.add(new DummyConfigElement.DummyCategoryElement("General",
|
||||
"tr.configgui.category.trGeneral", TRGeneral.class));
|
||||
list.add(new DummyConfigElement.DummyCategoryElement("World Gen",
|
||||
"tr.configgui.category.trWorld", TRWORLD.class));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public static class TRGeneral extends CategoryEntry {
|
||||
|
||||
public TRGeneral(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement configElement)
|
||||
{
|
||||
super(owningScreen, owningEntryList, configElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiScreen buildChildScreen()
|
||||
{
|
||||
return new GuiConfig(this.owningScreen,
|
||||
(new ConfigElement(ConfigTechReborn.config
|
||||
.getCategory(Configuration.CATEGORY_GENERAL)))
|
||||
.getChildElements(), this.owningScreen.modID,
|
||||
Configuration.CATEGORY_GENERAL,
|
||||
this.configElement.requiresWorldRestart()|| this.owningScreen.allRequireWorldRestart,
|
||||
this.configElement.requiresMcRestart()|| this.owningScreen.allRequireMcRestart,
|
||||
GuiConfig.getAbridgedConfigPath(ConfigTechReborn.config.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
// World
|
||||
public static class TRWORLD extends CategoryEntry {
|
||||
public TRWORLD(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement configElement)
|
||||
{
|
||||
super(owningScreen, owningEntryList, configElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiScreen buildChildScreen()
|
||||
{
|
||||
return new GuiConfig(this.owningScreen,
|
||||
(new ConfigElement(ConfigTechReborn.config
|
||||
.getCategory(ConfigTechReborn.CATEGORY_WORLD)))
|
||||
.getChildElements(), this.owningScreen.modID,
|
||||
Configuration.CATEGORY_GENERAL,
|
||||
this.configElement.requiresWorldRestart()
|
||||
|| this.owningScreen.allRequireWorldRestart,
|
||||
this.configElement.requiresMcRestart()
|
||||
|| this.owningScreen.allRequireMcRestart,
|
||||
GuiConfig.getAbridgedConfigPath(ConfigTechReborn.config
|
||||
.toString()));
|
||||
}
|
||||
}
|
||||
}
|
37
src/main/java/techreborn/config/TechRebornGUIFactory.java
Normal file
37
src/main/java/techreborn/config/TechRebornGUIFactory.java
Normal file
|
@ -0,0 +1,37 @@
|
|||
package techreborn.config;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import cpw.mods.fml.client.IModGuiFactory;
|
||||
import cpw.mods.fml.client.IModGuiFactory.RuntimeOptionCategoryElement;
|
||||
import cpw.mods.fml.client.IModGuiFactory.RuntimeOptionGuiHandler;
|
||||
|
||||
public class TechRebornGUIFactory implements IModGuiFactory{
|
||||
@Override
|
||||
public void initialize(Minecraft minecraftInstance)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends GuiScreen> mainConfigGuiClass()
|
||||
{
|
||||
return TechRebornConfigGui.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuntimeOptionGuiHandler getHandlerFor(
|
||||
RuntimeOptionCategoryElement element)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue