1
0
mirror of synced 2024-12-01 02:27:22 +01:00

Add image program settings for editing with other programs.

This commit is contained in:
KillzXGaming 2019-04-29 19:15:09 -04:00
parent 68d244e9f7
commit 64623a0223
8 changed files with 90 additions and 32 deletions

Binary file not shown.

View File

@ -821,44 +821,50 @@ namespace Switch_Toolbox.Library.Forms
EditInExternalProgram();
}
private TEX_FORMAT FormatToChange = TEX_FORMAT.UNKNOWN;
private void EditInExternalProgram(bool UseDefaultEditor = true)
{
if (!ActiveTexture.CanEdit)
return;
string UseExtension = ".dds";
string TemporaryName = Path.GetTempFileName();
Utils.DeleteIfExists(Path.ChangeExtension(TemporaryName, UseExtension));
File.Move(TemporaryName, Path.ChangeExtension(TemporaryName, UseExtension));
TemporaryName = Path.ChangeExtension(TemporaryName, UseExtension);
switch (UseExtension)
ImageProgramSettings settings = new ImageProgramSettings();
settings.LoadImage(ActiveTexture);
if (settings.ShowDialog() == DialogResult.OK)
{
case ".dds":
ActiveTexture.SaveDDS(TemporaryName, CurArrayDisplayLevel, CurMipDisplayLevel);
break;
case ".astc":
ActiveTexture.SaveASTC(TemporaryName, CurArrayDisplayLevel, CurMipDisplayLevel);
break;
case ".tga":
ActiveTexture.SaveTGA(TemporaryName, CurArrayDisplayLevel, CurMipDisplayLevel);
break;
default:
ActiveTexture.SaveBitMap(TemporaryName, CurArrayDisplayLevel, CurMipDisplayLevel);
break;
string UseExtension = settings.GetSelectedExtension();
FormatToChange = settings.GetSelectedImageFormat();
string TemporaryName = Path.GetTempFileName();
Utils.DeleteIfExists(Path.ChangeExtension(TemporaryName, UseExtension));
File.Move(TemporaryName, Path.ChangeExtension(TemporaryName, UseExtension));
TemporaryName = Path.ChangeExtension(TemporaryName, UseExtension);
switch (UseExtension)
{
case ".dds":
ActiveTexture.SaveDDS(TemporaryName, CurArrayDisplayLevel, CurMipDisplayLevel);
break;
case ".astc":
ActiveTexture.SaveASTC(TemporaryName, CurArrayDisplayLevel, CurMipDisplayLevel);
break;
case ".tga":
ActiveTexture.SaveTGA(TemporaryName, CurArrayDisplayLevel, CurMipDisplayLevel);
break;
default:
ActiveTexture.SaveBitMap(TemporaryName, CurArrayDisplayLevel, CurMipDisplayLevel);
break;
}
if (UseDefaultEditor)
Process.Start(TemporaryName);
else
ShowOpenWithDialog(TemporaryName);
FileWatcher.Filter = Path.GetFileName(TemporaryName);
//Start watching for changes
FileWatcher.EnableRaisingEvents = true;
}
if (UseDefaultEditor)
Process.Start(TemporaryName);
else
ShowOpenWithDialog(TemporaryName);
FileWatcher.Filter = Path.GetFileName(TemporaryName);
//Start watching for changes
FileWatcher.EnableRaisingEvents = true;
}
public static Process ShowOpenWithDialog(string path)
@ -878,6 +884,9 @@ namespace Switch_Toolbox.Library.Forms
if (Result == DialogResult.Yes)
{
if (FormatToChange != TEX_FORMAT.UNKNOWN)
ActiveTexture.Format = FormatToChange;
if (FileName.EndsWith(".dds"))
{
DDS dds = new DDS(FileName);

View File

@ -32,19 +32,23 @@
this.textureImageFormatCB = new Switch_Toolbox.Library.Forms.STComboBox();
this.textureFileFormatCB = new Switch_Toolbox.Library.Forms.STComboBox();
this.stLabel2 = new Switch_Toolbox.Library.Forms.STLabel();
this.stButton1 = new Switch_Toolbox.Library.Forms.STButton();
this.contentContainer.SuspendLayout();
this.SuspendLayout();
//
// contentContainer
//
this.contentContainer.Controls.Add(this.stButton1);
this.contentContainer.Controls.Add(this.textureFileFormatCB);
this.contentContainer.Controls.Add(this.stLabel2);
this.contentContainer.Controls.Add(this.textureImageFormatCB);
this.contentContainer.Controls.Add(this.stLabel1);
this.contentContainer.Size = new System.Drawing.Size(393, 133);
this.contentContainer.Controls.SetChildIndex(this.stLabel1, 0);
this.contentContainer.Controls.SetChildIndex(this.textureImageFormatCB, 0);
this.contentContainer.Controls.SetChildIndex(this.stLabel2, 0);
this.contentContainer.Controls.SetChildIndex(this.textureFileFormatCB, 0);
this.contentContainer.Controls.SetChildIndex(this.stButton1, 0);
//
// stLabel1
//
@ -88,11 +92,22 @@
this.stLabel2.TabIndex = 13;
this.stLabel2.Text = "File Format:";
//
// stButton1
//
this.stButton1.DialogResult = System.Windows.Forms.DialogResult.OK;
this.stButton1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.stButton1.Location = new System.Drawing.Point(308, 107);
this.stButton1.Name = "stButton1";
this.stButton1.Size = new System.Drawing.Size(75, 23);
this.stButton1.TabIndex = 15;
this.stButton1.Text = "Ok";
this.stButton1.UseVisualStyleBackColor = false;
//
// ImageProgramSettings
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(549, 398);
this.ClientSize = new System.Drawing.Size(399, 138);
this.Name = "ImageProgramSettings";
this.Text = "ImageProgramSettings";
this.contentContainer.ResumeLayout(false);
@ -107,5 +122,6 @@
private STComboBox textureImageFormatCB;
private STComboBox textureFileFormatCB;
private STLabel stLabel2;
private STButton stButton1;
}
}

