Пример #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
        public void Initialize(MapEditorTilesToolVM vm)
        {
            _vm = vm ?? throw new InvalidOperationException(nameof(vm));

            EntryRef.Initialize(vm.RefIdEditor);
            TilesSelector.Initialize(_vm.TilesSelector);
        }
Пример #3
0
        public TileSetViewerVM()
        {
            Selector              = new TilesSelector(this);
            Selector.InfoChanged += (s, a) => Info = Selector.Info;

            Items              = new BindingList <TileVM>();
            Items.ListChanged += (s, a) => OnPropertyChanged(nameof(Items));



            Bitmap = new Bitmap(1, 1, PixelFormat.Format8bppIndexed);
        }
Пример #4
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);
                    }
                }
            }
        }