Ejemplo n.º 1
0
        public void Load(IModuleContext context)
        {
            var settingsManager = context.ServiceLocator.GetInstance<ISettingsManager>();
            settingsManager.RegisterSettings<KeyboardBindingSettings>();
            settingsManager.RegisterSettings<GamepadBindingSettings>();
            settingsManager.RegisterSettings<InputSettings>();

            SetDefaults(settingsManager);

            InputManager inputManager = new InputManager();

            context.InputSourceAssembler.ConfigureInputSource((c) =>
                {
                    var settings = settingsManager.LoadSettings<InputSettings>(c);

                    if (settings.IsUserInputEnabled)
                    {
                        var bindings = settingsManager.LoadSettings<KeyboardBindingSettings>(c);
                        KeyboardInputSource keyboard = new KeyboardInputSource(inputManager.GetKeyboard(), bindings);
                        return keyboard;
                    }

                    return null;

                });


            context.InputSourceAssembler.ConfigureInputSource((c) =>
                {
                    var settings = settingsManager.LoadSettings<InputSettings>(c);

                    if (settings.IsUserInputEnabled)
                    {
                        CompositeInputSource cis = new CompositeInputSource();

                        for (Int32 i = 0; i < inputManager.GetJoystickCount(); i++)
                        {
                            var bindings = settingsManager.LoadSettings<GamepadBindingSettings>(c);

                            if (i == 0)
                            {
                                GamepadInputSource gamepad = new GamepadInputSource(inputManager.GetJoystick(i), bindings.Gamepad1Bindings);
                                cis.AddInputSource(gamepad);
                            }
                            else if (i == 1)
                            {
                                GamepadInputSource gamepad = new GamepadInputSource(inputManager.GetJoystick(i), bindings.Gamepad2Bindings);
                                cis.AddInputSource(gamepad);
                            }
                        }

                        return cis;
                    }

                    return null;
                });
        }
Ejemplo n.º 2
0
        public IInputSource BuildInputSource(EmulationContext context)
        {
            IInputSource inputSource = new CompositeInputSource(); ;

            foreach (var source in _inputSourceFactories)
            {
                var newSource = source.Invoke(context);
                if (newSource != null)
                {
                    ((CompositeInputSource)inputSource).AddInputSource(source.Invoke(context));
                }
            }

            foreach (var configuration in _inputSourceConfigurations)
            {
                inputSource = configuration.Invoke(context, inputSource);
            }

            return inputSource;
        }