Add box rearranging

enables the left/right arrows on each box to allow switching with the
adjacent box
This commit is contained in:
Kurt 2018-01-23 22:37:55 -08:00
parent 713e9ea209
commit b16a2f9ad2
4 changed files with 51 additions and 7 deletions

View file

@ -574,8 +574,8 @@
private System.Windows.Forms.PictureBox bpkx3; private System.Windows.Forms.PictureBox bpkx3;
private System.Windows.Forms.PictureBox bpkx2; private System.Windows.Forms.PictureBox bpkx2;
private System.Windows.Forms.PictureBox bpkx1; private System.Windows.Forms.PictureBox bpkx1;
private System.Windows.Forms.Button B_BoxRight; public System.Windows.Forms.Button B_BoxRight;
private System.Windows.Forms.Button B_BoxLeft; public System.Windows.Forms.Button B_BoxLeft;
private System.Windows.Forms.ComboBox CB_BoxSelect; public System.Windows.Forms.ComboBox CB_BoxSelect;
} }
} }

View file

@ -98,7 +98,7 @@ namespace PKHeX.WinForms.Controls
pb.BackgroundImage = M.colorizedcolor; pb.BackgroundImage = M.colorizedcolor;
} }
public void ResetBoxNames() public void ResetBoxNames(int box = -1)
{ {
if (!SAV.HasBox) if (!SAV.HasBox)
return; return;
@ -110,8 +110,10 @@ namespace PKHeX.WinForms.Controls
catch { getBoxNamesDefault(); } catch { getBoxNamesDefault(); }
} }
if (SAV.CurrentBox < CB_BoxSelect.Items.Count) if (box < 0 && SAV.CurrentBox < CB_BoxSelect.Items.Count)
CurrentBox = SAV.CurrentBox; // restore selected box CurrentBox = SAV.CurrentBox; // restore selected box
else
CurrentBox = box;
void getBoxNamesFromSave() void getBoxNamesFromSave()
{ {
@ -170,6 +172,12 @@ namespace PKHeX.WinForms.Controls
} }
return false; return false;
} }
public void ClearEvents()
{
B_BoxRight.Click -= ClickBoxRight;
B_BoxLeft.Click -= ClickBoxLeft;
CB_BoxSelect.SelectedIndexChanged -= GetBox;
}
public int GetSlot(object sender) => SlotPictureBoxes.IndexOf(WinFormsUtil.GetUnderlyingControl(sender) as PictureBox); public int GetSlot(object sender) => SlotPictureBoxes.IndexOf(WinFormsUtil.GetUnderlyingControl(sender) as PictureBox);

View file

@ -403,6 +403,22 @@ namespace PKHeX.WinForms.Controls
SE.SetParty(); SE.SetParty();
} }
// Utility
public void SwapBoxes(int index, int other)
{
if (index == other)
return;
SAV.SwapBox(index, other);
foreach (var box in Boxes)
{
if (box.CurrentBox != index && box.CurrentBox != other)
continue;
box.ResetSlots();
box.ResetBoxNames(box.CurrentBox);
}
}
public void Dispose() public void Dispose()
{ {
SE?.Dispose(); SE?.Dispose();

View file

@ -2,6 +2,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Windows.Forms; using System.Windows.Forms;
using PKHeX.Core;
using PKHeX.WinForms.Controls; using PKHeX.WinForms.Controls;
namespace PKHeX.WinForms namespace PKHeX.WinForms
@ -41,7 +43,7 @@ namespace PKHeX.WinForms
}; };
} }
private void AddControls(SAVEditor p, SlotChangeManager m, Core.SaveFile sav) private void AddControls(SAVEditor p, SlotChangeManager m, SaveFile sav)
{ {
for (int i = 0; i < sav.BoxCount; i++) for (int i = 0; i < sav.BoxCount; i++)
{ {
@ -50,10 +52,28 @@ namespace PKHeX.WinForms
pb.ContextMenuStrip = p.SlotPictureBoxes[0].ContextMenuStrip; pb.ContextMenuStrip = p.SlotPictureBoxes[0].ContextMenuStrip;
boxEditor.Setup(m); boxEditor.Setup(m);
boxEditor.CurrentBox = i; boxEditor.CurrentBox = i;
boxEditor.ControlsEnabled = false; boxEditor.CB_BoxSelect.Enabled = false;
Boxes.Add(boxEditor); Boxes.Add(boxEditor);
FLP_Boxes.Controls.Add(Boxes[i]); FLP_Boxes.Controls.Add(Boxes[i]);
} }
// Setup swapping
foreach (var box in Boxes)
{
box.ClearEvents();
box.B_BoxLeft.Click += (s, e) =>
{
int index = Boxes.FindIndex(z => z == ((Button)s).Parent);
int other = (index + Boxes.Count - 1) % Boxes.Count;
m.SwapBoxes(index, other);
};
box.B_BoxRight.Click += (s, e) =>
{
int index = Boxes.FindIndex(z => z == ((Button)s).Parent);
int other = (index + 1) % Boxes.Count;
m.SwapBoxes(index, other);
};
}
} }
private void SetWindowDimensions(int count) private void SetWindowDimensions(int count)