예제 #1
0
 public TileSheetDeleteCommand(Map map, TileSheet tileSheet, MapTreeView mapTreeView)
 {
     m_map = map;
     m_tileSheet = tileSheet;
     m_mapTreeView = mapTreeView;
     m_description = "Delete tile sheet \"" + tileSheet.Id + "\"";
 }
예제 #2
0
 public TileSheetNewCommand(Map map, TileSheet newTileSheet, MapTreeView mapTreeView)
 {
     m_map = map;
     m_newTileSheet = newTileSheet;
     m_mapTreeView = mapTreeView;
     m_description = "Add new tile sheet \"" + newTileSheet.Id + "\"";
 }
예제 #3
0
        public void Refresh(TileSheet tileSheet)
        {
            // clear only autotiles bound to the givne tile sheet
            for (int index = 0; index < m_autoTiles.Count; )
            {
                if (m_autoTiles[index].TileSheet == tileSheet)
                    m_autoTiles.RemoveAt(index);
                else
                    ++index;
            }

            foreach (string propertyKey in tileSheet.Properties.Keys)
            {
                if (!propertyKey.StartsWith("@AutoTile@"))
                    continue;
                string[] tokens
                    = propertyKey.Split(new char[] { '@' }, StringSplitOptions.RemoveEmptyEntries);
                if (tokens.Length != 2)
                    return;
                string autoTileId = tokens[1];
                string autoTileSet = tileSheet.Properties[propertyKey];
                RefreshSet(autoTileId, tileSheet, autoTileSet);
            }

            SortAutoTiles();
        }
예제 #4
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;
        }
예제 #5
0
        public AutoTileDialog(TileSheet tileSheet)
        {
            InitializeComponent();

            m_tileSheet = tileSheet;
            m_draggedTileIndex = -1;
        }
예제 #6
0
        public TileSheetPropertiesDialog(TileSheet tileSheet, bool isNewTileSheet, MapTreeView mapTreeView)
        {
            InitializeComponent();

            m_tileSheet = tileSheet;
            m_isNewTileSheet = isNewTileSheet;
            m_mapTreeView = mapTreeView;
        }
예제 #7
0
 public ReadOnlyCollection<AutoTile> GetAutoTiles(TileSheet tileSheet)
 {
     List<AutoTile> autoTiles = new List<AutoTile>();
     foreach (AutoTile autoTile in m_autoTiles)
         if (autoTile.TileSheet == tileSheet)
             autoTiles.Add(autoTile);
     return autoTiles.AsReadOnly();
 }
예제 #8
0
        public TileSheetSwapTilesCommand(TileSheet tileSheet, int tileIndex1, int tileIndex2)
        {
            m_tileSheet = tileSheet;
            m_tileIndex1 = tileIndex1;
            m_tileIndex2 = tileIndex2;

            m_description = "Swap tile " + m_tileSheet.Id + ":" + m_tileIndex1 + " with tile " + m_tileSheet.Id + ":" + m_tileIndex2;
        }
예제 #9
0
파일: AutoTile.cs 프로젝트: dekk7/xEngine
 public AutoTile(string id, TileSheet tileSheet, int[] indexSet)
 {
     m_id = id;
     m_tileSheet = tileSheet;
     if (indexSet.Length != 16)
         throw new Exception("AutoTile index set must contain exactly 16 indices");
     m_indexSet = new int[16];
     indexSet.CopyTo(m_indexSet, 0);
 }
예제 #10
0
        public TileSheetAutoTilesCommand(
            TileSheet tileSheet,
            IEnumerable<AutoTile> autoTiles)
        {
            m_tileSheet = tileSheet;
            m_autoTiles = new List<AutoTile>(autoTiles);
            m_oldAutoTiles = new Dictionary<string, PropertyValue>();

            m_description = "Update auto tile definitions for tile sheet \"" + tileSheet.Id + "\"";
        }
