Exemple #1
0
        private void UpdateTextureDisplay()
        {
            // If no item is selected in the list, don't show the information panel
            if (treeTextures.SelectedNode == null)
            {
                pbTextureImage.Image = null;

                tlpTextureProperties.Visible = false;
                return;
            }

            // Otherwise, extract the TextureReference structure to get the selected texture
            TextureReference textureData = (TextureReference)treeTextures.SelectedNode.Tag;
            TplTexture       tex         = tpl[textureData.TextureIdx];

            // If the texture is null, then show a "bogus" information panel
            if (tex.IsEmpty)
            {
                pbTextureImage.Image = null;

                tlpTextureProperties.Visible  = true;
                lblTextureDimensions.Text     = "-";
                lblTextureFormat.Text         = "-";
                btnExportTextureLevel.Enabled = false;
                btnImportTextureLevel.Enabled = false;

                return;
            }

            // If selecting the whole texture, then show data about the first level, otherwise from the selected model
            int effTextureLevel = (textureData.TextureLevel != -1) ? textureData.TextureLevel : 0;

            pbTextureImage.Image = tex.DecodeLevelToBitmap(effTextureLevel);

            tlpTextureProperties.Visible = true;
            lblTextureDimensions.Text    = string.Format("{0} x {1}",
                                                         tex.WidthOfLevel(effTextureLevel), tex.HeightOfLevel(effTextureLevel));
            lblTextureFormat.Text         = string.Format("{0} ({1})", tex.Format, EnumUtils.GetEnumDescription(tex.Format));
            btnExportTextureLevel.Enabled = true;
            btnImportTextureLevel.Enabled = true;
        }
Exemple #2
0
        private void btnImportTextureLevel_Click(object sender, EventArgs e)
        {
            // Extract the TextureReference structure to get the selected texture
            TextureReference textureData = (TextureReference)treeTextures.SelectedNode.Tag;
            TplTexture       tex         = tpl[textureData.TextureIdx];

            // Request image filename
            if (ofdTextureImportPath.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            // Load image
            Bitmap bmp;

            try
            {
                bmp = new Bitmap(ofdTextureImportPath.FileName);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error loading image.",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (textureData.TextureLevel == -1) // Replacing whole texture
            {
                // Ask the user to select the format to import
                GcTextureFormatPickerDialog formatPickerDlg = new GcTextureFormatPickerDialog(
                    TplTexture.SupportedTextureFormats, tex.Format);
                if (formatPickerDlg.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                GcTextureFormat newFmt = formatPickerDlg.SelectedFormat;

                // Redefine the entire texture from the bitmap
                tex.DefineTextureFromBitmap(newFmt, bmp);

                TextureHasChanged(textureData.TextureIdx);
                UpdateTextureTree();
                treeTextures.SelectedNode = treeTextures.Nodes.Cast <TreeNode>()
                                            .Where(tn => ((TextureReference)tn.Tag).TextureIdx == textureData.TextureIdx).First();
            }
            else // Replacing single level
            {
                if (bmp.Width != tex.WidthOfLevel(textureData.TextureLevel) ||
                    bmp.Height != tex.HeightOfLevel(textureData.TextureLevel))
                {
                    MessageBox.Show("The selected image has an invalid size to replace this level.\n" +
                                    "If you wish to replace the entire texture, select the node coresponding to the texture.",
                                    "Invalid image size", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                // Replace just the selected level from the bitmap
                tex.DefineLevelDataFromBitmap(textureData.TextureLevel, bmp);

                TextureHasChanged(textureData.TextureIdx);
            }
        }