Esempio n. 1
0
        /// <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;
        }
Esempio n. 2
0
        /// <summary>
        /// Handles the Leave event of the txtAmount 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 txtChance_Leave(object sender, EventArgs e)
        {
            if (lstItems.SelectedItem == null)
            {
                return;
            }

            // Get the selected item
            if (!(lstItems.SelectedItem is CharacterTemplateEquippedItem))
            {
                Debug.Fail("Was expecting type " + typeof(CharacterTemplateEquippedItem));
                return;
            }

            var sel = (CharacterTemplateEquippedItem)lstItems.SelectedItem;

            // Parse the new amount
            float chancePct;

            if (!float.TryParse(txtChance.Text, out chancePct))
            {
                return;
            }

            ItemChance newItemChance = ItemChance.FromPercent(chancePct / 100f);

            // Check that the amount changed
            if (sel.Chance == newItemChance)
            {
                return;
            }

            // Set the new amount
            sel.Chance = newItemChance;

            // Force the text to refresh
            lstItems.Items[lstItems.SelectedIndex] = sel;
        }