diff --git a/src/main/java/eu/crushedpixel/replaymod/ReplayMod.java b/src/main/java/eu/crushedpixel/replaymod/ReplayMod.java index 25477d2d..8ebbafad 100755 --- a/src/main/java/eu/crushedpixel/replaymod/ReplayMod.java +++ b/src/main/java/eu/crushedpixel/replaymod/ReplayMod.java @@ -59,6 +59,7 @@ public class ReplayMod { public static boolean firstMainMenu = true; public static RecordingHandler recordingHandler; public static ChatMessageHandler chatMessageHandler = new ChatMessageHandler(); + public static KeyInputHandler keyInputHandler = new KeyInputHandler(); public static ReplaySender replaySender; public static int TP_DISTANCE_LIMIT = 128; public static FileCopyHandler fileCopyHandler; @@ -94,7 +95,7 @@ public class ReplayMod { FMLCommonHandler.instance().bus().register(new ConnectionEventHandler()); MinecraftForge.EVENT_BUS.register(new GuiEventHandler()); - FMLCommonHandler.instance().bus().register(new KeyInputHandler()); + FMLCommonHandler.instance().bus().register(keyInputHandler); MinecraftForge.EVENT_BUS.register(new MouseInputHandler()); recordingHandler = new RecordingHandler(); diff --git a/src/main/java/eu/crushedpixel/replaymod/events/KeyInputHandler.java b/src/main/java/eu/crushedpixel/replaymod/events/KeyInputHandler.java index bb2ab584..d1ba224e 100755 --- a/src/main/java/eu/crushedpixel/replaymod/events/KeyInputHandler.java +++ b/src/main/java/eu/crushedpixel/replaymod/events/KeyInputHandler.java @@ -12,6 +12,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.settings.KeyBinding; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent; +import org.lwjgl.LWJGLException; import org.lwjgl.input.Keyboard; public class KeyInputHandler { @@ -21,10 +22,10 @@ public class KeyInputHandler { private boolean escDown = false; @SubscribeEvent - public void onKeyInput(KeyInputEvent event) { + public void onKeyInput(KeyInputEvent event) throws LWJGLException { if(!ReplayHandler.isInReplay()) return; - if(mc.currentScreen != null) { + if(mc.currentScreen != null && !(mc.currentScreen instanceof GuiMouseInput)) { return; } @@ -34,6 +35,7 @@ public class KeyInputHandler { mc.displayGuiScreen(new GuiCancelRender()); } + if(!Keyboard.isCreated()) Keyboard.create(); escDown = Keyboard.isKeyDown(Keyboard.KEY_ESCAPE) && Keyboard.getEventKeyState(); boolean found = false; @@ -90,19 +92,7 @@ public class KeyInputHandler { break; } - //Custom registered handlers - if(kb.getKeyDescription().equals(KeybindRegistry.KEY_THUMBNAIL) && kb.isPressed() && !found) { - TickAndRenderListener.requestScreenshot(); - //TODO: Make this properly work - } - - if(kb.getKeyDescription().equals(KeybindRegistry.KEY_SPECTATE) && kb.isPressed() && !found) { - SpectateHandler.openSpectateSelection(); - } - - if(kb.getKeyDescription().equals(KeybindRegistry.KEY_LIGHTING) && kb.isPressed()) { - ReplayMod.replaySettings.setLightingEnabled(!ReplayMod.replaySettings.isLightingEnabled()); - } + handleCustomKeybindings(kb, found, null); } catch(Exception e) { e.printStackTrace(); @@ -110,4 +100,28 @@ public class KeyInputHandler { found = true; } } + + public void handleCustomKeybindings(KeyBinding kb, boolean found, Integer keyCode) { + //Custom registered handlers + if(kb.getKeyDescription().equals(KeybindRegistry.KEY_THUMBNAIL) && (kb.isPressed() || kb.getKeyCode() == keyCode) && !found) { + TickAndRenderListener.requestScreenshot(); + //TODO: Make this properly work + } + + if(kb.getKeyDescription().equals(KeybindRegistry.KEY_SPECTATE) && (kb.isPressed() || kb.getKeyCode() == keyCode) && !found) { + SpectateHandler.openSpectateSelection(); + } + + if(kb.getKeyDescription().equals(KeybindRegistry.KEY_LIGHTING) && (kb.isPressed() || kb.getKeyCode() == keyCode)) { + ReplayMod.replaySettings.setLightingEnabled(!ReplayMod.replaySettings.isLightingEnabled()); + } + + if(kb.getKeyDescription().equals(KeybindRegistry.KEY_CLEAR_KEYFRAMES) && (kb.isPressed() || kb.getKeyCode() == keyCode)) { + ReplayHandler.resetKeyframes(); + } + + if(kb.getKeyDescription().equals(KeybindRegistry.KEY_SYNC_TIMELINE) && (kb.isPressed() || kb.getKeyCode() == keyCode)) { + ReplayHandler.syncTimeCursor(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)); + } + } } diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/GuiMouseInput.java b/src/main/java/eu/crushedpixel/replaymod/gui/GuiMouseInput.java index 98a52ffc..d9bb2bda 100755 --- a/src/main/java/eu/crushedpixel/replaymod/gui/GuiMouseInput.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/GuiMouseInput.java @@ -1,7 +1,19 @@ package eu.crushedpixel.replaymod.gui; +import eu.crushedpixel.replaymod.ReplayMod; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.settings.KeyBinding; + +import java.io.IOException; public class GuiMouseInput extends GuiScreen { + @Override + protected void keyTyped(char typedChar, int keyCode) throws IOException { + for(KeyBinding kb : Minecraft.getMinecraft().gameSettings.keyBindings) + ReplayMod.keyInputHandler.handleCustomKeybindings(kb, false, keyCode); + + super.keyTyped(typedChar, keyCode); + } }