using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO; using OpenRa.FileFormats; namespace ShpViewer { public partial class ShpViewForm : Form { List bitmaps = new List(); public ShpViewForm( string filename ) { InitializeComponent(); string ext = Path.GetExtension( filename ).ToLowerInvariant(); if( ext == ".shp" ) { ShpReader shpReader = new ShpReader( File.OpenRead( filename ) ); Palette pal = new Palette( File.OpenRead( "../../../temperat.pal" ) ); foreach( ImageHeader h in shpReader ) bitmaps.Add( BitmapBuilder.FromBytes( h.Image, shpReader.Width, shpReader.Height, pal ) ); } else if( ext == ".tem" || ext == ".sno" || ext == ".int" ) { Palette pal = new Palette( File.OpenRead( "../../../temperat.pal" ) ); switch( ext ) { case ".sno": pal = new Palette( File.OpenRead( "../../../snow.pal" ) ); break; case ".int": pal = new Palette( File.OpenRead( "../../../interior.pal" ) ); break; } Terrain t = new Terrain( File.OpenRead( filename ), pal ); Bitmap bigTile = new Bitmap( 24 * t.XDim, 24 * t.YDim ); using( Graphics g = Graphics.FromImage( bigTile ) ) { for( int x = 0 ; x < t.XDim ; x++ ) for( int y = 0 ; y < t.YDim ; y++ ) g.DrawImageUnscaled( t.GetTile( x + y * t.XDim ) ?? new Bitmap( 24, 24 ), x * 24, y * 24 ); } bitmaps.Add( bigTile ); } else if( ext == ".ini" || ext == ".mpr" ) { IniFile iniFile = new IniFile( File.OpenRead( filename ) ); Map map = new Map( iniFile ); TileSet tileSet = LoadTileSet( map ); flowLayoutPanel1.Visible = false; flowLayoutPanel1.BackColor = Color.Blue; mapViewControl1.Visible = true; mapViewControl1.Map = map; mapViewControl1.TileSet = tileSet; mapViewControl1.Invalidate(); mapViewControl1.MouseClick += delegate( object sender, MouseEventArgs e ) { if( e.Button == MouseButtons.Left ) { mapViewControl1.Map = new Map( iniFile ); mapViewControl1.TileSet = LoadTileSet( map ); } else if( e.Button == MouseButtons.Middle ) { int dx = ( e.X * 2 - mapViewControl1.Width ) / 24; int dy = ( e.Y * 2 - mapViewControl1.Height ) / 24; mapViewControl1.XScroll += dx; mapViewControl1.YScroll += dy; } mapViewControl1.Invalidate(); }; } foreach (Bitmap b in bitmaps) { PictureBox p = new PictureBox(); p.Image = b; p.Size = b.Size; flowLayoutPanel1.Controls.Add(p); } Focus(); BringToFront(); } TileSet LoadTileSet( Map currentMap ) { Palette pal; switch( currentMap.Theater.ToLowerInvariant() ) { case "temperate": pal = new Palette( File.OpenRead( "../../../temperat.pal" ) ); return new TileSet( new Package( "../../../temperat.mix" ), ".tem", pal ); case "snow": pal = new Palette( File.OpenRead( "../../../snow.pal" ) ); return new TileSet( new Package( "../../../snow.mix" ), ".sno", pal ); case "interior": pal = new Palette( File.OpenRead( "../../../interior.pal" ) ); return new TileSet( new Package( "../../../interior.mix" ), ".int", pal ); } throw new NotImplementedException(); } } }