/// <summary> /// Handles the Click event of the btnAdd control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> void btnAdd_Click(object sender, EventArgs e) { // Validate if (!_selectedItem.HasValue) { MessageBox.Show("You must select an item to add first."); return; } if (RequireDistinct) { if (lstItems.Items.Cast<CharacterTemplateInventoryItem>().Any(x => _selectedItem.HasValue && x.ID == _selectedItem.Value)) { MessageBox.Show("That item is already in the list."); _selectedItem = null; return; } } // Add var newItem = new CharacterTemplateInventoryItem(_selectedItem.Value, ItemChance.FromPercent(1f), 1, 1); lstItems.Items.Add(newItem); if (RequireDistinct) { _selectedItem = null; txtItem.Text = string.Empty; } // Select the new item lstItems.SelectedItem = newItem; }
/// <summary> /// Handles the Click event of the btnAdd control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> void btnAdd_Click(object sender, EventArgs e) { // Validate if (!_selectedItem.HasValue) { MessageBox.Show("You must select an item to add first."); return; } if (RequireDistinct) { if ( lstItems.Items.Cast <CharacterTemplateInventoryItem>().Any( x => _selectedItem.HasValue && x.ID == _selectedItem.Value)) { MessageBox.Show("That item is already in the list."); _selectedItem = null; return; } } // Add var newItem = new CharacterTemplateInventoryItem(_selectedItem.Value, ItemChance.Percent100, 1, 1); lstItems.Items.Add(newItem); if (RequireDistinct) { _selectedItem = null; txtItem.Text = string.Empty; } // Select the new item lstItems.SelectedItem = newItem; }
/// <summary> /// Gets the string to draw for a list item. /// </summary> /// <param name="x">The list item.</param> /// <returns>The string to draw for a list item.</returns> static string GetDrawString(CharacterTemplateInventoryItem x) { var t = ItemTemplateManager.Instance[x.ID]; string item; if (t == null) { item = "ID " + x; } else { item = t.ID + ". " + t.Name; } var chance = string.Format("[{0:#,000.00}%] [{1} - {2}]", Math.Round(x.Chance.Percentage * 100, 2), x.Min, x.Max); return(chance + " " + item); }