PhotoVM.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Diagnostics;
  3. using Windows.UI.Xaml;
  4. using Windows.UI.Xaml.Media;
  5. using Windows.UI.Xaml.Media.Imaging;
  6. namespace YJMPD_UWP.ViewModels
  7. {
  8. public class PhotoVM : TemplateVM
  9. {
  10. DispatcherTimer timer;
  11. int secondsleft = 60;
  12. public PhotoVM() : base("Photo")
  13. {
  14. timer = new DispatcherTimer();
  15. timer.Interval = TimeSpan.FromSeconds(1);
  16. timer.Tick += Timer_Tick;
  17. timer.Start();
  18. App.Photo.OnStatusUpdate += Photo_OnStatusUpdate;
  19. }
  20. private void Photo_OnStatusUpdate(object sender, Helpers.EventArgs.PhotoStatusUpdatedEventArgs e)
  21. {
  22. dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
  23. {
  24. if (e.Status == Model.PhotoHandler.PhotoStatus.NOPHOTO)
  25. timer.Start();
  26. else
  27. {
  28. secondsleft = 60;
  29. timer.Stop();
  30. }
  31. });
  32. }
  33. private void Timer_Tick(object sender, object e)
  34. {
  35. NotifyPropertyChanged(nameof(TimeOut));
  36. secondsleft--;
  37. if(secondsleft <= 0)
  38. {
  39. timer.Stop();
  40. secondsleft = 60;
  41. App.Game.StopGame();
  42. }
  43. }
  44. public string TimeOut
  45. {
  46. get
  47. {
  48. return "Take a photo within " + secondsleft + " seconds";
  49. }
  50. }
  51. }
  52. }