Exemplo n.º 1
0
        public void PlaceObject()
        {
            lock (Board.ParentControl)
            {
                if (state == MouseState.StaticObjectAdding || state == MouseState.RandomTiles) // tiles, obj
                {
                    List <UndoRedoAction> undoPipe = new List <UndoRedoAction>();
                    currAddedObj.OnItemPlaced(undoPipe);
                    Board.UndoRedoMan.AddUndoBatch(undoPipe);
                    ReleaseItem(currAddedObj);
                    if (currAddedObj is LayeredItem)
                    {
                        int highestZ = 0;
                        foreach (LayeredItem item in Board.BoardItems.TileObjs)
                        {
                            if (item.Z > highestZ)
                            {
                                highestZ = item.Z;
                            }
                        }
                        currAddedObj.Z = highestZ;
                        Board.BoardItems.Sort();
                    }
                    if (state == MouseState.StaticObjectAdding)
                    {
                        BoardItem boardItem = currAddedInfo.CreateInstance(Board.SelectedLayer, Board, X + currAddedInfo.Origin.X - currAddedInfo.Image.Width / 2, Y + currAddedInfo.Origin.Y - currAddedInfo.Image.Height / 2, 50, false);
                        currAddedObj = boardItem;
                    }
                    else
                    {
                        BoardItem boardItem = tileRandomList[NextInt32(tileRandomList.Length)].CreateInstance(Board.SelectedLayer, Board, X + currAddedInfo.Origin.X - currAddedInfo.Image.Width / 2, Y + currAddedInfo.Origin.Y - currAddedInfo.Image.Height / 2, 50, false);
                        currAddedObj = boardItem;
                    }

                    Board.BoardItems.Add(currAddedObj, false);
                    BindItem(currAddedObj, new Microsoft.Xna.Framework.Point(currAddedInfo.Origin.X - currAddedInfo.Image.Width / 2, currAddedInfo.Origin.Y - currAddedInfo.Image.Height / 2));
                }
                else if (state == MouseState.Chairs) // Chair
                {
                    Board.UndoRedoMan.AddUndoBatch(new List <UndoRedoAction> {
                        UndoRedoManager.ItemAdded(currAddedObj)
                    });
                    ReleaseItem(currAddedObj);
                    currAddedObj = new Chair(Board, X, Y);
                    Board.BoardItems.Add(currAddedObj, false);
                    BindItem(currAddedObj, new Microsoft.Xna.Framework.Point());
                }
                else if (state == MouseState.Ropes) // Ropes
                {
                    int        count  = BoundItems.Count;
                    RopeAnchor anchor = (RopeAnchor)BoundItems.Keys.ElementAt(0);
                    ReleaseItem(anchor);
                    if (count == 1)
                    {
                        Board.UndoRedoMan.AddUndoBatch(new List <UndoRedoAction> {
                            UndoRedoManager.RopeAdded(anchor.ParentRope)
                        });
                        CreateRope();
                    }
                }
                else if (state == MouseState.Tooltip) // Tooltip
                {
                    int        count = BoundItems.Count;
                    ToolTipDot dot   = (ToolTipDot)BoundItems.Keys.ElementAt(0);
                    ReleaseItem(dot);
                    if (count == 1)
                    {
                        List <UndoRedoAction> undoPipe = new List <UndoRedoAction>();
                        dot.ParentTooltip.OnItemPlaced(undoPipe);
                        Board.UndoRedoMan.AddUndoBatch(undoPipe);
                        CreateTooltip();
                    }
                }
                else if (state == MouseState.Clock) // Clock
                {
                    int count = BoundItems.Count;
                    List <BoardItem> items = BoundItems.Keys.ToList();
                    Clock            clock = null;
                    foreach (BoardItem item in items)
                    {
                        if (item is Clock)
                        {
                            clock = (Clock)item;
                        }
                    }
                    foreach (BoardItem item in items)
                    {
                        ReleaseItem(item);
                    }
                    List <UndoRedoAction> undoPipe = new List <UndoRedoAction>();
                    clock.OnItemPlaced(undoPipe);
                    Board.UndoRedoMan.AddUndoBatch(undoPipe);
                    CreateClock();
                }
            }
        }