MatchVM.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System.Collections.Generic;
  2. using YJMPD_UWP.Model.Object;
  3. namespace YJMPD_UWP.ViewModels
  4. {
  5. public class MatchVM : TemplateVM
  6. {
  7. public MatchVM() : base("Match")
  8. {
  9. App.Geo.OnStatusUpdate += Geo_OnStatusUpdate;
  10. App.Network.OnStatusUpdate += Network_OnStatusUpdate;
  11. App.Game.OnStatusUpdate += Game_OnStatusUpdate;
  12. App.Game.OnPlayersUpdate += Game_OnPlayersUpdate;
  13. }
  14. private void Game_OnPlayersUpdate(object sender, Helpers.EventArgs.GamePlayersUpdatedEventArgs e)
  15. {
  16. dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
  17. {
  18. NotifyPropertyChanged(nameof(Players));
  19. NotifyPropertyChanged(nameof(PlayersCount));
  20. });
  21. }
  22. private void Game_OnStatusUpdate(object sender, Helpers.EventArgs.GameStatusUpdatedEventArgs e)
  23. {
  24. dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
  25. {
  26. NotifyPropertyChanged(nameof(StartMatch));
  27. NotifyPropertyChanged(nameof(StopMatch));
  28. });
  29. }
  30. private void Network_OnStatusUpdate(object sender, Helpers.EventArgs.NetworkStatusUpdatedEventArgs e)
  31. {
  32. dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
  33. {
  34. NotifyPropertyChanged(nameof(MatchAvailable));
  35. NotifyPropertyChanged(nameof(ConnectingServer));
  36. });
  37. }
  38. private void Geo_OnStatusUpdate(object sender, Helpers.EventArgs.PositionStatusUpdatedEventArgs e)
  39. {
  40. dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
  41. {
  42. NotifyPropertyChanged(nameof(MatchAvailable));
  43. NotifyPropertyChanged(nameof(ConnectingServer));
  44. });
  45. }
  46. public List<Player> Players
  47. {
  48. get
  49. {
  50. return new List<Player>(App.Game.Players);
  51. }
  52. }
  53. public string PlayersCount
  54. {
  55. get
  56. {
  57. return "There are currently " + App.Game.Players.Count + " players in the match.";
  58. }
  59. }
  60. public bool MatchAvailable
  61. {
  62. get
  63. {
  64. return App.Geo.Status == Windows.Devices.Geolocation.PositionStatus.Ready && App.Network.Status == Model.NetworkHandler.NetworkStatus.CONNECTED;
  65. }
  66. }
  67. public bool ConnectingServer
  68. {
  69. get
  70. {
  71. return !MatchAvailable;
  72. }
  73. }
  74. public bool StartMatch
  75. {
  76. get
  77. {
  78. return App.Game.Status == Model.GameHandler.GameStatus.STOPPED;
  79. }
  80. }
  81. public bool StopMatch
  82. {
  83. get
  84. {
  85. return !StartMatch;
  86. }
  87. }
  88. }
  89. }