Example #1
0
        public static Frame CreateFromNode(Wz_Node frameNode, GraphicsDevice graphicsDevice, GlobalFindNodeFunction findNode)
        {
            if (frameNode == null || frameNode.Value == null)
            {
                return(null);
            }

            while (frameNode.Value is Wz_Uol)
            {
                Wz_Uol  uol     = frameNode.Value as Wz_Uol;
                Wz_Node uolNode = uol.HandleUol(frameNode);
                if (uolNode != null)
                {
                    frameNode = uolNode;
                }
            }
            if (frameNode.Value is Wz_Png)
            {
                var    linkNode = frameNode.GetLinkedSourceNode(findNode);
                Wz_Png png      = linkNode?.GetValue <Wz_Png>() ?? (Wz_Png)frameNode.Value;

                var frame = new Frame(png.ToTexture(graphicsDevice))
                {
                    Png = png,
                };

                foreach (Wz_Node propNode in frameNode.Nodes)
                {
                    switch (propNode.Text)
                    {
                    case "origin":
                        frame.Origin = (propNode.Value as Wz_Vector).ToPoint();
                        break;

                    case "delay":
                        frame.Delay = propNode.GetValue <int>();
                        break;

                    case "z":
                        frame.Z = propNode.GetValue <int>();
                        break;

                    case "a0":
                        frame.A0 = propNode.GetValue <int>();
                        break;

                    case "a1":
                        frame.A1 = propNode.GetValue <int>();
                        break;
                    }
                }

                if (frame.Delay == 0)
                {
                    frame.Delay = 100;//给予默认delay
                }
                return(frame);
            }
            return(null);
        }
Example #2
0
        private Wz_Png GetLinkedPng(Wz_Node node)
        {
            var wzFile = node.GetNodeWzFile();

            if (wzFile != null)
            {
                var linkNode = node.GetLinkedSourceNode(path =>
                                                        PluginBase.PluginManager.FindWz(path, wzFile));

                //添加回收池机制...
                if (linkNode != null)
                {
                    var linkImg = linkNode.GetNodeWzImage();
                    if (linkImg != null && !_currentWzImg.Contains(linkImg))
                    {
                        if (_disposeQueue == null)
                        {
                            _disposeQueue = new DisposeQueue(32);
                        }
                        _disposeQueue.Add(linkImg, _currentWzImg);
                    }
                }

                return(linkNode.GetValueEx <Wz_Png>(null));
            }
            return(null);
        }
Example #3
0
        private Frame LoadFrame(Wz_Node node)
        {
            //处理uol
            while (node.Value is Wz_Uol)
            {
                node = ((Wz_Uol)node.Value).HandleUol(node);
            }
            //寻找link
            var linkNode = node.GetLinkedSourceNode(PluginManager.FindWz);
            //加载资源
            var atlas = Load <TextureAtlas>(linkNode);
            //读取其他信息
            var frame = new Frame()
            {
                Texture   = atlas.Texture,
                AtlasRect = atlas.SrcRect,
                Z         = node.Nodes["z"].GetValueEx(0),
                Delay     = node.Nodes["delay"].GetValueEx(100),
                Blend     = node.Nodes["blend"].GetValueEx(0) != 0,
                Origin    = (node.Nodes["origin"]?.Value as Wz_Vector)?.ToPoint() ?? Point.Zero
            };

            frame.A0 = node.Nodes["a0"].GetValueEx(255);
            frame.A1 = node.Nodes["a1"].GetValueEx(frame.A0);
            return(frame);
        }
