From da51291364b044e6dd4c00f97b1d8e0530d1c23e Mon Sep 17 00:00:00 2001 From: Kurt Date: Fri, 17 May 2024 13:18:25 -0500 Subject: [PATCH] PK1/2 edit: Use save language when detecting lang GBPKM allow spa/ita lang as fallback (so that nicknamed species just use fallback) SK2 GetNonNickname reuse the passed language ID instead of recomputing --- PKHeX.Core/PKM/SK2.cs | 2 +- PKHeX.Core/PKM/Shared/GBPKM.cs | 13 ++++++++++--- PKHeX.WinForms/Controls/PKM Editor/EditPK1.cs | 3 ++- PKHeX.WinForms/Controls/PKM Editor/EditPK2.cs | 3 ++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/PKHeX.Core/PKM/SK2.cs b/PKHeX.Core/PKM/SK2.cs index 70995cf37..e2621e789 100644 --- a/PKHeX.Core/PKM/SK2.cs +++ b/PKHeX.Core/PKM/SK2.cs @@ -137,7 +137,7 @@ public sealed class SK2 : GBPKM, ICaughtData2 protected override void GetNonNickname(int language, Span data) { var name = SpeciesName.GetSpeciesNameGeneration(Species, language, 2); - StringConverter2.SetString(data, name, data.Length, Language, StringConverterOption.Clear50); + StringConverter2.SetString(data, name, data.Length, language, StringConverterOption.Clear50); } public override void SetNotNicknamed(int language) => GetNonNickname(language, NicknameTrash); diff --git a/PKHeX.Core/PKM/Shared/GBPKM.cs b/PKHeX.Core/PKM/Shared/GBPKM.cs index 72e6cd187..5e6b6188b 100644 --- a/PKHeX.Core/PKM/Shared/GBPKM.cs +++ b/PKHeX.Core/PKM/Shared/GBPKM.cs @@ -187,12 +187,20 @@ public abstract class GBPKM : PKM public void SetNotNicknamed() => SetNotNicknamed(GuessedLanguage()); public abstract void SetNotNicknamed(int language); + public bool IsSpeciesNameMatch(int language) + { + var expect = SpeciesName.GetSpeciesNameGeneration(Species, language, 2); + Span current = stackalloc char[TrashCharCountNickname]; + int len = LoadString(NicknameTrash, current); + return current[..len].SequenceEqual(expect); + } + public int GuessedLanguage(int fallback = (int)LanguageID.English) { int lang = Language; if (lang > 0) return lang; - if (fallback is (int)LanguageID.French or (int)LanguageID.German) // only other permitted besides English + if (fallback is (int)LanguageID.French or (int)LanguageID.German or (int)LanguageID.Italian or (int)LanguageID.Spanish) // only other permitted besides English return fallback; return (int)LanguageID.English; } @@ -205,8 +213,7 @@ public abstract class GBPKM : PKM protected int TransferLanguage(int destLanguage) { // if the Species name of the destination language matches the current nickname, transfer with that language. - var expect = SpeciesName.GetSpeciesNameGeneration(Species, destLanguage, 2); - if (Nickname == expect) + if (IsSpeciesNameMatch(destLanguage)) return destLanguage; return GuessedLanguage(destLanguage); } diff --git a/PKHeX.WinForms/Controls/PKM Editor/EditPK1.cs b/PKHeX.WinForms/Controls/PKM Editor/EditPK1.cs index 54a249d48..e6cf97fc4 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/EditPK1.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/EditPK1.cs @@ -15,7 +15,8 @@ public partial class PKMEditor CR_PK1.LoadPK1(pk1); // Attempt to detect language - CB_Language.SelectedValue = pk1.GuessedLanguage(); + var language = RequestSaveFile.Language; + CB_Language.SelectedValue = pk1.IsSpeciesNameMatch(language) ? language : pk1.GuessedLanguage(language); LoadPartyStats(pk1); UpdateStats(); diff --git a/PKHeX.WinForms/Controls/PKM Editor/EditPK2.cs b/PKHeX.WinForms/Controls/PKM Editor/EditPK2.cs index 7b435a6f3..3946e223f 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/EditPK2.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/EditPK2.cs @@ -24,7 +24,8 @@ public partial class PKMEditor CB_MetTimeOfDay.SelectedIndex = c2.MetTimeOfDay; // Attempt to detect language - CB_Language.SelectedValue = pk2.GuessedLanguage(); + var language = RequestSaveFile.Language; + CB_Language.SelectedValue = pk2.IsSpeciesNameMatch(language) ? language : pk2.GuessedLanguage(language); LoadPartyStats(pk2); UpdateStats();