diff --git a/PKHeX.Core/PKM/PKM.cs b/PKHeX.Core/PKM/PKM.cs index 6eb688a0b..2a4c6e0b6 100644 --- a/PKHeX.Core/PKM/PKM.cs +++ b/PKHeX.Core/PKM/PKM.cs @@ -912,9 +912,9 @@ protected void SetLinkTradeEgg(int day, int month, int y, int location) /// Gets the PP of a Move ID with consideration of the amount of PP Ups applied. /// /// Move ID - /// PP Ups count + /// PP Ups count /// Current PP for the move. - public virtual int GetMovePP(int move, int ppup) => GetBasePP(move) * (5 + ppup) / 5; + public virtual int GetMovePP(int move, int ppUpCount) => GetBasePP(move) * (5 + ppUpCount) / 5; /// /// Gets the base PP of a move ID depending on the 's format. diff --git a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs index 04ba52605..6bb2f7a3f 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs @@ -104,13 +104,36 @@ public bool HideSecretValues public bool FieldsLoaded { get; private set; } public bool ChangingFields { get; set; } + /// + /// Currently loaded met location group that is populating Met and Egg location comboboxes + /// private GameVersion origintrack; + + /// + /// Action to perform when loading a PKM to the editor GUI. + /// private Action GetFieldsfromPKM; + + /// + /// Function that returns a from the loaded fields. + /// private Func GetPKMfromFields; + + /// + /// Latest legality check result used to show legality indication. + /// private LegalityAnalysis Legality; - private IReadOnlyList gendersymbols = GameInfo.GenderSymbolUnicode; + + /// + /// List of legal moves for the latest . + /// private readonly LegalMoveSource LegalMoveSource = new LegalMoveSource(); + /// + /// Gender Symbols for showing Genders + /// + private IReadOnlyList gendersymbols = GameInfo.GenderSymbolUnicode; + public event EventHandler LegalityChanged; public event EventHandler UpdatePreviewSprite; public event EventHandler RequestShowdownImport; @@ -256,7 +279,7 @@ private void LoadFieldsFromPKM(PKM pk, bool focus = true, bool skipConversionChe if (HaX) // Load original values from pk not pkm { - MT_Level.Text = (pk.PartyStatsPresent ? pk.Stat_Level : Experience.GetLevel(pk.EXP, pk.PersonalInfo.EXPGrowth)).ToString(); + MT_Level.Text = (pk.PartyStatsPresent ? pk.Stat_Level : pk.CurrentLevel).ToString(); TB_EXP.Text = pk.EXP.ToString(); MT_Form.Text = Math.Max(0, pk.AltForm).ToString(); if (pk.PartyStatsPresent) // stats present @@ -461,19 +484,15 @@ private void UpdateIsShiny() private void SetMarkings() { - static double getOpacity(bool b) => b ? 1 : 0.175; - static Image changeOpacity(PictureBox p, double opacity) => opacity == 1 ? p.InitialImage - : ImageUtil.ChangeOpacity(p.InitialImage, opacity); - var pba = Markings; var markings = Entity.Markings; for (int i = 0; i < pba.Length; i++) - pba[i].Image = changeOpacity(pba[i], getOpacity(markings[i] != 0)); + pba[i].Image = GetMarkSprite(pba[i], markings[i] != 0); - PB_MarkShiny.Image = changeOpacity(PB_MarkShiny, getOpacity(!BTN_Shinytize.Enabled)); - PB_MarkCured.Image = changeOpacity(PB_MarkCured, getOpacity(CHK_Cured.Checked)); + PB_MarkShiny.Image = GetMarkSprite(PB_MarkShiny, !BTN_Shinytize.Enabled); + PB_MarkCured.Image = GetMarkSprite(PB_MarkCured, CHK_Cured.Checked); - PB_Favorite.Image = changeOpacity(PB_Favorite, getOpacity(Entity is IFavorite pb7 && pb7.Favorite)); + PB_Favorite.Image = GetMarkSprite(PB_Favorite, Entity is IFavorite f && f.Favorite); PB_Origin.Image = GetOriginSprite(Entity); // Colored Markings @@ -513,18 +532,18 @@ private static Image GetOriginSprite(PKM pkm) private void UpdateGender() { - int Gender = Entity.GetSaneGender(); - Label_Gender.Text = gendersymbols[Gender]; - Label_Gender.ForeColor = Draw.GetGenderColor(Gender); + int gender = Entity.GetSaneGender(); + Label_Gender.Text = gendersymbols[gender]; + Label_Gender.ForeColor = Draw.GetGenderColor(gender); } - private static void SetCountrySubRegion(ComboBox CB, string type) + private static void SetCountrySubRegion(ComboBox cb, string type) { - int index = CB.SelectedIndex; - CB.DataSource = Util.GetCountryRegionList(type, GameInfo.CurrentLanguage); + int oldIndex = cb.SelectedIndex; + cb.DataSource = Util.GetCountryRegionList(type, GameInfo.CurrentLanguage); - if (index > 0 && index < CB.Items.Count) - CB.SelectedIndex = index; + if (oldIndex > 0 && oldIndex < cb.Items.Count) + cb.SelectedIndex = oldIndex; } // Prompted Updates of PKM // @@ -581,11 +600,11 @@ private void ClickPP(object sender, EventArgs e) private void ClickPPUps(object sender, EventArgs e) { bool min = (ModifierKeys & Keys.Control) != 0; - static int getValue(ListControl cb, bool zero) => zero || WinFormsUtil.GetIndex(cb) == 0 ? 0 : 3; - CB_PPu1.SelectedIndex = getValue(CB_Move1, min); - CB_PPu2.SelectedIndex = getValue(CB_Move2, min); - CB_PPu3.SelectedIndex = getValue(CB_Move3, min); - CB_PPu4.SelectedIndex = getValue(CB_Move4, min); + static int GetValue(ListControl cb, bool zero) => zero || WinFormsUtil.GetIndex(cb) == 0 ? 0 : 3; + CB_PPu1.SelectedIndex = GetValue(CB_Move1, min); + CB_PPu2.SelectedIndex = GetValue(CB_Move2, min); + CB_PPu3.SelectedIndex = GetValue(CB_Move3, min); + CB_PPu4.SelectedIndex = GetValue(CB_Move4, min); } private void ClickMarking(object sender, EventArgs e) @@ -1017,16 +1036,16 @@ private void UpdatePP(object sender, EventArgs e) private void RefreshMovePP(int index) { int move = WinFormsUtil.GetIndex(Moves[index]); - var ppctrl = PPUps[index]; - int ppups = ppctrl.SelectedIndex; + var ppUpControl = PPUps[index]; + int ppUpCount = ppUpControl.SelectedIndex; if (move <= 0) { - ppctrl.SelectedIndex = 0; + ppUpControl.SelectedIndex = 0; MovePP[index].Text = 0.ToString(); } else { - MovePP[index].Text = Entity.GetMovePP(move, ppups).ToString(); + MovePP[index].Text = Entity.GetMovePP(move, ppUpCount).ToString(); } } @@ -1150,15 +1169,14 @@ private void UpdateSpecies(object sender, EventArgs e) private void UpdateOriginGame(object sender, EventArgs e) { - GameVersion Version = (GameVersion)WinFormsUtil.GetIndex(CB_GameOrigin); + GameVersion version = (GameVersion)WinFormsUtil.GetIndex(CB_GameOrigin); if (FieldsLoaded) - Entity.Version = (int)Version; - - // check if differs - var group = GameUtil.GetMetLocationVersionGroup(Version); + Entity.Version = (int)version; + // Does the list of locations need to be changed to another group? + var group = GameUtil.GetMetLocationVersionGroup(version); if (group != origintrack) - ReloadMetLocations(Version); + ReloadMetLocations(version); origintrack = group; // Visibility logic for Gen 4 encounter type; only show for Gen 4 Pokemon. @@ -1177,19 +1195,13 @@ private void UpdateOriginGame(object sender, EventArgs e) UpdateLegality(); } - private void ReloadMetLocations(GameVersion Version) + private void ReloadMetLocations(GameVersion version) { - var met_list = GameInfo.GetLocationList(Version, Entity.Format, egg: false); - CB_MetLocation.DataSource = new BindingSource(met_list, null); + var metList = GameInfo.GetLocationList(version, Entity.Format, egg: false); + CB_MetLocation.DataSource = new BindingSource(metList, null); - var egg_list = GameInfo.GetLocationList(Version, Entity.Format, egg: true); - CB_EggLocation.DataSource = new BindingSource(egg_list, null); - - // Stretch C/XD met location dropdowns - int width = CB_EggLocation.DropDownWidth; - if (Version == GameVersion.CXD && Entity.Format == 3) - width *= 2; - CB_MetLocation.DropDownWidth = width; + var eggList = GameInfo.GetLocationList(version, Entity.Format, egg: true); + CB_EggLocation.DataSource = new BindingSource(eggList, null); if (FieldsLoaded) { @@ -1856,11 +1868,13 @@ private void LoadShowdownSetDefault(IBattleTemplate Set) private void CB_BattleVersion_SelectedValueChanged(object sender, EventArgs e) { - static double getOpacity(bool b) => b ? 1 : 0.175; - static Image changeOpacity(PictureBox p, double opacity) => opacity == 1 ? p.InitialImage - : ImageUtil.ChangeOpacity(p.InitialImage, opacity); + PB_BattleVersion.Image = GetMarkSprite(PB_BattleVersion, Entity is IBattleVersion b && b.BattleVersion != 0); + } - PB_BattleVersion.Image = changeOpacity(PB_BattleVersion, getOpacity(Entity is IBattleVersion b && b.BattleVersion != 0)); + private static Image GetMarkSprite(PictureBox p, bool opaque, double trans = 0.175) + { + var sprite = p.InitialImage; + return opaque ? sprite : ImageUtil.ChangeOpacity(sprite, trans); } public void ChangeLanguage(ITrainerInfo sav, PKM pk)