public void Move4Test() { const string xml = "<xml><eins/><zwei/></xml>"; XmlDocument xmldoc = xml.ToXmlDocument(); var root = xmldoc.DocumentElement; var first = xmldoc.DocumentElement.FirstChild; string res = NodeMover.Move(root, first); }
public void Init() { normalNode = GameObject.Instantiate(normalPrefab); hardNode = GameObject.Instantiate(hardPrefab); normalNode.Clicked += OnNormalSequenceSelected; hardNode.Clicked += OnHardSequenceSelected; gameObject.SetActive(true); GetComponent <CanvasGroup>().DOFade(1, 0.5f); }
public void InsertBefore3Test() { const string xml = "<xml><eins/><zwei/></xml>"; XmlDocument xmldoc = xml.ToXmlDocument(); var root = xmldoc.DocumentElement; var first = xmldoc.DocumentElement.FirstChild; var second = xmldoc.DocumentElement.LastChild; string res = NodeMover.InsertBefore(root, second); }
public void Move2Test() { const string xml = "<xml><eins/><zwei/></xml>"; XmlDocument xmldoc = xml.ToXmlDocument(); var first = xmldoc.DocumentElement.FirstChild; var second = xmldoc.DocumentElement.LastChild; string res = NodeMover.Move(first, second); const string exp = "<xml><zwei><eins /></zwei></xml>"; StringAssert.Contains(res, exp); }
public void InsertBeforeTest() { const string xml = "<xml><eins/><zwei/></xml>"; XmlDocument xmldoc = xml.ToXmlDocument(); var root = xmldoc.DocumentElement; var first = xmldoc.DocumentElement.FirstChild; var second = xmldoc.DocumentElement.LastChild; string res = NodeMover.InsertBefore(second, first); const string exp = "<xml><zwei /><eins /></xml>"; StringAssert.Contains(res, exp); }
IEnumerator Blink(NodeMover node) { while (node.isActiveAndEnabled && node.IsLive) { node.LightBy(this); yield return(new WaitForSeconds(0.3f)); if ((!node.isActiveAndEnabled) || (!node.IsLive)) { yield break; } node.UnLightBy(this); yield return(new WaitForSeconds(0.3f)); } }
public void Add(NodeMover node, Beam beam) { _Nodes.Add(node); _Beams.Add(beam); bool hadMultipleColors = (_Colors.Count > 1) || (node.Colors.Length > 1); if (_Nodes.Count == 1) { _Colors = new HashSet <NodeColor>(node.Colors); } else { _Colors.IntersectWith(node.Colors); } if (hadMultipleColors && _Colors.Count == 1) { _Beams.ForEach(bm => bm.SetColor(_Colors.ElementAt(0).ToType())); } }
public void ReStart() { tweens.ForEach(tw => tw.Kill()); tweens.Clear(); gameObject.SetActive(true); CanvasGroup canvasGroup = GetComponent <CanvasGroup>(); canvasGroup.alpha = 0; tweens.Add(canvasGroup.DOFade(1, 0.5f)); sequenceNodesParent.Children.Clear(); foreach (Sequence seq in sequences) { NodeMover node = Instantiate(nodePrefab); sequenceNodesParent.Children.Add(node.transform); node.Clicked += (_, __) => OnSequenceSelected(seq); node.GetComponent <MeshRenderer>().material.SetTexture("_MainTex", tTRenderer.Render(seq.Data.Name)); nodes.Add(node); } }
private void moveItem(TreeViewItem sourceItem, TreeViewItem targetItem) { ViewerNode source = (ViewerNode)sourceItem.Tag; ViewerNode target = (ViewerNode)targetItem.Tag; if (source == target) { return; } TaskDialogResult res = TaskDialog.Show( new TaskDialogOptions { AllowDialogCancellation = true, Owner = Application.Current.MainWindow, Title = "Move node", MainInstruction = "Where do you like to drop to source node?", Content = "Source: " + source + "\nTarget: " + target, CommandButtons = new[] { "Make child", "Insert before", "Insert after", "Cancel" }, MainIcon = VistaTaskDialogIcon.Information, ExpandedInfo = "Source: " + source.XPath + "\nTarget: " + target.XPath }); try { string newXml = null; switch (res.CommandButtonResult) { case 0: //make child newXml = NodeMover.Move(source.OriginalNode, target.OriginalNode); break; case 1: //insert before newXml = NodeMover.InsertBefore(source.OriginalNode, target.OriginalNode); break; case 2: //insert after newXml = NodeMover.InsertAfter(source.OriginalNode, target.OriginalNode); break; case 3: //cancel break; case null: //cancel by closing window break; default: Debug.Fail(""); break; } if (newXml != null) { Update(new XSDocument(newXml)); if (XmlChanged != null) { XmlChanged(newXml); } } } catch (Exception e) { MessageBox.Show(Application.Current.MainWindow, e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public BoardManager LoadBoard(StageData stage) { BoardManager board = Instantiate(boardPrefab); Vector2Int numNodeGaps = new Vector2Int( stage.Rows.Max(row => row.Nodes.Count()) - 1, stage.Rows.Count - 1 ); //ステージの実際のサイズ決定 Vector2 actualSize; if (stage.DistanceUnit != Vector2.zero) { //ステージのデータで決まってる場合それを使う actualSize = numNodeGaps * stage.DistanceUnit; } else { if ((float)numNodeGaps.x / numNodeGaps.y > stageSizeDefault.x / stageSizeDefault.y) { //横長の場合、横は目一杯広げてyはそれに合わせる actualSize.x = stageSizeDefault.x; actualSize.y = actualSize.x * ((float)numNodeGaps.y / numNodeGaps.x); } else { //縦長の場合、縦は目一杯広げてxはそれに合わせる actualSize.y = stageSizeDefault.y; actualSize.x = actualSize.y * ((float)numNodeGaps.x / numNodeGaps.y); } } Vector2 distanceUnit = actualSize / numNodeGaps; for (int i = 0; i < stage.Rows.Count; i++) { Transform row = Instantiate(rowPrefab, board.transform).transform; (float upBound, float downBound) = (actualSize.y / 2, -actualSize.y / 2); row.position += new Vector3(0, Mathf.Lerp(upBound, downBound, (float)i / (stage.Rows.Count - 1)), 0); for (int j = 0; j < stage.Rows[i].Nodes.Count; j++) { NodeType type = stage.Rows[i].Nodes[j]; if (type != NodeType.None) { NodeMover node = Instantiate(TypeDataHolder.Instance[type].Prefab, row); (float leftBound, float rightBound) = (-actualSize.x / 2, actualSize.x / 2); node.transform.position += new Vector3( Mathf.Lerp(leftBound, rightBound, (float)j / (stage.Rows[i].Nodes.Count - 1)), 0, 0 ); if (node.Bomb != null) { node.Bomb.SetRadius(distanceUnit.y * stage.BombRadius); } } } } return(board); }
protected override void Execute(EditorFrame ef, TreeViewItem parameter, ViewerNode selectedNode, XmlDocument xmldoc, XmlNode node, XmlNode parentNode) { ef.XmlEditor.Text = NodeMover.MoveUp(node); ef._editorTree.Update(); ef._editorTree.tree.ExpandAll(); }
/// <summary> /// When an answer's vary in repeat changes: /// - move the node /// - change its xpath /// - change the databinding in all relevant controls /// </summary> /// <param name="questionID"></param> /// <param name="xp"></param> /// <param name="answersPart"></param> public void moveIfNecessary(string questionID, xpathsXpath xp, Office.CustomXMLPart answersPart) { string varyInRepeat = getVaryingRepeat( ); if (varyInRepeat == null) { // make the answer top level and we're done. NodeMover nm = new NodeMover(); nm.Move(xp.dataBinding.xpath, "/oda:answers"); nm.adjustBinding(thisQuestionControls, "/oda:answers", questionID); } else { // Move it to the selected repeat // get the node corresponding to the repeat's row Office.CustomXMLNode node = answersPart.SelectSingleNode("//oda:repeat[@qref='" + varyInRepeat + "']/oda:row[1]"); if (node == null) { log.Error("no node for nested repeat " + varyInRepeat); } string toRepeat = NodeToXPath.getXPath(node); NodeMover nm = new NodeMover(); nm.Move(xp.dataBinding.xpath, toRepeat); nm.adjustBinding(thisQuestionControls, toRepeat, questionID); } }
private void ProcessEvents(Event e) { if (!mapRect.Contains(e.mousePosition)) // if mouse not inside the middle map area { return; } bool used = true; Vector2 mousePos = (e.mousePosition - offset - mapRect.position - new Vector2(mapRect.width / 2, mapRect.height / 2)) / zoomLevel; switch (e.type) { case EventType.MouseDown: if (e.button == 0) // left click { dragged = false; currentDrag = DragType.Position; if (!GetNodeFromPosition(mousePos, out BNode node)) // is mouse hovering over box { break; } // check if the click was on one of the connection boxes and the node was not the root node if (inPlayMode == false && GetConnection(mousePos, node, out bool isTop) && isTop && node != rootNode) { currentDrag = DragType.NodeConnection; RemoveConnection(node); Vector3 connectionMiddlePos = isTop ? GetUpperMiddle(node) : GetLowerMiddle(node); connectionConstructor = new ConnectionConstructor(node, connectionMiddlePos, isTop, mousePos); } else // click was not on the connection boxes { currentDrag = DragType.Node; nodeMover = new NodeMover(node, node.boundsInEditor.position - mousePos); } } break; case EventType.MouseDrag: if (e.button == 0) // left click { switch (currentDrag) { case DragType.None: goto MouseDragFinished; // skip the changed set to true flag case DragType.Node: if (inPlayMode == true) { break; } Rect toChange = nodeMover.node.boundsInEditor; Vector2 newPos = mousePos + nodeMover.clickedPosition; newPos /= SNAPPING_PIXELS; newPos.x = Mathf.Round(newPos.x); newPos.y = Mathf.Round(newPos.y); toChange.position = newPos * SNAPPING_PIXELS; nodeMover.node.boundsInEditor = toChange; break; case DragType.Position: offset += e.delta; break; case DragType.NodeConnection: connectionConstructor.mousePos = mousePos; break; } GUI.changed = true; MouseDragFinished: dragged = true; } break; case EventType.MouseUp: if (e.button == 0) // left click { if (dragged == false) { selectedObject = null; if (nodeMover != null) { selectedObject = nodeMover.node; } } else // if dragged == true { if (currentDrag == DragType.Node) // Save the position of the dragged node { Rect toChange = nodeMover.node.boundsInEditor; ShapesUtil.RectRoundToNextInt(ref toChange); nodeMover.node.boundsInEditor = toChange; // The node was moved so the order of the parented children might be wrong if (GetParentNode(nodeMover.node, out BNode parent)) { SortChildren(parent); } AssetDatabase.SaveAssets(); } else if (currentDrag == DragType.NodeConnection) // try to connect the node to its new parent { TryConnectNodeFromPosition(mousePos); } // end if currentDrag is NodeConnection } // end if dragged dragged = false; currentDrag = DragType.None; nodeMover = null; connectionConstructor = null; } else if (e.button == 1) // right click { if (inPlayMode == true) { break; } if (!dragged) { if (GetNodeFromPosition(mousePos, out BNode deleteNode)) // is mouse hovering over node { // Show delete menu for node GenericMenu nodeMenu = new GenericMenu(); nodeMenu.AddItem(new GUIContent("Delete"), false, () => { RemoveNode(deleteNode); Reload(); }); nodeMenu.ShowAsContext(); } else // mouse was not over node { // show menu for creating a new node GenericMenu nodeMenu = new GenericMenu(); for (int i = 0; i < nodeTypes.Length; i++) { Type type = nodeTypes[i]; int maxNumberOfChilds = allNodesForTypes[i].MaxNumberOfChildren; string nodeName = nodeTypes[i].Name; if (nodeName.EndsWith("node", StringComparison.OrdinalIgnoreCase)) { nodeName = nodeName.Substring(0, nodeName.Length - 4); } string prefix; if (type.IsSubclassOf(typeof(BoolNode))) { prefix = NODES_INHERIT_FROM_BOOLNODE_STRING; } else if (maxNumberOfChilds == -1 || maxNumberOfChilds > 0) { prefix = NODES_WITH_CHILDREN_STRING; } else { prefix = NODES_WITH_NO_CHILDREN_STRING; } nodeMenu.AddItem(new GUIContent(prefix + "/" + nodeName, allNodesForTypes[i].StringToolTip), false, () => { BNode createNode = (BNode)CreateInstance(type); createNode.name = createNode.GetType().Name; createNode.boundsInEditor = new Rect(mousePos, new Vector2(80, 80)); AssetDatabase.AddObjectToAsset(createNode, tree.targetObject); AssetDatabase.SaveAssets(); Reload(); }); } nodeMenu.ShowAsContext(); } } } break; case EventType.ScrollWheel: zoomLevel = Mathf.Clamp(zoomLevel - e.delta.y / 50, MIN_ZOOM_LEVEL, MAX_ZOOM_LEVEL); GUI.changed = true; break; default: used = false; break; } if (used) // consume event if used { e.Use(); } }