mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-05-06 05:27:14 -05:00
Add box movement to box layout editor
Box insertion (movement gap ex/ 5->13) untested and not used in code box movement checked for locked slots
This commit is contained in:
parent
29a1a83b07
commit
4636042fe1
|
|
@ -73,9 +73,9 @@ public virtual byte[] Write(bool DSV)
|
|||
public bool E => Version == GameVersion.E;
|
||||
public bool FRLG => Version == GameVersion.FRLG;
|
||||
public bool RS => Version == GameVersion.RS;
|
||||
public bool RBY => Version == GameVersion.RBY;
|
||||
|
||||
public bool GSC => Version == GameVersion.GS || Version == GameVersion.C;
|
||||
public bool RBY => Version == GameVersion.RBY;
|
||||
public bool GameCube => new[] { GameVersion.COLO, GameVersion.XD, GameVersion.RSBOX }.Contains(Version);
|
||||
|
||||
public virtual int MaxMoveID => int.MaxValue;
|
||||
public virtual int MaxSpeciesID => int.MaxValue;
|
||||
|
|
@ -361,6 +361,81 @@ public virtual MysteryGiftAlbum GiftAlbum
|
|||
public virtual int CurrentBox { get { return 0; } set { } }
|
||||
protected int[] LockedSlots = new int[0];
|
||||
protected int[] TeamSlots = new int[0];
|
||||
public bool MoveBox(int box, int insertBeforeBox)
|
||||
{
|
||||
if (box == insertBeforeBox) // no movement required
|
||||
return true;
|
||||
if (box >= BoxCount || insertBeforeBox >= BoxCount) // invalid box positions
|
||||
return false;
|
||||
|
||||
int pos1 = BoxSlotCount*box;
|
||||
int pos2 = BoxSlotCount*insertBeforeBox;
|
||||
int min = Math.Min(pos1, pos2);
|
||||
int max = Math.Max(pos1, pos2);
|
||||
if (LockedSlots.Any(slot => min <= slot && slot < max)) // slots locked within operation range
|
||||
return false;
|
||||
|
||||
int len = BoxSlotCount*SIZE_STORED;
|
||||
byte[] boxdata = getData(getBoxOffset(0), len*BoxCount); // get all boxes
|
||||
string[] boxNames = new int[BoxCount].Select((x, i) => getBoxName(i)).ToArray();
|
||||
int[] boxWallpapers = new int[BoxCount].Select((x, i) => getBoxWallpaper(i)).ToArray();
|
||||
|
||||
min /= BoxSlotCount;
|
||||
max /= BoxSlotCount;
|
||||
|
||||
// move all boxes within range to final spot
|
||||
for (int i = min, ctr = min; i < max; i++)
|
||||
{
|
||||
int b = insertBeforeBox; // if box is the moved box, move to insertion point, else move to unused box.
|
||||
if (i != box)
|
||||
{
|
||||
if (insertBeforeBox == ctr)
|
||||
++ctr;
|
||||
b = ctr++;
|
||||
}
|
||||
Array.Copy(boxdata, len*i, Data, getBoxOffset(b), len);
|
||||
setBoxName(b, boxNames[i]);
|
||||
setBoxWallpaper(b, boxWallpapers[i]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool SwapBox(int box1, int box2)
|
||||
{
|
||||
if (box1 == box2) // no movement required
|
||||
return true;
|
||||
if (box1 >= BoxCount || box2 >= BoxCount) // invalid box positions
|
||||
return false;
|
||||
|
||||
int min = BoxSlotCount * box1;
|
||||
int max = BoxSlotCount * box1 + BoxSlotCount;
|
||||
if (LockedSlots.Any(slot => min <= slot && slot < max)) // slots locked within box
|
||||
return false;
|
||||
|
||||
min = BoxSlotCount * box2;
|
||||
max = BoxSlotCount * box2 + BoxSlotCount;
|
||||
if (LockedSlots.Any(slot => min <= slot && slot < max)) // slots locked within box
|
||||
return false;
|
||||
|
||||
// Data
|
||||
int b1o = getBoxOffset(box1);
|
||||
int b2o = getBoxOffset(box2);
|
||||
int len = BoxSlotCount*SIZE_STORED;
|
||||
byte[] b1 = new byte[len];
|
||||
Array.Copy(Data, b1o, b1, 0, len);
|
||||
Array.Copy(Data, b2o, Data, b1o, len);
|
||||
Array.Copy(b1, 0, Data, b2o, len);
|
||||
|
||||
// Name
|
||||
string b1n = getBoxName(box1);
|
||||
setBoxName(box1, getBoxName(box2));
|
||||
setBoxName(box2, b1n);
|
||||
|
||||
// Wallpaper
|
||||
int b1w = getBoxWallpaper(box1);
|
||||
setBoxWallpaper(box1, getBoxWallpaper(box2));
|
||||
setBoxWallpaper(box2, b1w);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected virtual int getBoxWallpaperOffset(int box) { return -1; }
|
||||
public int getBoxWallpaper(int box)
|
||||
|
|
|
|||
|
|
@ -42,6 +42,8 @@ private void InitializeComponent()
|
|||
this.CB_Unlocked = new System.Windows.Forms.ComboBox();
|
||||
this.FLP_Flags = new System.Windows.Forms.FlowLayoutPanel();
|
||||
this.L_Flag = new System.Windows.Forms.Label();
|
||||
this.B_Up = new System.Windows.Forms.Button();
|
||||
this.B_Down = new System.Windows.Forms.Button();
|
||||
this.FLP_Misc.SuspendLayout();
|
||||
this.FLP_Unlocked.SuspendLayout();
|
||||
this.FLP_Flags.SuspendLayout();
|
||||
|
|
@ -62,7 +64,7 @@ private void InitializeComponent()
|
|||
//
|
||||
// TB_BoxName
|
||||
//
|
||||
this.TB_BoxName.Location = new System.Drawing.Point(133, 35);
|
||||
this.TB_BoxName.Location = new System.Drawing.Point(158, 35);
|
||||
this.TB_BoxName.MaxLength = 15;
|
||||
this.TB_BoxName.Name = "TB_BoxName";
|
||||
this.TB_BoxName.Size = new System.Drawing.Size(136, 20);
|
||||
|
|
@ -73,7 +75,7 @@ private void InitializeComponent()
|
|||
// L_BoxName
|
||||
//
|
||||
this.L_BoxName.AutoSize = true;
|
||||
this.L_BoxName.Location = new System.Drawing.Point(131, 19);
|
||||
this.L_BoxName.Location = new System.Drawing.Point(156, 19);
|
||||
this.L_BoxName.Name = "L_BoxName";
|
||||
this.L_BoxName.Size = new System.Drawing.Size(59, 13);
|
||||
this.L_BoxName.TabIndex = 2;
|
||||
|
|
@ -82,7 +84,7 @@ private void InitializeComponent()
|
|||
// B_Save
|
||||
//
|
||||
this.B_Save.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.B_Save.Location = new System.Drawing.Point(303, 255);
|
||||
this.B_Save.Location = new System.Drawing.Point(328, 255);
|
||||
this.B_Save.Name = "B_Save";
|
||||
this.B_Save.Size = new System.Drawing.Size(67, 23);
|
||||
this.B_Save.TabIndex = 9;
|
||||
|
|
@ -93,7 +95,7 @@ private void InitializeComponent()
|
|||
// B_Cancel
|
||||
//
|
||||
this.B_Cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.B_Cancel.Location = new System.Drawing.Point(303, 284);
|
||||
this.B_Cancel.Location = new System.Drawing.Point(328, 284);
|
||||
this.B_Cancel.Name = "B_Cancel";
|
||||
this.B_Cancel.Size = new System.Drawing.Size(67, 23);
|
||||
this.B_Cancel.TabIndex = 10;
|
||||
|
|
@ -103,9 +105,10 @@ private void InitializeComponent()
|
|||
//
|
||||
// CB_BG
|
||||
//
|
||||
this.CB_BG.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.CB_BG.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.CB_BG.FormattingEnabled = true;
|
||||
this.CB_BG.Location = new System.Drawing.Point(275, 34);
|
||||
this.CB_BG.Location = new System.Drawing.Point(300, 34);
|
||||
this.CB_BG.Name = "CB_BG";
|
||||
this.CB_BG.Size = new System.Drawing.Size(98, 21);
|
||||
this.CB_BG.TabIndex = 13;
|
||||
|
|
@ -117,9 +120,9 @@ private void InitializeComponent()
|
|||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.PAN_BG.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.PAN_BG.Location = new System.Drawing.Point(133, 61);
|
||||
this.PAN_BG.Location = new System.Drawing.Point(126, 61);
|
||||
this.PAN_BG.Name = "PAN_BG";
|
||||
this.PAN_BG.Size = new System.Drawing.Size(240, 160);
|
||||
this.PAN_BG.Size = new System.Drawing.Size(272, 160);
|
||||
this.PAN_BG.TabIndex = 14;
|
||||
//
|
||||
// FLP_Misc
|
||||
|
|
@ -128,9 +131,9 @@ private void InitializeComponent()
|
|||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.FLP_Misc.Controls.Add(this.FLP_Unlocked);
|
||||
this.FLP_Misc.Controls.Add(this.FLP_Flags);
|
||||
this.FLP_Misc.Location = new System.Drawing.Point(133, 234);
|
||||
this.FLP_Misc.Location = new System.Drawing.Point(129, 234);
|
||||
this.FLP_Misc.Name = "FLP_Misc";
|
||||
this.FLP_Misc.Size = new System.Drawing.Size(164, 73);
|
||||
this.FLP_Misc.Size = new System.Drawing.Size(193, 73);
|
||||
this.FLP_Misc.TabIndex = 15;
|
||||
//
|
||||
// FLP_Unlocked
|
||||
|
|
@ -139,7 +142,7 @@ private void InitializeComponent()
|
|||
this.FLP_Unlocked.Controls.Add(this.CB_Unlocked);
|
||||
this.FLP_Unlocked.Location = new System.Drawing.Point(3, 3);
|
||||
this.FLP_Unlocked.Name = "FLP_Unlocked";
|
||||
this.FLP_Unlocked.Size = new System.Drawing.Size(161, 25);
|
||||
this.FLP_Unlocked.Size = new System.Drawing.Size(185, 25);
|
||||
this.FLP_Unlocked.TabIndex = 16;
|
||||
//
|
||||
// L_Unlocked
|
||||
|
|
@ -166,7 +169,7 @@ private void InitializeComponent()
|
|||
this.FLP_Flags.Controls.Add(this.L_Flag);
|
||||
this.FLP_Flags.Location = new System.Drawing.Point(3, 34);
|
||||
this.FLP_Flags.Name = "FLP_Flags";
|
||||
this.FLP_Flags.Size = new System.Drawing.Size(161, 25);
|
||||
this.FLP_Flags.Size = new System.Drawing.Size(185, 25);
|
||||
this.FLP_Flags.TabIndex = 17;
|
||||
//
|
||||
// L_Flag
|
||||
|
|
@ -178,11 +181,33 @@ private void InitializeComponent()
|
|||
this.L_Flag.Text = "Flags:";
|
||||
this.L_Flag.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
|
||||
//
|
||||
// B_Up
|
||||
//
|
||||
this.B_Up.Location = new System.Drawing.Point(124, 13);
|
||||
this.B_Up.Name = "B_Up";
|
||||
this.B_Up.Size = new System.Drawing.Size(23, 23);
|
||||
this.B_Up.TabIndex = 16;
|
||||
this.B_Up.Text = "^";
|
||||
this.B_Up.UseVisualStyleBackColor = true;
|
||||
this.B_Up.Click += new System.EventHandler(this.moveBox);
|
||||
//
|
||||
// B_Down
|
||||
//
|
||||
this.B_Down.Location = new System.Drawing.Point(124, 35);
|
||||
this.B_Down.Name = "B_Down";
|
||||
this.B_Down.Size = new System.Drawing.Size(23, 23);
|
||||
this.B_Down.TabIndex = 17;
|
||||
this.B_Down.Text = "v";
|
||||
this.B_Down.UseVisualStyleBackColor = true;
|
||||
this.B_Down.Click += new System.EventHandler(this.moveBox);
|
||||
//
|
||||
// SAV_BoxLayout
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(384, 321);
|
||||
this.ClientSize = new System.Drawing.Size(409, 321);
|
||||
this.Controls.Add(this.B_Down);
|
||||
this.Controls.Add(this.B_Up);
|
||||
this.Controls.Add(this.FLP_Misc);
|
||||
this.Controls.Add(this.PAN_BG);
|
||||
this.Controls.Add(this.CB_BG);
|
||||
|
|
@ -221,5 +246,7 @@ private void InitializeComponent()
|
|||
private System.Windows.Forms.FlowLayoutPanel FLP_Unlocked;
|
||||
private System.Windows.Forms.FlowLayoutPanel FLP_Flags;
|
||||
private System.Windows.Forms.Label L_Flag;
|
||||
private System.Windows.Forms.Button B_Up;
|
||||
private System.Windows.Forms.Button B_Down;
|
||||
}
|
||||
}
|
||||
|
|
@ -17,6 +17,11 @@ public SAV_BoxLayout(int box)
|
|||
|
||||
switch (SAV.Generation)
|
||||
{
|
||||
case 3:
|
||||
if (SAV.GameCube)
|
||||
goto default;
|
||||
CB_BG.Items.AddRange(Main.GameStrings.wallpapernames.Take(16).ToArray());
|
||||
break;
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
|
|
@ -26,8 +31,8 @@ public SAV_BoxLayout(int box)
|
|||
CB_BG.Items.AddRange(Main.GameStrings.wallpapernames.Take(16).ToArray());
|
||||
break;
|
||||
default:
|
||||
Util.Error("Box layout is not supported for this game.");
|
||||
return;
|
||||
Util.Error("Box layout is not supported for this game.", "Please close the window.");
|
||||
break;
|
||||
}
|
||||
|
||||
// Go
|
||||
|
|
@ -121,5 +126,50 @@ private void changeBoxBG(object sender, EventArgs e)
|
|||
|
||||
PAN_BG.BackgroundImage = BoxWallpaper.getWallpaper(SAV, CB_BG.SelectedIndex);
|
||||
}
|
||||
|
||||
private bool MoveItem(int direction)
|
||||
{
|
||||
// Checking selected item
|
||||
if (LB_BoxSelect.SelectedItem == null || LB_BoxSelect.SelectedIndex < 0)
|
||||
return false; // No selected item - nothing to do
|
||||
|
||||
// Calculate new index using move direction
|
||||
int newIndex = LB_BoxSelect.SelectedIndex + direction;
|
||||
|
||||
// Checking bounds of the range
|
||||
if (newIndex < 0 || newIndex >= LB_BoxSelect.Items.Count)
|
||||
return false; // Index out of range - nothing to do
|
||||
|
||||
object selected = LB_BoxSelect.SelectedItem;
|
||||
|
||||
// Removing removable element
|
||||
LB_BoxSelect.Items.Remove(selected);
|
||||
// Insert it in new position
|
||||
LB_BoxSelect.Items.Insert(newIndex, selected);
|
||||
// Restore selection
|
||||
LB_BoxSelect.SetSelected(newIndex, true);
|
||||
editing = renameBox = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void moveBox(object sender, EventArgs e)
|
||||
{
|
||||
int index = LB_BoxSelect.SelectedIndex;
|
||||
int dir = sender == B_Up ? -1 : +1;
|
||||
editing = renameBox = true;
|
||||
if (!MoveItem(dir))
|
||||
{
|
||||
System.Media.SystemSounds.Asterisk.Play();
|
||||
}
|
||||
else if (!SAV.SwapBox(index, index + dir)) // valid but locked
|
||||
{
|
||||
MoveItem(-dir); // undo
|
||||
Util.Alert("Locked slots prevent movement of box(es).");
|
||||
}
|
||||
else
|
||||
changeBox(null, null);
|
||||
editing = renameBox = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user