Esempio n. 1
0
        /// <summary>
        /// Downloads the asset images mentioned in the provided tree asynchronously.
        /// Existing files are not overriden.
        /// </summary>
        /// <param name="inTree"></param>
        /// <param name="reportProgress">If specified, it is called to set this method's progress as a value
        /// from 0 to 1.</param>
        /// <returns></returns>
        internal async Task DownloadAssetsAsync(PoESkillTree inTree, Action <double> reportProgress = null)
        {
            Directory.CreateDirectory(_tempAssetsPath);
            var zoomLevel        = inTree.imageZoomLevels[Constants.AssetZoomLevel].ToString(CultureInfo.InvariantCulture);
            var perAssetProgress = 1.0 / inTree.assets.Count;
            var progress         = 0.0;

            foreach (var asset in inTree.assets)
            {
                var path = _tempAssetsPath + asset.Key + ".png";
                var url  = asset.Value.GetOrDefault(zoomLevel, () => asset.Value.Values.First());
                await DownloadAsync(url, path);

                progress += perAssetProgress;
                reportProgress?.Invoke(progress);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Downloads the node sprite images mentioned in the provided tree asynchronously.
        /// Existing files are not overriden.
        /// </summary>
        /// <param name="inTree"></param>
        /// <param name="reportProgress">If specified, it is called to set this method's progress as a value
        /// from 0 to 1.</param>
        /// <returns></returns>
        internal async Task DownloadSkillNodeSpritesAsync(PoESkillTree inTree,
                                                          Action <double> reportProgress = null)
        {
            Directory.CreateDirectory(_tempAssetsPath);
            var perSpriteProgress = 1.0 / inTree.skillSprites.Count;
            var progress          = 0.0;

            foreach (var obj in inTree.skillSprites)
            {
                var sprite = obj.Value[Constants.AssetZoomLevel];
                var path   = _tempAssetsPath + sprite.filename;
                var url    = SpriteUrl + sprite.filename;
                await DownloadAsync(url, path);

                progress += perSpriteProgress;
                reportProgress?.Invoke(progress);
            }
        }
Esempio n. 3
0
        public SkillTree(String treestring, bool displayProgress, UpdateLoadingWindow update)
        {
            PoESkillTree inTree = null;

            if (!_Initialized)
            {
                var jss = new JsonSerializerSettings
                {
                    Error = delegate(object sender, ErrorEventArgs args)
                    {
                        Debug.WriteLine(args.ErrorContext.Error.Message);
                        args.ErrorContext.Handled = true;
                    }
                };

                inTree = JsonConvert.DeserializeObject <PoESkillTree>(treestring.Replace("Additional ", ""), jss);
            }
            int qindex = 0;

            if (!_Initialized)
            {
                SkillTree._IconInActiveSkills = new SkillIcons();
                //TODO: (SpaceOgre) This is not used atm, so no need to run it.
                foreach (var obj in inTree.skillSprites)
                {
                    if (obj.Key.Contains("inactive"))
                    {
                        continue;
                    }
                    _IconInActiveSkills.Images[obj.Value[3].filename] = null;
                    foreach (var o in obj.Value[3].coords)
                    {
                        _IconInActiveSkills.SkillPositions[o.Key + "_" + o.Value.w] =
                            new KeyValuePair <Rect, string>(new Rect(o.Value.x, o.Value.y, o.Value.w, o.Value.h),
                                                            obj.Value[3].filename);
                    }
                }
            }

            if (!_Initialized)
            {
                SkillTree._IconActiveSkills = new SkillIcons();
                foreach (var obj in inTree.skillSprites)
                {
                    if (obj.Key.Contains("active"))
                    {
                        continue;
                    }
                    _IconActiveSkills.Images[obj.Value[3].filename] = null;
                    foreach (var o in obj.Value[3].coords)
                    {
                        _IconActiveSkills.SkillPositions[o.Key + "_" + o.Value.w] =
                            new KeyValuePair <Rect, string>(new Rect(o.Value.x, o.Value.y, o.Value.w, o.Value.h),
                                                            obj.Value[3].filename);
                    }
                }
            }

            if (!_Initialized)
            {
                foreach (var ass in inTree.assets)
                {
                    _assets[ass.Key] = new Asset(ass.Key,
                                                 ass.Value.ContainsKey(0.3835f) ? ass.Value[0.3835f] : ass.Value.Values.First());
                }
            }

            if (!_Initialized)
            {
                _rootNodeList = new List <int>();
                if (inTree.root != null)
                {
                    foreach (int i in inTree.root.ot)
                    {
                        _rootNodeList.Add(i);
                    }
                }
                else if (inTree.main != null)
                {
                    foreach (int i in inTree.main.ot)
                    {
                        _rootNodeList.Add(i);
                    }
                }
            }

            if (displayProgress)
            {
                update(50, 100);
            }

            if (!_Initialized)
            {
                _IconActiveSkills.OpenOrDownloadImages(update);
            }

            if (displayProgress)
            {
                update(75, 100);
            }

            if (!_Initialized)
            {
                _IconInActiveSkills.OpenOrDownloadImages(update);
            }


            if (!_Initialized)
            {
                _CharBaseAttributes = new Dictionary <string, float> [7];
                foreach (var c in inTree.characterData)
                {
                    _CharBaseAttributes[c.Key] = new Dictionary <string, float>
                    {
                        { "+# to Strength", c.Value.base_str },
                        { "+# to Dexterity", c.Value.base_dex },
                        { "+# to Intelligence", c.Value.base_int }
                    };
                }
            }



            if (!_Initialized)
            {
                _Skillnodes = new Dictionary <ushort, SkillNode>();
                foreach (Node nd in inTree.nodes)
                {
                    _Skillnodes.Add(nd.id, new SkillNode
                    {
                        Id         = nd.id,
                        Name       = nd.dn,
                        attributes = nd.sd,
                        Orbit      = nd.o,
                        OrbitIndex = nd.oidx,
                        Icon       = nd.icon,
                        LinkId     = nd.ot,
                        G          = nd.g,
                        Da         = nd.da,
                        Ia         = nd.ia,
                        IsKeyStone = nd.ks,
                        IsNotable  = nd.not,
                        Sa         = nd.sa,
                        IsMastery  = nd.m,
                        Spc        = nd.spc.Count() > 0 ? (int?)nd.spc[0] : null
                    });
                    if (_rootNodeList.Contains(nd.id))
                    {
                        _rootNodeClassDictionary.Add(nd.dn.ToString().ToUpper(), nd.id);
                        foreach (int linkedNode in nd.ot)
                        {
                            _startNodeDictionary.Add(linkedNode, nd.id);
                        }
                    }
                    foreach (int node in nd.ot)
                    {
                        if (!_startNodeDictionary.ContainsKey(nd.id) && _rootNodeList.Contains(node))
                        {
                            _startNodeDictionary.Add(nd.id, node);
                        }
                    }
                }


                foreach (var skillNode in Skillnodes)
                {
                    foreach (ushort i in skillNode.Value.LinkId)
                    {
                        if (
                            _links.Count(nd => (nd[0] == i && nd[1] == skillNode.Key) || nd[0] == skillNode.Key && nd[1] == i) ==
                            1)
                        {
                            continue;
                        }
                        _links.Add(new[] { skillNode.Key, i });
                    }
                }
                foreach (var ints in _links)
                {
                    if (!Skillnodes[ints[0]].Neighbor.Contains(Skillnodes[ints[1]]))
                    {
                        Skillnodes[ints[0]].Neighbor.Add(Skillnodes[ints[1]]);
                    }
                    if (!Skillnodes[ints[1]].Neighbor.Contains(Skillnodes[ints[0]]))
                    {
                        Skillnodes[ints[1]].Neighbor.Add(Skillnodes[ints[0]]);
                    }
                }
            }



            if (!_Initialized)
            {
                _NodeGroups = new List <SkillNodeGroup>();
                foreach (var gp in inTree.groups)
                {
                    var ng = new SkillNodeGroup();

                    ng.OcpOrb   = gp.Value.oo;
                    ng.Position = new Vector2D(gp.Value.x, gp.Value.y);
                    foreach (ushort node in gp.Value.n)
                    {
                        ng.Nodes.Add(Skillnodes[node]);
                    }
                    NodeGroups.Add(ng);
                }
                foreach (SkillNodeGroup group in NodeGroups)
                {
                    foreach (SkillNode node in group.Nodes)
                    {
                        node.SkillNodeGroup = group;
                    }
                }
            }

            if (!_Initialized)
            {
                _TRect = new Rect2D(new Vector2D(inTree.min_x * 1.1, inTree.min_y * 1.1),
                                    new Vector2D(inTree.max_x * 1.1, inTree.max_y * 1.1));
            }


            InitNodeSurround();//

            DrawNodeSurround();
            DrawNodeBaseSurround();
            InitSkillIconLayers();
            DrawSkillIconLayer();
            DrawBackgroundLayer();
            InitFaceBrushesAndLayer();
            DrawLinkBackgroundLayer(_links);
            InitOtherDynamicLayers();
            CreateCombineVisual();

            if (_links != null)
            {
                var regexAttrib = new Regex("[0-9]*\\.?[0-9]+");
                foreach (var skillNode in Skillnodes)
                {
                    skillNode.Value.Attributes = new Dictionary <string, List <float> >();
                    foreach (string s in skillNode.Value.attributes)
                    {
                        var values = new List <float>();

                        foreach (Match m in regexAttrib.Matches(s))
                        {
                            if (!AttributeTypes.Contains(regexAttrib.Replace(s, "#")))
                            {
                                AttributeTypes.Add(regexAttrib.Replace(s, "#"));
                            }
                            if (m.Value == "")
                            {
                                values.Add(float.NaN);
                            }
                            else
                            {
                                values.Add(float.Parse(m.Value, CultureInfo.InvariantCulture));
                            }
                        }
                        string cs = (regexAttrib.Replace(s, "#"));

                        skillNode.Value.Attributes[cs] = values;
                    }
                }
            }
            if (displayProgress)
            {
                update(100, 100);
            }

            _Initialized = true;
        }