예제 #1
0
파일: GraphWindow.cs 프로젝트: AJ213/Awitu
		private void DrawGraph () 
//			{using (Timer.Start("DrawGraph"))
		{
				//background
				#if MM_DOC
					float gridColor = 0.25f;
					float gridBackgroundColor = 0.25f;
				#else
					float gridColor = !StylesCache.isPro ? 0.45f : 0.14f; //0.135f; 
					float gridBackgroundColor = !StylesCache.isPro ? 0.5f : 0.16f; //0.16f;
				#endif

				Draw.StaticGrid(
					displayRect: new Rect(0, 0, Screen.width, Screen.height-toolbarSize),
					cellSize:32,
					color:new Color(gridColor,gridColor,gridColor), 
					background:new Color(gridBackgroundColor,gridBackgroundColor,gridBackgroundColor),
					fadeWithZoom:true);


				//drawing groups
				foreach (Group group in graph.groups)
					using (Cell.Custom(group.guiPos.x, group.guiPos.y, group.guiSize.x, group.guiSize.y))
					{
						GroupDraw.DragGroup(group, graph.generators);
						GroupDraw.DrawGroup(group);
					}


				//dragging nodes
				foreach (Generator gen in graph.generators)
					GeneratorDraw.DragGenerator(gen, selected);


				//drawing links
				//using (Timer.Start("Links"))
				if (!UI.current.layout)
				{
					List<(IInlet<object> inlet, IOutlet<object> outlet)> linksToRemove = null;
					foreach (var kvp in graph.links)
					{
						IInlet<object> inlet = kvp.Key;
						IOutlet<object> outlet = kvp.Value;

						Cell outletCell = UI.current.cellObjs.GetCell(outlet, "Outlet");
						Cell inletCell = UI.current.cellObjs.GetCell(inlet, "Inlet");

						if (outletCell == null || inletCell == null)
						{
							Debug.LogError("Could not find a cell for inlet/outlet. Removing link");
							if (linksToRemove == null) linksToRemove = new List<(IInlet<object> inlet, IOutlet<object> outlet)>();
							linksToRemove.Add((inlet,outlet));
							continue;
						}

						GeneratorDraw.DrawLink(
							GeneratorDraw.StartCellLinkpos(outletCell),
							GeneratorDraw.EndCellLinkpos(inletCell), 
							GeneratorDraw.GetLinkColor(inlet) );
					}

					if (linksToRemove != null)
						foreach ((IInlet<object> inlet, IOutlet<object> outlet) in linksToRemove)
						{
							graph.UnlinkInlet(inlet);
							graph.UnlinkOutlet(outlet);
						}
				}

				//removing null generators (for test purpose)
				for (int n=graph.generators.Length-1; n>=0; n--)
				{
					if (graph.generators[n] == null)
						ArrayTools.RemoveAt(ref graph.generators, n);
				}

				//drawing generators
				//using (Timer.Start("Generators"))
				foreach (Generator gen in graph.generators)
					using (Cell.Custom(gen.guiPosition.x, gen.guiPosition.y, GeneratorDraw.nodeWidth, 0))
					{
						if (gen is IPortalEnter<object> || gen is IPortalExit<object> || gen is IFunctionInput<object> || gen is IFunctionOutput<object>) 
							GeneratorDraw.DrawPortal(gen, graph, selected:selected.Contains(gen));

						else
						{
							try { GeneratorDraw.DrawGenerator(gen, graph, selected:selected.Contains(gen)); }
							catch (ExitGUIException)
								{ } //ignoring
							catch (Exception e) 
								{ Debug.LogError("Draw Graph Window failed: " + e); }
						}
					}

				//de-selecting nodes (after dragging and drawing since using drag obj)
				if (!UI.current.layout)
				{
					GeneratorDraw.SelectGenerators(selected);
					GeneratorDraw.DeselectGenerators(selected);
				}
				
				//add/remove button
				//using (Timer.Start("AddRemove"))
				using (Cell.Full)
					DragDrawAddRemove();

				//right click menu (should have access to cellObjs)
				if (!UI.current.layout  &&  Event.current.type == EventType.MouseDown  &&  Event.current.button == 1)
					RightClick.DrawRightClickItems(graphUI, graphUI.mousePos, graph);

				//create menu on space
				if (!UI.current.layout  &&  Event.current.type == EventType.KeyDown  &&  Event.current.keyCode == KeyCode.Space  && !Event.current.shift)
					CreateRightClick.DrawCreateItems(graphUI.mousePos, graph);

				//delete selected generators
				if (selected!=null  &&  selected.Count!=0  &&  Event.current.type==EventType.KeyDown  &&  Event.current.keyCode==KeyCode.Delete)
					GraphEditorActions.RemoveGenerators(graph, selected);
		}
