Exemplo n.º 1
0
        private unsafe void Load(int index, int program, PLT0Node palette)
        {
            if (_context == null)
            {
                return;
            }

            Source = null;

            if (Texture != null)
            {
                Texture.Delete();
            }
            Texture = new GLTexture();
            Texture.Bind(index, program, _context);

            //ctx._states[String.Format("{0}_TexRef", Name)] = Texture;

            Bitmap   bmp   = null;
            TEX0Node tNode = null;

            if (_context._states.ContainsKey("_Node_Refs"))
            {
                List <ResourceNode> nodes    = _context._states["_Node_Refs"] as List <ResourceNode>;
                List <ResourceNode> searched = new List <ResourceNode>(nodes.Count);

                foreach (ResourceNode n in nodes)
                {
                    ResourceNode node = n.RootNode;
                    if (searched.Contains(node))
                    {
                        continue;
                    }
                    searched.Add(node);

                    //Search node itself first
                    if ((tNode = node.FindChild("Textures(NW4R)/" + Name, true) as TEX0Node) != null)
                    {
                        Source = tNode;
                        if (palette != null)
                        {
                            Texture.Attach(tNode, palette);
                        }
                        else
                        {
                            Texture.Attach(tNode);
                        }
                        return;
                    }
                    else
                    {
                        //Then search node directory
                        string path = node._origPath;
                        if (path != null)
                        {
                            DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(path));
                            if (dir.Exists && Name != "<null>")
                            {
                                foreach (FileInfo file in dir.GetFiles(Name + ".*"))
                                {
                                    if (file.Name.EndsWith(".tga"))
                                    {
                                        Source = file.FullName;
                                        bmp    = TGA.FromFile(file.FullName);
                                        break;
                                    }
                                    else if (file.Name.EndsWith(".png") || file.Name.EndsWith(".tiff") || file.Name.EndsWith(".tif"))
                                    {
                                        Source = file.FullName;
                                        bmp    = (Bitmap)Bitmap.FromFile(file.FullName);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    if (bmp != null)
                    {
                        break;
                    }
                }
                searched.Clear();

                if (bmp != null)
                {
                    Texture.Attach(bmp);
                }
            }
        }
Exemplo n.º 2
0
        private unsafe void Load(int index, int program)
        {
            if (TKContext.CurrentContext == null)
            {
                return;
            }

            Source = null;

            if (Texture != null)
            {
                Texture.Delete();
            }
            Texture = new GLTexture();
            Texture.Bind(index, program);

            Bitmap bmp = null;

            if (_folderWatcher.EnableRaisingEvents && !String.IsNullOrEmpty(_folderWatcher.Path))
            {
                bmp = SearchDirectory(_folderWatcher.Path + Name);
            }

            if (bmp == null && TKContext.CurrentContext._states.ContainsKey("_Node_Refs"))
            {
                List <ResourceNode> nodes    = TKContext.CurrentContext._states["_Node_Refs"] as List <ResourceNode>;
                List <ResourceNode> searched = new List <ResourceNode>(nodes.Count);
                TEX0Node            tNode    = null;

                foreach (ResourceNode n in nodes)
                {
                    ResourceNode node = n.RootNode;
                    if (searched.Contains(node))
                    {
                        continue;
                    }
                    searched.Add(node);

                    //Search node itself first
                    if ((tNode = node.FindChild("Textures(NW4R)/" + Name, true) as TEX0Node) != null)
                    {
                        Source = tNode;
                        Texture.Attach(tNode, _palette);
                        return;
                    }
                    else //Then search the directory
                    {
                        bmp = SearchDirectory(node._origPath);
                    }

                    if (bmp != null)
                    {
                        break;
                    }
                }
                searched.Clear();
            }

            if (bmp != null)
            {
                Texture.Attach(bmp);
            }
            else
            {
                Texture.Default();
            }
        }
Exemplo n.º 3
0
        private unsafe void Load(int index, int program)
        {
            if (TKContext.CurrentContext == null)
            {
                return;
            }

            bool isStage = false;

            Source = null;

            if (Texture != null)
            {
                Texture.Delete();
            }
            Texture = new GLTexture();
            Texture.Bind(index, program);

            Bitmap bmp = null;

            if (RootNode is ARCNode)
            {
                isStage = ((ARCNode)RootNode).IsStage;
            }

            if (_folderWatcher.EnableRaisingEvents && !String.IsNullOrEmpty(_folderWatcher.Path))
            {
                bmp = SearchDirectory(_folderWatcher.Path + Name);
            }

            BRRESNode parentBRRES = null;
            ARCNode   parentARC   = null;

            // Safely search for whether this is part of a BRRES
            if (_parent != null)
            {
                if (_parent._parent != null)
                {
                    if (_parent._parent._parent != null)
                    {
                        if (_parent._parent._parent._parent != null)
                        {
                            if (_parent._parent._parent._parent is BRRESNode)
                            {
                                parentBRRES = (BRRESNode)_parent._parent._parent._parent;
                                if (parentBRRES._parent != null)
                                {
                                    if (parentBRRES._parent is ARCNode)
                                    {
                                        parentARC = (ARCNode)parentBRRES._parent;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            List <ResourceNode> nodes = TKContext.CurrentContext._states["_Node_Refs"] as List <ResourceNode>;
            TEX0Node            tNode = null;

            if (bmp == null && TKContext.CurrentContext._states.ContainsKey("_Node_Refs") && parentBRRES != null)
            {
                ResourceNode node = parentBRRES;

                //Search node itself first
                if ((tNode = node.SearchForTextures("Textures(NW4R)/" + Name, true, false) as TEX0Node) != null)
                {
                    Source = tNode;
                    Texture.Attach(tNode, _palette);
                    return;
                }
            }

            if (bmp == null && TKContext.CurrentContext._states.ContainsKey("_Node_Refs") && parentARC != null)
            {
                ResourceNode node = parentARC;

                //Search node itself first
                if ((tNode = node.SearchForTextures("Textures(NW4R)/" + Name, true, isStage) as TEX0Node) != null)
                {
                    Source = tNode;
                    Texture.Attach(tNode, _palette);
                    return;
                }
                else //Then search the directory
                {
                    bmp = SearchDirectory(node._origPath);
                }
            }

            if (bmp != null)
            {
                Texture.Attach(bmp);
            }
            else
            {
                Texture.Default();
            }
        }