Ejemplo n.º 1
0
        public static bool ReadSubImageFile(string filePath, out SubImage subImage)
        {
            subImage = new SubImage(filePath);

            string rawTextFile;

            if (!ResourceManager.Instance.GetTextFile(filePath, out rawTextFile, true))
            {
                return(false);
            }

            List <string> textFile = FileHandler.StringToList(rawTextFile);

            for (int i = 0; i < textFile.Count; i++)
            {
                SubImageProperty subImageProperty;
                if (!ParseConfigLine(i, textFile[i], out subImageProperty))
                {
                    continue;
                }

                subImage.properties.Add(subImageProperty);
            }

            return(true);
        }
Ejemplo n.º 2
0
        //////////////////////////////////////////////////////////////////
        ///// Manager Operations

        public void RefreshUI()
        {
            if (SubImageManager.Instance.loadingSubs)
            {
                return;
            }

            if (ImageManager.Instance.image != null)
            {
                MainForm.openSubToolStripMenuItem.Enabled = true;
                MainForm.saveSubToolStripMenuItem.Enabled = true;
                MainForm.saveAllToolStripMenuItem.Enabled = true;
                MainForm.SubImageStripDropDown.Enabled    = true;
                MainForm.ImageToolStripDropDown.Enabled   = true;
            }

            if (SubImageManager.Instance.subImageList.Count() == 0)
            {
                MainForm.editSubToolStripMenuItem.Enabled   = false;
                MainForm.removeSubToolStripMenuItem.Enabled = false;
            }
            else
            {
                MainForm.editSubToolStripMenuItem.Enabled   = true;
                MainForm.removeSubToolStripMenuItem.Enabled = true;
                MainForm.editSubToolStripMenuItem.DropDownItems.Clear();
                MainForm.removeSubToolStripMenuItem.DropDownItems.Clear();

                for (int i = 0; i < SubImageManager.Instance.subImageList.Count; i++)
                {
                    SubImage subImage = SubImageManager.Instance.subImageList[i];

                    ToolStripMenuItem removeOption = new ToolStripMenuItem();
                    removeOption.Text     = subImage.name;
                    removeOption.Tag      = i;
                    removeOption.MouseUp += OnRemoveSubClick;


                    ToolStripMenuItem editOption = new ToolStripMenuItem();
                    editOption.Text     = subImage.name;
                    editOption.Tag      = i;
                    editOption.MouseUp += OnEditSubClick;

                    if (SubImageManager.Instance.selectedSubIndex == i)
                    {
                        removeOption.Image = Properties.Resources._600px_Green_check_svg;
                        editOption.Image   = Properties.Resources._600px_Green_check_svg;
                    }

                    MainForm.removeSubToolStripMenuItem.DropDownItems.Add(removeOption);
                    MainForm.editSubToolStripMenuItem.DropDownItems.Add(editOption);
                }
            }

            MainForm.displayImageBox.Invalidate();
        }
Ejemplo n.º 3
0
        public void SaveSubImage(SubImage subImage, string path, string extension)
        {
            Bitmap bmp = UsefulThings.WinForms.Imaging.CreateBitmap(ImageManager.Instance.image.GetWPFBitmap(), false);

            UIManager.Instance.MainForm.displayImageBox.Image = bmp;
            int top = 0, bottom = 0, left = 0, right = 0;

            foreach (var property in subImage.properties)
            {
                if (property.name == "top")
                {
                    top = Convert.ToInt32(property.value);
                }

                if (property.name == "bottom")
                {
                    bottom = Convert.ToInt32(property.value);
                }

                if (property.name == "left")
                {
                    left = Convert.ToInt32(property.value);
                }

                if (property.name == "right")
                {
                    right = Convert.ToInt32(property.value);
                }
            }

            Rectangle rect = Rectangle.FromLTRB(left, top, right, bottom);

            if (rect.Width <= 0 || rect.Height <= 0)
            {
                LogManager.Instance.MsgError("Invalid sub image on file " + subImage.path);
                return;
            }

            try
            {
                bmp = bmp.Clone(rect, bmp.PixelFormat);

                using (var stream = new MemoryStream())
                {
                    bmp.Save(stream, ImageFormat.Png);
                    ImageEngineImage img = new ImageEngineImage(stream.ToArray());
                    img.Save(path + @"\" + subImage.name + "." + extension, ImageEngineFormat.DDS_DXT3, MipHandling.KeepExisting, 0, 0, false);
                }
            }
            catch (Exception e)
            {
                LogManager.Instance.MsgError("Could not save image " + path + @"\" + subImage.name + "." + extension
                                             + "\nError: " + e.Message);
            }
        }
Ejemplo n.º 4
0
        //////////////////////////////////////////////////////////////////
        ///// Manager Operations

        public void AddSubImage(SubImage subImage)
        {
            subImageList.Add(subImage);

            if (selectedSubIndex == -1 || selectedSubIndex == subImageList.Count - 1)
            {
                selectedSubIndex += 1;
            }

            UIManager.Instance.RefreshUI();
        }