Implement pkm sort option control

right click the box tab
* no longer silly key-combos to initiate a clear/sort
* provides multiple sorting options
Advanced sorting includes:
* Recieved Date
* Friendship usage (using it raises friendship, more used pkm will be
sorted to the top)
* Ownership (current SAV's first, then by other OTs)
This commit is contained in:
Kurt 2018-04-21 16:31:41 -07:00
parent 488b5215a7
commit df75543f2a
5 changed files with 114 additions and 45 deletions

View file

@ -148,7 +148,7 @@
this.tabBoxMulti.SelectedIndex = 0;
this.tabBoxMulti.Size = new System.Drawing.Size(310, 225);
this.tabBoxMulti.TabIndex = 101;
this.tabBoxMulti.Click += new System.EventHandler(this.ClickBoxSort);
this.tabBoxMulti.MouseClick += new System.Windows.Forms.MouseEventHandler(this.ClickBoxSort);
this.tabBoxMulti.DragOver += new System.Windows.Forms.DragEventHandler(this.MultiDragOver);
this.tabBoxMulti.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.ClickBoxDouble);
//

View file

@ -13,7 +13,7 @@ using static PKHeX.Core.MessageStrings;
namespace PKHeX.WinForms.Controls
{
public partial class SAVEditor : UserControl
public partial class SAVEditor : UserControl, ISortableDisplay
{
public SaveFile SAV;
public readonly PictureBox[] SlotPictureBoxes;
@ -21,6 +21,7 @@ namespace PKHeX.WinForms.Controls
public readonly Stack<SlotChange> UndoStack = new Stack<SlotChange>();
public readonly Stack<SlotChange> RedoStack = new Stack<SlotChange>();
public readonly ContextMenuSAV menu = new ContextMenuSAV();
public readonly ContextMenuStrip SortMenu;
public bool HaX;
public bool ModifyPKM;
@ -73,6 +74,7 @@ namespace PKHeX.WinForms.Controls
GB_Daycare.Click += SwitchDaycare;
FLP_SAVtools.Scroll += WinFormsUtil.PanelScroll;
SortMenu = this.GetSortStrip();
}
private void InitializeDragDrop(Control pb)
{
@ -361,52 +363,60 @@ namespace PKHeX.WinForms.Controls
pb.BackColor = Color.Transparent;
}
private void ClickBoxSort(object sender, EventArgs e)
#region Box Manipulation
private void ClickBoxSort(object sender, MouseEventArgs e)
{
if (tabBoxMulti.SelectedTab != Tab_Box)
if (tabBoxMulti.SelectedTab != Tab_Box || !e.Button.HasFlag(MouseButtons.Right))
return;
if (!SAV.HasBox)
if (!tabBoxMulti.GetTabRect(tabBoxMulti.SelectedIndex).Contains(PointToClient(MousePosition)))
return;
string modified;
bool all = false;
if (ModifierKeys == (Keys.Alt | Keys.Shift) && DialogResult.Yes == WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgSaveBoxClearAll))
{
if (SAV.IsAnySlotLockedInBox(0, SAV.BoxCount - 1))
{ WinFormsUtil.Alert(MsgSaveBoxClearAllFailBattle); return; }
SAV.ClearBoxes();
modified = MsgSaveBoxClearAllSuccess;
all = true;
}
else if (ModifierKeys == Keys.Alt && DialogResult.Yes == WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgSaveBoxClearCurrent))
{
if (SAV.IsAnySlotLockedInBox(Box.CurrentBox, Box.CurrentBox))
{ WinFormsUtil.Alert(MsgSaveBoxClearCurrentFailBattle); return; }
SAV.ClearBoxes(Box.CurrentBox, Box.CurrentBox + 1);
modified = MsgSaveBoxClearCurrentSuccess;
}
else if (ModifierKeys == (Keys.Control | Keys.Shift) && DialogResult.Yes == WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgSaveBoxSortAll))
{
if (SAV.IsAnySlotLockedInBox(0, SAV.BoxCount - 1))
{ WinFormsUtil.Alert(MsgSaveBoxSortAllFailBattle); return; }
SAV.SortBoxes();
modified = MsgSaveBoxSortAllSuccess;
all = true;
}
else if (ModifierKeys == Keys.Control && DialogResult.Yes == WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgSaveBoxSortCurrent))
{
if (SAV.IsAnySlotLockedInBox(Box.CurrentBox, Box.CurrentBox))
{ WinFormsUtil.Alert(MsgSaveBoxSortCurrentFailBattle); return; }
SAV.SortBoxes(Box.CurrentBox, Box.CurrentBox + 1);
modified = MsgSaveBoxSortCurrentSuccess;
}
else
var pt = Tab_Box.PointToScreen(new Point(0, 0));
SortMenu.Show(pt);
}
public void ClearAll()
{
if (!CanManipulateRegion(0, SAV.BoxCount - 1, MsgSaveBoxClearAll, MsgSaveBoxClearAllFailBattle))
return;
SAV.ClearBoxes();
FinishBoxManipulation(MsgSaveBoxClearAllSuccess, true);
}
public void ClearCurrent()
{
if (!CanManipulateRegion(Box.CurrentBox, Box.CurrentBox, MsgSaveBoxClearCurrent, MsgSaveBoxClearCurrentFailBattle))
return;
SAV.ClearBoxes(Box.CurrentBox, Box.CurrentBox + 1);
FinishBoxManipulation(MsgSaveBoxClearCurrentSuccess, false);
}
public void SortAll(Func<IEnumerable<PKM>, IEnumerable<PKM>> sorter)
{
if (!CanManipulateRegion(0, SAV.BoxCount - 1, MsgSaveBoxSortAll, MsgSaveBoxSortAllFailBattle))
return;
SAV.SortBoxes(0, SAV.BoxCount - 1, sorter);
FinishBoxManipulation(MsgSaveBoxSortAllSuccess, true);
}
public void SortCurrent(Func<IEnumerable<PKM>, IEnumerable<PKM>> sorter)
{
if (!CanManipulateRegion(Box.CurrentBox, Box.CurrentBox, MsgSaveBoxSortCurrent, MsgSaveBoxSortCurrentFailBattle))
return;
SAV.SortBoxes(Box.CurrentBox, Box.CurrentBox + 1, sorter);
FinishBoxManipulation(MsgSaveBoxSortCurrentSuccess, false);
}
private void FinishBoxManipulation(string message, bool all)
{
SetPKMBoxes();
UpdateBoxViewers(all);
WinFormsUtil.Alert(modified);
WinFormsUtil.Alert(message);
}
private bool CanManipulateRegion(int start, int end, string prompt, string fail)
{
if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, prompt) != DialogResult.Yes)
return false;
if (!SAV.IsAnySlotLockedInBox(start, end))
return true;
WinFormsUtil.Alert(fail);
return false;
}
#endregion
private void ClickBoxDouble(object sender, MouseEventArgs e)
{
if (tabBoxMulti.SelectedTab == Tab_SAV)

View file

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using PKHeX.Core;
namespace PKHeX.WinForms.Controls
{
public static class Sorter
{
public static ContextMenuStrip GetSortStrip(this SAVEditor sav)
{
var sortMenu = new ContextMenuStrip();
var options = new[]
{
GetItem("mnu_ClearBox", "Clear", Clear),
GetItem("mnu_SortBoxSpecies", "Sort: SpeciesID", () => Sort(PKMSorting.OrderBySpecies)),
GetItem("mnu_SortBoxSpecies", "Sort: SpeciesIDRev", () => Sort(PKMSorting.OrderByDescendingSpecies)),
GetItem("mnu_SortBoxSpecies", "Sort: Level Low->High", () => Sort(PKMSorting.OrderByLevel)),
GetItem("mnu_SortBoxSpecies", "Sort: Level High->Low", () => Sort(PKMSorting.OrderByDescendingLevel)),
GetItem("mnu_SortBoxSpecies", "Sort: Date", () => Sort(PKMSorting.OrderByDateObtained)),
GetItem("mnu_SortBoxSpecies", "Sort: Usage", () => Sort(PKMSorting.OrderByDescendingLevel)),
GetItem("mnu_SortBoxSpecies", "Sort: SpeciesName", () => Sort(list => list.OrderBySpeciesName(GameInfo.Strings.Species))),
GetItem("mnu_SortBoxSpecies", "Sort: Ownership", () => Sort(list => list.OrderByOwnership(sav.SAV))),
};
sortMenu.Items.AddRange(options);
void Clear()
{
if (Control.ModifierKeys.HasFlag(Keys.Shift))
sav.ClearAll();
else
sav.ClearCurrent();
}
void Sort(Func<IEnumerable<PKM>, IEnumerable<PKM>> sorter)
{
if (Control.ModifierKeys.HasFlag(Keys.Shift))
sav.SortAll(sorter);
else
sav.SortCurrent(sorter);
}
return sortMenu;
}
private static ToolStripItem GetItem(string name, string text, Action action)
{
var tsi = new ToolStripMenuItem {Name = name, Text = text};
tsi.Click += (s, e) => action();
return tsi;
}
}
public interface ISortableDisplay
{
void ClearAll();
void ClearCurrent();
void SortAll(Func<IEnumerable<PKM>, IEnumerable<PKM>> sorter);
void SortCurrent(Func<IEnumerable<PKM>, IEnumerable<PKM>> sorter);
}
}

View file

@ -203,6 +203,7 @@
<Compile Include="Controls\SAV Editor\SlotList.Designer.cs">
<DependentUpon>SlotList.cs</DependentUpon>
</Compile>
<Compile Include="Controls\SAV Editor\Sorter.cs" />
<Compile Include="MainWindow\Main.cs">
<SubType>Form</SubType>
</Compile>

View file

@ -53,10 +53,7 @@ Doubleclick on the SAV Tab: Auto-detect/Reload latest save.
// Boxes
Control-Click Box Tab: Sort Current Box contents.
Control-Shift-Click Box Tab: Sort All Boxes.
Alt-Click Box Tab: Delete Current Box contents.
Alt-Shift-Click Box Tab: Delete All Boxes.
Right click on Box Tab: Clear/Sort Box contents. Hold shift when selecting the action to apply to ALL boxes.
Control-RightClick a Box Slot to show extra options (ie Legality check)
Control-Drag a Box Slot to Copy-Overwrite