Cards.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using Microsoft.Xna.Framework;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. namespace OpenVIII
  6. {
  7. public sealed partial class Cards : SP2
  8. {
  9. #region Constructors
  10. /// <summary>
  11. /// Card images used in menus. The images used in the triple triad game are in the ff8.exe in
  12. /// tim files.
  13. /// </summary>
  14. /// <seealso cref="http://forums.qhimm.com/index.php?topic=11084.0"/>
  15. public Cards()
  16. {
  17. }
  18. #endregion Constructors
  19. #region Methods
  20. public static Cards Load() => Load<Cards>();
  21. protected override void DefaultValues()
  22. {
  23. base.DefaultValues();
  24. Props = new List<TexProps>()
  25. {
  26. new TexProps{Filename="mc00.tex", Count = 1 },
  27. new TexProps{Filename="mc01.tex", Count = 1 },
  28. new TexProps{Filename="mc02.tex", Count = 1 },
  29. new TexProps{Filename="mc03.tex", Count = 1 },
  30. new TexProps{Filename="mc04.tex", Count = 1 },
  31. new TexProps{Filename="mc05.tex", Count = 1 },
  32. new TexProps{Filename="mc06.tex", Count = 1 },
  33. new TexProps{Filename="mc07.tex", Count = 1 },
  34. new TexProps{Filename="mc08.tex", Count = 1 },
  35. new TexProps{Filename="mc09.tex", Count = 1 }
  36. };
  37. TextureStartOffset = 0;
  38. EntriesPerTexture = 11;
  39. IndexFilename = "cardanm.sp2";
  40. }
  41. public const float AspectRatio = 62f / 88f; //B6 paper
  42. protected override void Init() => base.Init();
  43. public override TextureHandler GetTexture(Enum id, int file = -1)
  44. {
  45. var pos = Convert.ToInt32(id);
  46. var pageFile = pos / EntriesPerTexture;
  47. return pos >= (int)(Cards.ID.Card_Back) ? Textures[0] : Textures[pageFile];
  48. }
  49. public override void Draw(Enum id, Rectangle dst, float fade = 1)
  50. {
  51. var v = Convert.ToUInt32(id);
  52. uint pos;
  53. if (v >= Convert.ToUInt32(Cards.ID.Card_Back))
  54. {
  55. //assuming to use back card for Card_Back, Immune and Fail
  56. pos = Memory.Cards.Count - 1;
  57. }
  58. else
  59. {
  60. pos = (uint)(v % EntriesPerTexture);
  61. }
  62. var src = GetEntry(pos).GetRectangle;
  63. var tex = GetTexture(id);
  64. tex.Draw(dst, src, Color.White * fade);
  65. }
  66. public override Entry GetEntry(uint id)
  67. {
  68. if (Entries.ContainsKey(id))
  69. {
  70. return Entries[id];
  71. }
  72. return null;
  73. }
  74. #endregion Methods
  75. }
  76. }