コード例 #1
0
        public void PopulateControl(Tile[,] tiles)
        {
            tileDataList = tiles;
            imagesList   = new List <List <CustomImage> >();
            for (var tileX = 0; tileX < tiles.GetLength(0); tileX++)
            {
                imagesList.Add(new List <CustomImage>());
                for (var tileY = 0; tileY < tiles.GetLength(1); tileY++)
                {
                    var tile = tiles[tileX, tileY];
                    tile.TileId = (tileX * tiles.GetLength(1)) + tileY;
                    var customImage = ImageExtensions.GetIndividualSensorVisual(tile, true);

                    customImage.TileData             = tile;
                    customImage.InCanvasPosition     = new Point(tileX, tileY);
                    customImage.MouseLeftButtonDown += (sender, args) => SelectTile(customImage);
                    imagesList[tileX].Add(customImage);
                }
            }

            foreach (var item in imagesList.SelectMany(list => list))
            {
                item.Margin = new Thickness(1);
            }
            PopulateCanvas(RightViewControl, imagesList);
        }
コード例 #2
0
        public void SelectTile(CustomImage customImage)
        {
            if (selectedImage != null && selectedImage.TileData.TileId == customImage.TileData.TileId)
            {
                var customImg = ImageExtensions.GetIndividualSensorVisual(selectedImage.TileData, true);
                selectedImage.Source = customImg.Source;
                selectedImage        = null;
            }
            else if (selectedImage != null)
            {
                var selectedX   = Convert.ToInt32(selectedImage.InCanvasPosition.X);
                var selectedY   = Convert.ToInt32(selectedImage.InCanvasPosition.Y);
                var selectedPos = selectedImage.TileData.Position;
                var customX     = Convert.ToInt32(customImage.InCanvasPosition.X);
                var customY     = Convert.ToInt32(customImage.InCanvasPosition.Y);
                var customPos   = customImage.TileData.Position;

                imagesList[selectedX][selectedY] = customImage;
                imagesList[selectedX][selectedY].InCanvasPosition = new Point(selectedX, selectedY);
                tileDataList[selectedX, selectedY]          = customImage.TileData;
                tileDataList[selectedX, selectedY].Position = customPos;

                imagesList[customX][customY] = selectedImage;
                imagesList[customX][customY].InCanvasPosition = new Point(customX, customY);
                tileDataList[customX, customY]          = selectedImage.TileData;
                tileDataList[customX, customY].Position = selectedPos;

                var customImg = ImageExtensions.GetIndividualSensorVisual(selectedImage.TileData, true);
                imagesList[customX][customY].Source = customImg.Source;
                selectedImage = null;
            }
            else
            {
                selectedImage = customImage;
                var bmp = new Bitmap(12, 12);
                bmp.DrawRectangle(Vector2.Zero(), 15, 15, true, 2, Color.Red);
                bmp.DrawText(new Vector2(0, 0), customImage.TileData.TileId.ToString(), 8, Color.Blue);
                selectedImage.Source = ImageExtensions.BitmapToImageSource(bmp);
            }
        }