/*
         * public static void DrawLabels(Rect visibleRect)
         * {
         *
         *  var i = 1;
         *  foreach (var node in _instance._queue)
         *  {
         *      if (node.IsVisible(visibleRect))
         *      {
         *          var main = ColorCompleted[node.Research.techLevel];
         *          var background = i > 1 ? ColorUnavailable[node.Research.techLevel] : main;
         *          DrawLabel(node.QueueRect, main, background, i);
         *      }
         *
         *      i++;
         *  }
         *
         * }
         *
         *
         * public static void DrawLabel(Rect canvas, Color main, Color background, int label)
         * {
         *  // draw coloured tag
         *  GUI.color = main;
         *  GUI.DrawTexture(canvas, CircleFill);
         *
         *  // if this is not first in line, grey out centre of tag
         *  if (background != main)
         *  {
         *      GUI.color = background;
         *      GUI.DrawTexture(canvas.ContractedBy(2f), CircleFill);
         *  }
         *
         *  // draw queue number
         *  GUI.color = Color.white;
         *  Text.Anchor = TextAnchor.MiddleCenter;
         *  Widgets.Label(canvas, label.ToString());
         *  Text.Anchor = TextAnchor.UpperLeft;
         * }*/

        public static void Unselect()
        {
            selected = null;
            newName  = null;
            unlockedDefs.Clear();
            unlockedInit = false;
        }
 public static void Select(ResearchNode node)
 {
     selected = node;
     newName  = node.Research.label;
     unlockedDefs.Clear();
     unlockedInit = false;
 }
Beispiel #3
0
        public List <Edge <Node, Node> > GetPathTo(ResearchNode rn, List <Edge <Node, Node> > edges)
        {
            List <Edge <Node, Node> > path;

            path = new List <Edge <Node, Node> >();
            foreach (var edge in edges)
            {
                if (edge.In == rn)
                {
                    path.Add(edge);
                    return(path);
                }
                else if (!(edge.In is DummyNode))
                {
                    continue;
                }
                List <Edge <Node, Node> > found = GetPathTo(rn, edge.In.InEdges);
                if (found != null)
                {
                    path.Add(edge);
                    path.AddRange(found);
                    return(path);
                }
            }
            return(null);
        }
Beispiel #4
0
        private static void CreateEdges()
        {
            // create links between nodes
            if (_edges.NullOrEmpty())
            {
                _edges = new List <Edge <Node, Node> >();
            }

            foreach (var node in Nodes.OfType <ResearchNode>())
            {
                if (node.Research.prerequisites.NullOrEmpty())
                {
                    continue;
                }
                foreach (var prerequisite in node.Research.prerequisites)
                {
                    ResearchNode prerequisiteNode = prerequisite;
                    if (prerequisiteNode == null)
                    {
                        continue;
                    }
                    var edge = new Edge <Node, Node>(prerequisiteNode, node);
                    Edges.Add(edge);
                    node.InEdges.Add(edge);
                    prerequisiteNode.OutEdges.Add(edge);
                }
            }
        }
Beispiel #5
0
        public void AddPrereq(ResearchNode rn)
        {
            var newEdge = new Edge <Node, Node>(rn, this);

            Tree._edges.Add(newEdge);
            _inEdges.Add(newEdge);
            rn._outEdges.Add(newEdge);
        }
        public static void InitUnlockedIcons(ResearchNode node, Rect canvas, bool bigIcons = true)
        {
            Vector2 iconSize  = bigIcons ? bigIconSize : IconSize;
            float   iconSpace = (iconSize.x + 4f);
            float   defaultX  = canvas.xMin + NodeSize.x * 2f + Margin + iconSpace;
            float   defaultY  = canvas.yMin;

            unlockedDefs.Clear();
            List <Pair <Def, string> > unlocks = selected.Research.GetDirectUnlocks();
            var indirectUnlocks = selected.Research.GetIndirectUnlocks();

            indirectUnlocks.ForEach(x => unlocks.RemoveAll(y => y.First == x.First.First));

            float currentX = defaultX;
            float currentY = defaultY;

            foreach (Pair <Def, string> unlock in unlocks ?? Enumerable.Empty <Pair <Def, string> >())
            {
                Rect iconRect = new Rect(
                    currentX,
                    currentY,
                    iconSize.x,
                    iconSize.y);
                unlockedDefs.Add(new UnlockedDef(unlock.First, unlock.Second, iconRect));

                currentX += (iconSpace);
                if (currentX > canvas.xMax)
                {
                    currentX  = defaultX;
                    currentY += iconSpace - 2f;
                }
            }

            foreach (Pair <Pair <ThingDef, string>, List <Pair <RecipeDef, string> > > item in indirectUnlocks ?? Enumerable.Empty <Pair <Pair <ThingDef, string>, List <Pair <RecipeDef, string> > > >())
            {
                float width = (item.Second.Count + 1) * (iconSpace);
                float newX  = currentX + width + Margin;
                if (newX > canvas.xMax)
                {
                    newX      = defaultX + width + Margin;
                    currentX  = defaultX;
                    currentY += iconSize.y + 2f;
                }
                Rect iconRect = new Rect(
                    currentX,
                    currentY,
                    bigIconSize.x,
                    bigIconSize.y);
                Rect groupUnlockRect = new Rect(currentX, currentY, width, iconSize.y);
                unlockedDefs.Add(new UnlockedGroup(item.First.First, item.First.Second, iconRect, groupUnlockRect, item.Second));

                currentX = newX;
            }
            unlockedInit = true;
        }
Beispiel #7
0
        public void RemovePrereq(ResearchNode rn)
        {
            var path = GetPathTo(rn, _inEdges);

            foreach (var edge in path ?? Enumerable.Empty <Edge <Node, Node> >())
            {
                //Tree._edges.Remove(Tree._edges.Find(x => x.In == edge.In && x.Out == edge.Out));
                Tree._edges.Remove(edge);
                edge.Out._inEdges.Remove(edge);
                edge.In._outEdges.Remove(edge);
                if (edge.Out is DummyNode && edge.Out.OutEdges.Count == 0 && edge.Out.InEdges.Count == 0)
                {
                    Tree._nodes.Remove(edge.Out);
                }
            }
        }