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 button2_Click(object sender, EventArgs e) { openFileDialog1.FileName = "*.PAL"; openFileDialog1.Filter = "PAL files|*.pal|All files|*.*"; DialogResult dres = openFileDialog1.ShowDialog(); if (dres == DialogResult.OK) { int res = ChaosImage.loadPalette(openFileDialog1.FileName, ref loadedPalette); if (res == 1) { MessageBox.Show("Oh, you. That's not a Chaos Island PAL file, silly."); return; } else if (res == 2) { MessageBox.Show("The PAL file seems to be missing some data.."); return; } else if (res != 0) { MessageBox.Show("Unknown error in PAL file."); //Just in case I forget if I add any more error codes to that function. return; } //Draw it to a box Bitmap imfabulous = new Bitmap(16, 16); for (int x = 0; x < loadedPalette.Length && x < 256; x++) { imfabulous.SetPixel(x % 16, x >> 4, Color.FromArgb(loadedPalette[x])); } pictureBox1.Image = imfabulous; pictureBox1.Refresh(); } }