using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
public class ChooseItemWin : Window
|
{
|
[SerializeField] SelectBoxItemCell chooseCell;
|
[SerializeField] Transform getItemParent;
|
[SerializeField] Button chooseBtn;
|
[SerializeField] Button closeBtn;
|
[SerializeField] Button numBtn;
|
[SerializeField] Button plusBtn;
|
[SerializeField] Button reduceBtn;
|
[SerializeField] Text numText;
|
[SerializeField] NumKeyBoard numKeyboard;
|
|
BoxGetItemModel boxModel;
|
BoxGetItemModel BoxModel
|
{
|
get { return boxModel ?? (boxModel = ModelCenter.Instance.GetModel<BoxGetItemModel>()); }
|
}
|
|
PlayerPackModel _playerPack;
|
PlayerPackModel playerPack
|
{
|
get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PlayerPackModel>()); }
|
}
|
|
ItemTipsModel _itemTipsModel;
|
ItemTipsModel itemTipsModel
|
{
|
get
|
{
|
return _itemTipsModel ?? (_itemTipsModel = ModelCenter.Instance.GetModel<ItemTipsModel>());
|
}
|
}
|
|
int chooseId = 0;
|
int useNum = 1;
|
List<SelectBoxItemCell> GetList = new List<SelectBoxItemCell>();
|
|
public static event Action<int> RefreshChooseCellAct;
|
|
protected override void BindController()
|
{
|
|
}
|
|
protected override void AddListeners()
|
{
|
reduceBtn.onClick.AddListener(OnClickReduceBuyNum);
|
plusBtn.onClick.AddListener(OnClickPlusBuyNum);
|
numBtn.onClick.AddListener(OnClickCountBtn);
|
numKeyboard.onConfirm.AddListener(OnClickConfirmBtn);
|
numKeyboard.onValueChange.AddListener(OnClickNum);
|
}
|
|
protected override void OnPreOpen()
|
{
|
useNum = 1;
|
numKeyboard.gameObject.SetActive(false);
|
chooseCell.gameObject.SetActive(false);
|
chooseBtn.AddListener(ClickChooseBtn);
|
closeBtn.AddListener(CloseWin);
|
chooseId = 0;
|
CreateChooseCell();
|
numText.text = useNum.ToString();
|
}
|
|
protected override void OnAfterOpen()
|
{
|
|
}
|
|
protected override void OnPreClose()
|
{
|
BoxModel.selectDict = null;
|
chooseBtn.RemoveAllListeners();
|
closeBtn.RemoveAllListeners();
|
}
|
|
protected override void OnAfterClose()
|
{
|
|
}
|
|
private void OnClickCountBtn()
|
{
|
numKeyboard.gameObject.SetActive(true);
|
}
|
|
private void OnClickNum()
|
{
|
ItemModel itemModel = playerPack.GetItemModelByGUID(boxModel.guid);
|
if (itemModel == null) return;
|
|
useNum = int.Parse(numKeyboard.Value);
|
|
if (useNum > itemModel.count)
|
{
|
useNum = itemModel.count;
|
ServerTipDetails.DisplayNormalTip(Language.Get("MaxUseNum"));
|
}
|
else if(useNum < 1)
|
{
|
useNum = 1;
|
}
|
|
numKeyboard.Value = useNum.ToString();
|
numText.text = useNum.ToString();
|
}
|
|
private void OnClickConfirmBtn(bool arg0)
|
{
|
if (arg0)
|
{
|
numText.text = useNum.ToString();
|
numKeyboard.gameObject.SetActive(false);
|
}
|
}
|
|
|
private void OnClickPlusBuyNum()
|
{
|
ItemModel itemModel = playerPack.GetItemModelByGUID(boxModel.guid);
|
if (itemModel == null) return;
|
|
useNum += 1;
|
|
if(useNum > itemModel.count)
|
{
|
useNum = itemModel.count;
|
ServerTipDetails.DisplayNormalTip(Language.Get("MaxUseNum"));
|
}
|
|
numText.text = useNum.ToString();
|
}
|
|
private void OnClickReduceBuyNum()
|
{
|
useNum -= 1;
|
if(useNum < 1)
|
{
|
useNum = 1;
|
}
|
numText.text = useNum.ToString();
|
}
|
|
private void CreateChooseCell()
|
{
|
if(BoxModel.selectDict == null) return;
|
|
DestroyGetItemlist();
|
GetList.Clear();
|
DebugEx.Log("CreateChooseCell" + BoxModel.selectDict.Count);
|
foreach(int id in BoxModel.selectDict.Keys)
|
{
|
int itemId = id;
|
SelectBoxItemCell item = Instantiate(chooseCell);
|
item.transform.SetParent(getItemParent);
|
item.transform.localPosition = Vector3.zero;
|
item.transform.localScale = Vector3.one;
|
item.name = StringUtility.Contact("ChooseCell",id);
|
item.gameObject.SetActive(true);
|
item.InitModel(id);
|
GetList.Add(item);
|
item.chooseCellBtn.RemoveAllListeners();
|
item.chooseCellBtn.AddListener(() =>
|
{
|
ClickChooseCell(itemId);
|
});
|
}
|
}
|
|
private void DestroyGetItemlist()
|
{
|
for (int i = 0; i < GetList.Count; i++)
|
{
|
Destroy(GetList[i].gameObject);
|
}
|
}
|
private void ClickChooseCell(int itemId)
|
{
|
if (chooseId == itemId)
|
{
|
ItemAttrData attrData = new ItemAttrData(itemId,true);
|
itemTipsModel.SetItemTipsModel(attrData);
|
}
|
|
chooseId = itemId;
|
if(RefreshChooseCellAct != null)
|
{
|
RefreshChooseCellAct(itemId);
|
}
|
}
|
|
private void ClickChooseBtn()
|
{
|
if(chooseId == 0)
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("ItemSwith_Z"));
|
return;
|
}
|
ItemModel itemModel = playerPack.GetItemModelByGUID(BoxModel.guid);
|
if(itemModel != null)
|
{
|
ItemOperateUtility.Instance.UseItem(itemModel.itemPlace,useNum,chooseId);
|
}
|
CloseImmediately();
|
}
|
|
private void CloseWin()
|
{
|
CloseImmediately();
|
}
|
|
}
|
}
|