private static SlotViewInfo <PictureBox> GetSenderInfo(ref object sender) { var pb = WinFormsUtil.GetUnderlyingControl <PictureBox>(sender); if (pb == null) { throw new InvalidCastException("Unable to find PictureBox"); } var view = WinFormsUtil.FindFirstControlOfType <ISlotViewer <PictureBox> >(pb); if (view == null) { throw new InvalidCastException("Unable to find View Parent"); } var loc = view.GetSlotData(pb); sender = pb; return(new SlotViewInfo <PictureBox>(loc, view)); }
private static SlotViewInfo <PictureBox> GetSenderInfo(ref object sender) { var pb = WinFormsUtil.GetUnderlyingControl <PictureBox>(sender); if (pb == null) { throw new ArgumentNullException(nameof(pb)); } var view = WinFormsUtil.FindFirstControlOfType <ISlotViewer <PictureBox> >(pb); if (view == null) { throw new ArgumentNullException(nameof(view)); } var loc = view.GetSlotData(pb); sender = pb; return(new SlotViewInfo <PictureBox>(loc, view)); }
private static SlotChangeManager GetSenderInfo(ref object sender, out SlotChange loc) { loc = new SlotChange(); var ctrl = WinFormsUtil.GetUnderlyingControl(sender); var obj = ctrl.Parent.Parent; if (obj is BoxEditor b) { loc.Box = b.CurrentBox; loc.Slot = b.GetSlot(sender); loc.Offset = b.GetOffset(loc.Slot, loc.Box); loc.Parent = b.FindForm(); sender = ctrl; return(b.M); } if (obj is SlotList s) { const int shift = 44; loc.Slot = s.GetSlot(sender) + shift; loc.Offset = s.GetSlotOffset(loc.Slot - shift); loc.Parent = s.FindForm(); sender = ctrl; return(s.M); } obj = obj.Parent.Parent; if (obj is SAVEditor z) { loc.Box = z.Box.CurrentBox; loc.Slot = z.GetSlot(sender); loc.Offset = z.GetPKMOffset(loc.Slot, loc.Box); loc.Parent = z.FindForm(); sender = ctrl; return(z.M); } return(null); }
private void ClickSet(object sender, EventArgs e) { var m = GetSenderInfo(ref sender, out SlotChange info); if (m == null) { return; } var editor = m.SE.PKME_Tabs; var sav = m.SE.SAV; if (info.IsParty && editor.IsEmptyOrEgg && sav.IsPartyAllEggs(info.Slot) && !m.SE.HaX) { WinFormsUtil.Alert(MsgSaveSlotEmpty); return; } if (m.SE.SAV.IsSlotLocked(info.Box, info.Slot)) { WinFormsUtil.Alert(MsgSaveSlotLocked); return; } if (!editor.EditsComplete) { return; } PKM pk = editor.PreparePKM(); var errata = sav.IsPKMCompatible(pk); if (errata.Count > 0 && DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, string.Join(Environment.NewLine, errata), MsgContinue)) { return; } m.HoverCancel(); if (info.Type == StorageSlotType.Party) // Party { // If info.Slot isn't overwriting existing PKM, make it write to the lowest empty PKM info.Slot if (sav.PartyCount < info.Slot + 1) { var pb = (PictureBox)WinFormsUtil.GetUnderlyingControl(sender); var view = WinFormsUtil.FindFirstControlOfType <ISlotViewer <PictureBox> >(pb); info = view.GetSlotData(view.SlotPictureBoxes[sav.PartyCount]); } m.SetPKM(pk, info, true, Resources.slotSet); } else if (info.Type == StorageSlotType.Box || m.SE.HaX) { if (info.Type == StorageSlotType.Box) { m.SE.UndoStack.Push(new SlotChange(info, sav)); m.SE.Menu_Undo.Enabled = true; } m.SetPKM(pk, info, true, Resources.slotSet); } else { return; } editor.LastData = pk.Data; m.SE.RedoStack.Clear(); m.SE.Menu_Redo.Enabled = false; }
public int GetSlot(object sender) => slots.IndexOf(WinFormsUtil.GetUnderlyingControl(sender) as PictureBox);
private int GetSlot(PictureBox sender) => SlotPictureBoxes.IndexOf(WinFormsUtil.GetUnderlyingControl(sender) as PictureBox);
public int GetSlot(PictureBox sender) => slots.IndexOf(WinFormsUtil.GetUnderlyingControl <PictureBox>(sender));