private void label_MouseDown(object sender, MouseEventArgs e) { // Label is used to show an empty numeric up/down. if (numericUpDown.Visible && Parameter == null) { Parameter = new TriggerParameterUshort(0); } }
private void numericUpDown_ValueChanged(object sender, EventArgs e) { if (_currentlyChanging || !numericUpDown.Visible) { return; } Parameter = new TriggerParameterUshort(BitConverter.ToUInt16(BitConverter.GetBytes((int)numericUpDown.Value), 0)); }
private void UpdateVisibleControls(bool repopulate) { // Prevent combo content manipulation try { _currentlyChanging = true; // Populate controls if (repopulate) { combo.DataSource = null; } bool typeMatches = ParameterRange.ParameterMatches(Parameter, true); butReset.Visible = !typeMatches; if (typeMatches) { ITriggerParameter[] listOfThings; try { listOfThings = ParameterRange.BuildList(Level)?.ToArray(); } catch (Exception exc) { logger.Warn(exc, "Unable to create trigger parameter list."); listOfThings = null; } if (ParameterRange.IsEmpty) { label.Text = "-"; combo.Visible = false; butSearch.Visible = false; numericUpDown.Visible = false; label.Visible = true; colorPreview.Visible = false; } else if (listOfThings == null || _rawMode && !ParameterRange.IsObject && !ParameterRange.IsRoom) { label.Text = ""; combo.Visible = false; butSearch.Visible = false; numericUpDown.Visible = true; if (_parameter != null && _parameter is TriggerParameterUshort) { numericUpDown.Value = BitConverter.ToInt16(BitConverter.GetBytes((_parameter as TriggerParameterUshort).Key), 0); } else { Parameter = new TriggerParameterUshort(0); } label.Visible = Parameter == null; colorPreview.Visible = false; } else { if (repopulate) { // Sort // For some reason the sorted property of the combo box does not work. if (ParameterRange.Kind == NgParameterKind.FixedEnumeration) { string[] cachedNames = listOfThings.Select(obj => obj?.ToString()).ToArray(); Array.Sort(cachedNames, listOfThings); } combo.DataSource = listOfThings; } combo.SelectedItem = listOfThings.FirstOrDefault(item => item.Equals(Parameter)) ?? null; if (combo.SelectedItem == null) { if (listOfThings?.Count() > 0) { Parameter = listOfThings.First(); return; // Update will finish recursively } else { combo.Text = ""; } } combo.Visible = true; butSearch.Visible = true; numericUpDown.Visible = false; label.Visible = false; SetupColorPreview(combo.SelectedItem?.ToString()); } } else { label.Text = "Wrong parameter: " + (Parameter?.ToString() ?? "<null>"); combo.Visible = false; butSearch.Visible = false; numericUpDown.Visible = false; colorPreview.Visible = false; label.Visible = true; } } finally { _currentlyChanging = false; } }