Пример #1
0
        protected virtual int?GetIndex(IVariableInventoryCell stareCell, IVariableInventoryCellData effectCellData, CellCorner cellCorner)
        {
            var index = GetIndex(stareCell);

            // offset index
            var(width, height) = GetRotateSize(effectCellData);
            if (width % 2 == 0)
            {
                if ((cellCorner & CellCorner.Left) != CellCorner.None)
                {
                    index--;
                }
            }

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

            index -= (width - 1) / 2;
            index -= (height - 1) / 2 * StashData.CapacityWidth;
            return(index);
        }
Пример #2
0
        public virtual void OnCellExit(IVariableInventoryCell stareCell)
        {
            conditionTransform.gameObject.SetActive(false);
            condition.color = defaultColor;

            cellCorner = CellCorner.None;

            (stareCell as StandardCell).SetHighLight(false);
        }
Пример #3
0
        public virtual void OnPrePick(IVariableInventoryCell stareCell)
        {
            if (stareCell?.CellData == null)
            {
                return;
            }

            var(width, height)           = GetRotateSize(stareCell.CellData);
            conditionTransform.sizeDelta = new Vector2(stareCell.DefaultCellSize.x * width, stareCell.DefaultCellSize.y * height);
        }
Пример #4
0
        protected virtual int?GetIndex(IVariableInventoryCell stareCell)
        {
            var index = (int?)null;

            for (var i = 0; i < itemViews.Length; i++)
            {
                if (itemViews[i] == stareCell)
                {
                    index = i;
                }
            }

            return(index);
        }
Пример #5
0
        public virtual void OnDrag(IVariableInventoryCell stareCell, IVariableInventoryCell effectCell, PointerEventData pointerEventData)
        {
            if (stareCell == null)
            {
                return;
            }

            // auto scroll
            var pointerViewportPosition = GetLocalPosition(scrollRect.viewport, pointerEventData.position, pointerEventData.enterEventCamera);

            if (pointerViewportPosition.y < scrollRect.viewport.rect.min.y + holdScrollPadding)
            {
                var scrollValue = scrollRect.verticalNormalizedPosition * scrollRect.viewport.rect.height;
                scrollValue -= holdScrollRate;
                scrollRect.verticalNormalizedPosition = Mathf.Clamp01(scrollValue / scrollRect.viewport.rect.height);
            }

            if (pointerViewportPosition.y > scrollRect.viewport.rect.max.y - holdScrollPadding)
            {
                var scrollValue = scrollRect.verticalNormalizedPosition * scrollRect.viewport.rect.height;
                scrollValue += holdScrollRate;
                scrollRect.verticalNormalizedPosition = Mathf.Clamp01(scrollValue / scrollRect.viewport.rect.height);
            }

            // depends on anchor
            var pointerLocalPosition = GetLocalPosition(stareCell.RectTransform, pointerEventData.position, pointerEventData.enterEventCamera);
            var anchor           = new Vector2(stareCell.DefaultCellSize.x * 0.5f, -stareCell.DefaultCellSize.y * 0.5f);
            var anchoredPosition = pointerLocalPosition + anchor;

            conditionOffset = new Vector3(
                Mathf.Floor(anchoredPosition.x / stareCell.DefaultCellSize.x) * stareCell.DefaultCellSize.x,
                Mathf.Ceil(anchoredPosition.y / stareCell.DefaultCellSize.y) * stareCell.DefaultCellSize.y);

            // cell corner
            var prevCorner = cellCorner;

            cellCorner = GetCorner((new Vector2(anchoredPosition.x % stareCell.DefaultCellSize.x, anchoredPosition.y % stareCell.DefaultCellSize.y) - anchor) * 0.5f);

            // shift the position only even number size
            var(width, height) = GetRotateSize(effectCell.CellData);
            var evenNumberOffset = GetEvenNumberOffset(width, height, stareCell.DefaultCellSize.x * 0.5f, stareCell.DefaultCellSize.y * 0.5f);

            conditionTransform.position = stareCell.RectTransform.position + ((conditionOffset + evenNumberOffset) * stareCell.RectTransform.lossyScale.x);

            // update condition
            if (prevCorner != cellCorner)
            {
                UpdateCondition(stareCell, effectCell);
            }
        }