예제 #11
0
        /*****************************
        ** P E T   A D O P T I O N **
        *****************************/

        /// <summary>Places the pet bed in Marnie's</summary>
        internal void PlacePetBed()
        {
            GameLocation marnies   = Game1.getLocationFromName("AnimalShop");
            TileSheet    tileSheet = new xTile.Tiles.TileSheet("PetBed", marnies.map, Earth.Helper.Content.GetActualAssetKey("assets/petbed.png"), new xTile.Dimensions.Size(1, 1), new xTile.Dimensions.Size(16, 15));

            marnies.map.AddTileSheet(tileSheet);
            Layer buildingLayer = marnies.map.GetLayer("Buildings");

            buildingLayer.Tiles[17, 15] = new StaticTile(buildingLayer, tileSheet, BlendMode.Alpha, 0);
            marnies.updateMap();
        }
예제 #12
0
파일: StaticTile.cs 프로젝트: dekk7/xEngine
        /// <summary>
        /// Constructs a static tile for the given layer, tile sheet, blend
        /// mode and tile index
        /// </summary>
        /// <param name="layer">Layer to assign the tile to</param>
        /// <param name="tileSheet">Tile sheet associated with the tile</param>
        /// <param name="blendMode">Tile blend mode</param>
        /// <param name="tileIndex">Index of the tile in the given tile sheet</param>
        public StaticTile(Layer layer, TileSheet tileSheet, BlendMode blendMode, int tileIndex)
            : base(layer)
        {
            if (!layer.Map.TileSheets.Contains(tileSheet))
                throw new Exception("The specified TileSheet is not in the parent map");

            m_blendMode = blendMode;

            m_tileSheet = tileSheet;

            if (tileIndex < 0 || tileIndex >= tileSheet.TileCount)
                throw new Exception("The specified Tile Index is out of range");

            m_tileIndex = tileIndex;
        }
예제 #13
0
        public void Refresh(TileSheet tileSheet)
        {
            try
            {
                System.Drawing.Bitmap tileSheetBitmap = null;

                // copy bitmap in memory, otherwise Clone() method forces
                // a reload of the image on every call!
                using (System.Drawing.Bitmap tileSheetBitmapDisk
                    = new System.Drawing.Bitmap(tileSheet.ImageSource))
                {
                    tileSheetBitmap = new System.Drawing.Bitmap(tileSheetBitmapDisk);
                }

                int tileCount = tileSheet.TileCount;
                System.Drawing.Bitmap[] tileBitmaps = new System.Drawing.Bitmap[tileCount];
                Size tileSize = tileSheet.TileSize;

                System.Drawing.Rectangle destRect
                    = new System.Drawing.Rectangle(0, 0, tileSize.Width, tileSize.Height);

                System.Drawing.Rectangle srcRect
                    = new System.Drawing.Rectangle(destRect.Location, destRect.Size);

                for (int tileIndex = 0; tileIndex < tileCount; tileIndex++)
                {
                    Rectangle tileRectangle = tileSheet.GetTileImageBounds(tileIndex);
                    srcRect.X = tileRectangle.Location.X;
                    srcRect.Y = tileRectangle.Location.Y;
                    srcRect.Width = tileRectangle.Size.Width;
                    srcRect.Height = tileRectangle.Size.Height;

                    System.Drawing.Bitmap tileBitmap = tileSheetBitmap.Clone(
                         srcRect, tileSheetBitmap.PixelFormat);

                    tileBitmaps[tileIndex] = tileBitmap;
                }

                m_bitmapCache[tileSheet] = tileBitmaps;
            }
            catch (Exception innerException)
            {
                Exception exception = new Exception(
                    "Unable to load tile sheet '" + tileSheet.Id + "' with image source '" + tileSheet.ImageSource + "'",
                    innerException);
                throw exception;
            }
        }
예제 #14
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 + "\"";
        }
