VictoryMenu.cs 5.6 KB

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