예제 #1
0
        public UnitConfigurationSelectionOption(
            string ClassName,
            string DetailsClassName,
            string OverlayClassName,
            UnitConfigurationLink UnitConfigurationLink,
            Faction Faction,
            UnitConfigurationRenderer Renderer,
            bool DisplayCount)
            : base(ClassName)
        {
            this.UnitConfigurationLink = UnitConfigurationLink;

            StackView = new UnitConfigurationStackView(
                UnitConfigurationLink.UnitConfiguration,
                Faction,
                Renderer,
                Class.GetAttributeWithDefault("unit-scale", 0),
                OverlayClassName,
                DisplayCount);
            StackView.Position = .5f * StackView.Size + new Vector2f(12, 12);
            StackView.Parent   = this;
            Value = StackView;

            _PointText                 = new Button(DetailsClassName);
            _PointText.Position        = new Vector2f(12, StackView.Size.Y + 16);
            _PointText.Parent          = this;
            _PointText.DisplayedString =
                UnitConfigurationLink.UnitConfiguration.GetPointValue(Faction.HalfPriceTrucks).ToString();
        }
        public void Add(UnitConfigurationLink UnitConfigurationLink)
        {
            if (_StackDuplicates)
            {
                var o =
                    _Items
                    .SelectMany(i => i)
                    .Cast <UnitConfigurationSelectionOption>()
                    .FirstOrDefault(i => i.UnitConfigurationLink == UnitConfigurationLink);
                if (o != null)
                {
                    o.StackView.Count++;
                    return;
                }
            }

            TableRow t = null;

            if (_Items.Count == 0 || _Items.Last().Count() >= _ItemWidth)
            {
                t = new TableRow(_RowClassName);
                _Items.Add(t);
            }
            else
            {
                t = _Items.Last();
            }

            var option =
                new UnitConfigurationSelectionOption(
                    _CellClassName,
                    _CellClassName + "-details",
                    _CellClassName + "-overlay",
                    UnitConfigurationLink,
                    _Faction,
                    _Renderer,
                    _StackDuplicates);

            option.OnClick      += HandleClick;
            option.OnRightClick += HandleRightClick;
            t.Add(option);
        }
        public void Remove(UnitConfigurationLink UnitConfigurationLink)
        {
            TableRow current = null;
            var      rows    = _Items.ToList();

            _Items.Clear();
            foreach (TableRow row in rows)
            {
                foreach (UnitConfigurationSelectionOption option in row)
                {
                    if (option.UnitConfigurationLink != UnitConfigurationLink ||
                        (_StackDuplicates && --option.StackView.Count > 0))
                    {
                        if (current == null || current.Count() >= _ItemWidth)
                        {
                            current = new TableRow(_RowClassName);
                            _Items.Add(current);
                        }
                        current.Add(option);
                    }
                }
            }
        }
예제 #4
0
 public bool Matches(UnitConfigurationLink Link)
 {
     return((Link.Faction == null || Faction == Link.Faction) && Parameters.Matches(Link.Constraints));
 }
 public bool Matches(UnitConfigurationLink Link)
 {
     return(Parameters.Matches(Link));
 }