예제 #1
0
        public override void OnPopulate()
        {
            int count = 0, index = 0;

            foreach (PAT0Flags p in texFlags)
            {
                if (p.HasFlag(PAT0Flags.Enabled))
                {
                    if (!p.HasFlag(PAT0Flags.FixedTexture))
                    {
                        new PAT0TextureNode(p, index).Initialize(this, new DataSource(Header->GetTexTable(count), PAT0Texture.Size));
                    }
                    else
                    {
                        PAT0TextureNode t = new PAT0TextureNode(p, index)
                        {
                            textureCount = 1
                        };
                        t._parent = this;
                        _children.Add(t);
                        PAT0TextureEntryNode entry = new PAT0TextureEntryNode();
                        entry._frame        = 0;
                        entry._texFileIndex = Header->GetIndex(count, false);
                        entry._pltFileIndex = Header->GetIndex(count, true);
                        entry._parent       = t;
                        t._children.Add(entry);
                        entry.GetStrings();
                    }
                    count++;
                }
                index++;
            }
        }
예제 #2
0
        /// <summary>
        /// Adds an animation to the end of this one
        /// </summary>
        public void Append(PAT0Node external)
        {
            int origIntCount = FrameCount;

            FrameCount += external.FrameCount;

            foreach (PAT0EntryNode w in external.Children)
            {
                foreach (PAT0TextureNode _extEntry in w.Children)
                {
                    PAT0TextureNode _intEntry = null;
                    if ((_intEntry = (PAT0TextureNode)FindChild(w.Name + "/" + _extEntry.Name, false)) == null)
                    {
                        PAT0EntryNode wi = null;
                        if ((wi = (PAT0EntryNode)FindChild(w.Name, false)) == null)
                        {
                            AddChild(wi = new PAT0EntryNode()
                            {
                                Name = FindName(null)
                            });
                        }

                        PAT0TextureNode newIntEntry = new PAT0TextureNode(_extEntry._texFlags, _extEntry.TextureIndex);

                        wi.AddChild(newIntEntry);
                        foreach (PAT0TextureEntryNode e in _extEntry.Children)
                        {
                            PAT0TextureEntryNode q = new PAT0TextureEntryNode()
                            {
                                _frame = e._frame + origIntCount
                            };
                            newIntEntry.AddChild(q);

                            q.Texture = e.Texture;
                            q.Palette = e.Palette;
                        }
                    }
                    else
                    {
                        foreach (PAT0TextureEntryNode e in _extEntry.Children)
                        {
                            PAT0TextureEntryNode q = new PAT0TextureEntryNode()
                            {
                                _frame = e._frame + origIntCount
                            };
                            _intEntry.AddChild(q);

                            q.Texture = e.Texture;
                            q.Palette = e.Palette;
                        }
                    }
                }
            }
        }
예제 #3
0
        public void CreateEntry()
        {
            int value = 0;
            foreach (PAT0TextureNode t in Children)
                if (t._textureIndex == value)
                    value++;

            if (value == 8)
                return;

            PAT0TextureNode node = new PAT0TextureNode((PAT0Flags)7, value);
            AddChild(node);
            node.CreateEntry();
        }
        internal void ApplyPAT0Texture(PAT0TextureNode node, int index)
        {
            PAT0TextureEntryNode prev = null;

            if (node != null && index != 0 && node.Children.Count > 0)
            {
                foreach (PAT0TextureEntryNode next in node.Children)
                {
                    if (next.Index == 0)
                    {
                        prev = next;
                        continue;
                    }
                    if (prev.key <= index - 1 && next.key > index - 1)
                    {
                        break;
                    }
                    prev = next;
                }

                PAT0Texture = prev.Texture;
                PAT0Palette = prev.Palette;
                if (!PAT0Textures.ContainsKey(PAT0Texture))
                {
                    TEX0Node texture = RootNode.FindChildByType(PAT0Texture, true, ResourceNodes.ResourceType.TEX0) as TEX0Node;
                    if (texture != null)
                    {
                        PAT0Textures[PAT0Texture] = new MDL0TextureNode(texture.Name)
                        {
                            Source = texture, palette = PAT0Palette != null?RootNode.FindChildByType(PAT0Palette, true, ResourceNodes.ResourceType.PLT0) as PLT0Node : null
                        }
                    }
                    ;
                }
                return;
            }
            else
            {
                PAT0Texture = PAT0Palette = null;
            }
        }
