Beispiel #1
0
        public void DrawFloatingMessage(Camera camera, string message, float factor)
        {
            BitmapFont font = ContentManager.Get <BitmapFont>("Fonts/Pericles");

            if (!camera.Eye.HasValue)
            {
                Vector2 position = camera.ViewportSize / 2f;
                position.X += 0.07f * camera.ViewportSize.X * (float)MathUtils.Sin(1.7300000190734863 * Time.FrameStartTime);
                position.Y += 0.07f * camera.ViewportSize.Y * (float)MathUtils.Cos(1.1200000047683716 * Time.FrameStartTime);
                FontBatch2D fontBatch2D = m_primitivesRenderer2D.FontBatch(font, 1, DepthStencilState.None, null, BlendState.AlphaBlend);
                int         count       = fontBatch2D.TriangleVertices.Count;
                fontBatch2D.QueueText(message, position, 0f, Color.White * factor, TextAnchor.HorizontalCenter | TextAnchor.VerticalCenter, Vector2.One * camera.GameWidget.GlobalScale, Vector2.Zero);
                fontBatch2D.TransformTriangles(camera.ViewportMatrix, count);
                fontBatch2D.Flush();
            }
            else
            {
                Vector3 position2 = -4f * Vector3.UnitZ;
                position2.X += 0.28f * (float)MathUtils.Sin(1.7300000190734863 * Time.FrameStartTime);
                position2.Y += 0.28f * (float)MathUtils.Cos(1.1200000047683716 * Time.FrameStartTime);
                FontBatch3D fontBatch3D = m_primitivesRenderer3D.FontBatch(font, 1, DepthStencilState.None, RasterizerState.CullNoneScissor, BlendState.AlphaBlend);
                fontBatch3D.QueueText(message, position2, 0.008f * Vector3.UnitX, -0.008f * Vector3.UnitY, Color.White * factor, TextAnchor.HorizontalCenter | TextAnchor.VerticalCenter, Vector2.Zero);
                fontBatch3D.Flush(camera.ProjectionMatrix);
            }
        }
Beispiel #2
0
        public void Updated(int value, int count)
        {
            RenderTarget2D renderTarget = Display.RenderTarget;

            Display.RenderTarget = m_renderTarget;
            Display.Clear(Color.Transparent);
            try
            {
                string numstr  = count.ToString();
                int    usedw   = numstr.Length * 16;
                int    padding = (256 - usedw) / 2;
                //base x 128 base y 384 efont 16 all w 256
                //base x 4 y 12
                FontBatch2D fontBatch = primitivesRenderer2D.FontBatch(ILibrary.m_font, 1, DepthStencilState.None, null, BlendState.Opaque, SamplerState.PointClamp);
                fontBatch.QueueText($"{numstr}", new Vector2(128 + padding, 384), 0f, Color.White, TextAnchor.HorizontalCenter, new Vector2(4, 4), Vector2.Zero);                //不是纹理坐标
                PrimitivesRenderer3D mprimitivesRenderer3D = new PrimitivesRenderer3D();
                int   id    = Terrain.ExtractContents(value);
                Block block = BlocksManager.Blocks[id];
                DrawBlockEnvironmentData blockEnvironmentData = new DrawBlockEnvironmentData();
                Matrix m2 = Matrix.CreateLookAt(block.GetIconViewOffset(value, blockEnvironmentData), Vector3.Zero, Vector3.UnitY);
                m2 *= Matrix.CreateOrthographic(3.6f, 3.6f, -10f - 1f * 1f, 10f - 1f * 1f);
                m2 *= Matrix.CreateTranslation(0, 0.2f, 0);
                Matrix matrix = Matrix.Identity;
                blockEnvironmentData.ViewProjectionMatrix = m2;
                block.DrawBlock(mprimitivesRenderer3D, value, Color.White, 0.8f, ref matrix, blockEnvironmentData);
                mprimitivesRenderer3D.Flush(matrix);
                primitivesRenderer2D.Flush();
                Display.RenderTarget = renderTarget;
            }
            catch (Exception e) {
                Log.Information("error display" + e.ToString());
            }
        }
