Advertisement
zjqyf

GLQ_PlayerInfoPlugin.cs

Aug 27th, 2017
862
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.45 KB | None | 0 0
  1. namespace Turbo.Plugins.glq
  2. {
  3. using System.Globalization;
  4. using System.Linq;
  5. using Turbo.Plugins.Default;
  6. using Turbo.Plugins.Jack.Decorators.TopTables;
  7.  
  8. public class GLQ_PlayerInfoPlugin : BasePlugin, INewAreaHandler, IInGameTopPainter
  9. {
  10. public TopTable Table { get; set; }
  11.  
  12. private int lastPlayerCount = -1;
  13. private int hoveredPlayerIndex = -1;
  14.  
  15. public GLQ_PlayerInfoPlugin()
  16. {
  17. Enabled = true;
  18. Order = int.MaxValue;
  19. }
  20.  
  21. public override void Load(IController hud)
  22. {
  23. base.Load(hud);
  24.  
  25. Table = new TopTable(Hud)
  26. {
  27. RatioPositionX = 0.5f,
  28. RatioPositionY = 0.03f,
  29. HorizontalCenter = true,
  30. VerticalCenter = false,
  31. PositionFromRight = false,
  32. PositionFromBottom = false,
  33. ShowHeaderLeft = false,
  34. ShowHeaderTop = true,
  35. ShowHeaderRight = false,
  36. ShowHeaderBottom = false,
  37. DefaultCellDecorator = new TopTableCellDecorator(Hud)
  38. {
  39. BackgroundBrush = Hud.Render.CreateBrush(255, 0, 0, 0, 0),
  40. BorderBrush = Hud.Render.CreateBrush(255, 70, 56, 42, 1.5f),
  41. TextFont = Hud.Render.CreateFont("tahoma", 7, 255, 255, 255, 255, false, false, false),
  42. },
  43. DefaultHighlightDecorator = new TopTableCellDecorator(Hud)
  44. {
  45. BackgroundBrush = Hud.Render.CreateBrush(255, 0, 0, 242, 0),
  46. BorderBrush = Hud.Render.CreateBrush(255, 70, 56, 42, 1.5f),
  47. TextFont = Hud.Render.CreateFont("tahoma", 7, 255, 255, 255, 255, false, false, false),
  48. },
  49. DefaultHeaderDecorator = new TopTableCellDecorator(Hud)
  50. {
  51. BackgroundBrush = Hud.Render.CreateBrush(255, 0, 0, 0, 0),
  52. BorderBrush = Hud.Render.CreateBrush(255, 70, 56, 42, 1.5f),
  53. TextFont = Hud.Render.CreateFont("tahoma", 7, 255, 255, 255, 255, false, false, true),
  54. }
  55. };
  56. DefineColumns();
  57. }
  58.  
  59. public void OnNewArea(bool newGame, ISnoArea area)
  60. {
  61. if (!newGame) return;
  62.  
  63. lastPlayerCount = -1;
  64. }
  65.  
  66. private void DefineTable()
  67. {
  68. Table.Reset(true); // keep columns
  69.  
  70. foreach (var player in Hud.Game.Players.OrderBy(p => p.PortraitIndex))
  71. {
  72. if (player == null) continue;
  73.  
  74. Table.AddLine(
  75. new TopTableHeader(Hud, (pos, curPos) => "")
  76. {
  77. RatioWidth = 120 / 1080f,
  78. RatioHeight = 28 / 1080f,
  79. HighlightFunc = (pos, curPos) => hoveredPlayerIndex == pos,
  80. HighlightDecorator = new TopTableCellDecorator(Hud)
  81. {
  82. BackgroundBrush = Hud.Render.CreateBrush(255, 255, 255, 128, 0),
  83. BorderBrush = Hud.Render.CreateBrush(255, 70, 56, 42, 1.5f),
  84. TextFont = Hud.Render.CreateFont("tahoma", 7, 255, 0, 0, 0, true, false, false),
  85. },
  86. CellHighlightDecorator = new TopTableCellDecorator(Hud)
  87. {
  88. BackgroundBrush = Hud.Render.CreateBrush(255, 255, 0, 255, 0),
  89. BorderBrush = Hud.Render.CreateBrush(255, 70, 56, 42, 1.5f),
  90. TextFont = Hud.Render.CreateFont("tahoma", 7, 255, 255, 255, 255, true, false, true),
  91. },
  92. },
  93. new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  94. new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  95. new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  96. new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  97. new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  98. new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  99. new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  100. new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  101. new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  102. new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  103. new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c))
  104. );
  105. }
  106. }
  107.  
  108. private string GetCellText(int line, int column)
  109. {
  110. var player = Hud.Game.Players.FirstOrDefault(p => p.PortraitIndex == line);
  111. if (player == null) return string.Empty;
  112.  
  113. switch (column)
  114. {
  115. case 0:
  116. return player.BattleTagAbovePortrait;
  117. case 1:
  118. return ValueToString((long)player.Defense.EhpCur, ValueFormat.LongNumber);
  119. case 2:
  120. return ValueToString((long)player.Offense.SheetDps, ValueFormat.LongNumber);
  121. case 3:
  122. return player.Stats.MainStat.ToString();
  123. case 4:
  124. return player.Offense.AttackSpeedPets.ToString("F2", CultureInfo.InvariantCulture) + "/s";
  125. case 5:
  126. return player.Offense.CriticalHitChance.ToString("F2", CultureInfo.InvariantCulture) + "%";
  127. case 6:
  128. return player.Offense.CritDamage.ToString("F2", CultureInfo.InvariantCulture) + "%";
  129. case 7:
  130. return (player.Stats.CooldownReduction * 100).ToString("F1", CultureInfo.InvariantCulture) + "%";
  131. case 8:
  132. return (player.Stats.ResourceCostReduction * 100).ToString("F1", CultureInfo.InvariantCulture) + "%";
  133. case 9:
  134. return player.Offense.AreaDamageBonus.ToString() + "%";
  135. case 10:
  136. return player.HighestSoloRiftLevel.ToString();
  137. default:
  138. return string.Empty;
  139. }
  140. }
  141.  
  142. private void DefineColumns()
  143. {
  144. Table.DefineColumns(
  145. new TopTableHeader(Hud, (pos, curPos) => "player")
  146. {
  147. RatioHeight = 28 / 1080f,
  148. RatioWidth = 120 / 1080f,
  149. },
  150. new TopTableHeader(Hud, (pos, curPos) => "CurEHP")
  151. {
  152. RatioWidth = 0.07f,
  153. },
  154. new TopTableHeader(Hud, (pos, curPos) => "SheetDps")
  155. {
  156. RatioWidth = 0.07f,
  157. },
  158. new TopTableHeader(Hud, (pos, curPos) => "MainStat")
  159. {
  160. RatioWidth = 0.06f,
  161. },
  162. new TopTableHeader(Hud, (pos, curPos) => "ASPet")
  163. {
  164. RatioWidth = 0.05f,
  165. },
  166. new TopTableHeader(Hud, (pos, curPos) => "CritHitChance")
  167. {
  168. RatioWidth = 0.08f,
  169. },
  170. new TopTableHeader(Hud, (pos, curPos) => "CritDamage")
  171. {
  172. RatioWidth = 0.07f,
  173. },
  174. new TopTableHeader(Hud, (pos, curPos) => "CDR")
  175. {
  176. RatioWidth = 0.045f,
  177. },
  178. new TopTableHeader(Hud, (pos, curPos) => "RCR")
  179. {
  180. RatioWidth = 0.045f,
  181. },
  182. new TopTableHeader(Hud, (pos, curPos) => "AreaD")
  183. {
  184. RatioWidth = 0.04f,
  185. },
  186. new TopTableHeader(Hud, (pos, curPos) => "SoloRift")
  187. {
  188. RatioWidth = 0.05f,
  189. }
  190. );
  191. }
  192.  
  193. public void PaintTopInGame(ClipState clipState)
  194. {
  195. if (clipState != ClipState.BeforeClip) return;
  196. if (Hud.Inventory.StashMainUiElement.Visible) return;
  197. var myPortrait = Hud.Game.Me.PortraitUiElement.Rectangle;
  198. if (Hud.Window.CursorX > myPortrait.Right)
  199. {
  200. lastPlayerCount = -1;
  201. return; // cursor is too much to the right, no need to go further
  202. }
  203.  
  204. if (lastPlayerCount != Hud.Game.Players.Count())
  205. {
  206. lastPlayerCount = Hud.Game.Players.Count();
  207. DefineTable();
  208. return; // no need to lose more time within this frame
  209. }
  210.  
  211. var displayTable = false;
  212. foreach (var player in Hud.Game.Players.OrderBy(p => p.PortraitIndex))
  213. {
  214. if (player == null) continue;
  215. var portrait = player.PortraitUiElement.Rectangle;
  216. if (!Hud.Window.CursorInsideRect(portrait.X, portrait.Y, portrait.Width, portrait.Height)) continue;
  217.  
  218. hoveredPlayerIndex = (Hud.Game.NumberOfPlayersInGame > 1) ? player.PortraitIndex : -1;
  219. displayTable = true;
  220. }
  221.  
  222. if (displayTable && Table != null)
  223. Table.Paint();
  224. }
  225. }
  226. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement