MatchVM.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. });
  36. }
  37. private void Geo_OnStatusUpdate(object sender, Helpers.EventArgs.PositionStatusUpdatedEventArgs e)
  38. {
  39. dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
  40. {
  41. NotifyPropertyChanged(nameof(MatchAvailable));
  42. });
  43. }
  44. public List<Player> Players
  45. {
  46. get
  47. {
  48. return new List<Player>(App.Game.Players);
  49. }
  50. }
  51. public string PlayersCount
  52. {
  53. get
  54. {
  55. return "There are currently " + App.Game.Players.Count + " players in the match.";
  56. }
  57. }
  58. public bool MatchAvailable
  59. {
  60. get
  61. {
  62. return App.Geo.Status == Windows.Devices.Geolocation.PositionStatus.Ready && App.Network.Status == Model.NetworkHandler.NetworkStatus.CONNECTED;
  63. }
  64. }
  65. public bool StartMatch
  66. {
  67. get
  68. {
  69. return App.Game.Status == Model.GameHandler.GameStatus.STOPPED;
  70. }
  71. }
  72. public bool StopMatch
  73. {
  74. get
  75. {
  76. return !StartMatch;
  77. }
  78. }
  79. }
  80. }