Tidy up comboitem fetch naming

This commit is contained in:
Kurt 2019-02-15 11:47:35 -08:00
parent d1f6a5a3ff
commit 202f911d45
5 changed files with 56 additions and 54 deletions

View file

@ -365,13 +365,13 @@ namespace PKHeX.Core
// Gen 2
{
var met_list = Util.GetCBList(metGSC_00000, Enumerable.Range(0, 0x5F).ToArray());
met_list = Util.GetOffsetCBList(met_list, metGSC_00000, 00000, new[] { 0x7E, 0x7F });
Util.AddCBWithOffset(met_list, metGSC_00000, 00000, new[] { 0x7E, 0x7F });
MetGen2 = met_list;
}
// Gen 3
{
var met_list = Util.GetCBList(metRSEFRLG_00000, Enumerable.Range(0, 213).ToArray());
met_list = Util.GetOffsetCBList(met_list, metRSEFRLG_00000, 00000, new[] { 253, 254, 255 });
Util.AddCBWithOffset(met_list, metRSEFRLG_00000, 00000, new[] { 253, 254, 255 });
MetGen3 = met_list;
MetGen3CXD = Util.GetCBList(metCXD_00000, Enumerable.Range(0, metCXD_00000.Length).ToArray()).Where(c => c.Text.Length > 0).ToList();
@ -379,56 +379,56 @@ namespace PKHeX.Core
// Gen 4
{
var met_list = Util.GetCBList(metHGSS_00000, new[] { 0 });
met_list = Util.GetOffsetCBList(met_list, metHGSS_02000, 2000, new[] { 2000 });
met_list = Util.GetOffsetCBList(met_list, metHGSS_02000, 2000, new[] { 2002 });
met_list = Util.GetOffsetCBList(met_list, metHGSS_03000, 3000, new[] { 3001 });
met_list = Util.GetOffsetCBList(met_list, metHGSS_00000, 0000, Legal.Met_HGSS_0);
met_list = Util.GetOffsetCBList(met_list, metHGSS_02000, 2000, Legal.Met_HGSS_2);
met_list = Util.GetOffsetCBList(met_list, metHGSS_03000, 3000, Legal.Met_HGSS_3);
Util.AddCBWithOffset(met_list, metHGSS_02000, 2000, new[] { 2000 });
Util.AddCBWithOffset(met_list, metHGSS_02000, 2000, new[] { 2002 });
Util.AddCBWithOffset(met_list, metHGSS_03000, 3000, new[] { 3001 });
Util.AddCBWithOffset(met_list, metHGSS_00000, 0000, Legal.Met_HGSS_0);
Util.AddCBWithOffset(met_list, metHGSS_02000, 2000, Legal.Met_HGSS_2);
Util.AddCBWithOffset(met_list, metHGSS_03000, 3000, Legal.Met_HGSS_3);
MetGen4 = met_list;
}
// Gen 5
{
var met_list = Util.GetCBList(metBW2_00000, new[] { 0 });
met_list = Util.GetOffsetCBList(met_list, metBW2_60000, 60001, new[] { 60002 });
met_list = Util.GetOffsetCBList(met_list, metBW2_30000, 30001, new[] { 30003 });
met_list = Util.GetOffsetCBList(met_list, metBW2_00000, 00000, Legal.Met_BW2_0);
met_list = Util.GetOffsetCBList(met_list, metBW2_30000, 30001, Legal.Met_BW2_3);
met_list = Util.GetOffsetCBList(met_list, metBW2_40000, 40001, Legal.Met_BW2_4);
met_list = Util.GetOffsetCBList(met_list, metBW2_60000, 60001, Legal.Met_BW2_6);
Util.AddCBWithOffset(met_list, metBW2_60000, 60001, new[] { 60002 });
Util.AddCBWithOffset(met_list, metBW2_30000, 30001, new[] { 30003 });
Util.AddCBWithOffset(met_list, metBW2_00000, 00000, Legal.Met_BW2_0);
Util.AddCBWithOffset(met_list, metBW2_30000, 30001, Legal.Met_BW2_3);
Util.AddCBWithOffset(met_list, metBW2_40000, 40001, Legal.Met_BW2_4);
Util.AddCBWithOffset(met_list, metBW2_60000, 60001, Legal.Met_BW2_6);
MetGen5 = met_list;
}
// Gen 6
{
var met_list = Util.GetCBList(metXY_00000, new[] { 0 });
met_list = Util.GetOffsetCBList(met_list, metXY_60000, 60001, new[] { 60002 });
met_list = Util.GetOffsetCBList(met_list, metXY_30000, 30001, new[] { 30002 });
met_list = Util.GetOffsetCBList(met_list, metXY_00000, 00000, Legal.Met_XY_0);
met_list = Util.GetOffsetCBList(met_list, metXY_30000, 30001, Legal.Met_XY_3);
met_list = Util.GetOffsetCBList(met_list, metXY_40000, 40001, Legal.Met_XY_4);
met_list = Util.GetOffsetCBList(met_list, metXY_60000, 60001, Legal.Met_XY_6);
Util.AddCBWithOffset(met_list, metXY_60000, 60001, new[] { 60002 });
Util.AddCBWithOffset(met_list, metXY_30000, 30001, new[] { 30002 });
Util.AddCBWithOffset(met_list, metXY_00000, 00000, Legal.Met_XY_0);
Util.AddCBWithOffset(met_list, metXY_30000, 30001, Legal.Met_XY_3);
Util.AddCBWithOffset(met_list, metXY_40000, 40001, Legal.Met_XY_4);
Util.AddCBWithOffset(met_list, metXY_60000, 60001, Legal.Met_XY_6);
MetGen6 = met_list;
}
// Gen 7
{
var met_list = Util.GetCBList(metSM_00000, new[] { 0 });
met_list = Util.GetOffsetCBList(met_list, metSM_60000, 60001, new[] { 60002 });
met_list = Util.GetOffsetCBList(met_list, metSM_30000, 30001, new[] { 30002 });
met_list = Util.GetOffsetCBList(met_list, metSM_00000, 00000, Legal.Met_SM_0);
met_list = Util.GetOffsetCBList(met_list, metSM_30000, 30001, Legal.Met_SM_3);
met_list = Util.GetOffsetCBList(met_list, metSM_40000, 40001, Legal.Met_SM_4);
met_list = Util.GetOffsetCBList(met_list, metSM_60000, 60001, Legal.Met_SM_6);
Util.AddCBWithOffset(met_list, metSM_60000, 60001, new[] { 60002 });
Util.AddCBWithOffset(met_list, metSM_30000, 30001, new[] { 30002 });
Util.AddCBWithOffset(met_list, metSM_00000, 00000, Legal.Met_SM_0);
Util.AddCBWithOffset(met_list, metSM_30000, 30001, Legal.Met_SM_3);
Util.AddCBWithOffset(met_list, metSM_40000, 40001, Legal.Met_SM_4);
Util.AddCBWithOffset(met_list, metSM_60000, 60001, Legal.Met_SM_6);
MetGen7 = met_list;
}
// Gen 7 GG
{
var met_list = Util.GetCBList(metGG_00000, new[] { 0 });
met_list = Util.GetOffsetCBList(met_list, metGG_60000, 60001, new[] { 60002 });
met_list = Util.GetOffsetCBList(met_list, metGG_30000, 30001, new[] { 30002 });
met_list = Util.GetOffsetCBList(met_list, metGG_00000, 00000, Legal.Met_GG_0);
met_list = Util.GetOffsetCBList(met_list, metGG_30000, 30001, Legal.Met_GG_3);
met_list = Util.GetOffsetCBList(met_list, metGG_40000, 40001, Legal.Met_GG_4);
met_list = Util.GetOffsetCBList(met_list, metGG_60000, 60001, Legal.Met_GG_6);
Util.AddCBWithOffset(met_list, metGG_60000, 60001, new[] { 60002 });
Util.AddCBWithOffset(met_list, metGG_30000, 30001, new[] { 30002 });
Util.AddCBWithOffset(met_list, metGG_00000, 00000, Legal.Met_GG_0);
Util.AddCBWithOffset(met_list, metGG_30000, 30001, Legal.Met_GG_3);
Util.AddCBWithOffset(met_list, metGG_40000, 40001, Legal.Met_GG_4);
Util.AddCBWithOffset(met_list, metGG_60000, 60001, Legal.Met_GG_6);
MetGen7GG = met_list;
}
}

