using Turbo.Plugins.Default;  
using System;
using System.Globalization;
using System.Linq;    
using System.Collections.Generic;
using SharpDX;
using SharpDX.Direct2D1;
 
namespace Turbo.Plugins.User
{        
    public class BuildsIconsAndCoe : BasePlugin, IInGameTopPainter, ICustomizer, INewAreaHandler
    {       
        private Dictionary<HeroClass,List<int>> AllBonusElements { get; set; }
        private int[] IndexToBonus { get; set; } = new int[8] { 7, 5, 3, 1, 6, 2, 0, 4 };
        
        private int Ticks0 { get; set; } = 0;
        private int Count0 { get; set; } = 0;       
        
        private float SizeIconWidth  { get; set; } 
        private float SizeIconHeight  { get; set; } 
        private SharpDX.DirectWrite.TextLayout layout { get; set; } = null;   
 
        private IFont FontAS { get; set; }
        private IFont FontWhite { get; set; }
        private IFont FontGray { get; set; }
        private IFont FontGreen { get; set; }   
        private IFont FontYellow { get; set; }
        private IFont FontOrange { get; set; }
        private IFont FontBlue { get; set; }
        private IFont FontDefault { get; set; } = null;
        private IFont FontNames { get; set; }   
        private IFont FontLocust { get; set; }          
        private IFont FontFury { get; set; }
        
        private IFont FontStacks { get; set; }
        private IFont FontTimeLeft { get; set; }
        private IFont FontTimeLeft2 { get; set; }       
        private IFont FontStacksRed { get; set; }
        
        private IBrush TimeLeftClockBrush { get; set; }     
        private IBrush BrushBlack { get; set; }
        private IBrush BrushGreen { get; set; }
        private IBrush BrushRed { get; set; }       
        private IBrush BrushYellow { get; set; }
        private IBrush BrushOrange { get; set; }
        private IBrush BrushBlue { get; set; }
        private IBrush BrushDefault { get; set; } 
        
        private IFont FontCounter { get; set; }
        private IFont FontExpl { get; set; }
        private IFont FontLimit { get; set; }   
        private IFont FontLimit2 { get; set; }          
        
        public float Xpor  { get; set; }
        public float Ypor  { get; set; }        
        public float SizeMultiplier  { get; set; }
        public bool ShowCoe { get; set; }
        public bool OnlyGR { get; set; }
        public bool OnlyMe { get; set; } = false;
        public bool ShowMe { get; set; }
        public bool ShowOthers { get; set; }
        public float Opacity { get; set; }
        public bool InactiveRedFrame { get; set; }
        public bool ShowNames { get; set; }
        public int ProgressBarWidth { get; set; } = 2;  
        
        public bool Nayr { get; set; }
        public bool BoneSpear { get; set; }     
        public bool Singularity { get; set; }
        public bool ShowEssenceMages { get; set; }  
        public float EssenceLimit { get; set; }
        
        public bool SpiritBarrage { get; set; }
        public bool ShowGlobes { get; set; }
        public bool ShowSoulHarvest { get; set; }       
        public bool ShowBigBadVoodoo { get; set; }
        public bool ShowSpiritWalk { get; set; }
        public bool ShowLocust { get; set; }
        public bool ShowHaunted { get; set; }
        public int YardsLocustHaunt { get; set; }
        public float SBWarning { get; set; }
        
        public bool ThornsBomb { get; set; }
        public bool ValorFotH { get; set; } 
        public bool SteedCharge { get; set; }
        public bool FlailCharge { get; set; }
        public bool Akarat { get; set; }
        
        private Dictionary<uint,int> Phantasms { get;set; } = new Dictionary<uint,int>();       
 
        private HashSet<ActorSnoEnum> ZombieDogSno = new HashSet<ActorSnoEnum>
        {       
            ActorSnoEnum._wd_zombiedog,                 // 51353    //2 rune
            ActorSnoEnum._wd_zombiedogrune_fire,        // 103215   //4 rune
            ActorSnoEnum._wd_zombiedogrune_healthglobe, // 105763   //0 rune
            ActorSnoEnum._wd_zombiedogrune_healthlink,  // 110959   //3 rune
            ActorSnoEnum._wd_zombiedogrune_lifesteal,   // 103235   //5 rune
            ActorSnoEnum._wd_zombiedogrune_poison,      // 103217   //1 rune
        };  
        private HashSet<ActorSnoEnum> MagesSno = new HashSet<ActorSnoEnum>
        {       
            ActorSnoEnum._p6_necro_skeletonmage_b,      
            ActorSnoEnum._p6_necro_skeletonmage_e,      
            ActorSnoEnum._p6_necro_skeletonmage_f_archer,   
            ActorSnoEnum._p6_necro_skeletonmage_c,  
            ActorSnoEnum._p6_necro_skeletonmage_d,  
        };  
        
        public BuildsIconsAndCoe()
        {
            Enabled = true;    
        }
        
