예제 #1
0
        private void UpdateInsertion()
        {
            TilesCursor.Clear();

            var indexCoords     = Parent.MapView.Cursor.WorldIndexCoords;
            var selectionCenter = TilesSelector.GetIndexCoords(TilesSelector.CenterCoord);

            for (int i = 0; i < TilesSelector.SelectedIndexes.Count; i++)
            {
                int tileId           = TilesSelector.SelectedIndexes[i];
                var rectangle        = TilesSelector.CurrentTileSet.Tiles[tileId].Rectangle;
                int tileInsertIndexX = indexCoords.X + rectangle.X / rectangle.Width;
                int tileInsertIndexY = indexCoords.Y + rectangle.Y / rectangle.Height;
                tileInsertIndexX -= selectionCenter.X;
                tileInsertIndexY -= selectionCenter.Y;

                if (tileInsertIndexX < 0 || tileInsertIndexX >= Layout.Width)
                {
                    continue;
                }

                if (tileInsertIndexY < 0 || tileInsertIndexY >= Layout.Height)
                {
                    continue;
                }

                TilesCursor.Add(new MapEditorTileInsertOperation(new Point(tileInsertIndexX, tileInsertIndexY), 0, tileId));
            }
        }
예제 #2
0
        private void InsertSelection()
        {
            var indexCoords     = Parent.MapView.Cursor.WorldIndexCoords;
            var selectionCenter = TilesSelector.GetIndexCoords(TilesSelector.CenterCoord);

            for (int i = 0; i < TilesSelector.SelectedIndexes.Count; i++)
            {
                int tileId           = TilesSelector.SelectedIndexes[i];
                var rectangle        = TilesSelector.CurrentTileSet.Tiles[tileId].Rectangle;
                int tileInsertIndexX = indexCoords.X + rectangle.X / rectangle.Width;
                int tileInsertIndexY = indexCoords.Y + rectangle.Y / rectangle.Height;
                tileInsertIndexX -= selectionCenter.X;
                tileInsertIndexY -= selectionCenter.Y;

                if (tileInsertIndexX < 0 || tileInsertIndexX >= Layout.Width)
                {
                    continue;
                }

                if (tileInsertIndexY < 0 || tileInsertIndexY >= Layout.Height)
                {
                    continue;
                }

                var tileReplacement = InsertBuffer[tileInsertIndexX, tileInsertIndexY];
                if (tileReplacement == null)
                {
                    int oldTileId = Layout.GetCellValue(LayerIndex, tileInsertIndexX, tileInsertIndexY);

                    if (oldTileId != tileId)
                    {
                        InsertBuffer[tileInsertIndexX, tileInsertIndexY] = new MapEditorTileInsertOperation(new Point(tileInsertIndexX, tileInsertIndexY), oldTileId, tileId);
                    }
                }
                else
                {
                    if (tileReplacement.TileIdAfter != tileId)
                    {
                        InsertBuffer[tileInsertIndexX, tileInsertIndexY] = new MapEditorTileInsertOperation(new Point(tileInsertIndexX, tileInsertIndexY), tileReplacement.TileIdBefore, tileId);
                    }
                }
            }
        }