Пример #1
0
        /// <summary>
        /// Handles the <see cref="Selector.SelectionChanged"/> event for the "Variables" <see
        /// cref="ListView"/> on the <see cref="VariablesTab"/> page.</summary>
        /// <param name="sender">
        /// The <see cref="Object"/> where the event handler is attached.</param>
        /// <param name="args">
        /// A <see cref="SelectionChangedEventArgs"/> object containing event data.</param>
        /// <remarks>
        /// <b>OnVariableSelected</b> updates the "Value" control with the data of the first
        /// selected item in the "Variables" list view.</remarks>

        private void OnVariableSelected(object sender, SelectionChangedEventArgs args)
        {
            args.Handled = true;
            if (!this._initialized)
            {
                return;
            }

            // retrieve selected variable entry, if any
            decimal value = 0m;
            int     index = VariableList.SelectedIndex;

            if (index >= 0)
            {
                // update numeric control with variable value
                VariableListItem item = (VariableListItem)VariableList.Items[index];
                if (item.Target == null)
                {
                    value = VariableClass.ParseUnscaled(item.Value);
                }
                else
                {
                    ModifierTarget target;
                    if (!VariableClass.TryParseUnscaled(item.Value, out value, out target))
                    {
                        Debug.Fail("OnVariableSelected: TryParseUnscaled failed.");
                    }
                    Debug.Assert(target == item.Target.Value);
                }
            }

            VariableUpDown.Value = value;
        }
Пример #2
0
        /// <summary>
        /// Handles the <see cref="NumericUpDown.ValueChanged"/> event for the "Value" <see
        /// cref="NumericUpDown"/> control on the <see cref="VariablesTab"/> page.</summary>
        /// <param name="sender">
        /// The <see cref="NumericUpDown"/> control sending the event.</param>
        /// <param name="args">
        /// An <see cref="EventArgs"/> object containing event data.</param>
        /// <remarks>
        /// <b>OnVariableChanged</b> updates the "Value" column of the first selected item in the
        /// "Variables" list view, as well as the corresponding backing dictionary.</remarks>

        private void OnVariableChanged(object sender, EventArgs args)
        {
            if (!this._initialized)
            {
                return;
            }

            // retrieve selected variable entry, if any
            int index = VariableList.SelectedIndex;

            if (index < 0)
            {
                return;
            }
            var item = (VariableListItem)VariableList.Items[index];

            // extract decimal value and modifier flag
            decimal oldValue;

            if (item.Target == null)
            {
                oldValue = VariableClass.ParseUnscaled(item.Value);
            }
            else
            {
                ModifierTarget target;
                if (!VariableClass.TryParseUnscaled(item.Value, out oldValue, out target))
                {
                    Debug.Fail("OnVariableChanged: TryParseUnscaled failed.");
                }
                Debug.Assert(target == item.Target.Value);
            }

            // check if variable value has actually changed
            if (VariableUpDown.Value == oldValue)
            {
                return;
            }
            int value = (int)VariableUpDown.Value;

            // update variable value in collection
            string formatValue;

            if (item.Target == null)
            {
                this._currentVariables[item.Id] = value;
                formatValue = VariableClass.FormatUnscaled(value, false);
            }
            else
            {
                this._currentVariableModifiers[item.Id].SetByTarget(item.Target.Value, value);
                formatValue = VariableClass.FormatUnscaled(value, item.Target.Value);
            }

            // update variable value in list view
            item.Value = formatValue;
            VariableList.Items.Refresh();
            VariableList.SelectAndShow(index);
        }