Esempio n. 1
0
        public void DrawSquares(DrawContext dc)
        {
            FlatBatch2D flatBatch2D = dc.PrimitivesRenderer2D.FlatBatch(1, DepthStencilState.None, null, BlendState.AlphaBlend);
            int         count       = flatBatch2D.LineVertices.Count;
            int         count2      = flatBatch2D.TriangleVertices.Count;
            float       num         = (float)MathUtils.Remainder(Time.FrameStartTime + (double)m_timeOffset, 10000.0);
            float       num2        = base.ActualSize.X / 12f;
            float       num3        = (float)(int)base.GlobalColorTransform.A / 255f;

            for (float num4 = 0f; num4 < base.ActualSize.X; num4 += num2)
            {
                for (float num5 = 0f; num5 < base.ActualSize.Y; num5 += num2)
                {
                    float   num6    = 0.35f * MathUtils.Pow(MathUtils.Saturate(SimplexNoise.OctavedNoise(num4 + 1000f, num5, 0.7f * num, 0.5f, 1, 2f, 1f) - 0.1f), 1f) * num3;
                    float   num7    = 0.7f * MathUtils.Pow(SimplexNoise.OctavedNoise(num4, num5, 0.5f * num, 0.5f, 1, 2f, 1f), 3f) * num3;
                    Vector2 corner  = new Vector2(num4, num5);
                    Vector2 corner2 = new Vector2(num4 + num2, num5 + num2);
                    if (num6 > 0.01f)
                    {
                        flatBatch2D.QueueRectangle(corner, corner2, 0f, new Color(0f, 0f, 0f, num6));
                    }
                    if (num7 > 0.01f)
                    {
                        flatBatch2D.QueueQuad(corner, corner2, 0f, new Color(0f, 0f, 0f, num7));
                    }
                }
            }
            flatBatch2D.TransformLines(base.GlobalTransform, count);
            flatBatch2D.TransformTriangles(base.GlobalTransform, count2);
        }
Esempio n. 2
0
        public override void Draw(DrawContext dc)
        {
            Color color = new Color((byte)128, (byte)128, (byte)128) * base.GlobalColorTransform * MathUtils.Saturate(m_scrollBarAlpha);

            if (color.A > 0 && m_scrollAreaLength > 0f)
            {
                FlatBatch2D flatBatch2D = dc.PrimitivesRenderer2D.FlatBatch(0, DepthStencilState.None);
                int         count       = flatBatch2D.TriangleVertices.Count;
                if (Direction == LayoutDirection.Horizontal)
                {
                    float   scrollPosition = ScrollPosition;
                    float   x       = base.ActualSize.X;
                    Vector2 corner  = new Vector2(scrollPosition / m_scrollAreaLength * x, base.ActualSize.Y - 5f);
                    Vector2 corner2 = new Vector2((scrollPosition + x) / m_scrollAreaLength * x, base.ActualSize.Y - 1f);
                    flatBatch2D.QueueQuad(corner, corner2, 0f, color);
                }
                else
                {
                    float   scrollPosition2 = ScrollPosition;
                    float   y       = base.ActualSize.Y;
                    Vector2 corner3 = new Vector2(base.ActualSize.X - 5f, scrollPosition2 / m_scrollAreaLength * y);
                    Vector2 corner4 = new Vector2(base.ActualSize.X - 1f, (scrollPosition2 + y) / m_scrollAreaLength * y);
                    flatBatch2D.QueueQuad(corner3, corner4, 0f, color);
                }
                flatBatch2D.TransformTriangles(base.GlobalTransform, count);
            }
        }
Esempio n. 3
0
        public override void Update(float dt)
        {
            dt = MathUtils.Min(dt, 0.1f);
            Vector3 zero = Vector3.Zero;

            if (Keyboard.IsKeyDown(Key.A))
            {
                zero.X = -1f;
            }
            if (Keyboard.IsKeyDown(Key.D))
            {
                zero.X = 1f;
            }
            if (Keyboard.IsKeyDown(Key.W))
            {
                zero.Z = 1f;
            }
            if (Keyboard.IsKeyDown(Key.S))
            {
                zero.Z = -1f;
            }
            Vector2 vector    = 0.03f * new Vector2(Mouse.MouseMovement.X, -Mouse.MouseMovement.Y);
            bool    num       = Keyboard.IsKeyDown(Key.Shift);
            bool    flag      = Keyboard.IsKeyDown(Key.Control);
            Vector3 direction = m_direction;
            Vector3 unitY     = Vector3.UnitY;
            Vector3 vector2   = Vector3.Normalize(Vector3.Cross(direction, unitY));
            float   num2      = 8f;

            if (num)
            {
                num2 *= 10f;
            }
            if (flag)
            {
                num2 /= 10f;
            }
            Vector3 zero2 = Vector3.Zero;

            zero2      += num2 * zero.X * vector2;
            zero2      += num2 * zero.Y * unitY;
            zero2      += num2 * zero.Z * direction;
            m_position += zero2 * dt;
            m_direction = Vector3.Transform(m_direction, Matrix.CreateFromAxisAngle(unitY, -4f * vector.X * dt));
            m_direction = Vector3.Transform(m_direction, Matrix.CreateFromAxisAngle(vector2, 4f * vector.Y * dt));
            SetupPerspectiveCamera(m_position, m_direction, Vector3.UnitY);
            Vector2     v           = ViewportSize / 2f;
            FlatBatch2D flatBatch2D = PrimitivesRenderer2D.FlatBatch(0, DepthStencilState.None);
            int         count       = flatBatch2D.LineVertices.Count;

            flatBatch2D.QueueLine(v - new Vector2(5f, 0f), v + new Vector2(5f, 0f), 0f, Color.White);
            flatBatch2D.QueueLine(v - new Vector2(0f, 5f), v + new Vector2(0f, 5f), 0f, Color.White);
            flatBatch2D.TransformLines(ViewportMatrix, count);
            PrimitivesRenderer2D.Flush();
        }
Esempio n. 4
0
 public override void Draw(DrawContext dc)
 {
     if (m_highlighted)
     {
         FlatBatch2D flatBatch2D = dc.PrimitivesRenderer2D.FlatBatch(100, DepthStencilState.None);
         int         count       = flatBatch2D.TriangleVertices.Count;
         flatBatch2D.QueueQuad(Vector2.Zero, base.ActualSize, 0f, new Color(128, 128, 128, 128));
         flatBatch2D.TransformTriangles(base.GlobalTransform, count);
         m_highlighted = false;
     }
 }
