Exemple #1
0
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (sfdDataFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (selectedObj is NisPackFile)
                {
                    NisPackFile file = (selectedObj as NisPackFile);
                    file.ParentFile.ExtractFile(file, sfdDataFile.FileName);
                }
                else if (selectedObj is PacFile)
                {
                    PacFile file = (selectedObj as PacFile);
                    file.ParentFile.ExtractFile(file, sfdDataFile.FileName);
                }
                else if (selectedObj is ImageInformation)
                {
                    (selectedObj as ImageInformation).Bitmap.Save(sfdDataFile.FileName);
                }
                else if (selectedObj is SpriteData)
                {
                    (selectedObj as SpriteData).Image.Save(sfdDataFile.FileName);
                }
                else if (selectedObj is TxpImage)
                {
                    (selectedObj as TxpImage).Image.Save(sfdDataFile.FileName);
                }

                sfdDataFile.FileName = Path.GetFileName(sfdDataFile.FileName);
            }
        }
Exemple #2
0
        private void tvObject_AfterSelect(object sender, TreeViewEventArgs e)
        {
            pgObject.SelectedObject = e.Node.Tag;

            /* TODO: a more sensible way of encapsulating rendering-related code instead of this mess and Render() below... */

            ClearObjects();

            if (selectedObj is NisPackFile)
            {
                NisPackFile file = (selectedObj as NisPackFile);

                e.Node.ContextMenuStrip = cmsTreeNode;
                sfdDataFile.Filter      = "All Files (*.*)|*.*";
                sfdDataFile.FileName    = file.DecompressedFilename;

                if (e.Node.Nodes.Count == 0)
                {
                    if (file.DetectedFileType != null)
                    {
                        string path = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + "_" + file.DecompressedFilename);

                        file.ParentFile.ExtractFile(file, path);
                        object tempObject = (BaseFile)Activator.CreateInstance(file.DetectedFileType, new object[] { path });
                        e.Node.Nodes.Add(FileHelpers.TraverseObject(e.Node, file.DecompressedFilename, tempObject, true));

                        if (File.Exists(path))
                        {
                            File.Delete(path);
                        }
                    }
                }
            }
            else if (selectedObj is PacFile)
            {
                PacFile file = (selectedObj as PacFile);

                e.Node.ContextMenuStrip = cmsTreeNode;
                sfdDataFile.Filter      = "All Files (*.*)|*.*";
                sfdDataFile.FileName    = file.Filename;

                if (e.Node.Nodes.Count == 0)
                {
                    if (file.DetectedFileType != null)
                    {
                        string path = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + "_" + file.Filename);

                        file.ParentFile.ExtractFile(file, path);
                        object tempObject = (BaseFile)Activator.CreateInstance(file.DetectedFileType, new object[] { path });
                        e.Node.Nodes.Add(FileHelpers.TraverseObject(e.Node, file.Filename, tempObject, true));

                        if (File.Exists(path))
                        {
                            File.Delete(path);
                        }
                    }
                }
            }
            else if (selectedObj is ImageInformation)
            {
                e.Node.ContextMenuStrip = cmsTreeNode;
                sfdDataFile.Filter      = "Image Files (*.png)|*.png|All Files (*.*)|*.*";

                ImageInformation image = (selectedObj as ImageInformation);
                glObjectNames.Add(image.PrepareRender(glHelper));

                render3D = false;
            }
            else if (selectedObj is SpriteData)
            {
                e.Node.ContextMenuStrip = cmsTreeNode;
                sfdDataFile.Filter      = "Image Files (*.png)|*.png|All Files (*.*)|*.*";

                SpriteData sprite = (selectedObj as SpriteData);
                glObjectNames.Add(sprite.PrepareRender(glHelper));

                render3D = false;
            }
            else if (selectedObj is ObfPrimitiveListEntry)
            {
                ObfPrimitiveListEntry primitiveListEntry = (selectedObj as ObfPrimitiveListEntry);
                string primitiveListName = primitiveListEntry.PrepareRender(glHelper);

                glObjectNames.Add(primitiveListName);
                //if (!glObjectMatrixMap.ContainsKey(primitiveListName))
                glObjectMatrixMap.Add(primitiveListName, Matrix4.Identity);

                render3D = true;
            }
            else if (selectedObj is ObfGroupListEntry)
            {
                ObfGroupListEntry groupListEntry = (selectedObj as ObfGroupListEntry);
                List <string>     groupListNames = groupListEntry.PrepareRender(glHelper);

                glObjectNames.AddRange(groupListNames);
                foreach (string groupListName in groupListNames)
                {
                    if (!glObjectMatrixMap.ContainsKey(groupListName))
                    {
                        glObjectMatrixMap.Add(groupListName, Matrix4.Identity);
                    }
                }

                render3D = true;
            }
            else if (selectedObj is ObfNodeListEntry)
            {
                ObfNodeListEntry nodeListEntry = (selectedObj as ObfNodeListEntry);

                if (nodeListEntry.Group != null)
                {
                    List <string> nodeListNames = nodeListEntry.Group.PrepareRender(glHelper);

                    glObjectNames.AddRange(nodeListNames);
                    foreach (string nodeListName in nodeListNames)
                    {
                        if (!glObjectMatrixMap.ContainsKey(nodeListName))
                        {
                            glObjectMatrixMap.Add(nodeListName, nodeListEntry.GetTransformationMatrix(0));
                        }
                    }
                }

                render3D = true;
            }
            else if (selectedObj is ObfObjectListEntry)
            {
                ObfObjectListEntry objectListEntry = (selectedObj as ObfObjectListEntry);

                foreach (ObfNodeListEntry nodeListEntry in objectListEntry.Nodes.Where(x => x.Group != null))
                {
                    List <string> nodeListNames = nodeListEntry.Group.PrepareRender(glHelper);

                    glObjectNames.AddRange(nodeListNames);
                    foreach (string nodeListName in nodeListNames)
                    {
                        if (!glObjectMatrixMap.ContainsKey(nodeListName))
                        {
                            glObjectMatrixMap.Add(nodeListName, nodeListEntry.GetTransformationMatrix(0));
                        }
                    }
                }

                render3D = true;
            }
            else if (selectedObj is MapChr)
            {
                MapChr mapChrFile = (selectedObj as MapChr);

                /* TEMP map chr unit paint test thing */
                if (Environment.MachineName == "NANAMI-X")  // :P
                {
                    const int unitSize = 6;

                    using (Bitmap bmp = new Bitmap(512, 512))
                    {
                        using (Graphics g = Graphics.FromImage(bmp))
                        {
                            g.Clear(Color.Black);

                            int centerX = bmp.Width / 2;
                            int centerY = bmp.Height / 2;

                            foreach (MapChrUnit unit in mapChrFile.Units)
                            {
                                g.FillRectangle(Brushes.Gray, new Rectangle(unit.PositionX, unit.PositionZ, unitSize, unitSize));
                                g.DrawString(string.Format("{0}\n{1}\n{2}", unit.PositionX, unit.PositionY, unit.PositionZ), DefaultFont, Brushes.White, unit.PositionX, unit.PositionZ);
                            }
                        }
                        bmp.Save(@"C:\temp\d4-map.png");
                    }
                }

                //todo!
            }
            else if (selectedObj is TxpImage)
            {
                e.Node.ContextMenuStrip = cmsTreeNode;
                sfdDataFile.Filter      = "Image Files (*.png)|*.png|All Files (*.*)|*.*";

                TxpImage txp = (selectedObj as TxpImage);
                glObjectNames.Add(txp.PrepareRender(glHelper));

                render3D = false;
            }

            animCounter = 0;
            maxCounter  = 0;
        }