public void MoveSelected(Point oldPos, Point newPos, bool duplicate = false, bool forceUpdate = false)
 {
     oldPos = new Point(oldPos.X / TILE_SIZE, oldPos.Y / TILE_SIZE);
     newPos = new Point(newPos.X / TILE_SIZE, newPos.Y / TILE_SIZE);
     if (oldPos != newPos)
     {
         Dictionary <Point, ushort> newDict = new Dictionary <Point, ushort>();
         List <Point> newPoints             = new List <Point>(SelectedTiles.Count);
         foreach (Point point in SelectedTiles.PopAll())
         {
             Point newPoint = new Point(point.X + (newPos.X - oldPos.X), point.Y + (newPos.Y - oldPos.Y));
             newPoints.Add(newPoint);
             if (SelectedTilesValue.ContainsKey(point))
             {
                 newDict[newPoint] = SelectedTilesValue[point];
             }
             else
             {
                 // Not moved yet
                 newDict[newPoint] = Layer.Tiles[point.Y][point.X];
                 if (!duplicate)
                 {
                     RemoveTile(point);
                 }
             }
         }
         if (duplicate)
         {
             Deselect();
             // Create new actions group
             Actions.Add(new ActionDummy());
         }
         SelectedTilesValue = newDict;
         SelectedTiles.AddPoints(newPoints);
         InvalidateSelectedChunks();
     }
     else if (forceUpdate)
     {
         for (int y = 0; y < chunks.Length; ++y)
         {
             for (int x = 0; x < chunks[0].Length; ++x)
             {
                 if (SelectedTiles.IsChunkUsed(x, y))
                 {
                     SelectedTiles.ChangedChunks.Add(new Point(x, y));
                 }
             }
         }
         InvalidateSelectedChunks();
     }
 }
Beispiel #2
0
        public void Draw(DevicePanel d)
        {
            int Transperncy = (Editor.Instance.EditLayer != null && Editor.Instance.EditLayer != this) ? 0x32 : 0xFF;

            Rectangle screen = d.GetScreen();

            int start_x = screen.X / (TILES_CHUNK_SIZE * TILE_SIZE);
            int end_x   = Math.Min(DivideRoundUp(screen.X + screen.Width, TILES_CHUNK_SIZE * TILE_SIZE), TileChunksTextures[0].Length);
            int start_y = screen.Y / (TILES_CHUNK_SIZE * TILE_SIZE);
            int end_y   = Math.Min(DivideRoundUp(screen.Y + screen.Height, TILES_CHUNK_SIZE * TILE_SIZE), TileChunksTextures.Length);

            for (int y = start_y; y < end_y; ++y)
            {
                for (int x = start_x; x < end_x; ++x)
                {
                    Rectangle rect = GetTilesChunkArea(x, y);
                    if (SelectedTiles.IsChunkUsed(x, y) || TempSelectionTiles.IsChunkUsed(x, y))
                    {
                        // TODO: If the full chunk is selected, cache it
                        // draw one by one
                        DrawTilesChunk(d, x, y, Transperncy);
                    }
                    else
                    {
                        d.DrawBitmap(GetTilesChunkTexture(d, x, y), rect.X * TILE_SIZE, rect.Y * TILE_SIZE, rect.Width * TILE_SIZE, rect.Height * TILE_SIZE, false, Transperncy);
                    }
                    DrawSelectedTiles(d, x, y, Transperncy);
                }
            }
        }
