コード例 #1
0
        public static PopupMenu.Item CreateItems(Vector2 mousePos, Graph graph, int priority = 5)
        {
            PopupMenu.Item create = new PopupMenu.Item("Add (Create)");
            create.onDraw   = RightClick.DrawItem;
            create.icon     = RightClick.texturesCache.GetTexture("MapMagic/Popup/Create");
            create.color    = Color.gray;
            create.subItems = new List <PopupMenu.Item>();
            create.priority = priority;

            //automatically adding generators from this assembly
            Type[] types = typeof(Generator).Subtypes();
            for (int t = 0; t < types.Length; t++)
            {
                if (!generatorTypes.Contains(types[t]))
                {
                    generatorTypes.Add(types[t]);
                }
            }

            //adding outer-assembly types
            //via their initialize

            //creating unsorted create items
            foreach (Type type in generatorTypes)
            {
                GeneratorMenuAttribute attribute = GeneratorDraw.GetMenuAttribute(type);
                if (attribute == null)
                {
                    continue;
                }

                string texPath = attribute.iconName ?? "MapMagic/Popup/Standard";
                string texName = texPath;
                if (StylesCache.isPro)
                {
                    texName += "_icon";
                }

                PopupMenu.Item item = new PopupMenu.Item( )
                {
                    name     = attribute.name,
                    onDraw   = RightClick.DrawItem,
                    icon     = RightClick.texturesCache.GetTexture(texPath, texName, forceLight: true),
                    color    = GeneratorDraw.GetGeneratorColor(attribute.colorType ?? Generator.GetGenericType(type)),
                    onClick  = () => GraphEditorActions.CreateGenerator(graph, type, mousePos),
                    priority = attribute.priority
                };

                //moving into the right section using priority
                //int sectionPriority = 10000 - attribute.section*1000;
                //item.priority += sectionPriority;


                //placing items in categories
                string catName = attribute.menu;
                if (catName == null)
                {
                    continue;                                  //if no 'menu' defined this generator could not be created
                }
                string[] catNameSplit = catName.Split('/');

                PopupMenu.Item currCat = create;
                if (catName != "")                  //if empty menu is defined using root category
                {
                    for (int i = 0; i < catNameSplit.Length; i++)
                    {
                        //trying to find category
                        bool catFound = false;
                        if (currCat.subItems != null)
                        {
                            foreach (PopupMenu.Item sub in currCat.subItems)
                            {
                                if (sub.onClick == null && sub.name == catNameSplit[i])
                                {
                                    currCat  = sub;
                                    catFound = true;
                                    break;
                                }
                            }
                        }

                        //creating if not found
                        if (!catFound)
                        {
                            PopupMenu.Item newCat = new PopupMenu.Item(catNameSplit[i]);
                            if (currCat.subItems == null)
                            {
                                currCat.subItems = new List <PopupMenu.Item>();
                            }
                            currCat.subItems.Add(newCat);
                            currCat = newCat;

                            newCat.color = item.color;
                        }
                    }
                }

                if (currCat.subItems == null)
                {
                    currCat.subItems = new List <PopupMenu.Item>();
                }
                currCat.subItems.Add(item);
            }

            //default sorting order
            foreach (PopupMenu.Item item in create.All(true))
            {
                if (item.name == "Map")
                {
                    item.priority = 10004; item.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Map"); item.color = Color.gray;
                }
                if (item.name == "Objects" && item.onClick == null)
                {
                    item.priority = 10003; item.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Objects"); item.color = Color.gray;
                }
                if (item.name == "Spline")
                {
                    item.priority = 10002; item.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Spline"); item.color = Color.gray;
                }
                if (item.name == "Biomes")
                {
                    item.priority = 9999; item.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Biomes");
                }

                if (item.name == "Initial")
                {
                    item.priority = 10009; item.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Initial");
                }
                if (item.name == "Modifiers")
                {
                    item.priority = 10008; item.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Modifier");
                }
                if (item.name == "Standard")
                {
                    item.priority = 10009; item.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Standard");
                }
                if (item.name == "Output")
                {
                    item.priority = 10007; item.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Output");
                }
                if (item.name == "Outputs")
                {
                    item.priority = 10006; item.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Output");
                }
                if (item.name == "Input")
                {
                    item.priority = 10005; item.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Input");
                }
                if (item.name == "Inputs")
                {
                    item.priority = 10004; item.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Input");
                }
                if (item.name == "Portals")
                {
                    item.priority = 10003; item.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Portals");
                }
                if (item.name == "Function")
                {
                    item.priority = 10002; item.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Function");
                }

                if (item.name == "Height")
                {
                    item.priority = 10003;
                }
                if (item.name == "Textures")
                {
                    item.priority = 10002;
                }
                if (item.name == "Grass")
                {
                    item.priority = 10001;
                }

                if (item.onDraw == null)
                {
                    item.onDraw = RightClick.DrawItem;
                }
            }

            //adding separator between standard and special categories
            if (create.subItems.FindIndex(i => i.name == "Biomes") >= 0)         //add separator if biomes item present
            {
                PopupMenu.Item separator = PopupMenu.Item.Separator(priority: 10001);
                separator.onDraw = RightClick.DrawSeparator;
                separator.color  = Color.gray;
                create.subItems.Add(separator);
            }

            return(create);
        }
コード例 #2
0
        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);
        }