Exemplo n.º 1
0
        public static Label LoadFrom(StreamReader reader)
        {
            string currentLine = reader.ReadLine();

            if (string.IsNullOrEmpty(currentLine))
            {
                return(null);
            }

            int categoryEndIndex = currentLine.IndexOf(':', 1);

            if (categoryEndIndex < 0 || categoryEndIndex + 8 > currentLine.Length)
            {
                return(null);
            }
            string categoryString = currentLine.Substring(1, categoryEndIndex - 1);

            LabelCategory category = Atlas.GetLabelCategory(categoryString);

            if (category == null)
            {
                return(null);
            }

            string[] theOtherParts = currentLine.Substring(categoryEndIndex + 2).Split(new char[] { ' ' }, 4);

            short x;

            if (!short.TryParse(theOtherParts[0], out x))
            {
                return(null);
            }

            short y;

            if (!short.TryParse(theOtherParts[1], out y))
            {
                return(null);
            }

            byte facet;

            if (!byte.TryParse(theOtherParts[2], out facet))
            {
                return(null);
            }

            Label l = new Label();

            l.Category = category;
            l.X        = x;
            l.Y        = y;
            l.Facet    = facet;
            l.Text     = theOtherParts[3];
            return(l);
        }
Exemplo n.º 2
0
        private static void LoadLabelCategories()
        {
            string labelCategoryNamesFilePath = Path.Combine(Application.StartupPath, "Icons.txt");

            if (!File.Exists(labelCategoryNamesFilePath))
            {
                using (FileStream outStream = new FileStream(labelCategoryNamesFilePath, FileMode.Create))
                {
                    using (StreamWriter writer = new StreamWriter(outStream))
                    {
                        writer.Write(Resources.MapLabelCategories);
                    }
                }
            }

            string labelCategoryIconsFilePath = Path.Combine(Application.StartupPath, "Icons.png");

            if (!File.Exists(labelCategoryIconsFilePath))
            {
                using (FileStream outStream = new FileStream(labelCategoryIconsFilePath, FileMode.Create))
                {
                    Resources.LabelCategoryIcons.Save(outStream, ImageFormat.Png);
                }
            }


            using (StreamReader labelReader = new StreamReader(labelCategoryNamesFilePath))
            {
                using (Image icons = Image.FromFile(labelCategoryIconsFilePath))
                {
                    int iconX = 0;
                    int iconY = 0;

                    string labelName;
                    do
                    {
                        labelName = labelReader.ReadLine();
                        if (string.IsNullOrEmpty(labelName))
                        {
                            continue;
                        }

                        Bitmap labelIcon = new Bitmap(31, 31);
                        using (Graphics g = Graphics.FromImage(labelIcon))
                        {
                            g.DrawImage(icons, new Rectangle(0, 0, 31, 31), iconX, iconY, 31, 31, GraphicsUnit.Pixel);
                        }

                        iconX += 32;
                        if (iconX >= icons.Width)
                        {
                            iconY += 32;
                            iconX  = 0;
                        }

                        LabelCategory category = new LabelCategory();
                        category.Name = labelName;
                        category.Icon = labelIcon;
                        Atlas.LabelCategories[labelName.ToUpper()] = category;
                    } while (labelName != null);
                }
            }
        }
Exemplo n.º 3
0
        private static void LoadLabelCategories()
        {
            string labelCategoryNamesFilePath = Path.Combine(Application.StartupPath, "Icons.txt");
            if (!File.Exists(labelCategoryNamesFilePath))
            {
                using (FileStream outStream = new FileStream(labelCategoryNamesFilePath, FileMode.Create))
                {
                    using (StreamWriter writer = new StreamWriter(outStream))
                    {
                        writer.Write(Resources.MapLabelCategories);
                    }
                }
            }

            string labelCategoryIconsFilePath = Path.Combine(Application.StartupPath, "Icons.png");
            if (!File.Exists(labelCategoryIconsFilePath))
            {

                using (FileStream outStream = new FileStream(labelCategoryIconsFilePath, FileMode.Create))
                {
                    Resources.LabelCategoryIcons.Save(outStream, ImageFormat.Png);
                }
            }


            using (StreamReader labelReader = new StreamReader(labelCategoryNamesFilePath))
            {
                using (Image icons = Image.FromFile(labelCategoryIconsFilePath))
                {
                    int iconX = 0;
                    int iconY = 0;

                    string labelName;
                    do
                    {
                        labelName = labelReader.ReadLine();
                        if (string.IsNullOrEmpty(labelName))
                        {
                            continue;
                        }

                        Bitmap labelIcon = new Bitmap(31, 31);
                        using (Graphics g = Graphics.FromImage(labelIcon))
                        {
                            g.DrawImage(icons, new Rectangle(0, 0, 31, 31), iconX, iconY, 31, 31, GraphicsUnit.Pixel);
                        }

                        iconX += 32;
                        if (iconX >= icons.Width)
                        {
                            iconY += 32;
                            iconX = 0;
                        }

                        LabelCategory category = new LabelCategory();
                        category.Name = labelName;
                        category.Icon = labelIcon;
                        Atlas.LabelCategories[labelName.ToUpper()] = category;

                    } while (labelName != null);
                }
            }
        }