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); }
//private bool running = false; public MainWindow(IInputHelper inputHelper, IOverlayHelper overlayHelper, IGamepadHelper gamepadHelper) { InitializeComponent(); this.gamepadHelper = gamepadHelper; this.gamepadHelper.OnConnected += GamepadHelper_OnConnected; this.gamepadHelper.OnDisconnected += GamepadHelper_OnDisconnected; this.gamepadHelper.OnButtonUp += GamepadHelper_OnButtonUp; this.gamepadHelper.OnButtonDown += GamepadHelper_OnButtonDown; this.gamepadHelper.OnAnalogUpdate += GamepadHelper_OnAnalogUpdate; timer = new Timer(5); timer.Elapsed += Timer_Elapsed; profileManager = new ProfileManager(AppDomain.CurrentDomain.BaseDirectory, (int)SystemParameters.PrimaryScreenWidth, (int)SystemParameters.PrimaryScreenHeight); profileManager.ReloadProfiles(); gamepadBasicTranslator = new BasicTranslator(inputHelper); gamepadAimOverlayTranslator = new OverlayAimTranslator(inputHelper, overlayHelper); ViewModel = new AppViewModel { ProfileManager = profileManager, Profile = profileManager.Profiles[ProfileManager.DefaultProfile], GamepadTranslator = gamepadAimOverlayTranslator, GamepadIndex = 0, Gamepads = new List <KeyValuePair <int, string> > { new KeyValuePair <int, string>(0, "Gamepad 0"), new KeyValuePair <int, string>(1, "Gamepad 1"), new KeyValuePair <int, string>(2, "Gamepad 2"), new KeyValuePair <int, string>(3, "Gamepad 3"), }, Running = false }; DataContext = ViewModel; ReloadConfigurations(); ViewModel.Status = "Startup finished"; }
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); }