Exemplo n.º 1
0
        /// <summary>
        /// Adds the FieldVisibilityModifier to the VisibilityModifiers List. Replaces another modifier with the same ID. Sorts the new Entry: First alls additive, then all multiplicative modifiers. Calculates the new Visibility value for the Field.
        /// </summary>
        /// <param name="visibilityModifier">The modifier to add to the list.</param>
        private void AddVisibilityModifier(Modifier.FieldVisibilityModifier visibilityModifier)
        {
            bool   ModIsInserted = false;
            double visibility    = 1;

            for (int i = 0; i < VisibilityModifiers.Count; i++)
            {
                //Is there a modifier with the same ID? Replace it.
                if (visibilityModifier.ModifierID == VisibilityModifiers[i].ModifierID)
                {
                    VisibilityModifiers.RemoveAt(i);
                    VisibilityModifiers.Insert(i, visibilityModifier);
                    ModIsInserted = true;
                }
                //Insert the additive modifier at the end of all the additive modifiers, if there was no duplicate.
                if (!ModIsInserted && visibilityModifier.Additive && !VisibilityModifiers[i].Additive)
                {
                    VisibilityModifiers.Insert(i, visibilityModifier);
                    ModIsInserted = true;
                }
                //Insert the modifier, when the end of the list is reached and it wasn't inserted already.
                if (!ModIsInserted && i == VisibilityModifiers.Count - 1)
                {
                    VisibilityModifiers.Add(visibilityModifier);
                    ModIsInserted = true;
                }

                //If the modifier at position i is Additive, add it. If it is a multiplicator, multiply it.
                if (VisibilityModifiers[i].Additive)
                {
                    visibility += VisibilityModifiers[i].Value;
                }
                else
                {
                    visibility *= VisibilityModifiers[i].Value;
                }
            }

            Visibility = visibility;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Adds a VisibilityModifier to the VisibilityModifiers List by ID.
 /// </summary>
 /// <param name="modifierID"></param>
 /// <param name="value"></param>
 public void AddVisibilityModifier(int modifierID, double value = 1)
 {
     Modifier.FieldVisibilityModifier visibilityModifier = new Modifier.FieldVisibilityModifier(this, modifierID, value);
     AddVisibilityModifier(visibilityModifier);
 }