MainPageVM.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using YJMPD_UWP.Helpers;
  3. namespace YJMPD_UWP.ViewModels
  4. {
  5. public class MainPageVM : TemplateVM
  6. {
  7. public MainPageVM() : base("Loading")
  8. {
  9. App.Game.OnStatusUpdate += Game_OnStatusUpdate;
  10. App.Game.OnPlayersUpdate += Game_OnPlayersUpdate;
  11. }
  12. private void Game_OnPlayersUpdate(object sender, Helpers.EventArgs.GamePlayersUpdatedEventArgs e)
  13. {
  14. dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
  15. {
  16. NotifyPropertyChanged(nameof(Players));
  17. });
  18. }
  19. private void Game_OnStatusUpdate(object sender, Helpers.EventArgs.GameStatusUpdatedEventArgs e)
  20. {
  21. dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
  22. {
  23. NotifyPropertyChanged(nameof(GameState));
  24. NotifyPropertyChanged(nameof(GameVisible));
  25. });
  26. }
  27. public string GameState
  28. {
  29. get
  30. {
  31. return App.Game.Status.ToString().UppercaseFirst();
  32. }
  33. }
  34. public string Players
  35. {
  36. get
  37. {
  38. if (App.Game.Players.Count == 1)
  39. return "1 player";
  40. else
  41. return App.Game.Players.Count + " players";
  42. }
  43. }
  44. public bool GameVisible
  45. {
  46. get
  47. {
  48. return App.Game.Status != Model.GameHandler.GameStatus.STOPPED;
  49. }
  50. }
  51. public string Year
  52. {
  53. get
  54. {
  55. int year = DateTime.Now.Year;
  56. return year.ToString();
  57. }
  58. }
  59. }
  60. }