Advertisement
zerenx

THUD_BuffSideBarPlugin.cs

Jan 19th, 2017
841
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.17 KB | None | 0 0
  1. namespace Turbo.Plugins.ZX
  2. {
  3.     using System.Collections.Generic;
  4.     using Turbo.Plugins.Default;
  5.  
  6.     public class BuffSideBarPlugin : BasePlugin, ICustomizer, IInGameTopPainter
  7.     {
  8.         public class IBuffBarsList
  9.         {
  10.             public string Shorthand, Description;
  11.             public uint SNO;
  12.             public int IconIndex;
  13.             public HeroClass OnlyHeroClass;
  14.             public IBuffBarsList(string inpShorthand, string inpDescription, uint inpSNO, int inpIconIndex)
  15.             {
  16.                 this.Shorthand = inpShorthand;
  17.                 this.Description = inpDescription;
  18.                 this.SNO = inpSNO;
  19.                 this.IconIndex = inpIconIndex;
  20.                 this.OnlyHeroClass = HeroClass.None;
  21.             }
  22.             public IBuffBarsList(string inpShorthand, string inpDescription, uint inpSNO, int inpIconIndex, HeroClass inpHeroclass)
  23.             {
  24.                 this.Shorthand = inpShorthand;
  25.                 this.Description = inpDescription;
  26.                 this.SNO = inpSNO;
  27.                 this.IconIndex = inpIconIndex;
  28.                 this.OnlyHeroClass = inpHeroclass;
  29.             }
  30.         }
  31.  
  32.         public List<IBuffBarsList> BuffBarsList { get; set; }
  33.  
  34.         public TopLabelDecorator BuffBar_Active_Label { get; set; }
  35.         public TopLabelDecorator BuffBar_Inactive_Label { get; set; }
  36.  
  37.         public float barW, barH, barX, barY;
  38.  
  39.         public bool ShowAsVertical, HorizontalShowCentered;
  40.         public int LastBuffsDiplayedCount;
  41.  
  42.         private ITexture buttonTextureGray, buttonTextureBlue, buttonTextureOrange;
  43.         private ITexture bgTextureOrange, bgTextureGreen, bgTextureYellow, bgTextureBlue;
  44.  
  45.         public BuffSideBarPlugin()
  46.         {
  47.             // Inits
  48.             Enabled = true;
  49.             BuffBarsList = new List<IBuffBarsList>();
  50.             LastBuffsDiplayedCount = 0;
  51.             ShowAsVertical = true;
  52.             HorizontalShowCentered = true;
  53.         }
  54.  
  55.         public override void Load(IController hud)
  56.         {
  57.             base.Load(hud);
  58.  
  59.             BuffBar_Active_Label = new TopLabelDecorator(Hud)
  60.             {
  61.                 TextFont = Hud.Render.CreateFont("tahoma", 7, 120, 255, 240, 0, true, false, false),
  62.                 BackgroundTexture1 = Hud.Texture.ButtonTextureOrange,
  63.                 BackgroundTexture2 = Hud.Texture.BackgroundTextureOrange,
  64.                 BackgroundTextureOpacity2 = 0.5f
  65.             };
  66.             BuffBar_Inactive_Label = new TopLabelDecorator(Hud)
  67.             {
  68.                 TextFont = Hud.Render.CreateFont("tahoma", 7, 100, 192, 192, 192, false, false, false),
  69.                 BackgroundTexture1 = Hud.Texture.ButtonTextureGray,
  70.                 BackgroundTexture2 = Hud.Texture.BackgroundTextureOrange,
  71.                 BackgroundTextureOpacity2 = 0.5f
  72.             };
  73.         }
  74.  
  75.         public void Customize()
  76.         {
  77.             ShowAsVertical = true;
  78.             HorizontalShowCentered = true;
  79.  
  80.             // Unlike the old XML system where it draws x,y,w,h in terms of percentage of screen size, the new plugin uses actual pixel coordinates
  81.             // To convert x,y,w,h sizes from the XML system to the new plugin system, multiply the screensize with percentage. ie. XML size of 2 => 0.02f * screensize
  82.             // Below is equivalent to x=98, y=40, w=2, h=2 in old XML system
  83.             barW = Hud.Window.Size.Width * 0.02f;
  84.             barH = Hud.Window.Size.Height * 0.02f;
  85.  
  86.             if (ShowAsVertical)
  87.             {
  88.                 // Vertical alignment
  89.                 barX = Hud.Window.Size.Width - barW;
  90.                 barY = Hud.Window.Size.Height * 0.4f;
  91.             }
  92.             else
  93.             {
  94.                 // Horizontal alignment
  95.                 // If not-centered these are the starting X for the first buff, if centered it is where the point of the center is
  96.                 barX = Hud.Window.Size.Width / 2;
  97.                 barY = Hud.Window.Size.Height * 0.52f;
  98.             }
  99.  
  100.             // Add the list of buff bars
  101.             // BuffBarsList.Clear();
  102.             BuffBarsList.Add(new IBuffBarsList("NB", "Nemesis Bracers", 318820, -1));
  103.             BuffBarsList.Add(new IBuffBarsList("GW", "Goldwrap", 318875, 1));
  104.             BuffBarsList.Add(new IBuffBarsList("OR", "Oculus Ring", 402461, 2));
  105.             //BuffBarsList.Add(new IBuffBarsList("CE", "Convention of Elements", 430674, 5)); //1 Arcane, 2 Cold, 3 Fire, 4 Holy, 5 Lightning, 6 Physical, 7 Poison
  106.             //BuffBarsList.Add(new IBuffBarsList("BP", "Broken Promises", 402462, 2));
  107.  
  108.             BuffBarsList.Add(new IBuffBarsList("IS", "Inner Sanctuary", 317076, -1, HeroClass.Monk));
  109.             BuffBarsList.Add(new IBuffBarsList("FD", "Flying Dragon", 246562, 1, HeroClass.Monk));
  110.             BuffBarsList.Add(new IBuffBarsList("SM", "Swiftmount", 359537, -1, HeroClass.Monk));
  111.             BuffBarsList.Add(new IBuffBarsList("MS", "Mantra of Salvation", 375050, 1, HeroClass.Monk));
  112.  
  113.             BuffBarsList.Add(new IBuffBarsList("CS", "Command Skeleton", 453801, -1, HeroClass.Necromancer));
  114.             BuffBarsList.Add(new IBuffBarsList("DB", "Dayntee Binding DR", 476689, 1, HeroClass.Necromancer));
  115.  
  116.             /*
  117.             HeroClass.
  118.               DemonHunter 0
  119.               Barbarian 1
  120.               Wizard 2
  121.               WitchDoctor 3
  122.               Monk 4
  123.               Crusader 5
  124.               Necromancer 6
  125.               None
  126.             */
  127.         }
  128.         public void PaintTopInGame(ClipState clipState)
  129.         {
  130.             if (clipState != ClipState.BeforeClip) return;
  131.  
  132.             // Inits
  133.             TopLabelDecorator BuffBarLabel;
  134.             var loopCtr = 0;
  135.  
  136.             // Determine starting X coordinate for horizontal alignment
  137.             var h_barX = (!ShowAsVertical && HorizontalShowCentered) ? barX - (LastBuffsDiplayedCount * barW / 2) : barX;
  138.  
  139.             // Iterate the BuffBarList
  140.             foreach (var ctrBuffBar in BuffBarsList)
  141.             {
  142.                 // If the buff in the list is not for all class AND not for current specific heroclass, skip drawing it                
  143.                 if (ctrBuffBar.OnlyHeroClass == HeroClass.None || ctrBuffBar.OnlyHeroClass == Hud.Game.Me.Hero.ClassDefinition.HeroClass)
  144.                 {
  145.                     // Check if this specific buff is currently active or not, and use the correct Label type
  146.                     BuffBarLabel = (Hud.Game.Me.Powers.BuffIsActive(ctrBuffBar.SNO, ctrBuffBar.IconIndex)) ? BuffBar_Active_Label : BuffBar_Inactive_Label;
  147.  
  148.                     // Text of the labels
  149.                     BuffBarLabel.TextFunc = () => ctrBuffBar.Shorthand;
  150.                     BuffBarLabel.HintFunc = () => ctrBuffBar.Description;
  151.  
  152.                     // Draw the label
  153.                     if (ShowAsVertical)
  154.                     { BuffBarLabel.Paint(barX, barY + (loopCtr * barH), barW, barH, HorizontalAlign.Center); }
  155.                     else
  156.                     { BuffBarLabel.Paint(h_barX + (loopCtr * barW), barY, barW, barH, HorizontalAlign.Center); }
  157.  
  158.                     loopCtr++;
  159.                 }
  160.             }
  161.             LastBuffsDiplayedCount = loopCtr;
  162.         } // endfunc PaintTopInGame
  163.     }
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement