Ejemplo n.º 1
0
        public void RefreshItem(int index)
        {
            if (index >= this.itemList.Count || index < 0)
            {
                return;
            }

            ListView.ListItem listItem = this.itemList[index];
            this.ShowItem(listItem, true);
            float num      = Mathf.Abs(listItem.endPos - listItem.startPos);
            float itemSize = this.GetItemSize(listItem);

            listItem.endPos = this.m_isPositive ? (listItem.startPos + itemSize) : (listItem.startPos - itemSize);
            float num2 = itemSize - num;

            this.totalSize += num2;
            this.SetContainerSize(this.totalSize);
            for (int i = index + 1; i < this.itemList.Count; i++)
            {
                ListView.ListItem listItem2 = this.itemList[i];
                listItem2.startPos = this.m_isPositive ? (listItem2.startPos + num2) : (listItem2.startPos - num2);
                listItem2.endPos   = this.m_isPositive ? (listItem2.endPos + num2) : (listItem2.endPos - num2);
                if (listItem2.go != null)
                {
                    this.UpdateItemGameObjectPosition(listItem2);
                }

                this.ShowItem(listItem2, false);
            }
        }
Ejemplo n.º 2
0
        public void RemoveAt(int index)
        {
            if (index >= this.itemList.Count || index < 0)
            {
                return;
            }

            ListView.ListItem listItem = this.itemList[index];
            float             num      = Mathf.Abs(listItem.endPos - listItem.startPos) + this.spacing;

            this.totalSize -= num;
            this.SetContainerSize(this.totalSize);
            this.OnItemLeave(listItem);
            for (int i = index + 1; i < this.itemList.Count; i++)
            {
                ListView.ListItem listItem2 = this.itemList[i];
                listItem2.index--;
                listItem2.startPos = this.m_isPositive ? (listItem2.startPos - num) : (listItem2.startPos + num);
                listItem2.endPos   = this.m_isPositive ? (listItem2.endPos - num) : (listItem2.endPos + num);
                if (listItem2.go != null)
                {
                    this.UpdateItemGameObjectPosition(listItem2);
                    this.ShowItem(listItem2);
                }
                else
                {
                    this.ShowItem(listItem2, true);
                }
            }

            this.itemList.RemoveAt(index);
        }
Ejemplo n.º 3
0
        public void Clear()
        {
            for (int i = 0; i < this.itemList.Count; i++)
            {
                ListView.ListItem listItem = this.itemList[i];
                if (listItem.go != null)
                {
                    m_funcTab.ItemRemove?.Invoke(listItem);
                    PrefabManager.Instance.UnloadAsset(listItem.go);
                    listItem.go = null;
                }
            }

            this.prefabSizeMap.Clear();
            this.containerLastPos = 0f;
            this.itemList.Clear();
            this.totalSize = 0f;
            this.SetContainerSize(0f);
            ScrollRect component = base.GetComponent <ScrollRect>();

            if (component != null)
            {
                component.StopMovement();
            }
        }
Ejemplo n.º 4
0
        private void UpdateItemGameObjectPosition(ListView.ListItem item)
        {
            Vector3       v         = (!this.isVertical) ? new Vector2(item.startPos, 0f) : new Vector2(0f, item.startPos);
            RectTransform component = item.go.GetComponent <RectTransform>();

            component.anchoredPosition = v;
            component.localScale       = Vector3.one;
        }
Ejemplo n.º 5
0
        private string GetItemTag(ListView.ListItem item)
        {
            if (m_funcTab != null && m_funcTab.GetItemTag != null)
            {
                return(m_funcTab.GetItemTag(item));
            }

            return(string.Empty);
        }
Ejemplo n.º 6
0
        private string GetItemPrefabName(ListView.ListItem item)
        {
            if (m_funcTab != null && m_funcTab.GetItemPrefabName != null)
            {
                return(m_funcTab.GetItemPrefabName(item));
            }

            return(this.defaultPrefabName);
        }