예제 #15
0
        /// <summary>
        /// Constructs a static tile for the given layer, tile sheet, blend
        /// mode and tile index
        /// </summary>
        /// <param name="layer">Layer to assign the tile to</param>
        /// <param name="tileSheet">Tile sheet associated with the tile</param>
        /// <param name="blendMode">Tile blend mode</param>
        /// <param name="tileIndex">Index of the tile in the given tile sheet</param>
        public StaticTile(Layer layer, TileSheet tileSheet, BlendMode blendMode, int tileIndex)
            : base(layer)
        {
            if (!layer.Map.TileSheets.Contains(tileSheet))
            {
                throw new Exception("The specified TileSheet is not in the parent map");
            }

            m_blendMode = blendMode;

            m_tileSheet = tileSheet;

            if (tileIndex < 0 || tileIndex >= tileSheet.TileCount)
            {
                throw new Exception("The specified Tile Index is out of range");
            }

            m_tileIndex = tileIndex;
        }
        public TileSheetRemoveDependencyCommand(Map map, TileSheet tileSheet)
        {
            m_map = map;
            m_tileSheet = tileSheet;
            m_description = "Remove dependencies on tile sheet \"" + tileSheet.Id + "\"";

            m_tileSheetDependencies = new List<TileSheetDependency>();
            foreach (Layer layer in m_map.Layers)
            {
                Size layerSize = layer.LayerSize;
                Location location;
                for (location.Y = 0; location.Y < layerSize.Height; location.Y++)
                    for (location.X = 0; location.X < layerSize.Width; location.X++)
                    {
                        Tile tile = layer.Tiles[location];
                        if (tile != null && tile.DependsOnTileSheet(m_tileSheet))
                            m_tileSheetDependencies.Add(new TileSheetDependency(layer, location, tile));
                    }
            }
        }
예제 #17
0
 /// <summary>
 /// Tests if this tile depends on the given tile sheet
 /// </summary>
 /// <param name="tileSheet">Tile sheet to test</param>
 /// <returns>True if this tile depends on the sheet, False otherwise</returns>
 public override bool DependsOnTileSheet(TileSheet tileSheet)
 {
     return(m_tileSheet == tileSheet);
 }
예제 #18
0
파일: TilePicker.cs 프로젝트: dekk7/xEngine
        public void RefreshSelectedTileSheet()
        {
            m_lblIdxValue.Text = "";

            if (m_comboBoxTileSheets.SelectedIndex < 0)
                m_tileSheet = null;
            else
            {
                string tileSheetId = m_comboBoxTileSheets.SelectedItem.ToString();
                m_tileSheet = m_map.GetTileSheet(tileSheetId);
            }

            ResetMru();

            m_horizontalScrollBar.Visible = m_verticalScrollBar.Visible = false;
            m_horizontalScrollBar.Value = m_verticalScrollBar.Value = 0;
            UpdateInternalDimensions();
            m_tilePanel.Invalidate();

            /*
            // ensure tiles within 256 wide/high and preserve aspect ratio
            System.Drawing.Size tileSize = new System.Drawing.Size(
                m_tileSheet.TileWidth, m_tileSheet.TileHeight);
            int maxDimension = Math.Max(tileSize.Width, tileSize.Height);
            if (maxDimension > 256)
            {
                tileSize.Width = (tileSize.Width * 256) / maxDimension;
                tileSize.Height = (tileSize.Height * 256) / maxDimension;
            }*/
        }
예제 #19
0
 /// <summary>
 /// Tests if this tile depends on the given tile sheet
 /// </summary>
 /// <param name="tileSheet">tile sheet to test</param>
 /// <returns>True if the tile depends on the given tile sheet, False otherwise</returns>
 public abstract bool DependsOnTileSheet(TileSheet tileSheet);
예제 #20
0
 /// <summary>
 /// Constructs an accessor for the given tile sheet
 /// </summary>
 /// <param name="tileSheet">Tile sheet associated with the accessor</param>
 internal TileIndexPropertyAccessor(TileSheet tileSheet)
 {
     m_tileSheet = tileSheet;
 }
예제 #21
0
 public void Clear(TileSheet tileSheet)
 {
     m_bitmapCache.Remove(tileSheet);
 }
예제 #22
0
        private void OnTileDragEnter(object sender, DragEventArgs dragEventArgs)
        {
            dragEventArgs.Effect = DragDropEffects.Copy;

            m_draggedTileSheet = m_tilePicker.SelectedTileSheet;
            m_draggedTileIndex = m_tilePicker.SelectedTileIndex;

            Bitmap tileImage = TileImageCache.Instance.GetTileBitmap(
                m_draggedTileSheet, m_draggedTileIndex);

            IconInfo iconInfo = new IconInfo();
            GetIconInfo(tileImage.GetHicon(), ref iconInfo);
            iconInfo.HotSpotX = tileImage.Width / 2;
            iconInfo.HotSpotY = tileImage.Height / 2;
            iconInfo.Icon = false;

            Cursor = new Cursor(CreateIconIndirect(ref iconInfo));
        }
