Text.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using Microsoft.Xna.Framework;
  2. namespace OpenVIII.IGMDataItem
  3. {
  4. public class Text : Base, I_Data<FF8String>, I_Palette, I_FontColor
  5. {
  6. #region Fields
  7. private FF8String _data;
  8. private Icons.ID? _icon = Icons.ID.None;
  9. private byte _palette;
  10. #endregion Fields
  11. #region Constructors
  12. public Text()
  13. {
  14. FontColor = Font.ColorID.White;
  15. Blink_Adjustment = 1f;
  16. Palette = 2;
  17. }
  18. #endregion Constructors
  19. #region Properties
  20. public override bool Blink { get => base.Blink; set => base.Blink = value; }
  21. public FF8String Data
  22. {
  23. get => _data; set
  24. {
  25. _data = value;
  26. DataSize = Memory.Font.RenderBasicText(_data, Pos.Location, Scale, skipdraw: true);
  27. OffsetIcon();
  28. }
  29. }
  30. public Rectangle DataSize { get; private set; }
  31. public byte Faded_Palette { get; set; }
  32. public Font.ColorID FontColor { get; set; }
  33. public override int Height => DataSize.Height;
  34. public Icons.ID? Icon
  35. {
  36. get => _icon; set
  37. {
  38. _icon = value;
  39. OffsetIcon();
  40. }
  41. }
  42. public byte Palette
  43. {
  44. get => _palette; set => _palette = (byte)(value < Memory.Icons.PaletteCount ? value : 2);
  45. }
  46. public override int Width => DataSize.Width;
  47. #endregion Properties
  48. #region Methods
  49. public override void Draw() => Draw(false);
  50. public void Draw(bool skipdraw)
  51. {
  52. if (Enabled)
  53. {
  54. var r = Pos;
  55. if (OffsetAnchor != null)
  56. r.Offset(OffsetAnchor);
  57. var r2 = r;
  58. if (Icon != null && Icon != Icons.ID.None)
  59. {
  60. r2.Size = Point.Zero;
  61. if (!skipdraw)
  62. Memory.Icons.Draw(Icon, Palette, r2, new Vector2(Scale.X), Fade);
  63. if (Blink)
  64. Memory.Icons.Draw(Icon, Faded_Palette, r2, new Vector2(Scale.X), Fade * Blink_Amount * Blink_Adjustment);
  65. r.Offset(Memory.Icons.GetEntryGroup(Icon).Width * Scale.X, 0);
  66. }
  67. DataSize = Rectangle.Union(r2, Memory.Font.RenderBasicText(Data, r.Location, Scale, Fade: Fade, color: FontColor, blink: Blink, skipdraw: skipdraw));
  68. }
  69. }
  70. private void OffsetIcon()
  71. {
  72. if (_icon != Icons.ID.None)
  73. {
  74. var entryGroup = Memory.Icons.GetEntryGroup(_icon);
  75. if (entryGroup != null)
  76. DataSize.Offset(entryGroup.Width * Scale.X, 0);
  77. }
  78. }
  79. #endregion Methods
  80. }
  81. }