Ejemplo n.º 1
0
        public static void DrawGroupColorSelector(Group group)
        {
            PopupMenu.Item menuItem = new PopupMenu.Item("Colors");
            menuItem.subItems = new List <PopupMenu.Item>
            {
                GetGroupColorSelectorItem(group, "Neutral", new Color(0.625f, 0.625f, 0.625f, 1), 210),
                GetGroupColorSelectorItem(group, "Rose Quartz", new Color(246f / 256f, 202f / 256f, 201f / 256f, 1), 200),
                GetGroupColorSelectorItem(group, "Dahlia", new Color(235f / 256f, 149f / 256f, 135f / 256f, 1), 190),
                GetGroupColorSelectorItem(group, "Flame", new Color(243f / 256f, 85f / 256f, 76f / 256f, 1), 180),
                GetGroupColorSelectorItem(group, "Marsala", new Color(150f / 256f, 79f / 256f, 77f / 256f, 1), 170),
                GetGroupColorSelectorItem(group, "Hazelnut", new Color(225f / 256f, 174f / 256f, 155f / 256f, 1), 160),
                GetGroupColorSelectorItem(group, "Butterum", new Color(196f / 256f, 142f / 256f, 104f / 256f, 1), 150),
                GetGroupColorSelectorItem(group, "Primrose", new Color(255f / 256f, 204f / 256f, 115f / 256f, 1), 140),
                GetGroupColorSelectorItem(group, "Amber", new Color(255f / 256f, 182f / 256f, 72f / 256f, 1), 130),
                GetGroupColorSelectorItem(group, "Cream Gold", new Color(221f / 256f, 191f / 256f, 94f / 256f, 1), 120),
                GetGroupColorSelectorItem(group, "Gold Lime", new Color(155f / 256f, 151f / 256f, 64f / 256f, 1), 110),
                GetGroupColorSelectorItem(group, "Lint", new Color(182f / 256f, 186f / 256f, 153f / 256f, 1), 100),
                GetGroupColorSelectorItem(group, "Greenery", new Color(118f / 256f, 177f / 256f, 97f / 256f, 1), 90),
                GetGroupColorSelectorItem(group, "Green", new Color(84f / 256f, 194f / 256f, 71f / 256f, 1), 80),
                GetGroupColorSelectorItem(group, "Kale", new Color(89f / 256f, 118f / 256f, 87f / 256f, 1), 70),
                GetGroupColorSelectorItem(group, "Beryl", new Color(96f / 256f, 144f / 256f, 135f / 256f, 1), 60),
                GetGroupColorSelectorItem(group, "Arctic", new Color(100f / 256f, 133f / 256f, 137f / 256f, 1), 50),
                GetGroupColorSelectorItem(group, "Niagara", new Color(51f / 256f, 142f / 256f, 163f / 256f, 1), 40),
                GetGroupColorSelectorItem(group, "Island", new Color(118f / 256f, 206f / 256f, 216f / 256f, 1), 30),
                GetGroupColorSelectorItem(group, "Carolina", new Color(139f / 256f, 184f / 256f, 232f / 256f, 1), 20),
                GetGroupColorSelectorItem(group, "Navy", new Color(64f / 256f, 63f / 256f, 111f / 256f, 1), 10)
            };
            PopupMenu menu = new PopupMenu()
            {
                items = menuItem.subItems, minWidth = 150
            };

            menu.Show(Event.current.mousePosition);
        }
Ejemplo n.º 2
0
        public static void DrawItem(PopupMenu.Item item, Rect rect)
        {
            Rect leftRect = new Rect(rect.x, rect.y, 28, rect.height);

            leftRect.x  -= 1; leftRect.height += 2;
            item.color.a = 0.25f;
            EditorGUI.DrawRect(leftRect, item.color);

            Rect labelRect = new Rect(rect.x + leftRect.width + 3, rect.y, rect.width - leftRect.width - 3, rect.height);

            if (itemTextStyle == null)
            {
                itemTextStyle = new GUIStyle(UnityEditor.EditorStyles.label);
                itemTextStyle.normal.textColor = itemTextStyle.focused.textColor = itemTextStyle.active.textColor = Color.black;
            }

            EditorGUI.LabelField(labelRect, item.name, itemTextStyle);

            if (item.icon != null)
            {
                Rect iconRect = new Rect(leftRect.center.x - 6, leftRect.center.y - 6, 12, 12);
                iconRect.y -= 2;
                UnityEngine.GUI.DrawTexture(iconRect, item.icon);
            }
        }
