mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-09-15 06:05:41 -05:00
* Util.cs: Reducing number of unnecessary UInt32 Parse error under
Mono due to the Underscore character being at the end of strings. Also consolidated To[U]Int32 code from controls to use string version. * f1-Main.cs: Fixed issue that is causing by initializing the values of the GameOrigin combo box causing the SelectedValue field to be queried before it knows it's ValueMember.
This commit is contained in:
77
Misc/Util.cs
77
Misc/Util.cs
@@ -147,62 +147,56 @@ internal static uint rnd32()
|
||||
}
|
||||
|
||||
internal static int ToInt32(TextBox tb)
|
||||
{
|
||||
string value = tb.Text;
|
||||
if (String.IsNullOrEmpty(value))
|
||||
{ return 0; }
|
||||
try
|
||||
{ return Int32.Parse(value); }
|
||||
catch
|
||||
{ return 0; }
|
||||
}
|
||||
{
|
||||
string value = tb.Text;
|
||||
return ToInt32(value);
|
||||
}
|
||||
internal static uint ToUInt32(TextBox tb)
|
||||
{
|
||||
string value = tb.Text;
|
||||
if (String.IsNullOrEmpty(value))
|
||||
{ return 0; }
|
||||
try
|
||||
{ return UInt32.Parse(value); }
|
||||
catch
|
||||
{ return 0; }
|
||||
}
|
||||
{
|
||||
string value = tb.Text;
|
||||
return ToUInt32(value);
|
||||
}
|
||||
internal static int ToInt32(MaskedTextBox tb)
|
||||
{
|
||||
string value = tb.Text;
|
||||
if (String.IsNullOrEmpty(value))
|
||||
{ return 0; }
|
||||
try
|
||||
{ return Int32.Parse(value); }
|
||||
catch
|
||||
{ return 0; }
|
||||
return ToInt32(value);
|
||||
}
|
||||
internal static uint ToUInt32(MaskedTextBox tb)
|
||||
{
|
||||
string value = tb.Text;
|
||||
if (String.IsNullOrEmpty(value))
|
||||
{ return 0; }
|
||||
try
|
||||
{ return UInt32.Parse(value); }
|
||||
catch
|
||||
{ return 0; }
|
||||
return ToUInt32(value);
|
||||
}
|
||||
internal static int ToInt32(String value)
|
||||
{
|
||||
if (String.IsNullOrEmpty(value))
|
||||
{ return 0; }
|
||||
if (String.IsNullOrEmpty(value))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
try
|
||||
{ return Int32.Parse(value); }
|
||||
{
|
||||
value = value.TrimEnd(new char[]{'_'});
|
||||
return Int32.Parse(value);
|
||||
}
|
||||
catch
|
||||
{ return 0; }
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
internal static uint ToUInt32(String value)
|
||||
{
|
||||
if (String.IsNullOrEmpty(value))
|
||||
{ return 0; }
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
try
|
||||
{ return UInt32.Parse(value); }
|
||||
{
|
||||
value = value.TrimEnd(new char[]{'_'});
|
||||
return UInt32.Parse(value);
|
||||
}
|
||||
catch
|
||||
{ return 0; }
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
internal static uint getHEXval(TextBox tb)
|
||||
{
|
||||
@@ -215,14 +209,19 @@ internal static int getIndex(ComboBox cb)
|
||||
{
|
||||
int val = 0;
|
||||
if (cb.SelectedValue == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
try { val = Util.ToInt32(cb.SelectedValue.ToString()); }
|
||||
try
|
||||
{
|
||||
val = Util.ToInt32(cb.SelectedValue.ToString());
|
||||
}
|
||||
catch
|
||||
{
|
||||
val = cb.SelectedIndex;
|
||||
if (val < 0) val = 0;
|
||||
};
|
||||
}
|
||||
return val;
|
||||
}
|
||||
internal static string getOnlyHex(string str)
|
||||
|
||||
@@ -1477,9 +1477,15 @@ private void InitializeLanguage()
|
||||
origin_list.Add(item);
|
||||
}
|
||||
|
||||
/*
|
||||
* Moving the assignment of the Display and ValueMemeber to before the DataSource is assigned
|
||||
as assigning the DataSource causes a onSelectedIndexChanged which causes a call
|
||||
to updateOriginGame which access the SelectedValue property, but since there is no
|
||||
ValueMember assigned it uses the cbItem to string method which returns the Text member
|
||||
*/
|
||||
CB_GameOrigin.DisplayMember = "Text";
|
||||
CB_GameOrigin.ValueMember = "Value";
|
||||
CB_GameOrigin.DataSource = origin_list;
|
||||
CB_GameOrigin.DisplayMember = "Text";
|
||||
CB_GameOrigin.ValueMember = "Value";
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -2787,8 +2793,7 @@ private void updateOriginGame(object sender, EventArgs e)
|
||||
// Error handling for unset field
|
||||
try
|
||||
{
|
||||
cbItem CBItem_GameOrigin = (cbItem)CB_GameOrigin.SelectedValue;
|
||||
gameorigin = CBItem_GameOrigin.GetValue();
|
||||
gameorigin = Util.ToInt32(CB_GameOrigin.SelectedValue.ToString());
|
||||
}
|
||||
catch { gameorigin = 0; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user