Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System;
- namespace Turbo.Plugins.Default
- {
- public enum GroundShape { X, NStar }
- // this is not a plugin, just a helper class to display labels on the ground
- public class GroundShapeDecorator: IWorldDecoratorWithRadius
- {
- public bool Enabled { get; set; }
- public WorldLayer Layer { get; private set; }
- public IController Hud { get; set; }
- public IBrush Brush { get; set; }
- public GroundShape Shape { get; set; }
- public bool HasShadow { get; set; }
- private IBrush _shadowBrush;
- public float Radius { get; set; }
- public IRadiusTransformator RadiusTransformator { get; set; }
- //new
- public int Vertices { get; set; }
- public int SkipVertices { get; set; }
- public float Angle { get; set; }
- public bool Rotation { get; set; }
- public int RotationSpeed { get; set; }
- public GroundShapeDecorator(IController hud)
- {
- Enabled = true;
- Layer = WorldLayer.Ground;
- Hud = hud;
- _shadowBrush = Hud.Render.CreateBrush(96, 0, 0, 0, 1);
- Shape = GroundShape.X;
- HasShadow = true;
- //new
- SkipVertices = 1;
- Rotation = false;
- RotationSpeed = 30;
- }
- public void Paint(IActor actor, IWorldCoordinate coord, string text)
- {
- if (!Enabled) return;
- if (Brush == null) return;
- //if (Radius <= 0) return;
- var sc = coord.ToScreenCoordinate(true, true);
- var screenBorderPadding = Hud.Window.Size.Height * 0.01f;
- var radius = Radius;
- if (radius == -1)
- {
- if (actor != null)
- {
- radius = Math.Min(actor.RadiusBottom, 20);
- }
- else return;
- }
- radius = RadiusTransformator != null ? RadiusTransformator.TransformRadius(Radius) : Radius;
- if (Brush.StrokeStyle.DashStyle == SharpDX.Direct2D1.DashStyle.Solid)
- _shadowBrush.StrokeWidth = Brush.StrokeWidth >= 0 ? Brush.StrokeWidth + 1 : Brush.StrokeWidth - 1;
- switch (Shape)
- {
- case GroundShape.X:
- PaintX(radius, coord.X, coord.Y, coord.Z);
- break;
- case GroundShape.NStar:
- PaintNStar(radius, coord.X, coord.Y, coord.Z);
- break;
- }
- }
- private void PaintX(float radius, float x, float y, float z)
- {
- if (Radius <= 0) return;
- if (Brush.StrokeStyle.DashStyle == SharpDX.Direct2D1.DashStyle.Solid)
- {
- _shadowBrush.DrawWorldPlus(radius, x, y, z);
- }
- Brush.DrawWorldPlus(radius, x, y, z);
- }
- private void PaintNStar(float radius, float x, float y, float z)
- {
- if (Vertices <= 2) return;
- if (Vertices > 360) return;
- if (SkipVertices <= 0) return;
- if (SkipVertices >= Vertices) return;
- var Phi = 360f / Vertices;
- var tickRotationAngle = Rotation ? ((Hud.Game.CurrentRealTimeMilliseconds / RotationSpeed) % 360) : 0;
- for (int Edge = 0; Edge < Vertices; Edge++)
- {
- var XStart = x + radius * (float)Math.Cos((tickRotationAngle + Angle + Edge * Phi) * (Math.PI / 180f));
- var XEnd = x + radius * (float)Math.Cos((tickRotationAngle + Angle + (Edge + SkipVertices) * Phi) * (Math.PI / 180f));
- var YStart = y + radius * (float)Math.Sin((tickRotationAngle + Angle + Edge * Phi) * (Math.PI / 180f));
- var YEnd = y + radius * (float)Math.Sin((tickRotationAngle + Angle + (Edge + SkipVertices) * Phi) * (Math.PI / 180f));
- if (HasShadow)
- _shadowBrush.DrawLineWorld(XStart, YStart, z, XEnd, YEnd, z);
- Brush.DrawLineWorld(XStart, YStart, z, XEnd, YEnd, z);
- } /**/
- }
- public IEnumerable<ITransparent> GetTransparents()
- {
- yield return Brush;
- yield return _shadowBrush;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment