Ejemplo n.º 1
0
        public void reloadData()
        {
            if (_cellsUsed.Count > 0)
            {
                for (int i = 0; i < _cellsUsed.Count; i++)
                {
                    LGridViewCell cell = _cellsUsed[i];
                    _cellsFreed.Add(cell);
                    cell.reset();
                    cell.node.SetActive(false);
                }
                _cellsUsed.Clear();
            }

            Transform tran = transform.Find("container/cell_tpl");

            if (tran != null)
            {
                tran.gameObject.SetActive(false);
            }
            try {
                _indices.Clear();
                _positions.Clear();
                updatePositions();
                setContentOffsetToTop();
                onScrolling();
            }
            catch (Exception e) {
                Debug.Log(e);
            }

            relocateContainer();
        }
Ejemplo n.º 2
0
 protected LGridViewCell _onDataSourceAdapterHandler(LGridViewCell cell, int idx)
 {
     if (cell == null)
     {
         cell = new LGridViewCell();
         if (cell_tpl != null)
         {
             cell.node = (GameObject)Instantiate(cell_tpl);
         }
         else
         {
             Transform tpl = transform.Find("container/cell_tpl");
             if (tpl)
             {
                 cell.node = (GameObject)Instantiate(tpl.gameObject);
             }
             else
             {
                 Debug.LogWarning("模板为空");
             }
         }
     }
     if (onCellHandle != null)
     {
         onCellHandle.Invoke(idx, cell.node);
     }
     return(cell);
 }
Ejemplo n.º 3
0
        public void updateCellAtIndex(int idx, int row)
        {
            if (cellsCount == 0)
            {
                return;
            }

            LGridViewCell cell = _onDataSourceAdapterHandler(dequeueCell(), idx);

            cell.idx = idx;
            cell.row = row;
            RectTransform rtran = cell.node.GetComponent <RectTransform>();

            rtran.pivot     = new Vector2(0, 1);
            rtran.sizeDelta = cellsSize;
            cell.node.SetActive(true);
            cell.node.transform.SetParent(container.transform);
            cell.node.transform.localPosition = cellPositionFromIndex(idx);
            cell.node.transform.localScale    = new Vector3(1, 1, 1);
            insertSortableCell(cell, idx);

            //新抽象出来的Item接口
            IListItem item = rtran.GetComponent <IListItem>();

            if (item != null)
            {
                item.Init(idx);
                item.OnRefresh();
            }

            _indices.Add(idx, 1);
        }
Ejemplo n.º 4
0
 public LGridView()
 {
     cellsCount = 0;
     cellsSize = Vector2.zero;
     cols = 0;
     _rows = 0;
     direction = ScrollDirection.VERTICAL;
     cellTemplate = new LGridViewCell ();
     _cellsUsed = new List<LGridViewCell>();
     _cellsFreed = new List<LGridViewCell>();
     _positions = new List<Vector2>();
     _indices = new Dictionary<int, int>();
 }
Ejemplo n.º 5
0
 public LGridView()
 {
     cellsCount   = 0;
     cellsSize    = Vector2.zero;
     cols         = 0;
     _rows        = 0;
     direction    = ScrollDirection.VERTICAL;
     cellTemplate = new LGridViewCell();
     _cellsUsed   = new List <LGridViewCell>();
     _cellsFreed  = new List <LGridViewCell>();
     _positions   = new List <Vector2>();
     _indices     = new Dictionary <int, int>();
 }
Ejemplo n.º 6
0
 protected LGridViewCell _onDataSourceAdapterHandler(LGridViewCell cell, int idx)
 {
     if (cell == null)
     {
         cell      = new LGridViewCell();
         cell.node = (GameObject)Instantiate(transform.Find("container/cell_tpl").gameObject);
     }
     if (onCellHandle != null)
     {
         onCellHandle.Invoke(idx, cell.node);
     }
     return(cell);
 }
Ejemplo n.º 7
0
        protected LGridViewCell dequeueCell()
        {
            LGridViewCell cell = null;

            if (_cellsFreed.Count == 0)
            {
                return(null);
            }
            else
            {
                cell = _cellsFreed[0];
                _cellsFreed.Remove(cell);
            }
            return(cell);
        }
Ejemplo n.º 8
0
 public void insertSortableCell(LGridViewCell cell, int idx)
 {
     if (_cellsUsed.Count == 0)
     {
         _cellsUsed.Add(cell);
     }
     else
     {
         for (int i = 0; i < _cellsUsed.Count; i++)
         {
             if (_cellsUsed[i].idx > idx)
             {
                 _cellsUsed.Insert(i, cell);
                 return;
             }
         }
         _cellsUsed.Add(cell);
         return;
     }
 }
