Exemple #1
0
        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;
        }
Exemple #2
0
        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listView1.SelectedIndices.Count == 0)
            {
                return;
            }

            if (loadedPalette.Length == 0)
            {
                MessageBox.Show("Please load a palette first... just because.");
                return;
            }

            int t = listView1.SelectedIndices[0]; //For shorter lines of code

            pictureBox2.Width  = sprites[t].dataWidth;
            pictureBox2.Height = sprites[t].height * sprites[t].subimages;
            pictureBox2.Image  = new Bitmap(pictureBox2.Width, pictureBox2.Height);

            Bitmap[] subimages    = new Bitmap[0];
            byte[]   outputBuffer = new byte[0];

            int res = ChaosImage.decompressSpriteStage1(sprites[t], ref outputBuffer, loadedPalette, ref subimages);

            /* I used to have various code like this for outputting the data as hex to RichTextBoxes.
             *  if (textOutput == 2)
             *  {
             *      int selectionStart = rtbOutput.TextLength;
             *      rtbOutput.AppendText(outputBuffer2[outputOffset2 - 1].ToString("X2") + (outputColumn == 15 ? "\r\n" : (outputColumn == 7 ? "  " : " ")));
             *      outputColumn = (outputColumn + 1) & 15; //Increment but keep between 0 and 7
             *      rtbOutput.Select(selectionStart, rtbOutput.TextLength - selectionStart);
             *      rtbOutput.SelectionColor = Color.White; //Literals (including anything that came from references in the previous pass) are white
             *
             *      ScrollToBottom(rtbInput);
             *      ScrollToBottom(rtbOutput);
             *  }
             */
            res = ChaosImage.decompressSpriteStage2(sprites[t], outputBuffer, loadedPalette, ref subimages);

            //Draw all the subimages, however many there are.
            Graphics g = pictureBox2.CreateGraphics();

            for (int x = 0; x < sprites[t].subimages; x++)
            {
                g.DrawImageUnscaledAndClipped(subimages[x], new Rectangle(0, sprites[t].height * x, subimages[0].Width, subimages[0].Height));
            }
            g.Dispose();
            //pictureBox2.Refresh();
            //Can't do this anymore: ((Bitmap)pictureBox2.Image).Save("data/testOutput/" + listView1.SelectedItems[0].Text + ".png", System.Drawing.Imaging.ImageFormat.Png);
            //But you can totally save the frames from subimages[] if you want.

            //File.WriteAllBytes("data/testOutput/" + listView1.SelectedItems[0].Text + ".bin", outputBuffer2);
        }