View File

@ -17,10 +17,20 @@ namespace Switch_Toolbox.Library.Forms
InitializeComponent();
CanResize = false;
this.Text = "Image Program Settings";
stButton1.Select();
}
public void LoadImage(STGenericTexture texture)
{
textureFileFormatCB.Items.Add("Direct Draw Surface (.dds)");
textureFileFormatCB.Items.Add("Portable Network Graphics (.png)");
textureFileFormatCB.Items.Add("Joint Photographic Experts Group (.jpg)");
textureFileFormatCB.Items.Add("TGA (.tga)");
textureFileFormatCB.Items.Add("Tagged Image File Format (.tiff)");
textureFileFormatCB.Items.Add("Bitmap Image (.bmp)");
textureFileFormatCB.SelectedIndex = 0;
foreach (var format in texture.SupportedFormats)
{
textureImageFormatCB.Items.Add(format);
@ -28,5 +38,28 @@ namespace Switch_Toolbox.Library.Forms
textureImageFormatCB.SelectedItem = texture.Format;
}
public TEX_FORMAT GetSelectedImageFormat()
{
return (TEX_FORMAT)textureImageFormatCB.SelectedItem;
}
public string GetSelectedExtension()
{
string SelectedExt = textureFileFormatCB.GetSelectedText();
string output = GetSubstringByString("(", ")", SelectedExt);
output = output.Replace('*', ' ');
if (output == ".")
output = ".raw";
return output;
}
public string GetSubstringByString(string a, string b, string c)
{
return c.Substring((c.IndexOf(a) + a.Length), (c.IndexOf(b) - c.IndexOf(a) - a.Length));
}
}
}