// event handler for secondary type combobox DropDownClosed event private void secondaryTypeComboBox_DropDownClosed(object sender, EventArgs e) { // if the type was deleted from primary type combobox insert it back and reset variable if (DeletedTypeFromPrimaryCombobox != null) { PrimaryPkmnTypeList.Insert(IndexOfDeletedPrimaryType, DeletedTypeFromPrimaryCombobox); DeletedTypeFromPrimaryCombobox = null; } // helper variable var selectedSecondaryType = secondaryTypeComboBox.SelectedItem as IPkmnType; // if selected secondarytype is not "(none)" delete it from primarytype list and save to "Deleted" properties if (!(selectedSecondaryType is EmptyPkmnType)) { DeletedTypeFromPrimaryCombobox = PrimaryPkmnTypeList.Where(i => i.TypeName == selectedSecondaryType.TypeName).FirstOrDefault(); IndexOfDeletedPrimaryType = PrimaryPkmnTypeList.IndexOf(DeletedTypeFromPrimaryCombobox); PrimaryPkmnTypeList.Remove(PrimaryPkmnTypeList.Where(i => i.TypeName == selectedSecondaryType.TypeName).FirstOrDefault()); } // refresh primarytype combobox primaryTypeComboBox.DataSource = null; primaryTypeComboBox.DataSource = PrimaryPkmnTypeList; // if something was selected in primary combobox select it again after combobox refreshed and possibly changed index if (DeletedTypeFromSecondaryCombobox != null) { primaryTypeComboBox.SelectedIndex = PrimaryPkmnTypeList. IndexOf(PrimaryPkmnTypeList. Where(i => i.TypeName == DeletedTypeFromSecondaryCombobox.TypeName).FirstOrDefault()); } }
public IndexModel(ILogger <IndexModel> logger) { _logger = logger; // add empty pkmn types to the comboboxes PrimaryPkmnTypeList.Insert(0, PkmnTypeFactory.CreateEmptyPkmnType()); SecondaryPkmnTypeList.Insert(0, PkmnTypeFactory.CreateEmptyPkmnType()); }
public void OnGet() { //PrimaryPkmnTypeList = PkmnTypeFactory.GeneratePkmnTypeList(); //SecondaryPkmnTypeList = PkmnTypeFactory.GeneratePkmnTypeList(); //PrimaryPkmnTypeList.Insert(0, PkmnTypeFactory.CreateEmptyPkmnType()); //SecondaryPkmnTypeList.Insert(0, PkmnTypeFactory.CreateEmptyPkmnType()); // check for nulls and change to (none) if types are not selected if (SelectedPrimaryTypeName == null) { SelectedPrimaryTypeName = "(none)"; SelectedPrimaryTypeColor = "white"; } //if(SelectedPrimaryType == null) //{ // SelectedPrimaryType = PkmnTypeFactory.CreateEmptyPkmnType(); //} //if(SelectedSecondaryType == null) //{ // SelectedSecondaryType = PkmnTypeFactory.CreateEmptyPkmnType(); //} if (SelectedSecondaryTypeName == null) { SelectedSecondaryTypeName = "(none)"; SelectedSecondaryTypeColor = "white"; } selectedPrimaryType = PrimaryPkmnTypeList.Where(type => type.TypeName == SelectedPrimaryTypeName).FirstOrDefault(); selectedSecondaryType = SecondaryPkmnTypeList.Where(type => type.TypeName == SelectedSecondaryTypeName).FirstOrDefault(); // delete selected type from the other list //PrimaryPkmnTypeList.Remove(SecondaryPkmnTypeList.Where(type => type.TypeName == SelectedSecondaryTypeName).FirstOrDefault()); //SecondaryPkmnTypeList.Remove(PrimaryPkmnTypeList.Where(type => type.TypeName == SelectedPrimaryTypeName).FirstOrDefault()); SelectedPrimaryTypeColor = selectedPrimaryType.TypeColor; SelectedSecondaryTypeColor = selectedSecondaryType.TypeColor; // check if both comboboxes select the (none) type if (SelectedPrimaryTypeName == "(none)" && SelectedSecondaryTypeName == "(none)") { return; } // calculate damage multiplier for each pkmn type in the list foreach (var pkmnType in PkmnTypeList) { pkmnType.DmgMultiplier = pkmnType.CalculateDmgMultiplier(selectedPrimaryType, selectedSecondaryType); } // sort by damage multiplier from highest to lowest PkmnTypeList.Sort((x, y) => y.DmgMultiplier.CompareTo(x.DmgMultiplier)); }
// form constructor public PokemonTypeCalculatorForm() { InitializeComponent(); // add empty pkmn types to the comboboxes PrimaryPkmnTypeList.Insert(0, PkmnTypeFactory.CreateEmptyPkmnType()); SecondaryPkmnTypeList.Insert(0, PkmnTypeFactory.CreateEmptyPkmnType()); // set the collection properties as datasources for the comboboxes primaryTypeComboBox.DataSource = PrimaryPkmnTypeList; secondaryTypeComboBox.DataSource = SecondaryPkmnTypeList; // set the name of the pokemon type as a displayed value for comboboxes primaryTypeComboBox.DisplayMember = "TypeName"; secondaryTypeComboBox.DisplayMember = "TypeName"; // set the collection for list view pkmnTypeObjectListView.SetObjects(PkmnTypeList); // set focus on damage taken button showDamageTakenButton.Select(); }