View file

@ -44,7 +44,8 @@ namespace PKHeX.Core
}
Array.Resize(ref allowed, allowed.Length - 1);
var memory_list1 = Util.GetCBList(new[] { mems[0] });
return Util.GetOffsetCBList(memory_list1, mems, 0, allowed);
Util.AddCBWithOffset(memory_list1, mems, 0, allowed);
return memory_list1;
}
public string[] GetMemoryQualities()

View file

@ -83,7 +83,8 @@ namespace PKHeX.Core
return (string[])stringListCache[f].Clone();
var txt = GetStringResource(f); // Fetch File, \n to list.
if (txt == null) return Array.Empty<string>();
if (txt == null)
return Array.Empty<string>();
string[] rawlist = txt.Split('\n');
for (int i = 0; i < rawlist.Length; i++)
rawlist[i] = rawlist[i].TrimEnd('\r');
@ -198,9 +199,10 @@ namespace PKHeX.Core
{
ReflectUtil.SetValue(t, prop, value);
}
catch
catch (Exception e)
{
Debug.WriteLine($"Property not present: {prop} || Value written: {value}");
Debug.WriteLine(e.Message);
}
}
}
@ -230,7 +232,7 @@ namespace PKHeX.Core
#endregion
#region DataSource Providing
public static List<ComboItem> GetCBList(string textfile, string lang)
public static List<ComboItem> GetCountryRegionList(string textfile, string lang)
{
// Set up
string[] inputCSV = GetStringList(textfile);
@ -266,14 +268,13 @@ namespace PKHeX.Core
.ToList();
}
public static List<ComboItem> GetOffsetCBList(List<ComboItem> cbList, IReadOnlyList<string> inStrings, int offset, IEnumerable<int> allowed)
public static void AddCBWithOffset(List<ComboItem> cbList, IReadOnlyList<string> inStrings, int offset, IEnumerable<int> allowed)
{
var list = allowed
.Select(z => new ComboItem {Text = inStrings[z - offset], Value = z})
.OrderBy(z => z.Text);
cbList.AddRange(list);
return cbList;
}
public static List<ComboItem> GetVariedCBListBall(string[] inStrings, int[] stringNum, int[] stringVal)

