mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-05-05 21:17:14 -05:00
[Language Reference](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-10.0/file-scoped-namespaces) Updates all the files, one less level of indentation. Some small changes were made to API surfaces, renaming `PKM pkm` -> `PKM pk`, and `LegalityAnalysis.pkm` -> `LegalityAnalysis.Entity`
122 lines
3.0 KiB
C#
122 lines
3.0 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.Drawing.Imaging;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using PKHeX.Core;
|
|
|
|
namespace PKHeX.WinForms;
|
|
|
|
public partial class SAV_CGearSkin : Form
|
|
{
|
|
private readonly SaveFile Origin;
|
|
private readonly SAV5 SAV;
|
|
|
|
public SAV_CGearSkin(SaveFile sav)
|
|
{
|
|
InitializeComponent();
|
|
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
|
SAV = (SAV5)(Origin = sav).Clone();
|
|
|
|
byte[] data = SAV.CGearSkinData;
|
|
bg = new CGearBackground(data);
|
|
|
|
PB_Background.Image = CGearImage.GetBitmap(bg);
|
|
}
|
|
|
|
private CGearBackground bg;
|
|
|
|
private void B_ImportPNG_Click(object sender, EventArgs e)
|
|
{
|
|
using var ofd = new OpenFileDialog
|
|
{
|
|
Filter = "PNG File|*.png",
|
|
FileName = "Background.png",
|
|
};
|
|
|
|
if (ofd.ShowDialog() != DialogResult.OK)
|
|
return;
|
|
|
|
Bitmap img = (Bitmap)Image.FromFile(ofd.FileName);
|
|
|
|
try
|
|
{
|
|
bg = CGearImage.GetCGearBackground(img);
|
|
PB_Background.Image = CGearImage.GetBitmap(bg);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
WinFormsUtil.Error(ex.Message);
|
|
}
|
|
}
|
|
|
|
private void B_ExportPNG_Click(object sender, EventArgs e)
|
|
{
|
|
Image png = PB_Background.Image;
|
|
using var sfd = new SaveFileDialog
|
|
{
|
|
Filter = "PNG File|*.png",
|
|
FileName = "Background.png",
|
|
};
|
|
|
|
if (sfd.ShowDialog() != DialogResult.OK)
|
|
return;
|
|
|
|
png.Save(sfd.FileName, ImageFormat.Png);
|
|
}
|
|
|
|
private void B_ImportCGB_Click(object sender, EventArgs e)
|
|
{
|
|
using var ofd = new OpenFileDialog
|
|
{
|
|
Filter = CGearBackground.Filter + "|PokeStock C-Gear Skin|*.psk",
|
|
};
|
|
|
|
if (ofd.ShowDialog() != DialogResult.OK)
|
|
return;
|
|
|
|
var path = ofd.FileName;
|
|
var len = new FileInfo(path).Length;
|
|
if (len != CGearBackground.SIZE_CGB)
|
|
{
|
|
WinFormsUtil.Error($"Incorrect size, got {len} bytes, expected {CGearBackground.SIZE_CGB} bytes.");
|
|
return;
|
|
}
|
|
|
|
byte[] data = File.ReadAllBytes(path);
|
|
bg = new CGearBackground(data);
|
|
PB_Background.Image = CGearImage.GetBitmap(bg);
|
|
}
|
|
|
|
private void B_ExportCGB_Click(object sender, EventArgs e)
|
|
{
|
|
using var sfd = new SaveFileDialog
|
|
{
|
|
Filter = CGearBackground.Filter,
|
|
};
|
|
|
|
if (sfd.ShowDialog() != DialogResult.OK)
|
|
return;
|
|
|
|
byte[] data = bg.GetSkin(true);
|
|
File.WriteAllBytes(sfd.FileName, data);
|
|
}
|
|
|
|
private void B_Save_Click(object sender, EventArgs e)
|
|
{
|
|
byte[] bgdata = bg.GetSkin(SAV is SAV5B2W2);
|
|
if (bgdata.Any(z => z != 0))
|
|
{
|
|
SAV.CGearSkinData = bgdata;
|
|
Origin.CopyChangesFrom(SAV);
|
|
}
|
|
Close();
|
|
}
|
|
|
|
private void B_Cancel_Click(object sender, EventArgs e)
|
|
{
|
|
Close();
|
|
}
|
|
}
|