MatchVM.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. namespace YJMPD_UWP.ViewModels
  2. {
  3. public class MatchVM : TemplateVM
  4. {
  5. public MatchVM() : base("Match")
  6. {
  7. App.Geo.OnStatusUpdate += Geo_OnStatusUpdate;
  8. App.Network.OnStatusUpdate += Network_OnStatusUpdate;
  9. App.Game.OnStatusUpdate += Game_OnStatusUpdate;
  10. }
  11. private void Game_OnStatusUpdate(object sender, Helpers.EventArgs.GameStatusUpdatedEventArgs e)
  12. {
  13. dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
  14. {
  15. NotifyPropertyChanged(nameof(StartMatch));
  16. NotifyPropertyChanged(nameof(StopMatch));
  17. });
  18. }
  19. private void Network_OnStatusUpdate(object sender, Helpers.EventArgs.NetworkStatusUpdatedEventArgs e)
  20. {
  21. dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
  22. {
  23. NotifyPropertyChanged(nameof(MatchAvailable));
  24. });
  25. }
  26. private void Geo_OnStatusUpdate(object sender, Helpers.EventArgs.PositionStatusUpdatedEventArgs e)
  27. {
  28. dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
  29. {
  30. NotifyPropertyChanged(nameof(MatchAvailable));
  31. });
  32. }
  33. public bool MatchAvailable
  34. {
  35. get
  36. {
  37. return App.Geo.Status == Windows.Devices.Geolocation.PositionStatus.Ready && App.Network.Status == Model.NetworkHandler.NetworkStatus.CONNECTED;
  38. }
  39. }
  40. public bool StartMatch
  41. {
  42. get
  43. {
  44. return App.Game.Status == Model.GameHandler.GameStatus.STOPPED;
  45. }
  46. }
  47. public bool StopMatch
  48. {
  49. get
  50. {
  51. return !StartMatch;
  52. }
  53. }
  54. }
  55. }