Exemplo n.º 1
0
        private void OnDialogApply(object sender, EventArgs e)
        {
            string newLayerId = m_textBoxId.Text;

            if (IsDuplicateLayerId(newLayerId))
            {
                m_duplicateIdMessageBox.Show();
                return;
            }

            Size newLayerSize = new Size((int)m_numericLayerWidth.Value, (int)m_numericLayerHeight.Value);
            Size newTileSize = new Size((int)m_numericTileWidth.Value, (int)m_numericTileHeight.Value);

            Command command = null;

            if (m_isNewLayer)
            {
                m_layer.Id = newLayerId;
                m_layer.Description = m_textBoxDescription.Text;
                m_layer.LayerSize = newLayerSize;
                m_layer.TileSize = newTileSize;
                command = new LayerNewCommand(m_layer.Map, m_layer);

                m_isNewLayer = false;
            }
            else
                command = new LayerPropertiesCommand(m_layer, newLayerId, m_textBoxDescription.Text,
                    newLayerSize, newTileSize, m_checkBoxVisible.Checked,
                    m_customPropertyGrid.NewProperties, m_alignmentButton.Alignment);

            CommandHistory.Instance.Do(command);

            MarkAsApplied();
        }
Exemplo n.º 2
0
        public TileSheetPropertiesCommand(TileSheet tileSheet,
            string newId, string newDescription,
            Size newTileSize, Size newMargin, Size newSpacing,
            Size newSheetSize, string newImageSource,
            PropertyCollection newProperties)
        {
            m_tileSheet = tileSheet;

            m_oldId = tileSheet.Id;
            m_oldDescription = tileSheet.Description;
            m_oldTileSize = tileSheet.TileSize;
            m_oldMargin = tileSheet.Margin;
            m_oldSpacing = tileSheet.Spacing;
            m_oldSheetSize = tileSheet.SheetSize;
            m_oldImageSource = tileSheet.ImageSource;
            m_oldProperties = new PropertyCollection(tileSheet.Properties);

            m_newId = newId;
            m_newDescription = newDescription;
            m_newTileSize = newTileSize;
            m_newMargin = newMargin;
            m_newSpacing = newSpacing;
            m_newSheetSize = newSheetSize;
            m_newImageSource = newImageSource;
            m_newProperties = newProperties;
        }
Exemplo n.º 3
0
        internal TileBrush(string id, Layer layer, TileSelection tileSelection)
        {
            m_id = id;
            xTile.Dimensions.Rectangle selectionBounds = tileSelection.Bounds;

            m_brushSize   = selectionBounds.Size;
            m_tileSize    = layer.TileSize;
            m_displaySize = new xTile.Dimensions.Size(
                m_brushSize.Width * m_tileSize.Width,
                m_brushSize.Height * m_tileSize.Height);

            m_tileBrushElements = new List <TileBrushElement>();
            foreach (Location location in tileSelection.Locations)
            {
                if (!layer.IsValidTileLocation(location))
                {
                    continue;
                }

                Tile             tile             = layer.Tiles[location];
                Tile             tileClone        = tile == null ? null : tile.Clone(layer);
                TileBrushElement tileBrushElement = new TileBrushElement(
                    tileClone, location - selectionBounds.Location);
                m_tileBrushElements.Add(tileBrushElement);
            }
        }
Exemplo n.º 4
0
        public override void Do()
        {
            m_oldFringeAssignments.Clear();

            Size blockSize = new Size(m_oldTiles.GetLength(0), m_oldTiles.GetLength(1));
            int tileY = m_blockLocation.Y;
            for (int blockY = 0; blockY < blockSize.Height; blockY++, tileY++)
            {
                int tileX = m_blockLocation.X;
                for (int blockX = 0; blockX < blockSize.Width; blockX++, tileX++)
                {
                    // place block tile (after preserving old tile)
                    m_oldTiles[blockX, blockY] = m_layer.Tiles[tileX, tileY];
                    StaticTile localTile = new StaticTile(m_layer, m_tileSheet, BlendMode.Alpha, m_tileIndex);
                    m_layer.Tiles[tileX, tileY] = localTile;

                    // determine local fringe auto-tiles
                    Dictionary<Location, Tile> localAssignments = AutoTileManager.Instance.DetermineTileAssignments(
                        m_layer, new Location(tileX, tileY), localTile);

                    // place fringe auto-tiles (after preserving previous tiles)
                    foreach (Location locationKey in localAssignments.Keys)
                    {
                        m_oldFringeAssignments[locationKey] = m_layer.Tiles[locationKey];
                        m_layer.Tiles[locationKey] = localAssignments[locationKey];
                    }
                }
            }
        }
