Example #1
0
            public SaveData()
            {
                WorldInfo = new WorldMapInfo[24];

                for (int i = 0; i < WorldInfo.Length; i++)
                {
                    WorldInfo[i] = new WorldMapInfo();
                }

                WorldInfo[0].IsUnlocked = true; // First level should always be unlocked
            }
Example #2
0
        public void LoadWzResource()
        {
            if (this.IsDataLoaded)
            {
                return;
            }

            //读取所有世界地图
            var worldmapNode = PluginBase.PluginManager.FindWz("Map/WorldMap");

            if (worldmapNode == null) //加载失败
            {
                return;
            }

            this.worldMaps.Clear();
            this.CurrentWorldMap = null;

            foreach (var imgNode in worldmapNode.Nodes)
            {
                var     img = imgNode.GetNodeWzImage();
                Wz_Node node;
                if (img != null && img.TryExtract())
                {
                    var worldMapInfo = new WorldMapInfo();

                    //加载地图索引
                    node = img.Node.Nodes["info"];
                    if (node != null)
                    {
                        if (!this.UseImageNameAsInfoName)
                        {
                            worldMapInfo.Name = node.Nodes["WorldMap"].GetValueEx <string>(null);
                        }
                        worldMapInfo.ParentMap = node.Nodes["parentMap"].GetValueEx <string>(null);
                    }
                    if (string.IsNullOrEmpty(worldMapInfo.Name))
                    {
                        var m = Regex.Match(img.Name, @"^(.*)\.img$");
                        worldMapInfo.Name = m.Success ? m.Result("$1") : img.Name;
                    }

                    //加载地图名称
                    {
                        var m = Regex.Match(worldMapInfo.Name, @"^WorldMap(.+)$");
                        if (m.Success)
                        {
                            var stringNode = PluginBase.PluginManager.FindWz("String/WorldMap.img/" + m.Result("$1"));
                            worldMapInfo.DisplayName = stringNode?.Nodes["name"].GetValueEx <string>(null);
                        }
                    }

                    //加载baseImg
                    node = img.Node.Nodes["BaseImg"]?.Nodes["0"];
                    if (node != null)
                    {
                        worldMapInfo.BaseImg = LoadTextureItem(node);
                    }

                    //加载地图列表
                    node = img.Node.Nodes["MapList"];
                    if (node != null)
                    {
                        foreach (var spotNode in node.Nodes)
                        {
                            var spot     = new MapSpot();
                            var location = spotNode.Nodes["spot"]?.GetValueEx <Wz_Vector>(null);
                            if (location != null)
                            {
                                spot.Spot = location.ToPointF();
                            }
                            else //兼容pre-bb的格式
                            {
                                spot.IsPreBB = true;
                                spot.Spot    = new PointF(spotNode.Nodes["x"].GetValueEx <int>(0),
                                                          spotNode.Nodes["y"].GetValueEx <int>(0));
                            }
                            spot.Type      = spotNode.Nodes["type"].GetValueEx <int>(0);
                            spot.Title     = spotNode.Nodes["title"].GetValueEx <string>(null);
                            spot.Desc      = spotNode.Nodes["desc"].GetValueEx <string>(null);
                            spot.NoTooltip = spotNode.Nodes["noToolTip"].GetValueEx <int>(0) != 0;
                            var pathNode = spotNode.Nodes["path"];
                            if (pathNode != null)
                            {
                                spot.Path = LoadTextureItem(pathNode);
                            }
                            var mapNoNode = spotNode.Nodes["mapNo"];
                            if (mapNoNode != null)
                            {
                                foreach (var subNode in mapNoNode.Nodes)
                                {
                                    spot.MapNo.Add(subNode.GetValue <int>());
                                }
                            }
                            worldMapInfo.MapList.Add(spot);
                        }
                    }

                    //加载地图链接
                    node = img.Node.Nodes["MapLink"];
                    if (node != null)
                    {
                        foreach (var mapLinkNode in node.Nodes)
                        {
                            var link = new MapLink();
                            link.Index   = int.Parse(mapLinkNode.Text);
                            link.Tooltip = mapLinkNode.Nodes["toolTip"].GetValueEx <string>(null);
                            var linkNode = mapLinkNode.Nodes["link"];
                            if (linkNode != null)
                            {
                                link.LinkMap = linkNode.Nodes["linkMap"].GetValueEx <string>(null);
                                var linkImgNode = linkNode.Nodes["linkImg"];
                                if (linkImgNode != null)
                                {
                                    link.LinkImg = LoadTextureItem(linkImgNode, true);
                                }
                            }
                            worldMapInfo.MapLinks.Add(link);
                        }
                    }

                    this.worldMaps.Add(worldMapInfo);
                }
            }

            //读取公共资源
            var worldMapResNode = PluginBase.PluginManager.FindWz("Map/MapHelper.img/worldMap");
            var mapImageNode    = worldMapResNode?.Nodes["mapImage"];

            if (mapImageNode != null)
            {
                foreach (var imgNode in mapImageNode.Nodes)
                {
                    var texture = this.LoadTextureItem(imgNode);
                    var key     = "mapImage/" + imgNode.Text;
                    this.Resources[key] = texture;
                }
            }

            var curPosNode = worldMapResNode?.FindNodeByPath(@"curPos\0");

            if (curPosNode != null)
            {
                var texture = this.LoadTextureItem(curPosNode);
                this.Resources["curPos"] = texture;
            }

            //处理当前地图信息
            foreach (var map in this.worldMaps)
            {
                if (map.ParentMap != null)
                {
                    map.ParentMapInfo = this.worldMaps.FirstOrDefault(_map => _map.Name == map.ParentMap);
                }
            }

            this.IsDataLoaded = true;
            this.JumpToCurrentMap();
        }
