Esempio n. 1
0
        public void BuildDefaultSettings()
        {
            Joypads.Clear();
            JoypadSettings joypadSettings = new JoypadSettings();

            joypadSettings.Port   = 1;
            joypadSettings.Start  = joypadSettings.EncodeKeyboardMapping(Keys.Enter);
            joypadSettings.Select = joypadSettings.EncodeKeyboardMapping(Keys.Tab);
            joypadSettings.A      = joypadSettings.EncodeKeyboardMapping(Keys.Z);
            joypadSettings.B      = joypadSettings.EncodeKeyboardMapping(Keys.X);
            joypadSettings.Up     = joypadSettings.EncodeKeyboardMapping(Keys.Up);
            joypadSettings.Down   = joypadSettings.EncodeKeyboardMapping(Keys.Down);
            joypadSettings.Left   = joypadSettings.EncodeKeyboardMapping(Keys.Left);
            joypadSettings.Right  = joypadSettings.EncodeKeyboardMapping(Keys.Right);

            Joypads.Add(joypadSettings);

            ZapperSettings zapperSettings = new ZapperSettings();

            zapperSettings.Port       = 2;
            zapperSettings.Trigger    = "mouse:left";
            zapperSettings.LightSense = "mouse:cursor";

            Zappers.Add(zapperSettings);
        }
Esempio n. 2
0
        private void UpdateControllerLists()
        {
            Joypads.Clear();
            Zappers.Clear();

            foreach (ControllerSettings controllerSettings in controllerMap.Values)
            {
                if (controllerSettings is JoypadSettings)
                {
                    Joypads.Add((JoypadSettings)controllerSettings);
                }

                if (controllerSettings is ZapperSettings)
                {
                    Zappers.Add((ZapperSettings)controllerSettings);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Initialize this module.
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();

            HardwareInput = Host.Platform.GetInput(Host.Window);
            HardwareInput.Initialize();

            HardwareInput.JoypadConnection += (obj, e) =>
            {
                if (!InputStates.ContainsKey(e.Joypad))
                {
                    InputStates.Add(e.Joypad, new InputState());
                }

                if (e.Connected)
                {
                    Joypads.Add(new VirtualJoypad(InputStates?[e.Joypad], e.Joypad.Index, e.Joypad.Name));
                }
                else
                {
                    Joypads.RemoveAt(Joypads.FindIndex(x => x.Index == e.Joypad.Index));
                }

                JoypadConnection?.Invoke(obj, e);
            };

            InputStates.Add(HardwareKeyboard, new InputState());
            InputStates.Add(HardwareMouse, new InputState());

            HardwareKeyboard.OnTypeWithMods += HardwareKeyboard_OnTypeWithMods;
            HardwareKeyboard.OnKeyEvent     += HardwareKeyboard_OnKeyEvent;
            HardwareKeyboard.OnType         += HardwareKeyboard_OnType;

            HardwareMouse.OnButtonEvent += HardwareMouse_OnButtonEvent;
            HardwareMouse.OnScroll      += HardwareMouse_OnScroll;
            HardwareMouse.OnMove        += HardwareMouse_OnMove;

            foreach (var j in HardwareJoypads)
            {
                Joypads.Add(new VirtualJoypad(null, j.Index, j.Name));
            }
        }
Esempio n. 4
0
        public override void Initialize()
        {
            base.Initialize();

            JoypadConnection += (obj, e) =>
            {
                if (e.Connected)
                {
                    Joypads.Add(new VirtualJoypad(currentInputState?[e.Joypad], e.Joypad.Index, e.Joypad.Name));
                }
                else
                {
                    Joypads.RemoveAt(Joypads.FindIndex(x => x.Index == e.Joypad.Index));
                }
            };

            RunningLoop.Scheduler.AddDelayed(() =>
            {
                while (inputHistory.Count > 0)
                {
                    currentInputHistory.Clear();
                    inputHistory.TryDequeue(out DeviceStates state);

                    Mouse.UpdateCurrentState(state?[Module.HardwareMouse]);
                    Keyboard.UpdateCurrentState(state?[Module.HardwareKeyboard]);

                    Mouse.Update(RunningLoop.Clock);
                    Keyboard.Update(RunningLoop.Clock);

                    foreach (var j in Joypads)
                    {
                        j.UpdateCurrentState(state?[Module.HardwareJoypads.Where(x => x.Index == j.Index).FirstOrDefault()]);
                        j.Update(RunningLoop.Clock);
                    }

                    currentInputHistory.Add(state);
                }
            }, 0, true);
        }