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