Example #3
0
        public void LoadWzResource()
        {
            if (this.IsDataLoaded)
            {
                return;
            }

            //读取所有世界地图
            var worldmapNode = PluginBase.PluginManager.FindWz("Map/WorldMap");

            if (worldmapNode == null) //加载失败
            {
                return;
            }

            this.worldMaps.Clear();
            this.CurrentWorldMap = null;

            foreach (var imgNode in worldmapNode.Nodes)
            {
                var     img = imgNode.GetNodeWzImage();
                Wz_Node node;
                if (img != null && img.TryExtract())
                {
                    var worldMapInfo = new WorldMapInfo();

                    //加载地图索引
                    node = img.Node.Nodes["info"];
                    if (node != null)
                    {
                        if (!this.UseImageNameAsInfoName)
                        {
                            worldMapInfo.Name = node.Nodes["WorldMap"].GetValueEx <string>(null);
                        }
                        worldMapInfo.ParentMap = node.Nodes["parentMap"].GetValueEx <string>(null);
                    }
                    if (string.IsNullOrEmpty(worldMapInfo.Name))
                    {
                        var m = Regex.Match(img.Name, @"^(.*)\.img$");
                        worldMapInfo.Name = m.Success ? m.Result("$1") : img.Name;
                    }

                    //加载地图名称
                    {
                        var m = Regex.Match(worldMapInfo.Name, @"^WorldMap(.+)$");
                        if (m.Success)
                        {
                            var stringNode = PluginBase.PluginManager.FindWz("String/WorldMap.img/" + m.Result("$1"));
                            worldMapInfo.DisplayName = stringNode?.Nodes["name"].GetValueEx <string>(null);
                        }
                    }

                    //加载baseImg
                    node = img.Node.Nodes["BaseImg"]?.Nodes["0"];
                    if (node != null)
                    {
                        worldMapInfo.BaseImg = LoadTextureItem(node);
                    }

                    //加载地图列表
                    node = img.Node.Nodes["MapList"];
                    if (node != null)
                    {
                        // KMST 1125: the spot indices are not always continuous.
                        var spotNodes = node.Nodes.Select(child => new {
                            child,
                            index = int.TryParse(child.Text, out var nodeInex) ? nodeInex : -1,
                        }).Where(item => item.index > -1)