Guest User

GroundShapeDecorator.cs

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