Ejemplo n.º 7
0
        public void Insert(int index)
        {
            if (index > this.itemList.Count || index < 0)
            {
                return;
            }

            ListView.ListItem listItem = new ListView.ListItem();
            listItem.index      = index;
            listItem.prefabName = this.GetItemPrefabName(listItem);
            listItem.tag        = this.GetItemTag(listItem);
            if (index != 0)
            {
                if (m_isPositive)
                {
                    listItem.startPos = (this.itemList[index - 1].endPos + this.spacing);
                }
                else
                {
                    listItem.startPos = (this.itemList[index - 1].endPos - this.spacing);
                }
            }
            else
            {
                if (m_isPositive)
                {
                    listItem.startPos = this.offset;
                }
                else
                {
                    listItem.startPos = -this.offset;
                }
            }

            float itemSize = this.GetItemSize(listItem);

            listItem.endPos = this.m_isPositive ? (listItem.startPos + itemSize) : (listItem.startPos - itemSize);
            this.itemList.Insert(index, listItem);
            this.ShowItem(listItem, false);
            this.totalSize += itemSize;
            this.SetContainerSize(this.totalSize);
            for (int i = index + 1; i < this.itemList.Count; i++)
            {
                listItem = this.itemList[i];
                listItem.index++;
                listItem.startPos = this.m_isPositive ? (listItem.startPos + itemSize) : (listItem.startPos - itemSize);
                listItem.endPos   = this.m_isPositive ? (listItem.endPos + itemSize) : (listItem.endPos - itemSize);
                if (listItem.go != null)
                {
                    this.UpdateItemGameObjectPosition(listItem);
                }

                this.ShowItem(listItem, false);
            }
        }
Ejemplo n.º 8
0
 private void OnItemLeave(ListView.ListItem item)
 {
     if (item.go == null)
     {
         return;
     }
     RecycleItem(item);
     //CoreUtils.assetService.Destroy(item.go);
     //item.go = null;
     //item.isInit = false;
 }
Ejemplo n.º 9
0
        public void ShowContentAt(float pos)
        {
            this.SetViewRect(pos);
            for (int i = 0; i < this.itemList.Count; i++)
            {
                ListView.ListItem item = this.itemList[i];
                this.ShowItem(item, false);
            }

            this.containerLastPos = pos;
        }
Ejemplo n.º 10
0
        private bool ShowItem(ListView.ListItem item, bool force = false)
        {
            if (this.ItemVisible(item))
            {
                this.OnItemEnter(item, force);
                return(true);
            }

            this.OnItemLeave(item);
            return(false);
        }
Ejemplo n.º 11
0
 public void RecycleItem(ListView.ListItem item)
 {
     if (!mItemObjectDict.ContainsKey(item.go))
     {
         mItemObjectDict[item.go] = item.data;
     }
     m_funcTab.ItemRemove?.Invoke(item);
     item.data = null;
     item.go.SetActive(false);
     this.mItemPoolDict[item.prefabName].Add(item.go);
     item.go = null;
 }
Ejemplo n.º 12
0
        private float GetItemSize(ListView.ListItem item)
        {
            if (m_funcTab != null && m_funcTab.GetItemSize != null)
            {
                return(m_funcTab.GetItemSize(item));
            }

            if (item.startPos != 0 || item.endPos != 0)
            {
                return(Mathf.Abs(item.startPos - item.endPos));
            }

            return(this.prefabSizeMap[item.prefabName]);
        }
Ejemplo n.º 13
0
        public void FillContent(int listLength)
        {
            int count = this.itemList.Count;

            this.totalSize = ((!this.isVertical) ? this.offset : (-this.offset));
            for (int i = 0; i < listLength; i++)
            {
                ListView.ListItem listItem;
                if (i < count)
                {
                    listItem = this.itemList[i];
                    this.OnItemLeave(listItem);
                }
                else
                {
                    listItem = new ListView.ListItem();
                    this.itemList.Add(listItem);
                }

                listItem.index      = i;
                listItem.prefabName = this.GetItemPrefabName(listItem);
                listItem.tag        = this.GetItemTag(listItem);
                float itemSize = this.GetItemSize(listItem);
                if (this.m_isPositive)
                {
                    listItem.startPos = this.totalSize;
                    listItem.endPos   = this.totalSize + itemSize;
                    this.totalSize   += (itemSize + this.spacing);
                }
                else
                {
                    listItem.startPos = this.totalSize;
                    listItem.endPos   = this.totalSize - itemSize;
                    this.totalSize   += (-(itemSize + this.spacing));
                }
            }

            for (int j = count - 1; j >= listLength; j--)
            {
                this.OnItemLeave(this.itemList[j]);
                this.itemList.RemoveAt(j);
            }

            this.totalSize = Mathf.Abs(this.totalSize);
            this.SetContainerSize(this.totalSize);
            this.SetContainerPos(this.containerLastPos);
            this.ShowContentAt(this.containerLastPos);
        }
