public void Clear() { lock (Board.ParentControl) { if (currAddedObj != null) { currAddedObj.RemoveItem(null); currAddedObj = null; } if (state == MouseState.Ropes || state == MouseState.Tooltip) { if (state == MouseState.Ropes) { ((RopeAnchor)BoundItems.Keys.ElementAt(0)).RemoveItem(null); } else { ((ToolTipDot)BoundItems.Keys.ElementAt(0)).ParentTooltip.RemoveItem(null); } } else if (state == MouseState.Footholds && connectedLines.Count > 0) { FootholdLine fh = (FootholdLine)connectedLines[0]; fh.Remove(false, null); Board.BoardItems.FootholdLines.Remove(fh); } else if (state == MouseState.Clock) { List <BoardItem> items = BoundItems.Keys.ToList(); foreach (BoardItem item in items) { item.RemoveItem(null); } } InputHandler.ClearBoundItems(Board); InputHandler.ClearSelectedItems(Board); IsDown = false; } }
public void UndoRedo(HashSet <int> layersToRecheck) { Board board; switch (type) { case UndoRedoType.ItemDeleted: //item.Board.BoardItems.Add(item, true); item.InsertItem(); break; case UndoRedoType.ItemAdded: item.RemoveItem(null); break; case UndoRedoType.ItemMoved: XNA.Point oldPos = (XNA.Point)ParamA; item.Move(oldPos.X, oldPos.Y); break; case UndoRedoType.ItemFlipped: ((IFlippable)item).Flip = !((IFlippable)item).Flip; break; case UndoRedoType.LineRemoved: board = ((MapleDot)ParamB).Board; if (ParamC is FootholdLine) { board.BoardItems.FootholdLines.Add((FootholdLine)ParamC); } else if (ParamC is RopeLine) { board.BoardItems.RopeLines.Add((RopeLine)ParamC); } else { throw new Exception("wrong type at undoredo, lineremoved"); } ((MapleLine)ParamC).FirstDot = (MapleDot)ParamA; ((MapleLine)ParamC).SecondDot = (MapleDot)ParamB; ((MapleDot)ParamA).connectedLines.Add((MapleLine)ParamC); ((MapleDot)ParamB).connectedLines.Add((MapleLine)ParamC); break; case UndoRedoType.LineAdded: board = ((MapleDot)ParamB).Board; if (ParamC is FootholdLine) { board.BoardItems.FootholdLines.Remove((FootholdLine)ParamC); } else if (ParamC is RopeLine) { board.BoardItems.RopeLines.Remove((RopeLine)ParamC); } else { throw new Exception("wrong type at undoredo, lineadded"); } ((MapleLine)ParamC).Remove(false, null); break; case UndoRedoType.ToolTipLinked: ((ToolTipInstance)item).CharacterToolTip = null; ((ToolTipChar)ParamA).BoundTooltip = null; break; case UndoRedoType.ToolTipUnlinked: ((ToolTipChar)ParamA).BoundTooltip = (ToolTipInstance)item; break; case UndoRedoType.BackgroundMoved: ((BackgroundInstance)item).BaseX = ((XNA.Point)ParamA).X; ((BackgroundInstance)item).BaseY = ((XNA.Point)ParamA).Y; break; case UndoRedoType.ItemsLinked: item.ReleaseItem((BoardItem)ParamA); break; case UndoRedoType.ItemsUnlinked: item.BindItem((BoardItem)ParamA, (Microsoft.Xna.Framework.Point)ParamB); break; case UndoRedoType.ItemsLayerChanged: InputHandler.ClearSelectedItems(((BoardItem)((List <IContainsLayerInfo>)ParamC)[0]).Board); foreach (IContainsLayerInfo layerInfoItem in (List <IContainsLayerInfo>)ParamC) { layerInfoItem.LayerNumber = (int)ParamA; } ((BoardItem)((List <IContainsLayerInfo>)ParamC)[0]).Board.Layers[(int)ParamA].RecheckTileSet(); ((BoardItem)((List <IContainsLayerInfo>)ParamC)[0]).Board.Layers[(int)ParamB].RecheckTileSet(); break; case UndoRedoType.ItemLayerPlatChanged: Tuple <int, int> oldLayerPlat = (Tuple <int, int>)ParamA; Tuple <int, int> newLayerPlat = (Tuple <int, int>)ParamB; IContainsLayerInfo li = (IContainsLayerInfo)ParamC; li.LayerNumber = oldLayerPlat.Item1; li.PlatformNumber = oldLayerPlat.Item2; layersToRecheck.Add(oldLayerPlat.Item1); layersToRecheck.Add(newLayerPlat.Item1); break; case UndoRedoType.RopeAdded: ((Rope)ParamA).Remove(null); break; case UndoRedoType.RopeRemoved: ((Rope)ParamA).Create(); break; case UndoRedoType.ItemZChanged: item.Z = (int)ParamA; item.Board.BoardItems.Sort(); break; case UndoRedoType.VRChanged: //TODO break; case UndoRedoType.MapCenterChanged: //TODO break; case UndoRedoType.LayerTSChanged: string ts_old = (string)ParamA; string ts_new = (string)ParamB; Layer l = (Layer)ParamC; l.ReplaceTS(ts_old); break; case UndoRedoType.zMChanged: int zm_old = (int)ParamA; int zm_new = (int)ParamB; IContainsLayerInfo target = (IContainsLayerInfo)ParamC; target.PlatformNumber = zm_old; break; } }
private void parentBoard_ShortcutKeyPressed(Board selectedBoard, bool ctrl, bool shift, bool alt, Keys key) { lock (parentBoard) { if (parentBoard == null || parentBoard.SelectedBoard == null) { return; } OnUserInteraction(); List <UndoRedoAction> actions = new List <UndoRedoAction>(); if (key == Keys.ControlKey || key == Keys.ShiftKey || key == Keys.Menu /*ALT key*/) { return; } bool clearRedo = true; switch (key) { case Keys.Left: foreach (BoardItem item in selectedBoard.SelectedItems) { if (!item.BoundToSelectedItem(selectedBoard)) { item.X--; actions.Add(CreateItemUndoMoveAction(item, new XNA.Point(1, 0))); } } break; case Keys.Right: foreach (BoardItem item in selectedBoard.SelectedItems) { if (!item.BoundToSelectedItem(selectedBoard)) { item.X++; actions.Add(CreateItemUndoMoveAction(item, new XNA.Point(-1, 0))); } } break; case Keys.Up: foreach (BoardItem item in selectedBoard.SelectedItems) { if (!item.BoundToSelectedItem(selectedBoard)) { item.Y--; actions.Add(CreateItemUndoMoveAction(item, new XNA.Point(0, 1))); } } break; case Keys.Down: foreach (BoardItem item in selectedBoard.SelectedItems) { if (!item.BoundToSelectedItem(selectedBoard)) { item.Y++; actions.Add(CreateItemUndoMoveAction(item, new XNA.Point(0, -1))); } } break; case Keys.Delete: switch (selectedBoard.Mouse.State) { case MouseState.Selection: bool askedVr = false, askedMm = false; List <BoardItem> selectedItems = selectedBoard.SelectedItems.ToList(); // Dupe the selection list foreach (BoardItem item in selectedItems) { if (item is ToolTipDot || item is MiscDot) { continue; } else if (item is VRDot) { if (!askedVr) { askedVr = true; if (MessageBox.Show("This will remove the map's VR. This is not undoable, you must re-add VR from the map's main menu. Continue?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { selectedBoard.VRRectangle.RemoveItem(null); } } } else if (item is MinimapDot) { if (!askedMm) { askedMm = true; if (MessageBox.Show("This will remove the map's minimap. This is not undoable, you must re-add the minimap from the map's main menu. Continue?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { selectedBoard.MinimapRectangle.RemoveItem(null); } } } else { item.RemoveItem(actions); } } break; case MouseState.RandomTiles: case MouseState.StaticObjectAdding: case MouseState.Chairs: case MouseState.Ropes: parentBoard.InvokeReturnToSelectionState(); break; case MouseState.Footholds: while (selectedBoard.Mouse.connectedLines.Count > 0 && selectedBoard.Mouse.connectedLines[0].FirstDot.connectedLines.Count > 0) { selectedBoard.Mouse.connectedLines[0].FirstDot.connectedLines[0].Remove(false, actions); } break; } break; case Keys.F: if (ctrl) { foreach (BoardItem item in selectedBoard.SelectedItems) { if (item is IFlippable) { ((IFlippable)item).Flip = !((IFlippable)item).Flip; actions.Add(UndoRedoManager.ItemFlipped((IFlippable)item)); } } } break; case Keys.Add: foreach (BoardItem item in selectedBoard.SelectedItems) { item.Z += UserSettings.zShift; actions.Add(UndoRedoManager.ItemZChanged(item, item.Z - UserSettings.zShift, item.Z)); } selectedBoard.BoardItems.Sort(); break; case Keys.Subtract: foreach (BoardItem item in selectedBoard.SelectedItems) { item.Z -= UserSettings.zShift; actions.Add(UndoRedoManager.ItemZChanged(item, item.Z + UserSettings.zShift, item.Z)); } selectedBoard.BoardItems.Sort(); break; case Keys.A: if (ctrl) { foreach (BoardItem item in selectedBoard.BoardItems.Items) { if ((selectedBoard.EditedTypes & item.Type) == item.Type) { if (item is LayeredItem) { LayeredItem li = (LayeredItem)item; if (li.CheckIfLayerSelected(selectedBoard.GetUserSelectionInfo())) { item.Selected = true; } } else { item.Selected = true; } } } } clearRedo = false; break; case Keys.X: // Cut if (ctrl && selectedBoard.Mouse.State == MouseState.Selection) { Clipboard.SetData(SerializationManager.HaClipboardData, selectedBoard.SerializationManager.SerializeList(selectedBoard.SelectedItems.Cast <ISerializableSelector>())); int selectedItemIndex = 0; while (selectedBoard.SelectedItems.Count > selectedItemIndex) { BoardItem item = selectedBoard.SelectedItems[selectedItemIndex]; if (item is ToolTipDot || item is MiscDot || item is VRDot || item is MinimapDot) { selectedItemIndex++; } else { item.RemoveItem(actions); } } break; } break; case Keys.C: // Copy if (ctrl) { Clipboard.SetData(SerializationManager.HaClipboardData, selectedBoard.SerializationManager.SerializeList(selectedBoard.SelectedItems.Cast <ISerializableSelector>())); } break; case Keys.V: // Paste if (ctrl && Clipboard.ContainsData(SerializationManager.HaClipboardData)) { List <ISerializable> items; try { items = selectedBoard.SerializationManager.DeserializeList((string)Clipboard.GetData(SerializationManager.HaClipboardData)); } catch (SerializationException de) { MessageBox.Show(de.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } catch (Exception e) { MessageBox.Show(string.Format("An error occurred: {0}", e.ToString()), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } bool needsLayer = false; // Make sure we dont have any tS conflicts string tS = null; foreach (ISerializable item in items) { if (item is TileInstance) { TileInstance tile = (TileInstance)item; string currtS = ((TileInfo)tile.BaseInfo).tS; if (currtS != tS) { if (tS == null) { tS = currtS; } else { MessageBox.Show("Clipboard contains two tiles with different tile sets, cannot paste.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } if (item is IContainsLayerInfo) { needsLayer = true; } } if (needsLayer && (selectedBoard.SelectedLayerIndex < 0 || selectedBoard.SelectedPlatform < 0)) { MessageBox.Show("Layered items in clipboard and no layer/platform selected, cannot paste.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (tS != null && selectedBoard.SelectedLayer.tS != null && tS != selectedBoard.SelectedLayer.tS) { MessageBox.Show("Clipboard contains tile in a different set than the current selected layer, cannot paste.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Calculate offsetting XNA.Point minPos = new XNA.Point(int.MaxValue, int.MaxValue); XNA.Point maxPos = new XNA.Point(int.MinValue, int.MinValue); foreach (ISerializable item in items) { if (item is BoardItem) { BoardItem bi = (BoardItem)item; if (bi.Left < minPos.X) { minPos.X = bi.Left; } if (bi.Top < minPos.Y) { minPos.Y = bi.Top; } if (bi.Right > maxPos.X) { maxPos.X = bi.Right; } if (bi.Bottom > maxPos.Y) { maxPos.Y = bi.Bottom; } } else if (item is Rope) { Rope r = (Rope)item; int x = r.FirstAnchor.X; int minY = Math.Min(r.FirstAnchor.Y, r.SecondAnchor.Y); int maxY = Math.Max(r.FirstAnchor.Y, r.SecondAnchor.Y); if (x < minPos.X) { minPos.X = x; } if (x > maxPos.X) { maxPos.X = x; } if (minY < minPos.Y) { minPos.Y = minY; } if (maxY > maxPos.Y) { maxPos.Y = maxY; } } } XNA.Point center = new XNA.Point((maxPos.X + minPos.X) / 2, (maxPos.Y + minPos.Y) / 2); XNA.Point offset = new XNA.Point(selectedBoard.Mouse.X - center.X, selectedBoard.Mouse.Y - center.Y); // Add the items ClearSelectedItems(selectedBoard); List <UndoRedoAction> undoPipe = new List <UndoRedoAction>(); foreach (ISerializable item in items) { item.AddToBoard(undoPipe); item.PostDeserializationActions(true, offset); } selectedBoard.BoardItems.Sort(); selectedBoard.UndoRedoMan.AddUndoBatch(undoPipe); } break; case Keys.Z: if (ctrl && selectedBoard.UndoRedoMan.UndoList.Count > 0) { selectedBoard.UndoRedoMan.Undo(); } clearRedo = false; break; case Keys.Y: if (ctrl && selectedBoard.UndoRedoMan.RedoList.Count > 0) { selectedBoard.UndoRedoMan.Redo(); } clearRedo = false; break; case Keys.S: if (ctrl) { parentBoard.OnExportRequested(); } break; case Keys.O: if (ctrl) { parentBoard.OnLoadRequested(); } break; case Keys.Escape: if (selectedBoard.Mouse.State == MouseState.Selection) { ClearBoundItems(selectedBoard); ClearSelectedItems(selectedBoard); clearRedo = false; } else if (selectedBoard.Mouse.State == MouseState.Footholds) { selectedBoard.Mouse.Clear(); } else { parentBoard.InvokeReturnToSelectionState(); } break; default: clearRedo = false; break; case Keys.W: if (ctrl) { parentBoard.OnCloseTabRequested(); } break; case Keys.Tab: if (ctrl) { parentBoard.OnSwitchTabRequested(shift); } break; } if (actions.Count > 0) { selectedBoard.UndoRedoMan.AddUndoBatch(actions); } if (clearRedo) { selectedBoard.UndoRedoMan.RedoList.Clear(); } } }