//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Tuesday, June 11, 2019
|
//--------------------------------------------------------
|
|
using vnxbqy.UI;
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
using DG.Tweening;
|
|
|
|
public class GodKingRandomGiftWin : ILWindow
|
{
|
|
Button closeBtn;
|
Button resetBtn;
|
Text resetCnt;
|
Button randomBtn;
|
Text lsMoney;
|
Image moneyImg;
|
Text useMoney;
|
Text freeTip;
|
List<Transform> items = new List<Transform>();
|
Toggle skipAnim;
|
|
//物品初始坐标
|
List<Vector3> itemStartPos = new List<Vector3>() {
|
new Vector3(18, 195, 0),
|
new Vector3(188, 68, 0),
|
new Vector3(-214, -75, 0),
|
new Vector3(-233, 117, 0),
|
new Vector3(256, -123, 0),
|
new Vector3(-483, 90, 0),
|
new Vector3(-461, -125, 0),
|
new Vector3(0, -99, 0),
|
new Vector3(415, 154, 0),
|
new Vector3(486, -90, 0),
|
};
|
|
Vector3[] path1 = new Vector3[] {
|
new Vector3(0, 0, 0),
|
new Vector3(73, 35 , 0),
|
new Vector3(140 , -58 , 0),
|
new Vector3(25 , -115 , 0),
|
new Vector3(-112 , -66 , 0),
|
new Vector3(-108 , 68 , 0) ,
|
new Vector3(8 , 115 , 0),
|
new Vector3(175 , 90 , 0),
|
new Vector3(275 , -15 , 0),
|
new Vector3(216 , -146 , 0),
|
new Vector3(18 , -198 , 0),
|
new Vector3(-200 , -155 , 0),
|
new Vector3(-273 , 6 , 0),
|
new Vector3(-162 , 169 , 0),
|
new Vector3(0, 195 , 0)
|
};
|
|
|
List<int> showItemIndex = new List<int>(); //还未抽中的物品索引
|
PackModel playerPack { get { return ModelCenter.Instance.GetModelEx<PackModel>(); } }
|
|
|
#region Built-in
|
protected override void BindController()
|
{
|
closeBtn = proxy.GetWidgtEx<Button>("Button_Close");
|
resetBtn = proxy.GetWidgtEx<Button>("reset");
|
resetCnt = proxy.GetWidgtEx<Text>("resetcnt");
|
randomBtn = proxy.GetWidgtEx<Button>("random");
|
lsMoney = proxy.GetWidgtEx<Text>("lsmoney");
|
moneyImg = proxy.GetWidgtEx<Image>("Image");
|
useMoney = proxy.GetWidgtEx<Text>("usemoney");
|
freeTip = proxy.GetWidgtEx<Text>("free");
|
for (int i = 0; i < itemStartPos.Count; i++)
|
{
|
items.Add(proxy.GetWidgtEx<Transform>("godItem" + i));
|
}
|
skipAnim = proxy.GetWidgtEx<Toggle>("skipAnim");
|
}
|
|
protected override void AddListeners()
|
{
|
closeBtn.SetListener(() => {
|
if (GodKingGiftModel.Instance.awardShowSetp != -1) return;
|
WindowCenter.Instance.CloseIL<GodKingRandomGiftWin>();
|
});
|
|
resetBtn.SetListener(OnReset);
|
randomBtn.SetListener(RandomItem);
|
}
|
|
protected override void OnPreOpen()
|
{
|
GodKingGiftModel.Instance.awardShowSetp = -1;
|
GodKingGiftModel.Instance.selectedItems.Clear();
|
|
|
GodKingGiftModel.Instance.OnPlayerInfoEvent += OnPlayerInfoEvent;
|
DisplayDelay();
|
}
|
|
protected override void OnPreClose()
|
{
|
GodKingGiftModel.Instance.OnPlayerInfoEvent -= OnPlayerInfoEvent;
|
}
|
|
protected override void LateUpdate()
|
{
|
if (GodKingGiftModel.Instance.awardShowSetp == 2)
|
{
|
WindowCenter.Instance.OpenIL<GodKingGiftResultWin>();
|
DisplayDelay(true);
|
GodKingGiftModel.Instance.awardShowSetp = -1;
|
}
|
}
|
#endregion
|
|
void OnPlayerInfoEvent()
|
{
|
if (GodKingGiftModel.Instance.awardShowSetp == 1)
|
{
|
if (skipAnim.isOn)
|
{
|
//直接显示结果
|
GodKingGiftModel.Instance.awardShowSetp = 2;
|
}
|
else
|
{
|
//开始表现动画-动画结束-打开结果界面-刷新界面信息
|
for (int i = 0; i < showItemIndex.Count; i++)
|
{
|
int index = showItemIndex[i];
|
items[index].transform.DOLocalMove(new Vector3(0, 0, 0), 0.1f * i + 0.1f).OnComplete(() => {
|
items[index].transform.DOLocalPath(path1, 2f, PathType.CatmullRom).SetLoops(1).SetEase(Ease.Linear).OnComplete(() => {
|
if (GodKingGiftModel.Instance.awardShowSetp == 1)
|
GodKingGiftModel.Instance.awardShowSetp = 2; //转圈结束
|
if (index == GodKingGiftModel.Instance.newItemIndex)
|
return;
|
items[index].transform.DOLocalMove(itemStartPos[index], 0.5f);
|
});
|
});
|
}
|
}
|
}
|
}
|
|
void OnReset()
|
{
|
if (GodKingGiftModel.Instance.awardShowSetp != -1) return;
|
|
OperationBase operationBase;
|
if (!OperationTimeHepler.Instance.TryGetOperationTime(GodKingGiftModel.operationType, out operationBase))
|
{
|
return;
|
}
|
OperationGodKingGift operation = operationBase as OperationGodKingGift;
|
if (GodKingGiftModel.Instance.ResetCount >= operation.ResetCountMax)
|
{
|
return;
|
}
|
|
ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("tdlb9"), (bool isOk) =>
|
{
|
if (isOk)
|
{
|
var pack = new IL_CAA22_tagCMActGodGiftReset();
|
pack.ActNum = 10;
|
GameNetSystem.Instance.SendInfo(pack);
|
};
|
});
|
}
|
|
//抽奖延迟显示
|
void DisplayDelay(bool isMove = false)
|
{
|
OperationBase operationBase;
|
if (!OperationTimeHepler.Instance.TryGetOperationTime(GodKingGiftModel.operationType, out operationBase))
|
{
|
return;
|
}
|
|
OperationGodKingGift operation = operationBase as OperationGodKingGift;
|
|
if (GodKingGiftModel.Instance.AwardItemList.Length >= operation.ResetLimitTimes &&
|
GodKingGiftModel.Instance.ResetCount < operation.ResetCountMax)
|
{
|
resetBtn.SetColorful(null, true);
|
resetBtn.interactable = true;
|
}
|
else
|
{
|
resetBtn.SetColorful(null, false);
|
resetBtn.interactable = false;
|
}
|
|
resetCnt.text = Language.Get("tdlb10") + (operation.ResetCountMax - GodKingGiftModel.Instance.ResetCount);
|
lsMoney.text = Language.Get("tdlb13", operation.PrizeMoneyValueList[Math.Min(
|
GodKingGiftModel.Instance.AwardItemList.Length, operation.PrizeMoneyValueList.Length - 1)]);
|
var needMoney = operation.CostMoneyValueList[Math.Min(GodKingGiftModel.Instance.AwardItemList.Length, operation.CostMoneyValueList.Length - 1)];
|
if (needMoney == 0)
|
{
|
freeTip.SetActiveIL(true);
|
moneyImg.SetActiveIL(false);
|
}
|
else
|
{
|
freeTip.SetActiveIL(false);
|
moneyImg.SetActiveIL(true);
|
moneyImg.SetSprite("Money_Type_" + operation.CostMoneyType);
|
ulong money = HeroControler.Instance.GetMoneyCntIL(operation.CostMoneyType);
|
if (money < needMoney)
|
{
|
useMoney.text = UIHelper.AppendColor(TextColType.Red, money.ToString()) + "/" + needMoney;
|
}
|
else
|
{
|
useMoney.text = money + "/" + needMoney;
|
}
|
}
|
|
showItemIndex.Clear();
|
for (int i = 0; i < items.Count; i++)
|
{
|
if (i < GodKingGiftModel.Instance.godKingItems.Count)
|
{
|
var itemInfo = GodKingGiftModel.Instance.godKingItems[i];
|
if (!hasGetYet(itemInfo.libType, itemInfo.itemNum))
|
{
|
items[i].SetActiveIL(true);
|
if (!isMove)
|
items[i].localPosition = itemStartPos[i];
|
showItemIndex.Add(i);
|
var paoImg = items[i].Find("paopao").GetComponent<Image>();
|
paoImg.SetSprite("tdlbPao" + itemInfo.libType);
|
var itemImg = items[i].Find("paopao/Image").GetComponent<Image>();
|
itemImg.SetSprite(ItemConfig.Get((int)itemInfo.itemID).IconKey);
|
var itemCnt = items[i].Find("paopao/TextEx").GetComponent<Text>();
|
itemCnt.text = "x" + itemInfo.itemCount;
|
}
|
else
|
{
|
items[i].SetActiveIL(false);
|
}
|
|
}
|
else
|
{
|
items[i].SetActiveIL(false);
|
}
|
}
|
}
|
|
//是否已抽中
|
bool hasGetYet(int libType, int itemNum)
|
{
|
for (int i = 0; i < GodKingGiftModel.Instance.AwardItemList.Length; i++)
|
{
|
var itemInfo = GodKingGiftModel.Instance.AwardItemList[i];
|
if (itemInfo.ItemLibType == libType && itemInfo.ItemNum == itemNum)
|
{
|
return true;
|
}
|
}
|
return false;
|
}
|
|
void RandomItem()
|
{
|
if (GodKingGiftModel.Instance.awardShowSetp != -1) return;
|
OperationBase operationBase;
|
if (!OperationTimeHepler.Instance.TryGetOperationTime(GodKingGiftModel.operationType, out operationBase))
|
{
|
return;
|
}
|
|
OperationGodKingGift operation = operationBase as OperationGodKingGift;
|
var needMoney = operation.CostMoneyValueList[Math.Min(GodKingGiftModel.Instance.AwardItemList.Length, operation.CostMoneyValueList.Length - 1)];
|
|
if (HeroControler.Instance.GetMoneyCntIL(operation.CostMoneyType) < needMoney)
|
{
|
//RechargeTipWin.moneyType = operation.CostMoneyType;
|
//WindowCenter.Instance.OpenEx<RechargeTipWin>();
|
SysNotifyMgr.Instance.ShowTip("LackMoney", operation.CostMoneyType);
|
return;
|
}
|
|
if (GodKingGiftModel.Instance.godKingItems.Count == GodKingGiftModel.Instance.AwardItemList.Length)
|
{
|
SysNotifyMgr.Instance.ShowTip("ActGodGiftNotify3");
|
return;
|
}
|
|
if (playerPack.GetEmptyGridCount(PackType.Item) <= 2)
|
{
|
SysNotifyMgr.Instance.ShowTip("GeRen_lhs_202580");
|
return;
|
}
|
|
var pack = new IL_CAA21_tagCMActGodGiftlottery();
|
pack.ActNum = 10;
|
GameNetSystem.Instance.SendInfo(pack);
|
|
GodKingGiftModel.Instance.awardShowSetp = 0; //开始转圈
|
}
|
}
|