2017-05-23 04:55:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using PKHeX.Core;
|
|
|
|
|
|
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
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
public SaveDataEditor<PictureBox> Editor { private get; set; }
|
|
|
|
|
public SlotChangeManager Manager { get; set; }
|
|
|
|
|
|
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;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
default:
|
|
|
|
|
return;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
|
|
|
|
|
// restart hovering since the mouse event isn't fired
|
|
|
|
|
Manager.MouseEnter(sender, e);
|
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 ClickView(object sender, EventArgs e)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
var info = GetSenderInfo(ref sender);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if ((sender as PictureBox)?.Image == null)
|
|
|
|
|
{ System.Media.SystemSounds.Asterisk.Play(); return; }
|
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
Manager.Hover.Stop();
|
|
|
|
|
var pkm = Editor.Slots.Get(info.Slot);
|
|
|
|
|
Editor.PKMEditor.PopulateFields(pkm, false, true);
|
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
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
var editor = Editor.PKMEditor;
|
|
|
|
|
if (!editor.EditsComplete)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
PKM pk = editor.PreparePKM();
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
var info = GetSenderInfo(ref sender);
|
|
|
|
|
var sav = info.View.SAV;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
if (!CheckDest(info, sav, pk))
|
2017-11-18 16:42:20 +00:00
|
|
|
|
return;
|
|
|
|
|
|
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-09-03 02:30:58 +00:00
|
|
|
|
Manager.Hover.Stop();
|
|
|
|
|
Editor.Slots.Set(info.Slot, pk);
|
|
|
|
|
Manager.SE.UpdateUndoRedo();
|
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 ClickDelete(object sender, EventArgs e)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
var info = GetSenderInfo(ref sender);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if ((sender as PictureBox)?.Image == null)
|
|
|
|
|
{ System.Media.SystemSounds.Asterisk.Play(); return; }
|
2019-10-08 01:40:09 +00:00
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
var sav = info.View.SAV;
|
|
|
|
|
var pk = sav.BlankPKM;
|
|
|
|
|
if (!CheckDest(info, sav, pk))
|
|
|
|
|
return;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
Manager.Hover.Stop();
|
|
|
|
|
Editor.Slots.Delete(info.Slot);
|
|
|
|
|
Manager.SE.UpdateUndoRedo();
|
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
private static bool CheckDest(SlotViewInfo<PictureBox> info, SaveFile sav, PKM pk)
|
|
|
|
|
{
|
|
|
|
|
var msg = info.Slot.CanWriteTo(sav, pk);
|
|
|
|
|
if (msg == WriteBlockedMessage.None)
|
|
|
|
|
return true;
|
2018-07-28 16:56:13 +00:00
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
switch (msg)
|
2018-08-13 02:27:11 +00:00
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
case WriteBlockedMessage.InvalidPartyConfiguration:
|
|
|
|
|
WinFormsUtil.Alert(MsgSaveSlotEmpty);
|
|
|
|
|
break;
|
|
|
|
|
case WriteBlockedMessage.IncompatibleFormat:
|
|
|
|
|
break;
|
|
|
|
|
case WriteBlockedMessage.InvalidDestination:
|
|
|
|
|
WinFormsUtil.Alert(MsgSaveSlotLocked);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new ArgumentOutOfRangeException();
|
2018-08-13 02:27:11 +00:00
|
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
return false;
|
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 ClickShowLegality(object sender, EventArgs e)
|
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
var info = GetSenderInfo(ref sender);
|
|
|
|
|
var sav = info.View.SAV;
|
|
|
|
|
var pk = info.Slot.Read(sav);
|
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;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
var info = GetSenderInfo(ref ctrl);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
bool SlotFull = (ctrl as PictureBox)?.Image != null;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
bool Editable = info.Slot.CanWriteTo(info.View.SAV);
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
private static SlotViewInfo<PictureBox> GetSenderInfo(ref object sender)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2019-09-25 01:14:15 +00:00
|
|
|
|
var pb = WinFormsUtil.GetUnderlyingControl<PictureBox>(sender);
|
2018-05-05 15:07:22 +00:00
|
|
|
|
var view = WinFormsUtil.FindFirstControlOfType<ISlotViewer<PictureBox>>(pb);
|
2019-09-03 02:30:58 +00:00
|
|
|
|
var loc = view.GetSlotData(pb);
|
2019-09-29 02:29:15 +00:00
|
|
|
|
sender = pb;
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
return new SlotViewInfo<PictureBox>(loc, view);
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|