Esempio n. 1
0
        void CreateCells()
        {
            for (int i = 0; i < rowNum * colNum; i++)
            {
                GameObject unit = GameObject.Instantiate(go);

                unit.name = unit.name + i;

                unit.transform.SetParent(pool.transform, false);

                (unit.transform as RectTransform).localScale = new Vector3(cellScale, cellScale, cellScale);

                (unit.transform as RectTransform).pivot = new Vector2(0, 1);

                (unit.transform as RectTransform).anchorMin = new Vector2(0, 1);

                (unit.transform as RectTransform).anchorMax = new Vector2(0, 1);

                SuperListCell cell = unit.GetComponent <SuperListCell>();

                if (isAlphaIn)
                {
                    cell.canvasGroup = unit.AddComponent <CanvasGroup>();
                }

                hidePool.Add(cell);
            }
        }
Esempio n. 2
0
        private void OneAlphaInOver()
        {
            alphaInList.RemoveAt(0);

            if (alphaInList.Count > 0)
            {
                SuperListCell cell = alphaInList[0];

                cell.AlphaIn(OneAlphaInOver);
            }
        }
Esempio n. 3
0
        public void UpdateItemAt(int _index, object _data)
        {
            data [_index] = _data;

            for (int i = 0; i < showPool.Count; i++)
            {
                SuperListCell cell = showPool[i];

                if (cell.index == _index)
                {
                    cell.SetData(_data);

                    break;
                }
            }
        }
Esempio n. 4
0
        public void UpdateItemAt(int _index, object _data)
        {
            data [_index] = _data;

            foreach (GameObject unit in showPool)
            {
                SuperListCell cell = unit.GetComponent <SuperListCell> ();

                if (cell.index == _index)
                {
                    cell.SetData(_data);

                    break;
                }
            }
        }
Esempio n. 5
0
        public void SetSelectedIndex(int _index)
        {
            if (selectedIndex == _index)
            {
                return;
            }

            if (needSelectedIndex)
            {
                for (int i = 0; i < showPool.Count; i++)
                {
                    SuperListCell cell = showPool[i];

                    if (cell.index == _index)
                    {
                        cell.SetSelected(true);
                    }
                    else if (cell.index == selectedIndex)
                    {
                        cell.SetSelected(false);
                    }
                }

                selectedIndex = _index;
            }

            if (selectedIndex != -1 || !needSelectedIndex)
            {
                if (CellClickHandle != null)
                {
                    CellClickHandle(data [_index]);
                }

                if (CellClickIndexHandle != null)
                {
                    CellClickIndexHandle(_index);
                }
            }
        }
Esempio n. 6
0
        public void SetSelectedIndex(int _index)
        {
            if (selectedIndex == _index)
            {
                return;
            }

            if (needSelectedIndex)
            {
                foreach (GameObject unit in showPool)
                {
                    SuperListCell cell = unit.GetComponent <SuperListCell> ();

                    if (cell.index == selectedIndex)
                    {
                        cell.SetSelected(false);
                    }
                    else if (cell.index == _index)
                    {
                        cell.SetSelected(true);
                    }
                }

                selectedIndex = _index;
            }

            if (selectedIndex != -1 || !needSelectedIndex)
            {
                if (CellClickHandle != null)
                {
                    CellClickHandle(data [_index]);
                }

                if (CellClickIndexHandle != null)
                {
                    CellClickIndexHandle(_index);
                }
            }
        }
Esempio n. 7
0
 void CellClick(SuperListCell _cell)
 {
     SetSelectedIndex(_cell.index);
 }
Esempio n. 8
0
        private void SetCellData(SuperListCell _cell, int _index)
        {
            if (!isAlphaIn)
            {
                _cell.SetData(data[_index]);
            }
            else
            {
                bool result = _cell.SetData(data[_index]);

                if (result)
                {
                    _cell.canvasGroup.alpha = 0;

                    int index = alphaInList.IndexOf(_cell);

                    bool needStart = false;

                    if (index != -1)
                    {
                        if (index == 0)
                        {
                            _cell.StopAlphaIn();

                            needStart = true;
                        }

                        alphaInList.RemoveAt(index);
                    }

                    alphaInList.Add(_cell);

                    if (alphaInList.Count == 1 || needStart)
                    {
                        alphaInList[0].AlphaIn(OneAlphaInOver);
                    }
                }
                else
                {
                    _cell.canvasGroup.alpha = 1;

                    int index = alphaInList.IndexOf(_cell);

                    bool needStart = false;

                    if (index != -1)
                    {
                        if (index == 0)
                        {
                            _cell.StopAlphaIn();

                            needStart = true;
                        }

                        alphaInList.RemoveAt(index);
                    }

                    if (needStart && alphaInList.Count > 0)
                    {
                        alphaInList[0].AlphaIn(OneAlphaInOver);
                    }
                }
            }
        }
