Ejemplo n.º 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;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new item for the "Variables" <see cref="ListView"/> on the <see
        /// cref="VariablesTab"/> page, containing the specified <see cref="VariableClass"/>
        /// identifier and associated modifier value for the specified <see cref="ModifierTarget"/>.
        /// </summary>
        /// <param name="id">
        /// The <see cref="VariableClass.Id"/> string of a <see cref="VariableClass"/>.</param>
        /// <param name="target">
        /// A <see cref="ModifierTarget"/> value indicating which modifier value to add.</param>
        /// <returns>
        /// The new <see cref="VariableListItem"/> if one was created and added to the "Variables"
        /// <see cref="ListView"/>; otherwise, a null reference.</returns>
        /// <remarks>
        /// <b>CreateVariableItem</b> immediately returns a null reference if the specified
        /// <paramref name="id"/> is not found in the currently selected default <see
        /// cref="VariableModifierDictionary"/>, or if the element that matches the specified
        /// <paramref name="id"/> does not define a modifier value for the specified <paramref
        /// name="target"/>.</remarks>

        private VariableListItem CreateVariableItem(string id, ModifierTarget target)
        {
            if (this._defaultVariableModifiers == null)
            {
                return(null);
            }

            // get default modifier if present
            VariableModifier defaultModifier;

            if (!this._defaultVariableModifiers.TryGetValue(id, out defaultModifier))
            {
                return(null);
            }

            // get value for specified target, if any
            int?defaultValue = defaultModifier.GetByTarget(target);

            if (defaultValue == null)
            {
                return(null);
            }

            // add current modifier if necessary
            VariableModifier currentModifier;

            if (!this._currentVariableModifiers.TryGetValue(id, out currentModifier))
            {
                currentModifier = (VariableModifier)defaultModifier.Clone();
                this._currentVariableModifiers.Add(id, currentModifier);
            }

            // format variable as modifier value
            int?currentValue         = currentModifier.GetByTarget(target);
            VariableListItem newItem = new VariableListItem(id,
                                                            VariableClass.FormatUnscaled(currentValue, target),
                                                            VariableClass.FormatUnscaled(defaultValue.Value, true), target);

            ItemCollection items = VariableList.Items;

            for (int i = 0; i < items.Count; i++)
            {
                VariableListItem item = (VariableListItem)items[i];

                // sort alphabetically, with basic values before modifiers
                if (String.CompareOrdinal(item.Id, newItem.Id) > 0)
                {
                    items.Insert(i, newItem);
                    return(newItem);
                }
            }

            // append to end of list
            items.Add(newItem);
            return(newItem);
        }
Ejemplo n.º 3
0
        /// <overloads>
        /// Creates a new item for the "Variables" <see cref="ListView"/> on the <see
        /// cref="VariablesTab"/> page, containing the specified <see cref="VariableClass"/>
        /// identifier and associated value.</overloads>
        /// <summary>
        /// Creates a new item for the "Variables" <see cref="ListView"/> on the <see
        /// cref="VariablesTab"/> page, containing the specified <see cref="VariableClass"/>
        /// identifier and associated basic value.</summary>
        /// <param name="id">
        /// The <see cref="VariableClass.Id"/> string of a <see cref="VariableClass"/>.</param>
        /// <returns>
        /// The new <see cref="VariableListItem"/> if one was created and added to the "Variables"
        /// <see cref="ListView"/>; otherwise, a null reference.</returns>
        /// <remarks>
        /// <b>CreateVariableItem</b> immediately returns a null reference if the specified
        /// <paramref name="id"/> is not found in the currently selected default <see
        /// cref="VariableValueDictionary"/>.</remarks>

        private VariableListItem CreateVariableItem(string id)
        {
            if (this._defaultVariables == null)
            {
                return(null);
            }

            // get default value if present
            int defaultValue;

            if (!this._defaultVariables.TryGetValue(id, out defaultValue))
            {
                return(null);
            }

            // add current value if necessary
            int currentValue;

            if (!this._currentVariables.TryGetValue(id, out currentValue))
            {
                currentValue = defaultValue;
            }

            // format variable as basic value
            VariableListItem newItem = new VariableListItem(id,
                                                            VariableClass.FormatUnscaled(currentValue, false),
                                                            VariableClass.FormatUnscaled(defaultValue, false), null);

            ItemCollection items = VariableList.Items;

            for (int i = 0; i < items.Count; i++)
            {
                VariableListItem item = (VariableListItem)items[i];

                // sort alphabetically, with basic values before modifiers
                if (item.Id == newItem.Id || String.CompareOrdinal(item.Id, newItem.Id) > 0)
                {
                    items.Insert(i, newItem);
                    return(newItem);
                }
            }

            // append to end of list
            items.Add(newItem);
            return(newItem);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Resets all current values in the "Variables" <see cref="ListView"/> on the <see
        /// cref="VariablesTab"/> page to their default values.</summary>
        /// <remarks>
        /// <b>ResetVariables</b> copies the "Default Value" column to the "Value" column for all
        /// items in the "Variables" list view, and then reselects the currently selected item to
        /// update all other controls.</remarks>

        private void ResetVariables()
        {
            if (VariableList.Items.Count == 0)
            {
                return;
            }

            // reset all current values to their default values
            for (int i = 0; i < VariableList.Items.Count; i++)
            {
                VariableListItem item = (VariableListItem)VariableList.Items[i];
                item.Value = item.DefaultValue;
            }
            VariableList.Items.Refresh();

            // reselect current selection to update other controls
            int index = VariableList.SelectedIndex;

            VariableList.SelectedIndex = -1;
            VariableList.SelectAndShow(Math.Max(0, index));
        }