Exemplo n.º 1
0
    public bool IsListItemVisible(int index, float err = 1f)
    {
        if (IsInited)
        {
            RectTransform rt_v = _ScrollRect.viewport;
            GListItem     item = GetListItem(index);
            if (item != null)
            {
                Rect rect_child = GNewUITools.GetRelativeRect(rt_v, item.RectTrans);
                Rect rect_v     = rt_v.rect;

                if (IsVertical)
                {
                    bool is_inside = rect_child.yMin + err >= rect_v.yMin && rect_child.yMax - err <= rect_v.yMax;
                    return(is_inside);
                }
                else
                {
                    bool is_inside = rect_child.xMin + err >= rect_v.xMin && rect_child.xMax - err <= rect_v.xMax;
                    return(is_inside);
                }
            }
        }
        return(false);
    }
Exemplo n.º 2
0
    public void Preview(int count)
    {
        SafeInit();

        for (int i = 0; i < _viewItems.Count; i++)
        {
            Destroy(_viewItems[i].gameObject);
        }
        _viewItems.Clear();

        this._ItemCount = count;
        RecalculateBound();

        //_CellRect.localScale = Vector3.zero;

        for (int i = 0; i < _ItemCount; i++)
        {
            GListItem g_li = TryCreateItem();
            if (g_li != null)
            {
                SetPivotAnchor(g_li.RectTrans, _Align);
                g_li.RectTrans.anchoredPosition = Index2Pos2(i, g_li.RectTrans);
            }
            g_li.UpdateItem(i);
            //PostSetupItem(g_li);
            _viewItems.Add(g_li);
        }

        //_CellRect.localScale = Vector3.zero;
        //_CellRect.gameObject.SetActive(false);
        //PlayEffect();
    }
Exemplo n.º 3
0
    protected virtual GListItem TryCreateItem()
    {
        if (CellTemplate == null)
        {
            return(null);
        }

        GListItem rv = null;

        rv = _CellPool.TakeOut();

        if (rv == null)
        {
            GameObject item    = CUnityUtil.Instantiate(CellTemplate.gameObject) as GameObject;
            GListItem  itemCon = GListItem.Get(item);
            itemCon.RectTrans.SetParent(_Content, false);

            rv = itemCon;

            if (HasChildButton && this.ClickItemButtonCallBack != null)
            {
                itemCon.OnItemClickButton = this.OnClickItemButton;
            }
        }

        GNewUITools.SetVisible(rv.RectTrans, true);

        return(rv);
    }
Exemplo n.º 4
0
    //private void DisposeItem(List<GListItem> items)
    //{
    //    if (items.Count > 0)
    //    {
    //        GListItem item = items[items.Count - 1];
    //        if (item != null)
    //        {
    //            if (_pool.PutIn(item))
    //            {
    //                GNewUITools.SetVisible(item.RectTrans, false);
    //            }
    //            else
    //            {
    //                Destroy(item.gameObject);
    //            }
    //        }

    //        items.RemoveAt(items.Count - 1);
    //    }
    //}

    private void UpdateItem(List <GListItem> items, int pos, bool is_need_init)
    {
        //Debug.Log("UpdateItem " + pos);

        GListItem item = null;

        if (items.Count > pos)
        {
            item = items[pos];
        }
        else
        {
            item = TryCreateItem();
            items.Add(item);
            //OnAddItem(item.gameObject, item.index);
        }

        AdjustItemAnchor(item.RectTrans);
        item.SetPosition(Index2Pos2(pos, item.RectTrans));
        //item.RectTrans.anchoredPosition = Index2Pos2(pos, item.RectTrans);
        //item.SetLocalPosition(Index2Pos2(pos, item.RectTrans));

        item.UpdateItem(pos, is_need_init);

        if (SingleSelect)
        {
            item.IsOn = (_SingleSelectIndex == pos);
        }
    }
Exemplo n.º 5
0
    //private void DisposeItem(List<GListItem> items)
    //{
    //    if (items.Count > 0)
    //    {
    //        GListItem item = items[items.Count - 1];
    //        if (item != null)
    //        {
    //            if (_pool.PutIn(item))
    //            {
    //                GNewUITools.SetVisible(item.RectTrans, false);
    //            }
    //            else
    //            {
    //                Destroy(item.gameObject);
    //            }
    //        }
    //        items.RemoveAt(items.Count - 1);
    //    }
    //}

    private void UpdateItem(List <GListItem> items, int pos, int index)
    {
        if (items.Count > pos)
        {
            //Debug.Log("UpdateItem " + pos + " " + index);
            if (items[pos] == null)
            {
                items[pos] = TryCreateItem();
            }

            GListItem item = items[pos];

            //dont want to wast time here
            //SetPivotAnchor(item.RectTrans, _Align);

            AdjustItemAnchor(item.RectTrans);

            item.SetPosition(Index2Pos2(index, item.RectTrans));
            //item.gameObject.SetActive(id < this._DataCount);
            //item.SetLocalPosition(Index2Pos2(index, item.RectTrans));

            item.UpdateItem(index, true);

            if (SingleSelect)
            {
                item.IsOn = (_SingleSelectIndex == index);
            }
        }
    }
