コード例 #1
0
        public TechNodeViewModel()
        {
            Width = 40;
            Height = 40;

            TechNode = new TechNode();
        }
コード例 #2
0
        public override TechNode PopulateFromSource(KerbalNode sourceNode)
        {
            TechNode newNode = new TechNode();
            var v = sourceNode.Values;
            newNode.NodePart = v.ContainsKey("nodepart") ? v["nodepart"].First() : "";

            double x;
            double y;
            newNode.Id = v.ContainsKey("id") ? v["id"].First() : "";

            if (v.ContainsKey("pos"))
            {
                var posString = v["pos"].First();
                var coordinates = posString.Split(',');

                if (coordinates.Length >= 2)
                {
                    if (!Double.TryParse(coordinates[0], out x))
                    {
                        x = 0;
                    }

                    if (!Double.TryParse(coordinates[1], out y))
                    {
                        y = 0;
                    }
                    newNode.Pos = new Point(x, y);

                    decimal z;
                    if (!Decimal.TryParse(coordinates[2], out z))
                    {
                        newNode.Zlayer = -1;
                    }
                    newNode.Zlayer = (int)z;
                }
            }

            if (v.ContainsKey("icon"))
            {
                String iconString = v["icon"].First();
                int id = Array.FindIndex(IconStringConverter.IconString, row => row == iconString);
                if (id != -1)
                {
                    newNode.Icon = (IconsEnum)id;
                }
                else
                {
                    newNode.Icon = IconsEnum.RDicon_generic;
                }
            }

            if (v.ContainsKey("scale"))
            {
                var s = v["scale"].First();
                newNode.Scale = Double.Parse(s);
            }

            newNode.Title = v.ContainsKey("title") ? v["title"].First() : "";
            newNode.Description = v.ContainsKey("description") ? v["description"].First() : "";

            newNode.AnyToUnlock = false;
            newNode.HideEmpty = false;
            newNode.HideIfNoBranchParts = false;
            if (v.ContainsKey("cost"))
            {
                int c;
                if (!Int32.TryParse(v["cost"].First(), out c))
                {
                    newNode.Cost = 0;
                }
                newNode.Cost = c;
            }
            if (v.ContainsKey("anyParent"))
            {
                switch (v["anyParent"].First().Trim().ToLower())
                {
                    case "true":
                        newNode.AnyToUnlock = true;
                        break;
                }
            }
            if (v.ContainsKey("hideEmpty"))
            {
                switch (v["hideEmpty"].First().Trim().ToLower())
                {
                    case "true":
                        newNode.HideEmpty = true;
                        break;
                }
            }
            if (v.ContainsKey("hideIfNoBranchParts"))
            {
                switch (v["hideIfNoBranchParts"].First().Trim().ToLower())
                {
                    case "true":
                        newNode.HideIfNoBranchParts = true;
                        break;
                }
            }

            // Create an empty parents collection, populated during linking
            newNode.Parents = new List<TechNode>();

            var tmpParts = new List<string>();
            foreach (var child in sourceNode.Children.Where(child => child.Name == "Unlocks").Where(child => child.Values.ContainsKey("part")))
            {
                tmpParts.AddRange(child.Values["part"]);
            }
            newNode.Parts = new List<string>(tmpParts);

            return newNode;
        }
コード例 #3
0
 public bool RemoveNode(TechNode node)
 {
     Nodes.Remove(node);
     return(true);
 }
コード例 #4
0
 public bool AddNode(TechNode node)
 {
     Nodes.Add(node);
     return(true);
 }
コード例 #5
0
ファイル: TechTree.cs プロジェクト: jcalero/ksp-techtree-edit
 public bool RemoveNode(TechNode node)
 {
     Nodes.Remove(node);
     return true;
 }
コード例 #6
0
ファイル: TechTree.cs プロジェクト: jcalero/ksp-techtree-edit
 public bool AddNode(TechNode node)
 {
     Nodes.Add(node);
     return true;
 }
コード例 #7
0
 public TechNodeViewModel AddNode(Point pos)
 {
     var node = new TechNode(GenerateNodeName()) { Pos = pos };
     var nodeViewModel = new TechNodeViewModel { TechNode = node };
     TechTree.Add(nodeViewModel);
     return nodeViewModel;
 }