Example #4
0
        public static GifFrame CreateFrameFromNode(Wz_Node frameNode, GlobalFindNodeFunction findNode)
        {
            if (frameNode == null || frameNode.Value == null)
            {
                return(null);
            }

            while (frameNode.Value is Wz_Uol)
            {
                Wz_Uol  uol     = frameNode.Value as Wz_Uol;
                Wz_Node uolNode = uol.HandleUol(frameNode);
                if (uolNode != null)
                {
                    frameNode = uolNode;
                }
            }
            if (frameNode.Value is Wz_Png)
            {
                var    linkNode = frameNode.GetLinkedSourceNode(findNode);
                Wz_Png png      = linkNode?.GetValue <Wz_Png>() ?? (Wz_Png)frameNode.Value;

                var gifFrame = new GifFrame(png.ExtractPng());
                foreach (Wz_Node propNode in frameNode.Nodes)
                {
                    switch (propNode.Text)
                    {
                    case "origin":
                        gifFrame.Origin = (propNode.Value as Wz_Vector);
                        break;

                    case "delay":
                        gifFrame.Delay = propNode.GetValue <int>();
                        break;

                    case "a0":
                        gifFrame.A0 = propNode.GetValue <int>();
                        break;

                    case "a1":
                        gifFrame.A1 = propNode.GetValue <int>();
                        break;
                    }
                }
                if (gifFrame.Delay == 0)
                {
                    gifFrame.Delay = 100;//给予默认delay
                }
                return(gifFrame);
            }
            return(null);
        }
Example #5
0
        public static TextureBase LoadTexture(Wz_Node node)
        {
            node = node?.GetLinkedSourceNode(PluginManager.FindWz);
            var png = node.GetValueEx <Wz_Png>(null);

            if (png != null)
            {
                return(Engine.Instance.AssetManager.LoadTexture(null, node.FullPathToFile));
            }
            else
            {
                return(null);
            }
        }
Example #6
0
        private TextureItem LoadTextureItem(Wz_Node node, bool loadHitMap = false)
        {
            var item     = new TextureItem();
            var linkNode = node.GetLinkedSourceNode(PluginBase.PluginManager.FindWz);

            item.Texture = UIHelper.LoadTexture(linkNode);
            item.Z       = node.Nodes["z"].GetValueEx <int>(0);
            var origin = node.Nodes["origin"]?.GetValueEx <Wz_Vector>(null);

            item.Origin = origin.ToPointF();
            if (item.Texture != null && loadHitMap)
            {
                item.HitMap = UIHelper.CreateHitMap(item.Texture.GetNativeTexture() as Microsoft.Xna.Framework.Graphics.Texture2D);
            }
            return(item);
        }
Example #7
0
        private void LoadMinimap(Wz_Node miniMapNode, ResourceLoader resLoader)
        {
            Wz_Node canvas  = miniMapNode.FindNodeByPath("canvas"),
                    width   = miniMapNode.FindNodeByPath("width"),
                    height  = miniMapNode.FindNodeByPath("height"),
                    centerX = miniMapNode.FindNodeByPath("centerX"),
                    centerY = miniMapNode.FindNodeByPath("centerY"),
                    mag     = miniMapNode.FindNodeByPath("mag");

            this.MiniMap.ExtraCanvas.Clear();

            canvas = canvas.GetLinkedSourceNode(PluginManager.FindWz);
            if (canvas != null)
            {
                this.MiniMap.Canvas = resLoader.Load <Texture2D>(canvas);
                this.MiniMap.ExtraCanvas.Add("canvas", this.MiniMap.Canvas);
            }
            else
            {
                this.MiniMap.Canvas = null;
            }

            // example mapID: 993200000, KMST1140
            for (int i = 1; ; i++)
            {
                string canvasName  = $"canvas{i}";
                var    extraCanvas = miniMapNode.FindNodeByPath(canvasName);
                if (extraCanvas == null)
                {
                    break;
                }
                extraCanvas = extraCanvas.GetLinkedSourceNode(PluginManager.FindWz);
                this.MiniMap.ExtraCanvas.Add(canvasName, resLoader.Load <Texture2D>(extraCanvas));
            }

            this.MiniMap.Width   = width.GetValueEx(0);
            this.MiniMap.Height  = height.GetValueEx(0);
            this.MiniMap.CenterX = centerX.GetValueEx(0);
            this.MiniMap.CenterY = centerY.GetValueEx(0);
            this.MiniMap.Mag     = mag.GetValueEx(0);
        }
