private void switchMaps(int newSelection) { Cursor.Current = Cursors.WaitCursor; Application.DoEvents(); //Load the palette int res = ChaosImage.loadPalette(Path.Combine(Path.GetDirectoryName(openMaps[newSelection].mapName), openMaps[newSelection].paletteName), ref activePalette); if (res != 0) { MessageBox.Show("The map's chosen palette could not be loaded."); } //Load the tileset ChaosImage.Sprite tempSprite = new ChaosImage.Sprite(); byte[] outputBuffer = new byte[0]; if (openMaps[newSelection].backgroundTileset != "") { res = ChaosImage.loadSprite(Path.Combine(Path.GetDirectoryName(openMaps[newSelection].mapName), openMaps[newSelection].backgroundTileset), ref tempSprite); if (res != 0) { MessageBox.Show("The map's tileset could not be loaded."); } res = ChaosImage.decompressSpriteStage1(tempSprite, ref outputBuffer, activePalette, ref activeTileset); if (res != 0) { MessageBox.Show("The map's tileset could not be decompressed (stage 1)."); } //I don't think any of the tilesets have a stage 2 decompression, but I'll leave this here anyway. Can't hurt. res = ChaosImage.decompressSpriteStage2(tempSprite, outputBuffer, activePalette, ref activeTileset); if (res != 0) { MessageBox.Show("The map's tileset could not be decompressed (stage 2)."); } } //Load the background if (!openMaps[newSelection].useTileset && openMaps[newSelection].background != "") { res = ChaosImage.loadSprite(Path.Combine(Path.GetDirectoryName(openMaps[newSelection].mapName), openMaps[newSelection].background), ref tempSprite); if (res != 0) { MessageBox.Show("The map's background could not be loaded."); } res = ChaosImage.decompressSpriteStage1(tempSprite, ref outputBuffer, activePalette, ref activeBackground); if (res != 0) { MessageBox.Show("The map's background could not be decompressed (stage 1)."); } res = ChaosImage.decompressSpriteStage2(tempSprite, outputBuffer, activePalette, ref activeBackground); if (res != 0) { MessageBox.Show("The map's background could not be decompressed (stage 2)."); } } cm = newSelection; //Update the loaded map index picPalette.Refresh(); picMap.Refresh(); Cursor.Current = Cursors.Default; }
private void button1_Click(object sender, EventArgs e) { openFileDialog1.FileName = "*.SPR"; openFileDialog1.Filter = "SPR files|*.spr|All files|*.*"; DialogResult dres = openFileDialog1.ShowDialog(); //byte[][] wholeFile; if (dres == DialogResult.OK) { string[] allFiles = Directory.GetFiles(Path.GetDirectoryName(openFileDialog1.FileName), "*.SPR", SearchOption.TopDirectoryOnly); //wholeFile = new byte[allFiles.Length][]; sprites = new ChaosImage.Sprite[allFiles.Length]; //Load all the SPR files in that directory for (int x = 0; x < allFiles.Length; x++) { int res = ChaosImage.loadSprite(allFiles[x], ref sprites[x]); if (res == 1) { //Report invalid sprite file based on my silly assumptions System.Diagnostics.Debugger.Break(); listView1.Items.Add(new ListViewItem(new string[] { allFiles[x], sprites[x].fType.ToString("X"), "NOT", "A", "SPR" })); } else if (res == 0) { //Everything's fiiine listView1.Items.Add(new ListViewItem(new string[] { Path.GetFileNameWithoutExtension(allFiles[x]), sprites[x].fType.ToString("X"), sprites[x].width.ToString(), sprites[x].height.ToString(), sprites[x].subimages.ToString() })); } else { listView1.Items.Add(new ListViewItem(new string[] { allFiles[x], sprites[x].fType.ToString("X"), "UNKNOWN", "ERROR", "" })); } } if (false) { //For debug use only! Outputs *all* the sprites (though for some reason, you have to click in the ListView for it to activate). for (int x = 0; x < listView1.Items.Count; x++) { listView1.Items[x].Selected = true; Application.DoEvents(); listView1.Items[x].Selected = false; } } } }