using System;

namespace SharpQuake
{
	internal static class client_input
	{
		public static void Init()
		{
			cmd.Add("+moveup", new xcommand_t(client_input.UpDown));
			cmd.Add("-moveup", new xcommand_t(client_input.UpUp));
			cmd.Add("+movedown", new xcommand_t(client_input.DownDown));
			cmd.Add("-movedown", new xcommand_t(client_input.DownUp));
			cmd.Add("+left", new xcommand_t(client_input.LeftDown));
			cmd.Add("-left", new xcommand_t(client_input.LeftUp));
			cmd.Add("+right", new xcommand_t(client_input.RightDown));
			cmd.Add("-right", new xcommand_t(client_input.RightUp));
			cmd.Add("+forward", new xcommand_t(client_input.ForwardDown));
			cmd.Add("-forward", new xcommand_t(client_input.ForwardUp));
			cmd.Add("+back", new xcommand_t(client_input.BackDown));
			cmd.Add("-back", new xcommand_t(client_input.BackUp));
			cmd.Add("+lookup", new xcommand_t(client_input.LookupDown));
			cmd.Add("-lookup", new xcommand_t(client_input.LookupUp));
			cmd.Add("+lookdown", new xcommand_t(client_input.LookdownDown));
			cmd.Add("-lookdown", new xcommand_t(client_input.LookdownUp));
			cmd.Add("+strafe", new xcommand_t(client_input.StrafeDown));
			cmd.Add("-strafe", new xcommand_t(client_input.StrafeUp));
			cmd.Add("+moveleft", new xcommand_t(client_input.MoveleftDown));
			cmd.Add("-moveleft", new xcommand_t(client_input.MoveleftUp));
			cmd.Add("+moveright", new xcommand_t(client_input.MoverightDown));
			cmd.Add("-moveright", new xcommand_t(client_input.MoverightUp));
			cmd.Add("+speed", new xcommand_t(client_input.SpeedDown));
			cmd.Add("-speed", new xcommand_t(client_input.SpeedUp));
			cmd.Add("+attack", new xcommand_t(client_input.AttackDown));
			cmd.Add("-attack", new xcommand_t(client_input.AttackUp));
			cmd.Add("+use", new xcommand_t(client_input.UseDown));
			cmd.Add("-use", new xcommand_t(client_input.UseUp));
			cmd.Add("+jump", new xcommand_t(client_input.JumpDown));
			cmd.Add("-jump", new xcommand_t(client_input.JumpUp));
			cmd.Add("impulse", new xcommand_t(client_input.ImpulseCmd));
			cmd.Add("+klook", new xcommand_t(client_input.KLookDown));
			cmd.Add("-klook", new xcommand_t(client_input.KLookUp));
			cmd.Add("+mlook", new xcommand_t(client_input.MLookDown));
			cmd.Add("-mlook", new xcommand_t(client_input.MLookUp));
		}

		private static void KeyDown(ref kbutton_t b)
		{
			string text = cmd.Argv(1);
			int num;
			if (!string.IsNullOrEmpty(text))
			{
				num = int.Parse(text);
			}
			else
			{
				num = -1;
			}
			if (num == b.down0 || num == b.down1)
			{
				return;
			}
			if (b.down0 == 0)
			{
				b.down0 = num;
			}
			else
			{
				if (b.down1 != 0)
				{
					Con.Print("Three keys down for a button!\n", Array.Empty<object>());
					return;
				}
				b.down1 = num;
			}
			if ((b.state & 1) != 0)
			{
				return;
			}
			b.state |= 3;
		}

		private static void KeyUp(ref kbutton_t b)
		{
			string text = cmd.Argv(1);
			if (string.IsNullOrEmpty(text))
			{
				b.down0 = (b.down1 = 0);
				b.state = 4;
				return;
			}
			int num = int.Parse(text);
			if (b.down0 == num)
			{
				b.down0 = 0;
			}
			else
			{
				if (b.down1 != num)
				{
					return;
				}
				b.down1 = 0;
			}
			if (b.down0 != 0 || b.down1 != 0)
			{
				return;
			}
			if ((b.state & 1) == 0)
			{
				return;
			}
			b.state &= -2;
			b.state |= 4;
		}

		private static void KLookDown()
		{
			client_input.KeyDown(ref client_input.KLookBtn);
		}

		private static void KLookUp()
		{
			client_input.KeyUp(ref client_input.KLookBtn);
		}

