Ejemplo n.º 1
0
 public void moveTileset(Vector2 pos)
 {
     Vector2 position = TilesetView.Position + pos; //new Vector2(TileSelectorField.X, TileSelectorField.Y);
     if (true) //TODO CLAMP MOVEMENT
     {
         TilesetView.MoveCamera(pos);
     }
 }
Ejemplo n.º 2
0
        private void CreateNewTab()
        {
            var tilesetView = new TilesetView();

            tilesetView.TilesetPath = "e:\\Users\\Mr_Dark\\Dropbox\\Pokemon Universe\\Mapping\\util\\Pokemon Universe Tileset 2.png";
            tilesetView.Dock        = DockStyle.Fill;

            var tabPage = new TabPage("Custom Tab");

            tabPage.BackColor = Color.White;
            tabPage.Controls.Add(tilesetView);
            tcTilesets.TabPages.Add(tabPage);
        }
Ejemplo n.º 3
0
        public void DrawTileset(SpriteBatch sb)
        {                    
                for (int y = (int)TileSelectorField.Y; y < currentTileset.texture.Height + TileSelectorField.Y; y+= level.CurrentMap.TileHeight)
                {
                    for (int x = 0; x < currentTileset.texture.Width; x+= level.CurrentMap.TileWidth)
                    {
                        Rectangle source = new Rectangle(x, y-(int)TileSelectorField.Y, level.CurrentMap.TileWidth, level.CurrentMap.TileHeight);
                        if (TilesetView.WorldToScreen(new Vector2(x, y)).X+ level.CurrentMap.TileWidth > TileSelectorBackground.Width || TilesetView.WorldToScreen(new Vector2(x, y)).Y < TileSelectorField.Y) continue;
                        sb.Draw(currentTileset.texture, new Rectangle(x, y, level.CurrentMap.TileWidth, level.CurrentMap.TileHeight),source, Color.White);
                    }
                }

                foreach(var id in currentItemIDs)
                {
                    Rectangle sourceRectangle = level.CurrentMap.getSourceRectangle(id - currentTileset.startvalue, currentTileset);
                    sb.Draw(SelectedTileTexture, new Rectangle(TileSelectorField.X + sourceRectangle.X, TileSelectorField.Y + sourceRectangle.Y, level.CurrentMap.TileWidth, level.CurrentMap.TileHeight), Color.White);
                }                           
        }
Ejemplo n.º 4
0
 public void zoomTileset(float value)
 {
     TilesetView.AdjustZoom(value);
 }
