using System;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
using System.Collections.Generic;
|
using System.Linq;
|
using UnityEngine.Events;
|
|
namespace Snxxz.UI
|
{
|
public class TreasureFindHostWin : Window
|
{
|
[SerializeField] ScrollerController reciveConditionCtrl;
|
[SerializeField] Button closeBtn;
|
[SerializeField] Button gotoBtn;
|
[SerializeField] Text gotoText;
|
[SerializeField] UIEffect effect;
|
[SerializeField] GameObject alreadyGetImg;
|
[SerializeField] Button treasureBtn;
|
[SerializeField] Text getAwardDesText;
|
[SerializeField] Text progressText;
|
[SerializeField] Button leftBtn;
|
[SerializeField] Button rightBtn;
|
[SerializeField] List<FunctionButton> funcBtnlist = new List<FunctionButton>();
|
[SerializeField] List<RedpointBehaviour> funcRedlist = new List<RedpointBehaviour>();
|
[SerializeField] List<Text> funcTitlelist = new List<Text>();
|
[SerializeField] FunctionButtonGroup funcBtnGroup;
|
[SerializeField] Image treasureEffectImg1;
|
[SerializeField] RawImage treasureIcon;
|
TreasureFindHostModel hostModel { get { return ModelCenter.Instance.GetModel<TreasureFindHostModel>(); } }
|
TreasureModel treasureModel { get { return ModelCenter.Instance.GetModel<TreasureModel>(); } }
|
|
Dictionary<int, List<FindTreasureInfo>> findTreasureDict;
|
int selectTreasureId = 0;
|
List<FindTreasureInfo> findInfolist;
|
List<FindTreasureInfo> orderFindlist = new List<FindTreasureInfo>();
|
List<int> treasureIdlist;
|
bool isOpenFirst = true;
|
protected override void BindController()
|
{
|
reciveConditionCtrl.OnRefreshCell += RefreshConditionCell;
|
reciveConditionCtrl.lockType = EnhanceLockType.KeepVertical;
|
}
|
|
protected override void AddListeners()
|
{
|
treasureBtn.AddListener(() => { WindowJumpMgr.Instance.WindowJumpTo((JumpUIType)findInfolist[0].jumpId); });
|
leftBtn.onClick.AddListener(OnClickLeftBtn);
|
rightBtn.onClick.AddListener(OnClickRightBtn);
|
closeBtn.AddListener(CloseClick);
|
gotoBtn.AddListener(() => { WindowJumpMgr.Instance.WindowJumpTo((JumpUIType)findInfolist[0].jumpId); });
|
}
|
|
protected override void OnPreOpen()
|
{
|
isOpenFirst = true;
|
hostModel.OnCompletedAct += OnCompleted;
|
findTreasureDict = hostModel.GetFindTreasureInfoDict();
|
treasureIdlist = findTreasureDict.Keys.ToList();
|
selectTreasureId = treasureIdlist[0];
|
}
|
|
protected override void OnActived()
|
{
|
base.OnActived();
|
FuncBtnUICtrl();
|
if(hostModel.jumpTreasureId == 0)
|
{
|
for (int i = funcBtnlist.Count - 1; i > -1; i--)
|
{
|
if(i < treasureIdlist.Count)
|
{
|
if (funcBtnlist[i].state != TitleBtnState.Locked)
|
{
|
functionOrder = i;
|
break;
|
}
|
}
|
}
|
}
|
else
|
{
|
for(int i = 0; i < treasureIdlist.Count; i++)
|
{
|
if(treasureIdlist[i] == hostModel.jumpTreasureId)
|
{
|
functionOrder = i;
|
hostModel.jumpTreasureId = 0;
|
break;
|
}
|
}
|
}
|
|
funcBtnGroup.TriggerByOrder(functionOrder);
|
}
|
|
protected override void OnAfterOpen()
|
{
|
|
}
|
|
protected override void OnPreClose()
|
{
|
hostModel.OnCompletedAct -= OnCompleted;
|
}
|
|
protected override void OnAfterClose()
|
{
|
UI3DTreasureExhibition.Instance.StopShow();
|
for (int i = 0; i < funcBtnlist.Count; i++)
|
{
|
if (i < treasureIdlist.Count)
|
{
|
funcBtnlist[i].OnPointClickLockFunc -= ClickLockBtn;
|
}
|
}
|
if (!WindowJumpMgr.Instance.IsJumpState)
|
{
|
WindowCenter.Instance.Open<MainInterfaceWin>();
|
}
|
}
|
|
private void FuncBtnUICtrl()
|
{
|
for(int i = 0; i < funcBtnlist.Count; i++)
|
{
|
funcBtnlist[i].RemoveAllListeners();
|
if(i < treasureIdlist.Count)
|
{
|
funcBtnlist[i].OnPointClickLockFunc += ClickLockBtn;
|
funcBtnlist[i].enabled = true;
|
funcTitlelist[i].gameObject.SetActive(true);
|
funcRedlist[i].gameObject.SetActive(true);
|
int treasureId = treasureIdlist[i];
|
int index = i;
|
TreasureConfig config = TreasureConfig.Get(treasureId);
|
if (config != null)
|
{
|
funcRedlist[i].redpointId = hostModel.GetTreasureCellRedIdById(treasureId);
|
funcTitlelist[i].text = config.Name;
|
}
|
funcBtnlist[i].AddListener(() => { ClickTitleBtn(treasureId,index); });
|
|
if( i != 0)
|
{
|
int preTreasureId = treasureIdlist[i-1];
|
Treasure treasure = null;
|
treasureModel.TryGetTreasure(preTreasureId, out treasure);
|
|
if (treasure != null && treasure.state != TreasureState.Collected)
|
{
|
funcBtnlist[i].state = TitleBtnState.Locked;
|
}
|
else if(treasure != null && treasure.state == TreasureState.Collected)
|
{
|
funcBtnlist[i].state = TitleBtnState.Normal;
|
}
|
}
|
}
|
else
|
{
|
funcBtnlist[i].enabled = false;
|
funcTitlelist[i].gameObject.SetActive(false);
|
funcRedlist[i].gameObject.SetActive(false);
|
}
|
}
|
}
|
|
private void ClickLockBtn(string key)
|
{
|
int index = int.Parse(key.Substring(key.Length - 1,1)) - 2;
|
TreasureConfig config = TreasureConfig.Get(treasureIdlist[index]);
|
if(config != null)
|
{
|
SysNotifyMgr.Instance.ShowTip("UnLock_TreasureLimit",config.Name);
|
}
|
|
}
|
|
private void OnClickLeftBtn()
|
{
|
funcBtnGroup.TriggerLast();
|
}
|
|
private void OnClickRightBtn()
|
{
|
funcBtnGroup.TriggerNext();
|
}
|
|
private void ClickTitleBtn(int treasureId,int index)
|
{
|
if(isOpenFirst)
|
{
|
isOpenFirst = false;
|
}
|
else
|
{
|
if (treasureId == selectTreasureId)
|
{
|
return;
|
}
|
}
|
|
selectTreasureId = treasureId;
|
hostModel.SetSelectTreasureId(treasureId);
|
UI3DTreasureExhibition.Instance.BeginShowTreasure(selectTreasureId, treasureIcon);
|
CreateConditionCell();
|
functionOrder = index;
|
}
|
|
private void RefreshTreasureUI()
|
{
|
TreasureConfig config = TreasureConfig.Get(selectTreasureId);
|
if (config == null) return;
|
|
string[] treasureEffectImgs = TreasureFindHostConfig.Get(findInfolist[0].id).EffectIconKeys;
|
treasureEffectImg1.SetSprite(treasureEffectImgs[0]);
|
treasureEffectImg1.SetNativeSize();
|
getAwardDesText.text = Language.Get("TreasureFindHost_UnLock",config.Name);
|
int progress = 0;
|
Treasure treasure = null;
|
treasureModel.TryGetTreasure(selectTreasureId, out treasure);
|
if (hostModel.IsReachUnlock(selectTreasureId,out progress))
|
{
|
if(!effect.IsPlaying && treasure.state != TreasureState.Collected)
|
{
|
effect.Play();
|
}
|
else
|
{
|
effect.Stop();
|
}
|
progressText.text = UIHelper.AppendColor(TextColType.Green,StringUtility.Contact("(",progress,"/",findInfolist.Count,")"), true);
|
}
|
else
|
{
|
if (effect.IsPlaying)
|
{
|
effect.Stop();
|
}
|
progressText.text = UIHelper.AppendColor(TextColType.Red, StringUtility.Contact("(",progress, "/", findInfolist.Count,")"));
|
}
|
gotoBtn.gameObject.SetActive(true);
|
if (treasure.state == TreasureState.Collected)
|
{
|
alreadyGetImg.SetActive(true);
|
gotoText.text = Language.Get("TreasureFindHost_UnLock2");
|
}
|
else
|
{
|
alreadyGetImg.SetActive(false);
|
gotoText.text = Language.Get("TreasureFindHost_UnLock1");
|
}
|
}
|
|
private void OnCompleted()
|
{
|
CreateConditionCell();
|
int progress = 0;
|
if (hostModel.IsReachUnlock(selectTreasureId,out progress))
|
{
|
SysNotifyMgr.Instance.ShowTip("TreasureFindHost2");
|
}
|
else
|
{
|
SysNotifyMgr.Instance.ShowTip("TreasureFindHost1");
|
}
|
|
}
|
|
private void CreateConditionCell()
|
{
|
findInfolist = findTreasureDict[selectTreasureId];
|
RefreshTreasureUI();
|
orderFindlist.Clear();
|
orderFindlist.AddRange(findInfolist);
|
orderFindlist.Sort(CompareByState);
|
reciveConditionCtrl.Refresh();
|
for(int i = 0; i < orderFindlist.Count; i++)
|
{
|
reciveConditionCtrl.AddCell(ScrollerDataType.Header, orderFindlist[i].id);
|
}
|
reciveConditionCtrl.Restart();
|
reciveConditionCtrl.JumpIndex(0);
|
}
|
|
private int CompareByState(FindTreasureInfo start,FindTreasureInfo next)
|
{
|
bool x = IsReach(start);
|
bool y = IsReach(next);
|
if (x.CompareTo(y) != 0) return -x.CompareTo(y);
|
|
x = IsNoReach(start);
|
y = IsNoReach(next);
|
if (x.CompareTo(y) != 0) return -x.CompareTo(y);
|
|
x = start.IsCompleted;
|
y = next.IsCompleted;
|
if (x.CompareTo(y) != 0) return x.CompareTo(y);
|
|
int orderx = findInfolist.IndexOf(start);
|
int ordery = findInfolist.IndexOf(next);
|
if (orderx.CompareTo(ordery) != 0) return orderx.CompareTo(ordery);
|
|
return 0;
|
}
|
|
private bool IsReach(FindTreasureInfo info)
|
{
|
if (info.IsCompleted)
|
{
|
return false;
|
}
|
else
|
{
|
int progress = 0;
|
if (hostModel.IsReachCondition(info, out progress))
|
{
|
return true;
|
}
|
else
|
{
|
return false;
|
}
|
}
|
}
|
|
private bool IsNoReach(FindTreasureInfo info)
|
{
|
if (info.IsCompleted)
|
{
|
return false;
|
}
|
else
|
{
|
int progress = 0;
|
if (hostModel.IsReachCondition(info, out progress))
|
{
|
return false;
|
}
|
else
|
{
|
return true;
|
}
|
}
|
}
|
|
private void RefreshConditionCell(ScrollerDataType type, CellView cell)
|
{
|
ReciveConditionCell conditionCell = cell.GetComponent<ReciveConditionCell>();
|
conditionCell.SetModel(cell.index);
|
}
|
|
}
|
}
|