Exemplo n.º 6
0
    protected virtual void UpdateItem(List <GListItem> items, int pos)
    {
        //Debug.Log("UpdateItem " + pos);

        GListItem item = null;

        if (items.Count > pos)
        {
            item = items[pos];
        }
        else
        {
            item = TryCreateItem();
            if (item != null)
            {
                items.Add(item);
                //OnAddItem(item.gameObject, item.index);
            }
        }

        if (item != null)
        {
            item.UpdateItem(pos, true);
        }
    }
Exemplo n.º 7
0
    protected override Vector2 GetItemSize(GListItem item, float x, float y, float fx, float fy)
    {
        Vector2 real_size = new Vector2();

        if (item != null)
        {
            RectTransform rt = item.RectTrans;

            item.SetPosition(AlignXY(rt, y, fy));
            //rt.anchoredPosition = AlignXY(rt, y, fy);
            //item.SetLocalPosition(AlignXY(rt, y, fy));

            real_size.x = rt.sizeDelta.x;
            real_size.y = rt.sizeDelta.y;

            y += real_size.y * fy;

            if (item.index == MainSelected)
            {
                //float dsx = SubViewTemplate.sizeDelta.x;
                //float dsy = SubViewTemplate.sizeDelta.y /* * rt.localScale.y*/;

                Vector2 size = SubViewTemplate.rect.size;

                SubViewTemplate.anchoredPosition = AlignXY(SubViewTemplate, y, fy);

                real_size.x  = Mathf.Max(size.x, real_size.x);
                real_size.y += size.y;
            }
        }

        return(real_size);
    }
Exemplo n.º 8
0
    public void SetSelection(int index)
    {
        if (SingleSelect)
        {
            if (_SingleSelectIndex != index)
            {
                GListItem item_com = GetListItem(_SingleSelectIndex);
                if (item_com != null)
                {
                    item_com.IsOn = false;
                }
                _SingleSelectIndex = index;

                item_com = GetListItem(_SingleSelectIndex);
                if (item_com != null)
                {
                    item_com.IsOn = true;
                }
                else
                {
                    _SingleSelectIndex = -1;
                }
            }
        }
    }
Exemplo n.º 9
0
    //no-base call
    public override void AddItem(int index, int count)
    {
        SafeInit();

        if (index < 0 || index > _ItemCount)
        {
            HobaDebuger.LogWarning("<GNewList> AddItem: index out of range! ");
            return;
        }

        if (count < 1)
        {
            return;
        }

        _ItemCount += count;
        RecalculateBound();

        //InternalUpdateContent(index);

        for (int i = 0; i < count; i++)
        {
            GListItem g_item = TryCreateItem();
            _viewItems.Insert(index + i, g_item);
            UpdateItem(_viewItems, index + i, true);
        }

        for (int i = index + count, max = _viewItems.Count; i < max; i++)
        {
            UpdateItem(_viewItems, i, false);
        }
    }
Exemplo n.º 10
0
 private void SwitchItem(GListItem item, bool on)
 {
     if (item != null)
     {
         item.IsOn = on;
     }
 }
Exemplo n.º 11
0
    public void AddItem(int index)
    {
        if (index < 0 || index > _ItemCount)
        {
            HobaDebuger.LogWarning("<GNewLayoutTable> AddItem: index out of range! ");
            return;
        }

        //InsertItem(_ViewItems, index);

        GListItem item = null;

        item = TryCreateItem();
        if (item != null)
        {
            _ViewItems.Insert(index, item);
            _ItemCount = _ViewItems.Count;

            //OnAddItem(item.gameObject, item.index);
            item.UpdateItem(index, true);

            for (int i = index + 1, max = _ViewItems.Count; i < max; i++)
            {
                _ViewItems[i].UpdateItem(i, false);
                _ViewItems[i].RectTrans.SetAsLastSibling();
            }

            if (_MainSelection >= index)
            {
                _MainSelection += 1;
            }

            //RepositionItems();
        }
    }
Exemplo n.º 12
0
    private void SwapItem(List <GListItem> items, int destPos, int srcPos)
    {
        //Debug.Log("swap " + destPos + " " + srcPos);

        GListItem tmp = items[destPos];

        items[destPos] = items[srcPos];
        items[srcPos]  = tmp;
    }
