Skip to content

Commit

Permalink
Adding feature to replace tiles in blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
MainMemory committed Jun 6, 2016
1 parent c6baeed commit 061b55b
Show file tree
Hide file tree
Showing 11 changed files with 840 additions and 19 deletions.
32 changes: 22 additions & 10 deletions SonLVL/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 52 additions & 2 deletions SonLVL/MainForm.cs
Expand Up @@ -110,6 +110,7 @@ void Application_ThreadException(object sender, System.Threading.ThreadException
ReplaceChunksDialog replaceFGChunksDialog;
ReplaceChunksDialog replaceBGChunksDialog;
ReplaceChunkBlocksDialog replaceChunkBlocksDialog;
ReplaceBlockTilesDialog replaceBlockTilesDialog;
List<LayoutSection> savedLayoutSections;
List<Bitmap> savedLayoutSectionImages;
int waterPalette;
Expand Down Expand Up @@ -305,6 +306,7 @@ private void MainForm_Load(object sender, EventArgs e)
replaceFGChunksDialog = new ReplaceChunksDialog();
replaceBGChunksDialog = new ReplaceChunksDialog();
replaceChunkBlocksDialog = new ReplaceChunkBlocksDialog();
replaceBlockTilesDialog = new ReplaceBlockTilesDialog();
if (Program.Arguments.Length > 0)
LoadINI(Program.Arguments[0]);
}
Expand Down Expand Up @@ -749,7 +751,7 @@ private void backgroundLevelLoader_RunWorkerCompleted(object sender, RunWorkerCo
BlockCount.Text = LevelData.Blocks.Count.ToString("X") + " / " + LevelData.GetBlockMax().ToString("X");
TileCount.Text = LevelData.Tiles.Count.ToString("X") + " / 800";
deleteUnusedTilesToolStripButton.Enabled = deleteUnusedBlocksToolStripButton.Enabled = deleteUnusedChunksToolStripButton.Enabled =
replaceBlocksToolStripButton.Enabled = replaceBackgroundToolStripButton.Enabled = replaceForegroundToolStripButton.Enabled =
replaceBlockTilesToolStripButton.Enabled = replaceChunkBlocksToolStripButton.Enabled = replaceBackgroundToolStripButton.Enabled = replaceForegroundToolStripButton.Enabled =
clearBackgroundToolStripButton.Enabled = clearForegroundToolStripButton.Enabled = usageCountsToolStripMenuItem.Enabled = true;
#if !DEBUG
loadingAnimation1.Hide();
Expand Down Expand Up @@ -8851,7 +8853,7 @@ private void replaceBackgroundToolStripButton_Click(object sender, EventArgs e)
}
}

private void replaceBlocksToolStripButton_Click(object sender, EventArgs e)
private void replaceChunkBlocksToolStripButton_Click(object sender, EventArgs e)
{
if (replaceChunkBlocksDialog.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{
Expand Down Expand Up @@ -8894,6 +8896,54 @@ private void replaceBlocksToolStripButton_Click(object sender, EventArgs e)
ChunkSelector.Invalidate();
DrawChunkPicture();
chunkBlockEditor.SelectedObjects = chunkBlockEditor.SelectedObjects;
MessageBox.Show(this, "Replaced " + list.Count + " chunk blocks.", "SonLVL");
}
}

private void replaceBlockTilesToolStripButton_Click(object sender, EventArgs e)
{
if (replaceBlockTilesDialog.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{
var list = LevelData.Blocks.SelectMany((a, b) => a.Tiles.OfType<PatternIndex>().Select(c => new KeyValuePair<int, PatternIndex>(b, c))).ToList();
ushort? tile = replaceBlockTilesDialog.findTile.Tile;
if (tile.HasValue)
list = list.Where(a => a.Value.Tile == tile.Value).ToList();
bool? xflip = replaceBlockTilesDialog.findTile.XFlip;
if (xflip.HasValue)
list = list.Where(a => a.Value.XFlip == xflip.Value).ToList();
bool? yflip = replaceBlockTilesDialog.findTile.YFlip;
if (yflip.HasValue)
list = list.Where(a => a.Value.YFlip = yflip.Value).ToList();
bool? priority = replaceBlockTilesDialog.findTile.Priority;
if (priority.HasValue)
list = list.Where(a => a.Value.Priority == priority.Value).ToList();
byte? palette = replaceBlockTilesDialog.findTile.Palette;
if (palette.HasValue)
list = list.Where(a => a.Value.Palette == palette.Value).ToList();
tile = replaceBlockTilesDialog.replaceTile.Tile;
xflip = replaceBlockTilesDialog.replaceTile.XFlip;
yflip = replaceBlockTilesDialog.replaceTile.YFlip;
priority = replaceBlockTilesDialog.replaceTile.Priority;
palette = replaceBlockTilesDialog.replaceTile.Palette;
foreach (PatternIndex blk in list.Select(a => a.Value))
{
if (tile.HasValue)
blk.Tile = tile.Value;
if (xflip.HasValue)
blk.XFlip = xflip.Value;
if (yflip.HasValue)
blk.YFlip = yflip.Value;
if (priority.HasValue)
blk.Priority = priority.Value;
if (palette.HasValue)
blk.Palette = palette.Value;
}
foreach (int i in list.Select(a => a.Key).Distinct())
LevelData.RedrawBlock(i, true);
BlockSelector.Invalidate();
DrawBlockPicture();
blockTileEditor.SelectedObjects = blockTileEditor.SelectedObjects;
MessageBox.Show(this, "Replaced " + list.Count + " block tiles.", "SonLVL");
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions SonLVL/MainForm.resx
Expand Up @@ -169,12 +169,6 @@
<metadata name="blockListToolStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>287, 95</value>
</metadata>
<metadata name="blockListToolStrip.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="blockListToolStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>287, 95</value>
</metadata>
<data name="remapBlocksButton.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
Expand Down
4 changes: 3 additions & 1 deletion SonLVL/PatternIndexEditor.cs
Expand Up @@ -169,7 +169,9 @@ private void tile_ValueChanged(object sender, EventArgs e)
item.Tile = (ushort)tile.Value;
PropertyValueChanged(tile, EventArgs.Empty);
initializing = true;
if (LevelData.Level.TwoPlayerCompatible)
if (tile.Value >= LevelData.Tiles.Count)
tileList.SelectedIndex = -1;
else if (LevelData.Level.TwoPlayerCompatible)
tileList.SelectedIndex = (int)tile.Value / 2;
else
tileList.SelectedIndex = (int)tile.Value;
Expand Down
183 changes: 183 additions & 0 deletions SonLVL/PatternIndexSearchControl.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 061b55b

Please sign in to comment.