using System;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace vnxbqy.UI
|
{
|
|
public class CustomizedGiftChooseWin : Window
|
{
|
[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;
|
CustomizedRechargeModel model { get { return ModelCenter.Instance.GetModel<CustomizedRechargeModel>(); } }
|
VipModel vipModel { get { return ModelCenter.Instance.GetModel<VipModel>(); } }
|
int index;
|
int actCtgIndex;
|
#region Built-in
|
protected override void BindController()
|
{
|
}
|
|
protected override void AddListeners()
|
{
|
closeBtn.SetListener(CloseClick);
|
|
closeBtn2.SetListener(CloseClick);
|
|
okBtn.SetListener(ChooseItem);
|
}
|
|
|
protected override void OnPreOpen()
|
{
|
model.InitChoose();
|
m_Controller.OnRefreshCell += OnRefreshCell;
|
model.UpdateWin += OnUpdateWin;
|
vipModel.rechargeCountEvent += VipModel_rechargeCountEvent;
|
Display();
|
}
|
void VipModel_rechargeCountEvent(int obj)
|
{
|
if (model.chooseCTGID == obj)
|
{
|
CloseClick();
|
}
|
}
|
|
protected override void OnAfterOpen()
|
{
|
DisplayScroll();
|
}
|
|
protected override void OnPreClose()
|
{
|
m_Controller.OnRefreshCell -= OnRefreshCell;
|
model.UpdateWin -= OnUpdateWin;
|
vipModel.rechargeCountEvent -= VipModel_rechargeCountEvent;
|
}
|
|
void OnUpdateWin()
|
{
|
Display();
|
m_Controller.m_Scorller.RefreshActiveCellViews();
|
}
|
|
protected override void OnAfterClose()
|
{
|
|
}
|
#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(model.chooseCTGID);
|
var selectItemInfo = ctgConfig.SelectItemInfo[model.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(model.chooseCTGID);
|
var selectItemInfo = ctgConfig.SelectItemInfo[model.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 = model.GetChooseSubIndex(i);
|
if (chooseIndex != 0)
|
{
|
int selectID = ctgConfig.SelectItemInfo[i][chooseIndex - 1];
|
var itemData = new ItemCellModel(CTGSelectItemConfig.Get(selectID).ItemID, false, (ulong)CTGSelectItemConfig.Get(selectID).ItemCount);
|
itemCellList[i].Init(itemData);
|
if (i == model.chooseWinIndex)
|
{
|
selectItemID = CTGSelectItemConfig.Get(selectID).ItemID;
|
selectIemCount = CTGSelectItemConfig.Get(selectID).ItemCount;
|
}
|
}
|
else
|
{
|
itemCellList[i].Init(null);
|
}
|
|
int index = i;
|
itemCellList[i].button.SetListener(() =>
|
{
|
if (model.chooseWinIndex != index)
|
{
|
model.chooseWinIndex = index;
|
Display();
|
DisplayScroll();
|
}
|
});
|
|
imageList[i].SetActive(i == model.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(model.chooseCTGID);
|
if (ctgConfig.SelectItemInfo.Length != model.chooseIndexDict.Count)
|
{
|
SysNotifyMgr.Instance.ShowTip("CustomizedGift01");
|
return;
|
}
|
|
CA126_tagCMSelectCTGItem pack = new CA126_tagCMSelectCTGItem();
|
pack.RecordID = (ushort)model.chooseCTGID;
|
pack.SelectItemValue = model.GetSelectedItemValue();
|
GameNetSystem.Instance.SendInfo(pack);
|
}
|
}
|
}
|