Code:
using System;
using Turbo.Plugins.Default;
using System.Linq;
using System.Collections.Generic;
using SharpDX;
using SharpDX.Direct2D1;
using System.Threading;
using System.Drawing;
namespace Turbo.Plugins.RNN
{
public class ArchoinIcon : BasePlugin, IInGameTopPainter
{
private SharpDX.DirectWrite.TextLayout layout { get; set; } = null;
public bool ShowLegendaryBackground { get; set; } = true;
private IFont FontTimeLeft { get; set; }
private IFont FontCooldown { get; set; }
private IFont FontStacks { get; set; }
private IFont FontNames { get; set; }
public bool ShowNames { get; set; }
public bool EnableBuffsFar { get; set; }
private float _SizeMultiplier { get; set; }
public float OffsetX { get; set; }
public float OffsetY { get; set; }
public float Opacity { get; set; }
public int ProgressBarWidth { get; set; }
public IBrush BorderBrush { get; set; }
public IBrush TimeLeftClockBrush { get; set; }
public IBrush SwamiBrush { get; set; }
private IBrush BrushBlack { get; set; }
private IBrush BrushRed { get; set; }
private float SizeIconW { get; set; }
private float SizeIconH { get; set; }
public float SizeMultiplier
{
get { return _SizeMultiplier; }
set
{
if (_SizeMultiplier != value)
{
_SizeMultiplier = value;
FontTimeLeft = Hud.Render.CreateFont("Tahoma", 7.5f * _SizeMultiplier, 255, 0, 255, 0, true, false, 255, 0, 0, 0, true);
FontCooldown = Hud.Render.CreateFont("Tahoma", 7.5f * _SizeMultiplier, 255, 255, 255, 255, true, false, 255, 0, 0, 0, true);
FontStacks = Hud.Render.CreateFont("Tahoma", 9f * _SizeMultiplier, 255, 255, 255, 0, true, false, 255, 0, 0, 0, true);
}
}
}
public ArchoinIcon()
{
Enabled = true;
}
public override void Load(IController hud)
{
base.Load(hud);
Order = 91000;
OffsetX = 3.0f; // To set the x coordinate of the icon (OffsetYX * Portrait Width)
OffsetY = 0.48f; // To set the y coordinate of the icon (OffsetYX * Portrait Height)
Opacity = 1f; // 0f..1f Opacity for icon texture
SizeMultiplier = 1.4f; // Size multiplier for icons
ShowNames = true; // Show players names
EnableBuffsFar = true; // Show Archon and Swami Buffs when the player is far
ProgressBarWidth = 90; // Width progressbar swami (pixels)
BorderBrush = Hud.Render.CreateBrush(255, 0, 255, 0, 6f);
BrushBlack = Hud.Render.CreateBrush(220, 80, 80, 80, 0);
BrushRed = Hud.Render.CreateBrush(230, 255, 0 , 0, 0);
TimeLeftClockBrush = Hud.Render.CreateBrush(220, 0, 0, 0, 0);
SwamiBrush = Hud.Render.CreateBrush(255, 0, 255, 0, 7f); // green
FontNames = Hud.Render.CreateFont("tahoma", 8f * SizeMultiplier, 235, 235, 235, 235, false, false, 255, 0, 0, 0, true); // user name
}
public void PaintTopInGame(ClipState clipState)
{
if (clipState != ClipState.BeforeClip) return;
if (!Hud.Game.IsInGame) return;
var players = Hud.Game.Players.Where(p => p.HeroClassDefinition.HeroClass == HeroClass.Wizard);
foreach(var player in players)
{
var skill = player.Powers.UsedSkills.FirstOrDefault(s => s.SnoPower.Sno == 134872);
if (skill != null && skill.Buff != null)
{
var x = player.PortraitUiElement.Rectangle.X + player.PortraitUiElement.Rectangle.Width * OffsetX; var y = player.PortraitUiElement.Rectangle.Y + player.PortraitUiElement.Rectangle.Height * OffsetY;
var SizeIconWidth = Hud.Texture.BuffFrameTexture.Width * Hud.Window.Size.Height/1200.0f * _SizeMultiplier; var SizeIconHeight = Hud.Texture.BuffFrameTexture.Height * Hud.Window.Size.Height/1200.0f * _SizeMultiplier;
var SizeIconW = Hud.Texture.BuffFrameTexture.Width * Hud.Window.Size.Height/1200.0f * 0.7f; // swaimi icon W resize
var SizeIconH = Hud.Texture.BuffFrameTexture.Height * Hud.Window.Size.Height/1200.0f * 0.5f; // swaimi icon H rezize
if (player.HasValidActor)
{
if (ShowNames) { layout = FontNames.GetTextLayout(player.BattleTagAbovePortrait); FontNames.DrawText(layout,x + 1,y ); y += layout.Metrics.Height + 1; }
double timeleft = 0f;
int stacks = -1;
if (skill.Buff.IconCounts[6] > 0)
{
timeleft = skill.Buff.TimeLeftSeconds[5];
stacks = skill.Buff.IconCounts[5];
Hud.Texture.InventoryLegendaryBackgroundLarge.Draw(x,y,SizeIconWidth,SizeIconHeight,Opacity);
// Hud.Texture.GetItemTexture(Hud.Sno.SnoItems.P3_Unique_WizardHat_003).Draw(x + SizeIconWidth/8, y - SizeIconHeight/4, SizeIconWidth * 0.75f, SizeIconHeight * 1.70f, Opacity); // default
Hud.Texture.GetItemTexture(Hud.Sno.SnoItems.P3_Unique_WizardHat_003).Draw(x + 100 + SizeIconW/8, y + 30 - SizeIconH/4, SizeIconW * 0.75f, SizeIconH * 1.7f, Opacity); // swami icon y + @
SwamiBrush.DrawRectangle(x, y, SizeIconWidth, SizeIconHeight ); // green box
BrushBlack.DrawRectangle(x , y, SizeIconWidth , ProgressBarWidth);
if ( timeleft > 0)
{
BrushRed.DrawRectangle(x, y, - ( timeleft * SizeIconWidth) , - ProgressBarWidth);
}
}
else
{
if (skill.Buff.IconCounts[2] > 0)
{
timeleft = skill.Buff.TimeLeftSeconds[2];
stacks = skill.Buff.IconCounts[4] + skill.Buff.IconCounts[5];
}
Hud.Texture.GetTexture(skill.SnoPower.NormalIconTextureId).Draw(x, y, SizeIconWidth, SizeIconHeight, Opacity);
}
Hud.Texture.BuffFrameTexture.Draw(x, y, SizeIconWidth, SizeIconHeight, Opacity);
if (timeleft > 0)
{
layout = FontTimeLeft.GetTextLayout((timeleft < 1.0f)?String.Format("{0:N1}", timeleft): String.Format("{0:0}", (int) (timeleft + 0.80)));
FontTimeLeft.DrawText(layout, x - 20+ ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/2.0f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/12.0f) ); // stack left time x - @
}
if (stacks >= 0)
{
layout = FontStacks.GetTextLayout(stacks.ToString());
FontStacks.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/2.0f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/2.0f) );
}
if (EnableBuffsFar || player.HasValidActor)
{
if (timeleft > 0)
{
layout = FontTimeLeft.GetTextLayout((timeleft < 1.0f)?String.Format("{0:N1}", timeleft): String.Format("{0:0}", (int) (timeleft + 0.80)));
FontTimeLeft.DrawText(layout, x -20 + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/2.0f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/12.0f) );
}
}
}
else
{
Hud.Texture.GetTexture(skill.SnoPower.NormalIconTextureId).Draw(x, y, SizeIconWidth, SizeIconHeight, Opacity);
Hud.Texture.DebuffFrameTexture.Draw(x, y, SizeIconWidth, SizeIconHeight, Opacity);
}
if (skill.CooldownFinishTick > Hud.Game.CurrentGameTick)
{
double remaining = (skill.CooldownFinishTick - Hud.Game.CurrentGameTick)/60.0d;
layout = FontCooldown.GetTextLayout( remaining.ToString( (remaining < 1)? "F1":"F0" ) );
FontCooldown.DrawText(layout, x + 20 + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/2.0f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/1.1f) ); // skill cooldown x + @
}
}
}
}
}
}