diff --git a/src/main/java/de/skate702/craftingkeys/CraftingKeys.java b/src/main/java/de/skate702/craftingkeys/CraftingKeys.java index 1f4c465..7e31571 100644 --- a/src/main/java/de/skate702/craftingkeys/CraftingKeys.java +++ b/src/main/java/de/skate702/craftingkeys/CraftingKeys.java @@ -10,10 +10,13 @@ import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.InputEvent; import cpw.mods.fml.common.gameevent.TickEvent; import cpw.mods.fml.common.network.NetworkRegistry; import de.skate702.craftingkeys.config.Config; +import de.skate702.craftingkeys.config.GuiConfig; import de.skate702.craftingkeys.config.GuiConfigHandler; +import de.skate702.craftingkeys.config.KeyBindings; import de.skate702.craftingkeys.manager.*; import de.skate702.craftingkeys.proxies.CraftingKeysProxy; import de.skate702.craftingkeys.util.Logger; @@ -29,8 +32,7 @@ import net.minecraftforge.common.MinecraftForge; * * @author skate702 */ -@Mod(modid = CraftingKeys.MODID, name = CraftingKeys.NAME, version = CraftingKeys.VERSION, - guiFactory = "de.skate702.craftingkeys.config.ConfigGuiFactory") +@Mod(modid = CraftingKeys.MODID, name = CraftingKeys.NAME, version = CraftingKeys.VERSION) public class CraftingKeys { public static final String MODID = "craftingkeys"; @@ -74,6 +76,7 @@ public class CraftingKeys { FMLCommonHandler.instance().bus().register(this); MinecraftForge.EVENT_BUS.register(this); NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiConfigHandler()); + KeyBindings.init(); Logger.info("load(e)", "Registered Mod."); } @@ -87,6 +90,18 @@ public class CraftingKeys { public void postInit(FMLPostInitializationEvent event) { } + @SubscribeEvent + public void onKeyInput(InputEvent.KeyInputEvent event) { + if (KeyBindings.openGuiBinding.isPressed()) { + Logger.info("onKeyInput(e)", "Open Crafting Keys Config Gui."); + Util.client.thePlayer.openGui(instance, GuiConfig.GuiID, Util.client.theWorld, + ((int) Util.client.thePlayer.posX), (int) Util.client.thePlayer.posY, + (int) Util.client.thePlayer.posZ); + } + + + } + /** * This method will be executed when the Config is changed. Update! * @@ -108,7 +123,7 @@ public class CraftingKeys { @SubscribeEvent public void onGuiOpened(GuiOpenEvent event) { if (event.gui instanceof GuiMainMenu) { - //event.gui = new GuiConfig(); // Delete this! + //event.gui = new GuiConfig(); // (Only for testing) } } @@ -120,10 +135,6 @@ public class CraftingKeys { @SubscribeEvent public void onTick(TickEvent.ClientTickEvent tick) { - if (Util.client.currentScreen == null) { - Util.client.thePlayer.openGui(instance, 702, Util.client.theWorld, 0, 0, 0); - } - // Get current Screen, then test GuiScreen currentScreen = Util.client.currentScreen; diff --git a/src/main/java/de/skate702/craftingkeys/config/Config.java b/src/main/java/de/skate702/craftingkeys/config/Config.java index 6f54cbc..fca8ca4 100644 --- a/src/main/java/de/skate702/craftingkeys/config/Config.java +++ b/src/main/java/de/skate702/craftingkeys/config/Config.java @@ -146,40 +146,27 @@ public class Config { private static void syncProperties() { // Standard Keys - keyTopLeft = configFile.get(categoryKeys, "1.0-keyTopLeft", Keyboard.KEY_Q, "Top Left crafting key (key value)"); - keyTopLeft.setLanguageKey("key.topleft"); - keyTopCenter = configFile.get(categoryKeys, "1.1-2keyTopCenter", Keyboard.KEY_W, "Top Center crafting key (key value)"); - keyTopCenter.setLanguageKey("key.topcenter"); - keyTopRight = configFile.get(categoryKeys, "1.2-keyTopRight", Keyboard.KEY_E, "Top Right crafting key (key value)"); - keyTopRight.setLanguageKey("key.topright"); + keyTopLeft = configFile.get(categoryKeys, "keyTopLeft", Keyboard.KEY_Q); + keyTopCenter = configFile.get(categoryKeys, "keyTopCenter", Keyboard.KEY_W); + keyTopRight = configFile.get(categoryKeys, "keyTopRight", Keyboard.KEY_E); - keyCenterLeft = configFile.get(categoryKeys, "2.0-keyCenterLeft", Keyboard.KEY_A, "Center Left crafting key (key value)"); - keyCenterLeft.setLanguageKey("key.centerleft"); - keyCenterCenter = configFile.get(categoryKeys, "2.1-keyCenterCenter", Keyboard.KEY_S, "Center Center crafting key (key value)"); - keyCenterCenter.setLanguageKey("key.centercenter"); - keyCenterRight = configFile.get(categoryKeys, "2.2-keyCenterRight", Keyboard.KEY_D, "Center Right crafting key (key value)"); - keyCenterRight.setLanguageKey("key.centerright"); + keyCenterLeft = configFile.get(categoryKeys, "keyCenterLeft", Keyboard.KEY_A); + keyCenterCenter = configFile.get(categoryKeys, "keyCenterCenter", Keyboard.KEY_S); + keyCenterRight = configFile.get(categoryKeys, "keyCenterRight", Keyboard.KEY_D); - keyLowerLeft = configFile.get(categoryKeys, "3.0-keyLowerLeft", Keyboard.KEY_Y, "Lower Left crafting key (key value)"); // German Keyboard Layout - keyLowerLeft.setLanguageKey("key.lowerleft"); - keyLowerCenter = configFile.get(categoryKeys, "3.1-keyLowerCenter", Keyboard.KEY_X, "Lower Center crafting key (key value)"); - keyLowerCenter.setLanguageKey("key.lowercenter"); - keyLowerRight = configFile.get(categoryKeys, "3.2-keyLowerRight", Keyboard.KEY_C, "Lower Right crafting key (key value)"); - keyLowerRight.setLanguageKey("key.lowerright"); + keyLowerLeft = configFile.get(categoryKeys, "keyLowerLeft", Keyboard.KEY_Y); // German Keyboard Layout + keyLowerCenter = configFile.get(categoryKeys, "keyLowerCenter", Keyboard.KEY_X); + keyLowerRight = configFile.get(categoryKeys, "keyLowerRight", Keyboard.KEY_C); // Special Keys - keyStack = configFile.get(categoryKeys, "4.0-keyStack", Keyboard.KEY_LSHIFT, "Key to move stacks instead of single items (key value)"); - keyStack.setLanguageKey("key.stack"); - keyInteract = configFile.get(categoryKeys, "4.1-keyInteract", Keyboard.KEY_LCONTROL, "Key to interact with e.g. crafting output (key value)"); - keyInteract.setLanguageKey("key.interact"); - keyDrop = configFile.get(categoryKeys, "4.2-keyDrop", Keyboard.KEY_SPACE, "Key to drop all items from crafting (key value)"); - keyDrop.setLanguageKey("key.drop"); + keyStack = configFile.get(categoryKeys, "keyStack", Keyboard.KEY_LSHIFT); + keyInteract = configFile.get(categoryKeys, "keyInteract", Keyboard.KEY_LCONTROL); + keyDrop = configFile.get(categoryKeys, "keyDrop", Keyboard.KEY_SPACE); // Other Settings enableNumPad = configFile.get(categoryOther, "numPadEnabled", true, "Activates the NumPad for crafting"); - enableNumPad.setLanguageKey("options.numpadEnabled"); } } diff --git a/src/main/java/de/skate702/craftingkeys/config/GuiConfig.java b/src/main/java/de/skate702/craftingkeys/config/GuiConfig.java index 4e90b05..5a4245b 100644 --- a/src/main/java/de/skate702/craftingkeys/config/GuiConfig.java +++ b/src/main/java/de/skate702/craftingkeys/config/GuiConfig.java @@ -2,7 +2,6 @@ package de.skate702.craftingkeys.config; import de.skate702.craftingkeys.util.LanguageLocalizer; import de.skate702.craftingkeys.util.Logger; -import de.skate702.craftingkeys.util.Util; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; @@ -131,13 +130,11 @@ public class GuiConfig extends GuiScreen { public void actionPerformed(GuiButton button) { if (button.id == buttonAbortID) { Logger.info("actionPerformed(b)", "Closing Crafting Keys GUI now!"); - Util.client.thePlayer.closeScreen(); mc.thePlayer.closeScreen(); - Util.client.displayGuiScreen(null); } else if (button.id == buttonSaveID) { save(); Logger.info("actionPerformed(b)", "Saving & closing Crafting Keys GUI now!"); - Util.client.thePlayer.closeScreen(); + mc.thePlayer.closeScreen(); } else if (button.id >= 0 && button.id <= 11) { if (selectedButtonID == -1) { selectedButtonID = button.id; @@ -166,8 +163,14 @@ public class GuiConfig extends GuiScreen { public void keyTyped(char character, int keyCode) { if (keyCode == Keyboard.KEY_ESCAPE) { - selectedButtonID = -1; - drawKeyValues(); + if (selectedButtonID != -1) { + selectedButtonID = -1; + drawKeyValues(); + } else { + Logger.info("keyTyped(c,i)", "Trying to close inventory with esc."); + super.keyTyped(character, keyCode); // Enable standard gui closing + } + } else if (selectedButtonID != -1) { if (!ArrayUtils.contains(keyValues, keyCode)) { // No double keys keyValues[selectedButtonID] = keyCode; @@ -178,10 +181,7 @@ public class GuiConfig extends GuiScreen { } - // TODO: Lang files - // TODO: Config files - // TODO: Crafting symbols - // TODO: KeyBindings + // TODO: Crafting symbols & labels private void drawCraftingTable() { GL11.glColor4f(1F, 1F, 1F, 1F); diff --git a/src/main/java/de/skate702/craftingkeys/config/KeyBindings.java b/src/main/java/de/skate702/craftingkeys/config/KeyBindings.java index eb44cfc..191b6b9 100644 --- a/src/main/java/de/skate702/craftingkeys/config/KeyBindings.java +++ b/src/main/java/de/skate702/craftingkeys/config/KeyBindings.java @@ -1,49 +1,24 @@ package de.skate702.craftingkeys.config; import cpw.mods.fml.client.registry.ClientRegistry; -import net.minecraft.client.Minecraft; import net.minecraft.client.settings.KeyBinding; import org.lwjgl.input.Keyboard; /** * Provides all Key Bindings and methods to register and check them. */ -@Deprecated public class KeyBindings { - // WARNING: This does NOT work! Have to use own Option Dialog OR Settings file. Bindings are exclusive. Shit! + private static final String category = "craftingkeys.binding.cat"; - - private static final String category = "key.categories.craftingkeys"; - - private static KeyBinding[] bindings = { // Inspired by CSS Position Properties - new KeyBinding("key.topleft", Keyboard.KEY_Q, category), - new KeyBinding("key.topcenter", Keyboard.KEY_W, category), - new KeyBinding("key.topright", Keyboard.KEY_E, category), - - new KeyBinding("key.centerleft", Keyboard.KEY_A, category), - new KeyBinding("key.centercenter", Keyboard.KEY_S, category), - new KeyBinding("key.centerright", Keyboard.KEY_D, category), - - new KeyBinding("key.lowerleft", Keyboard.KEY_Y, category), // GERMAN Keyboard layout - new KeyBinding("key.lowercenter", Keyboard.KEY_X, category), - new KeyBinding("key.lowerright", Keyboard.KEY_C, category), - - new KeyBinding("key.stack", Keyboard.KEY_LSHIFT, category), - new KeyBinding("key.interact", Keyboard.KEY_LCONTROL, category), - }; + public static KeyBinding openGuiBinding = new KeyBinding("craftingkeys.binding.opengui", + Keyboard.KEY_K, category); /** - * Initializes all key bindings and registers them to the client-side. Bindings are exclusive. - * Do NOT use until there is a solution for this! + * Initializes all key bindings and registers them to the client-side. */ - @Deprecated public static void init() { - for (KeyBinding binding : bindings) { - ClientRegistry.registerKeyBinding(binding); - } - ClientRegistry.registerKeyBinding(Minecraft.getMinecraft().gameSettings.keyBindRight); - //Minecraft.getMinecraft().gameSettings.keybind + ClientRegistry.registerKeyBinding(openGuiBinding); } } diff --git a/src/main/resources/assets/craftingkeys/lang/de_DE.lang b/src/main/resources/assets/craftingkeys/lang/de_DE.lang index 5888f73..5fa7882 100644 --- a/src/main/resources/assets/craftingkeys/lang/de_DE.lang +++ b/src/main/resources/assets/craftingkeys/lang/de_DE.lang @@ -1,33 +1,4 @@ -# Control Names -key.topleft=1. Oben Links -key.topcenter=2. Oben Mitte -key.topright=3. Oben Rechts -key.centerleft=4. Mitte Links -key.centercenter=5. Mitte Mitte -key.centerright=6. Mitte Rechts -key.lowerleft=7. Unten Links -key.lowercenter=8. Unten Mitte -key.lowerright=9. Unten Rechts -key.stack=Stack Taste -key.interact=Interaktions Taste -key.drop=Drop Taste - -options.numpadEnabled=Aktiviere Num pad - -# Control Category Name -key.categories.craftingkeys=Crafting Keys - # Config Stuff -de.skate702.craftingkeys.config.keys=Tastaturbelegung -de.skate702.craftingkeys.config.other=Anderes -de.skate702.craftingkeys.config.keys.tooltip=Belege hier deine Tasten (Einfach mal "LWJGL Key codes" googlen!) -de.skate702.craftingkeys.config.other.tooltip=Saemtliche anderen Einstellungen sind hier! - -# Warning -de.skate702.craftingkeys.warn.line1=Achtung: Crafting-Keys befindet sich in der Alpha! -de.skate702.craftingkeys.warn.line2=Es gibt noch viele Fehler, und es fehlen noch einige Funktionen. -de.skate702.craftingkeys.warn.line3=Mehr Info's findest du auf: https://github.com/0xSeb/CraftingKeys! - craftingkeys.config.title=Crafting Keys Konfiguration craftingkeys.config.description=Konfiguriere hier deine Tastenbelegung und klicke dann auf "Speichern". craftingkeys.config.button.save=Speichern @@ -35,3 +6,6 @@ craftingkeys.config.button.abort=Abbruch craftingkeys.config.stack=Stapel Taste craftingkeys.config.drop=Wegwerf Taste +# Key Bindings +craftingkeys.binding.opengui=Konfigurieren-Fenster oeffnen +craftingkeys.binding.cat=Crafting Keys \ No newline at end of file diff --git a/src/main/resources/assets/craftingkeys/lang/en_US.lang b/src/main/resources/assets/craftingkeys/lang/en_US.lang index bee3a4b..9321830 100644 --- a/src/main/resources/assets/craftingkeys/lang/en_US.lang +++ b/src/main/resources/assets/craftingkeys/lang/en_US.lang @@ -1,36 +1,11 @@ -# Control Names -key.topleft=1. Top Left -key.topcenter=2. Top Center -key.topright=3. Top Right -key.centerleft=4. Center Left -key.centercenter=5. Center Center -key.centerright=6. Center Right -key.lowerleft=7. Lower Left -key.lowercenter=8. Lower Center -key.lowerright=9. Lower Right -key.stack=Stack Key -key.interact=Interaction Key -key.drop=Drop Key - -options.numpadEnabled=Enable Num Pad - -# Control Category Name -key.categories.craftingkeys=Crafting Keys - -# Config Stuff -de.skate702.craftingkeys.config.keys=Keys -de.skate702.craftingkeys.config.other=Other -de.skate702.craftingkeys.config.keys.tooltip=Set your Keys here (Just google "LWJGL Key codes"!) -de.skate702.craftingkeys.config.other.tooltip=All other settings are here! - -# Warning -de.skate702.craftingkeys.warn.line1=Warning: Crafting Keys is still in development! -de.skate702.craftingkeys.warn.line2=This mod is not complete and there are some errors left. -de.skate702.craftingkeys.warn.line3=More Information: https://github.com/0xSeb/CraftingKeys! - +# Config Stuff craftingkeys.config.title=Crafting Keys Config craftingkeys.config.description=Configure your keys here. Click "Save" when finished! craftingkeys.config.button.save=Save craftingkeys.config.button.abort=Abort craftingkeys.config.stack=Stack key -craftingkeys.config.drop=Drop key \ No newline at end of file +craftingkeys.config.drop=Drop key + +# Key Bindings +craftingkeys.binding.opengui=Open config-gui +craftingkeys.binding.cat=Crafting Keys \ No newline at end of file