Exemplo n.º 13
0
    protected GListItem TryCreateItem()
    {
        GListItem rv = null;

#if IN_GAME
        rv = _Pool.TakeOut();
#endif

        if (rv == null)
        {
            RectTransform item = CUnityUtil.Instantiate(_CellRect) as RectTransform;
            item.SetParent(Trans, false);

            GListItem item_com = item.GetComponent <GListItem>();
            if (item_com == null)
            {
                item_com = item.gameObject.AddComponent <GListItem>();
            }

            //register events
            if (this.InitItemCallBack != null)
            {
                item_com.OnItemInit = this.OnShowItem;
            }

            if (this.ClickItemCallBack != null)
            {
                item_com.OnItemClick = this.OnClickItem;
            }

            //if (this.PressItemCallBack != null)
            //{
            //    item_com.OnItemPointerDown = this.OnPressItem;
            //}

            //if (this.ReleaseItemCallBack != null)
            //{
            //    item_com.OnItemPointerUp = this.OnReleaseItem;
            //}

            if (this.LongPressCallBack != null)
            {
                item_com.OnItemLongPress = this.OnLongPressItem;
            }

            if (HasChildButton && this.ClickItemButtonCallBack != null)
            {
                item_com.OnItemClickButton = this.OnClickItemButton;
            }

            rv = item_com;
        }

        GNewUITools.SetVisible(rv.RectTrans, true);

        return(rv);
    }
Exemplo n.º 14
0
    public GameObject GetItem(int index)
    {
        GListItem g_item = GetListItem(index);

        if (g_item != null)
        {
            return(g_item.gameObject);
        }
        return(null);
    }
Exemplo n.º 15
0
    //animation
    //private GTweenUIBase[] _tweenList;

    public static GListItem Get(GameObject g)
    {
        GListItem gListitem = g.GetComponent <GListItem>();

        if (gListitem == null)
        {
            gListitem = g.AddComponent <GListItem>();
        }
        return(gListitem);
    }
Exemplo n.º 16
0
    public void RefreshItem(int i_index)
    {
        GListItem git = GetListItem(i_index);

        if (git != null)
        {
            //OnShowItem(git.gameObject, git.index);
            git.UpdateItem(i_index, true);
        }
    }
Exemplo n.º 17
0
 public void SetManualSelection(int index, bool is_on)
 {
     if (!SingleSelect)
     {
         GListItem item = GetListItem(index);
         if (item != null)
         {
             item.IsOn = is_on;
         }
     }
 }
Exemplo n.º 18
0
 public virtual void ScrollToStep(int index)
 {
     if (IsInited)
     {
         GListItem item = GetListItem(index);
         if (item != null)
         {
             ScrollToPosition(Mathf.Abs(item.RectTrans.anchoredPosition.y) - Spacing.y);
         }
     }
 }
Exemplo n.º 19
0
 public override GListItem GetListItem(int index)
 {
     if (IsInited)
     {
         int offset = index - _viewRange.left * PageDiv;
         if (offset > -1 && offset < _viewItems.Count)
         {
             GListItem item = _viewItems[offset];
             return(item);
         }
     }
     return(null);
 }
Exemplo n.º 20
0
    private void OnShowItem(GameObject item, int index)
    {
        GListItem git = GetListItem(index);

        if (git != null)
        {
            git.IsOn = git.index == MainSelected;
        }
        if (InitItemCallBack != null)
        {
            InitItemCallBack(this.gameObject, item, index, -1);
        }
    }
Exemplo n.º 21
0
    //public void UpdateSelection(int index1, int index2)
    //{
    //    SetSelection(index1, index2);
    //}

    float CalcPosY(int id)
    {
        GListItem item = GetListItem(id);

        if (item)
        {
            Rect    old_subRT  = item.RectTrans.rect;
            Vector3 old_subPos = item.RectTrans.localPosition;

            return(old_subPos.y + old_subRT.yMax);
        }

        return(0);
    }
Exemplo n.º 22
0
 public override GListItem GetListItem(int index)
 {
     if (IsInited)
     {
         if (index > -1 && index < _viewItems.Count)
         {
             GListItem item = _viewItems[index];
             if (item != null)
             {
                 return(item);
             }
         }
     }
     return(null);
 }
Exemplo n.º 23
0
 private void SwitchItem(GListItem item, bool on)
 {
     if (item != null)
     {
         item.IsOn = on;
         if (on)
         {
             GUISound.PlaySoundClip(GUISound.PlayType.RollDown);
         }
         else
         {
             GUISound.PlaySoundClip(GUISound.PlayType.RollUp);
         }
     }
 }