Ejemplo n.º 5
0
        public void Update()
        {
            Vector2 mousePos = input.MousePos;
            Vector2 tilesetPos = TilesetView.ScreenToWorld(input.MousePos);
            Vector2 mapPos = input.GetMapPos(input.MousePos);

            if (!tilesetScroll)
            {
                if (input.CurrentMouseState.ScrollWheelValue > input.PreviousMouseState.ScrollWheelValue && input.KeyDown(Keys.LeftControl)) Global.camera.AdjustZoom(0.2f);
                if (input.CurrentMouseState.ScrollWheelValue < input.PreviousMouseState.ScrollWheelValue && input.KeyDown(Keys.LeftControl)) Global.camera.AdjustZoom(-0.2f);
            }

            if (input.KeyPressed(Keys.Z) && input.KeyDown(Keys.LeftControl)) Undo();


            if (input.KeyPressed(Microsoft.Xna.Framework.Input.Keys.C) || input.MouseRightButtonPressed())
            {
                currentItemIDs = new int[0, 0];
                sourceRectangle = new Rectangle();
                currentEditorMode = EditorMode.Default;
            }

            foreach (var button in components)
            {
                button.update(input);
            }

            if (input.KeyPressed(Keys.E))
            {
                currentItemIDs = new int[1, 1] { { 0 } };
                sourceRectangle = new Rectangle();
                currentEditorMode = EditorMode.Rubber;
            }

            if (mousePos.X > TileSelectorField.X && mousePos.X < TileSelectorField.X + TileSelectorField.Width && mousePos.Y > TileSelectorField.Y && mousePos.Y < TileSelectorField.Y + TileSelectorField.Height)
            {
                if (input.CurrentMouseState.ScrollWheelValue > input.PreviousMouseState.ScrollWheelValue && input.KeyDown(Keys.LeftControl)) zoomTileset(0.2f);
                if (input.CurrentMouseState.ScrollWheelValue < input.PreviousMouseState.ScrollWheelValue && input.KeyDown(Keys.LeftControl)) zoomTileset(-0.2f);
                tilesetScroll = true;    
                if (input.ButtonDown(input.CurrentMouseState.LeftButton))
                {
                    currentEditorMode = EditorMode.TileSelector;
                }
            }else
            {
                tilesetScroll = false;
            }
            

            if(currentEditorMode == EditorMode.TileSelector)
            {
                if (mousePos.X > TileSelectorField.X && mousePos.X < TileSelectorField.X + TileSelectorField.Width && mousePos.Y > TileSelectorField.Y && mousePos.Y < TileSelectorField.Y + TileSelectorField.Height)
                {
                    if (input.ButtonDown(input.CurrentMouseState.LeftButton))
                    {
                        if (!Drag)
                        {
                            startID = ((int)tilesetPos.X / level.CurrentMap.TileWidth) + ((int)tilesetPos.Y - TileSelectorField.Y) / level.CurrentMap.TileHeight * (currentTileset.width) + 1;
                            Drag = true;
                        }
                    }
                    if (!input.ButtonDown(input.CurrentMouseState.LeftButton))
                    {
                        if (Drag)
                        {
                            endID = ((int)tilesetPos.X / level.CurrentMap.TileWidth) + ((int)tilesetPos.Y - TileSelectorField.Y) / level.CurrentMap.TileHeight * (currentTileset.width) + 1;


                            Rectangle endid = new Rectangle(level.CurrentMap.getSourceRectangle(endID, currentTileset).X / level.CurrentMap.TileWidth + 1, level.CurrentMap.getSourceRectangle(endID, currentTileset).Y / level.CurrentMap.TileHeight, level.CurrentMap.TileHeight, level.CurrentMap.TileHeight);
                            Rectangle startid = new Rectangle(level.CurrentMap.getSourceRectangle(startID, currentTileset).X / level.CurrentMap.TileWidth + 1, level.CurrentMap.getSourceRectangle(startID, currentTileset).Y / level.CurrentMap.TileHeight, level.CurrentMap.TileHeight, level.CurrentMap.TileHeight);
                            if (startID > endID || startid.X > endid.X || startid.Y > endid.Y) return;
                            currentItemIDs = new int[endid.X - startid.X + 1, endid.Y - startid.Y + 1];
                            for (int y = startid.Y; y <= endid.Y; y++)
                            {
                                for (int x = startid.X; x <= endid.X; x++)
                                {
                                    currentItemIDs[x - startid.X, y - startid.Y] = Tiles[x + y * currentTileset.width]-1;
                                }
                            };
                            sourceRectangle = new Rectangle((startid.X-1) * level.CurrentMap.TileWidth, startid.Y * level.CurrentMap.TileHeight, (endid.X - startid.X) * level.CurrentMap.TileWidth + level.CurrentMap.TileWidth, (endid.Y - startid.Y) * level.CurrentMap.TileHeight + level.CurrentMap.TileHeight);
                            Drag = false;
                            currentEditorMode = EditorMode.Place;
                        }
                    }
                }
            }

            if (input.MousePos.X < TileSelectorBackground.Width) return; // STOP IF CURSOR IS AT OVERLAY

            switch (currentEditorMode)
            {
                case EditorMode.Default:
                   
                    break;

                case EditorMode.Place:
                  
                    if (input.ButtonDown(input.CurrentMouseState.LeftButton))
                    {
                        int mapX = (int)(mapPos.X) / level.CurrentMap.TileWidth;
                        int mapY = (int)(mapPos.Y) / level.CurrentMap.TileHeight;
                        if (mapX < 0 || mapY < 0 || mapX + currentItemIDs.GetLength(0) > level.CurrentMap.MapWidth || mapY + currentItemIDs.GetLength(1) > level.CurrentMap.MapHeight) return;
                        int[,] restoreIDs = new int[currentItemIDs.GetLength(0), currentItemIDs.GetLength(1)];
                        bool change = false;

                        for (int y = mapY; y < mapY + currentItemIDs.GetLength(1); y++)
                        {
                            for (int x = mapX; x < mapX + currentItemIDs.GetLength(0); x++)
                            {
                                if (currentLayer[x + y * level.CurrentMap.MapWidth] != currentItemIDs[x - mapX, y - mapY]) change = true;
                                restoreIDs[x - mapX, y - mapY] = currentLayer[x + y * level.CurrentMap.MapWidth];
                                currentLayer[x + y * level.CurrentMap.MapWidth] = currentItemIDs[x - mapX, y - mapY];
                            }
                        }

                        if (change) undo.Push(new Backup(new Vector2(mapX, mapY), restoreIDs, currentLayerID));

                    }

                    break;

                case EditorMode.Rubber:

                    if (input.ButtonDown(input.CurrentMouseState.LeftButton))
                    {
                        int mapX = (int)(mapPos.X) / level.CurrentMap.TileWidth;
                        int mapY = (int)(mapPos.Y) / level.CurrentMap.TileHeight;
                        if (mapX < 0 || mapY < 0 || mapX + currentItemIDs.GetLength(0) > level.CurrentMap.MapWidth || mapY + currentItemIDs.GetLength(1) > level.CurrentMap.MapHeight) return;
                        int[,] restoreIDs = new int[1, 1];
                        bool change = false;

                        if (currentLayer[mapX + mapY * level.CurrentMap.MapWidth] != 0) change = true;
                        restoreIDs[0, 0] = currentLayer[mapX + mapY * level.CurrentMap.MapWidth];
                        currentLayer[mapX + mapY * level.CurrentMap.MapWidth] = 0;
                                             
                        if (change) undo.Push(new Backup(new Vector2(mapX, mapY), restoreIDs, currentLayerID));
                    }

                    break;
               
                case EditorMode.ObjectAdd:
                    if (input.ButtonDown(input.CurrentMouseState.LeftButton) && !objectdrag)
                    {
                        objectposition.X = (int)mapPos.X;
                        objectposition.Y = (int)mapPos.Y;
                        objectdrag = true;
                    }
                    if (objectdrag)
                    {
                        objectposition.Width = (int)mapPos.X - objectposition.X;
                        objectposition.Height = (int)mapPos.Y - objectposition.Y;
                    }

                    if (!input.ButtonDown(input.CurrentMouseState.LeftButton) && objectdrag)
                    {
                        if (objectposition.X < 0)
                        {
                            objectposition.Width += objectposition.X;
                            objectposition.X = 0;
                        }
                        if (objectposition.Y < 0)
                        {
                            objectposition.Height += objectposition.Y;
                            objectposition.Y = 0;
                        }
                        if (objectposition.Width + objectposition.X > level.CurrentMap.MapWidth * level.CurrentMap.TileWidth) objectposition.Width = level.CurrentMap.MapWidth * level.CurrentMap.TileWidth - objectposition.X;
                        if (objectposition.Height + objectposition.Y > level.CurrentMap.MapHeight * level.CurrentMap.TileHeight) objectposition.Height = level.CurrentMap.MapHeight * level.CurrentMap.TileHeight - objectposition.Y;

                        if (objectposition.Width > 0 && objectposition.Height > 0)
                        {
                            if (currentObjectAddmode == ObjectAddMode.Collision) level.CurrentMap.collisions.Add(objectposition);
                            else if (currentObjectAddmode == ObjectAddMode.Teleporter)
                            {
                                level.CurrentMap.teleporters.Add(new Teleporter(objectposition, teleporterparams.mapID, teleporterparams.tpCoordinates));
                                currentEditorMode = EditorMode.Default;
                            }

                            //ADD COllison or teleporter
                        }
                        objectposition = new Rectangle();
                        objectdrag = false;
                    }
                    break;

                case EditorMode.ObjectEdit:

                    if (input.MouseLeftButtonPressed())
                    {
                        Rectangle obj = new Rectangle();
                        foreach (var coll in level.CurrentMap.collisions)
                        {
                            if (CollisionDetector.Collison(coll, mapPos))
                            {
                                obj = coll;
                                break;
                            }
                        }
                        Furniture fur = null;
                        foreach (var coll in level.CurrentMap.entities)
                        {
                            if (CollisionDetector.Collison(new Rectangle((int)coll.Position.X + coll.clickbox.X, (int)coll.Position.Y + coll.clickbox.Y, coll.clickbox.Width, coll.clickbox.Height), mapPos))
                            {
                                fur = coll;
                                break;
                            }
                        }
                        Teleporter tp = null;
                        foreach (var coll in level.CurrentMap.teleporters)
                        {
                            if (CollisionDetector.Collison(coll.position, mapPos))
                            {
                                tp = coll;
                                break;
                            }
                        }
                        if (obj.Width != 0)
                        {
                            level.CurrentMap.collisions.Remove(obj);
                        }
                        if (fur != null)
                        {
                            level.CurrentMap.entities.Remove(fur);
                            level.entities.Remove(fur);
                        }
                        if (tp != null)
                        {
                            level.CurrentMap.teleporters.Remove(tp);
                        }
                    }
                    break;
            }       
        }