/// <summary>
        /// Loads Blocks for level editor
        /// </summary>
        private void LoadBlocks()
        {
            var videoNes      = new Video();
            var numCols       = 5;
            var currentColumn = 0;
            var currentRow    = 0;

            _blocks = videoNes.makeBigBlocks(0, 0, 0, 0, MapViewType.Tiles, MapViewType.Tiles, 0);

            GrdBlocks.Children.Clear();

            //loop through blocks and add them to the wrap panel.
            for (int i = 0; i < _blocks.Length; i++)
            {
                var img = new System.Windows.Controls.Image
                {
                    Stretch = System.Windows.Media.Stretch.Fill,
                    Source  = UtilsGDI.GetImageStream(_blocks[i])
                };

                var border = new Border
                {
                    BorderBrush     = System.Windows.Media.Brushes.White,
                    BorderThickness = new Thickness(1),
                    Child           = img
                };



                if (currentColumn == numCols - 1)
                {
                    //new row
                    var rowDef = new RowDefinition();
                    GrdBlocks.RowDefinitions.Add(rowDef);

                    GrdBlocks.Children.Add(border);
                    Grid.SetColumn(border, currentColumn);
                    Grid.SetRow(border, currentRow);

                    currentColumn = 0;
                    currentRow++;
                }
                else
                {
                    GrdBlocks.Children.Add(border);
                    Grid.SetColumn(border, currentColumn);
                    Grid.SetRow(border, currentRow);

                    currentColumn++;
                }
            }
        }
        /// <summary>
        /// Loads an 8x8 screen onto the tile map
        /// </summary>
        /// <param name="screenNo">The 0 based screen number to load.</param>
        private void LoadMapScreen(int screenNo, int screenWidth, int screenHeight, bool hasBorder, ref Grid MapGrid)
        {
            //int screenWidth = 8;
            //int screenHeight = 8;
            int[] screen  = _layers[0].screens[screenNo];
            int   blockNo = 0;

            //first we need to remove old contents of grid to mitigate memory consumption
            MapGrid.Children.Clear();

            //iterate through block indexes and add appropriate block to map screen
            for (int i = 0; i < screenHeight; i++)
            {
                //for each row
                for (int y = 0; y < screenWidth; y++)
                {
                    //for each column
                    var currentBlockIdx = screen[blockNo]; //grab the index of the current block

                    var img = new System.Windows.Controls.Image
                    {
                        Stretch = System.Windows.Media.Stretch.Fill,
                        Source  = UtilsGDI.GetImageStream(_blocks[currentBlockIdx])
                    };

                    var border = new Border
                    {
                        BorderBrush     = System.Windows.Media.Brushes.White,
                        BorderThickness = new Thickness(hasBorder ? 1 : 0),
                        Child           = img
                    };

                    MapGrid.ShowGridLines = false;

                    //add image to map grid
                    MapGrid.Children.Add(border);
                    Grid.SetColumn(border, y);
                    Grid.SetRow(border, i);
                    blockNo++;
                }
            }
        }
Beispiel #3
0
        public static void RenderAllBlocks(DrawingContext g, System.Windows.Controls.Image parentControl, Image[] bigBlocks, int blockWidth, int blockHeight, Rect?visibleRect, float CurScale, int activeBlock, bool showBlocksAxis)
        {
            int TILE_SIZE_X = (int)(blockWidth * CurScale);
            int TILE_SIZE_Y = (int)(blockHeight * CurScale);
            int WIDTH       = (int)parentControl.Width / TILE_SIZE_X;

            if (WIDTH == 0)
            {
                return;
            }

            for (int i = 0; i < bigBlocks.Length; i++)
            {
                int bigBlockNo = i;
                //Rectangle tileRect = new Rectangle((i % WIDTH) * TILE_SIZE_X, i / WIDTH * TILE_SIZE_Y, TILE_SIZE_X, TILE_SIZE_Y);
                Rect tileRect = new Rect((i % WIDTH) * TILE_SIZE_X, i / WIDTH * TILE_SIZE_Y, TILE_SIZE_X, TILE_SIZE_Y);

                if (visibleRect == null || visibleRect.Value.Contains(tileRect) || visibleRect.Value.IntersectsWith(tileRect))
                {
                    if (bigBlockNo > -1 && bigBlockNo < bigBlocks.Length)
                    {
                        g.DrawImage(UtilsGDI.GetImageStream(bigBlocks[bigBlockNo]), tileRect);
                    }
                    else

                    //g.FillRectangle(System.Windows.Media.Brushes.White, tileRect);

                    if (showBlocksAxis)
                    {
                        g.DrawRectangle(null, new System.Windows.Media.Pen(System.Windows.Media.Brushes.Black, 1), tileRect);
                        //g.DrawRectangle(null,new System.Windows.Media.Pen(Color.FromArgb(255, 255, 255, 255),1), tileRect);
                    }

                    if (i == activeBlock)
                    {
                        //g.DrawRectangle(new Pen(Brushes.Red, 3.0f), tileRect);
                        g.DrawRectangle(null, new System.Windows.Media.Pen(System.Windows.Media.Brushes.Red, 1), tileRect);
                    }
                }
            }
        }
        /// <summary>
        /// replaces the tile on the map screen with the one selected from the block/tile screen
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MapScreen_OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            //populate current selected cell with CurrentSelectedBlock
            //Get currently selected column and row (Note, may refactor later to use Grid.GetRow / Grid.GetColumn ?)
            var col = GridSelectedColumn(ref MapScreen);
            var row = GridSelectedRow(ref MapScreen);

            //navigate to column/row to get cell
            var cell = MapScreen.Children.Cast <UIElement>()
                       .First(ctl => Grid.GetRow(ctl) == row && Grid.GetColumn(ctl) == col);

            //I'll eventually rewrite this to use a copy of the layer so it's not rewritten whenever the map is redrawn...
            if (cell is Border)
            {
                var img = new System.Windows.Controls.Image
                {
                    Stretch = System.Windows.Media.Stretch.Fill,
                    Source  = UtilsGDI.GetImageStream(_blocks[CurrentSelectedBlock])
                };

                ((Border)cell).Child = img;
            }
        }