/// <summary> /// 研究速度補正の値変更時の処理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnModifierTextBoxValidated(object sender, EventArgs e) { // 変更後の文字列を数値に変換できなければ値を戻す double modifier; if (!DoubleHelper.TryParse(modifierTextBox.Text, out modifier)) { modifierTextBox.Text = DoubleHelper.ToString(Researches.Modifier); return; } // 0以下の値だとまともに計算できなくなるので保険 if (modifier <= 0.00005) { modifierTextBox.Text = DoubleHelper.ToString(Researches.Modifier); return; } // 値に変化がなければ何もしない if (DoubleHelper.IsEqual(modifier, Researches.Modifier)) { return; } // 値を更新する Researches.Modifier = modifier; // 研究機関リストを更新する UpdateTeamList(); }
/// <summary> /// 編集項目テキストボックスフォーカス移動後の処理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnItemTextBoxValidated(object sender, EventArgs e) { TextBox textBox = sender as TextBox; if (textBox == null) { return; } MiscItemId id = (MiscItemId)textBox.Tag; MiscItemType type = Misc.ItemTypes[(int)id]; double d = 0; int i = 0; // 変更後の文字列を数値に変換できなければ値を戻す switch (type) { case MiscItemType.Int: case MiscItemType.PosInt: case MiscItemType.NonNegInt: case MiscItemType.NonPosInt: case MiscItemType.NonNegIntMinusOne: case MiscItemType.NonNegInt1: case MiscItemType.RangedInt: case MiscItemType.RangedPosInt: case MiscItemType.RangedIntMinusOne: case MiscItemType.RangedIntMinusThree: if (!int.TryParse(textBox.Text, out i)) { textBox.Text = Misc.GetString(id); return; } break; case MiscItemType.Dbl: case MiscItemType.PosDbl: case MiscItemType.NonNegDbl: case MiscItemType.NonPosDbl: case MiscItemType.NonNegDbl0: case MiscItemType.NonNegDbl2: case MiscItemType.NonNegDbl5: case MiscItemType.NonPosDbl0: case MiscItemType.NonPosDbl2: case MiscItemType.NonNegDblMinusOne: case MiscItemType.NonNegDblMinusOne1: case MiscItemType.NonNegDbl2AoD: case MiscItemType.NonNegDbl4Dda13: case MiscItemType.NonNegDbl2Dh103Full: case MiscItemType.NonNegDbl2Dh103Full1: case MiscItemType.NonNegDbl2Dh103Full2: case MiscItemType.NonPosDbl5AoD: case MiscItemType.NonPosDbl2Dh103Full: case MiscItemType.RangedDbl: case MiscItemType.RangedDblMinusOne: case MiscItemType.RangedDblMinusOne1: case MiscItemType.RangedDbl0: case MiscItemType.NonNegIntNegDbl: if (!DoubleHelper.TryParse(textBox.Text, out d)) { textBox.Text = Misc.GetString(id); return; } break; case MiscItemType.None: case MiscItemType.Bool: case MiscItemType.Enum: break; } // 設定範囲外の値ならば戻す switch (type) { case MiscItemType.PosInt: if (i <= 0) { textBox.Text = Misc.GetString(id); return; } break; case MiscItemType.NonNegInt: case MiscItemType.NonNegInt1: if (i < 0) { textBox.Text = Misc.GetString(id); return; } break; case MiscItemType.NonPosInt: if (i > 0) { textBox.Text = Misc.GetString(id); return; } break; case MiscItemType.NonNegIntMinusOne: if ((i < 0) && (i != -1)) { textBox.Text = Misc.GetString(id); return; } break; case MiscItemType.RangedInt: if ((i < Misc.IntMinValues[id]) || (i > Misc.IntMaxValues[id])) { textBox.Text = Misc.GetString(id); return; } break; case MiscItemType.RangedPosInt: if (i < Misc.IntMinValues[id]) { textBox.Text = Misc.GetString(id); return; } break; case MiscItemType.RangedIntMinusOne: if (((i < Misc.IntMinValues[id]) || (i > Misc.IntMaxValues[id])) && (i != -1)) { textBox.Text = Misc.GetString(id); return; } break; case MiscItemType.RangedIntMinusThree: if (((i < Misc.IntMinValues[id]) || (i > Misc.IntMaxValues[id])) && (i != -1) && (i != -2) && (i != -3)) { textBox.Text = Misc.GetString(id); return; } break; case MiscItemType.PosDbl: if (d <= 0) { textBox.Text = Misc.GetString(id); return; } break; case MiscItemType.NonNegDbl: case MiscItemType.NonNegDbl0: case MiscItemType.NonNegDbl2: case MiscItemType.NonNegDbl5: case MiscItemType.NonNegDbl2AoD: case MiscItemType.NonNegDbl4Dda13: case MiscItemType.NonNegDbl2Dh103Full: case MiscItemType.NonNegDbl2Dh103Full1: case MiscItemType.NonNegDbl2Dh103Full2: if (d < 0) { textBox.Text = Misc.GetString(id); return; } break; case MiscItemType.NonPosDbl: case MiscItemType.NonPosDbl0: case MiscItemType.NonPosDbl2: case MiscItemType.NonPosDbl5AoD: case MiscItemType.NonPosDbl2Dh103Full: if (d > 0) { textBox.Text = Misc.GetString(id); return; } break; case MiscItemType.NonNegDblMinusOne: case MiscItemType.NonNegDblMinusOne1: if ((d < 0) && !DoubleHelper.IsEqual(d, -1)) { textBox.Text = Misc.GetString(id); return; } break; case MiscItemType.RangedDbl: case MiscItemType.RangedDbl0: if ((d < Misc.DblMinValues[id]) || (d > Misc.DblMaxValues[id])) { textBox.Text = Misc.GetString(id); return; } break; case MiscItemType.RangedDblMinusOne: case MiscItemType.RangedDblMinusOne1: if (((d < Misc.DblMinValues[id]) || (d > Misc.DblMaxValues[id])) && !DoubleHelper.IsEqual(d, -1)) { textBox.Text = Misc.GetString(id); return; } break; } // 値に変化がなければ何もしない switch (type) { case MiscItemType.Int: case MiscItemType.PosInt: case MiscItemType.NonNegInt: case MiscItemType.NonPosInt: case MiscItemType.NonNegIntMinusOne: case MiscItemType.NonNegInt1: case MiscItemType.RangedInt: case MiscItemType.RangedPosInt: case MiscItemType.RangedIntMinusOne: case MiscItemType.RangedIntMinusThree: if (i == Misc.GetInt(id)) { return; } break; case MiscItemType.Dbl: case MiscItemType.PosDbl: case MiscItemType.NonNegDbl: case MiscItemType.NonPosDbl: case MiscItemType.NonNegDbl0: case MiscItemType.NonNegDbl2: case MiscItemType.NonNegDbl5: case MiscItemType.NonPosDbl0: case MiscItemType.NonPosDbl2: case MiscItemType.NonNegDblMinusOne: case MiscItemType.NonNegDblMinusOne1: case MiscItemType.NonNegDbl2AoD: case MiscItemType.NonNegDbl4Dda13: case MiscItemType.NonNegDbl2Dh103Full: case MiscItemType.NonNegDbl2Dh103Full1: case MiscItemType.NonNegDbl2Dh103Full2: case MiscItemType.NonPosDbl5AoD: case MiscItemType.NonPosDbl2Dh103Full: case MiscItemType.RangedDbl: case MiscItemType.RangedDblMinusOne: case MiscItemType.RangedDblMinusOne1: case MiscItemType.RangedDbl0: case MiscItemType.NonNegIntNegDbl: if (DoubleHelper.IsEqual(d, Misc.GetDouble(id))) { return; } break; } string old = Misc.GetString(id); // 値を更新する switch (type) { case MiscItemType.Int: case MiscItemType.PosInt: case MiscItemType.NonNegInt: case MiscItemType.NonPosInt: case MiscItemType.NonNegIntMinusOne: case MiscItemType.NonNegInt1: case MiscItemType.RangedInt: case MiscItemType.RangedPosInt: case MiscItemType.RangedIntMinusOne: case MiscItemType.RangedIntMinusThree: Misc.SetItem(id, i); break; case MiscItemType.Dbl: case MiscItemType.PosDbl: case MiscItemType.NonNegDbl: case MiscItemType.NonPosDbl: case MiscItemType.NonNegDbl0: case MiscItemType.NonNegDbl2: case MiscItemType.NonNegDbl5: case MiscItemType.NonPosDbl0: case MiscItemType.NonPosDbl2: case MiscItemType.NonNegDblMinusOne: case MiscItemType.NonNegDblMinusOne1: case MiscItemType.NonNegDbl2AoD: case MiscItemType.NonNegDbl4Dda13: case MiscItemType.NonNegDbl2Dh103Full: case MiscItemType.NonNegDbl2Dh103Full1: case MiscItemType.NonNegDbl2Dh103Full2: case MiscItemType.NonPosDbl5AoD: case MiscItemType.NonPosDbl2Dh103Full: case MiscItemType.RangedDbl: case MiscItemType.RangedDblMinusOne: case MiscItemType.RangedDblMinusOne1: case MiscItemType.RangedDbl0: case MiscItemType.NonNegIntNegDbl: Misc.SetItem(id, d); break; } Log.Info("[Misc] {0}: {1} -> {2}", Misc.GetItemName(id), old, Misc.GetString(id)); // 編集済みフラグを設定する Misc.SetDirty(id); // 文字色を変更する textBox.ForeColor = Color.Red; // 他のフォームに更新を通知する NotifyItemChange(id); }
/// <summary> /// 数字を解析する /// </summary> /// <returns>トークン</returns> private Token ParseNumber() { StringBuilder sb = new StringBuilder(); bool minus = false; bool point = false; bool identifier = false; int c = _reader.Peek(); if (c == '-') { minus = true; _reader.Read(); sb.Append((char)c); } while (true) { c = _reader.Peek(); // ファイルの末尾ならば読み込み終了 if (c == -1) { break; } // 数字ならば読み進める if (char.IsDigit((char)c)) { _reader.Read(); sb.Append((char)c); continue; } // 小数点 if (!point && !identifier && c == '.') { point = true; _reader.Read(); sb.Append((char)c); continue; } // 英文字ならば識別子に切り替えて読み進める if (!minus && !point && (char.IsLetter((char)c) || c == '_')) { identifier = true; _reader.Read(); sb.Append((char)c); continue; } // 対象外の文字ならば抜ける break; } // 識別子トークンを返す if (identifier) { return(new Token { Type = TokenType.Identifier, Value = sb.ToString() }); } // 数字トークンを返す double d; if (DoubleHelper.TryParse(sb.ToString(), out d)) { return(new Token { Type = TokenType.Number, Value = d }); } return(new Token { Type = TokenType.Invalid, Value = sb.ToString() }); }