From f8f0d76793e9e72451499bc845833c3e4cccabfa Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Thu, 21 Jan 2016 22:40:59 -0800 Subject: [PATCH] Cleanup Simplified cbItem a little. Check for null input, then null selected value; catch only happens if the method is fed something irregular. --- Misc/Util.cs | 11 +++-------- PKX/f1-Main.cs | 2 +- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/Misc/Util.cs b/Misc/Util.cs index cee838e31..05289ad06 100644 --- a/Misc/Util.cs +++ b/Misc/Util.cs @@ -226,13 +226,8 @@ internal static uint getHEXval(string s) } internal static int getIndex(ComboBox cb) { - int val; - if (cb.SelectedValue == null) return 0; - - try { val = int.Parse(cb.SelectedValue.ToString()); } - catch { val = cb.SelectedIndex; if (val < 0) val = 0; } - - return val; + try { return (int)(cb?.SelectedValue ?? 0); } + catch { return Math.Max(cb.SelectedIndex, 0); } } internal static string getOnlyHex(string s) { @@ -363,7 +358,7 @@ internal static DialogResult Prompt(MessageBoxButtons btn, params string[] lines public class cbItem { public string Text { get; set; } - public object Value { get; set; } + public int Value { get; set; } } internal static List getCBList(string textfile, string lang) { diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index 48c2fe3e2..08d0e159f 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -2403,7 +2403,7 @@ public byte[] preparepkx(bool click = true) pk6.Ball = Util.getIndex(CB_Ball); pk6.Met_Level = Util.ToInt32(TB_MetLevel.Text); pk6.OT_Gender = PKX.getGender(Label_OTGender.Text); - pk6.EncounterType = Util.ToInt32(CB_EncounterType.SelectedValue.ToString()); + pk6.EncounterType = Util.getIndex(CB_EncounterType); pk6.Version = Util.getIndex(CB_GameOrigin); pk6.Country = Util.getIndex(CB_Country); pk6.Region = Util.getIndex(CB_SubRegion);