protected void SetRootNodes(IEnumerable <TreeViewItemViewModel> source, string defaultText = "")
 {
     _currentRootNodesViewModel = source.ToList();
     if (_currentRootNodesViewModel.Count == 0 && !string.IsNullOrEmpty(defaultText))
     {
         _currentRootNodesViewModel.Add(new TextItemViewModel(_imageSourceFactory, null, defaultText));
     }
     _rootNodes.Clear();
     _currentRootNodesViewModel.ForAll(x => _rootNodes.Add(x));
 }
Ejemplo n.º 2
0
        public static ArrayDiffsResult <T> BuildArrayDiffsForLargeArrays <T>(
            IList <T> leftList,
            IList <T> rightList,
            IEqualityComparer <T> comparer)
        {
            comparer = comparer ?? EqualityComparer <T> .Default;

            var result = new ArrayDiffsResult <T>(
                new List <T>(),
                new List <T>(),
                new List <LeftRightItemPair <T> >()
                );

            // Build both map from item to item index.
            var leftMap = new Dictionary <T, int>(leftList.Count, comparer);

            leftList.ForAll((index, x) => leftMap.Add(x, index));

            var rightMap = new Dictionary <T, int>(leftList.Count, comparer);

            rightList.ForAll((index, x) => rightMap.Add(x, index));

            // Append left items, either unique or common with right items
            foreach (var left in leftList)
            {
                var rightIndex = MapIndexOf(rightMap, left);
                if (rightIndex >= 0)
                {
                    result.CommonItems.Add(new LeftRightItemPair <T>(left, rightList[rightIndex]));
                }
                else
                {
                    result.LeftOnlyItems.Add(left);
                }
            }

            // Append right items (unique ones only)
            foreach (var right in rightList)
            {
                var leftIndex = MapIndexOf(leftMap, right);
                if (leftIndex < 0)
                {
                    result.RightOnlyItems.Add(right);
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
    public void SetPartCardGray(IList <int> part, bool isGray)
    {
        var card = default(CardShowInfo);

        part.ForAll
            (i =>
        {
            var ti = i;
            for (var j = 0; j <= ti; j++)
            {
                if (transform.GetChild(j).GetComponent <CardShowInfo>().IsDead)
                {
                    ti++;
                }
            }
            card        = transform.GetChild(ti).GetComponent <CardShowInfo>();
            card.IsGray = isGray;
        }
            );
    }
Ejemplo n.º 4
0
        /// <summary>
        /// Repositions all the Unit elements in the formation designated by the Cmd.
        /// Called when 1) a fleet is first formed, 2) the desired formation has changed, 3) the HQ Element has changed,
        /// or 4) when another large fleet joins this one.
        /// <remarks>Repositioning is accomplished by calling Cmd.PositionElementInFormation().</remarks>
        /// </summary>
        /// <param name="allElements">All elements.</param>
        public void RepositionAllElementsInFormation(IList<IUnitElement> allElements) {
            Formation formation = _unitCmd.UnitFormation;
            if (formation != _currentFormation) {
                _occupiedStationSlotLookup.Clear();
                float formationRadius;
                _availableStationSlots = GenerateFormationSlotInfo(formation, _unitCmd.transform, out formationRadius);
                //D.Log(ShowDebugLog, "{0} generated {1} {2}s for Formation {3} => {4}.", DebugName, _availableStationSlots.Count, typeof(FormationStationSlotInfo).Name, formation.GetValueName(), _availableStationSlots.Concatenate());
                _unitCmd.UnitMaxFormationRadius = formationRadius;
                _currentFormation = formation;
            }
            else {
                ReturnAllOccupiedStationSlotsToAvailable();
            }

            int hqCount = Constants.Zero;
            allElements.ForAll(e => {
                if (e.IsHQ) {
                    hqCount++;
                }
                AddAndPositionElement(e);
            });
            D.AssertEqual(Constants.One, hqCount);
        }
Ejemplo n.º 5
0
    /// <summary>
    /// Detaches one or more sensors from this command's SensorRangeMonitors.
    /// Note: Sensors are part of a Unit's elements but the monitors they attach to
    /// are children of the Command. Thus sensor range is always measured from
    /// the Command, not from the element.
    /// </summary>
    /// <param name="sensors">The sensors.</param>
    private void DetachSensorsFromMonitors(IList<Sensor> sensors) {
        sensors.ForAll(sensor => {
            var monitor = sensor.RangeMonitor;
            bool isRangeMonitorStillInUse = monitor.Remove(sensor);

            if (!isRangeMonitorStillInUse) {
                monitor.enemyTargetsInRange -= EnemyTargetsInSensorRangeChangedEventHandler;
                monitor.Reset();    // OPTIMIZE either reset or destroy, not both
                SensorRangeMonitors.Remove(monitor);
                //D.Log(ShowDebugLog, "{0} is destroying unused {1} as a result of removing {2}.", DebugName, typeof(SensorRangeMonitor).Name, sensor.Name);
                GameUtility.DestroyIfNotNullOrAlreadyDestroyed(monitor);
            }
        });
    }
Ejemplo n.º 6
0
 /// <summary>
 /// Attaches one or more sensors to this command's SensorRangeMonitors.
 /// Note: Sensors are part of a Unit's elements but the monitors they attach to
 /// are children of the Command. Thus sensor range is always measured from
 /// the Command, not from the element.
 /// </summary>
 /// <param name="sensors">The sensors.</param>
 private void AttachSensorsToMonitors(IList<Sensor> sensors) {
     sensors.ForAll(sensor => {
         var monitor = UnitFactory.Instance.AttachSensorToCmdsMonitor(sensor, this);
         if (!SensorRangeMonitors.Contains(monitor)) {
             // only need to record and setup range monitors once. The same monitor can have more than 1 sensor
             SensorRangeMonitors.Add(monitor);
             monitor.enemyTargetsInRange += EnemyTargetsInSensorRangeChangedEventHandler;
         }
     });
 }
 protected void SetRootNodes(IEnumerable<TreeViewItemViewModel> source, string defaultText = "")
 {
     _currentRootNodesViewModel = source.ToList();
       if (_currentRootNodesViewModel.Count == 0 && !string.IsNullOrEmpty(defaultText)) {
     _currentRootNodesViewModel.Add(new TextItemViewModel(_imageSourceFactory, null, defaultText));
       }
       _rootNodes.Clear();
       _currentRootNodesViewModel.ForAll(x => _rootNodes.Add(x));
 }