Example #1
0
		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);
					}
				}
			}
		}
Example #2
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);
        }
Example #3
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)));
			}
		}
        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);
        }