Esempio n. 5
0
 public override void Draw(DrawContext dc)
 {
     if (SelectedIndex.HasValue && SelectedIndex.Value >= m_firstVisibleIndex && SelectedIndex.Value <= m_lastVisibleIndex)
     {
         Vector2     vector      = (Direction == LayoutDirection.Horizontal) ? new Vector2((float)SelectedIndex.Value * ItemSize - ScrollPosition, 0f) : new Vector2(0f, (float)SelectedIndex.Value * ItemSize - ScrollPosition);
         FlatBatch2D flatBatch2D = dc.PrimitivesRenderer2D.FlatBatch(0, DepthStencilState.None);
         int         count       = flatBatch2D.TriangleVertices.Count;
         Vector2     v           = (Direction == LayoutDirection.Horizontal) ? new Vector2(ItemSize, base.ActualSize.Y) : new Vector2(base.ActualSize.X, ItemSize);
         flatBatch2D.QueueQuad(vector, vector + v, 0f, SelectionColor * base.GlobalColorTransform);
         flatBatch2D.TransformTriangles(base.GlobalTransform, count);
     }
     base.Draw(dc);
 }
        public static void Draw()
        {
            Vector2  scale    = new Vector2(MathUtils.Round(MathUtils.Clamp(ScreensManager.RootWidget.GlobalScale, 1f, 4f)));
            Viewport viewport = Display.Viewport;

            if (SettingsManager.DisplayFpsCounter)
            {
                if (Time.PeriodicEvent(1.0, 0.0))
                {
                    m_statsString = $"CPUMEM {(float)TotalMemoryUsed / 1024f / 1024f:0}MB, GPUMEM {(float)TotalGpuMemoryUsed / 1024f / 1024f:0}MB, CPU {AverageCpuFrameTime / AverageFrameTime * 100f:0}%, FPS {1f / AverageFrameTime:0.0}";
                }
                m_primitivesRenderer.FontBatch(BitmapFont.DebugFont, 0, null, null, null, SamplerState.PointClamp).QueueText(m_statsString, new Vector2(viewport.Width, 0f), 0f, Color.White, TextAnchor.Right, scale, Vector2.Zero);
            }
            if (SettingsManager.DisplayFpsRibbon)
            {
                float num  = ((float)viewport.Width / scale.X > 480f) ? (scale.X * 2f) : scale.X;
                float num2 = (float)viewport.Height / -0.1f;
                float num3 = viewport.Height - 1;
                float s    = 0.5f;
                int   num4 = MathUtils.Max((int)((float)viewport.Width / num), 1);
                if (m_frameData == null || m_frameData.Length != num4)
                {
                    m_frameData      = new FrameData[num4];
                    m_frameDataIndex = 0;
                }
                m_frameData[m_frameDataIndex] = new FrameData
                {
                    CpuTime   = Program.LastCpuFrameTime,
                    TotalTime = Program.LastFrameTime
                };
                m_frameDataIndex = (m_frameDataIndex + 1) % m_frameData.Length;
                FlatBatch2D flatBatch2D = m_primitivesRenderer.FlatBatch();
                Color       color       = Color.Orange * s;
                Color       color2      = Color.Red * s;
                for (int num5 = m_frameData.Length - 1; num5 >= 0; num5--)
                {
                    int       num6      = (num5 - m_frameData.Length + 1 + m_frameDataIndex + m_frameData.Length) % m_frameData.Length;
                    FrameData frameData = m_frameData[num6];
                    float     x         = (float)num5 * num;
                    float     x2        = (float)(num5 + 1) * num;
                    flatBatch2D.QueueQuad(new Vector2(x, num3), new Vector2(x2, num3 + frameData.CpuTime * num2), 0f, color);
                    flatBatch2D.QueueQuad(new Vector2(x, num3 + frameData.CpuTime * num2), new Vector2(x2, num3 + frameData.TotalTime * num2), 0f, color2);
                }
                flatBatch2D.QueueLine(new Vector2(0f, num3 + 0.0166666675f * num2), new Vector2(viewport.Width, num3 + 0.0166666675f * num2), 0f, Color.Green);
            }
            else
            {
                m_frameData = null;
            }
            m_primitivesRenderer.Flush();
        }
Esempio n. 7
0
 public override void Draw(DrawContext dc)
 {
     if (m_inventory != null && m_inventoryDragData != null)
     {
         int slotValue = m_inventoryDragData.Inventory.GetSlotValue(m_inventoryDragData.SlotIndex);
         if (m_inventory.GetSlotProcessCapacity(m_slotIndex, slotValue) >= 0 || m_inventory.GetSlotCapacity(m_slotIndex, slotValue) > 0)
         {
             float       num         = 80f * base.GlobalTransform.Right.Length();
             Vector2     center      = Vector2.Transform(base.ActualSize / 2f, base.GlobalTransform);
             FlatBatch2D flatBatch2D = dc.PrimitivesRenderer2D.FlatBatch(100);
             flatBatch2D.QueueEllipse(center, new Vector2(num), 0f, new Color(0, 0, 0, 96) * base.GlobalColorTransform, 64);
             flatBatch2D.QueueEllipse(center, new Vector2(num - 0.5f), 0f, new Color(0, 0, 0, 64) * base.GlobalColorTransform, 64);
             flatBatch2D.QueueEllipse(center, new Vector2(num + 0.5f), 0f, new Color(0, 0, 0, 48) * base.GlobalColorTransform, 64);
             flatBatch2D.QueueDisc(center, new Vector2(num), 0f, new Color(0, 0, 0, 48) * base.GlobalColorTransform, 64);
         }
     }
     m_inventoryDragData = null;
 }
Esempio n. 8
0
        public override void Draw(DrawContext dc)
        {
            if (m_parsingPending)
            {
                ParsePoints();
            }
            Color       color       = Color * base.GlobalColorTransform;
            FlatBatch2D flatBatch2D = dc.PrimitivesRenderer2D.FlatBatch(1, DepthStencilState.None);
            int         count       = flatBatch2D.TriangleVertices.Count;

            for (int i = 0; i < m_vertices.Count; i += 3)
            {
                Vector2 p  = m_startOffset + m_vertices[i];
                Vector2 p2 = m_startOffset + m_vertices[i + 1];
                Vector2 p3 = m_startOffset + m_vertices[i + 2];
                flatBatch2D.QueueTriangle(p, p2, p3, 0f, color);
            }
            flatBatch2D.TransformTriangles(base.GlobalTransform, count);
        }
Esempio n. 9
0
        public override void Draw(DrawContext dc)
        {
            if (Time.RealTime - m_lastBoxesStepTime > 0.25)
            {
                m_boxIndex++;
                m_lastBoxesStepTime = Time.RealTime;
            }
            FlatBatch2D flatBatch2D = dc.PrimitivesRenderer2D.FlatBatch();
            int         count       = flatBatch2D.TriangleVertices.Count;

            for (int i = 0; i < 5; i++)
            {
                Vector2 v  = new Vector2(((float)i + 0.5f) * 24f, 6f);
                Color   c  = (i == m_boxIndex % 5) ? LitBarColor : UnlitBarColor;
                float   v2 = (i == m_boxIndex % 5) ? 12f : 8f;
                flatBatch2D.QueueQuad(v - new Vector2(v2) / 2f, v + new Vector2(v2) / 2f, 0f, c * base.GlobalColorTransform);
            }
            flatBatch2D.TransformTriangles(base.GlobalTransform, count);
        }
