//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Monday, November 12, 2018
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
using EnhancedUI.EnhancedScroller;
|
|
namespace vnxbqy.UI
|
{
|
|
public class IceCrystalVeinWin : Window, SecondWindowInterface
|
{
|
[SerializeField] ScrollerController m_ScrollerController;
|
[SerializeField] Button m_SweepingButton;//扫荡
|
[SerializeField] Button m_ChallengeButton;//挑战
|
[SerializeField] Transform m_GridMiddle;//中间组
|
[SerializeField] Transform m_GridBottom;//底层组
|
[SerializeField] Text m_TextNumber;//扫荡战力
|
[SerializeField] Text m_Text_Fight;//我的战力
|
[SerializeField] Text m_TextLv;//挑战等级
|
IceCrystalVeinModel m_IceCrystalVeinModel;
|
IceCrystalVeinModel iceCrystalVeinModel { get { return m_IceCrystalVeinModel ?? (m_IceCrystalVeinModel = ModelCenter.Instance.GetModel<IceCrystalVeinModel>()); } }
|
DungeonModel m_Model;
|
DungeonModel model { get { return m_Model ?? (m_Model = ModelCenter.Instance.GetModel<DungeonModel>()); } }
|
|
public Button close { get; set; }
|
|
private int IndexSelect = 1;
|
private int StarAll = 0;
|
private Dictionary<int, int> IceCrystalVeinMiddleDic = new Dictionary<int, int>();
|
private List<IceLodeStarAwardClass> IceLodeStarAwardList = new List<IceLodeStarAwardClass>();
|
#region Built-in
|
protected override void BindController()
|
{
|
if (this is SecondWindowInterface)
|
{
|
var frame = this.GetComponentInChildren<SecondFrameLoader2>();
|
frame.Create();
|
close = frame.GetComponentInChildren<Button>();
|
}
|
|
m_ScrollerController.OnRefreshCell += OnRefreshGridCell;
|
var _IceCrystalVeinReward = FuncConfigConfig.Get("IceCrystalVeinReward");
|
IceCrystalVeinMiddleDic = ConfigParse.GetDic<int, int>(_IceCrystalVeinReward.Numerical1);
|
var Openconfig = FuncOpenLVConfig.Get(83);
|
m_TextLv.text = Language.Get("IceCrystal_4", Openconfig.LimitLV);
|
}
|
|
protected override void AddListeners()
|
{
|
close.AddListener(OnClickClose);
|
m_SweepingButton.AddListener(OnClickSweeping);
|
m_ChallengeButton.AddListener(OnClickChallenge);
|
}
|
|
protected override void OnPreOpen()
|
{
|
StarAll = iceCrystalVeinModel.GetAllStar();
|
SelectedByDefault();
|
OnCreateGridLineCell(m_ScrollerController);
|
AddIceLodeStarAwardList();
|
SetGridMiddle();
|
SetGridBotton();
|
SetText();
|
}
|
|
protected override void OnAfterOpen()
|
{
|
model.dungeonRecordChangeEvent += dungeonRecordChangeEvent;
|
iceCrystalVeinModel.UpdateIceLodeInf += UpdateIceLodeInf;
|
PlayerDatas.Instance.playerDataRefreshEvent += Updatefighting;//数据的刷新(h0418)
|
}
|
|
|
protected override void OnPreClose()
|
{
|
}
|
|
protected override void OnAfterClose()
|
{
|
model.dungeonRecordChangeEvent -= dungeonRecordChangeEvent;
|
iceCrystalVeinModel.UpdateIceLodeInf -= UpdateIceLodeInf;
|
PlayerDatas.Instance.playerDataRefreshEvent -= Updatefighting;//数据的刷新(h0418)
|
}
|
|
private void Updatefighting(PlayerDataType obj)
|
{
|
if (obj == PlayerDataType.FightPower)
|
{
|
SetText();
|
}
|
if (obj == PlayerDataType.LV)
|
{
|
SetText();
|
}
|
}
|
|
private void UpdateIceLodeInf()
|
{
|
StarAll = iceCrystalVeinModel.GetAllStar();
|
m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见
|
SetGridBotton();
|
}
|
|
private void dungeonRecordChangeEvent(int fbId)
|
{
|
if (fbId == IceCrystalVeinModel.ICECRYSTALVEIN_MAPID)
|
{
|
StarAll = iceCrystalVeinModel.GetAllStar();
|
SetGridBotton();
|
m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见
|
}
|
}
|
|
#endregion
|
private void OnClickClose()
|
{
|
Close();
|
}
|
private void OnClickSweeping()
|
{
|
var _Dungeon = new Dungeon(31140, 0);
|
model.selectedKylinDungeon = _Dungeon;
|
var dungeonId = model.GetDungeonId(_Dungeon);
|
var dungeonConfig = DungeonConfig.Get(dungeonId);
|
if (dungeonConfig == null)
|
{
|
return;
|
}
|
if (PlayerDatas.Instance.baseData.MapID == IceCrystalVeinModel.ICECRYSTALVEIN_MAPID)//副本中不允许扫荡
|
{
|
SysNotifyMgr.Instance.ShowTip("IceCrystal_Sweep");
|
return;
|
}
|
if (dungeonConfig.SweepLVLimit > PlayerDatas.Instance.baseData.LV)
|
{
|
SysNotifyMgr.Instance.ShowTip("IceCrystal_LV", dungeonConfig.SweepLVLimit);
|
return;
|
}
|
if (iceCrystalVeinModel.NeedVipLv > PlayerDatas.Instance.baseData.VIPLv)//所需VIP等级不足
|
{
|
SysNotifyMgr.Instance.ShowTip("IceCrystal_VIP", iceCrystalVeinModel.NeedVipLv);
|
return;
|
}
|
var PlayerLV = PlayerLVConfig.Get(PlayerDatas.Instance.baseData.LV);
|
if (PlayerLV == null)
|
{
|
return;
|
}
|
if ((ulong)PlayerLV.IceLodeFightPower > PlayerDatas.Instance.baseData.FightPoint)//所需战力不足
|
{
|
SysNotifyMgr.Instance.ShowTip("IceCrystal_Point", PlayerLV.IceLodeFightPower);
|
return;
|
}
|
if (iceCrystalVeinModel.HasSweep != 0)//花费扫荡
|
{
|
string str = Language.Get("IceCrystal_2", iceCrystalVeinModel.SweepingNeedMoney);
|
ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), str, (bool isOk) =>
|
{
|
if (isOk)
|
{
|
int Money = (int)UIHelper.GetMoneyCnt(1);
|
if (Money >= iceCrystalVeinModel.SweepingNeedMoney)
|
{
|
model.RequestSweep(model.selectedKylinDungeon);
|
}
|
else
|
{
|
WindowCenter.Instance.Open<RechargeTipWin>();
|
}
|
}
|
});
|
return;
|
}
|
else//免费扫荡
|
{
|
model.RequestSweep(model.selectedKylinDungeon);
|
return;
|
}
|
}
|
private void OnClickChallenge()
|
{
|
if (iceCrystalVeinModel.IsFree(IndexSelect))//免费
|
{
|
EnterTheCopy();
|
}
|
else//收费
|
{
|
string str = Language.Get("IceCrystal_1", iceCrystalVeinModel.Cost);
|
ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), str, (bool isOk) =>
|
{
|
if (isOk)
|
{
|
int diamond = (int)UIHelper.GetMoneyCnt(1);
|
if (diamond >= iceCrystalVeinModel.Cost)
|
{
|
EnterTheCopy();
|
}
|
else
|
{
|
WindowCenter.Instance.Open<RechargeTipWin>();
|
}
|
}
|
});
|
}
|
|
}
|
private void EnterTheCopy()
|
{
|
|
model.currentDungeon = new Dungeon(31140, IndexSelect);
|
model.SingleChallenge(model.currentDungeon);
|
}
|
|
void OnCreateGridLineCell(ScrollerController gridCtrl)
|
{
|
gridCtrl.Refresh();
|
for (int i = 0; i < iceCrystalVeinModel.LineList.Count; i++)
|
{
|
gridCtrl.AddCell(ScrollerDataType.Header, iceCrystalVeinModel.LineList[i]);
|
}
|
gridCtrl.Restart();
|
}
|
private void OnRefreshGridCell(ScrollerDataType type, CellView cell)
|
{
|
GameObject Obj1 = cell.transform.Find("TargetBox_1").gameObject;
|
GameObject Obj2 = cell.transform.Find("TargetBox_2").gameObject;
|
int Index = cell.index;
|
if (Index == IndexSelect)
|
{
|
Obj1.SetActive(true);
|
Obj2.SetActive(false);
|
IceCrystalVeinCell iceCrystal = Obj1.GetComponent<IceCrystalVeinCell>();
|
iceCrystal.SetIceCrystalVeinCell(Index);
|
iceCrystal._Button.SetListener(() =>
|
{
|
IndexSelect = Index;
|
m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见
|
});
|
}
|
else
|
{
|
Obj1.SetActive(false);
|
Obj2.SetActive(true);
|
IceCrystalVeinCell iceCrystal = Obj2.GetComponent<IceCrystalVeinCell>();
|
iceCrystal.SetIceCrystalVeinCell(Index);
|
iceCrystal._Button.SetListener(() =>
|
{
|
IndexSelect = Index;
|
m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见
|
});
|
}
|
}
|
private void SetGridMiddle()
|
{
|
for (int i = 0; i < m_GridMiddle.childCount; i++)
|
{
|
GameObject ObjChild = m_GridMiddle.GetChild(i).gameObject;
|
ObjChild.SetActive(false);
|
}
|
int INDEX = 0;
|
foreach (var key in IceCrystalVeinMiddleDic.Keys)
|
{
|
GameObject ObjChild = m_GridMiddle.GetChild(INDEX).gameObject;
|
ObjChild.SetActive(true);
|
INDEX += 1;
|
ItemCell _ItemCell = ObjChild.GetComponent<ItemCell>();
|
ItemCellModel cellModel = new ItemCellModel(key, true, (ulong)IceCrystalVeinMiddleDic[key]);
|
_ItemCell.Init(cellModel);
|
_ItemCell.button.SetListener(() =>
|
{
|
ItemTipUtility.Show(key);
|
});
|
}
|
}
|
private void SetGridBotton()
|
{
|
for (int i = 0; i < m_GridBottom.childCount; i++)
|
{
|
|
GameObject ObjChild = m_GridBottom.GetChild(i).gameObject;
|
if (i < IceLodeStarAwardList.Count)
|
{
|
IceLodeStarAwardClass IceLode = IceLodeStarAwardList[i];
|
ObjChild.SetActive(true);
|
ItemCell _ItemCell = ObjChild.transform.Find("ItemCell_1").GetComponent<ItemCell>();
|
Text TextStar = ObjChild.transform.Find("Text_Star").GetComponent<Text>();
|
GameObject m_NIKE = ObjChild.transform.Find("NIKE").gameObject;
|
GameObject m_Collar = ObjChild.transform.Find("Collar").gameObject;
|
if (StarAll >= IceLode.Star)
|
{
|
TextStar.text = Language.Get("IceCrystal_G", StarAll, IceLode.Star);
|
}
|
else
|
{
|
TextStar.text = Language.Get("IceCrystal_R", StarAll, IceLode.Star);
|
}
|
m_NIKE.SetActive(false);
|
m_Collar.SetActive(false);
|
bool _bool = MathUtility.GetBitValue((uint)iceCrystalVeinModel.AwardRecord, (ushort)IceLode.Index);
|
if (StarAll >= IceLode.Star)//是否到达领取条件
|
{
|
if (_bool)
|
{
|
m_NIKE.SetActive(true);
|
}
|
else
|
{
|
m_Collar.SetActive(true);
|
}
|
}
|
ItemCellModel cellModel = new ItemCellModel(IceLode.ItemID, true, (ulong)IceLode.ItemCount);
|
_ItemCell.Init(cellModel);
|
int type = i;
|
_ItemCell.button.SetListener(() =>
|
{
|
if (StarAll >= IceLode.Star && !_bool)
|
{
|
iceCrystalVeinModel.SendGetAward(IceLode.Index);
|
return;
|
}
|
|
ItemTipUtility.Show(IceLode.ItemID);
|
return;
|
});
|
}
|
else
|
{
|
ObjChild.SetActive(false);
|
}
|
}
|
}
|
private void AddIceLodeStarAwardList()
|
{
|
IceLodeStarAwardList.Clear();
|
foreach (var key in iceCrystalVeinModel.DicIceLodeStarAward.Keys)
|
{
|
var Dic = iceCrystalVeinModel.DicIceLodeStarAward[key];
|
int Lv = iceCrystalVeinModel.DayLv;
|
if (Lv >= Dic.MinLv && Lv <= Dic.MaxLv)
|
{
|
IceLodeStarAwardList.Add(Dic);
|
}
|
}
|
}
|
private void SetText()
|
{
|
m_Text_Fight.text = PlayerDatas.Instance.baseData.FightPoint.ToString();
|
int Lv = PlayerDatas.Instance.baseData.LV;
|
|
var PlayerLV = PlayerLVConfig.Get(Lv);
|
if (PlayerLV == null)
|
{
|
return;
|
}
|
m_TextNumber.text = PlayerLV.IceLodeFightPower.ToString();
|
//if (PlayerDatas.Instance.baseData.FightPoint >= PlayerLV.IceLodeFightPower)
|
//{
|
// m_Text_Fight.color = new Color32(16,157,6,255);
|
//}
|
//else
|
//{
|
// m_Text_Fight.color = new Color32(255, 3, 3, 255);
|
//}
|
}
|
private void SelectedByDefault()//默认选中
|
{
|
int Star = 9;
|
for (int i = 0; i < iceCrystalVeinModel.LineList.Count; i++)
|
{
|
DungeonRecord dungeonRecord;
|
if (model.TryGetRecord(31140, out dungeonRecord))
|
{
|
int Id = iceCrystalVeinModel.LineList[i];
|
if (dungeonRecord.lineGrades.ContainsKey(Id))
|
{
|
if (dungeonRecord.lineGrades[Id] < Star)
|
{
|
Star = dungeonRecord.lineGrades[Id];
|
IndexSelect = Id;
|
}
|
|
}
|
}
|
}
|
}
|
}
|
|
}
|
|
|
|
|