        public override void Load(IController hud)
        {
            base.Load(hud); 
            Order = 30001;
            /* Necro */
            Nayr = true;                // Enable Icons Build Nayr
            BoneSpear = true;           // Enable Icons Build Bone Spear (Set Bonus 6)  
            Singularity = true;         // Enable Icons Build Singularity
            ShowEssenceMages = true;    // Show amount of essence with which the mages are summoned
            EssenceLimit = 0.66f;       // 0f .. 0.95f . When the essence is below this value it will be colored orange (Green if it is at maximum and in another case yellow)
            
            /* WitchDoctor  */
            SpiritBarrage = true;       // Enable Icons Build Spirit Barrage    
            SBWarning = 2.0f;           // 9.0f...0f Text will take the color yellow when it reaches this value
            ShowGlobes = true;          // Health Globes Counter (floor)
            ShowSoulHarvest = true;     // Show SoulHarvest icon
            ShowBigBadVoodoo = false;   // Show Big Bad Voodoo icon
            ShowSpiritWalk = false;     // Show Spirit Walk icon
            ShowLocust = false;         // Locust Affected Monster Counters (Total \n Elites) at distance = YardsLocustHaunt
            ShowHaunted = false;        // Haunted Affected Monster Counters (Total \n Elites) at distance = YardsLocustHaunt
            YardsLocustHaunt = 40;      // Yards for Monsters Counters (Locust and Haunted)
            /* Crusader */
            ThornsBomb = true;          // Enable Icons Build Thorns Bomb (Invoker set 2 items + belt of the Trove) 
            ValorFotH = true;           // Enable Icons Build Valor - Fist of the Heaven            
            SteedCharge = true;         // Show Steed Charge icon 
            FlailCharge = true;         // Show Flail of the Charge (Bonus 2) icon 
            Akarat = true;              // Show Icon Akarat´s Champion
            
            /* Common */            
            ShowMe = true;              // Show for my character
            ShowOthers = true;          // Show for others character
            ShowNames = true;           // Show players names
            OnlyGR = false;             // Show  in GR only
            Xpor = 0.72f;               //0.72f;// To set the x coordinate of the icon
            Ypor = 0.10f;               //0.10f;// To set the y coordinate of the icon          
            SizeMultiplier = 0.8f;     // Size multiplier for icons
            Opacity = 0.9f;            // 0f..1f  Opacity for icon texture 
            ShowCoe = true;             // Show COE status 
            InactiveRedFrame = false;   // Inactive elements (coe) are shown in red (active in yellow)
            ProgressBarWidth = 2;       // Width progressbar Coe (pixels)
            
            TimeLeftClockBrush = Hud.Render.CreateBrush(220, 0, 0, 0, 0);   
            BrushBlack = Hud.Render.CreateBrush(255, 80, 80, 80, 0);
            BrushGreen = Hud.Render.CreateBrush(255, 0, 255 , 0, 0);
            BrushYellow = Hud.Render.CreateBrush(255, 255, 255 , 0, 0);
            BrushOrange = Hud.Render.CreateBrush(255, 255, 185 , 0, 0);
            BrushBlue = Hud.Render.CreateBrush(255, 50, 150 , 250, 0);  
 
            AllBonusElements = new Dictionary<HeroClass, List<int>> // 1 = Arcane, 2 = Cold, 3 = Fire, 4 = Holy, 5 = Lightning, 6 = Physical, 7 = Poison
            {   
                {   HeroClass.Necromancer,  new List<int>{2,6,7}        },
                {   HeroClass.Barbarian,    new List<int>{2,3,5,6}      },
                {   HeroClass.DemonHunter,  new List<int>{2,3,5,6}      },
                {   HeroClass.Wizard,       new List<int>{1,2,3,5}      },
                {   HeroClass.WitchDoctor,  new List<int>{2,3,6,7}      },
                {   HeroClass.Crusader,     new List<int>{3,4,5,6}      },
                {   HeroClass.Monk,         new List<int>{2,3,4,5,6}    },
            };              
        }
 
        public void Customize()
        {
            var OpacityBrush = (int) (Opacity * 255);   
            BrushRed = Hud.Render.CreateBrush(OpacityBrush, 255, 50 , 50, 0);
            
            FontWhite = Hud.Render.CreateFont("tahoma", 10f * SizeMultiplier, 255, 255, 255, 255, true, false, 255, 0, 0, 0, true);
            FontGray = Hud.Render.CreateFont("tahoma", 10f * SizeMultiplier, 235, 235, 235, 235, true, false, 255, 0, 0, 0, true);
            FontGreen = Hud.Render.CreateFont("tahoma", 13f * SizeMultiplier, 255, 0, 255, 0, true, false, 255, 0, 0, 0, true);                 
            FontYellow = Hud.Render.CreateFont("tahoma", 13f * SizeMultiplier, 255, 255, 255, 0, true, false, 255, 0, 0, 0, true);
            FontOrange = Hud.Render.CreateFont("tahoma", 13f * SizeMultiplier, 255, 255, 150, 0, true, false, 255, 0, 0, 0, true);
            FontBlue = Hud.Render.CreateFont("tahoma", 7f * SizeMultiplier, 255, 50, 150, 250, true, false, 255, 0, 0, 0, true);
            FontNames = Hud.Render.CreateFont("tahoma", 8f * SizeMultiplier, 235, 235, 235, 235, false, false, 255, 0, 0, 0, true);
 
            FontStacks = Hud.Render.CreateFont("tahoma", 10f * SizeMultiplier, 255, 255, 255, 0, true, false, 255, 0, 0, 0, true);
            FontStacksRed = Hud.Render.CreateFont("tahoma", 10f * SizeMultiplier, 255, 255, 0, 0, true, false, 160, 0, 0, 0, true);
            FontTimeLeft = Hud.Render.CreateFont("tahoma", 10f * SizeMultiplier, 255, 0, 255, 0, true, false, 255, 0, 0, 0, true);              
            FontTimeLeft2 = Hud.Render.CreateFont("tahoma", 7f * SizeMultiplier, 255, 0, 255, 0, true, false, 255, 0, 0, 0, true);                          
            
            FontCounter = Hud.Render.CreateFont("tahoma", 8f * SizeMultiplier, 255, 0, 255, 0, true, false, 160, 0, 0, 0, true);
            FontLimit = Hud.Render.CreateFont("tahoma", 8f * SizeMultiplier, 255, 255, 220, 100, true, false, 160, 0, 0, 0, true);
            FontExpl = Hud.Render.CreateFont("tahoma", 9f * SizeMultiplier, 255, 50, 150, 255, true, false, 160, 0, 0, 0, true);    
 
            FontLimit2 = Hud.Render.CreateFont("tahoma", 8f * SizeMultiplier, 255, 255, 100, 50, true, false, 160, 0, 0, 0, true);
            
            FontLocust = Hud.Render.CreateFont("tahoma", 9f * SizeMultiplier, 255, 255, 255, 255, false, false, 255, 0, 0, 0, true);            
 
            FontAS = Hud.Render.CreateFont("tahoma", 6f * SizeMultiplier, 255, 255, 255, 255, false, false, 255, 0, 0, 0, true);
 
            FontFury = Hud.Render.CreateFont("Tahoma", 9f * SizeMultiplier ,  255, 220, 150,255, true, false, 255, 0, 0, 0, true);
            
            SizeIconWidth = Hud.Texture.BuffFrameTexture.Width   * Hud.Window.Size.Height/1200.0f * SizeMultiplier;
            SizeIconHeight = Hud.Texture.BuffFrameTexture.Height * Hud.Window.Size.Height/1200.0f * SizeMultiplier;
            
            if ((SBWarning < 0f) || (SBWarning > 9f)) { SBWarning = 2; }
            if (EssenceLimit < 0 || EssenceLimit > 0.95 ) { EssenceLimit = 0.66f;   }
            
        }
 
