using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; namespace DIGIEVO { public static class Input { public enum InputMode { Combat, CombatWait, Ignore, VerticalMenu, Text, Notification, YesNo } public static KeyboardState oldState; public static KeyboardState newState; public static InputMode inputMode = InputMode.Combat; public static string enteredText = ""; public static void Initialize() { newState = Keyboard.GetState(); } public static void Update() { oldState = newState; newState = Keyboard.GetState(); switch (inputMode) { case InputMode.Combat: if (KeyPressed(Buttons.Left)) Combat.MoveSelection(-1, 0); if (KeyPressed(Buttons.Right)) Combat.MoveSelection(1, 0); if (KeyPressed(Buttons.Up)) Combat.MoveSelection(0, -1); if (KeyPressed(Buttons.Down)) Combat.MoveSelection(0, 1); if (KeyPressed(Buttons.Confirm)) Combat.ConfirmAttack(); break; case InputMode.CombatWait: if (KeyPressed(Buttons.Confirm)) Combat.Confirm(); break; case InputMode.VerticalMenu: if (KeyPressed(Buttons.Up)) Menu.MoveSelection(-1); if (KeyPressed(Buttons.Down)) Menu.MoveSelection(1); if (KeyPressed(Buttons.Confirm) /*|| KeyPressed(Keys.Right)*/) Menu.Confirm(); if (KeyPressed(Buttons.Cancel) /*|| KeyPressed(Keys.Left)*/) Menu.Cancel(); break; case InputMode.Text: if (KeyPressed(Keys.A)) enteredText += "A"; if (KeyPressed(Keys.B)) enteredText += "B"; if (KeyPressed(Keys.C)) enteredText += "C"; if (KeyPressed(Keys.D)) enteredText += "D"; if (KeyPressed(Keys.E)) enteredText += "E"; if (KeyPressed(Keys.F)) enteredText += "F"; if (KeyPressed(Keys.G)) enteredText += "G"; if (KeyPressed(Keys.H)) enteredText += "H"; if (KeyPressed(Keys.I)) enteredText += "I"; if (KeyPressed(Keys.J)) enteredText += "J"; if (KeyPressed(Keys.K)) enteredText += "K"; if (KeyPressed(Keys.L)) enteredText += "L"; if (KeyPressed(Keys.M)) enteredText += "M"; if (KeyPressed(Keys.N)) enteredText += "N"; if (KeyPressed(Keys.O)) enteredText += "O"; if (KeyPressed(Keys.P)) enteredText += "P"; if (KeyPressed(Keys.Q)) enteredText += "Q"; if (KeyPressed(Keys.R)) enteredText += "R"; if (KeyPressed(Keys.S)) enteredText += "S"; if (KeyPressed(Keys.T)) enteredText += "T"; if (KeyPressed(Keys.U)) enteredText += "U"; if (KeyPressed(Keys.V)) enteredText += "V"; if (KeyPressed(Keys.W)) enteredText += "W"; if (KeyPressed(Keys.X)) enteredText += "X"; if (KeyPressed(Keys.Y)) enteredText += "Y"; if (KeyPressed(Keys.Z)) enteredText += "Z"; if (KeyPressed(Keys.NumPad0) || KeyPressed(Keys.D0)) enteredText += "0"; if (KeyPressed(Keys.NumPad1) || KeyPressed(Keys.D1)) enteredText += "1"; if (KeyPressed(Keys.NumPad2) || KeyPressed(Keys.D2)) enteredText += "2"; if (KeyPressed(Keys.NumPad3) || KeyPressed(Keys.D3)) enteredText += "3"; if (KeyPressed(Keys.NumPad4) || KeyPressed(Keys.D4)) enteredText += "4"; if (KeyPressed(Keys.NumPad5) || KeyPressed(Keys.D5)) enteredText += "5"; if (KeyPressed(Keys.NumPad6) || KeyPressed(Keys.D6)) enteredText += "6"; if (KeyPressed(Keys.NumPad7) || KeyPressed(Keys.D7)) enteredText += "7"; if (KeyPressed(Keys.NumPad8) || KeyPressed(Keys.D8)) enteredText += "8"; if (KeyPressed(Keys.NumPad9) || KeyPressed(Keys.D9)) enteredText += "9"; if (KeyPressed(Keys.Space)) enteredText += " "; if (KeyPressed(Keys.Back)) { if (enteredText.Length > 0) enteredText = enteredText.Substring(0, enteredText.Length - 1); } if (KeyPressed(Keys.Enter)) { Menu.Confirm(); } if (KeyPressed(Keys.Escape)) Menu.Cancel(); break; case InputMode.Notification: if (KeyPressed(Buttons.Confirm) || KeyPressed(Buttons.Cancel)) Menu.ConfirmNotification(); break; case InputMode.YesNo: if (KeyPressed(Buttons.CarefulConfirm)) Menu.ConfirmNotification(); if (KeyPressed(Buttons.CarefulCancel)) Menu.CancelNotification(); break; } if (KeyPressed(Keys.F) && inputMode != InputMode.Text) { VBXSE.SpriteEngine.ToggleFullscreen(); } } public static void StartTextEntry() { enteredText = ""; inputMode = InputMode.Text; } public static bool KeyPressed(Keys key) { if (!oldState.IsKeyDown(key) && newState.IsKeyDown(key)) { if (inputMode == InputMode.Text) { if (key != Keys.Enter && key != Keys.Escape) Audio.PlaySound("cursor"); } return true; } else return false; } public enum Buttons { Up, Down, Left, Right, Confirm, Cancel, CarefulConfirm, CarefulCancel } public static bool KeyPressed(Buttons purpose) { switch (purpose) { case Buttons.Up: return KeyPressed(Keys.Up) || KeyPressed(Keys.W); case Buttons.Down: return KeyPressed(Keys.Down) || KeyPressed(Keys.S); case Buttons.Left: return KeyPressed(Keys.Left) || KeyPressed(Keys.A); case Buttons.Right: return KeyPressed(Keys.Right) || KeyPressed(Keys.D); case Buttons.Confirm: return KeyPressed(Keys.Enter) || KeyPressed(Keys.Z) || KeyPressed(Keys.Space); case Buttons.CarefulConfirm: return KeyPressed(Keys.Z) || KeyPressed(Keys.Y); case Buttons.Cancel: return (KeyPressed(Keys.Escape) || KeyPressed(Keys.X) || KeyPressed(Keys.Back)); case Buttons.CarefulCancel: return (KeyPressed(Keys.Escape) || KeyPressed(Keys.X) || KeyPressed(Keys.Back) || KeyPressed(Keys.N)); } return false; } } }