IGMData_Slots.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. using Microsoft.Xna.Framework;
  2. using System;
  3. using System.Collections.Generic;
  4. namespace OpenVIII
  5. {
  6. public partial class Junction
  7. {
  8. #region Classes
  9. public abstract class IGMData_Slots<C> : IGMData.Base
  10. where C : class
  11. {
  12. #region Fields
  13. protected bool eventAdded = false;
  14. protected List<Kernel.Abilities> unlocked;
  15. private C _prevSetting;
  16. private Font.ColorID? colorid = null;
  17. #endregion Fields
  18. #region Events
  19. public static event EventHandler<C> PrevSettingUpdateEventListener;
  20. #endregion Events
  21. #region Properties
  22. public Kernel.Stat[] Contents { get; protected set; }
  23. #endregion Properties
  24. #region Methods
  25. public static T Create<T>(int count, int depth, Menu_Base container = null, int? cols = null, int? rows = null) where T : IGMData_Slots<C>, new()
  26. {
  27. var r = IGMData.Base.Create<T>(count, depth, container, cols, rows);
  28. r.Contents = new Kernel.Stat[r.Count];
  29. return r;
  30. }
  31. public abstract void BackupSetting();
  32. public virtual void CheckMode(bool cursor = true) => CheckMode(0, Mode.None, Mode.None, false, false, cursor);
  33. public void CheckMode(int pos, Mode one, Mode two, bool slots, bool pools, bool cursor = true)
  34. {
  35. if (Junction != null && slots && Enabled)
  36. {
  37. Cursor_Status &= ~Cursor_Status.Horizontal;
  38. Cursor_Status |= Cursor_Status.Vertical;
  39. Cursor_Status &= ~Cursor_Status.Blinking;
  40. if (CURSOR_SELECT > pos)
  41. Junction.SetMode(two);
  42. else
  43. Junction.SetMode(one);
  44. }
  45. else if (Junction != null && pools && Enabled)
  46. {
  47. Cursor_Status |= Cursor_Status.Blinking;
  48. }
  49. if (cursor)
  50. Cursor_Status |= Cursor_Status.Enabled;
  51. else
  52. Cursor_Status &= ~Cursor_Status.Enabled;
  53. }
  54. public virtual void ConfirmChange() => SetPrevSetting(default);
  55. public C GetPrevSetting() => _prevSetting;
  56. public override bool Inputs()
  57. {
  58. var ret = false;
  59. if (CONTAINER.Pos.Contains(MouseLocation))
  60. {
  61. if (Input2.DelayedButton(MouseButtons.MouseWheelup))
  62. {
  63. PageLeft();
  64. ret = true;
  65. }
  66. else if (Input2.DelayedButton(MouseButtons.MouseWheeldown))
  67. {
  68. PageRight();
  69. ret = true;
  70. }
  71. if (ret)
  72. {
  73. if (!skipsnd)
  74. AV.Sound.Play(0);
  75. }
  76. }
  77. if (!ret)
  78. ret = base.Inputs();
  79. if (ret) CheckMode();
  80. return ret;
  81. }
  82. /// <summary>
  83. /// please overload with a if statement to check for mode you want or else this will run
  84. /// the checkmode method everytime a mode change happens.
  85. /// </summary>
  86. /// <param name="sender"></param>
  87. /// <param name="e"></param>
  88. public override void ModeChangeEvent(object sender, Enum e) => Refresh();
  89. public override void Refresh()
  90. {
  91. if (Damageable != null && Damageable.GetCharacterData(out var c))
  92. {
  93. unlocked = c.UnlockedGFAbilities;
  94. AddEventListener();
  95. CheckMode();
  96. base.Refresh();
  97. }
  98. }
  99. public abstract void UndoChange();
  100. /// <summary>
  101. /// Add event if not added already.
  102. /// </summary>
  103. protected virtual void AddEventListener()
  104. {
  105. if (!eventAdded)
  106. {
  107. Junction.ModeChangeHandler += ModeChangeEvent;
  108. IGMData_Values.ColorChangeEventListener += ColorChangeEvent;
  109. eventAdded = true;
  110. }
  111. }
  112. protected void FillData(Icons.ID starticon, Kernel.Stat statatk, Kernel.Stat statdef)
  113. {
  114. if (Damageable.GetCharacterData(out var c))
  115. for (byte pos = 0; pos < Count; pos++)
  116. {
  117. var stat = pos != 0 ? statdef + pos - 1 : statatk;
  118. Contents[pos] = stat;
  119. getColor(pos, out var palette, out var _colorid, out var unlocked);
  120. var name = GetName(stat);
  121. UpdateItems();
  122. FF8String GetName(Kernel.Stat key)
  123. {
  124. var _name = Memory.KernelBin.MagicData[c.StatJ[key]].Name;
  125. if (_name == null || _name.Length == 0)
  126. _name = Strings.Name._;
  127. return _name;
  128. }
  129. void UpdateItems()
  130. {
  131. ((IGMDataItem.Icon)ITEM[pos, 0]).Data = starticon + 1;
  132. ((IGMDataItem.Icon)ITEM[pos, 0]).Palette = palette;
  133. ((IGMDataItem.Text)ITEM[pos, 1]).Data = name;
  134. ((IGMDataItem.Text)ITEM[pos, 1]).FontColor = _colorid;
  135. BLANKS[pos] = !unlocked;
  136. }
  137. }
  138. }
  139. protected override void Init()
  140. {
  141. base.Init();
  142. for (byte pos = 0; pos < Count; pos++)
  143. {
  144. ITEM[pos, 0] = new IGMDataItem.Icon { Pos = new Rectangle(SIZE[pos].X, SIZE[pos].Y, 0, 0) };
  145. ITEM[pos, 1] = new IGMDataItem.Text { Pos = new Rectangle(SIZE[pos].X + 60, SIZE[pos].Y, 0, 0) };
  146. BLANKS[pos] = true;
  147. }
  148. }
  149. protected abstract void PageLeft();
  150. protected abstract void PageRight();
  151. protected void SetPrevSetting(C value)
  152. {
  153. if (!EqualityComparer<C>.Default.Equals(_prevSetting, value))
  154. {
  155. _prevSetting = value;
  156. PrevSettingUpdateEventListener?.Invoke(this, _prevSetting);
  157. if (value == null)
  158. colorid = null;
  159. }
  160. }
  161. /// <summary>
  162. /// overload me and return true if type at pos is unlocked or not.
  163. /// </summary>
  164. /// <param name="pos">current position</param>
  165. /// <returns></returns>
  166. protected virtual bool Unlocked(byte pos) => true;
  167. private void ColorChangeEvent(object sender, Font.ColorID e)
  168. {
  169. if (colorid != e)
  170. {
  171. colorid = e;
  172. Refresh();
  173. }
  174. }
  175. private void getColor(byte pos, out byte palette, out Font.ColorID _colorid, out bool unlocked)
  176. {
  177. unlocked = Unlocked(pos);
  178. palette = 2;
  179. _colorid = Font.ColorID.White;
  180. if (unlocked)
  181. {
  182. if (colorid != null && CURSOR_SELECT == pos && _prevSetting != null)
  183. {
  184. if (colorid == Font.ColorID.Red)
  185. {
  186. palette = 5;
  187. _colorid = Font.ColorID.Red;
  188. }
  189. else if (colorid == Font.ColorID.Yellow)
  190. {
  191. palette = 6;
  192. _colorid = Font.ColorID.Yellow;
  193. }
  194. }
  195. }
  196. else
  197. {
  198. palette = 7;
  199. _colorid = Font.ColorID.Grey;
  200. }
  201. }
  202. #endregion Methods
  203. }
  204. #endregion Classes
  205. }
  206. }