Ejemplo n.º 14
0
        public void ScrollList2IdxCenter(int index)
        {
            if (index >= this.itemList.Count || index < 0)
            {
                return;
            }

            float num = -this.itemList[index].startPos;

            ListView.ListItem item          = this.itemList[index];
            float             itemSize      = this.GetItemSize(item);
            float             containerSize = this.GetContainerSize();

            if (m_isPositive)
            {
                if (this.itemList[index].startPos < this.viewSize / 2f)
                {
                    num = 0f;
                }
                else if (this.itemList[index].startPos > containerSize - this.viewSize / 2f)
                {
                    num = this.viewSize - containerSize;
                }
                else
                {
                    num = -this.itemList[index].startPos + this.viewSize / 2f - itemSize / 2f;
                }
            }
            else
            {
                if (this.itemList[index].startPos > -this.viewSize / 2f)
                {
                    num = 0f;
                }
                else if (this.itemList[index].startPos < -(containerSize - this.viewSize / 2f))
                {
                    num = -this.viewSize + containerSize;
                }
                else
                {
                    num = -this.itemList[index].startPos - this.viewSize / 2f + itemSize / 2f;
                }
            }

            this.SetContainerPos(num);
            this.ShowContentAt(num);
        }
Ejemplo n.º 15
0
        private bool ItemVisible(ListView.ListItem item)
        {
            if (m_isPositive)
            {
                if (item.endPos < this.viewStartPos || item.startPos > this.viewEndPos)
                {
                    return(false);
                }
            }
            else
            {
                if (item.endPos > this.viewStartPos || item.startPos < this.viewEndPos)
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 16
0
        public void RefreshAndRestPos(int count = 0)
        {
            for (int i = 0; i < this.itemList.Count; i++)
            {
                ListView.ListItem listItem = this.itemList[i];
                if (listItem.go != null)
                {
                    RecycleItem(listItem);
                }
            }

            this.itemList.Clear();
            this.containerLastPos = 0f;
            this.totalSize        = 0f;
            this.SetContainerSize(0f);
            ScrollRect component = base.GetComponent <ScrollRect>();

            if (component != null)
            {
                component.StopMovement();
            }

            FillContent(count);
        }
Ejemplo n.º 17
0
        private void OnItemEnter(ListView.ListItem item, bool force = false)
        {
            if (item.go != null && !force)
            {
                return;
            }

            if (item.go == null)
            {
                item.go = GetRecycleItem(item.prefabName);
                if (item.go == null)
                {
                    item.go     = GameObject.Instantiate(assetObjectDic[item.prefabName], this.listContainer);
                    item.isInit = false;
                    item.data   = null;
                }
                else
                {
                    item.isInit = true;
                    this.mItemObjectDict.TryGetValue(item.go, out item.data);
                    //item.go.transform.SetParent(this.listContainer);
                }
                if (!item.go.activeSelf)
                {
                    item.go.SetActive(true);
                }

                RectTransform rect = item.go.GetComponent <RectTransform>();
                Vector2       size = rect.rect.size;
                switch (this.layoutType)
                {
                case ListViewLayoutType.TopToBottom:
                    rect.pivot     = TopToDownPreset;
                    rect.anchorMin = TopToDownPreset;
                    rect.anchorMax = TopToDownPreset;
                    break;

                case ListViewLayoutType.BottomToTop:
                    rect.pivot     = DownToTopPreset;
                    rect.anchorMin = DownToTopPreset;
                    rect.anchorMax = DownToTopPreset;
                    break;

                case ListViewLayoutType.LeftToRight:
                    rect.pivot     = LeftToRightPreset;
                    rect.anchorMin = LeftToRightPreset;
                    rect.anchorMax = LeftToRightPreset;
                    break;

                case ListViewLayoutType.RightToLeft:
                    rect.pivot     = RightToLeftPreset;
                    rect.anchorMin = RightToLeftPreset;
                    rect.anchorMax = RightToLeftPreset;
                    break;

                default: break;
                }
                rect.sizeDelta = size;
            }

            this.UpdateItemGameObjectPosition(item);
            m_funcTab.ItemEnter(item);
        }