using System;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
|
namespace vnxbqy.UI
|
{
|
public class UnionTaskWin : Window, SecondWindowInterface
|
{
|
[SerializeField]
|
private ScrollerController _taskCtrl;
|
|
[SerializeField]
|
private Slider _livenSlider;
|
|
[SerializeField]
|
private List<GameObject> _livenIconlist = new List<GameObject>();
|
|
[SerializeField]
|
private Text _livenScoreText;
|
|
private List<UnionLivenConfig> _livenModellist;
|
|
UnionTaskModel TaskModel { get { return ModelCenter.Instance.GetModel<UnionTaskModel>(); } }
|
|
bool isHaveRecieve = false;
|
#region 实现抽象类
|
|
public Button close { get; set; }
|
|
protected override void BindController()
|
{
|
if (this is SecondWindowInterface)
|
{
|
var frame = this.GetComponentInChildren<SecondFrameLoader2>();
|
frame.Create();
|
close = frame.GetComponentInChildren<Button>();
|
}
|
}
|
|
protected override void AddListeners()
|
{
|
_taskCtrl.OnRefreshCell += RefreshTaskCell;
|
close.onClick.AddListener(CloseWin);
|
}
|
|
protected override void OnPreOpen()
|
{
|
isHaveRecieve = false;
|
FuncOpen.Instance.OnFuncStateChangeEvent += CreateCell;
|
TaskModel.RefreshLivenScoreEvent = RefreshUI;
|
InitUI();
|
}
|
|
protected override void OnAfterOpen()
|
{
|
CheckJumpToModel();
|
}
|
|
protected override void OnPreClose()
|
{
|
FuncOpen.Instance.OnFuncStateChangeEvent -= CreateCell;
|
}
|
|
protected override void OnAfterClose()
|
{
|
|
}
|
#endregion
|
|
private void CheckJumpToModel()
|
{
|
if (AchievementGoto.guideAchievementId != 0)
|
{
|
SuccessConfig successConfig = SuccessConfig.Get(AchievementGoto.guideAchievementId);
|
if (successConfig.Type == 110)
|
{
|
if (!isHaveRecieve)
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("UnionLiven104"));
|
}
|
AchievementGoto.guideAchievementId = 0;
|
}
|
}
|
}
|
|
private void InitUI()
|
{
|
int i = 0;
|
for (i = 0; i < TaskModel.unionLivenScores.Length; i++)
|
{
|
int index = i;
|
Text score = _livenIconlist[i].transform.Find("ScoreText").GetComponent<Text>();
|
Text reward = _livenIconlist[i].transform.Find("RewardText").GetComponent<Text>();
|
Button iconBtn = _livenIconlist[i].GetComponent<Button>();
|
int scoreValue = TaskModel.unionLivenScores[i];
|
int rewardValue = TaskModel.unionLivenRewards[i];
|
score.text = Language.Get("UnionLiven101", scoreValue);
|
reward.text = Language.Get("UnionLiven102", rewardValue);
|
iconBtn.onClick.RemoveAllListeners();
|
iconBtn.onClick.AddListener(() =>
|
{
|
OnClickLivenScoreBtn(scoreValue, index);
|
});
|
}
|
_livenSlider.minValue = 0;
|
_livenSlider.maxValue = TaskModel.unionLivenScores[TaskModel.unionLivenScores.Length - 1];
|
RefreshUI();
|
}
|
|
private void RefreshUI()
|
{
|
_livenSlider.value = TaskModel.curLivenScore;
|
_livenScoreText.text = TaskModel.curLivenScore.ToString();
|
CreateCell(0);
|
RefreshReciveUIEffect();
|
}
|
|
private void CreateCell(int func)
|
{
|
_taskCtrl.Refresh();
|
_livenModellist = TaskModel.GetOpenUnionTasklist();
|
if (_livenModellist.Count > 0)
|
{
|
int i = 0;
|
int remain = _livenModellist.Count % 2;
|
int line = (int)_livenModellist.Count / 2;
|
if (remain > 0)
|
{
|
line += 1;
|
}
|
|
for (i = 0; i < line; i++)
|
{
|
_taskCtrl.AddCell(ScrollerDataType.Header, i);
|
}
|
}
|
_taskCtrl.Restart();
|
}
|
|
private void RefreshTaskCell(ScrollerDataType type, CellView cell)
|
{
|
int childCode = 0;
|
for (childCode = 0; childCode < cell.transform.childCount; childCode++)
|
{
|
int cellCount = (cell.transform.childCount) * cell.index + (childCode + 1);
|
|
UnionTaskCell taskCell = cell.transform.GetChild(childCode).GetComponent<UnionTaskCell>();
|
if (taskCell == null)
|
taskCell = cell.gameObject.AddComponent<UnionTaskCell>();
|
if (_livenModellist.Count >= cellCount)
|
{
|
cell.transform.GetChild(childCode).SetActive(true);
|
UnionLivenConfig tagUnion = _livenModellist[cellCount - 1];
|
taskCell.taskIcon.SetSprite(tagUnion.IconName);
|
taskCell.taskNameText.text = tagUnion.Name.Replace("{0}", tagUnion.TotalActivityTime.ToString());
|
taskCell.RewardText.text = string.Format(tagUnion.RewardDes, tagUnion.SingleActiveValue, tagUnion.OnceActivity);
|
UnionTaskInfo taskInfo = TaskModel.GetUnionTaskInfo(tagUnion.ID);
|
if (taskInfo != null)
|
{
|
if (taskInfo.IsComplete)
|
{
|
taskCell.completeImage.SetActive(true);
|
taskCell.progressText.text = Language.Get("UnionLiven103", tagUnion.TotalActivityTime.ToString(), tagUnion.TotalActivityTime.ToString());
|
}
|
else
|
{
|
taskCell.completeImage.SetActive(false);
|
taskCell.progressText.text = Language.Get("UnionLiven103", taskInfo.FinishCnt.ToString(), tagUnion.TotalActivityTime.ToString());
|
}
|
}
|
else
|
{
|
taskCell.completeImage.SetActive(false);
|
taskCell.progressText.text = Language.Get("UnionLiven103", "0", tagUnion.TotalActivityTime.ToString());
|
}
|
}
|
else
|
{
|
cell.transform.GetChild(childCode).SetActive(false);
|
}
|
}
|
|
}
|
|
private void RefreshReciveUIEffect()
|
{
|
for (int i = 0; i < TaskModel.unionLivenScores.Length; i++)
|
{
|
UIEffect effect = _livenIconlist[i].transform.Find("UIEffct").GetComponent<UIEffect>();
|
GameObject alreadyReceiveObj = _livenIconlist[i].transform.Find("AlreadyReceiveImg").gameObject;
|
int scoreValue = TaskModel.unionLivenScores[i];
|
if (TaskModel.curLivenScore >= scoreValue)
|
{
|
if (!TaskModel.receiveAwardRecord[i])
|
{
|
isHaveRecieve = true;
|
alreadyReceiveObj.SetActive(false);
|
effect.Play();
|
}
|
else
|
{
|
alreadyReceiveObj.SetActive(true);
|
effect.Stop();
|
}
|
}
|
else
|
{
|
alreadyReceiveObj.SetActive(false);
|
effect.Stop();
|
}
|
}
|
}
|
|
private void OnClickLivenScoreBtn(int score, int index)
|
{
|
DebugEx.Log(TaskModel.curLivenScore + "和" + score);
|
if (TaskModel.curLivenScore >= score)
|
{
|
if (!TaskModel.receiveAwardRecord[index])
|
{
|
CA504_tagCMPlayerGetReward getReward = new CA504_tagCMPlayerGetReward();
|
getReward.RewardType = 1;
|
getReward.DataEx = (uint)index;
|
getReward.DataExStrLen = 0;
|
getReward.DataExStr = "";
|
GameNetSystem.Instance.SendInfo(getReward);
|
}
|
else
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("UnionLiven105"));
|
}
|
}
|
else
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("UnionLiven104"));
|
}
|
|
}
|
|
private void CloseWin()
|
{
|
Close();
|
}
|
|
}
|
}
|