//--------------------------------------------------------
|
// [Author]: 玩个游戏
|
// [ Date ]: Tuesday, July 24, 2018
|
//--------------------------------------------------------
|
|
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
|
////开服盛典
|
public class OSGalaBaseWin : UIBase
|
{
|
[SerializeField] Transform moneyTrans2;
|
[SerializeField] Transform galaTrans;
|
[SerializeField] ScrollerController tabScroller;
|
[SerializeField] Image processImg;
|
[SerializeField] Text galaTimeText;
|
[SerializeField] Text totalScoreText;
|
[SerializeField] ItemCell[] itemCells;
|
[SerializeField] Image[] gotImgs;
|
[SerializeField] Text[] scoreTexts;
|
[SerializeField] UIEffectPlayer[] effectPlayers;
|
|
[SerializeField] Transform totalRechargeTrans;
|
[SerializeField] Text totalRechargeTimeText;
|
[SerializeField] ItemCell totalRechargeItemCell;
|
[SerializeField] Text totalRechargeScoreText;
|
[SerializeField] RotationTween totalRechargeRotationTween;
|
[SerializeField] Image totalRechargeFreeRedImage;
|
[SerializeField] Image totalRechargeHaveImage;
|
|
[SerializeField] Transform totDayRechargeTrans;
|
[SerializeField] Text totDayRechargeTimeText;
|
[SerializeField] ItemCell totDayRechargeItemCell;
|
[SerializeField] Text totDayRechargeScoreText;
|
[SerializeField] RotationTween totDayRechargeRotationTween;
|
[SerializeField] Image totDayRechargeFreeRedImage;
|
[SerializeField] Image totDayRechargeHaveImage;
|
|
private int nowTabId = 0;
|
private UIBase currentSubUI;
|
private List<int> tabIdList = new List<int> { 0, 1, 2, 3, 4 };
|
private Dictionary<int, string> tabTitleKeys = new Dictionary<int, string>
|
{
|
{ 0, "DayMission1" },
|
{ 1, "OSActivity9" },
|
{ 2, "OSActivity3" },
|
{ 3, "TotalRecharge04" },
|
{ 4, "TotalRecharge05" },
|
};
|
private Dictionary<int, int> tabRedpointKeys = new Dictionary<int, int>
|
{
|
{ 0, 1131 },
|
{ 1, 1132 },
|
{ 2, 1133 },
|
{ 3, 1135 },
|
{ 4, 1136 },
|
};
|
|
protected override void OnPreOpen()
|
{
|
tabScroller.OnRefreshCell += OnRefreshTabCell;
|
OSActivityManager.Instance.OnOSGalaDataChangeEvent += OnOSGalaDataChangeEvent;
|
GlobalTimeEvent.Instance.secondEvent += ShowTime;
|
StoreModel.Instance.RefreshBuyShopLimitEvent += OnRefreshBuyShopLimitEvent;
|
TotalRechargeManager.Instance.OnTotalRechargePlayerInfoEvent += OnTotalRechargePlayerInfoEvent;
|
TotDayRechargeManager.Instance.OnTotDayRechargePlayerInfoEvent += OnTotDayRechargePlayerInfoEvent;
|
CreateTabScroller();
|
Display();
|
}
|
|
protected override void OnPreClose()
|
{
|
tabScroller.OnRefreshCell -= OnRefreshTabCell;
|
OSActivityManager.Instance.OnOSGalaDataChangeEvent -= OnOSGalaDataChangeEvent;
|
GlobalTimeEvent.Instance.secondEvent -= ShowTime;
|
StoreModel.Instance.RefreshBuyShopLimitEvent -= OnRefreshBuyShopLimitEvent;
|
TotalRechargeManager.Instance.OnTotalRechargePlayerInfoEvent -= OnTotalRechargePlayerInfoEvent;
|
TotDayRechargeManager.Instance.OnTotDayRechargePlayerInfoEvent -= OnTotDayRechargePlayerInfoEvent;
|
CloseCurrentSubUI();
|
}
|
|
private void OnTotDayRechargePlayerInfoEvent()
|
{
|
tabScroller.m_Scorller.RefreshActiveCellViews();
|
RefreshRechargeTransData();
|
Display();
|
}
|
|
private void OnTotalRechargePlayerInfoEvent()
|
{
|
tabScroller.m_Scorller.RefreshActiveCellViews();
|
RefreshRechargeTransData();
|
Display();
|
}
|
|
private void OnRefreshBuyShopLimitEvent()
|
{
|
tabScroller.m_Scorller.RefreshActiveCellViews();
|
RefreshRechargeTransData();
|
Display();
|
}
|
|
private void CreateTabScroller()
|
{
|
tabScroller.Refresh();
|
bool isOSGalaOpen = OSActivityManager.Instance.IsOpenedOSGala();
|
bool isTotDayRechargeOpen = TotDayRechargeManager.Instance.IsOpen;
|
bool isTotalRechargeOpen = TotalRechargeManager.Instance.IsOpen;
|
List<int> visibleTabs = new List<int>();
|
for (int i = 0; i < tabIdList.Count; i++)
|
{
|
int tabId = tabIdList[i];
|
bool canShow = false;
|
if (tabId == 0 || tabId == 1 || tabId == 2)
|
{
|
canShow = isOSGalaOpen;
|
}
|
else if (tabId == 3)
|
{
|
canShow = isTotalRechargeOpen;
|
}
|
else if (tabId == 4)
|
{
|
canShow = isTotDayRechargeOpen;
|
}
|
if (canShow)
|
{
|
visibleTabs.Add(tabId);
|
tabScroller.AddCell(ScrollerDataType.Header, tabId);
|
}
|
}
|
if (visibleTabs.Count > 0)
|
{
|
nowTabId = visibleTabs[0];
|
}
|
tabScroller.Restart();
|
SelectBottomTab(nowTabId);
|
}
|
|
private void OnRefreshTabCell(ScrollerDataType type, CellView cell)
|
{
|
var _cell = cell.GetComponent<OSGalaTabCell>();
|
string titleKey = tabTitleKeys.ContainsKey(cell.index) ? tabTitleKeys[cell.index] : "";
|
int redpointId = tabRedpointKeys.ContainsKey(cell.index) ? tabRedpointKeys[cell.index] : 0;
|
_cell?.Display(cell.index, nowTabId, titleKey, redpointId, OnTabClicked);
|
}
|
|
private void OnTabClicked(int index)
|
{
|
if (nowTabId == index)
|
{
|
return;
|
}
|
nowTabId = index;
|
tabScroller.m_Scorller.RefreshActiveCellViews();
|
SelectBottomTab(index);
|
}
|
|
private void SelectBottomTab(int index)
|
{
|
if (currentSubUI != null)
|
{
|
currentSubUI.CloseWindow();
|
currentSubUI = null;
|
}
|
|
galaTrans.SetActive(index == 0 || index == 1 || index == 2);
|
moneyTrans2.SetActive(index == 0 || index == 1 || index == 2);
|
|
totalRechargeTrans.SetActive(index == 3);
|
totDayRechargeTrans.SetActive(index == 4);
|
|
switch (index)
|
{
|
case 0:
|
currentSubUI = UIManager.Instance.OpenWindow<OSGalaMissionWin>();
|
break;
|
case 1:
|
currentSubUI = UIManager.Instance.OpenWindow<OSGalaChangeWin>();
|
break;
|
case 2:
|
currentSubUI = UIManager.Instance.OpenWindow<OSGalaGiftWin>();
|
break;
|
case 3:
|
currentSubUI = UIManager.Instance.OpenWindow<TotalRechargeWin>();
|
|
var data = TotalRechargeManager.Instance.GetStoreData();
|
bool isReceived = TotalRechargeManager.Instance.IsReceived(data.shopId);
|
totalRechargeItemCell.Init(new ItemCellModel(data.storeConfig.ItemID, false, data.storeConfig.ItemCnt));
|
totalRechargeItemCell.button.SetListener(() =>
|
{
|
if (!isReceived)
|
{
|
StoreModel.Instance.SendBuyShopItem(data.storeConfig, 1);
|
}
|
else
|
{
|
ItemTipUtility.Show(data.storeConfig.ItemID);
|
}
|
|
});
|
|
totalRechargeHaveImage.SetActive(isReceived);
|
totalRechargeFreeRedImage.SetActive(!isReceived);
|
totalRechargeTimeText.text = TotalRechargeManager.Instance.GetActTimeStr();
|
totalRechargeScoreText.text = Language.Get("TotalRecharge06", TotalRechargeManager.Instance.coinTotal);
|
if (!isReceived)
|
{
|
totalRechargeRotationTween.Play();
|
}
|
else
|
{
|
totalRechargeRotationTween.Stop();
|
totalRechargeRotationTween.SetStartState();
|
}
|
break;
|
case 4:
|
currentSubUI = UIManager.Instance.OpenWindow<TotDayRechargeWin>();
|
|
var data1 = TotDayRechargeManager.Instance.GetStoreData();
|
bool isReceived1 = TotDayRechargeManager.Instance.IsReceived(data1.shopId);
|
totDayRechargeItemCell.Init(new ItemCellModel(data1.storeConfig.ItemID, false, data1.storeConfig.ItemCnt));
|
totDayRechargeItemCell.button.SetListener(() =>
|
{
|
if (!isReceived1)
|
{
|
StoreModel.Instance.SendBuyShopItem(data1.storeConfig, 1);
|
}
|
else
|
{
|
ItemTipUtility.Show(data1.storeConfig.ItemID);
|
}
|
|
});
|
|
totDayRechargeHaveImage.SetActive(isReceived1);
|
totDayRechargeFreeRedImage.SetActive(!isReceived1);
|
totDayRechargeTimeText.text = TotDayRechargeManager.Instance.GetActTimeStr();
|
totDayRechargeScoreText.text = Language.Get("TotalRecharge07", TotDayRechargeManager.Instance.totalDays);
|
if (!isReceived1)
|
{
|
totDayRechargeRotationTween.Play();
|
}
|
else
|
{
|
totDayRechargeRotationTween.Stop();
|
totDayRechargeRotationTween.SetStartState();
|
}
|
break;
|
}
|
}
|
|
private void CloseCurrentSubUI()
|
{
|
if (currentSubUI != null)
|
{
|
currentSubUI.CloseWindow();
|
currentSubUI = null;
|
}
|
}
|
|
/// <summary>
|
/// 刷新累计充值和每日充值界面的数据(不重新创建界面)
|
/// </summary>
|
private void RefreshRechargeTransData()
|
{
|
// 刷新累计充值数据(tab 3)
|
if (nowTabId == 3)
|
{
|
var data = TotalRechargeManager.Instance.GetStoreData();
|
bool isReceived = TotalRechargeManager.Instance.IsReceived(data.shopId);
|
totalRechargeItemCell.Init(new ItemCellModel(data.storeConfig.ItemID, false, data.storeConfig.ItemCnt));
|
totalRechargeHaveImage.SetActive(isReceived);
|
totalRechargeFreeRedImage.SetActive(!isReceived);
|
totalRechargeTimeText.text = TotalRechargeManager.Instance.GetActTimeStr();
|
totalRechargeScoreText.text = Language.Get("TotalRecharge06", TotalRechargeManager.Instance.coinTotal);
|
if (!isReceived)
|
{
|
totalRechargeRotationTween.Play();
|
}
|
else
|
{
|
totalRechargeRotationTween.Stop();
|
totalRechargeRotationTween.SetStartState();
|
}
|
}
|
// 刷新每日充值数据(tab 4)
|
else if (nowTabId == 4)
|
{
|
var data1 = TotDayRechargeManager.Instance.GetStoreData();
|
bool isReceived1 = TotDayRechargeManager.Instance.IsReceived(data1.shopId);
|
totDayRechargeItemCell.Init(new ItemCellModel(data1.storeConfig.ItemID, false, data1.storeConfig.ItemCnt));
|
totDayRechargeHaveImage.SetActive(isReceived1);
|
totDayRechargeFreeRedImage.SetActive(!isReceived1);
|
totDayRechargeTimeText.text = TotDayRechargeManager.Instance.GetActTimeStr();
|
totDayRechargeScoreText.text = Language.Get("TotalRecharge07", TotDayRechargeManager.Instance.totalDays);
|
if (!isReceived1)
|
{
|
totDayRechargeRotationTween.Play();
|
}
|
else
|
{
|
totDayRechargeRotationTween.Stop();
|
totDayRechargeRotationTween.SetStartState();
|
}
|
}
|
}
|
|
private void OnOSGalaDataChangeEvent()
|
{
|
Display();
|
}
|
|
void Display()
|
{
|
var keys = OSActivityManager.Instance.osGalaScoreAwards.Keys.ToList();
|
keys.Sort();
|
// value 分段,按keys中的达标获取
|
var addValue = 1.0f / keys.Count;
|
var value = 0f;
|
for (int i = 0; i < keys.Count; i++)
|
{
|
var score = keys[i];
|
var award = OSActivityManager.Instance.osGalaScoreAwards[score];
|
if (OSActivityManager.Instance.osGalaScore >= score)
|
{
|
value += addValue;
|
}
|
else
|
{
|
break;
|
}
|
}
|
processImg.fillAmount = value;
|
ShowTime();
|
totalScoreText.text = Language.Get("OSActivity11") + OSActivityManager.Instance.osGalaScore.ToString();
|
|
for (int i = 0; i < itemCells.Length; i++)
|
{
|
if (i < keys.Count)
|
{
|
itemCells[i].SetActive(true);
|
int score = keys[i];
|
int index = i;
|
int itemID = OSActivityManager.Instance.osGalaScoreAwards[score][0][0];
|
itemCells[i].Init(new ItemCellModel(itemID, false, OSActivityManager.Instance.osGalaScoreAwards[score][0][1]));
|
itemCells[i].button.AddListener(() =>
|
{
|
if (!OSActivityManager.Instance.CanGetAward(index, score))
|
{
|
ItemTipUtility.Show(itemID);
|
return;
|
}
|
|
var pack = new CA504_tagCMPlayerGetReward();
|
pack.RewardType = 9;
|
pack.DataEx = (uint)score;
|
GameNetSystem.Instance.SendInfo(pack);
|
});
|
|
gotImgs[i].SetActive(OSActivityManager.Instance.IsGotAward(i));
|
scoreTexts[i].text = keys[i].ToString();
|
if (OSActivityManager.Instance.CanGetAward(index, score))
|
{
|
effectPlayers[i].Play();
|
}
|
else
|
{
|
effectPlayers[i].Stop();
|
}
|
}
|
else
|
{
|
itemCells[i].SetActive(false);
|
}
|
}
|
}
|
|
void ShowTime()
|
{
|
if (TimeUtility.OpenDay >= OSActivityManager.Instance.osGalaOpenDays)
|
{
|
galaTimeText.text = Language.Get("OSActivity6");
|
}
|
else
|
{
|
galaTimeText.text = Language.Get("OSActivity10") + TimeUtility.SecondsToShortDHMS(TimeUtility.GetRemindTimeByOpenDay(OSActivityManager.Instance.osGalaOpenDays));
|
}
|
totalRechargeTimeText.text = TotalRechargeManager.Instance.GetActTimeStr();
|
totDayRechargeTimeText.text = TotDayRechargeManager.Instance.GetActTimeStr();
|
}
|
}
|