예제 #5
0
        public void CreateEntry()
        {
            int value = 0;

            foreach (PAT0TextureNode t in Children)
            {
                if (t._textureIndex == value)
                {
                    value++;
                }
            }

            if (value == 8)
            {
                return;
            }

            PAT0TextureNode node = new PAT0TextureNode((PAT0Flags)7, value);

            AddChild(node);
            node.CreateEntry();
        }
예제 #6
0
        public static BRESNode FromGIF(string file)
        {
            string   s = Path.GetFileNameWithoutExtension(file);
            BRESNode b = new BRESNode()
            {
                _name = s
            };
            PAT0Node p = new PAT0Node()
            {
                _name = s
            };

            p.CreateEntry();

            PAT0TextureNode t = p.Children[0].Children[0] as PAT0TextureNode;

            GifDecoder d = new GifDecoder();

            d.Read(file);

            int f = d.GetFrameCount();

            using (TextureConverterDialog dlg = new TextureConverterDialog())
            {
                dlg.Source = (Bitmap)d.GetFrame(0);
                if (dlg.ShowDialog(null, b) == DialogResult.OK)
                {
                    for (int i = 1; i < f; i++)
                    {
                        dlg.Source = (Bitmap)d.GetFrame(i);
                        dlg.EncodeSource();
                    }
                }
            }

            return(b);
        }
예제 #7
0
        public void ImportGIF(string file)
        {
            Action <object, DoWorkEventArgs> work = (object sender, DoWorkEventArgs e) =>
            {
                GifDecoder decoder = new GifDecoder();
                decoder.Read(file, null);
                e.Result = decoder;
            };
            Action <object, RunWorkerCompletedEventArgs> completed = (object sender, RunWorkerCompletedEventArgs e) =>
            {
                GifDecoder decoder = e.Result as GifDecoder;
                string     s       = Path.GetFileNameWithoutExtension(file);
                PAT0Node   p       = CreateResource <PAT0Node>(s);
                p._loop = true;
                p.CreateEntry();

                PAT0TextureNode      textureNode = p.Children[0].Children[0] as PAT0TextureNode;
                PAT0TextureEntryNode entry       = textureNode.Children[0] as PAT0TextureEntryNode;

                //Get the number of images in the file
                int frames = decoder.GetFrameCount();

                //The framecount will be created by adding up each image delay.
                float frameCount = 0;

                bool resized = false;
                int  w = 0, h = 0;
                Action <int, int> onResized = (newW, newH) =>
                {
                    if (resized != true)
                    {
                        w       = newW;
                        h       = newH;
                        resized = true;
                    }
                };

                using (TextureConverterDialog dlg = new TextureConverterDialog())
                {
                    using (ProgressWindow progress = new ProgressWindow(RootNode._mainForm, "GIF to PAT0 converter",
                                                                        "Converting, please wait...", true))
                    {
                        Bitmap prev = null;

                        progress.Begin(0, frames, 0);
                        for (int i = 0; i < frames; i++, entry = new PAT0TextureEntryNode())
                        {
                            if (progress.Cancelled)
                            {
                                break;
                            }

                            string name = s + "." + i;

                            dlg.ImageSource = name + ".";

                            using (Bitmap img = (Bitmap)decoder.GetFrame(i))
                            {
                                if (i == 0)
                                {
                                    dlg.LoadImages(img.Copy());
                                    dlg.Resized += onResized;
                                    if (dlg.ShowDialog(null, this) != DialogResult.OK)
                                    {
                                        return;
                                    }

                                    textureNode._hasTex = dlg.TextureData != null;
                                    textureNode._hasPlt = dlg.PaletteData != null;

                                    prev = img.Copy();
                                }
                                else
                                {
                                    //Draw the current image over the previous
                                    //This is because some GIFs use pixels of the previous frame
                                    //in order to compress the overall image data
                                    using (Graphics graphics = Graphics.FromImage(prev))
                                    {
                                        graphics.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                                        graphics.CompositingQuality = CompositingQuality.HighQuality;
                                        graphics.CompositingMode    = CompositingMode.SourceOver;
                                        graphics.SmoothingMode      = SmoothingMode.HighQuality;
                                        graphics.DrawImage(img, 0, 0, prev.Width, prev.Height);
                                    }

                                    dlg.LoadImages(prev.Copy());
                                    if (resized)
                                    {
                                        dlg.ResizeImage(w, h);
                                    }
                                    else
                                    {
                                        dlg.UpdatePreview();
                                    }

                                    dlg.EncodeSource();

                                    textureNode.AddChild(entry);
                                }
                            }

                            entry._frame = (float)Math.Round(frameCount, 2);
                            frameCount  += decoder.GetDelay(i) / 1000.0f * 60.0f;

                            if (textureNode._hasTex)
                            {
                                entry.Texture = name;
                            }

                            if (textureNode._hasPlt)
                            {
                                entry.Palette = name;
                            }

                            progress.Update(progress.CurrentValue + 1);
                        }

                        progress.Finish();
                        if (prev != null)
                        {
                            prev.Dispose();
                        }
                    }
                }

                p._numFrames = (ushort)(frameCount + 0.5f);
            };

            using (BackgroundWorker b = new BackgroundWorker())
            {
                b.DoWork             += new DoWorkEventHandler(work);
                b.RunWorkerCompleted += new RunWorkerCompletedEventHandler(completed);
                b.RunWorkerAsync();
            }
        }
        internal void ApplyPAT0Texture(PAT0TextureNode node, int index)
        {
            PAT0TextureEntryNode prev = null;
            if (node != null && index != 0 && node.Children.Count > 0)
            {
                foreach (PAT0TextureEntryNode next in node.Children)
                {
                    if (next.Index == 0)
                    {
                        prev = next;
                        continue;
                    }
                    if (prev._frame <= index - 1 && next._frame > index - 1)
                        break;
                    prev = next;
                }

                PAT0Texture = prev.Texture;
                PAT0Palette = prev.Palette;
                if (!PAT0Textures.ContainsKey(PAT0Texture))
                {
                    TEX0Node texture = RootNode.FindChildByType(PAT0Texture, true, ResourceNodes.ResourceType.TEX0) as TEX0Node;
                    if (texture != null)
                        PAT0Textures[PAT0Texture] = new MDL0TextureNode(texture.Name) { Source = texture, palette = !String.IsNullOrEmpty(PAT0Palette) ? RootNode.FindChildByType(PAT0Palette, true, ResourceNodes.ResourceType.PLT0) as PLT0Node : null };
                }
                return;
            }
            else PAT0Texture = PAT0Palette = null;
        }
