Config GUIs are cool.

This commit is contained in:
Ben Spiers 2014-06-27 03:22:46 +01:00
parent ac223c8df5
commit ff1b3b792e
11 changed files with 279 additions and 9 deletions

View file

@ -156,9 +156,7 @@ import cpw.mods.fml.relauncher.SideOnly;
public class ClientProxy extends CommonProxy
{
public static int MACHINE_RENDER_ID = RenderingRegistry.getNextAvailableRenderId();
public static int TRANSMITTER_RENDER_ID = RenderingRegistry.getNextAvailableRenderId();
public static int BASIC_RENDER_ID = RenderingRegistry.getNextAvailableRenderId();
public static int PLASTIC_RENDER_ID = RenderingRegistry.getNextAvailableRenderId();
@Override
public void loadConfiguration()

View file

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

View file

@ -0,0 +1,66 @@
package mekanism.client.gui;
import java.util.ArrayList;
import java.util.List;
import mekanism.common.Mekanism;
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.DummyCategoryElement;
import cpw.mods.fml.client.config.GuiConfig;
import cpw.mods.fml.client.config.GuiConfigEntries;
import cpw.mods.fml.client.config.GuiConfigEntries.CategoryEntry;
import cpw.mods.fml.client.config.IConfigElement;
public class GuiMekanismConfig extends GuiConfig
{
public GuiMekanismConfig(GuiScreen parent)
{
super(parent, getConfigElements(),
"Mekanism", false, false, GuiConfig.getAbridgedConfigPath(Mekanism.configuration.toString()));
}
private static List<IConfigElement> getConfigElements()
{
List<IConfigElement> list = new ArrayList<IConfigElement>();
list.add(new DummyCategoryElement("Mekanism General Settings", "mekanism.configgui.ctgy.general", GeneralEntry.class));
list.add(new DummyCategoryElement("Usage Settings", "mekanism.configgui.ctgy.usage", UsageEntry.class));
return list;
}
public static class GeneralEntry extends CategoryEntry
{
public GeneralEntry(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement prop)
{
super(owningScreen, owningEntryList, prop);
}
@Override
protected GuiScreen buildChildScreen()
{
return new GuiConfig(this.owningScreen,
new ConfigElement(Mekanism.configuration.getCategory(Configuration.CATEGORY_GENERAL)).getChildElements(),
this.owningScreen.modID, Configuration.CATEGORY_GENERAL, false, false,
GuiConfig.getAbridgedConfigPath(Mekanism.configuration.toString()));
}
}
public static class UsageEntry extends CategoryEntry
{
public UsageEntry(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement prop)
{
super(owningScreen, owningEntryList, prop);
}
@Override
protected GuiScreen buildChildScreen()
{
return new GuiConfig(this.owningScreen,
new ConfigElement(Mekanism.configuration.getCategory("usage")).getChildElements(),
this.owningScreen.modID, Configuration.CATEGORY_GENERAL, false, false,
GuiConfig.getAbridgedConfigPath(Mekanism.configuration.toString()));
}
}
}

View file

@ -133,6 +133,8 @@ import org.apache.logging.log4j.Logger;
import rebelkeithy.mods.metallurgy.api.IOreInfo;
import rebelkeithy.mods.metallurgy.api.MetallurgyAPI;
import codechicken.multipart.handler.MultipartProxy;
import cpw.mods.fml.client.event.ConfigChangedEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.IFuelHandler;
import cpw.mods.fml.common.Mod;
@ -154,7 +156,7 @@ import cpw.mods.fml.common.registry.GameRegistry;
* @author AidanBrady
*
*/
@Mod(modid = "Mekanism", name = "Mekanism", version = "7.0.0")
@Mod(modid = "Mekanism", name = "Mekanism", version = "7.0.0", guiFactory = "mekanism.client.gui.ConfigGuiFactory")
public class Mekanism
{
/** Mekanism Packet Pipeline */
@ -892,7 +894,6 @@ public class Mekanism
public void addItems()
{
//Declarations
configuration.load();
PartTransmitter = new ItemPartTransmitter().setUnlocalizedName("MultipartTransmitter");
EnrichedAlloy = new ItemMekanism().setUnlocalizedName("EnrichedAlloy");
EnrichedIron = new ItemMekanism().setUnlocalizedName("EnrichedIron");
@ -936,8 +937,6 @@ public class Mekanism
BioFuel = new ItemMekanism().setUnlocalizedName("BioFuel");
GlowPanel = new ItemGlowPanel().setUnlocalizedName("GlowPanel");
configuration.save();
//Fluid Container stuff
FluidContainerRegistry.registerFluidContainer(FluidRegistry.getFluid("brine"), new ItemStack(BrineBucket), FluidContainerRegistry.EMPTY_BUCKET);
@ -1442,4 +1441,14 @@ public class Mekanism
}
}
}
@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event)
{
if(event.modID.equals("Mekanism") || event.modID.equals("MekanismGenerators") || event.modID.equals("MekanismTools"))
{
proxy.loadConfiguration();
proxy.onConfigSync();
}
}
}

View file

@ -22,7 +22,6 @@ import mekanism.common.util.MekanismUtils;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import cpw.mods.fml.common.Optional.Interface;
import cpw.mods.fml.common.Optional.InterfaceList;
import cpw.mods.fml.common.Optional.Method;
import dan200.computercraft.api.peripheral.IComputerAccess;

View file