        public void OnNewArea(bool newGame, ISnoArea area)
        {   
            if (newGame) Phantasms.Clear();
        }
        
        private void DrawTimeLeftClock(RectangleF rect, double elapsed, double timeLeft)   // plugins\Default\BuffLists\Painter\BuffPainter.cs
        {
            if ((timeLeft > 0) && (elapsed >= 0) && (TimeLeftClockBrush != null))
            {
                var endAngle = Convert.ToInt32(360.0d / (timeLeft + elapsed) * elapsed);
                var startAngle = 0;
                TimeLeftClockBrush.Opacity = 1 - (float)(0.5f / (timeLeft + elapsed) * elapsed);
                var rad = rect.Width * 0.45f;
                using (var pg = Hud.Render.CreateGeometry())
                {
                    using (var gs = pg.Open())
                    {
                        gs.BeginFigure(rect.Center, FigureBegin.Filled);
                        for (var angle = startAngle; angle <= endAngle; angle++)
                        {
                            var mx = rad * (float)Math.Cos((angle - 90) * Math.PI / 180.0f);
                            var my = rad * (float)Math.Sin((angle - 90) * Math.PI / 180.0f);
                            var vec = new Vector2(rect.Center.X + mx, rect.Center.Y + my);
                            gs.AddLine(vec);
                        }
 
                        gs.EndFigure(FigureEnd.Closed);
                        gs.Close();
                    }
 
                    TimeLeftClockBrush.DrawGeometry(pg);
                }
            }
        }
 
        public void DrawIconBuff(float x, float y, float width, float height, uint idtexture, int stacks, double timeleft, double elapsed, double timeleft2 = 0)
        {
            Hud.Texture.GetTexture(idtexture).Draw(x, y, width, height, Opacity);
            Hud.Texture.BuffFrameTexture.Draw(x, y, width, height, Opacity);
            if (timeleft > 0)
            {
                DrawTimeLeftClock(new RectangleF(x, y , width, height), elapsed , timeleft);
                layout = FontTimeLeft.GetTextLayout(timeleft.ToString( (timeleft < 1)? "F1" : "F0") );
                FontTimeLeft.DrawText(layout, x + ((width - (float)Math.Ceiling(layout.Metrics.Width))/6.0f), y + ((height - (float)Math.Ceiling(layout.Metrics.Height))/14.0f) );
                if (timeleft2 > 0)  
                {
                    layout = FontTimeLeft2.GetTextLayout(timeleft2.ToString((timeleft2 < 1)? "F1" : "F0") );
                    FontTimeLeft2.DrawText(layout, x + ((width - (float)Math.Ceiling(layout.Metrics.Width))/5.0f), y + ((height - (float)Math.Ceiling(layout.Metrics.Height))/1.1f) );
                }   
            }
            layout = FontStacks.GetTextLayout( stacks.ToString() );
            (stacks == 0?FontStacksRed:FontStacks).DrawText(layout, x + ((width - (float)Math.Ceiling(layout.Metrics.Width))/1.15f), y + ((height - (float)Math.Ceiling(layout.Metrics.Height))/1.05f) );
        }
        
        public void DrawIconSkill(float x, float y, float width, float height, IPlayerSkill skill, int index = 1)
        {
            Hud.Texture.GetTexture(skill.SnoPower.NormalIconTextureId).Draw(x, y, width, height, Opacity);
            if (skill.Buff != null) // 465839
            {
                Hud.Texture.BuffFrameTexture.Draw(x, y, width, height, Opacity);
                
                double remaining = 0d;      double elapsed = 0d;
                if (skill.CooldownFinishTick > Hud.Game.CurrentGameTick) {
                    remaining = (skill.CooldownFinishTick - Hud.Game.CurrentGameTick) / 60.0d;
                    elapsed = (Hud.Game.CurrentGameTick - skill.CooldownStartTick) / 60.0d;
                    DrawTimeLeftClock(new RectangleF(x, y , width, height), elapsed , remaining);
                    layout = FontWhite.GetTextLayout( remaining.ToString( (remaining < 1)? "F1":"F0" ) );
                }
                else { layout = FontWhite.GetTextLayout("✔"); }
                FontWhite.DrawText(layout, x + ((width - (float)Math.Ceiling(layout.Metrics.Width))/1.40f), y + ((height - (float)Math.Ceiling(layout.Metrics.Height))/1.1f) );
                
                double timeleft = skill.Buff.TimeLeftSeconds[index];        
                if (timeleft > 0)
                {
                    layout = FontTimeLeft.GetTextLayout(timeleft.ToString( (timeleft < 1)? "F1" : "F0") );
                    FontTimeLeft.DrawText(layout, x + ((width - (float)Math.Ceiling(layout.Metrics.Width))/6.0f), y + ((height - (float)Math.Ceiling(layout.Metrics.Height))/14.0f) );  
                }
            }
            else { Hud.Texture.DebuffFrameTexture.Draw(x, y, width, height, Opacity); }
        }
        
