2017-05-23 04:55:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using PKHeX.Core;
|
|
|
|
|
using PKHeX.WinForms.Properties;
|
|
|
|
|
|
2018-04-07 04:23:09 +00:00
|
|
|
|
using static PKHeX.Core.MessageStrings;
|
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
namespace PKHeX.WinForms.Controls
|
|
|
|
|
{
|
|
|
|
|
public partial class ContextMenuSAV : UserControl
|
|
|
|
|
{
|
2019-02-03 18:28:33 +00:00
|
|
|
|
public ContextMenuSAV() => InitializeComponent();
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2017-06-04 20:35:51 +00:00
|
|
|
|
public event LegalityRequest RequestEditorLegality;
|
2017-12-16 22:11:41 +00:00
|
|
|
|
public delegate void LegalityRequest(object sender, EventArgs e, PKM pkm);
|
2017-06-04 20:35:51 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
public void OmniClick(object sender, EventArgs e, Keys z)
|
|
|
|
|
{
|
|
|
|
|
switch (z)
|
|
|
|
|
{
|
|
|
|
|
case Keys.Control: ClickView(sender, e); break;
|
|
|
|
|
case Keys.Shift: ClickSet(sender, e); break;
|
|
|
|
|
case Keys.Alt: ClickDelete(sender, e); break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-13 02:27:11 +00:00
|
|
|
|
|
2018-04-22 05:31:11 +00:00
|
|
|
|
private void ClickView(object sender, EventArgs e)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2018-08-13 02:27:11 +00:00
|
|
|
|
var m = GetSenderInfo(ref sender, out SlotChange info);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (m == null)
|
|
|
|
|
return;
|
|
|
|
|
if ((sender as PictureBox)?.Image == null)
|
|
|
|
|
{ System.Media.SystemSounds.Asterisk.Play(); return; }
|
|
|
|
|
|
2019-08-21 02:50:28 +00:00
|
|
|
|
m.Hover.Stop();
|
2018-07-28 16:56:13 +00:00
|
|
|
|
|
2017-10-28 21:26:27 +00:00
|
|
|
|
m.SE.PKME_Tabs.PopulateFields(m.GetPKM(info), false, true);
|
2019-08-21 02:50:28 +00:00
|
|
|
|
m.SetColor(info.Box, info.Slot, SlotTouchType.Get);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-08-13 02:27:11 +00:00
|
|
|
|
|
2018-04-22 05:31:11 +00:00
|
|
|
|
private void ClickSet(object sender, EventArgs e)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2018-08-13 02:27:11 +00:00
|
|
|
|
var m = GetSenderInfo(ref sender, out SlotChange info);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (m == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var editor = m.SE.PKME_Tabs;
|
|
|
|
|
var sav = m.SE.SAV;
|
2018-05-05 15:07:22 +00:00
|
|
|
|
if (info.IsParty && editor.IsEmptyOrEgg && sav.IsPartyAllEggs(info.Slot) && !m.SE.HaX)
|
2018-04-07 04:23:09 +00:00
|
|
|
|
{ WinFormsUtil.Alert(MsgSaveSlotEmpty); return; }
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (m.SE.SAV.IsSlotLocked(info.Box, info.Slot))
|
2018-04-07 04:23:09 +00:00
|
|
|
|
{ WinFormsUtil.Alert(MsgSaveSlotLocked); return; }
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2019-02-10 01:07:44 +00:00
|
|
|
|
if (!editor.EditsComplete)
|
2017-11-18 16:42:20 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
PKM pk = editor.PreparePKM();
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2018-07-21 04:32:33 +00:00
|
|
|
|
var errata = sav.IsPKMCompatible(pk);
|
|
|
|
|
if (errata.Count > 0 && DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, string.Join(Environment.NewLine, errata), MsgContinue))
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2019-08-21 02:50:28 +00:00
|
|
|
|
m.Hover.Stop();
|
2018-07-28 16:56:13 +00:00
|
|
|
|
|
2018-05-05 15:07:22 +00:00
|
|
|
|
if (info.Type == StorageSlotType.Party) // Party
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
// If info.Slot isn't overwriting existing PKM, make it write to the lowest empty PKM info.Slot
|
2018-05-05 15:07:22 +00:00
|
|
|
|
if (sav.PartyCount < info.Slot + 1)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2018-05-05 15:07:22 +00:00
|
|
|
|
var pb = (PictureBox)WinFormsUtil.GetUnderlyingControl(sender);
|
|
|
|
|
var view = WinFormsUtil.FindFirstControlOfType<ISlotViewer<PictureBox>>(pb);
|
|
|
|
|
info = view.GetSlotData(view.SlotPictureBoxes[sav.PartyCount]);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2019-08-21 02:50:28 +00:00
|
|
|
|
m.SetPKM(pk, info, true, SlotTouchType.Set);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-05-05 15:07:22 +00:00
|
|
|
|
else if (info.Type == StorageSlotType.Box || m.SE.HaX)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2018-05-05 15:07:22 +00:00
|
|
|
|
if (info.Type == StorageSlotType.Box)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2018-03-26 02:05:49 +00:00
|
|
|
|
m.SE.UndoStack.Push(new SlotChange(info, sav));
|
2017-05-23 04:55:05 +00:00
|
|
|
|
m.SE.Menu_Undo.Enabled = true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 02:50:28 +00:00
|
|
|
|
m.SetPKM(pk, info, true, SlotTouchType.Set);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-01-31 02:52:55 +00:00
|
|
|
|
else
|
2018-08-13 02:27:11 +00:00
|
|
|
|
{
|
2018-01-31 02:52:55 +00:00
|
|
|
|
return;
|
2018-08-13 02:27:11 +00:00
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2017-06-19 05:27:40 +00:00
|
|
|
|
editor.LastData = pk.Data;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
m.SE.RedoStack.Clear(); m.SE.Menu_Redo.Enabled = false;
|
|
|
|
|
}
|
2018-08-13 02:27:11 +00:00
|
|
|
|
|
2018-04-22 05:31:11 +00:00
|
|
|
|
private void ClickDelete(object sender, EventArgs e)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2018-08-13 02:27:11 +00:00
|
|
|
|
var m = GetSenderInfo(ref sender, out SlotChange info);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (m == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if ((sender as PictureBox)?.Image == null)
|
|
|
|
|
{ System.Media.SystemSounds.Asterisk.Play(); return; }
|
|
|
|
|
|
|
|
|
|
var sav = m.SE.SAV;
|
2018-05-05 15:07:22 +00:00
|
|
|
|
if (info.IsParty && sav.IsPartyAllEggs(info.Slot) && !m.SE.HaX)
|
2018-04-07 04:23:09 +00:00
|
|
|
|
{ WinFormsUtil.Alert(MsgSaveSlotEmpty); return; }
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (sav.IsSlotLocked(info.Box, info.Slot))
|
2018-04-07 04:23:09 +00:00
|
|
|
|
{ WinFormsUtil.Alert(MsgSaveSlotLocked); return; }
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2019-08-21 02:50:28 +00:00
|
|
|
|
m.Hover.Stop();
|
2018-07-28 16:56:13 +00:00
|
|
|
|
|
2018-05-05 15:07:22 +00:00
|
|
|
|
if (info.Type == StorageSlotType.Party) // Party
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2019-08-21 02:50:28 +00:00
|
|
|
|
m.SetPKM(sav.BlankPKM, info, true, SlotTouchType.Delete);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2018-05-05 15:07:22 +00:00
|
|
|
|
if (info.Type == StorageSlotType.Box || m.SE.HaX)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2018-05-05 15:07:22 +00:00
|
|
|
|
if (info.Type == StorageSlotType.Box)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2018-03-26 02:05:49 +00:00
|
|
|
|
m.SE.UndoStack.Push(new SlotChange(info, sav));
|
2017-05-23 04:55:05 +00:00
|
|
|
|
m.SE.Menu_Undo.Enabled = true;
|
|
|
|
|
}
|
2019-08-21 02:50:28 +00:00
|
|
|
|
m.SetPKM(sav.BlankPKM, info, true, SlotTouchType.Delete);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-08-13 02:27:11 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
|
|
|
|
m.SE.RedoStack.Clear(); m.SE.Menu_Redo.Enabled = false;
|
|
|
|
|
}
|
2018-08-13 02:27:11 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
private void ClickShowLegality(object sender, EventArgs e)
|
|
|
|
|
{
|
2018-08-13 02:27:11 +00:00
|
|
|
|
var m = GetSenderInfo(ref sender, out SlotChange info);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (m == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var pk = m.GetPKM(info);
|
2017-06-04 20:35:51 +00:00
|
|
|
|
RequestEditorLegality?.Invoke(sender, e, pk);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-08-13 02:27:11 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
private void MenuOpening(object sender, CancelEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var items = ((ContextMenuStrip)sender).Items;
|
|
|
|
|
|
|
|
|
|
object ctrl = ((ContextMenuStrip)sender).SourceControl;
|
|
|
|
|
GetSenderInfo(ref ctrl, out SlotChange info);
|
|
|
|
|
bool SlotFull = (ctrl as PictureBox)?.Image != null;
|
2018-05-05 15:07:22 +00:00
|
|
|
|
bool Editable = info.Editable;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
bool legality = ModifierKeys == Keys.Control;
|
|
|
|
|
ToggleItem(items, mnuSet, Editable);
|
|
|
|
|
ToggleItem(items, mnuDelete, Editable && SlotFull);
|
2017-06-04 20:35:51 +00:00
|
|
|
|
ToggleItem(items, mnuLegality, legality && SlotFull && RequestEditorLegality != null);
|
2017-05-30 05:34:45 +00:00
|
|
|
|
ToggleItem(items, mnuView, SlotFull || !Editable, true);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
|
|
|
|
if (items.Count == 0)
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static SlotChangeManager GetSenderInfo(ref object sender, out SlotChange loc)
|
|
|
|
|
{
|
2018-05-05 15:07:22 +00:00
|
|
|
|
sender = WinFormsUtil.GetUnderlyingControl(sender);
|
|
|
|
|
var pb = (PictureBox)sender;
|
|
|
|
|
var view = WinFormsUtil.FindFirstControlOfType<ISlotViewer<PictureBox>>(pb);
|
|
|
|
|
loc = view.GetSlotData(pb);
|
|
|
|
|
return view.M;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-08-13 02:27:11 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
private static void ToggleItem(ToolStripItemCollection items, ToolStripItem item, bool visible, bool first = false)
|
|
|
|
|
{
|
|
|
|
|
if (visible)
|
|
|
|
|
{
|
|
|
|
|
if (first)
|
|
|
|
|
items.Insert(0, item);
|
|
|
|
|
else
|
|
|
|
|
items.Add(item);
|
|
|
|
|
}
|
|
|
|
|
else if (items.Contains(item))
|
2018-08-13 02:27:11 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
items.Remove(item);
|
2018-08-13 02:27:11 +00:00
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|