CocoDressItemConflictData GetDressConflictData(CocoDressItemHolder newItemHolder, CocoDressItemHolder oldItemHolder)
        {
            if (newItemHolder.IsCoverLayerConflicted(oldItemHolder) || newItemHolder == oldItemHolder)
            {
                CocoDressItemConflictData conflictData = new CocoDressItemConflictData();
                conflictData.itemHolder = oldItemHolder;
                return(conflictData);
            }

            return(null);
        }
        List <CocoDressItemConflictData> GetDressConflictDatas(CocoDressItemHolder itemHolder)
        {
            List <CocoDressItemConflictData> conflictDatas = new List <CocoDressItemConflictData> ();

            if (itemHolder != null)
            {
                m_CurrDressModelSetDic.ForEach(modelSet => {
                    CocoDressItemConflictData conflictData = GetDressConflictData(itemHolder, modelSet.ItemHolder);
                    if (conflictData != null)
                    {
                        conflictDatas.Add(conflictData);
                    }
                });
            }

            return(conflictDatas);
        }
        List <CocoDressItemConflictData> GetDressConflictDatas(CocoDressItemHolder itemHolder, List <string> checkedItemIds)
        {
            List <CocoDressItemConflictData> conflictDatas = new List <CocoDressItemConflictData> ();

            if (itemHolder != null && checkedItemIds != null)
            {
                checkedItemIds.ForEach(itemId => {
                    CocoDressItemHolder checkedItemHolder  = m_ItemHolderDic.GetValue(itemId);
                    CocoDressItemConflictData conflictData = GetDressConflictData(itemHolder, checkedItemHolder);
                    if (conflictData != null)
                    {
                        conflictDatas.Add(conflictData);
                    }
                });
            }

            return(conflictDatas);
        }
        public List <string> PrepareRemoveDressItems(List <string> itemIds, out List <CocoDressItemConflictData> conflictDatas)
        {
            // make will removed items as conflict datas
            Dictionary <string, CocoDressItemConflictData> itemConflictDataDic = new Dictionary <string, CocoDressItemConflictData> ();

            itemIds.ForEach(itemId => {
                if (!itemConflictDataDic.ContainsKey(itemId))
                {
                    CocoDressItemHolder itemHolder = m_ItemHolderDic.GetValue(itemId);
                    if (itemHolder != null)
                    {
                        CocoDressItemConflictData conflictData = new CocoDressItemConflictData();
                        conflictData.itemHolder = itemHolder;
                        itemConflictDataDic.Add(itemId, conflictData);
                    }
                    else
                    {
                        Debug.LogErrorFormat("{0}->PrepareAddDressItems: item [{1}] NOT exists in asset config !", GetType().Name, itemId);
                    }
                }
            });

            // find should added items
            List <string> shouldAddedItemIds = new List <string> ();

            // curr items
            List <string> currItemIds = new List <string> ();

            m_CurrDressModelSetDic.Keys.ForEach(itemId => {
                if (!itemConflictDataDic.ContainsKey(itemId))
                {
                    currItemIds.Add(itemId);
                }
            });

            // try add last items
            for (int i = m_SortedLastCovers.Count - 1; i >= 0; i--)
            {
                CocoDressItemHolder lastItemHolder = m_LastCoverItemHolderDic [m_SortedLastCovers [i]];
                if (itemConflictDataDic.ContainsKey(lastItemHolder.id))
                {
                    // should removed, skip it
                    continue;
                }

                TryFillUpDressItem(lastItemHolder, shouldAddedItemIds, currItemIds);
            }

            // try add basic items
            for (int i = m_BasicItemIds.Count - 1; i >= 0; i--)
            {
                CocoDressItemHolder basicItemHolder = m_ItemHolderDic.GetValue(m_BasicItemIds [i]);
                TryFillUpDressItem(basicItemHolder, shouldAddedItemIds, currItemIds, true);
            }

            // try add will remove items (if not other choice)
            foreach (var itemId in itemIds)
            {
                CocoDressItemHolder willRemoveItemHolder = m_ItemHolderDic.GetValue(itemId);
                TryFillUpDressItem(willRemoveItemHolder, shouldAddedItemIds, currItemIds, true);
            }

            // if should add, don't remove them
            HashSet <string> shouldAddedItemIdSet = new HashSet <string> (shouldAddedItemIds);

            shouldAddedItemIdSet.ForEach(itemId => {
                if (itemConflictDataDic.ContainsKey(itemId))
                {
                    itemConflictDataDic.Remove(itemId);
                    shouldAddedItemIds.Remove(itemId);
                }
            });

            //string str = "PrepareRemoveDressItems should add: ";
            //shouldAddedItemIds.ForEach (itemId => str += itemId + ", ");
            //str += " conflict: ";
            //itemConflictDataDic.Keys.ForEach (itemId => str += itemId + ", ");
            //Debug.LogError (str);

            conflictDatas = new List <CocoDressItemConflictData> (itemConflictDataDic.Values);
            return(shouldAddedItemIds);
        }
 void PorcessConflictData(CocoDressItemConflictData conflctData)
 {
     RemoveDressModelSet(conflctData.itemHolder.id);
 }