Пример #6
0
        public virtual void OnSwitchRotate(IVariableInventoryCell stareCell, IVariableInventoryCell effectCell)
        {
            if (stareCell == null)
            {
                return;
            }

            var(width, height)           = GetRotateSize(effectCell.CellData);
            conditionTransform.sizeDelta = new Vector2(effectCell.DefaultCellSize.x * width, effectCell.DefaultCellSize.y * height);

            var evenNumberOffset = GetEvenNumberOffset(width, height, stareCell.DefaultCellSize.x * 0.5f, stareCell.DefaultCellSize.y * 0.5f);

            conditionTransform.position = stareCell.RectTransform.position + ((conditionOffset + evenNumberOffset) * stareCell.RectTransform.lossyScale.x);

            UpdateCondition(stareCell, effectCell);
        }
Пример #7
0
        protected virtual void UpdateCondition(IVariableInventoryCell stareCell, IVariableInventoryCell effectCell)
        {
            var index = GetIndex(stareCell, effectCell.CellData, cellCorner);

            if ((index.HasValue && StashData.CheckInsert(index.Value, effectCell.CellData)))
            {
                condition.color = positiveColor;
            }
            else
            {
                // check free space in case
                if (stareCell.CellData != null &&
                    stareCell.CellData is VariableInventorySystem.IStandardCaseCellData caseData &&
                    caseData.CaseData.GetInsertableId(effectCell.CellData).HasValue)
                {
                    condition.color = positiveColor;
                }
Пример #8
0
        public virtual bool OnDrop(IVariableInventoryCell stareCell, IVariableInventoryCell effectCell)
        {
            if (!itemViews.Any(item => item == stareCell))
            {
                return(false);
            }

            // check target;
            var index = GetIndex(stareCell, effectCell.CellData, cellCorner);

            if (!index.HasValue)
            {
                return(false);
            }

            if (!StashData.CheckInsert(index.Value, effectCell.CellData))
            {
                // check free space in case
                if (stareCell.CellData != null && stareCell.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);
            }

            // place
            StashData.InsertInventoryItem(index.Value, effectCell.CellData);
            itemViews[index.Value].Apply(effectCell.CellData);

            originalId       = null;
            originalCellData = null;
            return(true);
        }
Пример #9
0
        public virtual bool OnPick(IVariableInventoryCell stareCell)
        {
            if (stareCell?.CellData == null)
            {
                return(false);
            }

            var id = StashData.GetId(stareCell.CellData);

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

                itemViews[id.Value].Apply(null);
                StashData.InsertInventoryItem(id.Value, null);
                return(true);
            }

            return(false);
        }
Пример #10
0
        protected override void OnCellClick(IVariableInventoryCell cell)
        {
            if (cell.CellData is IStandardCaseCellData caseData)
            {
                if (popupList.Contains(caseData))
                {
                    return;
                }

                popupList.Add(caseData);

                var standardCaseViewPopup = Instantiate(casePopupPrefab, caseParent).GetComponent <StandardCaseViewPopup>();
                AddInventoryView(standardCaseViewPopup.StandardCaseView);

                standardCaseViewPopup.Open(
                    caseData,
                    () =>
                {
                    RemoveInventoryView(standardCaseViewPopup.StandardCaseView);
                    Destroy(standardCaseViewPopup.gameObject);
                    popupList.Remove(caseData);
                });
            }
        }
Пример #11
0
 public virtual void OnCellEnter(IVariableInventoryCell stareCell, IVariableInventoryCell effectCell)
 {
     conditionTransform.gameObject.SetActive(effectCell?.CellData != null);
     (stareCell as StandardCell).SetHighLight(true);
 }
 public virtual void Initialize()
 {
     effectCell = Instantiate(CellPrefab, EffectCellParent).GetComponent <IVariableInventoryCell>();
     effectCell.RectTransform.gameObject.SetActive(false);
     effectCell.SetSelectable(false);
 }