PartyAP.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. using System.Collections.Concurrent;
  2. using System.Collections.Generic;
  3. using Microsoft.Xna.Framework;
  4. using OpenVIII.AV;
  5. using OpenVIII.Encoding.Tags;
  6. using OpenVIII.IGMData.Dialog;
  7. using OpenVIII.IGMDataItem;
  8. using OpenVIII.Kernel;
  9. namespace OpenVIII.IGMData
  10. {
  11. public class PartyAP : Base
  12. {
  13. #region Fields
  14. private readonly FF8String DialogSelectedAbility;
  15. private readonly FF8String DialogSelectedGF;
  16. private readonly FF8String DialogSelectedIcon;
  17. private readonly FF8String DialogSelectedNum;
  18. private readonly FF8String str_GF_AP;
  19. private readonly FF8String str_Learn;
  20. private readonly FF8String str_Levelup;
  21. private ConcurrentQueue<KeyValuePair<GFs, Abilities>> _abilities;
  22. private uint _ap;
  23. private GFs _gf;
  24. #endregion Fields
  25. #region Constructors
  26. private PartyAP()
  27. {
  28. DialogSelectedGF = new[] { (byte)FF8TextTagCode.Dialog, (byte)FF8TextTagDialog.SelectedGF };
  29. DialogSelectedNum = new[] { (byte)FF8TextTagCode.Dialog, (byte)FF8TextTagDialog.Number };
  30. DialogSelectedAbility = new[] { (byte)FF8TextTagCode.Dialog, (byte)FF8TextTagDialog.SelectedGFAbility };
  31. DialogSelectedIcon = new[] { (byte)FF8TextTagCode.Dialog, (byte)FF8TextTagDialog.CustomICON };
  32. str_Levelup =
  33. Strings.Name.GF2 +
  34. DialogSelectedGF + " " +
  35. Strings.Name.LevelUP_;
  36. str_Learn =
  37. Strings.Name.GF2 +
  38. DialogSelectedGF + "\n " +
  39. Strings.Name.Learned + "\n " +
  40. DialogSelectedIcon + " " +
  41. DialogSelectedAbility +
  42. Strings.Name.ExclamationPoint;
  43. str_GF_AP = Strings.Name.GF_Received_X_AP_;
  44. Leveled = new ConcurrentQueue<GFs>();
  45. }
  46. #endregion Constructors
  47. #region Properties
  48. public ConcurrentQueue<KeyValuePair<GFs, Abilities>> Abilities { get => _abilities; set => _abilities = value; }
  49. public uint AP
  50. {
  51. get => _ap; set
  52. {
  53. _ap = value;
  54. ((Small)ITEM[0, 1]).Data = str_GF_AP.Clone().Replace(DialogSelectedNum, _ap.ToString());
  55. Leveled = Memory.State.EarnAP(_ap, out _abilities);
  56. }
  57. }
  58. public GFs GF { get => _gf; private set => _gf = value; }
  59. public ConcurrentQueue<GFs> Leveled { get; set; }
  60. #endregion Properties
  61. #region Methods
  62. public static PartyAP Create(Rectangle pos)
  63. {
  64. var r = new PartyAP();
  65. r.Init(1, 7, new Empty { Pos = pos }, 1, 1);
  66. return r;
  67. }
  68. public void Earn()
  69. {
  70. skipsnd = true;
  71. Sound.Play(17);
  72. }
  73. public override bool Inputs_CANCEL() => false;
  74. public override bool Inputs_OKAY()
  75. {
  76. base.Inputs_OKAY();
  77. if (ITEM[0, 1].Enabled)
  78. {
  79. ITEM[0, 1].Hide();
  80. ITEM[0, 2].Show();
  81. }
  82. if (Leveled != null && Leveled.Count > 0)
  83. {
  84. Refresh();
  85. return true;
  86. }
  87. if (Abilities != null && Abilities.Count > 0)
  88. {
  89. if (!ITEM[0, 3].Enabled)
  90. {
  91. ITEM[0, 2].Hide();
  92. ITEM[0, 3].Show();
  93. }
  94. Refresh();
  95. return true;
  96. }
  97. ITEM[0, 1].Show();
  98. ITEM[0, 2].Hide();
  99. ITEM[0, 3].Hide();
  100. return false;
  101. }
  102. public void Learn()
  103. {
  104. if (Abilities.TryDequeue(out var Ability))
  105. {
  106. GF = Ability.Key;
  107. ((Small)ITEM[0, 3]).Data =
  108. str_Learn.Clone()
  109. .Replace(DialogSelectedGF, Memory.Strings.GetName(GF))
  110. .Replace(DialogSelectedIcon, DialogSelectedIcon.Clone() + new[] {
  111. (byte)((short)Memory.KernelBin.AllAbilities[Ability.Value].Icon & 0xFF),
  112. (byte)(((short)Memory.KernelBin.AllAbilities[Ability.Value].Icon & 0xFF00)>>8),
  113. (Memory.KernelBin.AllAbilities[Ability.Value].Palette)
  114. })
  115. .Replace(DialogSelectedAbility, Memory.KernelBin.AllAbilities[Ability.Value].Name);
  116. skipsnd = true;
  117. Sound.Play(0x28);
  118. }
  119. }
  120. public void Level()
  121. {
  122. if (Leveled.TryDequeue(out _gf))
  123. {
  124. ((Small)ITEM[0, 2]).Data = str_Levelup.Clone().Replace(DialogSelectedGF, Memory.Strings.GetName(GF));
  125. skipsnd = true;
  126. Sound.Play(0x28);
  127. }
  128. }
  129. public override void Refresh()
  130. {
  131. base.Refresh();
  132. if (Enabled)
  133. {
  134. if (ITEM[0, 1].Enabled)
  135. Earn();
  136. else if (ITEM[0, 2].Enabled && Leveled != null && Leveled.Count > 0)
  137. Level();
  138. else if (ITEM[0, 3].Enabled && Abilities != null && Abilities.Count > 0)
  139. Learn();
  140. }
  141. }
  142. protected override void Init()
  143. {
  144. base.Init();
  145. Hide();
  146. ITEM[0, 0] = new Box { Data = Strings.Name.Raising_GF, Pos = new Rectangle(SIZE[0].X, SIZE[0].Y, SIZE[0].Width, 78), Title = Icons.ID.INFO, Options = Box_Options.Middle };
  147. ITEM[0, 1] = Small.Create(str_GF_AP, SIZE[0].X + 232, SIZE[0].Y + 315, Icons.ID.NOTICE, Box_Options.Center | Box_Options.Middle, SIZE[0]); // GF recieved ### AP!
  148. ITEM[0, 2] = Small.Create(null, SIZE[0].X + 232, SIZE[0].Y + 315, Icons.ID.NOTICE, Box_Options.Center | Box_Options.Middle, SIZE[0]); // GF Leveled up!
  149. ITEM[0, 3] = Small.Create(null, SIZE[0].X + 232, SIZE[0].Y + 315, Icons.ID.NOTICE, Box_Options.Center | Box_Options.Middle, SIZE[0]); // GF Leveled up!
  150. ITEM[0, 1].Show();
  151. ITEM[0, 2].Hide();
  152. ITEM[0, 3].Hide();
  153. Cursor_Status |= (Cursor_Status.Hidden | (Cursor_Status.Enabled | Cursor_Status.Static));
  154. }
  155. #endregion Methods
  156. }
  157. }