Show
Ignore:
Timestamp:
06/27/09 14:39:04 (14 months ago)
Author:
ibboard
Message:

Re #90: Stop new units showing up twice

  • Hand all of unit adding/removing down to category
  • Refactor out OnFailedRequirement method in Army
  • Make Army listen to and propogate FailedRequirement events from Units
  • Add OnUnitAdded/Removed method to ArmyCategory that takes list of failures
  • Remove direct reference to Army from Unit and go via ArmyCategory instead
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • IBBoard.WarFoundry.API/trunk/api/Objects/ArmyCategory.cs

    r143 r146  
    2323        public event ObjectAddDelegate UnitAdded; 
    2424        public event ObjectRemoveDelegate UnitRemoved; 
     25        public event FailedUnitRequirementDelegate FailedRequirement; 
    2526 
    2627        public ArmyCategory(Army army, Category cat) : base() 
     
    7576            unitTypes[unit.UnitType.ID] = (int)unitTypeCount + 1; 
    7677            TotalPoints+= unit.PointsValue; 
    77             OnUnitAdded(unit); 
     78            OnUnitAdded(unit, failedReqs); 
    7879        } 
    7980 
    8081        internal void RemoveUnit(Unit unit) 
    8182        { 
     83            List<FailedUnitRequirement> failedReqs = ParentArmy.CanRemoveUnit(unit); 
    8284            units.Remove(unit); 
    8385            unitTypes[unit.UnitType.ID] = ((int)unitTypes[unit.UnitType.ID])-1; 
    8486            TotalPoints-= unit.PointsValue; 
    8587            unit.PointsValueChanged-= PointsValueChangedMethod; 
    86             OnUnitRemoved(unit); 
     88            OnUnitRemoved(unit, failedReqs); 
    8789        } 
    8890 
     
    126128        } 
    127129 
    128         private void OnUnitAdded(Unit unit) 
     130        protected void OnUnitAdded(Unit unit) 
    129131        { 
    130             if (UnitAdded!=null) 
     132            OnUnitAdded(unit, null); 
     133        } 
     134 
     135        protected void OnUnitAdded(Unit unit, List<FailedUnitRequirement> failedReqs) 
     136        { 
     137            if (UnitAdded != null) 
    131138            { 
    132139                UnitAdded(unit); 
    133140            } 
     141 
     142            if (FailedRequirement != null && failedReqs != null && failedReqs.Count > 0) 
     143            { 
     144                FailedRequirement(failedReqs); 
     145            } 
    134146        } 
    135147 
    136         private void OnUnitRemoved(Unit unit) 
     148        protected void OnUnitRemoved(Unit unit) 
    137149        { 
    138             if (UnitRemoved!=null) 
     150            OnUnitRemoved(unit, null); 
     151        } 
     152 
     153        protected void OnUnitRemoved(Unit unit, List<FailedUnitRequirement> failedReqs) 
     154        { 
     155            if (UnitRemoved != null) 
    139156            { 
    140157                UnitRemoved(unit); 
     158            } 
     159 
     160            if (FailedRequirement != null && failedReqs != null && failedReqs.Count > 0) 
     161            { 
     162                FailedRequirement(failedReqs); 
    141163            } 
    142164        }