Esempio n. 10
0
        public void DrawOverlay(Camera camera, Color color, float innerFactor, float outerFactor)
        {
            Vector2     viewportSize = camera.ViewportSize;
            Vector2     vector       = new Vector2(0f, 0f);
            Vector2     vector2      = new Vector2(viewportSize.X, 0f);
            Vector2     vector3      = new Vector2(viewportSize.X, viewportSize.Y);
            Vector2     vector4      = new Vector2(0f, viewportSize.Y);
            Vector2     p            = new Vector2(viewportSize.X / 2f, viewportSize.Y / 2f);
            Color       color2       = color * outerFactor;
            Color       color3       = color * innerFactor;
            FlatBatch2D flatBatch2D  = m_primitivesRenderer2D.FlatBatch(0, DepthStencilState.None, null, BlendState.AlphaBlend);
            int         count        = flatBatch2D.TriangleVertices.Count;

            flatBatch2D.QueueTriangle(vector, vector2, p, 0f, color2, color2, color3);
            flatBatch2D.QueueTriangle(vector2, vector3, p, 0f, color2, color2, color3);
            flatBatch2D.QueueTriangle(vector3, vector4, p, 0f, color2, color2, color3);
            flatBatch2D.QueueTriangle(vector4, vector, p, 0f, color2, color2, color3);
            flatBatch2D.TransformTriangles(camera.ViewportMatrix, count);
            flatBatch2D.Flush();
        }
 public override void Draw(DrawContext dc)
 {
     if (Texture != null)
     {
         SamplerState    samplerState    = TextureLinearFilter ? SamplerState.LinearWrap : SamplerState.PointWrap;
         FlatBatch2D     flatBatch2D     = dc.PrimitivesRenderer2D.FlatBatch(0, DepthStencilState.None);
         TexturedBatch2D texturedBatch2D = dc.PrimitivesRenderer2D.TexturedBatch(Texture, useAlphaTest: false, 0, DepthStencilState.None, null, null, samplerState);
         int             count           = flatBatch2D.TriangleVertices.Count;
         int             count2          = texturedBatch2D.TriangleVertices.Count;
         QueueBevelledRectangle(texturedBatch2D, flatBatch2D, Vector2.Zero, base.ActualSize, 0f, BevelSize, CenterColor * base.GlobalColorTransform, BevelColor * base.GlobalColorTransform, ShadowColor * base.GlobalColorTransform, AmbientLight, DirectionalLight, TextureScale);
         flatBatch2D.TransformTriangles(base.GlobalTransform, count);
         texturedBatch2D.TransformTriangles(base.GlobalTransform, count2);
     }
     else
     {
         FlatBatch2D flatBatch2D2 = dc.PrimitivesRenderer2D.FlatBatch(0, DepthStencilState.None);
         int         count3       = flatBatch2D2.TriangleVertices.Count;
         QueueBevelledRectangle(null, flatBatch2D2, Vector2.Zero, base.ActualSize, 0f, BevelSize, CenterColor * base.GlobalColorTransform, BevelColor * base.GlobalColorTransform, ShadowColor * base.GlobalColorTransform, AmbientLight, DirectionalLight, 0f);
         flatBatch2D2.TransformTriangles(base.GlobalTransform, count3);
     }
 }
Esempio n. 12
0
        public override void Draw(DrawContext dc)
        {
            Color color = Color * base.GlobalColorTransform;

            if (!string.IsNullOrEmpty(m_text))
            {
                Vector2      position     = new Vector2(0f - m_scroll, base.ActualSize.Y / 2f);
                SamplerState samplerState = TextureLinearFilter ? SamplerState.LinearClamp : SamplerState.PointClamp;
                FontBatch2D  fontBatch2D  = dc.PrimitivesRenderer2D.FontBatch(Font, 1, DepthStencilState.None, null, null, samplerState);
                int          count        = fontBatch2D.TriangleVertices.Count;
                fontBatch2D.QueueText(Text, position, 0f, color, TextAnchor.VerticalCenter, new Vector2(FontScale), FontSpacing);
                fontBatch2D.TransformTriangles(base.GlobalTransform, count);
            }
            if (!m_hasFocus || !(MathUtils.Remainder(Time.RealTime - m_focusStartTime, 0.5) < 0.25))
            {
                return;
            }
            float   num = Font.CalculateCharacterPosition(Text, CaretPosition, new Vector2(FontScale), FontSpacing);
            Vector2 v   = new Vector2(0f, base.ActualSize.Y / 2f) + new Vector2(num - m_scroll, 0f);

            if (m_hasFocus)
            {
                if (v.X < 0f)
                {
                    m_scroll = MathUtils.Max(m_scroll + v.X, 0f);
                }
                if (v.X > base.ActualSize.X)
                {
                    m_scroll += v.X - base.ActualSize.X + 1f;
                }
            }
            FlatBatch2D flatBatch2D = dc.PrimitivesRenderer2D.FlatBatch(1, DepthStencilState.None);
            int         count2      = flatBatch2D.TriangleVertices.Count;

            flatBatch2D.QueueQuad(v - new Vector2(0f, Font.GlyphHeight / 2f * FontScale * Font.Scale), v + new Vector2(1f, Font.GlyphHeight / 2f * FontScale * Font.Scale), 0f, color);
            flatBatch2D.TransformTriangles(base.GlobalTransform, count2);
        }
