Advertisement
s4000

DAV_Extend_FuncPlugin

May 29th, 2020
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.85 KB | None | 0 0
  1. using SharpDX;
  2. using SharpDX.Direct2D1;
  3. using SharpDX.DirectWrite;
  4. using System;
  5. using System.Linq;
  6. using System.Collections.Generic;
  7. using System.Text.RegularExpressions;
  8. using Turbo.Plugins.Default;
  9.  
  10. namespace Turbo.Plugins.DAV
  11. {
  12.     public static class DAV_ExtendFunc {
  13.         public static IController Hud { get; private set; }
  14.         public static int arcIncrement { get; set; } = 6;
  15.         private static double toRad { get; set; } = Math.PI / 180d;
  16.  
  17.     // ITexture variable
  18.         public static ITexture[] ElementIcon { get; private set; }
  19.         public static ITexture[] ElementIconBar { get; private set; }
  20.  
  21.     // Initial Setting
  22.         public static void Init(IController hud) {
  23.             Hud = hud;
  24.  
  25.             ElementIcon = new ITexture[7] {
  26.                 Hud.Texture.GetTexture(928374825), // Physical
  27.                 Hud.Texture.GetTexture(4122635698), // Fire
  28.                 Hud.Texture.GetTexture(569405584), // Lightning
  29.                 Hud.Texture.GetTexture(1541236666), // Cold
  30.                 Hud.Texture.GetTexture(3513867492), // Poison
  31.                 Hud.Texture.GetTexture(3405442230), // Arcane
  32.                 Hud.Texture.GetTexture(2639019912), // Holy
  33.             };
  34.  
  35.             ElementIconBar = new ITexture[7] {
  36.                 Hud.Texture.GetTexture(683458403), // Physical      Barb
  37.                 Hud.Texture.GetTexture(3778595852), // Fire         DH
  38.                 Hud.Texture.GetTexture(3627085962), // Lightning    Monk
  39.                 Hud.Texture.GetTexture(1676312247), // Cold         Necro
  40.                 Hud.Texture.GetTexture(710378302), // Poison        WD
  41.                 Hud.Texture.GetTexture(126669904), // Arcane        Wiz
  42.                 Hud.Texture.GetTexture(3778674082), // Holy         Sader
  43.             };
  44.         }
  45.  
  46.     // ITexture Extends
  47.         public static void DrawMiniMap(this ITexture iconTexture, float x, float y, float w, float h, float opacityMultiplier = 1f) {
  48.             Hud.Render.GetMinimapCoordinates(x, y, out var mapX, out var mapY);
  49.             iconTexture.Draw(mapX - w / 2f, mapY - h / 2f, w, h, opacityMultiplier);
  50.         }
  51.  
  52.         public static void DrawElement(this ITextureController IconController, float x, float y, float w, float h, int eleType, bool isCOErank = false) {
  53.             if (isCOErank) { // 1 ~ 7
  54.                 switch (eleType) {
  55.                     case 1 : ElementIcon[5].Draw(x, y, w, h); return;
  56.                     case 2 : ElementIcon[3].Draw(x, y, w, h); return;
  57.                     case 3 : ElementIcon[1].Draw(x, y, w, h); return;
  58.                     case 4 : ElementIcon[6].Draw(x, y, w, h); return;
  59.                     case 5 : ElementIcon[2].Draw(x, y, w, h); return;
  60.                     case 6 : ElementIcon[0].Draw(x, y, w, h); return;
  61.                     case 7 : ElementIcon[4].Draw(x, y, w, h); return;
  62.                 }
  63.             }
  64.             // 0 ~ 6
  65.             ElementIcon[eleType].Draw(x, y, w, h);
  66.         }
  67.  
  68.         public static void DrawElementBar(this ITextureController IconController, float x, float y, float w, float h, int eleType, bool isCOErank = false) {
  69.             if (isCOErank) { // 1 ~ 7
  70.                 switch (eleType) {
  71.                     case 1 : ElementIconBar[5].Draw(x, y, w, h); return;
  72.                     case 2 : ElementIconBar[3].Draw(x, y, w, h); return;
  73.                     case 3 : ElementIconBar[1].Draw(x, y, w, h); return;
  74.                     case 4 : ElementIconBar[6].Draw(x, y, w, h); return;
  75.                     case 5 : ElementIconBar[2].Draw(x, y, w, h); return;
  76.                     case 6 : ElementIconBar[0].Draw(x, y, w, h); return;
  77.                     case 7 : ElementIconBar[4].Draw(x, y, w, h); return;
  78.                 }
  79.             }
  80.             // 0 ~ 6
  81.             ElementIconBar[eleType].Draw(x, y, w, h);
  82.         }
  83.  
  84.     // IFont Extends
  85.         public static void DrawIconText(this IFont textFonnt, string text, float x, float y, float w, float h, int position, int correctionX = 2, int correctionY = 2) {
  86.             var textLayout = textFonnt.GetTextLayout(text);
  87.             var xref = 0f;
  88.             var yref = 0f;
  89.             switch (position % 3) {
  90.                 case 0 : xref = x + correctionX; break;
  91.                 case 1 : xref = x + (w - textLayout.Metrics.Width) / 2f; break;
  92.                 case 2 :
  93.                 default: xref = x +  w - textLayout.Metrics.Width - correctionX; break;
  94.             }
  95.  
  96.             switch (position / 3) {
  97.                 case 0 : yref = y + correctionY; break;
  98.                 case 1 : yref = y + (h - textLayout.Metrics.Height) / 2f; break;
  99.                 case 2 :
  100.                 default: yref = y +  h - textLayout.Metrics.Height - correctionY; break;
  101.             }
  102.  
  103.             textFonnt.DrawText(textLayout, xref, yref);
  104.         }
  105.  
  106.     // IBrush Extends
  107.         public static void SetArcIncrement(int arcDiff) { arcIncrement = arcDiff; }
  108.  
  109.         public static void DrawWorldLineFromMe(this IBrush cBrush, IWorldCoordinate worldCoord, float strokeWidthCorrection = 0) {
  110.             cBrush?.DrawLineWorld(Hud.Game.Me.FloorCoordinate, worldCoord, strokeWidthCorrection);
  111.         }
  112.  
  113.         public static void DrawWorldArc(this IBrush cBrush, IWorldCoordinate worldCoord, float radius, int Angle_Start, int Angle_End, float ArcCorrection = 1f) {
  114.             if (cBrush == null || Angle_Start >= Angle_End) return;
  115.             if (!worldCoord.IsOnScreen()) return;
  116.  
  117.             var AdjustArc = (int)Math.Ceiling(arcIncrement * ArcCorrection * (Angle_End - Angle_Start)) / arcIncrement + Angle_Start;
  118.             using (var pg = Hud.Render.CreateGeometry()) {
  119.                 using (var gs = pg.Open()) {
  120.                     var mx = radius * (float)Math.Cos(Angle_Start * toRad);
  121.                     var my = radius * (float)Math.Sin(Angle_Start * toRad);
  122.                     var screenCoord = worldCoord.Offset(mx, my, 0).ToScreenCoordinate(true);
  123.                     var vector = new Vector2(screenCoord.X, screenCoord.Y);
  124.                     gs.BeginFigure(vector, FigureBegin.Filled); // FigureBegin.Filled , FigureBegin.Hollow
  125.  
  126.                     for (var angle = Angle_Start + arcIncrement; angle <= AdjustArc; angle += arcIncrement) {
  127.                         mx = radius * (float)Math.Cos(angle * toRad);
  128.                         my = radius * (float)Math.Sin(angle * toRad);
  129.                         screenCoord = worldCoord.Offset(mx, my, 0).ToScreenCoordinate(true);
  130.                         vector = new Vector2(screenCoord.X, screenCoord.Y);
  131.                         gs.AddLine(vector);
  132.                     }
  133.  
  134.                     gs.EndFigure(FigureEnd.Open);
  135.                     gs.Close();
  136.                 }
  137.  
  138.                 cBrush.DrawGeometry(pg);
  139.             }
  140.         }
  141.  
  142.         public static void DrawClockRectangle(this IBrush timeBrush, float x, float y, float w, float h, double timeTotal, double timeLeft) {
  143.             if (timeBrush == null || timeLeft <= 0) return;
  144.             if (timeTotal <= timeLeft) {
  145.                 timeBrush.DrawRectangle(x, y, w, h);
  146.                 return;
  147.             }
  148.  
  149.             var endAngle = (int)Math.Ceiling(360d * timeLeft / timeTotal) - 90;
  150.             var rotAngle = (w == h) ? 45 : (int)(Math.Atan2(w, h) / toRad);
  151.             var mx = (float)Math.Cos(endAngle * toRad) * w;
  152.             var my = (float)Math.Sin(endAngle * toRad) * h;
  153.             using (var pg = Hud.Render.CreateGeometry()) {
  154.                 using (var gs = pg.Open()) {
  155.                     var vector = new Vector2(x + 0.5f * w, y + 0.5f * h); gs.BeginFigure(vector, FigureBegin.Filled);
  156.                     vector = new Vector2(x + 0.5f * w, y); gs.AddLine(vector);
  157.  
  158.                     if (endAngle <= -rotAngle) {
  159.                         vector = new Vector2(x + 0.5f * w * (1 + mx / my), y); gs.AddLine(vector);
  160.                     }
  161.                     else if (endAngle <= rotAngle) {
  162.                         vector = new Vector2(x, y); gs.AddLine(vector);
  163.  
  164.                         vector = new Vector2(x, y + 0.5f * h * (1 + my / mx)); gs.AddLine(vector);
  165.                     }
  166.                     else if (endAngle <= 180 - rotAngle) {
  167.                         vector = new Vector2(x, y); gs.AddLine(vector);
  168.                         vector = new Vector2(x, y + h); gs.AddLine(vector);
  169.  
  170.                         vector = new Vector2(x + 0.5f * w * (1 - mx / my), y + h); gs.AddLine(vector);
  171.                     }
  172.                     else if (endAngle <= 180 + rotAngle) {
  173.                         vector = new Vector2(x, y); gs.AddLine(vector);
  174.                         vector = new Vector2(x, y + h); gs.AddLine(vector);
  175.                         vector = new Vector2(x + w, y + h); gs.AddLine(vector);
  176.  
  177.                         vector = new Vector2(x + w, y + 0.5f * h * (1 - my / mx)); gs.AddLine(vector);
  178.                     }
  179.                     else {
  180.                         vector = new Vector2(x, y); gs.AddLine(vector);
  181.                         vector = new Vector2(x, y + h); gs.AddLine(vector);
  182.                         vector = new Vector2(x + w, y + h); gs.AddLine(vector);
  183.                         vector = new Vector2(x + w, y); gs.AddLine(vector);
  184.  
  185.                         vector = new Vector2(x + 0.5f * w * (1 + mx / my), y); gs.AddLine(vector);
  186.                     }
  187.  
  188.                     gs.EndFigure(FigureEnd.Closed);
  189.                     gs.Close();
  190.                 }
  191.                 timeBrush.DrawGeometry(pg);
  192.             }
  193.         }
  194.     }
  195.  
  196.     public class DAV_Extend_FuncPlugin : BasePlugin {
  197.  
  198.         public DAV_Extend_FuncPlugin() {
  199.             Enabled = true;
  200.         }
  201.  
  202.         public override void Load(IController hud) {
  203.             base.Load(hud);
  204.  
  205.             DAV_ExtendFunc.Init(hud);
  206.             Enabled = false;
  207.         }
  208.     }
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement