public static InputBindingDevices LoadFromFile(string fileName)
        {
            if (!File.Exists(fileName))
            {
                return(null);
            }

            var result     = new InputBindingDevices();
            var serializer = new CustomXmlSerializer();

            serializer.ReadXml(fileName, result);

            // If there was no format version, assume it was version 1.
            if (result.FormatVersion <= 0)
            {
                result.FormatVersion = 1;
            }

            // Format Version 1 skipped the "Console" device.
            if (result.FormatVersion == 1)
            {
                result.devices.Insert(0, new InputBindingDevice());
            }

            return(result);
        }
Example #2
0
        public JohnnyInputSettings(InputBindingDevices originalDeviceBindings, string bindingsFilePath)
        {
            this.devices          = (InputBindingDevices)originalDeviceBindings.Clone();
            this.BindingsFilePath = bindingsFilePath;

            this.DialogResult = DialogResult.Cancel;

            this.InitializeComponent();

            // This form requires 6 devices.
            while (this.devices.Count < 6)
            {
                this.devices.AddDevice();
            }
        }
        public static InputBindingDevices LoadDefault()
        {
            var newSettings = new InputBindingDevices();

            var device = newSettings.AddDevice();
            var set    = device.BindingSets.AddSet();

            set.SetBinding(InputButton.Up, new KeyboardInputTrigger(Keys.W));
            set.SetBinding(InputButton.Down, new KeyboardInputTrigger(Keys.S));
            set.SetBinding(InputButton.Left, new KeyboardInputTrigger(Keys.A));
            set.SetBinding(InputButton.Right, new KeyboardInputTrigger(Keys.D));
            set.SetBinding(InputButton.A, new KeyboardInputTrigger(Keys.J));
            set.SetBinding(InputButton.B, new KeyboardInputTrigger(Keys.K));
            set.SetBinding(InputButton.C, new KeyboardInputTrigger(Keys.L));
            set.SetBinding(InputButton.X, new KeyboardInputTrigger(Keys.Q));
            set.SetBinding(InputButton.P, new KeyboardInputTrigger(Keys.E));
            set.SetBinding(InputButton.L, new KeyboardInputTrigger(Keys.LShiftKey));
            set.SetBinding(InputButton.R, new KeyboardInputTrigger(Keys.OemQuestion));

            return(newSettings);
        }
Example #4
0
        private void LoadKeys()
        {
            InputBindingDevices newDevices = null;

            try
            {
                newDevices = InputBindingDevices.LoadFromFile(JohnnyInputPlugin.bindingsFilePath);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed when loading bindings: " + ex.ToString());
            }

            if (newDevices == null)
            {
                newDevices = InputBindingDevices.LoadDefault();
            }

            /////////////
            // Use the new bindings.

            // TODO: Does this need to be thread protected?
            this.devices = newDevices;
        }