Esempio n. 1
0
        public override void InsertInventoryItem(int id, IInventoryCellData cellData)
        {
            CellData[id] = cellData;
            IsDirty      = true;

            UpdateMask();
        }
Esempio n. 2
0
        public override bool CheckInsert(int id, IInventoryCellData cellData)
        {
            if (id < 0)
            {
                return(false);
            }
            var width  = cellData.Width;
            var height = cellData.Height;

            // check width
            if ((id % this.width) + (width - 1) >= this.width)
            {
                return(false);
            }

            // check height
            if (id + ((height - 1) * this.width) >= CellData.Length)
            {
                return(false);
            }

            for (var i = 0; i < width; i++)
            {
                for (var t = 0; t < height; t++)
                {
                    if (mask[id + i + (t * this.width)])
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Esempio n. 3
0
        protected virtual int?GetIndex(IInventoryCellView targetCell, IInventoryCellData effectCellData, CellCorner cellCorner)
        {
            var index = GetIndex(targetCell);

            // offset index
            int width  = effectCellData.Width;
            int height = effectCellData.Height;

            if (width % 2 == 0)
            {
                if ((cellCorner & CellCorner.Left) != CellCorner.None)
                {
                    index--;
                }
            }

            if (height % 2 == 0)
            {
                if ((cellCorner & CellCorner.Top) != CellCorner.None)
                {
                    index -= playerInventoryviewData.width;
                }
            }

            index -= (width - 1) / 2;
            index -= (height - 1) / 2 * playerInventoryviewData.width;
            return(index);
        }
 public override int?GetId(IInventoryCellData cellData)
 {
     for (var i = 0; i < CellData.Length; i++)
     {
         if (CellData[i] == cellData)
         {
             return(i);
         }
     }
     return(null);
 }
Esempio n. 5
0
        public override void OnDroped(bool isDroped)
        {
            if (!isDroped && originalId.HasValue)
            {
                // revert
                ApplyCell(itemViews[originalId.Value], originalId.Value, originalCellData);
            }

            originalId       = null;
            originalCellData = null;
        }
Esempio n. 6
0
        public override int?GetInsertableId(IInventoryCellData cellData)
        {
            for (var i = 0; i < mask.Length; i++)
            {
                if (!mask[i] && CheckInsert(i, cellData))
                {
                    return(i);
                }
            }

            return(null);
        }
Esempio n. 7
0
        public override void OnDroped(bool isDroped)
        {
            conditionTransform.gameObject.SetActive(false);
            condition.color = defaultColor;

            if (!isDroped && originalId.HasValue)
            {
                // revert
                ApplyCell(itemViews[originalId.Value], originalId.Value, originalCellData);
            }

            originalId       = null;
            originalCellData = null;
        }
 public override bool CheckInsert(int id, IInventoryCellData cellData)
 {
     // if (cellData is PlayerInventoryCellData inventoryCellData && inventoryCellData.item is Equipment equipment)
     // {
     //     var equipCellData = CellData[id] as PlayerEquipmentCellData;
     //     Debug.LogError(equipment.equipmentType);
     //     // Debug.LogError(GetType().ToString() + "drop" + "---" + equipCellData.slot + ":" + equipment.equipmentType);
     //     if (CheckCanEquip(equipCellData.slot, equipment.equipmentType))
     //     {
     //         Debug.LogError(GetType().ToString() + "Equip");
     //         return true;
     //     }
     // }
     return(false);
 }
Esempio n. 9
0
 public void HandleEvent(int key, params object[] args)
 {
     switch (key)
     {
     case (int)EventID.OnAddInventory:
         if (args == null || args.Length <= 0)
         {
             return;
         }
         IInventoryCellData data = (IInventoryCellData)args[0];
         var insertID            = viewData.GetInsertableId(data);
         if (insertID.HasValue)
         {
             itemViews[insertID.Value].Apply(data);
             viewData.InsertInventoryItem(insertID.Value, data);
         }
         break;
     }
 }
Esempio n. 10
0
        public override bool OnPick(IInventoryCellView targetCell)
        {
            if (targetCell?.CellData == null)
            {
                return(false);
            }

            var id = viewData.GetId(targetCell.CellData);

            if (id.HasValue)
            {
                originalId       = id;
                originalCellData = targetCell.CellData;

                ApplyCell(itemViews[id.Value], id.Value, null);
                return(true);
            }


            return(false);
        }
 public abstract int?GetId(IInventoryCellData cellData);
 public abstract bool CheckInsert(int id, IInventoryCellData cellData);
 public abstract void InsertInventoryItem(int id, IInventoryCellData cellData);
Esempio n. 14
0
 protected void ApplyCell(IInventoryCellView cellView, int cellIndex, IInventoryCellData cellData)
 {
     cellView.Apply(cellData);
     viewData.InsertInventoryItem(cellIndex, cellData);
 }
Esempio n. 15
0
 public void Apply(IInventoryCellData cellData)
 {
     CellData = cellData;
     OnApply();
 }
Esempio n. 16
0
 public override int?GetInsertableId(IInventoryCellData cellData)
 {
     return(null);
 }
Esempio n. 17
0
        public override bool OnDrop(IInventoryCellView targetCell, IInventoryCellView effectCell)
        {
            if (!itemViews.Any(item => item == targetCell))
            {
                return(false);
            }
            // Debug.LogError(GetType().ToString() + "OnDrop" + (effectCell.CellData.GetType()));
            // check target;
            var index = GetIndex(targetCell, effectCell.CellData, cellCorner);

            if (!index.HasValue || index.Value < 0)
            {
                return(false);
            }

            if (!viewData.CheckInsert(index.Value, effectCell.CellData))
            {
                if (targetCell.CellData == null)
                {
                    return(false);
                }

                if (targetCell.CellData is PlayerInventoryCellData) //如果目标也是道具栏位
                {
                    int?targetID = viewData.GetId(targetCell.CellData);
                    // Debug.LogError(index.Value + "---" + targetID.Value);
                    if (targetCell.CellData.size == effectCell.CellData.size)//大小一致 交换 并且完全盖住的时候
                    {
                        if (originalId.HasValue && originalCellData != null)
                        {
                            itemViews[targetID.Value].Apply(targetCell.CellData);
                            itemViews[originalId.Value].Apply(originalCellData);
                            viewData.InsertInventoryItem(originalId.Value, originalCellData);
                            playerInventoryviewData.ExchangeInventoryItem(targetID.Value, originalId.Value);
                            Debug.LogError("Exchange");
                            //ReApply();
                            originalId       = null;
                            originalCellData = null;
                            return(true);
                        }
                    }
                }

                //     // check free space in case
                //     if (targetCell.CellData != null && targetCell.CellData is VariableInventorySystem.IStandardCaseCellData caseData)
                //     {
                //         var id = caseData.CaseData.GetInsertableId(effectCell.CellData);
                //         if (id.HasValue)
                //         {
                //             caseData.CaseData.InsertInventoryItem(id.Value, effectCell.CellData);
                //             originalId = null;
                //             originalCellData = null;
                //             return true;
                //         }
                //     }

                return(false);
            }

            var newCellData = effectCell.CellData;

            if (effectCell.CellData is PlayerEquipmentCellData equipmentCellData)
            {
                newCellData = new PlayerInventoryCellData(equipmentCellData.item);
                Debug.LogError(newCellData.GetType());
            }

            // place
            ApplyCell(itemViews[index.Value], index.Value, newCellData);

            originalId       = null;
            originalCellData = null;
            return(true);
        }
 public abstract int?GetInsertableId(IInventoryCellData cellData);