VictoryMenu.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using Microsoft.Xna.Framework;
  2. using OpenVIII.Encoding.Tags;
  3. using System;
  4. using System.Collections.Concurrent;
  5. using System.Collections.Generic;
  6. using System.Threading.Tasks;
  7. namespace OpenVIII
  8. {
  9. public partial class VictoryMenu : Menu
  10. {
  11. #region Fields
  12. private uint _ap = 0;
  13. private ConcurrentDictionary<Cards.ID, byte> _cards;
  14. private int _exp = 0;
  15. private ConcurrentDictionary<Characters, int> _expextra;
  16. private ConcurrentDictionary<byte, byte> _items;
  17. private IReadOnlyDictionary<Mode, Func<bool>> InputFunctions;
  18. #endregion Fields
  19. #region Enums
  20. public enum Mode
  21. {
  22. Exp,
  23. Items,
  24. AP,
  25. All,
  26. }
  27. #endregion Enums
  28. #region Methods
  29. public static VictoryMenu Create() => Create<VictoryMenu>();
  30. public override bool Inputs()
  31. {
  32. bool ret = false;
  33. if (InputFunctions != null && InputFunctions.TryGetValue((Mode)GetMode(), out Func<bool> fun))
  34. {
  35. ret = fun();
  36. }
  37. if (!ret && Input2.Button(FF8TextTagKey.Confirm))
  38. {
  39. do
  40. {
  41. SetMode(((Mode)GetMode()) + 1);
  42. }
  43. while (
  44. (GetMode().Equals(Mode.Items) && _items.Count + _cards.Count == 0) ||
  45. (GetMode().Equals(Mode.AP) && _ap == 0));
  46. }
  47. return true;
  48. }
  49. /// <summary>
  50. /// if you use this you will get no exp, ap, or items
  51. /// </summary>
  52. public override void Refresh() { }
  53. /// <summary>
  54. /// if you use this you will get no exp, ap, or items, No character specifics for this menu.
  55. /// </summary>
  56. public override void Refresh(Damageable damageable, bool backup = false) { }
  57. public void Refresh(int exp, uint ap, ConcurrentDictionary<Characters, int> expextra, ConcurrentDictionary<byte, byte> items, ConcurrentDictionary<Cards.ID, byte> cards)
  58. {
  59. SetMode(Mode.Exp);
  60. _expextra = expextra;
  61. _exp = exp;
  62. ((IGMData.Group.PlayerEXP)Data[Mode.Exp]).NoEarnExp = true;
  63. ((IGMData.Group.PlayerEXP)Data[Mode.Exp]).EXP = _exp;
  64. ((IGMData.Group.PlayerEXP)Data[Mode.Exp]).EXPExtra = _expextra;
  65. ((IGMData.Group.PlayerEXP)Data[Mode.Exp]).NoEarnExp = false;
  66. _ap = ap;
  67. ((IGMData.PartyAP)Data[Mode.AP]).AP = _ap;
  68. _items = items;
  69. _cards = cards;
  70. ((IGMData.PartyItems)Data[Mode.Items]).SetItems(_items);
  71. ((IGMData.PartyItems)Data[Mode.Items]).SetItems(_cards);
  72. base.Refresh();
  73. }
  74. public override bool SetMode(Enum mode)
  75. {
  76. if (mode.GetType() == typeof(Mode))
  77. {
  78. switch ((Mode)mode)
  79. {
  80. case Mode.AP:
  81. Data[Mode.Exp].Hide();
  82. Data[Mode.Items].Hide();
  83. Data[Mode.AP].Show();
  84. Data[Mode.AP].Refresh();
  85. break;
  86. case Mode.Exp:
  87. Data[Mode.Exp].Show();
  88. Data[Mode.Items].Hide();
  89. Data[Mode.AP].Hide();
  90. Data[Mode.Exp].Refresh();
  91. break;
  92. case Mode.Items:
  93. Data[Mode.Exp].Hide();
  94. Data[Mode.Items].Show();
  95. Data[Mode.AP].Hide();
  96. Data[Mode.Items].Refresh();
  97. break;
  98. default:
  99. Menu.BattleMenus.ReturnTo();
  100. break;
  101. }
  102. return base.SetMode((Mode)mode);
  103. }
  104. return false;
  105. }
  106. protected override void Init()
  107. {
  108. NoInputOnUpdate = true;
  109. Size = new Vector2(881, 606);
  110. base.Init();
  111. Menu_Base[] tmp = new Menu_Base[3];
  112. List<Task> tasks = new List<Task>
  113. {
  114. Task.Run(() => Data.TryAdd(Mode.All, IGMData.Group.Base.Create(
  115. new IGMDataItem.Box{ Data = new FF8String(new byte[] {
  116. (byte)FF8TextTagCode.Key,
  117. (byte)FF8TextTagKey.Confirm})+
  118. " "+
  119. (Strings.Name.To_confirm),
  120. Pos = new Rectangle(0,(int)Size.Y-78,(int)Size.X,78),Options= Box_Options.Center | Box_Options.Middle }))),
  121. Task.Run(() => tmp[0] = IGMData.PlayerEXP.Create(0)),
  122. Task.Run(() => tmp[1] = IGMData.PlayerEXP.Create(1)),
  123. Task.Run(() => tmp[2] = IGMData.PlayerEXP.Create(2)),
  124. Task.Run(() => Data.TryAdd(Mode.Items, IGMData.PartyItems.Create(new Rectangle(Point.Zero,Size.ToPoint())))),
  125. Task.Run(() => Data.TryAdd(Mode.AP, IGMData.PartyAP.Create(new Rectangle(Point.Zero,Size.ToPoint())))),
  126. };
  127. Task.WaitAll(tasks.ToArray());
  128. Data.TryAdd(Mode.Exp, IGMData.Group.PlayerEXP.Create(tmp));
  129. Data[Mode.Exp].CONTAINER.Pos = new Rectangle(Point.Zero, Size.ToPoint());
  130. SetMode(Mode.Exp);
  131. InputFunctions = new Dictionary<Mode, Func<bool>>
  132. {
  133. { Mode.Exp, Data[Mode.Exp].Inputs},
  134. { Mode.Items, Data[Mode.Items].Inputs},
  135. { Mode.AP, Data[Mode.AP].Inputs}
  136. };
  137. }
  138. #endregion Methods
  139. }
  140. }