Exemplo n.º 24
0
    private void SetSelection(int main_index)
    {
        int last_MainSelected = MainSelected;

        if (MainSelected != main_index)
        {
            MainSelected = main_index;

            GListItem git = GetListItem(last_MainSelected);
            SwitchItem(git, false);

            git = GetListItem(MainSelected);
            SwitchItem(git, true);
        }
    }
Exemplo n.º 25
0
    protected void RepositionItems()
    {
        int i;
        //int index;
        float width  = _Content.sizeDelta.x;
        float height = 0;
        float offset = 0;
        float x      = 0;
        float y      = 0;
        //float max;

        float fx = 1;
        float fy = -1;

        //x = _Spacing.x;
        //y = _Spacing.y * fy;

        for (i = 0; i < _ViewItems.Count; i++)
        {
            //index = i;
            GListItem item = _ViewItems[i];
            if (item == null || !item.gameObject.activeSelf /*|| layout.RectTrans.sizeDelta.x <= 0 || layout.RectTrans.sizeDelta.y <= 0*/ || item.RectTrans.localScale.x < Mathf.Epsilon)
            {
                continue;
            }

            Vector2 cell_size = GetItemSize(item, x, y, fx, fy);

            //max = Mathf.Abs(x) + cell_size.x;
            if (cell_size.y > offset)  //一行中最高的那一个
            {
                offset = cell_size.y;
            }

            y += offset * fy;
            if (i < _ViewItems.Count - 1)
            {
                y += _Spacing.y * fy;
            }
            offset = 0;
        }
        //width += _Spacing.x;
        y     += offset * fy;
        y     += _Spacing.y * fy;
        height = Mathf.Abs(y);

        _Content.sizeDelta = new Vector2(width, height);
    }
Exemplo n.º 26
0
    public void SelectItem(int main_index)
    {
        SetSelection(main_index);

        if (main_index != -1)
        {
            GListItem git = GetListItem(MainSelected);
            if (git != null)
            {
                if (ClickItemCallBack != null)
                {
                    ClickItemCallBack(this.gameObject, git.gameObject, main_index);
                }
            }
        }
    }
Exemplo n.º 27
0
    private void OnShowSubItem(GameObject list, GameObject item, int index)
    {
        if (_SubList == null)
        {
            return;
        }
        GListItem git = _SubList.GetListItem(index);

        if (git != null)
        {
            git.IsOn = git.index == SubSelected;
        }

        if (InitItemCallBack != null)
        {
            InitItemCallBack(this.gameObject, item, MainSelected, index);
        }
    }
Exemplo n.º 28
0
    protected virtual Vector2 GetItemSize(GListItem item, float x, float y, float fx, float fy)
    {
        Vector2 real_size = new Vector2();

        if (item != null)
        {
            RectTransform rt = item.RectTrans;
            item.SetPosition(AlignXY(rt, y, fy));
            //item.SetLocalPosition(AlignXY(rt, y, fy));
            //rt.anchoredPosition = AlignXY(rt, y, fy);

            real_size = rt.rect.size;

            y += real_size.y * fy;
        }

        return(real_size);
    }
Exemplo n.º 29
0
    public void SetSelection(int index1, int index2)
    {
        //if (index2 == -1 && index1 == MainSelected)
        //{
        //    index1 = -1;
        //}

        LastMainSelected = MainSelected;

        if (MainSelected != index1)
        {
            MainSelected = index1;

            LastSubSelected = -1;
            SubSelected     = index2;
            if (SubSelected == -1)
            {
                SubSelected = DefaultSubNotSelected ? -1 : 0;
            }

            GListItem git = GetListItem(LastMainSelected);
            SwitchItem(git, false);

            git = GetListItem(MainSelected);
            SwitchItem(git, true);
        }
        else
        {
            if (_SubList != null)
            {
                if (SubSelected != index2 && index2 != -1)
                {
                    LastSubSelected = SubSelected;
                    SubSelected     = index2;

                    GListItem git = _SubList.GetListItem(LastSubSelected);
                    SwitchItem(git, false);

                    git = _SubList.GetListItem(SubSelected);
                    SwitchItem(git, true);
                }
            }
        }
    }
Exemplo n.º 30
0
    protected override GListItem TryCreateItem()
    {
        GListItem rv = base.TryCreateItem();

        if (rv != null)
        {
            //register events
            if (this.InitItemCallBack != null)
            {
                rv.OnItemInit = this.OnShowItem;
            }

            if (this.ClickItemCallBack != null)
            {
                rv.OnItemClick = this.OnClickItem;
            }
        }
        return(rv);
    }