Exemplo n.º 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);
					}
				}
			}
		}
Exemplo n.º 2
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);
		}
Exemplo n.º 3
0
		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);
		}
Exemplo n.º 4
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)));
			}
		}