Beispiel #1
0
        public InputDetectorWindow(IInputManager inputManager, InputDetectorDeviceFilter filter, IPresetElement presetElement, IEmulationSlot slot)
            : this(inputManager, filter)
        {
            this.InputDetectorTarget = InputDetectorTarget.Key;
            this.FunctionName        = this.RetrieveFunctionName(presetElement);
            this.GamepadName         = "on " + slot.Gamepad.FriendlyName;
            this.keyboard            = slot.Keyboard;
            this.mouse = slot.Mouse;
            this.Title = "Waiting for ";
            switch (this.DeviceFilter)
            {
            case InputDetectorDeviceFilter.KeyboardOnly:
                this.Title += this.keyboard.StrongName;
                break;

            case InputDetectorDeviceFilter.MouseOnly:
                this.Title += this.mouse.StrongName;
                break;

            case InputDetectorDeviceFilter.KeyboardAndMouse:
                this.Title += this.keyboard.StrongName + " and " + this.mouse.StrongName;
                break;

            default:
                break;
            }

            this.Title += " input...";
        }
Beispiel #2
0
        public InputDetectorWindow(IInputManager inputManager, InputDetectorDeviceFilter filter)
        {
            this.InitializeComponent();
            if (inputManager == null)
            {
                throw new ArgumentNullException("inputManager");
            }

            this.inputManager = inputManager;
            this.inputManager.InputActivity += this.OnInputActivity;
            this.DeviceFilter        = filter;
            this.InputDetectorTarget = InputDetectorTarget.Device;
            switch (this.DeviceFilter)
            {
            case InputDetectorDeviceFilter.KeyboardOnly:
                this.Title = "Keyboard detector";
                break;

            case InputDetectorDeviceFilter.MouseOnly:
                this.Title = "Mouse detector";
                break;

            case InputDetectorDeviceFilter.KeyboardAndMouse:
                this.Title = "Error: Wrong device filter passed!";
                break;

            default:
                this.Title = "Not implemented device filter passed!";
                break;
            }
        }
        private void OnDetectKeyRequested(object parameter)
        {
            var presetElement = parameter as IPresetElement;

            if (presetElement == null)
            {
                return;
            }

            var slot = Helpers.ParentFinder.FindParent <EmulationSlot>(this);

            if (slot == null)
            {
                return;
            }

            var mainWindow = Application.Current.MainWindow as MainWindow;

            if (mainWindow == null)
            {
                return;
            }

            var splitter = mainWindow.Splitter;

            if (splitter == null)
            {
                return;
            }

            bool isKeyboardSet = slot.Keyboard != null && slot.Keyboard != Keyboard.None;
            bool isMouseSet    = slot.Mouse != null && slot.Mouse != Mouse.None;

            if (!isKeyboardSet && !isMouseSet)
            {
                Controls.MessageBox.Show(
                    "You can not detect an input key, because the slot is not assosiated with any valid input device!",
                    ApplicationInfo.AppNameVersion,
                    MessageBoxButton.OK,
                    MessageBoxImage.Hand);

                return;
            }

            InputDetectorDeviceFilter filter = InputDetectorDeviceFilter.KeyboardAndMouse;

            if (isKeyboardSet && !isMouseSet)
            {
                filter = InputDetectorDeviceFilter.KeyboardOnly;
            }

            if (isMouseSet && !isKeyboardSet)
            {
                filter = InputDetectorDeviceFilter.MouseOnly;
            }

            var detector = new InputDetectorWindow(splitter.InputManager, filter, presetElement, slot);

            detector.Owner = mainWindow;
            detector.WindowStartupLocation = WindowStartupLocation.CenterOwner;

            InputKey newKey = InputKey.None;

            detector.InputDetected += (ss, ee) =>
            {
                newKey = ee.Key;
                detector.Close();
            };

            detector.ShowDialog();
            if (newKey == InputKey.None)
            {
                return;
            }

            int index = 0;

            switch (presetElement.FunctionType)
            {
            case SplitterCore.FunctionType.Button:
                index = this.Preset.Buttons.IndexOf(presetElement as PresetButton);
                this.Preset.Buttons[index] = new PresetButton(this.Preset.Buttons[index].Button, newKey);
                break;

            case SplitterCore.FunctionType.Trigger:
                index = this.Preset.Triggers.IndexOf(presetElement as PresetTrigger);
                this.Preset.Triggers[index] = new PresetTrigger(this.Preset.Triggers[index].Trigger, newKey);
                break;

            case SplitterCore.FunctionType.Axis:
                index = this.Preset.Axes.IndexOf(presetElement as PresetAxis);
                this.Preset.Axes[index] = new PresetAxis(this.Preset.Axes[index].Axis, this.Preset.Axes[index].Value, newKey);
                break;

            case SplitterCore.FunctionType.Dpad:
                index = this.Preset.Dpads.IndexOf(presetElement as PresetDpad);
                this.Preset.Dpads[index] = new PresetDpad(this.Preset.Dpads[index].Direction, newKey);
                break;

            case SplitterCore.FunctionType.Custom:
                index = this.Preset.CustomFunctions.IndexOf(presetElement as PresetCustom);
                this.Preset.CustomFunctions[index] = new PresetCustom(this.Preset.CustomFunctions[index].Function, newKey);
                break;

            default:
                break;
            }
        }