diff --git a/YJMPD-UWP/Helpers/Util.cs b/YJMPD-UWP/Helpers/Util.cs index 776fd2d..8595b9b 100644 --- a/YJMPD-UWP/Helpers/Util.cs +++ b/YJMPD-UWP/Helpers/Util.cs @@ -7,8 +7,10 @@ using System.Threading.Tasks; using Windows.Data.Xml.Dom; using Windows.Devices.Geolocation; using Windows.Services.Maps; +using Windows.UI; using Windows.UI.Notifications; using Windows.UI.Popups; +using Windows.UI.Xaml.Controls.Maps; namespace YJMPD_UWP.Helpers { @@ -130,6 +132,25 @@ namespace YJMPD_UWP.Helpers return address; } + public static MapPolyline GetRouteLine(BasicGeoposition p1, BasicGeoposition p2, Color color, int zindex, int thickness = 5) + { + var line = new MapPolyline + { + StrokeThickness = thickness, + StrokeColor = color, + StrokeDashed = false, + ZIndex = zindex + }; + + List plist = new List(); + plist.Add(p1); + plist.Add(p2); + + line.Path = new Geopath(plist); + + return line; + } + public static double Distance(BasicGeoposition pos1, BasicGeoposition pos2) { var R = 6371; // Radius of the earth in km diff --git a/YJMPD-UWP/Model/ApiHandler.cs b/YJMPD-UWP/Model/ApiHandler.cs index 936bc1e..5b542e3 100644 --- a/YJMPD-UWP/Model/ApiHandler.cs +++ b/YJMPD-UWP/Model/ApiHandler.cs @@ -96,8 +96,11 @@ namespace YJMPD_UWP.Model App.Game.StopMatch(); break; case Command.StopGame: - if(App.Game.Status != GameHandler.GameStatus.STOPPED) + if (App.Game.Status != GameHandler.GameStatus.STOPPED) + { + Util.ShowToastNotification("Game stopped", "A player has left the game."); App.Game.StopGame(); + } break; default: //Do nothing diff --git a/YJMPD-UWP/Model/GameHandler.cs b/YJMPD-UWP/Model/GameHandler.cs index 68e1b61..fc1aa67 100644 --- a/YJMPD-UWP/Model/GameHandler.cs +++ b/YJMPD-UWP/Model/GameHandler.cs @@ -216,6 +216,8 @@ namespace YJMPD_UWP.Model Settings.Statistics.AddPoints(GetPlayer(Settings.Username).Points); + Settings.SaveStatistics(); + GeofenceMonitor.Current.Geofences.Clear(); Selected = false; App.Photo.Reset(); diff --git a/YJMPD-UWP/Views/MatchView.xaml.cs b/YJMPD-UWP/Views/MatchView.xaml.cs index acc8f50..6f4210b 100644 --- a/YJMPD-UWP/Views/MatchView.xaml.cs +++ b/YJMPD-UWP/Views/MatchView.xaml.cs @@ -1,4 +1,8 @@ -using Windows.UI.Xaml.Controls; +using Windows.Devices.Geolocation; +using Windows.UI; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Controls.Maps; +using YJMPD_UWP.Helpers; using YJMPD_UWP.ViewModels; namespace YJMPD_UWP.Views @@ -6,12 +10,42 @@ namespace YJMPD_UWP.Views public sealed partial class MatchView : Page { MatchVM matchvm; + MapIcon pos; + Geoposition old; public MatchView() { matchvm = new MatchVM(); this.DataContext = matchvm; this.InitializeComponent(); + + pos = new MapIcon(); + pos.Title = "You"; + pos.ZIndex = 100; + + App.Geo.OnPositionUpdate += Geo_OnPositionUpdate; + } + + private void Geo_OnPositionUpdate(object sender, Helpers.EventArgs.PositionUpdatedEventArgs e) + { + Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => + { + pos.Location = e.Position.Coordinate.Point; + + if (!Map.MapElements.Contains(pos)) + Map.MapElements.Add(pos); + + + if(old != null && !App.Game.Selected) + { + Map.MapElements.Add(Util.GetRouteLine(old.Coordinate.Point.Position, e.Position.Coordinate.Point.Position, Color.FromArgb(255, 200, 50, 50), 50)); + } + + old = e.Position; + + Map.TrySetViewAsync(e.Position.Coordinate.Point); + Map.TryZoomToAsync(13); + }); } } }