public InputManager(String gameName, KeyMap defaultKeyMap) { game = gameName; keyMap = KeyMap.LoadKeyMap(game, defaultKeyMap); Mode = InputMode.Mapped; InputModeDelegates = new SortedList <InputMode, Delegate>(); }
public static void SaveKeyMap(KeyMap km) { XmlSerializer x = new XmlSerializer(typeof(KeyMap)); StreamWriter stm = null; try { string filepath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\CnJ Xna Physics\\KeyBindings\\" + km.Game + ".xml"; if (!Directory.Exists(filepath)) { string dirpath = Path.GetDirectoryName(filepath); Directory.CreateDirectory(dirpath); } stm = new StreamWriter(filepath); x.Serialize(stm, km); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Error in SaveKeyMap " + e.Message); } finally { if (stm != null) { stm.Close(); } } }
public InputManager(String gameName, KeyMap defaultKeyMap) { game = gameName; keyMap = KeyMap.LoadKeyMap(game, defaultKeyMap); Mode = InputMode.Mapped; InputModeDelegates = new SortedList<InputMode, Delegate>(); }
public void EditSettings() { frmSettings = new Settings(keyMap); InputMode lastMode = Mode; Mode = InputMode.Setup; System.Windows.Forms.DialogResult dr = frmSettings.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.OK) { keyMap = frmSettings.keyMap; Save(); } frmSettings.Dispose(); Mode = lastMode; }
public static KeyMap LoadKeyMap(string game, KeyMap defaultKeyMap) { XmlSerializer x = new XmlSerializer(typeof(KeyMap)); KeyMap loadedKeyMap = new KeyMap(defaultKeyMap); StreamReader stm = null; try { string filepath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\CnJ Xna Physics\\KeyBindings\\" + game + ".xml"; stm = new StreamReader(filepath); KeyMap km = (KeyMap)x.Deserialize(stm); foreach (KeyBinding saved in km.KeyBindings) { foreach (KeyBinding kb in loadedKeyMap.KeyBindings) { // We found a saved keybinding, use its settings instead if (saved.Alias.Equals(kb.Alias)) { kb.Alt = saved.Alt; kb.Ctrl = saved.Ctrl; kb.Key = saved.Key; kb.KeyEvent = saved.KeyEvent; kb.Shift = saved.Shift; } } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Error in LoadKeyMap " + e.Message); } finally { if (stm != null) { stm.Close(); } } return(loadedKeyMap); }
public KeyMap(KeyMap other) { Game = other.Game; KeyBindings = new List <KeyBinding>(other.KeyBindings); }
public Settings(KeyMap km) { InitializeComponent(); keyMap = km; AddKeys(); }
public void Save() { KeyMap.SaveKeyMap(keyMap); }
public static KeyMap LoadKeyMap(string game, KeyMap defaultKeyMap) { XmlSerializer x = new XmlSerializer(typeof(KeyMap)); KeyMap loadedKeyMap = new KeyMap(defaultKeyMap); StreamReader stm = null; try { string filepath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\CnJ Xna Physics\\KeyBindings\\" + game + ".xml"; stm = new StreamReader(filepath); KeyMap km = (KeyMap)x.Deserialize(stm); foreach (KeyBinding saved in km.KeyBindings) { foreach (KeyBinding kb in loadedKeyMap.KeyBindings) { // We found a saved keybinding, use its settings instead if (saved.Alias.Equals(kb.Alias)) { kb.Alt = saved.Alt; kb.Ctrl = saved.Ctrl; kb.Key = saved.Key; kb.KeyEvent = saved.KeyEvent; kb.Shift = saved.Shift; } } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Error in LoadKeyMap " + e.Message); } finally { if (stm != null) stm.Close(); } return loadedKeyMap; }
public KeyMap(KeyMap other) { Game = other.Game; KeyBindings = new List<KeyBinding>(other.KeyBindings); }
public static void SaveKeyMap(KeyMap km) { XmlSerializer x = new XmlSerializer(typeof(KeyMap)); StreamWriter stm = null; try { string filepath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\CnJ Xna Physics\\KeyBindings\\" + km.Game + ".xml"; if (!Directory.Exists(filepath)) { string dirpath = Path.GetDirectoryName(filepath); Directory.CreateDirectory(dirpath); } stm = new StreamWriter(filepath); x.Serialize(stm, km); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Error in SaveKeyMap " + e.Message); } finally { if(stm != null) stm.Close(); } }