Exemple #1
0
        /// <summary>
        /// 获得子项列表中索引最小的子项
        /// </summary>
        /// <param name="isIncludeNotActive">是否包含不激活的子项</param>
        /// <returns></returns>
        protected UITool_ListItem GetMinIndexItem(bool isIncludeNotActive)
        {
            UITool_ListItem item  = null;
            int             min   = -1;
            int             count = GetListItemCount(true);

            for (int i = 0; i < count; i++)
            {
                if (listItems[i].gameObject.activeSelf)
                {
                    item = listItems[i];
                    min  = item.itemIndex;
                    break;
                }
            }

            for (int i = 1; i < count; i++)
            {
                //去除未激活的物体
                if (!isIncludeNotActive && !listItems[i].gameObject.activeSelf)
                {
                    continue;
                }

                if (listItems[i].itemIndex < min)
                {
                    min  = listItems[i].itemIndex;
                    item = listItems[i];
                }
            }
            return(item);
        }
Exemple #2
0
        public void OnCreateListViewItem(UITool_ListItem item)
        {
            ServerItemInfo info = new ServerItemInfo();

            info.zoneName = item.GetComponentInItem <Text>("Text");
            item.param    = info;
        }
        public static UITool_ListItem FindItemByChildObj(GameObject childObj)
        {
            UITool_ListItem item = childObj.transform.parent.GetComponent<UITool_ListItem>();
            if (!item)
                FindItemByChildObj(childObj);

            return item;
        }
Exemple #4
0
        public void HandleClickItem(UITool_ListItem listItem)
        {
            UpdateSelectItemState(listItem);

            if (onClickItem != null)
            {
                onClickItem(listItem);
            }
        }
Exemple #5
0
        /// <summary>
        /// 更新指定索引子项的界面显示(但是不更新数据源)
        /// </summary>
        /// <param name="index">子项的索引</param>
        private void UpdateItem(int index)
        {
            UITool_ListItem item = FindItem(index);

            //adapter.OnUpdateListViewItem(item);
            if (onUpdateItem != null)
            {
                onUpdateItem(item);
            }
        }
Exemple #6
0
        public void OnClickListViewItem(UITool_ListItem item)
        {
            uiServerList.SetActive(false);
            mapIndex  = item.itemIndex; //UnityEngine.Random.Range(0, lhConfigData.cdn.map.Count);
            zoneIndex = item.itemIndex;

            lhCacheData.SetHistoryValue("mapIndex", mapIndex.ToString());
            lhCacheData.SetHistoryValue("zoneIndex", zoneIndex.ToString());

            //更新界面显示
            serverNameText.text = lhConfigData.cdn.zone[item.itemIndex].name;
        }
Exemple #7
0
        /// <summary>
        /// 设置被选中子项的状态,即ListPanelItem中的isSelected字段
        /// </summary>
        /// <param name="item">当前被选中的子项</param>
        private void UpdateSelectItemState(UITool_ListItem item)
        {
            if (item)
            {
                for (int i = 0; i < GetListItemCount(true); i++)
                {
                    listItems[i].isSelected = false;
                }

                item.isSelected = true;
                selectIndex     = item.itemIndex;
                UpdateItems();
            }
        }
Exemple #8
0
        /// <summary>
        /// 通过索引来找子项
        /// </summary>
        /// <param name="index">子项的索引</param>
        public UITool_ListItem FindItem(int index)
        {
            UITool_ListItem item = null;

            for (int i = 0; i < GetListItemCount(true); i++)
            {
                if (listItems[i].itemIndex == index)
                {
                    item = listItems[i];
                    break;
                }
            }
            return(item);
        }
        /// <summary>
        /// 删除子项
        /// </summary>
        /// <param name="index">要删除子项的索引</param>
        public override void DeleteItem(int index)
        {
            if (index < 0)
            {
                return;
            }
            UITool_ListItem item = FindItem(index);

            DestroyImmediate(item.gameObject);
            listItems.Remove(item);
            UpdateItemsIndex();
            //UpdateItemsUI();
            CalculateContent();
            layoutGroupInner.UpdatePosition();
        }
