Advertisement
Guest User

BuffLabelsPlugin.cs

a guest
Nov 18th, 2017
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.82 KB | None | 0 0
  1. namespace Turbo.Plugins.RuneB
  2. {
  3. using Turbo.Plugins.Default;
  4. using System.Collections.Generic;
  5.  
  6. public class BuffLabelsPlugin : BasePlugin, IInGameTopPainter
  7. {
  8. public bool ShowIgnorePain { get; set; }
  9. public bool ShowOculus { get; set; }
  10. public bool ShowInnerSanctuary { get; set; }
  11.  
  12. public bool ChangeTextSize { get; set; }
  13.  
  14. public float YPos { get; set; }
  15. public float XPos { get; set; }
  16. public float SizeModifier { get; set; }
  17. public float TextSize { get; set; }
  18. public float JumpDistance { get; set; }
  19. public float SmoothSpeed { get; set; }
  20. public int NumRows { get; set; }
  21.  
  22. public float YPosIncrement { get; set; }
  23.  
  24. public bool Debug { get; set; }
  25. public bool SmoothMovement { get; set; }
  26.  
  27. public IFont TextFont { get; set; }
  28. public IBrush BorderBrush { get; set; }
  29. public IBrush BackgroundBrushIP { get; set; }
  30. public IBrush BackgroundBrushOC { get; set; }
  31. public IBrush BackgroundBrushIS { get; set; }
  32.  
  33. public List<Label> Labels { get; set; }
  34.  
  35. private float _yPosTemp, _xPosTemp, _xPosGoal, _labelWidthPercentage, _labelHeightPercentage, _jumpCount;
  36. private bool _jumped, _debugStarted, _debugDone, _debugAlreadyAdded, _started;
  37. private int _debugAddShifter = 0, _activeBuffsCount = 0;
  38.  
  39. private float hudWidth { get { return Hud.Window.Size.Width; } }
  40. private float hudHeight { get { return Hud.Window.Size.Height; } }
  41. private float lWidth { get { return hudWidth * _labelWidthPercentage * SizeModifier; } }
  42. private float lHeight { get { return hudHeight * _labelHeightPercentage * SizeModifier; } }
  43.  
  44. private List<Label> _debugLabels;
  45. private IWatch debugWatch;
  46.  
  47. public BuffLabelsPlugin()
  48. {
  49. Enabled = true;
  50. }
  51.  
  52. public override void Load(IController hud)
  53. {
  54. base.Load(hud);
  55.  
  56. //Turn labels on and off
  57. ShowIgnorePain = true;
  58. ShowOculus = true;
  59. ShowInnerSanctuary = true;
  60.  
  61. //Horizontal and Vertical label positions.
  62. YPos = 0.65f;
  63. XPos = 0.5f;
  64.  
  65. SizeModifier = 1f;
  66. TextSize = 7;
  67. JumpDistance = 1.07f;
  68. NumRows = 1;
  69.  
  70. //Label size is based on a percentage of screen width/height
  71. _labelWidthPercentage = 0.055f;
  72. _labelHeightPercentage = 0.016f;
  73.  
  74. //Vertical distance between labels
  75. YPosIncrement = 0.021f;
  76.  
  77. //If true labels are always shown
  78. Debug = false;
  79. SmoothMovement = true;
  80. SmoothSpeed = 0.05f;
  81. debugWatch = Hud.Time.CreateWatch();
  82. debugWatch.Restart();
  83.  
  84. BorderBrush = Hud.Render.CreateBrush(150, 30, 30, 30, 0);
  85.  
  86. BackgroundBrushIP = Hud.Render.CreateBrush(100, 100, 225, 100, 0); // Ignore Pain
  87. BackgroundBrushOC = Hud.Render.CreateBrush(100, 255, 255, 50, 0); // Oculus
  88. BackgroundBrushIS = Hud.Render.CreateBrush(100, 185, 220, 245, 0); // Inner Sanctuary
  89.  
  90. Labels = new List<Label>();
  91.  
  92. _jumpCount = 1;
  93. _yPosTemp = YPos;
  94. _xPosTemp = XPos;
  95. _xPosGoal = 0.5f;
  96. if (NumRows < 1) NumRows = 1;
  97. }
  98.  
  99. public void PaintTopInGame(ClipState clipState)
  100. {
  101. if (clipState != ClipState.BeforeClip) return;
  102. if (!_started)
  103. {// Fix to make it possible to set oculus & sanc to false through customize. this is a bit overheady
  104. _started = true;
  105. Labels.Add(new Label("Oculus", 402461, 2, BackgroundBrushOC, ShowOculus));
  106. Labels.Add(new Label("Inner Sanctuary", 317076, 1, BackgroundBrushIS, ShowInnerSanctuary));
  107. }
  108. //Allow changing font size from a customize method by instatiating here instead of in Load
  109. if (TextFont == null)
  110. {
  111. TextFont = Hud.Render.CreateFont("tahoma", TextSize * SizeModifier, 240, 240, 240, 240, true, false, true);
  112. }
  113.  
  114. //Draw all labels
  115. foreach (Label l in Labels)
  116. if (l.Show && (Hud.Game.Me.Powers.BuffIsActive((uint)l.Sno, l.IconCount) || Debug))
  117. DrawLabel(l.LabelBrush, l.NameText);
  118.  
  119. //Avoid potentially showing two IP labels. TODO: Find a better way to do this - without adding a list of conditions to the Label class since this would make adding new buffs more complex.
  120. if (ShowIgnorePain && (Hud.Game.Me.Powers.BuffIsActive(79528, 0) || Hud.Game.Me.Powers.BuffIsActive(79528, 1)) || Debug)
  121. DrawLabel(BackgroundBrushIP, "Ignore Pain");
  122.  
  123. //Smooth horizontal movement
  124. CalculateXPosTemp();
  125.  
  126. //Reset vars
  127. _yPosTemp = YPos;
  128. _jumped = false;
  129. _jumpCount = 0;
  130. _activeBuffsCount = 0;
  131.  
  132. //Add labels one by one if debug
  133. if (Debug && !_debugDone)
  134. {
  135. DebugTimedAdd();
  136. }
  137. }
  138.  
  139. private void DrawLabel(IBrush label, string buffText)
  140. {
  141. _activeBuffsCount++;
  142. _yPosTemp += YPosIncrement * SizeModifier;
  143. float xJump = CalculateJump();
  144.  
  145. BorderBrush.DrawRectangle(hudWidth * _xPosTemp - (lWidth * 1.05f * .5f) + xJump, hudHeight * _yPosTemp - lHeight * 1.1f, lWidth * 1.05f, lHeight * 1.2f);
  146. label.DrawRectangle(hudWidth * _xPosTemp - lWidth * .5f + xJump, hudHeight * _yPosTemp - lHeight, lWidth, lHeight);
  147.  
  148. var layout = TextFont.GetTextLayout(buffText);
  149. TextFont.DrawText(layout, hudWidth * _xPosTemp - (layout.Metrics.Width * 0.5f) + xJump, hudHeight * _yPosTemp - (layout.Metrics.Height * 1.1f));
  150.  
  151. }
  152.  
  153. private float CalculateJump()
  154. {
  155. float xJump = lWidth * JumpDistance * _jumpCount;
  156. if (_yPosTemp >= (YPos + (YPosIncrement * SizeModifier * .9f * (NumRows))))
  157. {
  158. _yPosTemp = YPos;
  159. _jumpCount += 1;
  160. }
  161. return xJump;
  162. }
  163.  
  164. private void CalculateXPosTemp()
  165. {
  166. var jump = _jumpCount;
  167. //_xPosGoal = 0.5f;
  168. if (_activeBuffsCount % NumRows == 0)
  169. {
  170. jump = (_activeBuffsCount - 1) / NumRows;
  171. _xPosGoal = (_jumpCount < 1) ? XPos : (float)(XPos - (_labelWidthPercentage * SizeModifier * ((_activeBuffsCount * .01f) + 1) * (jump)) / 2);
  172.  
  173. }
  174. if (SmoothMovement)
  175. {
  176. if (_xPosTemp < _xPosGoal) _xPosTemp += (_xPosGoal - _xPosTemp) * SmoothSpeed;
  177. if (_xPosTemp > _xPosGoal) _xPosTemp -= (_xPosTemp - _xPosGoal) * SmoothSpeed;
  178. }
  179. else _xPosTemp = _xPosGoal;
  180. }
  181.  
  182. private void DebugTimedAdd()
  183. {
  184. if (!_debugStarted)
  185. {
  186. _debugLabels = new List<Label>();
  187. foreach (Label l in Labels)
  188. _debugLabels.Add(l);
  189. Labels.Clear();
  190. _debugStarted = true;
  191. }
  192.  
  193. int time = (int)debugWatch.ElapsedMilliseconds / 1000;
  194. if (time != _debugAddShifter)
  195. _debugAlreadyAdded = false;
  196. if (time % 2 == 0 && !_debugAlreadyAdded)
  197. {
  198. _debugAlreadyAdded = true;
  199. _debugAddShifter = time;
  200. var layout1 = TextFont.GetTextLayout("" + time);
  201. TextFont.DrawText(layout1, hudWidth * 0.2f - (layout1.Metrics.Width * 0.5f), hudHeight * .15f);
  202.  
  203. Labels.Add(_debugLabels[0]);
  204. _debugLabels.RemoveAt(0);
  205. }
  206. if (_debugLabels.Count == 0)
  207. _debugDone = true;
  208. }
  209.  
  210. }
  211.  
  212. public class Label
  213. {
  214. public string NameText { get; set; }
  215. public int Sno { get; set; }
  216. public int IconCount { get; set; }
  217. public IBrush LabelBrush { get; set; }
  218. public bool Show { get; set; }
  219.  
  220. public Label(string NameText, int Sno, int IconCount, IBrush LabelBrush)
  221. {
  222. this.NameText = NameText;
  223. this.Sno = Sno;
  224. this.IconCount = IconCount;
  225. this.LabelBrush = LabelBrush;
  226. Show = true;
  227. }
  228.  
  229. public Label(string NameText, int Sno, int IconCount, IBrush LabelBrush, bool Show)
  230. {
  231. this.NameText = NameText;
  232. this.Sno = Sno;
  233. this.IconCount = IconCount;
  234. this.LabelBrush = LabelBrush;
  235. this.Show = Show;
  236. }
  237. }
  238. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement