Misc clean

lowercase input parameters
This commit is contained in:
Kurt 2019-02-16 19:53:14 -08:00
parent 202f911d45
commit 4aa103a320
3 changed files with 86 additions and 90 deletions

View file

@ -355,47 +355,45 @@ namespace PKHeX.WinForms.Controls
}
// General Use Functions //
private void SetDetailsOT(ITrainerInfo SAV)
private void SetDetailsOT(ITrainerInfo tr)
{
if (string.IsNullOrWhiteSpace(SAV.OT))
if (string.IsNullOrWhiteSpace(tr.OT))
return;
// Get Save Information
TB_OT.Text = SAV.OT;
Label_OTGender.Text = gendersymbols[SAV.Gender & 1];
Label_OTGender.ForeColor = Draw.GetGenderColor(SAV.Gender & 1);
TID_Trainer.LoadInfo(SAV);
TB_OT.Text = tr.OT;
Label_OTGender.Text = gendersymbols[tr.Gender & 1];
Label_OTGender.ForeColor = Draw.GetGenderColor(tr.Gender & 1);
TID_Trainer.LoadInfo(tr);
if (SAV.Game >= 0)
CB_GameOrigin.SelectedValue = SAV.Game;
if (tr.Game >= 0)
CB_GameOrigin.SelectedValue = tr.Game;
var lang = SAV.Language;
var lang = tr.Language;
if (lang <= 0)
lang = (int)LanguageID.English;
CB_Language.SelectedValue = lang;
if (SAV.ConsoleRegion != 0)
if (tr.ConsoleRegion != 0)
{
CB_3DSReg.SelectedValue = SAV.ConsoleRegion;
CB_Country.SelectedValue = SAV.Country;
CB_SubRegion.SelectedValue = SAV.SubRegion;
CB_3DSReg.SelectedValue = tr.ConsoleRegion;
CB_Country.SelectedValue = tr.Country;
CB_SubRegion.SelectedValue = tr.SubRegion;
}
// Copy OT trash bytes for sensitive games (Gen1/2)
if (SAV is SAV1 s1 && pkm is PK1 p1) p1.OT_Trash = s1.OT_Trash;
else if (SAV is SAV2 s2 && pkm is PK2 p2) p2.OT_Trash = s2.OT_Trash;
if (tr is SAV1 s1 && pkm is PK1 p1) p1.OT_Trash = s1.OT_Trash;
else if (tr is SAV2 s2 && pkm is PK2 p2) p2.OT_Trash = s2.OT_Trash;
UpdateNickname(null, EventArgs.Empty);
}
private void SetDetailsHT(ITrainerInfo SAV)
private void SetDetailsHT(ITrainerInfo tr)
{
if (string.IsNullOrWhiteSpace(SAV.OT))
if (string.IsNullOrWhiteSpace(tr.OT))
return;
if (TB_OTt2.Text.Length > 0)
Label_CTGender.Text = gendersymbols[SAV.Gender & 1];
Label_CTGender.Text = gendersymbols[tr.Gender & 1];
}
private void SetForms()
@ -1238,14 +1236,14 @@ namespace PKHeX.WinForms.Controls
if (ModifierKeys != Keys.Control)
return;
var SAV = RequestSaveFile;
if (SAV == null) // form did not provide the needed info
var sav = RequestSaveFile;
if (sav == null) // form did not provide the needed info
return;
if (tb == TB_Nickname)
{
pkm.Nickname = tb.Text;
var d = new TrashEditor(tb, pkm.Nickname_Trash, SAV);
var d = new TrashEditor(tb, pkm.Nickname_Trash, sav);
d.ShowDialog();
tb.Text = d.FinalString;
pkm.Nickname_Trash = d.FinalBytes;
@ -1253,7 +1251,7 @@ namespace PKHeX.WinForms.Controls
else if (tb == TB_OT)
{
pkm.OT_Name = tb.Text;
var d = new TrashEditor(tb, pkm.OT_Trash, SAV);
var d = new TrashEditor(tb, pkm.OT_Trash, sav);
d.ShowDialog();
tb.Text = d.FinalString;
pkm.OT_Trash = d.FinalBytes;
@ -1261,7 +1259,7 @@ namespace PKHeX.WinForms.Controls
else if (tb == TB_OTt2)
{
pkm.HT_Name = tb.Text;
var d = new TrashEditor(tb, pkm.HT_Trash, SAV);
var d = new TrashEditor(tb, pkm.HT_Trash, sav);
d.ShowDialog();
tb.Text = d.FinalString;
pkm.HT_Trash = d.FinalBytes;
@ -1304,9 +1302,9 @@ namespace PKHeX.WinForms.Controls
// if egg wasn't originally obtained by OT => Link Trade, else => None
bool isTraded = false;
var SAV = SaveFileRequested?.Invoke(this, e);
if (SAV != null)
isTraded = SAV.OT != TB_OT.Text || SAV.TID != pkm.TID || SAV.SID != pkm.SID;
var sav = SaveFileRequested?.Invoke(this, e);
if (sav != null)
isTraded = sav.OT != TB_OT.Text || sav.TID != pkm.TID || sav.SID != pkm.SID;
CB_MetLocation.SelectedIndex = isTraded ? 2 : 0;
if (!CHK_Nicknamed.Checked)
@ -1664,7 +1662,7 @@ namespace PKHeX.WinForms.Controls
PopulateFilteredDataSources(sav);
PopulateFields(pkm);
// SAV Specific Limits
// Save File Specific Limits
TB_OT.MaxLength = pkm.OTLength;
TB_OTt2.MaxLength = pkm.OTLength;
TB_Nickname.MaxLength = pkm.NickLength;
@ -1758,7 +1756,7 @@ namespace PKHeX.WinForms.Controls
tabMain.SelectedTab = Tab_Main; // first tab
}
private void InitializeLanguage(SaveFile SAV)
private void InitializeLanguage(SaveFile sav)
{
// Set the various ComboBox DataSources up with their allowed entries
SetCountrySubRegion(CB_Country, "countries");
@ -1770,25 +1768,25 @@ namespace PKHeX.WinForms.Controls
// Sub editors
Stats.InitializeDataSources();
PopulateFilteredDataSources(SAV);
PopulateFilteredDataSources(sav);
}
private void PopulateFilteredDataSources(SaveFile SAV)
private void PopulateFilteredDataSources(SaveFile sav)
{
GameInfo.Strings.SetItemDataSource(SAV.Version, SAV.Generation, SAV.MaxItemID, SAV.HeldItems, HaX);
if (SAV.Generation > 1)
CB_HeldItem.DataSource = new BindingSource(GameInfo.ItemDataSource.Where(i => i.Value <= SAV.MaxItemID).ToList(), null);
GameInfo.Strings.SetItemDataSource(sav.Version, sav.Generation, sav.MaxItemID, sav.HeldItems, HaX);
if (sav.Generation > 1)
CB_HeldItem.DataSource = new BindingSource(GameInfo.ItemDataSource.Where(i => i.Value <= sav.MaxItemID).ToList(), null);
CB_Language.DataSource = GameInfo.LanguageDataSource(SAV.Generation);
CB_Language.DataSource = GameInfo.LanguageDataSource(sav.Generation);
CB_Ball.DataSource = new BindingSource(GameInfo.BallDataSource.Where(b => b.Value <= SAV.MaxBallID).ToList(), null);
CB_Species.DataSource = new BindingSource(GameInfo.SpeciesDataSource.Where(s => s.Value <= SAV.MaxSpeciesID).ToList(), null);
DEV_Ability.DataSource = new BindingSource(GameInfo.AbilityDataSource.Where(a => a.Value <= SAV.MaxAbilityID).ToList(), null);
var gamelist = GameUtil.GetVersionsWithinRange(SAV, SAV.Generation).ToList();
CB_Ball.DataSource = new BindingSource(GameInfo.BallDataSource.Where(b => b.Value <= sav.MaxBallID).ToList(), null);
CB_Species.DataSource = new BindingSource(GameInfo.SpeciesDataSource.Where(s => s.Value <= sav.MaxSpeciesID).ToList(), null);
DEV_Ability.DataSource = new BindingSource(GameInfo.AbilityDataSource.Where(a => a.Value <= sav.MaxAbilityID).ToList(), null);
var gamelist = GameUtil.GetVersionsWithinRange(sav, sav.Generation).ToList();
CB_GameOrigin.DataSource = new BindingSource(GameInfo.VersionDataSource.Where(g => gamelist.Contains((GameVersion)g.Value)).ToList(), null);
// Set the Move ComboBoxes too..
MoveDataAllowed = GameInfo.Strings.MoveDataSource = (HaX ? GameInfo.HaXMoveDataSource : GameInfo.LegalMoveDataSource).Where(m => m.Value <= SAV.MaxMoveID).ToList(); // Filter Z-Moves if appropriate
MoveDataAllowed = GameInfo.Strings.MoveDataSource = (HaX ? GameInfo.HaXMoveDataSource : GameInfo.LegalMoveDataSource).Where(m => m.Value <= sav.MaxMoveID).ToList(); // Filter Z-Moves if appropriate
foreach (var cb in Moves.Concat(Relearn))
{
cb.DataSource = new BindingSource(GameInfo.MoveDataSource, null);

View file

@ -87,53 +87,53 @@ namespace PKHeX.WinForms
return Resources.unknown;
}
private static Image GetSprite(PKM pkm, bool isBoxBGRed = false)
private static Image GetSprite(PKM pk, bool isBoxBGRed = false)
{
var img = GetSprite(pkm.Species, pkm.AltForm, pkm.Gender, pkm.SpriteItem, pkm.IsEgg, pkm.IsShiny, pkm.Format, isBoxBGRed);
if (pkm is IShadowPKM s && s.Purification > 0)
var img = GetSprite(pk.Species, pk.AltForm, pk.Gender, pk.SpriteItem, pk.IsEgg, pk.IsShiny, pk.Format, isBoxBGRed);
if (pk is IShadowPKM s && s.Purification > 0)
{
if (pkm.Species == 249) // Lugia
img = Spriter.GetSprite(Resources._249x, 249, pkm.HeldItem, pkm.IsEgg, pkm.IsShiny, pkm.Format, isBoxBGRed);
GetSpriteGlow(pkm, new byte[] { 75, 0, 130 }, out var pixels, out var baseSprite, true);
if (pk.Species == 249) // Lugia
img = Spriter.GetSprite(Resources._249x, 249, pk.HeldItem, pk.IsEgg, pk.IsShiny, pk.Format, isBoxBGRed);
GetSpriteGlow(pk, new byte[] { 75, 0, 130 }, out var pixels, out var baseSprite, true);
var glowImg = ImageUtil.GetBitmap(pixels, baseSprite.Width, baseSprite.Height, baseSprite.PixelFormat);
img = ImageUtil.LayerImage(glowImg, img, 0, 0);
}
return img;
}
private static Image GetSprite(SaveFile SAV)
private static Image GetSprite(SaveFile sav)
{
string file = "tr_00";
if (SAV.Generation == 6 && (SAV.ORAS || SAV.ORASDEMO))
file = $"tr_{SAV.MultiplayerSpriteID:00}";
if (sav.Generation == 6 && (sav.ORAS || sav.ORASDEMO))
file = $"tr_{sav.MultiplayerSpriteID:00}";
return Resources.ResourceManager.GetObject(file) as Image;
}
private static Image GetWallpaper(SaveFile SAV, int box)
private static Image GetWallpaper(SaveFile sav, int box)
{
string s = BoxWallpaper.GetWallpaperResourceName(SAV.Version, SAV.GetBoxWallpaper(box));
string s = BoxWallpaper.GetWallpaperResourceName(sav.Version, sav.GetBoxWallpaper(box));
return (Bitmap)(Resources.ResourceManager.GetObject(s) ?? Resources.box_wp16xy);
}
private static Image GetSprite(PKM pkm, SaveFile SAV, int box, int slot, bool flagIllegal = false)
private static Image GetSprite(PKM pk, SaveFile sav, int box, int slot, bool flagIllegal = false)
{
if (!pkm.Valid)
if (!pk.Valid)
return null;
bool inBox = slot >= 0 && slot < 30;
var sprite = pkm.Species == 0 ? null : pkm.Sprite(isBoxBGRed: inBox && BoxWallpaper.IsWallpaperRed(SAV.Version, SAV.GetBoxWallpaper(box)));
var sprite = pk.Species == 0 ? null : pk.Sprite(isBoxBGRed: inBox && BoxWallpaper.IsWallpaperRed(sav.Version, sav.GetBoxWallpaper(box)));
if (flagIllegal)
{
if (box >= 0)
pkm.Box = box;
var la = new LegalityAnalysis(pkm, SAV.Personal);
if (!la.Valid && pkm.Species != 0)
pk.Box = box;
var la = new LegalityAnalysis(pk, sav.Personal);
if (!la.Valid && pk.Species != 0)
sprite = ImageUtil.LayerImage(sprite, Resources.warn, 0, 14);
}
if (inBox) // in box
{
var flags = SAV.GetSlotFlags(box, slot);
var flags = sav.GetSlotFlags(box, slot);
if (flags.HasFlagFast(StorageSlotFlag.Locked))
sprite = ImageUtil.LayerImage(sprite, Resources.locked, 26, 0);
int team = flags.IsBattleTeam();
@ -180,12 +180,12 @@ namespace PKHeX.WinForms
}
// Extension Methods
public static Image WallpaperImage(this SaveFile SAV, int box) => GetWallpaper(SAV, box);
public static Image WallpaperImage(this SaveFile sav, int box) => GetWallpaper(sav, box);
public static Image Sprite(this MysteryGift gift) => GetSprite(gift);
public static Image Sprite(this SaveFile SAV) => GetSprite(SAV);
public static Image Sprite(this PKM pkm, bool isBoxBGRed = false) => GetSprite(pkm, isBoxBGRed);
public static Image Sprite(this SaveFile sav) => GetSprite(sav);
public static Image Sprite(this PKM pk, bool isBoxBGRed = false) => GetSprite(pk, isBoxBGRed);
public static Image Sprite(this PKM pkm, SaveFile SAV, int box, int slot, bool flagIllegal = false)
=> GetSprite(pkm, SAV, box, slot, flagIllegal);
public static Image Sprite(this PKM pk, SaveFile sav, int box, int slot, bool flagIllegal = false)
=> GetSprite(pk, sav, box, slot, flagIllegal);
}
}

View file

@ -165,13 +165,13 @@ namespace PKHeX.WinForms
/// <summary>
/// Opens a dialog to open a <see cref="SaveFile"/>, <see cref="PKM"/> file, or any other supported file.
/// </summary>
/// <param name="Extensions">Misc extensions of <see cref="PKM"/> files supported by the SAV.</param>
/// <param name="extensions">Misc extensions of <see cref="PKM"/> files supported by the Save File.</param>
/// <param name="path">Output result path</param>
/// <returns>Result of whether or not a file is to be loaded from the output path.</returns>
public static bool OpenSAVPKMDialog(IEnumerable<string> Extensions, out string path)
public static bool OpenSAVPKMDialog(IEnumerable<string> extensions, out string path)
{
string supported = string.Join(";", Extensions.Select(s => $"*.{s}").Concat(new[] { "*.pkm" }));
OpenFileDialog ofd = new OpenFileDialog
string supported = string.Join(";", extensions.Select(s => $"*.{s}").Concat(new[] { "*.pkm" }));
var ofd = new OpenFileDialog
{
Filter = "All Files|*.*" +
$"|Supported Files (*.*)|main;*.bin;{supported};*.bak" + ExtraSaveExtensions +
@ -248,41 +248,47 @@ namespace PKHeX.WinForms
/// <summary>
/// Opens a dialog to save a <see cref="SaveFile"/> file.
/// </summary>
/// <param name="SAV"><see cref="SaveFile"/> to be saved.</param>
/// <param name="sav"><see cref="SaveFile"/> to be saved.</param>
/// <param name="CurrentBox">Box the player will be greeted with when accessing the PC ingame.</param>
/// <returns>Result of whether or not the file was saved.</returns>
public static bool SaveSAVDialog(SaveFile SAV, int CurrentBox = 0)
public static bool SaveSAVDialog(SaveFile sav, int CurrentBox = 0)
{
// Chunk Error Checking
string err = SAV.MiscSaveChecks();
string err = sav.MiscSaveChecks();
if (err.Length > 0 && Prompt(MessageBoxButtons.YesNo, err, MsgSaveExportContinue) != DialogResult.Yes)
return false;
SaveFileDialog main = new SaveFileDialog
{
Filter = SAV.Filter,
FileName = SAV.FileName,
Filter = sav.Filter,
FileName = sav.FileName,
FilterIndex = 1000, // default to last, All Files
RestoreDirectory = true
};
if (Directory.Exists(SAV.FileFolder))
main.InitialDirectory = SAV.FileFolder;
if (Directory.Exists(sav.FileFolder))
main.InitialDirectory = sav.FileFolder;
// Export
if (main.ShowDialog() != DialogResult.OK)
return false;
if (SAV.HasBox)
SAV.CurrentBox = CurrentBox;
if (sav.HasBox)
sav.CurrentBox = CurrentBox;
var ext = Path.GetExtension(main.FileName)?.ToLower();
ExportSAV(sav, main.FileName);
return true;
}
private static void ExportSAV(SaveFile sav, string path)
{
var ext = Path.GetExtension(path)?.ToLower();
bool dsv = ext == ".dsv";
bool gci = ext == ".gci";
try
{
File.WriteAllBytes(main.FileName, SAV.Write(dsv, gci));
SAV.Edited = false;
Alert(MsgSaveExportSuccessPath, main.FileName);
File.WriteAllBytes(path, sav.Write(dsv, gci));
sav.Edited = false;
Alert(MsgSaveExportSuccessPath, path);
}
catch (Exception x)
{
@ -290,7 +296,6 @@ namespace PKHeX.WinForms
Error(MsgFileWriteFail + Environment.NewLine + x.Message, MsgFileWriteProtectedAdvice);
else throw;
}
return true;
}
/// <summary>
@ -310,14 +315,7 @@ namespace PKHeX.WinForms
return false;
string path = output.FileName;
if (File.Exists(path))
{
// File already exists, save a .bak
string bakpath = $"{path}.bak";
if (!File.Exists(bakpath))
File.Move(path, bakpath);
}
SaveBackup(path);
File.WriteAllBytes(path, gift.Data);
return true;