Exemple #10
0
        /// <summary>
        /// 获得被选中的子项,如果没有选中的,就返回null
        /// </summary>
        public UITool_ListItem GetSelectedItem()
        {
            UITool_ListItem item = null;

            for (int i = 0; i < GetListItemCount(true); i++)
            {
                if (listItems[i].isSelected)
                {
                    item = listItems[i];
                    break;
                }
            }

            return(item);
        }
Exemple #11
0
        /// <summary>
        /// 更新所有的子项界面显示(但是不更新数据源)
        /// </summary>
        public void UpdateItems()
        {
            UITool_ListItem maxItem = GetMaxIndexItem(false);

            //当,没有子项的时候,就找不到了
            if (!maxItem)
            {
                return;
            }

            for (int i = 0; i <= maxItem.itemIndex; i++)
            {
                UpdateItem(i);
            }
        }
        protected void WrapContent()
        {
            curContentPos = ContentPosSingle;

            if (curContentPos - preContentPos >= CellSingle)
            {
                RectTransform rtItem1 = listItems[0].GetComponent <RectTransform>();
                RectTransform rtItem2 = listItems[listItems.Count - 1].GetComponent <RectTransform>();
                rtItem1.anchoredPosition = rtItem2.anchoredPosition - new Vector2(0, CellSingle);
                layoutGroupInner.rectTransform.sizeDelta += new Vector2(0, CellSingle);
                UITool_ListItem item = listItems[0];
                listItems.RemoveAt(0);
                listItems.Add(item);
                preContentPos = curContentPos;
            }
        }
Exemple #13
0
        /// <summary>
        /// 更新所有子项的索引,使得子项的索引重新连续排列(例如,如果删除子项时,使得索引不连续,可以调用此方法更新下)
        /// </summary>
        public void UpdateItemsIndex()
        {
            UITool_ListItem maxItem = GetMaxIndexItem(false);

            if (!maxItem)
            {
                return;
            }

            for (int i = 0; i < maxItem.itemIndex; i++)
            {
                UITool_ListItem item = listItems[i];
                item.itemIndex = i;
                item.name      = i.ToString();
            }
        }
Exemple #14
0
        /// <summary>
        /// 创建一个子项
        /// </summary>
        ///<param name="index">子项索引</param>
        protected UITool_ListItem CreateItemOne(int index)
        {
            GameObject itemCopy = lhInstantiate(itemPrefab) as GameObject;

            itemCopy.SetActive(true);
            UITool_ListItem listItem = itemCopy.AddComponent <UITool_ListItem>();

            itemCopy.transform.SetParent(layoutGroupInner.rectTransform);
            RectTransform rtItemCopy   = itemCopy.GetComponent <RectTransform>();
            RectTransform rtItemPrefab = itemPrefab.GetComponent <RectTransform>();

            if (!layoutGroupInner.IsIgnoreAdapter)
            {
                //将锚点设置成左上角对齐,因为这样可以当设置content大小时,不会是子项跟着拉伸,然后会在UITool_Grid中会重置锚点,重新排列
                rtItemCopy.anchorMin = new Vector2(0, 1);
                rtItemCopy.anchorMax = new Vector2(0, 1);
            }
            rtItemCopy.anchoredPosition   = rtItemPrefab.anchoredPosition;
            rtItemCopy.sizeDelta          = new Vector2(rtItemPrefab.rect.width, rtItemPrefab.rect.height); //rtItemPrefab.sizeDelta;
            itemCopy.transform.localScale = Vector3.one;

            listItem.width    = layoutGroupInner.CellWidth;
            listItem.height   = layoutGroupInner.CellHeight;
            listItem.listView = this;

            listItem.itemIndex       = index;
            listItem.gameObject.name = listItem.itemIndex.ToString();
            //listItem.itemData = dataSource[listItem.itemIndex];
            listItems.Insert(listItem.itemIndex, listItem);

            //adapter.OnCreateListViewItem(listItem);
            //adapter.OnUpdateListViewItem(listItem);
            if (onCreateItem != null)
            {
                onCreateItem(listItem);
            }
            if (onUpdateItem != null)
            {
                onUpdateItem(listItem);
            }

            return(listItem);
        }
Exemple #15
0
        public void OnUpdateListViewItem(UITool_ListItem item)
        {
            ServerItemInfo info = (ServerItemInfo)item.param;

            info.zoneName.text = lhConfigData.cdn.zone[item.itemIndex].name;
        }