Skip to content

Commit

Permalink
Adding advanced remapping dialog for chunks, blocks and tiles.
Browse files Browse the repository at this point in the history
  • Loading branch information
MainMemory committed Feb 3, 2015
1 parent 41490fe commit 74197be
Show file tree
Hide file tree
Showing 8 changed files with 872 additions and 61 deletions.
250 changes: 191 additions & 59 deletions SonLVL/MainForm.Designer.cs

Large diffs are not rendered by default.

119 changes: 119 additions & 0 deletions SonLVL/MainForm.cs
Expand Up @@ -514,6 +514,7 @@ private void backgroundLevelLoader_RunWorkerCompleted(object sender, RunWorkerCo
ChunkSelector.SelectedIndex = 0;
ChunkPicture.Size = new Size(LevelData.chunksz, LevelData.chunksz);
flipChunkHButton.Enabled = flipChunkVButton.Enabled = true;
remapChunksButton.Enabled = remapBlocksButton.Enabled = remapTilesButton.Enabled = true;
BlockSelector.SelectedIndex = 0;
TileSelector.Images.Clear();
for (int i = 0; i < LevelData.Tiles.Count; i++)
Expand Down Expand Up @@ -6457,6 +6458,124 @@ private void TileSelector_DragDrop(object sender, DragEventArgs e)
}
}
}

private void remapChunksButton_Click(object sender, EventArgs e)
{
using (TileRemappingDialog dlg = new TileRemappingDialog("Chunks", LevelData.CompChunkBmps, ChunkSelector.ImageSize))
if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{
List<Chunk> oldchunks = LevelData.Chunks.ToList();
List<BitmapBits[]> oldchunkbmpbits = new List<BitmapBits[]>(LevelData.ChunkBmpBits);
List<Bitmap[]> oldchunkbmps = new List<Bitmap[]>(LevelData.ChunkBmps);
List<BitmapBits[]> oldchunkcolbmpbits = new List<BitmapBits[]>(LevelData.ChunkColBmpBits);
List<Bitmap[]> oldchunkcolbmps = new List<Bitmap[]>(LevelData.ChunkColBmps);
List<BitmapBits> oldcompchunkbmpbits = new List<BitmapBits>(LevelData.CompChunkBmpBits);
List<Bitmap> oldcompchunkbmps = new List<Bitmap>(LevelData.CompChunkBmps);
Dictionary<byte, byte> bytedict = new Dictionary<byte, byte>(dlg.TileMap.Count);
foreach (KeyValuePair<int, int> item in dlg.TileMap)
{
LevelData.Chunks[item.Value] = oldchunks[item.Key];
LevelData.ChunkBmpBits[item.Value] = oldchunkbmpbits[item.Key];
LevelData.ChunkBmps[item.Value] = oldchunkbmps[item.Key];
LevelData.ChunkColBmpBits[item.Value] = oldchunkcolbmpbits[item.Key];
LevelData.ChunkColBmps[item.Value] = oldchunkcolbmps[item.Key];
LevelData.CompChunkBmpBits[item.Value] = oldcompchunkbmpbits[item.Key];
LevelData.CompChunkBmps[item.Value] = oldcompchunkbmps[item.Key];
bytedict.Add((byte)item.Key, (byte)item.Value);
}
for (int y = 0; y < LevelData.FGHeight; y++)
for (int x = 0; x < LevelData.FGWidth; x++)
if (bytedict.ContainsKey(LevelData.Layout.FGLayout[x, y]))
LevelData.Layout.FGLayout[x, y] = bytedict[LevelData.Layout.FGLayout[x, y]];
for (int y = 0; y < LevelData.BGHeight; y++)
for (int x = 0; x < LevelData.BGWidth; x++)
if (bytedict.ContainsKey(LevelData.Layout.BGLayout[x, y]))
LevelData.Layout.BGLayout[x, y] = bytedict[LevelData.Layout.BGLayout[x, y]];
ChunkSelector.ChangeSize();
ChunkSelector_SelectedIndexChanged(this, EventArgs.Empty);
}
}

