Пример #1
0
 public bool LoadPaletteFile(string path)
 {
     try
     {
         PaletteFile pal = new PaletteFile();
         pal.ReadFromFile(path);
         _paletteFile = pal;
         return(true);
     }
     catch
     {
         MessageBox.Show("The file is not a valid palette file.");
         return(false);
     }
 }
Пример #2
0
 public override bool LoadFile(string path)
 {
     try
     {
         PaletteFile pal = new PaletteFile();
         pal.ReadFromFile(path);
         _pal   = pal;
         _dirty = false;
         _path  = path;
         return(true);
     }
     catch
     {
         MessageBox.Show("The file is not a valid resource file.");
         return(false);
     }
 }
Пример #3
0
        private void bImportPalette_Click(object sender, EventArgs e)
        {
            if (ofdImportPalette.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    PaletteFile paletteFile = new PaletteFile();
                    paletteFile.ReadFromFile(ofdImportPalette.FileName);
                    UserPalette = paletteFile.Palette;
                }
                catch
                {
                    MessageBox.Show("Unable to load new palette.");
                }

                _choice = PaletteChoice.USER;
                ImportImageData();
            }
        }
Пример #4
0
        private void Import(ref List <ResourceElement> workingList, Palette_18Bit basePalette, string rootDir, IProgress <int> progress = null)
        {
            foreach (string key in Entries.GetKeys())
            {
                if (!int.TryParse(key, out int ikey))
                {
                    continue;
                }

                ResourceExportEntry entry = Entries[key];
                if (ikey >= workingList.Count)
                {
                    continue;
                }

                Bitmap   image = new Bitmap(Path.Combine(rootDir, entry.ImagePath));
                IPalette pal   = basePalette;
                if (entry.UseOwnPalette == true)
                {
                    PaletteFile palfile = new PaletteFile();
                    palfile.ReadFromFile(Path.Combine(rootDir, entry.PalettePath));
                    pal = palfile.Palette;
                }

                if (entry.UsePalette)
                {
                    workingList[ikey].ImportImageDataAs8Bit(image, pal, entry.UseOwnPalette == false, out int _);
                }
                else
                {
                    workingList[ikey].ImportImageDataAs15Bit(image);
                }

                workingList[ikey].FrameSize     = entry.FrameSize;
                workingList[ikey].ImageOffset   = entry.ImageOffset;
                workingList[ikey].Alignment     = entry.Alignment;
                workingList[ikey].ImageHandle   = entry.ImageHandle;
                workingList[ikey].PaletteHandle = entry.PaletteHandle;

                progress?.Report(ikey);
            }
        }
Пример #5
0
        private void bImportPalette_Click(object sender, EventArgs e)
        {
            int index = lboxItems.SelectedIndex;

            if (_resourceFile == null)
            {
                return;
            }
            if (index < 0 || index >= _resourceFile.Resources.Count)
            {
                return;
            }

            if (_resourceFile.Resources[index].PaletteType == PaletteType.EMPTY_ENTRY || _resourceFile.Resources[index].PaletteType == PaletteType.INVALID)
            {
                MessageBox.Show("The resource entry is empty and cannot be assigned a palette.");
                return;
            }
            else if (_resourceFile.Resources[index].PaletteType == PaletteType.HIGH_COLOR)
            {
                MessageBox.Show("The resource entry is in 15-bit HighColor mode and cannot be assigned a palette.");
                return;
            }
            else if (_resourceFile.Resources[index].PaletteType == PaletteType.BASE_PALETTE)
            {
                if (MessageBox.Show("The resource entry currently uses the game's base palette. Replace with an embedded palette?", "Confirm Import Palette", MessageBoxButtons.YesNo) != DialogResult.Yes)
                {
                    return;
                }
            }

            if (ofdImportPalette.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    PaletteFile paletteFile = new PaletteFile();
                    paletteFile.ReadFromFile(ofdImportPalette.FileName);

                    _resourceFile.Resources[index].Palette.Import(paletteFile.Palette);
                    if (_resourceFile.Resources[index].Palette.HasNonUniqueSpecialIndices(out byte[] affected))
                    {
                        MessageBox.Show("The palette has some special indices that are mapped to the same colors as other indices. This may give incorrect results when importing images with this palette.\n\n" +
                                        "Affected indices: {0}".F(string.Join(",", affected)));
                    }

                    if (_resourceFile.Resources[index].PaletteType == PaletteType.BASE_PALETTE)
                    {
                        _resourceFile.Resources[index].PaletteHandle  = 1; // any non-zero number
                        _resourceFile.Resources[index].Memory         = 1; // any non-zero number
                        _resourceFile.Resources[index].PaletteHandle2 = 1; // any non-zero number
                    }

                    _resourceFile.Resources[index].FirstByte = 1; // embedded
                    MessageBox.Show("Palette imported successfully.");
                }
                catch
                {
                    MessageBox.Show("Unable to load new palette.");
                }
                _dirty = true;
                ReloadEntry();
            }
        }