Beispiel #1
0
        private void InjectBitmap(string filePath)
        {
            // Set the UI to be disabled while we update the arc files.
            this.EditorOwner.SetUIState(false);

            // Parse the DDS image from file.
            DDSImage ddsImage = DDSImage.FromFile(filePath);

            if (ddsImage == null)
            {
                // Failed to parse the image.
                MessageBox.Show("Failed to read " + filePath);
                this.EditorOwner.SetUIState(true);
                return;
            }

            // Convert the dds image to a rtexture.
            rTexture newTexture = rTexture.FromDDSImage(ddsImage, this.Bitmap.FileName, this.Bitmap.Datum, this.Bitmap.FileType, this.Bitmap.IsBigEndian);

            if (newTexture == null)
            {
                // Failed to convert the dds image to rtexture.
                MessageBox.Show("Failed to convert dds image to rtexture!");
                this.EditorOwner.SetUIState(true);
                return;
            }

            // Check if the old texture has a background color, and if so copy it.
            if (this.Bitmap.Flags.HasFlag(TextureFlags.HasD3DClearColor) == true)
            {
                // Copy the background color.
                newTexture.header.Flags   |= TextureFlags.HasD3DClearColor;
                newTexture.BackgroundColor = this.Bitmap.BackgroundColor;
            }

            // Write the texture to a buffer we can use to update all the files for this texture.
            byte[] textureBuffer = newTexture.ToBuffer();

            // Get a list of every datum to be updated for this file and update all of them.
            DatumIndex[] datums = this.EditorOwner.GetDatumsToUpdateForResource(this.GameResource.FileName);
            if (ArchiveCollection.Instance.InjectFile(datums, textureBuffer) == false)
            {
                // Failed to update files.
                this.EditorOwner.SetUIState(true);
                return;
            }

            // Update the game resource instance and reload the UI.
            this.GameResource = newTexture;
            OnGameResourceUpdated();

            // Image successfully injected.
            this.EditorOwner.SetUIState(true);
            MessageBox.Show("Done!");
        }