Exemplo n.º 5
0
 public TileEventArgs(Graphics graphics, Location location, Location tileLocation, xTile.Dimensions.Size tileSize)
 {
     Graphics     = graphics;
     Location     = location;
     TileLocation = tileLocation;
     TileSize     = tileSize;
 }
Exemplo n.º 6
0
Arquivo: Map.cs Projeto: dekk7/xEngine
 /// <summary>
 /// Constructs a map with the given ID
 /// </summary>
 /// <param name="id">ID to assign to the Map</param>
 public Map(string id)
     : base(id)
 {
     m_tileSheets = new List<TileSheet>();
     m_layers = new List<Layer>();
     m_elapsedTime = 0;
     m_displaySize = Size.Zero;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Constructs a TileSheet for the given map, image source, sheet size
 /// and tile size. An GUID-based ID is automatically assigned to the
 /// sheet
 /// </summary>
 /// <param name="map">Map associated with the tile sheet</param>
 /// <param name="imageSource">Reference to an image source</param>
 /// <param name="sheetSize">Size of the sheet in tiles</param>
 /// <param name="tileSize">Size of the tiles in pixels</param>
 public TileSheet(Map map, string imageSource, Size sheetSize, Size tileSize)
 {
     m_map = map;
     m_imageSource = imageSource;
     m_sheetSize = sheetSize;
     m_tileSize = tileSize;
     m_margin = m_spacing = Size.Zero;
     m_tileIndexPropertyAccessor = new TileIndexPropertyAccessor(this);
 }
Exemplo n.º 8
0
 internal TileBrush(TileBrush tileBrush)
 {
     m_id = tileBrush.m_id;
     m_brushSize = tileBrush.m_brushSize;
     m_tileSize = tileBrush.m_tileSize;
     m_displaySize = tileBrush.m_displaySize;
     m_tileBrushElements = new List<TileBrushElement>(tileBrush.m_tileBrushElements);
     m_imageRepresentation = tileBrush.m_imageRepresentation;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Constructs a new layer with the given ID, parent map,
 /// layer dimensions and tile dimensions
 /// </summary>
 /// <param name="id">ID to assign to the layer</param>
 /// <param name="map">map containing the new layer</param>
 /// <param name="layerSize">width and height of the layer in tiles</param>
 /// <param name="tileSize">tile width and height in pixels</param>
 public Layer(string id, Map map, Size layerSize, Size tileSize)
     : base(id)
 {
     m_map = map;
     m_tileSheets = map.TileSheets;
     m_layerSize = layerSize;
     m_tileSize = tileSize;
     m_tiles = new Tile[layerSize.Width, layerSize.Height];
     m_tileArray = new TileArray(this, m_tiles);
     m_visible = true;
 }
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
        internal TileBrush(string id, List<TileBrushElement> tileBrushElements)
        {
            m_id = id;

            m_brushSize = new xTile.Dimensions.Size();
            m_tileSize = new xTile.Dimensions.Size();
            foreach (TileBrushElement tileBrushElement in tileBrushElements)
            {
                m_brushSize.Width = Math.Max(m_brushSize.Width, tileBrushElement.Location.X + 1);
                m_brushSize.Height = Math.Max(m_brushSize.Height, tileBrushElement.Location.Y + 1);
                if (tileBrushElement.Tile != null)
                    m_tileSize = tileBrushElement.Tile.TileSheet.TileSize;
            }

            m_displaySize = new xTile.Dimensions.Size(
                m_brushSize.Width * m_tileSize.Width,
                m_brushSize.Height * m_tileSize.Height);

            m_tileBrushElements = new List<TileBrushElement>(tileBrushElements);
        }
Exemplo n.º 12
0
        internal void ApplyTo(Layer layer, Location brushLocation,
                              TileSelection tileSelection)
        {
            Map map = layer.Map;

            xTile.Dimensions.Size layerTileSize = layer.TileSize;

            if (layerTileSize != m_tileSize)
            {
                return;
            }


            tileSelection.Clear();
            foreach (TileBrushElement tileBrushElement in m_tileBrushElements)
            {
                Location tileLocation = brushLocation + tileBrushElement.Location;
                if (!layer.IsValidTileLocation(tileLocation))
                {
                    continue;
                }

                Tile tile      = tileBrushElement.Tile;
                Tile tileClone = null;
                if (tile != null)
                {
                    TileSheet tileSheet = tile.TileSheet;

                    if (!map.TileSheets.Contains(tile.TileSheet))
                    {
                        continue;
                    }

                    tileClone = tile.Clone(layer);
                }

                layer.Tiles[tileLocation] = tileClone;
                tileSelection.AddLocation(tileLocation);
            }
        }
Exemplo n.º 13
0
        internal TileBrush(string id, List <TileBrushElement> tileBrushElements)
        {
            m_id = id;

            m_brushSize = new xTile.Dimensions.Size();
            m_tileSize  = new xTile.Dimensions.Size();
            foreach (TileBrushElement tileBrushElement in tileBrushElements)
            {
                m_brushSize.Width  = Math.Max(m_brushSize.Width, tileBrushElement.Location.X + 1);
                m_brushSize.Height = Math.Max(m_brushSize.Height, tileBrushElement.Location.Y + 1);
                if (tileBrushElement.Tile != null)
                {
                    m_tileSize = tileBrushElement.Tile.TileSheet.TileSize;
                }
            }

            m_displaySize = new xTile.Dimensions.Size(
                m_brushSize.Width * m_tileSize.Width,
                m_brushSize.Height * m_tileSize.Height);

            m_tileBrushElements = new List <TileBrushElement>(tileBrushElements);
        }
Exemplo n.º 14
0
        internal TileBrush(string id, Layer layer, TileSelection tileSelection)
        {
            m_id = id;
            xTile.Dimensions.Rectangle selectionBounds = tileSelection.Bounds;

            m_brushSize = selectionBounds.Size;
            m_tileSize = layer.TileSize;
            m_displaySize = new xTile.Dimensions.Size(
                m_brushSize.Width * m_tileSize.Width,
                m_brushSize.Height * m_tileSize.Height);

            m_tileBrushElements = new List<TileBrushElement>();
            foreach (Location location in tileSelection.Locations)
            {
                if (!layer.IsValidTileLocation(location))
                    continue;

                Tile tile = layer.Tiles[location];
                Tile tileClone = tile == null ? null : tile.Clone(layer);
                TileBrushElement tileBrushElement = new TileBrushElement(
                    tileClone, location - selectionBounds.Location);
                m_tileBrushElements.Add(tileBrushElement);
            }
        }
Exemplo n.º 15
0
        public override void Undo()
        {
            // undo fringe auto-tiles
            foreach (Location locationKey in m_oldFringeAssignments.Keys)
                m_layer.Tiles[locationKey] = m_oldFringeAssignments[locationKey];

            // undo block tiles
            Size blockSize = new Size(m_oldTiles.GetLength(0), m_oldTiles.GetLength(1));
            int layerY = m_blockLocation.Y;
            for (int tileY = 0; tileY < blockSize.Height; tileY++, layerY++)
            {
                int layerX = m_blockLocation.X;
                for (int tileX = 0; tileX < blockSize.Width; tileX++, layerX++)
                    m_layer.Tiles[layerX, layerY] = m_oldTiles[tileX, tileY];
            }
        }
Exemplo n.º 16
0
Arquivo: Map.cs Projeto: dekk7/xEngine
 internal void UpdateDisplaySize()
 {
     m_displaySize = Size.Zero;
     foreach (Layer layer in m_layers)
     {
         Size displaySize = layer.DisplaySize;
         m_displaySize.Width = Math.Max(m_displaySize.Width, displaySize.Width);
         m_displaySize.Height = Math.Max(m_displaySize.Height, displaySize.Height);
     }
 }
Exemplo n.º 17
0
 /// <summary>
 /// Returns a reference to a tile given a pixel location within the
 /// map and the viewport size taking into account parallax effects.
 /// If no tile is assigned a at the computed location, null is
 /// returned
 /// </summary>
 /// <param name="mapDisplayLocation">pixel location where to pick the tile</param>
 /// <param name="viewportSize">viewport size to compute parallax for this layer</param>
 /// <returns>Tile picked at the location, or null if one present</returns>
 public Tile PickTile(Location mapDisplayLocation, Size viewportSize)
 {
     Location tileLocation = ConvertMapToLayerLocation(mapDisplayLocation, viewportSize);
     if (IsValidTileLocation(tileLocation))
         return m_tiles[tileLocation.X, tileLocation.Y];
     else
         return null;
 }
Exemplo n.º 18
0
        /// <summary>
        /// Convers the map location given in pixels to a layer location in
        /// pixels taking into account parallax effects given the viewport size
        /// </summary>
        /// <param name="mapDisplayLocation">Location in map pixel coordinates</param>
        /// <param name="viewportSize">Viewport dimensions in pixels</param>
        /// <returns>Location in layer pixel coordinates</returns>
        public Location ConvertMapToLayerLocation(Location mapDisplayLocation, Size viewportSize)
        {
            Size mapDisplaySize = m_map.DisplaySize;
            Size layerDisplaySize = DisplaySize;

            int viewportWidth = viewportSize.Width;
            int viewportHeight = viewportSize.Height;

            int layerWidthDifference = layerDisplaySize.Width - viewportWidth;
            int layerHeightDifference = layerDisplaySize.Height - viewportHeight;

            int mapWidthDifference = mapDisplaySize.Width - viewportWidth;
            int mapHeightDifference = mapDisplaySize.Height - viewportHeight;

            int layerLocationX = mapWidthDifference > 0
                ? mapDisplayLocation.X * layerWidthDifference / mapWidthDifference
                : 0;

            int layerLocationY = mapHeightDifference > 0
                ? mapDisplayLocation.Y * layerHeightDifference / mapHeightDifference
                : 0;

            return new Location(layerLocationX, layerLocationY);
        }
Exemplo n.º 19
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.º 20
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.º 21
0
 private void StoreSize(Stream stream, Size size)
 {
     StoreInt32(stream, size.Width);
     StoreInt32(stream, size.Height);
 }
Exemplo n.º 22
0
 private Size LoadSize(Stream stream)
 {
     Dimensions.Size size = new Size();
     size.Width = LoadInt32(stream);
     size.Height = LoadInt32(stream);
     return size;
 }
Exemplo n.º 23
0
        public Map Load(Stream stream)
        {
            Map map = new Map("Flixel Map");

            // if using wait cursor, switch to default one during dialog
            bool useWaitCursor = Application.UseWaitCursor;
            Application.UseWaitCursor = false;
            Application.DoEvents();

            TileSheet tilesheet = new TileSheet("Flixel Tile Sheet", map, "", new Size(10, 10), new Size(16, 15));
            TileSheetPropertiesDialog tileSheetPropertiesDialog = new TileSheetPropertiesDialog(tilesheet, true, null);
            if (tileSheetPropertiesDialog.ShowDialog() == DialogResult.Cancel)
                throw new Exception("No tile sheet configured");

            Application.UseWaitCursor = useWaitCursor;
            Application.DoEvents();

            TextReader layerTextReader = new StreamReader(stream);

            List<List<int>> tileIndices = new List<List<int>>();

            char[] commas = new char[] { ',' };
            Size layerSize = new Size();

            while (true)
            {
                string layerLine = layerTextReader.ReadLine();
                if (layerLine == null)
                    break;

                List<int> indexRow = new List<int>();
                tileIndices.Add(indexRow);

                string[] tokens = layerLine.Split(commas);

                layerSize.Width = Math.Max(layerSize.Width, tokens.Length);

                foreach (string token in tokens)
                {
                    int tileIndex = int.Parse(token.Trim());
                    indexRow.Add(tileIndex);
                }

                layerSize.Height++;
            }

            Layer layer = new Layer("Flixel Layer", map, layerSize, tilesheet.TileSize);
            map.AddLayer(layer);

            for (int tileY = 0; tileY < tileIndices.Count; tileY++)
            {
                List<int> indexRow = tileIndices[tileY];
                for (int tileX = 0; tileX < indexRow.Count; tileX++)
                    layer.Tiles[tileX, tileY] = new StaticTile(layer, tilesheet, BlendMode.Alpha, indexRow[tileX]);
            }

            return map;
        }
Exemplo n.º 24
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.º 25
0
        private void OnFieldChanged(object sender, EventArgs e)
        {
            MarkAsModified();

            Size newLayerSize = new Size((int)m_numericLayerWidth.Value, (int)m_numericLayerHeight.Value);
            m_lblAlignment.Visible = m_alignmentButton.Visible =
                !m_isNewLayer && m_layer.LayerSize != newLayerSize;
        }
Exemplo n.º 26
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.º 27
0
        private void OnDialogApply(object sender, EventArgs eventArgs)
        {
            if (m_bitmapImageSource == null)
            {
                m_noImageSourceMessageBox.Show();
                DialogResult = DialogResult.None;
                return;
            }

            string newId = m_textBoxId.Text;

            foreach (TileSheet tileSheet in m_tileSheet.Map.TileSheets)
            {
                if (tileSheet == m_tileSheet)
                {
                    continue;
                }
                if (newId == tileSheet.Id)
                {
                    m_duplicateIdMessageBox.Show();
                    DialogResult = DialogResult.None;
                    return;
                }
            }

            if ((m_tileSheet.TileWidth != m_textBoxTileWidth.Value ||
                 m_tileSheet.TileHeight != m_textBoxTileHeight.Value) &&
                m_tileSheet.Map.DependsOnTileSheet(m_tileSheet))
            {
                m_tileSizeFixedMessageBox.Show();
                DialogResult = DialogResult.None;
                return;
            }

            xTile.Dimensions.Size newTileSize = new xTile.Dimensions.Size(
                (int)m_textBoxTileWidth.Value, (int)m_textBoxTileHeight.Value);

            xTile.Dimensions.Size newMargin = new xTile.Dimensions.Size(
                (int)m_textBoxLeftMargin.Value, (int)m_textBoxTopMargin.Value);

            xTile.Dimensions.Size newSpacing = new xTile.Dimensions.Size(
                (int)m_textBoxSpacingX.Value, (int)m_textBoxSpacingY.Value);

            xTile.Dimensions.Size newSheetSize = xTile.Dimensions.Size.Zero;
            if (m_bitmapImageSource != null)
            {
                newSheetSize.Width = (m_bitmapImageSource.Width + newSpacing.Width - newMargin.Width)
                                     / (newTileSize.Width + newSpacing.Width);
                newSheetSize.Height = (m_bitmapImageSource.Height + newSpacing.Height - newMargin.Height)
                                      / (newTileSize.Height + newSpacing.Height);
            }

            Command command = null;

            if (m_isNewTileSheet)
            {
                m_tileSheet.Id          = newId;
                m_tileSheet.Description = m_textBoxDescription.Text;
                m_tileSheet.TileSize    = newTileSize;
                m_tileSheet.Margin      = newMargin;
                m_tileSheet.Spacing     = newSpacing;
                m_tileSheet.SheetSize   = newSheetSize;
                m_tileSheet.ImageSource = m_textBoxImageSource.Text;
                m_tileSheet.Properties.Clear();
                m_tileSheet.Properties.CopyFrom(m_customPropertyGrid.NewProperties);
                command = new TileSheetNewCommand(m_tileSheet.Map, m_tileSheet, m_mapTreeView);

                m_isNewTileSheet = false;
            }
            else
            {
                command = new TileSheetPropertiesCommand(m_tileSheet, newId, m_textBoxDescription.Text,
                                                         newTileSize, newMargin, newSpacing, newSheetSize, m_textBoxImageSource.Text,
                                                         m_customPropertyGrid.NewProperties);
            }

            CommandHistory.Instance.Do(command);

            AutoTileManager.Instance.Refresh(m_tileSheet);

            MarkAsApplied();
        }
Exemplo n.º 28
0
        private void LoadTileSet(XmlHelper xmlHelper, Map map)
        {
            string id = xmlHelper.GetAttribute("name");

            int firstGid = xmlHelper.GetIntAttribute("firstgid");

            int tileWidth = xmlHelper.GetIntAttribute("tilewidth");
            int tileHeight = xmlHelper.GetIntAttribute("tileheight");
            Size tileSize = new Size(tileWidth, tileHeight);

            int marginValue = xmlHelper.GetIntAttribute("margin", 0);
            Size margin = new Size(marginValue);

            int spacingValue = xmlHelper.GetIntAttribute("spacing", 0);
            Size spacing = new Size(spacingValue);

            xmlHelper.AdvanceStartElement("image");
            string imageSource = xmlHelper.GetAttribute("source");
            xmlHelper.AdvanceEndElement("image");

            Size sheetSize = new Size();
            try
            {
                using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(imageSource))
                {
                    sheetSize.Width = (bitmap.Width + spacingValue - marginValue) / (tileWidth + spacingValue);
                    sheetSize.Height = (bitmap.Height + spacingValue - marginValue) / (tileHeight + spacingValue);
                }
            }
            catch (Exception exception)
            {
                throw new Exception("Unable to determine sheet size from image source", exception);
            }

            TileSheet tileSheet = new TileSheet(id, map, imageSource, sheetSize, tileSize);
            tileSheet.Margin = margin;
            tileSheet.Spacing = spacing;

            // keep track of first gid as custom property
            tileSheet.Properties["@FirstGid"] = firstGid;

            // also add lastgid to facilitate import
            tileSheet.Properties["@LastGid"] = firstGid + tileSheet.TileCount - 1;

            // properties at tile level within tile sets not supported
            // but are mapped as prefixed properties at tile sheet level
            XmlNodeType xmlNodeType = xmlHelper.AdvanceNode();
            while (xmlNodeType == XmlNodeType.Element && xmlHelper.XmlReader.Name == "tile")
            {
                int tileId = xmlHelper.GetIntAttribute("id");
                xmlHelper.AdvanceNamedNode(XmlNodeType.Element, "properties");
                Component dummyComponent = new DummyComponent();
                LoadProperties(xmlHelper, dummyComponent);
                xmlHelper.AdvanceEndElement("tile");

                foreach (string propertyName in dummyComponent.Properties.Keys)
                {
                    tileSheet.Properties["@Tile@" + tileId + "@" + propertyName]
                        = dummyComponent.Properties[propertyName];
                }

                xmlNodeType = xmlHelper.AdvanceNode();
            }

            map.AddTileSheet(tileSheet);
        }
Exemplo n.º 29
0
        private void OnDialogApply(object sender, EventArgs eventArgs)
        {
            if (m_bitmapImageSource == null)
            {
                m_noImageSourceMessageBox.Show();
                DialogResult = DialogResult.None;
                return;
            }

            string newId = m_textBoxId.Text;

            foreach (TileSheet tileSheet in m_tileSheet.Map.TileSheets)
            {
                if (tileSheet == m_tileSheet)
                    continue;
                if (newId == tileSheet.Id)
                {
                    m_duplicateIdMessageBox.Show();
                    DialogResult = DialogResult.None;
                    return;
                }
            }

            if ((m_tileSheet.TileWidth != m_textBoxTileWidth.Value
                || m_tileSheet.TileHeight != m_textBoxTileHeight.Value)
                && m_tileSheet.Map.DependsOnTileSheet(m_tileSheet))
            {
                m_tileSizeFixedMessageBox.Show();
                DialogResult = DialogResult.None;
                return;
            }

            xTile.Dimensions.Size newTileSize = new xTile.Dimensions.Size(
                (int)m_textBoxTileWidth.Value, (int)m_textBoxTileHeight.Value);

            xTile.Dimensions.Size newMargin = new xTile.Dimensions.Size(
                (int)m_textBoxLeftMargin.Value, (int)m_textBoxTopMargin.Value);

            xTile.Dimensions.Size newSpacing = new xTile.Dimensions.Size(
                (int)m_textBoxSpacingX.Value, (int)m_textBoxSpacingY.Value);

            xTile.Dimensions.Size newSheetSize = xTile.Dimensions.Size.Zero;
            if (m_bitmapImageSource != null)
            {
                newSheetSize.Width = (m_bitmapImageSource.Width + newSpacing.Width - newMargin.Width)
                        / (newTileSize.Width + newSpacing.Width);
                newSheetSize.Height = (m_bitmapImageSource.Height + newSpacing.Height - newMargin.Height)
                        / (newTileSize.Height + newSpacing.Height);
            }

            Command command = null;

            if (m_isNewTileSheet)
            {
                m_tileSheet.Id = newId;
                m_tileSheet.Description = m_textBoxDescription.Text;
                m_tileSheet.TileSize = newTileSize;
                m_tileSheet.Margin = newMargin;
                m_tileSheet.Spacing = newSpacing;
                m_tileSheet.SheetSize = newSheetSize;
                m_tileSheet.ImageSource = m_textBoxImageSource.Text;
                m_tileSheet.Properties.Clear();
                m_tileSheet.Properties.CopyFrom(m_customPropertyGrid.NewProperties);
                command = new TileSheetNewCommand(m_tileSheet.Map, m_tileSheet, m_mapTreeView);

                m_isNewTileSheet = false;
            }
            else
            {
                command = new TileSheetPropertiesCommand(m_tileSheet, newId, m_textBoxDescription.Text,
                    newTileSize, newMargin, newSpacing, newSheetSize, m_textBoxImageSource.Text,
                    m_customPropertyGrid.NewProperties);
            }

            CommandHistory.Instance.Do(command);

            AutoTileManager.Instance.Refresh(m_tileSheet);

            MarkAsApplied();
        }
Exemplo n.º 30
0
        /// <summary>
        /// Convers the layer location given in pixels to a map location in
        /// pixels taking into account parallax effects given the viewport size
        /// </summary>
        /// <param name="layerDisplayLocation">Location in layer pixel coordinates</param>
        /// <param name="viewportSize">Viewport dimensions in pixels</param>
        /// <returns>Location in map pixel coordinates</returns>
        public Location ConvertLayerToMapLocation(Location layerDisplayLocation, Size viewportSize)
        {
            Size mapDisplaySize = m_map.DisplaySize;
            Size layerDisplaySize = DisplaySize;

            return new Location(
                (layerDisplayLocation.X * (mapDisplaySize.Width - viewportSize.Width)) / (layerDisplaySize.Width - viewportSize.Width),
                (layerDisplayLocation.Y * (mapDisplaySize.Height - viewportSize.Height)) / (layerDisplaySize.Height - viewportSize.Height));
        }
Exemplo n.º 31
0
        private void LoadLayer(XmlHelper xmlHelper, Map map)
        {
            if (map.TileSheets.Count == 0)
                throw new Exception("Must load at least one tileset to determine layer tile size");

            string id = xmlHelper.GetAttribute("name");

            int layerWidth = xmlHelper.GetIntAttribute("width");
            int layerHeight = xmlHelper.GetIntAttribute("height");
            Size layerSize = new Size(layerWidth, layerHeight);

            int visible = xmlHelper.GetIntAttribute("visible", 1);

            // must assume tile size from first tile set
            Size tileSize = map.TileSheets[0].TileSize;

            Layer layer = new Layer(id, map, layerSize, tileSize);
            layer.Visible = visible > 0;

            // load properties if available
            XmlNodeType xmlNodeType = xmlHelper.AdvanceNode();
            if (xmlNodeType == XmlNodeType.Element && xmlHelper.XmlReader.Name == "properties")
            {
                LoadProperties(xmlHelper, layer);

                // try to obtain layer description via custom property
                if (layer.Properties.ContainsKey("@Description"))
                    layer.Description = layer.Properties["@Description"];

                xmlHelper.AdvanceStartElement("data");
            }
            else if (xmlNodeType != XmlNodeType.Element || xmlHelper.XmlReader.Name != "data")
                throw new Exception("The element <properties> or <data> expected");

            string dataEncoding = xmlHelper.GetAttribute("encoding", "xml");
            string dataCompression = xmlHelper.GetAttribute("compression", "none");

            if (dataEncoding == "xml")
                LoadLayerDataXml(xmlHelper, layer);
            else if (dataEncoding == "base64")
                LoadLayerDataBase64(xmlHelper, layer, dataCompression);
            else if (dataEncoding == "csv")
                LoadLayerDataCsv(xmlHelper, layer);
            else
                throw new Exception("Unknown encoding/compression setting combination (" + dataEncoding + "/" + dataCompression + ")");

            xmlHelper.AdvanceEndElement("layer");

            map.AddLayer(layer);
        }