public static KeyMapCollection Load(string game, KeyMapCollection defaultKeyMap) { DataContractSerializer x = new DataContractSerializer(typeof(KeyMapCollection)); KeyMapCollection finalCollection = new KeyMapCollection(defaultKeyMap); StreamReader stm = null; try { string filepath = KeyMapCollection.GetSettingsPath(game); stm = new StreamReader(filepath); KeyMapCollection savedCollection = (KeyMapCollection)x.ReadObject(stm.BaseStream); foreach (KeyMap finalkm in finalCollection.keyMaps.Values) // if tha keymap by this name exists on disk if (savedCollection.keyMaps.ContainsKey(finalkm.Alias)) { KeyMap savedkm = savedCollection.keyMaps[finalkm.Alias]; // load those preferences, overriding the defaults finalkm.LoadOverrides(savedkm); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Error in LoadKeyMap " + e.StackTrace); } finally { if (stm != null) stm.Close(); } return finalCollection; }
public InputManager(String gameName, KeyMapCollection defaultKeyMapcollection) { game = gameName; keyMaps = KeyMapCollection.Load(game, defaultKeyMapcollection); Mode = InputMode.Mapped; InputModeDelegates = new SortedList <InputMode, Delegate>(); }
public InputManager(String gameName, KeyMapCollection defaultKeyMapcollection) { game = gameName; keyMaps = KeyMapCollection.Load(game, defaultKeyMapcollection); Mode = InputMode.Mapped; InputModeDelegates = new SortedList<InputMode, Delegate>(); }
public void EditSettings() { frmSettings = new Settings(keyMaps); InputMode lastMode = Mode; Mode = InputMode.Setup; System.Windows.Forms.DialogResult dr = frmSettings.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.OK) { keyMaps = frmSettings.keyMaps; Save(); } frmSettings.Dispose(); Mode = lastMode; }
public static void Save(KeyMapCollection kmc) { DataContractSerializer x = new DataContractSerializer(typeof(KeyMapCollection)); StreamWriter stm = null; StringWriter sw = new StringWriter(); XmlTextWriter tw = new XmlTextWriter(sw); try { string filepath = kmc.FilePath; if (!Directory.Exists(filepath)) { string dirpath = Path.GetDirectoryName(filepath); Directory.CreateDirectory(dirpath); } stm = new StreamWriter(filepath); tw.Formatting = Formatting.Indented; // Make it human readable! x.WriteObject(tw, kmc); tw.Flush(); stm.Write(sw.ToString()); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Error in SaveKeyMap " + e.StackTrace); } finally { if (tw != null) { tw.Close(); } if (stm != null) { stm.Close(); } } }
public static KeyMapCollection Load(string game, KeyMapCollection defaultKeyMap) { DataContractSerializer x = new DataContractSerializer(typeof(KeyMapCollection)); KeyMapCollection finalCollection = new KeyMapCollection(defaultKeyMap); StreamReader stm = null; try { string filepath = KeyMapCollection.GetSettingsPath(game); stm = new StreamReader(filepath); KeyMapCollection savedCollection = (KeyMapCollection)x.ReadObject(stm.BaseStream); foreach (KeyMap finalkm in finalCollection.keyMaps.Values) { // if tha keymap by this name exists on disk if (savedCollection.keyMaps.ContainsKey(finalkm.Alias)) { KeyMap savedkm = savedCollection.keyMaps[finalkm.Alias]; // load those preferences, overriding the defaults finalkm.LoadOverrides(savedkm); } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Error in LoadKeyMap " + e.StackTrace); } finally { if (stm != null) { stm.Close(); } } return(finalCollection); }
public KeyMapCollection(KeyMapCollection other) { Game = other.Game; keyMaps = new SortedList<string, KeyMap>(other.keyMaps); }
public static void Save(KeyMapCollection kmc) { DataContractSerializer x = new DataContractSerializer(typeof(KeyMapCollection)); StreamWriter stm = null; StringWriter sw = new StringWriter(); XmlTextWriter tw = new XmlTextWriter(sw); try { string filepath = kmc.FilePath; if (!Directory.Exists(filepath)) { string dirpath = Path.GetDirectoryName(filepath); Directory.CreateDirectory(dirpath); } stm = new StreamWriter(filepath); tw.Formatting = Formatting.Indented; // Make it human readable! x.WriteObject(tw, kmc); tw.Flush(); stm.Write(sw.ToString()); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Error in SaveKeyMap " + e.StackTrace); } finally { if(tw!=null) tw.Close(); if (stm != null) stm.Close(); } }
public virtual void InitializeInputs() { if (isClient) { } keyMapCollections = GetDefaultControls(); }
public override KeyMapCollection GetDefaultControls() { KeyMapCollection defControls = new KeyMapCollection(); defControls.Game = this.name; List<KeyBinding> cameraDefaults = new List<KeyBinding>(); cameraDefaults.Add(new KeyBinding("Forward", Keys.NumPad8, false, false, false, KeyEvent.Down, CameraMoveForward)); cameraDefaults.Add(new KeyBinding("Left", Keys.NumPad4, false, false, false, KeyEvent.Down, CameraMoveLeft)); cameraDefaults.Add(new KeyBinding("Backward", Keys.NumPad5, false, false, false, KeyEvent.Down, CameraMoveBackward)); cameraDefaults.Add(new KeyBinding("Right", Keys.NumPad6, false, false, false, KeyEvent.Down, CameraMoveRight)); cameraDefaults.Add(new KeyBinding("Speed Increase", Keys.NumPad7, false, false, false, KeyEvent.Pressed, CameraMoveSpeedIncrease)); cameraDefaults.Add(new KeyBinding("Speed Decrease", Keys.NumPad1, false, false, false, KeyEvent.Pressed, CameraMoveSpeedDecrease)); cameraDefaults.Add(new KeyBinding("Height Increase", Keys.NumPad9, false, false, false, KeyEvent.Down, CameraMoveHeightIncrease)); cameraDefaults.Add(new KeyBinding("Height Decrease", Keys.NumPad3, false, false, false, KeyEvent.Down, CameraMoveHeightDecrease)); cameraDefaults.Add(new KeyBinding("Change Mode", Keys.Decimal, false, false, false, KeyEvent.Pressed, CameraModeCycle)); cameraDefaults.Add(new KeyBinding("Home", Keys.Multiply, false, false, false, KeyEvent.Pressed, CameraMoveHome)); // cameraDefaults.Add(new KeyBinding("Toggle Debug Info", Keys.F1, false, false, false, KeyEvent.Pressed, ToggleDebugInfo)); cameraDefaults.Add(new KeyBinding("Toggle Physics Debug", Keys.F2, false, false, false, KeyEvent.Pressed, TogglePhsyicsDebug)); KeyMap camControls = new KeyMap(GenericInputGroups.Camera.ToString(), cameraDefaults); List<KeyBinding> ClientDefs = new List<KeyBinding>(); ClientDefs.Add(new KeyBinding("Escape", Keys.Escape, false, false, false, KeyEvent.Pressed, Stop)); KeyMap clientControls = new KeyMap(GenericInputGroups.Client.ToString(), ClientDefs); // Car List<KeyBinding> roverDefaults = new List<KeyBinding>(); //careDefaults.Add(new KeyBinding("Spawn", Keys.R, false, true, false, KeyEvent.Pressed, SpawnCar)); roverDefaults.Add(new KeyBinding("Forward", Keys.Up, false, false, false, KeyEvent.Down, Accelerate)); roverDefaults.Add(new KeyBinding("Left", Keys.Left, false, false, false, KeyEvent.Down, SteerLeft)); roverDefaults.Add(new KeyBinding("Backward", Keys.Down, false, false, false, KeyEvent.Down, Deccelerate)); roverDefaults.Add(new KeyBinding("Right", Keys.Right, false, false, false, KeyEvent.Down, SteerRight)); roverDefaults.Add(new KeyBinding("Laser", Keys.B, false, false, false, KeyEvent.Down, UseLaser)); roverDefaults.Add(new KeyBinding("Pan Camera Left", Keys.J, false, false, false, KeyEvent.Down, RoverCamPanLeft)); roverDefaults.Add(new KeyBinding("Pan Camera Right", Keys.L, false, false, false, KeyEvent.Down, RoverCamPanRight)); roverDefaults.Add(new KeyBinding("Pan Camera Up", Keys.I, false, false, false, KeyEvent.Down, RoverCamPanUp)); roverDefaults.Add(new KeyBinding("Pan Camera Down", Keys.K, false, false, false, KeyEvent.Down, RoverCamPanDown)); KeyMap roverControls = new KeyMap(InputGroups.Rover.ToString(),roverDefaults); // player // Spheres //cardefaults.Add(new KeyBinding("SpawnSpheres", Keys.N, false, true, false, KeyEvent.Pressed, SpawnSpheres)); //Lunar Lander List<KeyBinding> landerDefaults = new List<KeyBinding>(); //landerDefaults.Add(new KeyBinding("Spawn", Keys.Decimal, false, false, false, KeyEvent.Pressed, SpawnLander)); landerDefaults.Add(new KeyBinding("Thrust Up", Keys.Space, false, false, false, KeyEvent.Down, LunarThrustUp)); landerDefaults.Add(new KeyBinding("Pitch Up", Keys.NumPad5, false, false, false, KeyEvent.Down, LunarPitchUp)); landerDefaults.Add(new KeyBinding("Pitch Down", Keys.NumPad8, false, false, false, KeyEvent.Down, LunarPitchDown)); landerDefaults.Add(new KeyBinding("Roll Left", Keys.NumPad4, false, false, false, KeyEvent.Down, LunarRollLeft)); landerDefaults.Add(new KeyBinding("Roll Right", Keys.NumPad6, false, false, false, KeyEvent.Down, LunarRollRight)); landerDefaults.Add(new KeyBinding("Yaw Left", Keys.NumPad7, false, false, false, KeyEvent.Down, LunarYawLeft)); landerDefaults.Add(new KeyBinding("Yaw Right", Keys.NumPad9, false, false, false, KeyEvent.Down, LunarYawRight)); KeyMap landerControls = new KeyMap(InputGroups.Lander.ToString(), landerDefaults); // Chat List<KeyBinding> commDefaults = new List<KeyBinding>(); commDefaults.Add(new KeyBinding("Chat ", Keys.Enter, false, false, false, KeyEvent.Pressed, ChatKeyPressed)); KeyMap commControls = new KeyMap(InputGroups.Communication.ToString(), commDefaults); // Interface List<KeyBinding> interfaceDefaults = new List<KeyBinding>(); //interfaceDefaults.Add(new KeyBinding("Enter / Exit Vehicle", Keys.E, false, true, false, KeyEvent.Pressed, EnterExitVehicle)); interfaceDefaults.Add(new KeyBinding("Spawn Lander", Keys.L, false, true, false, KeyEvent.Pressed, SpawnLander)); interfaceDefaults.Add(new KeyBinding("Spawn Rover", Keys.R, false, true, false, KeyEvent.Pressed, Request_Rover)); KeyMap interfaceControls = new KeyMap(InputGroups.Interface.ToString(), interfaceDefaults); defControls.AddMap(camControls); defControls.AddMap(clientControls); defControls.AddMap(roverControls); defControls.AddMap(landerControls); defControls.AddMap(commControls); defControls.AddMap(interfaceControls); Vector3 res = new Vector3(); Vector3 l = Vector3.Left; Vector3 n = Vector3.Zero; Vector3.Subtract(ref l, ref n, out res); return defControls; }
public KeyMapCollection(KeyMapCollection other) { Game = other.Game; keyMaps = new SortedList <string, KeyMap>(other.keyMaps); }
public void Save() { KeyMapCollection.Save(keyMaps); //KeyMap.SaveKeyMap(keyMap); }
public Settings(KeyMapCollection kmc) { InitializeComponent(); keyMaps = kmc; AddKeyBindingGuiControls(); }
public override KeyMapCollection GetDefaultControls() { KeyMapCollection defControls = new KeyMapCollection(); defControls.Game = this.name; List<KeyBinding> buildDefaults = new List<KeyBinding>(); buildDefaults.Add(new KeyBinding("Forward", Keys.NumPad8, false, false, false, KeyEvent.Down, CameraMoveForward)); buildDefaults.Add(new KeyBinding("Left", Keys.NumPad4, false, false, false, KeyEvent.Down, CameraMoveLeft)); buildDefaults.Add(new KeyBinding("Backward", Keys.NumPad5, false, false, false, KeyEvent.Down, CameraMoveBackward)); buildDefaults.Add(new KeyBinding("Right", Keys.NumPad6, false, false, false, KeyEvent.Down, CameraMoveRight)); buildDefaults.Add(new KeyBinding("Speed Increase", Keys.NumPad7, false, false, false, KeyEvent.Pressed, CameraMoveSpeedIncrease)); buildDefaults.Add(new KeyBinding("Speed Decrease", Keys.NumPad1, false, false, false, KeyEvent.Pressed, CameraMoveSpeedDecrease)); buildDefaults.Add(new KeyBinding("Height Increase", Keys.NumPad9, false, false, false, KeyEvent.Down, CameraMoveHeightIncrease)); buildDefaults.Add(new KeyBinding("Height Decrease", Keys.NumPad3, false, false, false, KeyEvent.Down, CameraMoveHeightDecrease)); buildDefaults.Add(new KeyBinding("Cycle Mode", Keys.Decimal, false, false, false, KeyEvent.Pressed, CameraModeCycle)); buildDefaults.Add(new KeyBinding("Home", Keys.Multiply, false, false, false, KeyEvent.Pressed, CameraMoveHome)); // buildDefaults.Add(new KeyBinding("Toggle Debug Info", Keys.F1, false, false, false, KeyEvent.Pressed, ToggleDebugInfo)); buildDefaults.Add(new KeyBinding("Toggle Physics Debug", Keys.F2, false, false, false, KeyEvent.Pressed, TogglePhsyicsDebug)); KeyMap buildControls = new KeyMap(InputGroups.Build.ToString(), buildDefaults); List<KeyBinding> ClientDefs = new List<KeyBinding>(); ClientDefs.Add(new KeyBinding("Escape", Keys.Escape, false, false, false, KeyEvent.Pressed, Stop)); KeyMap clientControls = new KeyMap(GenericInputGroups.Client.ToString(), ClientDefs); // Chat List<KeyBinding> commDefaults = new List<KeyBinding>(); commDefaults.Add(new KeyBinding("Chat ", Keys.Enter, false, false, false, KeyEvent.Pressed, ChatKeyPressed)); KeyMap commControls = new KeyMap(InputGroups.Communication.ToString(), commDefaults); // Interface List<KeyBinding> interfaceDefaults = new List<KeyBinding>(); interfaceDefaults.Add(new KeyBinding("Pause Physics", Keys.P, false, true, false, KeyEvent.Pressed, Pause)); interfaceDefaults.Add(new KeyBinding("Toggle Build / Play Mode", Keys.F5, false, false, false, KeyEvent.Pressed, ToggleMode)); interfaceDefaults.Add(new KeyBinding("Toggle Build Camera", Keys.C, false, false, false, KeyEvent.Pressed, buildCamToggle)); KeyMap interfaceControls = new KeyMap(InputGroups.Interface.ToString(), interfaceDefaults); defControls.AddMap(buildControls); defControls.AddMap(clientControls); defControls.AddMap(commControls); defControls.AddMap(interfaceControls); Vector3 res = new Vector3(); Vector3 l = Vector3.Left; Vector3 n = Vector3.Zero; Vector3.Subtract(ref l, ref n, out res); return defControls; }