diff --git a/OpenRA.Editor/Form1.cs b/OpenRA.Editor/Form1.cs index 78df763411..cee9f96e0b 100644 --- a/OpenRA.Editor/Form1.cs +++ b/OpenRA.Editor/Form1.cs @@ -140,7 +140,16 @@ namespace OpenRA.Editor if (DialogResult.OK != rd.ShowDialog()) return; - surface1.Bind(surface1.Map, surface1.TileSet, surface1.Palette); // rebind it to invalidate all caches + surface1.Map.TopLeft = new int2((int)rd.cordonLeft.Value, (int)rd.cordonTop.Value); + surface1.Map.BottomRight = new int2((int)rd.cordonRight.Value, (int)rd.cordonBottom.Value); + + if ((int)rd.width.Value != surface1.Map.MapSize.X || (int)rd.height.Value != surface1.Map.MapSize.Y) + { + surface1.Map.Resize((int)rd.width.Value, (int)rd.height.Value); + surface1.Bind(surface1.Map, surface1.TileSet, surface1.Palette); // rebind it to invalidate all caches + } + + surface1.Invalidate(); } } } diff --git a/OpenRA.Editor/ResizeDialog.Designer.cs b/OpenRA.Editor/ResizeDialog.Designer.cs index d712881805..3b39cc685c 100644 --- a/OpenRA.Editor/ResizeDialog.Designer.cs +++ b/OpenRA.Editor/ResizeDialog.Designer.cs @@ -196,6 +196,7 @@ this.Controls.Add(this.width); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.Name = "ResizeDialog"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Resize Map"; ((System.ComponentModel.ISupportInitialize)(this.width)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.cordonLeft)).EndInit(); diff --git a/OpenRA.Editor/Surface.cs b/OpenRA.Editor/Surface.cs index 4ddbc13aa1..eee1abd48c 100644 --- a/OpenRA.Editor/Surface.cs +++ b/OpenRA.Editor/Surface.cs @@ -136,8 +136,8 @@ namespace OpenRA.Editor if (Map == null) return; if (TileSet == null) return; - for( var u = 0; u <= Map.BottomRight.X; u += ChunkSize ) - for (var v = 0; v <= Map.BottomRight.Y; v += ChunkSize) + for( var u = 0; u < Map.MapSize.X; u += ChunkSize ) + for (var v = 0; v < Map.MapSize.Y; v += ChunkSize) { var x = new int2(u/ChunkSize,v/ChunkSize); if (!Chunks.ContainsKey(x)) Chunks[x] = RenderChunk(u / ChunkSize, v / ChunkSize); diff --git a/OpenRA.FileFormats/Map/Map.cs b/OpenRA.FileFormats/Map/Map.cs index 4ede89ce57..50a99810da 100644 --- a/OpenRA.FileFormats/Map/Map.cs +++ b/OpenRA.FileFormats/Map/Map.cs @@ -261,5 +261,22 @@ namespace OpenRA.FileFormats foreach (var s in Smudges) Console.WriteLine("\t{0} {1} {2}", s.Type, s.Location, s.Depth); } + + static T[,] ResizeArray(T[,] ts, T t, int width, int height) + { + var result = new T[width, height]; + for (var i = 0; i < width; i++) + for (var j = 0; j < height; j++) + result[i, j] = i <= ts.GetUpperBound(0) && j <= ts.GetUpperBound(1) + ? ts[i, j] : t; + return result; + } + + public void Resize(int width, int height) // editor magic. + { + MapTiles = ResizeArray(MapTiles, MapTiles[0, 0], width, height); + MapResources = ResizeArray(MapResources, MapResources[0, 0], width, height); + MapSize = new int2(width, height); + } } }