mirror of
https://github.com/kwsch/PKHeX
synced 2025-02-17 05:48:44 +00:00
Add Undo/Redo for box slots
Closes #301 Reset undo/redo stack when a new save is loaded, juggle undo&redo when reverting changes.
This commit is contained in:
parent
4eeb90dd87
commit
031d7d78b1
5 changed files with 758 additions and 633 deletions
36
PKHeX/MainWindow/Main.Designer.cs
generated
36
PKHeX/MainWindow/Main.Designer.cs
generated
|
@ -436,6 +436,8 @@
|
|||
this.mnuLSave = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.PB_Legal = new System.Windows.Forms.PictureBox();
|
||||
this.L_UpdateAvailable = new System.Windows.Forms.LinkLabel();
|
||||
this.Menu_Undo = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.Menu_Redo = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.tabMain.SuspendLayout();
|
||||
this.Tab_Main.SuspendLayout();
|
||||
this.FLP_Main.SuspendLayout();
|
||||
|
@ -3898,7 +3900,7 @@
|
|||
this.CB_MainLanguage});
|
||||
this.Menu_Language.Image = global::PKHeX.Properties.Resources.language;
|
||||
this.Menu_Language.Name = "Menu_Language";
|
||||
this.Menu_Language.Size = new System.Drawing.Size(139, 22);
|
||||
this.Menu_Language.Size = new System.Drawing.Size(152, 22);
|
||||
this.Menu_Language.Text = "Language";
|
||||
//
|
||||
// CB_MainLanguage
|
||||
|
@ -3912,10 +3914,12 @@
|
|||
//
|
||||
this.Menu_Modify.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.Menu_ModifyDex,
|
||||
this.Menu_ModifyPKM});
|
||||
this.Menu_ModifyPKM,
|
||||
this.Menu_Undo,
|
||||
this.Menu_Redo});
|
||||
this.Menu_Modify.Image = global::PKHeX.Properties.Resources.settings;
|
||||
this.Menu_Modify.Name = "Menu_Modify";
|
||||
this.Menu_Modify.Size = new System.Drawing.Size(139, 22);
|
||||
this.Menu_Modify.Size = new System.Drawing.Size(152, 22);
|
||||
this.Menu_Modify.Text = "Set to SAV";
|
||||
//
|
||||
// Menu_ModifyDex
|
||||
|
@ -3944,7 +3948,7 @@
|
|||
this.Menu_Unicode.CheckOnClick = true;
|
||||
this.Menu_Unicode.CheckState = System.Windows.Forms.CheckState.Checked;
|
||||
this.Menu_Unicode.Name = "Menu_Unicode";
|
||||
this.Menu_Unicode.Size = new System.Drawing.Size(139, 22);
|
||||
this.Menu_Unicode.Size = new System.Drawing.Size(152, 22);
|
||||
this.Menu_Unicode.Text = "Unicode";
|
||||
this.Menu_Unicode.Click += new System.EventHandler(this.mainMenuUnicode);
|
||||
//
|
||||
|
@ -3954,7 +3958,7 @@
|
|||
this.Menu_About.Name = "Menu_About";
|
||||
this.Menu_About.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.P)));
|
||||
this.Menu_About.ShowShortcutKeys = false;
|
||||
this.Menu_About.Size = new System.Drawing.Size(139, 22);
|
||||
this.Menu_About.Size = new System.Drawing.Size(152, 22);
|
||||
this.Menu_About.Text = "About &PKHeX";
|
||||
this.Menu_About.Click += new System.EventHandler(this.mainMenuAbout);
|
||||
//
|
||||
|
@ -5603,6 +5607,26 @@
|
|||
this.L_UpdateAvailable.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
|
||||
this.L_UpdateAvailable.Visible = false;
|
||||
//
|
||||
// Menu_Undo
|
||||
//
|
||||
this.Menu_Undo.Enabled = false;
|
||||
this.Menu_Undo.Name = "Menu_Undo";
|
||||
this.Menu_Undo.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.U)));
|
||||
this.Menu_Undo.ShowShortcutKeys = false;
|
||||
this.Menu_Undo.Size = new System.Drawing.Size(164, 22);
|
||||
this.Menu_Undo.Text = "Undo Last Change";
|
||||
this.Menu_Undo.Click += new System.EventHandler(this.clickUndo);
|
||||
//
|
||||
// Menu_Redo
|
||||
//
|
||||
this.Menu_Redo.Enabled = false;
|
||||
this.Menu_Redo.Name = "Menu_Redo";
|
||||
this.Menu_Redo.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Y)));
|
||||
this.Menu_Redo.ShowShortcutKeys = false;
|
||||
this.Menu_Redo.Size = new System.Drawing.Size(164, 22);
|
||||
this.Menu_Redo.Text = "Redo Last Change";
|
||||
this.Menu_Redo.Click += new System.EventHandler(this.clickRedo);
|
||||
//
|
||||
// Main
|
||||
//
|
||||
this.AllowDrop = true;
|
||||
|
@ -6238,6 +6262,8 @@
|
|||
private System.Windows.Forms.FlowLayoutPanel FLP_ShadowID;
|
||||
private System.Windows.Forms.Label L_ShadowID;
|
||||
private System.Windows.Forms.NumericUpDown NUD_ShadowID;
|
||||
private System.Windows.Forms.ToolStripMenuItem Menu_Undo;
|
||||
private System.Windows.Forms.ToolStripMenuItem Menu_Redo;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1170,6 +1170,10 @@ namespace PKHeX
|
|||
|
||||
if (WindowTranslationRequired) // force update -- re-added controls may be untranslated
|
||||
Util.TranslateInterface(this, curlanguage);
|
||||
|
||||
// No changes made yet
|
||||
UndoStack.Clear(); Menu_Undo.Enabled = false;
|
||||
RedoStack.Clear(); Menu_Redo.Enabled = false;
|
||||
|
||||
// Indicate audibly the save is loaded
|
||||
SystemSounds.Beep.Play();
|
||||
|
@ -3202,6 +3206,18 @@ namespace PKHeX
|
|||
}
|
||||
else if (slot < 30 || HaX && slot >= 36 && slot < 42)
|
||||
{
|
||||
if (slot < 30)
|
||||
{
|
||||
UndoStack.Push(new SlotChange
|
||||
{
|
||||
Box = CB_BoxSelect.SelectedIndex,
|
||||
Slot = slot,
|
||||
Offset = offset,
|
||||
OriginalData = SAV.getStoredSlot(offset)
|
||||
});
|
||||
Menu_Undo.Enabled = true;
|
||||
}
|
||||
|
||||
SAV.setStoredSlot(pk, offset);
|
||||
getQuickFiller(SlotPictureBoxes[slot], pk);
|
||||
getSlotColor(slot, Properties.Resources.slotSet);
|
||||
|
@ -3209,16 +3225,6 @@ namespace PKHeX
|
|||
|
||||
updateBoxViewers();
|
||||
}
|
||||
|
||||
private void updateSaveSlot(object sender, EventArgs e)
|
||||
{
|
||||
if (SAV.Version == GameVersion.BATREV)
|
||||
{
|
||||
((SAV4BR) SAV).CurrentSlot = Util.getIndex(CB_SaveSlot);
|
||||
setPKXBoxes();
|
||||
}
|
||||
}
|
||||
|
||||
private void clickDelete(object sender, EventArgs e)
|
||||
{
|
||||
int slot = getSlot(sender);
|
||||
|
@ -3238,13 +3244,81 @@ namespace PKHeX
|
|||
return;
|
||||
}
|
||||
if (slot < 30 || HaX && slot >= 36 && slot < 42)
|
||||
{ SAV.setStoredSlot(SAV.BlankPKM, getPKXOffset(slot)); }
|
||||
{
|
||||
if (slot < 30)
|
||||
{
|
||||
UndoStack.Push(new SlotChange
|
||||
{
|
||||
Box = CB_BoxSelect.SelectedIndex,
|
||||
Slot = slot,
|
||||
Offset = offset,
|
||||
OriginalData = SAV.getStoredSlot(offset)
|
||||
});
|
||||
Menu_Undo.Enabled = true;
|
||||
}
|
||||
SAV.setStoredSlot(SAV.BlankPKM, getPKXOffset(slot));
|
||||
}
|
||||
else return;
|
||||
|
||||
getQuickFiller(SlotPictureBoxes[slot], SAV.BlankPKM);
|
||||
getSlotColor(slot, Properties.Resources.slotDel);
|
||||
updateBoxViewers();
|
||||
}
|
||||
private readonly Stack<SlotChange> UndoStack = new Stack<SlotChange>();
|
||||
private readonly Stack<SlotChange> RedoStack = new Stack<SlotChange>();
|
||||
private void clickUndo(object sender, EventArgs e)
|
||||
{
|
||||
if (!UndoStack.Any())
|
||||
return;
|
||||
|
||||
SlotChange change = UndoStack.Pop();
|
||||
if (change.Slot >= 30)
|
||||
return;
|
||||
|
||||
RedoStack.Push(new SlotChange
|
||||
{
|
||||
Slot = change.Slot,
|
||||
Box = change.Box,
|
||||
Offset = change.Offset,
|
||||
OriginalData = SAV.getStoredSlot(change.Offset)
|
||||
});
|
||||
undoSlotChange(change);
|
||||
}
|
||||
private void clickRedo(object sender, EventArgs e)
|
||||
{
|
||||
if (!RedoStack.Any())
|
||||
return;
|
||||
|
||||
SlotChange change = RedoStack.Pop();
|
||||
if (change.Slot >= 30)
|
||||
return;
|
||||
|
||||
UndoStack.Push(new SlotChange
|
||||
{
|
||||
Slot = change.Slot,
|
||||
Box = change.Box,
|
||||
Offset = change.Offset,
|
||||
OriginalData = SAV.getStoredSlot(change.Offset)
|
||||
});
|
||||
undoSlotChange(change);
|
||||
}
|
||||
private void undoSlotChange(SlotChange change)
|
||||
{
|
||||
int slot = change.Slot;
|
||||
int offset = change.Offset;
|
||||
PKM pk = (PKM)change.OriginalData;
|
||||
|
||||
if (CB_BoxSelect.SelectedIndex != change.Box)
|
||||
CB_BoxSelect.SelectedIndex = change.Box;
|
||||
SAV.setStoredSlot(pk, offset);
|
||||
getQuickFiller(SlotPictureBoxes[slot], pk);
|
||||
getSlotColor(slot, Properties.Resources.slotSet);
|
||||
|
||||
Menu_Undo.Enabled = UndoStack.Any();
|
||||
Menu_Redo.Enabled = RedoStack.Any();
|
||||
|
||||
SystemSounds.Asterisk.Play();
|
||||
}
|
||||
private void clickClone(object sender, EventArgs e)
|
||||
{
|
||||
if (getSlot(sender) > 30) return; // only perform action if cloning to boxes
|
||||
|
@ -3285,7 +3359,13 @@ namespace PKHeX
|
|||
}
|
||||
showLegality(pk as PK6, slot < 0, ModifierKeys == Keys.Control);
|
||||
}
|
||||
|
||||
private void updateSaveSlot(object sender, EventArgs e)
|
||||
{
|
||||
if (SAV.Version != GameVersion.BATREV)
|
||||
return;
|
||||
((SAV4BR)SAV).CurrentSlot = Util.getIndex(CB_SaveSlot);
|
||||
setPKXBoxes();
|
||||
}
|
||||
private void updateEggRNGSeed(object sender, EventArgs e)
|
||||
{
|
||||
if (TB_RNGSeed.Text.Length == 0)
|
||||
|
@ -3363,7 +3443,6 @@ namespace PKHeX
|
|||
SAV.Edited = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateIsNicknamed(object sender, EventArgs e)
|
||||
{
|
||||
if (!fieldsLoaded)
|
||||
|
|
File diff suppressed because it is too large
Load diff
10
PKHeX/MainWindow/SlotChange.cs
Normal file
10
PKHeX/MainWindow/SlotChange.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
namespace PKHeX
|
||||
{
|
||||
public class SlotChange
|
||||
{
|
||||
public int Box;
|
||||
public int Slot;
|
||||
public int Offset;
|
||||
public object OriginalData;
|
||||
}
|
||||
}
|
|
@ -129,6 +129,7 @@
|
|||
<Compile Include="MainWindow\MainPK3.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="MainWindow\SlotChange.cs" />
|
||||
<Compile Include="Misc\ErrorWindow.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
|
Loading…
Add table
Reference in a new issue