Esempio n. 13
0
        public override void Overdraw(DrawContext dc)
        {
            Color       color            = new Color(181, 172, 154) * base.GlobalColorTransform;
            float       num              = 0.6f;
            float       directionalLight = 0.4f;
            FlatBatch2D flatBatch2D      = dc.PrimitivesRenderer2D.FlatBatch();
            int         count            = flatBatch2D.TriangleVertices.Count;

            if (Children.Count == 2)
            {
                if (SettingsManager.ScreenLayout2 == ScreenLayout.DoubleVertical || SettingsManager.ScreenLayout2 == ScreenLayout.DoubleOpposite)
                {
                    Vector2 c  = new Vector2(base.ActualSize.X / 2f - m_spacing / 2f, -100f);
                    Vector2 c2 = new Vector2(base.ActualSize.X / 2f + m_spacing / 2f, base.ActualSize.Y + 100f);
                    BevelledRectangleWidget.QueueBevelledRectangle(null, flatBatch2D, c, c2, 0f, m_bevel, color, color, Color.Transparent, num, directionalLight, 0f);
                }
                if (SettingsManager.ScreenLayout2 == ScreenLayout.DoubleHorizontal)
                {
                    Vector2 c3 = new Vector2(-100f, base.ActualSize.Y / 2f - m_spacing / 2f);
                    Vector2 c4 = new Vector2(base.ActualSize.X + 100f, base.ActualSize.Y / 2f + m_spacing / 2f);
                    BevelledRectangleWidget.QueueBevelledRectangle(null, flatBatch2D, c3, c4, 0f, m_bevel, color, color, Color.Transparent, num, directionalLight, 0f);
                }
            }
            else if (Children.Count == 3)
            {
                if (SettingsManager.ScreenLayout3 == ScreenLayout.TripleVertical || SettingsManager.ScreenLayout3 == ScreenLayout.TripleOpposite)
                {
                    float x  = -100f;
                    float x2 = base.ActualSize.X / 2f - m_spacing / 2f + m_bevel;
                    float x3 = base.ActualSize.X / 2f + m_spacing / 2f - m_bevel;
                    float x4 = base.ActualSize.X + 100f;
                    float y  = -100f;
                    float y2 = base.ActualSize.Y / 2f - m_spacing / 2f + m_bevel;
                    float y3 = base.ActualSize.Y / 2f + m_spacing / 2f - m_bevel;
                    float y4 = base.ActualSize.Y + 100f;
                    BevelledRectangleWidget.QueueBevelledRectangle(null, flatBatch2D, new Vector2(x, y), new Vector2(x2, y4), 0f, 0f - m_bevel, Color.Transparent, color, Color.Transparent, num, directionalLight, 0f);
                    BevelledRectangleWidget.QueueBevelledRectangle(null, flatBatch2D, new Vector2(x3, y), new Vector2(x4, y2), 0f, 0f - m_bevel, Color.Transparent, color, Color.Transparent, num, directionalLight, 0f);
                    BevelledRectangleWidget.QueueBevelledRectangle(null, flatBatch2D, new Vector2(x3, y3), new Vector2(x4, y4), 0f, 0f - m_bevel, Color.Transparent, color, Color.Transparent, num, directionalLight, 0f);
                    Color color2 = color * new Color(num, num, num, 1f);
                    flatBatch2D.QueueQuad(new Vector2(x2, y), new Vector2(x3, y4), 0f, color2);
                    flatBatch2D.QueueQuad(new Vector2(x3, y2), new Vector2(x4, y3), 0f, color2);
                }
                if (SettingsManager.ScreenLayout3 == ScreenLayout.TripleHorizontal)
                {
                    float x5 = -100f;
                    float x6 = base.ActualSize.X / 2f - m_spacing / 2f + m_bevel;
                    float x7 = base.ActualSize.X / 2f + m_spacing / 2f - m_bevel;
                    float x8 = base.ActualSize.X + 100f;
                    float y5 = -100f;
                    float y6 = base.ActualSize.Y / 2f - m_spacing / 2f + m_bevel;
                    float y7 = base.ActualSize.Y / 2f + m_spacing / 2f - m_bevel;
                    float y8 = base.ActualSize.Y + 100f;
                    BevelledRectangleWidget.QueueBevelledRectangle(null, flatBatch2D, new Vector2(x5, y5), new Vector2(x8, y6), 0f, 0f - m_bevel, Color.Transparent, color, Color.Transparent, num, directionalLight, 0f);
                    BevelledRectangleWidget.QueueBevelledRectangle(null, flatBatch2D, new Vector2(x5, y7), new Vector2(x6, y8), 0f, 0f - m_bevel, Color.Transparent, color, Color.Transparent, num, directionalLight, 0f);
                    BevelledRectangleWidget.QueueBevelledRectangle(null, flatBatch2D, new Vector2(x7, y7), new Vector2(x8, y8), 0f, 0f - m_bevel, Color.Transparent, color, Color.Transparent, num, directionalLight, 0f);
                    Color color3 = color * new Color(num, num, num, 1f);
                    flatBatch2D.QueueQuad(new Vector2(x5, y6), new Vector2(x8, y7), 0f, color3);
                    flatBatch2D.QueueQuad(new Vector2(x6, y7), new Vector2(x7, y8), 0f, color3);
                }
                if (SettingsManager.ScreenLayout3 == ScreenLayout.TripleEven)
                {
                    float x9  = -100f;
                    float x10 = base.ActualSize.X / 2f - m_spacing / 2f + m_bevel;
                    float x11 = base.ActualSize.X / 2f + m_spacing / 2f - m_bevel;
                    float x12 = base.ActualSize.X + 100f;
                    float x13 = base.ActualSize.X / 4f;
                    float x14 = base.ActualSize.X * 3f / 4f;
                    float y9  = -100f;
                    float y10 = base.ActualSize.Y / 2f - m_spacing / 2f + m_bevel;
                    float y11 = base.ActualSize.Y / 2f + m_spacing / 2f - m_bevel;
                    float y12 = base.ActualSize.Y + 100f;
                    BevelledRectangleWidget.QueueBevelledRectangle(null, flatBatch2D, new Vector2(x9, y9), new Vector2(x10, y10), 0f, 0f - m_bevel, Color.Transparent, color, Color.Transparent, num, directionalLight, 0f);
                    BevelledRectangleWidget.QueueBevelledRectangle(null, flatBatch2D, new Vector2(x11, y9), new Vector2(x12, y10), 0f, 0f - m_bevel, Color.Transparent, color, Color.Transparent, num, directionalLight, 0f);
                    BevelledRectangleWidget.QueueBevelledRectangle(null, flatBatch2D, new Vector2(x13, y11), new Vector2(x14, y12), 0f, 0f - m_bevel, Color.Transparent, color, Color.Transparent, num, directionalLight, 0f);
                    Color color4 = color * new Color(num, num, num, 1f);
                    flatBatch2D.QueueQuad(new Vector2(x10, y9), new Vector2(x11, y10), 0f, color4);
                    flatBatch2D.QueueQuad(new Vector2(x9, y10), new Vector2(x12, y11), 0f, color4);
                    flatBatch2D.QueueQuad(new Vector2(x9, y11), new Vector2(x13, y12), 0f, color4);
                    flatBatch2D.QueueQuad(new Vector2(x14, y11), new Vector2(x12, y12), 0f, color4);
                }
            }
            else if (Children.Count == 4)
            {
                float x15 = -100f;
                float x16 = base.ActualSize.X / 2f - m_spacing / 2f + m_bevel;
                float x17 = base.ActualSize.X / 2f + m_spacing / 2f - m_bevel;
                float x18 = base.ActualSize.X + 100f;
                float y13 = -100f;
                float y14 = base.ActualSize.Y / 2f - m_spacing / 2f + m_bevel;
                float y15 = base.ActualSize.Y / 2f + m_spacing / 2f - m_bevel;
                float y16 = base.ActualSize.Y + 100f;
                BevelledRectangleWidget.QueueBevelledRectangle(null, flatBatch2D, new Vector2(x15, y13), new Vector2(x16, y14), 0f, 0f - m_bevel, Color.Transparent, color, Color.Transparent, num, directionalLight, 0f);
                BevelledRectangleWidget.QueueBevelledRectangle(null, flatBatch2D, new Vector2(x17, y13), new Vector2(x18, y14), 0f, 0f - m_bevel, Color.Transparent, color, Color.Transparent, num, directionalLight, 0f);
                BevelledRectangleWidget.QueueBevelledRectangle(null, flatBatch2D, new Vector2(x15, y15), new Vector2(x16, y16), 0f, 0f - m_bevel, Color.Transparent, color, Color.Transparent, num, directionalLight, 0f);
                BevelledRectangleWidget.QueueBevelledRectangle(null, flatBatch2D, new Vector2(x17, y15), new Vector2(x18, y16), 0f, 0f - m_bevel, (Children.Count == 3) ? color : Color.Transparent, color, Color.Transparent, num, directionalLight, 0f);
                Color color5 = color * new Color(num, num, num, 1f);
                flatBatch2D.QueueQuad(new Vector2(x16, y13), new Vector2(x17, y16), 0f, color5);
                flatBatch2D.QueueQuad(new Vector2(x15, y14), new Vector2(x18, y15), 0f, color5);
            }
            else if (Children.Count > 4)
            {
                throw new InvalidOperationException("Too many GameWidgets.");
            }
            flatBatch2D.TransformTriangles(base.GlobalTransform, count);
        }
