2017-12-02 22:20:56 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using PKHeX.Core;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.WinForms
|
|
|
|
|
{
|
|
|
|
|
public partial class SAV_MailBox : Form
|
|
|
|
|
{
|
|
|
|
|
private readonly SaveFile Origin;
|
|
|
|
|
private readonly SaveFile SAV;
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-12-02 22:20:56 +00:00
|
|
|
|
public SAV_MailBox(SaveFile sav)
|
|
|
|
|
{
|
2018-04-03 03:36:13 +00:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
2017-12-02 22:20:56 +00:00
|
|
|
|
SAV = (Origin = sav).Clone();
|
|
|
|
|
Gen = SAV.Generation;
|
|
|
|
|
p = SAV.PartyData;
|
|
|
|
|
editing = true;
|
|
|
|
|
|
2017-12-03 03:12:04 +00:00
|
|
|
|
Messages = new[]
|
|
|
|
|
{
|
2017-12-02 22:20:56 +00:00
|
|
|
|
new[] { NUD_Message00, NUD_Message01, NUD_Message02, NUD_Message03 },
|
|
|
|
|
new[] { NUD_Message10, NUD_Message11, NUD_Message12, NUD_Message13 },
|
|
|
|
|
new[] { NUD_Message20, NUD_Message21, NUD_Message22, NUD_Message23 }
|
|
|
|
|
};
|
|
|
|
|
PKMLabels = new[] { L_PKM1, L_PKM2, L_PKM3, L_PKM4, L_PKM5, L_PKM6 };
|
|
|
|
|
PKMHeldItems = new[] { L_HeldItem1, L_HeldItem2, L_HeldItem3, L_HeldItem4, L_HeldItem5, L_HeldItem6 };
|
|
|
|
|
PKMNUDs = new[] { NUD_MailID1, NUD_MailID2, NUD_MailID3, NUD_MailID4, NUD_MailID5, NUD_MailID6 };
|
|
|
|
|
AppearPKMs = new[] { CB_AppearPKM1, CB_AppearPKM2, CB_AppearPKM3 };
|
2017-12-03 14:48:04 +00:00
|
|
|
|
Miscs = new[] { NUD_Misc1, NUD_Misc2, NUD_Misc3 };
|
2017-12-02 22:20:56 +00:00
|
|
|
|
|
|
|
|
|
NUD_BoxSize.Visible = L_BoxSize.Visible = Gen == 2;
|
|
|
|
|
GB_MessageTB.Visible = Gen == 2;
|
|
|
|
|
GB_MessageNUD.Visible = Gen != 2;
|
2020-12-25 20:30:26 +00:00
|
|
|
|
Messages[0][3].Visible = Messages[1][3].Visible = Messages[2][3].Visible = Gen is 4 or 5;
|
2017-12-02 22:20:56 +00:00
|
|
|
|
NUD_AuthorSID.Visible = Gen != 2;
|
2020-12-25 20:30:26 +00:00
|
|
|
|
Label_OTGender.Visible = CB_AuthorLang.Visible = CB_AuthorVersion.Visible = Gen is 4 or 5;
|
2017-12-03 14:48:04 +00:00
|
|
|
|
L_AppearPKM.Visible = AppearPKMs[0].Visible = Gen != 5;
|
|
|
|
|
AppearPKMs[1].Visible = AppearPKMs[2].Visible = Gen == 4;
|
|
|
|
|
NUD_MessageEnding.Visible = Gen == 5;
|
|
|
|
|
L_MiscValue.Visible = NUD_Misc1.Visible = NUD_Misc2.Visible = NUD_Misc3.Visible = Gen == 5;
|
|
|
|
|
|
2017-12-02 22:20:56 +00:00
|
|
|
|
for (int i = p.Count; i < 6; i++)
|
|
|
|
|
PKMNUDs[i].Visible = PKMLabels[i].Visible = PKMHeldItems[i].Visible = false;
|
2017-12-03 14:48:04 +00:00
|
|
|
|
if (Gen != 3)
|
2017-12-02 22:20:56 +00:00
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < PKMNUDs.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
PKMNUDs[i].Value = i;
|
|
|
|
|
PKMNUDs[i].Enabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (SAV)
|
|
|
|
|
{
|
|
|
|
|
case SAV2 sav2:
|
|
|
|
|
m = new Mail2[6 + 10];
|
|
|
|
|
for (int i = 0; i < m.Length; i++)
|
|
|
|
|
m[i] = new Mail2(sav2, i);
|
|
|
|
|
|
|
|
|
|
NUD_BoxSize.Value = SAV.Data[0x834];
|
2017-12-03 02:24:48 +00:00
|
|
|
|
MailItemID = new[] { 0x9E, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD };
|
2019-07-05 04:48:18 +00:00
|
|
|
|
PartyBoxCount = 6;
|
2017-12-02 22:20:56 +00:00
|
|
|
|
break;
|
|
|
|
|
case SAV3 sav3:
|
|
|
|
|
m = new Mail3[6 + 10];
|
|
|
|
|
for (int i = 0; i < m.Length; i++)
|
2021-05-22 16:28:04 +00:00
|
|
|
|
m[i] = sav3.GetMail(i);
|
2017-12-02 22:20:56 +00:00
|
|
|
|
|
2021-05-22 16:28:04 +00:00
|
|
|
|
MailItemID = new[] {121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132};
|
2019-07-05 04:48:18 +00:00
|
|
|
|
PartyBoxCount = 6;
|
2017-12-02 22:20:56 +00:00
|
|
|
|
break;
|
|
|
|
|
case SAV4 sav4:
|
|
|
|
|
m = new Mail4[p.Count + 20];
|
|
|
|
|
for (int i = 0; i < p.Count; i++)
|
2020-12-05 14:09:33 +00:00
|
|
|
|
m[i] = new Mail4(((PK4)p[i]).GetHeldMailData());
|
2017-12-02 22:20:56 +00:00
|
|
|
|
for (int i = p.Count, j = 0; i < m.Length; i++, j++)
|
2021-05-22 16:28:04 +00:00
|
|
|
|
m[i] = sav4.GetMail(j);
|
|
|
|
|
var l4 = (Mail4)m[^1];
|
2017-12-03 14:48:04 +00:00
|
|
|
|
ResetVer = l4.AuthorVersion;
|
|
|
|
|
ResetLang = l4.AuthorLanguage;
|
2021-05-22 16:28:04 +00:00
|
|
|
|
MailItemID = new[] {137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148};
|
2019-07-05 04:48:18 +00:00
|
|
|
|
PartyBoxCount = p.Count;
|
2017-12-03 14:48:04 +00:00
|
|
|
|
break;
|
|
|
|
|
case SAV5 sav5:
|
|
|
|
|
m = new Mail5[p.Count + 20];
|
|
|
|
|
for (int i = 0; i < p.Count; i++)
|
2020-09-06 17:53:13 +00:00
|
|
|
|
m[i] = new Mail5(((PK5)p[i]).GetHeldMailData());
|
2017-12-03 14:48:04 +00:00
|
|
|
|
for (int i = p.Count, j = 0; i < m.Length; i++, j++)
|
2021-05-22 16:28:04 +00:00
|
|
|
|
m[i] = sav5.GetMail(j);
|
|
|
|
|
var l5 = (Mail5)m[^1];
|
2017-12-03 14:48:04 +00:00
|
|
|
|
ResetVer = l5.AuthorVersion;
|
|
|
|
|
ResetLang = l5.AuthorLanguage;
|
2021-05-22 16:28:04 +00:00
|
|
|
|
MailItemID = new[] {137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148};
|
2019-07-05 04:48:18 +00:00
|
|
|
|
PartyBoxCount = p.Count;
|
2017-12-02 22:20:56 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2017-12-03 14:48:04 +00:00
|
|
|
|
MakePartyList();
|
|
|
|
|
MakePCList();
|
2017-12-02 22:20:56 +00:00
|
|
|
|
|
2020-12-25 20:30:26 +00:00
|
|
|
|
if (Gen is 2 or 3)
|
2017-12-02 22:20:56 +00:00
|
|
|
|
{
|
|
|
|
|
CB_AppearPKM1.Items.Clear();
|
2018-07-14 23:00:28 +00:00
|
|
|
|
CB_AppearPKM1.InitializeBinding();
|
2019-10-28 03:39:07 +00:00
|
|
|
|
CB_AppearPKM1.DataSource = new BindingSource(GameInfo.FilteredSources.Species.ToList(), null);
|
2017-12-02 22:20:56 +00:00
|
|
|
|
}
|
2020-12-25 20:30:26 +00:00
|
|
|
|
else if (Gen is 4 or 5)
|
2017-12-02 22:20:56 +00:00
|
|
|
|
{
|
2019-10-28 03:39:07 +00:00
|
|
|
|
var species = GameInfo.FilteredSources.Species.ToList();
|
2017-12-03 14:48:04 +00:00
|
|
|
|
foreach (ComboBox a in AppearPKMs)
|
2017-12-02 22:20:56 +00:00
|
|
|
|
{
|
|
|
|
|
a.Items.Clear();
|
2018-07-14 23:00:28 +00:00
|
|
|
|
a.InitializeBinding();
|
2017-12-02 22:20:56 +00:00
|
|
|
|
a.DataSource = new BindingSource(species, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CB_AuthorVersion.Items.Clear();
|
2018-07-14 23:00:28 +00:00
|
|
|
|
CB_AuthorVersion.InitializeBinding();
|
2017-12-03 14:48:04 +00:00
|
|
|
|
CB_AuthorVersion.DataSource = new BindingSource(Gen == 4
|
|
|
|
|
? new[] {
|
2019-06-02 02:12:41 +00:00
|
|
|
|
new ComboItem("Diamond", (int)GameVersion.D),
|
|
|
|
|
new ComboItem("Pearl", (int)GameVersion.P),
|
|
|
|
|
new ComboItem("Platinum", (int)GameVersion.Pt),
|
|
|
|
|
new ComboItem("HeartGold", (int)GameVersion.HG),
|
|
|
|
|
new ComboItem("SoulSilver", (int)GameVersion.SS),
|
2019-10-28 03:39:07 +00:00
|
|
|
|
}
|
2017-12-03 14:48:04 +00:00
|
|
|
|
: new[] {
|
2019-06-02 02:12:41 +00:00
|
|
|
|
new ComboItem("Black", (int)GameVersion.B),
|
|
|
|
|
new ComboItem("White", (int)GameVersion.W),
|
|
|
|
|
new ComboItem("Black2", (int)GameVersion.B2),
|
|
|
|
|
new ComboItem("White2", (int)GameVersion.W2),
|
2019-10-28 03:39:07 +00:00
|
|
|
|
}, null);
|
2017-12-02 22:20:56 +00:00
|
|
|
|
|
2019-07-05 04:48:18 +00:00
|
|
|
|
CB_AuthorLang.Items.Clear();
|
2018-07-14 23:00:28 +00:00
|
|
|
|
CB_AuthorLang.InitializeBinding();
|
2017-12-03 03:12:04 +00:00
|
|
|
|
CB_AuthorLang.DataSource = new BindingSource(new[] {
|
2017-12-02 22:20:56 +00:00
|
|
|
|
// not sure
|
2019-06-02 02:12:41 +00:00
|
|
|
|
new ComboItem("JPN", 1),
|
|
|
|
|
new ComboItem("ENG", 2),
|
|
|
|
|
new ComboItem("FRE", 3),
|
|
|
|
|
new ComboItem("ITA", 4),
|
|
|
|
|
new ComboItem("GER", 5),
|
|
|
|
|
new ComboItem("ESP", 7),
|
|
|
|
|
new ComboItem("KOR", 8),
|
2019-10-28 03:39:07 +00:00
|
|
|
|
}, null);
|
2017-12-02 22:20:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-30 16:59:48 +00:00
|
|
|
|
var ItemList = GameInfo.Strings.GetItemStrings(Gen, SAV.Version);
|
2017-12-02 22:20:56 +00:00
|
|
|
|
CB_MailType.Items.Clear();
|
|
|
|
|
CB_MailType.Items.Add(ItemList[0]);
|
2017-12-03 03:12:04 +00:00
|
|
|
|
foreach (int item in MailItemID)
|
|
|
|
|
CB_MailType.Items.Add(ItemList[item]);
|
2017-12-02 22:20:56 +00:00
|
|
|
|
|
|
|
|
|
LoadPKM(true);
|
|
|
|
|
entry = -1;
|
|
|
|
|
editing = false;
|
2019-07-05 04:48:18 +00:00
|
|
|
|
if (LB_PartyHeld.Items.Count > 0)
|
|
|
|
|
LB_PartyHeld.SelectedIndex = 0;
|
|
|
|
|
else if (LB_PCBOX.Items.Count > 0)
|
|
|
|
|
LB_PCBOX.SelectedIndex = 0;
|
2017-12-02 22:20:56 +00:00
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-12-02 22:20:56 +00:00
|
|
|
|
private void LoadList()
|
|
|
|
|
{
|
2019-07-05 04:48:18 +00:00
|
|
|
|
if (entry < PartyBoxCount) MakePartyList();
|
2017-12-02 22:20:56 +00:00
|
|
|
|
else MakePCList();
|
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-12-02 22:20:56 +00:00
|
|
|
|
private void MakePartyList()
|
|
|
|
|
{
|
|
|
|
|
LB_PartyHeld.BeginUpdate();
|
|
|
|
|
LB_PartyHeld.Items.Clear();
|
2019-07-05 04:48:18 +00:00
|
|
|
|
for (int i = 0; i < PartyBoxCount; i++)
|
2019-09-03 02:30:58 +00:00
|
|
|
|
LB_PartyHeld.Items.Add(GetLBLabel(i));
|
2017-12-02 22:20:56 +00:00
|
|
|
|
LB_PartyHeld.EndUpdate();
|
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-12-02 22:20:56 +00:00
|
|
|
|
private void MakePCList()
|
|
|
|
|
{
|
|
|
|
|
LB_PCBOX.BeginUpdate();
|
|
|
|
|
LB_PCBOX.Items.Clear();
|
2019-07-05 04:48:18 +00:00
|
|
|
|
if (Gen == 2)
|
2017-12-02 22:20:56 +00:00
|
|
|
|
{
|
2019-07-05 04:48:18 +00:00
|
|
|
|
for (int i = PartyBoxCount, j = 0, boxsize = (int)NUD_BoxSize.Value; i < m.Length; i++, j++)
|
|
|
|
|
{
|
|
|
|
|
if (j < boxsize)
|
2019-09-03 02:30:58 +00:00
|
|
|
|
LB_PCBOX.Items.Add(GetLBLabel(i));
|
2019-07-05 04:48:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (int i = PartyBoxCount; i < m.Length; i++)
|
2019-09-03 02:30:58 +00:00
|
|
|
|
LB_PCBOX.Items.Add(GetLBLabel(i));
|
2017-12-02 22:20:56 +00:00
|
|
|
|
}
|
|
|
|
|
LB_PCBOX.EndUpdate();
|
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-12-02 22:20:56 +00:00
|
|
|
|
private void LoadPKM(bool isInit)
|
|
|
|
|
{
|
2019-07-05 04:48:18 +00:00
|
|
|
|
editing = true;
|
2017-12-03 03:12:04 +00:00
|
|
|
|
for (int i = 0; i < p.Count; i++)
|
2017-12-02 22:20:56 +00:00
|
|
|
|
{
|
|
|
|
|
if (isInit)
|
|
|
|
|
PKMLabels[i].Text = GetSpeciesNameFromCB(p[i].Species);
|
2019-07-05 04:48:18 +00:00
|
|
|
|
int j = Array.IndexOf(MailItemID, p[i].HeldItem);
|
|
|
|
|
PKMHeldItems[i].Text = j >= 0 ? CB_MailType.Items[j + 1].ToString() : "(not Mail)";
|
2017-12-03 03:12:04 +00:00
|
|
|
|
if (Gen != 3)
|
|
|
|
|
continue;
|
|
|
|
|
int k = ((PK3)p[i]).HeldMailID;
|
|
|
|
|
PKMNUDs[i].Value = k >= -1 && k <= 5 ? k : -1;
|
2017-12-02 22:20:56 +00:00
|
|
|
|
}
|
2019-07-05 04:48:18 +00:00
|
|
|
|
editing = false;
|
2017-12-02 22:20:56 +00:00
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2020-10-18 18:02:39 +00:00
|
|
|
|
private readonly Mail[] m = null!;
|
2017-12-02 22:20:56 +00:00
|
|
|
|
private bool editing;
|
|
|
|
|
private int entry;
|
|
|
|
|
private readonly NumericUpDown[][] Messages;
|
2017-12-03 14:48:04 +00:00
|
|
|
|
private readonly NumericUpDown[] PKMNUDs, Miscs;
|
2017-12-02 22:20:56 +00:00
|
|
|
|
private readonly Label[] PKMLabels, PKMHeldItems;
|
|
|
|
|
private readonly ComboBox[] AppearPKMs;
|
|
|
|
|
private readonly int Gen;
|
2017-12-03 14:48:04 +00:00
|
|
|
|
private readonly byte ResetVer, ResetLang;
|
2019-07-05 04:48:18 +00:00
|
|
|
|
private readonly int PartyBoxCount;
|
2020-10-18 18:02:39 +00:00
|
|
|
|
private string loadedLBItemLabel = null!;
|
2019-07-05 04:48:18 +00:00
|
|
|
|
private bool LabelValue_GenderF;
|
2020-10-18 18:02:39 +00:00
|
|
|
|
private readonly int[] MailItemID = null!;
|
2019-07-05 04:48:18 +00:00
|
|
|
|
private readonly IList<PKM> p;
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-12-02 22:20:56 +00:00
|
|
|
|
private void Save()
|
|
|
|
|
{
|
|
|
|
|
switch (Gen)
|
|
|
|
|
{
|
|
|
|
|
case 2:
|
|
|
|
|
foreach (var n in m) n.CopyTo(SAV);
|
|
|
|
|
// duplicate
|
|
|
|
|
int ofs = 0x600;
|
|
|
|
|
int len = 0x2F * 6;
|
|
|
|
|
Array.Copy(SAV.Data, ofs, SAV.Data, ofs + len, len);
|
|
|
|
|
ofs += len << 1;
|
|
|
|
|
SAV.Data[ofs] = (byte)NUD_BoxSize.Value;
|
2018-08-04 17:06:06 +00:00
|
|
|
|
len = (0x2F * 10) + 1;
|
2017-12-02 22:20:56 +00:00
|
|
|
|
Array.Copy(SAV.Data, ofs, SAV.Data, ofs + len, len);
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
foreach (var n in m) n.CopyTo(SAV);
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
for (int i = 0; i < p.Count; i++)
|
2019-07-05 04:48:18 +00:00
|
|
|
|
m[i].CopyTo((PK4)p[i]);
|
2017-12-02 22:20:56 +00:00
|
|
|
|
for (int i = p.Count; i < m.Length; i++)
|
|
|
|
|
m[i].CopyTo(SAV);
|
|
|
|
|
break;
|
2017-12-03 14:48:04 +00:00
|
|
|
|
case 5:
|
|
|
|
|
for (int i = 0; i < p.Count; i++)
|
2019-07-05 04:48:18 +00:00
|
|
|
|
m[i].CopyTo((PK5)p[i]);
|
2017-12-03 14:48:04 +00:00
|
|
|
|
for (int i = p.Count; i < m.Length; i++)
|
|
|
|
|
m[i].CopyTo(SAV);
|
|
|
|
|
break;
|
2017-12-02 22:20:56 +00:00
|
|
|
|
}
|
2019-07-05 04:48:18 +00:00
|
|
|
|
if (p.Count > 0)
|
|
|
|
|
SAV.PartyData = p;
|
2017-12-02 22:20:56 +00:00
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-12-02 22:20:56 +00:00
|
|
|
|
private void TempSave()
|
|
|
|
|
{
|
2019-07-05 04:48:18 +00:00
|
|
|
|
Mail mail = m[entry];
|
|
|
|
|
mail.AuthorName = TB_AuthorName.Text;
|
|
|
|
|
mail.AuthorTID = (ushort)NUD_AuthorTID.Value;
|
|
|
|
|
mail.MailType = CBIndexToMailType(CB_MailType.SelectedIndex);
|
2020-10-18 18:02:39 +00:00
|
|
|
|
// ReSharper disable once ConstantNullCoalescingCondition
|
2019-07-05 04:48:18 +00:00
|
|
|
|
int v = (int?)CB_AppearPKM1.SelectedValue ?? 0;
|
|
|
|
|
if (Gen == 2)
|
|
|
|
|
{
|
|
|
|
|
mail.AppearPKM = v;
|
|
|
|
|
mail.SetMessage(TB_MessageBody21.Text, TB_MessageBody22.Text);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mail.AuthorSID = (ushort)NUD_AuthorSID.Value;
|
|
|
|
|
for (int y = 0, xc = Gen == 3 ? 3 : 4; y < 3; y++)
|
|
|
|
|
{
|
|
|
|
|
for (int x = 0; x < xc; x++)
|
|
|
|
|
mail.SetMessage(y, x, (ushort)Messages[y][x].Value);
|
|
|
|
|
}
|
|
|
|
|
if (Gen == 3)
|
|
|
|
|
{
|
2021-03-08 07:22:07 +00:00
|
|
|
|
mail.AppearPKM = SpeciesConverter.GetG3Species(v);
|
2019-07-05 04:48:18 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2020-10-18 18:02:39 +00:00
|
|
|
|
|
|
|
|
|
// ReSharper disable once ConstantNullCoalescingCondition
|
2019-07-05 04:48:18 +00:00
|
|
|
|
mail.AuthorVersion = (byte)((int?)CB_AuthorVersion.SelectedValue ?? 0);
|
2020-10-18 18:02:39 +00:00
|
|
|
|
|
|
|
|
|
// ReSharper disable once ConstantNullCoalescingCondition
|
2019-07-05 04:48:18 +00:00
|
|
|
|
mail.AuthorLanguage = (byte)((int?)CB_AuthorLang.SelectedValue ?? 0);
|
2020-10-18 18:02:39 +00:00
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
mail.AuthorGender = (byte)((mail.AuthorGender & 0xFE) | (LabelValue_GenderF ? 1 : 0));
|
2019-07-05 04:48:18 +00:00
|
|
|
|
switch (mail)
|
2017-12-02 22:20:56 +00:00
|
|
|
|
{
|
|
|
|
|
case Mail4 m4:
|
|
|
|
|
for (int i = 0; i < AppearPKMs.Length; i++)
|
|
|
|
|
m4.SetAppearPKM(i, (AppearPKMs[i].SelectedValue as int?) + 7 ?? 0);
|
2017-12-03 14:48:04 +00:00
|
|
|
|
break;
|
|
|
|
|
case Mail5 m5:
|
|
|
|
|
for (int i = 0; i < Miscs.Length; i++)
|
|
|
|
|
m5.SetMisc(i, (ushort)Miscs[i].Value);
|
|
|
|
|
m5.MessageEnding = (ushort)NUD_MessageEnding.Value;
|
2017-12-02 22:20:56 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2019-07-05 04:48:18 +00:00
|
|
|
|
private List<string> CheckValid()
|
2017-12-02 22:20:56 +00:00
|
|
|
|
{
|
2019-07-05 04:48:18 +00:00
|
|
|
|
var ret = new List<string>();
|
2017-12-02 22:20:56 +00:00
|
|
|
|
// Gen3
|
|
|
|
|
// A: held item is mail, but heldMailID is not 0 to 5. it should be 0 to 5, or held not mail.
|
|
|
|
|
// B: held item is mail, but mail is empty(mail type is 0). it should be not empty, or held not mail and heldMailId -1.
|
|
|
|
|
// C: held item is not mail, but heldMailID is not -1. it should be -1, or held mail and mail not empty.
|
|
|
|
|
// D: other pkm have same heldMailID. it should be different.
|
|
|
|
|
// E: mail is not empty, but no pkm refer to the mail. it should be empty, or someone refer to the mail.
|
|
|
|
|
if (Gen == 3)
|
|
|
|
|
{
|
|
|
|
|
int[] heldMailIDs = new int[p.Count];
|
2017-12-03 03:12:04 +00:00
|
|
|
|
for (int i = 0; i < p.Count; i++)
|
2017-12-02 22:20:56 +00:00
|
|
|
|
{
|
2019-07-05 04:48:18 +00:00
|
|
|
|
int h = ((PK3)p[i]).HeldMailID;
|
2017-12-02 22:20:56 +00:00
|
|
|
|
heldMailIDs[i] = h;
|
|
|
|
|
if (ItemIsMail(p[i].HeldItem))
|
|
|
|
|
{
|
2020-12-25 20:30:26 +00:00
|
|
|
|
if (h is < 0 or > 5) //A
|
2019-07-05 04:48:18 +00:00
|
|
|
|
ret.Add($"Party#{i + 1} MailID mismatch");
|
2017-12-03 02:24:48 +00:00
|
|
|
|
else if (m[h].IsEmpty == true) //B
|
2019-07-05 04:48:18 +00:00
|
|
|
|
ret.Add($"Party#{i + 1} MailID mismatch");
|
2017-12-02 22:20:56 +00:00
|
|
|
|
}
|
|
|
|
|
else if (h != -1) //C
|
2018-08-04 17:06:06 +00:00
|
|
|
|
{
|
2019-07-05 04:48:18 +00:00
|
|
|
|
ret.Add($"Party#{i + 1} MailID mismatch");
|
2018-08-04 17:06:06 +00:00
|
|
|
|
}
|
2017-12-02 22:20:56 +00:00
|
|
|
|
}
|
2017-12-03 02:24:48 +00:00
|
|
|
|
for (int i = 0; i < 6; i++)
|
2017-12-02 22:20:56 +00:00
|
|
|
|
{
|
2020-08-31 02:24:40 +00:00
|
|
|
|
var index = i;
|
|
|
|
|
if (heldMailIDs.Count(v => v == index) > 1) //D
|
2019-07-05 04:48:18 +00:00
|
|
|
|
ret.Add($"MailID{i} duplicated");
|
2020-08-31 02:24:40 +00:00
|
|
|
|
if (m[i].IsEmpty == false && heldMailIDs.All(v => v != index)) //E
|
2019-07-05 04:48:18 +00:00
|
|
|
|
ret.Add($"MailID{i} not referred");
|
2017-12-02 22:20:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Gen2, Gen4
|
|
|
|
|
// P: held item is mail, but mail is empty(invalid mail type. g2:not 181 to 189, g4:12 to 255). it should be not empty or held not mail.
|
|
|
|
|
// Q: held item is not mail, but mail is not empty. it should be empty or held mail.
|
2020-12-25 20:30:26 +00:00
|
|
|
|
else if (Gen is 2 or 4)
|
2017-12-02 22:20:56 +00:00
|
|
|
|
{
|
2017-12-03 02:24:48 +00:00
|
|
|
|
for (int i = 0; i < p.Count; i++)
|
2017-12-02 22:20:56 +00:00
|
|
|
|
{
|
|
|
|
|
if (ItemIsMail(p[i].HeldItem))
|
|
|
|
|
{
|
2017-12-03 02:24:48 +00:00
|
|
|
|
if (m[i].IsEmpty == true) //P
|
2019-07-05 04:48:18 +00:00
|
|
|
|
ret.Add($"MailID{i} MailType mismatch");
|
2017-12-02 22:20:56 +00:00
|
|
|
|
}
|
2017-12-03 02:24:48 +00:00
|
|
|
|
else if (m[i].IsEmpty == false) //Q
|
2018-08-04 17:06:06 +00:00
|
|
|
|
{
|
2019-07-05 04:48:18 +00:00
|
|
|
|
ret.Add($"MailID{i} MailType mismatch");
|
2018-08-04 17:06:06 +00:00
|
|
|
|
}
|
2017-12-02 22:20:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-03 14:48:04 +00:00
|
|
|
|
// Gen5
|
|
|
|
|
// P
|
|
|
|
|
// gen5, move mail to pc will not erase mail data, still remains, duplicates.
|
|
|
|
|
else if (Gen == 5)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < p.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (ItemIsMail(p[i].HeldItem))
|
|
|
|
|
{
|
|
|
|
|
if (m[i].IsEmpty == true) //P
|
2019-07-05 04:48:18 +00:00
|
|
|
|
ret.Add($"MailID{i} MailType mismatch");
|
2017-12-03 14:48:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-03 02:24:48 +00:00
|
|
|
|
// Gen*
|
|
|
|
|
// Z: mail type is illegal
|
|
|
|
|
for (int i = 0; i < m.Length; i++)
|
2018-08-04 17:06:06 +00:00
|
|
|
|
{
|
2017-12-03 02:24:48 +00:00
|
|
|
|
if (m[i].IsEmpty == null) // Z
|
2019-07-05 04:48:18 +00:00
|
|
|
|
ret.Add($"MailID{i} MailType mismatch");
|
2018-08-04 17:06:06 +00:00
|
|
|
|
}
|
2017-12-03 02:24:48 +00:00
|
|
|
|
|
2017-12-02 22:20:56 +00:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void B_Cancel_Click(object sender, EventArgs e) => Close();
|
|
|
|
|
|
|
|
|
|
private void B_Save_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (entry >= 0) TempSave();
|
|
|
|
|
Save();
|
2019-07-05 04:48:18 +00:00
|
|
|
|
var Err = CheckValid();
|
|
|
|
|
if (Err.Count != 0 && DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, $"{Err.Aggregate($"Validation Error. Save?{Environment.NewLine}", (tmp, v) => $"{tmp}{Environment.NewLine}{v}")}"))
|
2017-12-03 03:12:04 +00:00
|
|
|
|
return;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
Origin.CopyChangesFrom(SAV);
|
2017-12-03 03:12:04 +00:00
|
|
|
|
Close();
|
2017-12-02 22:20:56 +00:00
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
private string GetLBLabel(int index) => m[index].IsEmpty != true ? $"{index}: From {m[index].AuthorName}" : $"{index}: (empty)";
|
2017-12-02 22:20:56 +00:00
|
|
|
|
private bool ItemIsMail(int itemID) => Array.IndexOf(MailItemID, itemID) >= 0;
|
2019-07-05 04:48:18 +00:00
|
|
|
|
private int MailTypeToCBIndex(Mail mail) => Gen <= 3 ? 1 + Array.IndexOf(MailItemID, mail.MailType) : (mail.IsEmpty == false ? 1 + mail.MailType : 0);
|
|
|
|
|
private int CBIndexToMailType(int cbindex) => Gen <= 3 ? (cbindex > 0 ? MailItemID[cbindex - 1] : 0) : (cbindex > 0 ? cbindex - 1 : 0xFF);
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-12-02 22:20:56 +00:00
|
|
|
|
private string GetSpeciesNameFromCB(int index)
|
|
|
|
|
{
|
2021-03-14 23:16:55 +00:00
|
|
|
|
var result = CB_AppearPKM1.Items.OfType<ComboItem>().FirstOrDefault(z => z.Value == index);
|
|
|
|
|
return result != null ? result.Text : "PKM";
|
2017-12-02 22:20:56 +00:00
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-12-02 22:20:56 +00:00
|
|
|
|
private DialogResult ModifyHeldItem()
|
|
|
|
|
{
|
|
|
|
|
DialogResult ret = DialogResult.Abort;
|
2019-07-05 04:48:18 +00:00
|
|
|
|
var s = p.Select((pkm, i) => ((sbyte)PKMNUDs[i].Value == entry) && ItemIsMail(pkm.HeldItem) ? pkm : null).ToArray();
|
2020-11-14 16:20:48 +00:00
|
|
|
|
if (s.All(v => v == null))
|
2019-07-05 04:48:18 +00:00
|
|
|
|
return ret;
|
2017-12-02 22:20:56 +00:00
|
|
|
|
System.Media.SystemSounds.Question.Play();
|
2019-10-26 19:33:58 +00:00
|
|
|
|
var msg = $"{s.Select((v, i) => v == null ? string.Empty : $"{Environment.NewLine} {PKMLabels[i].Text}: {PKMHeldItems[i].Text} -> {CB_MailType.Items[0]}").Aggregate($"Modify PKM's HeldItem?{Environment.NewLine}", (tmp, v) => $"{tmp}{v}")}{Environment.NewLine}{Environment.NewLine}Yes: Delete Mail & Modify PKM{Environment.NewLine}No: Delete Mail";
|
|
|
|
|
ret = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel, msg);
|
2019-07-05 04:48:18 +00:00
|
|
|
|
if (ret != DialogResult.Yes)
|
|
|
|
|
return ret;
|
2020-10-18 18:02:39 +00:00
|
|
|
|
foreach (var pkm in s)
|
2019-07-05 04:48:18 +00:00
|
|
|
|
{
|
2020-10-18 18:02:39 +00:00
|
|
|
|
if (pkm == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
pkm.HeldItem = 0;
|
|
|
|
|
if (Gen == 3)
|
|
|
|
|
((PK3)pkm).HeldMailID = -1;
|
2019-07-05 04:48:18 +00:00
|
|
|
|
}
|
2017-12-02 22:20:56 +00:00
|
|
|
|
LoadPKM(false);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-12-02 22:20:56 +00:00
|
|
|
|
private void B_Delete_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2019-09-12 05:17:16 +00:00
|
|
|
|
if (entry < 0)
|
|
|
|
|
return;
|
2017-12-03 14:48:04 +00:00
|
|
|
|
if (entry < p.Count)
|
2017-12-02 22:20:56 +00:00
|
|
|
|
{
|
2019-09-12 05:17:16 +00:00
|
|
|
|
if (ModifyHeldItem() == DialogResult.Cancel)
|
|
|
|
|
return;
|
2017-12-02 22:20:56 +00:00
|
|
|
|
}
|
2017-12-03 14:48:04 +00:00
|
|
|
|
switch (m[entry])
|
|
|
|
|
{
|
|
|
|
|
case Mail4 m4: m4.SetBlank(ResetLang, ResetVer); break;
|
|
|
|
|
case Mail5 m5: m5.SetBlank(ResetLang, ResetVer); break;
|
|
|
|
|
default: m[entry].SetBlank(); break;
|
|
|
|
|
}
|
2017-12-02 22:20:56 +00:00
|
|
|
|
LoadList();
|
2017-12-03 02:24:48 +00:00
|
|
|
|
LoadMail();
|
2017-12-02 22:20:56 +00:00
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-12-02 22:20:56 +00:00
|
|
|
|
private void EntryControl(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (editing) return;
|
|
|
|
|
editing = true;
|
|
|
|
|
int partyIndex = LB_PartyHeld.SelectedIndex;
|
|
|
|
|
int pcIndex = LB_PCBOX.SelectedIndex;
|
|
|
|
|
if (entry >= 0)
|
|
|
|
|
{
|
|
|
|
|
TempSave();
|
2019-09-03 02:30:58 +00:00
|
|
|
|
if (GetLBLabel(entry) != loadedLBItemLabel)
|
2019-07-05 04:48:18 +00:00
|
|
|
|
LoadList();
|
2017-12-02 22:20:56 +00:00
|
|
|
|
}
|
2019-07-05 04:48:18 +00:00
|
|
|
|
if (sender == LB_PartyHeld && partyIndex >= 0)
|
2017-12-02 22:20:56 +00:00
|
|
|
|
{
|
2019-07-05 04:48:18 +00:00
|
|
|
|
entry = partyIndex;
|
|
|
|
|
LB_PartyHeld.SelectedIndex = partyIndex;
|
2017-12-02 22:20:56 +00:00
|
|
|
|
LB_PCBOX.SelectedIndex = -1;
|
|
|
|
|
}
|
2019-07-05 04:48:18 +00:00
|
|
|
|
else if (sender == LB_PCBOX && pcIndex >= 0)
|
2017-12-02 22:20:56 +00:00
|
|
|
|
{
|
2019-07-05 04:48:18 +00:00
|
|
|
|
entry = PartyBoxCount + pcIndex;
|
|
|
|
|
LB_PCBOX.SelectedIndex = pcIndex;
|
2017-12-02 22:20:56 +00:00
|
|
|
|
LB_PartyHeld.SelectedIndex = -1;
|
|
|
|
|
}
|
2019-07-05 04:48:18 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
entry = -1;
|
|
|
|
|
}
|
2017-12-02 22:20:56 +00:00
|
|
|
|
editing = false;
|
2019-07-05 04:48:18 +00:00
|
|
|
|
if (entry >= 0)
|
|
|
|
|
{
|
|
|
|
|
LoadMail();
|
2019-09-03 02:30:58 +00:00
|
|
|
|
loadedLBItemLabel = GetLBLabel(entry);
|
2019-07-05 04:48:18 +00:00
|
|
|
|
}
|
2017-12-02 22:20:56 +00:00
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-12-02 22:20:56 +00:00
|
|
|
|
private void LoadMail()
|
|
|
|
|
{
|
2019-07-05 04:48:18 +00:00
|
|
|
|
editing = true;
|
|
|
|
|
Mail mail = m[entry];
|
|
|
|
|
TB_AuthorName.Text = mail.AuthorName;
|
|
|
|
|
NUD_AuthorTID.Value = mail.AuthorTID;
|
|
|
|
|
CB_MailType.SelectedIndex = MailTypeToCBIndex(mail);
|
|
|
|
|
int v = mail.AppearPKM;
|
|
|
|
|
if (Gen == 2)
|
|
|
|
|
{
|
|
|
|
|
AppearPKMs[0].SelectedValue = v;
|
|
|
|
|
TB_MessageBody21.Text = mail.GetMessage(false);
|
|
|
|
|
TB_MessageBody22.Text = mail.GetMessage(true);
|
|
|
|
|
editing = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
NUD_AuthorSID.Value = mail.AuthorSID;
|
|
|
|
|
for (int y = 0, xc = Gen == 3 ? 3 : 4; y < 3; y++)
|
|
|
|
|
{
|
|
|
|
|
for (int x = 0; x < xc; x++)
|
|
|
|
|
Messages[y][x].Value = mail.GetMessage(y, x);
|
|
|
|
|
}
|
|
|
|
|
if (Gen == 3)
|
|
|
|
|
{
|
2021-03-08 07:22:07 +00:00
|
|
|
|
AppearPKMs[0].SelectedValue = SpeciesConverter.GetG4Species(v);
|
2019-07-05 04:48:18 +00:00
|
|
|
|
editing = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
CB_AuthorVersion.SelectedValue = (int)mail.AuthorVersion;
|
|
|
|
|
CB_AuthorLang.SelectedValue = (int)mail.AuthorLanguage;
|
|
|
|
|
LabelValue_GenderF = (mail.AuthorGender & 1) != 0;
|
|
|
|
|
LoadOTlabel();
|
|
|
|
|
switch (mail)
|
2017-12-02 22:20:56 +00:00
|
|
|
|
{
|
|
|
|
|
case Mail4 m4:
|
|
|
|
|
for (int i = 0; i < AppearPKMs.Length; i++)
|
|
|
|
|
AppearPKMs[i].SelectedValue = Math.Max(0, m4.GetAppearPKM(i) - 7);
|
|
|
|
|
break;
|
2017-12-03 14:48:04 +00:00
|
|
|
|
case Mail5 m5:
|
|
|
|
|
for (int i = 0; i < Miscs.Length; i++)
|
|
|
|
|
Miscs[i].Value = m5.GetMisc(i);
|
|
|
|
|
NUD_MessageEnding.Value = m5.MessageEnding;
|
|
|
|
|
break;
|
2017-12-02 22:20:56 +00:00
|
|
|
|
}
|
2019-07-05 04:48:18 +00:00
|
|
|
|
editing = false;
|
2017-12-02 22:20:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly string[] gendersymbols = { "♂", "♀" };
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2019-07-05 04:48:18 +00:00
|
|
|
|
private void LoadOTlabel()
|
2017-12-02 22:20:56 +00:00
|
|
|
|
{
|
2019-07-05 04:48:18 +00:00
|
|
|
|
Label_OTGender.Text = gendersymbols[LabelValue_GenderF ? 1 : 0];
|
2019-10-28 03:39:07 +00:00
|
|
|
|
Label_OTGender.ForeColor = Main.Draw.GetGenderColor(LabelValue_GenderF ? 1 : 0);
|
2017-12-02 22:20:56 +00:00
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-12-02 22:20:56 +00:00
|
|
|
|
private void Label_OTGender_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2019-07-05 04:48:18 +00:00
|
|
|
|
LabelValue_GenderF ^= true;
|
|
|
|
|
LoadOTlabel();
|
2017-12-02 22:20:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-05 04:48:18 +00:00
|
|
|
|
private void NUD_BoxSize_ValueChanged(object sender, EventArgs e) => MakePCList();
|
|
|
|
|
|
|
|
|
|
private void NUD_MailIDn_ValueChanged(object sender, EventArgs e)
|
2017-12-02 22:20:56 +00:00
|
|
|
|
{
|
2019-07-05 04:48:18 +00:00
|
|
|
|
if (editing || Gen != 3) return;
|
|
|
|
|
int index = Array.IndexOf(PKMNUDs, (NumericUpDown)sender);
|
|
|
|
|
if (index < 0 || index >= p.Count) return;
|
|
|
|
|
((PK3)p[index]).HeldMailID = (sbyte)PKMNUDs[index].Value;
|
2017-12-02 22:20:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|