Exemple #1
0
        internal override void Load(InputMap savedMap)
        {
            if (savedMap is AnalogMap == false)
            {
                throw new Exception("AnalogMap attempting to load type other than AnalogMap");
            }

            AnalogMap savedAnalogMap = savedMap as AnalogMap;

            foreach (AnalogBinding saved in savedAnalogMap.AnalogBindings.Values)
            {
                if (AnalogBindings.ContainsKey(saved.Alias))
                {
                    AnalogBinding binding = AnalogBindings[saved.Alias];

                    if (binding.GetType().Equals(saved) == false)
                    {
                        throw new Exception("Error loading Button Bindings: Saved binding is not a same type as default binding");
                    }

                    if (binding is GamePadThumbStickBinding)
                    {
                        GamePadThumbStickBinding gpjb  = binding as GamePadThumbStickBinding;
                        GamePadThumbStickBinding other = saved as GamePadThumbStickBinding;
                    }
                }
            }
        }
        /// <summary>
        /// Adds a keymap to the collection
        /// </summary>
        /// <param name="keyMap"></param>
        public void AddMap(InputMap keyMap)
        {
            string alias = keyMap.Alias;

            if (inputMaps.ContainsKey(alias))
            {
                throw new ArgumentException("A Button Map group by the name " + alias + " already exists. Use a different name.");
            }
            inputMaps.Add(alias, keyMap);
        }
Exemple #3
0
        internal override void Load(InputMap savedMap)
        {
            if (savedMap is ButtonMap == false)
            {
                throw new Exception("ButtonMap attempting to load type other than ButtonMap");
            }

            ButtonMap savedButtonMap = savedMap as ButtonMap;

            foreach (ButtonBinding saved in savedButtonMap.ButtonBindings.Values)
            {
                if (this.ButtonBindings.ContainsKey(saved.Alias))
                {
                    ButtonBinding binding = ButtonBindings[saved.Alias];

                    if (binding.GetType().Equals(saved) == false)
                    {
                        throw new Exception("Error loading Button Bindings: Saved binding is not a same type as default binding");
                    }


                    if (binding is KeyBinding)
                    {
                        KeyBinding kb    = binding as KeyBinding;
                        KeyBinding other = saved as KeyBinding;
                        kb.Key       = other.Key;
                        kb.Modifiers = other.Modifiers;
                    }
                    else if (binding is GamePadButtonBinding)
                    {
                        GamePadButtonBinding gb    = binding as GamePadButtonBinding;
                        GamePadButtonBinding other = saved as GamePadButtonBinding;
                        gb.Button = other.Button;
                    }
                    else
                    {
                        throw new Exception("Unknown ButtonBinding type being loaded. Did you add a new type and forget to handle loading?");
                    }
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Adds controls (custom tab pages containing keybindingControls) for displaying each keybinding
        /// </summary>
        public void AddKeyBindingGuiControls()
        {
            for (int kmi = 0; kmi < keyMaps.inputMaps.Count; kmi++)
            {
                FlowLayoutTabPage fltp = new FlowLayoutTabPage();
                tcControlGroups.TabPages.Add(fltp);
                InputMap im = keyMaps.inputMaps.Values[kmi];
                if (im is ButtonMap == false)
                {
                    continue;
                }
                ButtonMap bm = im as ButtonMap;
                fltp.Text = bm.Alias;
                foreach (Input.KeyBinding kb in bm.ButtonBindings.Values)
                {
                    KeyBindingControl kbc = new KeyBindingControl(kb);

                    fltp.AddControl(kbc);
                }
            }
        }
        public static InputCollection Load(string game, InputCollection defaultButtonMap)
        {
            DataContractSerializer x = new DataContractSerializer(typeof(InputCollection));
            InputCollection        finalCollection = new InputCollection(defaultButtonMap);
            StreamReader           stm             = null;

            try
            {
                string filepath = InputCollection.GetSettingsPath(game);
                stm = new StreamReader(filepath);

                InputCollection savedCollection = (InputCollection)x.ReadObject(stm.BaseStream);

                foreach (InputMap finalim in finalCollection.inputMaps.Values)
                {
                    // if tha keymap by this name exists on disk
                    if (savedCollection.inputMaps.ContainsKey(finalim.Alias))
                    {
                        InputMap savedkm = savedCollection.inputMaps[finalim.Alias];
                        // load those preferences, overriding the defaults
                        finalim.Load(savedkm);
                    }
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Error in loading an InputMap " + e.StackTrace);
            }
            finally
            {
                if (stm != null)
                {
                    stm.Close();
                }
            }
            return(finalCollection);
        }
Exemple #6
0
 internal abstract void Load(InputMap savedMap);