Пример #1
0
        public virtual void reloadData()
        {
            for (int i = 0; i < cellsUsed.Count; i++)
            {
                LTableViewCell cell = cellsUsed[i];
                cellsFreed.Add(cell);
                //cell.node.transform.SetParent(null);
                cell.node.SetActive(false);
                cell.reset();
            }

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

            if (tran != null)
            {
                tran.gameObject.SetActive(false);
            }

            cellsUsed.Clear();
            indices.Clear();
            positions.Clear();
            updatePositions();
            setContentOffsetToTop();
            onScrolling();
            relocateContainer();
        }
Пример #2
0
        public override void updateCellAtIndex(int idx)
        {
            LTableViewCell cell = onDataSourceAdapterHandler.Invoke(dequeueCell(), idx);

            if (cell == null)
            {
                Debug.LogError("cell can not be NULL");
            }
            cell.idx = idx;

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

            switch (direction)
            {
            case ScrollDirection.HORIZONTAL:
                rtran.pivot = new Vector2(0, 0);
                break;

            default:
                rtran.pivot = new Vector2(0, 1);
                break;
            }

            rtran.sizeDelta = cellsSize;
            cell.node.transform.SetParent(container.transform);
            cell.node.transform.localPosition = cellPositionFromIndex(idx);
            insertSortableCell(cell, idx);
            indices.Add(idx, 1);
        }
Пример #3
0
        protected virtual void updateCellByAdapter(int idx)
        {
            LTableViewCell cell = _onDataSourceAdapterHandler(dequeueCell(), idx);

            if (cell == null)
            {
                Debug.LogError("cell can not be NULL");
            }
            cell.idx = idx;
            RectTransform rtran = cell.node.GetComponent <RectTransform>();

            switch (direction)
            {
            case ScrollDirection.HORIZONTAL:
                rtran.pivot = Vector2.zero;
                break;

            default:
                rtran.pivot = new Vector2(0, 1);
                break;
            }

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

            insertSortableCell(cell, idx);
            if (!indices.ContainsKey(idx))
            {
                indices.Add(idx, 1);
            }
        }
Пример #4
0
        public LTableView()
        {
            cellsCount   = 0;
            cellsSize    = Vector2.zero;
            direction    = ScrollDirection.HORIZONTAL;
            autoRelocate = false;

            cellsUsed    = new List <LTableViewCell>();
            cellsFreed   = new List <LTableViewCell>();
            positions    = new List <float>();
            indices      = new Dictionary <int, int>();
            cellTemplate = new LTableViewCell();
        }
Пример #5
0
 protected LTableViewCell _onDataSourceAdapterHandler(LTableViewCell cell, int idx)
 {
     if (cell == null)
     {
         cell      = new LTableViewCell();
         cell.node = (GameObject)Instantiate(transform.Find("container/cell_tpl").gameObject);
     }
     if (onCellHandle != null)
     {
         onCellHandle.Invoke(idx, cell.node);
     }
     return(cell);
 }
Пример #6
0
        public LTableView()
        {
            cellsCount = 0;
            cellsSize = Vector2.zero;
            direction = ScrollDirection.HORIZONTAL;
            autoRelocate = false;
            autoRelocateSpeed = AUTO_RELOCATE_SPPED;

            cellsUsed = new List<LTableViewCell>();
            cellsFreed = new List<LTableViewCell>();
            positions = new List<float>();
            indices = new Dictionary<int, int>();
            cellTemplate = new LTableViewCell();
        }
Пример #7
0
        protected LTableViewCell dequeueCell()
        {
            LTableViewCell cell = null;

            if (cellsFreed.Count == 0)
            {
                return(null);
            }
            else
            {
                cell = cellsFreed[cellsFreed.Count - 1];
                cellsFreed.Remove(cell);
            }
            return(cell);
        }
Пример #8
0
        public virtual void reloadData()
        {
            for (int i = 0; i < cellsUsed.Count; i++)
            {
                LTableViewCell cell = cellsUsed[i];
                cellsFreed.Add(cell);
                cell.node.transform.SetParent(null);
                cell.reset();
            }

            cellsUsed.Clear();
            indices.Clear();
            positions.Clear();
            updatePositions();
            setContentOffsetToTop();
            onScrolling();
            relocateContainer();
        }
Пример #9
0
 protected void insertSortableCell(LTableViewCell 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);
     }
 }
Пример #10
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();
    }
Пример #11
0
 protected void insertSortableCell(LTableViewCell 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);
     }
 }
Пример #12
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();
    }
Пример #13
0
        protected override void onScrolling()
        {
            if (cellsCount == 0)
            {
                return;
            }

            int beginIdx = 0, endIdx = 0;

            beginIdx = cellBeginIndexFromOffset(getContentOffset());
            endIdx   = cellEndIndexFromOffset(getContentOffset());

            while (cellsUsed.Count > 0)
            {
                LTableViewCell cell = cellsUsed[0];
                int            idx  = cell.idx;

                if (idx < beginIdx)
                {
                    indices.Remove(idx);
                    cellsUsed.Remove(cell);
                    cellsFreed.Add(cell);
                    cell.reset();
                    cell.node.transform.SetParent(null);
                }
                else
                {
                    break;
                }
            }

            while (cellsUsed.Count > 0)
            {
                LTableViewCell cell = cellsUsed[cellsUsed.Count - 1];
                int            idx  = cell.idx;

                if (idx > endIdx && idx < cellsCount)
                {
                    indices.Remove(idx);
                    cellsUsed.RemoveAt(cellsUsed.Count - 1);
                    cellsFreed.Add(cell);
                    cell.reset();
                    cell.node.transform.SetParent(null);
                }
                else
                {
                    break;
                }
            }

            for (int idx = beginIdx; idx <= endIdx && idx < cellsCount; ++idx)
            {
                if (indices.ContainsKey(idx))
                {
                    continue;
                }
                updateCellAtIndex(idx);
            }

            base.onScrolling();
        }