Beispiel #3
0
        public void DrawMessage(Camera camera, string message, float factor)
        {
            BitmapFont font = ContentManager.Get <BitmapFont>("Fonts/Pericles");

            if (!camera.Eye.HasValue)
            {
                Vector2     position    = new Vector2(camera.ViewportSize.X / 2f, camera.ViewportSize.Y - 25f);
                FontBatch2D fontBatch2D = m_primitivesRenderer2D.FontBatch(font, 0, DepthStencilState.None, null, BlendState.AlphaBlend);
                int         count       = fontBatch2D.TriangleVertices.Count;
                fontBatch2D.QueueText(message, position, 0f, Color.Gray * factor, TextAnchor.HorizontalCenter | TextAnchor.Bottom, Vector2.One * camera.GameWidget.GlobalScale, Vector2.Zero);
                fontBatch2D.TransformTriangles(camera.ViewportMatrix, count);
                fontBatch2D.Flush();
            }
            else
            {
                Vector3     position2   = -4f * Vector3.UnitZ + -0.24f / camera.ProjectionMatrix.M22 * 2f * Vector3.UnitY;
                FontBatch3D fontBatch3D = m_primitivesRenderer3D.FontBatch(font, 0, DepthStencilState.None, RasterizerState.CullNoneScissor, BlendState.AlphaBlend);
                fontBatch3D.QueueText(message, position2, 0.0104f * Vector3.UnitX, -0.0104f * Vector3.UnitY, Color.White * factor, TextAnchor.HorizontalCenter | TextAnchor.VerticalCenter, Vector2.Zero);
                fontBatch3D.Flush(camera.ProjectionMatrix);
            }
        }
Beispiel #4
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);
        }
Beispiel #5
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;
                }
            }
        }
Beispiel #6
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;
             */
        }
Beispiel #7
0
 public override void Draw(DrawContext dc)
 {
     if (!string.IsNullOrEmpty(Text) && Color.A != 0)
     {
         SamplerState samplerState = TextureLinearFilter ? SamplerState.LinearClamp : SamplerState.PointClamp;
         FontBatch2D  fontBatch2D  = dc.PrimitivesRenderer2D.FontBatch(Font, 1, DepthStencilState.None, null, null, samplerState);
         int          count        = fontBatch2D.TriangleVertices.Count;
         float        num          = 0f;
         if ((TextAnchor & TextAnchor.VerticalCenter) != 0)
         {
             float num2 = Font.GlyphHeight * FontScale * Font.Scale + (float)(m_lines.Count - 1) * ((Font.GlyphHeight + Font.Spacing.Y) * FontScale * Font.Scale + FontSpacing.Y);
             num = (base.ActualSize.Y - num2) / 2f;
         }
         else if ((TextAnchor & TextAnchor.Bottom) != 0)
         {
             float num3 = Font.GlyphHeight * FontScale * Font.Scale + (float)(m_lines.Count - 1) * ((Font.GlyphHeight + Font.Spacing.Y) * FontScale * Font.Scale + FontSpacing.Y);
             num = base.ActualSize.Y - num3;
         }
         TextAnchor anchor = TextAnchor & ~(TextAnchor.VerticalCenter | TextAnchor.Bottom);
         Color      color  = Color * base.GlobalColorTransform;
         float      num4   = CalculateLineHeight();
         foreach (string line in m_lines)
         {
             float x = 0f;
             if ((TextAnchor & TextAnchor.HorizontalCenter) != 0)
             {
                 x = base.ActualSize.X / 2f;
             }
             else if ((TextAnchor & TextAnchor.Right) != 0)
             {
                 x = base.ActualSize.X;
             }
             bool    flag   = true;
             Vector2 vector = Vector2.Zero;
             float   angle  = 0f;
             if (TextOrientation == TextOrientation.Horizontal)
             {
                 vector = new Vector2(x, num);
                 angle  = 0f;
                 _      = Display.ScissorRectangle;
                 flag   = true;
             }
             else if (TextOrientation == TextOrientation.VerticalLeft)
             {
                 vector = new Vector2(x, base.ActualSize.Y + num);
                 angle  = MathUtils.DegToRad(-90f);
                 flag   = true;
             }
             if (flag)
             {
                 if (DropShadow)
                 {
                     fontBatch2D.QueueText(line, vector + 1f * new Vector2(FontScale), 0f, new Color((byte)0, (byte)0, (byte)0, color.A), anchor, new Vector2(FontScale), FontSpacing, angle);
                 }
                 fontBatch2D.QueueText(line, vector, 0f, color, anchor, new Vector2(FontScale), FontSpacing, angle);
             }
             num += num4;
         }
         fontBatch2D.TransformTriangles(base.GlobalTransform, count);
     }
 }
Beispiel #8
0
 public override void Load(ValuesDictionary valuesDictionary)
 {
     fontBatch2D = primitivesRenderer.FontBatch(ContentManager.Get <BitmapFont>("Fonts/SignFont"));
     subsystemItemElectricBehavior = Project.FindSubsystem <SubsystemItemElectricBehavior>();
     base.Load(valuesDictionary);
 }