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
|
|
|
|
|
2020-10-18 18:02:39 +00:00
|
|
|
|
public SaveDataEditor<PictureBox> Editor { private get; set; } = null!;
|
|
|
|
|
public SlotChangeManager Manager { get; set; } = null!;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
|
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately
Don't store within the object, track the slot origin data separately.
Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.
- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code
* Remove WasLink virtual in PKM
Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.
* Use Fateful to directly check gen5 mysterygift origins
No other encounter types in gen5 apply Fateful
* Simplify double ball comparison
Used to be separate for deferral cases, now no longer needed to be separate.
* Grab move/relearn reference and update locally
Fix relearn move identifier
* Inline defog HM transfer preference check
HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.
* Extract more met location metadata checks: WasBredEgg
* Replace Console.Write* with Debug.Write*
There's no console output UI, so don't include them in release builds.
* Inline WasGiftEgg, WasEvent, and WasEventEgg logic
Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-23 03:23:48 +00:00
|
|
|
|
public Action<LegalityAnalysis>? RequestEditorLegality;
|
|
|
|
|
public delegate void LegalityRequest(object sender, EventArgs e, LegalityAnalysis la);
|
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;
|
|
|
|
|
|
2021-10-22 05:13:21 +00:00
|
|
|
|
var errata = sav.EvaluateCompatibility(pk);
|
2018-07-21 04:32:33 +00:00
|
|
|
|
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:
|
2020-11-14 16:20:48 +00:00
|
|
|
|
throw new IndexOutOfRangeException(nameof(msg));
|
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);
|
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately
Don't store within the object, track the slot origin data separately.
Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.
- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code
* Remove WasLink virtual in PKM
Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.
* Use Fateful to directly check gen5 mysterygift origins
No other encounter types in gen5 apply Fateful
* Simplify double ball comparison
Used to be separate for deferral cases, now no longer needed to be separate.
* Grab move/relearn reference and update locally
Fix relearn move identifier
* Inline defog HM transfer preference check
HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.
* Extract more met location metadata checks: WasBredEgg
* Replace Console.Write* with Debug.Write*
There's no console output UI, so don't include them in release builds.
* Inline WasGiftEgg, WasEvent, and WasEventEgg logic
Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-23 03:23:48 +00:00
|
|
|
|
var type = info.Slot is SlotInfoBox ? SlotOrigin.Box : SlotOrigin.Party;
|
|
|
|
|
var la = new LegalityAnalysis(pk, sav.Personal, type);
|
|
|
|
|
RequestEditorLegality?.Invoke(la);
|
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);
|
2020-10-18 18:02:39 +00:00
|
|
|
|
if (pb == null)
|
2020-11-14 16:20:48 +00:00
|
|
|
|
throw new InvalidCastException("Unable to find PictureBox");
|
2018-05-05 15:07:22 +00:00
|
|
|
|
var view = WinFormsUtil.FindFirstControlOfType<ISlotViewer<PictureBox>>(pb);
|
2020-10-18 18:02:39 +00:00
|
|
|
|
if (view == null)
|
2020-11-14 16:20:48 +00:00
|
|
|
|
throw new InvalidCastException("Unable to find View Parent");
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|