Icons.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. using Microsoft.Xna.Framework;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. namespace FF8
  7. {
  8. /// <summary>
  9. /// Images of parts of most of the menus and ui.
  10. /// </summary>
  11. public partial class Icons : SP2
  12. {
  13. #region Fields
  14. private new Dictionary<ID, EntryGroup> Entries = null;
  15. #endregion Fields
  16. #region Constructors
  17. public Icons()
  18. {
  19. Color[] red = new Color[256];
  20. red[15] = new Color(255, 30, 30, 255); //red
  21. red[14] = new Color(140, 30, 30, 255); //dark red
  22. red[13] = new Color(37, 37, 37, 255); //gray
  23. Color[] yellow = new Color[256];
  24. yellow[15] = new Color(222, 222, 8, 255); //yellow
  25. yellow[14] = new Color(131, 131, 24, 255); //dark yellow
  26. yellow[13] = new Color(41, 41, 41, 255); //gray
  27. //FORCE_ORIGINAL = true;
  28. Props = new List<TexProps>()
  29. {
  30. new TexProps("icon.tex",1,new BigTexProps("iconfl{0:00}.TEX",4)), //0-15 pallet
  31. new TexProps("icon.tex",1,red, new BigTexProps("iconfl{0:00}.TEX",4,red)),//16 pallet
  32. new TexProps("icon.tex",1,yellow, new BigTexProps("iconfl{0:00}.TEX",4,yellow))//17 pallet
  33. };
  34. IndexFilename = "icon.sp1";
  35. Init();
  36. }
  37. #endregion Constructors
  38. #region Enums
  39. public enum NumType
  40. {
  41. Num_8x8_0,
  42. Num_8x8_1,
  43. Num_8x8_2,
  44. Num_8x16_0,
  45. Num_8x16_1,
  46. Num_16x16_0,
  47. sysFntBig,
  48. sysfnt,
  49. menuFont,
  50. }
  51. #endregion Enums
  52. #region Properties
  53. public new uint EntriesPerTexture => (uint)Enum.GetValues(typeof(Icons.ID)).Cast<Icons.ID>().Max();
  54. public new uint PalletCount => (uint)Textures.Count();
  55. public new uint Count => (uint)Entries.Count();
  56. private new uint TextureStartOffset => 0;
  57. #endregion Properties
  58. // this really isn't improtant to icons. this really isn't improtant to icons.
  59. #region Indexers
  60. public new EntryGroup this[Enum id] => GetEntryGroup(id);
  61. #endregion Indexers
  62. #region Methods
  63. public void Draw(int number, NumType type, int pallet, string format, Vector2 location, Vector2 scale, float fade = 1f)
  64. {
  65. if (type == NumType.sysfnt)
  66. {
  67. Memory.font.RenderBasicText(number.ToString(), location, scale, Font.Type.sysfnt, Fade: fade);
  68. return;
  69. }
  70. else if (type == NumType.sysFntBig)
  71. {
  72. Memory.font.RenderBasicText(number.ToString(), location, scale, Font.Type.sysFntBig, Fade: fade);
  73. return;
  74. }
  75. else if (type == NumType.menuFont)
  76. {
  77. Memory.font.RenderBasicText(number.ToString(), location, scale, Font.Type.menuFont, Fade: fade);
  78. return;
  79. }
  80. ID[] numberstarts = { ID.Num_8x8_0_0, ID.Num_8x8_1_0, ID.Num_8x8_2_0, ID.Num_8x16_0_0, ID.Num_8x16_1_0, ID.Num_16x16_0_0 };
  81. List<ID>[] nums = new List<ID>[numberstarts.Length];
  82. int j = 0;
  83. foreach (ID id in numberstarts)
  84. {
  85. nums[j] = new List<ID>(10);
  86. for (byte i = 0; i < 10; i++)
  87. {
  88. nums[j].Add(id + i);
  89. }
  90. j++;
  91. }
  92. IEnumerable<int> intList = number.ToString(format).Select(digit => int.Parse(digit.ToString()));
  93. Rectangle dst = new Rectangle { Location = location.ToPoint() };
  94. foreach (int i in intList)
  95. {
  96. Draw(nums[(int)type][i], pallet, dst, scale, fade);
  97. dst.Offset(Entries[nums[(int)type][i]].GetRectangle.Width * scale.X, 0);
  98. }
  99. }
  100. public void Draw(Enum id, int pallet, Rectangle dst, Vector2 scale, float fade = 1f)
  101. {
  102. if ((ID)id != ID.None)
  103. Entries[(ID)id].Draw(Textures, pallet, dst, scale, fade);
  104. }
  105. public override void Draw(Enum id, Rectangle dst, float fade = 1) => Draw((ID)id, 2, dst, Vector2.One, fade);
  106. public Entry GetEntry(Enum id, int index) => Entries[(ID)id][index] ?? null;
  107. public override Entry GetEntry(Enum id) => Entries[(ID)id][0] ?? null;
  108. public EntryGroup GetEntryGroup(Enum id)
  109. {
  110. if ((ID)id != ID.None)
  111. return Entries[(ID)id] ?? null;
  112. return null;
  113. }
  114. protected override void InitEntries(ArchiveWorker aw = null)
  115. {
  116. if (Entries == null)
  117. {
  118. //read from icon.sp1
  119. using (MemoryStream ms = new MemoryStream(ArchiveWorker.GetBinaryFile(ArchiveString,
  120. aw.GetListOfFiles().First(x => x.IndexOf(IndexFilename, StringComparison.OrdinalIgnoreCase) >= 0))))
  121. {
  122. using (BinaryReader br = new BinaryReader(ms))
  123. {
  124. Loc[] locs = new Loc[br.ReadUInt32()];
  125. for (int i = 0; i < locs.Length; i++)
  126. {
  127. locs[i].seek = br.ReadUInt16();
  128. locs[i].length = br.ReadUInt16();
  129. }
  130. Entries = new Dictionary<ID, EntryGroup>(locs.Length + 10);
  131. for (int i = 0; i < locs.Length; i++)
  132. {
  133. ms.Seek(locs[i].seek, SeekOrigin.Begin);
  134. byte c = (byte)locs[i].length;
  135. Entries[(ID)i] = new EntryGroup(c);
  136. for (int e = 0; e < c; e++)
  137. {
  138. Entry tmp = new Entry();
  139. tmp.LoadfromStreamSP1(br);
  140. tmp.Part = (byte)e;
  141. tmp.SetLoc(locs[i]);
  142. Entries[(ID)i].Add(tmp);
  143. }
  144. }
  145. }
  146. //custom stuff not in sp1
  147. InsertCustomEntries();
  148. }
  149. }
  150. }
  151. protected override void InitTextures(ArchiveWorker aw = null)
  152. {
  153. Textures = new List<TextureHandler>();
  154. for (int t = 0; t < Props.Count; t++)
  155. {
  156. TEX tex;
  157. tex = new TEX(ArchiveWorker.GetBinaryFile(ArchiveString,
  158. aw.GetListOfFiles().First(x => x.IndexOf(Props[t].Filename, StringComparison.OrdinalIgnoreCase) >= 0)));
  159. if (Props[t].Colors == null || Props[t].Colors.Length == 0)
  160. {
  161. for (int i = 0; i < tex.TextureData.NumOfPalettes; i++)
  162. {
  163. if (FORCE_ORIGINAL == false && Props[t].Big != null && Props[t].Big.Count > 0)
  164. Textures.Add(new TextureHandler(Props[t].Big[0].Filename, tex, 2, Props[t].Big[0].Split / 2, i));
  165. else
  166. Textures.Add(new TextureHandler(Props[t].Filename, tex, 1, 1, i));
  167. }
  168. }
  169. else
  170. {
  171. if (FORCE_ORIGINAL == false && Props[t].Big != null && Props[t].Big.Count > 0)
  172. Textures.Add(new TextureHandler(Props[t].Big[0].Filename, tex, 2, Props[t].Big[0].Split / 2, Textures.Count,colors: Props[t].Big[0].Colors ?? Props[t].Colors));
  173. else
  174. Textures.Add(new TextureHandler(Props[t].Filename, tex, 1, 1, Textures.Count, colors: Props[t].Colors));
  175. }
  176. }
  177. }
  178. #endregion Methods
  179. }
  180. }