Icons.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. internal 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. //FORCE_ORIGINAL = true;
  20. TextureBigFilename = new string[] { "iconfl{0:00}.TEX" };
  21. TextureBigSplit = new uint[] { 4 };
  22. TextureFilename[0] = "icon.tex";
  23. IndexFilename = "icon.sp1";
  24. Init();
  25. }
  26. #endregion Constructors
  27. #region Properties
  28. public new uint Count => (uint)Entries.Count();
  29. public new uint PalletCount => (uint)Textures.Count();
  30. public new uint TextureCount => 1;
  31. private new uint TextureStartOffset => 0;// this really isn't improtant to icons.
  32. public new uint EntriesPerTexture => (uint)Enum.GetValues(typeof(Icons.ID)).Cast<Icons.ID>().Max(); // this really isn't improtant to icons.
  33. #endregion Properties
  34. #region Indexers
  35. public new EntryGroup this[Enum id] => GetEntryGroup(id);
  36. #endregion Indexers
  37. #region Methods
  38. protected override void InitTextures(ArchiveWorker aw = null)
  39. {
  40. TEX tex;
  41. tex = new TEX(ArchiveWorker.GetBinaryFile(ArchiveString,
  42. aw.GetListOfFiles().First(x => x.IndexOf(TextureFilename[0], StringComparison.OrdinalIgnoreCase) >= 0)));
  43. Textures = new List<TextureHandler>(tex.TextureData.NumOfPalettes);
  44. for (int i = 0; i < tex.TextureData.NumOfPalettes; i++)
  45. {
  46. if (FORCE_ORIGINAL == false && TextureBigFilename != null && TextureBigSplit != null)
  47. Textures.Add(new TextureHandler(TextureBigFilename[0], tex, 2, TextureBigSplit[0] / 2, i));
  48. else
  49. Textures.Add(new TextureHandler(TextureFilename[0], tex, 1, 1, i));
  50. }
  51. }
  52. protected override void InitEntries(ArchiveWorker aw = null)
  53. {
  54. if (Entries == null)
  55. {
  56. //read from icon.sp1
  57. using (MemoryStream ms = new MemoryStream(ArchiveWorker.GetBinaryFile(ArchiveString,
  58. aw.GetListOfFiles().First(x => x.IndexOf(IndexFilename, StringComparison.OrdinalIgnoreCase) >= 0))))
  59. {
  60. using (BinaryReader br = new BinaryReader(ms))
  61. {
  62. Loc[] locs = new Loc[br.ReadUInt32()];
  63. for (int i = 0; i < locs.Length; i++)
  64. {
  65. locs[i].seek = br.ReadUInt16();
  66. locs[i].length = br.ReadUInt16();
  67. }
  68. Entries = new Dictionary<ID, EntryGroup>(locs.Length + 10);
  69. for (int i = 0; i < locs.Length; i++)
  70. {
  71. ms.Seek(locs[i].seek, SeekOrigin.Begin);
  72. byte c = (byte)locs[i].length;
  73. Entries[(ID)i] = new EntryGroup(c);
  74. for (int e = 0; e < c; e++)
  75. {
  76. Entry tmp = new Entry();
  77. tmp.LoadfromStreamSP1(br);
  78. tmp.Part = (byte)e;
  79. tmp.SetLoc(locs[i]);
  80. Entries[(ID)i].Add(tmp);
  81. }
  82. }
  83. }
  84. //custom stuff not in sp1
  85. InsertCustomEntries();
  86. }
  87. }
  88. }
  89. public void Draw(int number,byte type, int pallet, string format, Vector2 location, Vector2 scale, float fade = 1f)
  90. {
  91. ID[] numberstarts = { ID.Size_08x08_0, ID.Size_08x08_ALT_0,ID.Size_08x08_ALT2_0, ID.Size_08x16_0, ID.Size_08x16_ALT_0, ID.Size_16x16_0 };
  92. List<ID>[] nums = new List<ID>[numberstarts.Length];
  93. int j = 0;
  94. foreach (ID id in numberstarts)
  95. {
  96. nums[j] = new List<ID>(10);
  97. for (byte i = 0; i < 10; i++)
  98. {
  99. nums[j].Add(id + i);
  100. }
  101. j++;
  102. }
  103. IEnumerable<int> intList = number.ToString(format).Select(digit => int.Parse(digit.ToString()));
  104. var dst = new Rectangle { Location = location.ToPoint() };
  105. foreach (int i in intList)
  106. {
  107. Draw(nums[type][i], pallet,dst, scale, fade);
  108. dst.Offset(Entries[nums[type][i]].GetRectangle.Width* scale.X, 0);
  109. }
  110. }
  111. public void Draw(Enum id, int pallet, Rectangle dst, Vector2 scale, float fade = 1f) => Entries[(ID)id].Draw(Textures, pallet, dst, scale, fade);
  112. public override void Draw(Enum id, Rectangle dst, float fade = 1) => Draw((ID)id, 2, dst, Vector2.One,fade);
  113. public Entry GetEntry(Enum id, int index) => Entries[(ID)id][index] ?? null;
  114. public override Entry GetEntry(Enum id) => Entries[(ID)id][0] ?? null;
  115. public EntryGroup GetEntryGroup(Enum id) => Entries[(ID)id] ?? null;
  116. #endregion Methods
  117. }
  118. }