Ejemplo n.º 3
0
        public static PopupMenu.Item ValueItems(FieldInfo valField, IOutlet <object> layer, Generator gen, Graph graph, int priority = 2)
        {
            PopupMenu.Item valItems = new PopupMenu.Item("Value");
            valItems.onDraw   = RightClick.DrawItem;
            valItems.icon     = RightClick.texturesCache.GetTexture("MapMagic/Popup/Value");
            valItems.color    = Color.gray;
            valItems.subItems = new List <PopupMenu.Item>();
            valItems.priority = priority;

            valItems.disabled = valField == null || gen == null;

            PopupMenu.Item exposeItem = new PopupMenu.Item("Expose", onDraw: RightClick.DrawItem, priority: 6);
            exposeItem.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Expose");
            if (valField != null)
            {
                exposeItem.onClick =                               // () => { if (gen.exposed==null) gen.exposed=new Exposed(); gen.exposed.ExposeField(valField); };
                                     () => ExposeWindow.ShowWindow(graph, gen, layer, valField, Event.current.mousePosition + EditorWindow.focusedWindow.position.position);
            }
            // graph.exposed.Expose(gen, valField);
            valItems.subItems.Add(exposeItem);

            PopupMenu.Item unExposeItem = new PopupMenu.Item("UnExpose", onDraw: RightClick.DrawItem, priority: 6);
            unExposeItem.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/UnExpose");
            if (valField != null)
            {
                unExposeItem.onClick =                               //() => { if (gen.exposed==null) gen.exposed=new Exposed(); gen.exposed.ExposeField(valField); };
                                       () => graph.exposed.Unexpose(gen, valField);
            }
            valItems.subItems.Add(unExposeItem);

            return(valItems);
        }
Ejemplo n.º 4
0
        private static void DrawItem(PopupMenu.Item item)
        {
            PopupMenu menu = new PopupMenu()
            {
                items = item.subItems, minWidth = 150
            };

            menu.Show(Event.current.mousePosition);
        }
