예제 #1
0
 public void FPGRefresh()
 {
     lvContent.Items.Clear();
     lvContent.LargeImageList = new ImageList()
     {
         ImageSize = new Size(50, 50),
         ColorDepth = ColorDepth.Depth32Bit
     };
     Gpk = GPK.Load(Filename);
     foreach (GPBitmap bmp in Gpk.Bitmaps)
     {
         lvContent.LargeImageList.Images.Add(bmp.Code.ToString(), bmp.Bitmap);
         lvContent.Items.Add(new ListViewItem() { Text = bmp.Code.ToString().PadLeft(3, '0'), ImageKey = bmp.Code.ToString(), Tag = bmp });
     }
     Gpk.Save(Filename);
     WinAPI.ListViewItem_SetSpacing(lvContent, 55, 70);
     UIRefresh();
 }
예제 #2
0
        public static GPK Load(String filename)
        {
            GPK rv = new GPK(filename);

            ZIP z = new ZIP(filename);
            z.Open();

            String type = z.ExtractFileToString("Type.txt");
            switch (type.ToUpperInvariant().Trim())
            {
                case "GFX":
                    rv.PackageType = GPKType.Graphics;
                    break;
                case "FNT":
                    rv.PackageType = GPKType.Font;
                    break;
            }

            foreach(ZipStorer.ZipFileEntry zf in z.ListFiles().Where(x => x.FilenameInZip != "Type.txt"))
            {
                MemoryStream ms = new MemoryStream();
                if(z.ExtractFileToStream(zf, ref ms))
                {
                    int code = -1;
                    String name = String.Empty;
                    if (zf.FilenameInZip.Contains("_"))
                    {
                        code = int.Parse(zf.FilenameInZip.Substring(0, zf.FilenameInZip.IndexOf('_')));
                        name = zf.FilenameInZip.Substring(zf.FilenameInZip.IndexOf('_') + 1);
                    }
                    else
                    {
                        code = int.Parse(zf.FilenameInZip.Substring(0, zf.FilenameInZip.IndexOf(".")));
                        name = zf.FilenameInZip;
                    }
                    GPBitmap bmp = new GPBitmap()
                    {
                        Code = code,
                        Name = name,
                        Filename = zf.FilenameInZip,
                        Bitmap = Image.FromStream(ms)
                    };
                    bmp.Name = bmp.Name.Substring(0, bmp.Name.LastIndexOf('.'));
                    bmp.Size = bmp.Bitmap.Size;
                    ms.Position = 0;
                    PNG p = new PNG(ms);
                    String tmp = String.Empty;
                    foreach (PNG.PNGChunk c in p.Chunks.Where(x => x.Type == "tEXt"))
                    {
                        switch (c.ToString().Split('=')[0])
                        {
                            case "Description":
                                bmp.Description = c.ToString().Substring(c.ToString().IndexOf('=') + 1);
                                break;
                            case "ControlPoints":
                                foreach (String cp in c.ToString().Substring(c.ToString().IndexOf('=') + 1).Split('|'))
                                    bmp.ControlPoints.Add(int.Parse(cp.Split('=')[0]), new Point(int.Parse(cp.Split('=')[1].Split(',')[0]), int.Parse(cp.Split('=')[1].Split(',')[1])));
                                break;
                            case "OffsetPos":
                                tmp = c.ToString().Substring(c.ToString().IndexOf('=') + 1);
                                bmp.OffsetPosition = new Point(int.Parse(tmp.Split(',')[0]), int.Parse(tmp.Split(',')[1]));
                                break;
                            case "OffsetSize":
                                tmp = c.ToString().Substring(c.ToString().IndexOf('=') + 1);
                                bmp.OffsetSize = new Size(int.Parse(tmp.Split(',')[0]), int.Parse(tmp.Split(',')[1]));
                                break;
                        }
                    }
                    if (bmp.ControlPoints.Count == 0)
                        bmp.ControlPoints.Add(0, new Point(bmp.Bitmap.Size.Width / 2, bmp.Bitmap.Size.Height / 2));
                    bmp.Center = bmp.ControlPoints[0];
                    ms.Close(); ms.Dispose();
                    rv.Bitmaps.Add(bmp);
                }
            }

            z.Close();
            rv._filename = filename;
            return rv;
        }
예제 #3
0
 private void GPKOpen(String filename)
 {
     Gpk = GPK.Load(filename);
     if (Gpk.PackageType == GPK.GPKType.Font)
         MessageBox.Show("Warning! The GPK editor is not suited for editing Font files yet. If you make changes here, the font might end up corrupted in your game. This is to be fixed soon, but it's not ready yet.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     Filename = filename;
     FPGRefresh();
 }
예제 #4
0
 private void tsNew_Click(object sender, EventArgs e)
 {
     SaveFileDialog dlg = new SaveFileDialog()
     {
         AddExtension = true,
         AutoUpgradeEnabled = true,
         CheckFileExists = false,
         CheckPathExists = true,
         OverwritePrompt = true,
         DefaultExt = "*.zip",
         Filter = "GPK Package|*.zip",
         SupportMultiDottedExtensions = false,
         Title = "New GPK",
         ValidateNames = true
     };
     dlg.ShowDialog();
     if (dlg.FileName.Length > 0)
     {
         Gpk = GPK.Create(GPK.GPKType.Graphics, dlg.FileName);
         Filename = dlg.FileName;
         FPGRefresh();
     }
 }
예제 #5
0
        private void GPKAdd(String filename)
        {
            if (!tsAdd.Enabled)
                return;

            FileInfo fi = new FileInfo(filename);

            Image dImage = Image.FromFile(fi.FullName);
            Image mImage = new Bitmap(dImage);
            dImage.Dispose();

            Gpk = GPK.Load(Filename);
            Gpk.Open();

            // TODO: Prevent > 999
            GPBitmap bmp = new GPBitmap()
            {
                Code = Gpk.Bitmaps.Count > 0 ? Gpk.Bitmaps.Max(x => x.Code) + 1 : 1,
                Description = fi.Name,
                Filename = fi.Name,
                Size = mImage.Size,
                Center = new Point(mImage.Size.Width / 2, mImage.Size.Height / 2),
                ControlPoints = new Dictionary<int, Point>(),
                Bitmap = mImage
            };

            if(Gpk.PackageType == GPK.GPKType.Graphics)
                bmp.Save(Gpk.TempFolder + bmp.Code.ToString().PadLeft(3, '0') + "_" + bmp.Filename);
            else
                bmp.Save(Gpk.TempFolder + bmp.Code.ToString().PadLeft(3, '0'));

            Gpk.Close();
        }