- bugfix in Format80

- fixed heisenburg-endianness in map loader
    - THERES A BUG in the mix loading; I need another 4 bytes padding to load temperat.mix and snow.mix (not interior.mix, though)
    - ShpViewer can now load and view map files
    - Copy TEMPERAT, SNOW, INFERIOR (sic) mixes into $(SolutionDir) for this to work
    - Left-click to reload tile-ID file, middle-click scrolls
    - the tile-id file has some collisions between tile-sets, be careful about ordering if you change anything


git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1081 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
bob
2007-06-26 21:25:20 +00:00
parent f87448c958
commit 1438053505
15 changed files with 436 additions and 102 deletions

View File

@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using OpenRa.FileFormats;
using System.Drawing;
namespace ShpViewer
{
public class MapViewControl : Control
{
public int XScroll, YScroll;
public Map Map;
public TileSet TileSet;
public MapViewControl()
{
}
static Font font = new Font( FontFamily.GenericMonospace, 10 );
protected override void OnPaint( PaintEventArgs e )
{
base.OnPaint( e );
if( Map == null || TileSet == null )
return;
using( Graphics g = e.Graphics )
{
for( int x = 50 ; x >= 0 ; x-- )
{
int tX = x + Map.XOffset + XScroll;
if( tX < 1 || tX > 127 )
continue;
for( int y = 50 ; y >= 0 ; y-- )
{
int tY = y + Map.YOffset + YScroll;
if( tY < 1 || tY > 127 )
continue;
Terrain t;
if( TileSet.tiles.TryGetValue( Map.MapTiles[ tX, tY ].tile, out t ) )
{
Bitmap b = t.GetTile( Map.MapTiles[ tX, tY ].image );
if( b == null )
{
g.FillRectangle( Brushes.Blue, x * 24, y * 24, 24, 24 );
g.DrawString( string.Format( "{0:x}", Map.MapTiles[ tX, tY ].image ),
font, Brushes.White, x * 24, y * 24 );
}
else
g.DrawImage( b, x * 24, y * 24 );
}
else
{
g.FillRectangle( Brushes.Red, x * 24, y * 24, 24, 24 );
g.DrawString( string.Format( "{0:x}", Map.MapTiles[ tX, tY ].tile ),
font, Brushes.White, x * 24, y * 24 );
}
}
}
}
}
}
}

View File

@@ -19,7 +19,7 @@ namespace ShpViewer
try
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "SHP Files (*.shp)|*.shp|Terrain Files (*.tem; *.sno; *.int)|*.tem;*.sno;*.int|All Files (*.*)|*.*";
ofd.Filter = "SHP Files (*.shp)|*.shp|Terrain Files (*.tem; *.sno; *.int)|*.tem;*.sno;*.int|Map Files (*.ini;*.mpr)|*.ini;*.mpr|All Files (*.*)|*.*";
ofd.RestoreDirectory = true;
if( ofd.ShowDialog() == DialogResult.OK )
Application.Run( new ShpViewForm( ofd.FileName ) );

View File

@@ -8,64 +8,56 @@
// </auto-generated>
//------------------------------------------------------------------------------
namespace ShpViewer.Properties
{
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute( "System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0" )]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute( "Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode" )]
internal Resources()
{
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute( global::System.ComponentModel.EditorBrowsableState.Advanced )]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if( ( resourceMan == null ) )
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager( "ShpViewer.Properties.Resources", typeof( Resources ).Assembly );
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute( global::System.ComponentModel.EditorBrowsableState.Advanced )]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
}
namespace ShpViewer.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ShpViewer.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}

View File

@@ -8,23 +8,19 @@
// </auto-generated>
//------------------------------------------------------------------------------
namespace ShpViewer.Properties
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute( "Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "8.0.0.0" )]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
private static Settings defaultInstance = ( (Settings)( global::System.Configuration.ApplicationSettingsBase.Synchronized( new Settings() ) ) );
public static Settings Default
{
get
{
return defaultInstance;
}
}
}
namespace ShpViewer.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "8.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
}
}

View File

@@ -29,21 +29,38 @@ namespace ShpViewer
private void InitializeComponent()
{
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
this.mapViewControl1 = new ShpViewer.MapViewControl();
this.SuspendLayout();
//
// flowLayoutPanel1
//
this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.flowLayoutPanel1.Location = new System.Drawing.Point( 0, 0 );
this.flowLayoutPanel1.Anchor = ( (System.Windows.Forms.AnchorStyles)( ( ( ( System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom )
| System.Windows.Forms.AnchorStyles.Left )
| System.Windows.Forms.AnchorStyles.Right ) ) );
this.flowLayoutPanel1.Location = new System.Drawing.Point( 1, 1 );
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
this.flowLayoutPanel1.Size = new System.Drawing.Size( 292, 273 );
this.flowLayoutPanel1.TabIndex = 0;
//
// mapViewControl1
//
this.mapViewControl1.Anchor = ( (System.Windows.Forms.AnchorStyles)( ( ( ( System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom )
| System.Windows.Forms.AnchorStyles.Left )
| System.Windows.Forms.AnchorStyles.Right ) ) );
this.mapViewControl1.BackColor = System.Drawing.Color.Black;
this.mapViewControl1.Location = new System.Drawing.Point( 0, 0 );
this.mapViewControl1.Name = "mapViewControl1";
this.mapViewControl1.Size = new System.Drawing.Size( 293, 274 );
this.mapViewControl1.TabIndex = 1;
this.mapViewControl1.Text = "mapViewControl1";
this.mapViewControl1.Visible = false;
//
// ShpViewForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF( 6F, 13F );
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size( 292, 273 );
this.Controls.Add( this.mapViewControl1 );
this.Controls.Add( this.flowLayoutPanel1 );
this.Name = "ShpViewForm";
this.Text = "Form1";
@@ -54,6 +71,7 @@ namespace ShpViewer
#endregion
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
private MapViewControl mapViewControl1;
}
}

View File

@@ -19,7 +19,7 @@ namespace ShpViewer
{
InitializeComponent();
string ext = Path.GetExtension( filename );
string ext = Path.GetExtension( filename ).ToLowerInvariant();
if( ext == ".shp" )
{
ShpReader shpReader = new ShpReader( File.OpenRead( filename ) );
@@ -53,6 +53,37 @@ namespace ShpViewer
}
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)
{
@@ -65,5 +96,24 @@ 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();
}
}
}

View File

@@ -38,6 +38,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MapViewControl.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="ShpViewForm.cs">
<SubType>Form</SubType>
</Compile>
@@ -58,6 +61,7 @@
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>