Module_main_menu_MainLobby.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. namespace FF8
  7. {
  8. internal static partial class Module_main_menu_debug
  9. {
  10. #region Fields
  11. private static Mitems s_mchoose;
  12. private static TextureHandler start;
  13. /// <summary>
  14. /// Strings for the main menu
  15. /// </summary>
  16. private static Dictionary<Enum, Item> strMainLobby;
  17. #endregion Fields
  18. #region Enums
  19. /// <summary>
  20. /// Identifiers and Ordering of main menu items
  21. /// </summary>
  22. private enum Mitems
  23. {
  24. New,
  25. Load,
  26. Debug
  27. }
  28. #endregion Enums
  29. #region Properties
  30. /// <summary>
  31. /// Current choice on main menu
  32. /// </summary>
  33. private static Mitems Mchoose
  34. {
  35. get => s_mchoose;
  36. set
  37. {
  38. if (value > s_mchoose && value > (Mitems)Enum.GetValues(typeof(Mitems)).Cast<int>().Max())
  39. {
  40. value = 0;
  41. }
  42. else if (value < s_mchoose && s_mchoose <= 0)
  43. {
  44. value = (Mitems)Enum.GetValues(typeof(Mitems)).Cast<int>().Max();
  45. }
  46. s_mchoose = value;
  47. }
  48. }
  49. #endregion Properties
  50. #region Methods
  51. /// <summary>
  52. /// Draw Main menu
  53. /// </summary>
  54. private static void DrawMainLobby()
  55. {
  56. Vector2 vp = (new Vector2(vpWidth, vpHeight)) * scale;
  57. float item = 0;
  58. Vector2 textSize = new Vector2(2.545454545f, 3.0375f);// scaled in render function.
  59. Vector2 textStart = new Vector2(vp.X * 0.45078125f, vp.Y * .65f);
  60. Memory.SpriteBatchStartAlpha();
  61. Rectangle dst = new Rectangle()
  62. {
  63. Location = new Point(0),
  64. Size = vp.ToPoint()
  65. };
  66. start.Draw(dst, null, Color.White * fade);
  67. Memory.SpriteBatchEnd();
  68. Memory.SpriteBatchStartAlpha(SamplerState.PointClamp);
  69. foreach (Mitems i in (Mitems[])Enum.GetValues(typeof(Mitems)))
  70. {
  71. Item c = strMainLobby[i];
  72. c.Loc = (Memory.font.RenderBasicText(c.Text,
  73. (int)(textStart.X), (int)(textStart.Y + ((textSize.Y + vpSpace) * item++)), textSize.X, textSize.Y, 1, 0, Fade));
  74. strMainLobby[i] = c;
  75. }
  76. DrawPointer(new Point((int)(textStart.X), (int)((((textSize.Y + vpSpace) * (float)Mchoose)+textStart.Y+(6*textSize.Y)))));
  77. Memory.SpriteBatchEnd();
  78. }
  79. private static void InitMain()
  80. {
  81. strMainLobby = new Dictionary<Enum, Item>()
  82. {
  83. { Mitems.New, new Item{Text=Memory.Strings.Read(Strings.FileID.MNGRP, 1 ,105) } },
  84. { Mitems.Load, new Item{Text=Memory.Strings.Read(Strings.FileID.MNGRP, 1 ,106) } },
  85. { Mitems.Debug, new Item{Text=new FF8String("OpenVIII debug tools") } }
  86. };
  87. if (start == null)
  88. {
  89. start = new TextureHandler("start{0:00}", 2);
  90. }
  91. }
  92. /// <summary>
  93. /// Update Main Lobby
  94. /// </summary>
  95. /// <returns>true on change</returns>
  96. private static bool UpdateMainLobby()
  97. {
  98. bool ret = false;
  99. Point ml = Input.MouseLocation;
  100. foreach (KeyValuePair<Enum, Item> entry in strMainLobby)
  101. {
  102. if (entry.Value.Loc.Contains(ml))
  103. {
  104. Mchoose = (Mitems)entry.Key;
  105. ret = true;
  106. if (Input.Button(Buttons.MouseWheelup) || Input.Button(Buttons.MouseWheeldown))
  107. {
  108. return ret;
  109. }
  110. break;
  111. }
  112. }
  113. if (Input.Button(Buttons.Down))
  114. {
  115. Input.ResetInputLimit();
  116. init_debugger_Audio.PlaySound(0);
  117. Mchoose++;
  118. ret = true;
  119. }
  120. if (Input.Button(Buttons.Up))
  121. {
  122. Input.ResetInputLimit();
  123. init_debugger_Audio.PlaySound(0);
  124. Mchoose--;
  125. ret = true;
  126. }
  127. if (Input.Button(Buttons.Okay))
  128. {
  129. Input.ResetInputLimit();
  130. switch (Mchoose)
  131. {
  132. case Mitems.New:
  133. init_debugger_Audio.PlaySound(28);
  134. State = MainMenuStates.NewGameChoosed;
  135. break;
  136. case Mitems.Load:
  137. init_debugger_Audio.PlaySound(0);
  138. State = MainMenuStates.LoadGameChooseSlot;
  139. break;
  140. case Mitems.Debug:
  141. init_debugger_Audio.PlaySound(0);
  142. Mchoose = 0;
  143. Dchoose = 0;
  144. State = MainMenuStates.DebugScreen;
  145. Fade = 0.0f;
  146. break;
  147. }
  148. ret = true;
  149. }
  150. return ret;
  151. }
  152. /// <summary>
  153. /// Waits for fade to end then triggers new game.
  154. /// </summary>
  155. private static void UpdateNewGame()
  156. {
  157. if (Fade > 0.0f)
  158. {
  159. Fade -= Memory.gameTime.ElapsedGameTime.Milliseconds / 1000.0f / 2;
  160. return;
  161. }
  162. /*reverse engineering notes:
  163. *
  164. * we should happen to reset wm2field values
  165. * also the basic party of Squall is now set: SG_PARTY_FIELD1 = 0, and other members are 0xFF
  166. */
  167. FieldPointer = 74; //RE: startup stage ID is hardcoded. Probably we would want to change it for modding
  168. //the module changes to 1 now
  169. Module_field_debug.ResetField();
  170. Module_movie_test.Index = 30;
  171. Module_movie_test.ReturnState = Memory.MODULE_FIELD_DEBUG;
  172. Memory.module = Memory.MODULE_MOVIETEST;
  173. State = MainMenuStates.MainLobby;
  174. }
  175. #endregion Methods
  176. }
  177. }