Beispiel #3
0
        public void Draw(DevicePanel d)
        {
            if (!Visible)
            {
                return;
            }

            bool LoopX = true;

            bool DrawLined = Editor.Instance.EditLayer != this && Layer.ScrollIndexes.Length > 1;

            int Transperncy = (Editor.Instance.EditLayer != null && Editor.Instance.EditLayer != this) ? 0x32 : 0xFF;

            Rectangle screen = d.GetScreen();

            int alteredX = screen.X * Layer.ScrollingInfo[0].RelativeX / 0x100;
            int alteredY = screen.Y * Layer.RelativeY / 0x100;

            int start_x = alteredX / (TILES_CHUNK_SIZE * TILE_SIZE);
            int end_x   = Math.Min(DivideRoundUp(alteredX + screen.Width, TILES_CHUNK_SIZE * TILE_SIZE), TileChunksTextures[0].Length);

            if (LoopX)
            {
                end_x = DivideRoundUp(alteredX + screen.Width, TILES_CHUNK_SIZE * TILE_SIZE);
            }

            int start_y = alteredY / (TILES_CHUNK_SIZE * TILE_SIZE);
            int end_y   = Math.Min(DivideRoundUp(alteredY + screen.Height, TILES_CHUNK_SIZE * TILE_SIZE), TileChunksTextures.Length);


            for (int y = start_y; y < end_y; y++)
            {
                for (int oldx = start_x; oldx < end_x; oldx++)
                {
                    int x = oldx % TileChunksTextures[0].Length;

                    Rectangle rect = GetTilesChunkArea(x, y);

                    rect.X += oldx / TileChunksTextures[0].Length * TileChunksTextures[0].Length * TILES_CHUNK_SIZE;

                    if (SelectedTiles.IsChunkUsed(x, y) || TempSelectionTiles.IsChunkUsed(x, y))
                    {
                        // draw one by one
                        DrawTilesChunk(d, x, y, Transperncy);
                    }
                    else
                    {
                        d.DrawBitmap(GetTilesChunkTexture(d, x, y),
                                     rect.X * TILE_SIZE - screen.X * Layer.ScrollingInfo[0].RelativeX / 0x100 + screen.X,
                                     rect.Y * TILE_SIZE - screen.Y * Layer.RelativeY / 0x100 + screen.Y,
                                     rect.Width * TILE_SIZE,
                                     rect.Height * TILE_SIZE,
                                     false,
                                     Transperncy);
                    }
                    DrawSelectedTiles(d, x, y, Transperncy);
                }
            }
        }
        private void UpdateChunkVBO(int x, int y)
        {
            ChunkVBO vbo = chunks[y][x];

            if (vbo.TexCoordsUpdated && vbo.VerticesUpdated)
            {
                return;
            }

            if (!vbo.VerticesUpdated)
            {
                vbo.Vertices.Reset();
            }
            if (!vbo.TexCoordsUpdated)
            {
                vbo.TexCoords.Reset();
            }

            bool checkSelected = SelectedTiles.IsChunkUsed(x, y) || TempSelectionTiles.IsChunkUsed(x, y);

            Rectangle rect = GetTilesChunkArea(x, y);

            for (int ty = rect.Y; ty < rect.Y + rect.Height; ++ty)
            {
                for (int tx = rect.X; tx < rect.X + rect.Width; ++tx)
                {
                    if (checkSelected && TempSelectionDeselect && SelectedTiles.Contains(new Point(tx, ty)) && TempSelectionTiles.Contains(new Point(tx, ty)))
                    {
                        Point p = new Point(tx, ty);
                        if (SelectedTilesValue.ContainsKey(p))
                        {
                            AddTileToVBO(vbo, SelectedTilesValue[p], p.X, p.Y);
                        }
                        else // It is still in the original place
                        {
                            AddTileToVBO(vbo, Layer.Tiles[p.Y][p.X], p.X, p.Y);
                        }
                    }
                    else if (Layer.Tiles[ty][tx] != 0xffff)
                    {
                        if (!checkSelected || dragging)
                        {
                            AddTileToVBO(vbo, Layer.Tiles[ty][tx], tx, ty);
                        }
                        else
                        {
                            Point p = new Point(tx, ty);
                            if (SelectedTiles.Contains(p) || TempSelectionTiles.Contains(p))
                            {
                                if (SelectedTiles.Contains(p) && TempSelectionTiles.Contains(p) && TempSelectionDeselect)
                                {
                                    AddTileToVBO(vbo, Layer.Tiles[ty][tx], tx, ty);
                                }
                            }
                            else
                            {
                                AddTileToVBO(vbo, Layer.Tiles[ty][tx], tx, ty);
                            }
                        }
                    }
                }
            }

            if (!vbo.VerticesUpdated)
            {
                vbo.Vertices.UpdateData();
                vbo.VerticesUpdated = true;
            }
            if (!vbo.TexCoordsUpdated)
            {
                vbo.TexCoords.UpdateData();
                vbo.TexCoordsUpdated = true;
            }
        }