		private static void MLookDown()
		{
			client_input.KeyDown(ref client_input.MLookBtn);
		}

		private static void MLookUp()
		{
			client_input.KeyUp(ref client_input.MLookBtn);
			if ((client_input.MLookBtn.state & 1) == 0 && client.LookSpring)
			{
				view.StartPitchDrift();
			}
		}

		private static void UpDown()
		{
			client_input.KeyDown(ref client_input.UpBtn);
		}

		private static void UpUp()
		{
			client_input.KeyUp(ref client_input.UpBtn);
		}

		private static void DownDown()
		{
			client_input.KeyDown(ref client_input.DownBtn);
		}

		private static void DownUp()
		{
			client_input.KeyUp(ref client_input.DownBtn);
		}

		private static void LeftDown()
		{
			client_input.KeyDown(ref client_input.LeftBtn);
		}

		private static void LeftUp()
		{
			client_input.KeyUp(ref client_input.LeftBtn);
		}

		private static void RightDown()
		{
			client_input.KeyDown(ref client_input.RightBtn);
		}

		private static void RightUp()
		{
			client_input.KeyUp(ref client_input.RightBtn);
		}

		private static void ForwardDown()
		{
			client_input.KeyDown(ref client_input.ForwardBtn);
		}

		private static void ForwardUp()
		{
			client_input.KeyUp(ref client_input.ForwardBtn);
		}

		private static void BackDown()
		{
			client_input.KeyDown(ref client_input.BackBtn);
		}

		private static void BackUp()
		{
			client_input.KeyUp(ref client_input.BackBtn);
		}

		private static void LookupDown()
		{
			client_input.KeyDown(ref client_input.LookUpBtn);
		}

		private static void LookupUp()
		{
			client_input.KeyUp(ref client_input.LookUpBtn);
		}

		private static void LookdownDown()
		{
			client_input.KeyDown(ref client_input.LookDownBtn);
		}

		private static void LookdownUp()
		{
			client_input.KeyUp(ref client_input.LookDownBtn);
		}

		private static void MoveleftDown()
		{
			client_input.KeyDown(ref client_input.MoveLeftBtn);
		}

		private static void MoveleftUp()
		{
			client_input.KeyUp(ref client_input.MoveLeftBtn);
		}

		private static void MoverightDown()
		{
			client_input.KeyDown(ref client_input.MoveRightBtn);
		}

		private static void MoverightUp()
		{
			client_input.KeyUp(ref client_input.MoveRightBtn);
		}

		private static void SpeedDown()
		{
			client_input.KeyDown(ref client_input.SpeedBtn);
		}

		private static void SpeedUp()
		{
			client_input.KeyUp(ref client_input.SpeedBtn);
		}

		private static void StrafeDown()
		{
			client_input.KeyDown(ref client_input.StrafeBtn);
		}

		private static void StrafeUp()
		{
			client_input.KeyUp(ref client_input.StrafeBtn);
		}

		private static void AttackDown()
		{
			client_input.KeyDown(ref client_input.AttackBtn);
		}

		private static void AttackUp()
		{
			client_input.KeyUp(ref client_input.AttackBtn);
		}

		private static void UseDown()
		{
			client_input.KeyDown(ref client_input.UseBtn);
		}

		private static void UseUp()
		{
			client_input.KeyUp(ref client_input.UseBtn);
		}

		private static void JumpDown()
		{
			client_input.KeyDown(ref client_input.JumpBtn);
		}

		private static void JumpUp()
		{
			client_input.KeyUp(ref client_input.JumpBtn);
		}

		private static void ImpulseCmd()
		{
			client_input.Impulse = common.atoi(cmd.Argv(1));
		}

		public static kbutton_t MLookBtn;

		public static kbutton_t KLookBtn;

		public static kbutton_t LeftBtn;

		public static kbutton_t RightBtn;

		public static kbutton_t ForwardBtn;

		public static kbutton_t BackBtn;

		public static kbutton_t LookUpBtn;

		public static kbutton_t LookDownBtn;

		public static kbutton_t MoveLeftBtn;

		public static kbutton_t MoveRightBtn;

		public static kbutton_t StrafeBtn;

		public static kbutton_t SpeedBtn;

		public static kbutton_t UseBtn;

		public static kbutton_t JumpBtn;

		public static kbutton_t AttackBtn;

		public static kbutton_t UpBtn;

		public static kbutton_t DownBtn;

		public static int Impulse;
	}
}