예제 #2
0
파일: GraphWindow.cs 프로젝트: AJ213/Awitu
		private void DragDrawAddRemove ()
		{
			int origButtonSize = 34; int origButtonOffset = 20;

			Vector2 buttonPos = new Vector2(
				UI.current.editorWindow.position.width - (origButtonSize + origButtonOffset)*UI.current.DpiScaleFactor,
				20*UI.current.DpiScaleFactor);
			Vector2 buttonSize = new Vector2(origButtonSize,origButtonSize) * UI.current.DpiScaleFactor;

			using (Cell.Custom(buttonPos,buttonSize))
			//later button pos could be overriden if dragging it
			{
				Cell.current.MakeStatic();


				//if dragging generator
				if (DragDrop.IsDragging()  &&  !DragDrop.IsStarted()  &&  DragDrop.obj is Cell  &&  UI.current.cellObjs.TryGetObject((Cell)DragDrop.obj, "Generator", out Generator draggedGen) )
				
				{
					if (Cell.current.Contains(UI.current.mousePos))
						Draw.Texture(UI.current.textures.GetTexture("MapMagic/Icons/NodeRemoveActive"));
					else
						Draw.Texture(UI.current.textures.GetTexture("MapMagic/Icons/NodeRemove"));
				}


				//if released generator on remove icon
				else if (DragDrop.IsReleased()  &&  
					DragDrop.releasedObj is Cell  &&  
					UI.current.cellObjs.TryGetObject((Cell)DragDrop.releasedObj, "Generator", out Generator releasedGen)  &&  
					Cell.current.Contains(UI.current.mousePos))
				{
					GraphEditorActions.RemoveGenerator(graph, releasedGen, selected);
					GraphWindow.RefreshMapMagic();
				}


				//if not dragging generator
				else
				{
					if (focusedWindow==this) drawAddRemoveButton = true;   //re-enabling when window is focused again after popup
					bool drawFrame = false;
					Color frameColor = new Color();

					//dragging button
					if (DragDrop.TryDrag(addDragId, UI.current.mousePos))
					{
						Cell.current.pixelOffset += DragDrop.totalDelta; //offsetting cell position with the mouse

						Draw.Texture(UI.current.textures.GetTexture("MapMagic/Icons/NodeAdd"));

						//if dragging near link, output or node
						Vector2 mousePos = graphUI.mousePos;
						//Vector2 mousePos = graphUI.scrollZoom.ToInternal(addDragTo + new Vector2(addDragSize/2,addDragSize/2)); //add button center

						object clickedObj = RightClick.ClickedOn(graphUI, mousePos);
				
						if (clickedObj != null  &&  !(clickedObj is Group))
						{
							drawFrame = true;
							frameColor = GeneratorDraw.GetLinkColor(Generator.GetGenericType(clickedObj.GetType()));
						}
					}

					//releasing button
					if (DragDrop.TryRelease(addDragId))
					{
						drawAddRemoveButton = false;

						Vector2 mousePos = graphUI.mousePos;
						//Vector2 mousePos = graphUI.scrollZoom.ToInternal(addDragTo + new Vector2(addDragSize/2,addDragSize/2)); //add button center

						RightClick.ClickedNear (graphUI, 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);

						if (clickedOutlet != null)
							CreateRightClick.DrawAppendItems(mousePos, graph, clickedOutlet);

						else if (clickedLayer != null)
							CreateRightClick.DrawAppendItems(mousePos, graph, clickedLayer);

						else if (clickedLink != null)
							CreateRightClick.DrawInsertItems(mousePos, graph, clickedLink);

						else
							CreateRightClick.DrawCreateItems(mousePos, graph);
					}

					//starting button drag
					DragDrop.TryStart(addDragId, UI.current.mousePos, Cell.current.InternalRect);

					//drawing button
					if (drawAddRemoveButton) //don't show this button if right-click items are shown
						Draw.Texture(UI.current.textures.GetTexture("MapMagic/Icons/NodeAdd")); //using Texture since Icon is scaled with scrollzoom

					if (drawFrame)
					{
						Texture2D frameTex = UI.current.textures.GetColorizedTexture("MapMagic/Icons/NodeAddRemoveFrame", frameColor);
						Draw.Texture(frameTex);
					}
				}
			}
		}