Example #8
0
        private void LoadMinimap(Wz_Node miniMapNode, ResourceLoader resLoader)
        {
            Wz_Node canvas  = miniMapNode.FindNodeByPath("canvas"),
                    width   = miniMapNode.FindNodeByPath("width"),
                    height  = miniMapNode.FindNodeByPath("height"),
                    centerX = miniMapNode.FindNodeByPath("centerX"),
                    centerY = miniMapNode.FindNodeByPath("centerY"),
                    mag     = miniMapNode.FindNodeByPath("mag");

            canvas = canvas.GetLinkedSourceNode(PluginManager.FindWz);

            if (canvas != null)
            {
                this.MiniMap.Canvas = resLoader.Load <Texture2D>(canvas);
            }
            this.MiniMap.Width   = width.GetValueEx(0);
            this.MiniMap.Height  = height.GetValueEx(0);
            this.MiniMap.CenterX = centerX.GetValueEx(0);
            this.MiniMap.CenterY = centerY.GetValueEx(0);
            this.MiniMap.Mag     = mag.GetValueEx(0);
        }
Example #9
0
        public static BitmapOrigin CreateFromNode(Wz_Node node, GlobalFindNodeFunction findNode)
        {
            BitmapOrigin bp = new BitmapOrigin();
            Wz_Uol       uol;

            while ((uol = node.GetValue <Wz_Uol>(null)) != null)
            {
                node = uol.HandleUol(node);
            }

            //获取linkNode
            var    linkNode = node.GetLinkedSourceNode(findNode);
            Wz_Png png      = linkNode?.GetValue <Wz_Png>() ?? (Wz_Png)node.Value;

            bp.Bitmap = png?.ExtractPng();
            Wz_Node   originNode = node.FindNodeByPath("origin");
            Wz_Vector vec        = (originNode == null) ? null : originNode.GetValue <Wz_Vector>();

            bp.Origin = (vec == null) ? new Point() : new Point(vec.X, vec.Y);

            return(bp);
        }
        private Frame LoadFrame(Wz_Node node)
        {
            //处理uol
            while (node?.Value is Wz_Uol uol)
            {
                node = uol.HandleUol(node);
            }
            if (node == null)
            {
                return(new Frame());
            }
            //寻找link
            var linkNode = node.GetLinkedSourceNode(PluginManager.FindWz);
            //加载资源
            var atlas = Load <TextureAtlas>(linkNode);
            //读取其他信息
            var frame = new Frame()
            {
                Texture   = atlas.Texture,
                AtlasRect = atlas.SrcRect,
                Z         = node.Nodes["z"].GetValueEx(0),
                Delay     = node.Nodes["delay"].GetValueEx(100),
                Blend     = node.Nodes["blend"].GetValueEx(0) != 0,
                Origin    = (node.Nodes["origin"]?.Value as Wz_Vector)?.ToPoint() ?? Point.Zero
            };
            Wz_Vector lt = node.Nodes["lt"]?.Value as Wz_Vector;
            Wz_Vector rb = node.Nodes["rb"]?.Value as Wz_Vector;

            if (lt != null && rb != null)
            {
                frame.BoundingBox = new Rectangle(lt.X, lt.Y, Math.Abs(lt.X - rb.X), Math.Abs(lt.Y - rb.Y));
            }
            frame.A0 = node.Nodes["a0"].GetValueEx(255);
            frame.A1 = node.Nodes["a1"].GetValueEx(frame.A0);
            return(frame);
        }
Example #11
0
        public static TextureBase LoadTexture(Wz_Node node)
        {
            var png = node?.GetLinkedSourceNode(PluginManager.FindWz)?.GetValueEx <Wz_Png>(null);

            return(png == null ? null : Engine.Instance.Renderer.CreateTexture(png));
        }