Ejemplo n.º 5
0
        public static TexturesCache texturesCache = new TexturesCache();         //to store icons


        public static void DrawRightClickItems(UI ui, Vector2 mousePos, Graph graph)
        {
            PopupMenu.Item item = RightClickItems(ui, mousePos, graph);
            PopupMenu      menu = new PopupMenu()
            {
                items = item.subItems, minWidth = 150
            };

            menu.Show(Event.current.mousePosition);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        private static void FillSubGraphItems(Graph graph, Graph root, string prefix, List <PopupMenu.Item> items)
        {
            PopupMenu.Item item = new PopupMenu.Item(prefix + graph.name);
            items.Add(item);
            item.onClick = () => GraphWindow.current.OpenBiome(graph, root);

            foreach (Graph subGraph in graph.SubGraphs())
            {
                FillSubGraphItems(subGraph, root, $"{prefix}   ", items);
            }
        }
Ejemplo n.º 8
0
        public static PopupMenu.Item GroupItems(Vector2 mousePos, Group grp, Graph graph, int priority = 3)
        {
            PopupMenu.Item genItems = new PopupMenu.Item("Group");
            genItems.onDraw   = RightClick.DrawItem;
            genItems.icon     = RightClick.texturesCache.GetTexture("MapMagic/Popup/Generator");
            genItems.color    = Color.gray;
            genItems.subItems = new List <PopupMenu.Item>();
            genItems.priority = priority;

            //genItems.disabled = grp == null;

            genItems.subItems.Add(new PopupMenu.Item("Create", onDraw: RightClick.DrawItem, priority: 12)
            {
                icon    = RightClick.texturesCache.GetTexture("MapMagic/Popup/GroupAdd"),
                color   = Color.gray,
                onClick = () => CreateGroup(mousePos, graph)
            });

            genItems.subItems.Add(new PopupMenu.Item("Group Selected", onDraw: RightClick.DrawItem, priority: 12)
            {
                icon     = RightClick.texturesCache.GetTexture("MapMagic/Popup/GroupSelected"),
                color    = Color.gray,
                disabled = GraphWindow.current.selected == null || GraphWindow.current.selected.Count == 0,
                onClick  = () => { Group ngrp = CreateGroup(mousePos, graph); GroupSelected(ngrp); }
            });

            //genItems.subItems.Add( new PopupMenu.Item("Export", onDraw:DrawItem, priority:10) { icon = texturesCache.GetTexture("MapMagic/Popup/Export"), color = Color.gray } );
            //genItems.subItems.Add( new PopupMenu.Item("Import", onDraw:DrawItem, priority:9) { icon = texturesCache.GetTexture("MapMagic/Popup/Import"), color = Color.gray } );
            //genItems.subItems.Add( new PopupMenu.Item("Duplicate", onDraw:DrawItem, priority:8) { icon = texturesCache.GetTexture("MapMagic/Popup/Duplicate"), color = Color.gray } );
            //genItems.subItems.Add( new PopupMenu.Item("Update", onDraw:DrawItem, priority:7) { icon = texturesCache.GetTexture("MapMagic/Popup/Update"), color = Color.gray } );

            genItems.subItems.Add(new PopupMenu.Item("Ungroup", onDraw: RightClick.DrawItem, priority: 5)
            {
                icon    = RightClick.texturesCache.GetTexture("MapMagic/Popup/Ungroup"),
                color   = Color.gray,
                onClick = () => graph.Remove(grp)
            });

            genItems.subItems.Add(new PopupMenu.Item("Remove", onDraw: RightClick.DrawItem, priority: 4)
            {
                icon    = RightClick.texturesCache.GetTexture("MapMagic/Popup/Remove"),
                color   = Color.gray,
                onClick = () =>
                {
                    GraphWindow.current.graphUI.undo.Record();
                    GroupDraw.RemoveGroupContents(grp, graph);
                    graph.Remove(grp);
                }
            });

            return(genItems);
        }
Ejemplo n.º 9
0
        public static void DrawPortalSelector(Graph graph, IPortalExit <object> portalExit)
        {
            //if (MapMagic.instance.guiGens == null) MapMagic.instance.guiGens = MapMagic.instance.gens;
            //GeneratorsAsset gens = MapMagic.instance.guiGens;
            //if (MapMagic.instance.guiGens != null) gens = MapMagic.instance.guiGens;

            Type exitType = typeof(Den.Tools.Matrices.MatrixWorld);             //portalExit.GetType().GetGenericArguments()[0];

            //TODO: generic portals

            if (itemTextStyle == null)
            {
                itemTextStyle = new GUIStyle(UnityEditor.EditorStyles.label);
                itemTextStyle.normal.textColor = itemTextStyle.focused.textColor = itemTextStyle.active.textColor = Color.black;
            }

            List <PopupMenu.Item> enterPortalsItems = new List <PopupMenu.Item>();

            for (int g = 0; g < graph.generators.Length; g++)
            {
                IPortalEnter <object> portalEnter = graph.generators[g] as IPortalEnter <object>;
                if (portalEnter == null)
                {
                    continue;
                }
                //if (portalEnter.GetType().GetGenericArguments()[0] != exitType) continue;
                //TODO: generic portals

                PopupMenu.Item item = new PopupMenu.Item(portalEnter.Name,
                                                         onDraw: (i, r) => EditorGUI.LabelField(r, i.name, itemTextStyle),
                                                         onClick: () =>
                {
                    if (graph.AreDependent((Generator)portalExit, (Generator)portalEnter))
                    {
                        EditorUtility.DisplayDialog("MapMagic", "Linking portals this way will create a dependency loop.", "Cancel"); return;
                    }

                    portalExit.AssignEnter(portalEnter, graph);

                    GraphWindow.RefreshMapMagic();
                });

                enterPortalsItems.Add(item);
            }

            PopupMenu menu = new PopupMenu()
            {
                items = enterPortalsItems
            };

            menu.Show(Event.current.mousePosition);
        }
Ejemplo n.º 10
0
        public static void DrawSeparator(PopupMenu.Item item, Rect rect)
        {
            Rect leftRect = new Rect(rect.x, rect.y, 28, rect.height);

            leftRect.x  -= 1; leftRect.height += 2;
            item.color.a = 0.125f;
            EditorGUI.DrawRect(leftRect, item.color);

            Rect labelRect     = new Rect(rect.x + leftRect.width + 3, rect.y, rect.width - leftRect.width - 3, rect.height);
            Rect separatorRect = new Rect(labelRect.x, labelRect.y + 2, labelRect.width - 6, 1);

            EditorGUI.DrawRect(separatorRect, new Color(0.3f, 0.3f, 0.3f, 1));
        }
Ejemplo n.º 11
0
        private static void DrawGroupColorSelectorItem(PopupMenu.Item item, Rect rect)
        {
            Rect iconRect  = new Rect(rect.x, rect.y, 18, 18);
            Rect labelRect = new Rect(rect.x + iconRect.width + 3, rect.y, rect.width - iconRect.width - 3, rect.height);

            if (itemTextStyle == null)
            {
                itemTextStyle = new GUIStyle(UnityEditor.EditorStyles.label);
                itemTextStyle.normal.textColor = itemTextStyle.focused.textColor = itemTextStyle.active.textColor = Color.black;
            }

            EditorGUI.DrawRect(iconRect.Extended(-2), new Color(item.color.r * 0.7f, item.color.g * 0.7f, item.color.b * 0.7f, 1));
            EditorGUI.DrawRect(iconRect.Extended(-3), item.color);

            UnityEditor.EditorGUI.LabelField(labelRect, item.name, itemTextStyle);
        }
Ejemplo n.º 12
0
        public static PopupMenu.Item GraphItems(Graph graph, int priority = 1)
        {
            PopupMenu.Item graphItems = new PopupMenu.Item("Graph");
            graphItems.onDraw   = RightClick.DrawItem;
            graphItems.icon     = RightClick.texturesCache.GetTexture("MapMagic/Popup/Graph");
            graphItems.color    = Color.gray;
            graphItems.subItems = new List <PopupMenu.Item>();
            graphItems.priority = priority;

            PopupMenu.Item importItem = new PopupMenu.Item("Import", onDraw: RightClick.DrawItem, priority: 9)
            {
                icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Import"), color = Color.gray
            };
            importItem.onClick = () =>
            {
                Graph imported = ScriptableAssetExtensions.LoadAsset <Graph>("Load Graph", filters: new string[] { "Asset", "asset" });
                if (imported != null)
                {
                    graph.Import(imported);
                }
            };
            graphItems.subItems.Add(importItem);

            PopupMenu.Item exportItem = new PopupMenu.Item("Export", onDraw: RightClick.DrawItem, priority: 9)
            {
                icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Export"), color = Color.gray
            };
            exportItem.disabled = GraphWindow.current.selected == null || GraphWindow.current.selected.Count == 0;
            exportItem.onClick  = () =>
            {
                Graph exported = graph.Export(GraphWindow.current.selected);
                ScriptableAssetExtensions.SaveAsset(exported, caption: "Save Graph", type: "asset");
            };
            graphItems.subItems.Add(exportItem);

            graphItems.subItems.Add(new PopupMenu.Item("Update All", onDraw: RightClick.DrawItem, priority: 7)
            {
                icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Update"), color = Color.gray
            });

            //graphItems.subItems.Add( new PopupMenu.Item("Background", onClick:()=>GraphWindow.current.noBackground=!GraphWindow.current.noBackground, onDraw:RightClick.DrawItem, priority:8));
            //graphItems.subItems.Add( new PopupMenu.Item("Debug", onClick:()=>GraphWindow.current.drawGenDebug=!GraphWindow.current.drawGenDebug, onDraw:RightClick.DrawItem, priority:9));

            return(graphItems);
        }
Ejemplo n.º 13
0
        public static PopupMenu.Item RightClickItems(UI ui, Vector2 mousePos, Graph graph)
        {
            ClickedNear(ui, mousePos,
                        out Group clickedGroup,
                        out Generator clickedGen,
                        out IOutlet <object> clickedLayer,
                        out IInlet <object> clickedLink,
                        out IInlet <object> clickedInlet,
                        out IOutlet <object> clickedOutlet,
                        out FieldInfo clickedField);

            PopupMenu.Item menu = new PopupMenu.Item("Menu");
            menu.subItems = new List <PopupMenu.Item>();

            if (clickedOutlet != null)
            {
                menu.subItems.Add(CreateRightClick.AppendItems(mousePos, graph, clickedOutlet, priority: 5));
            }

            else if (clickedLink != null)
            {
                menu.subItems.Add(CreateRightClick.InsertItems(mousePos, graph, clickedLink, priority: 5));
            }

            else
            {
                menu.subItems.Add(CreateRightClick.CreateItems(mousePos, graph, priority: 5));
            }

            menu.subItems.Add(GeneratorRightClick.GeneratorItems(clickedGen, graph, priority: 4));
            menu.subItems.Add(GroupRightClick.GroupItems(mousePos, clickedGroup, graph, priority: 3));
            menu.subItems.Add(ValueRightClick.ValueItems(clickedField, clickedLayer, clickedGen, graph, priority: 2));
            menu.subItems.Add(GraphPopup.GraphItems(graph, priority: 1));

            return(menu);
        }
Ejemplo n.º 14
0
        public static PopupMenu.Item GeneratorItems(Generator gen, Graph graph, int priority = 3)
        {
            PopupMenu.Item genItems = new PopupMenu.Item("Generator");
            genItems.onDraw   = RightClick.DrawItem;
            genItems.icon     = RightClick.texturesCache.GetTexture("MapMagic/Popup/Generator");
            genItems.color    = Color.gray;
            genItems.subItems = new List <PopupMenu.Item>();
            genItems.priority = priority;

            genItems.disabled = gen == null;

            PopupMenu.Item enableItem = new PopupMenu.Item(gen == null || gen.enabled ? "Disable" : "Enable", onDraw: RightClick.DrawItem, priority: 11)
            {
                icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Eye"), color = Color.gray
            };
            enableItem.onClick = () =>
            {
                gen.enabled = !gen.enabled;
                GraphWindow.RefreshMapMagic(gen);
            };
            genItems.subItems.Add(enableItem);

            //genItems.subItems.Add( new PopupMenu.Item("Export", onDraw:RightClick.DrawItem, priority:10) { icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Export"), color = Color.gray } );
            //genItems.subItems.Add( new PopupMenu.Item("Import", onDraw:RightClick.DrawItem, priority:9) { icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Import"), color = Color.gray } );

            PopupMenu.Item duplicateItem = new PopupMenu.Item("Duplicate", onDraw: RightClick.DrawItem, priority: 8);
            duplicateItem.icon    = RightClick.texturesCache.GetTexture("MapMagic/Popup/Duplicate");
            duplicateItem.color   = Color.gray;
            duplicateItem.onClick = () => GraphEditorActions.DuplicateGenerator(graph, gen, ref GraphWindow.current.selected);
            genItems.subItems.Add(duplicateItem);

            genItems.subItems.Add(new PopupMenu.Item("Update", onDraw: RightClick.DrawItem, priority: 7)
            {
                icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Update"), color = Color.gray
            });
            genItems.subItems.Add(new PopupMenu.Item("Reset", onDraw: RightClick.DrawItem, priority: 4)
            {
                icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Reset"), color = Color.gray
            });

            /*PopupMenu.Item testItem = new PopupMenu.Item("Create Test", onDraw:RightClick.DrawItem, priority:5);
             * testItem.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Export");
             * testItem.color = Color.gray;
             * testItem.onClick = ()=> GeneratorsTester.CreateTestCase(gen, GraphWindow.current.mapMagic.PreviewData);
             * genItems.subItems.Add(testItem);*/

            PopupMenu.Item removeItem = new PopupMenu.Item("Remove", onDraw: RightClick.DrawItem, priority: 5);
            removeItem.icon    = RightClick.texturesCache.GetTexture("MapMagic/Popup/Remove");
            removeItem.color   = Color.gray;
            removeItem.onClick = () => GraphEditorActions.RemoveGenerator(graph, gen, GraphWindow.current.selected);
            genItems.subItems.Add(removeItem);

            PopupMenu.Item unlinkItem = new PopupMenu.Item("Unlink", onDraw: RightClick.DrawItem, priority: 6);
            unlinkItem.icon    = RightClick.texturesCache.GetTexture("MapMagic/Popup/Unlink");
            unlinkItem.color   = Color.gray;
            unlinkItem.onClick = () =>
            {
                graph.UnlinkGenerator(gen);
                GraphWindow.RefreshMapMagic(gen);
                //undo
            };
            genItems.subItems.Add(unlinkItem);


            return(genItems);
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
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);
        }