Module_face_test.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using System;
  4. namespace OpenVIII
  5. {
  6. public static class Module_face_test
  7. {
  8. #region Fields
  9. private static Mode currentMode;
  10. private static Faces.ID[] FaceValue;
  11. private static int pointer = -1;
  12. private static TimeSpan time;
  13. #endregion Fields
  14. #region Enums
  15. private enum Mode
  16. {
  17. Initialize,
  18. Draw,
  19. Wait
  20. }
  21. #endregion Enums
  22. #region Methods
  23. public static void Draw()
  24. {
  25. switch (currentMode)
  26. {
  27. case Mode.Initialize:
  28. break;
  29. case Mode.Wait:
  30. case Mode.Draw:
  31. DrawFace();
  32. break;
  33. }
  34. }
  35. /// <summary>
  36. /// Make sure the next frame will draw.
  37. /// </summary>
  38. public static void Show()
  39. {
  40. if (currentMode == Mode.Wait)
  41. currentMode = Mode.Draw;
  42. Memory.SuppressDraw = false;
  43. }
  44. public static void Update()
  45. {
  46. switch (currentMode)
  47. {
  48. case Mode.Initialize:
  49. Initialize();
  50. currentMode++;
  51. break;
  52. case Mode.Draw:
  53. pointer++;
  54. if (pointer >= FaceValue.Length) pointer = 0;
  55. currentMode++;
  56. break;
  57. case Mode.Wait:
  58. if (Input2.DelayedButton(InputActions.Cancel))
  59. {
  60. Memory.Module = OpenVIII.Module.MainMenuDebug;
  61. return;
  62. }
  63. time += Memory.ElapsedGameTime;
  64. if (time > TimeSpan.FromMilliseconds(2000))
  65. {
  66. currentMode--;
  67. time = TimeSpan.Zero;
  68. }
  69. else
  70. Memory.SuppressDraw = true;
  71. break;
  72. }
  73. }
  74. private static void DrawFace()
  75. {
  76. if (pointer >= 0)
  77. {
  78. var vp = Memory.Graphics.GraphicsDevice.Viewport;
  79. var rows = 2;
  80. var cols = 8;
  81. var totalitems = rows * cols;
  82. var id = FaceValue[pointer];
  83. var pos = (int)id;
  84. int i = Memory.Faces.GetEntry(id).File;
  85. var col = (pos % cols);
  86. var row = (pos / cols) % rows;
  87. var scale = vp.Height / Memory.Faces.GetEntry(id).Height;
  88. var dst = new Rectangle(new Point(0), (Memory.Faces.GetEntry(id).Size * scale).ToPoint());
  89. dst.Offset(vp.Width / 2 - dst.Center.X, 0);
  90. Memory.SpriteBatchStartAlpha();
  91. Memory.SpriteBatch.GraphicsDevice.Clear(Color.Black);
  92. Memory.Faces.Draw(id, dst);
  93. Memory.Font.RenderBasicText($"{FaceValue[pointer].ToString().Replace('_', ' ')}\n" +
  94. $"pos: {pos}\n" +
  95. $"file: {i}\n" +
  96. $"col: {col}\n" +
  97. $"row: {row}\n" +
  98. $"x: {Memory.Faces.GetEntry(id).X}\n" +
  99. $"y: {Memory.Faces.GetEntry(id).Y}\n" +
  100. $"width: {Memory.Faces.GetEntry(id).Width}\n" +
  101. $"height: {Memory.Faces.GetEntry(id).Height}",
  102. (int)(vp.Width * 0.10f), (int)(vp.Height * 0.05f), lineSpacing: 1);
  103. Memory.SpriteBatchEnd();
  104. }
  105. }
  106. private static void Initialize()
  107. {
  108. FaceValue = (Faces.ID[])Enum.GetValues(typeof(Faces.ID));
  109. Array.Sort(FaceValue);
  110. }
  111. #endregion Methods
  112. }
  113. }