Allowed Keyboard Inputs in GuiMouseInput

This commit is contained in:
CrushedPixel
2015-04-30 17:45:18 +02:00
parent 263ce4df8b
commit bc9fbfa786
3 changed files with 43 additions and 16 deletions

View File

@@ -59,6 +59,7 @@ public class ReplayMod {
public static boolean firstMainMenu = true; public static boolean firstMainMenu = true;
public static RecordingHandler recordingHandler; public static RecordingHandler recordingHandler;
public static ChatMessageHandler chatMessageHandler = new ChatMessageHandler(); public static ChatMessageHandler chatMessageHandler = new ChatMessageHandler();
public static KeyInputHandler keyInputHandler = new KeyInputHandler();
public static ReplaySender replaySender; public static ReplaySender replaySender;
public static int TP_DISTANCE_LIMIT = 128; public static int TP_DISTANCE_LIMIT = 128;
public static FileCopyHandler fileCopyHandler; public static FileCopyHandler fileCopyHandler;
@@ -94,7 +95,7 @@ public class ReplayMod {
FMLCommonHandler.instance().bus().register(new ConnectionEventHandler()); FMLCommonHandler.instance().bus().register(new ConnectionEventHandler());
MinecraftForge.EVENT_BUS.register(new GuiEventHandler()); MinecraftForge.EVENT_BUS.register(new GuiEventHandler());
FMLCommonHandler.instance().bus().register(new KeyInputHandler()); FMLCommonHandler.instance().bus().register(keyInputHandler);
MinecraftForge.EVENT_BUS.register(new MouseInputHandler()); MinecraftForge.EVENT_BUS.register(new MouseInputHandler());
recordingHandler = new RecordingHandler(); recordingHandler = new RecordingHandler();

View File

@@ -12,6 +12,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding; import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent; import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard; import org.lwjgl.input.Keyboard;
public class KeyInputHandler { public class KeyInputHandler {
@@ -21,10 +22,10 @@ public class KeyInputHandler {
private boolean escDown = false; private boolean escDown = false;
@SubscribeEvent @SubscribeEvent
public void onKeyInput(KeyInputEvent event) { public void onKeyInput(KeyInputEvent event) throws LWJGLException {
if(!ReplayHandler.isInReplay()) return; if(!ReplayHandler.isInReplay()) return;
if(mc.currentScreen != null) { if(mc.currentScreen != null && !(mc.currentScreen instanceof GuiMouseInput)) {
return; return;
} }
@@ -34,6 +35,7 @@ public class KeyInputHandler {
mc.displayGuiScreen(new GuiCancelRender()); mc.displayGuiScreen(new GuiCancelRender());
} }
if(!Keyboard.isCreated()) Keyboard.create();
escDown = Keyboard.isKeyDown(Keyboard.KEY_ESCAPE) && Keyboard.getEventKeyState(); escDown = Keyboard.isKeyDown(Keyboard.KEY_ESCAPE) && Keyboard.getEventKeyState();
boolean found = false; boolean found = false;
@@ -90,19 +92,7 @@ public class KeyInputHandler {
break; break;
} }
//Custom registered handlers handleCustomKeybindings(kb, found, null);
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());
}
} catch(Exception e) { } catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
@@ -110,4 +100,28 @@ public class KeyInputHandler {
found = true; 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));
}
}
} }

View File

@@ -1,7 +1,19 @@
package eu.crushedpixel.replaymod.gui; 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.gui.GuiScreen;
import net.minecraft.client.settings.KeyBinding;
import java.io.IOException;
public class GuiMouseInput extends GuiScreen { 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);
}
} }