Skip to content

Commit

Permalink
Evo editor: better GUI response in case of invalid values
Browse files Browse the repository at this point in the history
  • Loading branch information
AdAstra-LD committed Nov 26, 2023
1 parent 45d2851 commit 89f6a47
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions DS_Map/EvolutionsEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,28 @@ private void evoMethodComboBox7_SelectedIndexChanged(object sender, EventArgs e)
}


private void ResetGUIRow(int index) {
//Reset GUI row
(ComboBox m, Label l, NumericUpDown p, ComboBox t) = evoRows[index];
l.Text = "";
p.Enabled = false;
t.Enabled = false;
p.Value = 0;
}

private void UpdateDescriptionLabel(int index) {
if (index < 0 || index >= evoRows.Length) {
throw new ArgumentOutOfRangeException("Index out of range: " + index);
}
(ComboBox m, Label l, NumericUpDown p, ComboBox t) = evoRows[index];

if (m.SelectedIndex < 0 || m.SelectedIndex > Enum.GetValues(typeof(EvolutionMethod)).Length) {
l.Text = "";
if (m.SelectedIndex <= (int)EvolutionMethod.None) {
ResetGUIRow(index);
return;
}
if ( m.SelectedIndex > Enum.GetValues(typeof(EvolutionMethod)).Length){
MessageBox.Show("Invalid evolution method selected", "Evolution method error", MessageBoxButtons.OK, MessageBoxIcon.Error);
ResetGUIRow(index);
return;
}

Expand All @@ -230,39 +243,47 @@ private void UpdateDescriptionLabel(int index) {
case EvolutionParamMeaning.Ignored:
l.Text = "";
p.Enabled = false;
t.Enabled = true;

if (p.Value != 0) {
Console.WriteLine("Warning: Evolution parameter is not 0, but it should be.");
}

p.Value = 0;
break;

case EvolutionParamMeaning.FromLevel:
l.Text = "From Level: ";
p.Enabled = true;
t.Enabled = true;
p.Maximum = 100;
break;

case EvolutionParamMeaning.ItemName:
l.Text = $"({itemNames[(int)p.Value]})";
p.Enabled = true;
t.Enabled = true;
p.Maximum = itemNames.Length - 1;
break;

case EvolutionParamMeaning.MoveName:
l.Text = $"({moveNames[(int)p.Value]})";
p.Enabled = true;
t.Enabled = true;
p.Maximum = moveNames.Length - 1;
break;

case EvolutionParamMeaning.PokemonName:
l.Text = $"({pokeNames[(int)p.Value]})";
p.Enabled = true;
t.Enabled = true;
p.Maximum = pokeNames.Length - 1;
break;

case EvolutionParamMeaning.BeautyValue:
l.Text = "Beauty >=";
p.Enabled = true;
t.Enabled = true;
p.Maximum = 255;
break;

Expand Down

0 comments on commit 89f6a47

Please sign in to comment.