private void SaveTheRoute_Click(object sender, RoutedEventArgs e) { var routeName = NewRouteNameBox.Text; if (string.IsNullOrEmpty(routeName)) { return; } if (!_builded) { MessageBox.Show( TranslationEngine.GetDynamicTranslationString("%ERR_BUILD_THE_ROUTE%", "Build the route first"), "Routing error", MessageBoxButton.OK, MessageBoxImage.Information); return; } if ( _globalSettings.Routes.Any( x => string.Equals(x.Name, routeName, StringComparison.CurrentCultureIgnoreCase))) { routeName += "_" + DeviceSettings.RandomString(5); } var route = new BotRoute { Name = routeName, InitialWp = _mapPoints.Select(x => x.Location).ToList(), Route = new CustomRoute() { RoutePoints = new List <GeoCoordinate>(_buildedRoute) } }; _globalSettings.Routes.Add(route); _globalSettings.Save(); NewRouteNameBox.Text = string.Empty; }
private void ExportRoute_Click(object sender, RoutedEventArgs e) { ImportExportRouteText.Clear(); var points = _mapPoints.Select(x => x.Location).ToList(); string encodedRoute = null; var firstOrDefault = points.FirstOrDefault(); if (firstOrDefault == null) { return; } try { encodedRoute = RoutingUtils.EncodeToPolyline(points); } catch (Exception) { //do nothing } if (encodedRoute == null) { return; } ImportExportRouteText.Text = encodedRoute; ImportExportRoute.Visibility = Visibility.Visible; ImportExportHeading.Text = TranslationEngine.GetDynamicTranslationString("%EXPORT_ROUTE%", "Export Route"); ImportExportRouteSubmit.Visibility = Visibility.Collapsed; ImportExportInstructions.Text = TranslationEngine.GetDynamicTranslationString("%EXPORT_INSTRUCTION%", "Copy the below route to create a backup or share with others."); }
private static void SetPokemonAsBuddy(Queue <PokemonUiData> pokemonQueue) { if (pokemonQueue == null) { return; } while (pokemonQueue.Count > 0) { var pokemon = pokemonQueue.Dequeue(); if (pokemon == null) { continue; } if (pokemon.OwnerBot != null && pokemon.OwnerBot.Started || _debugMode) { pokemon.OwnerBot.Session.AddActionToQueue( async() => { await SetBuddyPokemonTask.Execute(pokemon.OwnerBot.Session, pokemon.Id); return(true); }, $"{TranslationEngine.GetDynamicTranslationString("%SET_BUDDY%", "Set Buddy")}: {pokemon.Name}", pokemon.Id); pokemon.InAction = true; } } }
private void mi_recycleItem_Click(object sender, RoutedEventArgs e) { var mi = sender as MenuItem; var itemListBox = (mi?.Parent as ContextMenu)?.Tag as ListBox; if (itemListBox == null || itemListBox.SelectedItems.Count != 1) { return; } var item = (ItemUiData)itemListBox.SelectedItem; if (item?.OwnerBot == null) { return; } var curSession = item.OwnerBot.Session; int amount; var inputDialog = new SupportForms.InputDialog(TranslationEngine.GetDynamicTranslationString("%RECYCLE_INPUT%", "Please, enter amout to recycle:"), "1", true); if (inputDialog.ShowDialog() != true) { return; } if (int.TryParse(inputDialog.Answer, out amount)) { RecycleItem(curSession, item, amount, item.OwnerBot.CancellationToken); } }
private static void LevelUpPokemon(Queue <PokemonUiData> pokemonQueue, bool toMax = false) { if (pokemonQueue == null) { return; } while (pokemonQueue.Count > 0) { var pokemon = pokemonQueue.Dequeue(); if (pokemon == null) { continue; } if (pokemon.OwnerBot != null && pokemon.OwnerBot.Started || _debugMode) { pokemon.OwnerBot.Session.AddActionToQueue( async() => { await LevelUpSpecificPokemonTask.Execute(pokemon.OwnerBot.Session, pokemon.Id, pokemon.OwnerBot.CancellationToken, toMax); return(true); }, $"{TranslationEngine.GetDynamicTranslationString("%LEVEL_UP%", "Level up")}: {pokemon.Name}", pokemon.Id); pokemon.InAction = true; } } }
private static void RenamePokemon(Queue <PokemonUiData> pokemonQueue, string name = null, bool toDefault = false) { if (pokemonQueue == null) { return; } if (name == null) { return; } while (pokemonQueue.Count > 0) { var pokemon = pokemonQueue.Dequeue(); if (pokemon == null) { continue; } if (pokemon.OwnerBot != null && pokemon.OwnerBot.Started || _debugMode) { pokemon.OwnerBot.Session.AddActionToQueue( async() => { await RenameSpecificPokemonTask.Execute(pokemon.OwnerBot.Session, pokemon.Id, pokemon.OwnerBot.CancellationToken, name, toDefault); return(true); }, $"{TranslationEngine.GetDynamicTranslationString("%RENAME_POKE%", "Rename poke")}: {pokemon.Name}", pokemon.Id); pokemon.InAction = true; } } }
private static void EvolvePokemon(Queue <PokemonUiData> pokemonQueue) { if (pokemonQueue == null) { return; } while (pokemonQueue.Count > 0) { var pokemon = pokemonQueue.Dequeue(); if (pokemon == null) { continue; } if (pokemon.OwnerBot != null && pokemon.OwnerBot.Started && pokemon.Evolutions.Any() || _debugMode) { pokemon.OwnerBot.Session.AddActionToQueue( async() => { await EvolveSpecificPokemonTask.Execute(pokemon.OwnerBot.Session, pokemon.Id, pokemon.OwnerBot.CancellationToken); return(true); }, $"{TranslationEngine.GetDynamicTranslationString("%EVOLVE%", "Evolve")} {pokemon.Name}", pokemon.Id); pokemon.InAction = true; } } }
private void mi_renamePokemon_Click(object sender, RoutedEventArgs e) { var mi = sender as MenuItem; var pokeListBox = (mi?.Parent as ContextMenu)?.Tag as ListBox; if (pokeListBox?.SelectedIndex == -1) { return; } var pokemonToRename = GetMultipleSelectedPokemon(pokeListBox); if (pokemonToRename == null) { return; } var inputDialog = new SupportForms.InputDialog(TranslationEngine.GetDynamicTranslationString("%POKE_NAME_INPUT%", "Please Enter a Name to Rename Pokemon:"), "", false, 12); if (inputDialog.ShowDialog() != true) { return; } var customName = inputDialog.Answer; if (customName.Length > 12) { return; } RenamePokemon(pokemonToRename, customName); }
private void ClearRouteBuilder() { _currentIndex = 1; _currentRoute?.Points.Clear(); _currentRoute?.RegenerateShape(RouteCreatorMap); BuildingProgressBar.Value = 0; ProgressText.Text = TranslationEngine.GetDynamicTranslationString("%ROUTE_PROGRESS_1%", "Route progress"); _builded = false; while (_mapPoints.Any()) { RemoveMarker(_mapPoints[0]); } RouteCreatorMap.Markers.Clear(); _pokestops.Clear(); _pokemons.Clear(); _mappedPokemons.Clear(); if (_routeBuilder != null && _routeBuilder.Status == TaskStatus.Running) { _cts.Cancel(); } _ctsPrev.Cancel(); _ctsPrev = new CancellationTokenSource(); _showPsTask = null; _showHeatMapTask = null; }
private void ImportRoute_Click(object sender, RoutedEventArgs e) { ImportExportRoute.Visibility = Visibility.Visible; ImportExportHeading.Text = TranslationEngine.GetDynamicTranslationString("%IMPORT_ROUTE%", "Import Route"); ImportExportRouteSubmit.Visibility = Visibility.Visible; ImportExportInstructions.Text = TranslationEngine.GetDynamicTranslationString("%IMPORT_INSTRUCTION%", "Enter a route below to Import it into Catchem, once entered click import."); ImportExportRouteText.Clear(); }
private static void RecycleItem(ISession session, ItemUiData item, int amount, CancellationToken cts) { long uidLong = -1; var uid = (ulong)uidLong; session.AddActionToQueue(async() => { await RecycleSpecificItemTask.Execute(session, item.Id, amount, cts); return(true); }, $"{TranslationEngine.GetDynamicTranslationString("%RECYCLE_ITEM%", "Recycle item")}: {item.Id}x{amount}", uid); }
public void UpdatePokedexCount() { Dispatcher.Invoke(new ThreadStart(delegate { var seen = _bot?.PokeDex?.Count(x => x.Seen); var caught = _bot?.PokeDex?.Count(x => x.Captured); var seenTranslation = TranslationEngine.GetDynamicTranslationString("%SEEN%", "Seen"); var capturedTranslation = TranslationEngine.GetDynamicTranslationString("%CAUGHT%", "Caught"); var totalTranslation = TranslationEngine.GetDynamicTranslationString("%TOTAL%", "Total"); PokedexStatusText.Text = $"{seenTranslation}: {seen} / {capturedTranslation}: {caught} / {totalTranslation}: 151"; })); }
private static void UseItem(ItemUiData item) { if (item.OwnerBot.Started || _debugMode) { item.OwnerBot.Session.AddActionToQueue( async() => { await UseItemTask.Execute(item.OwnerBot.Session, item.Id, item.OwnerBot.CancellationToken); return(true); }, $"{TranslationEngine.GetDynamicTranslationString("%USING%", "Using")}: {item.Name}", 0); } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var s = parameter as string; if (value == null || s == null) { return(value); } var tag = s.Split(';'); return(tag.Length > 1 ? TranslationEngine.GetDynamicTranslationString(tag[0], tag[1]) : value); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { try { var prop = parameter as string; var status = (bool?)value; if (value == null || prop == null) { return(value); } if (prop == "Text") { return((bool)status ? TranslationEngine.GetDynamicTranslationString("%STOP%", "STOP") : TranslationEngine.GetDynamicTranslationString("%START%", "START")); } if (prop == "Background") { var color1 = (bool)status ? System.Windows.Media.Color.FromArgb(255, 192, 79, 83) : System.Windows.Media.Color.FromArgb(255, 83, 192, 177); var color2 = (bool)status ? System.Windows.Media.Color.FromArgb(255, 238, 178, 156) : System.Windows.Media.Color.FromArgb(255, 176, 238, 156); return(new LinearGradientBrush { GradientStops = new GradientStopCollection { new GradientStop { Color = color1, Offset = 1 }, new GradientStop { Color = color2, Offset = 0 } } }); } return(value); } catch (Exception) { return(value); } }
public object Convert(object[] value, Type targetType, object parameter, CultureInfo culture) { var s = parameter as string; if (value == null || s == null || value.Length < 2) { return(value); } var tag = value[0] as string; var lng = value[1] as string; if (tag != null) { return(TranslationEngine.GetDynamicTranslationString(tag, s)); } return(value); }
private void team_image_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { if (_bot == null || !_bot.Started || _bot.Team != TeamColor.Neutral || _bot.Level < 5) { return; } var inputDialog = new SupportForms.InputDialog(TranslationEngine.GetDynamicTranslationString("%SELECT_TEAM_INPUT%", "Please, select a team:"), null, false, 0, new List <object> { TeamColor.Blue, TeamColor.Yellow, TeamColor.Red }); if (inputDialog.ShowDialog() != true || inputDialog.ObjectAnswer == null) { return; } var team = (TeamColor)inputDialog.ObjectAnswer; SelectTeam(team); }
private async Task ShowPokestops(double lat, double lng, double dist, CancellationToken token) { var pokeStops = DbHandler.GetPokestopsForCoords(lat, lng, dist); foreach (var ps in pokeStops) { if (_pokestops.ContainsKey(ps.Id)) { continue; } await Dispatcher.BeginInvoke(new ThreadStart(delegate { var markerShape = Properties.Resources.pstop.ToImage(string.IsNullOrEmpty(ps.Name) ? TranslationEngine.GetDynamicTranslationString("%POKESTOP%", "PokeStop") : ps.Name); var marker = new GMapMarker(new PointLatLng(ps.Latitude, ps.Longitude)) { Shape = markerShape, Offset = new Point(-16, -32), ZIndex = 5 }; try { token.ThrowIfCancellationRequested(); if (!_pokestops.ContainsKey(ps.Id)) { _pokestops.Add(ps.Id, marker); } } catch (Exception) { //ignore } RouteCreatorMap.Markers.Add(marker); })); } }
private void CreateNewMarker(PointLatLng mapPos, bool starter) { var marker = new GMapMarker(mapPos) { Offset = starter ? new Point(-24, -48) : new Point(-16, -32), ZIndex = int.MaxValue, Position = mapPos }; var imgSource = starter ? Properties.Resources.force_move.LoadBitmap() : Properties.Resources.wp.LoadBitmap(); var tooltipText = starter ? TranslationEngine.GetDynamicTranslationString("%ROUTE_MARKER_START%", "Route Marker - START") : TranslationEngine.GetDynamicTranslationString("%ROUTE_MARKER_WP%", "Route Marker - Waypoint") + $" {_currentIndex++}"; var rm = new RouteMarker(imgSource, tooltipText, RouteCreatorMap, this) { IsStart = starter, Location = new GeoCoordinate(mapPos.Lat, mapPos.Lng), Marker = marker }; marker.Shape = rm; rm.MouseLeftButtonDown += delegate { if (!Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) { RemoveMarker(rm); } }; AddMarker(rm, starter); }
public static async Task <Dictionary <int, GMapMarker> > GuildPokemonSeenHeatMap(List <PokemonSeen> seenList, int searchRad, Dispatcher dispatcher, CancellationToken token) { var heatMap = new Dictionary <int, GMapMarker>(); while (seenList.Any()) { List <PokemonSeen> group; try { token.ThrowIfCancellationRequested(); group = GetBestPokeGroup2(seenList, searchRad, token); if (group.Count == 0) { break; } } catch (Exception) { return(null); } var firstPokeToGroup = group.First(); double circleSize = group.Count * 2 + 2; if (circleSize > searchRad) { circleSize = searchRad; } await dispatcher.BeginInvoke(new ThreadStart(delegate { Brush ellipseBrush = new SolidColorBrush(Color.FromArgb(122, 32, 193, 8)); if (group.Count > 15) { ellipseBrush = new RadialGradientBrush(Color.FromArgb(122, 193, 59, 8), Color.FromArgb(122, 193, 166, 8)); } else if (group.Count > 5) { ellipseBrush = new RadialGradientBrush(Color.FromArgb(122, 193, 166, 8), Color.FromArgb(122, 32, 193, 8)); } var tooltipText = string.Format( TranslationEngine.GetDynamicTranslationString("%HEATMAP_SEEN%", "Seen {0} poke here"), group.Count); var ellipse = new Ellipse { Fill = ellipseBrush, StrokeThickness = 0, Width = circleSize, Height = circleSize, ToolTip = new ToolTip { Content = tooltipText } }; var marker = new GMapMarker(GetMidPoint(group.Select(x => (new PointLatLng(x.Latitude, x.Longitude))))) { Shape = ellipse, Offset = new Point(-circleSize / 2, -circleSize / 2), ZIndex = 2 }; if (!heatMap.ContainsKey(firstPokeToGroup.Id)) { heatMap.Add(firstPokeToGroup.Id, marker); } })); foreach (var c in group) { seenList.Remove(c); } await Task.Delay(1); } return(heatMap); }
private void UpdateMarkerCounter() { PointsNumber.Text = TranslationEngine.GetDynamicTranslationString("%NUMBER_OF_WAYPOINTS%", "Number of waypoints:") + $" {_mapPoints.Count}"; }
private async Task BuildTheRouteTask(CancellationToken token) { try { token.ThrowIfCancellationRequested(); if (_mapPoints.Count < 2) { return; } await Dispatcher.BeginInvoke(new ThreadStart(CheckRouteServicePrefer)); if (_mapPoints.Count > 47 && !_manualRoute) { Dispatcher.Invoke(new ThreadStart(delegate { MessageBox.Show( TranslationEngine.GetDynamicTranslationString("%TOO_MANY_ROUTE_POINTS%", "Too many waypoints, try to reduce them to 47, or wait for next releases, where that limit will be increased!"), "Routing Error", MessageBoxButton.OK, MessageBoxImage.Information); })); return; } UpdateProgress(TranslationEngine.GetDynamicTranslationString("%ROUTE_PROGRESS_2%", "Started!..."), 0); BotWindowData bot; var route = GetWorkingRouting(out bot); if (route == "error" && !_manualRoute) { MessageBox.Show( TranslationEngine.GetDynamicTranslationString("%NO_ROUTE_API_FOUND%", "You have to enter Google Direction API or Mapzen Valhalla API to any of your bots, before creating a route"), "API Key Error", MessageBoxButton.OK, MessageBoxImage.Information); return; } var start = _mapPoints.FirstOrDefault(x => x.IsStart) ?? _mapPoints.First(); UpdateProgress(TranslationEngine.GetDynamicTranslationString("%ROUTE_PROGRESS_3%", "Started!..."), 10); RoutingResponse response = null; var cycleWp = _mapPoints.Where(x => !x.IsStart).Select(x => x.Location).ToList(); cycleWp.Add(start.Location); List <GeoCoordinate> routePoints; token.ThrowIfCancellationRequested(); if (!_manualRoute) { if (route == "google") { response = GoogleRouting.GetRoute(start.Location, null, bot.Session, cycleWp, true); } else if (route == "mapzen") { response = MapzenRouting.GetRoute(start.Location, null, bot.Session, cycleWp, true); } if (response?.Coordinates == null || response.Coordinates.Count == 0) { return; } routePoints = response.Coordinates.Select(wp => new GeoCoordinate(wp[0], wp[1])).ToList(); } else { cycleWp.Insert(0, start.Location); routePoints = new List <GeoCoordinate>(cycleWp); } token.ThrowIfCancellationRequested(); UpdateProgress( TranslationEngine.GetDynamicTranslationString("%ROUTE_PROGRESS_4%", "Handling result..."), 60); _currentRoute?.Points?.Clear(); if (_currentRoute == null) { _currentRoute = new GMapRoute(new List <PointLatLng>()); } await RouteCreatorMap.Dispatcher.BeginInvoke(new ThreadStart(delegate { RouteCreatorMap.Markers.Add(_currentRoute); })); token.ThrowIfCancellationRequested(); UpdateProgress( TranslationEngine.GetDynamicTranslationString("%ROUTE_PROGRESS_5%", "Requesting altitude..."), 70); _buildedRoute = new List <GeoCoordinate>(routePoints); token.ThrowIfCancellationRequested(); foreach (var item in routePoints) { _currentRoute.Points?.Add(new PointLatLng(item.Latitude, item.Longitude)); } await Dispatcher.BeginInvoke(new ThreadStart(delegate { try { _currentRoute.RegenerateShape(RouteCreatorMap); } catch (Exception) { //ignore } })); var path = _currentRoute?.Shape as Path; await Dispatcher.BeginInvoke(new ThreadStart(delegate { if (path != null) { path.Stroke = new SolidColorBrush(Color.FromRgb(255, 0, 0)); } })); bot = MainWindow.BotsCollection.FirstOrDefault( x => !string.IsNullOrEmpty(x.GlobalSettings.LocationSettings.MapzenApiKey)); if (bot != null) { await bot.Session.MapzenApi.FillAltitude(_buildedRoute.ToList(), token : token); } UpdateProgress(TranslationEngine.GetDynamicTranslationString("%ROUTE_PROGRESS_6%", "Done!"), 100); _builded = true; } catch (OperationCanceledException) { //ignore } }