        public void PaintTopInGame(ClipState clipState)
        {
            if (clipState != ClipState.BeforeClip) return;
            if (!Hud.Game.IsInGame) return;
            if (OnlyGR && !Hud.Game.Me.InGreaterRift) return;
    
            var players = Hud.Game.Players.Where( p => p.IsMe?ShowMe:(ShowOthers && p.HasValidActor) ).OrderBy(p => p.PortraitIndex);
            if (players.Count() == 0) return;
 
            var y =  Hud.Window.Size.Height * Ypor ;
            foreach(var player in players)
            {
                var x =  Hud.Window.Size.Width * Xpor;
                if (player.HeroClassDefinition.HeroClass == HeroClass.Necromancer)
                {               
                    IPlayerSkill skill = player.Powers.UsedNecromancerPowers.SkeletalMage;  // 462089
                    var build = false;  
 
                    if (BoneSpear && player.Powers.BuffIsActive(484303)) // Bonut 6 set
                    {
                        build = true;                       
                        if (ShowNames) { layout = FontNames.GetTextLayout(player.BattleTagAbovePortrait); FontNames.DrawText(layout,x + 1,y ); y += layout.Metrics.Height + 1; }
                        if (player.Powers.BuffIsActive(478534)) // Dayntee Equipped
                        {
                            Hud.Texture.InventoryLegendaryBackgroundLarge.Draw(x,y,SizeIconWidth,SizeIconHeight,Opacity);
                            Hud.Texture.GetItemTexture(Hud.Sno.SnoItems.P61_Unique_Belt_01).Draw(x,y,SizeIconWidth,SizeIconHeight,Opacity);                         
                            Hud.Texture.BuffFrameTexture.Draw(x, y, SizeIconWidth, SizeIconHeight, Opacity);
                            var n = Hud.Game.AliveMonsters.Where(m => m.Cursed).Count();
                            layout = FontStacks.GetTextLayout(n.ToString());                            
                            ((n > 0)?FontStacks:FontStacksRed).DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/1.20f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/1.05f) );
                            if (player.Powers.BuffIsActive(478534,1))   
                            {
                                layout = FontTimeLeft.GetTextLayout("✔");  // Dayntee Buff
                                FontTimeLeft.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/5f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/14f) );
                            }                           
                            x += SizeIconWidth;
                        }
                    }
                    
