2017-05-23 04:55:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Media;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using PKHeX.Core;
|
|
|
|
|
using PKHeX.WinForms.Properties;
|
2018-04-06 04:25:18 +00:00
|
|
|
|
using static PKHeX.Core.MessageStrings;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.WinForms.Controls
|
|
|
|
|
{
|
2018-05-13 19:49:26 +00:00
|
|
|
|
public partial class SAVEditor : UserControl, ISlotViewer<PictureBox>, ISaveFileProvider
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2018-05-13 19:49:26 +00:00
|
|
|
|
public SaveFile SAV { get; set; }
|
|
|
|
|
public int CurrentBox => Box.CurrentBox;
|
2018-05-05 15:07:22 +00:00
|
|
|
|
public SlotChangeManager M { get; }
|
2017-05-23 04:55:05 +00:00
|
|
|
|
public readonly Stack<SlotChange> UndoStack = new Stack<SlotChange>();
|
|
|
|
|
public readonly Stack<SlotChange> RedoStack = new Stack<SlotChange>();
|
2017-06-04 20:35:51 +00:00
|
|
|
|
public readonly ContextMenuSAV menu = new ContextMenuSAV();
|
2018-05-24 01:29:30 +00:00
|
|
|
|
public readonly BoxMenuStrip SortMenu;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2019-02-02 07:08:03 +00:00
|
|
|
|
public bool HaX;
|
2018-08-20 01:22:07 +00:00
|
|
|
|
public bool ModifyPKM { private get; set; }
|
|
|
|
|
private bool _hideSecret;
|
2018-12-20 06:10:32 +00:00
|
|
|
|
public bool HideSecretDetails { private get => _hideSecret; set { if (SAV != null) ToggleSecrets(SAV, _hideSecret = value); } }
|
2017-05-23 04:55:05 +00:00
|
|
|
|
public ToolStripMenuItem Menu_Redo;
|
|
|
|
|
public ToolStripMenuItem Menu_Undo;
|
|
|
|
|
private bool FieldsLoaded;
|
|
|
|
|
public PKMEditor PKME_Tabs;
|
|
|
|
|
|
2018-05-05 15:07:22 +00:00
|
|
|
|
public SlotChange GetSlotData(PictureBox view)
|
|
|
|
|
{
|
|
|
|
|
int slot = GetSlot(view);
|
|
|
|
|
var type = Extensions.GetMiscSlotType(slot);
|
|
|
|
|
return new SlotChange
|
|
|
|
|
{
|
|
|
|
|
Slot = GetSlot(view),
|
|
|
|
|
Box = ViewIndex,
|
|
|
|
|
Offset = GetSlotOffset(slot),
|
|
|
|
|
Parent = FindForm(),
|
|
|
|
|
Type = type.GetMiscSlotType(),
|
|
|
|
|
Editable = type.IsEditable(),
|
|
|
|
|
IsPartyFormat = type.IsParty(SAV.Generation)
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2018-05-05 15:07:22 +00:00
|
|
|
|
public IList<PictureBox> SlotPictureBoxes { get; }
|
|
|
|
|
public int GetSlot(PictureBox sender) => SlotPictureBoxes.IndexOf(WinFormsUtil.GetUnderlyingControl(sender) as PictureBox);
|
|
|
|
|
public int ViewIndex { get; set; } = -1;
|
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
public bool FlagIllegal
|
|
|
|
|
{
|
|
|
|
|
get => Box.FlagIllegal;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Box.FlagIllegal = value && !HaX;
|
2018-12-20 06:10:32 +00:00
|
|
|
|
if (SAV != null)
|
|
|
|
|
ReloadSlots();
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2018-01-03 01:08:14 +00:00
|
|
|
|
public void ReloadSlots()
|
|
|
|
|
{
|
|
|
|
|
UpdateBoxViewers(all: true);
|
|
|
|
|
ResetNonBoxSlots();
|
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2018-01-03 07:00:52 +00:00
|
|
|
|
public SAVEditor()
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2018-07-07 18:20:05 +00:00
|
|
|
|
|
|
|
|
|
L_SlotOccupied = new[] { L_DC1, L_DC2 };
|
|
|
|
|
TB_SlotEXP = new[] { TB_Daycare1XP, TB_Daycare2XP };
|
|
|
|
|
L_SlotEXP = new[] { L_XP1, L_XP2 };
|
2018-05-05 15:07:22 +00:00
|
|
|
|
SlotPictureBoxes = new[]
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
ppkx1, ppkx2, ppkx3, ppkx4, ppkx5, ppkx6,
|
|
|
|
|
bbpkx1, bbpkx2, bbpkx3, bbpkx4, bbpkx5, bbpkx6,
|
|
|
|
|
|
2018-01-31 02:52:55 +00:00
|
|
|
|
dcpkx1, dcpkx2
|
2017-05-23 04:55:05 +00:00
|
|
|
|
};
|
2018-12-20 06:10:32 +00:00
|
|
|
|
Tab_Box.ContextMenuStrip = SortMenu = new BoxMenuStrip(this);
|
2017-06-30 06:48:25 +00:00
|
|
|
|
Box.Setup(M = new SlotChangeManager(this));
|
2018-01-31 02:52:55 +00:00
|
|
|
|
SL_Extra.M = M;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2018-09-03 01:02:25 +00:00
|
|
|
|
M.OtherSlots.Add(this);
|
|
|
|
|
SL_Extra.ViewIndex = -2;
|
|
|
|
|
M.OtherSlots.Add(SL_Extra);
|
|
|
|
|
InitializeEvents();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitializeEvents()
|
|
|
|
|
{
|
2018-05-05 15:07:22 +00:00
|
|
|
|
foreach (PictureBox pb in Box.SlotPictureBoxes)
|
|
|
|
|
pb.ContextMenuStrip = menu.mnuVSD;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
foreach (PictureBox pb in SlotPictureBoxes)
|
2018-05-05 15:07:22 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeDragDrop(pb);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
pb.ContextMenuStrip = menu.mnuVSD;
|
2018-05-05 15:07:22 +00:00
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2018-09-03 01:02:25 +00:00
|
|
|
|
GiveFeedback += (sender, e) => e.UseDefaultCursors = false;
|
2018-07-26 02:29:41 +00:00
|
|
|
|
Tab_Box.MouseWheel += (s, e) =>
|
|
|
|
|
{
|
2018-08-15 02:39:14 +00:00
|
|
|
|
if (menu.mnuVSD.Visible)
|
2018-08-12 18:01:21 +00:00
|
|
|
|
return;
|
2018-07-26 02:29:41 +00:00
|
|
|
|
if (e.Delta > 1)
|
|
|
|
|
Box.MoveLeft();
|
|
|
|
|
else
|
|
|
|
|
Box.MoveRight();
|
|
|
|
|
};
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
GB_Daycare.Click += SwitchDaycare;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
FLP_SAVtools.Scroll += WinFormsUtil.PanelScroll;
|
2018-06-17 00:03:22 +00:00
|
|
|
|
SortMenu.Opening += (s, x) => x.Cancel = !tabBoxMulti.GetTabRect(tabBoxMulti.SelectedIndex).Contains(PointToClient(MousePosition));
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2018-01-31 02:52:55 +00:00
|
|
|
|
private void InitializeDragDrop(Control pb)
|
|
|
|
|
{
|
|
|
|
|
pb.MouseEnter += M.MouseEnter;
|
|
|
|
|
pb.MouseLeave += M.MouseLeave;
|
|
|
|
|
pb.MouseClick += M.MouseClick;
|
2018-05-11 23:38:09 +00:00
|
|
|
|
pb.MouseMove += M.MouseMove;
|
2018-01-31 02:52:55 +00:00
|
|
|
|
pb.MouseDown += M.MouseDown;
|
|
|
|
|
pb.MouseUp += M.MouseUp;
|
|
|
|
|
|
|
|
|
|
pb.DragEnter += M.DragEnter;
|
2018-05-11 23:38:09 +00:00
|
|
|
|
pb.DragDrop += M.DragDrop;
|
2018-01-31 02:52:55 +00:00
|
|
|
|
pb.QueryContinueDrag += M.QueryContinueDrag;
|
|
|
|
|
pb.GiveFeedback += (sender, e) => e.UseDefaultCursors = false;
|
|
|
|
|
pb.AllowDrop = true;
|
|
|
|
|
pb.ContextMenuStrip = menu.mnuVSD;
|
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>Occurs when the Control Collection requests a cloning operation to the current box.</summary>
|
|
|
|
|
public event EventHandler RequestCloneData;
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
/// <summary>Occurs when the Control Collection requests a save to be reloaded.</summary>
|
|
|
|
|
public event EventHandler RequestReloadSave;
|
|
|
|
|
|
|
|
|
|
public Cursor GetDefaultCursor => DefaultCursor;
|
|
|
|
|
private Image GetSprite(PKM p, int slot) => p.Sprite(SAV, Box.CurrentBox, slot, Box.FlagIllegal);
|
|
|
|
|
|
|
|
|
|
public void EnableDragDrop(DragEventHandler enter, DragEventHandler drop)
|
|
|
|
|
{
|
|
|
|
|
AllowDrop = true;
|
|
|
|
|
DragDrop += drop;
|
|
|
|
|
foreach (TabPage tab in tabBoxMulti.TabPages)
|
|
|
|
|
{
|
|
|
|
|
tab.AllowDrop = true;
|
|
|
|
|
tab.DragEnter += enter;
|
|
|
|
|
tab.DragDrop += drop;
|
|
|
|
|
}
|
2017-05-31 02:17:37 +00:00
|
|
|
|
M.RequestExternalDragDrop += drop;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
// Generic Subfunctions //
|
2018-05-05 15:07:22 +00:00
|
|
|
|
public int GetSlotOffset(int slot)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2018-01-21 23:30:57 +00:00
|
|
|
|
if (slot < (int)SlotIndex.BattleBox) // Party Slot
|
|
|
|
|
return SAV.GetPartyOffset(slot - (int)SlotIndex.Party);
|
|
|
|
|
if (slot < (int)SlotIndex.Daycare) // Battle Box Slot
|
2018-08-03 03:11:42 +00:00
|
|
|
|
return SAV.BattleBox + ((slot - (int)SlotIndex.BattleBox) * SAV.SIZE_STORED);
|
2018-05-05 15:07:22 +00:00
|
|
|
|
return SAV.GetDaycareSlotOffset(SAV.DaycareIndex, slot - (int)SlotIndex.Daycare);
|
2018-01-31 02:52:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public int SwapBoxesViewer(int viewBox)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
int mainBox = Box.CurrentBox;
|
|
|
|
|
Box.CurrentBox = viewBox;
|
|
|
|
|
return mainBox;
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public void UpdateBoxViewers(bool all = false)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
foreach (var v in M.Boxes.Where(v => v.CurrentBox == Box.CurrentBox || all))
|
|
|
|
|
{
|
|
|
|
|
v.FlagIllegal = Box.FlagIllegal;
|
|
|
|
|
v.ResetSlots();
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public void SetPKMBoxes()
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
if (SAV.HasBox)
|
|
|
|
|
Box.ResetSlots();
|
|
|
|
|
|
2017-09-07 05:11:08 +00:00
|
|
|
|
ResetNonBoxSlots();
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2017-09-07 05:11:08 +00:00
|
|
|
|
// Recoloring of a storage box slot (to not show for other storage boxes)
|
2018-05-19 23:33:06 +00:00
|
|
|
|
if (M?.ColorizedSlot >= (int)SlotIndex.Party && M.ColorizedSlot < SlotPictureBoxes.Count)
|
2018-01-30 01:52:21 +00:00
|
|
|
|
SlotPictureBoxes[M.ColorizedSlot].BackgroundImage = M.ColorizedColor;
|
2017-09-07 05:11:08 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-09-07 05:11:08 +00:00
|
|
|
|
private void ResetNonBoxSlots()
|
|
|
|
|
{
|
|
|
|
|
ResetParty();
|
|
|
|
|
ResetBattleBox();
|
|
|
|
|
ResetDaycare();
|
|
|
|
|
ResetMiscSlots();
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-09-07 05:11:08 +00:00
|
|
|
|
private void ResetMiscSlots()
|
|
|
|
|
{
|
2018-01-31 02:52:55 +00:00
|
|
|
|
var slots = SL_Extra.SlotPictureBoxes;
|
|
|
|
|
for (int i = 0; i < SL_Extra.SlotCount; i++)
|
|
|
|
|
GetSlotFiller(SL_Extra.GetSlotOffset(i), slots[i]);
|
2017-09-07 05:11:08 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-09-07 05:11:08 +00:00
|
|
|
|
private void ResetParty()
|
|
|
|
|
{
|
|
|
|
|
if (!SAV.HasParty)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 6; i++)
|
2018-01-21 23:30:57 +00:00
|
|
|
|
GetSlotFiller(SAV.GetPartyOffset(i), SlotPictureBoxes[i + (int)SlotIndex.Party]);
|
2017-09-07 05:11:08 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-09-07 05:11:08 +00:00
|
|
|
|
private void ResetBattleBox()
|
|
|
|
|
{
|
|
|
|
|
if (!SAV.HasBattleBox)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 6; i++)
|
2018-08-03 03:11:42 +00:00
|
|
|
|
GetSlotFiller(SAV.BattleBox + (SAV.SIZE_STORED * i), SlotPictureBoxes[i + (int)SlotIndex.BattleBox]);
|
2017-09-07 05:11:08 +00:00
|
|
|
|
}
|
2018-07-07 18:20:05 +00:00
|
|
|
|
|
|
|
|
|
private readonly Label[] L_SlotOccupied;
|
|
|
|
|
private readonly TextBox[] TB_SlotEXP;
|
|
|
|
|
private readonly Label[] L_SlotEXP;
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-09-07 05:11:08 +00:00
|
|
|
|
private void ResetDaycare()
|
|
|
|
|
{
|
|
|
|
|
if (!SAV.HasDaycare)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
|
{
|
2018-01-21 23:30:57 +00:00
|
|
|
|
var pb = SlotPictureBoxes[i + (int)SlotIndex.Daycare];
|
|
|
|
|
GetSlotFiller(SAV.GetDaycareSlotOffset(SAV.DaycareIndex, i), pb);
|
2017-09-07 05:11:08 +00:00
|
|
|
|
uint? exp = SAV.GetDaycareEXP(SAV.DaycareIndex, i);
|
|
|
|
|
TB_SlotEXP[i].Visible = L_SlotEXP[i].Visible = exp != null;
|
|
|
|
|
TB_SlotEXP[i].Text = exp.ToString();
|
|
|
|
|
bool? occ = SAV.IsDaycareOccupied(SAV.DaycareIndex, i);
|
|
|
|
|
L_SlotOccupied[i].Visible = occ != null;
|
|
|
|
|
if (occ == true) // If Occupied
|
2018-08-03 03:11:42 +00:00
|
|
|
|
{
|
2017-09-07 05:11:08 +00:00
|
|
|
|
L_SlotOccupied[i].Text = $"{i + 1}: ✓";
|
2018-08-03 03:11:42 +00:00
|
|
|
|
}
|
2017-09-07 05:11:08 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
L_SlotOccupied[i].Text = $"{i + 1}: ✘";
|
2018-01-21 23:30:57 +00:00
|
|
|
|
pb.Image = ImageUtil.ChangeOpacity(pb.Image, 0.6);
|
2017-09-07 05:11:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool? egg = SAV.IsDaycareHasEgg(SAV.DaycareIndex);
|
|
|
|
|
DayCare_HasEgg.Visible = egg != null;
|
|
|
|
|
DayCare_HasEgg.Checked = egg == true;
|
|
|
|
|
|
|
|
|
|
var seed = SAV.GetDaycareRNGSeed(SAV.DaycareIndex);
|
|
|
|
|
if (seed != null)
|
|
|
|
|
{
|
|
|
|
|
TB_RNGSeed.MaxLength = SAV.DaycareSeedSize;
|
|
|
|
|
TB_RNGSeed.Text = seed;
|
|
|
|
|
}
|
|
|
|
|
L_DaycareSeed.Visible = TB_RNGSeed.Visible = seed != null;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2018-08-13 02:28:35 +00:00
|
|
|
|
public void SetParty() => ResetParty();
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public void ClickUndo()
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2018-05-12 19:28:48 +00:00
|
|
|
|
if (UndoStack.Count == 0)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
SlotChange change = UndoStack.Pop();
|
2018-07-16 13:40:35 +00:00
|
|
|
|
if (change.Box < 0)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
RedoStack.Push(new SlotChange
|
|
|
|
|
{
|
|
|
|
|
Slot = change.Slot,
|
|
|
|
|
Box = change.Box,
|
|
|
|
|
Offset = change.Offset,
|
2017-06-18 01:37:19 +00:00
|
|
|
|
PKM = SAV.GetStoredSlot(change.Offset)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
});
|
2017-06-18 01:37:19 +00:00
|
|
|
|
UndoSlotChange(change);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
M.SetColor(change.Box, change.Slot, Resources.slotSet);
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public void ClickRedo()
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2018-05-12 19:28:48 +00:00
|
|
|
|
if (RedoStack.Count == 0)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
SlotChange change = RedoStack.Pop();
|
2018-07-16 13:40:35 +00:00
|
|
|
|
if (change.Box < 0)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
UndoStack.Push(new SlotChange
|
|
|
|
|
{
|
|
|
|
|
Slot = change.Slot,
|
|
|
|
|
Box = change.Box,
|
|
|
|
|
Offset = change.Offset,
|
2017-06-18 01:37:19 +00:00
|
|
|
|
PKM = SAV.GetStoredSlot(change.Offset)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
});
|
2017-06-18 01:37:19 +00:00
|
|
|
|
UndoSlotChange(change);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
M.SetColor(change.Box, change.Slot, Resources.slotSet);
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
public void SetClonesToBox(PKM pk)
|
|
|
|
|
{
|
2018-07-07 18:20:05 +00:00
|
|
|
|
if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, string.Format(MsgSaveBoxCloneFromTabs, Box.CurrentBoxName)) != DialogResult.Yes)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2018-07-07 18:20:05 +00:00
|
|
|
|
int slotSkipped = SetClonesToCurrentBox(pk, Box.CurrentBox);
|
|
|
|
|
if (slotSkipped > 0)
|
|
|
|
|
WinFormsUtil.Alert(string.Format(MsgSaveBoxImportSkippedLocked, slotSkipped));
|
|
|
|
|
|
|
|
|
|
UpdateBoxViewers();
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2018-07-07 18:20:05 +00:00
|
|
|
|
private int SetClonesToCurrentBox(PKM pk, int box)
|
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
int slotSkipped = 0;
|
|
|
|
|
for (int i = 0; i < SAV.BoxSlotCount; i++) // set to every slot in box
|
|
|
|
|
{
|
2018-12-05 06:59:28 +00:00
|
|
|
|
if (SAV.IsSlotOverwriteProtected(box, i))
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{ slotSkipped++; continue; }
|
2018-07-07 18:20:05 +00:00
|
|
|
|
SAV.SetStoredSlot(pk, Box.GetSlotOffset(box, i));
|
|
|
|
|
Box.SetSlotFiller(pk, box, i);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-07 18:20:05 +00:00
|
|
|
|
return slotSkipped;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public void ClickSlot(object sender, EventArgs e)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
switch (ModifierKeys)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
case Keys.Control | Keys.Alt: ClickClone(sender, e); break;
|
2018-07-07 18:20:05 +00:00
|
|
|
|
default: // forward to contextmenu for default behavior
|
2017-05-23 04:55:05 +00:00
|
|
|
|
menu.OmniClick(sender, e, ModifierKeys);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void UndoSlotChange(SlotChange change)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
int box = change.Box;
|
|
|
|
|
int slot = change.Slot;
|
|
|
|
|
int offset = change.Offset;
|
|
|
|
|
PKM pk = change.PKM;
|
|
|
|
|
|
|
|
|
|
if (Box.CurrentBox != change.Box)
|
|
|
|
|
Box.CurrentBox = change.Box;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SAV.SetStoredSlot(pk, offset);
|
|
|
|
|
Box.SetSlotFiller(pk, box, slot);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
M?.SetColor(box, slot, Resources.slotSet);
|
|
|
|
|
|
|
|
|
|
if (Menu_Undo != null)
|
2018-05-12 19:28:48 +00:00
|
|
|
|
Menu_Undo.Enabled = UndoStack.Count > 0;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (Menu_Redo != null)
|
2018-05-12 19:28:48 +00:00
|
|
|
|
Menu_Redo.Enabled = RedoStack.Count > 0;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
|
|
|
|
SystemSounds.Asterisk.Play();
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void GetSlotFiller(int offset, PictureBox pb)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2018-03-18 23:22:21 +00:00
|
|
|
|
if (!SAV.IsPKMPresent(offset))
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
pb.Image = null;
|
|
|
|
|
pb.BackColor = Color.Transparent;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
PKM p = SAV.GetStoredSlot(offset);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (!p.Valid) // Invalid
|
|
|
|
|
{
|
|
|
|
|
// Bad Egg present in slot.
|
|
|
|
|
pb.Image = null;
|
|
|
|
|
pb.BackColor = Color.Red;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int slot = GetSlot(pb);
|
2018-08-13 02:28:35 +00:00
|
|
|
|
pb.Image = GetSprite(p, slot < 6 ? -1 : slot);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
pb.BackColor = Color.Transparent;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-21 23:31:41 +00:00
|
|
|
|
private void ClickBoxSort(object sender, MouseEventArgs e)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2018-04-24 01:55:58 +00:00
|
|
|
|
if (tabBoxMulti.SelectedTab != Tab_Box)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return;
|
2018-04-21 23:31:41 +00:00
|
|
|
|
if (!tabBoxMulti.GetTabRect(tabBoxMulti.SelectedIndex).Contains(PointToClient(MousePosition)))
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return;
|
2018-04-24 01:55:58 +00:00
|
|
|
|
if (!e.Button.HasFlag(MouseButtons.Right))
|
|
|
|
|
{
|
|
|
|
|
if (ModifierKeys.HasFlag(Keys.Alt))
|
2018-09-02 18:31:34 +00:00
|
|
|
|
SortMenu.Clear();
|
2018-04-24 01:55:58 +00:00
|
|
|
|
else if (ModifierKeys.HasFlag(Keys.Control))
|
2018-09-02 18:31:34 +00:00
|
|
|
|
SortMenu.Sort();
|
2018-04-24 01:55:58 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2018-04-21 23:31:41 +00:00
|
|
|
|
var pt = Tab_Box.PointToScreen(new Point(0, 0));
|
|
|
|
|
SortMenu.Show(pt);
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2018-09-02 18:31:34 +00:00
|
|
|
|
public void FinishBoxManipulation(string message, bool all)
|
2018-04-21 23:31:41 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetPKMBoxes();
|
|
|
|
|
UpdateBoxViewers(all);
|
2018-04-22 19:43:18 +00:00
|
|
|
|
if (message != null)
|
|
|
|
|
WinFormsUtil.Alert(message);
|
2018-09-02 18:31:34 +00:00
|
|
|
|
else
|
|
|
|
|
SystemSounds.Asterisk.Play();
|
2018-04-21 23:31:41 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickBoxDouble(object sender, MouseEventArgs e)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
if (tabBoxMulti.SelectedTab == Tab_SAV)
|
|
|
|
|
{
|
|
|
|
|
RequestReloadSave?.Invoke(sender, e);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (tabBoxMulti.SelectedTab != Tab_Box)
|
|
|
|
|
return;
|
|
|
|
|
if (!SAV.HasBox)
|
|
|
|
|
return;
|
2018-01-23 05:38:42 +00:00
|
|
|
|
if (ModifierKeys == Keys.Shift)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
if (M.Boxes.Count > 1) // subview open
|
2018-01-23 05:38:42 +00:00
|
|
|
|
{
|
|
|
|
|
// close all subviews
|
|
|
|
|
for (int i = 1; i < M.Boxes.Count; i++)
|
2018-07-07 18:20:05 +00:00
|
|
|
|
M.Boxes[i].ParentForm?.Close();
|
2018-01-23 05:38:42 +00:00
|
|
|
|
}
|
|
|
|
|
new SAV_BoxList(this, M).Show();
|
|
|
|
|
return;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-01-23 05:38:42 +00:00
|
|
|
|
if (M.Boxes.Count > 1) // subview open
|
|
|
|
|
{ var z = M.Boxes[1].ParentForm; z.CenterToForm(ParentForm); z.BringToFront(); return; }
|
2017-05-23 04:55:05 +00:00
|
|
|
|
new SAV_BoxViewer(this, M).Show();
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickClone(object sender, EventArgs e)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2018-05-05 15:07:22 +00:00
|
|
|
|
if (GetSlot((PictureBox)sender) >= 0)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return; // only perform action if cloning to boxes
|
|
|
|
|
RequestCloneData?.Invoke(sender, e);
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void UpdateSaveSlot(object sender, EventArgs e)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
if (SAV.Version != GameVersion.BATREV)
|
|
|
|
|
return;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
((SAV4BR)SAV).CurrentSlot = WinFormsUtil.GetIndex(CB_SaveSlot);
|
2018-05-23 02:02:56 +00:00
|
|
|
|
Box.ResetBoxNames(); // fix box names
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetPKMBoxes();
|
2018-05-19 23:39:01 +00:00
|
|
|
|
UpdateBoxViewers(true);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void UpdateStringSeed(object sender, EventArgs e)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
if (!FieldsLoaded)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-05-12 19:28:48 +00:00
|
|
|
|
if (!(sender is TextBox tb))
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2018-07-07 18:20:05 +00:00
|
|
|
|
if (string.IsNullOrWhiteSpace(tb.Text))
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
tb.Undo();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
string filterText = Util.GetOnlyHex(tb.Text);
|
2019-02-02 07:08:03 +00:00
|
|
|
|
if (string.IsNullOrWhiteSpace(filterText) || filterText.Length != tb.Text.Length)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2018-04-06 04:25:18 +00:00
|
|
|
|
WinFormsUtil.Alert(MsgProgramErrorExpectedHex, tb.Text);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
tb.Undo();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Write final value back to the save
|
|
|
|
|
if (tb == TB_RNGSeed)
|
|
|
|
|
{
|
|
|
|
|
var value = filterText.PadLeft(SAV.DaycareSeedSize, '0');
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SAV.SetDaycareRNGSeed(SAV.DaycareIndex, value);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
SAV.Edited = true;
|
|
|
|
|
}
|
|
|
|
|
else if (tb == TB_GameSync)
|
|
|
|
|
{
|
|
|
|
|
var value = filterText.PadLeft(SAV.GameSyncIDSize, '0');
|
|
|
|
|
SAV.GameSyncID = value;
|
|
|
|
|
SAV.Edited = true;
|
|
|
|
|
}
|
2018-12-19 01:15:35 +00:00
|
|
|
|
else if (SAV is ISecureValueStorage s)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
var value = Convert.ToUInt64(filterText, 16);
|
|
|
|
|
if (tb == TB_Secure1)
|
2018-12-19 01:15:35 +00:00
|
|
|
|
s.TimeStampCurrent = value;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
else if (tb == TB_Secure2)
|
2018-12-19 01:15:35 +00:00
|
|
|
|
s.TimeStampPrevious = value;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
SAV.Edited = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void SwitchDaycare(object sender, EventArgs e)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2018-05-20 03:48:03 +00:00
|
|
|
|
if (!SAV.HasTwoDaycares)
|
|
|
|
|
return;
|
|
|
|
|
var current = string.Format(MsgSaveSwitchDaycareCurrent, SAV.DaycareIndex + 1);
|
|
|
|
|
if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgSaveSwitchDaycareView, current))
|
|
|
|
|
return;
|
|
|
|
|
SAV.DaycareIndex ^= 1;
|
|
|
|
|
ResetDaycare();
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
private void B_SaveBoxBin_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!SAV.HasBox)
|
2018-04-07 04:23:09 +00:00
|
|
|
|
{ WinFormsUtil.Alert(MsgSaveBoxFailNone); return; }
|
2017-05-23 04:55:05 +00:00
|
|
|
|
Box.SaveBoxBinary();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Subfunction Save Buttons //
|
|
|
|
|
private void B_OpenWondercards_Click(object sender, EventArgs e) => new SAV_Wondercard(SAV, sender as MysteryGift).ShowDialog();
|
|
|
|
|
private void B_OpenPokepuffs_Click(object sender, EventArgs e) => new SAV_Pokepuff(SAV).ShowDialog();
|
|
|
|
|
private void B_OpenPokeBeans_Click(object sender, EventArgs e) => new SAV_Pokebean(SAV).ShowDialog();
|
|
|
|
|
private void B_OpenItemPouch_Click(object sender, EventArgs e) => new SAV_Inventory(SAV).ShowDialog();
|
|
|
|
|
private void B_OpenBerryField_Click(object sender, EventArgs e) => new SAV_BerryFieldXY(SAV).ShowDialog();
|
|
|
|
|
private void B_OpenPokeblocks_Click(object sender, EventArgs e) => new SAV_PokeBlockORAS(SAV).ShowDialog();
|
|
|
|
|
private void B_OpenSuperTraining_Click(object sender, EventArgs e) => new SAV_SuperTrain(SAV).ShowDialog();
|
|
|
|
|
private void B_OpenSecretBase_Click(object sender, EventArgs e) => new SAV_SecretBase(SAV).ShowDialog();
|
2017-11-12 06:48:22 +00:00
|
|
|
|
private void B_CellsStickers_Click(object sender, EventArgs e) => new SAV_ZygardeCell(SAV).ShowDialog();
|
2017-05-23 04:55:05 +00:00
|
|
|
|
private void B_LinkInfo_Click(object sender, EventArgs e) => new SAV_Link6(SAV).ShowDialog();
|
2017-10-11 01:48:14 +00:00
|
|
|
|
private void B_Roamer_Click(object sender, EventArgs e) => new SAV_Roamer3(SAV).ShowDialog();
|
2017-12-18 17:36:53 +00:00
|
|
|
|
private void B_OpenApricorn_Click(object sender, EventArgs e) => new SAV_Apricorn(SAV).ShowDialog();
|
2018-07-07 18:20:05 +00:00
|
|
|
|
private void B_CGearSkin_Click(object sender, EventArgs e) => new SAV_CGearSkin(SAV).ShowDialog();
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-09-26 06:06:16 +00:00
|
|
|
|
private void B_OpenEventFlags_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2018-11-14 03:23:31 +00:00
|
|
|
|
Form form;
|
|
|
|
|
switch (SAV)
|
|
|
|
|
{
|
|
|
|
|
case SAV1 s:
|
|
|
|
|
form = new SAV_EventReset1(s);
|
|
|
|
|
break;
|
|
|
|
|
case SAV7b s:
|
|
|
|
|
form = new SAV_EventWork(s);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
form = new SAV_EventFlags(SAV);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-09-26 06:06:16 +00:00
|
|
|
|
form.ShowDialog();
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
private void B_OpenBoxLayout_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
new SAV_BoxLayout(SAV, Box.CurrentBox).ShowDialog();
|
|
|
|
|
Box.ResetBoxNames(); // fix box names
|
|
|
|
|
Box.ResetSlots(); // refresh box background
|
2017-06-18 01:37:19 +00:00
|
|
|
|
UpdateBoxViewers(all: true); // update subviewers
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
private void B_OpenTrainerInfo_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (SAV.Generation < 6)
|
|
|
|
|
new SAV_SimpleTrainer(SAV).ShowDialog();
|
|
|
|
|
else if (SAV.Generation == 6)
|
|
|
|
|
new SAV_Trainer(SAV).ShowDialog();
|
2018-06-30 16:59:48 +00:00
|
|
|
|
else if (SAV is SAV7)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
new SAV_Trainer7(SAV).ShowDialog();
|
2018-11-14 03:23:31 +00:00
|
|
|
|
else if (SAV is SAV7b b)
|
|
|
|
|
new SAV_Trainer7GG(b).ShowDialog();
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
private void B_OpenOPowers_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (SAV.Generation != 6)
|
|
|
|
|
return;
|
2018-06-10 04:04:34 +00:00
|
|
|
|
new SAV_OPower((SAV6)SAV).ShowDialog();
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
private void B_OpenFriendSafari_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!SAV.XY)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-04-06 04:25:18 +00:00
|
|
|
|
var dr = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgSaveGen6FriendSafari, MsgSaveGen6FriendSafariCheatDesc);
|
2018-07-07 18:20:05 +00:00
|
|
|
|
if (dr == DialogResult.Yes)
|
|
|
|
|
((SAV6)SAV).UnlockAllFriendSafariSlots();
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-07-07 18:20:05 +00:00
|
|
|
|
|
|
|
|
|
private static Form GetPokeDexEditor(SaveFile sav)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2018-07-07 18:20:05 +00:00
|
|
|
|
switch (sav)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2018-07-07 18:20:05 +00:00
|
|
|
|
case SAV1 s1: return new SAV_SimplePokedex(s1);
|
|
|
|
|
case SAV2 s2: return new SAV_SimplePokedex(s2);
|
|
|
|
|
case SAV3 s3: return new SAV_SimplePokedex(s3);
|
|
|
|
|
case SAV4 s4: return new SAV_Pokedex4(s4);
|
|
|
|
|
case SAV5 s5: return new SAV_Pokedex5(s5);
|
|
|
|
|
case SAV6 s6 when s6.XY: return new SAV_PokedexXY(s6);
|
|
|
|
|
case SAV6 s6 when s6.ORAS: return new SAV_PokedexORAS(s6);
|
|
|
|
|
case SAV7 s7 when s7.SM || s7.USUM: return new SAV_PokedexSM(s7);
|
2018-11-14 03:23:31 +00:00
|
|
|
|
case SAV7b b7: return new SAV_PokedexGG(b7);
|
2018-07-07 18:20:05 +00:00
|
|
|
|
|
|
|
|
|
default: return null;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2018-07-07 18:20:05 +00:00
|
|
|
|
private void B_OpenPokedex_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var editor = GetPokeDexEditor(SAV);
|
|
|
|
|
editor?.ShowDialog();
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
private void B_OpenMiscEditor_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
switch (SAV.Generation)
|
|
|
|
|
{
|
2018-05-20 03:48:03 +00:00
|
|
|
|
case 3: new SAV_Misc3(SAV).ShowDialog(); break;
|
|
|
|
|
case 4: new SAV_Misc4(SAV).ShowDialog(); break;
|
|
|
|
|
case 5: new SAV_Misc5(SAV).ShowDialog(); break;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
private void B_OpenRTCEditor_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
switch (SAV.Generation)
|
|
|
|
|
{
|
2017-09-24 05:13:48 +00:00
|
|
|
|
case 2:
|
2018-04-06 04:25:18 +00:00
|
|
|
|
WinFormsUtil.Alert(string.Format(MsgSaveGen2RTCResetPassword, ((SAV2) SAV).ResetKey)); break;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
case 3:
|
|
|
|
|
new SAV_RTC3(SAV).ShowDialog(); break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
private void B_OpenHoneyTreeEditor_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
switch (SAV.Version)
|
|
|
|
|
{
|
|
|
|
|
case GameVersion.DP:
|
|
|
|
|
case GameVersion.Pt:
|
|
|
|
|
new SAV_HoneyTree(SAV).ShowDialog(); break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
private void B_OUTPasserby_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (SAV.Generation != 6)
|
|
|
|
|
return;
|
2018-04-06 04:25:18 +00:00
|
|
|
|
if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgSaveGen6Passerby))
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return;
|
2018-07-07 18:20:05 +00:00
|
|
|
|
var result = PSS6.GetPSSParse((SAV6)SAV);
|
2017-09-30 05:58:25 +00:00
|
|
|
|
Clipboard.SetText(string.Join(Environment.NewLine, result));
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
private void B_OUTHallofFame_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (SAV.Generation == 6)
|
|
|
|
|
new SAV_HallOfFame(SAV).ShowDialog();
|
2018-06-30 16:59:48 +00:00
|
|
|
|
else if (SAV is SAV7)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
new SAV_HallOfFame7(SAV).ShowDialog();
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
private void B_JPEG_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
byte[] jpeg = SAV.JPEGData;
|
2019-02-02 07:26:43 +00:00
|
|
|
|
if (SAV.JPEGData.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
WinFormsUtil.Alert(MsgSaveJPEGExportFail);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
string filename = SAV.JPEGTitle + "'s picture";
|
2019-02-02 07:26:43 +00:00
|
|
|
|
var sfd = new SaveFileDialog { FileName = filename, Filter = "JPEG|*.jpeg" };
|
|
|
|
|
if (sfd.ShowDialog() != DialogResult.OK)
|
|
|
|
|
return;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
File.WriteAllBytes(sfd.FileName, jpeg);
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickVerifyCHK(object sender, EventArgs e)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2018-04-06 04:25:18 +00:00
|
|
|
|
if (SAV.Edited) { WinFormsUtil.Alert(MsgSaveChecksumFailEdited); return; }
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2018-04-06 04:25:18 +00:00
|
|
|
|
if (SAV.ChecksumsValid) { WinFormsUtil.Alert(MsgSaveChecksumValid); return; }
|
|
|
|
|
if (DialogResult.Yes == WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgSaveChecksumFailExport))
|
2017-05-23 04:55:05 +00:00
|
|
|
|
Clipboard.SetText(SAV.ChecksumInfo);
|
|
|
|
|
}
|
2018-02-02 01:29:07 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
// File I/O
|
2018-12-29 01:58:13 +00:00
|
|
|
|
public bool GetBulkImportSettings(out bool clearAll, out bool overwrite, out bool? noSetb)
|
2018-02-02 01:29:07 +00:00
|
|
|
|
{
|
2018-12-29 01:58:13 +00:00
|
|
|
|
clearAll = false; noSetb = false; overwrite = false;
|
2018-04-06 04:25:18 +00:00
|
|
|
|
var dr = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel, MsgSaveBoxImportClear, MsgSaveBoxImportClearNo);
|
2018-02-02 01:29:07 +00:00
|
|
|
|
if (dr == DialogResult.Cancel)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
clearAll = dr == DialogResult.Yes;
|
2018-09-03 01:02:25 +00:00
|
|
|
|
noSetb = GetPKMSetOverride(ModifyPKM);
|
2018-02-02 01:29:07 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static bool IsFolderPath(out string path)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
FolderBrowserDialog fbd = new FolderBrowserDialog();
|
|
|
|
|
var result = fbd.ShowDialog() == DialogResult.OK;
|
|
|
|
|
path = fbd.SelectedPath;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ExportSaveFile()
|
|
|
|
|
{
|
|
|
|
|
ValidateChildren();
|
2018-11-15 06:20:59 +00:00
|
|
|
|
bool reload = SAV is SAV7b b && b.FixPreWrite();
|
|
|
|
|
if (reload)
|
|
|
|
|
ReloadSlots();
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return WinFormsUtil.SaveSAVDialog(SAV, SAV.CurrentBox);
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
public bool ExportBackup()
|
|
|
|
|
{
|
|
|
|
|
if (!SAV.Exportable)
|
|
|
|
|
return false;
|
2018-06-30 16:59:48 +00:00
|
|
|
|
var sfd = new SaveFileDialog {FileName = Util.CleanFileName(SAV.BAKName)};
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (sfd.ShowDialog() != DialogResult.OK)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
string path = sfd.FileName;
|
|
|
|
|
File.WriteAllBytes(path, SAV.BAK);
|
2018-04-06 04:25:18 +00:00
|
|
|
|
WinFormsUtil.Alert(MsgSaveBackup, path);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
public bool OpenPCBoxBin(byte[] input, out string c)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (SAV.PCBinary.Length == input.Length)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (SAV.IsAnySlotLockedInBox(0, SAV.BoxCount - 1))
|
2018-04-06 04:25:18 +00:00
|
|
|
|
{ c = MsgSaveBoxImportPCFailBattle; return false; }
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (!SAV.SetPCBinary(input))
|
2018-04-06 04:25:18 +00:00
|
|
|
|
{ c = string.Format(MsgSaveCurrentGeneration, SAV.Generation); return false; }
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2018-04-06 04:25:18 +00:00
|
|
|
|
c = MsgSaveBoxImportPCBinary;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
else if (SAV.GetBoxBinary(Box.CurrentBox).Length == input.Length)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (SAV.IsAnySlotLockedInBox(Box.CurrentBox, Box.CurrentBox))
|
2018-04-06 04:25:18 +00:00
|
|
|
|
{ c = MsgSaveBoxImportBoxFailBattle; return false; }
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (!SAV.SetBoxBinary(input, Box.CurrentBox))
|
2018-04-06 04:25:18 +00:00
|
|
|
|
{ c = string.Format(MsgSaveCurrentGeneration, SAV.Generation); return false; }
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2018-04-06 04:25:18 +00:00
|
|
|
|
c = MsgSaveBoxImportBoxBinary;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-04-06 04:25:18 +00:00
|
|
|
|
c = string.Format(MsgSaveCurrentGeneration, SAV.Generation);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetPKMBoxes();
|
|
|
|
|
UpdateBoxViewers();
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
public bool OpenBattleVideo(BattleVideo b, out string c)
|
|
|
|
|
{
|
|
|
|
|
if (b == null || SAV.Generation != b.Generation)
|
|
|
|
|
{
|
2018-04-06 04:25:18 +00:00
|
|
|
|
c = MsgSaveBoxImportVideoFailGeneration;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-06 04:25:18 +00:00
|
|
|
|
var prompt = WinFormsUtil.Prompt(MessageBoxButtons.YesNo,
|
|
|
|
|
string.Format(MsgSaveBoxImportVideo, Box.CurrentBoxName), MsgSaveBoxImportOverwrite);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (prompt != DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
c = string.Empty;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-03 01:02:25 +00:00
|
|
|
|
bool? noSetb = GetPKMSetOverride(ModifyPKM);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
PKM[] data = b.BattlePKMs;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int offset = SAV.GetBoxOffset(Box.CurrentBox);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
int slotSkipped = 0;
|
|
|
|
|
for (int i = 0; i < 24; i++)
|
|
|
|
|
{
|
2018-12-05 06:59:28 +00:00
|
|
|
|
if (SAV.IsSlotOverwriteProtected(Box.CurrentBox, i))
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{ slotSkipped++; continue; }
|
2018-08-03 03:11:42 +00:00
|
|
|
|
SAV.SetStoredSlot(data[i], offset + (i * SAV.SIZE_STORED), noSetb);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetPKMBoxes();
|
|
|
|
|
UpdateBoxViewers();
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2018-04-06 04:25:18 +00:00
|
|
|
|
c = slotSkipped > 0 ? string.Format(MsgSaveBoxImportSkippedLocked, slotSkipped) : MsgSaveBoxImportVideoSuccess;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
public bool DumpBoxes(out string result, string path = null, bool separate = false)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (path == null && !IsFolderPath(out path))
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
result = path;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-03 06:13:40 +00:00
|
|
|
|
Directory.CreateDirectory(path);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2019-02-10 04:19:55 +00:00
|
|
|
|
var count = SAV.DumpBoxes(path, separate);
|
|
|
|
|
if (count < 0)
|
|
|
|
|
result = MsgSaveBoxExportInvalid;
|
|
|
|
|
else
|
|
|
|
|
result = string.Format(MsgSaveBoxExportPathCount, count) + Environment.NewLine + path;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
public bool DumpBox(out string result, string path = null)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (path == null && !IsFolderPath(out path))
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
result = path;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-03 06:13:40 +00:00
|
|
|
|
Directory.CreateDirectory(path);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2019-02-10 04:19:55 +00:00
|
|
|
|
var count = SAV.DumpBox(path, Box.CurrentBox);
|
|
|
|
|
if (count < 0)
|
|
|
|
|
result = MsgSaveBoxExportInvalid;
|
|
|
|
|
else
|
|
|
|
|
result = string.Format(MsgSaveBoxExportPathCount, count) + Environment.NewLine + path;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
public bool LoadBoxes(out string result, string path = null)
|
|
|
|
|
{
|
|
|
|
|
result = string.Empty;
|
|
|
|
|
if (!SAV.HasBox)
|
|
|
|
|
return false;
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (path == null && !IsFolderPath(out path))
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
result = path;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(path))
|
|
|
|
|
return false;
|
|
|
|
|
|
2018-12-29 01:58:13 +00:00
|
|
|
|
if (!GetBulkImportSettings(out bool clearAll, out var overwrite, out var noSetb))
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2018-12-29 01:58:13 +00:00
|
|
|
|
SAV.LoadBoxes(path, out result, Box.CurrentBox, clearAll, overwrite, noSetb);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetPKMBoxes();
|
2017-08-27 01:37:44 +00:00
|
|
|
|
UpdateBoxViewers();
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ToggleInterface()
|
|
|
|
|
{
|
|
|
|
|
FieldsLoaded = false;
|
|
|
|
|
|
2017-06-19 05:27:40 +00:00
|
|
|
|
ToggleViewReset();
|
|
|
|
|
ToggleViewSubEditors(SAV);
|
|
|
|
|
|
|
|
|
|
bool WindowTranslationRequired = false;
|
|
|
|
|
WindowTranslationRequired |= ToggleViewBox(SAV);
|
2017-12-30 00:50:55 +00:00
|
|
|
|
int BoxTab = tabBoxMulti.TabPages.IndexOf(Tab_Box);
|
2017-06-19 05:27:40 +00:00
|
|
|
|
WindowTranslationRequired |= ToggleViewParty(SAV, BoxTab);
|
2017-12-30 00:50:55 +00:00
|
|
|
|
int PartyTab = tabBoxMulti.TabPages.IndexOf(Tab_PartyBattle);
|
2017-06-19 05:27:40 +00:00
|
|
|
|
WindowTranslationRequired |= ToggleViewDaycare(SAV, BoxTab, PartyTab);
|
2017-09-22 04:42:27 +00:00
|
|
|
|
SetPKMBoxes(); // Reload all of the PKX Windows
|
2017-06-19 05:27:40 +00:00
|
|
|
|
|
|
|
|
|
ToggleViewMisc(SAV);
|
|
|
|
|
|
|
|
|
|
FieldsLoaded = true;
|
|
|
|
|
return WindowTranslationRequired;
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-19 05:27:40 +00:00
|
|
|
|
private void ToggleViewReset()
|
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
// Close subforms that are save dependent
|
|
|
|
|
foreach (var z in M.Boxes.Skip(1).ToArray())
|
|
|
|
|
z.FindForm()?.Close();
|
|
|
|
|
|
|
|
|
|
UndoStack.Clear();
|
|
|
|
|
RedoStack.Clear();
|
|
|
|
|
Box.M = M;
|
|
|
|
|
Box.ResetBoxNames(); // Display the Box Names
|
|
|
|
|
M.SetColor(-1, -1, null);
|
2018-05-24 01:29:30 +00:00
|
|
|
|
SortMenu.ToggleVisibility();
|
2017-06-19 05:27:40 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-19 05:27:40 +00:00
|
|
|
|
private bool ToggleViewBox(SaveFile sav)
|
|
|
|
|
{
|
|
|
|
|
if (!sav.HasBox)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2017-06-19 05:27:40 +00:00
|
|
|
|
if (tabBoxMulti.TabPages.Contains(Tab_Box))
|
|
|
|
|
tabBoxMulti.TabPages.Remove(Tab_Box);
|
|
|
|
|
B_SaveBoxBin.Enabled = false;
|
|
|
|
|
return false;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2017-06-19 05:27:40 +00:00
|
|
|
|
|
|
|
|
|
B_SaveBoxBin.Enabled = true;
|
|
|
|
|
int startBox = !sav.Exportable ? 0 : sav.CurrentBox; // FF if BattleBox
|
|
|
|
|
if (startBox > sav.BoxCount - 1) { tabBoxMulti.SelectedIndex = 1; Box.CurrentBox = 0; }
|
|
|
|
|
else { tabBoxMulti.SelectedIndex = 0; Box.CurrentBox = startBox; }
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2017-06-19 05:27:40 +00:00
|
|
|
|
if (tabBoxMulti.TabPages.Contains(Tab_Box))
|
|
|
|
|
return false;
|
|
|
|
|
tabBoxMulti.TabPages.Insert(0, Tab_Box);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-19 05:27:40 +00:00
|
|
|
|
private bool ToggleViewParty(SaveFile sav, int BoxTab)
|
|
|
|
|
{
|
2019-01-05 23:40:25 +00:00
|
|
|
|
if (!sav.HasParty || !sav.Exportable)
|
2017-06-19 05:27:40 +00:00
|
|
|
|
{
|
|
|
|
|
if (tabBoxMulti.TabPages.Contains(Tab_PartyBattle))
|
|
|
|
|
tabBoxMulti.TabPages.Remove(Tab_PartyBattle);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PB_Locked.Visible = sav.HasBattleBox && sav.BattleBoxLocked;
|
|
|
|
|
if (tabBoxMulti.TabPages.Contains(Tab_PartyBattle))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
int index = BoxTab;
|
|
|
|
|
if (index < 0)
|
|
|
|
|
index = -1;
|
|
|
|
|
tabBoxMulti.TabPages.Insert(index + 1, Tab_PartyBattle);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-19 05:27:40 +00:00
|
|
|
|
private bool ToggleViewDaycare(SaveFile sav, int BoxTab, int PartyTab)
|
|
|
|
|
{
|
2019-01-05 23:40:25 +00:00
|
|
|
|
if (!sav.HasDaycare || !sav.Exportable)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2017-06-19 05:27:40 +00:00
|
|
|
|
if (tabBoxMulti.TabPages.Contains(Tab_Other))
|
|
|
|
|
tabBoxMulti.TabPages.Remove(Tab_Other);
|
|
|
|
|
return false;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-05 15:07:22 +00:00
|
|
|
|
SlotPictureBoxes[(int)SlotIndex.Daycare + 1].Visible = sav.Generation >= 2; // Second daycare slot
|
2017-06-19 05:27:40 +00:00
|
|
|
|
if (tabBoxMulti.TabPages.Contains(Tab_Other))
|
|
|
|
|
return false;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2017-06-19 05:27:40 +00:00
|
|
|
|
int index = PartyTab;
|
|
|
|
|
if (index < 0)
|
|
|
|
|
index = BoxTab;
|
|
|
|
|
if (index < 0)
|
|
|
|
|
index = -1;
|
|
|
|
|
tabBoxMulti.TabPages.Insert(index + 1, Tab_Other);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-19 05:27:40 +00:00
|
|
|
|
private void ToggleViewSubEditors(SaveFile sav)
|
|
|
|
|
{
|
2018-02-24 21:03:32 +00:00
|
|
|
|
if (!sav.Exportable || sav is BulkStorage)
|
|
|
|
|
{
|
|
|
|
|
GB_SAVtools.Visible = false;
|
|
|
|
|
B_JPEG.Visible = false;
|
|
|
|
|
SL_Extra.HideAllSlots();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-19 05:27:40 +00:00
|
|
|
|
{
|
|
|
|
|
PAN_BattleBox.Visible = L_BattleBox.Visible = L_ReadOnlyPBB.Visible = sav.HasBattleBox;
|
|
|
|
|
GB_Daycare.Visible = sav.HasDaycare;
|
|
|
|
|
B_OpenSecretBase.Enabled = sav.HasSecretBase;
|
2018-12-19 01:15:35 +00:00
|
|
|
|
B_OpenPokepuffs.Enabled = sav is IPokePuff p && p.HasPuffData;
|
2017-06-19 05:27:40 +00:00
|
|
|
|
B_OUTPasserby.Enabled = sav.HasPSS;
|
2017-12-27 23:52:29 +00:00
|
|
|
|
B_OpenBoxLayout.Enabled = sav.HasNamableBoxes;
|
2017-06-19 05:27:40 +00:00
|
|
|
|
B_OpenWondercards.Enabled = sav.HasWondercards;
|
|
|
|
|
B_OpenSuperTraining.Enabled = sav.HasSuperTrain;
|
|
|
|
|
B_OpenHallofFame.Enabled = sav.HasHoF;
|
|
|
|
|
B_OpenOPowers.Enabled = sav.HasOPower;
|
|
|
|
|
B_OpenPokedex.Enabled = sav.HasPokeDex;
|
|
|
|
|
B_OpenBerryField.Enabled = sav.HasBerryField && sav.XY;
|
|
|
|
|
B_OpenFriendSafari.Enabled = sav.XY;
|
|
|
|
|
B_OpenPokeblocks.Enabled = sav.HasPokeBlock;
|
|
|
|
|
B_JPEG.Visible = sav.HasJPEG;
|
|
|
|
|
B_OpenEventFlags.Enabled = sav.HasEvents;
|
|
|
|
|
B_OpenLinkInfo.Enabled = sav.HasLink;
|
|
|
|
|
B_CGearSkin.Enabled = sav.Generation == 5;
|
2018-06-30 16:59:48 +00:00
|
|
|
|
B_OpenPokeBeans.Enabled = B_CellsStickers.Enabled = B_FestivalPlaza.Enabled = sav is SAV7;
|
2017-06-19 05:27:40 +00:00
|
|
|
|
|
2018-12-11 04:32:08 +00:00
|
|
|
|
B_OpenTrainerInfo.Enabled = B_OpenItemPouch.Enabled = (sav.HasParty && !(SAV is SAV4BR)) || SAV is SAV7b; // Box RS & Battle Revolution
|
2017-06-19 05:27:40 +00:00
|
|
|
|
B_OpenMiscEditor.Enabled = sav is SAV3 || sav is SAV4 || sav is SAV5;
|
2017-10-11 01:48:14 +00:00
|
|
|
|
B_Roamer.Enabled = sav is SAV3;
|
2017-06-19 05:27:40 +00:00
|
|
|
|
|
|
|
|
|
B_OpenHoneyTreeEditor.Enabled = sav.DP || sav.Pt;
|
2017-12-18 17:36:53 +00:00
|
|
|
|
B_OpenApricorn.Enabled = sav.HGSS;
|
2017-09-24 05:13:48 +00:00
|
|
|
|
B_OpenRTCEditor.Enabled = sav.RS || sav.E || sav.Generation == 2;
|
2017-08-27 20:52:47 +00:00
|
|
|
|
B_OpenUGSEditor.Enabled = sav.DP || sav.Pt;
|
2018-02-01 04:21:47 +00:00
|
|
|
|
B_MailBox.Enabled = sav is SAV2 || sav is SAV3 || sav is SAV4 || sav is SAV5;
|
2018-01-31 02:52:55 +00:00
|
|
|
|
|
2018-05-05 15:07:22 +00:00
|
|
|
|
SL_Extra.Initialize(sav.GetExtraSlots(HaX), InitializeDragDrop);
|
2018-01-31 02:52:55 +00:00
|
|
|
|
}
|
2018-06-30 16:59:48 +00:00
|
|
|
|
GB_SAVtools.Visible = sav.Exportable && FLP_SAVtools.Controls.OfType<Control>().Any(c => c.Enabled);
|
2018-07-07 18:20:05 +00:00
|
|
|
|
foreach (Control c in FLP_SAVtools.Controls.OfType<Control>())
|
2017-05-23 04:55:05 +00:00
|
|
|
|
c.Visible = c.Enabled;
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-19 05:27:40 +00:00
|
|
|
|
private void ToggleViewMisc(SaveFile sav)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
// Generational Interface
|
2018-08-20 01:22:07 +00:00
|
|
|
|
ToggleSecrets(sav, HideSecretDetails);
|
2017-06-19 05:27:40 +00:00
|
|
|
|
B_VerifyCHK.Enabled = SAV.Exportable;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2018-05-20 03:48:03 +00:00
|
|
|
|
if (sav is SAV4BR br)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
L_SaveSlot.Visible = CB_SaveSlot.Visible = true;
|
2018-08-04 17:06:06 +00:00
|
|
|
|
var list = br.SaveNames.Select((z, i) => new ComboItem {Text = z, Value = i}).ToList();
|
2018-07-14 23:00:28 +00:00
|
|
|
|
CB_SaveSlot.InitializeBinding();
|
2018-05-20 03:48:03 +00:00
|
|
|
|
CB_SaveSlot.DataSource = new BindingSource(list, null);
|
|
|
|
|
CB_SaveSlot.SelectedValue = br.CurrentSlot;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2018-08-04 17:06:06 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
L_SaveSlot.Visible = CB_SaveSlot.Visible = false;
|
2018-08-04 17:06:06 +00:00
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2018-12-19 01:15:35 +00:00
|
|
|
|
if (sav is ISecureValueStorage s)
|
|
|
|
|
{
|
|
|
|
|
TB_Secure1.Text = s.TimeStampCurrent.ToString("X16");
|
|
|
|
|
TB_Secure2.Text = s.TimeStampPrevious.ToString("X16");
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-19 05:27:40 +00:00
|
|
|
|
switch (sav.Generation)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
case 6:
|
|
|
|
|
case 7:
|
2017-06-19 05:27:40 +00:00
|
|
|
|
TB_GameSync.Enabled = sav.GameSyncID != null;
|
|
|
|
|
TB_GameSync.MaxLength = sav.GameSyncIDSize;
|
|
|
|
|
TB_GameSync.Text = (sav.GameSyncID ?? 0.ToString()).PadLeft(sav.GameSyncIDSize, '0');
|
2017-05-23 04:55:05 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-20 01:22:07 +00:00
|
|
|
|
private void ToggleSecrets(SaveFile sav, bool hide)
|
|
|
|
|
{
|
|
|
|
|
TB_Secure1.Visible = TB_Secure2.Visible = L_Secure1.Visible = L_Secure2.Visible = sav.Exportable && sav.Generation >= 6 && !hide;
|
|
|
|
|
TB_GameSync.Visible = L_GameSync.Visible = sav.Exportable && sav.Generation >= 6 && !hide;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
// DragDrop
|
2017-09-15 16:13:08 +00:00
|
|
|
|
private void MultiDragOver(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// iterate over all tabs to see if a tab switch should occur when drag/dropping
|
|
|
|
|
Point pt = tabBoxMulti.PointToClient(new Point(e.X, e.Y));
|
|
|
|
|
for (int i = 0; i < tabBoxMulti.TabCount; i++)
|
|
|
|
|
{
|
|
|
|
|
if (tabBoxMulti.SelectedIndex == i || !tabBoxMulti.GetTabRect(i).Contains(pt))
|
|
|
|
|
continue;
|
|
|
|
|
tabBoxMulti.SelectedIndex = i;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-19 03:02:49 +00:00
|
|
|
|
|
2018-09-03 01:02:25 +00:00
|
|
|
|
public void ClickShowdownExportParty(object sender, EventArgs e) => ExportShowdownText(SAV, MsgSimulatorExportParty, sav => sav.PartyData);
|
|
|
|
|
public void ClickShowdownExportBattleBox(object sender, EventArgs e) => ExportShowdownText(SAV, MsgSimulatorExportBattleBox, sav => sav.BattleBoxData);
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2018-06-17 04:56:16 +00:00
|
|
|
|
public void ClickShowdownExportCurrentBox(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!SAV.HasBox)
|
|
|
|
|
return;
|
2018-09-03 01:02:25 +00:00
|
|
|
|
ExportShowdownText(SAV, MsgSimulatorExportList,
|
|
|
|
|
sav => (ModifierKeys & Keys.Control) != 0 ? sav.BoxData : sav.GetBoxData(CurrentBox));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void ExportShowdownText(SaveFile SAV, string success, Func<SaveFile, IEnumerable<PKM>> func)
|
|
|
|
|
{
|
2018-06-17 04:56:16 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2018-09-03 01:02:25 +00:00
|
|
|
|
var pkms = func(SAV);
|
|
|
|
|
var str = ShowdownSet.GetShowdownSets(pkms, Environment.NewLine + Environment.NewLine);
|
2018-06-17 04:56:16 +00:00
|
|
|
|
if (string.IsNullOrWhiteSpace(str)) return;
|
|
|
|
|
Clipboard.SetText(str);
|
2019-02-02 07:08:03 +00:00
|
|
|
|
WinFormsUtil.Alert(success);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2019-02-02 23:20:08 +00:00
|
|
|
|
WinFormsUtil.Error(MsgClipboardFailWrite);
|
2018-06-17 04:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-27 19:32:43 +00:00
|
|
|
|
|
|
|
|
|
private void B_OpenUGSEditor_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
switch (SAV.Version)
|
|
|
|
|
{
|
|
|
|
|
case GameVersion.DP:
|
|
|
|
|
case GameVersion.Pt:
|
|
|
|
|
new SAV_Underground(SAV).ShowDialog(); break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-11-19 21:50:30 +00:00
|
|
|
|
private void B_FestivalPlaza_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2018-06-30 16:59:48 +00:00
|
|
|
|
if (SAV is SAV7)
|
2017-11-19 21:50:30 +00:00
|
|
|
|
new SAV_FestivalPlaza(SAV).ShowDialog();
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-12-02 22:20:56 +00:00
|
|
|
|
private void B_MailBox_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
new SAV_MailBox(SAV).ShowDialog();
|
|
|
|
|
ResetParty();
|
|
|
|
|
}
|
2018-01-21 23:30:57 +00:00
|
|
|
|
|
2018-05-10 04:02:35 +00:00
|
|
|
|
private void GenerateLivingDex()
|
|
|
|
|
{
|
2018-09-03 01:02:25 +00:00
|
|
|
|
SAV.BoxData = GetLivingDex(SAV);
|
|
|
|
|
ReloadSlots();
|
|
|
|
|
}
|
2018-05-10 04:02:35 +00:00
|
|
|
|
|
2018-09-03 01:02:25 +00:00
|
|
|
|
private static bool? GetPKMSetOverride(bool currentSetting)
|
|
|
|
|
{
|
|
|
|
|
var yn = currentSetting ? MsgYes : MsgNo;
|
|
|
|
|
DialogResult noSet = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel,
|
|
|
|
|
MsgSaveBoxImportModifyIntro,
|
|
|
|
|
MsgSaveBoxImportModifyYes + Environment.NewLine +
|
|
|
|
|
MsgSaveBoxImportModifyNo + Environment.NewLine +
|
|
|
|
|
string.Format(MsgSaveBoxImportModifyCurrent, yn));
|
2019-01-12 02:27:29 +00:00
|
|
|
|
switch (noSet)
|
|
|
|
|
{
|
|
|
|
|
case DialogResult.Yes: return true;
|
|
|
|
|
case DialogResult.No: return false;
|
|
|
|
|
default: return null;
|
|
|
|
|
}
|
2018-09-03 01:02:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static IList<PKM> GetLivingDex(SaveFile SAV)
|
|
|
|
|
{
|
|
|
|
|
var bd = SAV.BoxData;
|
2018-05-10 04:02:35 +00:00
|
|
|
|
var tr = SAV;
|
|
|
|
|
for (int i = 1; i <= 807; i++)
|
|
|
|
|
{
|
|
|
|
|
var pk = SAV.BlankPKM;
|
|
|
|
|
pk.Species = i;
|
|
|
|
|
pk.Gender = pk.GetSaneGender();
|
|
|
|
|
if (i == 678)
|
|
|
|
|
pk.AltForm = pk.Gender;
|
|
|
|
|
var f = EncounterMovesetGenerator.GeneratePKMs(pk, tr).FirstOrDefault();
|
|
|
|
|
if (f != null)
|
|
|
|
|
bd[i] = PKMConverter.ConvertToType(f, SAV.PKMType, out _);
|
|
|
|
|
}
|
2018-09-03 01:02:25 +00:00
|
|
|
|
return bd;
|
2018-05-10 04:02:35 +00:00
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|