Example #1
0
        private void OnRendering(object sender, RenderingEventArgs args)
        {
            try {
                if (_devices == null || _states == null)
                {
                    return;
                }

                switch (MessageBoxResult)
                {
                case MessageBoxResult.No:
                    AlterValue(YesBar, false, null);
                    return;

                case MessageBoxResult.Yes:
                    AlterValue(NoBar, false, null);
                    return;
                }

                for (var index = _devices.Length - 1; index >= 0; index--)
                {
                    var joystick = _devices[index];
                    if (joystick == null || joystick.Disposed)
                    {
                        continue;
                    }

                    try {
                        if (!joystick.Acquire().IsFailure&& !joystick.Poll().IsFailure&& !Result.Last.IsFailure)
                        {
                            _states[index] = joystick.GetCurrentState();
                        }
                    } catch (DirectInputException e) when(e.Message.Contains(@"DIERR_UNPLUGGED"))
                    {
                        _devices[index] = null;
                    } catch (DirectInputException e) {
                        _devices[index] = null;
                        Logging.Warning(e);
                    }
                }

                var yes = _yes.IsPressed(_states);
                var no  = _no.IsPressed(_states);
                AlterValue(NoBar, no, NoCommand);
                AlterValue(YesBar, !no && yes, YesCommand);
            } finally {
                _inGameAppParams.YesProgress = YesBar.Value;
                _inGameAppParams.NoProgress  = NoBar.Value;
                _inGameApp.Update(_inGameAppParams);
            }
        }