                    else if ( Singularity && ((skill != null) && (skill?.Rune == 1 || player.Powers.BuffIsActive(484311))) ) // Singularity
                    {
                        build = true;
                        if (ShowNames) layout = FontNames.GetTextLayout(player.BattleTagAbovePortrait); FontNames.DrawText(layout,x + 1,y ); y += layout.Metrics.Height + 1;                        
                        if (skill.Buff != null)
                        {
                            var stacks = ( (skill.Buff.IconCounts[6] == 1) && (skill.Buff.TimeLeftSeconds[5] == 0) )? 0:skill.Buff.IconCounts[6];
                            if (stacks == 0) 
                            {
                                DrawIconBuff(x,y,SizeIconWidth,SizeIconHeight,skill.SnoPower.NormalIconTextureId,0, 0, 0 );
                            }
                            else 
                            {
                                DrawIconBuff(x,y,SizeIconWidth,SizeIconHeight,skill.SnoPower.NormalIconTextureId,stacks,skill.Buff.TimeLeftSeconds[5],skill.Buff.TimeElapsedSeconds[5],skill.Buff.TimeLeftSeconds[6]);
                            }
                        }
                        else 
                        {
                            Hud.Texture.GetTexture(265393923).Draw(x, y, SizeIconWidth,SizeIconHeight, Opacity); // skill.SnoPower.NormalIconTextureId
                            Hud.Texture.DebuffFrameTexture.Draw(x, y, SizeIconWidth,SizeIconHeight, Opacity);                       
                        }
                        x += SizeIconWidth;
                        if (ShowEssenceMages /*&& player.Powers.BuffIsActive(475247)*/) // Nailuj
                        {
                            Hud.Texture.GetTexture(265393923).Draw(x, y, SizeIconWidth,SizeIconHeight, Opacity); 
                            Hud.Texture.BuffFrameTexture.Draw(x, y, SizeIconWidth,SizeIconHeight, Opacity);
                            
                            var mages = Hud.Game.Actors.Where(a => MagesSno.Contains(a.SnoActor.Sno) && a.SummonerAcdDynamicId == player.SummonerId);
                            if (mages.Any())
                            {
                                double removegem = (player.Powers.BuffIsActive(403466))? 100d/(100 + player.GetAttributeValue(Hud.Sno.Attributes.Item_Power_Passive,403466) * 10d): 1;
                                var c = 1;
                                var resmax = ((player.Powers.UsedNecromancerPowers.Simulacrum == null) || player.Powers.BuffIsActive(465350))? player.Stats.ResourceMaxPri: player.Stats.ResourceMaxPri * 2;
                                foreach (var MagesGroup in mages.GroupBy(a => (int)(a.GetAttributeValue(Hud.Sno.Attributes.Multiplicative_Damage_Percent_Bonus, 1048575) * removegem / 0.03d)).OrderBy(g => g.Key))
                                {
                                    if (MagesGroup.FirstOrDefault().GetAttributeValue(Hud.Sno.Attributes.Multiplicative_Damage_Percent_Bonus, 1048575) == 1) continue;                                                  
                                    FontDefault = (MagesGroup.Key >= resmax - 3)? FontCounter: (MagesGroup.Key < resmax * EssenceLimit)?FontLimit2:FontLimit ;                                  
                                    var layout = FontDefault.GetTextLayout( String.Format("{0,-3} {1,2}",MagesGroup.Key ,MagesGroup.Count()) ); 
                                    FontDefault.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/2.5f), y + (layout.Metrics.Height * 0.91f * (c - 1)) );                                   
                                    if (++c > 3) break;
                                }                               
                            }
                            x += SizeIconWidth; 
                        }           
                    }
                    
                    if (Nayr && player.Powers.BuffIsActive(476587)) // Nayr
                    {
                        if (!build) 
                        { 
                            build = true;
                            if (ShowNames) layout = FontNames.GetTextLayout(player.BattleTagAbovePortrait); FontNames.DrawText(layout,x + 1,y ); y += layout.Metrics.Height + 1; 
                        }
                        var buff = player.Powers.GetBuff(476587);
                        if (buff != null)
                        {
                            var c = buff.IconCounts[7];
                            if (c > 0) 
                            {
                                int j = 7; double timeleft = 0; double timeleft2 = 15;
                                for (var i = 1; i < 7; i++)
                                {
                                    var t = buff.TimeLeftSeconds[i];
                                    if (t > 0) 
                                    {
                                        if (t > timeleft) { j = i; timeleft = t; }
                                        if (t < timeleft2) { timeleft2 = t; }
                                    }
                                }
                                DrawIconBuff(x,y,SizeIconWidth,SizeIconHeight,2831437924, c, buff.TimeLeftSeconds[j], buff.TimeElapsedSeconds[j],(c > 1)?timeleft2:0 );
                            }
                            else { DrawIconBuff(x,y,SizeIconWidth,SizeIconHeight,2831437924, 0, 0, 0); }
                        }
                        x += SizeIconWidth; 
                    }
                    
                    
                    if (build)
                    {
                        skill = player.Powers.UsedNecromancerPowers.LandOfTheDead; // 465839
                        if (skill != null)
                        {
                            DrawIconSkill(x,y,SizeIconWidth,SizeIconHeight,skill, 0);   // index 0
                            x += SizeIconWidth;  
                        }
                        
                        skill = player.Powers.UsedNecromancerPowers.Simulacrum; // 465350
                        if (skill != null)
                        {                   
                            DrawIconSkill(x,y,SizeIconWidth,SizeIconHeight,skill, 1);   // index 1 , para averiguar el timeleft
                            if (player.Powers.BuffIsActive(465350) && player.Powers.BuffIsActive(484309)) 
                            {
                                layout = FontTimeLeft.GetTextLayout("∞");
                                FontTimeLeft.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/6.0f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/14.0f) );
                            }                       
                            x += SizeIconWidth;
                        }
                                                            
                        skill = player.Powers.UsedNecromancerPowers.BoneArmor;  // 466857
                        if (skill != null)  
                        {           
                            if (skill.Buff != null)
                            {
                                DrawIconBuff(x,y,SizeIconWidth,SizeIconHeight,skill.SnoPower.NormalIconTextureId,skill.Buff.IconCounts[0],skill.Buff.TimeLeftSeconds[0], skill.Buff.TimeElapsedSeconds[0] );
                            }
                            else 
                            {
                                Hud.Texture.GetTexture(436563001).Draw(x, y, SizeIconWidth,SizeIconHeight, Opacity);
                                Hud.Texture.DebuffFrameTexture.Draw(x, y, SizeIconWidth,SizeIconHeight, Opacity);                       
                            }
                            x += SizeIconWidth;
                        }
                        
                        if (player.Powers.BuffIsActive(475251)) // Bloodtide Blade
                        {       
                            Hud.Texture.InventoryLegendaryBackgroundLarge.Draw(x,y,SizeIconWidth,SizeIconHeight,Opacity);
                            Hud.Texture.GetItemTexture(Hud.Sno.SnoItems.P65_Unique_Scythe2H_02).Draw(x,y,SizeIconWidth,SizeIconHeight,Opacity);
                            if (Math.Abs(Hud.Game.CurrentGameTick - Ticks0) > 20)
                            {
                                Count0 = Hud.Game.AliveMonsters.Where(m => m.FloorCoordinate.XYDistanceTo(player.FloorCoordinate) <= 25).Count();
                                Ticks0 = Hud.Game.CurrentGameTick;
                            }
                            layout = FontTimeLeft.GetTextLayout( Count0.ToString() );
                            FontStacks.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/2.0f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/2.0f) );                     
                            x += SizeIconWidth;
                        }
                    }
                    else continue;                  
                }
                else if (player.HeroClassDefinition.HeroClass == HeroClass.WitchDoctor)
                {
                    if (!SpiritBarrage) continue;
                    IPlayerSkill skill = player.Powers.UsedWitchDoctorPowers.SpiritBarrage; // 108506
                    if ( (skill != null) && (skill.Rune == 2 || player.Powers.BuffIsActive(484270)))
                    {                       
                        {   // Simple bloque
                            if (ShowNames) { layout = FontNames.GetTextLayout(player.BattleTagAbovePortrait); FontNames.DrawText(layout,x + 1,y ); y += layout.Metrics.Height + 1; }
                            var actors = Hud.Game.Actors.Where(a => a.SnoActor.Sno == ActorSnoEnum._wd_spiritbarragerune_aoe_ghostmodel && (a.SummonerAcdDynamicId == player.SummonerId));
                            Hud.Texture.GetTexture(skill.SnoPower.NormalIconTextureId).Draw(x, y, SizeIconWidth , SizeIconHeight, Opacity); // TextureId 1117784160
                            int total = actors.Count();
                            if (total > 0)
                            {
                                foreach(var a in actors) 
                                { 
                                    if (!Phantasms.ContainsKey(a.AnnId)) { Phantasms[a.AnnId] = a.CreatedAtInGameTick; }
                                }
                                actors = actors.OrderByDescending(a => Phantasms[a.AnnId]);                         
                                Hud.Texture.BuffFrameTexture.Draw(x, y, SizeIconWidth, SizeIconHeight, Opacity);
                                var c = 0;                          
                                foreach (var actor in actors)
                                {
                                    if (++c > 3) break;
                                    var t = (player.Powers.BuffIsActive(484270)?10:5) - (Hud.Game.CurrentGameTick - Phantasms[actor.AnnId]) /  60f;
                                    if (t <= 0)
                                    {
                                        var layout = FontExpl.GetTextLayout("*");                            
                                        FontExpl.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/8.0f), y + (layout.Metrics.Height * 0.68f * (c - 1)) );                          
                                    }
                                    else
                                    {
                                        FontDefault = (t > SBWarning)? FontCounter:FontLimit;
                                        var layout = FontDefault.GetTextLayout( String.Format("{0:0}",(int) (t + 0.90)) ); // Redondeará a X si es menor  a X.10
                                        FontDefault.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/7.0f), y + (layout.Metrics.Height * 0.90f * (c - 1)) );                                                                   
                                    }
                                }                           
                            }               
                            else {  Hud.Texture.BuffFrameTexture.Draw(x, y, SizeIconWidth, SizeIconHeight, Opacity);    }
                            layout = FontStacks.GetTextLayout(total.ToString());
                            (total == 0?FontStacksRed:FontStacks).DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/1.15f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/1.05f) );
                            layout = FontAS.GetTextLayout(player.Offense.AttackSpeed.ToString("F2", CultureInfo.InvariantCulture));
                            FontAS.DrawText(layout,x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/1.24f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/7.0f) );
                            x +=  SizeIconWidth;
                        }
                        if (ShowSoulHarvest) 
                        {
                            skill = player.Powers.UsedWitchDoctorPowers.SoulHarvest; 
                            if (skill != null)  
                            {           
                                if (skill.Buff != null) // 67616
                                {      
                                    DrawIconBuff(x,y,SizeIconWidth,SizeIconHeight,skill.SnoPower.NormalIconTextureId,skill.Buff.IconCounts[0],skill.Buff.TimeLeftSeconds[0],skill.Buff.TimeElapsedSeconds[0] );
                                }
                                else 
                                {
                                    Hud.Texture.GetTexture(skill.SnoPower.NormalIconTextureId).Draw(x, y, SizeIconWidth, SizeIconHeight, Opacity);  // skill.SnoPower.NormalIconTextureId = 2196086897
                                    Hud.Texture.DebuffFrameTexture.Draw(x, y, SizeIconWidth, SizeIconHeight, Opacity);                              
                                }
                                x += SizeIconWidth;
                            }
                        }
                        if (ShowLocust) 
                        {
                            skill = player.Powers.UsedWitchDoctorPowers.LocustSwarm; 
                            if ( (skill != null) || player.Powers.BuffIsActive(423238) )
                            {
                                Hud.Texture.GetTexture(1465459957).Draw(x, y, SizeIconWidth,SizeIconHeight, Opacity);  // skill.SnoPower.NormalIconTextureId = 1465459957
                                Hud.Texture.BuffFrameTexture.Draw(x, y, SizeIconWidth,SizeIconHeight, Opacity);
                                var m = Hud.Game.AliveMonsters.Where(a => a.FloorCoordinate.XYDistanceTo(player.FloorCoordinate) <= YardsLocustHaunt);
                                var mLc = m.Where(a => a.Locust).Count();
                                if (mLc > 0)
                                {
                                    var mc = m.Count();
                                    var e = m.Where(a => (a.Rarity == ActorRarity.Champion || a.Rarity == ActorRarity.Rare || a.Rarity == ActorRarity.Boss) && (a.SummonerAcdDynamicId == 0) );
                                    var ec = e.Count();                                 
                                    if (mc > ec)
                                    {
                                        layout = FontLocust.GetTextLayout( mLc.ToString() + "|" + mc.ToString());
                                        FontLocust.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/2.0f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/6.0f) );
                                    }                                   
                                    if (ec > 0)
                                    {
                                        var eLc = e.Where(a => a.Locust).Count();
                                        layout = FontLocust.GetTextLayout( eLc.ToString() + "|" + ec.ToString());
                                        FontLocust.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/2.0f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/1.20f) );
                                    }
                                }
                                x += SizeIconWidth;                         
                            }
                        }   
                        if (ShowHaunted) 
                        {
                            skill = player.Powers.UsedWitchDoctorPowers.Haunt; 
                            if (skill != null)
                            {
                                Hud.Texture.GetTexture(skill.SnoPower.NormalIconTextureId).Draw(x, y, SizeIconWidth,SizeIconHeight, Opacity);  // skill.SnoPower.NormalIconTextureId = 
                                Hud.Texture.BuffFrameTexture.Draw(x, y, SizeIconWidth,SizeIconHeight, Opacity);
                                var m = Hud.Game.AliveMonsters.Where(a => a.FloorCoordinate.XYDistanceTo(player.FloorCoordinate) <= YardsLocustHaunt);
                                var mHc = m.Where(a => a.Haunted).Count();
                                if (mHc > 0)
                                {
                                    var mc = m.Count();
                                    var e = m.Where(a => (a.Rarity == ActorRarity.Champion || a.Rarity == ActorRarity.Rare || a.Rarity == ActorRarity.Boss) && (a.SummonerAcdDynamicId == 0) );
                                    var ec = e.Count();                                 
                                    if (mc > ec)
                                    {
                                        layout = FontLocust.GetTextLayout( mHc.ToString() + "|" + mc.ToString());
                                        FontLocust.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/2.0f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/6.0f) );
                                    }                                   
                                    if (ec > 0)
                                    {
                                        var eHc = e.Where(a => a.Haunted).Count();
                                        layout = FontLocust.GetTextLayout( eHc.ToString() + "|" + ec.ToString());
                                        FontLocust.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/2.0f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/1.20f) );
                                    }
                                }
                                x += SizeIconWidth;                         
                            }
                        }                       
                        if (ShowBigBadVoodoo) 
                        {
                            skill = player.Powers.UsedWitchDoctorPowers.BigBadVoodoo;   
                            if (skill != null)
                            {                   
                                DrawIconSkill(x,y,SizeIconWidth,SizeIconHeight,skill, 4);   // index 4 , para averiguar el timeleft                 
                                x += SizeIconWidth;
                            }
                        }
                        if (ShowSpiritWalk) // 106237
                        {
                            skill = player.Powers.UsedWitchDoctorPowers.SpiritWalk; 
                            if (skill != null)
                            {                   
                                DrawIconSkill(x,y,SizeIconWidth,SizeIconHeight,skill, 0);   // index,  para averiguar el timeleft                   
                                x += SizeIconWidth;
                            }
                        }                       
                        skill = player.Powers.UsedWitchDoctorPowers.Sacrifice;  // 102572 - Sacrifice
                        if ( (skill != null) && (skill.Rune == 0) )
                        {
                            if (skill.Buff != null) 
                            {      
                                DrawIconBuff(x,y,SizeIconWidth,SizeIconHeight,skill.SnoPower.NormalIconTextureId,skill.Buff.IconCounts[0],skill.Buff.TimeLeftSeconds[0],skill.Buff.TimeElapsedSeconds[0] );
                            }
                            else 
                            {
                                Hud.Texture.GetTexture(skill.SnoPower.NormalIconTextureId).Draw(x, y, SizeIconWidth, SizeIconHeight, Opacity);  // skill.SnoPower.NormalIconTextureId = 
                                Hud.Texture.DebuffFrameTexture.Draw(x, y, SizeIconWidth, SizeIconHeight, Opacity);                              
                            }
                            var n = Hud.Game.Actors.Where(a => ZombieDogSno.Contains(a.SnoActor.Sno) && (a.SummonerAcdDynamicId == player.SummonerId)).Count();
                            if (n > 0)
                            {
                                layout = FontWhite.GetTextLayout(n.ToString()); 
                                FontWhite.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/7.0f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/1.05f) );
                            }                           
                            x += SizeIconWidth;                         
                        }                                               
                        if (player.Powers.UsedPassives.Any(p => p.Sno == Hud.Sno.SnoPowers.WitchDoctor_Passive_GruesomeFeast.Sno)) // 208594
                        {
                            IBuff buff = player.Powers.GetBuff(208594);
                            if (buff != null)  // Hud.Sno.SnoPowers.WitchDoctor_Passive_GruesomeFeast.NormalIconTextureId  = 1591242582
                            {               
                                DrawIconBuff(x,y,SizeIconWidth,SizeIconHeight,1591242582,buff.IconCounts[1],buff.TimeLeftSeconds[1],buff.TimeElapsedSeconds[1] );   
                            }
                            else 
                            {
                                Hud.Texture.GetTexture(1591242582).Draw(x, y, SizeIconWidth, SizeIconHeight, Opacity);
                                Hud.Texture.DebuffFrameTexture.Draw(x, y, SizeIconWidth, SizeIconHeight, Opacity);                                  
                            }
                            x +=  SizeIconWidth;        
                            if (ShowGlobes)
                            {
                                var n = Hud.Game.Actors.Where(a => a.SnoActor.Kind == ActorKind.HealthGlobe).Count();
                                if (n > 0)
                                {
                                    layout = FontWhite.GetTextLayout(n.ToString());
                                    var w = (n < 10)? layout.Metrics.Width + 1:(layout.Metrics.Width/2 + 2);
                                    BrushRed.DrawEllipse(x + SizeIconWidth / 2 , y + SizeIconHeight / 2 , w , w );
                                    FontWhite.DrawText(layout,x + (SizeIconWidth - layout.Metrics.Width) / 2 , y + (SizeIconHeight - layout.Metrics.Height) / 2 - 1 );
                                }
                            }
                        }
                    }
                    else continue;                  
                }
                else if (player.HeroClassDefinition.HeroClass == HeroClass.Crusader)
                {
                    if (ThornsBomb && player.Powers.BuffIsActive(445829) && player.Powers.BuffIsActive(423235))
                    {
                        if (ShowNames) { layout = FontNames.GetTextLayout(player.BattleTagAbovePortrait); FontNames.DrawText(layout,x + 1,y ); y += layout.Metrics.Height + 1; }
                        IBuff buff = player.Powers.GetBuff(445829);
                        if (buff != null)
                        {
                            DrawIconBuff(x,y,SizeIconWidth,SizeIconHeight,2503653692,buff.IconCounts[1],buff.TimeLeftSeconds[1],buff.TimeElapsedSeconds[1] );
                        }
                        x += SizeIconWidth; 
                    }
                    else if (ValorFotH && player.Powers.BuffIsActive(483655))
                    {
                        if (ShowNames) { layout = FontNames.GetTextLayout(player.BattleTagAbovePortrait); FontNames.DrawText(layout,x + 1,y ); y += layout.Metrics.Height + 1; }
                        IBuff buff = player.Powers.GetBuff(483655);
                        if (buff != null)
                        {
                            DrawIconBuff(x,y,SizeIconWidth,SizeIconHeight,3114805186,buff.IconCounts[1],buff.TimeLeftSeconds[1],buff.TimeElapsedSeconds[1] );                       
                            if (player.Powers.UsedCrusaderPowers.HeavensFury != null && (player.Powers.GetBuff(483643) != null))
                            {
                                layout = FontFury.GetTextLayout(player.Powers.GetBuff(483643).IconCounts[1].ToString());
                                FontFury.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/6.0f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/1.11f) );
                            }
                        }
                        x += SizeIconWidth;
                    }
                    else continue;
                    IPlayerSkill skill = player.Powers.UsedCrusaderPowers.SteedCharge; // 243853
                    if (skill != null)
                    {                   
                        if (SteedCharge) 
                        {
                            DrawIconSkill(x,y,SizeIconWidth,SizeIconHeight,skill, 0);
                            x += SizeIconWidth;
                        }                       
                        if (FlailCharge && player.Powers.BuffIsActive(447291))
                        {
                            IBuff buff = player.Powers.GetBuff(447291);
                            if (buff != null)
                            {
                                Hud.Texture.InventorySetBackgroundLarge.Draw(x, y, SizeIconWidth, SizeIconHeight, Opacity);
                                Hud.Texture.GetItemTexture(Hud.Sno.SnoItems.P4_Unique_Flail_2H_Set_01_x1).Draw(x + SizeIconWidth/6, y, SizeIconWidth * 0.55f, SizeIconHeight, Opacity);
                                Hud.Texture.BuffFrameTexture.Draw(x, y, SizeIconWidth, SizeIconHeight, Opacity);
                                var timeleft = buff.TimeLeftSeconds[1]; var stacks = (buff.IconCounts[1] == 1 || skill.Buff?.IconCounts[0] == 1)?400:0;
                                if (timeleft > 0)
                                {
                                    layout = FontTimeLeft.GetTextLayout(timeleft.ToString( (timeleft < 1)? "F1" : "F0") );
                                    FontTimeLeft.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/6.0f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/14.0f) );
                                }
                                layout = FontStacks.GetTextLayout( stacks.ToString());
                                (stacks == 0?FontStacksRed:FontStacks).DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/1.25f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/1.05f) );
                            }
                            x += SizeIconWidth;
                        }                   
                    }
                    if (Akarat)
                    {
                        skill = player.Powers.UsedCrusaderPowers.AkaratsChampion; // 269032
                        if (skill != null)
                        {
                            DrawIconSkill(x,y,SizeIconWidth,SizeIconHeight,skill, 1);   // index 1,  para averiguar el timeleft
                            x += SizeIconWidth;                     
                        }
                    }                   
                }               
                else continue;
                
                x =  Hud.Window.Size.Width * Xpor;  y +=  SizeIconHeight;           
                if (ShowCoe && (player.Powers.GetBuff(Hud.Sno.SnoPowers.ConventionOfElements.Sno) != null) ) // 430674
                {               
                    var BuffCoE = player.Powers.GetBuff(430674);
                    var HeroBonusElements = AllBonusElements[player.HeroClassDefinition.HeroClass];
                    var j = HeroBonusElements.Count;    var ActiveElement = -1; var BestElement = -1;  double MaxBonus = -1;    bool UniqueBestElement = false;
                    for(var k = j - 1; k > -1 ; k--)
                    {
                        var index = HeroBonusElements[k];
                        if (BuffCoE.IconCounts[index] > 0)  {   ActiveElement = index;  }
                        
                        var bonus = player.Offense.ElementalDamageBonus[IndexToBonus[index]];
                        if (bonus > MaxBonus) 
                        {
                            MaxBonus = bonus; 
                            BestElement = index;
                            UniqueBestElement = true;
                        }   
                        else if (bonus == MaxBonus) UniqueBestElement = false;              
                    }               
                    if ((ActiveElement != -1) && (BestElement != -1) )
                    {                       
                        for (var l = 0; l < j; l++)
                        {
                            if (HeroBonusElements[j - 1] != BestElement)
                            {
                                HeroBonusElements.Insert(0,HeroBonusElements[j - 1]);
                                HeroBonusElements.RemoveAt(j);
                            }
                            else  {   break;  }
                        } 
                        y += ProgressBarWidth;
                        foreach(var index in HeroBonusElements) 
                        {               
                            Hud.Texture.GetTexture(BuffCoE.SnoPower.Icons[index].TextureId).Draw(x, y, SizeIconWidth, SizeIconHeight, Opacity);
                            DrawTimeLeftClock(new RectangleF(x, y , SizeIconWidth, SizeIconHeight), BuffCoE.TimeElapsedSeconds[index], BuffCoE.TimeLeftSeconds[index]);             
                            
                            double s = 0;                       
                            if (UniqueBestElement)
                            {
                                if (index == ActiveElement)
                                {
                                    s = BuffCoE.TimeLeftSeconds[index];
                                    if (index == BestElement) { FontDefault = FontGreen; BrushDefault = BrushGreen; }
                                    else { FontDefault = FontGray; }
                                    Hud.Texture.BuffFrameTexture.Draw(x, y, SizeIconWidth, SizeIconHeight, Opacity);
                                }
                                else
                                {           
                                    if (index == BestElement)
                                    {
                                        s = (j - HeroBonusElements.IndexOf(ActiveElement) - 1) * 4 - BuffCoE.TimeElapsedSeconds[ActiveElement] ;            
                                        if (  s >  ((j - 1) * 2) ) { FontDefault = FontOrange;  BrushDefault = BrushOrange; }
                                        else { FontDefault = FontYellow; BrushDefault = BrushYellow; }
                                    }
                                    (InactiveRedFrame?Hud.Texture.DebuffFrameTexture:Hud.Texture.BuffFrameTexture).Draw(x, y, SizeIconWidth, SizeIconHeight, Opacity);
                                }
                            }
                            else
                            {
                                if (player.Offense.ElementalDamageBonus[IndexToBonus[index]] == player.Offense.HighestElementalDamageBonus) 
                                {
                                    layout = FontBlue.GetTextLayout( (player.Offense.HighestElementalDamageBonus * 100).ToString() );
                                    FontBlue.DrawText(layout, x + (SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/1.15f , y + (SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/1.07f );
                                }
                                s = BuffCoE.TimeLeftSeconds[index];
                                BrushDefault = BrushBlue;   FontDefault = FontWhite;
                                Hud.Texture.BuffFrameTexture.Draw(x, y, SizeIconWidth, SizeIconHeight, Opacity);
                            }
 
                            if (s > 0) 
                            {
                                //layout = FontDefault.GetTextLayout(s.ToString( (s < 1)? "F1" : "F0") );
                                layout = FontDefault.GetTextLayout( (s < 1)? s.ToString("F1") : String.Format("{0:0}",(int) (s + 0.80)) ); // Redondeará a X si es menor  a X.20
                                FontDefault.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/2.0f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/2.0f));
                            }   
                            x += SizeIconWidth;                     
                        }
                        BrushBlack.DrawRectangle(x , y, - SizeIconWidth * j , - ProgressBarWidth);
                        var t = (float) ( SizeIconWidth * (j - HeroBonusElements.IndexOf(ActiveElement) - BuffCoE.TimeElapsedSeconds[ActiveElement] / 4) );
                        if (t > 0) BrushDefault.DrawRectangle(x, y, - t , - ProgressBarWidth);
                        y =  y + SizeIconHeight;
                    }                   
                }
                y += SizeIconHeight * (ShowNames?0.1f:0.4f);
            }
        }
    }
}