-
-
Save JackCeparou/3a6e7788134c429392c46780a0cb9b77 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Turbo.Plugins.glq | |
{ | |
using System.Globalization; | |
using System.Linq; | |
using Turbo.Plugins.Default; | |
using Turbo.Plugins.Jack.Decorators.TopTables; | |
public class GLQ_PlayerInfoPlugin : BasePlugin, INewAreaHandler, IInGameTopPainter | |
{ | |
public TopTable Table { get; set; } | |
private int lastPlayerCount = -1; | |
private int hoveredPlayerIndex = -1; | |
public GLQ_PlayerInfoPlugin() | |
{ | |
Enabled = true; | |
Order = int.MaxValue; | |
} | |
public override void Load(IController hud) | |
{ | |
base.Load(hud); | |
Table = new TopTable(Hud) | |
{ | |
RatioPositionX = 0.5f, | |
RatioPositionY = 0.03f, | |
HorizontalCenter = true, | |
VerticalCenter = false, | |
PositionFromRight = false, | |
PositionFromBottom = false, | |
ShowHeaderLeft = false, | |
ShowHeaderTop = true, | |
ShowHeaderRight = false, | |
ShowHeaderBottom = false, | |
DefaultCellDecorator = new TopTableCellDecorator(Hud) | |
{ | |
BackgroundBrush = Hud.Render.CreateBrush(255, 0, 0, 0, 0), | |
BorderBrush = Hud.Render.CreateBrush(255, 70, 56, 42, 1.5f), | |
TextFont = Hud.Render.CreateFont("tahoma", 7, 255, 255, 255, 255, false, false, false), | |
}, | |
DefaultHighlightDecorator = new TopTableCellDecorator(Hud) | |
{ | |
BackgroundBrush = Hud.Render.CreateBrush(255, 0, 0, 242, 0), | |
BorderBrush = Hud.Render.CreateBrush(255, 70, 56, 42, 1.5f), | |
TextFont = Hud.Render.CreateFont("tahoma", 7, 255, 255, 255, 255, false, false, false), | |
}, | |
DefaultHeaderDecorator = new TopTableCellDecorator(Hud) | |
{ | |
BackgroundBrush = Hud.Render.CreateBrush(255, 0, 0, 0, 0), | |
BorderBrush = Hud.Render.CreateBrush(255, 70, 56, 42, 1.5f), | |
TextFont = Hud.Render.CreateFont("tahoma", 7, 255, 255, 255, 255, false, false, true), | |
} | |
}; | |
DefineColumns(); | |
} | |
public void OnNewArea(bool newGame, ISnoArea area) | |
{ | |
if (!newGame) return; | |
lastPlayerCount = -1; | |
} | |
private void DefineTable() | |
{ | |
Table.Reset(true); // keep columns | |
foreach (var player in Hud.Game.Players.OrderBy(p => p.PortraitIndex)) | |
{ | |
if (player == null) continue; | |
Table.AddLine( | |
new TopTableHeader(Hud, (pos, curPos) => "") | |
{ | |
RatioWidth = 120 / 1080f, | |
RatioHeight = 28 / 1080f, | |
HighlightFunc = (pos, curPos) => hoveredPlayerIndex == pos, | |
HighlightDecorator = new TopTableCellDecorator(Hud) | |
{ | |
BackgroundBrush = Hud.Render.CreateBrush(255, 255, 255, 128, 0), | |
BorderBrush = Hud.Render.CreateBrush(255, 70, 56, 42, 1.5f), | |
TextFont = Hud.Render.CreateFont("tahoma", 7, 255, 0, 0, 0, true, false, false), | |
}, | |
CellHighlightDecorator = new TopTableCellDecorator(Hud) | |
{ | |
BackgroundBrush = Hud.Render.CreateBrush(255, 255, 0, 255, 0), | |
BorderBrush = Hud.Render.CreateBrush(255, 70, 56, 42, 1.5f), | |
TextFont = Hud.Render.CreateFont("tahoma", 7, 255, 255, 255, 255, true, false, true), | |
}, | |
}, | |
new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)), | |
new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)), | |
new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)), | |
new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)), | |
new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)), | |
new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)), | |
new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)), | |
new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)), | |
new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)), | |
new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)), | |
new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)) | |
); | |
} | |
} | |
private string GetCellText(int line, int column) | |
{ | |
var player = Hud.Game.Players.FirstOrDefault(p => p.PortraitIndex == line); | |
if (player == null) return string.Empty; | |
switch (column) | |
{ | |
case 0: | |
return player.BattleTagAbovePortrait; | |
case 1: | |
return ValueToString((long)player.Defense.EhpCur, ValueFormat.LongNumber); | |
case 2: | |
return ValueToString((long)player.Offense.SheetDps, ValueFormat.LongNumber); | |
case 3: | |
return player.Stats.MainStat.ToString(); | |
case 4: | |
return player.Offense.AttackSpeedPets.ToString("F2", CultureInfo.InvariantCulture) + "/s"; | |
case 5: | |
return player.Offense.CriticalHitChance.ToString("F2", CultureInfo.InvariantCulture) + "%"; | |
case 6: | |
return player.Offense.CritDamage.ToString("F2", CultureInfo.InvariantCulture) + "%"; | |
case 7: | |
return (player.Stats.CooldownReduction * 100).ToString("F1", CultureInfo.InvariantCulture) + "%"; | |
case 8: | |
return (player.Stats.ResourceCostReduction * 100).ToString("F1", CultureInfo.InvariantCulture) + "%"; | |
case 9: | |
return player.Offense.AreaDamageBonus.ToString() + "%"; | |
case 10: | |
return player.HighestSoloRiftLevel.ToString(); | |
default: | |
return string.Empty; | |
} | |
} | |
private void DefineColumns() | |
{ | |
Table.DefineColumns( | |
new TopTableHeader(Hud, (pos, curPos) => "player") | |
{ | |
RatioHeight = 28 / 1080f, | |
RatioWidth = 120 / 1080f, | |
}, | |
new TopTableHeader(Hud, (pos, curPos) => "CurEHP") | |
{ | |
RatioWidth = 0.07f, | |
}, | |
new TopTableHeader(Hud, (pos, curPos) => "SheetDps") | |
{ | |
RatioWidth = 0.07f, | |
}, | |
new TopTableHeader(Hud, (pos, curPos) => "MainStat") | |
{ | |
RatioWidth = 0.06f, | |
}, | |
new TopTableHeader(Hud, (pos, curPos) => "ASPet") | |
{ | |
RatioWidth = 0.05f, | |
}, | |
new TopTableHeader(Hud, (pos, curPos) => "CritHitChance") | |
{ | |
RatioWidth = 0.08f, | |
}, | |
new TopTableHeader(Hud, (pos, curPos) => "CritDamage") | |
{ | |
RatioWidth = 0.07f, | |
}, | |
new TopTableHeader(Hud, (pos, curPos) => "CDR") | |
{ | |
RatioWidth = 0.045f, | |
}, | |
new TopTableHeader(Hud, (pos, curPos) => "RCR") | |
{ | |
RatioWidth = 0.045f, | |
}, | |
new TopTableHeader(Hud, (pos, curPos) => "AreaD") | |
{ | |
RatioWidth = 0.04f, | |
}, | |
new TopTableHeader(Hud, (pos, curPos) => "SoloRift") | |
{ | |
RatioWidth = 0.05f, | |
} | |
); | |
} | |
public void PaintTopInGame(ClipState clipState) | |
{ | |
if (clipState != ClipState.BeforeClip) return; | |
foreach (var player in Hud.Game.Players) | |
{ | |
var rect = player.PortraitUiElement.Rectangle; | |
var text = string.Format("{0} Index : {1} PortraitIndex : {2}", player.BattleTagAbovePortrait, player.Index, player.PortraitIndex); | |
Table.DefaultCellDecorator.TextFont.DrawText(text, rect.Right, rect.Bottom); | |
} | |
if (lastPlayerCount != Hud.Game.Players.Count()) | |
{ | |
lastPlayerCount = Hud.Game.Players.Count(); | |
DefineTable(); | |
return; // no need to lose more time within this frame | |
} | |
var myPortrait = Hud.Game.Me.PortraitUiElement.Rectangle; | |
if (Hud.Window.CursorX > myPortrait.Right) return; // cursor is too much to the right, no need to go further | |
var displayTable = false; | |
foreach (var player in Hud.Game.Players.OrderBy(p => p.PortraitIndex)) | |
{ | |
if (player == null) continue; | |
var portrait = player.PortraitUiElement.Rectangle; | |
if (!Hud.Window.CursorInsideRect(portrait.X, portrait.Y, portrait.Width, portrait.Height)) continue; | |
hoveredPlayerIndex = (Hud.Game.NumberOfPlayersInGame > 1) ? player.PortraitIndex : -1; | |
displayTable = true; | |
} | |
if (displayTable && Table != null) | |
Table.Paint(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment