Module_main_menu_LGSG_ChooseGame.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using Microsoft.Xna.Framework.Input;
  4. using System;
  5. using System.Collections.Generic;
  6. namespace FF8
  7. {
  8. public static partial class Module_main_menu_debug
  9. {
  10. private static void DrawLGSGChooseBlocks()
  11. {
  12. Rectangle dst = new Rectangle
  13. {
  14. X = (int)(vp_per.X * 0.171875f),
  15. Y = (int)(vp_per.Y * 0.266666666666667f),
  16. Width = (int)(vp_per.X * 0.65625f),
  17. Height = (int)(vp_per.Y * 0.6625f),
  18. };
  19. if (OffScreenBuffer != null && !OffScreenBuffer.IsDisposed)
  20. {
  21. Memory.graphics.GraphicsDevice.SetRenderTarget(OffScreenBuffer);
  22. // Matrix osbMatrix = Matrix.CreateScale(new Vector3())
  23. Memory.SpriteBatchStartAlpha();
  24. for (int bloc = 0; bloc < 3; bloc++)
  25. {
  26. int block = bloc + 3 * (Blockpage);
  27. Saves.Data d = Saves.FileList?[SlotLoc, block];
  28. Tuple<Rectangle, Point> b = DrawBlock(block, d);
  29. //cords returned by drawblock assume being in the offscreen buffer.
  30. //Which is the size of the 3 blocks. So we need to offset
  31. //everything by the draw location.
  32. Rectangle r = b.Item1;
  33. r.Offset(dst.Location);
  34. Point p = b.Item2;
  35. p.Offset(dst.Location);
  36. BlockLocs[bloc] = new Tuple<Rectangle, Point, Rectangle>(r, p, new Rectangle());
  37. }
  38. Memory.SpriteBatchEnd();
  39. Memory.graphics.GraphicsDevice.SetRenderTarget(null);
  40. }
  41. }
  42. private static void DrawLGSGChooseGame(FF8String topright, FF8String help)
  43. {
  44. Rectangle dst = new Rectangle
  45. {
  46. X = (int)(vp_per.X * 0.171875f),
  47. Y = (int)(vp_per.Y * 0.266666666666667f),
  48. Width = (int)(vp_per.X * 0.65625f),
  49. Height = (int)(vp_per.Y * 0.6625f),
  50. };
  51. DrawLGSGHeader(strLoadScreen[Litems.GameFolderSlot1 + SlotLoc].Text, topright, help);
  52. if (LastPage == null || LastPage.IsDisposed)
  53. {
  54. Entry e = Memory.Icons.GetEntry(Icons.ID.Arrow_Left);
  55. Rectangle arrow = new Rectangle
  56. {
  57. X = (int)(dst.X - ((e.Width - 2) * 3f)),
  58. Y = (dst.Y + dst.Height / 2)
  59. };
  60. Memory.Icons.Draw(Icons.ID.Arrow_Left, 1, arrow, new Vector2(3f), fade);
  61. Memory.Icons.Draw(Icons.ID.Arrow_Left, 2, arrow, new Vector2(3f), fade * blink_Amount);
  62. arrow = new Rectangle
  63. {
  64. X = (int)((dst.X + dst.Width) + -2 * 3f),
  65. Y = arrow.Y
  66. };
  67. Memory.Icons.Draw(Icons.ID.Arrow_Right2, 1, arrow, new Vector2(3f), fade);
  68. Memory.Icons.Draw(Icons.ID.Arrow_Right2, 2, arrow, new Vector2(3f), fade * blink_Amount);
  69. }
  70. float speed = .17f;
  71. if (OffScreenBuffer != null && !OffScreenBuffer.IsDisposed)
  72. {
  73. dst.Location = (dst.Location.ToVector2()).ToPoint();
  74. PageTarget = dst.Location.ToVector2();
  75. dst.Size = (dst.Size.ToVector2()).ToPoint();
  76. PageSize = dst.Size.ToVector2();
  77. CurrentPageLoc = CurrentPageLoc == Vector2.Zero ? PageTarget : Vector2.SmoothStep(CurrentPageLoc, PageTarget, speed).FloorOrCeiling(PageTarget);
  78. dst.Location = CurrentPageLoc.RoundedPoint();
  79. Memory.spriteBatch.Draw(OffScreenBuffer, dst, Color.White * fade);
  80. }
  81. if (LastPage != null && !LastPage.IsDisposed)
  82. {
  83. CurrentLastPageLoc = CurrentLastPageLoc == Vector2.Zero ? PageTarget : Vector2.SmoothStep(CurrentLastPageLoc, LastPageTarget, speed).FloorOrCeiling(LastPageTarget);
  84. if (LastPageTarget == CurrentLastPageLoc)
  85. {
  86. LastPage.Dispose(); CurrentLastPageLoc = Vector2.Zero;
  87. }
  88. else
  89. {
  90. dst.Location = CurrentLastPageLoc.RoundedPoint();
  91. Memory.spriteBatch.Draw(LastPage, dst, Color.White * fade);
  92. }
  93. }
  94. else //if(BlockLocs[BlockLoc] != null)
  95. {
  96. Point ptr = BlockLocs[BlockLoc].Item2;
  97. DrawPointer(ptr);
  98. }
  99. }
  100. private static void DrawSGChooseGame() => DrawLGSGChooseGame(strLoadScreen[Litems.Save].Text, strLoadScreen[Litems.BlockToSave].Text);
  101. private static bool UpdateLGChooseGame()
  102. {
  103. bool ret = false;
  104. if (BlockLocs != null && BlockLocs.Length > 0 && BlockLocs[0] != null)
  105. {
  106. for (int i = 0; i < BlockLocs.Length && BlockLocs[i] != null; i++)
  107. {
  108. if (BlockLocs[i].Item1.Contains(ml))
  109. {
  110. BlockLoc = (sbyte)i;
  111. ret = true;
  112. if (Input.Button(Buttons.MouseWheelup))
  113. {
  114. UpdateLGChooseGameLEFT();
  115. return true;
  116. }
  117. else if (Input.Button(Buttons.MouseWheeldown))
  118. {
  119. UpdateLGChooseGameRIGHT();
  120. return true;
  121. }
  122. break;
  123. }
  124. }
  125. if (Input.Button(Buttons.Down))
  126. {
  127. Input.ResetInputLimit();
  128. init_debugger_Audio.PlaySound(0);
  129. BlockLoc++;
  130. ret = true;
  131. }
  132. else if (Input.Button(Buttons.Left))
  133. {
  134. UpdateLGChooseGameLEFT();
  135. ret = true;
  136. }
  137. else if (Input.Button(Buttons.Right))
  138. {
  139. UpdateLGChooseGameRIGHT();
  140. ret = true;
  141. }
  142. else if (Input.Button(Buttons.Up))
  143. {
  144. Input.ResetInputLimit();
  145. init_debugger_Audio.PlaySound(0);
  146. BlockLoc--;
  147. ret = true;
  148. }
  149. else if (Input.Button(Keys.PageDown))
  150. {
  151. Input.ResetInputLimit();
  152. init_debugger_Audio.PlaySound(0);
  153. SlotLoc++;
  154. ret = true;
  155. }
  156. else if (Input.Button(Keys.PageUp))
  157. {
  158. Input.ResetInputLimit();
  159. init_debugger_Audio.PlaySound(0);
  160. SlotLoc--;
  161. ret = true;
  162. }
  163. else if (Input.Button(Buttons.Cancel))
  164. {
  165. Input.ResetInputLimit();
  166. init_debugger_Audio.PlaySound(8);
  167. init_debugger_Audio.StopMusic();
  168. Dchoose = 0;
  169. Fade = 0.0f;
  170. State = MainMenuStates.LoadGameChooseSlot;
  171. ret = true;
  172. }
  173. else if (Input.Button(Buttons.Okay))
  174. {
  175. PercentLoaded = 0f;
  176. //State = MainMenuStates.LoadGameCheckingSlot;
  177. State = MainMenuStates.LoadGameLoading;
  178. }
  179. }
  180. if (scale != lastscale && OffScreenBuffer != null && !OffScreenBuffer.IsDisposed)
  181. OffScreenBuffer.Dispose();
  182. if (OffScreenBuffer == null || OffScreenBuffer.IsDisposed)
  183. //if you make these with out disposing enough times gfx driver crashes.
  184. //happened many times if i left this running and had this just ran every draw call. heh.
  185. OffScreenBuffer = new RenderTarget2D(Memory.graphics.GraphicsDevice, (int)(vp_per.X * 0.65625f), (int)(vp_per.Y * 0.6625f), false, SurfaceFormat.Color, DepthFormat.None);
  186. return ret;
  187. }
  188. private static void UpdateLGChooseGameRIGHT()
  189. {
  190. Input.ResetInputLimit();
  191. init_debugger_Audio.PlaySound(0);
  192. if (LastPage != null && !LastPage.IsDisposed)
  193. {
  194. LastPage.Dispose();
  195. CurrentLastPageLoc = Vector2.Zero;
  196. }
  197. if (OffScreenBuffer != null && !OffScreenBuffer.IsDisposed)
  198. {
  199. lock (OffScreenBuffer)
  200. {
  201. LastPage = new Texture2D(Memory.graphics.GraphicsDevice, OffScreenBuffer.Width, OffScreenBuffer.Height);
  202. lock (LastPage)
  203. {
  204. Color[] texdata = new Color[OffScreenBuffer.Width * OffScreenBuffer.Height];
  205. OffScreenBuffer.GetData(texdata);
  206. LastPage.SetData(texdata);
  207. LastPageTarget = new Vector2(-PageSize.X, CurrentPageLoc.Y);
  208. CurrentPageLoc = new Vector2(vp_per.X, CurrentPageLoc.Y);
  209. }
  210. }
  211. }
  212. Blockpage++;
  213. }
  214. private static void UpdateLGChooseGameLEFT()
  215. {
  216. Input.ResetInputLimit();
  217. init_debugger_Audio.PlaySound(0);
  218. if (LastPage != null && !LastPage.IsDisposed)
  219. {
  220. LastPage.Dispose();
  221. CurrentLastPageLoc = Vector2.Zero;
  222. }
  223. if (OffScreenBuffer != null && !OffScreenBuffer.IsDisposed)
  224. {
  225. lock (OffScreenBuffer)
  226. {
  227. LastPage = new Texture2D(Memory.graphics.GraphicsDevice, OffScreenBuffer.Width, OffScreenBuffer.Height);
  228. lock (LastPage)
  229. {
  230. Color[] texdata = new Color[OffScreenBuffer.Width * OffScreenBuffer.Height];
  231. OffScreenBuffer.GetData(texdata);
  232. LastPage.SetData(texdata);
  233. LastPageTarget = new Vector2(vp_per.X, CurrentPageLoc.Y);
  234. CurrentPageLoc = new Vector2(-PageSize.X, CurrentPageLoc.Y);
  235. }
  236. }
  237. }
  238. Blockpage--;
  239. }
  240. private static void UpdateSGChooseGame() => throw new NotImplementedException();
  241. private static void DrawLGChooseGame() => DrawLGSGChooseGame(strLoadScreen[Litems.Load].Text, strLoadScreen[Litems.BlockToLoad].Text);
  242. private static RenderTarget2D OffScreenBuffer;
  243. private static Tuple<Rectangle, Point> DrawBlock(int block, Saves.Data d)
  244. {
  245. block++;
  246. Rectangle dst = new Rectangle
  247. {
  248. X = 0,
  249. Y = (OffScreenBuffer.Height / 3 * ((block - 1) % 3)),
  250. Width = (OffScreenBuffer.Width),
  251. Height = OffScreenBuffer.Height / 3,
  252. };
  253. Vector2 offset = dst.Location.ToVector2();
  254. DrawBox(dst);
  255. Vector2 blocknumpos = new Vector2
  256. {
  257. X = (OffScreenBuffer.Width * 0.00952381f),
  258. Y = 0,
  259. } + offset;
  260. Vector2 blocknumsize = new Vector2(OffScreenBuffer.Height * 0.00628930817610063f);
  261. Memory.Icons.Draw(block, Icons.NumType.Num_8x16_0, 2, "D2", blocknumpos, blocknumsize, fade); // 2,2 looks close
  262. Rectangle faceRect = new Rectangle
  263. {
  264. X = (int)(OffScreenBuffer.Width * 0.0654761904761905f),
  265. Y = (int)(OffScreenBuffer.Height * 0.0157232704402516f),
  266. Width = (int)(OffScreenBuffer.Width * 0.113095238095238f),
  267. Height = (int)(OffScreenBuffer.Height * 0.30188679245283f),
  268. };
  269. faceRect.Offset(offset);
  270. sbyte mainchar = -1;
  271. for (byte face = 0; d != null && d.Party != null && face < d.Party.Length; face++)
  272. {
  273. if (face != 0)
  274. faceRect.Offset(faceRect.Width, 0);
  275. if (d.Party[face] != Characters.Blank)
  276. {
  277. Memory.Faces.Draw(d.Party[face], faceRect, Vector2.UnitY, fade);
  278. Memory.Icons.Draw(Icons.ID.MenuBorder, 2, faceRect, new Vector2(1f), fade);
  279. if (mainchar == -1) mainchar = (sbyte)face;
  280. }
  281. }
  282. if (mainchar > -1 && d != null && d.Party != null && d.Party[mainchar] != Characters.Blank)
  283. {
  284. Vector2 detailsLoc = new Vector2
  285. {
  286. X = (int)(OffScreenBuffer.Width * 0.408333333333333f),
  287. Y = (int)(OffScreenBuffer.Height * 0.0251572327044026f),
  288. } + offset;
  289. FF8String name = Memory.Strings.GetName(d.Party[mainchar], d);
  290. FF8String lv_ = new FF8String($"LV. {d.firstcharacterslevel}");
  291. TextScale = new Vector2(OffScreenBuffer.Width * 0.0030303030297619f, OffScreenBuffer.Height * 0.00636792452830189f);
  292. Memory.font.RenderBasicText(name, detailsLoc, TextScale, Fade: fade);
  293. int playy = (int)detailsLoc.Y;
  294. detailsLoc.Y += (int)(OffScreenBuffer.Height * 0.0817610062893082f);
  295. Rectangle disc = Memory.font.RenderBasicText(lv_, detailsLoc, TextScale, Fade: fade);
  296. disc.Offset(0, (int)(OffScreenBuffer.Height * 0.0125786163522013f));
  297. disc.X = (int)(OffScreenBuffer.Width * 0.583333333333333f);
  298. Vector2 DiscScale = new Vector2(OffScreenBuffer.Height * 0.0060987230787661f);
  299. Memory.Icons.Draw(Icons.ID.DISC, 2, disc, DiscScale, fade);
  300. Vector2 CurrDiscLoc = new Vector2(disc.X + (0.119047619047619f * OffScreenBuffer.Width), disc.Y);
  301. Memory.Icons.Draw((int)d.CurrentDisk + 1, 0, 2, "D1", CurrDiscLoc, DiscScale, fade);
  302. float X1 = OffScreenBuffer.Width * 0.952380952380952f;
  303. float X2 = OffScreenBuffer.Width * -0.0238095238095238f;
  304. float X3 = OffScreenBuffer.Width * -0.0952380952380952f;
  305. disc.Location = new Vector2 { X = X1, Y = disc.Y }.ToPoint();
  306. Memory.Icons.Draw(Icons.ID.G, 2, disc, DiscScale, fade);
  307. double digits = (d.AmountofGil==0?1:Math.Floor(Math.Log10(d.AmountofGil)+2));
  308. disc.Offset(new Vector2 { X = (float)(digits * X2) });
  309. Memory.Icons.Draw((int)d.AmountofGil, 0, 2, "D1", disc.Location.ToVector2(), DiscScale, fade);
  310. disc.Location = new Vector2 { X = X1, Y = playy }.ToPoint();
  311. disc.Offset(new Vector2 { X = X2 });
  312. Memory.Icons.Draw(d.Timeplayed.Minutes, 0, 2, "D2", disc.Location.ToVector2(), DiscScale, fade);
  313. if ((int)d.Timeplayed.TotalHours > 0)
  314. {
  315. disc.Offset(new Vector2 { X = 1 * X2 });
  316. Memory.Icons.Draw(Icons.ID.Colon, 13, disc, DiscScale, fade);
  317. disc.Offset(new Vector2 { X = (float)Math.Floor(Math.Log10((int)d.Timeplayed.TotalHours) + 1) * X2 });
  318. Memory.Icons.Draw((int)d.Timeplayed.TotalHours, 0, 2, "D1", disc.Location.ToVector2(), DiscScale, fade);
  319. }
  320. disc.Offset(new Vector2 { X = X3 + X2 });
  321. Memory.Icons.Draw(Icons.ID.PLAY, 13, disc, DiscScale, fade);
  322. Rectangle locbox = new Rectangle
  323. {
  324. X = faceRect.Width + faceRect.X,
  325. Y = (int)(OffScreenBuffer.Height * 0.19496855345912f),
  326. Width = OffScreenBuffer.Width - faceRect.Width - faceRect.X,
  327. Height = (int)(OffScreenBuffer.Height * 0.138364779874214f),
  328. };
  329. locbox.Offset(offset);
  330. DrawBox(locbox);
  331. FF8String loc = Memory.Strings.Read(Strings.FileID.AREAMES, 0, d.LocationID).ReplaceRegion();
  332. locbox.Offset(0.0297619047619048f * OffScreenBuffer.Width, 0.0440251572327044f * OffScreenBuffer.Height);
  333. Memory.font.RenderBasicText(loc, locbox.Location, TextScale, Fade: fade);
  334. }
  335. dst.X = (int)(vp_per.X * 0f);
  336. dst.Y = (int)(vp_per.Y * 0.220833333333333f * ((block - 1) % 3));
  337. dst.Width = (int)(vp_per.X * 0.65625f);
  338. dst.Height = (int)(vp_per.Y * 0.220833333333333f);
  339. return new Tuple<Rectangle, Point>(dst, (dst.Location.ToVector2() + new Vector2(25f, dst.Height / 2)).ToPoint());
  340. }
  341. private static sbyte BlockLoc
  342. {
  343. get => _blockLoc; set
  344. {
  345. if (value >= BlockLocs.Length)
  346. value = 0;
  347. else if (value < 0)
  348. value = (sbyte)(BlockLocs.Length - 1);
  349. _blockLoc = value;
  350. }
  351. }
  352. private static sbyte _blockLoc;
  353. private static sbyte blockpage;
  354. public static sbyte Blockpage
  355. {
  356. get => blockpage; set
  357. {
  358. if (value >= 10)
  359. value = 0;
  360. else if (value < 0)
  361. value = 9;
  362. blockpage = value;
  363. }
  364. }
  365. private static Tuple<Rectangle, Point, Rectangle>[] BlockLocs = new Tuple<Rectangle, Point, Rectangle>[3];
  366. private static Texture2D LastPage;
  367. }
  368. }