private void ClearAttributeConstraints()
 {
     _addedAttributes.Clear();
     AttributeConstraints.Clear();
     AttributesView.Refresh();
     AttributesView.MoveCurrentToFirst();
     NewAttributeConstraint = new AttributeConstraint(AttributesView.CurrentItem as string);
 }
 public override void Reset()
 {
     _addedAttributes.Clear();
     AttributeConstraints.Clear();
     AttributesView.Refresh();
     AttributesView.MoveCurrentToFirst();
     NewAttributeConstraint = new AttributeConstraint(AttributesView.CurrentItem as string);
     _addedPseudoAttributes.Clear();
     PseudoAttributeConstraints.Clear();
     PseudoAttributesView.Refresh();
     PseudoAttributesView.MoveCurrentToFirst();
     NewPseudoAttributeConstraint =
         new PseudoAttributeConstraint(PseudoAttributesView.CurrentItem as PseudoAttribute);
     TreePlusItemsMode = TreePlusItemsModeDefaultValue;
     WeaponClass       = WeaponClassDefaultValue;
     OffHand           = OffHandDefaultValue;
     Tags = TagsDefaultValue;
 }
        /// <summary>
        /// Converts attribute constraints to pseudo attribute constraints with the set Tags, WeaponClass,
        /// OffHand and check-tagged keystones where possible.
        /// Str, Int and Dex are not removed from the attribute constraint list but still converted.
        /// </summary>
        private void ConverteAttributeToPseudoAttributeConstraints()
        {
            var keystones = from node in Tree.GetCheckedNodes()
                            where node.Type == NodeType.Keystone
                            select node.Name;
            var conditionSettings    = new ConditionSettings(Tags.Value, OffHand.Value, keystones.ToArray(), WeaponClass.Value);
            var convertedConstraints = new List <AttributeConstraint>();

            foreach (var attributeConstraint in AttributeConstraints)
            {
                var attrName = attributeConstraint.Data;
                // Select the pseudo attributes and the multiplier for attributes which match the given one and evaluate to true.
                var pseudos =
                    from pseudo in _pseudoAttributes
                    let matches = (from attr in pseudo.Attributes
                                   where attr.MatchesAndEvaluates(conditionSettings, attrName)
                                   select attr)
                                  where matches.Any()
                                  select new { PseudoAttribute = pseudo, Multiplier = matches.First().ConversionMultiplier };

                // Add attribute target and weight to the pseudo attributes.
                var converted = false;
                foreach (var pseudo in pseudos)
                {
                    var pseudoAttribute = pseudo.PseudoAttribute;
                    converted = true;
                    if (_addedPseudoAttributes.Contains(pseudoAttribute))
                    {
                        foreach (var pseudoAttributeConstraint in PseudoAttributeConstraints)
                        {
                            if (pseudoAttributeConstraint.Data == pseudoAttribute)
                            {
                                pseudoAttributeConstraint.TargetValue += attributeConstraint.TargetValue * pseudo.Multiplier;
                            }
                        }
                    }
                    else
                    {
                        _addedPseudoAttributes.Add(pseudoAttribute);
                        PseudoAttributeConstraints.Add(new PseudoAttributeConstraint(pseudoAttribute)
                        {
                            TargetValue = attributeConstraint.TargetValue * pseudo.Multiplier
                        });
                    }
                }

                if (converted &&
                    attrName != "+# to Intelligence" && attrName != "+# to Dexterity" && attrName != "+# to Strength")
                {
                    convertedConstraints.Add(attributeConstraint);
                }
            }

            // Update the attribute constraint related collections.
            foreach (var convertedConstraint in convertedConstraints)
            {
                _addedAttributes.Remove(convertedConstraint.Data);
                AttributeConstraints.Remove(convertedConstraint);
            }
            if (convertedConstraints.Count > 0)
            {
                AttributesView.Refresh();
                NewAttributeConstraint = convertedConstraints[0];
                PseudoAttributesView.Refresh();
                PseudoAttributesView.MoveCurrentToFirst();
                NewPseudoAttributeConstraint.Data = PseudoAttributesView.CurrentItem as PseudoAttribute;
            }
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            View.BackgroundColor             = UIColor.White;
            ExtendedLayoutIncludesOpaqueBars = false;
            EdgesForExtendedLayout           = UIRectEdge.None;

            var imageView = new ImageView();

            imageView.TranslatesAutoresizingMaskIntoConstraints = false;
            imageView.SetContentCompressionResistancePriority((float)UILayoutPriority.DefaultLow, UILayoutConstraintAxis.Vertical);
            imageView.SetContentCompressionResistancePriority((float)UILayoutPriority.DefaultLow, UILayoutConstraintAxis.Horizontal);

            var titleView = new TitleView();

            titleView.TranslatesAutoresizingMaskIntoConstraints = false;
            titleView.Title = viewModel.Title;
            titleView.SetContentCompressionResistancePriority((float)UILayoutPriority.Required, UILayoutConstraintAxis.Vertical);
            titleView.SetContentCompressionResistancePriority((float)UILayoutPriority.Required, UILayoutConstraintAxis.Horizontal);

            var attributesView = new AttributesView();

            attributesView.TranslatesAutoresizingMaskIntoConstraints = false;
            attributesView.NumberOfAttributes = viewModel.NumberOfAttributes;
            attributesView.SetContentCompressionResistancePriority((float)UILayoutPriority.Required, UILayoutConstraintAxis.Vertical);
            attributesView.SetContentCompressionResistancePriority((float)UILayoutPriority.Required, UILayoutConstraintAxis.Horizontal);

            for (int i = 0; i < attributesView.AttributesNamesColumn.Labels.Count; i++)
            {
                var attributeViewModel = viewModel.Atrribute(i);
                attributesView.AttributesNamesColumn.Labels[i].Text = attributeViewModel.AttributeName;
            }
            for (int i = 0; i < attributesView.AttributesValuesColumn.Labels.Count; i++)
            {
                var attributeViewModel = viewModel.Atrribute(i);
                attributesView.AttributesNamesColumn.Labels[i].Text = attributeViewModel.AttributeValue;
            }

            stackView.AddArrangedSubview(imageView);
            stackView.AddArrangedSubview(titleView);
            stackView.AddArrangedSubview(attributesView);
            stackView.Axis         = UILayoutConstraintAxis.Vertical;
            stackView.Distribution = UIStackViewDistribution.Fill;
            stackView.TranslatesAutoresizingMaskIntoConstraints = false;

            View.AddSubview(scrollView);
            scrollView.TranslatesAutoresizingMaskIntoConstraints = false;
            scrollView.AlwaysBounceVertical = true;
            scrollView.AddSubview(stackView);

            stackView.TopAnchor.ConstraintEqualTo(scrollView.TopAnchor).Active = true;
            stackView.HeightAnchor.ConstraintEqualTo(View.HeightAnchor).Active = true;
            stackView.WidthAnchor.ConstraintEqualTo(View.WidthAnchor).Active   = true;

            this.SetActiveNavigationItemTitle(viewModel.Title);

            View.SetNeedsLayout();
            View.LayoutIfNeeded();

            imageView.CustomImage = viewModel.ThumbnailImage(new CGSize(imageView.Bounds.Width, imageView.Bounds.Height));
        }