private void PaletteComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            paletteComboBox.Text = paletteComboBox.SelectedItem.ToString();
            selectedPaletteIndex = paletteComboBox.SelectedIndex;
            if (loadedImages.Count > 0 && loadedImages[loadedImageIndex].data != null)
            {
                //Reload all the images using the new palette
                int index = 0;
                foreach (ShandalarAsset asset in loadedImages)
                {
                    switch (asset.imageType)
                    {
                    case ImageType.Pic:
                        asset.image = GetPic(asset.data, asset.filePath).image;
                        break;

                    case ImageType.Spr:
                        List <Bitmap> sprites = SprDecoder.GetSprites(loadedImages[loadedImageIndex].data, palettes[selectedPaletteIndex]);
                        asset.image = sprites[asset.childIndex];
                        break;
                    }
                    SetProgressBarValue((int)Math.Round(100f * ((float)index / (float)loadedImages.Count)));
                    index++;
                }
                SetProgressBarValue(0);

                ShowImage(loadedImages[loadedImageIndex].image);
            }
        }
        private void UseLastEmbeddedPaletteCheckbox_CheckedChanged(object sender, EventArgs e)
        {
            useLastEmbeddedPalette = useLastEmbeddedPaletteCheckbox.Checked;
            Color[] palette = useLastEmbeddedPalette ? lastEmbeddedPalette : palettes[selectedPaletteIndex];
            if (loadedImages.Count > 0 && loadedImages[loadedImageIndex].data != null)
            {
                //Reload all the images using the new palette
                int index = 0;
                foreach (ShandalarAsset asset in loadedImages)
                {
                    switch (asset.imageType)
                    {
                    case ImageType.Pic:
                        asset.image = GetPic(asset.data, asset.filename).image;
                        break;

                    case ImageType.Spr:
                        List <Bitmap> sprites = SprDecoder.GetSprites(loadedImages[loadedImageIndex].data, palette);
                        asset.image = sprites[asset.childIndex];
                        break;
                    }
                    SetProgressBarValue((int)Math.Round(100f * ((float)index / (float)loadedImages.Count)));
                    index++;
                }
                SetProgressBarValue(0);

                ShowImage(loadedImages[loadedImageIndex].image);
            }
        }
        private void LoadSprToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.DefaultExt = "spr";
            openFileDialog.Filter     = "Sprite Files|*.spr|All Files|*.*";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                exportToolStripMenuItem.Enabled = true;
                byte[] data = File.ReadAllBytes(openFileDialog.FileName);
                previewModeComboBox.SelectedIndex = 0;
                Text = windowTitle + " - " + Path.GetFileName(openFileDialog.FileName);
                string loadedImageFilename = Path.GetFileNameWithoutExtension(openFileDialog.FileName);
                Console.WriteLine("Loaded file path: " + openFileDialog.FileName);
                Color[]       palette = useLastEmbeddedPalette && lastEmbeddedPalette != null ? lastEmbeddedPalette : palettes[selectedPaletteIndex];
                List <Bitmap> sprites = SprDecoder.GetSprites(data, palette).ToList();
                ClearImagePanel();
                assetsListBox.Items.Clear();
                loadedImages.Clear();
                UpdateStatusBarText("Loading images from spr file...");
                for (int i = 0; i < sprites.Count; i++)
                {
                    ShandalarAsset asset = new ShandalarAsset(loadedImageFilename, data, ImageType.Spr);
                    asset.image      = sprites[i];
                    asset.childIndex = i;
                    asset.parentName = loadedImageFilename;
                    asset.filename   = Path.GetFileNameWithoutExtension(asset.filePath) + "_" + i;
                    loadedImages.Add(asset);
                    SetProgressBarValue((int)Math.Round(100f * ((float)i / (float)sprites.Count)));
                }
                for (int i = 0; i < loadedImages.Count; i++)
                {
                    assetsListBox.Items.Add(loadedImageFilename + "_" + i);
                }
                SetProgressBarValue(0);
                UpdateStatusBarText("Finished loading images from spr file.");
                exportToolStripMenuItem.Enabled    = true;
                exportAllToolStripMenuItem.Enabled = true;
            }
        }