Advertisement
zjqyf

GLQ_SkillBarPainter

Jul 27th, 2017
2,198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.87 KB | None | 0 0
  1. using SharpDX;
  2. using SharpDX.Direct2D1;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Globalization;
  6. using System.Linq;
  7. using Turbo.Plugins.Default;
  8. namespace Turbo.Plugins.glq
  9. {
  10.  
  11. public class GLQ_SkillBarPainter : ITransparentCollection
  12. {
  13. public bool Enabled { get; set; }
  14. public IController Hud { get; set; }
  15.  
  16. public IFont CooldownFont { get; set; }
  17.  
  18. public float TextureOpacity { get; set; }
  19.  
  20. private readonly IWatch _lastTownEliteSimulation;
  21.  
  22. public IBrush TimeLeftClockBrush { get; set; }
  23.  
  24. public GLQ_SkillBarPainter(IController hud, bool setDefaultStyle)
  25. {
  26. Enabled = true;
  27. Hud = hud;
  28.  
  29. _lastTownEliteSimulation = Hud.Time.CreateWatch();
  30.  
  31. if (setDefaultStyle)
  32. {
  33. CooldownFont = Hud.Render.CreateFont("arial", 14, 255, 255, 255, 255, true, false, 255, 0, 0, 0, true);
  34. TimeLeftClockBrush = Hud.Render.CreateBrush(220, 0, 0, 0, 0);
  35.  
  36.  
  37. }
  38. }
  39.  
  40. public void Paint(IPlayerSkill skill, RectangleF rect)
  41. {
  42. if (skill == null) return;
  43.  
  44. if (TextureOpacity > 0)
  45. {
  46. var texture = Hud.Texture.GetTexture(skill.SnoPower.NormalIconTextureId);
  47. if (texture != null)
  48. {
  49. texture.Draw(rect.X, rect.Y, rect.Width, rect.Height, TextureOpacity);
  50. }
  51. }
  52.  
  53. if (skill.IsOnCooldown && (skill.CooldownFinishTick > Hud.Game.CurrentGameTick))
  54. {
  55. var remaining = (skill.CooldownFinishTick - Hud.Game.CurrentGameTick) / 60.0d;
  56. var text = remaining > 1.0f ? remaining.ToString("F0", CultureInfo.InvariantCulture) : remaining.ToString("F1", CultureInfo.InvariantCulture);
  57.  
  58. var textLayout = CooldownFont.GetTextLayout(text);
  59. DrawTimeLeftClock(rect, (Hud.Game.CurrentGameTick - skill.CooldownStartTick) / 60.0d , (skill.CooldownFinishTick - Hud.Game.CurrentGameTick) / 60.0d);
  60. CooldownFont.DrawText(textLayout, rect.X + (rect.Width - (float)Math.Ceiling(textLayout.Metrics.Width)) / 2.0f, rect.Y + (rect.Height - textLayout.Metrics.Height) / 2);
  61. }
  62.  
  63. var rune = skill.Rune;
  64. if (rune == byte.MaxValue) rune = 0; else rune += 1;
  65. }
  66.  
  67. private void DrawTimeLeftClock(RectangleF rect, double elapsed, double timeLeft)
  68. {
  69. if ((timeLeft > 0) && (elapsed >= 0) && (TimeLeftClockBrush != null))
  70. {
  71. var endAngle = Convert.ToInt32((360.0d / (timeLeft + elapsed)) * elapsed);
  72. var startAngle = 0;
  73. TimeLeftClockBrush.Opacity = 1 - (float)(0.3f / (timeLeft + elapsed) * elapsed);
  74. var rad = rect.Width * 0.45f;
  75. using (var pg = Hud.Render.CreateGeometry())
  76. {
  77. using (var gs = pg.Open())
  78. {
  79. gs.BeginFigure(rect.Center, FigureBegin.Filled);
  80. for (int angle = startAngle; angle <= endAngle; angle++)
  81. {
  82. var mx = rad * (float)Math.Cos((angle - 90) * Math.PI / 180.0f);
  83. var my = rad * (float)Math.Sin((angle - 90) * Math.PI / 180.0f);
  84. var vec = new Vector2(rect.Center.X + mx, rect.Center.Y + my);
  85. gs.AddLine(vec);
  86. }
  87. gs.EndFigure(FigureEnd.Closed);
  88. gs.Close();
  89. }
  90. TimeLeftClockBrush.DrawGeometry(pg);
  91. }
  92. }
  93. }
  94.  
  95. public IEnumerable<ITransparent> GetTransparents()
  96. {
  97. yield return CooldownFont;
  98. }
  99.  
  100. }
  101.  
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement