Esempio n. 1
0
    private static Color ReadColorCells(string[] cells, Color _default)
    {
        if (int.TryParse(cells[2], out int r) &&
            int.TryParse(cells[3], out int g) &&
            int.TryParse(cells[4], out int b))
        {
            return(ColorExtensions.FromRGB(r, g, b));
        }

        return(_default);
    }
Esempio n. 2
0
    private static List <Typology> Parse(StreamReader sr)
    {
        List <Typology> typologies = new List <Typology>();

        // Parse header
        string line    = sr.ReadLine();
        var    matches = CsvHelper.regex.Matches(line);

        string[] names = new string[matches.Count];

        Dictionary <string, TypologyInfo> infos = new Dictionary <string, TypologyInfo>();

        // Separate name and unit
        for (int i = 0; i < matches.Count; ++i)
        {
            string[] toSplit = matches[i].Groups[2].Value.Split('|');
            names[i] = toSplit[0].Trim();

            if (i >= FirstAttributeColumn && !infos.ContainsKey(names[i]))
            {
                if (names[i][0].Equals('_'))
                {
                    continue;
                }

                if (toSplit.Length > 1)
                {
                    var units = toSplit[1].Trim();
                    infos.Add(names[i], new TypologyInfo {
                        units   = (units == "/") ? "" : units,
                        isRatio = units == "/"                        //"%"
                    });
                }
                else
                {
                    infos.Add(names[i], new TypologyInfo {
                        units = "N/A"
                    });
                }
            }
        }

        while ((line = sr.ReadLine()) != null)
        {
            matches = CsvHelper.regex.Matches(line);
            string typologyName = matches[0].Groups[2].Value;

            if (string.IsNullOrEmpty(typologyName))
            {
                continue;
            }

            Typology typology = new Typology
            {
                name        = typologyName,
                description = matches[2].Groups[2].Value.Trim(),
                author      = matches[3].Groups[2].Value.Trim(),
                color       = ColorExtensions.FromRGB(int.Parse(matches[4].Groups[2].Value), int.Parse(matches[5].Groups[2].Value), int.Parse(matches[6].Groups[2].Value)),
                values      = new Dictionary <string, float>()
            };

            string sites = matches[1].Groups[2].Value;
            if (!string.IsNullOrWhiteSpace(sites))
            {
                typology.sites = new HashSet <string>(sites.Trim().Split(','));
            }

            // Add a value for each column (data layer)
            for (int i = FirstAttributeColumn; i < matches.Count; ++i)
            {
                if (float.TryParse(matches[i].Groups[2].Value, out float value))
                {
                    if (names[i][0].Equals('_'))
                    {
                        continue;
                    }

                    typology.values.Add(names[i], value);
                }
            }
            typologies.Add(typology);
        }

        Typology.info = infos;

        return(typologies);
    }
Esempio n. 3
0
        public static AutoColorPalette FromFileContent(string name, string[] fileContentLines)
        {
            var colors = fileContentLines.Select(x => ColorExtensions.FromRGB(x));

            return(new AutoColorPalette(name, colors));
        }
Esempio n. 4
0
        public static void RenderSpriteLine(DynamicFontRenderer renderer, UIMarkupToken token, Vector3 position, UIRenderData destination)
        {
            string[] args = token.GetAttribute(0)?.m_Value?.value?.Split(new char[] { ',' }, 3);
            if (args == null || args.Length != 3)
            {
                LogUtils.DoErrorLog($"INVALID ARGUMENT: {token.GetAttribute(0)?.m_Value?.value ?? "<NULL>"}");
                return;
            }

            UITextureAtlas.SpriteInfo spriteInfo = renderer.spriteAtlas[args[0]];
            if (spriteInfo == null)
            {
                CODebugBase <InternalLogChannel> .Warn(InternalLogChannel.UI, "Missing sprite " + args[0] + " in " + renderer.spriteAtlas.name);
            }
            else
            {
                var midLine = new Vector3(position.x, position.y - (((UIDynamicFont)renderer.font).baseline * renderer.textScale / 2));

                Texture2D texture        = renderer.spriteAtlas.texture;
                float     calcHeight     = ((UIDynamicFont)renderer.font).baseline * renderer.textScale * 2f;
                float     calcProportion = spriteInfo.region.width * texture.width / (spriteInfo.region.height * texture.height);
                float     calcWidth      = Mathf.CeilToInt(calcHeight * calcProportion);

                int height = Mathf.CeilToInt(calcHeight);
                int width  = Mathf.CeilToInt(calcWidth);

                Color32 bgColor        = ColorExtensions.FromRGB(args[1]);
                Color32 color2         = ApplyOpacity(renderer, bgColor);
                var     size           = new Vector3(width, height);
                Vector2 textDimensions = MeasureTextWidth(renderer, args[2], renderer.textScale, out Vector2 yBounds);

                float imageProportions = width / spriteInfo.width;

                float borderWidth = renderer.textScale * 2;

                float textBoundHeight = height - (spriteInfo.border.vertical * imageProportions) - borderWidth;
                float textBoundWidth  = width - (spriteInfo.border.horizontal * imageProportions) - borderWidth;

                var textAreaSize = new Vector4((spriteInfo.border.left * imageProportions) + (borderWidth / 2), (-spriteInfo.border.top + spriteInfo.border.bottom) * imageProportions / 2, textBoundWidth, textBoundHeight);

                float textScale = renderer.textScale;
                float multipler = Mathf.Min(Mathf.Min(3.5f, textAreaSize.z / textDimensions.x), Mathf.Min(3.5f, textAreaSize.w / textDimensions.y));
                if (multipler > 1)
                {
                    textScale     *= 1 + ((multipler - 1) / 2.1f);
                    multipler      = 1;
                    textDimensions = MeasureTextWidth(renderer, args[2], textScale, out yBounds);
                }
                float midLineOffset = (((UIDynamicFont)renderer.font).baseline / 2 * renderer.textScale);

                Color contrastColor = KlyteMonoUtils.ContrastColor(bgColor);

                RenderSprite(renderer.spriteBuffer, new RenderOptions
                {
                    atlas         = renderer.spriteAtlas,
                    color         = contrastColor,
                    fillAmount    = 1f,
                    flip          = UISpriteFlip.None,
                    offset        = position - new Vector3(0, -(height / 2) + midLineOffset),
                    pixelsToUnits = renderer.pixelRatio,
                    size          = size,
                    spriteInfo    = spriteInfo
                });

                RenderSprite(renderer.spriteBuffer, new RenderOptions
                {
                    atlas         = renderer.spriteAtlas,
                    color         = color2,
                    fillAmount    = 1f,
                    flip          = UISpriteFlip.None,
                    offset        = position - new Vector3(0, -(height / 2) + midLineOffset) + (new Vector3(borderWidth, -borderWidth) / 2),
                    pixelsToUnits = renderer.pixelRatio,
                    size          = size - new Vector3(borderWidth, borderWidth),
                    spriteInfo    = spriteInfo
                });
                midLineOffset = ((UIDynamicFont)renderer.font).baseline * textScale;
                Vector3 targetTextPos = midLine + VectorUtils.XY_(textAreaSize) + (new Vector3(textAreaSize.z - (textDimensions.x * multipler), -textDimensions.y) / 2);
                RenderText(renderer, args[2], targetTextPos, multipler, destination, textScale, contrastColor, bgColor);
            }
        }
Esempio n. 5
0
 set => m_colorList = value?.Select(x => ColorExtensions.FromRGB(x))?.ToList() ?? new List <Color32>();