private void pictureBoxTileset_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { return; } int x_ = overlay.SelectTS.Location.X / 16; int y_ = overlay.SelectTS.Location.Y / 16; if (this.selectedTiles == null) { this.selectedTiles = new CopyBuffer(overlay.SelectTS.Width, overlay.SelectTS.Height); } int[] selectedTiles = new int[(overlay.SelectTS.Width / 16) * (overlay.SelectTS.Height / 16)]; for (int y = 0; y < overlay.SelectTS.Height / 16; y++) { for (int x = 0; x < overlay.SelectTS.Width / 16; x++) { int tileX = overlay.SelectTS.X + (x * 16); int tileY = overlay.SelectTS.Y + (y * 16); selectedTiles[y * (overlay.SelectTS.Width / 16) + x] = (y + y_) * 8 + x + x_; } } this.selectedTiles.Copy = selectedTiles; pictureBoxTileset.Focus(); }
/// <summary> /// "Cements" either a dragged selection or a newly pasted selection. /// </summary> /// <param name="buffer">The dragged selection or the newly pasted selection.</param> private void Defloat(CopyBuffer buffer) { byte[] oldTileset = Bits.Copy(Tileset.Tileset_bytes); // selection = null; int x_ = overlay.SelectTS.X / 16; int y_ = overlay.SelectTS.Y / 16; for (int y = 0; y < buffer.Height / 16; y++) { for (int x = 0; x < buffer.Width / 16; x++) { if (y + y_ < 0 || y + y_ >= 16 || x + x_ < 0 || x + x_ >= 16) { continue; } Tile tile = buffer.Tiles[y * (buffer.Width / 16) + x]; Tileset.Tileset_tiles[(y + y_) * 16 + x + x_] = tile.Copy(); Tileset.Tileset_tiles[(y + y_) * 16 + x + x_].Index = (y + y_) * 16 + x + x_; } } Tileset.ParseTileset(Tileset.Tileset_tiles, Tileset.Tileset_bytes); commandStack.Push(commandCount + 1); commandCount = 0; SetWorldMapImage(); defloating = true; // commandStack.Push(new TilesetEdit(Tileset, oldTileset, Model.Graphics, 0x20, name)); }
private void Copy() { if (overlay.SelectTS.Empty) { return; } if (draggedTiles != null) { this.copiedTiles = draggedTiles; return; } // make the copy int x_ = overlay.SelectTS.Location.X / 16; int y_ = overlay.SelectTS.Location.Y / 16; this.copiedTiles = new CopyBuffer(overlay.SelectTS.Width, overlay.SelectTS.Height); Tile[] copiedTiles = new Tile[(overlay.SelectTS.Width / 16) * (overlay.SelectTS.Height / 16)]; for (int y = 0; y < overlay.SelectTS.Height / 16; y++) { for (int x = 0; x < overlay.SelectTS.Width / 16; x++) { copiedTiles[y * (overlay.SelectTS.Width / 16) + x] = Tileset.Tileset_tiles[(y + y_) * 16 + x + x_].Copy(); } } this.copiedTiles.Tiles = copiedTiles; }
public XTMFRuntime(Configuration configuration = null) { CopyBuffer = new CopyBuffer(); this.Configuration = configuration == null ? new Configuration() : configuration; this.ModelSystemController = new ModelSystemController(this); this.ProjectController = new ProjectController(this); }
/// <summary> /// Defloats either a dragged selection or a newly pasted selection. /// </summary> /// <param name="buffer">The dragged selection or the newly pasted selection.</param> private void Defloat(CopyBuffer buffer) { if (buffer == null) { return; } if (overlay.Select.Empty) { return; } Point location = new Point(); location.X = overlay.Select.X / 16; location.Y = overlay.Select.Y / 16; commandStack.Push(new MoldEdit( mold.Tiles, width / 16, height / 16, buffer.CopyBytes(), location.X, location.Y, buffer.Width / 16, buffer.Height / 16)); commandStack.Push(commandCount + 1); commandCount = 0; SetTilemapImage(); if (sequencesForm != null) { sequencesForm.SetFrameImages(); sequencesForm.RealignFrames(); } defloating = true; animation.WriteToBuffer(); }
/// <summary> /// Start dragging a selection. /// </summary> private void Drag() { if (overlay.SelectTS.Empty) { return; } // make the copy int x_ = overlay.SelectTS.Location.X / 16; int y_ = overlay.SelectTS.Location.Y / 16; this.draggedTiles = new CopyBuffer(overlay.SelectTS.Width, overlay.SelectTS.Height); Tile[] draggedTiles = new Tile[(overlay.SelectTS.Width / 16) * (overlay.SelectTS.Height / 16)]; for (int y = 0; y < overlay.SelectTS.Height / 16; y++) { for (int x = 0; x < overlay.SelectTS.Width / 16; x++) { int x__ = (x + x_) & 15; int y__ = (y + y_) & 15; int index = y__ * 16 + x__; index += ((x + x_) >> 4) * 256; index += ((y + y_) >> 4) * 512; if (index >= tileset.Tileset_tiles.Length) { continue; } draggedTiles[y * (overlay.SelectTS.Width / 16) + x] = tileset.Tileset_tiles[index].Copy(); } } this.draggedTiles.Tiles = draggedTiles; selection = new Bitmap(this.draggedTiles.GetImage()); Delete(); }
//Returns multi node context menu static GenericMenu GetNodeMenu_Multi(Graph graph) { var menu = new GenericMenu(); menu.AddItem(new GUIContent("Duplicate Selected Nodes"), false, () => { var newNodes = Graph.CloneNodes(GraphEditorUtility.activeElements.OfType <Node>().ToList(), graph); GraphEditorUtility.activeElements = newNodes.Cast <IGraphElement>().ToList(); }); menu.AddItem(new GUIContent("Copy Selected Nodes"), false, () => { CopyBuffer.Set <Node[]>(Graph.CloneNodes(GraphEditorUtility.activeElements.OfType <Node>().ToList()) .ToArray()); }); //callback graph related extra menu items menu = graph.CallbackOnNodesContextMenu(menu, GraphEditorUtility.activeElements.OfType <Node>().ToArray()); menu.AddSeparator("/"); menu.AddItem(new GUIContent("Delete Selected Nodes"), false, () => { foreach (Node n in GraphEditorUtility.activeElements.ToArray()) { graph.RemoveNode(n); } }); return(menu); }
///Generate and return task menu GenericMenu GetMenu(Action <Task> callback) { var menu = new GenericMenu(); menu.AddItem(new GUIContent("Open Script"), false, () => { EditorUtils.OpenScriptOfType(task.GetType()); }); menu.AddItem(new GUIContent("Copy"), false, () => { CopyBuffer.SetCache <Task>(task); }); foreach (var _m in task.GetType().RTGetMethods()) { var m = _m; var att = m.RTGetAttribute <ContextMenu>(true); if (att != null) { menu.AddItem(new GUIContent(att.menuItem), false, () => { m.Invoke(task, null); }); } } menu.AddSeparator("/"); menu.AddItem(new GUIContent("Delete"), false, () => { if (callback != null) { UndoUtility.RecordObject(task.ownerSystem.contextObject, "Delete Task"); callback(null); } }); return(menu); }
//Shows a button that when clicked, pops a context menu with a list of tasks deriving the base type specified. When something is selected the callback is called //On top of that it also shows a search field for Tasks public static void ShowCreateTaskSelectionButton(ITaskSystem ownerSystem, Type baseType, Action <Task> callback) { GUI.backgroundColor = Colors.lightBlue; var label = "Assign " + baseType.Name.SplitCamelCase(); if (GUILayout.Button(label)) { Action <Type> TaskTypeSelected = (t) => { var newTask = Task.Create(t, ownerSystem); Undo.RecordObject(ownerSystem.contextObject, "New Task"); callback(newTask); }; var menu = EditorUtils.GetTypeSelectionMenu(baseType, TaskTypeSelected); if (CopyBuffer.Has <Task>() && baseType.IsAssignableFrom(CopyBuffer.Peek <Task>().GetType())) { menu.AddSeparator("/"); menu.AddItem(new GUIContent(string.Format("Paste ({0})", CopyBuffer.Peek <Task>().name)), false, () => { callback(CopyBuffer.Get <Task>().Duplicate(ownerSystem)); }); } menu.ShowAsBrowser(label, typeof(Task)); } GUILayout.Space(2); GUI.backgroundColor = Color.white; }
private void editPaste_Click(object sender, EventArgs e) { if (draggedTiles != null) { Defloat(draggedTiles); draggedTiles = null; } Paste(new Point(0, 0), copiedTiles); }
private void Paste() { if (draggedTiles != null) { Defloat(draggedTiles); draggedTiles = null; } Paste(new Point(0, 0), copiedTiles); }
private void InitializeVariables() { this.overlay = new Overlay(); this.pictureBoxMold.ZoomBoxPosition = new Point(64, 0); this.commandStack = new UndoStack(true); this.selectedTiles = null; this.draggedTiles = null; this.copiedTiles = null; this.selection = null; }
//Shows a button that when clicked, pops a context menu with a list of tasks deriving the base type specified. When something is selected the callback is called //On top of that it also shows a search field for Tasks public static void ShowCreateTaskSelectionButton(ITaskSystem ownerSystem, Type baseType, Action <Task> callback) { Action <Type> TaskTypeSelected = (t) => { var newTask = Task.Create(t, ownerSystem); Undo.RecordObject(ownerSystem.contextObject, "New Task"); callback(newTask); }; Func <GenericMenu> GetMenu = () => { var menu = EditorUtils.GetTypeSelectionMenu(baseType, TaskTypeSelected); if (CopyBuffer.Has <Task>() && baseType.IsAssignableFrom(CopyBuffer.Peek <Task>().GetType())) { menu.AddSeparator("/"); menu.AddItem(new GUIContent(string.Format("Paste ({0})", CopyBuffer.Peek <Task>().name)), false, () => { callback(CopyBuffer.Get <Task>().Duplicate(ownerSystem)); }); } return(menu); }; GUI.backgroundColor = Colors.lightBlue; var label = "Assign " + baseType.Name.SplitCamelCase(); if (GUILayout.Button(label)) { GetMenu().ShowAsBrowser(label, typeof(Task)); } GUI.backgroundColor = Color.white; search = EditorUtils.SearchField(search); if (!string.IsNullOrEmpty(search)) { GUILayout.BeginVertical("TextField"); var itemAdded = false; foreach (var taskInfo in EditorUtils.GetScriptInfosOfType(baseType).OrderBy(i => StringUtils.ScoreSearchMatch(search, i.name))) { if (StringUtils.SearchMatch(search, taskInfo.name, taskInfo.category)) { itemAdded = true; if (GUILayout.Button(taskInfo.name)) { search = string.Empty; GUIUtility.keyboardControl = 0; TaskTypeSelected(taskInfo.type); } } } if (!itemAdded) { GUILayout.Label("No results to display with current search input."); } GUILayout.EndVertical(); } }
private void Paste(Point location, CopyBuffer buffer) { if (buffer == null) { return; } moving = true; // now dragging a new selection draggedTiles = buffer; overlay.Select.Set(16, location, buffer.Size, pictureBoxMold); pictureBoxMold.Invalidate(); defloating = false; }
private void Paste(Point location, CopyBuffer buffer) { if (buffer == null) { return; } moving = true; // now dragging a new selection draggedTiles = buffer; selection = buffer.GetImage(); overlay.SelectTS.Set(16, location, buffer.Size, picture); picture.Invalidate(); }
///the connection context menu GenericMenu GetConnectionMenu() { var menu = new GenericMenu(); menu.AddItem(new GUIContent(infoExpanded? "Collapse Info" : "Expand Info"), false, () => { infoExpanded = !infoExpanded; }); menu.AddItem(new GUIContent(isActive? "Disable" : "Enable"), false, () => { isActive = !isActive; }); var assignable = this as ITaskAssignable; if (assignable != null) { if (assignable.task != null) { menu.AddItem(new GUIContent("Copy Assigned Condition"), false, () => { CopyBuffer.Set <Task>(assignable.task); }); } else { menu.AddDisabledItem(new GUIContent("Copy Assigned Condition")); } if (CopyBuffer.Has <Task>()) { menu.AddItem(new GUIContent(string.Format("Paste Assigned Condition ({0})", CopyBuffer.Peek <Task>().name)), false, () => { if (assignable.task == CopyBuffer.Peek <Task>()) { return; } if (assignable.task != null) { if (!EditorUtility.DisplayDialog("Paste Condition", string.Format("Connection already has a Condition assigned '{0}'. Replace assigned condition with pasted condition '{1}'?", assignable.task.name, CopyBuffer.Peek <Task>().name), "YES", "NO")) { return; } } try { assignable.task = CopyBuffer.Get <Task>().Duplicate(graph); } catch { Logger.LogWarning("Can't paste Condition here. Incombatible Types.", "Editor", this); } }); } else { menu.AddDisabledItem(new GUIContent("Paste Assigned Condition")); } } menu.AddSeparator("/"); menu.AddItem(new GUIContent("Delete"), false, () => { graph.RemoveConnection(this); }); return(menu); }
private void Defloat() { if (copiedTiles != null && !defloating) { Defloat(copiedTiles); } if (draggedTiles != null) { Defloat(draggedTiles); draggedTiles = null; } moving = false; overlay.Select.Clear(); Cursor.Position = Cursor.Position; }
public static bool IsTypeInBuffer(Object obj) { var bufferContainsAType = IsValidObjectInBuffer(); if (!bufferContainsAType) { return(false); } var t = obj.GetType(); var copyBufferSplit = CopyBuffer.Split(new string[] { COPY_SPLIT }, StringSplitOptions.None); //Debug.Log("Main Type: " + t + " | Copy Type: " + copyBufferSplit[0]); return(t.ToString() == copyBufferSplit[0]); }
private void Defloat() { // if copied tiles were pasted and not dragging a non-copied selection if (copiedTiles != null && draggedTiles == null) { Defloat(copiedTiles); } if (draggedTiles != null) { Defloat(draggedTiles); draggedTiles = null; } moving = false; selection = null; overlay.SelectTS.Clear(); Cursor.Position = Cursor.Position; }
private void Flip(FlipType flipType) { if (draggedTiles != null) { Defloat(draggedTiles); } if (overlay.SelectTS.Empty) { return; } int x_ = overlay.SelectTS.Location.X / 16; int y_ = overlay.SelectTS.Location.Y / 16; CopyBuffer buffer = new CopyBuffer(overlay.SelectTS.Width, overlay.SelectTS.Height); Tile[] copiedTiles = new Tile[(overlay.SelectTS.Width / 16) * (overlay.SelectTS.Height / 16)]; for (int y = 0; y < overlay.SelectTS.Height / 16; y++) { for (int x = 0; x < overlay.SelectTS.Width / 16; x++) { int x__ = (x + x_) & 15; int y__ = (y + y_) & 15; int index = y__ * 16 + x__; index += ((x + x_) >> 4) * 256; index += ((y + y_) >> 4) * 512; if (index >= tileset.Tileset_tiles.Length) { continue; } copiedTiles[y * (overlay.SelectTS.Width / 16) + x] = tileset.Tileset_tiles[index].Copy(); } } if (flipType == FlipType.Horizontal) { Do.FlipHorizontal(copiedTiles, overlay.SelectTS.Width / 16, overlay.SelectTS.Height / 16); } else if (flipType == FlipType.Vertical) { Do.FlipVertical(copiedTiles, overlay.SelectTS.Width / 16, overlay.SelectTS.Height / 16); } buffer.Tiles = copiedTiles; Defloat(buffer); tileset.ParseTileset(tileset.Tileset_tiles, tileset.Tileset_bytes); SetBattlefieldImage(); }
private void delete_Click(object sender, EventArgs e) { if (!moving) { Delete(); } else { moving = false; draggedTiles = null; pictureBoxMold.Invalidate(); } if (!moving && commandCount > 0) { commandStack.Push(commandCount); commandCount = 0; } }
// Moving /// <summary> /// Start dragging a current selection. /// </summary> private void Drag() { if (overlay.Select.Empty || overlay.Select.Size == new Size(0, 0)) { return; } selection = new Bitmap(tilemapImage.Clone( new Rectangle(overlay.Select.Location, overlay.Select.Size), PixelFormat.DontCare)); int[] copiedTiles = new int[(overlay.Select.Width / 16) * (overlay.Select.Height / 16)]; this.draggedTiles = new CopyBuffer(overlay.Select.Width, overlay.Select.Height); for (int y = 0, y_ = overlay.Select.Y / 16; y < overlay.Select.Height / 16; y++, y_++) { for (int x = 0, x_ = overlay.Select.X / 16; x < overlay.Select.Width / 16; x++, x_++) { int tileX = overlay.Select.X + (x * 16); int tileY = overlay.Select.Y + (y * 16); copiedTiles[y * (overlay.Select.Width / 16) + x] = mold.Tiles[y_ * (width / 16) + x_]; } } this.draggedTiles.Copy = copiedTiles; Delete(); }
/// <summary> /// "Cements" either a dragged selection or a newly pasted selection. /// </summary> /// <param name="buffer">The dragged selection or the newly pasted selection.</param> private void Defloat(CopyBuffer buffer) { byte[] oldTileset = Bits.Copy(tileset.Tileset_bytes); // selection = null; int x_ = overlay.SelectTS.X / 16; int y_ = overlay.SelectTS.Y / 16; for (int y = 0; y < buffer.Height / 16; y++) { for (int x = 0; x < buffer.Width / 16; x++) { int x__ = (x + x_) & 15; int y__ = (y + y_) & 15; int index = y__ * 16 + x__; index += ((x + x_) >> 4) * 256; index += ((y + y_) >> 4) * 512; if (index >= tileset.Tileset_tiles.Length || index < 0) { continue; } if (y < 0 || x < 0) { continue; } Tile tile = buffer.Tiles[y * (buffer.Width / 16) + x]; tileset.Tileset_tiles[index] = tile.Copy(); tileset.Tileset_tiles[index].Index = index; } } tileset.ParseTileset(tileset.Tileset_tiles, tileset.Tileset_bytes); commandStack.Push(commandCount + 1); commandCount = 0; SetBattlefieldImage(); // commandStack.Push(new TilesetEdit(tileset, oldTileset, this)); }
private void Copy() { if (overlay.SelectTS.Empty) { return; } if (draggedTiles != null) { this.copiedTiles = draggedTiles; return; } // make the copy int x_ = overlay.SelectTS.Location.X / 16; int y_ = overlay.SelectTS.Location.Y / 16; this.copiedTiles = new CopyBuffer(overlay.SelectTS.Width, overlay.SelectTS.Height); Tile[] copiedTiles = new Tile[(overlay.SelectTS.Width / 16) * (overlay.SelectTS.Height / 16)]; for (int y = 0; y < overlay.SelectTS.Height / 16; y++) { for (int x = 0; x < overlay.SelectTS.Width / 16; x++) { int x__ = (x + x_) & 15; int y__ = (y + y_) & 15; int index = y__ * 16 + x__; index += ((x + x_) >> 4) * 256; index += ((y + y_) >> 4) * 512; if (index >= tileset.Tileset_tiles.Length) { continue; } copiedTiles[y * (overlay.SelectTS.Width / 16) + x] = tileset.Tileset_tiles[index].Copy(); } } this.copiedTiles.Tiles = copiedTiles; }
///<summary>Generate and return task menu</summary> GenericMenu GetMenu(Action <Task> callback) { var menu = new GenericMenu(); var taskType = task.GetType(); menu.AddItem(new GUIContent("Open Script"), false, () => { EditorUtils.OpenScriptOfType(taskType); }); menu.AddItem(new GUIContent("Copy"), false, () => { CopyBuffer.SetCache <Task>(task); }); foreach (var _m in taskType.RTGetMethods()) { var m = _m; var att = m.RTGetAttribute <ContextMenu>(true); if (att != null) { menu.AddItem(new GUIContent(att.menuItem), false, () => { m.Invoke(task, null); }); } } if (taskType.IsGenericType) { menu = EditorUtils.GetPreferedTypesSelectionMenu(taskType.GetGenericTypeDefinition(), (t) => { callback(Task.Create(t, task.ownerSystem)); }, menu, "Change Generic Type"); } menu.AddSeparator("/"); menu.AddItem(new GUIContent("Delete"), false, () => { if (callback != null) { UndoUtility.RecordObject(task.ownerSystem.contextObject, "Delete Task"); callback(null); } }); return(menu); }
private void Flip(FlipType flipType) { if (draggedTiles != null) { Defloat(draggedTiles); } if (overlay.SelectTS.Empty) { return; } int x_ = overlay.SelectTS.Location.X / 16; int y_ = overlay.SelectTS.Location.Y / 16; CopyBuffer buffer = new CopyBuffer(overlay.SelectTS.Width, overlay.SelectTS.Height); Tile[] copiedTiles = new Tile[(overlay.SelectTS.Width / 16) * (overlay.SelectTS.Height / 16)]; for (int y = 0; y < overlay.SelectTS.Height / 16; y++) { for (int x = 0; x < overlay.SelectTS.Width / 16; x++) { copiedTiles[y * (overlay.SelectTS.Width / 16) + x] = Tileset.Tileset_tiles[(y + y_) * 16 + x + x_].Copy(); } } if (flipType == FlipType.Horizontal) { Do.FlipHorizontal(copiedTiles, overlay.SelectTS.Width / 16, overlay.SelectTS.Height / 16); } else if (flipType == FlipType.Vertical) { Do.FlipVertical(copiedTiles, overlay.SelectTS.Width / 16, overlay.SelectTS.Height / 16); } buffer.Tiles = copiedTiles; Defloat(buffer); Tileset.ParseTileset(Tileset.Tileset_tiles, Tileset.Tileset_bytes); SetWorldMapImage(); }
/// <summary> /// Start dragging a selection. /// </summary> private void Drag() { if (overlay.SelectTS.Empty) { return; } // make the copy int x_ = overlay.SelectTS.Location.X / 16; int y_ = overlay.SelectTS.Location.Y / 16; this.draggedTiles = new CopyBuffer(overlay.SelectTS.Width, overlay.SelectTS.Height); Tile[] draggedTiles = new Tile[(overlay.SelectTS.Width / 16) * (overlay.SelectTS.Height / 16)]; for (int y = 0; y < overlay.SelectTS.Height / 16; y++) { for (int x = 0; x < overlay.SelectTS.Width / 16; x++) { draggedTiles[y * (overlay.SelectTS.Width / 16) + x] = Tileset.Tileset_tiles[(y + y_) * 16 + x + x_].Copy(); } } this.draggedTiles.Tiles = draggedTiles; selection = new Bitmap(this.draggedTiles.GetImage()); Delete(); }
///---------------------------------------------------------------------------------------------- ///Graph events AFTER nodes static void HandlePostNodesGraphEvents(Graph graph, Vector2 canvasMousePos) { //Shortcuts if (GUIUtility.keyboardControl == 0) { //Copy/Cut/Paste if (e.type == EventType.ValidateCommand || e.type == EventType.Used) { if (e.commandName == "Copy" || e.commandName == "Cut") { List <Node> selection = null; if (GraphEditorUtility.activeNode != null) { selection = new List <Node> { GraphEditorUtility.activeNode }; } if (GraphEditorUtility.activeElements != null && GraphEditorUtility.activeElements.Count > 0) { selection = GraphEditorUtility.activeElements.Cast <Node>().ToList(); } if (selection != null) { CopyBuffer.Set <Node[]>(Graph.CloneNodes(selection).ToArray()); if (e.commandName == "Cut") { foreach (Node node in selection) { graph.RemoveNode(node); } } } e.Use(); } if (e.commandName == "Paste") { if (CopyBuffer.Has <Node[]>()) { TryPasteNodesInGraph(graph, CopyBuffer.Get <Node[]>(), canvasMousePos + new Vector2(500, 500) / graph.zoomFactor); } e.Use(); } } if (e.type == EventType.KeyUp) { //Delete if (e.keyCode == KeyCode.Delete || e.keyCode == KeyCode.Backspace) { if (GraphEditorUtility.activeElements != null && GraphEditorUtility.activeElements.Count > 0) { foreach (var obj in GraphEditorUtility.activeElements.ToArray()) { if (obj is Node) { graph.RemoveNode(obj as Node); } if (obj is Connection) { graph.RemoveConnection(obj as Connection); } } GraphEditorUtility.activeElements = null; } if (GraphEditorUtility.activeNode != null) { graph.RemoveNode(GraphEditorUtility.activeNode); GraphEditorUtility.activeElement = null; } if (GraphEditorUtility.activeConnection != null) { graph.RemoveConnection(GraphEditorUtility.activeConnection); GraphEditorUtility.activeElement = null; } e.Use(); } //Duplicate if (e.keyCode == KeyCode.D && e.control) { if (GraphEditorUtility.activeElements != null && GraphEditorUtility.activeElements.Count > 0) { TryPasteNodesInGraph(graph, GraphEditorUtility.activeElements.OfType <Node>().ToArray(), default(Vector2)); } if (GraphEditorUtility.activeNode != null) { GraphEditorUtility.activeElement = GraphEditorUtility.activeNode.Duplicate(graph); } //Connections can't be duplicated by themselves. They do so as part of multiple node duplication. e.Use(); } } } //No panel is obscuring if (GraphEditorUtility.allowClick) { //'Tilt' or 'Space' keys, opens up the complete context menu browser if (e.type == EventType.KeyDown && !e.shift && (e.keyCode == KeyCode.BackQuote || e.keyCode == KeyCode.Space)) { GenericMenuBrowser.Show(GetAddNodeMenu(graph, canvasMousePos), e.mousePosition, string.Format("Add {0} Node", graph.GetType().FriendlyName()), graph.baseNodeType); e.Use(); } //Right click canvas context menu. Basicaly for adding new nodes. if (e.type == EventType.ContextClick) { var menu = GetAddNodeMenu(graph, canvasMousePos); if (CopyBuffer.Has <Node[]>() && CopyBuffer.Peek <Node[]>()[0].GetType().IsSubclassOf(graph.baseNodeType)) { menu.AddSeparator("/"); var copiedNodes = CopyBuffer.Get <Node[]>(); if (copiedNodes.Length == 1) { menu.AddItem(new GUIContent(string.Format("Paste Node ({0})", copiedNodes[0].GetType().FriendlyName())), false, () => { TryPasteNodesInGraph(graph, copiedNodes, canvasMousePos); }); } else if (copiedNodes.Length > 1) { menu.AddItem(new GUIContent(string.Format("Paste Nodes ({0})", copiedNodes.Length.ToString())), false, () => { TryPasteNodesInGraph(graph, copiedNodes, canvasMousePos); }); } } if (NCPrefs.useBrowser) { menu.ShowAsBrowser(e.mousePosition, string.Format("Add {0} Node", graph.GetType().FriendlyName()), graph.baseNodeType); } else { menu.ShowAsContext(); } e.Use(); } } }
//Returns single node context menu static GenericMenu GetNodeMenu_Single(Node node) { var menu = new GenericMenu(); if ( node.graph.primeNode != node && node.allowAsPrime ) { menu.AddItem(new GUIContent("Set Start"), false, () => { node.graph.primeNode = node; }); } if ( node is IGraphAssignable ) { menu.AddItem(new GUIContent("Edit Nested (Double Click)"), false, () => { node.graph.currentChildGraph = ( node as IGraphAssignable ).nestedGraph; }); } menu.AddItem(new GUIContent("Duplicate (CTRL+D)"), false, () => { GraphEditorUtility.activeElement = node.Duplicate(node.graph); }); menu.AddItem(new GUIContent("Copy Node"), false, () => { CopyBuffer.Set<Node[]>(new Node[] { node }); }); if ( node.inConnections.Count > 0 ) { menu.AddItem(new GUIContent(node.isActive ? "Disable" : "Enable"), false, () => { node.SetActive(!node.isActive); }); } if ( node.graph.isTree && node.outConnections.Count > 0 ) { menu.AddItem(new GUIContent(node.collapsed ? "Expand Children" : "Collapse Children"), false, () => { node.collapsed = !node.collapsed; }); } if ( node is ITaskAssignable ) { var assignable = node as ITaskAssignable; if ( assignable.task != null ) { menu.AddItem(new GUIContent("Copy Assigned Task"), false, () => { CopyBuffer.Set<Task>(assignable.task); }); } else { menu.AddDisabledItem(new GUIContent("Copy Assigned Task")); } if ( CopyBuffer.Has<Task>() ) { menu.AddItem(new GUIContent("Paste Assigned Task"), false, () => { if ( assignable.task == CopyBuffer.Peek<Task>() ) { return; } if ( assignable.task != null ) { if ( !EditorUtility.DisplayDialog("Paste Task", string.Format("Node already has a Task assigned '{0}'. Replace assigned task with pasted task '{1}'?", assignable.task.name, CopyBuffer.Peek<Task>().name), "YES", "NO") ) { return; } } try { assignable.task = CopyBuffer.Get<Task>().Duplicate(node.graph); } catch { ParadoxNotion.Services.Logger.LogWarning("Can't paste Task here. Incombatible Types", "Editor", node); } }); } else { menu.AddDisabledItem(new GUIContent("Paste Assigned Task")); } } //extra items with override menu = node.OnContextMenu(menu); if ( menu != null ) { //extra items with attribute foreach ( var _m in node.GetType().RTGetMethods() ) { var m = _m; var att = m.RTGetAttribute<ContextMenu>(true); if ( att != null ) { menu.AddItem(new GUIContent(att.menuItem), false, () => { m.Invoke(node, null); }); } } menu.AddSeparator("/"); menu.AddItem(new GUIContent("Delete (DEL)"), false, () => { node.graph.RemoveNode(node); }); } return menu; }
///Handle UI events void HandleEvents(Vector2 lineFrom, Vector2 lineTo) { var e = Event.current; //On click select this connection if (GraphEditorUtility.allowClick && e.type == EventType.MouseDown && e.button == 0) { if (IsPositionAlongConnection(lineFrom, lineTo, e.mousePosition) || centerRect.Contains(e.mousePosition) || startRect.Contains(e.mousePosition) || endRect.Contains(e.mousePosition)) { if (canRelink) { isRelinking = true; relinkClickPos = e.mousePosition; } GraphEditorUtility.activeElement = this; //双击 if ((this.GetType() == (typeof(FlowCanvas.BinderConnection)) || this.GetType().IsSubclassOf(typeof(FlowCanvas.BinderConnection))) && e.clickCount == 2) { graph.InsetNodeBetweenConnect((FlowCanvas.BinderConnection) this, e.mousePosition); } e.Use(); return; } } if (canRelink && isRelinking) { if (Vector2.Distance(relinkClickPos, e.mousePosition) > RELINK_DISTANCE_SNAP) { Handles.DrawBezier(startRect.center, e.mousePosition, startRect.center, e.mousePosition, defaultColor, null, defaultSize); } if (e.rawType == EventType.MouseUp && e.button == 0) { foreach (var node in graph.allNodes) { if (node != targetNode && node != sourceNode && node.rect.Contains(e.mousePosition) && node.IsNewConnectionAllowed()) { SetTarget(node); break; } } isRelinking = false; e.Use(); } } if (GraphEditorUtility.allowClick && e.type == EventType.MouseDown && e.button == 1 && centerRect.Contains(e.mousePosition)) { var menu = new GenericMenu(); menu.AddItem(new GUIContent(infoExpanded? "Collapse Info" : "Expand Info"), false, () => { infoExpanded = !infoExpanded; }); menu.AddItem(new GUIContent(isActive? "Disable" : "Enable"), false, () => { isActive = !isActive; }); var assignable = this as ITaskAssignable; if (assignable != null) { if (assignable.task != null) { menu.AddItem(new GUIContent("Copy Assigned Condition"), false, () => { CopyBuffer.Set <Task>(assignable.task); }); } else { menu.AddDisabledItem(new GUIContent("Copy Assigned Condition")); } if (CopyBuffer.Has <Task>()) { menu.AddItem(new GUIContent(string.Format("Paste Assigned Condition ({0})", CopyBuffer.Peek <Task>().name)), false, () => { if (assignable.task == CopyBuffer.Peek <Task>()) { return; } if (assignable.task != null) { if (!EditorUtility.DisplayDialog("Paste Condition", string.Format("Connection already has a Condition assigned '{0}'. Replace assigned condition with pasted condition '{1}'?", assignable.task.name, CopyBuffer.Peek <Task>().name), "YES", "NO")) { return; } } try { assignable.task = CopyBuffer.Get <Task>().Duplicate(graph); } catch { Logger.LogWarning("Can't paste Condition here. Incombatible Types.", "Editor", this); } }); } else { menu.AddDisabledItem(new GUIContent("Paste Assigned Condition")); } } menu.AddSeparator("/"); menu.AddItem(new GUIContent("Delete"), false, () => { graph.RemoveConnection(this); }); GraphEditorUtility.PostGUI += () => { menu.ShowAsContext(); }; e.Use(); } }