using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
using DG.Tweening;
|
|
using System.Linq;
|
|
namespace Snxxz.UI
|
{
|
public class HappyXBGetItemWin : Window
|
{
|
[SerializeField] GameObject getItem;
|
[SerializeField] RectTransform getItemParent;
|
[SerializeField] Button backBtn;
|
[SerializeField] Button xbBtn;
|
[SerializeField] Text xbBtnText;
|
[SerializeField] Text xbMoneyText;
|
[SerializeField] Button xbManyBtn;
|
[SerializeField] Text xbManyBtnText;
|
[SerializeField] Text xbManyMoneyText;
|
[SerializeField] Text xbScoreText;
|
[SerializeField] Text freeXBTimeText;
|
[SerializeField] float scaleTime = 0.2f;
|
[Header("有寻宝道具")]
|
[SerializeField] GameObject container_XBTool;
|
[SerializeField] Text haveToolText;
|
[SerializeField] Button makeUseToolBtn;
|
[SerializeField] GameObject selectUseToolImg;
|
[Header("消耗金钱或道具")]
|
[SerializeField] GameObject costMoneyObj;
|
[SerializeField] GameObject costToolObj;
|
[SerializeField] GameObject costManyMoneyObj;
|
[SerializeField] GameObject costManyToolObj;
|
[SerializeField] Text costToolNumText;
|
[SerializeField] Text costToolManyText;
|
|
HappyXBModel XBModel { get { return ModelCenter.Instance.GetModel<HappyXBModel>(); } }
|
PackModel playerPack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
ItemTipsModel _itemTipsModel;
|
ItemTipsModel itemTipsModel
|
{
|
get
|
{
|
return _itemTipsModel ?? (_itemTipsModel = ModelCenter.Instance.GetModel<ItemTipsModel>());
|
}
|
}
|
|
bool isHaveFreeTime = false;
|
List<GameObject> GetItemlist = new List<GameObject>();
|
List<XBGetItemCell> getItemBasiclist = new List<XBGetItemCell>();
|
List<XBGetItem> xbItemlist;
|
int oneMoney = 0;
|
int manyMoney = 0;
|
bool isHaveXBTool = false;
|
bool isCostToolMany = false;
|
XBGetItemConfig xbItemConfig = null;
|
protected override void BindController()
|
{
|
|
}
|
|
protected override void AddListeners()
|
{
|
backBtn.AddListener(ClickBackBtn);
|
xbBtn.AddListener(ClickXBBtn);
|
xbManyBtn.AddListener(ClickXBManyBtn);
|
makeUseToolBtn.AddListener(ClickMakeUseTool);
|
}
|
|
protected override void OnPreOpen()
|
{
|
XBModel.StartXBEvent += OnStartXB;
|
getItem.SetActive(false);
|
isHaveFreeTime = XBModel.IsHaveFreeXBTime((int)XBModel.title);
|
InitUI();
|
TimeDownMgr.CoolTimeData data;
|
switch (XBModel.title)
|
{
|
case HappXBTitle.Best:
|
XBModel.RefreshBestXBTimeAct += RefreshFreeTime;
|
if (TimeDownMgr.Instance.Get(TimeDownMgr.CoolTimeType.HappyFreeBestXB, out data))
|
{
|
data.func = RefreshFreeTime;
|
RefreshFreeTime(Mathf.CeilToInt(data.duration - data.time));
|
}
|
else
|
{
|
RefreshFreeTime(0);
|
}
|
break;
|
case HappXBTitle.Rune:
|
XBModel.RefreshRuneXBTimeAct += RefreshFreeTime;
|
if (TimeDownMgr.Instance.Get(TimeDownMgr.CoolTimeType.HappyFreeRuneXB, out data))
|
{
|
data.func = RefreshFreeTime;
|
RefreshFreeTime(Mathf.CeilToInt(data.duration - data.time));
|
}
|
else
|
{
|
RefreshFreeTime(0);
|
}
|
break;
|
}
|
|
}
|
|
protected override void OnAfterOpen()
|
{
|
CheckHaveXBTool();
|
UpdateCostType();
|
}
|
|
protected override void OnPreClose()
|
{
|
switch (XBModel.title)
|
{
|
case HappXBTitle.Best:
|
XBModel.RefreshBestXBTimeAct -= RefreshFreeTime;
|
break;
|
case HappXBTitle.Rune:
|
XBModel.RefreshRuneXBTimeAct -= RefreshFreeTime;
|
break;
|
}
|
XBModel.StartXBEvent -= OnStartXB;
|
XBModel.rangelist.Clear();
|
DestroyGetItemlist();
|
GetItemlist.Clear();
|
getItemBasiclist.Clear();
|
}
|
|
protected override void OnAfterClose()
|
{
|
|
}
|
|
private void InitUI()
|
{
|
xbItemConfig = XBModel.GetXBItemConfigByType((int)XBModel.title);
|
CreateGetItem();
|
xbScoreText.text = XBModel.addXBScore.ToString();
|
for(int i = 0; i < xbItemlist.Count; i++)
|
{
|
var xbItem = xbItemlist[i];
|
int count = playerPack.GetItemCountByID(PackType.Treasure,xbItemlist[i].itemId);
|
if(count > 0)
|
{
|
XBModel.RefreshXBWarehouse();
|
}
|
}
|
}
|
|
private void ClickMakeUseTool()
|
{
|
bool isToolXB = !selectUseToolImg.activeInHierarchy;
|
selectUseToolImg.SetActive(isToolXB);
|
XBModel.SetUseToolXB(isToolXB);
|
UpdateCostType();
|
}
|
|
private void CheckHaveXBTool()
|
{
|
int xbToolCnt = 0;
|
int needToolCnt = 0;
|
isHaveXBTool = XBModel.IsHaveManyXBTool((int)XBModel.title, out xbToolCnt, out needToolCnt);
|
isCostToolMany = xbToolCnt >= needToolCnt;
|
container_XBTool.SetActive(isHaveXBTool);
|
selectUseToolImg.SetActive(XBModel.IsUseToolXB());
|
haveToolText.text = StringUtility.Contact("x",xbToolCnt);
|
}
|
|
private void UpdateCostType()
|
{
|
bool isToolXB = selectUseToolImg.activeInHierarchy;
|
costMoneyObj.SetActive(!isHaveXBTool || !isToolXB);
|
costToolObj.SetActive(isHaveXBTool && isToolXB);
|
costManyMoneyObj.SetActive(!isCostToolMany || !isToolXB);
|
costManyToolObj.SetActive(isCostToolMany && isToolXB);
|
XBFuncSet funcSet = XBModel.GetXBFuncSet((int)XBModel.title);
|
if (funcSet != null)
|
{
|
oneMoney = funcSet.xbPrices[0];
|
manyMoney = funcSet.xbPrices[1];
|
if (isHaveXBTool && isToolXB)
|
{
|
xbBtnText.text = Language.Get("HappyXB107", funcSet.xbNums[0]);
|
costToolNumText.text = Language.Get("HappyXB108", funcSet.costToolNums[0]);
|
}
|
else
|
{
|
xbBtnText.text = Language.Get("HappyXB103", funcSet.xbNums[0]);
|
xbMoneyText.text = oneMoney.ToString();
|
|
}
|
|
if(isCostToolMany && isToolXB)
|
{
|
xbManyBtnText.text = Language.Get("HappyXB107", funcSet.xbNums[1]);
|
costToolManyText.text = Language.Get("HappyXB108", funcSet.costToolNums[1]); ;
|
}
|
else
|
{
|
xbManyBtnText.text = Language.Get("HappyXB103", funcSet.xbNums[1]);
|
xbManyMoneyText.text = manyMoney.ToString();
|
}
|
}
|
}
|
|
private void RefreshFreeTime(float time)
|
{
|
if (isHaveFreeTime)
|
{
|
if (XBModel.IsHaveFreeXB((int)XBModel.title))
|
{
|
freeXBTimeText.gameObject.SetActive(false);
|
}
|
else
|
{
|
freeXBTimeText.gameObject.SetActive(true);
|
freeXBTimeText.text = Language.Get("HappyXB102", TimeUtility.SecondsToHMSCHSRetain((int)time));
|
}
|
}
|
else
|
{
|
freeXBTimeText.gameObject.SetActive(false);
|
}
|
|
}
|
|
private void CreateGetItem()
|
{
|
xbItemlist = XBModel.rangelist;
|
for (int i = 0; i < xbItemlist.Count; i++)
|
{
|
XBGetItem xbItem = xbItemlist[i];
|
GameObject item = Instantiate(getItem);
|
item.transform.SetParent(getItemParent);
|
item.transform.localPosition = Vector3.zero;
|
item.transform.localScale = Vector3.one;
|
item.name = StringUtility.Contact("CommonItemCell", i);
|
item.gameObject.SetActive(true);
|
XBGetItemCell itemBasic = item.transform.Find("CommonItemCell").GetComponent<XBGetItemCell>();
|
ItemCellModel cellModel = new ItemCellModel(xbItem.itemId, false, (ulong)xbItem.count);
|
itemBasic.Init(cellModel);
|
itemBasic.button.RemoveAllListeners();
|
itemBasic.button.AddListener(() =>
|
{
|
ItemAttrData attrData = new ItemAttrData(xbItem.itemId, false, (ulong)xbItem.count);
|
itemTipsModel.SetItemTipsModel(attrData);
|
|
});
|
itemBasic.transform.localScale = Vector3.zero;
|
itemBasic.transform.localPosition = Vector3.zero;
|
GetItemlist.Add(item);
|
itemBasic.gameObject.SetActive(false);
|
getItemBasiclist.Add(itemBasic);
|
}
|
|
ShowGetItemCtrl(0);
|
}
|
|
private void ShowGetItemCtrl(int index)
|
{
|
if (index < getItemBasiclist.Count)
|
{
|
getItemBasiclist[index].gameObject.SetActive(true);
|
getItemBasiclist[index].transform.DOScale(new Vector3(1, 1, 1), scaleTime).OnComplete(() =>
|
{
|
getItemBasiclist[index].SetUIEffect();
|
index += 1;
|
ShowGetItemCtrl(index);
|
});
|
|
var xbItem = xbItemlist[index];
|
bool isJump = false;
|
switch(XBModel.title)
|
{
|
case HappXBTitle.Best:
|
if(XBModel.isJumpBestXB)
|
{
|
isJump = true;
|
}
|
break;
|
case HappXBTitle.Rune:
|
if (XBModel.isJumpRuneXB)
|
{
|
isJump = true;
|
}
|
break;
|
}
|
if (isJump
|
&& xbItem.gridIndex == xbItemConfig.LuckyGridNum)
|
{
|
SoundPlayer.Instance.PlayUIAudio(67);
|
}
|
}
|
}
|
|
private void DestroyGetItemlist()
|
{
|
for(int i = 0; i < GetItemlist.Count; i++)
|
{
|
Destroy(GetItemlist[i]);
|
}
|
}
|
|
|
private void ClickXBBtn()
|
{
|
SendXBQuest(0);
|
}
|
|
private void ClickXBManyBtn()
|
{
|
SendXBQuest(1);
|
}
|
|
public int GetCostType(int xbNum)
|
{
|
if(xbNum == 0)
|
{
|
bool isFreeXB = isHaveFreeTime && XBModel.IsHaveFreeXB((int)XBModel.title);
|
if (isFreeXB) return 1;
|
if (costMoneyObj.activeInHierarchy) return 0;
|
}
|
else
|
{
|
if (costManyMoneyObj.activeInHierarchy) return 0;
|
}
|
|
return 2;
|
}
|
|
public void SendXBQuest(int xbNum)
|
{
|
if (!XBModel.CheckIsEmptyGrid(PackType.Treasure)) return;
|
|
int costType = GetCostType(xbNum);
|
bool isMoneyEnough = true;
|
if (xbNum == 0)
|
{
|
isMoneyEnough = UIHelper.GetMoneyCnt(1) >= (ulong)oneMoney;
|
}
|
else
|
{
|
isMoneyEnough = UIHelper.GetMoneyCnt(1) >= (ulong)manyMoney;
|
}
|
|
switch(costType)
|
{
|
case 0:
|
if (!isMoneyEnough)
|
{
|
WindowCenter.Instance.Open<RechargeTipWin>();
|
return;
|
}
|
break;
|
case 1:
|
case 2:
|
|
break;
|
}
|
|
switch (XBModel.title)
|
{
|
case HappXBTitle.Best:
|
XBModel.SendXBQuest(1, xbNum, costType);
|
break;
|
case HappXBTitle.Rune:
|
XBModel.SendXBQuest(2, xbNum, costType);
|
break;
|
}
|
}
|
|
private void OnStartXB(int oneOrMany)
|
{
|
ClickBackBtn();
|
}
|
|
private void ClickBackBtn()
|
{
|
CloseImmediately();
|
}
|
|
}
|
}
|