Ejemplo n.º 1
0
        public virtual bool Draw(Batcher2D batcher, Vector3 position, MouseOverList list)
        {
            SpriteVertex[] vertex;

            bool hasShadow = HasShadow && position.Z >= 1000;

            if (hasShadow)
            {
                position.Z -= 1000;
            }

            if (Rotation != 0.0f)
            {
                float   w      = Bounds.Width / 2f;
                float   h      = Bounds.Height / 2f;
                Vector3 center = position;
                center.X -= Bounds.X - 44 + w;
                center.Y -= Bounds.Y + h;
                float sinx = (float)Math.Sin(Rotation) * w;
                float cosx = (float)Math.Cos(Rotation) * w;
                float siny = (float)Math.Sin(Rotation) * h;
                float cosy = (float)Math.Cos(Rotation) * h;

                vertex                = SpriteVertex.PolyBufferFlipped;
                vertex[0].Position    = center;
                vertex[0].Position.X += cosx - -siny;
                vertex[0].Position.Y -= sinx + -cosy;
                vertex[1].Position    = center;
                vertex[1].Position.X += cosx - siny;
                vertex[1].Position.Y += -sinx + -cosy;
                vertex[2].Position    = center;
                vertex[2].Position.X += -cosx - -siny;
                vertex[2].Position.Y += sinx + cosy;
                vertex[3].Position    = center;
                vertex[3].Position.X += -cosx - siny;
                vertex[3].Position.Y += sinx + -cosy;
            }
            else if (IsFlipped)
            {
                vertex                        = SpriteVertex.PolyBufferFlipped;
                vertex[0].Position            = position;
                vertex[0].Position.X         += Bounds.X + 44f;
                vertex[0].Position.Y         -= Bounds.Y;
                vertex[0].TextureCoordinate.Y = 0;
                vertex[1].Position            = vertex[0].Position;
                vertex[1].Position.Y         += Bounds.Height;
                vertex[2].Position            = vertex[0].Position;
                vertex[2].Position.X         -= Bounds.Width;
                vertex[2].TextureCoordinate.Y = 0;
                vertex[3].Position            = vertex[1].Position;
                vertex[3].Position.X         -= Bounds.Width;
            }
            else
            {
                vertex                        = SpriteVertex.PolyBuffer;
                vertex[0].Position            = position;
                vertex[0].Position.X         -= Bounds.X;
                vertex[0].Position.Y         -= Bounds.Y;
                vertex[0].TextureCoordinate.Y = 0;
                vertex[1].Position            = vertex[0].Position;
                vertex[1].Position.X         += Bounds.Width;
                vertex[1].TextureCoordinate.Y = 0;
                vertex[2].Position            = vertex[0].Position;
                vertex[2].Position.Y         += Bounds.Height;
                vertex[3].Position            = vertex[1].Position;
                vertex[3].Position.Y         += Bounds.Height;
            }

            bool isTransparent = false;

            if (DrawTransparent)
            {
                int dist    = Distance;
                int maxDist = Engine.Profile.Current.CircleOfTransparencyRadius + 1;

                if (dist <= maxDist)
                {
                    isTransparent = dist <= 3;
                    HueVector.Z   = MathHelper.Lerp(1f, 1f - (dist / (float)maxDist), 0.5f);
                    //HueVector.Z = 1f - (dist / (float)maxDist);
                }
                else
                {
                    HueVector.Z = 1f - AlphaHue / 255f;
                }
            }
            else
            {
                HueVector.Z = 1f - AlphaHue / 255f;
            }

            if (Engine.Profile.Current.HighlightGameObjects)
            {
                if (IsSelected)
                {
                    if (_storedHue == Vector3.Zero)
                    {
                        _storedHue = HueVector;
                    }
                    HueVector = ShaderHuesTraslator.SelectedHue;
                }
                else if (_storedHue != Vector3.Zero)
                {
                    HueVector  = _storedHue;
                    _storedHue = Vector3.Zero;
                }
            }

            if (vertex[0].Hue != HueVector)
            {
                vertex[0].Hue = vertex[1].Hue = vertex[2].Hue = vertex[3].Hue = HueVector;
            }


            if (hasShadow)
            {
                SpriteVertex[] vertexS =
                {
                    vertex[0],
                    vertex[1],
                    vertex[2],
                    vertex[3]
                };

                vertexS[0].Hue = vertexS[1].Hue = vertexS[2].Hue = vertexS[3].Hue = ShaderHuesTraslator.GetHueVector(0, ShadersEffectType.Shadow);

                batcher.DrawShadow(Texture, vertexS, new Vector2(position.X + 22, position.Y + Offset.Y - Offset.Z + 22), IsFlipped, 0);
            }

            if (!batcher.DrawSprite(Texture, vertex))
            {
                return(false);
            }

            MousePick(list, vertex, isTransparent);

            Texture.Ticks = Engine.Ticks;
            return(true);
        }