Esempio n. 14
0
 public void Draw(Camera camera, int drawOrder)
 {
     if (drawOrder == m_drawOrders[0])
     {
         ViewUnderWaterDepth = 0f;
         ViewUnderMagmaDepth = 0f;
         Vector3    viewPosition = camera.ViewPosition;
         int        x            = Terrain.ToCell(viewPosition.X);
         int        y            = Terrain.ToCell(viewPosition.Y);
         int        z            = Terrain.ToCell(viewPosition.Z);
         FluidBlock surfaceFluidBlock;
         float?     surfaceHeight = m_subsystemFluidBlockBehavior.GetSurfaceHeight(x, y, z, out surfaceFluidBlock);
         if (surfaceHeight.HasValue)
         {
             if (surfaceFluidBlock is WaterBlock)
             {
                 ViewUnderWaterDepth = surfaceHeight.Value + 0.1f - viewPosition.Y;
             }
             else if (surfaceFluidBlock is MagmaBlock)
             {
                 ViewUnderMagmaDepth = surfaceHeight.Value + 1f - viewPosition.Y;
             }
         }
         if (ViewUnderWaterDepth > 0f)
         {
             int   seasonalHumidity = m_subsystemTerrain.Terrain.GetSeasonalHumidity(x, z);
             int   temperature      = m_subsystemTerrain.Terrain.GetSeasonalTemperature(x, z) + SubsystemWeather.GetTemperatureAdjustmentAtHeight(y);
             Color c    = BlockColorsMap.WaterColorsMap.Lookup(temperature, seasonalHumidity);
             float num  = MathUtils.Lerp(1f, 0.5f, (float)seasonalHumidity / 15f);
             float num2 = MathUtils.Lerp(1f, 0.2f, MathUtils.Saturate(0.075f * (ViewUnderWaterDepth - 2f)));
             float num3 = MathUtils.Lerp(0.33f, 1f, SkyLightIntensity);
             m_viewFogRange.X           = 0f;
             m_viewFogRange.Y           = MathUtils.Lerp(4f, 10f, num * num2 * num3);
             m_viewFogColor             = Color.MultiplyColorOnly(c, 0.66f * num2 * num3);
             VisibilityRangeYMultiplier = 1f;
             m_viewIsSkyVisible         = false;
         }
         else if (ViewUnderMagmaDepth > 0f)
         {
             m_viewFogRange.X           = 0f;
             m_viewFogRange.Y           = 0.1f;
             m_viewFogColor             = new Color(255, 80, 0);
             VisibilityRangeYMultiplier = 1f;
             m_viewIsSkyVisible         = false;
         }
         else
         {
             float num4 = 1024f;
             float num5 = 128f;
             int   seasonalTemperature = m_subsystemTerrain.Terrain.GetSeasonalTemperature(Terrain.ToCell(viewPosition.X), Terrain.ToCell(viewPosition.Z));
             float num6 = MathUtils.Lerp(0.5f, 0f, m_subsystemWeather.GlobalPrecipitationIntensity);
             float num7 = MathUtils.Lerp(1f, 0.8f, m_subsystemWeather.GlobalPrecipitationIntensity);
             m_viewFogRange.X           = VisibilityRange * num6;
             m_viewFogRange.Y           = VisibilityRange * num7;
             m_viewFogColor             = CalculateSkyColor(new Vector3(camera.ViewDirection.X, 0f, camera.ViewDirection.Z), m_subsystemTimeOfDay.TimeOfDay, m_subsystemWeather.GlobalPrecipitationIntensity, seasonalTemperature);
             VisibilityRangeYMultiplier = MathUtils.Lerp(VisibilityRange / num4, VisibilityRange / num5, MathUtils.Pow(m_subsystemWeather.GlobalPrecipitationIntensity, 4f));
             m_viewIsSkyVisible         = true;
         }
         if (!FogEnabled)
         {
             m_viewFogRange = new Vector2(100000f, 100000f);
         }
         if (!DrawSkyEnabled || !m_viewIsSkyVisible || SettingsManager.SkyRenderingMode == SkyRenderingMode.Disabled)
         {
             FlatBatch2D flatBatch2D = m_primitivesRenderer2d.FlatBatch(-1, DepthStencilState.None, RasterizerState.CullNoneScissor, BlendState.Opaque);
             int         count       = flatBatch2D.TriangleVertices.Count;
             flatBatch2D.QueueQuad(Vector2.Zero, camera.ViewportSize, 0f, m_viewFogColor);
             flatBatch2D.TransformTriangles(camera.ViewportMatrix, count);
             m_primitivesRenderer2d.Flush();
         }
     }
     else if (drawOrder == m_drawOrders[1])
     {
         if (DrawSkyEnabled && m_viewIsSkyVisible && SettingsManager.SkyRenderingMode != SkyRenderingMode.Disabled)
         {
             DrawSkydome(camera);
             DrawStars(camera);
             DrawSunAndMoon(camera);
             DrawClouds(camera);
             m_primitivesRenderer3d.Flush(camera.ViewProjectionMatrix);
         }
     }
     else
     {
         DrawLightning(camera);
         m_primitivesRenderer3d.Flush(camera.ViewProjectionMatrix);
     }
 }
        public override void Draw(DrawContext dc)
        {
            if (Design == null)
            {
                return;
            }
            Matrix matrix;

            if (Mode == ViewMode.Perspective)
            {
                Viewport viewport = Display.Viewport;
                Vector3  vector   = new Vector3(0.5f, 0.5f, 0.5f);
                Matrix   m        = Matrix.CreateLookAt(2.65f * m_direction + vector, vector, Vector3.UnitY);
                Matrix   m2       = Matrix.CreatePerspectiveFieldOfView(1.2f, base.ActualSize.X / base.ActualSize.Y, 0.4f, 4f);
                Matrix   m3       = MatrixUtils.CreateScaleTranslation(base.ActualSize.X, 0f - base.ActualSize.Y, base.ActualSize.X / 2f, base.ActualSize.Y / 2f) * base.GlobalTransform * MatrixUtils.CreateScaleTranslation(2f / (float)viewport.Width, -2f / (float)viewport.Height, -1f, 1f);
                matrix = m * m2 * m3;
                FlatBatch3D flatBatch3D = m_primitivesRenderer3d.FlatBatch(1, DepthStencilState.DepthRead);
                for (int i = 0; i <= Design.Resolution; i++)
                {
                    float num   = (float)i / (float)Design.Resolution;
                    Color color = (i % 2 == 0) ? new Color(56, 56, 56, 56) : new Color(28, 28, 28, 28);
                    color *= base.GlobalColorTransform;
                    flatBatch3D.QueueLine(new Vector3(num, 0f, 0f), new Vector3(num, 0f, 1f), color);
                    flatBatch3D.QueueLine(new Vector3(0f, 0f, num), new Vector3(1f, 0f, num), color);
                    flatBatch3D.QueueLine(new Vector3(0f, num, 0f), new Vector3(0f, num, 1f), color);
                    flatBatch3D.QueueLine(new Vector3(0f, 0f, num), new Vector3(0f, 1f, num), color);
                    flatBatch3D.QueueLine(new Vector3(0f, num, 1f), new Vector3(1f, num, 1f), color);
                    flatBatch3D.QueueLine(new Vector3(num, 0f, 1f), new Vector3(num, 1f, 1f), color);
                }
                Color       color2      = new Color(64, 64, 64, 255) * base.GlobalColorTransform;
                FontBatch3D fontBatch3D = m_primitivesRenderer3d.FontBatch(ContentManager.Get <BitmapFont>("Fonts/Pericles"), 1);
                fontBatch3D.QueueText("Front", new Vector3(0.5f, 0f, 0f), 0.004f * new Vector3(-1f, 0f, 0f), 0.004f * new Vector3(0f, 0f, -1f), color2, TextAnchor.HorizontalCenter);
                fontBatch3D.QueueText("Side", new Vector3(1f, 0f, 0.5f), 0.004f * new Vector3(0f, 0f, -1f), 0.004f * new Vector3(1f, 0f, 0f), color2, TextAnchor.HorizontalCenter);
                if (DrawDebugFurniture)
                {
                    DebugDraw();
                }
            }
            else
            {
                Vector3 position;
                Vector3 up;
                if (Mode == ViewMode.Side)
                {
                    position = new Vector3(1f, 0f, 0f);
                    up       = new Vector3(0f, 1f, 0f);
                }
                else if (Mode != ViewMode.Top)
                {
                    position = new Vector3(0f, 0f, -1f);
                    up       = new Vector3(0f, 1f, 0f);
                }
                else
                {
                    position = new Vector3(0f, 1f, 0f);
                    up       = new Vector3(0f, 0f, 1f);
                }
                Viewport viewport2 = Display.Viewport;
                float    num2      = MathUtils.Min(base.ActualSize.X, base.ActualSize.Y);
                Matrix   m4        = Matrix.CreateLookAt(position, new Vector3(0f, 0f, 0f), up);
                Matrix   m5        = Matrix.CreateOrthographic(2f, 2f, -10f, 10f);
                Matrix   m6        = MatrixUtils.CreateScaleTranslation(num2, 0f - num2, base.ActualSize.X / 2f, base.ActualSize.Y / 2f) * base.GlobalTransform * MatrixUtils.CreateScaleTranslation(2f / (float)viewport2.Width, -2f / (float)viewport2.Height, -1f, 1f);
                matrix = Matrix.CreateTranslation(-0.5f, -0.5f, -0.5f) * m4 * m5 * m6;
                FlatBatch2D flatBatch2D = m_primitivesRenderer2d.FlatBatch();
                Matrix      m7          = base.GlobalTransform;
                for (int j = 1; j < Design.Resolution; j++)
                {
                    float   num3 = (float)j / (float)Design.Resolution;
                    Vector2 v    = new Vector2(base.ActualSize.X * num3, 0f);
                    Vector2 v2   = new Vector2(base.ActualSize.X * num3, base.ActualSize.Y);
                    Vector2 v3   = new Vector2(0f, base.ActualSize.Y * num3);
                    Vector2 v4   = new Vector2(base.ActualSize.X, base.ActualSize.Y * num3);
                    Vector2.Transform(ref v, ref m7, out v);
                    Vector2.Transform(ref v2, ref m7, out v2);
                    Vector2.Transform(ref v3, ref m7, out v3);
                    Vector2.Transform(ref v4, ref m7, out v4);
                    Color color3 = (j % 2 == 0) ? new Color(0, 0, 0, 56) : new Color(0, 0, 0, 28);
                    Color color4 = (j % 2 == 0) ? new Color(56, 56, 56, 56) : new Color(28, 28, 28, 28);
                    color3 *= base.GlobalColorTransform;
                    color4 *= base.GlobalColorTransform;
                    flatBatch2D.QueueLine(v, v2, 0f, (j % 2 == 0) ? color3 : (color3 * 0.75f));
                    flatBatch2D.QueueLine(v + new Vector2(1f, 0f), v2 + new Vector2(1f, 0f), 0f, color4);
                    flatBatch2D.QueueLine(v3, v4, 0f, color3);
                    flatBatch2D.QueueLine(v3 + new Vector2(0f, 1f), v4 + new Vector2(0f, 1f), 0f, color4);
                }
            }
            Matrix            matrix2  = Matrix.Identity;
            FurnitureGeometry geometry = Design.Geometry;

            for (int k = 0; k < 6; k++)
            {
                Color globalColorTransform = base.GlobalColorTransform;
                if (Mode == ViewMode.Perspective)
                {
                    float num4 = LightingManager.LightIntensityByLightValueAndFace[15 + 16 * CellFace.OppositeFace(k)];
                    globalColorTransform *= new Color(num4, num4, num4);
                }
                if (geometry.SubsetOpaqueByFace[k] != null)
                {
                    BlocksManager.DrawMeshBlock(m_primitivesRenderer3d, geometry.SubsetOpaqueByFace[k], globalColorTransform, 1f, ref matrix2, null);
                }
                if (geometry.SubsetAlphaTestByFace[k] != null)
                {
                    BlocksManager.DrawMeshBlock(m_primitivesRenderer3d, geometry.SubsetAlphaTestByFace[k], globalColorTransform, 1f, ref matrix2, null);
                }
            }
            m_primitivesRenderer3d.Flush(matrix);
            m_primitivesRenderer2d.Flush();
        }
