public ListPropertyControl(String propertyId, String label, String currentValue, String defaultValue, String helpText, String filterText, String categoryText, String propertyType) { InitializeComponent(); this.label = label; this.propertyId = propertyId; this.label1.Text = label; ListPropertyValues.addPropertyToListboxData(propertyId, propertyType); this.availableValues = ListPropertyValues.getListBoxLabels(propertyId); this.comboBox1.BeginUpdate(); foreach (String value in availableValues) { this.comboBox1.Items.Add(value); } this.comboBox1.EndUpdate(); this.originalValue = ListPropertyValues.getLabelForInvariantItem(propertyId, currentValue); this.comboBox1.Text = this.originalValue; this.comboBox1.SelectedIndex = availableValues.IndexOf(this.originalValue); this.defaultValue = ListPropertyValues.getLabelForInvariantItem(propertyId, defaultValue); this.toolTip1.SetToolTip(this.comboBox1, helpText); this.toolTip1.SetToolTip(this.label1, helpText); this.filter = new PropertyFilter(filterText, categoryText, propertyId, this.label); this.comboBox1.SelectedIndexChanged += textChanged; }
// Note: vast majority of startup time is in ShowDialog. Looks like pretty much the only way to speed it up is by reducing // number of controls or splitting in tabs. public PropertiesForm(System.Windows.Forms.Form parent) { if (MainWindow.forceMinWindowSize) { this.MinimumSize = new System.Drawing.Size(995, 745); } hasChanges = false; this.parent = parent; InitializeComponent(); if (CrewChief.Debugging) { this.saveButton.Text = "Save (manual restart required)"; } this.SuspendLayout(); this.propertiesFlowLayoutPanel.SuspendLayout(); int widgetCount = 0; foreach (SettingsProperty strProp in UserSettings.GetUserSettings().getProperties(typeof(String), null, null)) { if (strProp.Name.EndsWith(PropertiesForm.listPropPostfix) && ListPropertyValues.getListBoxLabels(strProp.Name) != null) { this.propertiesFlowLayoutPanel.Controls.Add(new ListPropertyControl(strProp.Name, Configuration.getUIString(strProp.Name) + " " + Configuration.getUIString("text_prop_type"), UserSettings.GetUserSettings().getString(strProp.Name), (String)strProp.DefaultValue, Configuration.getUIString(strProp.Name + "_help"), Configuration.getUIStringStrict(strProp.Name + "_filter"), Configuration.getUIStringStrict(strProp.Name + "_category"), Configuration.getUIStringStrict(strProp.Name + "_type"))); } else { this.propertiesFlowLayoutPanel.Controls.Add(new StringPropertyControl(strProp.Name, Configuration.getUIString(strProp.Name) + " " + Configuration.getUIString("text_prop_type"), UserSettings.GetUserSettings().getString(strProp.Name), (String)strProp.DefaultValue, Configuration.getUIString(strProp.Name + "_help"), Configuration.getUIStringStrict(strProp.Name + "_filter"), Configuration.getUIStringStrict(strProp.Name + "_category"))); } widgetCount++; } pad(widgetCount); widgetCount = 0; foreach (SettingsProperty boolProp in UserSettings.GetUserSettings().getProperties(typeof(Boolean), "enable", null)) { Boolean defaultValue; Boolean.TryParse((String)boolProp.DefaultValue, out defaultValue); this.propertiesFlowLayoutPanel.Controls.Add(new BooleanPropertyControl(boolProp.Name, Configuration.getUIString(boolProp.Name) + " " + Configuration.getUIString("boolean_prop_type"), UserSettings.GetUserSettings().getBoolean(boolProp.Name), defaultValue, Configuration.getUIString(boolProp.Name + "_help"), Configuration.getUIStringStrict(boolProp.Name + "_filter"), Configuration.getUIStringStrict(boolProp.Name + "_category"))); widgetCount++; } pad(widgetCount); widgetCount = 0; foreach (SettingsProperty intProp in UserSettings.GetUserSettings().getProperties(typeof(int), "frequency", null)) { int defaultValue; int.TryParse((String)intProp.DefaultValue, out defaultValue); this.propertiesFlowLayoutPanel.Controls.Add(new IntPropertyControl(intProp.Name, Configuration.getUIString(intProp.Name) + " " + Configuration.getUIString("integer_prop_type"), UserSettings.GetUserSettings().getInt(intProp.Name), defaultValue, Configuration.getUIString(intProp.Name + "_help"), Configuration.getUIStringStrict(intProp.Name + "_filter"), Configuration.getUIStringStrict(intProp.Name + "_category"))); widgetCount++; } pad(widgetCount); widgetCount = 0; foreach (SettingsProperty boolProp in UserSettings.GetUserSettings().getProperties(typeof(Boolean), null, "enable")) { Boolean defaultValue; Boolean.TryParse((String)boolProp.DefaultValue, out defaultValue); this.propertiesFlowLayoutPanel.Controls.Add(new BooleanPropertyControl(boolProp.Name, Configuration.getUIString(boolProp.Name) + " " + Configuration.getUIString("boolean_prop_type"), UserSettings.GetUserSettings().getBoolean(boolProp.Name), defaultValue, Configuration.getUIString(boolProp.Name + "_help"), Configuration.getUIStringStrict(boolProp.Name + "_filter"), Configuration.getUIStringStrict(boolProp.Name + "_category"))); widgetCount++; } pad(widgetCount); widgetCount = 0; foreach (SettingsProperty intProp in UserSettings.GetUserSettings().getProperties(typeof(int), null, "frequency")) { int defaultValue; int.TryParse((String)intProp.DefaultValue, out defaultValue); this.propertiesFlowLayoutPanel.Controls.Add(new IntPropertyControl(intProp.Name, Configuration.getUIString(intProp.Name) + " " + Configuration.getUIString("integer_prop_type"), UserSettings.GetUserSettings().getInt(intProp.Name), defaultValue, Configuration.getUIString(intProp.Name + "_help"), Configuration.getUIStringStrict(intProp.Name + "_filter"), Configuration.getUIStringStrict(intProp.Name + "_category"))); widgetCount++; } pad(widgetCount); widgetCount = 0; foreach (SettingsProperty floatProp in UserSettings.GetUserSettings().getProperties(typeof(float), null, null)) { float defaultValue; float.TryParse((String)floatProp.DefaultValue, out defaultValue); this.propertiesFlowLayoutPanel.Controls.Add(new FloatPropertyControl(floatProp.Name, Configuration.getUIString(floatProp.Name) + " " + Configuration.getUIString("real_number_prop_type"), UserSettings.GetUserSettings().getFloat(floatProp.Name), defaultValue, Configuration.getUIString(floatProp.Name + "_help"), Configuration.getUIStringStrict(floatProp.Name + "_filter"), Configuration.getUIStringStrict(floatProp.Name + "_category"))); widgetCount++; } pad(widgetCount); widgetCount = 0; this.searchTextPrev = DEFAULT_SEARCH_TEXT; this.gameFilterPrev = GameEnum.UNKNOWN; this.specialFilterPrev = SpecialFilter.UNKNOWN; this.categoryFilterPrev = PropertyCategory.ALL; // Initialize this here, so that initial game filtering works. this.includeCommonPreferencesPrev = true; this.searchTextBox.Text = DEFAULT_SEARCH_TEXT; this.searchTextBox.ForeColor = Color.Gray; this.searchTextBox.GotFocus += SearchTextBox_GotFocus; this.searchTextBox.LostFocus += SearchTextBox_LostFocus; this.searchTextBox.KeyDown += SearchTextBox_KeyDown; this.exitButton.Select(); this.KeyPreview = true; this.KeyDown += PropertiesForm_KeyDown; this.DoubleBuffered = true; // Filtering setup. this.filterBox.Items.Clear(); this.filterBox.Items.Add(new ComboBoxItem <SpecialFilter>() { Label = Configuration.getUIString("all_preferences_label"), Value = SpecialFilter.ALL_PREFERENCES }); this.filterBox.Items.Add(new ComboBoxItem <SpecialFilter>() { Label = Configuration.getUIString("common_preferences_label"), Value = SpecialFilter.COMMON_PREFERENCES }); lock (MainWindow.instanceLock) { if (MainWindow.instance != null) { var currSelectedGameFriendlyName = MainWindow.instance.gameDefinitionList.Text; foreach (var game in MainWindow.instance.gameDefinitionList.Items) { var friendlyGameName = game.ToString(); this.filterBox.Items.Add(new ComboBoxItem <GameEnum>() { Label = friendlyGameName, Value = GameDefinition.getGameDefinitionForFriendlyName(friendlyGameName).gameEnum }); if (friendlyGameName == currSelectedGameFriendlyName) { this.filterBox.SelectedIndex = this.filterBox.Items.Count - 1; } } } } // Special case for no game selected. if (this.filterBox.SelectedIndex == -1) { this.filterBox.SelectedIndex = 0; // No need to filter. this.specialFilterPrev = SpecialFilter.ALL_PREFERENCES; } // Category filter: this.categoriesBox.Items.Clear(); this.categoriesBox.Items.Add(new ComboBoxItem <PropertyCategory>() { Label = Configuration.getUIString("all_categories_label"), Value = PropertyCategory.ALL }); this.categoriesBox.Items.Add(new ComboBoxItem <PropertyCategory>() { Label = Configuration.getUIString("ui_startup_and_paths_category_label"), Value = PropertyCategory.UI_STARTUP_AND_PATHS }); this.categoriesBox.Items.Add(new ComboBoxItem <PropertyCategory>() { Label = Configuration.getUIString("audio_voice_and_controllers_category_label"), Value = PropertyCategory.AUDIO_VOICE_AND_CONTROLLERS }); this.categoriesBox.Items.Add(new ComboBoxItem <PropertyCategory>() { Label = Configuration.getUIString("spotter_category_label"), Value = PropertyCategory.SPOTTER }); this.categoriesBox.Items.Add(new ComboBoxItem <PropertyCategory>() { Label = Configuration.getUIString("flags_and_rules_category_label"), Value = PropertyCategory.FLAGS_AND_RULES }); this.categoriesBox.Items.Add(new ComboBoxItem <PropertyCategory>() { Label = Configuration.getUIString("message_frequences_category_label"), Value = PropertyCategory.MESSAGE_FREQUENCES }); this.categoriesBox.Items.Add(new ComboBoxItem <PropertyCategory>() { Label = Configuration.getUIString("fuel_temps_and_damages_category_label"), Value = PropertyCategory.FUEL_TEMPS_AND_DAMAGES }); this.categoriesBox.Items.Add(new ComboBoxItem <PropertyCategory>() { Label = Configuration.getUIString("timings_category_label"), Value = PropertyCategory.TIMINGS }); this.categoriesBox.Items.Add(new ComboBoxItem <PropertyCategory>() { Label = Configuration.getUIString("pit_stops_and_multiclass_category_label"), Value = PropertyCategory.PIT_STOPS_AND_MULTICLASS }); this.categoriesBox.Items.Add(new ComboBoxItem <PropertyCategory>() { Label = Configuration.getUIString("misc_category_label"), Value = PropertyCategory.MISC }); this.categoriesBox.SelectedIndex = 0; this.categoriesBox.SelectedValueChanged += this.CategoriesBox_SelectedValueChanged; this.propertiesFlowLayoutPanel.ResumeLayout(false); this.ResumeLayout(false); }
public String getValue() { return(ListPropertyValues.getInvariantValueForLabel(propertyId, this.availableValues[this.comboBox1.SelectedIndex])); }