Module_main_menu_DebugLobby.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. namespace FF8
  8. {
  9. public static partial class Module_main_menu_debug
  10. {
  11. #region Fields
  12. private static int debug_choosedBS, debug_choosedAudio, debug_fieldPointer, debug_moviePointer;
  13. private static string debug_choosedField, debug_choosedMovie, debug_choosedMusic;
  14. private static Ditems s_dchoose;
  15. /// <summary>
  16. /// Strings for the debug menu
  17. /// </summary>
  18. private static Dictionary<Enum, Item> strDebugLobby;
  19. #endregion Fields
  20. #region Enums
  21. /// <summary>
  22. /// Identifiers and Ordering of debug menu items
  23. /// </summary>
  24. private enum Ditems
  25. {
  26. Reset,
  27. Overture,
  28. Battle,
  29. Field,
  30. Movie,
  31. Music,
  32. Sounds,
  33. World,
  34. Faces,
  35. Icons,
  36. Cards
  37. }
  38. #endregion Enums
  39. #region Properties
  40. public static Vector2 DFontPos { get; private set; }
  41. /// <summary>
  42. /// Currently selected Field
  43. /// </summary>
  44. public static int FieldPointer
  45. {
  46. get => debug_fieldPointer;
  47. set
  48. {
  49. if (value >= Memory.FieldHolder.fields.Length)
  50. {
  51. value = 0;
  52. }
  53. else if (value < 0)
  54. {
  55. value = Memory.FieldHolder.fields.Length - 1;
  56. }
  57. debug_fieldPointer = value;
  58. Memory.FieldHolder.FieldID = (ushort)value;
  59. debug_choosedField = Memory.FieldHolder.fields[value];
  60. }
  61. }
  62. /// <summary>
  63. /// Currently selected Movie
  64. /// </summary>
  65. public static int MoviePointer
  66. {
  67. get => debug_moviePointer;
  68. set
  69. {
  70. if (value >= Module_movie_test.Movies.Count)
  71. {
  72. value = 0;
  73. }
  74. else if (value < 0)
  75. {
  76. value = Module_movie_test.Movies.Count - 1;
  77. }
  78. debug_moviePointer = value;
  79. Module_movie_test.Index = value;
  80. if(Module_movie_test.Movies.Count>0)
  81. debug_choosedMovie = Path.GetFileNameWithoutExtension(Module_movie_test.Movies[value]);
  82. }
  83. }
  84. /// <summary>
  85. /// Current choice on debug menu
  86. /// </summary>
  87. private static Ditems Dchoose
  88. {
  89. get => s_dchoose; set
  90. {
  91. if (value > s_dchoose && value > (Ditems)Enum.GetValues(typeof(Ditems)).Cast<int>().Max())
  92. {
  93. value = 0;
  94. }
  95. else if (value < s_dchoose && s_dchoose <= 0)
  96. {
  97. value = (Ditems)Enum.GetValues(typeof(Ditems)).Cast<int>().Max();
  98. }
  99. s_dchoose = value;
  100. }
  101. }
  102. private static Vector2 Offset { get; set; }
  103. #endregion Properties
  104. #region Methods
  105. private static Rectangle FontBoxCalc<T>(Dictionary<Enum, Item> dict)
  106. {
  107. Rectangle dst = new Rectangle();
  108. int item = 0;
  109. foreach (Enum i in Enum.GetValues(typeof(T)))
  110. {
  111. Item c = dict[i];
  112. c.Loc = Memory.font.RenderBasicText(FF8String.Combine(strDebugLobby[i].Text, InfoForLobby<Ditems>(i)),
  113. (int)DFontPos.X, (int)(DFontPos.Y + vpSpace * item++), 2.545454545f, 3.0375f,skipdraw:true);
  114. if (dst.X == 0 || dst.Y == 0)
  115. dst.Location = c.Loc.Location;
  116. if (c.Loc.Width > dst.Width)
  117. dst.Width = c.Loc.Width;
  118. dst.Height = c.Loc.Y + c.Loc.Height - dst.Y;
  119. dict[i] = c;
  120. }
  121. dst.Inflate(vp_per.X * .06f , vp_per.Y * .035f );
  122. return dst;
  123. }
  124. /// <summary>
  125. /// Draw Debug Menu
  126. /// </summary>
  127. private static void DrawDebugLobby()
  128. {
  129. vpSpace = vp_per.Y * 0.05f ;
  130. float item = 0;
  131. Rectangle dst = FontBoxCalc<Ditems>(strDebugLobby);
  132. Memory.SpriteBatchStartAlpha(tm: IGM_focus);
  133. DrawBox(dst, title: Icons.ID.DEBUG);
  134. //Memory.Icons.Draw(Icons.ID.Menu_BG_256, 0, dst, new Vector2(2f), Fade);
  135. item = 0;
  136. dst.Offset(4 * 3.5f, 0);
  137. dst.Size = (Memory.Icons[Icons.ID.DEBUG].GetRectangle.Size.ToVector2() * 3.5f).ToPoint();
  138. //Memory.Icons.Draw(Icons.ID.DEBUG, 2, dst, Vector2.Zero, fade);
  139. dst.Location = DFontPos.ToPoint();
  140. dst.Size = new Point((int)(24 * 2 ), (int)(16 * 2 ));
  141. dst.Offset(-(dst.Width + 10 ), 6 + vpSpace * ((float)Dchoose));
  142. //want to use new function brain hurts on this screen lol
  143. //DrawPointer(new Point((int)(textStart.X), (int)((((textSize.Y + vpSpace) * (float)Mchoose) + textStart.Y + (6 * textSize.Y)) )));
  144. Memory.Icons.Draw(Icons.ID.Finger_Right, 2, dst, Vector2.Zero, fade);
  145. //Memory.SpriteBatchEnd();
  146. //pointclamp looks bad on default fonts.
  147. //Memory.SpriteBatchStartAlpha();
  148. foreach (Ditems i in (Ditems[])Enum.GetValues(typeof(Ditems)))
  149. {
  150. Memory.font.RenderBasicText(FF8String.Combine(strDebugLobby[i].Text, InfoForLobby<Ditems>(i)),
  151. (int)(DFontPos.X), (int)(DFontPos.Y + vpSpace * item++), 2.545454545f, 3.0375f, 0, Fade, lineSpacing: 1);
  152. }
  153. //Memory.spriteBatch.Draw(Memory.iconsTex[2], dst,
  154. // new Rectangle(232, 0, 23, 15), Color.White * Fade);
  155. Memory.SpriteBatchEnd();
  156. }
  157. /// <summary>
  158. /// Dynamic info for Ditem that is read at draw time.
  159. /// </summary>
  160. /// <param name="i">Ditem being drawn</param>
  161. /// <returns>Dynamic info for Ditem</returns>
  162. private static string InfoForLobby<T>(Enum i)
  163. {
  164. switch (typeof(T).Name)
  165. {
  166. case "Ditems":
  167. switch (i)
  168. {
  169. case Ditems.Battle:
  170. return debug_choosedBS.ToString("D4");
  171. case Ditems.Field:
  172. return debug_choosedField;
  173. case Ditems.Movie:
  174. return debug_choosedMovie;
  175. case Ditems.Sounds:
  176. return $"{debug_choosedAudio}";
  177. case Ditems.Music:
  178. return $"{debug_choosedMusic}";
  179. };
  180. break;
  181. };
  182. return "";
  183. }
  184. private static void InitDebug()
  185. {
  186. strDebugLobby = new Dictionary<Enum, Item>()
  187. {
  188. { Ditems.Reset, new Item{Text=new FF8String("Reset Main Menu state") } },
  189. { Ditems.Overture, new Item{Text=new FF8String("Play Overture")} },
  190. { Ditems.Battle, new Item{Text=new FF8String("Battle encounter: ")} },
  191. { Ditems.Field, new Item{Text=new FF8String("Field debug render: ")} },
  192. { Ditems.Movie, new Item{Text=new FF8String("Movie debug render: ")} },
  193. { Ditems.Music, new Item{Text=new FF8String("Play/Stop music: ")} },
  194. { Ditems.Sounds, new Item{Text=new FF8String("Play audio.dat: ")} },
  195. { Ditems.World, new Item{Text=new FF8String("Jump to World Map")} },
  196. { Ditems.Faces, new Item{Text=new FF8String("Test Faces")} },
  197. { Ditems.Icons, new Item{Text=new FF8String("Test Icons")} },
  198. { Ditems.Cards, new Item{Text=new FF8String("Test Cards")} },
  199. };
  200. debug_choosedField = Memory.FieldHolder.fields[debug_fieldPointer];
  201. if(Module_movie_test.Movies.Count>0)
  202. debug_choosedMovie = Path.GetFileNameWithoutExtension(Module_movie_test.Movies[debug_moviePointer]);
  203. if(Memory.dicMusic.Count>0 && Memory.dicMusic[0].Count>0)
  204. debug_choosedMusic = Path.GetFileNameWithoutExtension(Memory.dicMusic[0][0]);
  205. debug_fieldPointer = 90;
  206. debug_moviePointer = 0;
  207. }
  208. /// <summary>
  209. /// Update Debug Menu
  210. /// </summary>
  211. /// <returns>true on change</returns>
  212. private static bool UpdateDebugLobby()
  213. {
  214. bool ret = false;
  215. foreach (KeyValuePair<Enum, Item> entry in strDebugLobby)
  216. {
  217. if (entry.Value.Loc.Contains(ml))
  218. {
  219. Dchoose = (Ditems)entry.Key;
  220. ret = true;
  221. if (Input.Button(Buttons.MouseWheelup))
  222. {
  223. return UpdateDebugLobbyLEFT();
  224. }
  225. if (Input.Button(Buttons.MouseWheeldown))
  226. {
  227. return UpdateDebugLobbyRIGHT();
  228. }
  229. break;
  230. }
  231. }
  232. if (Input.Button(Buttons.Down))
  233. {
  234. Input.ResetInputLimit();
  235. init_debugger_Audio.PlaySound(0);
  236. Dchoose++;
  237. ret = true;
  238. }
  239. if (Input.Button(Buttons.Up))
  240. {
  241. Input.ResetInputLimit();
  242. init_debugger_Audio.PlaySound(0);
  243. Dchoose--;
  244. ret = true;
  245. }
  246. if (Input.Button(Buttons.Okay) && Dchoose == Ditems.Reset || Input.Button(Buttons.Cancel))
  247. {
  248. Input.ResetInputLimit();
  249. init_debugger_Audio.PlaySound(8);
  250. init_debugger_Audio.StopMusic();
  251. Dchoose = 0;
  252. Fade = 0.0f;
  253. State = MainMenuStates.MainLobby;
  254. ret = true;
  255. }
  256. else if (Input.Button(Buttons.Okay))
  257. {
  258. ret = UpdateDebugLobbyOKAY();
  259. }
  260. else if (Input.Button(Buttons.Left))
  261. {
  262. ret = UpdateDebugLobbyLEFT();
  263. }
  264. else if (Input.Button(Buttons.Right))
  265. {
  266. ret = UpdateDebugLobbyRIGHT();
  267. }
  268. return ret;
  269. }
  270. private static bool UpdateDebugLobbyLEFT()
  271. {
  272. bool ret = true;
  273. Input.ResetInputLimit();
  274. switch (Dchoose)
  275. {
  276. case Ditems.Sounds:
  277. if (debug_choosedAudio > 0)
  278. {
  279. debug_choosedAudio--;
  280. }
  281. break;
  282. case Ditems.Battle:
  283. if (debug_choosedBS <= 0)
  284. {
  285. return false;
  286. }
  287. debug_choosedBS--;
  288. break;
  289. case Ditems.Field:
  290. FieldPointer--;
  291. break;
  292. case Ditems.Movie:
  293. MoviePointer--;
  294. break;
  295. case Ditems.Music:
  296. if (Memory.dicMusic.Count > 0)
  297. {
  298. if (Memory.MusicIndex <= ushort.MinValue)
  299. {
  300. Memory.MusicIndex = ushort.MaxValue;
  301. }
  302. else
  303. {
  304. Memory.MusicIndex--;
  305. }
  306. debug_choosedMusic = Path.GetFileNameWithoutExtension(Memory.dicMusic[Memory.MusicIndex][0]);
  307. }
  308. break;
  309. default:
  310. ret = false;
  311. break;
  312. }
  313. if (ret)
  314. {
  315. init_debugger_Audio.PlaySound(0);
  316. }
  317. return ret;
  318. }
  319. private static bool UpdateDebugLobbyOKAY()
  320. {
  321. bool ret = true;
  322. Input.ResetInputLimit();
  323. switch (Dchoose)
  324. {
  325. case Ditems.Overture:
  326. Dchoose = 0;
  327. Fade = 0.0f;
  328. State = MainMenuStates.MainLobby;
  329. Module_overture_debug.ResetModule();
  330. Memory.module = Memory.MODULE_OVERTURE_DEBUG;
  331. Memory.IsMouseVisible = false;
  332. init_debugger_Audio.StopMusic();
  333. break;
  334. case Ditems.Field:
  335. Fade = 0.0f;
  336. Module_field_debug.ResetField();
  337. Memory.module = Memory.MODULE_FIELD_DEBUG;
  338. Memory.IsMouseVisible = false;
  339. break;
  340. case Ditems.Music:
  341. Module_field_debug.ResetField();
  342. init_debugger_Audio.PlayStopMusic();
  343. break;
  344. case Ditems.Battle:
  345. Fade = 0.0f;
  346. Memory.battle_encounter = debug_choosedBS;
  347. Module_battle_debug.ResetState();
  348. Memory.module = Memory.MODULE_BATTLE_DEBUG;
  349. Memory.IsMouseVisible = false;
  350. break;
  351. case Ditems.Sounds:
  352. init_debugger_Audio.PlaySound(debug_choosedAudio);
  353. break;
  354. case Ditems.Movie:
  355. Fade = 0.0f;
  356. MoviePointer = MoviePointer; //makes movieindex in player match the moviepointer, it is set when ever this is.
  357. Memory.module = Memory.MODULE_MOVIETEST;
  358. Module_movie_test.MovieState = 0;
  359. Memory.IsMouseVisible = false;
  360. break;
  361. case Ditems.World:
  362. Fade = 0.0f;
  363. Memory.module = Memory.MODULE_WORLD_DEBUG;
  364. Memory.IsMouseVisible = false;
  365. break;
  366. case Ditems.Faces:
  367. Fade = 0.0f;
  368. Memory.module = Memory.MODULE_FACE_TEST;
  369. break;
  370. case Ditems.Icons:
  371. Fade = 0.0f;
  372. Memory.module = Memory.MODULE_ICON_TEST;
  373. break;
  374. case Ditems.Cards:
  375. Fade = 0.0f;
  376. Memory.module = Memory.MODULE_CARD_TEST;
  377. break;
  378. default:
  379. ret = false;
  380. break;
  381. }
  382. if (ret && Ditems.Sounds != Dchoose)
  383. {
  384. init_debugger_Audio.PlaySound(0);
  385. }
  386. return ret;
  387. }
  388. private static bool UpdateDebugLobbyRIGHT()
  389. {
  390. bool ret = true;
  391. Input.ResetInputLimit();
  392. switch (Dchoose)
  393. {
  394. case Ditems.Sounds:
  395. if (debug_choosedAudio < init_debugger_Audio.soundEntriesCount)
  396. {
  397. debug_choosedAudio++;
  398. }
  399. break;
  400. case Ditems.Battle:
  401. if (debug_choosedBS < Memory.encounters.Length)
  402. {
  403. debug_choosedBS++;
  404. }
  405. break;
  406. case Ditems.Field:
  407. FieldPointer++;
  408. break;
  409. case Ditems.Movie:
  410. MoviePointer++;
  411. break;
  412. case Ditems.Music:
  413. //case Ditems.MusicNext:
  414. if (Memory.dicMusic.Count > 0)
  415. {
  416. if (Memory.MusicIndex >= ushort.MaxValue || Memory.MusicIndex >= Memory.dicMusic.Keys.Max())
  417. {
  418. Memory.MusicIndex = 0;
  419. }
  420. else
  421. {
  422. Memory.MusicIndex++;
  423. }
  424. debug_choosedMusic = Path.GetFileNameWithoutExtension(Memory.dicMusic[Memory.MusicIndex][0]);
  425. }
  426. //init_debugger_Audio.PlayMusic();
  427. break;
  428. default:
  429. ret = false;
  430. break;
  431. }
  432. if (ret)
  433. {
  434. init_debugger_Audio.PlaySound(0);
  435. }
  436. return ret;
  437. }
  438. #endregion Methods
  439. }
  440. }