private void remapBlocksButton_Click(object sender, EventArgs e)
{
using (TileRemappingDialog dlg = new TileRemappingDialog("Blocks", LevelData.CompBlockBmps, BlockSelector.ImageSize))
if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{
List<Block> oldblocks = LevelData.Blocks.ToList();
List<BitmapBits[]> oldblockbmpbits = new List<BitmapBits[]>(LevelData.BlockBmpBits);
List<Bitmap[]> oldblockbmps = new List<Bitmap[]>(LevelData.BlockBmps);
List<BitmapBits> oldcompblockbmpbits = new List<BitmapBits>(LevelData.CompBlockBmpBits);
List<Bitmap> oldcompblockbmps = new List<Bitmap>(LevelData.CompBlockBmps);
List<byte> oldcolinds1 = null;
if (LevelData.ColInds1 != null)
oldcolinds1 = new List<byte>(LevelData.ColInds1);
List<byte> oldcolinds2 = null;
if (LevelData.ColInds2 != null && LevelData.ColInds2 != LevelData.ColInds1)
oldcolinds2 = new List<byte>(LevelData.ColInds2);
Dictionary<ushort, ushort> ushortdict = new Dictionary<ushort, ushort>(dlg.TileMap.Count);
foreach (KeyValuePair<int, int> item in dlg.TileMap)
{
LevelData.Blocks[item.Value] = oldblocks[item.Key];
LevelData.BlockBmpBits[item.Value] = oldblockbmpbits[item.Key];
LevelData.BlockBmps[item.Value] = oldblockbmps[item.Key];
LevelData.CompBlockBmpBits[item.Value] = oldcompblockbmpbits[item.Key];
LevelData.CompBlockBmps[item.Value] = oldcompblockbmps[item.Key];
if (oldcolinds1 != null)
LevelData.ColInds1[item.Value] = oldcolinds1[item.Key];
if (oldcolinds2 != null)
LevelData.ColInds2[item.Value] = oldcolinds2[item.Key];
ushortdict.Add((ushort)item.Key, (ushort)item.Value);
}
for (int c = 0; c < LevelData.Chunks.Count; c++)
{
bool redraw = false;
for (int y = 0; y < LevelData.chunksz / 16; y++)
for (int x = 0; x < LevelData.chunksz / 16; x++)
if (ushortdict.ContainsKey(LevelData.Chunks[c].Blocks[x, y].Block))
{
redraw = true;
LevelData.Chunks[c].Blocks[x, y].Block = ushortdict[LevelData.Chunks[c].Blocks[x, y].Block];
}
if (redraw)
LevelData.RedrawChunk(c);
}
BlockSelector.ChangeSize();
BlockSelector_SelectedIndexChanged(this, EventArgs.Empty);
}
}

private void remapTilesButton_Click(object sender, EventArgs e)
{
using (TileRemappingDialog dlg = new TileRemappingDialog("Tiles", TileSelector.Images, TileSelector.ImageSize))
if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{
List<byte[]> oldtiles = LevelData.Tiles.ToList();
List<Bitmap> oldimages = new List<Bitmap>(TileSelector.Images);
Dictionary<ushort, ushort> ushortdict = new Dictionary<ushort, ushort>(dlg.TileMap.Count);
foreach (KeyValuePair<int, int> item in dlg.TileMap)
{
LevelData.Tiles[item.Value] = oldtiles[item.Key];
TileSelector.Images[item.Value] = oldimages[item.Key];
ushortdict.Add((ushort)item.Key, (ushort)item.Value);
}
LevelData.UpdateTileArray();
for (int b = 0; b < LevelData.Blocks.Count; b++)
{
bool redraw = false;
for (int y = 0; y < 2; y++)
for (int x = 0; x < 2; x++)
if (ushortdict.ContainsKey(LevelData.Blocks[b].Tiles[x, y].Tile))
{
redraw = true;
LevelData.Blocks[b].Tiles[x, y].Tile = ushortdict[LevelData.Blocks[b].Tiles[x, y].Tile];
}
if (redraw)
LevelData.RedrawBlock(b, true);
}
TileSelector.ChangeSize();
TileSelector_SelectedIndexChanged(this, EventArgs.Empty);
}
}
}

internal enum EditingMode { Draw, Select }
Expand Down
74 changes: 73 additions & 1 deletion SonLVL/MainForm.resx
Expand Up @@ -135,6 +135,79 @@
<metadata name="toolStripSeparator10.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="toolStrip1.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>585, 56</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="remapChunksButton.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADrwAAA68AZW8ckkAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG
YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9
0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw
bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc
VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9
c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32
Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo
mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+
kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D
TgDQASA1MVpwzwAAAABJRU5ErkJggg==
</value>
</data>
<metadata name="panel1.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="panel2.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="toolStrip2.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="toolStrip2.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>690, 56</value>
</metadata>
<data name="remapBlocksButton.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADrwAAA68AZW8ckkAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG
YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9
0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw
bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc
VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9
c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32
Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo
mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+
kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D
TgDQASA1MVpwzwAAAABJRU5ErkJggg==
</value>
</data>
<metadata name="panel3.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="toolStrip3.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="toolStrip3.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>795, 56</value>
</metadata>
<data name="remapTilesButton.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADrwAAA68AZW8ckkAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG
YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9
0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw
bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc
VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9
c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32
Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo
mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+
kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D
TgDQASA1MVpwzwAAAABJRU5ErkJggg==
</value>
</data>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
Expand All @@ -150,7 +223,6 @@
<metadata name="objToolStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>467, 56</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="objGridSizeDropDownButton.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
Expand Down
9 changes: 9 additions & 0 deletions SonLVL/SonLVL.GUI.csproj
Expand Up @@ -169,6 +169,12 @@
<DependentUpon>AlternatePaletteDialog.cs</DependentUpon>
</Compile>
<Compile Include="Settings.cs" />
<Compile Include="TileRemappingDialog.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="TileRemappingDialog.Designer.cs">
<DependentUpon>TileRemappingDialog.cs</DependentUpon>
</Compile>
<EmbeddedResource Include="AddGroupDialog.resx">
<DependentUpon>AddGroupDialog.cs</DependentUpon>
</EmbeddedResource>
Expand Down Expand Up @@ -228,6 +234,9 @@
<EmbeddedResource Include="AlternatePaletteDialog.resx">
<DependentUpon>AlternatePaletteDialog.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="TileRemappingDialog.resx">
<DependentUpon>TileRemappingDialog.cs</DependentUpon>
</EmbeddedResource>
<None Include="app.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
Expand Down

0 comments on commit 74197be

Please sign in to comment.