예제 #23
0
 internal TileIndexPropertyCollection(TileSheet tileSheet, int tileIndex)
 {
     m_tileSheet = tileSheet;
     m_tileIndex = tileIndex;
 }
예제 #24
0
        /// <summary>
        /// Frees the tile sheet resources
        /// </summary>
        /// <param name="tileSheet">Tile sheet to dispose</param>
        public void DisposeTileSheet(TileSheet tileSheet)
        {
            if (!m_tileSheetTextures.ContainsKey(tileSheet))
                return;

            m_tileSheetTextures.Remove(tileSheet);
        }
예제 #25
0
 /// <summary>
 /// Loads the given tile sheet. The image source is loaded from the
 /// content pipeline by stripping any extension from the image source
 /// and using the resulting path into the content pipeline
 /// </summary>
 /// <param name="tileSheet">Tile sheet to load</param>
 public void LoadTileSheet(TileSheet tileSheet)
 {
     try
     {
         Texture2D texture2D = m_contentManager.Load<Texture2D>(tileSheet.ImageSource);
         m_tileSheetTextures[tileSheet] = texture2D;
     }
     catch (Exception epd)
     {
         Console.WriteLine(epd.Message);
     }
 }
예제 #26
0
파일: TbinFormat.cs 프로젝트: dekk7/xEngine
 private StaticTile LoadStaticTile(Stream stream, Layer layer, TileSheet tileSheet)
 {
     int tileIndex = LoadInt32(stream);
     BlendMode blendMode = (BlendMode)stream.ReadByte();
     StaticTile staticTile = new StaticTile(layer, tileSheet, blendMode, tileIndex);
     LoadProperties(stream, staticTile);
     return staticTile;
 }
예제 #27
0
        private void OnTileDragDrop(object sender, DragEventArgs dragEventArgs)
        {
            if (m_draggedTileSheet.TileSize != m_layer.TileSize)
            {
                m_tileSizeMessageBox.Show();
                return;
            }

            AddTileFrame(m_draggedTileSheet, m_draggedTileIndex);
            m_draggedTileSheet = null;
            m_draggedTileIndex = -1;

            Cursor = Cursors.Default;
            MarkAsModified();
        }
예제 #28
0
파일: TbinFormat.cs 프로젝트: dekk7/xEngine
 private void LoadTileSheet(Stream stream, Map map)
 {
     string id = LoadString(stream);
     string description = LoadString(stream);
     string imageSource = LoadString(stream);
     Size sheetSize = LoadSize(stream);
     Size tileSize = LoadSize(stream);
     Size margin = LoadSize(stream);
     Size spacing = LoadSize(stream);
     TileSheet tileSheet = new TileSheet(id, map, imageSource, sheetSize, tileSize);
     tileSheet.Margin = margin;
     tileSheet.Spacing = spacing;
     LoadProperties(stream, tileSheet);
     map.AddTileSheet(tileSheet);
 }
예제 #29
0
 private void AddTileFrame(TileSheet tileSheet, int tileIndex)
 {
     StaticTile newTileFrame = new StaticTile(m_layer, tileSheet, BlendMode.Alpha, tileIndex);
     AddTileFrame(newTileFrame);
 }
예제 #30
0
파일: TbinFormat.cs 프로젝트: dekk7/xEngine
 private void StoreTileSheet(Stream stream, TileSheet tileSheet)
 {
     StoreString(stream, tileSheet.Id);
     StoreString(stream, tileSheet.Description);
     StoreString(stream, tileSheet.ImageSource);
     StoreSize(stream, tileSheet.SheetSize);
     StoreSize(stream, tileSheet.TileSize);
     StoreSize(stream, tileSheet.Margin);
     StoreSize(stream, tileSheet.Spacing);
     StoreProperties(stream, tileSheet);
 }
예제 #31
0
 public System.Drawing.Bitmap GetTileBitmap(TileSheet tileSheet, int tileIndex)
 {
     return m_bitmapCache[tileSheet][tileIndex];
 }