@ -0,0 +1,36 @@
package mekanism.generators.client.gui;
import java.util.Set;
import mekanism.client.gui.GuiMekanismConfig;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import cpw.mods.fml.client.IModGuiFactory;
public class GeneratorsGuiFactory implements IModGuiFactory
{
@Override
public void initialize(Minecraft minecraftInstance)
{
}
@Override
public Class<? extends GuiScreen> mainConfigGuiClass()
{
return GuiGeneratorsConfig.class;
}
@Override
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories()
{
return null;
}
@Override
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element)
{
return null;
}
}

View file

@ -0,0 +1,21 @@
package mekanism.generators.client.gui;
import mekanism.common.Mekanism;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.common.config.ConfigElement;
import net.minecraftforge.common.config.Configuration;
import cpw.mods.fml.client.config.GuiConfig;
/**
* Created by ben on 27/06/14.
*/
public class GuiGeneratorsConfig extends GuiConfig
{
public GuiGeneratorsConfig(GuiScreen parent)
{
super(parent, new ConfigElement(Mekanism.configuration.getCategory("generation")).getChildElements(),
"MekanismGenerators", false, false, GuiConfig.getAbridgedConfigPath(Mekanism.configuration.toString()));
}
}

View file

@ -35,7 +35,7 @@ import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
@Mod(modid = "MekanismGenerators", name = "MekanismGenerators", version = "7.0.0", dependencies = "required-after:Mekanism")
@Mod(modid = "MekanismGenerators", name = "MekanismGenerators", version = "7.0.0", dependencies = "required-after:Mekanism", guiFactory = "mekanism.generators.client.gui.GeneratorsGuiFactory")
public class MekanismGenerators implements IModule
{
@SidedProxy(clientSide = "mekanism.generators.client.GeneratorsClientProxy", serverSide = "mekanism.generators.common.GeneratorsCommonProxy")

View file

@ -0,0 +1,71 @@
package mekanism.tools.client.gui;
import java.util.ArrayList;
import java.util.List;
import mekanism.common.Mekanism;
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.DummyCategoryElement;
import cpw.mods.fml.client.config.GuiConfig;
import cpw.mods.fml.client.config.GuiConfigEntries;
import cpw.mods.fml.client.config.GuiConfigEntries.CategoryEntry;
import cpw.mods.fml.client.config.IConfigElement;
/**
* Created by ben on 27/06/14.
*/
public class GuiToolsConfig extends GuiConfig
{
public GuiToolsConfig(GuiScreen parent)
{
super(parent, getConfigElements(),
"Mekanism", false, false, GuiConfig.getAbridgedConfigPath(Mekanism.configuration.toString()));
}
private static List<IConfigElement> getConfigElements()
{
List<IConfigElement> list = new ArrayList<IConfigElement>();
list.add(new DummyCategoryElement("Armor Balance", "mekanism.configgui.ctgy.armor", ArmorEntry.class));
list.add(new DummyCategoryElement("Tools Balance", "mekanism.configgui.ctgy.tools", ToolsEntry.class));
return list;
}
public static class ArmorEntry extends CategoryEntry
{
public ArmorEntry(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement prop)
{
super(owningScreen, owningEntryList, prop);
}
@Override
protected GuiScreen buildChildScreen()
{
return new GuiConfig(this.owningScreen,
new ConfigElement(Mekanism.configuration.getCategory("armor-balance")).getChildElements(),
this.owningScreen.modID, Configuration.CATEGORY_GENERAL, this.configElement.requiresWorldRestart() || this.owningScreen.allRequireWorldRestart,
this.configElement.requiresMcRestart() || this.owningScreen.allRequireMcRestart,
GuiConfig.getAbridgedConfigPath(Mekanism.configuration.toString()));
}
}
public static class ToolsEntry extends CategoryEntry
{
public ToolsEntry(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement prop)
{
super(owningScreen, owningEntryList, prop);
}
@Override
protected GuiScreen buildChildScreen()
{
return new GuiConfig(this.owningScreen,
new ConfigElement(Mekanism.configuration.getCategory("tool-balance")).getChildElements(),
this.owningScreen.modID, Configuration.CATEGORY_GENERAL, this.configElement.requiresWorldRestart() || this.owningScreen.allRequireWorldRestart,
this.configElement.requiresMcRestart() || this.owningScreen.allRequireMcRestart,
GuiConfig.getAbridgedConfigPath(Mekanism.configuration.toString()));
}
}
}

View file

@ -0,0 +1,36 @@
package mekanism.tools.client.gui;
import java.util.Set;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import cpw.mods.fml.client.IModGuiFactory;
public class ToolsGuiFactory implements IModGuiFactory
{
@Override
public void initialize(Minecraft minecraftInstance)
{
}
@Override
public Class<? extends GuiScreen> mainConfigGuiClass()
{
return GuiToolsConfig.class;
}
@Override
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories()
{
return null;
}
@Override
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element)
{
return null;
}
}

View file

@ -33,7 +33,7 @@ import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.registry.GameRegistry;
@Mod(modid = "MekanismTools", name = "MekanismTools", version = "7.0.0", dependencies = "required-after:Mekanism")
@Mod(modid = "MekanismTools", name = "MekanismTools", version = "7.0.0", dependencies = "required-after:Mekanism", guiFactory = "mekanism.tools.client.gui.ToolsGuiFactory")
public class MekanismTools implements IModule
{
@SidedProxy(clientSide = "mekanism.tools.client.ToolsClientProxy", serverSide = "mekanism.tools.common.ToolsCommonProxy")