Module_icon_test.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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(InputActions.Cancel))
  77. {
  78. Memory.Module = OpenVIII.Module.MainMenuDebug;
  79. return;
  80. }
  81. if (Input2.DelayedButton(new InputButton() { Key = Keys.OemMinus, Trigger = ButtonTrigger.Press }) || Input2.DelayedButton(new InputButton() { Key = Keys.Subtract, Trigger = ButtonTrigger.Press }))
  82. {
  83. if (zoom - 1 < 1f)
  84. zoom = 1f;
  85. else
  86. zoom--;
  87. Show();
  88. }
  89. if (Input2.DelayedButton(new InputButton() { Key = Keys.OemPlus, Trigger = ButtonTrigger.Press }) || Input2.DelayedButton(new InputButton() { Key = Keys.Add, Trigger = ButtonTrigger.Press }))
  90. {
  91. if (zoom + 1 > 100f)
  92. zoom = 100f;
  93. else
  94. zoom++;
  95. Show();
  96. }
  97. if (Input2.DelayedButton(FF8TextTagKey.Up))
  98. {
  99. if (palette <= 0)
  100. palette = (int)Memory.Icons.PaletteCount - 1;
  101. else
  102. palette--;
  103. Show();
  104. }
  105. if (Input2.DelayedButton(FF8TextTagKey.Down))
  106. {
  107. if (palette >= Memory.Icons.PaletteCount - 1)
  108. palette = 0;
  109. else
  110. palette++;
  111. Show();
  112. }
  113. if (Input2.DelayedButton(FF8TextTagKey.Right) || Input2.Button(Keys.PageDown))
  114. {
  115. do
  116. {
  117. if (icon >= Enum.GetValues(typeof(Icons.ID)).Cast<Icons.ID>().Max())
  118. icon = 0;
  119. else
  120. icon++;
  121. }
  122. while (Memory.Icons.GetEntry(icon) == null);
  123. Show();
  124. }
  125. if (Input2.DelayedButton(FF8TextTagKey.Left) || Input2.Button(Keys.PageUp))
  126. {
  127. do
  128. {
  129. if (icon <= 0)
  130. icon = Enum.GetValues(typeof(Icons.ID)).Cast<Icons.ID>().Max();
  131. //else if (Memory.Icons.GetEntry(icon) != null && Memory.Icons.GetEntry(icon).GetLoc.Count > 1)
  132. // icon -= Memory.Icons.GetEntry(icon).GetLoc.Count;
  133. else
  134. icon--;
  135. }
  136. while (Memory.Icons.GetEntry(icon) == null);
  137. Show();
  138. }
  139. switch (currentMode)
  140. {
  141. case Mode.Initialize:
  142. //SaveStringToFile();
  143. currentMode++;
  144. break;
  145. case Mode.Draw:
  146. currentMode++;
  147. break;
  148. case Mode.Wait:
  149. Memory.SuppressDraw = true;
  150. break;
  151. }
  152. }
  153. private static void DrawIcons()
  154. {
  155. Memory.SpriteBatchStartAlpha(ss: SamplerState.PointClamp);
  156. Memory.SpriteBatch.GraphicsDevice.Clear(Color.Gray);
  157. Memory.SpriteBatchEnd();
  158. var vp = Memory.Graphics.GraphicsDevice.Viewport;
  159. var scale = new Vector2(zoom);
  160. var dst = new Rectangle()
  161. {
  162. Width = (int)(Memory.Icons.GetEntryGroup(icon).Width * scale.X),
  163. Height = (int)(Memory.Icons.GetEntryGroup(icon).Height * scale.Y)
  164. };
  165. if (icon == Icons.ID.Menu_BG_368)
  166. {
  167. dst.Width = vp.Width;
  168. dst.Height = vp.Height - 50;
  169. scale = Vector2.Zero;
  170. }
  171. else
  172. {
  173. dst.X = vp.Width / 2 - dst.Width / 2;
  174. dst.Y = vp.Height / 2 - dst.Height / 2;
  175. }
  176. dst.Size = Point.Zero;
  177. Memory.SpriteBatchStartAlpha(ss: SamplerState.PointClamp);
  178. Memory.Icons.Draw(icon, palette, dst, scale);
  179. Memory.Font.RenderBasicText(
  180. $"{(icon).ToString().Replace('_', ' ')}\n" +
  181. $"ID: {(ushort)icon}\n\n" +
  182. $"palette: {palette}\n\n" +
  183. $"width: {Memory.Icons[icon].Width}\n" +
  184. $"height: {Memory.Icons[icon].Height}",
  185. (int)(vp.Width * 0.10f), (int)(vp.Height * 0.05f), lineSpacing: 0);
  186. Memory.SpriteBatchEnd();
  187. }
  188. #endregion Methods
  189. }
  190. }