git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1102 993157c7-ee19-0410-b2c4-bb4e9862e678

This commit is contained in:
bob
2007-07-05 11:38:48 +00:00
parent 6a188a1091
commit 866b45d3a7
5 changed files with 102 additions and 26 deletions

View File

@@ -63,7 +63,7 @@ namespace OpenRa.FileFormats
}
}
public class IniSection
public class IniSection : IEnumerable<KeyValuePair<string, string>>
{
string name;
Dictionary<string, string> values = new Dictionary<string, string>();
@@ -83,5 +83,15 @@ namespace OpenRa.FileFormats
string s;
return values.TryGetValue( key, out s ) ? s : defaultValue;
}
public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
{
return values.GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}

View File

@@ -17,6 +17,7 @@ namespace OpenRa.FileFormats
public readonly int Height;
public readonly TileReference[ , ] MapTiles = new TileReference[ 128, 128 ];
public readonly List<TreeReference> Trees = new List<TreeReference>();
public Map( IniFile file )
{
@@ -35,6 +36,8 @@ namespace OpenRa.FileFormats
MemoryStream ms = ReadMapPack( file );
UnpackTileData( ms );
ReadTrees( file );
}
static MemoryStream ReadMapPack( IniFile file )
@@ -104,6 +107,16 @@ namespace OpenRa.FileFormats
for( int j = 0 ; j < 128 ; j++ )
MapTiles[ j, i ].image = ReadByte( ms );
}
void ReadTrees( IniFile file )
{
IniSection terrain = file.GetSection( "TERRAIN" );
foreach( KeyValuePair<string, string> kv in terrain )
{
int xy = int.Parse( kv.Key );
Trees.Add( new TreeReference( xy % 128, xy / 128, kv.Value ) );
}
}
}
public struct TileReference
@@ -111,4 +124,18 @@ namespace OpenRa.FileFormats
public ushort tile;
public byte image;
}
public struct TreeReference
{
public readonly int X;
public readonly int Y;
public readonly string Image;
public TreeReference( int x, int y, string image )
{
X = x;
Y = y;
Image = image;
}
}
}

View File

@@ -9,9 +9,11 @@ namespace OpenRa.FileFormats
public class TileSet
{
public readonly Dictionary<ushort, Terrain> tiles = new Dictionary<ushort, Terrain>();
public readonly Package MixFile;
public TileSet( Package mixFile, string suffix, Palette pal )
{
MixFile = mixFile;
StreamReader tileIdFile = File.OpenText( "../../../tileSet.til" );
while( true )

View File

@@ -4,6 +4,7 @@ using System.Text;
using System.Windows.Forms;
using OpenRa.FileFormats;
using System.Drawing;
using System.IO;
namespace ShpViewer
{
@@ -11,8 +12,22 @@ namespace ShpViewer
{
public int XScroll, YScroll;
public Map Map;
public TileSet TileSet;
Map map;
public Map Map
{
get { return map; }
set
{
map = value;
TileSet = LoadTileSet( Map );
}
}
Palette pal;
TileSet TileSet;
Package TileMix;
string TileSuffix;
Dictionary<string, Bitmap> TreeCache = new Dictionary<string, Bitmap>();
public MapViewControl()
{
@@ -62,6 +77,50 @@ namespace ShpViewer
}
}
}
foreach( TreeReference tr in Map.Trees )
{
int tX = tr.X - Map.XOffset - XScroll;
int tY = tr.Y - Map.YOffset - YScroll;
g.DrawImage( GetTree( tr.Image, TileMix ), tX * 24, tY * 24 );
}
}
Bitmap GetTree( string name, Package mix )
{
Bitmap ret;
if( !TreeCache.TryGetValue( name, out ret ) )
{
ShpReader shp = new ShpReader( TileSet.MixFile.GetContent( name + TileSuffix ) );
ret = BitmapBuilder.FromBytes( shp[ 0 ].Image, shp.Width, shp.Height, pal ); ;
TreeCache.Add( name, ret );
}
return ret;
}
TileSet LoadTileSet( Map currentMap )
{
switch( currentMap.Theater.ToLowerInvariant() )
{
case "temperate":
pal = new Palette( File.OpenRead( "../../../temperat.pal" ) );
TileMix = new Package( "../../../temperat.mix" );
TileSuffix = ".tem";
break;
case "snow":
pal = new Palette( File.OpenRead( "../../../snow.pal" ) );
TileMix = new Package( "../../../snow.mix" );
TileSuffix = ".sno";
break;
case "interior":
pal = new Palette( File.OpenRead( "../../../interior.pal" ) );
TileMix = new Package( "../../../interior.mix" );
TileSuffix = ".int";
break;
default:
throw new NotImplementedException();
}
return new TileSet( TileMix, TileSuffix, pal );
}
}
}

View File

@@ -57,13 +57,11 @@ namespace ShpViewer
{
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();
int ux = 0, uy = 0;
@@ -104,9 +102,8 @@ namespace ShpViewer
if( e.Button == MouseButtons.Left )
{
mapViewControl1.Map = new Map( iniFile );
mapViewControl1.TileSet = LoadTileSet( map );
mapViewControl1.Invalidate();
}
mapViewControl1.Invalidate();
};
}
@@ -121,24 +118,5 @@ namespace ShpViewer
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();
}
}
}