/// <summary> /// Handles the Click event of the makePrototypeButton control. /// Makes the actor a prototype. /// First checks if the actor contains any scene specific variable values, if yes then it shows an option to automatically clear this values. /// </summary> private void makePrototypeButton_Click(object sender, EventArgs e) { // clone actor Actor clonedActor = (Actor)CloningHelper.Clone(Actor); // check if actor contains scene specific variable values (for actor and path) HashSet <ItemForDeletion> itemsToClear = new HashSet <ItemForDeletion>(); List <Actor> allActors = new List <Actor>(); AddAllActors(clonedActor, allActors); CheckActorBeforeMakingPrototype(clonedActor, allActors, itemsToClear); if (itemsToClear.Count == 0) { Project.Singleton.Prototypes.Add(clonedActor); Messages.ShowInfo("Prototype created."); } else { if (MessageBox.Show("Actor contains scene specific variable values. Do you want to clear these values to create prototype?", "Make Prototype", MessageBoxButtons.YesNoCancel) == DialogResult.Yes) { foreach (ItemForDeletion item in itemsToClear) { item.Delete(); } Project.Singleton.Prototypes.Add(clonedActor); Messages.ShowInfo("Prototype created."); } } }
/// <summary> /// Handles the DragDrop event of the SceneScreenControl control. /// If drawable asset is dropped to the scene new actor with the specified drawable asset is created and added to the scene. /// If prototype (actor) is dropped to the scene the prototype is cloned and added to the scene. /// </summary> private void SceneScreenControl_DragDrop(object sender, DragEventArgs e) { Vector2 position = PointAtScene(PointToClient(new System.Drawing.Point(e.X, e.Y))); if (e.Data.GetDataPresent(typeof(DrawableAsset))) { DrawableAsset drawableAsset = (DrawableAsset)e.Data.GetData(typeof(DrawableAsset)); if (drawableAsset != null) { if (Scene.SelectedLayer == null) { Messages.ShowWarning("No layer selected."); return; } // create new actor Actor newActor = new Actor(drawableAsset, position); // add to the scene selected layer Scene.SelectedLayer.Add(newActor); // add dropped objects to the history History.Add(newActor.CreateAddCommand()); } } else if (e.Data.GetDataPresent(typeof(Actor))) { Actor actor = (Actor)e.Data.GetData(typeof(Actor)); if (actor != null) { if (Scene.SelectedLayer == null) { Messages.ShowWarning("No layer selected."); return; } // create new actor Actor newActor = (Actor)CloningHelper.Clone(actor); newActor.Position = position; // add to the scene selected layer Scene.SelectedLayer.Add(newActor); // add dropped objects to the history History.Add(newActor.CreateAddCommand()); } } }
/// <inheritdoc /> /// <summary> /// Saves the selected scene nodes to the clipboard by Ctrl+C. /// Pastes the scene nodes from the clipboard by Ctrl+V. /// Deletes the selected scene nodes from the scene by Delete. /// </summary> public override void KeyDown(object sender, KeyEventArgs e) { base.KeyDown(sender, e); // copy selected objects at the scene to the clipboard if (e.Control && e.KeyCode == Keys.C) { // clear the current clipboard Screen.Clipboard.Clear(); // rectangle of selected nodes for calculate clipboard position Vector2? lowerBound = null, upperBound = null; // add selected objects at the scene to the clipboard foreach (SceneNode selectedNode in Screen.SelectedNodes) { if (selectedNode.Visible) { Screen.Clipboard.Add(selectedNode); if (lowerBound == null) { lowerBound = selectedNode.Rectangle.LowerBound; upperBound = selectedNode.Rectangle.UpperBound; } else { lowerBound = Vector2.Min(lowerBound.Value, selectedNode.Rectangle.LowerBound); upperBound = Vector2.Max(upperBound.Value, selectedNode.Rectangle.UpperBound); } } } // calculate clipboard position if (lowerBound != null) Screen.ClipboardPosition = 0.5f * (lowerBound.Value + upperBound.Value); } // paste objects from clipboard to the scene else if (e.Control && e.KeyCode == Keys.V && Screen.Clipboard.Count != 0) { // compute move vector for placing objects at the correct position at the scene Vector2 moveVector = Screen.MouseScenePosition - Screen.ClipboardPosition; // save copied objects to the history CompositeCommand command = new CompositeCommand(); List<GameObject> objectsToCloned = new List<GameObject>(); // copy all objects from clipboard to the scene foreach (SceneNode node in Screen.Clipboard) { if (node.Visible && !ContainsAnyParent(Screen.Clipboard, node)) { objectsToCloned.Add(node.Tag); } } foreach (GameObject clonedObject in CloningHelper.Clone(objectsToCloned, Screen.Scene.SelectedLayer, true, true)) { // move object to the new position Screen.Find(clonedObject).Move(moveVector); command.Commands.Add(clonedObject.CreateAddCommand()); } // add command to history if (command.Commands.Count != 0) Screen.History.Add(command); } // delete selected objects from the scene and copy them to the clipboard // NOT WORKING when safe deleting is on because it will clear clipboard /*else if (e.Control && e.KeyCode == Keys.X) { // clear the current clipboard Screen.Clipboard.Clear(); // rectangle of selected nodes for calculate clipboard position Vector2? lowerBound = null, upperBound = null; // save deleted objects to the history CompositeCommand command = new CompositeCommand(); List<ItemForDeletion> itemsForDeletion = new List<ItemForDeletion>(); // add selected objects at the scene to the clipboard foreach (SceneNode selectedNode in Screen.SelectedNodes) { if (selectedNode.Visible) { command.Commands.Add(selectedNode.Tag.CreateDeleteCommand()); if (selectedNode.Tag is Actor) itemsForDeletion.Add(new ConsistentDeletionHelper.ActorForDeletion((Actor)selectedNode.Tag)); else if (selectedNode.Tag is Path) itemsForDeletion.Add(new ConsistentDeletionHelper.PathForDeletion((Path)selectedNode.Tag)); else { Debug.Assert(true, "Not supported game objects deleting."); selectedNode.Tag.Remove(); } // add to the clipboard Screen.Clipboard.Add(selectedNode); if (lowerBound == null) { lowerBound = selectedNode.Rectangle.LowerBound; upperBound = selectedNode.Rectangle.UpperBound; } else { lowerBound = Vector2.Min(lowerBound.Value, selectedNode.Rectangle.LowerBound); upperBound = Vector2.Max(upperBound.Value, selectedNode.Rectangle.UpperBound); } } } // calculate clipboard position if (lowerBound != null) Screen.ClipboardPosition = 0.5f * (lowerBound.Value + upperBound.Value); if ((new ConsistentDeletionForm(itemsForDeletion) { ProcessWhenEmptyList = true }).ShowDialog() == DialogResult.OK) { if (command.Commands.Count != 0) Screen.History.Add(command); // clear selected objects at the scene Screen.SelectedNodes.Clear(); // selected nodes changed Screen.InvokeSelectedNodesChanged(); } }*/ // delete selected objects from the scene else if (e.KeyCode == Keys.Delete) { // save deleted objects to the history CompositeCommand command = new CompositeCommand(); List<ItemForDeletion> itemsForDeletion = new List<ItemForDeletion>(); // remove all selected objects from the scene foreach (SceneNode selectedNode in Screen.SelectedNodes) { if (selectedNode.Visible) { command.Commands.Add(selectedNode.Tag.CreateDeleteCommand()); if (selectedNode.Tag is Actor) itemsForDeletion.Add(new ConsistentDeletionHelper.ActorForDeletion((Actor)selectedNode.Tag)); else if (selectedNode.Tag is Path) itemsForDeletion.Add(new ConsistentDeletionHelper.PathForDeletion((Path)selectedNode.Tag)); else { Debug.Assert(true, "Not supported game objects deleting."); selectedNode.Tag.Remove(); } } } if ((new ConsistentDeletionForm(itemsForDeletion) { ProcessWhenEmptyList = true }).ShowDialog() == DialogResult.OK) { if (command.Commands.Count != 0) Screen.History.Add(command); // clear selected objects at the scene Screen.SelectedNodes.Clear(); // selected nodes changed Screen.InvokeSelectedNodesChanged(); } } }