예제 #1
0
 public static Bitmap Make(VGABitmap[] frames, int spacingX = 0, int firstFrame = 0, int numFrames = int.MaxValue, List <Rectangle> frameRectangles = null)
 {
     Bitmap[] bitmaps = new Bitmap[frames.Length];
     for (int i = 0; i < frames.Length; i++)
     {
         bitmaps[i] = VGABitmapConverter.ToRGBA(frames[i]);
     }
     return(Make(bitmaps, spacingX, firstFrame, numFrames, frameRectangles));
 }
예제 #2
0
        private void fileSelected(TOCListItem item)
        {
            selectedItem = item;
            applyChangesButton.Visible = false;

            var hidePages = new TabPage[] { txtPage, imgPage, infoPage, mapPage, tfmxPage, tilesPage, entitiesPage };

            foreach (TabPage page in hidePages)
            {
                if (previewTabs.TabPages.Contains(page))
                {
                    previewTabs.TabPages.Remove(page);
                }
            }

            currentBitmapIndex = 0;
            if (currentBitmaps != null)
            {
                foreach (Bitmap bmp in currentBitmaps)
                {
                    bmp.Dispose();
                }
                currentBitmaps = null;
            }

            mapMaker?.Cancel();

            if (mapPictureBox.Image != null)
            {
                var img = mapPictureBox.Image;
                mapPictureBox.Image = null;
                img.Dispose();
            }

            hexBox.ByteProvider = new DynamicByteProvider(item.Entry.Data);

            bool        preview     = true;
            Description description = game.Descriptions?.ByName(item.Entry.Name);

            if (description != null && description.NoPreview)
            {
                preview = false;
            }

            if (preview)
            {
                switch (item.Entry.Type)
                {
                case TOCEntryType.Text:
                case TOCEntryType.Language:
                    txtOutput.Text = Encoding.GetEncoding("437").GetString(item.Entry.Data);
                    previewTabs.TabPages.Add(txtPage);
                    previewTabs.SelectedTab = txtPage;
                    break;

                case TOCEntryType.StaticSprite:
                    PCXFile img = new PCXFile();
                    img.Load(item.Entry.Data);
                    currentImgZoom     = 3;
                    imgZoomInput.Value = currentImgZoom;
                    currentBitmaps     = new Bitmap[] { img.Bitmap };
                    imgPage.Text       = "Sprite";
                    previewTabs.TabPages.Add(imgPage);
                    previewTabs.SelectedTab     = imgPage;
                    bitmapControlsPanel.Visible = false;
                    updateImagePreview();
                    break;

                case TOCEntryType.AnimatedSprite:
                    BOBFile    bobFile    = new BOBFile(item.Entry.Data);
                    BOBDecoder decoder    = new BOBDecoder();
                    var        vgaBitmaps = decoder.DecodeFrames(bobFile);
                    currentBitmaps = new Bitmap[vgaBitmaps.Count];
                    imgPage.Text   = "Sprite Animation";
                    for (int i = 0; i < vgaBitmaps.Count; i++)
                    {
                        currentBitmaps[i] = VGABitmapConverter.ToRGBA(vgaBitmaps[i]);
                    }
                    currentImgZoom     = 10;
                    imgZoomInput.Value = currentImgZoom;
                    previewTabs.TabPages.Add(imgPage);
                    previewTabs.SelectedTab     = imgPage;
                    bitmapControlsPanel.Visible = true;
                    updateImagePreview();
                    break;

                case TOCEntryType.Palette:
                    currentImgZoom     = 14;
                    imgZoomInput.Value = currentImgZoom;
                    currentBitmaps     = new Bitmap[] { Palette.ToBitmap(item.Entry.Data) };
                    imgPage.Text       = "Palette";
                    previewTabs.TabPages.Add(imgPage);
                    previewTabs.SelectedTab     = imgPage;
                    bitmapControlsPanel.Visible = false;
                    updateImagePreview();
                    break;

                case TOCEntryType.Tileset:
                case TOCEntryType.CollisionInfo:
                    tilesCollisionsCheckbox.Checked = item.Entry.Type == TOCEntryType.CollisionInfo;
                    Bitmap tilesetBitmap = tilemapMaker.MakeTilesetBitmap(item.Entry, tilesCollisionsCheckbox.Checked);
                    if (tilesetBitmap != null)
                    {
                        tilesPictureBox.Image = tilesetBitmap;
                        previewTabs.TabPages.Add(tilesPage);
                        previewTabs.SelectedTab = tilesPage;
                    }
                    else
                    {
                        MessageBox.Show("Error: Failed to generate tileset preview!");
                    }
                    break;

                case TOCEntryType.Map:
                    previewTabs.TabPages.Add(mapPage);
                    previewTabs.SelectedTab       = mapPage;
                    mapMakerProgressBar.Value     = 0;
                    mapMakerProgressPanel.Visible = true;
                    mapMaker = new MapMaker(game.Assets, mapProgress, mapComplete);
                    if (!mapMaker.Make(item.Entry))
                    {
                        MessageBox.Show("Error: " + mapMaker.Error, "Failed to generate preview!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    break;

                case TOCEntryType.Music:
                    previewTabs.TabPages.Add(tfmxPage);
                    previewTabs.SelectedTab = tfmxPage;
                    playSelectedTFM();
                    break;

                case TOCEntryType.EntitiesList:
                    previewTabs.TabPages.Add(entitiesPage);
                    previewTabs.SelectedTab = entitiesPage;
                    entitiesList.Items.Clear();
                    try
                    {
                        EIBFile eibFile = new EIBFile(item.Entry.Data);
                        foreach (var entry in eibFile.Regions)
                        {
                            foreach (var point in entry.Points)
                            {
                                entitiesList.Items.Add(new EntityListItem(point));
                            }
                        }
                        entityFileInfo.Text = $"Unknown variables in file: D={eibFile.D}, E={eibFile.E}, F={eibFile.F}";
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    break;

                case TOCEntryType.PixelFont:
                case TOCEntryType.Sound:
                case TOCEntryType.DIR:
                case TOCEntryType.DAT:
                case TOCEntryType.Executable:
                case TOCEntryType.Unknown:
                default:
                    break;
                }
            }

            if (description != null && !string.IsNullOrEmpty(description.Info))
            {
                infoOutput.Text = description.Info;
                previewTabs.TabPages.Add(infoPage);
                if (previewTabs.TabPages.Count == 1)
                {
                    previewTabs.SelectedTab = infoPage;
                }
            }

            sectionsPanel.Invalidate();
        }