internal OffSpringTree FindOffspring(int type) { for (int i = 0; i < N; i++) { if (!_vis[i]) { continue; } _vis[i] = false; _roots[i] = new OffSpringNode(i); } Queue <int> Q = new Queue <int>(); Q.Enqueue(type); _vis[type] = true; while (Q.Count > 0) { var cur = Q.Dequeue(); foreach (var child in _G[cur]) { if (!_vis[child]) { _roots[cur].Children.Add(_roots[child]); Q.Enqueue(child); _vis[child] = true; } } } return(new OffSpringTree(_roots[type])); }
public RGraph() { N = Main.itemTexture.Length; _G = new List <int> [N]; _Grev = new List <Recipe> [N]; _vis = new bool[N]; _roots = new OffSpringNode[N]; for (int i = 0; i < N; i++) { _vis[i] = false; _roots[i] = new OffSpringNode(i); _G[i] = new List <int>(); _Grev[i] = new List <Recipe>(); } for (int i = 0; i < Recipe.numRecipes; i++) { var r = Main.recipe[i]; _Grev[r.createItem.type].Add(r); foreach (var req in r.requiredItem) { if (req.type <= 0) { continue; } _G[req.type].Add(r.createItem.type); } } }
private void _dfs1(OffSpringNode node) { _nodes[node.Type] = node; foreach (var child in node.Children) { _dfs1(child); } }
public OffSpringTree(OffSpringNode root) { int N = Main.itemTexture.Length; Root = root; SlotSize = 52f; MarginH = 15f; VerticalDistance = 30f; _depth = new int[N]; _nodePosition = new Vector2[N]; _nodes = new OffSpringNode[N]; for (int i = 0; i < N; i++) { _depth[i] = 0; } _dfs1(Root); }
private UISlotNode _dfs_slots(OffSpringNode node, UISlotNode parent) { var target = new UISlotNode(node.Type, parent, node.Page, node.MaxPage) { AnchorPoint = new Vector2(0, 0), Pivot = new Vector2(0.5f, 0.5f), Size = new Vector2(SlotSize, SlotSize), Position = _nodePosition[node.Type], }; _slots.Add(target); target.SlotChildren.Clear(); for (int i = (node.Page - 1) * 10; i < node.Children.Count && i < node.Page * 10; i++) { var child = node.Children[i]; var c = _dfs_slots(child, target); target.SlotChildren.Add(c); } return(target); }
private float _dfs(OffSpringNode node, float offsetX) { if (node.Children.Count == 0) { return(SlotSize); } float x = offsetX, totWidth = 0; for (int i = (node.Page - 1) * 10; i < node.Children.Count && i < node.Page * 10; i++) { var child = node.Children[i]; _depth[child.Type] = _depth[node.Type] + 1; _maxY = Math.Max(_maxY, (_depth[child.Type] + 1) * (SlotSize + VerticalDistance)); var width = _dfs(child, x); _nodePosition[child.Type] = new Vector2((2 * x + width) / 2, (_depth[child.Type] + 1) * (SlotSize + VerticalDistance)); x += MarginH + width; totWidth += MarginH + width; } totWidth -= MarginH; return(totWidth); }