mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-22 20:13:06 +00:00
Misc updates
relocate program language enum test that test case is proper move getcompatible & gettemplate to core remove catch rate changing for pk1 (catchrate editor now used instead)
This commit is contained in:
parent
3b8974665e
commit
858760fa28
9 changed files with 142 additions and 105 deletions
|
@ -231,47 +231,4 @@ namespace PKHeX.Core
|
|||
return Strings.GetLocationList(version, pkmFormat, egg);
|
||||
}
|
||||
}
|
||||
|
||||
public enum ProgramLanguage
|
||||
{
|
||||
/// <summary>
|
||||
/// Japanese
|
||||
/// </summary>
|
||||
日本語,
|
||||
|
||||
/// <summary>
|
||||
/// English
|
||||
/// </summary>
|
||||
English,
|
||||
|
||||
/// <summary>
|
||||
/// French
|
||||
/// </summary>
|
||||
Français,
|
||||
|
||||
/// <summary>
|
||||
/// Italian
|
||||
/// </summary>
|
||||
Italiano,
|
||||
|
||||
/// <summary>
|
||||
/// German
|
||||
/// </summary>
|
||||
Deutsch,
|
||||
|
||||
/// <summary>
|
||||
/// Spanish
|
||||
/// </summary>
|
||||
Español,
|
||||
|
||||
/// <summary>
|
||||
/// Korean
|
||||
/// </summary>
|
||||
한국어,
|
||||
|
||||
/// <summary>
|
||||
/// Chinese
|
||||
/// </summary>
|
||||
中文,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -327,10 +327,12 @@ namespace PKHeX.Core
|
|||
|
||||
public MemoryStrings Memories { get; private set; }
|
||||
|
||||
// ignores Poke/Great/Ultra
|
||||
private static readonly int[] ball_nums = { 007, 576, 013, 492, 497, 014, 495, 493, 496, 494, 011, 498, 008, 006, 012, 015, 009, 005, 499, 010, 001, 016, 851 };
|
||||
private static readonly int[] ball_vals = { 007, 025, 013, 017, 022, 014, 020, 018, 021, 019, 011, 023, 008, 006, 012, 015, 009, 005, 024, 010, 001, 016, 026 };
|
||||
|
||||
private void InitializeDataSources()
|
||||
{
|
||||
int[] ball_nums = { 007, 576, 013, 492, 497, 014, 495, 493, 496, 494, 011, 498, 008, 006, 012, 015, 009, 005, 499, 010, 001, 016, 851 };
|
||||
int[] ball_vals = { 007, 025, 013, 017, 022, 014, 020, 018, 021, 019, 011, 023, 008, 006, 012, 015, 009, 005, 024, 010, 001, 016, 026 };
|
||||
BallDataSource = Util.GetVariedCBListBall(itemlist, ball_nums, ball_vals);
|
||||
SpeciesDataSource = Util.GetCBList(specieslist);
|
||||
NatureDataSource = Util.GetCBList(natures);
|
||||
|
@ -437,50 +439,57 @@ namespace PKHeX.Core
|
|||
ItemDataSource = Util.GetCBList(items, (allowed == null || HaX ? Enumerable.Range(0, MaxItemID) : allowed.Select(i => (int)i)).ToArray());
|
||||
}
|
||||
|
||||
public IReadOnlyList<ComboItem> GetLocationList(GameVersion Version, int SaveFormat, bool egg)
|
||||
/// <summary>
|
||||
/// Fetches a Met Location list for a <see cref="version"/> that has been transferred away from and overwritten.
|
||||
/// </summary>
|
||||
/// <param name="version">Origin version</param>
|
||||
/// <param name="currentGen">Current savefile generation</param>
|
||||
/// <param name="egg">True if an egg location list, false if a regular met location list</param>
|
||||
/// <returns>Met location list</returns>
|
||||
public IReadOnlyList<ComboItem> GetLocationList(GameVersion version, int currentGen, bool egg = false)
|
||||
{
|
||||
if (SaveFormat == 2)
|
||||
if (currentGen == 2)
|
||||
return MetGen2;
|
||||
|
||||
if (egg && Version < GameVersion.W && SaveFormat >= 5)
|
||||
if (egg && version < GameVersion.W && currentGen >= 5)
|
||||
return MetGen4;
|
||||
|
||||
switch (Version)
|
||||
switch (version)
|
||||
{
|
||||
case GameVersion.CXD:
|
||||
if (SaveFormat == 3)
|
||||
if (currentGen == 3)
|
||||
return MetGen3CXD;
|
||||
break;
|
||||
|
||||
case GameVersion.R:
|
||||
case GameVersion.S:
|
||||
if (SaveFormat == 3)
|
||||
if (currentGen == 3)
|
||||
return MetGen3.OrderByDescending(loc => loc.Value <= 87).ToList(); // Ferry
|
||||
break;
|
||||
case GameVersion.E:
|
||||
if (SaveFormat == 3)
|
||||
if (currentGen == 3)
|
||||
return MetGen3.OrderByDescending(loc => loc.Value <= 87 || (loc.Value >= 196 && loc.Value <= 212)).ToList(); // Trainer Hill
|
||||
break;
|
||||
case GameVersion.FR:
|
||||
case GameVersion.LG:
|
||||
if (SaveFormat == 3)
|
||||
if (currentGen == 3)
|
||||
return MetGen3.OrderByDescending(loc => loc.Value > 87 && loc.Value < 197).ToList(); // Celadon Dept.
|
||||
break;
|
||||
|
||||
case GameVersion.D:
|
||||
case GameVersion.P:
|
||||
if (SaveFormat == 4 || (SaveFormat >= 5 && egg))
|
||||
if (currentGen == 4 || (currentGen >= 5 && egg))
|
||||
return MetGen4.Take(4).Concat(MetGen4.Skip(4).OrderByDescending(loc => loc.Value <= 111)).ToList(); // Battle Park
|
||||
break;
|
||||
|
||||
case GameVersion.Pt:
|
||||
if (SaveFormat == 4 || (SaveFormat >= 5 && egg))
|
||||
if (currentGen == 4 || (currentGen >= 5 && egg))
|
||||
return MetGen4.Take(4).Concat(MetGen4.Skip(4).OrderByDescending(loc => loc.Value <= 125)).ToList(); // Rock Peak Ruins
|
||||
break;
|
||||
|
||||
case GameVersion.HG:
|
||||
case GameVersion.SS:
|
||||
if (SaveFormat == 4 || (SaveFormat >= 5 && egg))
|
||||
if (currentGen == 4 || (currentGen >= 5 && egg))
|
||||
return MetGen4.Take(4).Concat(MetGen4.Skip(4).OrderByDescending(loc => loc.Value > 125 && loc.Value < 234)).ToList(); // Celadon Dept.
|
||||
break;
|
||||
|
||||
|
@ -523,22 +532,32 @@ namespace PKHeX.Core
|
|||
return MetGen7GG.Take(3).Concat(MetGen7GG.Skip(3).OrderByDescending(loc => loc.Value <= 54)).ToList(); // Pokémon League
|
||||
}
|
||||
|
||||
// Currently on a future game, return corresponding list for generation
|
||||
if (Version <= GameVersion.CXD && SaveFormat == 4)
|
||||
return GetLocationListModified(version, currentGen);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches a Met Location list for a <see cref="version"/> that has been transferred away from and overwritten.
|
||||
/// </summary>
|
||||
/// <param name="version">Origin version</param>
|
||||
/// <param name="currentGen">Current savefile generation</param>
|
||||
/// <returns>Met location list</returns>
|
||||
private IReadOnlyList<ComboItem> GetLocationListModified(GameVersion version, int currentGen)
|
||||
{
|
||||
if (version <= GameVersion.CXD && currentGen == 4)
|
||||
{
|
||||
return MetGen4.Where(loc => loc.Value == Legal.Transfer3) // Pal Park to front
|
||||
.Concat(MetGen4.Take(4))
|
||||
.Concat(MetGen4.Skip(4).Where(loc => loc.Value != Legal.Transfer3)).ToList();
|
||||
.Concat(MetGen4.Take(4))
|
||||
.Concat(MetGen4.Skip(4).Where(loc => loc.Value != Legal.Transfer3)).ToList();
|
||||
}
|
||||
|
||||
if (Version < GameVersion.X && SaveFormat >= 5) // PokéTransfer to front
|
||||
if (version < GameVersion.X && currentGen >= 5) // PokéTransfer to front
|
||||
{
|
||||
return MetGen5.Where(loc => loc.Value == Legal.Transfer4)
|
||||
.Concat(MetGen5.Take(3))
|
||||
.Concat(MetGen5.Skip(3).Where(loc => loc.Value != Legal.Transfer4)).ToList();
|
||||
.Concat(MetGen5.Take(3))
|
||||
.Concat(MetGen5.Skip(3).Where(loc => loc.Value != Legal.Transfer4)).ToList();
|
||||
}
|
||||
|
||||
return MetGen6;
|
||||
return Array.Empty<ComboItem>();
|
||||
}
|
||||
|
||||
public static IReadOnlyList<ComboItem> LanguageDataSource(int gen)
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace PKHeX.Core
|
|||
{
|
||||
if (!sav.Exportable) // Blank save file
|
||||
{
|
||||
sav.FileFolder = sav.FilePath = null;
|
||||
sav.FileFolder = sav.FilePath = string.Empty;
|
||||
sav.FileName = "Blank Save File";
|
||||
return;
|
||||
}
|
||||
|
@ -154,5 +154,48 @@ namespace PKHeX.Core
|
|||
yield return pk;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a compatible <see cref="PKM"/> for editing with a new <see cref="SaveFile"/>.
|
||||
/// </summary>
|
||||
/// <param name="sav">SaveFile to receive the compatible <see cref="pk"/></param>
|
||||
/// <param name="pk">Current Pokémon being edited</param>
|
||||
/// <returns>Current Pokémon, assuming conversion is possible. If conversion is not possible, a blank <see cref="PKM"/> will be obtained from the <see cref="sav"/>.</returns>
|
||||
public static PKM GetCompatiblePKM(this SaveFile sav, PKM pk = null)
|
||||
{
|
||||
if (pk == null)
|
||||
return sav.BlankPKM;
|
||||
if (pk.Format < 3 && sav.Generation < 7)
|
||||
{
|
||||
// gen1-2 compatibility check
|
||||
if (pk.Japanese != sav.Japanese)
|
||||
return sav.BlankPKM;
|
||||
if (sav is SAV2 s2 && s2.Korean != pk.Korean)
|
||||
return sav.BlankPKM;
|
||||
}
|
||||
return PKMConverter.ConvertToType(pk, sav.PKMType, out _) ?? sav.BlankPKM;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a blank file for the save file. If the template path exists, a template load will be attempted.
|
||||
/// </summary>
|
||||
/// <param name="sav">Save File to fetch a template for</param>
|
||||
/// <param name="templatePath">Path to look for a template in</param>
|
||||
/// <returns>Template if it exists, or a blank <see cref="PKM"/> from the <see cref="sav"/></returns>
|
||||
public static PKM LoadTemplate(this SaveFile sav, string templatePath = null)
|
||||
{
|
||||
var blank = sav.BlankPKM;
|
||||
if (!Directory.Exists(templatePath))
|
||||
return blank;
|
||||
|
||||
var di = new DirectoryInfo(templatePath);
|
||||
string path = Path.Combine(templatePath, $"{di.Name}.{blank.Extension}");
|
||||
|
||||
if (!File.Exists(path) || !PKX.IsPKM(new FileInfo(path).Length))
|
||||
return blank;
|
||||
|
||||
var pk = PKMConverter.GetPKMfromBytes(File.ReadAllBytes(path), prefer: blank.Format);
|
||||
return PKMConverter.ConvertToType(pk, sav.BlankPKM.GetType(), out path) ?? blank; // no sneaky plz; reuse string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace PKHeX.WinForms
|
|||
|
||||
private PictureBox GetBallView(Ball b, ICollection<Ball> legal, IReadOnlyList<ComboItem> names)
|
||||
{
|
||||
var img = SpriteUtil.GetBallSprite((int) b);
|
||||
var img = SpriteUtil.GetBallSprite((int)b);
|
||||
var pb = new PictureBox
|
||||
{
|
||||
Size = img.Size,
|
||||
|
@ -45,7 +45,7 @@ namespace PKHeX.WinForms
|
|||
BackgroundImage = legal.Contains(b) ? Resources.slotSet : Resources.slotDel,
|
||||
BackgroundImageLayout = ImageLayout.Tile
|
||||
};
|
||||
pb.MouseEnter += (_, __) => Text = names.First(z => z.Value == (int) b).Text;
|
||||
pb.MouseEnter += (_, __) => Text = names.First(z => z.Value == (int)b).Text;
|
||||
pb.Click += (_, __) => SelectBall(b);
|
||||
return pb;
|
||||
}
|
||||
|
|
|
@ -1205,8 +1205,6 @@ namespace PKHeX.WinForms.Controls
|
|||
case Keys.Control: RequestShowdownImport?.Invoke(sender, e); return;
|
||||
case Keys.Alt: RequestShowdownExport?.Invoke(sender, e); return;
|
||||
default:
|
||||
if (pkm is PK1 pk1)
|
||||
pk1.Catch_Rate = pk1.PersonalInfo.CatchRate;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1466,11 +1464,8 @@ namespace PKHeX.WinForms.Controls
|
|||
FieldsLoaded = true;
|
||||
}
|
||||
|
||||
private void ValidateComboBox(object sender)
|
||||
private void ValidateComboBox(ComboBox cb)
|
||||
{
|
||||
if (!(sender is ComboBox cb))
|
||||
return;
|
||||
|
||||
if (cb.Text.Length == 0 && cb.Items.Count > 0)
|
||||
cb.SelectedIndex = 0;
|
||||
else if (cb.SelectedValue == null)
|
||||
|
@ -1481,10 +1476,10 @@ namespace PKHeX.WinForms.Controls
|
|||
|
||||
private void ValidateComboBox(object sender, CancelEventArgs e)
|
||||
{
|
||||
if (!(sender is ComboBox))
|
||||
if (!(sender is ComboBox cb))
|
||||
return;
|
||||
|
||||
ValidateComboBox(sender);
|
||||
ValidateComboBox(cb);
|
||||
UpdateSprite();
|
||||
}
|
||||
|
||||
|
@ -1522,7 +1517,7 @@ namespace PKHeX.WinForms.Controls
|
|||
if (!FieldsLoaded)
|
||||
return;
|
||||
|
||||
ValidateComboBox(sender);
|
||||
ValidateComboBox((ComboBox)sender);
|
||||
if (Moves.Contains(sender)) // Move
|
||||
UpdatePP(sender, e);
|
||||
|
||||
|
@ -1565,10 +1560,10 @@ namespace PKHeX.WinForms.Controls
|
|||
|
||||
private void ValidateLocation(object sender, EventArgs e)
|
||||
{
|
||||
ValidateComboBox(sender);
|
||||
if (!FieldsLoaded)
|
||||
return;
|
||||
|
||||
ValidateComboBox((ComboBox)sender);
|
||||
pkm.Met_Location = WinFormsUtil.GetIndex(CB_MetLocation);
|
||||
pkm.Egg_Location = WinFormsUtil.GetIndex(CB_EggLocation);
|
||||
UpdateLegality();
|
||||
|
@ -1596,7 +1591,7 @@ namespace PKHeX.WinForms.Controls
|
|||
/// <param name="pk">Pokémon data to edit</param>
|
||||
public bool ToggleInterface(SaveFile sav, PKM pk)
|
||||
{
|
||||
pkm = GetCompatiblePKM(sav, pk);
|
||||
pkm = sav.GetCompatiblePKM(pk);
|
||||
ToggleInterface(pkm);
|
||||
return FinalizeInterface(sav);
|
||||
}
|
||||
|
@ -1820,12 +1815,5 @@ namespace PKHeX.WinForms.Controls
|
|||
var abils = pkm.PersonalInfo.Abilities;
|
||||
return GameInfo.GetAbilityList(abils, pkm.Format);
|
||||
}
|
||||
|
||||
private static PKM GetCompatiblePKM(SaveFile sav, PKM current)
|
||||
{
|
||||
if (current.Format < 3 || current.GetType() != sav.PKMType)
|
||||
return sav.BlankPKM;
|
||||
return current;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -708,22 +708,6 @@ namespace PKHeX.WinForms
|
|||
}
|
||||
}
|
||||
|
||||
private static PKM LoadTemplate(SaveFile sav)
|
||||
{
|
||||
var blank = sav.BlankPKM;
|
||||
if (!Directory.Exists(TemplatePath))
|
||||
return blank;
|
||||
|
||||
var di = new DirectoryInfo(TemplatePath);
|
||||
string path = Path.Combine(TemplatePath, $"{di.Name}.{blank.Extension}");
|
||||
|
||||
if (!File.Exists(path) || !PKX.IsPKM(new FileInfo(path).Length))
|
||||
return blank;
|
||||
|
||||
var pk = PKMConverter.GetPKMfromBytes(File.ReadAllBytes(path), prefer: blank.Format);
|
||||
return PKMConverter.ConvertToType(pk, sav.BlankPKM.GetType(), out path) ?? blank; // no sneaky plz; reuse string
|
||||
}
|
||||
|
||||
private bool OpenSAV(SaveFile sav, string path)
|
||||
{
|
||||
if (sav == null || sav.Version == GameVersion.Invalid)
|
||||
|
@ -762,7 +746,7 @@ namespace PKHeX.WinForms
|
|||
bool WindowToggleRequired = C_SAV.SAV?.Generation < 3 && sav.Generation >= 3; // version combobox refresh hack
|
||||
C_SAV.SAV = sav;
|
||||
|
||||
var pk = LoadTemplate(sav);
|
||||
var pk = sav.LoadTemplate(TemplatePath);
|
||||
var isBlank = pk.Data.SequenceEqual(sav.BlankPKM.Data);
|
||||
bool init = PKME_Tabs.pkm == null;
|
||||
PKME_Tabs.CurrentPKM = pk;
|
||||
|
@ -1135,8 +1119,9 @@ namespace PKHeX.WinForms
|
|||
try
|
||||
{
|
||||
File.WriteAllBytes(newfile, dragdata);
|
||||
PictureBox pb = (PictureBox)sender;
|
||||
C_SAV.M.DragInfo.Source.PKM = pkx;
|
||||
|
||||
var pb = (PictureBox)sender;
|
||||
if (pb.Image != null)
|
||||
C_SAV.M.DragInfo.Cursor = Cursor = new Cursor(((Bitmap)pb.Image).GetHicon());
|
||||
DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Move);
|
||||
|
|
45
PKHeX.WinForms/MainWindow/ProgramLanguage.cs
Normal file
45
PKHeX.WinForms/MainWindow/ProgramLanguage.cs
Normal file
|
@ -0,0 +1,45 @@
|
|||
namespace PKHeX.WinForms
|
||||
{
|
||||
public enum ProgramLanguage
|
||||
{
|
||||
/// <summary>
|
||||
/// Japanese
|
||||
/// </summary>
|
||||
日本語,
|
||||
|
||||
/// <summary>
|
||||
/// English
|
||||
/// </summary>
|
||||
English,
|
||||
|
||||
/// <summary>
|
||||
/// French
|
||||
/// </summary>
|
||||
Français,
|
||||
|
||||
/// <summary>
|
||||
/// Italian
|
||||
/// </summary>
|
||||
Italiano,
|
||||
|
||||
/// <summary>
|
||||
/// German
|
||||
/// </summary>
|
||||
Deutsch,
|
||||
|
||||
/// <summary>
|
||||
/// Spanish
|
||||
/// </summary>
|
||||
Español,
|
||||
|
||||
/// <summary>
|
||||
/// Korean
|
||||
/// </summary>
|
||||
한국어,
|
||||
|
||||
/// <summary>
|
||||
/// Chinese
|
||||
/// </summary>
|
||||
中文,
|
||||
}
|
||||
}
|
|
@ -267,6 +267,7 @@
|
|||
<DependentUpon>PKMEditor.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="MainWindow\PluginLoader.cs" />
|
||||
<Compile Include="MainWindow\ProgramLanguage.cs" />
|
||||
<Compile Include="Misc\About.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
|
|
@ -49,8 +49,7 @@ namespace PKHeX.Tests.Legality
|
|||
|
||||
var data = File.ReadAllBytes(file);
|
||||
var format = PKX.GetPKMFormatFromExtension(file[file.Length - 1], -1);
|
||||
if (format > 10)
|
||||
format = 6;
|
||||
format.Should().BeLessOrEqualTo(PKX.Generation, "filename is expected to have a valid extension");
|
||||
var pkm = PKMConverter.GetPKMfromBytes(data, prefer: format);
|
||||
pkm.Should().NotBeNull($"the PKM '{new FileInfo(file).Name}' should have been loaded");
|
||||
|
||||
|
|
Loading…
Reference in a new issue