public void DrawMap(Map aMap) { for (int k = 0; k < 5; k++) { for (int i = 0; i < aMap.WORLD_SIZE; i++) { for (int j = 0; j < aMap.WORLD_SIZE; j++) { MapElement _element = aMap.Elementes[aMap.WORLD_SIZE * j + i]; LevelNode.TileIndex[] _indexes = _element.pLevelNodes[k].tileIndexes; foreach (LevelNode.TileIndex _tileIndex in _indexes) { int _subIndex = _tileIndex.usTypeSubIndex - 1; if (aMap.MapTileSet.Length > _tileIndex.ubType) { StciIndexed _sti = aMap.MapTileSet[_tileIndex.ubType].Sti; if (_sti.Images.Length > _subIndex) { List <Color> _palette = _sti.ColorPalette .Select(x => new Color() { A = 255, R = x.Red, G = x.Green, B = x.Blue }) .ToList(); StciSubImage _subImage = _sti.Images[_subIndex]; StructureImage _image = new StructureImage(_subImage, _palette); int _x = (i - j) * StructureImage.TileWidth + _subImage.Header.OffsetX; int _y = (i + j) * StructureImage.TileHeight + _subImage.Header.OffsetY; if (k > 3) // крыша { _y -= 50; } Point point = new Point( _x + aMap.WORLD_SIZE * StructureImage.TileWidth / 2, _y - aMap.WORLD_SIZE * StructureImage.TileHeight / 2); Rect _rect = new Rect( point, new Size(_subImage.Header.Width, _subImage.Header.Height)); DrawingVisual _visual = new DrawingVisual(); using (DrawingContext _context = _visual.RenderOpen()) { _context.DrawImage(_image.Bitmap, _rect); } this.FVisuals[k] = _visual; base.AddVisualChild(_visual); base.AddLogicalChild(_visual); } } } } } } }
private void DrawLevel(Map aMap, int aLayerNumber, DrawingContext aContext, int aLevel) { for (int i = 0; i < aMap.WORLD_SIZE; i++) { for (int j = 0; j < aMap.WORLD_SIZE; j++) { MapElement _element = aMap.Elementes[aMap.WORLD_SIZE * j + i]; LevelNode.TileIndex[] _indexes = _element.pLevelNodes[aLayerNumber].tileIndexes; if (_indexes.Length > aLevel) { LevelNode.TileIndex _tileIndex = _indexes[aLevel]; int _subIndex = _tileIndex.usTypeSubIndex - 1; if (aMap.MapTileSet.Length > _tileIndex.ubType) { StciIndexed _sti = aMap.MapTileSet[_tileIndex.ubType].Sti; if (_sti != null && _sti.Images.Length > _subIndex) { List <Color> _palette = _sti.ColorPalette .Select(x => new Color() { A = 255, R = x.Red, G = x.Green, B = x.Blue }) .ToList(); StciSubImage _subImage = _sti.Images[_subIndex]; StructureImage _image = new StructureImage(_subImage, _palette); int _x = (i - j) * StructureImage.TileWidth / 2 + _subImage.Header.OffsetX; int _y = (i + j) * StructureImage.TileHeight / 2 + _subImage.Header.OffsetY; if (aLayerNumber > 3) // крыша { _y -= 50; } Point point = new Point( _x + aMap.WORLD_SIZE * StructureImage.TileWidth / 2, _y - aMap.WORLD_SIZE * StructureImage.TileHeight / 2); Rect _rect = new Rect( point, new Size(_subImage.Header.Width, _subImage.Header.Height)); aContext.DrawImage(_image.Bitmap, _rect); this.FDrewElementsCount++; this.FProgress.Progress = FDrewElementsCount * 100 / this.FTotalElementsCount; } } } } } }
private ImageSource GetGlobalMapImagefFromSti(string aFileName) { string _path = Path.Combine(this.FGlobalMapsFolder, aFileName); IStci _sti = null; if (File.Exists(_path)) { using (FileStream input = new FileStream(_path, FileMode.Open, FileAccess.Read)) _sti = StciLoader.LoadStci(input); } else { if (this.SlfFile != null) { SlfFile.Record _record = this.SlfFile.Records .SingleOrDefault(x => x.FileName.ToUpperInvariant() == aFileName.ToUpperInvariant()); if (_record != null) { using (MemoryStream input = new MemoryStream(_record.Data)) _sti = StciLoader.LoadStci(input); } } } if (_sti == null) { ImageSourceConverter _isc = new ImageSourceConverter(); ImageSource _is = (ImageSource)_isc.ConvertFromString("MAP_STUB.bmp"); return(_is); } else if (_sti is StciIndexed) { StciIndexed _stciIndexed = (StciIndexed)_sti; List <Color> _palette = _stciIndexed.ColorPalette .Select(x => new Color() { A = 255, R = x.Red, G = x.Green, B = x.Blue }) .ToList(); StciSubImage _subImage = _stciIndexed.Images[0]; StructureImage _image = new StructureImage(_subImage, _palette); BitmapPalette _pb = new BitmapPalette(_palette); PixelFormat _pf = PixelFormats.Indexed8; BitmapSource _bitmap = BitmapSource.Create( _subImage.Header.Width, _subImage.Header.Height, 96, 96, _pf, _pb, _subImage.ImageData, _subImage.Header.Width * _pf.BitsPerPixel / 8); return(_bitmap); } else if (_sti is StciRgb) { StciRgb _stciRgb = (StciRgb)_sti; PixelFormat _pf = PixelFormats.Bgr565; BitmapSource _bitmap = BitmapSource.Create( _stciRgb.Header.ImageWidth, _stciRgb.Header.ImageHeight, 96, 96, _pf, null, _stciRgb.ImageData, _stciRgb.Header.ImageWidth * _pf.BitsPerPixel / 8); return(_bitmap); } return(null); }
private DrawingVisual DrawMapLayerByTiles(Map aMap, int aLayerNumber) { DrawingVisual _visual = new DrawingVisual(); using (DrawingContext _context = _visual.RenderOpen()) { for (int i = 0; i < aMap.WORLD_SIZE; i++) { for (int j = 0; j < aMap.WORLD_SIZE; j++) { if (i + j > 3 * aMap.WORLD_SIZE / 2 || i + j < aMap.WORLD_SIZE / 2 || i - j > aMap.WORLD_SIZE / 2 || i - j < -aMap.WORLD_SIZE / 2) { continue; } MapElement _element = aMap.Elementes[aMap.WORLD_SIZE * j + i]; LevelNode.TileIndex[] _indexes = _element.pLevelNodes[aLayerNumber].tileIndexes; for (int _index = 0; _index < _indexes.Length; _index++) { if (_indexes.Length > _index) { LevelNode.TileIndex _tileIndex = _indexes[_index]; int _subIndex = _tileIndex.usTypeSubIndex - 1; if (aMap.MapTileSet.Length > _tileIndex.ubType) { StciIndexed _sti = aMap.MapTileSet[_tileIndex.ubType].Sti; if (_sti != null && _sti.Images.Length > _subIndex) { List <Color> _palette = _sti.ColorPalette .Select(z => new Color() { A = 255, R = z.Red, G = z.Green, B = z.Blue }) .ToList(); StciSubImage _subImage = _sti.Images[_subIndex]; StructureImage _image = new StructureImage(_subImage, _palette); int _x = (i - j) * StructureImage.TileWidth + _subImage.Header.OffsetX; int _y = (i + j) * StructureImage.TileHeight + _subImage.Header.OffsetY; // Надо поднимать всё кроме клифов. Как пока не понятно. //if (aLayerNumber == 1 && _element.sHeight > 0) //{ // int _heigthLevel = _element.sHeight % 256; // int _heigth = _element.sHeight / 256; // _y -= _heigthLevel + _heigth; //} if (aLayerNumber > 3) // крыша { _y -= 50; } Point point = new Point( _x + aMap.WORLD_SIZE * StructureImage.TileWidth / 2, _y - aMap.WORLD_SIZE * StructureImage.TileHeight / 2 ); Rect _rect = new Rect( point, new Size(_subImage.Header.Width, _subImage.Header.Height)); _context.DrawImage(_image.Bitmap, _rect); this.FDrewElementsCount++; this.FProgress.Progress = FDrewElementsCount * 100 / this.FTotalElementsCount; } } } } } } } return(_visual); }