public WindowCommands GetRightWindowCommands() { var windowCommands = new WindowCommands(); var refreshButton = WindowCommandHelper.CreateWindowCommandButton("appbar_refresh_counterclockwise_down", "refresh"); refreshButton.SetCurrentValue(System.Windows.Controls.Primitives.ButtonBase.CommandProperty, _commandManager.GetCommand("File.Refresh")); _commandManager.RegisterAction("File.Refresh", () => _messageService.ShowAsync("Refresh")); windowCommands.Items.Add(refreshButton); var saveButton = WindowCommandHelper.CreateWindowCommandButton("appbar_save", "save"); saveButton.SetCurrentValue(System.Windows.Controls.Primitives.ButtonBase.CommandProperty, _commandManager.GetCommand("File.Save")); _commandManager.RegisterAction("File.Save", () => _messageService.ShowAsync("Save")); windowCommands.Items.Add(saveButton); var showWindowButton = WindowCommandHelper.CreateWindowCommandButton("appbar_new_window", "show dialog window"); showWindowButton.SetCurrentValue(System.Windows.Controls.Primitives.ButtonBase.CommandProperty, new TaskCommand(() => _uiVisualizerService.ShowDialogAsync <ExampleDialogViewModel>())); windowCommands.Items.Add(showWindowButton); var showDataWindowButton = WindowCommandHelper.CreateWindowCommandButton("appbar_new_window", "show data window"); showDataWindowButton.SetCurrentValue(System.Windows.Controls.Primitives.ButtonBase.CommandProperty, new TaskCommand(() => _uiVisualizerService.ShowDialogAsync <ExampleDataViewModel>())); windowCommands.Items.Add(showDataWindowButton); return(windowCommands); }
public WindowCommands GetRightWindowCommands() { var windowCommands = new WindowCommands(); var refreshButton = WindowCommandHelper.CreateWindowCommandButton("appbar_refresh_counterclockwise_down", "refresh"); refreshButton.Command = _commandManager.GetCommand("File.Refresh"); _commandManager.RegisterAction("File.Refresh", () => _messageService.ShowAsync("Refresh")); windowCommands.Items.Add(refreshButton); var saveButton = WindowCommandHelper.CreateWindowCommandButton("appbar_save", "save"); saveButton.Command = _commandManager.GetCommand("File.Save"); _commandManager.RegisterAction("File.Save", () => _messageService.ShowAsync("Save")); windowCommands.Items.Add(saveButton); var showWindowButton = WindowCommandHelper.CreateWindowCommandButton("appbar_new_window", "show dialog window"); showWindowButton.Command = new Command(() => _uiVisualizerService.ShowDialog <ExampleDialogViewModel>()); windowCommands.Items.Add(showWindowButton); var showDataWindowButton = WindowCommandHelper.CreateWindowCommandButton("appbar_new_window", "show data window"); showDataWindowButton.Command = new Command(() => _uiVisualizerService.ShowDialog <ExampleDataViewModel>()); windowCommands.Items.Add(showDataWindowButton); return(windowCommands); }
private async Task TurnScreen(CancellationToken cancellationToken) { for (var i = 0; i < 15; i++) { WindowCommandHelper.PressKey(_hWnd, WindowCommandHelper.KeyCodes.Right); await Task.Delay(TimeSpan.FromSeconds(0.1), cancellationToken); } }
/// <summary> /// Initializes a new instance of the <see cref="ShellWindow"/> class. /// </summary> public ShellWindow() { ThemeHelper.EnsureApplicationThemes(GetType().Assembly, true); MahAppsHelper.ApplyTheme(); InitializeComponent(); var accentColorBrush = ThemeHelper.GetAccentColorBrush(); border.BorderBrush = accentColorBrush; var serviceLocator = ServiceLocator.Default; var statusService = serviceLocator.ResolveType <IStatusService>(); statusService.Initialize(statusTextBlock); var commandManager = serviceLocator.ResolveType <ICommandManager>(); var flyoutService = serviceLocator.ResolveType <IFlyoutService>(); var mahAppsService = serviceLocator.ResolveType <IMahAppsService>(); serviceLocator.RegisterInstance <IAboutInfoService>(mahAppsService); var flyouts = new FlyoutsControl(); foreach (var flyout in flyoutService.GetFlyouts()) { flyouts.Items.Add(flyout); } Flyouts = flyouts; var windowCommands = mahAppsService.GetRightWindowCommands(); if (mahAppsService.GetAboutInfo() != null) { var aboutWindowCommand = WindowCommandHelper.CreateWindowCommandButton("appbar_information", "about"); var aboutService = serviceLocator.ResolveType <IAboutService>(); commandManager.RegisterAction("Help.About", aboutService.ShowAbout); aboutWindowCommand.Command = commandManager.GetCommand("Help.About"); windowCommands.Items.Add(aboutWindowCommand); } RightWindowCommands = windowCommands; var mainView = mahAppsService.GetMainView(); contentControl.Content = mainView; SetBinding(TitleProperty, new Binding("ViewModel.Title") { Source = mainView }); }
private static void OnIsBindingToSystemCommandsChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) { var newValue = (bool)args.NewValue; if (obj is Window window && newValue) { var service = new WindowCommandHelper(window); service.ActiveCommands(); } }
private async Task <bool> SelectGoodTarget(CancellationToken cancellationToken, [NotNull] Bitmap screenshot) { if (screenshot == null) { throw new ArgumentNullException(nameof(screenshot)); } var screenshotWithExclude = ScreenshotHelper.ApplyExclude(_settings.ExcludeInfo.Data, screenshot); OnScreenCapture(new Bitmap(screenshotWithExclude)); var src = Mat.FromImageData(BitmapHelper.ImageToByte2(screenshotWithExclude)); var blacked = new Mat(); Cv2.Threshold(src, blacked, 127, 255, ThresholdTypes.Binary); var blackedBitmap = blacked.ToBitmap(); var targets = GetTargets(blackedBitmap); foreach (var target in targets) { WindowCommandHelper.LeftClick(target); var screenshotWithHp = ScreenshotHelper.GetScreenBitmap(_hWnd); var targetHealth = ScreenshotHelper.GetSubPart(screenshotWithHp, _settings.RegionInfo.TargetHp); var targetHealthPercent = GetTargetHpPercent(targetHealth); OnReport($"Target health: {targetHealthPercent}"); if (targetHealthPercent > 0) { return(true); } OnReport($"Target is dead or neutral"); await Task.Delay(TimeSpan.FromSeconds(0.5), cancellationToken); } var screenshotWithHp2 = ScreenshotHelper.GetScreenBitmap(_hWnd); var targetHealth2 = ScreenshotHelper.GetSubPart(screenshotWithHp2, _settings.RegionInfo.TargetHp); var targetHealthPercent2 = GetTargetHpPercent(targetHealth2); OnReport($"Target health: {targetHealthPercent2}"); if (targetHealthPercent2 > 0) { return(true); } OnReport($"Target is dead or neutral"); await Task.Delay(TimeSpan.FromSeconds(0.5), cancellationToken); return(false); }
internal MasterProcessor(IntPtr hWnd, [NotNull] SkSettings settings, IntPtr?_slaveIntPtr) { _hWnd = hWnd; _settings = settings ?? throw new ArgumentNullException(nameof(settings)); this._slaveIntPtr = _slaveIntPtr; _timer.Interval = TimeSpan.FromSeconds(30).TotalMilliseconds; _timer.Elapsed += (sender, args) => { _timer.Stop(); WindowCommandHelper.PressKey(_hWnd, WindowCommandHelper.KeyCodes.F6); }; _timer.AutoReset = false; }
private async Task FightTarget(CancellationToken cancellationToken) { _timer.Stop(); OnReport($"Target found!"); while (!cancellationToken.IsCancellationRequested) { var screenshot = ScreenshotHelper.GetScreenBitmap(_hWnd); var targetHealth = ScreenshotHelper.GetSubPart(screenshot, _settings.RegionInfo.TargetHp); var targetHealthPercent = GetTargetHpPercent(targetHealth); var myHealth = ScreenshotHelper.GetSubPart(screenshot, _settings.RegionInfo.MyHp); var myHealthPercent = GetMyHpPercent(myHealth); if (Math.Abs(myHealthPercent) < 100 && _slaveIntPtr.HasValue) { OnReport("Request self heal"); WindowCommandHelper.PressKey(_slaveIntPtr.Value, WindowCommandHelper.KeyCodes.F7); await Task.Delay(TimeSpan.FromSeconds(1)); WindowCommandHelper.PressKey(_slaveIntPtr.Value, WindowCommandHelper.KeyCodes.F3); } OnReport($"Target HP: {targetHealthPercent:###.##}% MY: {myHealthPercent:###.##}%"); if (Math.Abs(targetHealthPercent) < 0.00001) { break; } WindowCommandHelper.PressKey(_hWnd, WindowCommandHelper.KeyCodes.F1); await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken); } OnReport($"Target is dead!"); WindowCommandHelper.PressKey(_hWnd, WindowCommandHelper.KeyCodes.F4); await Task.Delay(TimeSpan.FromSeconds(2), cancellationToken); WindowCommandHelper.PressKey(_hWnd, WindowCommandHelper.KeyCodes.F4); await Task.Delay(TimeSpan.FromSeconds(2), cancellationToken); WindowCommandHelper.PressKey(_hWnd, WindowCommandHelper.KeyCodes.F4); await Task.Delay(TimeSpan.FromSeconds(2), cancellationToken); WindowCommandHelper.PressKey(_hWnd, WindowCommandHelper.KeyCodes.F4); }
private void SetupRightCommands( IServiceLocator serviceLocator, IMahAppsService mahAppsService, ICommandManager commandManager) { var windowCommands = mahAppsService.GetRightWindowCommands(); if (mahAppsService.GetAboutInfo() != null) { var aboutWindowCommand = WindowCommandHelper.CreateWindowCommandButton("appbar_information", "about"); var aboutService = serviceLocator.ResolveType <IAboutService>(); commandManager.RegisterAction("Help.About", aboutService.ShowAbout); aboutWindowCommand.Command = commandManager.GetCommand("Help.About"); windowCommands.Items.Add(aboutWindowCommand); } RightWindowCommands = windowCommands; }
public WindowCommands GetRightWindowCommands() { var windowCommands = new WindowCommands(); var refreshButton = WindowCommandHelper.CreateWindowCommandButton(new PackIconMaterial { Kind = PackIconMaterialKind.Refresh }, "Refresh"); refreshButton.SetCurrentValue(System.Windows.Controls.Primitives.ButtonBase.CommandProperty, _commandManager.GetCommand("File.Refresh")); _commandManager.RegisterAction("File.Refresh", () => _messageService.ShowAsync("Refresh")); windowCommands.Items.Add(refreshButton); var saveButton = WindowCommandHelper.CreateWindowCommandButton(new PackIconMaterial { Kind = PackIconMaterialKind.ContentSave }, "Save"); saveButton.SetCurrentValue(System.Windows.Controls.Primitives.ButtonBase.CommandProperty, _commandManager.GetCommand("File.Save")); _commandManager.RegisterAction("File.Save", () => _messageService.ShowAsync("Save")); windowCommands.Items.Add(saveButton); var showWindowButton = WindowCommandHelper.CreateWindowCommandButton(new PackIconMaterial { Kind = PackIconMaterialKind.OpenInNew }, "Show dialog window"); showWindowButton.SetCurrentValue(System.Windows.Controls.Primitives.ButtonBase.CommandProperty, new TaskCommand(() => _uiVisualizerService.ShowDialogAsync <ExampleDialogViewModel>())); windowCommands.Items.Add(showWindowButton); var showDataWindowButton = WindowCommandHelper.CreateWindowCommandButton(new PackIconMaterial { Kind = PackIconMaterialKind.OpenInNew }, "Show data window"); showDataWindowButton.SetCurrentValue(System.Windows.Controls.Primitives.ButtonBase.CommandProperty, new TaskCommand(() => _uiVisualizerService.ShowDialogAsync <ExampleDataViewModel>())); windowCommands.Items.Add(showDataWindowButton); return(windowCommands); }
/// <summary> /// Initializes a new instance of the <see cref="ShellWindow"/> class. /// </summary> public ShellWindow() : base(DataWindowMode.Custom, setOwnerAndFocus: false) { var serviceLocator = ServiceLocator.Default; InitializeComponent(); statusBar.Background = Orc.Controls.ThemeHelper.GetAccentColorBrush(Orc.Controls.AccentColorStyle.AccentColor4); serviceLocator.RegisterInstance(pleaseWaitProgressBar, "pleaseWaitService"); var statusService = serviceLocator.ResolveType <IStatusService>(); statusService.Initialize(statusTextBlock); var commandManager = serviceLocator.ResolveType <ICommandManager>(); var flyoutService = serviceLocator.ResolveType <IFlyoutService>(); var mahAppsService = serviceLocator.ResolveType <IMahAppsService>(); serviceLocator.RegisterInstance <IAboutInfoService>(mahAppsService); var flyouts = new FlyoutsControl(); foreach (var flyout in flyoutService.GetFlyouts()) { flyouts.Items.Add(flyout); } Flyouts = flyouts; var windowCommands = mahAppsService.GetRightWindowCommands(); if (mahAppsService.GetAboutInfo() != null) { var aboutWindowCommand = WindowCommandHelper.CreateWindowCommandButton("appbar_information", "about"); var aboutService = serviceLocator.ResolveType <IAboutService>(); #pragma warning disable AvoidAsyncVoid // Avoid async void commandManager.RegisterAction("Help.About", async() => await aboutService.ShowAboutAsync()); #pragma warning restore AvoidAsyncVoid // Avoid async void aboutWindowCommand.SetCurrentValue(System.Windows.Controls.Primitives.ButtonBase.CommandProperty, commandManager.GetCommand("Help.About")); windowCommands.Items.Add(aboutWindowCommand); } RightWindowCommands = windowCommands; var statusBarContent = mahAppsService.GetStatusBar(); if (statusBarContent != null) { customStatusBarItem.SetCurrentValue(ContentProperty, statusBarContent); } var mainView = mahAppsService.GetMainView(); contentControl.Content = mainView; ShellDimensionsHelper.ApplyDimensions(this, mainView); SetBinding(TitleProperty, new Binding("ViewModel.Title") { Source = mainView }); }
/// <summary> /// Initializes a new instance of the <see cref="ShellWindow"/> class. /// </summary> public ShellWindow() : base(DataWindowMode.Custom, setOwnerAndFocus: false) { var serviceLocator = ServiceLocator.Default; InitializeComponent(); statusBar.Background = ThemeHelper.GetAccentColorBrush(AccentColorStyle.AccentColor4); serviceLocator.RegisterInstance(pleaseWaitProgressBar, "pleaseWaitService"); var statusService = serviceLocator.ResolveType <IStatusService>(); statusService.Initialize(statusTextBlock); var commandManager = serviceLocator.ResolveType <ICommandManager>(); var flyoutService = serviceLocator.ResolveType <IFlyoutService>(); var mahAppsService = serviceLocator.ResolveType <IMahAppsService>(); serviceLocator.RegisterInstance <IAboutInfoService>(mahAppsService); var flyouts = new FlyoutsControl(); foreach (var flyout in flyoutService.GetFlyouts()) { flyouts.Items.Add(flyout); } Flyouts = flyouts; var windowCommands = mahAppsService.GetRightWindowCommands(); if (mahAppsService.GetAboutInfo() != null) { var aboutWindowCommand = WindowCommandHelper.CreateWindowCommandButton("appbar_information", "about"); var aboutService = serviceLocator.ResolveType <IAboutService>(); commandManager.RegisterAction("Help.About", aboutService.ShowAbout); aboutWindowCommand.Command = commandManager.GetCommand("Help.About"); windowCommands.Items.Add(aboutWindowCommand); } RightWindowCommands = windowCommands; var statusBarContent = mahAppsService.GetStatusBar(); if (statusBarContent != null) { customStatusBarItem.Content = statusBarContent; } var mainView = mahAppsService.GetMainView(); contentControl.Content = mainView; SetBinding(TitleProperty, new Binding("ViewModel.Title") { Source = mainView }); }