Esempio n. 16
0
        public override void Draw(DrawContext dc)
        {
            if (FillColor.A == 0 && (OutlineColor.A == 0 || OutlineThickness <= 0f))
            {
                return;
            }
            DepthStencilState depthStencilState = DepthWriteEnabled ? DepthStencilState.DepthWrite : DepthStencilState.None;
            Matrix            m  = base.GlobalTransform;
            Vector2           v  = Vector2.Zero;
            Vector2           v2 = new Vector2(base.ActualSize.X, 0f);
            Vector2           v3 = base.ActualSize;
            Vector2           v4 = new Vector2(0f, base.ActualSize.Y);

            Vector2.Transform(ref v, ref m, out Vector2 result);
            Vector2.Transform(ref v2, ref m, out Vector2 result2);
            Vector2.Transform(ref v3, ref m, out Vector2 result3);
            Vector2.Transform(ref v4, ref m, out Vector2 result4);
            Color color = FillColor * base.GlobalColorTransform;

            if (color.A != 0)
            {
                if (Subtexture != null)
                {
                    SamplerState    samplerState    = (!TextureWrap) ? (TextureLinearFilter ? SamplerState.LinearClamp : SamplerState.PointClamp) : (TextureLinearFilter ? SamplerState.LinearWrap : SamplerState.PointWrap);
                    TexturedBatch2D texturedBatch2D = dc.PrimitivesRenderer2D.TexturedBatch(Subtexture.Texture, useAlphaTest: false, 0, depthStencilState, null, null, samplerState);
                    Vector2         zero            = default(Vector2);
                    Vector2         texCoord;
                    Vector2         texCoord2 = default(Vector2);
                    Vector2         texCoord3;
                    if (TextureWrap)
                    {
                        zero      = Vector2.Zero;
                        texCoord  = new Vector2(base.ActualSize.X / (float)Subtexture.Texture.Width, 0f);
                        texCoord2 = new Vector2(base.ActualSize.X / (float)Subtexture.Texture.Width, base.ActualSize.Y / (float)Subtexture.Texture.Height);
                        texCoord3 = new Vector2(0f, base.ActualSize.Y / (float)Subtexture.Texture.Height);
                    }
                    else
                    {
                        zero.X      = MathUtils.Lerp(Subtexture.TopLeft.X, Subtexture.BottomRight.X, Texcoord1.X);
                        zero.Y      = MathUtils.Lerp(Subtexture.TopLeft.Y, Subtexture.BottomRight.Y, Texcoord1.Y);
                        texCoord2.X = MathUtils.Lerp(Subtexture.TopLeft.X, Subtexture.BottomRight.X, Texcoord2.X);
                        texCoord2.Y = MathUtils.Lerp(Subtexture.TopLeft.Y, Subtexture.BottomRight.Y, Texcoord2.Y);
                        texCoord    = new Vector2(texCoord2.X, zero.Y);
                        texCoord3   = new Vector2(zero.X, texCoord2.Y);
                    }
                    if (FlipHorizontal)
                    {
                        Utilities.Swap(ref zero.X, ref texCoord.X);
                        Utilities.Swap(ref texCoord2.X, ref texCoord3.X);
                    }
                    if (FlipVertical)
                    {
                        Utilities.Swap(ref zero.Y, ref texCoord2.Y);
                        Utilities.Swap(ref texCoord.Y, ref texCoord3.Y);
                    }
                    texturedBatch2D.QueueQuad(result, result2, result3, result4, Depth, zero, texCoord, texCoord2, texCoord3, color);
                }
                else
                {
                    dc.PrimitivesRenderer2D.FlatBatch(1, depthStencilState).QueueQuad(result, result2, result3, result4, Depth, color);
                }
            }
            Color color2 = OutlineColor * base.GlobalColorTransform;

            if (color2.A != 0 && OutlineThickness > 0f)
            {
                FlatBatch2D flatBatch2D = dc.PrimitivesRenderer2D.FlatBatch(1, depthStencilState);
                Vector2     vector      = Vector2.Normalize(base.GlobalTransform.Right.XY);
                Vector2     v5          = -Vector2.Normalize(base.GlobalTransform.Up.XY);
                int         num         = (int)MathUtils.Max(MathUtils.Round(OutlineThickness * base.GlobalTransform.Right.Length()), 1f);
                for (int i = 0; i < num; i++)
                {
                    flatBatch2D.QueueLine(result, result2, Depth, color2);
                    flatBatch2D.QueueLine(result2, result3, Depth, color2);
                    flatBatch2D.QueueLine(result3, result4, Depth, color2);
                    flatBatch2D.QueueLine(result4, result, Depth, color2);
                    result  += vector - v5;
                    result2 += -vector - v5;
                    result3 += -vector + v5;
                    result4 += vector + v5;
                }
            }
        }
