Example #1
0
 public InputManager(String gameName, KeyMap defaultKeyMap)
 {
     game               = gameName;
     keyMap             = KeyMap.LoadKeyMap(game, defaultKeyMap);
     Mode               = InputMode.Mapped;
     InputModeDelegates = new SortedList <InputMode, Delegate>();
 }
Example #2
0
        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();
                }
            }
        }
Example #3
0
 public InputManager(String gameName, KeyMap defaultKeyMap)
 {
     game = gameName;
     keyMap = KeyMap.LoadKeyMap(game, defaultKeyMap);
     Mode = InputMode.Mapped;
     InputModeDelegates = new SortedList<InputMode, Delegate>();
 }
Example #4
0
        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;
        }
Example #5
0
        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);
        }
Example #6
0
 public KeyMap(KeyMap other)
 {
     Game        = other.Game;
     KeyBindings = new List <KeyBinding>(other.KeyBindings);
 }
Example #7
0
 public Settings(KeyMap km)
 {
     InitializeComponent();
     keyMap = km;
     AddKeys();
 }
Example #8
0
 public Settings(KeyMap km)
 {
     InitializeComponent();
     keyMap = km;
     AddKeys();
 }
Example #9
0
 public void Save()
 {
     KeyMap.SaveKeyMap(keyMap);
 }
Example #10
0
 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;
 }
Example #11
0
        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;
        }
Example #12
0
 public KeyMap(KeyMap other)
 {
     Game = other.Game;
     KeyBindings = new List<KeyBinding>(other.KeyBindings);
 }
Example #13
0
 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();
     }
 }