Ejemplo n.º 9
0
        public void reloadData()
        {
            if (cellsUsed.Count > 0)
            {
                LGridViewCell cell = cellsUsed [0];
                while (cell != null)
                {
                    cellsFreed.Add(cell);
                    cellsUsed.Remove(cell);
                    cell.node.transform.SetParent(null);
                    cell.reset();
                }
            }
            indices.Clear();
            positions.Clear();
            updatePositions();
            setContentOffsetToTop();
            onScrolling();

            relocateContainer();
        }
Ejemplo n.º 10
0
        public void reloadData()
        {
            if (_cellsUsed.Count > 0)
            {
                for (int i = 0; i < _cellsUsed.Count; i++)
                {
                    LGridViewCell cell = _cellsUsed[i];
                    _cellsFreed.Add(cell);
                    cell.reset();
                    cell.node.SetActive(false);
                }
                _cellsUsed.Clear();
            }
            _indices.Clear();
            _positions.Clear();
            updatePositions();
            setContentOffsetToTop();
            onScrolling();

            relocateContainer();
        }
Ejemplo n.º 11
0
        public void updateCellAtIndex(int idx, int row)
        {
            if (cellsCount == 0)
            {
                return;
            }

            LGridViewCell cell = onDataSourceAdapterHandler.Invoke(dequeueCell(), idx);

            cell.idx = idx;
            cell.row = row;
            RectTransform rtran = cell.node.GetComponent <RectTransform>();

            rtran.pivot     = new Vector2(0, 1);
            rtran.sizeDelta = cellsSize;

            cell.node.transform.SetParent(container.transform);
            cell.node.transform.localPosition = cellPositionFromIndex(idx);
            insertSortableCell(cell, idx);

            indices.Add(idx, 1);
        }
Ejemplo n.º 12
0
 public void insertSortableCell(LGridViewCell cell, int idx)
 {
     if (_cellsUsed.Count == 0)
     {
         _cellsUsed.Add(cell);
     }
     else
     {
         for (int i = 0; i < _cellsUsed.Count; i++)
         {
             if (_cellsUsed[i].idx > idx)
             {
                 _cellsUsed.Insert(i, cell);
                 return;
             }
         }
         _cellsUsed.Add(cell);
         return;
     }
 }
Ejemplo n.º 13
0
        protected override void onScrolling()
        {
            base.onScrolling();

            int beginRow = 0, endRow = 0;

            beginRow = cellBeginRowFromOffset(getContentOffset());
            endRow   = cellEndRowFromOffset(getContentOffset());

            while (_cellsUsed.Count > 0)
            {
                LGridViewCell cell = _cellsUsed[0];
                int           row  = cell.row;
                int           idx  = cell.idx;

                if (row < beginRow)
                {
                    _indices.Remove(idx);
                    _cellsUsed.Remove(cell);
                    _cellsFreed.Add(cell);
                    cell.reset();
                    //cell.node.transform.SetParent(null);
                    cell.node.SetActive(false);
                }
                else
                {
                    break;
                }
            }

            while (_cellsUsed.Count > 0)
            {
                LGridViewCell cell = _cellsUsed[_cellsUsed.Count - 1];
                int           row  = cell.row;
                int           idx  = cell.idx;

                if (row > endRow && row < _rows)
                {
                    _indices.Remove(idx);
                    _cellsUsed.Remove(cell);
                    _cellsFreed.Add(cell);
                    cell.reset();
                    //cell.node.transform.SetParent(null);
                    cell.node.SetActive(false);
                }
                else
                {
                    break;
                }
            }

            for (int row = beginRow; row <= endRow && row < _rows; ++row)
            {
                int cellBeginIndex = cellFirstIndexFromRow(row);
                int cellEndIndex   = cellBeginIndex + cols;

                for (int idx = cellBeginIndex; idx < cellEndIndex && idx < cellsCount; ++idx)
                {
                    if (_indices.ContainsKey(idx))
                    {
                        continue;
                    }
                    updateCellAtIndex(idx, row);
                }
            }
        }
