Module_card_test.cs 4.6 KB

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