View file

@ -496,7 +496,7 @@ namespace PKHeX.WinForms.Controls
string cl = GameInfo.CurrentLanguage;
cl = cl == "zh" ? "ko" : cl == "ko" ? "zh" : cl;
CB.DataSource = Util.GetCBList(type, cl);
CB.DataSource = Util.GetCountryRegionList(type, cl);
if (index > 0 && index < CB.Items.Count)
CB.SelectedIndex = index;

View file

@ -876,7 +876,7 @@ namespace PKHeX.WinForms
string cl = GameInfo.CurrentLanguage;
cl = cl == "zh" ? "ko" : cl == "ko" ? "zh" : cl;
CB.DataSource = Util.GetCBList(type, cl);
CB.DataSource = Util.GetCountryRegionList(type, cl);
if (index > 0 && index < CB.Items.Count)
CB.SelectedIndex = index;
@ -971,21 +971,21 @@ namespace PKHeX.WinForms
{
if (!PKME_Tabs.EditsComplete)
return;
PKM pkx = PreparePKM();
PKM pk = PreparePKM();
Image qr;
switch (pkx.Format)
switch (pk.Format)
{
case 7 when pkx is PK7 pk7:
case 7 when pk is PK7 pk7:
qr = QR.GenerateQRCode7(pk7);
break;
default:
if (pkx.Format == 6 && !QR6Notified) // hint that the user should not be using QR6 injection
if (pk.Format == 6 && !QR6Notified) // hint that the user should not be using QR6 injection
{
WinFormsUtil.Alert(MsgQRDeprecated, MsgQRAlternative);
QR6Notified = true;
}
qr = QR.GetQRImage(pkx.EncryptedBoxData, QR.GetQRServer(pkx.Format));
qr = QR.GetQRImage(pk.EncryptedBoxData, QR.GetQRServer(pk.Format));
break;
}
@ -993,16 +993,16 @@ namespace PKHeX.WinForms
return;
var sprite = dragout.Image;
var la = new LegalityAnalysis(pkx, C_SAV.SAV.Personal);
if (la.Parsed && pkx.Species != 0)
var la = new LegalityAnalysis(pk, C_SAV.SAV.Personal);
if (la.Parsed && pk.Species != 0)
{
var img = la.Valid ? Resources.valid : Resources.warn;
sprite = ImageUtil.LayerImage(sprite, img, 24, 0);
}
string[] r = pkx.GetQRLines();
string[] r = pk.GetQRLines();
string refer = GetProgramTitle();
new QR(qr, sprite, pkx, r[0], r[1], r[2], $"{refer} ({pkx.GetType().Name})").ShowDialog();
new QR(qr, sprite, pk, r[0], r[1], r[2], $"{refer} ({pk.GetType().Name})").ShowDialog();
}
private void ClickLegality(object sender, EventArgs e)
@ -1109,17 +1109,17 @@ namespace PKHeX.WinForms
return;
// Create Temp File to Drag
PKM pkx = PreparePKM();
PKM pk = PreparePKM();
bool encrypt = ModifierKeys == Keys.Control;
string fn = pkx.FileNameWithoutExtension;
string filename = fn + (encrypt ? $".ek{pkx.Format}" : $".{pkx.Extension}");
byte[] dragdata = encrypt ? pkx.EncryptedBoxData : pkx.DecryptedBoxData;
string fn = pk.FileNameWithoutExtension;
string filename = fn + (encrypt ? $".ek{pk.Format}" : $".{pk.Extension}");
byte[] dragdata = encrypt ? pk.EncryptedBoxData : pk.DecryptedBoxData;
// Make file
string newfile = Path.Combine(Path.GetTempPath(), Util.CleanFileName(filename));
try
{
File.WriteAllBytes(newfile, dragdata);
C_SAV.M.DragInfo.Source.PKM = pkx;
C_SAV.M.DragInfo.Source.PKM = pk;
var pb = (PictureBox)sender;
if (pb.Image != null)