예제 #32
0
파일: MapPanel.cs 프로젝트: dekk7/xEngine
        private void PickTile()
        {
            if (m_selectedLayer == null)
                return;

            if (!m_selectedLayer.IsValidTileLocation(m_tileLayerLocation))
                return;

            Tile tile = m_selectedLayer.Tiles[m_tileLayerLocation];
            if (tile != null)
            {
                m_selectedTileSheet = tile.TileSheet;
                m_selectedTileIndex = tile.TileIndex;
            }

            if (TilePicked != null)
                TilePicked(new MapPanelEventArgs(tile, m_tileLayerLocation));

            this.EditTool = tile == null ? EditTool.Eraser : EditTool.SingleTile;
        }
예제 #33
0
        private void DisplayTileSheetStatistics(TileSheet tileSheet)
        {
            // tile sheet details
            m_textBoxStatistics.InsertImage(Properties.Resources.TileSheet);
            m_textBoxStatistics.SelectionFont = m_headerFont;
            m_textBoxStatistics.AppendText(" Tile Sheet ");
            m_textBoxStatistics.AppendText(tileSheet.Map.TileSheets.IndexOf(tileSheet).ToString());
            m_textBoxStatistics.AppendLine(" Details");
            m_textBoxStatistics.AppendLine();

            // set indentation
            m_textBoxStatistics.SelectionTabs = new int[] { 170 };

            // tile sheet id
            m_textBoxStatistics.SelectionFont = m_propertyNameFont;
            m_textBoxStatistics.AppendText("ID\t");

            m_textBoxStatistics.SelectionFont = m_propertyValueFont;
            m_textBoxStatistics.AppendLine(tileSheet.Id);

            // tile sheet description
            m_textBoxStatistics.SelectionFont = m_propertyNameFont;
            m_textBoxStatistics.AppendText("Description\t");

            m_textBoxStatistics.SelectionFont = m_propertyValueFont;
            m_textBoxStatistics.AppendLine(tileSheet.Description.Length == 0 ? "(no description)" : tileSheet.Description);

            // image source
            m_textBoxStatistics.SelectionFont = m_propertyNameFont;
            m_textBoxStatistics.AppendText("Image Source\t");

            m_textBoxStatistics.SelectionFont = m_propertyValueFont;
            m_textBoxStatistics.AppendLine(tileSheet.ImageSource);

            // sheet size
            m_textBoxStatistics.SelectionFont = m_propertyNameFont;
            m_textBoxStatistics.AppendText("Sheet Size\t");

            m_textBoxStatistics.SelectionFont = m_propertyValueFont;
            m_textBoxStatistics.AppendText(tileSheet.SheetSize.ToString());
            m_textBoxStatistics.AppendText(" (");
            m_textBoxStatistics.AppendText(tileSheet.TileCount.ToString());
            m_textBoxStatistics.AppendLine(") tiles");

            // tile size
            m_textBoxStatistics.SelectionFont = m_propertyNameFont;
            m_textBoxStatistics.AppendText("Tile Size\t");

            m_textBoxStatistics.SelectionFont = m_propertyValueFont;
            m_textBoxStatistics.AppendText(tileSheet.TileSize.ToString());
            m_textBoxStatistics.AppendLine(" pixels");

            // margin
            m_textBoxStatistics.SelectionFont = m_propertyNameFont;
            m_textBoxStatistics.AppendText("Left, Top Margin\t");

            m_textBoxStatistics.SelectionFont = m_propertyValueFont;
            m_textBoxStatistics.AppendText(tileSheet.Margin.ToString());
            m_textBoxStatistics.AppendLine(" pixels");

            // spacing
            m_textBoxStatistics.SelectionFont = m_propertyNameFont;
            m_textBoxStatistics.AppendText("Hor, Ver Spacing\t");

            m_textBoxStatistics.SelectionFont = m_propertyValueFont;
            m_textBoxStatistics.AppendText(tileSheet.Spacing.ToString());
            m_textBoxStatistics.AppendLine(" pixels");

            // custom properties
            m_textBoxStatistics.AppendLine();
            DisplayCustomProperties(tileSheet);

            // compute tile usage statistics per layer

            m_textBoxStatistics.AppendLine();
            m_textBoxStatistics.SelectionFont = m_propertyNameFont;
            m_textBoxStatistics.AppendLine("Tile Sheet Usage");
            m_textBoxStatistics.SelectionBullet = true;
            m_textBoxStatistics.SelectionTabs = new int[] { 400 };

            foreach (Layer layer in tileSheet.Map.Layers)
            {
                int totalTiles = layer.LayerSize.Area;

                int tileSheetTiles = 0;
                for (int tileY = 0; tileY < layer.LayerHeight; tileY++)
                    for (int tileX = 0; tileX < layer.LayerWidth; tileX++)
                    {
                        Tile tile = layer.Tiles[tileX, tileY];
                        if (tile != null && tile.TileSheet == tileSheet)
                            ++tileSheetTiles;
                    }

                m_textBoxStatistics.SelectionFont = m_propertyNameFont;
                m_textBoxStatistics.AppendText("Layer ");
                m_textBoxStatistics.AppendText(tileSheet.Map.Layers.IndexOf(layer).ToString());
                m_textBoxStatistics.AppendText("\t");

                m_textBoxStatistics.SelectionFont = m_propertyValueFont;
                m_textBoxStatistics.AppendText(tileSheetTiles.ToString());
                m_textBoxStatistics.AppendText(" (");
                m_textBoxStatistics.AppendText((Math.Round((tileSheetTiles * 100.0) / totalTiles)).ToString());
                m_textBoxStatistics.AppendLine("%)");
            }

            m_textBoxStatistics.SelectionBullet = false;

            m_textBoxStatistics.AppendLine();
        }
