示例#1
0
		private void DrawMiniSelected () 
		{
			if (selected.Count != 1)
				return;

			Generator gen = selected.Any();

			Vector2 cellSize = new Vector2(gen.guiSize.x, 0);
			Vector2 cellPos = PlaceByAnchor(graph.guiMiniAnchor, graph.guiMiniPos, gen.guiSize);

			using (Cell.Custom(cellPos, cellSize))
			{
				//dragging
				if (!UI.current.layout)
				{
					if (DragDrop.TryDrag(Cell.current, UI.current.mousePos))
					{
						Vector2 newPosition = GeneratorDraw.MoveGenerator(Cell.current, DragDrop.initialRect.position + DragDrop.totalDelta);
						(graph.guiMiniAnchor, graph.guiMiniPos) = GetAnchorPos(newPosition, gen.guiSize);
					}
					DragDrop.TryRelease(Cell.current);
					DragDrop.TryStart(Cell.current, UI.current.mousePos, Cell.current.InternalRect);
				}

				//shadow
				//GUIStyle shadowStyle = UI.current.textures.GetElementStyle("MapMagic/Node/ShadowMini", 
				//	borders:GeneratorDraw.shadowBorders,
				//	overflow:GeneratorDraw.shadowOverflow);
				//Draw.Element(shadowStyle);

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

				//right click menu (should have access to cellObjs)
				if (!UI.current.layout  &&  Event.current.type == EventType.MouseDown  &&  Event.current.button == 1)
					RightClick.DrawRightClickItems(miniSelectedUI, miniSelectedUI.mousePos, graph);
			}
		}
示例#2
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);
		}