Ejemplo n.º 14
0
    void Start()
    {
        wm = LSingleton.getInstance("LWindowManager") as LWindowManager;

        btn_grid.onClick.AddListener(() =>
        {
            ArrayList list = new ArrayList();
            list.Add(123);
            list.Add("测试内容");
            wm.runWindow("WindowGridView", WindowHierarchy.Normal, list);
        });

        btn_trans.onClick.AddListener(() =>
        {
            SceneManager.LoadScene("second");
        });

        btn_guide.onClick.AddListener(() =>
        {
            guideLayer.gameObject.SetActive(!guideLayer.gameObject.activeInHierarchy);
        });

        ctrlView.onControlHandler = (float ox, float oy) =>
        {
            Debug.Log(string.Format("offsetX={0} offsetY={1}", ox, oy));
        };

        scrolView.onMoveCompleteHandler = () =>
        {
            Debug.Log(" scrolView.onMoveCompleteHandler ");
        };

        tblView.cellsSize = new Vector2(150, 40);
        tblView.cellTemplate.node = Resources.Load("Prefabs/tbl_cell") as GameObject;
        tblView.GetComponent<RectTransform>().sizeDelta = new Vector2(150, 40 * 5);
        tblView.cellsCount = 100;
        tblView.onDataSourceAdapterHandler = (LTableViewCell cell, int idx) =>
        {
            if (cell == null)
            {
                cell = new LTableViewCell();
                cell.node = (GameObject)Instantiate(tblView.cellTemplate.node);
            }
            cell.node.GetComponent<Text>().text = idx.ToString();
            return cell;
        };
        tblView.reloadData();

        rtfView.insertElement("hello world!!", Color.blue, 25, true, false, Color.blue, "数据");
        rtfView.insertElement("测试文本内容!!", Color.red, 15, false, true, Color.blue, "");
        rtfView.insertElement("Image/face01", 5f, "");
        rtfView.insertElement("The article comes from the point of the examination", Color.green, 15, true, false, Color.blue, "");
        rtfView.insertElement("Image/face02/1", "");
        rtfView.insertElement(1);
        rtfView.insertElement("outline and newline", Color.yellow, 20, false, true, Color.blue, "");
        rtfView.onClickHandler = (string data) =>
        {
            Debug.Log("data " + data);
        };
        rtfView.reloadData();

        pageView.cellsSize = new Vector2(150, 100);
        pageView.cellTemplate.node = Resources.Load("Prefabs/page_cell") as GameObject;
        pageView.cellsCount = 14;
        pageView.onDataSourceAdapterHandler = (LTableViewCell cell, int idx) =>
        {
            if (cell == null)
            {
                cell = new LTableViewCell();
                cell.node = (GameObject)Instantiate(pageView.cellTemplate.node, Vector3.zero, pageView.cellTemplate.node.transform.rotation);
            }
            cell.node.transform.FindChild("Text").GetComponent<Text>().text = idx.ToString();
            return cell;
        };
        pageView.onPageChangedHandler = (int pageIdx) =>
        {
            Debug.Log("page " + pageIdx);
        };
        pageView.reloadData();

        RectTransform rtran = listView.GetComponent<RectTransform>();
        listView.bounceBox = new Rect(listView.transform.position.x,
                             listView.transform.position.y,
                             rtran.rect.width,
                             rtran.rect.height);

        listView.itemTemplate = Resources.Load("Prefabs/list_cell") as GameObject;
        listView.limitNum = 10; //not must to set limitNum
        for (int i = 0; i < 30; i++)
        {
            GameObject item = listView.dequeueItem();
            item.GetComponent<RectTransform>().sizeDelta = new Vector2(100, 40 + Random.Range(0, 40));
            item.GetComponent<Text>().text = i.ToString();
            listView.insertNodeAtLast(item);
        }
        listView.reloadData();

        gridView.cellsSize = new Vector2(100, 100);
        gridView.cellTemplate.node = Resources.Load("Prefabs/grid_cell") as GameObject;
        gridView.cols = 4;
        gridView.cellsCount = 100;
        gridView.onDataSourceAdapterHandler = (LGridViewCell cell, int idx) =>
        {
            if (cell == null)
            {
                cell = new LGridViewCell();
                cell.node = (GameObject)Instantiate(gridView.cellTemplate.node);
            }
            cell.node.GetComponent<Text>().text = idx.ToString();
            return cell;
        };
        gridView.reloadData();
    }