예제 #3
0
        public static Item CreateItems(Vector2 mousePos, Graph graph, int priority = 5)
        {
            Item create = new Item("Add (Create)");

            create.onDraw   = RightClick.DrawItem;
            create.icon     = RightClick.texturesCache.GetTexture("MapMagic/Popup/Create");
            create.color    = Color.gray;
            create.subItems = new List <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";

                Item item = new Item( )
                {
                    name     = attribute.name,
                    onDraw   = RightClick.DrawItem,
                    icon     = RightClick.texturesCache.GetTexture(texPath, texName),
                    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('/');

                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 (Item sub in currCat.subItems)
                            {
                                if (sub.onClick == null && sub.name == catNameSplit[i])
                                {
                                    currCat  = sub;
                                    catFound = true;
                                    break;
                                }
                            }
                        }

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

                            newCat.color = item.color;
                        }
                    }
                }

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

            //default sorting order
            foreach (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
            {
                Item separator = Item.Separator(priority: 10001);
                separator.onDraw = RightClick.DrawSeparator;
                separator.color  = Color.gray;
                create.subItems.Add(separator);
            }

            return(create);
        }
예제 #4
0
		private void DrawGraph ()
		{
			bool isMini = IsMini;

			//background
			float gridColor = !StylesCache.isPro ? 0.45f : 0.12f;
			float gridBackgroundColor = !StylesCache.isPro ? 0.5f : 0.15f;

			#if MM_DEBUG
				if (!graph.debugGraphBackground)
				{
					gridColor = graph.debugGraphBackColor;
					gridBackgroundColor = graph.debugGraphBackColor;
				}
			#endif

			Draw.StaticGrid(
				displayRect: new Rect(0, 0, Screen.width, Screen.height-toolbarSize),
				cellSize:32,
				color:new Color(gridColor,gridColor,gridColor), 
				background:new Color(gridBackgroundColor,gridBackgroundColor,gridBackgroundColor),
				fadeWithZoom:true);

			#if MM_DEBUG
				if (graph.drawInSceneView)
				{
					using (Cell.Full)
						DrawSceneView();
				}
			#endif

			//drawing groups
			foreach (Group group in graph.groups)
				using (Cell.Custom(group.guiPos.x, group.guiPos.y, group.guiSize.x, group.guiSize.y))
				{
					GroupDraw.DragGroup(group, graph.generators);
					GroupDraw.DrawGroup(group, isMini:isMini);
				}


			//dragging nodes
			foreach (Generator gen in graph.generators)
				GeneratorDraw.DragGenerator(gen, selected);


			//drawing links
			//using (Timer.Start("Links"))
			if (!UI.current.layout)
			{
				List<(IInlet<object> inlet, IOutlet<object> outlet)> linksToRemove = null;
				foreach (var kvp in graph.links)
				{
					IInlet<object> inlet = kvp.Key;
					IOutlet<object> outlet = kvp.Value;

					Cell outletCell = UI.current.cellObjs.GetCell(outlet, "Outlet");
					Cell inletCell = UI.current.cellObjs.GetCell(inlet, "Inlet");

					if (outletCell == null || inletCell == null)
					{
						Debug.LogError("Could not find a cell for inlet/outlet. Removing link");
						if (linksToRemove == null) linksToRemove = new List<(IInlet<object> inlet, IOutlet<object> outlet)>();
						linksToRemove.Add((inlet,outlet));
						continue;
					}

					GeneratorDraw.DrawLink(
						GeneratorDraw.StartCellLinkpos(outletCell),
						GeneratorDraw.EndCellLinkpos(inletCell), 
						GeneratorDraw.GetLinkColor(inlet),
						width:!isMini ? 4f : 6f );
				}

				if (linksToRemove != null)
					foreach ((IInlet<object> inlet, IOutlet<object> outlet) in linksToRemove)
					{
						graph.UnlinkInlet(inlet);
						graph.UnlinkOutlet(outlet);
					}
			}

			//removing null generators (for test purpose)
			for (int n=graph.generators.Length-1; n>=0; n--)
			{
				if (graph.generators[n] == null)
					ArrayTools.RemoveAt(ref graph.generators, n);
			}

			//drawing generators
			//using (Timer.Start("Generators"))
			float nodeWidth = !isMini ? GeneratorDraw.nodeWidth : GeneratorDraw.miniWidth;
			foreach (Generator gen in graph.generators)
				using (Cell.Custom(gen.guiPosition.x, gen.guiPosition.y, nodeWidth, 0))
					GeneratorDraw.DrawGeneratorOrPortal(gen, graph, isMini:isMini, selected.Contains(gen));


			//de-selecting nodes (after dragging and drawing since using drag obj)
			if (!UI.current.layout)
			{
				GeneratorDraw.SelectGenerators(selected, shiftForSingleSelect:!isMini);
				GeneratorDraw.DeselectGenerators(selected); //and deselected always without shift
			}
				
			//add/remove button
			//using (Timer.Start("AddRemove"))
			using (Cell.Full)
				DragDrawAddRemove();

			//right click menu (should have access to cellObjs)
			if (!UI.current.layout  &&  Event.current.type == EventType.MouseDown  &&  Event.current.button == 1)
				RightClick.DrawRightClickItems(graphUI, graphUI.mousePos, graph);

			//create menu on space
			if (!UI.current.layout  &&  Event.current.type == EventType.KeyDown  &&  Event.current.keyCode == KeyCode.Space  && !Event.current.shift)
				CreateRightClick.DrawCreateItems(graphUI.mousePos, graph);

			//delete selected generators
			if (selected!=null  &&  selected.Count!=0  &&  Event.current.type==EventType.KeyDown  &&  Event.current.keyCode==KeyCode.Delete)
				GraphEditorActions.RemoveGenerators(graph, selected);
		}
