Exemplo n.º 1
0
        internal static bool PerformAction([UseOutputBind] ref bool useOutput,
                                           [ThisBind] object @this,
                                           [InputBind(typeof(string), "action")] string action,
                                           [InputBind(typeof(Farmer), "who")] Farmer who,
                                           [InputBind(typeof(xTile.Dimensions.Location), "tileLocation")] xTile.Dimensions.Location tileLocation)
        {
            useOutput = false;

            if (action == null || !who.IsMainPlayer)
            {
                return(useOutput);
            }

            MapActionInformation mapActionInformation;

            if (MapActions.ContainsKey(Game1.currentLocation.Name))
            {
                var list = MapActions[Game1.currentLocation.Name];
                mapActionInformation = list?.FirstOrDefault(item => item.Action == action);
                if (mapActionInformation != null)
                {
                    useOutput = mapActionInformation.Callback.Invoke(action);
                }
            }
            else if ((mapActionInformation = GlobalActions.FirstOrDefault(item => item.Action == action)) != null)
            {
                useOutput = mapActionInformation.Callback.Invoke(action);
            }

            // TODO: Disabled Mod Handling
            //if (ModRegistry.GetRegisteredItems().FirstOrDefault(_ => Equals(_.UniqueId, mapActionInformation?.Owner.ModSettings.UniqueId)) == null)
            //    useOutput = false;

            return(useOutput);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create static collidable bodies from vertices in each layer
        /// sent with the parameter
        /// </summary>
        /// <param name="layers">List of layers ment for making collisionboxes</param>
        private void CreateStaticCollidables(List<Layer> layers)
        {
            foreach (Layer layer in layers)
            {
                TileArray tileArray = layer.Tiles;
                Size tileSize = layer.TileSize;
                Size amntOfTiles = layer.LayerSize;
                List<Point> points = new List<Point>();

                for (int y = 0; y < amntOfTiles.Height; y++)
                {
                    for (int x = 0; x < amntOfTiles.Width; x++)
                    {
                        Location tileLocation = new Location(x, y);
                        Tile thisTile = tileArray[tileLocation];
                        if (thisTile != null)
                        {
                            Point point = new Point(x * tileSize.Width, y * tileSize.Height);
                            points.Add(point);
                        }
                    }
                }
                ExtractRect(points);
            }
        }
Exemplo n.º 3
0
 public TileAnimationCommand(Layer layer, Location tileLocation, AnimatedTile animatedTile)
 {
     m_layer = layer;
     m_tileLocation = tileLocation;
     m_animatedTile = animatedTile;
     m_oldTile = null;
     m_description = "Set animated tile at " + tileLocation;
 }
Exemplo n.º 4
0
        public ToolsEraseTileCommand(Layer layer, Location tileLocation)
        {
            m_layer = layer;
            m_tileLocation = tileLocation;

            m_description = "Erase tile at " + m_tileLocation
                + " in layer \"" + m_layer.Id + "\"";
        }
Exemplo n.º 5
0
        public TileAnimationDialog(Map map, Layer layer, Location tileLocation)
        {
            InitializeComponent();

            m_map = map;
            m_layer = layer;
            m_tileLocation = tileLocation;
        }
Exemplo n.º 6
0
        public EditCutCommand(Layer layer, TileSelection tileSelection)
        {
            m_layer = layer;
            m_selectionLocation = tileSelection.Bounds.Location;
            m_tileSelection = tileSelection;
            m_oldTiles = null;

            m_description = "Cut selection from layer \"" + m_layer.Id + "\"";
        }
Exemplo n.º 7
0
        public EditDeleteCommand(Layer layer, TileSelection tileSelection)
        {
            m_layer = layer;
            m_selectionLocation = tileSelection.Bounds.Location;
            m_tileSelection = tileSelection;
            m_tileBrush = null;

            m_description = "Erase selection from layer \"" + m_layer.Id + "\"";
        }
        public override bool checkAction(xTile.Dimensions.Location tileLocation, xTile.Dimensions.Rectangle viewport, Farmer who)
        {
            int xTile = tileLocation.X, yTile = tileLocation.Y;

            if (xTile >= 23 && xTile <= 27 && yTile >= 10 && yTile <= 14)
            {
                createQuestionDialogue(I18n.Message_Planet_Jump(), createYesNoResponses(), "PlanetJump");
                return(true);
            }

            return(base.checkAction(tileLocation, viewport, who));
        }
Exemplo n.º 9
0
        public EditPasteCommand(Layer layer,
            TileBrush tileBrush, Location brushLocation,
            TileSelection tileSelection, bool fromClipboard)
        {
            m_layer = layer;
            m_tileBrush = tileBrush;
            m_brushLocation = brushLocation;
            m_tileSelection = tileSelection;
            m_fromClipboard = fromClipboard;
            m_oldTiles = null;

            m_description = fromClipboard
                ? "Paste copied tiles" : "Paste tile brush \"" + tileBrush.Id + "\"";
            m_description += " at " + m_brushLocation + " in layer \"" + m_layer.Id + "\"";
        }
Exemplo n.º 10
0
        public ToolsTileBlockCommand(Layer layer, TileSheet tileSheet,
            int tileIndex, Location blockLocation, Size blockSize)
        {
            m_layer = layer;
            m_tileSheet = tileSheet;
            m_tileIndex = tileIndex;
            m_blockLocation = blockLocation;

            m_oldTiles = new Tile[blockSize.Width, blockSize.Height];

            m_oldFringeAssignments = new Dictionary<Location, Tile>();

            m_description = "Draw a block of tiles \"" + m_tileSheet.Id + ":" + m_tileIndex
                + "\" at " + m_blockLocation + " of size " + blockSize
                + " in layer \"" + m_layer.Id + "\"";
        }
Exemplo n.º 11
0
        public void AddLocation(Location tileLocation)
        {
            if (m_tileSelections.Count == 0)
            {
                m_tileSelections[tileLocation] = new TileSelectionBorder();
                m_bounds.Location = tileLocation;
                m_bounds.Size.Width = m_bounds.Size.Height = 1;
            }
            else
            {
                if (m_bounds.Contains(tileLocation)
                    && m_tileSelections.ContainsKey(tileLocation))
                    return;

                m_tileSelections[tileLocation] = new TileSelectionBorder();
                m_bounds.ExtendTo(tileLocation);
            }
            UpdateSelectionBorders();
        }
Exemplo n.º 12
0
        public LayerOffsetCommand(Layer layer, Location offset,
            bool wrapHorizontally, bool wrapVertically)
        {
            m_layer = layer;
            m_offset = offset;
            m_wrapHorizontally = wrapHorizontally;
            m_wrapVertically = wrapVertically;
            m_tiles = null;

            m_description = "Offset layer \"" + m_layer.Id + "\" by " + m_offset + " tiles ";
            if (m_wrapHorizontally && m_wrapVertically)
                m_description += "with horizontal and vertical wrapping";
            else if (m_wrapHorizontally)
                m_description += "with horizontal wrapping only";
            else if (m_wrapVertically)
                m_description += "with vertical wrapping only";
            else
                m_description += "without wrapping";
        }
Exemplo n.º 13
0
        public Dictionary<Location, Tile> DetermineTileAssignments(Layer layer, Location tileLocation, StaticTile staticTile)
        {
            Dictionary<Location, Tile> allAssignments = new Dictionary<Location, Tile>();
            foreach (AutoTile autoTile in m_autoTiles)
            {
                if (autoTile.TileSheet != staticTile.TileSheet)
                    continue;

                Dictionary<Location, Tile> assignments
                    = autoTile.DetermineTileAssignments(layer, tileLocation, staticTile.TileIndex);

                foreach (Location location in assignments.Keys)
                    allAssignments[location] = assignments[location];
            }

            if (m_autoTiles.Count == 0)
                allAssignments[tileLocation] = staticTile.Clone(layer);

            return allAssignments;
        }
Exemplo n.º 14
0
        public ToolsPlaceTileCommand(Layer layer, Tile newTile, Location tileLocation)
        {
            m_layer = layer;

            if (newTile is StaticTile)
            {
                m_newAssignments = AutoTileManager.Instance.DetermineTileAssignments(
                    m_layer, tileLocation, (StaticTile) newTile);
            }
            else
            {
                m_newAssignments = new Dictionary<Location, Tile>();
                m_newAssignments[tileLocation] = newTile;
            }

            m_oldAssignments = new Dictionary<Location, Tile>();
            foreach (Location assignedLocation in m_newAssignments.Keys)
                m_oldAssignments[assignedLocation] = layer.Tiles[assignedLocation];

            m_description = "Place tile \"" + newTile.TileSheet.Id + ":" + newTile.TileIndex
                + "\" at " + tileLocation + " in layer \"" + m_layer.Id + "\"";
        }
        protected List<Vector2> ExtractGameObjectPositions(Layer layer)
        {
            TileArray tileArray = layer.Tiles;
            Size tileSize = layer.TileSize;
            Size amntOfTiles = layer.LayerSize;
            List<Vector2> gameObjectPositions = new List<Vector2>();

            for (int x = 0; x < amntOfTiles.Width; x++)
            {
                for (int y = 0; y < amntOfTiles.Height; y++)
                {
                    Location tileLocation = new Location(x, y);
                    Tile thisTile = tileArray[tileLocation];

                    if (thisTile != null)
                    {
                        Vector2 position = new Vector2(x * tileSize.Width, y * tileSize.Height);
                        gameObjectPositions.Add(position);
                    }
                }
            }

            return gameObjectPositions;
        }
Exemplo n.º 16
0
 /// <summary>
 /// Constructs a Rectangle from another one
 /// </summary>
 /// <param name="rectangle">Rectangle to clone</param>
 public Rectangle(Rectangle rectangle)
 {
     Location = rectangle.Location;
     Size = rectangle.Size;
 }
Exemplo n.º 17
0
 /// <summary>
 /// Constructs a Rectangle with the given location and height
 /// </summary>
 /// <param name="x">Horizontal location coordinate</param>
 /// <param name="y">Vertical location coordinate</param>
 /// <param name="width">Rectangle width</param>
 /// <param name="height">Rectangle height</param>
 public Rectangle(int x, int y, int width, int height)
 {
     Location = new Location(x, y);
     Size = new Size(width, height);
 }
Exemplo n.º 18
0
 /// <summary>
 /// Constructs a Rectangle with the given Size. The top-left
 /// corner is placed at the origin
 /// </summary>
 /// <param name="size">Recangle dimensions</param>
 public Rectangle(Size size)
 {
     Location = Location.Origin;
     Size = size;
 }
Exemplo n.º 19
0
 /// <summary>
 /// Constructs a Rectangle given a Location and Size
 /// </summary>
 /// <param name="location">Location of the Top-left corner</param>
 /// <param name="size">Rectangle dimensions</param>
 public Rectangle(Location location, Size size)
 {
     Location = location;
     Size = size;
 }
Exemplo n.º 20
0
        /// <summary>
        /// Extends the Rectangle bounds to contain the given Location
        /// </summary>
        /// <param name="location">Location to contain</param>
        public void ExtendTo(Location location)
        {
            Location deltaLocation = location - Location;

            if (deltaLocation.X < 0)
            {
                Location.X = location.X;
                Size.Width -= deltaLocation.X;
            }
            else if (Size.Width <= deltaLocation.X)
                Size.Width = deltaLocation.X + 1;

            if (deltaLocation.Y < 0)
            {
                Location.Y = location.Y;
                Size.Height -= deltaLocation.Y;
            }
            else if (Size.Height <= deltaLocation.Y)
                Size.Height = deltaLocation.Y + 1;
        }
Exemplo n.º 21
0
        public static void drawLayer(xTile.Layers.Layer layer, xTile.Display.IDisplayDevice displayDevice, xTile.Dimensions.Rectangle mapViewport, xTile.Dimensions.Location displayOffset, bool wrap, int pixelZoom)
        {
            pixelZoom = (int)Game1.options.zoomLevel;
            int      tileWidth          = pixelZoom * 16;
            int      tileHeight         = pixelZoom * 16;
            Location tileInternalOffset = new Location(mapViewport.X * tileWidth, mapViewport.Y * tileHeight);
            int      tileXMin           = (mapViewport.X >= 0) ? (mapViewport.X / tileWidth) : ((mapViewport.X - tileWidth + 1) / tileWidth);
            int      tileYMin           = (mapViewport.Y >= 0) ? (mapViewport.Y / tileHeight) : ((mapViewport.Y - tileHeight + 1) / tileHeight);

            if (tileXMin < 0)
            {
                displayOffset.X -= tileXMin * tileWidth;
                tileXMin         = 0;
            }
            if (tileYMin < 0)
            {
                displayOffset.Y -= tileYMin * tileHeight;
                tileYMin         = 0;
            }
            int tileColumns = 1 + (mapViewport.Size.Width - 1) / tileWidth;
            int tileRows    = 1 + (mapViewport.Size.Height - 1) / tileHeight;

            if (tileInternalOffset.X != 0)
            {
                tileColumns++;
            }
            if (tileInternalOffset.Y != 0)
            {
                tileRows++;
            }
            int      tileXMax     = Math.Min(tileXMin + tileColumns, layer.LayerSize.Width);
            int      tileYMax     = Math.Min(tileYMin + tileRows, layer.LayerSize.Height);
            Location tileLocation = displayOffset - tileInternalOffset;
            int      offset       = layer.Id.Equals("Front") ? (16 * pixelZoom) : 0;

            for (int tileY = tileYMin; tileY < tileYMax; tileY++)
            {
                tileLocation.X = displayOffset.X - tileInternalOffset.X;
                for (int tileX = tileXMin; tileX < tileXMax; tileX++)
                {
                    Tile tile = layer.Tiles[tileX, tileY];
                    if (tile != null)
                    {
                        displayDevice.DrawTile(tile, tileLocation, (float)(tileY * (16 * pixelZoom) + 16 * pixelZoom + offset) / 10000f);
                    }
                    tileLocation.X += tileWidth;
                }
                tileLocation.Y += tileHeight;
            }
        }
Exemplo n.º 22
0
        protected List<DoorInfo> ExtractGameObjectPositions(xTile.Layers.Layer layer)
        {
            TileArray tileArray = layer.Tiles;
            Size tileSize = layer.TileSize;
            Size amntOfTiles = layer.LayerSize;
            List<DoorInfo> doorInfos = new List<DoorInfo>();

            for (int x = 0; x < amntOfTiles.Width; x++)
            {
                for (int y = 0; y < amntOfTiles.Height; y++)
                {
                    Location tileLocation = new Location(x, y);
                    Tile thisTile = tileArray[tileLocation];

                    if (thisTile != null)
                    {
                        DoorInfo info = new DoorInfo();
                        info.position = new Point(x * tileSize.Width, y * tileSize.Height);
                        info.player = thisTile.Properties["color"];
                        doorInfos.Add(info);
                    }
                }
            }

            return doorInfos;
        }
Exemplo n.º 23
0
        private Location ConvertViewportOffsetToLayerLocation(Location viewportOffset)
        {
            Location layerLocation
                = m_selectedLayer.ConvertMapToLayerLocation(m_viewport.Location, m_viewport.Size);

            if (m_zoom > 1.0f)
                layerLocation += viewportOffset / (int)m_zoom;
            else if (m_zoom < 1.0f)
                layerLocation += viewportOffset * (int)(1.0f / m_zoom);
            else
                layerLocation += viewportOffset;

            xTile.Dimensions.Size tileSize = m_selectedLayer.TileSize;
            layerLocation.X /= tileSize.Width;
            layerLocation.Y /= tileSize.Height;

            return layerLocation;
        }
Exemplo n.º 24
0
        public void DrawTile(Tile tile, Location location)
        {
            if (m_graphics == null)
                return;

            Bitmap tileBitmap = TileImageCache.Instance.GetTileBitmap(
                tile.TileSheet, tile.TileIndex);

            xTile.Dimensions.Size tileSize = tile.TileSheet.TileSize;

            System.Drawing.Rectangle destRect = new System.Drawing.Rectangle(
                location.X, location.Y, tileSize.Width, tileSize.Height);

            if (tile.BlendMode == BlendMode.Alpha)
            {
                m_graphics.DrawImage(tileBitmap, destRect,
                    0, 0, tileSize.Width, tileSize.Height,
                    GraphicsUnit.Pixel, m_imageAttributes);
            }
            else
            {
                // manual additive blending using back buffer bitmap

                // determine clipping
                int minSrcX = 0;
                int minSrcY = 0;
                int maxSrcX = tileSize.Width;
                int maxSrcY = tileSize.Height;

                int minDstX = destRect.X;
                int minDstY = destRect.Y;
                int maxDstX = destRect.Right;
                int maxDstY = destRect.Bottom;

                // clip min x
                if (minDstX < 0)
                {
                    minSrcX = -minDstX;
                    minDstX = 0;
                }

                // clip min y
                if (minDstY < 0)
                {
                    minSrcY = -minDstY;
                    minDstY = 0;
                }

                // clip max x
                if (maxDstX > m_backBuffer.Width)
                {
                    int difference = maxDstX - m_backBuffer.Width;
                    maxSrcX -= difference;
                    maxDstX = m_backBuffer.Width;
                }

                // clip max y
                if (maxDstY > m_backBuffer.Height)
                {
                    int difference = maxDstY - m_backBuffer.Height;
                    maxSrcY -= difference;
                    maxDstY = m_backBuffer.Height;
                }

                // draw only if clipped region within buffer
                if (minSrcX < maxSrcX && minSrcY < maxSrcY)
                {
                    int srcY = minSrcY;
                    for (int dstY = minDstY; dstY < maxDstY; dstY++)
                    {
                        int srcX = minSrcX;
                        for (int dstX = minDstX; dstX < maxDstX; dstX++)
                        {
                            Color backPixel = m_backBuffer.GetPixel(dstX, dstY);
                            Color tilePixel = tileBitmap.GetPixel(srcX, srcY);
                            Color destPixel = Color.FromArgb(backPixel.A,
                                (byte)Math.Min(255, backPixel.R + ((int)tilePixel.R * tilePixel.A) / 255),
                                (byte)Math.Min(255, backPixel.G + ((int)tilePixel.G * tilePixel.A) / 255),
                                (byte)Math.Min(255, backPixel.B + ((int)tilePixel.B * tilePixel.A) / 255));

                            m_backBuffer.SetPixel(dstX, dstY, destPixel);
                            ++srcX;
                        }
                        ++srcY;
                    }
                }
            }
        }
Exemplo n.º 25
0
        private void SelectTiles()
        {
            if (m_selectedLayer == null)
                return;

            xTile.Dimensions.Size layerSize = m_selectedLayer.LayerSize;
            int minX = Math.Max(0, Math.Min(m_tileLayerLocation.X, m_dragTileStart.X));
            int minY = Math.Max(0, Math.Min(m_tileLayerLocation.Y, m_dragTileStart.Y));
            int maxX = Math.Min(layerSize.Width - 1, Math.Max(m_tileLayerLocation.X, m_dragTileStart.X));
            int maxY = Math.Min(layerSize.Height - 1, Math.Max(m_tileLayerLocation.Y, m_dragTileStart.Y));

            Location tileLocation = new Location(minX, minY);
            TileSelection tileSelection = new TileSelection();
            for (; tileLocation.Y <= maxY; tileLocation.Y++)
                for (tileLocation.X = minX; tileLocation.X <= maxX; tileLocation.X++)
                    tileSelection.AddLocation(tileLocation);

            Command command = new ToolsSelectCommand(
                m_selectedLayer, m_tileSelection, tileSelection,
                !m_ctrlKeyPressed);
            m_commandHistory.Do(command);

            m_innerPanel.Invalidate();

            if (SelectionChanged != null)
                SelectionChanged(this, EventArgs.Empty);
        }
        /// <summary>
        /// Repositioning of the camera according to player's position.
        /// Handles input.
        /// </summary>
        public void Update()
        {
            Input();

            // Calculate the "matrix" that center the camera.*/
            _centre = new Vector2(
                activePlayer.destinationBox.X + (activePlayer.destinationBox.Width / 2)
                        - (_viewport.Width / 2),
                activePlayer.destinationBox.Y + (activePlayer.destinationBox.Height / 2)
                        - (_viewport.Height - _viewport.Height / 3));

            // Calculate new camera position.
            _transform = Matrix.CreateScale(new Vector3(1.0f, 1.0f, 0)) *
                         Matrix.CreateTranslation(-_centre.X, -_centre.Y, 0);

            xTileViewportLocation = new Location((int)_centre.X, (int)_centre.Y);
            this.xTILE_viewport.Location = xTileViewportLocation;
        }
Exemplo n.º 27
0
        private void OnMouseDown(object sender, MouseEventArgs mouseEventArgs)
        {
            if (m_selectedLayer == null)
                return;

            m_mouseLocation.X = mouseEventArgs.X;
            m_mouseLocation.Y = mouseEventArgs.Y;

            m_tileLayerLocation
                = ConvertViewportOffsetToLayerLocation(m_mouseLocation);

            if (mouseEventArgs.Button == MouseButtons.Left)
            {
                m_bMouseDown = true;
                switch (m_editTool)
                {
                    case EditTool.Select:
                        m_dragTileStart = m_tileLayerLocation;
                        break;
                    case EditTool.SingleTile: DrawSingleTile(); break;
                    case EditTool.TileBlock: m_dragTileStart = m_tileLayerLocation; break;
                    case EditTool.Eraser: EraseTile(); break;
                    case EditTool.Dropper:
                        PickTile();
                        break;
                    case EditTool.Texture: DrawSampledTile(); break;
                    case EditTool.TileBrush: ApplyTileBrush(); break;
                }
            }
            else if (mouseEventArgs.Button == MouseButtons.Middle)
            {
                if (m_editTool == EditTool.Select)
                {
                    // drag mode
                    m_dragViewMode = true;
                    m_dragViewPosition = mouseEventArgs.Location;
                    Cursor = Cursors.Hand;
                }
                else
                    PickTile();
            }
            else if (mouseEventArgs.Button == MouseButtons.Right)
            {
                if (m_selectedLayer != null)
                {
                    if (m_selectedLayer.IsValidTileLocation(m_tileLayerLocation))
                    {
                        Tile tile = m_selectedLayer.Tiles[m_tileLayerLocation];
                        m_tilePropertiesMenuItem.Enabled = tile != null;
                        m_tileContextMenuStrip.Show(PointToScreen(mouseEventArgs.Location));
                    }
                }
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// Draws the given tile at the given location
        /// </summary>
        /// <param name="tile">Tile to draw</param>
        /// <param name="location">Drawing location</param>
        public void DrawTile(Tile tile, Location location)
        {
            if (tile == null)
                return;

            SpriteBatch spriteBatch = tile.BlendMode == BlendMode.Alpha
                ? m_spriteBatchAlpha : m_spriteBatchAdditive;

            xTile.Dimensions.Rectangle sourceRectangle
                = tile.TileSheet.GetTileImageBounds(tile.TileIndex);

            Texture2D texture2D = m_tileSheetTextures[tile.TileSheet];

            m_tilePosition.X = location.X;
            m_tilePosition.Y = location.Y;

            m_sourceRectangle.X = sourceRectangle.X;
            m_sourceRectangle.Y = sourceRectangle.Y;
            m_sourceRectangle.Width = sourceRectangle.Width;
            m_sourceRectangle.Height = sourceRectangle.Height;

            spriteBatch.Draw(texture2D, m_tilePosition, m_sourceRectangle, m_modulationColour);
        }
Exemplo n.º 29
0
        private void OnAfterLayerDraw(object sender, LayerEventArgs layerEventArgs)
        {
            if (layerEventArgs.Layer != m_selectedLayer)
                return;

            // alignment data
            Layer layer = layerEventArgs.Layer;
            xTile.Dimensions.Rectangle viewport = layerEventArgs.Viewport;
            xTile.Dimensions.Size tileSize = layer.TileSize;
            xTile.Dimensions.Location layerViewportLocation
                = m_selectedLayer.ConvertMapToLayerLocation(viewport.Location, m_viewport.Size);

            // tile guide
            if (m_tileGuides)
            {
                int offsetX = layerViewportLocation.X % tileSize.Width;
                int offsetY = layerViewportLocation.Y % tileSize.Height;
                for (int guideY = -offsetY; guideY < viewport.Size.Height; guideY += tileSize.Height)
                    m_graphics.DrawLine(m_tileGuidePen, 0, guideY, m_viewport.Size.Width, guideY);

                m_graphics.PixelOffsetMode = PixelOffsetMode.None;

                for (int guideX = -offsetX; guideX < viewport.Size.Width; guideX += tileSize.Width)
                    m_graphics.DrawLine(m_tileGuidePen, guideX, 0, guideX, m_viewport.Size.Height);
            }

            // tile selections
            if (!m_tileSelection.IsEmpty())
            {
                Location tileViewportLocation = new Location(
                    layerViewportLocation.X / tileSize.Width, layerViewportLocation.Y / tileSize.Height);
                xTile.Dimensions.Size tileViewportSize = viewport.Size;
                tileViewportSize.Width /= tileSize.Width;
                tileViewportSize.Height /= tileSize.Height;
                tileViewportSize.Width++;
                tileViewportSize.Height++;

                m_graphics.PixelOffsetMode = PixelOffsetMode.None;

                Location tileLocation = tileViewportLocation;
                for (;  tileLocation.Y <= tileViewportLocation.Y + tileViewportSize.Height; tileLocation.Y++)
                    for (tileLocation.X = tileViewportLocation.X;
                        tileLocation.X <= tileViewportLocation.X + tileViewportSize.Width; tileLocation.X++)
                    {
                        if (m_tileSelection.Contains(tileLocation))
                        {
                            xTile.Dimensions.Rectangle tileRectangle = m_selectedLayer.GetTileDisplayRectangle(viewport, tileLocation);
                            int x1 = tileRectangle.Location.X;
                            int y1 = tileRectangle.Location.Y;
                            int width = tileRectangle.Size.Width;
                            int height = tileRectangle.Size.Height;
                            int x2 = x1 + width;
                            int y2 = y1 + height;

                            m_graphics.FillRectangle(m_tileSelectionBrush, x1, y1 , width, height);

                            // selection borders
                            TileSelectionBorder tileSelectionBorder = m_tileSelection.GetTileSelectionBorder(tileLocation);
                            if (tileSelectionBorder.Left)
                                m_graphics.DrawLine(Pens.DarkCyan, x1, y1, x1, y2);

                            if (tileSelectionBorder.Right)
                                m_graphics.DrawLine(Pens.DarkCyan, x2, y1, x2, y2);

                            if (tileSelectionBorder.Above)
                                m_graphics.DrawLine(Pens.DarkCyan, x1, y1, x2, y1);

                            if (tileSelectionBorder.Below)
                                m_graphics.DrawLine(Pens.DarkCyan, x1, y2, x2, y2);
                        }
                    }
            }

            // highlight tile under mouse cursor
            if (m_mouseInside)
            {
                xTile.Dimensions.Rectangle tileDisplayRectangle
                    = m_selectedLayer.GetTileDisplayRectangle(m_viewport, m_tileLayerLocation);
                xTile.Dimensions.Location tileDisplayLocation = tileDisplayRectangle.Location;

                if (m_bMouseDown && (m_editTool == EditTool.Select || m_editTool == EditTool.TileBlock) )
                {
                    xTile.Dimensions.Rectangle tileDragRectangle
                        = m_selectedLayer.GetTileDisplayRectangle(m_viewport, m_dragTileStart);
                    xTile.Dimensions.Location tileDragLocation = tileDragRectangle.Location;

                    int minX = Math.Min(tileDragLocation.X, tileDisplayLocation.X);
                    int minY = Math.Min(tileDragLocation.Y, tileDisplayLocation.Y);
                    int maxX = Math.Max(tileDragLocation.X, tileDisplayLocation.X);
                    int maxY = Math.Max(tileDragLocation.Y, tileDisplayLocation.Y);

                    if (m_editTool == EditTool.TileBlock
                        && m_selectedTileSheet != null && m_selectedTileIndex >= 0)
                    {
                        m_graphics.PixelOffsetMode = PixelOffsetMode.Half;

                        Bitmap tileBitmap = TileImageCache.Instance.GetTileBitmap(m_selectedTileSheet, m_selectedTileIndex);
                        for (int tileY = minY; tileY <= maxY; tileY += tileSize.Height)
                            for (int tileX = minX; tileX <= maxX; tileX += tileSize.Width)
                                m_graphics.DrawImage(tileBitmap, tileX, tileY, tileSize.Width, tileSize.Height);
                    }

                    m_graphics.PixelOffsetMode = PixelOffsetMode.None;

                    int selectionWidth = maxX + tileSize.Width - minX;
                    int selectionHeight = maxY + tileSize.Height - minY;
                    m_graphics.FillRectangle(m_tileSelectionBrush, minX, minY, selectionWidth, selectionHeight);
                    m_graphics.DrawRectangle(m_tileSelectionPen, minX, minY, selectionWidth, selectionHeight);
                }
                else if (m_editTool == EditTool.TileBrush)
                {
                    if (m_selectedTileBrush != null)
                    {
                        xTile.Dimensions.Location location = tileDisplayRectangle.Location;
                        xTile.Dimensions.Size brushSize = m_selectedTileBrush.BrushSize;
                        xTile.Dimensions.Size displaySize = m_selectedTileBrush.DisplaySize;

                        location.X -= (brushSize.Width / 2) * tileSize.Width;
                        location.Y -= (brushSize.Height / 2) * tileSize.Height;

                        m_graphics.PixelOffsetMode = PixelOffsetMode.None;

                        m_colorMatrix.Matrix33 = 0.5f;
                        m_imageAttributes.SetColorMatrix(m_colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

                        System.Drawing.Rectangle destRect
                            = new System.Drawing.Rectangle(location.X, location.Y,
                                displaySize.Width, displaySize.Height);
                        m_graphics.DrawImage(m_selectedTileBrush.ImageRepresentation, destRect,
                            0, 0, displaySize.Width, displaySize.Height, GraphicsUnit.Pixel, m_imageAttributes);
                    }
                }
                else
                {
                    xTile.Dimensions.Location location = tileDisplayRectangle.Location;
                    xTile.Dimensions.Size size = tileDisplayRectangle.Size;

                    m_graphics.PixelOffsetMode = PixelOffsetMode.None;

                    m_graphics.FillRectangle(m_tileSelectionBrush,
                        location.X, location.Y, size.Width, size.Height);
                    m_graphics.DrawRectangle(m_tileSelectionPen,
                        location.X, location.Y, size.Width, size.Height);
                }
            }

            if (m_layerCompositing == LayerCompositing.DimUnselected)
            {
                // set translucency for upper layers
                m_colorMatrix.Matrix33 = 0.25f;
                m_imageAttributes.SetColorMatrix(m_colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
            }
        }
Exemplo n.º 30
0
        public MapPanel()
        {
            InitializeComponent();

            m_commandHistory = CommandHistory.Instance;

            m_singleTileCursor = new Cursor(new MemoryStream(Properties.Resources.ToolsSingleTileCursor));
            m_tileBlockCursor = new Cursor(new MemoryStream(Properties.Resources.ToolsTileBlockCursor));
            m_eraserCursor = new Cursor(new MemoryStream(Properties.Resources.ToolsEraserCursor));
            m_dropperCursor = new Cursor(new MemoryStream(Properties.Resources.ToolsDropperCursor));

            m_viewport = new xTile.Dimensions.Rectangle(
                xTile.Dimensions.Location.Origin, xTile.Dimensions.Size.Zero);
            m_autoScaleViewport = true;

            m_zoomIndex = 5;
            m_zoom = 1.0f;

            m_layerCompositing = LayerCompositing.DimUnselected;

            m_editTool = EditTool.SingleTile;
            m_innerPanel.Cursor = m_singleTileCursor;
            m_mouseInside = false;
            m_mouseLocation = new Location();
            m_tileLayerLocation = xTile.Dimensions.Location.Origin;
            m_dragTileStart = xTile.Dimensions.Location.Origin;

            m_tileSelection = new TileSelection();
            m_ctrlKeyPressed = false;

            m_random = new Random();
            m_textureDistribution = new List<Tile>();

            m_tileGuides = false;

            m_veilBrush = new SolidBrush(Color.FromArgb(192, SystemColors.InactiveCaption));
            m_imageAttributes = new ImageAttributes();
            m_colorMatrix = new ColorMatrix();
            m_tileSelectionPen = new Pen(SystemColors.ActiveCaption);
            m_tileSelectionBrush = new SolidBrush(
                Color.FromArgb(128, SystemColors.ActiveCaption));

            m_dashPattern = new float[] { 1.0f, 1.0f, 1.0f, 1.0f };
            m_tileGuidePen = new Pen(Color.Black);
            m_tileGuidePen.DashPattern = m_dashPattern;

            m_animationTimer.Enabled = !this.DesignMode;

            m_dtStart = DateTime.Now;

            this.MouseWheel += new MouseEventHandler(OnMouseWheel);
        }
Exemplo n.º 31
0
 /// <summary>
 /// Tests if a Location is inside the Rectangle
 /// </summary>
 /// <param name="location">Location to test</param>
 /// <returns>True if the Location is inside the Rectangle, False otherwise</returns>
 public bool Contains(Location location)
 {
     return location.X >= Location.X && location.Y >= Location.Y
         && location.X < Location.X + Size.Width
         && location.Y < Location.Y + Size.Height;
 }
Exemplo n.º 32
0
 /// <summary>
 /// Tile accessor using Location instance
 /// </summary>
 /// <param name="location">Tile location</param>
 /// <returns></returns>
 public Tile this[Location location]
 {
     get { return this[location.X, location.Y]; }
     set { this[location.X, location.Y] = value; }
 }
Exemplo n.º 33
0
        private void OnMouseMove(object sender, MouseEventArgs mouseEventArgs)
        {
            // needed for mouse wheel event to work
            this.Focus();

            if (m_selectedLayer == null)
                return;

            m_mouseInside = true;
            m_mouseLocation.X = mouseEventArgs.X;
            m_mouseLocation.Y = mouseEventArgs.Y;

            m_tileLayerLocation
                = ConvertViewportOffsetToLayerLocation(m_mouseLocation);

            if (m_bMouseDown && mouseEventArgs.Button == MouseButtons.Left)
            {
                switch (m_editTool)
                {
                    case EditTool.SingleTile: DrawSingleTile(); break;
                    case EditTool.Eraser: EraseTile(); break;
                    case EditTool.Dropper:
                        PickTile();
                        break;
                }
            }

            if (m_dragViewMode)
            {
                int deltaX = (int)((m_dragViewPosition.X - m_mouseLocation.X) / m_zoom);
                int deltaY = (int)((m_dragViewPosition.Y - m_mouseLocation.Y) / m_zoom);

                if (deltaX != 0 || deltaY != 0)
                {
                    m_dragViewPosition.X = m_mouseLocation.X;
                    m_dragViewPosition.Y = m_mouseLocation.Y;

                    m_viewport.X += deltaX;
                    m_viewport.Y += deltaY;

                    RestrictViewportToMap();
                }
            }

            if (TileHover != null)
            {
                Tile tile = m_selectedLayer.IsValidTileLocation(m_tileLayerLocation)
                    ? m_selectedLayer.Tiles[m_tileLayerLocation]
                    : null;
                TileHover(new MapPanelEventArgs
                    (tile, m_tileLayerLocation));
            }
        }