//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Thursday, April 18, 2019
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace vnxbqy.UI
|
{
|
|
public class HolidayWishPoolWin : Window
|
{
|
List<HolidayWishBottle> bottleList = new List<HolidayWishBottle>();
|
|
ScrollerController m_Controller; // 物品
|
Button wish1;
|
Text wishTxt1;
|
Text wishNeedNum1;
|
|
Button wish2;
|
Text wishTxt2;
|
Text wishNeedNum2;
|
|
Text allStarNum; //可祝福的物品总数
|
RichText wishLegend;
|
Text OpenTime;
|
|
Operation operationType = Operation.HolidayWish;
|
|
HolidayWishPoolModel model { get { return ModelCenter.Instance.GetModel<HolidayWishPoolModel>(); } }
|
PackModel playerPack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
|
#region Built-in
|
protected override void BindController()
|
{
|
bottleList.Add(GetWidgt<HolidayWishBottle>("light1"));
|
bottleList.Add(GetWidgt<HolidayWishBottle>("light2"));
|
bottleList.Add(GetWidgt<HolidayWishBottle>("light3"));
|
bottleList.Add(GetWidgt<HolidayWishBottle>("light4"));
|
bottleList.Add(GetWidgt<HolidayWishBottle>("light5"));
|
|
m_Controller = GetWidgt<ScrollerController>("ScrollerControl");
|
|
wish1 = GetWidgt<Button>("wishbtn1");
|
wishTxt1 = GetWidgt<Text>("Text1");
|
wishNeedNum1 = GetWidgt<Text>("startnum1");
|
|
wish2 = GetWidgt<Button>("wishbtn2");
|
wishTxt2 = GetWidgt<Text>("Text2");
|
wishNeedNum2 = GetWidgt<Text>("startnum2");
|
|
allStarNum = GetWidgt<Text>("allstarnum");
|
wishLegend = GetWidgt<RichText>("Content1");
|
OpenTime = GetWidgt<Text>("OpenTime");
|
}
|
|
|
void UseItemWish(int needEmpty, byte useCnt)
|
{
|
if (useCnt > playerPack.GetItemCountByID(PackType.Item, model.wishItemID))
|
{
|
SysNotifyMgr.Instance.ShowTip("RealmLevelUpError_3");
|
return;
|
}
|
int emptyCnt = playerPack.GetEmptyGridCount(PackType.Item);
|
if (emptyCnt < needEmpty)
|
{
|
SysNotifyMgr.Instance.ShowTip("GeRen_lhs_202580");
|
return;
|
}
|
model.SendWish(useCnt);
|
}
|
|
protected override void AddListeners()
|
{
|
wish1.SetListener(() =>
|
{
|
UseItemWish(2, (byte)model.wishCount1);
|
});
|
|
wish2.SetListener(() =>
|
{
|
UseItemWish(2, (byte)model.wishCount2);
|
});
|
|
}
|
|
protected override void OnPreOpen()
|
{
|
model.RequestLegend();
|
m_Controller.OnRefreshCell += OnRefreshCell;
|
OperationTimeHepler.Instance.operationTimeUpdateEvent += OperationTimeUpdateEvent;
|
playerPack.refreshItemCountEvent += RefreshItemCountEvent;
|
model.UpdateLegendMsg += UpdateLegendMsg;
|
model.UpdateBottleInfo += Display;
|
|
}
|
|
|
protected override void OnAfterOpen()
|
{
|
Display();
|
}
|
|
protected override void OnPreClose()
|
{
|
m_Controller.OnRefreshCell -= OnRefreshCell;
|
OperationTimeHepler.Instance.operationTimeUpdateEvent -= OperationTimeUpdateEvent;
|
playerPack.refreshItemCountEvent -= RefreshItemCountEvent;
|
model.UpdateLegendMsg -= UpdateLegendMsg;
|
model.UpdateBottleInfo -= Display;
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
#endregion
|
|
|
private void RefreshItemCountEvent(PackType packType, int index, int itemId)
|
{
|
if (itemId != model.wishItemID) return;
|
var itemCnt = playerPack.GetItemCountByID(PackType.Item, model.wishItemID);
|
allStarNum.text = itemCnt.ToString();
|
|
if (itemCnt < model.wishSingleNeedNum * model.wishCount1)
|
wishNeedNum1.color = UIHelper.GetUIColor(TextColType.Red, true);
|
else
|
wishNeedNum1.color = UIHelper.GetUIColor(TextColType.LightYellow, true);
|
|
if (itemCnt < model.wishSingleNeedNum * model.wishCount2)
|
wishNeedNum2.color = UIHelper.GetUIColor(TextColType.Red, true);
|
else
|
wishNeedNum2.color = UIHelper.GetUIColor(TextColType.LightYellow, true);
|
}
|
|
void DisplayOpenTime()
|
{
|
OperationHolidayWish operation;
|
if (OperationTimeHepler.Instance.TryGetOperation(operationType, out operation))
|
{
|
OpenTime.text = StringUtility.Contact(Language.Get("ExpActivity_Text1"), operation.ToDisplayTime());
|
}
|
}
|
|
void Display()
|
{
|
OperationHolidayWish holiday;
|
OperationTimeHepler.Instance.TryGetOperation(operationType, out holiday);
|
|
int index = 0;
|
foreach(var key in holiday.wishBottles.Keys)
|
{
|
if (index >= bottleList.Count)
|
{
|
break;
|
}
|
bottleList[index].SetActive(true);
|
bottleList[index].Display(key, holiday);
|
index++;
|
}
|
for (int i = index; i < bottleList.Count; i++)
|
{
|
bottleList[i].SetActive(false);
|
}
|
|
DisplayScroll();
|
DisplayOpenTime();
|
|
var itemCnt = playerPack.GetItemCountByID(PackType.Item, model.wishItemID);
|
|
wishTxt1.text = Language.Get("SubWishInfo4", model.wishCount1);
|
wishNeedNum1.text = (model.wishSingleNeedNum * model.wishCount1).ToString();
|
if (itemCnt < model.wishSingleNeedNum * model.wishCount1)
|
wishNeedNum1.color = UIHelper.GetUIColor(TextColType.Red, true);
|
else
|
wishNeedNum1.color = UIHelper.GetUIColor(TextColType.LightYellow, true);
|
|
wishTxt2.text = Language.Get("SubWishInfo4", model.wishCount2);
|
wishNeedNum2.text = (model.wishSingleNeedNum * model.wishCount2).ToString();
|
if (itemCnt < model.wishSingleNeedNum * model.wishCount2)
|
wishNeedNum2.color = UIHelper.GetUIColor(TextColType.Red, true);
|
else
|
wishNeedNum2.color = UIHelper.GetUIColor(TextColType.LightYellow, true);
|
|
allStarNum.text = itemCnt.ToString();
|
}
|
|
void DisplayScroll()
|
{
|
m_Controller.Refresh();
|
OperationHolidayWish holiday;
|
OperationTimeHepler.Instance.TryGetOperation(operationType, out holiday);
|
|
for (int i = 0; i < holiday.wishPool.Count; i++)
|
{
|
m_Controller.AddCell(ScrollerDataType.Header, i);
|
}
|
m_Controller.Restart();
|
m_Controller.m_Scorller.RefreshActiveCellViews();
|
}
|
|
private void OnRefreshCell(ScrollerDataType type, CellView cell)
|
{
|
if (type != ScrollerDataType.Header) return;
|
var _cell = cell as HolidayWishPoolItemCell;
|
_cell.Display(_cell.index);
|
}
|
|
private void OperationTimeUpdateEvent(Operation type)
|
{
|
if (type == operationType)
|
{
|
Display();
|
}
|
}
|
|
void UpdateLegendMsg()
|
{
|
string msg = string.Empty;
|
foreach (var legend in model.wishLegends)
|
{
|
if (legend.source == 1)
|
{
|
//祝福瓶获得
|
msg += Language.Get("SubWishInfo6", legend.name, legend.itemID, legend.itemCount);
|
}
|
else {
|
msg += Language.Get("SubWishInfo5", legend.name, legend.itemID, legend.itemCount);
|
}
|
}
|
|
wishLegend.text = msg;
|
}
|
|
}
|
}
|