/// <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<CharacterTemplateEquippedItem>().Any(x => _selectedItem.HasValue && x.ID == _selectedItem.Value)) { MessageBox.Show("That item is already in the list."); _selectedItem = null; return; } } // Add var newItem = new CharacterTemplateEquippedItem(_selectedItem.Value, ItemChance.FromPercent(1.0f)); 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 <CharacterTemplateEquippedItem>().Any(x => _selectedItem.HasValue && x.ID == _selectedItem.Value)) { MessageBox.Show("That item is already in the list."); _selectedItem = null; return; } } // Add var newItem = new CharacterTemplateEquippedItem(_selectedItem.Value, ItemChance.FromPercent(1.0f)); 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(CharacterTemplateEquippedItem 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}%]", Math.Round(x.Chance.Percentage * 100, 2)); return chance + " " + item; }
/// <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(CharacterTemplateEquippedItem 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}%]", Math.Round(x.Chance.Percentage * 100, 2)); return(chance + " " + item); }
/// <summary> /// Provides the extra text for the <see cref="AdvancedPropertyDescriptor"/> for a /// <see cref="CharacterTemplateEquippedItem"/>. /// </summary> /// <param name="v">The value.</param> /// <returns>The extra text to display.</returns> static string ExtraTextProvider_CharacterTemplateEquippedItem(CharacterTemplateEquippedItem v) { var item = ItemTemplateManager.Instance[v.ID]; if (item == null) return null; var chance = Math.Round(v.Chance.Percentage * 100f, 0) + "%"; return "[" + chance + "] " + item.Name; }