Advertisement
Guest User

CustomGroundShapeDecorator.cs

a guest
May 11th, 2017
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.21 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using Turbo.Plugins.Default;
  3. using System;
  4.  
  5. namespace Turbo.Plugins.gz
  6. {
  7.     public enum CustomGroundShape { NStar }
  8.  
  9.     // this is not a plugin, just a helper class to display labels on the ground
  10.     public class CustomGroundShapeDecorator : IWorldDecoratorWithRadius
  11.     {
  12.        
  13.         public bool Enabled { get; set; }
  14.         public WorldLayer Layer { get; private set; }
  15.         public IController Hud { get; private set; }
  16.  
  17.         public IBrush Brush { get; set; }
  18.         public CustomGroundShape Shape { get; set; }
  19.         public bool HasShadow { get; set; }
  20.         private IBrush _shadowBrush;
  21.  
  22.         public float Radius { get; set; }
  23.         public IRadiusTransformator RadiusTransformator { get; set; }
  24.         //new
  25.         public int Vertices { get; set; }
  26.         public int SkipVertices { get; set; }
  27.         public float Angle { get; set; }
  28.         public bool Rotation { get; set; }
  29.         public int RotationSpeed { get; set; }
  30.  
  31.         public CustomGroundShapeDecorator(IController hud)
  32.         {
  33.             Enabled = true;
  34.             Layer = WorldLayer.Ground;
  35.             Hud = hud;
  36.  
  37.             _shadowBrush = Hud.Render.CreateBrush(96, 0, 0, 0, 1);
  38.             Shape = CustomGroundShape.NStar;
  39.             HasShadow = true;
  40.  
  41.             //new
  42.             SkipVertices = 1;
  43.             Rotation = false;
  44.             RotationSpeed = 30;
  45.         }
  46.  
  47.         public void Paint(IActor actor, IWorldCoordinate coord, string text)
  48.         {
  49.             if (!Enabled) return;
  50.             if (Brush == null) return;
  51.  
  52.             var radius = Radius;
  53.            
  54.             if (radius == -1)
  55.             {
  56.                 if (actor != null)
  57.                 {
  58.                     radius = Math.Min(actor.RadiusBottom, 20);
  59.                 }
  60.                 else return;
  61.             }
  62.            
  63.             radius = (RadiusTransformator != null ? RadiusTransformator.TransformRadius(radius) : radius);
  64.            
  65.             if (Brush.StrokeStyle.DashStyle == SharpDX.Direct2D1.DashStyle.Solid)
  66.                 _shadowBrush.StrokeWidth = Brush.StrokeWidth >= 0 ? Brush.StrokeWidth + 1 : Brush.StrokeWidth - 1;
  67.  
  68.             switch (Shape)
  69.             {
  70.                 case CustomGroundShape.NStar:
  71.                     PaintNStar(radius, coord.X, coord.Y, coord.Z);
  72.                     break;
  73.             }
  74.         }
  75.        
  76.         private void PaintNStar(float radius, float x, float y, float z)
  77.         {
  78.             if (Vertices <= 2) return;
  79.             if (Vertices > 360) return;
  80.             if (SkipVertices <= 0) return;
  81.             if (SkipVertices >= Vertices) return;
  82.            
  83.             var Phi = 360f / Vertices;
  84.             var tickRotationAngle = Rotation ? ((Hud.Game.CurrentRealTimeMilliseconds / RotationSpeed) % 360) : 0;
  85.            
  86.             for (int Edge = 0; Edge < Vertices; Edge++)
  87.             {
  88.                 var XStart = x + radius * (float)Math.Cos((tickRotationAngle + Angle + Edge * Phi) * (Math.PI / 180f));
  89.                 var XEnd = x + radius * (float)Math.Cos((tickRotationAngle + Angle + (Edge + SkipVertices) * Phi) * (Math.PI / 180f));
  90.                 var YStart = y + radius * (float)Math.Sin((tickRotationAngle + Angle + Edge * Phi) * (Math.PI / 180f));
  91.                 var YEnd = y + radius * (float)Math.Sin((tickRotationAngle + Angle + (Edge + SkipVertices) * Phi) * (Math.PI / 180f));
  92.                
  93.                 if (HasShadow)
  94.                     _shadowBrush.DrawLineWorld(XStart, YStart, z, XEnd, YEnd, z);
  95.                
  96.                 Brush.DrawLineWorld(XStart, YStart, z, XEnd, YEnd, z);
  97.             }
  98.         }
  99.        
  100.         public IEnumerable<ITransparent> GetTransparents()
  101.         {
  102.             yield return Brush;
  103.             yield return _shadowBrush;
  104.         }
  105.        
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement