Commands.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. using Microsoft.Xna.Framework;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. namespace OpenVIII.IGMData.Pool
  6. {
  7. public partial class Draw
  8. {
  9. #region Classes
  10. /// <summary>
  11. /// (Draw) or (Cast and display target window)
  12. /// </summary>
  13. protected class Commands : IGMData.Base
  14. {
  15. #region Fields
  16. public Dictionary<int, Func<bool>> OKAY_Actions;
  17. private Battle.Dat.Magic Magic;
  18. #endregion Fields
  19. #region Properties
  20. public int _Draw => 0;
  21. public int Cast => 1;
  22. public IGMData.Target.Group Target_Group => (IGMData.Target.Group)(((IGMData.Base)ITEM[Targets_Window, 0]));
  23. public int Targets_Window => Count - 1;
  24. #endregion Properties
  25. #region Methods
  26. public static Commands Create(Rectangle pos, Damageable damageable, bool battle = false) => Create<Commands>(3, 1, new IGMDataItem.Box { Pos = pos, Title = Icons.ID.CHOICE }, 1, 2, damageable);
  27. public override void HideChildren()
  28. {
  29. if (Enabled)
  30. {
  31. //base.Hide();
  32. //maybe overkill to run hide on items. if group is hidden it won't draw.
  33. if (!skipdata)
  34. {
  35. var pos = 0;
  36. foreach (var i in ITEM)
  37. {
  38. if (pos != _Draw && pos != Cast && i != null)
  39. {
  40. i.HideChildren();
  41. i.Hide();
  42. }
  43. else i?.HideChildren();
  44. }
  45. }
  46. }
  47. }
  48. public override bool Inputs()
  49. {
  50. if (Target_Group.Enabled)
  51. {
  52. Cursor_Status |= Cursor_Status.Blinking;
  53. return Target_Group.Inputs();
  54. }
  55. else
  56. {
  57. Cursor_Status &= ~Cursor_Status.Blinking;
  58. return base.Inputs();
  59. }
  60. }
  61. public override bool Inputs_CANCEL()
  62. {
  63. Hide();
  64. return true;
  65. }
  66. public override bool Inputs_OKAY()
  67. {
  68. var ret = false;
  69. if (OKAY_Actions.TryGetValue(CURSOR_SELECT, out var func))
  70. ret = func();
  71. if (ret)
  72. base.Inputs_OKAY();
  73. return ret;
  74. }
  75. public override void Refresh()
  76. {
  77. if (Magic.ID > 0)
  78. {
  79. var gf = Magic.GF != GFs.Blank;
  80. var full = (Damageable.GetCharacterData(out var c) && c.Magics.TryGetByKey(Magic.ID, out var qty) && qty < 100);
  81. //TODO check for empty magic slots. as can only have 30 something spells in inventory.
  82. var candraw = gf || !full;
  83. if (!candraw)
  84. {
  85. ((IGMDataItem.Text)ITEM[_Draw, 0]).FontColor = Font.ColorID.Dark_Grey;
  86. BLANKS[_Draw] = true;
  87. }
  88. else
  89. {
  90. ((IGMDataItem.Text)ITEM[_Draw, 0]).FontColor = Font.ColorID.White;
  91. BLANKS[_Draw] = false;
  92. }
  93. if (gf)
  94. {
  95. ((IGMDataItem.Text)ITEM[Cast, 0]).FontColor = Font.ColorID.Dark_Grey;
  96. BLANKS[_Draw] = true;
  97. }
  98. else
  99. {
  100. Target_Group.SelectTargetWindows(Magic.Data);
  101. ((IGMDataItem.Text)ITEM[Cast, 0]).FontColor = Font.ColorID.White;
  102. BLANKS[_Draw] = false;
  103. }
  104. }
  105. base.Refresh();
  106. }
  107. public void Refresh(Battle.Dat.Magic magic)
  108. {
  109. if (Magic.ID != magic.ID)
  110. {
  111. Magic = magic;
  112. Refresh();
  113. }
  114. }
  115. protected override void Init()
  116. {
  117. base.Init();
  118. ITEM[_Draw, 0] = new IGMDataItem.Text { Data = Memory.Strings.Read(Strings.FileID.Kernel, 0, 12), Pos = SIZE[_Draw] };
  119. ITEM[Cast, 0] = new IGMDataItem.Text { Data = Memory.Strings.Read(Strings.FileID.Kernel, 0, 18), Pos = SIZE[Cast] };
  120. ITEM[Targets_Window, 0] = IGMData.Target.Group.Create(Damageable, false);
  121. Cursor_Status = Cursor_Status.Enabled;
  122. OKAY_Actions = new Dictionary<int, Func<bool>>
  123. {
  124. {_Draw, Inputs_OKAY_Draw },
  125. {Cast, Inputs_OKAY_Cast },
  126. };
  127. PointerZIndex = 0;
  128. }
  129. protected override void InitShift(int i, int col, int row)
  130. {
  131. base.InitShift(i, col, row);
  132. //SIZE[i].Inflate(-18, -20);
  133. //SIZE[i].Y -= 5 * row;
  134. SIZE[i].Inflate(-22, -8);
  135. SIZE[i].Offset(0, 12 + (-8 * row));
  136. SIZE[i].Height = (int)(12 * TextScale.Y);
  137. }
  138. private bool Inputs_OKAY_Cast()
  139. {
  140. Debug.WriteLine($"{Damageable.Name} Casting {Magic.Name}({Magic.ID}) from enemy.");
  141. Target_Group.ShowTargetWindows();
  142. return true;
  143. }
  144. private bool Inputs_OKAY_Draw()
  145. {
  146. Debug.WriteLine($"{Damageable.Name} Drawing {Magic.Name}({Magic.ID}) from enemy.");
  147. Damageable.EndTurn();
  148. return true;
  149. }
  150. #endregion Methods
  151. }
  152. #endregion Classes
  153. }
  154. }