Ejemplo n.º 15
0
    void Start()
    {
        _wm = LWindowManager.GetInstance();

        btn_grid.onClick.AddListener(() =>
        {
            ArrayList list = new ArrayList();
            list.Add(123);
            list.Add("测试内容");
            _wm.runWindow("WindowGridView", WindowHierarchy.Normal, list);
        });

        btn_trans.onClick.AddListener(() =>
        {
            _wm.LoadSceneAsync("second",(float p)=>
            {
                Debug.Log("进度 " + p);
            });
        });

        btn_guide.onClick.AddListener(() =>
        {
            bool isBlock = panel_root.GetComponent<CanvasGroup>().blocksRaycasts;
            panel_root.GetComponent<CanvasGroup>().blocksRaycasts = !isBlock;
            Text textComp = btn_guide.transform.FindChild("Text").gameObject.GetComponent<Text>();
            textComp.text = isBlock ? "关闭遮罩" : "开启遮罩";
        });

        ctrlView.onControlHandler = (float ox, float oy,bool isFinish) =>
        {
            //Debug.Log(string.Format("offsetX={0} offsetY={1}", ox, oy));
        };

        scrolView.onMoveCompleteHandler = () =>
        {
            Debug.Log(" scrolView.onMoveCompleteHandler ");
        };

        tblView.cellsSize = new Vector2(150, 40);
        tblView.cellTemplate.node = Resources.Load("Prefabs/tbl_cell") as GameObject;
        tblView.GetComponent<RectTransform>().sizeDelta = new Vector2(150, 40 * 5);
        tblView.cellsCount = 100;
        tblView.onDataSourceAdapterHandler = (LTableViewCell cell, int idx) =>
        {
            if (cell == null)
            {
                cell = new LTableViewCell();
                cell.node = (GameObject)Instantiate(tblView.cellTemplate.node);
            }
            cell.node.GetComponent<Text>().text = idx.ToString();
            return cell;
        };
        tblView.reloadData();

        //rtfView.insertElement("hello world!!", Color.blue, 25, true, false, Color.blue, "数据");
        //rtfView.insertElement("测试文本内容!!", Color.red, 15, false, true, Color.blue, "");
        //rtfView.insertElement("face01", 5f, "");
        //rtfView.insertElement("The article comes from the point of the examination", Color.green, 15, true, false, Color.blue, "");
        //rtfView.insertElement("face02/1", "");
        //rtfView.insertElement(1);
        //rtfView.insertElement("outline and newline", Color.yellow, 20, false, true, Color.blue, "");
        rtfView.parseRichDefaultString("<lab txt=\"hello world!!\" color=#ffff00 data=数据 /><lab txt=\"测试文本内容\" isUnderLine=true size=40/><anim path=face01 fps=5.0/><newline /><img path=face02/1/><lab txt=\"The article comes from the point of the examination\" color=#ff0000 />");
        rtfView.onClickHandler = (string data) =>
        {
            Debug.Log("data " + data);
        };
        //rtfView.reloadData();

        pageView.cellsSize = new Vector2(150, 100);
        pageView.cellTemplate.node = Resources.Load("Prefabs/page_cell") as GameObject;
        pageView.cellsCount = 14;
        pageView.onDataSourceAdapterHandler = (LTableViewCell cell, int idx) =>
        {
            if (cell == null)
            {
                cell = new LTableViewCell();
                cell.node = (GameObject)Instantiate(pageView.cellTemplate.node, Vector3.zero, pageView.cellTemplate.node.transform.rotation);
            }
            cell.node.transform.FindChild("Text").GetComponent<Text>().text = idx.ToString();
            return cell;
        };
        pageView.onPageChangedHandler = (int pageIdx) =>
        {
            Debug.Log("page " + pageIdx);
        };
        pageView.reloadData();

        listView.itemTemplate = Resources.Load("Prefabs/list_cell") as GameObject;
        listView.limitNum = 10; //not must to set limitNum
        for (int i = 0; i < 30; i++)
        {
            GameObject item = listView.dequeueItem();
            item.GetComponent<RectTransform>().sizeDelta = new Vector2(100, 40 + Random.Range(0, 40));
            item.GetComponent<Text>().text = i.ToString();
            listView.insertNodeAtLast(item);
        }
        listView.reloadData();

        gridView.cellsSize = new Vector2(100, 100);
        gridView.cellTemplate.node = Resources.Load("Prefabs/grid_cell") as GameObject;
        gridView.cols = 4;
        gridView.cellsCount = 100;
        gridView.onDataSourceAdapterHandler = (LGridViewCell cell, int idx) =>
        {
            if (cell == null)
            {
                cell = new LGridViewCell();
                cell.node = (GameObject)Instantiate(gridView.cellTemplate.node);
            }
            cell.node.GetComponent<Text>().text = idx.ToString();
            return cell;
        };
        gridView.reloadData();
    }