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 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)));
			}
		}