/// <summary> /// Creates a new instance of this class, adds it to the internal dictionary, and returns it /// </summary> public static FloatTextBoxValidator Create(TextBox textBox, string defaultText) { FloatTextBoxValidator validator = new FloatTextBoxValidator(textBox, defaultText); textBoxDictionary.Add(textBox, validator); return(validator); }
/// <summary> /// Wraps all text boxes for floats in a validator and registers the proper events /// </summary> private void WrapFloatTextBoxes() { // Value type single var validator = FloatTextBoxValidator.Create(AffixValueTypeSingleMinTextBox, "0"); validator.TextChanged += textbox => { localBaseValueMinSingle = FloatTextBoxValidator.GetValue(textbox); CheckAffixValueTypeSingleChanged(); }; validator = FloatTextBoxValidator.Create(AffixValueTypeSingleMaxTextBox, "0"); validator.TextChanged += textbox => { localBaseValueMaxSingle = FloatTextBoxValidator.GetValue(textbox); CheckAffixValueTypeSingleChanged(); }; // Value type range validator = FloatTextBoxValidator.Create(AffixValueTypeRangeMinMinTextBox, "0"); validator.TextChanged += textbox => { localBaseValueMinRange.MinValue = FloatTextBoxValidator.GetValue(textbox); CheckAffixValueTypeRangeMinChanged(); }; validator = FloatTextBoxValidator.Create(AffixValueTypeRangeMinMaxTextBox, "0"); validator.TextChanged += textbox => { localBaseValueMinRange.MaxValue = FloatTextBoxValidator.GetValue(textbox); CheckAffixValueTypeRangeMinChanged(); }; validator = FloatTextBoxValidator.Create(AffixValueTypeRangeMaxMinTextBox, "0"); validator.TextChanged += textbox => { localBaseValueMaxRange.MinValue = FloatTextBoxValidator.GetValue(textbox); CheckAffixValueTypeRangeMaxChanged(); }; validator = FloatTextBoxValidator.Create(AffixValueTypeRangeMaxMaxTextBox, "0"); validator.TextChanged += textbox => { localBaseValueMaxRange.MaxValue = FloatTextBoxValidator.GetValue(textbox); CheckAffixValueTypeRangeMaxChanged(); }; }
public EditProgressionParametersForm(float[] parameters) { originalParameters = parameters; Parameters = new float[parameters.Length]; parameters.CopyTo(Parameters, 0); for (int i = 0; i < parameters.Length; i++) { TextBox textbox = new TextBox { Location = new Point(10, 10 + (i * TEXTBOX_SPACING)), Text = parameters[i].ToString() }; FloatTextBoxValidator validator = FloatTextBoxValidator.Create(textbox); int index = i; validator.TextChanged += (_) => { Parameters[index] = FloatTextBoxValidator.GetValue(textbox); }; Controls.Add(textbox); } InitializeComponent(); Height = parameters.Length * TEXTBOX_SPACING + 100; }
/// <summary> /// Fills in all forms based on currentInfo /// </summary> private void UpdateCurrentAffixInfoDisplay() { if (currentInfo == null) { AffixNameTextBox.Text = ""; AffixNameTextBox.Enabled = false; AffixDescriptionTextBox.Text = ""; AffixDescriptionTextBox.Enabled = false; AffixValueTypeComboBox.SelectedIndex = 0; AffixValueTypeComboBox.Enabled = false; AffixProgressionComboBox.SelectedIndex = 0; AffixProgressionComboBox.Enabled = false; AffixValueTypeSinglePanel.Visible = false; AffixValueTypeRangePanel.Visible = false; AffixValueTypeSingleMinTextBox.Text = ""; AffixValueTypeSingleMaxTextBox.Text = ""; AffixValueTypeRangeMinMinTextBox.Text = ""; AffixValueTypeRangeMinMaxTextBox.Text = ""; AffixValueTypeRangeMaxMinTextBox.Text = ""; AffixValueTypeRangeMaxMaxTextBox.Text = ""; } else { AffixNameTextBox.Text = currentInfo.Name; AffixNameTextBox.Enabled = true; AffixDescriptionTextBox.Text = currentInfo.Description; AffixDescriptionTextBox.Enabled = true; AffixValueTypeComboBox.SelectedIndex = AffixValueTypeComboBox.Items.IndexOf(currentInfo.ValueType); AffixValueTypeComboBox.Enabled = true; // Copy parameters first since changing the combobox index calls the SelectedIndexChanged event // at which point we already compare the original values to our local copy localProgressionParameters = new float[currentInfo.ValueInfo.Progression.Parameters.Length]; currentInfo.ValueInfo.Progression.Parameters.CopyTo(localProgressionParameters, 0); AffixProgressionComboBox.SelectedIndex = AffixProgressionComboBox.Items.IndexOf(currentInfo.ValueInfo.Progression.GetName()); AffixProgressionComboBox.Enabled = true; if (currentInfo.ValueType == AffixValueType.SingleValue) { AffixValueTypeSingleMinTextBox.Text = currentInfo.ValueInfo.BaseValueMin.ToString(); FloatTextBoxValidator.CaptureContentsAsDefault(AffixValueTypeSingleMinTextBox); AffixValueTypeSingleMaxTextBox.Text = currentInfo.ValueInfo.BaseValueMax.ToString(); FloatTextBoxValidator.CaptureContentsAsDefault(AffixValueTypeSingleMaxTextBox); } else if (currentInfo.ValueType == AffixValueType.Range) { AffixValueTypeRangeMinMinTextBox.Text = (currentInfo.ValueInfo.BaseValueMin as AffixValueRange).Value.MinValue.ToString(); FloatTextBoxValidator.CaptureContentsAsDefault(AffixValueTypeRangeMinMinTextBox); AffixValueTypeRangeMinMaxTextBox.Text = (currentInfo.ValueInfo.BaseValueMin as AffixValueRange).Value.MaxValue.ToString(); FloatTextBoxValidator.CaptureContentsAsDefault(AffixValueTypeRangeMinMaxTextBox); AffixValueTypeRangeMaxMinTextBox.Text = (currentInfo.ValueInfo.BaseValueMax as AffixValueRange).Value.MinValue.ToString(); FloatTextBoxValidator.CaptureContentsAsDefault(AffixValueTypeRangeMaxMinTextBox); AffixValueTypeRangeMaxMaxTextBox.Text = (currentInfo.ValueInfo.BaseValueMax as AffixValueRange).Value.MaxValue.ToString(); FloatTextBoxValidator.CaptureContentsAsDefault(AffixValueTypeRangeMaxMaxTextBox); } } }