using Spine.Unity;
|
using System;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
using Spine;
|
|
namespace vnxbqy.UI
|
{
|
public class WytjGameWin : Window
|
{
|
#region 成员变量
|
[SerializeField]
|
Button closeBtn;
|
|
[SerializeField]
|
Button startBtn;
|
|
[SerializeField]
|
Button ruleBtn;
|
|
[SerializeField]
|
Button getRewardBtn;
|
|
[SerializeField]
|
Button freeBtn;
|
|
[SerializeField]
|
Text playNumText;
|
|
[SerializeField]
|
Text freeNumText;
|
|
[SerializeField]
|
Text reward1Text;
|
|
[SerializeField]
|
Text reward2Text;
|
|
[SerializeField]
|
Text reward3Text;
|
|
[SerializeField]
|
GameObject bottomPart;
|
|
[SerializeField] Text npcDesText;
|
|
[SerializeField] Button jumpAniBtn;
|
[SerializeField] Image jumAniImg;
|
|
[SerializeField] SkeletonGraphic pictureSG;
|
[SerializeField] List<FrameEffect> framEffectlist;
|
[SerializeField] List<Image> resultImglist;
|
[SerializeField] GameObject resultObj;
|
[SerializeField] List<Button> awardbtnlist = new List<Button>();
|
[SerializeField] List<Image> awardImagelist = new List<Image>();
|
#endregion
|
|
TaiChiModel _taiChiModel;
|
TaiChiModel taiChiModel {
|
get { return _taiChiModel ?? (_taiChiModel = ModelCenter.Instance.GetModel<TaiChiModel>()); }
|
}
|
|
private int remainFreeCnt;
|
private int completedTimes;
|
private int totalTimes;
|
|
private const string Star_Key = "Star";
|
private const string Star1_Key = "Star_1";
|
private const string Star3_Key = "Star_3";
|
private const string Rock_Key = "Rock_1";
|
private const string Stand_1_Key = "Stand_1";
|
private const string Stand_2_Key = "Stand_2";
|
|
private bool isfreeTo = false;
|
private bool isJumpAni = true;
|
|
protected override void BindController()
|
{
|
|
}
|
protected override void AddListeners()
|
{
|
closeBtn.AddListener(CloseWin);
|
startBtn.AddListener(ClickStartBtn);
|
getRewardBtn.AddListener(ClickGetRewardBtn);
|
freeBtn.AddListener(ClickFreeBtn);
|
ruleBtn.AddListener(ClickRuleBtn);
|
jumpAniBtn.AddListener(ClickJumpAniBtn);
|
}
|
|
protected override void OnPreOpen()
|
{
|
Init();
|
isfreeTo = false;
|
isJumpAni = true;
|
ClickJumpAniBtn();
|
taiChiModel.RefreshTaiChiModel += RefreshUI;
|
taiChiModel.GetResultEvent += GetReciveReward;
|
|
|
}
|
|
protected override void OnAfterOpen()
|
{
|
pictureSG.AnimationState.Complete += OnCompleteAniSG;
|
}
|
protected override void OnPreClose()
|
{
|
taiChiModel.RefreshTaiChiModel -= RefreshUI;
|
taiChiModel.GetResultEvent -= GetReciveReward;
|
pictureSG.AnimationState.Complete -= OnCompleteAniSG;
|
}
|
protected override void OnAfterClose()
|
{
|
|
}
|
|
private void Init()
|
{
|
completedTimes = taiChiModel.dailyQuestModel.GetDailyQuestCompletedTimes(12);
|
totalTimes = taiChiModel.dailyQuestModel.GetDailyQuestTotalTimes(12);
|
|
BottomUICtrl();
|
if (completedTimes >= totalTimes)
|
{
|
startBtn.interactable = false;
|
}
|
else
|
{
|
startBtn.interactable = true;
|
}
|
}
|
|
private void RefreshUI()
|
{
|
//completedTimes = taiChiModel.dailyQuestModel.GetDailyQuestCompletedTimes(12);
|
if (!isfreeTo)
|
{
|
if (completedTimes >= totalTimes)
|
{
|
startBtn.interactable = false;
|
}
|
else
|
{
|
startBtn.interactable = true;
|
}
|
BottomUICtrl();
|
}
|
}
|
|
private void BottomUICtrl()
|
{
|
|
completedTimes = taiChiModel.dailyQuestModel.GetDailyQuestCompletedTimes(12);
|
playNumText.text = StringUtility.Contact(completedTimes, "/", totalTimes);
|
remainFreeCnt = taiChiModel.sumFreeNum - taiChiModel.useFreeCnt;
|
freeNumText.text = remainFreeCnt.ToString();
|
DiceReward diceReward = taiChiModel.GetDiceReward(taiChiModel.taiChiNum);
|
if (diceReward != null)
|
{
|
reward1Text.text = ItemLogicUtility.Instance.OnChangeCoinsUnit((ulong)taiChiModel.GetDiceRewardExp(diceReward.exp));
|
reward2Text.text = ItemLogicUtility.Instance.OnChangeCoinsUnit((ulong)diceReward.gold);
|
reward3Text.text = ItemLogicUtility.Instance.OnChangeCoinsUnit((ulong)diceReward.itemCount);
|
|
for (int i = 0; i < awardbtnlist.Count; i++)
|
{
|
ItemConfig itemConfig = null;
|
switch (i)
|
{
|
case 0:
|
itemConfig = ItemConfig.Get(diceReward.itemID);
|
break;
|
case 1:
|
itemConfig = ItemConfig.Get(diceReward.goldId);
|
break;
|
case 2:
|
itemConfig = ItemConfig.Get(diceReward.expId);
|
break;
|
}
|
|
awardbtnlist[i].RemoveAllListeners();
|
if (itemConfig != null)
|
{
|
awardImagelist[i].SetSprite(itemConfig.IconKey);
|
awardbtnlist[i].AddListener(() =>
|
{
|
ItemTipUtility.Show(itemConfig.ID);
|
});
|
}
|
}
|
}
|
|
if (taiChiModel.taiChiResultNum == "0")
|
{
|
bottomPart.SetActive(false);
|
resultObj.SetActive(false);
|
startBtn.SetActive(true);
|
npcDesText.text = Language.Get("Wytj0");
|
}
|
else
|
{
|
|
resultObj.SetActive(true);
|
bottomPart.SetActive(true);
|
startBtn.SetActive(false);
|
for (int i = 0; i < resultImglist.Count; i++)
|
{
|
framEffectlist[i].enabled = false;
|
int dicePoint = taiChiModel.resultNumlist[i];
|
resultImglist[i].SetSprite(StringUtility.Contact("XT_TJ_", dicePoint));
|
}
|
|
switch (taiChiModel.taiChiNum)
|
{
|
case 0:
|
npcDesText.text = Language.Get("Wytj0");
|
break;
|
case 1:
|
SoundPlayer.Instance.PlayUIAudio(733);
|
npcDesText.text = Language.Get("Wytj1");
|
break;
|
case 2:
|
SoundPlayer.Instance.PlayUIAudio(734);
|
npcDesText.text = Language.Get("Wytj2");
|
break;
|
case 3:
|
SoundPlayer.Instance.PlayUIAudio(735);
|
npcDesText.text = Language.Get("Wytj3");
|
break;
|
case 4:
|
SoundPlayer.Instance.PlayUIAudio(736);
|
npcDesText.text = Language.Get("Wytj4");
|
break;
|
case 5:
|
SoundPlayer.Instance.PlayUIAudio(737);
|
npcDesText.text = Language.Get("Wytj5");
|
break;
|
case 6:
|
SoundPlayer.Instance.PlayUIAudio(738);
|
npcDesText.text = Language.Get("Wytj6");
|
break;
|
}
|
}
|
|
getRewardBtn.interactable = true;
|
|
if (taiChiModel.taiChiNum >= 6)
|
{
|
freeBtn.interactable = false;
|
}
|
else
|
{
|
if (remainFreeCnt > 0)
|
{
|
freeBtn.interactable = true;
|
}
|
else
|
{
|
freeBtn.interactable = false;
|
}
|
}
|
}
|
|
private void ClickStartBtn()
|
{
|
if (isJumpAni)
|
{
|
isfreeTo = false;
|
}
|
else
|
{
|
startBtn.interactable = false;
|
isfreeTo = true;
|
pictureSG.Skeleton.SetToSetupPose();
|
pictureSG.AnimationState.SetAnimation(0, Star1_Key, false);
|
pictureSG.AnimationState.AddAnimation(0, Rock_Key, false, 0);
|
pictureSG.AnimationState.AddAnimation(0, Star_Key, false, 0);
|
pictureSG.AnimationState.AddAnimation(0, Stand_1_Key, true, 0);
|
}
|
taiChiModel.SendQuest(0);
|
}
|
|
|
private void OnCompleteAniSG(TrackEntry trackEntry)
|
{
|
string aniName = trackEntry.animation.name;
|
switch (aniName)
|
{
|
case Stand_1_Key:
|
break;
|
case Star1_Key:
|
SoundPlayer.Instance.PlayUIAudio(57);
|
break;
|
case Star3_Key:
|
StartPlayDiceAni();
|
taiChiModel.SendQuest(1);
|
SoundPlayer.Instance.PlayUIAudio(57);
|
break;
|
case Rock_Key:
|
break;
|
case Star_Key:
|
isfreeTo = false;
|
RefreshUI();
|
break;
|
}
|
}
|
|
private void StartPlayDiceAni()
|
{
|
if (taiChiModel.resultNumlist != null && taiChiModel.resultNumlist.Count == 6)
|
{
|
for (int i = 0; i < resultImglist.Count; i++)
|
{
|
framEffectlist[i].enabled = false;
|
if (!isJumpAni)
|
{
|
if (taiChiModel.resultNumlist[i] != 6)
|
{
|
framEffectlist[i].CompleteAct -= RefreshDiceResultUI;
|
framEffectlist[i].CompleteAct += RefreshDiceResultUI;
|
framEffectlist[i].loop = false;
|
framEffectlist[i].enabled = true;
|
}
|
else
|
{
|
framEffectlist[i].CompleteAct -= RefreshDiceResultUI;
|
framEffectlist[i].enabled = false;
|
}
|
}
|
else
|
{
|
framEffectlist[i].CompleteAct -= RefreshDiceResultUI;
|
framEffectlist[i].enabled = false;
|
}
|
|
}
|
}
|
}
|
|
private void ClickGetRewardBtn()
|
{
|
isfreeTo = false;
|
taiChiModel.SendQuest(2);
|
}
|
|
private void GetReciveReward()
|
{
|
WindowCenter.Instance.Open<TaichiGetRewardWin>();
|
}
|
|
private void ClickFreeBtn()
|
{
|
if (remainFreeCnt > 0)
|
{
|
if (isJumpAni)
|
{
|
freeBtn.interactable = true;
|
isfreeTo = false;
|
}
|
else
|
{
|
freeBtn.interactable = false;
|
getRewardBtn.interactable = false;
|
isfreeTo = true;
|
pictureSG.Skeleton.SetToSetupPose();
|
pictureSG.AnimationState.AddAnimation(0, Star3_Key, false, 0);
|
pictureSG.AnimationState.AddAnimation(0, Rock_Key, false, 0);
|
pictureSG.AnimationState.AddAnimation(0, Star_Key, false, 0);
|
pictureSG.AnimationState.AddAnimation(0, Stand_1_Key, true, 0);
|
|
}
|
}
|
else
|
{
|
freeBtn.interactable = false;
|
}
|
|
}
|
|
private void RefreshDiceResultUI(int index)
|
{
|
int dicePoint = taiChiModel.resultNumlist[index];
|
resultImglist[index].SetSprite(StringUtility.Contact("XT_TJ_", dicePoint));
|
}
|
|
private void ClickRuleBtn()
|
{
|
WindowCenter.Instance.Open<WytjRulesWin>();
|
}
|
|
private void ClickJumpAniBtn()
|
{
|
if (!isJumpAni)
|
{
|
jumAniImg.SetActive(true);
|
isJumpAni = true;
|
}
|
else
|
{
|
jumAniImg.SetActive(false);
|
isJumpAni = false;
|
}
|
}
|
|
private void CloseWin()
|
{
|
if (taiChiModel.taiChiResultNum != "0")
|
{
|
taiChiModel.SendQuest(2);
|
}
|
|
CloseImmediately();
|
}
|
|
}
|
}
|