using System;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
using System.Collections.Generic;
|
using System.Linq;
|
using UnityEngine.Events;
|
|
namespace vnxbqy.UI
|
{
|
public class TreasureFindHostWin : Window
|
{
|
[SerializeField] RectTransform m_Content;
|
[SerializeField] ScrollerController reciveConditionCtrl;
|
|
[SerializeField] Button gotoBtn;
|
[SerializeField] Text gotoText;
|
[SerializeField] UIEffect effect;
|
[SerializeField] GameObject alreadyGetImg;
|
[SerializeField] Button treasureBtn;
|
[SerializeField] Text getAwardDesText;
|
[SerializeField] Text progressText;
|
|
[SerializeField] Image treasureEffectImg1;
|
[SerializeField] RawImage treasureIcon;
|
|
[SerializeField] Text m_ReikiRemind;
|
|
Button closeBtn;
|
Button leftBtn;
|
Button rightBtn;
|
|
FunctionButtonGroup funcBtnGroup;
|
List<FunctionButton> funcBtnlist = new List<FunctionButton>();
|
List<RedpointBehaviour> funcRedlist = new List<RedpointBehaviour>();
|
List<Text> funcTitlelist = new List<Text>();
|
|
TreasureFindHostModel hostModel { get { return ModelCenter.Instance.GetModel<TreasureFindHostModel>(); } }
|
TreasureModel treasureModel { get { return ModelCenter.Instance.GetModel<TreasureModel>(); } }
|
ReikiRootModel reikiRootModel { get { return ModelCenter.Instance.GetModel<ReikiRootModel>(); } }
|
TitleModel titleModel { get { return ModelCenter.Instance.GetModel<TitleModel>(); } }
|
|
Dictionary<int, List<FindTreasureInfo>> findTreasureDict;
|
int selectTreasureId = 0;
|
List<FindTreasureInfo> findInfolist;
|
List<FindTreasureInfo> orderFindlist = new List<FindTreasureInfo>();
|
List<int> treasureIdlist;
|
bool isOpenFirst = true;
|
RectTransform moneyShow;
|
|
protected override void BindController()
|
{
|
var oneLevelFrame = UIUtility.CreateWidget("OneLevelWin_Pattern_1", "Pivot");
|
oneLevelFrame.transform.SetParentEx(this.transform, Vector3.zero, Quaternion.identity, Vector3.one);
|
oneLevelFrame.transform.SetAsFirstSibling();
|
var subWindowContainer = oneLevelFrame.transform.Find("Container_SubWindow");
|
m_Content.SetParentEx(subWindowContainer, Vector3.zero, Quaternion.identity, Vector3.one);
|
|
var titleIcon = oneLevelFrame.GetComponent<Image>("Container_BackGround/Img_Title");
|
titleIcon.SetSprite("OneLevelTitle_22");
|
|
funcBtnGroup = this.transform.GetComponent<FunctionButtonGroup>("Pivot/Container_Functions");
|
var functionContainer = funcBtnGroup.transform.Find("Content");
|
for (int i = 0; i < 4; i++)
|
{
|
var instance = UIUtility.CreateWidget("FunctionButton_Pattern_1", StringUtility.Contact("FunctionButton_", i + 1));
|
instance.transform.SetParentEx(functionContainer, Vector3.zero, Quaternion.identity, Vector3.one);
|
|
var functionButton = instance.GetComponent<FunctionButton>();
|
functionButton.order = i;
|
functionButton.group = funcBtnGroup;
|
funcBtnlist.Add(functionButton);
|
funcRedlist.Add(functionButton.redpoint);
|
funcTitlelist.Add(functionButton.title);
|
}
|
|
reciveConditionCtrl.OnRefreshCell += RefreshConditionCell;
|
reciveConditionCtrl.lockType = EnhanceLockType.KeepVertical;
|
|
moneyShow = oneLevelFrame.GetComponent<RectTransform>("Container_BackGround/FollowStoreBottom");
|
}
|
|
protected override void AddListeners()
|
{
|
leftBtn = this.GetComponent<Button>("Pivot/Container_Buttons/Btn_Left");
|
rightBtn = this.GetComponent<Button>("Pivot/Container_Buttons/Btn_Right");
|
closeBtn = this.GetComponent<Button>("Pivot/Container_Buttons/Btn_Close");
|
|
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()
|
{
|
moneyShow.SetActive(false);
|
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.Stop();
|
for (int i = 0; i < funcBtnlist.Count; i++)
|
{
|
if (i < treasureIdlist.Count)
|
{
|
funcBtnlist[i].OnPointClickLockFunc -= ClickLockBtn;
|
}
|
}
|
if (!WindowJumpMgr.Instance.IsJumpState)
|
{
|
WindowCenter.Instance.Open<MainInterfaceWin>();
|
}
|
}
|
|
void DisplayReikiRemind()
|
{
|
m_ReikiRemind.SetActive(reikiRootModel.treasureAddPoint.treasureId == selectTreasureId);
|
if (reikiRootModel.treasureAddPoint.treasureId == selectTreasureId)
|
{
|
var reikiPoint = 0;
|
if (PlayerDatas.Instance.baseData.LV >= reikiRootModel.reikiPointAutoAddLevel)
|
{
|
reikiPoint = (PlayerDatas.Instance.baseData.LV - reikiRootModel.reikiPointAutoAddLevel + 1)
|
* reikiRootModel.treasureAddPoint.point;
|
}
|
m_ReikiRemind.text = Language.Get("FairyTreasure_14", reikiPoint);
|
}
|
}
|
|
private void FuncBtnUICtrl()
|
{
|
for (int i = 0; i < funcBtnlist.Count; i++)
|
{
|
funcBtnlist[i].RemoveAllListeners();
|
if (i < treasureIdlist.Count)
|
{
|
funcBtnlist[i].OnPointClickLockFunc += ClickLockBtn;
|
funcBtnlist[i].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].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.ShowTreasure(selectTreasureId, treasureIcon);
|
CreateConditionCell();
|
functionOrder = index;
|
}
|
|
private void RefreshTreasureUI()
|
{
|
TreasureConfig config = TreasureConfig.Get(selectTreasureId);
|
if (config == null) return;
|
|
DisplayReikiRemind();
|
|
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.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 process;
|
if (hostModel.IsReachCondition(info, out process))
|
{
|
return true;
|
}
|
else
|
{
|
return false;
|
}
|
}
|
}
|
|
private bool IsNoReach(FindTreasureInfo info)
|
{
|
if (info.IsCompleted)
|
{
|
return false;
|
}
|
else
|
{
|
int process;
|
if (hostModel.IsReachCondition(info, out process))
|
{
|
return false;
|
}
|
else
|
{
|
return true;
|
}
|
}
|
}
|
|
private void RefreshConditionCell(ScrollerDataType type, CellView cell)
|
{
|
ReciveConditionCell conditionCell = cell.GetComponent<ReciveConditionCell>();
|
conditionCell.Display(cell.index);
|
}
|
|
}
|
}
|