| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- using System.Diagnostics;
- using Windows.UI.Xaml.Media;
- using Windows.UI.Xaml.Media.Imaging;
- using YJMPD_UWP.Helpers;
- namespace YJMPD_UWP.ViewModels
- {
- public class MatchVM : TemplateVM
- {
- private int angle;
- public MatchVM() : base("Match")
- {
- Error = "";
- Message = "";
- Degrees = 0;
- angle = (int)Util.DegreeBearing(App.Geo.Position.Coordinate.Point.Position, App.Game.Destination);
- HeadingVisible = true;
- App.Game.OnDestinationEnter += Game_OnDestinationEnter;
- App.Game.OnDestinationLeave += Game_OnDestinationLeave;
- App.Geo.OnPositionUpdate += Geo_OnPositionUpdate;
- App.Compass.OnHeadingUpdate += Compass_OnHeadingUpdate;
- }
- private void Compass_OnHeadingUpdate(object sender, Helpers.EventArgs.HeadingUpdatedEventArgs e)
- {
- dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
- {
- if (App.Game.Status != Model.GameHandler.GameStatus.STARTED)
- return;
- Degrees = (int)(angle + -e.Heading.HeadingMagneticNorth);
- NotifyPropertyChanged(nameof(Degrees));
- Debug.WriteLine(angle);
- });
- }
- private void Geo_OnPositionUpdate(object sender, Helpers.EventArgs.PositionUpdatedEventArgs e)
- {
- dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
- {
- if (App.Game.Status != Model.GameHandler.GameStatus.STARTED)
- return;
- angle = (int)Util.DegreeBearing(e.Position.Coordinate.Point.Position, App.Game.Destination);
- double b = Util.Distance(e.Position.Coordinate.Point.Position, App.Game.Destination) * 1000;
- HeadingVisible = (int)b > 250;
- Debug.WriteLine(HeadingVisible + " " + b);
- NotifyPropertyChanged(nameof(HeadingVisible));
- NotifyPropertyChanged(nameof(InvHeadingVisible));
- });
- }
- private void Game_OnDestinationLeave(object sender, System.EventArgs e)
- {
- dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
- {
- if (App.Game.Selected)
- Error = "Return to location!";
- NotifyPropertyChanged(nameof(ErrorVisible));
- NotifyPropertyChanged(nameof(Error));
- });
- }
- private void Game_OnDestinationEnter(object sender, System.EventArgs e)
- {
- dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
- {
- if (App.Game.Selected)
- Error = "";
- if (!App.Game.Selected)
- Message = "You reached the destination!";
- NotifyPropertyChanged(nameof(ErrorVisible));
- NotifyPropertyChanged(nameof(Error));
- NotifyPropertyChanged(nameof(MessageVisible));
- NotifyPropertyChanged(nameof(Message));
- });
- }
- public int Degrees
- {
- get; private set;
- }
- public bool HeadingVisible
- {
- get; private set;
- }
- public bool InvHeadingVisible
- {
- get
- {
- return !HeadingVisible;
- }
- }
- public bool MessageVisible
- {
- get
- {
- return Message != "";
- }
- }
- public bool ErrorVisible
- {
- get
- {
- return Error != "";
- }
- }
- public string Message
- {
- get; private set;
- }
- public string Error
- {
- get; private set;
- }
- public ImageSource Photo
- {
- get
- {
- return new BitmapImage(new System.Uri(App.Photo.Photo));
- }
- }
- }
- }
|