Esempio n. 17
0
        public void UpdateRenderTarget()
        {
            bool flag = false;

            foreach (GameWidget gameWidget in m_subsystemViews.GameWidgets)
            {
                bool flag2 = false;
                foreach (Vector3 lastUpdatePosition in m_lastUpdatePositions)
                {
                    if (Vector3.DistanceSquared(gameWidget.ActiveCamera.ViewPosition, lastUpdatePosition) < 4f)
                    {
                        flag2 = true;
                        break;
                    }
                }
                if (!flag2)
                {
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                return;
            }
            m_lastUpdatePositions.Clear();
            m_lastUpdatePositions.AddRange(m_subsystemViews.GameWidgets.Select((GameWidget v) => v.ActiveCamera.ViewPosition));
            m_nearTexts.Clear();
            foreach (TextData value in m_textsByPoint.Values)
            {
                Point3 point = value.Point;
                float  num   = m_subsystemViews.CalculateSquaredDistanceFromNearestView(new Vector3(point));
                if (num <= 400f)
                {
                    value.Distance = num;
                    m_nearTexts.Add(value);
                }
            }
            m_nearTexts.Sort((TextData d1, TextData d2) => Comparer <float> .Default.Compare(d1.Distance, d2.Distance));
            if (m_nearTexts.Count > 32)
            {
                m_nearTexts.RemoveRange(32, m_nearTexts.Count - 32);
            }
            foreach (TextData nearText in m_nearTexts)
            {
                nearText.ToBeRenderedFrame = Time.FrameIndex;
            }
            bool flag3 = false;

            for (int i = 0; i < MathUtils.Min(m_nearTexts.Count, 32); i++)
            {
                TextData textData = m_nearTexts[i];
                if (textData.TextureLocation.HasValue)
                {
                    continue;
                }
                int num2 = m_textureLocations.FirstIndex((TextData d) => d == null);
                if (num2 < 0)
                {
                    num2 = m_textureLocations.FirstIndex((TextData d) => d.ToBeRenderedFrame != Time.FrameIndex);
                }
                if (num2 >= 0)
                {
                    TextData textData2 = m_textureLocations[num2];
                    if (textData2 != null)
                    {
                        textData2.TextureLocation = null;
                        m_textureLocations[num2]  = null;
                    }
                    m_textureLocations[num2] = textData;
                    textData.TextureLocation = num2;
                    flag3 = true;
                }
            }
            if (flag3)
            {
                RenderTarget2D renderTarget = Display.RenderTarget;
                Display.RenderTarget = m_renderTarget;
                try
                {
                    Display.Clear(new Vector4(Color.Transparent));
                    FlatBatch2D flatBatch = m_primitivesRenderer2D.FlatBatch(0, DepthStencilState.None, null, BlendState.Opaque);

                    FontBatch2D fontBatch = m_primitivesRenderer2D.FontBatch(m_font, 1, DepthStencilState.None, null, BlendState.Opaque, SamplerState.PointClamp);
                    for (int j = 0; j < m_textureLocations.Length; j++)
                    {
                        TextData textData3 = m_textureLocations[j];
                        if (textData3 != null)
                        {
                            RenderText(fontBatch, flatBatch, textData3);
                        }
                    }
                    m_primitivesRenderer2D.Flush();
                }
                finally
                {
                    Display.RenderTarget = renderTarget;
                }
            }
        }
        public static void QueueBevelledRectangle(TexturedBatch2D texturedBatch, FlatBatch2D flatBatch, Vector2 c1, Vector2 c2, float depth, float bevelSize, Color color, Color bevelColor, Color shadowColor, float ambientLight, float directionalLight, float textureScale)
        {
            float   num     = MathUtils.Abs(bevelSize);
            Vector2 vector  = c1;
            Vector2 vector2 = c1 + new Vector2(num);
            Vector2 vector3 = c2 - new Vector2(num);
            Vector2 vector4 = c2;
            Vector2 vector5 = c2 + new Vector2(1.5f * num);
            float   x       = vector.X;
            float   x2      = vector2.X;
            float   x3      = vector3.X;
            float   x4      = vector4.X;
            float   x5      = vector5.X;
            float   y       = vector.Y;
            float   y2      = vector2.Y;
            float   y3      = vector3.Y;
            float   y4      = vector4.Y;
            float   y5      = vector5.Y;
            float   num2    = MathUtils.Saturate(((bevelSize > 0f) ? 1f : (-0.75f)) * directionalLight + ambientLight);
            float   num3    = MathUtils.Saturate(((bevelSize > 0f) ? (-0.75f) : 1f) * directionalLight + ambientLight);
            float   num4    = MathUtils.Saturate(((bevelSize > 0f) ? (-0.375f) : 0.5f) * directionalLight + ambientLight);
            float   num5    = MathUtils.Saturate(((bevelSize > 0f) ? 0.5f : (-0.375f)) * directionalLight + ambientLight);
            float   num6    = MathUtils.Saturate(0f * directionalLight + ambientLight);
            Color   color2  = new Color((byte)(num4 * (float)(int)bevelColor.R), (byte)(num4 * (float)(int)bevelColor.G), (byte)(num4 * (float)(int)bevelColor.B), bevelColor.A);
            Color   color3  = new Color((byte)(num5 * (float)(int)bevelColor.R), (byte)(num5 * (float)(int)bevelColor.G), (byte)(num5 * (float)(int)bevelColor.B), bevelColor.A);
            Color   color4  = new Color((byte)(num2 * (float)(int)bevelColor.R), (byte)(num2 * (float)(int)bevelColor.G), (byte)(num2 * (float)(int)bevelColor.B), bevelColor.A);
            Color   color5  = new Color((byte)(num3 * (float)(int)bevelColor.R), (byte)(num3 * (float)(int)bevelColor.G), (byte)(num3 * (float)(int)bevelColor.B), bevelColor.A);
            Color   color6  = new Color((byte)(num6 * (float)(int)color.R), (byte)(num6 * (float)(int)color.G), (byte)(num6 * (float)(int)color.B), color.A);

            if (texturedBatch != null)
            {
                float num7  = textureScale / (float)texturedBatch.Texture.Width;
                float num8  = textureScale / (float)texturedBatch.Texture.Height;
                float num9  = x * num7;
                float num10 = y * num8;
                float x6    = num9;
                float x7    = (x2 - x) * num7 + num9;
                float x8    = (x3 - x) * num7 + num9;
                float x9    = (x4 - x) * num7 + num9;
                float y6    = num10;
                float y7    = (y2 - y) * num8 + num10;
                float y8    = (y3 - y) * num8 + num10;
                float y9    = (y4 - y) * num8 + num10;
                if (bevelColor.A > 0)
                {
                    texturedBatch.QueueQuad(new Vector2(x, y), new Vector2(x2, y2), new Vector2(x3, y2), new Vector2(x4, y), depth, new Vector2(x6, y6), new Vector2(x7, y7), new Vector2(x8, y7), new Vector2(x9, y6), color4);
                    texturedBatch.QueueQuad(new Vector2(x3, y2), new Vector2(x3, y3), new Vector2(x4, y4), new Vector2(x4, y), depth, new Vector2(x8, y7), new Vector2(x8, y8), new Vector2(x9, y9), new Vector2(x9, y6), color3);
                    texturedBatch.QueueQuad(new Vector2(x, y4), new Vector2(x4, y4), new Vector2(x3, y3), new Vector2(x2, y3), depth, new Vector2(x6, y9), new Vector2(x9, y9), new Vector2(x8, y8), new Vector2(x7, y8), color5);
                    texturedBatch.QueueQuad(new Vector2(x, y), new Vector2(x, y4), new Vector2(x2, y3), new Vector2(x2, y2), depth, new Vector2(x6, y6), new Vector2(x6, y9), new Vector2(x7, y8), new Vector2(x7, y7), color2);
                }
                if (color6.A > 0)
                {
                    texturedBatch.QueueQuad(new Vector2(x2, y2), new Vector2(x3, y3), depth, new Vector2(x7, y7), new Vector2(x8, y8), color6);
                }
            }
            else if (flatBatch != null)
            {
                if (bevelColor.A > 0)
                {
                    flatBatch.QueueQuad(new Vector2(x, y), new Vector2(x2, y2), new Vector2(x3, y2), new Vector2(x4, y), depth, color4);
                    flatBatch.QueueQuad(new Vector2(x3, y2), new Vector2(x3, y3), new Vector2(x4, y4), new Vector2(x4, y), depth, color3);
                    flatBatch.QueueQuad(new Vector2(x, y4), new Vector2(x4, y4), new Vector2(x3, y3), new Vector2(x2, y3), depth, color5);
                    flatBatch.QueueQuad(new Vector2(x, y), new Vector2(x, y4), new Vector2(x2, y3), new Vector2(x2, y2), depth, color2);
                }
                if (color6.A > 0)
                {
                    flatBatch.QueueQuad(new Vector2(x2, y2), new Vector2(x3, y3), depth, color6);
                }
            }
            if (bevelSize > 0f && flatBatch != null && shadowColor.A > 0)
            {
                Color color7 = shadowColor;
                Color color8 = new Color(0, 0, 0, 0);
                flatBatch.QueueTriangle(new Vector2(x, y4), new Vector2(x2, y5), new Vector2(x2, y4), depth, color8, color8, color7);
                flatBatch.QueueTriangle(new Vector2(x4, y), new Vector2(x4, y2), new Vector2(x5, y2), depth, color8, color7, color8);
                flatBatch.QueueTriangle(new Vector2(x4, y4), new Vector2(x4, y5), new Vector2(x5, y4), depth, color7, color8, color8);
                flatBatch.QueueQuad(new Vector2(x2, y4), new Vector2(x2, y5), new Vector2(x4, y5), new Vector2(x4, y4), depth, color7, color8, color8, color7);
                flatBatch.QueueQuad(new Vector2(x4, y2), new Vector2(x4, y4), new Vector2(x5, y4), new Vector2(x5, y2), depth, color7, color7, color8, color8);
            }
        }
Esempio n. 19
0
        public void RenderText(FontBatch2D fontBatch, FlatBatch2D flatBatch, TextData textData)
        {
            if (!textData.TextureLocation.HasValue)
            {
                return;
            }
            List <string> list  = new List <string>();
            List <Color>  list2 = new List <Color>();

            for (int i = 0; i < textData.Lines.Length; i++)
            {
                if (!string.IsNullOrEmpty(textData.Lines[i]))
                {
                    list.Add(textData.Lines[i].Replace("\\", "").ToUpper());
                    list2.Add(textData.Colors[i]);
                }
            }
            if (list.Count <= 0)
            {
                return;
            }

            float num  = list.Max((string l) => l.Length) * 32; //宽
            float num2 = list.Count * 32;                       //高
            int   num3 = 0;

            foreach (string txt in list)
            {
                fontBatch.QueueText(list[num3], new Vector2(0, num3 * 32 + textData.TextureLocation.Value * 32), 0f, list2[num3], TextAnchor.Default);
                ++num3;
            }
            textData.UsedTextureHeight = num2;
            textData.UsedTextureWidth  = num;



            /*
             * float num3 = 4f;
             * float num4;
             * float num5;
             * if (num / num2 < num3)//宽不是高的4倍
             * {
             *      num4 = num2 * num3;//让宽变为高的4倍
             *      num5 = num2;//高度
             * }
             * else
             * {
             *      num4 = num;//绘制的宽度
             *      num5 = num / num3;//行高
             * }
             * bool flag = !string.IsNullOrEmpty(textData.Url);
             * for (int j = 0; j < list.Count; j++)
             * {
             *      Vector2 position = new Vector2(num4 / 2f, (j * 32) + textData.TextureLocation.Value * 32 + (num5 - num2) / 2f);
             *      fontBatch.QueueText(list[j], position, 0f, flag ? new Color(0, 0, 64) : list2[j], TextAnchor.HorizontalCenter);
             *      if (flag)
             *      {
             *              flatBatch.QueueLine(new Vector2(position.X - (float)(list[j].Length * 8 / 2), position.Y + 8f), new Vector2(position.X + (float)(list[j].Length * 8 / 2), position.Y + 8f), 0f, new Color(0, 0, 64));
             *      }
             * }
             * textData.UsedTextureWidth = num4;
             * textData.UsedTextureHeight = num5;
             */
        }