use SlotList view to dynamically show slots (#1798)

Closes #1795 by redoing the controls

Allows for a specified slot type & offset to be passed, can easily add extra slots by updating the GetExtraSlots extension method.
This commit is contained in:
Kurt 2018-01-30 18:52:55 -08:00 committed by GitHub
parent c4865c6c0a
commit 1ca9180e21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 206 additions and 224 deletions

View file

@ -23,6 +23,20 @@ namespace PKHeX.Core
return arr;
}
public static List<StorageSlotOffset> GetExtraSlots(this SaveFile sav, bool all = false)
{
var slots = GetExtraSlotsUnsafe(sav, all);
for (int i = 0; i < slots.Count;)
{
if (slots[i].Offset < 0)
slots.RemoveAt(i);
else
++i;
}
return slots;
}
private static readonly List<StorageSlotOffset> None = new List<StorageSlotOffset>();
private static List<StorageSlotOffset> GetExtraSlotsUnsafe(SaveFile sav, bool all)
{
switch (sav)
{
@ -33,12 +47,8 @@ namespace PKHeX.Core
case SAV7 sav7: return GetExtraSlots7(sav7, all);
}
}
private static readonly List<StorageSlotOffset> None = new List<StorageSlotOffset>();
private static List<StorageSlotOffset> GetExtraSlots4(SAV4 sav)
{
if (sav.GTS < 0)
return None;
return new List<StorageSlotOffset>
{
new StorageSlotOffset {Type = StorageSlotType.GTS, Offset = sav.GTS},
@ -54,6 +64,8 @@ namespace PKHeX.Core
}
private static List<StorageSlotOffset> GetExtraSlots6(SAV6 sav)
{
if (sav.ORASDEMO)
return None;
var list = new List<StorageSlotOffset>
{
new StorageSlotOffset {Type = StorageSlotType.GTS, Offset = sav.GTS},

View file

@ -86,6 +86,8 @@ namespace PKHeX.WinForms.Controls
m.SetPKM(pk, info, true, Resources.slotSet);
}
else
return;
editor.LastData = pk.Data;
m.SE.RedoStack.Clear(); m.SE.Menu_Redo.Enabled = false;
@ -170,6 +172,15 @@ namespace PKHeX.WinForms.Controls
sender = ctrl;
return b.M;
}
if (obj is SlotList s)
{
const int shift = 44;
loc.Slot = s.GetSlot(sender) + shift;
loc.Offset = s.GetSlotOffset(loc.Slot - shift);
loc.Parent = s.FindForm();
sender = ctrl;
return s.M;
}
obj = obj.Parent.Parent;
if (obj is SAVEditor z)
{

View file

@ -31,6 +31,7 @@
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SAVEditor));
this.tabBoxMulti = new System.Windows.Forms.TabControl();
this.Tab_Box = new System.Windows.Forms.TabPage();
this.Box = new PKHeX.WinForms.Controls.BoxEditor();
this.Tab_PartyBattle = new System.Windows.Forms.TabPage();
this.PAN_BattleBox = new System.Windows.Forms.Panel();
this.PB_Locked = new System.Windows.Forms.PictureBox();
@ -51,6 +52,7 @@
this.ppkx5 = new System.Windows.Forms.PictureBox();
this.ppkx6 = new System.Windows.Forms.PictureBox();
this.Tab_Other = new System.Windows.Forms.TabPage();
this.SL_Extra = new PKHeX.WinForms.Controls.SlotList();
this.GB_Daycare = new System.Windows.Forms.GroupBox();
this.L_XP2 = new System.Windows.Forms.Label();
this.L_XP1 = new System.Windows.Forms.Label();
@ -63,15 +65,7 @@
this.dcpkx2 = new System.Windows.Forms.PictureBox();
this.dcpkx1 = new System.Windows.Forms.PictureBox();
this.DayCare_HasEgg = new System.Windows.Forms.CheckBox();
this.GB_GTS = new System.Windows.Forms.GroupBox();
this.gtspkx = new System.Windows.Forms.PictureBox();
this.GB_Fused = new System.Windows.Forms.GroupBox();
this.fusedpkx = new System.Windows.Forms.PictureBox();
this.L_ReadOnlyOther = new System.Windows.Forms.Label();
this.GB_SUBE = new System.Windows.Forms.GroupBox();
this.subepkx1 = new System.Windows.Forms.PictureBox();
this.subepkx2 = new System.Windows.Forms.PictureBox();
this.subepkx3 = new System.Windows.Forms.PictureBox();
this.Tab_SAV = new System.Windows.Forms.TabPage();
this.CB_SaveSlot = new System.Windows.Forms.ComboBox();
this.L_SaveSlot = new System.Windows.Forms.Label();
@ -113,7 +107,6 @@
this.B_FestivalPlaza = new System.Windows.Forms.Button();
this.B_MailBox = new System.Windows.Forms.Button();
this.B_OpenApricorn = new System.Windows.Forms.Button();
this.Box = new PKHeX.WinForms.Controls.BoxEditor();
this.tabBoxMulti.SuspendLayout();
this.Tab_Box.SuspendLayout();
this.Tab_PartyBattle.SuspendLayout();
@ -136,14 +129,6 @@
this.GB_Daycare.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dcpkx2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dcpkx1)).BeginInit();
this.GB_GTS.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.gtspkx)).BeginInit();
this.GB_Fused.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.fusedpkx)).BeginInit();
this.GB_SUBE.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.subepkx1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.subepkx2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.subepkx3)).BeginInit();
this.Tab_SAV.SuspendLayout();
this.GB_SAVtools.SuspendLayout();
this.FLP_SAVtools.SuspendLayout();
@ -178,6 +163,19 @@
this.Tab_Box.Text = "Box";
this.Tab_Box.UseVisualStyleBackColor = true;
//
// Box
//
this.Box.AllowDrop = true;
this.Box.ControlsEnabled = true;
this.Box.ControlsVisible = true;
this.Box.CurrentBox = -1;
this.Box.FlagIllegal = false;
this.Box.Location = new System.Drawing.Point(26, 7);
this.Box.M = null;
this.Box.Name = "Box";
this.Box.Size = new System.Drawing.Size(251, 185);
this.Box.TabIndex = 1;
//
// Tab_PartyBattle
//
this.Tab_PartyBattle.Controls.Add(this.PAN_BattleBox);
@ -374,11 +372,9 @@
//
// Tab_Other
//
this.Tab_Other.Controls.Add(this.SL_Extra);
this.Tab_Other.Controls.Add(this.GB_Daycare);
this.Tab_Other.Controls.Add(this.GB_GTS);
this.Tab_Other.Controls.Add(this.GB_Fused);
this.Tab_Other.Controls.Add(this.L_ReadOnlyOther);
this.Tab_Other.Controls.Add(this.GB_SUBE);
this.Tab_Other.Location = new System.Drawing.Point(4, 22);
this.Tab_Other.Name = "Tab_Other";
this.Tab_Other.Size = new System.Drawing.Size(302, 199);
@ -386,6 +382,15 @@
this.Tab_Other.Text = "Other";
this.Tab_Other.UseVisualStyleBackColor = true;
//
// SL_Extra
//
this.SL_Extra.Dock = System.Windows.Forms.DockStyle.Right;
this.SL_Extra.Location = new System.Drawing.Point(227, 0);
this.SL_Extra.M = null;
this.SL_Extra.Name = "SL_Extra";
this.SL_Extra.Size = new System.Drawing.Size(75, 199);
this.SL_Extra.TabIndex = 30;
//
// GB_Daycare
//
this.GB_Daycare.Controls.Add(this.L_XP2);
@ -509,46 +514,6 @@
this.DayCare_HasEgg.Text = "Egg Available";
this.DayCare_HasEgg.UseVisualStyleBackColor = true;
//
// GB_GTS
//
this.GB_GTS.Controls.Add(this.gtspkx);
this.GB_GTS.Location = new System.Drawing.Point(227, 4);
this.GB_GTS.Name = "GB_GTS";
this.GB_GTS.Size = new System.Drawing.Size(60, 60);
this.GB_GTS.TabIndex = 26;
this.GB_GTS.TabStop = false;
this.GB_GTS.Text = "GTS";
//
// gtspkx
//
this.gtspkx.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.gtspkx.Location = new System.Drawing.Point(9, 18);
this.gtspkx.Name = "gtspkx";
this.gtspkx.Size = new System.Drawing.Size(42, 32);
this.gtspkx.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.gtspkx.TabIndex = 23;
this.gtspkx.TabStop = false;
//
// GB_Fused
//
this.GB_Fused.Controls.Add(this.fusedpkx);
this.GB_Fused.Location = new System.Drawing.Point(227, 70);
this.GB_Fused.Name = "GB_Fused";
this.GB_Fused.Size = new System.Drawing.Size(60, 60);
this.GB_Fused.TabIndex = 25;
this.GB_Fused.TabStop = false;
this.GB_Fused.Text = "Fused";
//
// fusedpkx
//
this.fusedpkx.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.fusedpkx.Location = new System.Drawing.Point(9, 18);
this.fusedpkx.Name = "fusedpkx";
this.fusedpkx.Size = new System.Drawing.Size(42, 32);
this.fusedpkx.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.fusedpkx.TabIndex = 24;
this.fusedpkx.TabStop = false;
//
// L_ReadOnlyOther
//
this.L_ReadOnlyOther.ForeColor = System.Drawing.Color.Red;
@ -559,48 +524,6 @@
this.L_ReadOnlyOther.Text = "This tab is read only.";
this.L_ReadOnlyOther.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// GB_SUBE
//
this.GB_SUBE.Controls.Add(this.subepkx1);
this.GB_SUBE.Controls.Add(this.subepkx2);
this.GB_SUBE.Controls.Add(this.subepkx3);
this.GB_SUBE.Location = new System.Drawing.Point(227, 136);
this.GB_SUBE.Name = "GB_SUBE";
this.GB_SUBE.Size = new System.Drawing.Size(60, 60);
this.GB_SUBE.TabIndex = 27;
this.GB_SUBE.TabStop = false;
this.GB_SUBE.Text = "OldMan";
//
// subepkx1
//
this.subepkx1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.subepkx1.Location = new System.Drawing.Point(9, 18);
this.subepkx1.Name = "subepkx1";
this.subepkx1.Size = new System.Drawing.Size(42, 32);
this.subepkx1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.subepkx1.TabIndex = 18;
this.subepkx1.TabStop = false;
//
// subepkx2
//
this.subepkx2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.subepkx2.Location = new System.Drawing.Point(62, 19);
this.subepkx2.Name = "subepkx2";
this.subepkx2.Size = new System.Drawing.Size(42, 34);
this.subepkx2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.subepkx2.TabIndex = 19;
this.subepkx2.TabStop = false;
//
// subepkx3
//
this.subepkx3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.subepkx3.Location = new System.Drawing.Point(109, 19);
this.subepkx3.Name = "subepkx3";
this.subepkx3.Size = new System.Drawing.Size(42, 34);
this.subepkx3.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.subepkx3.TabIndex = 20;
this.subepkx3.TabStop = false;
//
// Tab_SAV
//
this.Tab_SAV.Controls.Add(this.CB_SaveSlot);
@ -1057,18 +980,6 @@
this.B_OpenApricorn.UseVisualStyleBackColor = true;
this.B_OpenApricorn.Click += new System.EventHandler(this.B_OpenApricorn_Click);
//
// Box
//
this.Box.AllowDrop = true;
this.Box.ControlsVisible = true;
this.Box.CurrentBox = -1;
this.Box.FlagIllegal = false;
this.Box.Location = new System.Drawing.Point(26, 7);
this.Box.M = null;
this.Box.Name = "Box";
this.Box.Size = new System.Drawing.Size(251, 185);
this.Box.TabIndex = 1;
//
// SAVEditor
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
@ -1102,17 +1013,6 @@
this.GB_Daycare.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dcpkx2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dcpkx1)).EndInit();
this.GB_GTS.ResumeLayout(false);
this.GB_GTS.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.gtspkx)).EndInit();
this.GB_Fused.ResumeLayout(false);
this.GB_Fused.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.fusedpkx)).EndInit();
this.GB_SUBE.ResumeLayout(false);
this.GB_SUBE.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.subepkx1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.subepkx2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.subepkx3)).EndInit();
this.Tab_SAV.ResumeLayout(false);
this.Tab_SAV.PerformLayout();
this.GB_SAVtools.ResumeLayout(false);
@ -1157,15 +1057,7 @@
private System.Windows.Forms.PictureBox dcpkx2;
private System.Windows.Forms.PictureBox dcpkx1;
private System.Windows.Forms.CheckBox DayCare_HasEgg;
private System.Windows.Forms.GroupBox GB_GTS;
private System.Windows.Forms.PictureBox gtspkx;
private System.Windows.Forms.GroupBox GB_Fused;
private System.Windows.Forms.PictureBox fusedpkx;
private System.Windows.Forms.Label L_ReadOnlyOther;
private System.Windows.Forms.GroupBox GB_SUBE;
private System.Windows.Forms.PictureBox subepkx1;
private System.Windows.Forms.PictureBox subepkx2;
private System.Windows.Forms.PictureBox subepkx3;
private System.Windows.Forms.TabPage Tab_SAV;
private System.Windows.Forms.ComboBox CB_SaveSlot;
private System.Windows.Forms.Label L_SaveSlot;
@ -1208,5 +1100,6 @@
private System.Windows.Forms.Button B_FestivalPlaza;
private System.Windows.Forms.Button B_MailBox;
private System.Windows.Forms.Button B_OpenApricorn;
private SlotList SL_Extra;
}
}

