Renzokeken.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using System;
  4. namespace OpenVIII.IGMDataItem.Gradient
  5. {
  6. public class Renzokeken : Texture
  7. {
  8. #region Fields
  9. protected bool _trigger;
  10. protected Color Color_default;
  11. protected Slide<int> HitSlide;
  12. protected Rectangle HotSpot;
  13. #endregion Fields
  14. #region Constructors
  15. private Renzokeken()
  16. {
  17. }
  18. #endregion Constructors
  19. #region Properties
  20. public bool Done => HitSlide.Done || !Enabled;
  21. public bool Trigger { get => (_trigger && !Done); private set => _trigger = value; }
  22. #endregion Properties
  23. #region Methods
  24. public static Renzokeken Create(Rectangle? pos = null, Color? color = null, Color? faded_color = null, float blink_adjustment = 1f, Rectangle? hotspot = null, Rectangle? restriction = null, TimeSpan time = default, TimeSpan delay = default, Color? darkcolor = null, bool rev = false, bool vanish = true)
  25. {
  26. int total = 12 + 180;
  27. if (pos.HasValue && pos.Value.Width > 0)
  28. {
  29. total = pos.Value.Width;
  30. }
  31. Color[] cfade = new Color[total];
  32. Renzokeken r = new Renzokeken
  33. {
  34. Data = new Texture2D(Memory.graphics.GraphicsDevice, cfade.Length, 1),
  35. _pos = pos ?? Rectangle.Empty,
  36. HotSpot = hotspot ?? Rectangle.Empty,
  37. Restriction = restriction ?? Rectangle.Empty,
  38. Color = color ?? Color.White,
  39. Color_default = color ?? Color.White,
  40. Faded_Color = faded_color ?? color ?? Color.White,
  41. Blink_Adjustment = blink_adjustment
  42. };
  43. float dark = 0.067f;
  44. float fade = 0.933f;
  45. Color lightline = new Color(118, 118, 118, 255);
  46. Color darkline = new Color(58, 58, 58, 255);
  47. int i;
  48. if (!rev)
  49. {
  50. for (i = 0; i < dark * total; i++)
  51. cfade[i] = darkline;
  52. for (; i < cfade.Length; i++)
  53. cfade[i] = Color.Lerp(lightline, darkcolor ?? Color.TransparentBlack, (i - (dark * total)) / (fade * total));
  54. }
  55. else
  56. {
  57. for (i = 0; i < cfade.Length - (dark * total); i++)
  58. cfade[i] = Color.Lerp(Color.TransparentBlack, lightline, i / (fade * total));
  59. for (; i < cfade.Length; i++)
  60. cfade[i] = darkline;
  61. }
  62. r.Width = r.Data.Width;
  63. r.Data.SetData(cfade);
  64. if (vanish) r.HitSlide = new Slide<int>(r.Restriction.X + r.Restriction.Width, r.Restriction.X - r.Width, time, Lerp) { Delay = delay };
  65. else r.HitSlide = new Slide<int>(r.Restriction.X, r.Restriction.X - r.Width, time, Lerp) { Delay = delay };
  66. if (rev) r.HitSlide.Reverse();
  67. int Lerp(int x, int y, float p) => (int)Math.Round(MathHelper.Lerp(x, y, p));
  68. return r;
  69. }
  70. public override void Reset()
  71. {
  72. Restart();
  73. base.Reset();
  74. }
  75. public void Restart()
  76. {
  77. //Show();
  78. Color = Color_default;
  79. HitSlide.Restart();
  80. }
  81. public override bool Update()
  82. {
  83. X = HitSlide.Update();
  84. if (HotSpot.Contains(Pos.Location))
  85. {
  86. Color = Faded_Color;
  87. Trigger = true;
  88. }
  89. else
  90. {
  91. Trigger = false;
  92. }
  93. //if (HitSlide.Done) HitSlide.Restart();
  94. return base.Update();
  95. }
  96. #endregion Methods
  97. }
  98. }