Module_icon_test.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using Microsoft.Xna.Framework.Input;
  4. using OpenVIII.Encoding.Tags;
  5. using System;
  6. using System.IO;
  7. using System.Linq;
  8. namespace OpenVIII
  9. {
  10. public static class Module_icon_test
  11. {
  12. #region Fields
  13. private const int DefaultPalette = 2;
  14. private static Mode currentMode;
  15. private static Icons.ID icon = Icons.ID.Arrow_Down;
  16. private static int palette = DefaultPalette;
  17. private static float zoom = 40f;
  18. #endregion Fields
  19. #region Enums
  20. private enum Mode
  21. {
  22. Initialize,
  23. Draw,
  24. Wait
  25. }
  26. #endregion Enums
  27. #region Methods
  28. public static void Draw()
  29. {
  30. switch (currentMode)
  31. {
  32. case Mode.Initialize:
  33. break;
  34. case Mode.Wait:
  35. case Mode.Draw:
  36. DrawIcons();
  37. break;
  38. }
  39. }
  40. public static void SaveStringToFile()
  41. {
  42. FileStream fs = null;
  43. //fs is disposed by binary writer
  44. using (var bw =
  45. new BinaryWriter(fs = File.Open("D:\\iconsdatadump.csv",
  46. FileMode.Create, FileAccess.Write, FileShare.ReadWrite)))
  47. {
  48. bw.Write(System.Text.Encoding.UTF8.GetBytes(ToString()));
  49. fs = null;
  50. }
  51. }
  52. /// <summary>
  53. /// Make sure the next frame will draw.
  54. /// </summary>
  55. public static void Show()
  56. {
  57. if (currentMode == Mode.Wait)
  58. currentMode = Mode.Draw;
  59. Memory.SuppressDraw = false;
  60. }
  61. public static new string ToString()
  62. {
  63. var output = "{Enum Name},{Enum ID}," + Memory.Icons.GetEntry(Icons.ID.Finger_Right).ToStringHeader;
  64. for (uint i = 0; i < Memory.Icons.Count; i++)
  65. {
  66. var eg = Memory.Icons.GetEntryGroup((Icons.ID)i);
  67. foreach (Entry e in eg)
  68. {
  69. output += $"{((Icons.ID)i).ToString().Replace('_', ' ')},{i}," + e.ToString();
  70. }
  71. }
  72. return output;
  73. }
  74. public static void Update()
  75. {
  76. if (Input2.DelayedButton(new InputButton() { Key = Keys.OemMinus, Trigger = ButtonTrigger.Press }) || Input2.DelayedButton(new InputButton() { Key = Keys.Subtract, Trigger = ButtonTrigger.Press }))
  77. {
  78. if (zoom - 1 < 1f)
  79. zoom = 1f;
  80. else
  81. zoom--;
  82. Show();
  83. }
  84. if (Input2.DelayedButton(new InputButton() { Key = Keys.OemPlus, Trigger = ButtonTrigger.Press }) || Input2.DelayedButton(new InputButton() { Key = Keys.Add, Trigger = ButtonTrigger.Press }))
  85. {
  86. if (zoom + 1 > 100f)
  87. zoom = 100f;
  88. else
  89. zoom++;
  90. Show();
  91. }
  92. if (Input2.DelayedButton(FF8TextTagKey.Up))
  93. {
  94. if (palette <= 0)
  95. palette = (int)Memory.Icons.PaletteCount - 1;
  96. else
  97. palette--;
  98. Show();
  99. }
  100. if (Input2.DelayedButton(FF8TextTagKey.Down))
  101. {
  102. if (palette >= Memory.Icons.PaletteCount - 1)
  103. palette = 0;
  104. else
  105. palette++;
  106. Show();
  107. }
  108. if (Input2.DelayedButton(FF8TextTagKey.Right) || Input2.Button(Keys.PageDown))
  109. {
  110. do
  111. {
  112. if (icon >= Enum.GetValues(typeof(Icons.ID)).Cast<Icons.ID>().Max())
  113. icon = 0;
  114. else
  115. icon++;
  116. }
  117. while (Memory.Icons.GetEntry(icon) == null);
  118. Show();
  119. }
  120. if (Input2.DelayedButton(FF8TextTagKey.Left) || Input2.Button(Keys.PageUp))
  121. {
  122. do
  123. {
  124. if (icon <= 0)
  125. icon = Enum.GetValues(typeof(Icons.ID)).Cast<Icons.ID>().Max();
  126. //else if (Memory.Icons.GetEntry(icon) != null && Memory.Icons.GetEntry(icon).GetLoc.Count > 1)
  127. // icon -= Memory.Icons.GetEntry(icon).GetLoc.Count;
  128. else
  129. icon--;
  130. }
  131. while (Memory.Icons.GetEntry(icon) == null);
  132. Show();
  133. }
  134. switch (currentMode)
  135. {
  136. case Mode.Initialize:
  137. //SaveStringToFile();
  138. currentMode++;
  139. break;
  140. case Mode.Draw:
  141. currentMode++;
  142. break;
  143. case Mode.Wait:
  144. Memory.SuppressDraw = true;
  145. break;
  146. }
  147. }
  148. private static void DrawIcons()
  149. {
  150. Memory.SpriteBatchStartAlpha(ss: SamplerState.PointClamp);
  151. Memory.SpriteBatch.GraphicsDevice.Clear(Color.Gray);
  152. Memory.SpriteBatchEnd();
  153. var vp = Memory.Graphics.GraphicsDevice.Viewport;
  154. var scale = new Vector2(zoom);
  155. var dst = new Rectangle()
  156. {
  157. Width = (int)(Memory.Icons.GetEntryGroup(icon).Width * scale.X),
  158. Height = (int)(Memory.Icons.GetEntryGroup(icon).Height * scale.Y)
  159. };
  160. if (icon == Icons.ID.Menu_BG_368)
  161. {
  162. dst.Width = vp.Width;
  163. dst.Height = vp.Height - 50;
  164. scale = Vector2.Zero;
  165. }
  166. else
  167. {
  168. dst.X = vp.Width / 2 - dst.Width / 2;
  169. dst.Y = vp.Height / 2 - dst.Height / 2;
  170. }
  171. dst.Size = Point.Zero;
  172. Memory.SpriteBatchStartAlpha(ss: SamplerState.PointClamp);
  173. Memory.Icons.Draw(icon, palette, dst, scale);
  174. Memory.Font.RenderBasicText(
  175. $"{(icon).ToString().Replace('_', ' ')}\n" +
  176. $"ID: {(ushort)icon}\n\n" +
  177. $"palette: {palette}\n\n" +
  178. $"width: {Memory.Icons[icon].Width}\n" +
  179. $"height: {Memory.Icons[icon].Height}",
  180. (int)(vp.Width * 0.10f), (int)(vp.Height * 0.05f), lineSpacing: 0);
  181. Memory.SpriteBatchEnd();
  182. }
  183. #endregion Methods
  184. }
  185. }