public GamepadScanner(IGamepadHelper gamepadHelper, IGamepadRemote remote)
 {
     _remote        = remote;
     _gamepadHelper = gamepadHelper;
     _stopWatches   = gamepadHelper.GetControllers(false)
                      .Select((controller) => new KeyValuePair <UserIndex, Stopwatch>(controller.UserIndex, new Stopwatch()))
                      .ToDictionary(x => x.Key, x => x.Value);
 }
示例#2
0
        public Context(IGamepadScanner gamepadScanner, IGamepadHelper gamepadHelper, IGamepadRemote gamepadRemote, string appName, string appVersion)
        {
            _regController    = new RegistryController();
            _contextMenuStrip = new ContextMenuStrip();

            _gamepadScanner = gamepadScanner;
            _gamepadHelper  = gamepadHelper;
            _gamepadRemote  = gamepadRemote;
            _appName        = appName;
            _appVersion     = appVersion;

            _notifyIcon = new NotifyIcon
            {
                Icon             = Properties.Resources.AppIcon,
                Text             = _appName,
                Visible          = true,
                ContextMenuStrip = _contextMenuStrip
            };
            _notifyIcon.ContextMenuStrip.Opening += ContextMenuStrip_Opening;
            _notifyIcon.Click += notifyIcon_Click;

            _gamepadScanner.SetGuideButton(_regController.IsGuideButtonEnabled(_appName));
            _gamepadScanner.SetLowBatteryWarning(_regController.IsLowBatteryWarningEnabled(_appName));
            _gamepadScanner.OnBatteryInfoPressed(controller =>
            {
                _notifyIcon.BalloonTipText = $@"Controller {(int)controller.UserIndex + 1} ({controller.GetBatteryInformation(BatteryDeviceType.Gamepad).BatteryLevel.ToString().ToUpperInvariant()})";
                _notifyIcon.ShowBalloonTip(TimeSpan.FromSeconds(5).Milliseconds);
            });
            _gamepadScanner.OnBatteryLow(controller =>
            {
                _notifyIcon.BalloonTipText = $@"WARNING: Controller {(int)controller.UserIndex + 1} ({controller.GetBatteryInformation(BatteryDeviceType.Gamepad).BatteryLevel.ToString().ToUpperInvariant()})";
                _notifyIcon.ShowBalloonTip(TimeSpan.FromSeconds(5).Milliseconds);
            });

            _toolStripMenuItemVersion = new ToolStripMenuItem($"Version: {_appVersion}")
            {
                Image = Images.Resource.AppIcon
            };
            _toolStripMenuItemExit = new ToolStripMenuItem("Exit")
            {
                Image = Images.Resource.Exit
            };
            _toolStripMenuItemExit.Click += ClickToolStripMenuItemExit;

            _toolStripMenuItemAutoStartup = new ToolStripMenuItem("Run at startup")
            {
                Checked = _regController.IsProgramRegistered(_appName) && _regController.IsStartupPathUnchanged(_appName, Application.ExecutablePath)
            };
            _toolStripMenuItemAutoStartup.CheckedChanged += toolStripMenuItemAutoStartup_CheckedChanged;
            _toolStripMenuItemAutoStartup.Click          += (sender, args) =>
            {
                _toolStripMenuItemAutoStartup.Checked = !_toolStripMenuItemAutoStartup.Checked;
            };

            _toolStripMenuItemUseGuideButton = new ToolStripMenuItem("Use the 'Guide' button to turn off a controller")
            {
                Checked = _regController.IsGuideButtonEnabled(_appName)
            };
            _toolStripMenuItemUseGuideButton.CheckedChanged += ToolStripMenuItemUseGuideButton_CheckedChanged;
            _toolStripMenuItemUseGuideButton.Click          += (sender, args) =>
            {
                _toolStripMenuItemUseGuideButton.Checked = !_toolStripMenuItemUseGuideButton.Checked;
            };

            _toolStripMenuItemLowBatteryWarning = new ToolStripMenuItem("Show low battery warnings")
            {
                Checked = _regController.IsLowBatteryWarningEnabled(_appName)
            };
            _toolStripMenuItemLowBatteryWarning.CheckedChanged += toolStripMenuItemLowBatteryWarning_CheckedChanged;
            _toolStripMenuItemLowBatteryWarning.Click          += (sender, args) =>
            {
                _toolStripMenuItemLowBatteryWarning.Checked = !_toolStripMenuItemLowBatteryWarning.Checked;
            };

            Task.Factory.StartNew(() => ContextMenuStrip_Opening(null, null));
            Task.Factory.StartNew(_gamepadScanner.Start);
        }