mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-26 22:10:21 +00:00
Change slot indexing to use an enum
Still need to figure out how to reconfigure everything to support ancillary slot displays (3x fused in USUM)
This commit is contained in:
parent
b229a947f2
commit
f690f4885c
1 changed files with 45 additions and 35 deletions
|
@ -108,26 +108,24 @@ namespace PKHeX.WinForms.Controls
|
||||||
// Generic Subfunctions //
|
// Generic Subfunctions //
|
||||||
public int GetPKMOffset(int slot, int box = -1)
|
public int GetPKMOffset(int slot, int box = -1)
|
||||||
{
|
{
|
||||||
if (slot < 30) // Box Slot
|
if (slot < (int)SlotIndex.Party) // Box Slot
|
||||||
return Box.GetOffset(slot, box);
|
return Box.GetOffset(slot, box);
|
||||||
slot -= 30;
|
|
||||||
if (slot < 6) // Party Slot
|
if (slot < (int)SlotIndex.BattleBox) // Party Slot
|
||||||
return SAV.GetPartyOffset(slot);
|
return SAV.GetPartyOffset(slot - (int)SlotIndex.Party);
|
||||||
slot -= 6;
|
if (slot < (int)SlotIndex.Daycare) // Battle Box Slot
|
||||||
if (slot < 6) // Battle Box Slot
|
return SAV.BattleBox + (slot - (int)SlotIndex.BattleBox) * SAV.SIZE_STORED;
|
||||||
return SAV.BattleBox + slot * SAV.SIZE_STORED;
|
|
||||||
slot -= 6;
|
if (slot < (int)SlotIndex.GTS) // Daycare
|
||||||
if (slot < 2) // Daycare
|
return SAV.GetDaycareSlotOffset(SAV.DaycareIndex, slot - (int)SlotIndex.Daycare);
|
||||||
return SAV.GetDaycareSlotOffset(SAV.DaycareIndex, slot);
|
if (slot == (int)SlotIndex.Fused) // GTS
|
||||||
slot -= 2;
|
|
||||||
if (slot == 0) // GTS
|
|
||||||
return SAV.GTS;
|
return SAV.GTS;
|
||||||
slot -= 1;
|
slot -= 1;
|
||||||
if (slot == 0) // Fused
|
if (slot == (int)SlotIndex.SUBE) // Fused
|
||||||
return SAV.Fused;
|
return SAV.Fused;
|
||||||
slot -= 1;
|
slot -= 1;
|
||||||
if (slot < 3) // SUBE
|
if (slot < (int)SlotIndex.SUBE + 3) // SUBE
|
||||||
return SAV.SUBE + slot * (SAV.SIZE_STORED + 4);
|
return SAV.SUBE + (slot - (int)SlotIndex.SUBE) * (SAV.SIZE_STORED + 4);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
public int GetSlot(object sender) => Array.IndexOf(SlotPictureBoxes, WinFormsUtil.GetUnderlyingControl(sender));
|
public int GetSlot(object sender) => Array.IndexOf(SlotPictureBoxes, WinFormsUtil.GetUnderlyingControl(sender));
|
||||||
|
@ -153,7 +151,7 @@ namespace PKHeX.WinForms.Controls
|
||||||
ResetNonBoxSlots();
|
ResetNonBoxSlots();
|
||||||
|
|
||||||
// Recoloring of a storage box slot (to not show for other storage boxes)
|
// Recoloring of a storage box slot (to not show for other storage boxes)
|
||||||
if (M?.colorizedslot >= 30)
|
if (M?.colorizedslot >= (int)SlotIndex.Party)
|
||||||
SlotPictureBoxes[M.colorizedslot].BackgroundImage = M.colorizedcolor;
|
SlotPictureBoxes[M.colorizedslot].BackgroundImage = M.colorizedcolor;
|
||||||
}
|
}
|
||||||
private void ResetNonBoxSlots()
|
private void ResetNonBoxSlots()
|
||||||
|
@ -166,28 +164,28 @@ namespace PKHeX.WinForms.Controls
|
||||||
private void ResetMiscSlots()
|
private void ResetMiscSlots()
|
||||||
{
|
{
|
||||||
if (SAV.HasGTS) // GTS
|
if (SAV.HasGTS) // GTS
|
||||||
GetSlotFiller(SAV.GTS, SlotPictureBoxes[44]);
|
GetSlotFiller(SAV.GTS, SlotPictureBoxes[(int)SlotIndex.GTS]);
|
||||||
|
|
||||||
if (SAV.HasFused) // Fused
|
if (SAV.HasFused) // Fused
|
||||||
GetSlotFiller(SAV.Fused, SlotPictureBoxes[45]);
|
GetSlotFiller(SAV.Fused, SlotPictureBoxes[(int)SlotIndex.Fused]);
|
||||||
|
|
||||||
if (SAV.HasSUBE) // SUBE
|
if (SAV.HasSUBE) // SUBE
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
int offset = SAV.SUBE + i * (SAV.SIZE_STORED + 4);
|
int offset = SAV.SUBE + i * (SAV.SIZE_STORED + 4);
|
||||||
|
var pb = SlotPictureBoxes[(int) SlotIndex.SUBE + i];
|
||||||
if (BitConverter.ToUInt64(SAV.Data, offset) != 0)
|
if (BitConverter.ToUInt64(SAV.Data, offset) != 0)
|
||||||
GetSlotFiller(offset, SlotPictureBoxes[46 + i]);
|
GetSlotFiller(offset, pb);
|
||||||
else SlotPictureBoxes[46 + i].Image = null;
|
else pb.Image = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ResetParty()
|
private void ResetParty()
|
||||||
{
|
{
|
||||||
if (!SAV.HasParty)
|
if (!SAV.HasParty)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (int i = 0; i < 6; i++)
|
for (int i = 0; i < 6; i++)
|
||||||
GetSlotFiller(SAV.GetPartyOffset(i), SlotPictureBoxes[i + 30]);
|
GetSlotFiller(SAV.GetPartyOffset(i), SlotPictureBoxes[i + (int)SlotIndex.Party]);
|
||||||
}
|
}
|
||||||
private void ResetBattleBox()
|
private void ResetBattleBox()
|
||||||
{
|
{
|
||||||
|
@ -195,7 +193,7 @@ namespace PKHeX.WinForms.Controls
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (int i = 0; i < 6; i++)
|
for (int i = 0; i < 6; i++)
|
||||||
GetSlotFiller(SAV.BattleBox + SAV.SIZE_STORED * i, SlotPictureBoxes[i + 36]);
|
GetSlotFiller(SAV.BattleBox + SAV.SIZE_STORED * i, SlotPictureBoxes[i + (int)SlotIndex.BattleBox]);
|
||||||
}
|
}
|
||||||
private void ResetDaycare()
|
private void ResetDaycare()
|
||||||
{
|
{
|
||||||
|
@ -208,7 +206,8 @@ namespace PKHeX.WinForms.Controls
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
GetSlotFiller(SAV.GetDaycareSlotOffset(SAV.DaycareIndex, i), SlotPictureBoxes[i + 42]);
|
var pb = SlotPictureBoxes[i + (int)SlotIndex.Daycare];
|
||||||
|
GetSlotFiller(SAV.GetDaycareSlotOffset(SAV.DaycareIndex, i), pb);
|
||||||
uint? exp = SAV.GetDaycareEXP(SAV.DaycareIndex, i);
|
uint? exp = SAV.GetDaycareEXP(SAV.DaycareIndex, i);
|
||||||
TB_SlotEXP[i].Visible = L_SlotEXP[i].Visible = exp != null;
|
TB_SlotEXP[i].Visible = L_SlotEXP[i].Visible = exp != null;
|
||||||
TB_SlotEXP[i].Text = exp.ToString();
|
TB_SlotEXP[i].Text = exp.ToString();
|
||||||
|
@ -219,7 +218,7 @@ namespace PKHeX.WinForms.Controls
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
L_SlotOccupied[i].Text = $"{i + 1}: ✘";
|
L_SlotOccupied[i].Text = $"{i + 1}: ✘";
|
||||||
SlotPictureBoxes[i + 42].Image = ImageUtil.ChangeOpacity(SlotPictureBoxes[i + 42].Image, 0.6);
|
pb.Image = ImageUtil.ChangeOpacity(pb.Image, 0.6);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,17 +241,17 @@ namespace PKHeX.WinForms.Controls
|
||||||
{
|
{
|
||||||
var party = SAV.PartyData;
|
var party = SAV.PartyData;
|
||||||
for (int i = 0; i < party.Count; i++)
|
for (int i = 0; i < party.Count; i++)
|
||||||
SlotPictureBoxes[i + 30].Image = GetSprite(party[i], i + 30);
|
SlotPictureBoxes[i + (int)SlotIndex.Party].Image = GetSprite(party[i], i + (int)SlotIndex.Party);
|
||||||
for (int i = party.Count; i < 6; i++)
|
for (int i = party.Count; i < 6; i++)
|
||||||
SlotPictureBoxes[i + 30].Image = null;
|
SlotPictureBoxes[i + (int)SlotIndex.Party].Image = null;
|
||||||
}
|
}
|
||||||
if (SAV.HasBattleBox)
|
if (SAV.HasBattleBox)
|
||||||
{
|
{
|
||||||
var battle = SAV.BattleBoxData;
|
var battle = SAV.BattleBoxData;
|
||||||
for (int i = 0; i < battle.Count; i++)
|
for (int i = 0; i < battle.Count; i++)
|
||||||
SlotPictureBoxes[i + 36].Image = GetSprite(battle[i], i + 36);
|
SlotPictureBoxes[i + (int)SlotIndex.BattleBox].Image = GetSprite(battle[i], i + (int)SlotIndex.BattleBox);
|
||||||
for (int i = battle.Count; i < 6; i++)
|
for (int i = battle.Count; i < 6; i++)
|
||||||
SlotPictureBoxes[i + 36].Image = null;
|
SlotPictureBoxes[i + (int)SlotIndex.BattleBox].Image = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void ClickUndo()
|
public void ClickUndo()
|
||||||
|
@ -261,7 +260,7 @@ namespace PKHeX.WinForms.Controls
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SlotChange change = UndoStack.Pop();
|
SlotChange change = UndoStack.Pop();
|
||||||
if (change.Slot >= 30)
|
if (change.Slot >= (int)SlotIndex.Party)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
RedoStack.Push(new SlotChange
|
RedoStack.Push(new SlotChange
|
||||||
|
@ -280,7 +279,7 @@ namespace PKHeX.WinForms.Controls
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SlotChange change = RedoStack.Pop();
|
SlotChange change = RedoStack.Pop();
|
||||||
if (change.Slot >= 30)
|
if (change.Slot >= (int)SlotIndex.Party)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
UndoStack.Push(new SlotChange
|
UndoStack.Push(new SlotChange
|
||||||
|
@ -432,7 +431,7 @@ namespace PKHeX.WinForms.Controls
|
||||||
}
|
}
|
||||||
private void ClickClone(object sender, EventArgs e)
|
private void ClickClone(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (GetSlot(sender) > 30)
|
if (GetSlot(sender) >= (int)SlotIndex.Party)
|
||||||
return; // only perform action if cloning to boxes
|
return; // only perform action if cloning to boxes
|
||||||
RequestCloneData?.Invoke(sender, e);
|
RequestCloneData?.Invoke(sender, e);
|
||||||
}
|
}
|
||||||
|
@ -1069,7 +1068,7 @@ namespace PKHeX.WinForms.Controls
|
||||||
if (pb.Image == null)
|
if (pb.Image == null)
|
||||||
return;
|
return;
|
||||||
int slot = GetSlot(pb);
|
int slot = GetSlot(pb);
|
||||||
int box = slot >= 30 ? -1 : Box.CurrentBox;
|
int box = slot >= (int)SlotIndex.Party ? -1 : Box.CurrentBox;
|
||||||
if (SAV.IsSlotLocked(box, slot))
|
if (SAV.IsSlotLocked(box, slot))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -1083,8 +1082,8 @@ namespace PKHeX.WinForms.Controls
|
||||||
|
|
||||||
PictureBox pb = (PictureBox)sender;
|
PictureBox pb = (PictureBox)sender;
|
||||||
int slot = GetSlot(pb);
|
int slot = GetSlot(pb);
|
||||||
int box = slot >= 30 ? -1 : Box.CurrentBox;
|
int box = slot >= (int)SlotIndex.Party ? -1 : Box.CurrentBox;
|
||||||
if (SAV.IsSlotLocked(box, slot) || slot >= 36)
|
if (SAV.IsSlotLocked(box, slot) || slot >= (int)SlotIndex.BattleBox)
|
||||||
{
|
{
|
||||||
SystemSounds.Asterisk.Play();
|
SystemSounds.Asterisk.Play();
|
||||||
e.Effect = DragDropEffects.Copy;
|
e.Effect = DragDropEffects.Copy;
|
||||||
|
@ -1153,5 +1152,16 @@ namespace PKHeX.WinForms.Controls
|
||||||
new SAV_MailBox(SAV).ShowDialog();
|
new SAV_MailBox(SAV).ShowDialog();
|
||||||
ResetParty();
|
ResetParty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private enum SlotIndex
|
||||||
|
{
|
||||||
|
Box = 0, // -> 29 [30]
|
||||||
|
Party = 30, // -> 35 [6]
|
||||||
|
BattleBox = 36, // -> 41 [6]
|
||||||
|
Daycare = 42,
|
||||||
|
GTS = 44,
|
||||||
|
Fused = 45,
|
||||||
|
SUBE = 46,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue