Added AND finished successfully the work on the config file. Perfect with comments and stuff and a in-game config pane. that's a new feature. that's so cool!
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
package de.skate702.craftingkeys.config;
|
||||
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
/**
|
||||
* Configuration Management for Keys, etc.
|
||||
*/
|
||||
public class Config {
|
||||
|
||||
|
||||
/**
|
||||
* Defines the config string for the keys-category.
|
||||
*/
|
||||
public static final String categoryKeys = "keys";
|
||||
|
||||
/**
|
||||
* Defines the config string for the other-category.
|
||||
*/
|
||||
public static final String categoryOther = "other";
|
||||
/**
|
||||
* Defines all 11 Keys you can use with Crafting Keys.
|
||||
*/
|
||||
public static Property keyTopLeft, keyTopCenter, keyTopRight,
|
||||
keyCenterLeft, keyCenterCenter, keyCenterRight,
|
||||
keyLowerLeft, keyLowerCenter, keyLowerRight,
|
||||
keyStack, keyInteract;
|
||||
/**
|
||||
* Defines, if NumPad is always active for crafting.
|
||||
*/
|
||||
public static Property enableNumPad;
|
||||
|
||||
/**
|
||||
* Provides the Suggested Config File.
|
||||
*/
|
||||
public static Configuration configFile;
|
||||
|
||||
/**
|
||||
* Initializes the configFile Files, loads all values (or sets them to default).
|
||||
*
|
||||
* @param event PreInitEvent from Main Class
|
||||
*/
|
||||
public static void loadConfig(FMLPreInitializationEvent event) {
|
||||
|
||||
configFile = new Configuration(event.getSuggestedConfigurationFile());
|
||||
|
||||
configFile.load();
|
||||
|
||||
genComments();
|
||||
|
||||
syncConfig();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Syncs and saves the configFile file.
|
||||
*/
|
||||
public static void syncConfig() {
|
||||
|
||||
syncProperties();
|
||||
|
||||
if (configFile.hasChanged())
|
||||
configFile.save();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates comments for easier understanding of the categories.
|
||||
*
|
||||
* @param config Mod related Configuration File
|
||||
*/
|
||||
private static void genComments() {
|
||||
|
||||
configFile.addCustomCategoryComment(categoryKeys, "Keyboard codes based on http://minecraft.gamepedia.com/Key_codes");
|
||||
configFile.addCustomCategoryComment(categoryOther, "Other settings which have effects @ crafting keys");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all properties from the configFile file.
|
||||
*
|
||||
* @param config Mod related Configuration File
|
||||
*/
|
||||
private static void syncProperties() {
|
||||
|
||||
// Standart Keys
|
||||
|
||||
keyTopLeft = configFile.get(categoryKeys, "1. Top Left", Keyboard.KEY_Q, "Top Left crafting key (key value)");
|
||||
keyTopCenter = configFile.get(categoryKeys, "2. Top Center", Keyboard.KEY_W, "Top Center crafting key (key value)");
|
||||
keyTopRight = configFile.get(categoryKeys, "3. Top Right", Keyboard.KEY_E, "Top Right crafting key (key value)");
|
||||
|
||||
keyCenterLeft = configFile.get(categoryKeys, "4. Center Left", Keyboard.KEY_A, "Center Left crafting key (key value)");
|
||||
keyCenterCenter = configFile.get(categoryKeys, "5. Center Center", Keyboard.KEY_S, "Center Center crafting key (key value)");
|
||||
keyCenterRight = configFile.get(categoryKeys, "6. Center Right", Keyboard.KEY_D, "Center Right crafting key (key value)");
|
||||
|
||||
keyLowerLeft = configFile.get(categoryKeys, "7. Lower Left", Keyboard.KEY_Y, "Lower Left crafting key (key value)"); // German Keyboard Layout
|
||||
keyLowerCenter = configFile.get(categoryKeys, "8. Lower Center", Keyboard.KEY_X, "Lower Center crafting key (key value)");
|
||||
keyLowerRight = configFile.get(categoryKeys, "9. Lower Right", Keyboard.KEY_C, "Lower Right crafting key (key value)");
|
||||
|
||||
// Special Keys
|
||||
|
||||
keyStack = configFile.get(categoryKeys, "Stack Key", Keyboard.KEY_LSHIFT, "Key to move stacks instead of single items");
|
||||
keyInteract = configFile.get(categoryKeys, "Interaction Key", Keyboard.KEY_LCONTROL, "Key to interact with e.g. crafting output");
|
||||
|
||||
// Other Settings
|
||||
|
||||
enableNumPad = configFile.get(categoryOther, "Enable Num Pad", true, "Activates the NumPad for crafting");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package de.skate702.craftingkeys.config;
|
||||
|
||||
import cpw.mods.fml.client.config.DummyConfigElement;
|
||||
import cpw.mods.fml.client.config.GuiConfig;
|
||||
import cpw.mods.fml.client.config.IConfigElement;
|
||||
import de.skate702.craftingkeys.CraftingKeys;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraftforge.common.config.ConfigElement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Custom Config Gui for Mod Options inside of Minecraft.
|
||||
*/
|
||||
public class ConfigGui extends GuiConfig {
|
||||
public ConfigGui(GuiScreen parent) {
|
||||
super(parent, getConfigElements(),
|
||||
CraftingKeys.MODID, false, false, CraftingKeys.NAME);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates Config Entires based on the main config file.
|
||||
*
|
||||
* @return A List of IConfigElement-Items, ready to add to the gui.
|
||||
*/
|
||||
private static List<IConfigElement> getConfigElements() {
|
||||
List<IConfigElement> list = new ArrayList<IConfigElement>();
|
||||
|
||||
list.add(categoryElement(Config.categoryKeys, Config.categoryKeys, "de.skate702.craftingkeys.keys"));
|
||||
list.add(categoryElement(Config.categoryOther, Config.categoryOther, "de.skate702.craftingkeys.other"));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatically generates category elements for config categories.
|
||||
*
|
||||
* @param category the given category string (from the config file)
|
||||
* @param name the name of the category
|
||||
* @param tooltip_key a lang-string, must have tooltip available under .tooltip
|
||||
* @return Returns a IConfigElement ready to add to the list of elements
|
||||
*/
|
||||
private static IConfigElement categoryElement(String category, String name, String tooltip_key) {
|
||||
return new DummyConfigElement.DummyCategoryElement(name, tooltip_key,
|
||||
new ConfigElement<java.util.List<cpw.mods.fml.client.config.IConfigElement>>
|
||||
(Config.configFile.getCategory(category)).getChildElements());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package de.skate702.craftingkeys.config;
|
||||
|
||||
import cpw.mods.fml.client.IModGuiFactory;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A Config Gui Factory which always returns the ConfigGUI-Class. Nothing more to see here, go away!
|
||||
*/
|
||||
public class ConfigGuiFactory implements IModGuiFactory {
|
||||
@Override
|
||||
public void initialize(Minecraft minecraftInstance) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends GuiScreen> mainConfigGuiClass() {
|
||||
return ConfigGui.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user