예제 #9
0
 public override void OnPopulate()
 {
     int count = 0, index = 0;
     foreach (PAT0Flags p in texFlags)
     {
         if (p.HasFlag(PAT0Flags.Enabled))
         {
             if (!p.HasFlag(PAT0Flags.FixedTexture))
                 new PAT0TextureNode(p, index).Initialize(this, new DataSource(Header->GetTexTable(count), PAT0Texture.Size));
             else
             {
                 PAT0TextureNode t = new PAT0TextureNode(p, index) { textureCount = 1 };
                 t._parent = this;
                 _children.Add(t);
                 PAT0TextureEntryNode entry = new PAT0TextureEntryNode();
                 entry._frame = 0;
                 entry._texFileIndex = Header->GetIndex(count, false);
                 entry._pltFileIndex = Header->GetIndex(count, true);
                 entry._parent = t;
                 t._children.Add(entry);
                 entry.GetStrings();
             }
             count++;
         }
         index++;
     }
 }
예제 #10
0
        /// <summary>
        /// Adds an animation to the end of this one
        /// </summary>
        public void Append(PAT0Node external)
        {
            int origIntCount = FrameCount;
            FrameCount += external.FrameCount;

            foreach (PAT0EntryNode w in external.Children)
                foreach (PAT0TextureNode _extEntry in w.Children)
                {
                    PAT0TextureNode _intEntry = null;
                    if ((_intEntry = (PAT0TextureNode)FindChild(w.Name + "/" + _extEntry.Name, false)) == null)
                    {
                        PAT0EntryNode wi = null;
                        if ((wi = (PAT0EntryNode)FindChild(w.Name, false)) == null)
                            AddChild(wi = new PAT0EntryNode() { Name = FindName(null) });

                        PAT0TextureNode newIntEntry = new PAT0TextureNode(_extEntry._texFlags, _extEntry.TextureIndex);

                        wi.AddChild(newIntEntry);
                        foreach (PAT0TextureEntryNode e in _extEntry.Children)
                        {
                            PAT0TextureEntryNode q = new PAT0TextureEntryNode() { _frame = e._frame + origIntCount };
                            newIntEntry.AddChild(q);

                            q.Texture = e.Texture;
                            q.Palette = e.Palette;
                        }
                    }
                    else
                    {
                        foreach (PAT0TextureEntryNode e in _extEntry.Children)
                        {
                            PAT0TextureEntryNode q = new PAT0TextureEntryNode() { _frame = e._frame + origIntCount };
                            _intEntry.AddChild(q);

                            q.Texture = e.Texture;
                            q.Palette = e.Palette;
                        }
                    }
                }
        }