Module_face_test.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. time += Memory.ElapsedGameTime;
  59. if (time > TimeSpan.FromMilliseconds(2000))
  60. {
  61. currentMode--;
  62. time = TimeSpan.Zero;
  63. }
  64. else
  65. Memory.SuppressDraw = true;
  66. break;
  67. }
  68. }
  69. private static void DrawFace()
  70. {
  71. if (pointer >= 0)
  72. {
  73. var vp = Memory.Graphics.GraphicsDevice.Viewport;
  74. var rows = 2;
  75. var cols = 8;
  76. var totalitems = rows * cols;
  77. var id = FaceValue[pointer];
  78. var pos = (int)id;
  79. int i = Memory.Faces.GetEntry(id).File;
  80. var col = (pos % cols);
  81. var row = (pos / cols) % rows;
  82. var scale = vp.Height / Memory.Faces.GetEntry(id).Height;
  83. var dst = new Rectangle(new Point(0), (Memory.Faces.GetEntry(id).Size * scale).ToPoint());
  84. dst.Offset(vp.Width / 2 - dst.Center.X, 0);
  85. Memory.SpriteBatchStartAlpha();
  86. Memory.SpriteBatch.GraphicsDevice.Clear(Color.Black);
  87. Memory.Faces.Draw(id, dst);
  88. Memory.Font.RenderBasicText($"{FaceValue[pointer].ToString().Replace('_', ' ')}\n" +
  89. $"pos: {pos}\n" +
  90. $"file: {i}\n" +
  91. $"col: {col}\n" +
  92. $"row: {row}\n" +
  93. $"x: {Memory.Faces.GetEntry(id).X}\n" +
  94. $"y: {Memory.Faces.GetEntry(id).Y}\n" +
  95. $"width: {Memory.Faces.GetEntry(id).Width}\n" +
  96. $"height: {Memory.Faces.GetEntry(id).Height}",
  97. (int)(vp.Width * 0.10f), (int)(vp.Height * 0.05f), lineSpacing: 1);
  98. Memory.SpriteBatchEnd();
  99. }
  100. }
  101. private static void Initialize()
  102. {
  103. FaceValue = (Faces.ID[])Enum.GetValues(typeof(Faces.ID));
  104. Array.Sort(FaceValue);
  105. }
  106. #endregion Methods
  107. }
  108. }