diff --git a/PKHeX.Core/Legality/Moves/MoveTechnicalMachine.cs b/PKHeX.Core/Legality/Moves/MoveTechnicalMachine.cs index aadc3fe35..df82fe4d6 100644 --- a/PKHeX.Core/Legality/Moves/MoveTechnicalMachine.cs +++ b/PKHeX.Core/Legality/Moves/MoveTechnicalMachine.cs @@ -139,57 +139,74 @@ private static GameVersion GetIsMachine4HM(int species, int move, int form) private static GameVersion GetIsMachine5(int species, int move, int form) { for (int i = 0; i < Legal.TMHM_BW.Length; i++) + { if (Legal.TMHM_BW[i] == move) return PersonalTable.B2W2.GetFormeEntry(species, form).TMHM[i] ? GameVersion.Gen5 : Legal.NONE; + } return Legal.NONE; } private static GameVersion GetIsMachine6(int species, int move, int form, GameVersion ver) { if (GameVersion.XY.Contains(ver)) + { for (int i = 0; i < Legal.TMHM_XY.Length; i++) - if (Legal.TMHM_XY[i] == move) - { - if (PersonalTable.XY.GetFormeEntry(species, form).TMHM[i]) - return GameVersion.XY; - break; - } + { + if (Legal.TMHM_XY[i] != move) + continue; + if (PersonalTable.XY.GetFormeEntry(species, form).TMHM[i]) + return GameVersion.XY; + break; + } + } + if (GameVersion.ORAS.Contains(ver)) + { for (int i = 0; i < Legal.TMHM_AO.Length; i++) - if (Legal.TMHM_AO[i] == move) - { - if (PersonalTable.AO.GetFormeEntry(species, form).TMHM[i]) - return GameVersion.ORAS; - break; - } + { + if (Legal.TMHM_AO[i] != move) + continue; + if (PersonalTable.AO.GetFormeEntry(species, form).TMHM[i]) + return GameVersion.ORAS; + break; + } + } + return Legal.NONE; } private static GameVersion GetIsMachine7(int species, int move, int form, GameVersion ver) { if (GameVersion.SM.Contains(ver) && species <= Legal.MaxSpeciesID_7) + { for (int i = 0; i < Legal.TMHM_XY.Length; i++) - if (Legal.TMHM_XY[i] == move) - { - if (PersonalTable.SM.GetFormeEntry(species, form).TMHM[i]) - return GameVersion.SM; - break; - } + { + if (Legal.TMHM_XY[i] != move) + continue; + if (PersonalTable.SM.GetFormeEntry(species, form).TMHM[i]) + return GameVersion.SM; + break; + } + } + if (GameVersion.ORAS.Contains(ver) && species <= Legal.MaxSpeciesID_7_USUM) + { for (int i = 0; i < Legal.TMHM_SM.Length; i++) - if (Legal.TMHM_SM[i] == move) - { - if (PersonalTable.USUM.GetFormeEntry(species, form).TMHM[i]) - return GameVersion.USUM; - break; - } + { + if (Legal.TMHM_SM[i] != move) + continue; + if (PersonalTable.USUM.GetFormeEntry(species, form).TMHM[i]) + return GameVersion.USUM; + break; + } + } + return Legal.NONE; } - internal static IEnumerable GetTMHM(PKM pkm, int species, int form, int generation, GameVersion ver = GameVersion.Any, bool RemoveTransfer = true) { - List r = new List(); + var r = new List(); switch (generation) { diff --git a/PKHeX.WinForms/Controls/PKM Editor/StatEditor.cs b/PKHeX.WinForms/Controls/PKM Editor/StatEditor.cs index 7a190ceb8..7c12c19bc 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/StatEditor.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/StatEditor.cs @@ -398,14 +398,14 @@ public void ToggleInterface(int gen) Label_SPA.Visible = false; Label_SPC.Visible = true; TB_HPIV.Enabled = false; - SetMaskSize(Stat_HP.Size, "00000"); + SetEVMaskSize(Stat_HP.Size, "00000"); break; case 2: FLP_SpD.Visible = true; Label_SPA.Visible = true; Label_SPC.Visible = false; TB_HPIV.Enabled = false; - SetMaskSize(Stat_HP.Size, "00000"); + SetEVMaskSize(Stat_HP.Size, "00000"); TB_SPDEV.Enabled = TB_SPDIV.Enabled = false; break; default: @@ -413,12 +413,12 @@ public void ToggleInterface(int gen) Label_SPA.Visible = true; Label_SPC.Visible = false; TB_HPIV.Enabled = true; - SetMaskSize(TB_EVTotal.Size, "000"); + SetEVMaskSize(TB_EVTotal.Size, "000"); TB_SPDEV.Enabled = TB_SPDIV.Enabled = true; break; } - void SetMaskSize(Size s, string Mask) + void SetEVMaskSize(Size s, string Mask) { foreach (var ctrl in MT_EVs) { diff --git a/PKHeX.WinForms/Controls/SAV Editor/BoxEditor.cs b/PKHeX.WinForms/Controls/SAV Editor/BoxEditor.cs index 6d1985d86..dc46455aa 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/BoxEditor.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/BoxEditor.cs @@ -129,7 +129,9 @@ public void ResetBoxNames(int box = -1) if (!SAV.HasBox) return; if (!SAV.Exportable) + { getBoxNamesDefault(); + } else { try { getBoxNamesFromSave(); } diff --git a/PKHeX.WinForms/Controls/SAV Editor/BoxMenuStrip.cs b/PKHeX.WinForms/Controls/SAV Editor/BoxMenuStrip.cs index baab58ea5..57c0213f6 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/BoxMenuStrip.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/BoxMenuStrip.cs @@ -39,8 +39,8 @@ public BoxMenuStrip(SAVEditor SAV) AddItem(Level.SortBox, GetItem("Random", "Random", () => Sort(list => list.OrderByCustom(_ => Util.Rand32())), Resources.wand)); AddItem(Level.SortBoxAdvanced, GetItem("Usage", "Usage", () => Sort(PKMSorting.OrderByUsage), Resources.heart), s => s.Generation >= 3); - AddItem(Level.SortBoxAdvanced, GetItem("Potential", "IV Potential", () => Sort(list => list.OrderByCustom(pk => pk.MaxIV * 6 - pk.IVTotal)), Resources.numhilo)); - AddItem(Level.SortBoxAdvanced, GetItem("Training", "EV Training", () => Sort(list => list.OrderByCustom(pk => pk.MaxEV * 6 - pk.EVTotal)), Resources.showdown)); + AddItem(Level.SortBoxAdvanced, GetItem("Potential", "IV Potential", () => Sort(list => list.OrderByCustom(pk => (pk.MaxIV * 6) - pk.IVTotal)), Resources.numhilo)); + AddItem(Level.SortBoxAdvanced, GetItem("Training", "EV Training", () => Sort(list => list.OrderByCustom(pk => (pk.MaxEV * 6) - pk.EVTotal)), Resources.showdown)); AddItem(Level.SortBoxAdvanced, GetItem("Owner", "Ownership", () => Sort(list => list.OrderByOwnership(sav.SAV)), Resources.users)); AddItem(Level.SortBoxAdvanced, GetItem("Type", "Type", () => Sort(list => list.OrderByCustom(pk => pk.PersonalInfo.Type1, pk => pk.PersonalInfo.Type2)), Resources.main)); AddItem(Level.SortBoxAdvanced, GetItem("Version", "Version", () => Sort(list => list.OrderByCustom(pk => pk.GenNumber, pk => pk.Version)), Resources.numlohi), s => s.Generation >= 3); @@ -114,6 +114,7 @@ private void AddItem(Level v, ToolStripItem t, Func visible = nu private static bool All => (ModifierKeys & Keys.Shift) != 0; private static bool Reverse => (ModifierKeys & Keys.Control) != 0; + private void Clear(Func criteria = null) { if (All) @@ -121,6 +122,7 @@ private void Clear(Func criteria = null) else sav.ClearCurrent(criteria); } + private void Sort(Func, IEnumerable> sorter) { if (All) @@ -128,6 +130,7 @@ private void Sort(Func, IEnumerable> sorter) else sav.SortCurrent(sorter, Reverse); } + private void Modify(Action action) { if (All) diff --git a/PKHeX.WinForms/Controls/SAV Editor/ContextMenuSAV.cs b/PKHeX.WinForms/Controls/SAV Editor/ContextMenuSAV.cs index 79aadf023..e7f10a85a 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/ContextMenuSAV.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/ContextMenuSAV.cs @@ -27,9 +27,10 @@ public void OmniClick(object sender, EventArgs e, Keys z) case Keys.Alt: ClickDelete(sender, e); break; } } + private void ClickView(object sender, EventArgs e) { - SlotChangeManager m = GetSenderInfo(ref sender, out SlotChange info); + var m = GetSenderInfo(ref sender, out SlotChange info); if (m == null) return; if ((sender as PictureBox)?.Image == null) @@ -40,9 +41,10 @@ private void ClickView(object sender, EventArgs e) m.SE.PKME_Tabs.PopulateFields(m.GetPKM(info), false, true); m.SetColor(info.Box, info.Slot, Resources.slotView); } + private void ClickSet(object sender, EventArgs e) { - SlotChangeManager m = GetSenderInfo(ref sender, out SlotChange info); + var m = GetSenderInfo(ref sender, out SlotChange info); if (m == null) return; @@ -86,14 +88,17 @@ private void ClickSet(object sender, EventArgs e) m.SetPKM(pk, info, true, Resources.slotSet); } else + { return; + } editor.LastData = pk.Data; m.SE.RedoStack.Clear(); m.SE.Menu_Redo.Enabled = false; } + private void ClickDelete(object sender, EventArgs e) { - SlotChangeManager m = GetSenderInfo(ref sender, out SlotChange info); + var m = GetSenderInfo(ref sender, out SlotChange info); if (m == null) return; @@ -122,19 +127,24 @@ private void ClickDelete(object sender, EventArgs e) } m.SetPKM(sav.BlankPKM, info, true, Resources.slotDel); } - else return; + else + { + return; + } m.SE.RedoStack.Clear(); m.SE.Menu_Redo.Enabled = false; } + private void ClickShowLegality(object sender, EventArgs e) { - SlotChangeManager m = GetSenderInfo(ref sender, out SlotChange info); + var m = GetSenderInfo(ref sender, out SlotChange info); if (m == null) return; var pk = m.GetPKM(info); RequestEditorLegality?.Invoke(sender, e, pk); } + private void MenuOpening(object sender, CancelEventArgs e) { var items = ((ContextMenuStrip)sender).Items; @@ -161,6 +171,7 @@ private static SlotChangeManager GetSenderInfo(ref object sender, out SlotChange loc = view.GetSlotData(pb); return view.M; } + private static void ToggleItem(ToolStripItemCollection items, ToolStripItem item, bool visible, bool first = false) { if (visible) @@ -171,7 +182,9 @@ private static void ToggleItem(ToolStripItemCollection items, ToolStripItem item items.Add(item); } else if (items.Contains(item)) + { items.Remove(item); + } } } } diff --git a/PKHeX.WinForms/Controls/SAV Editor/SlotIndex.cs b/PKHeX.WinForms/Controls/SAV Editor/SlotIndex.cs index 8ceaf6f53..389d7528d 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/SlotIndex.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/SlotIndex.cs @@ -13,7 +13,7 @@ internal enum SlotIndex public static partial class Extensions { internal static bool IsEditable(this SlotIndex type) => type == SlotIndex.Party; - internal static bool IsParty(this SlotIndex type, int format) => type < SlotIndex.BattleBox || format== 5 && type == SlotIndex.BattleBox; + internal static bool IsParty(this SlotIndex type, int format) => type < SlotIndex.BattleBox || (format == 5 && type == SlotIndex.BattleBox); internal static SlotIndex GetMiscSlotType(int slot) { @@ -21,6 +21,7 @@ internal static SlotIndex GetMiscSlotType(int slot) if (slot < (int)SlotIndex.Daycare) return SlotIndex.BattleBox; return SlotIndex.Daycare; } + internal static StorageSlotType GetMiscSlotType(this SlotIndex type) { switch (type) diff --git a/PKHeX.WinForms/Controls/SAV Editor/SlotList.cs b/PKHeX.WinForms/Controls/SAV Editor/SlotList.cs index 5b9514516..1dc30d798 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/SlotList.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/SlotList.cs @@ -51,10 +51,11 @@ public SlotChange GetSlotData(PictureBox view) Parent = FindForm(), }; } + public IList SlotPictureBoxes => slots; public int GetSlot(PictureBox sender) => slots.IndexOf(WinFormsUtil.GetUnderlyingControl(sender) as PictureBox); public int GetSlotOffset(int slot) => SlotOffsets[slot].Offset; - public bool GetSlotIsParty(int slot) => false; + public bool GetSlotIsParty(int _) => false; public int ViewIndex { get; set; } = -1; private IEnumerable LoadSlots(int after, Action enableDragDropContext) @@ -89,9 +90,11 @@ private void AddSlots(int count) for (int i = 0; i < count; i++) slots.Add(GetPictureBox(i)); } + private const int PadPixels = 2; private const int SlotWidth = 40; private const int SlotHeight = 30; + private static PictureBox GetPictureBox(int index) { return new PictureBox @@ -110,6 +113,7 @@ private class LabelType : Label { public StorageSlotType Type; } + private void AddLabels() { for (var i = 0; i < names.Length; i++) @@ -129,6 +133,7 @@ private void AddLabels() FLP_Slots.SetFlowBreak(label, true); } } + private void SetLabelVisibility() { foreach (var l in Labels) diff --git a/PKHeX.WinForms/MainWindow/Main.cs b/PKHeX.WinForms/MainWindow/Main.cs index fca0f12aa..24790a56d 100644 --- a/PKHeX.WinForms/MainWindow/Main.cs +++ b/PKHeX.WinForms/MainWindow/Main.cs @@ -836,18 +836,19 @@ private static bool TryBackupExportCheck(SaveFile sav, string path) if (sav.Exportable && Directory.Exists(BackupPath) && !File.Exists(backupName)) File.WriteAllBytes(backupName, sav.BAK); - // Check location write protection - bool locked = true; - try { locked = File.GetAttributes(path).HasFlag(FileAttributes.ReadOnly); } - catch { } - - if (!locked) + if (!IsFileLocked(path)) return true; WinFormsUtil.Alert(MsgFileWriteProtected + Environment.NewLine + path, MsgFileWriteProtectedAdvice); return false; } + private static bool IsFileLocked(string path) + { + try { return File.GetAttributes(path).HasFlag(FileAttributes.ReadOnly); } + catch { return true; } + } + private static bool SanityCheckSAV(ref SaveFile sav) { // Finish setting up the save file.