예제 #5
0
		private void DragDrawAddRemove ()
		{
			//if dragging generator
			if (DragDrop.IsDragging()  &&  !DragDrop.IsStarted()  &&  DragDrop.obj is Cell  &&  UI.current.cellObjs.TryGetObject((Cell)DragDrop.obj, "Generator", out Generator draggedGen) )
			{
				if (Cell.current.Contains(UI.current.mousePos))
					Draw.Texture(UI.current.textures.GetTexture("MapMagic/Icons/NodeRemoveActive"));
				else
					Draw.Texture(UI.current.textures.GetTexture("MapMagic/Icons/NodeRemove"));
			}


			//if released generator on remove icon
			else if (DragDrop.IsReleased()  &&  
				DragDrop.releasedObj is Cell  &&  
				UI.current.cellObjs.TryGetObject((Cell)DragDrop.releasedObj, "Generator", out Generator releasedGen)  &&  
				Cell.current.Contains(UI.current.mousePos))
			{
				GraphEditorActions.RemoveGenerator(graph, releasedGen, selected);
				GraphWindow.RefreshMapMagic();
			}


			//if not dragging generator
			else
			{
				addDragTo = addDragDefault;

				if (focusedWindow == this) disableAddRemoveButton = false; //re-enabling when window is focused again after popup

				if (DragDrop.TryDrag(addDragId, UI.current.scrollZoom.ToScreen(UI.current.mousePos)))
				{
					addDragTo += DragDrop.totalDelta;

					Draw.Texture(UI.current.textures.GetTexture("MapMagic/Icons/NodeAdd"));

					//if dragging near link, output or node
					//Vector2 mousePos = graphUI.mousePos;
					Vector2 mousePos = graphUI.scrollZoom.ToInternal(addDragTo + new Vector2(addDragSize/2,addDragSize/2)); //add button center

					object clickedObj = RightClick.ClickedOn(graphUI, mousePos);
				
					if (clickedObj != null  &&  !(clickedObj is Group))
					{
						Color linkColor = GeneratorDraw.GetLinkColor(Generator.GetGenericType(clickedObj.GetType()));
						Texture2D frameTex = UI.current.textures.GetColorizedTexture("MapMagic/Icons/NodeAddRemoveFrame", linkColor);
						Draw.Texture(frameTex);
					}
				}
				else if (!disableAddRemoveButton) //don't show this button if right-click items are shown
					Draw.Texture(UI.current.textures.GetTexture("MapMagic/Icons/NodeAdd")); //using Texture since Icon is scaled with scrollzoom


				if (DragDrop.TryRelease(addDragId))
				{
					disableAddRemoveButton = true;

					//Vector2 mousePos = graphUI.mousePos;
					Vector2 mousePos = graphUI.scrollZoom.ToInternal(addDragTo + new Vector2(addDragSize/2,addDragSize/2)); //add button center

					RightClick.ClickedNear (graphUI, 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);

					if (clickedOutlet != null)
						CreateRightClick.DrawAppendItems(mousePos, graph, clickedOutlet);

					else if (clickedLayer != null)
						CreateRightClick.DrawAppendItems(mousePos, graph, clickedLayer);

					else if (clickedLink != null)
						CreateRightClick.DrawInsertItems(mousePos, graph, clickedLink);

					else
						CreateRightClick.DrawCreateItems(mousePos, graph);
				}


				DragDrop.TryStart(addDragId, new Rect(addDragDefault, new Vector2(addDragSize-4,addDragSize-4)));
			}
		}
