Clear empty wc6 slots, show current action slot

Like the main window, indicate which slot the user has
viewed/set/deleted.

Cards with cardID=0 are removed (none existing)
This commit is contained in:
Kurt
2015-12-18 20:48:47 -08:00
parent fbbb99037c
commit e2a176aac6
2 changed files with 27 additions and 6 deletions

View File

@@ -195,7 +195,7 @@ private void InitializeComponent()
this.B_WCSlottoDisplay.TabIndex = 8;
this.B_WCSlottoDisplay.Text = ">";
this.B_WCSlottoDisplay.UseVisualStyleBackColor = true;
this.B_WCSlottoDisplay.Click += new System.EventHandler(this.B_SAV2WC);
this.B_WCSlottoDisplay.Click += new System.EventHandler(this.cardView);
//
// B_DisplaytoWCSlot
//
@@ -205,7 +205,7 @@ private void InitializeComponent()
this.B_DisplaytoWCSlot.TabIndex = 9;
this.B_DisplaytoWCSlot.Text = "<";
this.B_DisplaytoWCSlot.UseVisualStyleBackColor = true;
this.B_DisplaytoWCSlot.Click += new System.EventHandler(this.B_WC2SAV);
this.B_DisplaytoWCSlot.Click += new System.EventHandler(this.cardSet);
//
// RTB
//
@@ -236,7 +236,7 @@ private void InitializeComponent()
this.B_DeleteWC.TabIndex = 12;
this.B_DeleteWC.Text = "X";
this.B_DeleteWC.UseVisualStyleBackColor = true;
this.B_DeleteWC.Click += new System.EventHandler(this.B_DeleteWC_Click);
this.B_DeleteWC.Click += new System.EventHandler(this.cardDelete);
//
// B_DeleteFlag
//

View File

@@ -43,8 +43,26 @@ public SAV_Wondercard(byte[] wcdata = null)
private PictureBox[] pba;
// Repopulation Functions
private void setBackground(int index, Image bg)
{
for (int i = 0; i < 24; i++)
pba[i].BackgroundImage = index == i ? bg : null;
}
private void removeEmptyWC6s()
{
byte[][] ca = new byte[24][];
for (int i = 0; i < ca.Length; i++)
ca[i] = sav.Skip(Main.SAV.WondercardData + WC6.Size*i).Take(WC6.Size).ToArray();
ca = ca.Where(c => BitConverter.ToUInt16(c, 0) > 0).ToArray();
for (int i = 0; i < ca.Length; i++)
ca[i].CopyTo(sav, Main.SAV.WondercardData + WC6.Size * i);
for (int i = ca.Length; i < 24; i++)
new byte[WC6.Size].CopyTo(sav, Main.SAV.WondercardData + WC6.Size * i);
}
private void populateWClist()
{
removeEmptyWC6s();
LB_WCs.Items.Clear();
for (int i = 0; i < 24; i++)
{
@@ -132,18 +150,20 @@ private void B_Output_Click(object sender, EventArgs e)
}
// Wondercard RW (window<->sav)
private void B_SAV2WC(object sender, EventArgs e)
private void cardView(object sender, EventArgs e)
{
// Load Wondercard from Save File
int index = LB_WCs.SelectedIndex;
setBackground(index, Properties.Resources.slotView);
int offset = Main.SAV.WondercardData + index * 0x108;
Array.Copy(sav, offset, wondercard_data, 0, 0x108);
loadwcdata();
}
private void B_WC2SAV(object sender, EventArgs e)
private void cardSet(object sender, EventArgs e)
{
// Write Wondercard to Save File
int index = LB_WCs.SelectedIndex;
setBackground(index, Properties.Resources.slotSet);
int offset = Main.SAV.WondercardData + index * 0x108;
if (Main.SAV.ORAS) // ORAS Only
if (BitConverter.ToUInt16(wondercard_data, 0) == 0x800) // Eon Ticket #
@@ -158,9 +178,10 @@ private void B_WC2SAV(object sender, EventArgs e)
if (!LB_Received.Items.Contains(cardID.ToString("0000")))
LB_Received.Items.Add(cardID.ToString("0000"));
}
private void B_DeleteWC_Click(object sender, EventArgs e)
private void cardDelete(object sender, EventArgs e)
{
int index = LB_WCs.SelectedIndex;
setBackground(index, Properties.Resources.slotDel);
int offset = Main.SAV.WondercardData + index * 0x108;
byte[] zeros = new byte[0x108];
Array.Copy(zeros, 0, sav, offset, 0x108);