using System;  
 | 
using System.Collections.Generic;  
 | 
using UnityEngine;  
 | 
using UnityEngine.UI;  
 | 
  
 | 
  
 | 
public class CustomizedGiftChooseWin : UIBase  
 | 
{  
 | 
    [SerializeField] ScrollerController m_Controller;  
 | 
    [SerializeField] Text txtTitle;  
 | 
    [SerializeField] RichText txtInfo;  
 | 
    [SerializeField] List<CustomizedItemCell> itemCellList;  
 | 
    [SerializeField] List<ImageEx> imageList;  
 | 
    [SerializeField] Button closeBtn;  
 | 
    [SerializeField] Button closeBtn2;  
 | 
    [SerializeField] Button okBtn;  
 | 
  
 | 
    int index;  
 | 
    int actCtgIndex;  
 | 
    #region Built-in  
 | 
    protected override void InitComponent()  
 | 
    {  
 | 
        closeBtn.SetListener(CloseWindow);  
 | 
  
 | 
        closeBtn2.SetListener(CloseWindow);  
 | 
  
 | 
        okBtn.SetListener(ChooseItem);  
 | 
    }  
 | 
  
 | 
    protected override void OnPreOpen()  
 | 
    {  
 | 
        CustomizedRechargeModel.Instance.InitChoose();  
 | 
        m_Controller.OnRefreshCell += OnRefreshCell;  
 | 
        CustomizedRechargeModel.Instance.UpdateWin += OnUpdateWin;  
 | 
        RechargeManager.Instance.rechargeCountEvent += VipModel_rechargeCountEvent;  
 | 
        Display();  
 | 
    }  
 | 
    void VipModel_rechargeCountEvent(int obj)  
 | 
    {  
 | 
        if (CustomizedRechargeModel.Instance.chooseCTGID == obj)  
 | 
        {  
 | 
            CloseWindow();  
 | 
        }  
 | 
    }  
 | 
  
 | 
    protected override void OnOpen()  
 | 
    {  
 | 
        DisplayScroll();  
 | 
    }  
 | 
  
 | 
    protected override void OnPreClose()  
 | 
    {  
 | 
        m_Controller.OnRefreshCell -= OnRefreshCell;  
 | 
        CustomizedRechargeModel.Instance.UpdateWin -= OnUpdateWin;  
 | 
        RechargeManager.Instance.rechargeCountEvent -= VipModel_rechargeCountEvent;  
 | 
    }  
 | 
  
 | 
    void OnUpdateWin()  
 | 
    {  
 | 
        Display();  
 | 
        m_Controller.m_Scorller.RefreshActiveCellViews();  
 | 
    }  
 | 
  
 | 
  
 | 
    #endregion  
 | 
  
 | 
    private void OnRefreshCell(ScrollerDataType type, CellView cell)  
 | 
    {  
 | 
        var _cell = cell as CustomizedGiftChooseCell;  
 | 
        _cell.Display(_cell.index);  
 | 
    }  
 | 
  
 | 
    void DisplayScroll()  
 | 
    {  
 | 
        m_Controller.Refresh();  
 | 
        var ctgConfig = CTGConfig.Get(CustomizedRechargeModel.Instance.chooseCTGID);  
 | 
        var selectItemInfo = ctgConfig.SelectItemInfo[CustomizedRechargeModel.Instance.chooseWinIndex];  
 | 
        int count = selectItemInfo.Length;  
 | 
        int lineCount = (int)Math.Ceiling((double)count / 7);  
 | 
        for (int i = 0; i < lineCount; i++)  
 | 
        {  
 | 
            m_Controller.AddCell(ScrollerDataType.Header, i);  
 | 
        }  
 | 
        m_Controller.Restart();  
 | 
    }  
 | 
  
 | 
    void Display()  
 | 
    {  
 | 
        for (int i = 0; i < imageList.Count; i++)  
 | 
        {  
 | 
            imageList[i].SetActive(false);  
 | 
        }  
 | 
  
 | 
        var ctgConfig = CTGConfig.Get(CustomizedRechargeModel.Instance.chooseCTGID);  
 | 
        var selectItemInfo = ctgConfig.SelectItemInfo[CustomizedRechargeModel.Instance.chooseWinIndex];  
 | 
  
 | 
        int selectItemID = 0;  
 | 
        int selectIemCount = 0;  
 | 
        for (int i = 0; i < itemCellList.Count; i++)  
 | 
        {  
 | 
            if (i < ctgConfig.SelectItemInfo.Length)  
 | 
            {  
 | 
                itemCellList[i].SetActive(true);  
 | 
                int chooseIndex = CustomizedRechargeModel.Instance.GetChooseSubIndex(i);  
 | 
                if (chooseIndex != 0)  
 | 
                {  
 | 
                    int selectID = ctgConfig.SelectItemInfo[i][chooseIndex - 1];  
 | 
                    var itemData = new ItemCellModel(CTGSelectItemConfig.Get(selectID).ItemID, false, CTGSelectItemConfig.Get(selectID).ItemCount);  
 | 
                    itemCellList[i].Init(itemData);  
 | 
                    if (i == CustomizedRechargeModel.Instance.chooseWinIndex)  
 | 
                    {  
 | 
                        selectItemID = CTGSelectItemConfig.Get(selectID).ItemID;  
 | 
                        selectIemCount = CTGSelectItemConfig.Get(selectID).ItemCount;  
 | 
                    }  
 | 
                }  
 | 
                else  
 | 
                {  
 | 
                    itemCellList[i].Init(null);  
 | 
                }  
 | 
  
 | 
                int index = i;  
 | 
                itemCellList[i].button.SetListener(() =>  
 | 
                {  
 | 
                    if (CustomizedRechargeModel.Instance.chooseWinIndex != index)  
 | 
                    {  
 | 
                        CustomizedRechargeModel.Instance.chooseWinIndex = index;  
 | 
                        Display();  
 | 
                        DisplayScroll();  
 | 
                    }  
 | 
                });  
 | 
  
 | 
                imageList[i].SetActive(i == CustomizedRechargeModel.Instance.chooseWinIndex);  
 | 
  
 | 
            }  
 | 
            else  
 | 
            {  
 | 
                itemCellList[i].SetActive(false);  
 | 
            }  
 | 
        }  
 | 
  
 | 
        if (selectItemID > 0)  
 | 
        {  
 | 
            txtTitle.SetActive(true);  
 | 
            txtInfo.SetActive(true);  
 | 
            txtTitle.text = StringUtility.Contact(ItemConfig.Get(selectItemID).ItemName, " x", selectIemCount);  
 | 
            txtInfo.text = ItemConfig.Get(selectItemID).Description;  
 | 
        }  
 | 
        else  
 | 
        {  
 | 
            txtTitle.SetActive(false);  
 | 
            txtInfo.SetActive(false);  
 | 
        }  
 | 
    }  
 | 
  
 | 
    void ChooseItem()  
 | 
    {  
 | 
        var ctgConfig = CTGConfig.Get(CustomizedRechargeModel.Instance.chooseCTGID);  
 | 
        if (ctgConfig.SelectItemInfo.Length != CustomizedRechargeModel.Instance.chooseIndexDict.Count)  
 | 
        {  
 | 
            SysNotifyMgr.Instance.ShowTip("CustomizedGift01");  
 | 
            return;  
 | 
        }  
 | 
          
 | 
        CA126_tagCMSelectCTGItem pack = new CA126_tagCMSelectCTGItem();  
 | 
        pack.RecordID = (ushort)CustomizedRechargeModel.Instance.chooseCTGID;  
 | 
        pack.SelectItemValue = CustomizedRechargeModel.Instance.GetSelectedItemValue();  
 | 
        GameNetSystem.Instance.SendInfo(pack);  
 | 
    }  
 | 
}  
 | 
  
 | 
  
 | 
  
 | 
  
 |