예제 #6
0
        public static Item GeneratorItems(Generator gen, Graph graph, int priority = 3)
        {
            Item genItems = new Item("Generator");

            genItems.onDraw   = RightClick.DrawItem;
            genItems.icon     = RightClick.texturesCache.GetTexture("MapMagic/Popup/Generator");
            genItems.color    = Color.gray;
            genItems.subItems = new List <Item>();
            genItems.priority = priority;

            genItems.disabled = gen == null;

            Item enableItem = new 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 Item("Export", onDraw:RightClick.DrawItem, priority:10) { icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Export"), color = Color.gray } );
            //genItems.subItems.Add( new Item("Import", onDraw:RightClick.DrawItem, priority:9) { icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Import"), color = Color.gray } );

            Item duplicateItem = new 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 Item("Update", onDraw: RightClick.DrawItem, priority: 7)
            {
                icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Update"), color = Color.gray
            });
            genItems.subItems.Add(new Item("Reset", onDraw: RightClick.DrawItem, priority: 4)
            {
                icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Reset"), color = Color.gray
            });

            /*Item testItem = new 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);*/

            Item removeItem = new 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);

            Item unlinkItem = new 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);
        }
        public static Item GeneratorItems(Vector2 mousePos, Generator gen, Graph graph, int priority = 3)
        {
            Item genItems = new Item("Generator");

            genItems.onDraw   = RightClick.DrawItem;
            genItems.icon     = RightClick.texturesCache.GetTexture("MapMagic/Popup/Generator");
            genItems.color    = RightClick.defaultColor;
            genItems.subItems = new List <Item>();
            genItems.priority = priority;

            genItems.disabled = gen == null && copiedGenerators == null;

            {             //enable/disable
                string caption = (gen == null || gen.enabled) ? "Disable" : "Enable";
                Item   item    = new Item(caption, onDraw: RightClick.DrawItem, priority: 11);
                item.icon     = RightClick.texturesCache.GetTexture("MapMagic/Popup/Eye");
                item.color    = RightClick.defaultColor;
                item.disabled = gen == null;
                item.onClick  = () =>
                {
                    gen.enabled = !gen.enabled;
                    GraphWindow.RefreshMapMagic(gen);
                    GraphWindow.current.Focus();
                    GraphWindow.current.Repaint();
                };
                genItems.subItems.Add(item);
            }

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

            {             //duplicate
                Item item = new Item("Duplicate", onDraw: RightClick.DrawItem, priority: 8);
                item.icon     = RightClick.texturesCache.GetTexture("MapMagic/Popup/Duplicate");
                item.color    = RightClick.defaultColor;
                item.disabled = gen == null;
                item.onClick  = () =>
                                GraphEditorActions.DuplicateGenerator(graph, gen, ref GraphWindow.current.selected);
                genItems.subItems.Add(item);
            }


            {             //copy
                Item item = new Item("Copy", onDraw: RightClick.DrawItem, priority: 8);
                item.icon     = RightClick.texturesCache.GetTexture("MapMagic/Popup/Export");
                item.color    = RightClick.defaultColor;
                item.disabled = !(gen != null || (GraphWindow.current.selected != null && GraphWindow.current.selected.Count != 0));
                item.onClick  = () =>
                {
                    HashSet <Generator> gens;
                    if (GraphWindow.current.selected != null && GraphWindow.current.selected.Count != 0)
                    {
                        gens = GraphWindow.current.selected;
                    }
                    else
                    {
                        gens = new HashSet <Generator>(); gens.Add(gen);
                    }
                    copiedGenerators = graph.Export(gens);
                };
                item.closeOnClick = true;
                genItems.subItems.Add(item);
            }


            {             //paste
                Item item = new Item("Paste", onDraw: RightClick.DrawItem, priority: 7);
                item.icon     = RightClick.texturesCache.GetTexture("MapMagic/Popup/Export");
                item.color    = RightClick.defaultColor;
                item.disabled = copiedGenerators == null;
                item.onClick  = () =>
                {
                    Generator[] imported = graph.Import(copiedGenerators);
                    Graph.Reposition(imported, mousePos);
                };
                item.closeOnClick = true;
                genItems.subItems.Add(item);
            }


            {             //update
                Item item = new Item("Update", onDraw: RightClick.DrawItem, priority: 7);
                item.icon         = RightClick.texturesCache.GetTexture("MapMagic/Popup/Update");
                item.color        = RightClick.defaultColor;
                item.closeOnClick = true;
                item.disabled     = gen == null;
            }


            {             //reset
                Item item = new Item("Reset", onDraw: RightClick.DrawItem, priority: 4);
                item.icon         = RightClick.texturesCache.GetTexture("MapMagic/Popup/Reset");
                item.color        = RightClick.defaultColor;
                item.closeOnClick = true;
                item.disabled     = gen == null;
            }


            {             //remove
                Item item = new Item("Remove", onDraw: RightClick.DrawItem, priority: 5);
                item.icon     = RightClick.texturesCache.GetTexture("MapMagic/Popup/Remove");
                item.color    = RightClick.defaultColor;
                item.disabled = gen == null;
                item.onClick  = () =>
                                GraphEditorActions.RemoveGenerator(graph, gen, GraphWindow.current.selected);
                item.closeOnClick = true;
                genItems.subItems.Add(item);
            }


            {             //unlink
                Item item = new Item("Unlink", onDraw: RightClick.DrawItem, priority: 6);
                item.icon     = RightClick.texturesCache.GetTexture("MapMagic/Popup/Unlink");
                item.color    = RightClick.defaultColor;
                item.disabled = gen == null;
                item.onClick  = () =>
                {
                    graph.UnlinkGenerator(gen);
                    GraphWindow.RefreshMapMagic(gen);
                    //undo
                };
                item.closeOnClick = true;
                genItems.subItems.Add(item);
            }


            if (gen != null)
            {             //id
                Item item = new Item($"Id: {gen.id}", onDraw: RightClick.DrawItem, priority: 3);
                item.color        = RightClick.defaultColor;
                item.onClick      = () => EditorGUIUtility.systemCopyBuffer = gen.id.ToString();
                item.closeOnClick = true;
                genItems.subItems.Add(item);
            }

                        #if MM_DEBUG
            if (gen != null)
            {             //position
                Item item = new Item($"Pos: {gen.guiPosition}", onDraw: RightClick.DrawItem, priority: 2);
                item.color        = RightClick.defaultColor;
                item.onClick      = () => EditorGUIUtility.systemCopyBuffer = gen.guiPosition.ToString();
                item.closeOnClick = true;
                genItems.subItems.Add(item);
            }
                        #endif

            return(genItems);
        }