Module_icon_test.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using Microsoft.Xna.Framework.Input;
  4. using System;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. namespace FF8
  9. {
  10. public static class Module_icon_test
  11. {
  12. #region Fields
  13. private static Mode currentMode;
  14. private static Icons.ID icon;
  15. private const int DefaultPallet = 2;
  16. private static int pallet = DefaultPallet;
  17. #endregion Fields
  18. #region Enums
  19. private enum Mode
  20. {
  21. Initialize,
  22. Draw,
  23. Wait
  24. }
  25. #endregion Enums
  26. #region Methods
  27. public static void Draw()
  28. {
  29. switch (currentMode)
  30. {
  31. case Mode.Initialize:
  32. break;
  33. case Mode.Wait:
  34. case Mode.Draw:
  35. DrawIcons();
  36. break;
  37. }
  38. }
  39. public static void Update()
  40. {
  41. if (Input.Button(Keys.Up))
  42. {
  43. if (pallet <= 0)
  44. pallet = (int)Memory.Icons.PalletCount - 1;
  45. else
  46. pallet--;
  47. currentMode = Mode.Draw;
  48. }
  49. if (Input.Button(Keys.Down))
  50. {
  51. if (pallet >= Memory.Icons.PalletCount - 1)
  52. pallet = 0;
  53. else
  54. pallet++;
  55. currentMode = Mode.Draw;
  56. }
  57. //if ((Input.Button(Keys.Up) || Input.Button(Keys.Down)) && Memory.Icons.GetEntry(icon) != null && (Memory.Icons.GetEntry(icon).GetLoc.count > 1))
  58. // icon -= (Memory.Icons.GetEntry(icon).GetLoc.count - 1);
  59. if (Input.Button(Keys.Right))
  60. {
  61. do
  62. {
  63. if (icon >= Enum.GetValues(typeof(Icons.ID)).Cast<Icons.ID>().Max())
  64. icon = 0;
  65. else
  66. icon++;
  67. }
  68. while (Memory.Icons.GetEntry(icon) == null);
  69. currentMode = Mode.Draw;
  70. }
  71. if (Input.Button(Keys.Left))
  72. {
  73. do
  74. {
  75. if (icon <= 0)
  76. icon = Enum.GetValues(typeof(Icons.ID)).Cast<Icons.ID>().Max();
  77. //else if (Memory.Icons.GetEntry(icon) != null && Memory.Icons.GetEntry(icon).GetLoc.count > 1)
  78. // icon -= Memory.Icons.GetEntry(icon).GetLoc.count;
  79. else
  80. icon--;
  81. }
  82. while (Memory.Icons.GetEntry(icon) == null);
  83. currentMode = Mode.Draw;
  84. }
  85. switch (currentMode)
  86. {
  87. case Mode.Initialize:
  88. //SaveStringToFile();
  89. currentMode++;
  90. break;
  91. case Mode.Draw:
  92. currentMode++;
  93. break;
  94. case Mode.Wait:
  95. Memory.SuppressDraw = true;
  96. break;
  97. }
  98. }
  99. private static void DrawIcons()
  100. {
  101. Memory.SpriteBatchStartAlpha(SamplerState.PointClamp);
  102. Memory.spriteBatch.GraphicsDevice.Clear(Color.Black);
  103. Memory.SpriteBatchEnd();
  104. Viewport vp = Memory.graphics.GraphicsDevice.Viewport;
  105. Vector2 scale = new Vector2(4f);
  106. Rectangle dst = new Rectangle()
  107. {
  108. Width = (int)(Memory.Icons.GetEntryGroup(icon).Width * scale.X),
  109. Height = (int)(Memory.Icons.GetEntryGroup(icon).Height * scale.Y)
  110. };
  111. if (icon == Icons.ID.Menu_BG_368)
  112. {
  113. dst.Width = vp.Width;
  114. dst.Height = vp.Height - 50;
  115. scale = Vector2.Zero;
  116. }
  117. else
  118. {
  119. dst.X = vp.Width / 2 - dst.Width / 2;
  120. dst.Y = vp.Height / 2 - dst.Height / 2;
  121. }
  122. Memory.SpriteBatchStartAlpha(SamplerState.PointClamp);
  123. Memory.Icons.Draw(icon, pallet, dst, scale);
  124. Memory.font.RenderBasicText(new FF8String($"{(icon).ToString().Replace('_', ' ')}\nid: {(ushort)icon}\n\npallet: {pallet}\n\nwidth: {Memory.Icons[icon].Width}\nheight: {Memory.Icons[icon].Height}"), (int)(vp.Width * 0.10f), (int)(vp.Height * 0.05f), 1f, 2f, 0, 1);
  125. Memory.SpriteBatchEnd();
  126. }
  127. static public void SaveStringToFile()
  128. {
  129. using (FileStream fs = File.Create("D:\\iconsdatadump.csv"))
  130. using (BinaryWriter bw = new BinaryWriter(fs))
  131. {
  132. bw.Write(Encoding.UTF8.GetBytes(ToString()));
  133. }
  134. }
  135. static public new string ToString()
  136. {
  137. string output = "{Enum Name},{Enum ID}," + Memory.Icons.GetEntry(Icons.ID.Finger_Right).ToStringHeader;
  138. for(uint i = 0; i < Memory.Icons.Count; i++)
  139. {
  140. EntryGroup eg = Memory.Icons.GetEntryGroup((Icons.ID)i);
  141. foreach(Entry e in eg)
  142. {
  143. output += $"{((Icons.ID)i).ToString().Replace('_', ' ')},{i}," + e.ToString();
  144. }
  145. }
  146. return output;
  147. }
  148. #endregion Methods
  149. }
  150. }