Esempio n. 9
0
        private void SetCellIndex(SuperListCell _cell, int _index)
        {
            int row;

            int col;

            float xFix = 0;

            float yFix = 0;

            if (isVertical)
            {
                row = _index / colNum;

                col = _index % colNum;

                if (insertIndexArr != null)
                {
                    for (int i = 0; i < insertIndexArr.Length; i++)
                    {
                        if (row >= insertIndexArr[i])
                        {
                            yFix += insertRectArr[i].rect.height + verticalGap;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            else
            {
                col = _index / rowNum;

                row = _index % rowNum;

                if (insertIndexArr != null)
                {
                    for (int i = 0; i < insertIndexArr.Length; i++)
                    {
                        if (col >= insertIndexArr[i])
                        {
                            xFix += insertRectArr[i].rect.width + horizontalGap;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }

            float xPos = col * (cellWidth + horizontalGap) + xFix;

            float yPos = -row * (cellHeight + verticalGap) - yFix;

            Vector2 pos = new Vector2(xPos, yPos);

            (_cell.transform as RectTransform).anchoredPosition = pos;

            _cell.index = _index;

            _cell.SetSelected(_index == selectedIndex);
        }
Esempio n. 10
0
        private void ResetPos(int _nowIndex, bool _dataHasChange, bool _insertHasChange)
        {
//			if (data.Count == 0) {
//
//				return;
//			}

            if (isVertical)
            {
                if (_nowIndex - showIndex == colNum)
                {
                    for (int i = 0; i < _nowIndex - showIndex; i++)
                    {
                        int newIndex = showIndex + rowNum * colNum + i;

                        SuperListCell unit = showPool [0];

                        showPool.RemoveAt(0);

                        if (newIndex < data.Count)
                        {
                            showPool.Add(unit);

                            SetCellIndex(unit, newIndex);

                            SetCellData(unit, newIndex);
                        }
                        else
                        {
                            hidePool.Add(unit);

                            unit.transform.SetParent(pool.transform, false);
                        }
                    }
                }
                else if (_nowIndex - showIndex == -colNum)
                {
                    for (int i = 0; i < showIndex - _nowIndex; i++)
                    {
                        int newIndex = showIndex - colNum + i;

                        SuperListCell unit;

                        if (showPool.Count == rowNum * colNum)
                        {
                            unit = showPool [showPool.Count - 1];

                            showPool.RemoveAt(showPool.Count - 1);
                        }
                        else
                        {
                            unit = hidePool [0];

                            hidePool.RemoveAt(0);

                            unit.transform.SetParent(container.transform, false);
                        }

                        showPool.Insert(0, unit);

                        SetCellIndex(unit, newIndex);

                        SetCellData(unit, newIndex);
                    }
                }
                else
                {
                    List <int> tmpList = new List <int> ();

                    for (int i = 0; i < rowNum * colNum; i++)
                    {
                        if (_nowIndex + i < data.Count)
                        {
                            tmpList.Add(_nowIndex + i);
                        }
                        else
                        {
                            break;
                        }
                    }

                    SuperListCell[] newShowPool = new SuperListCell[tmpList.Count];

                    List <SuperListCell> replacePool = new List <SuperListCell> ();

                    for (int i = 0; i < showPool.Count; i++)
                    {
                        SuperListCell unit = showPool [i];

                        int tmpIndex = unit.index;

                        if (tmpList.Contains(tmpIndex))
                        {
                            newShowPool [tmpList.IndexOf(tmpIndex)] = unit;

                            if (_dataHasChange)
                            {
                                SetCellData(unit, tmpIndex);                                //如果列表数据已经发生了变化则需要在这里进行一次单元格赋值
                            }

                            if (_insertHasChange)
                            {
                                SetCellIndex(unit, tmpIndex);
                            }
                        }
                        else
                        {
                            replacePool.Add(unit);
                        }
                    }

                    showPool.Clear();

                    for (int i = 0; i < newShowPool.Length; i++)
                    {
                        if (newShowPool [i] == null)
                        {
                            SuperListCell unit;

                            if (replacePool.Count > 0)
                            {
                                unit = replacePool [0];

                                replacePool.RemoveAt(0);
                            }
                            else
                            {
                                unit = hidePool [0];

                                hidePool.RemoveAt(0);

                                unit.transform.SetParent(container.transform, false);
                            }

                            newShowPool [i] = unit;

                            SetCellIndex(unit, tmpList [i]);

                            SetCellData(unit, tmpList [i]);
                        }

                        showPool.Add(newShowPool [i]);
                    }

                    foreach (SuperListCell unit in replacePool)
                    {
                        unit.transform.SetParent(pool.transform, false);

                        hidePool.Add(unit);
                    }
                }
            }
            else
            {
                if (_nowIndex - showIndex == rowNum)
                {
                    for (int i = 0; i < _nowIndex - showIndex; i++)
                    {
                        int newIndex = showIndex + rowNum * colNum + i;

                        SuperListCell unit = showPool [0];

                        showPool.RemoveAt(0);

                        if (newIndex < data.Count)
                        {
                            showPool.Add(unit);

                            SetCellIndex(unit, newIndex);

                            SetCellData(unit, newIndex);
                        }
                        else
                        {
                            hidePool.Add(unit);

                            unit.transform.SetParent(pool.transform, false);
                        }
                    }
                }
                else if (_nowIndex - showIndex == -rowNum)
                {
                    for (int i = 0; i < showIndex - _nowIndex; i++)
                    {
                        int newIndex = showIndex - rowNum + i;

                        SuperListCell unit;

                        if (showPool.Count == rowNum * colNum)
                        {
                            unit = showPool [showPool.Count - 1];

                            showPool.RemoveAt(showPool.Count - 1);
                        }
                        else
                        {
                            unit = hidePool [0];

                            hidePool.RemoveAt(0);

                            unit.transform.SetParent(container.transform, false);
                        }

                        showPool.Insert(0, unit);

                        SetCellIndex(unit, newIndex);

                        SetCellData(unit, newIndex);
                    }
                }
                else
                {
                    List <int> tmpList = new List <int> ();

                    for (int i = 0; i < rowNum * colNum; i++)
                    {
                        if (_nowIndex + i < data.Count)
                        {
                            tmpList.Add(_nowIndex + i);
                        }
                        else
                        {
                            break;
                        }
                    }

                    SuperListCell[] newShowPool = new SuperListCell[tmpList.Count];

                    List <SuperListCell> replacePool = new List <SuperListCell> ();

                    for (int i = 0; i < showPool.Count; i++)
                    {
                        SuperListCell unit = showPool [i];

                        int tmpIndex = unit.index;

                        if (tmpList.Contains(tmpIndex))
                        {
                            newShowPool [tmpList.IndexOf(tmpIndex)] = unit;

                            if (_dataHasChange)
                            {
                                SetCellData(unit, tmpIndex);
                            }

                            if (_insertHasChange)
                            {
                                SetCellIndex(unit, tmpIndex);
                            }
                        }
                        else
                        {
                            replacePool.Add(unit);
                        }
                    }

                    showPool.Clear();

                    for (int i = 0; i < newShowPool.Length; i++)
                    {
                        if (newShowPool [i] == null)
                        {
                            SuperListCell unit;

                            if (replacePool.Count > 0)
                            {
                                unit = replacePool [0];

                                replacePool.RemoveAt(0);
                            }
                            else
                            {
                                unit = hidePool [0];

                                hidePool.RemoveAt(0);

                                unit.transform.SetParent(container.transform, false);
                            }

                            newShowPool [i] = unit;

                            SetCellIndex(unit, tmpList [i]);

                            SetCellData(unit, tmpList [i]);
                        }

                        showPool.Add(newShowPool [i]);
                    }

                    foreach (SuperListCell unit in replacePool)
                    {
                        unit.transform.SetParent(pool.transform, false);

                        hidePool.Add(unit);
                    }
                }
            }

            showIndex = _nowIndex;
        }
Esempio n. 11
0
        void CellClick(GameObject obj)
        {
            SuperListCell cell = obj.GetComponent <SuperListCell> ();

            SetSelectedIndex(cell.index);
        }