public static PopupMenu.Item InsertItems(Vector2 mousePos, Graph graph, IInlet <object> inlet, int priority = 4) { IOutlet <object> outlet = graph.GetLink(inlet); PopupMenu.Item insertItems; if (inlet != null && outlet != null) { Type genericLinkType = Generator.GetGenericType(inlet); PopupMenu.Item createItems = CreateItems(mousePos, graph); PopupMenu.Item catItems = createItems.Find(GetCategoryByType(genericLinkType)); insertItems = catItems.Find("Modifiers"); //adding link to all create actions foreach (PopupMenu.Item item in insertItems.All(true)) { if (item.onClick != null) { Action baseOnClick = item.onClick; item.onClick = () => { baseOnClick(); Generator createdGen = graph.generators[graph.generators.Length - 1]; //the last on is the one that's just created. Hacky if (createdGen != null && Generator.GetGenericType((Generator)createdGen) == genericLinkType) { //inlet graph.AutoLink(createdGen, outlet); //outlet if (createdGen is IOutlet <object> createdOutlet) { graph.Link(createdOutlet, inlet); } } GraphWindow.RefreshMapMagic(createdGen); }; } } } else { insertItems = new PopupMenu.Item("Add"); insertItems.onDraw = RightClick.DrawItem; insertItems.disabled = true; } insertItems.name = "Add (Insert)"; insertItems.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Create"); insertItems.color = Color.gray; insertItems.priority = priority; return(insertItems); }
public static PopupMenu.Item AppendItems(Vector2 mousePos, Graph graph, IOutlet <object> clickedOutlet, int priority = 4) /// Item set appeared on node or outlet click { PopupMenu.Item addItems = null; if (clickedOutlet != null) { Type genericLinkType = Generator.GetGenericType(clickedOutlet); if (genericLinkType == null) { throw new Exception("Could not find category " + clickedOutlet.GetType().ToString()); } PopupMenu.Item createItems = CreateItems(mousePos, graph); addItems = createItems.Find(GetCategoryByType(genericLinkType)); } if (addItems != null && addItems.subItems != null) { PopupMenu.Item initial = addItems.Find("Initial"); if (initial != null) { initial.disabled = true; } //adding link to all create actions foreach (PopupMenu.Item item in addItems.All(true)) { if (item.onClick != null) { Action baseOnClick = item.onClick; item.onClick = () => { baseOnClick(); Generator createdGen = graph.generators[graph.generators.Length - 1]; //the last on is the one that's just created. Hacky Vector2 pos = clickedOutlet.Gen.guiPosition + new Vector2(200, 0); GeneratorDraw.FindPlace(ref pos, new Vector2(100, 200), GraphWindow.current.graph); createdGen.guiPosition = pos; graph.AutoLink(createdGen, clickedOutlet); GraphWindow.RefreshMapMagic(createdGen); }; } } } else { addItems = new PopupMenu.Item("Add"); addItems.onDraw = RightClick.DrawItem; addItems.disabled = true; } addItems.name = "Add (Append)"; addItems.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Create"); addItems.color = Color.gray; addItems.priority = priority; return(addItems); }