예제 #34
0
파일: MapPanel.cs 프로젝트: dekk7/xEngine
 public void DisposeTileSheet(TileSheet tileSheet)
 {
 }
예제 #35
0
        public Map Load(Stream stream)
        {
            ReadHeader(stream);

            MphdRecord mphdRecord = null;
            string[] authorLines = null;
            Color[] colourMap = null;
            BlockRecord[] blockRecords = null;
            AnimationRecord[] animationRecords = null;
            Image imageSource = null;
            short[][] layers = new short[8][];

            Dictionary<string, Chunk> chunks = MapChunks(stream);

            if (!chunks.ContainsKey("MPHD"))
                throw new Exception("Header chunk MPHD missing");
            Chunk mphdChunk = chunks["MPHD"];
            mphdRecord = ReadChunkMPHD(stream, mphdChunk);

            if (mphdRecord.BlockDepth == 8)
            {
                if (!chunks.ContainsKey("CMAP"))
                    throw new Exception("Colour map chuck CMAP is required for 8bit graphics blocks");
                Chunk cmapChunk = chunks["CMAP"];
                colourMap = ReadChunkCMAP(stream, cmapChunk);
            }

            if (chunks.ContainsKey("ATHR"))
                authorLines = ReadChunkATHR(stream, chunks["ATHR"]);

            if (!chunks.ContainsKey("BKDT"))
                throw new Exception("Block data chunk BKDT missing");
            Chunk bkdtChunk = chunks["BKDT"];
            blockRecords = ReadChunkBKDT(stream, bkdtChunk, mphdRecord);

            // optional ?
            if (chunks.ContainsKey("ANDT"))
            {
                Chunk andtChunk = chunks["ANDT"];
                animationRecords = ReadChunkANDT(stream, andtChunk, mphdRecord);
            }

            if (!chunks.ContainsKey("BGFX"))
                throw new Exception("Block graphics chunk BGFX missing");
            Chunk bgfxChunk = chunks["BGFX"];
            imageSource = ReadChunkBGFX(stream, bgfxChunk, mphdRecord, colourMap);

            if (!chunks.ContainsKey("BODY"))
                throw new Exception("Body chunk BODY missing");
            Chunk bodyChunk = chunks["BODY"];
            layers[0] = ReadChunkLayer(stream, bodyChunk, mphdRecord);

            // additional layers
            for (int layer = 1; layer <= 7; layer++)
            {
                string chunkId = "LYR" + layer;
                if (chunks.ContainsKey(chunkId))
                {
                    Chunk layerChuck = chunks[chunkId];
                    layers[layer] = ReadChunkLayer(stream, layerChuck, mphdRecord);
                }
            }

            // new map
            Map map = new Map();

            // attach ATHR lines as description
            if (authorLines != null)
            {
                StringBuilder stringBuilder = new StringBuilder();
                foreach (string authorLine in authorLines)
                    stringBuilder.AppendLine(authorLine);
                map.Description = stringBuilder.ToString();
            }

            // prompt user to save tilesheet image source
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.CheckPathExists = true;
            saveFileDialog.Filter = "Portable Network Geaphics (*.png)|*.png";
            saveFileDialog.OverwritePrompt = true;
            saveFileDialog.Title = "Save tile sheet image source as";
            saveFileDialog.ValidateNames = true;
            if (saveFileDialog.ShowDialog() == DialogResult.Cancel)
                throw new Exception("Mappy FMAP file import aborted");

            string tileSheetImageSource = saveFileDialog.FileName;

            imageSource.Save(tileSheetImageSource, ImageFormat.Png);

            // determine global tile size
            xTile.Dimensions.Size tileSize = new xTile.Dimensions.Size(mphdRecord.BlockWidth, mphdRecord.BlockHeight);

            // add tilesheet
            TileSheet tileSheet = new TileSheet("BGFX", map, tileSheetImageSource,
                new xTile.Dimensions.Size(1, mphdRecord.NumBlockGfx), tileSize);
            map.AddTileSheet(tileSheet);

            // determine global map size
            xTile.Dimensions.Size mapSize = new xTile.Dimensions.Size(mphdRecord.MapWidth, mphdRecord.MapHeight);

            // create layers
            for (int layerIndex = 0; layerIndex < 8; layerIndex++)
            {
                if (layers[layerIndex] == null)
                    continue;

                string layerId = layerIndex == 0 ? "BODY" : "LYR" + layerIndex;
                Layer layer = new Layer(layerId, map, mapSize, tileSize);
                map.AddLayer(layer);
                for (int tileY = 0; tileY < mapSize.Height; tileY++)
                {
                    for (int tileX = 0; tileX < mapSize.Width; tileX++)
                    {
                        int layerOffset = tileY * mapSize.Width + tileX;
                        int tileIndex = layers[layerIndex][layerOffset];
                        if (tileIndex >= 0)
                        {
                            layer.Tiles[tileX, tileY] = new StaticTile(layer, tileSheet, BlendMode.Alpha, tileIndex);
                        }
                        else
                        {
                            AnimationRecord animationRecord = animationRecords[-tileIndex - 1];
                            StaticTile[] tileFrames = new StaticTile[animationRecord.Frames.Length];

                            for (int frameIndex = 0; frameIndex < animationRecord.Frames.Length; frameIndex++)
                                tileFrames[frameIndex] = new StaticTile(layer, tileSheet, BlendMode.Alpha, animationRecord.Frames[frameIndex]);

                            // process loop types
                            switch (animationRecord.Type)
                            {
                                case 2: // LOOPR: loop backward
                                    Array.Reverse(tileFrames);
                                    break;
                                case 5: // PPFF -+
                                case 6: // PPRR  | - different states for ping-pong animation
                                case 7: // PPRF  | - treat all the same
                                case 8: // PPFR -+
                                    StaticTile[] pingPongFrames = new StaticTile[tileFrames.Length * 2 - 1];
                                    Array.Copy(tileFrames, pingPongFrames, tileFrames.Length);
                                    Array.Copy(tileFrames, 0, pingPongFrames, tileFrames.Length, tileFrames.Length - 1);
                                    Array.Reverse(pingPongFrames, tileFrames.Length, tileFrames.Length - 1);
                                    tileFrames = pingPongFrames;
                                    break;
                                default: // treat all other cases as LOOPF
                                    // 0 = NONE
                                    // 1 = LOOPF: loop forward
                                    // 3 = ONCE, 4 = ONCEH: one-off animations
                                    // 9 = ONCES: one-off animations
                                    break;
                            }

                            AnimatedTile animatedTile = new AnimatedTile(layer, tileFrames, (long)animationRecord.Delay * 20);
                            layer.Tiles[tileX, tileY] = animatedTile;
                        }
                    }
                }
            }

            return map;
        }
예제 #36
0
파일: MapPanel.cs 프로젝트: dekk7/xEngine
 public void LoadTileSheet(TileSheet tileSheet)
 {
     TileImageCache.Instance.Refresh(tileSheet);
 }