Module_card_test.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. //time += Memory.gameTime.ElapsedGameTime;
  58. //if (time > totaltime)
  59. //{
  60. // currentMode--;
  61. // time = TimeSpan.Zero;
  62. //}
  63. //else
  64. if (pointer<0 || Input2.DelayedButton(Button_Flags.Right,ButtonTrigger.OnPress|ButtonTrigger.Force))
  65. {
  66. pointer++;
  67. if (pointer >= CardValue.Length) pointer = 0;
  68. currentMode--;
  69. }
  70. else if (Input2.DelayedButton(Button_Flags.Left, ButtonTrigger.OnPress | ButtonTrigger.Force))
  71. {
  72. pointer--;
  73. if (pointer <0) pointer = CardValue.Length-1;
  74. currentMode--;
  75. }
  76. else
  77. Memory.SuppressDraw = true;
  78. break;
  79. }
  80. }
  81. private static void DrawFace()
  82. {
  83. if (pointer >= 0)
  84. {
  85. var vp = Memory.Graphics.GraphicsDevice.Viewport;
  86. var id = CardValue[pointer];
  87. var pos = (uint)((uint)id % Memory.Cards.EntriesPerTexture);
  88. if (id >= Cards.ID.Card_Back)
  89. pos = Memory.Cards.Count-1;
  90. //int i = cards.GetEntry(ID).File;
  91. var entry = Memory.Cards.GetEntry(pos);
  92. var col = (uint)(entry.X / entry.Width) + 1;
  93. var row = (uint)(entry.Y / entry.Width) + 1;
  94. var dst = new Rectangle(new Point(0), entry.Size.ToPoint());
  95. dst.Height = (int)Math.Round(dst.Width * (1+Cards.AspectRatio));
  96. float scale = vp.Height / dst.Height;
  97. dst = dst.Scale(new Vector2(scale));
  98. dst.Offset(vp.Width / 2 - dst.Center.X, vp.Height / 2 - dst.Center.Y);
  99. Memory.SpriteBatchStartAlpha();
  100. Memory.SpriteBatch.GraphicsDevice.Clear(Color.Black);
  101. Memory.Cards.Draw(id, dst);
  102. Memory.Font.RenderBasicText(
  103. $"{CardValue[pointer].ToString().Replace('_', ' ')}\n" +
  104. $"pos: {(uint)id}\n" +
  105. $"col: {col}\n" +
  106. $"row: {row}\n" +
  107. $"x: {entry.X}\n" +
  108. $"y: {entry.Y}\n" +
  109. $"width: {entry.Width}\n" +
  110. $"height: {entry.Height}",
  111. (int)(vp.Width * 0.10f), (int)(vp.Height * 0.05f), lineSpacing: 1);
  112. Memory.SpriteBatchEnd();
  113. }
  114. }
  115. private static void Initialize()
  116. {
  117. CardValue = (Cards.ID[])Enum.GetValues(typeof(Cards.ID));
  118. Array.Sort(CardValue);
  119. }
  120. #endregion Methods
  121. }
  122. }