ModuleMovieTest.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using Microsoft.Xna.Framework.Input;
  2. using OpenVIII.AV;
  3. using OpenVIII.Encoding.Tags;
  4. using OpenVIII.Movie;
  5. namespace OpenVIII
  6. {
  7. public static class ModuleMovieTest
  8. {
  9. private const Module DefaultReturnState = Module.MainMenuDebug;
  10. private static Player _player;
  11. /// <summary>
  12. /// Movie file list
  13. /// </summary>
  14. public static Module ReturnState { get; set; } = DefaultReturnState;
  15. public static int Index { get; set; }
  16. public static void Inputs()
  17. {
  18. var files = Files.Instance;
  19. if (Input2.DelayedButton(FF8TextTagKey.Confirm) || Input2.DelayedButton(FF8TextTagKey.Cancel) || Input2.DelayedButton(Keys.Space))
  20. {
  21. Return();
  22. }
  23. #if DEBUG
  24. // lets you move through all the fields just holding left or right. it will just loop
  25. // when it runs out.
  26. else if (Input2.DelayedButton(FF8TextTagKey.Left))
  27. {
  28. Sound.Play(0);
  29. if (Index > 0)
  30. Index--;
  31. else
  32. Index = files.Count - 1;
  33. Reset();
  34. }
  35. else if (Input2.DelayedButton(FF8TextTagKey.Right))
  36. {
  37. Sound.Play(0);
  38. if (Index < files.Count - 1)
  39. Index++;
  40. else
  41. Index = 0;
  42. Reset();
  43. }
  44. #endif
  45. }
  46. private static void Return()
  47. {
  48. Memory.Module = ReturnState;
  49. Reset();
  50. }
  51. public static void Play()
  52. {
  53. _player = Player.Load(Index);
  54. if (_player != null)
  55. _player.StateChanged += Player_StateChanged;
  56. }
  57. private static void Player_StateChanged(object sender, State e)
  58. {
  59. if (e == State.Return)
  60. Return();
  61. }
  62. public static void Update()
  63. {
  64. if (_player == null || _player.IsDisposed)
  65. Play();
  66. if (_player == null) // player is still null move on.
  67. Return();
  68. else
  69. {
  70. _player?.Update();
  71. Inputs();
  72. }
  73. }
  74. public static void Draw() => _player?.Draw();
  75. public static void Reset()
  76. {
  77. _player = null;
  78. ReturnState = DefaultReturnState;
  79. }
  80. }
  81. }