View file

@ -52,25 +52,15 @@ namespace PKHeX.WinForms.Controls
ppkx1, ppkx2, ppkx3, ppkx4, ppkx5, ppkx6,
bbpkx1, bbpkx2, bbpkx3, bbpkx4, bbpkx5, bbpkx6,
dcpkx1, dcpkx2, gtspkx, fusedpkx, subepkx1, subepkx2, subepkx3,
dcpkx1, dcpkx2
};
GiveFeedback += (sender, e) => e.UseDefaultCursors = false;
SAV = z.Result;
Box.Setup(M = new SlotChangeManager(this));
SL_Extra.M = M;
foreach (PictureBox pb in SupplementarySlots)
{
pb.MouseEnter += M.MouseEnter;
pb.MouseLeave += M.MouseLeave;
pb.MouseClick += M.MouseClick;
pb.MouseMove += BoxSlot_MouseMove;
pb.MouseDown += M.MouseDown;
pb.MouseUp += M.MouseUp;
pb.DragEnter += M.DragEnter;
pb.DragDrop += BoxSlot_DragDrop;
pb.QueryContinueDrag += M.QueryContinueDrag;
pb.GiveFeedback += (sender, e) => e.UseDefaultCursors = false;
pb.AllowDrop = true;
InitializeDragDrop(pb);
}
foreach (TabPage tab in tabBoxMulti.TabPages)
tab.AllowDrop = true;
@ -83,6 +73,22 @@ namespace PKHeX.WinForms.Controls
GB_Daycare.Click += SwitchDaycare;
FLP_SAVtools.Scroll += WinFormsUtil.PanelScroll;
}
private void InitializeDragDrop(Control pb)
{
pb.MouseEnter += M.MouseEnter;
pb.MouseLeave += M.MouseLeave;
pb.MouseClick += M.MouseClick;
pb.MouseMove += BoxSlot_MouseMove;
pb.MouseDown += M.MouseDown;
pb.MouseUp += M.MouseUp;
pb.DragEnter += M.DragEnter;
pb.DragDrop += BoxSlot_DragDrop;
pb.QueryContinueDrag += M.QueryContinueDrag;
pb.GiveFeedback += (sender, e) => e.UseDefaultCursors = false;
pb.AllowDrop = true;
pb.ContextMenuStrip = menu.mnuVSD;
}
/// <summary>Occurs when the Control Collection requests a cloning operation to the current box.</summary>
public event EventHandler RequestCloneData;
@ -115,20 +121,20 @@ namespace PKHeX.WinForms.Controls
return SAV.GetPartyOffset(slot - (int)SlotIndex.Party);
if (slot < (int)SlotIndex.Daycare) // Battle Box Slot
return SAV.BattleBox + (slot - (int)SlotIndex.BattleBox) * SAV.SIZE_STORED;
if (slot < (int)SlotIndex.GTS) // Daycare
return SAV.GetDaycareSlotOffset(SAV.DaycareIndex, slot - (int)SlotIndex.Daycare);
if (slot == (int)SlotIndex.Fused) // GTS
return SAV.GTS;
slot -= 1;
if (slot == (int)SlotIndex.SUBE) // Fused
return SAV.Fused;
slot -= 1;
if (slot < (int)SlotIndex.SUBE + 3) // SUBE
return SAV.SUBE + (slot - (int)SlotIndex.SUBE) * (SAV.SIZE_STORED + 4);
return -1;
slot -= 30+6+6+2;
return SL_Extra.GetSlotOffset(slot);
}
public int GetSlot(object sender) => Array.IndexOf(SlotPictureBoxes, WinFormsUtil.GetUnderlyingControl(sender));
public int GetSlot(object sender)
{
int slot = Array.IndexOf(SlotPictureBoxes, WinFormsUtil.GetUnderlyingControl(sender));
if (slot < 0) // check extra slots
slot = SL_Extra.GetSlot(sender) + SlotPictureBoxes.Length;
return slot;
}
public int SwapBoxesViewer(int viewBox)
{
int mainBox = Box.CurrentBox;
@ -163,21 +169,9 @@ namespace PKHeX.WinForms.Controls
}
private void ResetMiscSlots()
{
if (SAV.HasGTS) // GTS
GetSlotFiller(SAV.GTS, SlotPictureBoxes[(int)SlotIndex.GTS]);
if (SAV.HasFused) // Fused
GetSlotFiller(SAV.Fused, SlotPictureBoxes[(int)SlotIndex.Fused]);
if (SAV.HasSUBE) // SUBE
for (int i = 0; i < 3; i++)
{
int offset = SAV.SUBE + i * (SAV.SIZE_STORED + 4);
var pb = SlotPictureBoxes[(int) SlotIndex.SUBE + i];
if (BitConverter.ToUInt64(SAV.Data, offset) != 0)
GetSlotFiller(offset, pb);
else pb.Image = null;
}
var slots = SL_Extra.SlotPictureBoxes;
for (int i = 0; i < SL_Extra.SlotCount; i++)
GetSlotFiller(SL_Extra.GetSlotOffset(i), slots[i]);
}
private void ResetParty()
{
@ -988,8 +982,6 @@ namespace PKHeX.WinForms.Controls
{
PAN_BattleBox.Visible = L_BattleBox.Visible = L_ReadOnlyPBB.Visible = sav.HasBattleBox;
GB_Daycare.Visible = sav.HasDaycare;
GB_Fused.Visible = sav.HasFused;
GB_GTS.Visible = sav.HasGTS;
B_OpenSecretBase.Enabled = sav.HasSecretBase;
B_OpenPokepuffs.Enabled = sav.HasPuff;
B_OpenPokeBeans.Enabled = sav.Generation == 7;
@ -1019,6 +1011,13 @@ namespace PKHeX.WinForms.Controls
B_OpenUGSEditor.Enabled = sav.DP || sav.Pt;
B_FestivalPlaza.Enabled = sav.Generation == 7;
B_MailBox.Enabled = sav.Generation >= 2 && sav.Generation <= 5;
var slots = SL_Extra.Initialize(sav.GetExtraSlots(HaX), InitializeDragDrop);
Box.SlotPictureBoxes.AddRange(slots);
}
else
{
SL_Extra.HideAllSlots();
}
GB_SAVtools.Visible = sav.Exportable && FLP_SAVtools.Controls.Cast<Control>().Any(c => c.Enabled);
foreach (Control c in FLP_SAVtools.Controls.Cast<Control>())
@ -1029,7 +1028,6 @@ namespace PKHeX.WinForms.Controls
// Generational Interface
TB_Secure1.Visible = TB_Secure2.Visible = L_Secure1.Visible = L_Secure2.Visible = sav.Exportable && sav.Generation >= 6;
TB_GameSync.Visible = L_GameSync.Visible = sav.Exportable && sav.Generation >= 6;
GB_SUBE.Visible = SAV.HasSUBE;
B_VerifyCHK.Enabled = SAV.Exportable;
if (sav.Version == GameVersion.BATREV)

View file

@ -313,6 +313,9 @@
<metadata name="Tab_Other.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="SL_Extra.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="GB_Daycare.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
@ -349,33 +352,9 @@
<metadata name="DayCare_HasEgg.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="GB_GTS.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="gtspkx.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="GB_Fused.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="fusedpkx.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="L_ReadOnlyOther.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="GB_SUBE.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="subepkx1.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="subepkx2.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="subepkx3.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Tab_SAV.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
@ -490,6 +469,12 @@
<metadata name="B_Roamer.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_FestivalPlaza.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_MailBox.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_OpenApricorn.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>

View file

@ -33,6 +33,7 @@
//
// FLP_Slots
//
this.FLP_Slots.AutoScroll = true;
this.FLP_Slots.Dock = System.Windows.Forms.DockStyle.Fill;
this.FLP_Slots.Location = new System.Drawing.Point(0, 0);
this.FLP_Slots.Name = "FLP_Slots";
@ -41,8 +42,7 @@
//
// SlotList
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
this.Controls.Add(this.FLP_Slots);
this.Name = "SlotList";
this.Size = new System.Drawing.Size(86, 32);

View file

@ -1,5 +1,7 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using PKHeX.Core;
namespace PKHeX.WinForms.Controls
{
@ -7,36 +9,75 @@ namespace PKHeX.WinForms.Controls
{
public IReadOnlyList<PictureBox> SlotPictureBoxes => slots;
private static readonly string[] names = Enum.GetNames(typeof(StorageSlotType));
private readonly LabelType[] Labels = new LabelType[names.Length];
private readonly List<PictureBox> slots = new List<PictureBox>();
private int SlotCount => slots.Count;
private List<StorageSlotOffset> SlotOffsets = new List<StorageSlotOffset>();
public int SlotCount { get; private set; }
public SlotChangeManager M { get; set; }
public SlotList()
{
InitializeComponent();
AddLabels();
}
/// <summary>
/// Initializes the extra slot viewers with a list of offsets and sets up event handling.
/// </summary>
/// <param name="list">Extra slots to show</param>
/// <param name="enableDragDropContext">Events to set up</param>
/// <remarks>Uses an object pool for viewers (only generates as needed)</remarks>
/// <returns>A list of picture boxes that were added to the view pool</returns>
public IEnumerable<PictureBox> Initialize(List<StorageSlotOffset> list, Action<Control> enableDragDropContext)
{
SlotOffsets = list;
return LoadSlots(list.Count, enableDragDropContext);
}
/// <summary>
/// Hides all slots from the <see cref="SlotList"/>.
/// </summary>
public void HideAllSlots() => LoadSlots(0, null);
public int GetSlot(object sender) => slots.IndexOf(WinFormsUtil.GetUnderlyingControl(sender) as PictureBox);
public void AddSlots(int count)
public int GetSlotOffset(int slot) => SlotOffsets[slot].Offset;
private IEnumerable<PictureBox> LoadSlots(int after, Action<Control> enableDragDropContext)
{
for (int i = SlotCount; i < count; i++)
var generated = new List<PictureBox>();
int before = SlotCount;
SlotCount = after;
int diff = after - before;
if (diff > 0)
{
AddSlots(diff);
for (int i = before; i < after; i++)
{
var slot = slots[i];
enableDragDropContext(slot);
FLP_Slots.Controls.Add(slot);
FLP_Slots.SetFlowBreak(slot, true);
generated.Add(slot);
}
}
else
{
for (int i = before - 1; i >= after; i--)
FLP_Slots.Controls.Remove(slots[i]);
}
SetLabelVisibility();
return generated;
}
private void AddSlots(int count)
{
for (int i = 0; i < count; i++)
slots.Add(GetPictureBox(i));
}
private int _slotsperrow;
public int SlotsPerRow
{
get => _slotsperrow;
set
{
_slotsperrow = value;
Width = value * (SlotWidth + 2 + PadPixels) - PadPixels;
Height = (SlotCount / value + 1) * (SlotHeight + PadPixels) - PadPixels;
}
}
private const int PadPixels = 2;
private const int SlotWidth = 30;
private const int SlotHeight = 40;
private const int SlotWidth = 40;
private const int SlotHeight = 30;
private static PictureBox GetPictureBox(int index)
{
return new PictureBox
@ -45,9 +86,51 @@ namespace PKHeX.WinForms.Controls
Width = SlotWidth + 2,
Height = SlotHeight + 2,
AllowDrop = true,
Margin = new Padding(PadPixels),
SizeMode = PictureBoxSizeMode.CenterImage,
Name = $"bpkm{index}",
};
}
private class LabelType : Label
{
public StorageSlotType Type;
}
private void AddLabels()
{
for (var i = 0; i < names.Length; i++)
{
var name = names[i];
Enum.TryParse<StorageSlotType>(name, out var val);
var label = new LabelType
{
Name = $"L_{name}",
Text = name,
Type = val,
AutoSize = true,
Visible = false,
};
Labels[i] = label;
FLP_Slots.Controls.Add(label);
FLP_Slots.SetFlowBreak(label, true);
}
}
private void SetLabelVisibility()
{
foreach (var l in Labels)
{
int index = SlotOffsets.FindIndex(z => z.Type == l.Type);
if (index < 0)
{
l.Visible = false;
continue;
}
int pos = FLP_Slots.Controls.IndexOf(slots[index]);
if (pos > FLP_Slots.Controls.IndexOf(l))
pos--;
FLP_Slots.Controls.SetChildIndex(l, pos);
l.Visible = true;
}
}
}
}