using vnxbqy.UI;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
public class ChooseItemsWin : Window
|
{
|
[SerializeField] TextEx txtName;
|
[SerializeField] TextEx txtChooseNum;
|
[SerializeField] ButtonEx btnClose;
|
[SerializeField] ButtonEx btnUse;
|
[SerializeField] ScrollerController scroller;
|
[SerializeField] NumKeyBoard numKeyboard;
|
[SerializeField] Transform clickOther;
|
ChooseItemsModel model { get { return ModelCenter.Instance.GetModel<ChooseItemsModel>(); } }
|
BoxGetItemModel boxModel { get { return ModelCenter.Instance.GetModel<BoxGetItemModel>(); } }
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
protected override void BindController()
|
{
|
btnClose.SetListener(OnClickClose);
|
btnUse.SetListener(OnClickUse);
|
numKeyboard.onConfirm.AddListener(OnClickConfirmBtn);
|
numKeyboard.onValueChange.AddListener(OnClickNum);
|
}
|
|
private void OnClickConfirmBtn(bool arg0)
|
{
|
if (arg0)
|
{
|
numKeyboard.SetActive(false);
|
model.countChangeAction?.Invoke();
|
}
|
}
|
|
private void OnClickNum()
|
{
|
ItemModel itemModel = packModel.GetItemByGuid(boxModel.guid);
|
if (itemModel == null)
|
return;
|
int useNum = int.Parse(numKeyboard.Value);
|
if (model.GetAllOtherCount() + useNum > model.totalItemCount)
|
{
|
useNum = model.totalItemCount - model.GetAllOtherCount();
|
ServerTipDetails.DisplayNormalTip(Language.Get("MaxUseNum"));
|
}
|
numKeyboard.Value = useNum.ToString();
|
model.UpdateUserChooseItemDict(model.chooseKeyBoardItemId, itemModel.guid, int.Parse(numKeyboard.Value), model.chooseKeyBoardItemId);
|
}
|
|
protected override void OnPreOpen()
|
{
|
model.countChangeAction += OnCountChangeAction;
|
model.openKeyBoardAction += OnOpenKeyBoardAction;
|
scroller.OnRefreshCell += OnRefreshCell;
|
numKeyboard.SetActive(false);
|
clickOther.SetActive(false);
|
Display();
|
}
|
|
protected override void OnPreClose()
|
{
|
model.countChangeAction -= OnCountChangeAction;
|
model.openKeyBoardAction -= OnOpenKeyBoardAction;
|
scroller.OnRefreshCell -= OnRefreshCell;
|
}
|
|
private void OnOpenKeyBoardAction()
|
{
|
clickOther.SetActive(true);
|
numKeyboard.SetActive(true);
|
}
|
|
private void OnCountChangeAction()
|
{
|
scroller.m_Scorller.RefreshActiveCellViews();
|
Display();
|
}
|
|
protected override void OnAfterOpen()
|
{
|
CreateScroller();
|
}
|
|
protected override void OnAfterClose()
|
{
|
|
}
|
|
protected override void AddListeners()
|
{
|
|
}
|
|
private void OnRefreshCell(ScrollerDataType type, CellView cell)
|
{
|
var _cell = cell as ChooseItemsCell;
|
_cell.Display(_cell.index);
|
}
|
|
void Display()
|
{
|
if (!ItemConfig.Has(boxModel.itemId))
|
return;
|
ItemConfig itemConfig = ItemConfig.Get(boxModel.itemId);
|
txtName.text = itemConfig.ItemName;
|
txtName.color = UIHelper.GetUIColor(itemConfig.ItemColor, true);
|
int nowChooseItemCount = model.GetNowChooseItemCount();
|
int totalItemCount = model.totalItemCount;
|
txtChooseNum.text = Language.Get("BlessedLand036", nowChooseItemCount, totalItemCount);
|
txtChooseNum.colorType = nowChooseItemCount <= totalItemCount ? TextColType.DarkGreen : TextColType.Red;
|
}
|
|
void CreateScroller()
|
{
|
var list = model.GetShowList();
|
scroller.Refresh();
|
for (int i = 0; i < list.Count; i++)
|
{
|
scroller.AddCell(ScrollerDataType.Header, list[i]);
|
}
|
scroller.Restart();
|
}
|
|
void OnClickUse()
|
{
|
if (model.TrySendUse())
|
{
|
CloseImmediately();
|
}
|
|
}
|
|
void OnClickClose()
|
{
|
CloseImmediately();
|
}
|
}
|
|
|