MatchVM.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. if (App.Game.Players.Count == 1)
  58. return "There is currently " + App.Game.Players.Count + " player in the match.";
  59. else
  60. return "There are currently " + App.Game.Players.Count + " players in the match.";
  61. }
  62. }
  63. public bool MatchAvailable
  64. {
  65. get
  66. {
  67. return App.Geo.Status == Windows.Devices.Geolocation.PositionStatus.Ready && App.Network.Status == Model.NetworkHandler.NetworkStatus.CONNECTED;
  68. }
  69. }
  70. public bool ConnectingServer
  71. {
  72. get
  73. {
  74. return !MatchAvailable;
  75. }
  76. }
  77. public bool StartMatch
  78. {
  79. get
  80. {
  81. return App.Game.Status == Model.GameHandler.GameStatus.STOPPED;
  82. }
  83. }
  84. public bool StopMatch
  85. {
  86. get
  87. {
  88. return !StartMatch;
  89. }
  90. }
  91. }
  92. }