package com.teamderpy.shouldersurfing.event;

import org.lwjgl.glfw.GLFW;

import com.teamderpy.shouldersurfing.config.Config;

import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.event.InputEvent.KeyInputEvent;
import net.minecraftforge.client.settings.KeyModifier;
import net.minecraftforge.eventbus.api.SubscribeEvent;

@OnlyIn(Dist.CLIENT)
public class KeyHandler
{
	public static final KeyBinding KEYBIND_ROTATE_CAMERA_LEFT = new KeyBinding("Camera left", GLFW.GLFW_KEY_LEFT, "Shoulder Surfing");
	public static final KeyBinding KEYBIND_ROTATE_CAMERA_RIGHT = new KeyBinding("Camera right", GLFW.GLFW_KEY_RIGHT, "Shoulder Surfing");
	public static final KeyBinding KEYBIND_ZOOM_CAMERA_OUT = new KeyBinding("Camera closer", GLFW.GLFW_KEY_UP, "Shoulder Surfing");
	public static final KeyBinding KEYBIND_ZOOM_CAMERA_IN = new KeyBinding("Camera farther", GLFW.GLFW_KEY_DOWN, "Shoulder Surfing");
	public static final KeyBinding KEYBIND_SWAP_SHOULDER = new KeyBinding("Swap shoulder", GLFW.GLFW_KEY_O, "Shoulder Surfing");
	
	@SubscribeEvent
	public static void keyInputEvent(KeyInputEvent event)
	{
		if(Minecraft.getInstance() != null && Minecraft.getInstance().currentScreen == null)
		{
			if(Minecraft.getInstance().gameSettings.thirdPersonView == Config.CLIENT.getShoulderSurfing3ppId())
			{
				if(KeyHandler.isKeyDown(KeyHandler.KEYBIND_ROTATE_CAMERA_LEFT))
				{
					Config.CLIENT.adjustCameraLeft();
				}
				
				if(KeyHandler.isKeyDown(KeyHandler.KEYBIND_ROTATE_CAMERA_RIGHT))
				{
					Config.CLIENT.adjustCameraRight();
				}
				
				if(KeyHandler.isKeyDown(KeyHandler.KEYBIND_ZOOM_CAMERA_IN))
				{
					Config.CLIENT.adjustCameraIn();
				}
				
				if(KeyHandler.isKeyDown(KeyHandler.KEYBIND_ZOOM_CAMERA_OUT))
				{
					Config.CLIENT.adjustCameraOut();
				}
				
				if(KeyHandler.isPressed(KeyHandler.KEYBIND_SWAP_SHOULDER))
				{
					Config.CLIENT.swapShoulder();
				}
			}
		}
	}
	
	private static boolean isPressed(KeyBinding keyBinding)
	{
		return keyBinding.isPressed() && (KeyModifier.NONE.equals(keyBinding.getKeyModifier()) || KeyModifier.getActiveModifier().equals(keyBinding.getKeyModifier()));
	}
	
	private static boolean isKeyDown(KeyBinding keyBinding)
	{
		return keyBinding.isKeyDown() && (KeyModifier.NONE.equals(keyBinding.getKeyModifier()) || KeyModifier.getActiveModifier().equals(keyBinding.getKeyModifier()));
	}
}

@@ -119,16 +119,93 @@
 .Config;
+%0Aimport com.teamderpy.shouldersurfing.config.Config.ClientConfig.Perspective;
 %0A%0Aimport
@@ -605,16 +605,82 @@
 ndler%0A%7B%0A
+%09private static final String KEY_CATEGORY = %22Shoulder Surfing%22;%0A%09%0A
 %09public 
@@ -782,34 +782,39 @@
 Y_LEFT, 
-%22Shoulder Surfing%22
+KeyHandler.KEY_CATEGORY
 );%0A%09publ
@@ -922,34 +922,39 @@
 _RIGHT, 
-%22Shoulder Surfing%22
+KeyHandler.KEY_CATEGORY
 );%0A%09publ
@@ -1056,34 +1056,39 @@
 KEY_UP, 
-%22Shoulder Surfing%22
+KeyHandler.KEY_CATEGORY
 );%0A%09publ
@@ -1192,34 +1192,39 @@
 Y_DOWN, 
-%22Shoulder Surfing%22
+KeyHandler.KEY_CATEGORY
 );%0A%09publ
@@ -1323,34 +1323,186 @@
 _KEY_O, 
-%22Shoulder Surfing%22
+KeyHandler.KEY_CATEGORY);%0A%09public static final KeyBinding KEYBIND_TOGGLE_SHOULDER_SURFING = new KeyBinding(%22Toggle perspective%22, GLFW.GLFW_KEY_F6, KeyHandler.KEY_CATEGORY
 );%0A%09%0A%09@S
@@ -1674,99 +1674,656 @@
 %09if(
-Minecraft.getInstance().gameSettings.thirdPersonView == Config.CLIENT.getShoulderSurfing3pp
+KeyHandler.isPressed(KeyHandler.KEYBIND_TOGGLE_SHOULDER_SURFING))%0A%09%09%09%7B%0A%09%09%09%09if(Minecraft.getInstance().gameSettings.thirdPersonView == Perspective.SHOULDER_SURFING.getPerspectiveId())%0A%09%09%09%09%7B%0A%09%09%09%09%09Minecraft.getInstance().gameSettings.thirdPersonView = Perspective.FIRST_PERSON.getPerspectiveId();%0A%09%09%09%09%7D%0A%09%09%09%09else if(Minecraft.getInstance().gameSettings.thirdPersonView == Perspective.FIRST_PERSON.getPerspectiveId())%0A%09%09%09%09%7B%0A%09%09%09%09%09Minecraft.getInstance().gameSettings.thirdPersonView = Perspective.SHOULDER_SURFING.getPerspectiveId();%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%09%0A%09%09%09if(Minecraft.getInstance().gameSettings.thirdPersonView == Perspective.SHOULDER_SURFING.getPerspective
 Id()

Implement toggle key for shoulder surfing perspective