Esempio n. 1
0
        public void RenderSpritesToTexture(int area, ListReader <MySprite> sprites, Vector2I textureSize, Vector2 aspectRatio, Color backgroundColor, byte backgroundAlpha)
        {
            string  targetTexture = this.GenerateOffscreenTextureName(this.m_entity.EntityId, area);
            Vector2 aspectFactor  = CalcAspectFactor(textureSize, aspectRatio);
            Vector2 vector2       = CalcShift(textureSize, aspectFactor);

            for (int i = 0; i < sprites.Count; i++)
            {
                MySprite sprite  = sprites[i];
                Vector2? size    = sprite.Size;
                Vector2  vector3 = (size != null) ? size.GetValueOrDefault() : ((Vector2)textureSize);
                size = sprite.Position;
                Vector2 screenCoord = (size != null) ? size.GetValueOrDefault() : ((Vector2)(textureSize / 2));
                Color?  nullable2   = sprite.Color;
                Color   colorMask   = (nullable2 != null) ? nullable2.GetValueOrDefault() : Color.White;
                screenCoord += vector2;
                SpriteType type = sprite.Type;
                if (type != SpriteType.TEXTURE)
                {
                    if (type == SpriteType.TEXT)
                    {
                        switch (sprite.Alignment)
                        {
                        case TextAlignment.RIGHT:
                            screenCoord -= new Vector2(vector3.X, 0f);
                            break;

                        case TextAlignment.CENTER:
                            screenCoord -= new Vector2(vector3.X * 0.5f, 0f);
                            break;

                        default:
                            break;
                        }
                        MyFontDefinition definition = MyDefinitionManager.Static.GetDefinition <MyFontDefinition>(MyStringHash.GetOrCompute(sprite.FontId));
                        int textureWidthinPx        = (int)Math.Round((double)vector3.X);
                        MyRenderProxy.DrawStringAligned((definition != null) ? ((int)definition.Id.SubtypeId) : ((int)MyStringHash.GetOrCompute("Debug")), screenCoord, colorMask, sprite.Data ?? string.Empty, sprite.RotationOrScale, float.PositiveInfinity, targetTexture, textureWidthinPx, (MyRenderTextAlignmentEnum)sprite.Alignment);
                    }
                }
                else
                {
                    MyLCDTextureDefinition definition = MyDefinitionManager.Static.GetDefinition <MyLCDTextureDefinition>(MyStringHash.GetOrCompute(sprite.Data));
                    if (definition != null)
                    {
                        switch (sprite.Alignment)
                        {
                        case TextAlignment.LEFT:
                            screenCoord += new Vector2(vector3.X * 0.5f, 0f);
                            break;

                        case TextAlignment.RIGHT:
                            screenCoord -= new Vector2(vector3.X * 0.5f, 0f);
                            break;

                        default:
                            break;
                        }
                        Vector2 rightVector = new Vector2(1f, 0f);
                        if (Math.Abs(sprite.RotationOrScale) > 1E-05f)
                        {
                            rightVector = new Vector2((float)Math.Cos((double)sprite.RotationOrScale), (float)Math.Sin((double)sprite.RotationOrScale));
                        }
                        MyRenderProxy.DrawSpriteAtlas(definition.SpritePath ?? definition.TexturePath, screenCoord, Vector2.Zero, Vector2.One, rightVector, Vector2.One, colorMask, vector3 / 2f, targetTexture);
                    }
                }
            }
            backgroundColor.A = backgroundAlpha;
            uint[] renderObjectIDs = this.m_screenAreas[area].RenderObjectIDs;
            int    index           = 0;

            while ((index < renderObjectIDs.Length) && (renderObjectIDs[index] == uint.MaxValue))
            {
                index++;
            }
            if (index < renderObjectIDs.Length)
            {
                MyRenderProxy.RenderOffscreenTexture(targetTexture, new Vector2?(aspectFactor), new Color?(backgroundColor));
            }
        }