using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Data;
|
using UnityEngine;
|
|
public class FirstChargeWin : FunctionsBaseWin
|
{
|
[Header("标签页")]
|
[SerializeField] TextEx[] txtTabTitles;
|
[SerializeField] ButtonEx[] btnTabs;
|
[SerializeField] RedpointBehaviour[] rpTabs;
|
[Header("主物品")]
|
[SerializeField] TextEx txtName;
|
[SerializeField] TextEx txtDesc;
|
[SerializeField] ImageEx imgCountry;
|
[SerializeField] ImageEx imgJob;
|
[SerializeField] UIHeroController roleLhModel; //展示英雄立绘
|
[SerializeField] ButtonEx btnPreviewHero;
|
[Header("额外道具宣传文字")]
|
[SerializeField] ImageEx imgExtraRewardText;
|
[SerializeField] TextEx txtExtraRewardText;
|
|
[Header("奖励物品")]
|
[SerializeField] FirstChargeDayAward[] days;
|
|
[Header("性价比文字")]
|
[SerializeField] TextEx txtPercentage;
|
|
[Header("购买和领取")]
|
[SerializeField] ImageEx imgHave;
|
[SerializeField] ImageEx imgNoHave;
|
[SerializeField] ImageEx imgRed;
|
[SerializeField] TextEx txtHave;
|
[SerializeField] ButtonEx btnHave;
|
[SerializeField] TextEx txtBuy;
|
[SerializeField] ButtonEx btnBuy;
|
FirstChargeManager model { get { return FirstChargeManager.Instance; } }
|
protected override void InitComponent()
|
{
|
base.InitComponent();
|
btnHave.SetListener(OnClickHaveButton);
|
btnBuy.SetListener(OnClickBuyButton);
|
btnPreviewHero.SetListener(OnClickPreviewHero);
|
}
|
|
|
|
protected override void OnPreOpen()
|
{
|
base.OnPreOpen();
|
InitRedPoint();
|
|
functionOrder = GetDefaultTabIndex();
|
tabButtons[functionOrder].SelectBtn(true);
|
|
int firstId = model.GetFirstIDByTabIndex(functionOrder);
|
model.SetClickTabState(firstId);
|
model.OnUpdateFirstChargeInfo += OnUpdateFirstChargeInfo;
|
GlobalTimeEvent.Instance.secondEvent += OnSecondEvent;
|
DisplayMainItem();
|
Display();
|
}
|
|
protected override void OnPreClose()
|
{
|
base.OnPreClose();
|
model.OnUpdateFirstChargeInfo -= OnUpdateFirstChargeInfo;
|
GlobalTimeEvent.Instance.secondEvent -= OnSecondEvent;
|
}
|
|
private void OnSecondEvent()
|
{
|
int firstId = model.GetFirstIDByTabIndex(functionOrder);
|
if (!model.TryGetFirstChargeDataByFirstId(firstId, out var firstChargeData))
|
return;
|
if (!firstChargeData.IsUnlock())
|
return;
|
if (!firstChargeData.IsBuy())
|
return;
|
DisplayButton(firstId);
|
}
|
|
protected override void OpenSubUIByTabIndex()
|
{
|
int firstId = model.GetFirstIDByTabIndex(functionOrder);
|
model.SetClickTabState(firstId);
|
Display();
|
}
|
|
private void OnUpdateFirstChargeInfo()
|
{
|
Display();
|
}
|
private void OnClickBuyButton()
|
{
|
int firstId = model.GetFirstIDByTabIndex(functionOrder);
|
if (!model.TryGetFirstChargeConfigByFirstID(firstId, out FirstChargeConfig firstChargeConfig))
|
return;
|
RechargeManager.Instance.CTG(firstChargeConfig.CTGID);
|
}
|
|
private void OnClickHaveButton()
|
{
|
int firstId = model.GetFirstIDByTabIndex(functionOrder);
|
model.AutoClaimAllRewards(firstId);
|
}
|
private void OnClickPreviewHero()
|
{
|
HeroUIManager.Instance.selectForPreviewHeroID = model.mainItemId;
|
UIManager.Instance.OpenWindow<HeroBestWin>();
|
}
|
private void InitRedPoint()
|
{
|
for (int i = 0; i < rpTabs.Length; i++)
|
{
|
int firstID = model.GetFirstIDByTabIndex(i);
|
int redpointId = model.GetRedpointIdByFirstId(firstID);
|
rpTabs[i].redpointId = redpointId;
|
}
|
}
|
|
private int GetDefaultTabIndex()
|
{
|
List<int> unlockedAndBoughtAndClaimable = new List<int>(); // 已解锁已购买可领取
|
List<int> unlockedAndNotBought = new List<int>(); // 已解锁未购买
|
List<int> unlockedAndBoughtAndNotClaimed = new List<int>(); // 已解锁已购买未领取
|
|
var firstChargeList = FirstChargeConfig.GetKeys();
|
if (firstChargeList != null)
|
{
|
firstChargeList.Sort();
|
foreach (int firstId in firstChargeList)
|
{
|
if (!model.TryGetFirstChargeDataByFirstId(firstId, out FirstChargeData firstChargeData))
|
continue;
|
|
if (!firstChargeData.IsUnlock())
|
continue;
|
|
if (firstChargeData.IsBuy())
|
{
|
bool hasClaimable = false;
|
bool hasUnclaimed = false;
|
|
for (int day = 1; day <= model.maxDay; day++)
|
{
|
int awardState = firstChargeData.GetHaveState(day);
|
if (awardState == 2) // 可领取
|
{
|
hasClaimable = true;
|
break;
|
}
|
else if (awardState == 1) // 未到领取时间
|
{
|
hasUnclaimed = true;
|
}
|
}
|
|
if (hasClaimable)
|
{
|
unlockedAndBoughtAndClaimable.Add(firstId);
|
}
|
else if (hasUnclaimed)
|
{
|
unlockedAndBoughtAndNotClaimed.Add(firstId);
|
}
|
}
|
else
|
{
|
// 未购买
|
unlockedAndNotBought.Add(firstId);
|
}
|
}
|
|
// 按照优先级返回
|
if (unlockedAndBoughtAndClaimable.Count > 0)
|
{
|
return model.GetTabIndexByFirstID(unlockedAndBoughtAndClaimable[0]);
|
}
|
else if (unlockedAndNotBought.Count > 0)
|
{
|
return model.GetTabIndexByFirstID(unlockedAndNotBought[0]);
|
}
|
else if (unlockedAndBoughtAndNotClaimed.Count > 0)
|
{
|
return model.GetTabIndexByFirstID(unlockedAndBoughtAndNotClaimed[0]);
|
}
|
}
|
|
return 0;
|
}
|
|
private void Display()
|
{
|
int firstId = model.GetFirstIDByTabIndex(functionOrder);
|
DisplayTab();
|
DisplayExtraRewardText(firstId);
|
DisplayAward(firstId);
|
DisplayPercentage(firstId);
|
DisplayButton(firstId);
|
}
|
public void DisplayMainItem()
|
{
|
ItemInfo itemInfo = new ItemInfo();
|
itemInfo.itemId = FirstChargeManager.Instance.mainItemId;
|
HeroInfo heroInfo = new HeroInfo(new ItemModel(PackType.Item, itemInfo));
|
txtName.text = heroInfo.heroConfig.Name;
|
txtName.color = UIHelper.GetUIColorByFunc(heroInfo.Quality);
|
txtDesc.text = heroInfo.heroConfig.Desc;
|
imgCountry.SetSprite(HeroUIManager.Instance.GetCountryIconName(heroInfo.heroConfig.Country));
|
imgJob.SetSprite(HeroUIManager.Instance.GetJobIconName(heroInfo.heroConfig.Class));
|
roleLhModel.Create(heroInfo.SkinID, 0.6f, motionName: "", isLh: true);
|
roleLhModel.transform.localScale = new Vector3(0.6f, 0.6f, 0.6f);
|
}
|
|
public void DisplayAward(int firstId)
|
{
|
for (int i = 0; i < days.Length; i++)
|
{
|
days[i].Display(firstId, i + 1);
|
}
|
}
|
public void DisplayExtraRewardText(int firstId)
|
{
|
if (!model.TryGetFirstChargeConfigByFirstID(firstId, out var config))
|
return;
|
int extraRewardTextType = config.ExtraRewardTextType;
|
if (extraRewardTextType < 0 || extraRewardTextType > 1)
|
return;
|
if (extraRewardTextType == 0)
|
{
|
if (!IconConfig.HasKey(config.ExtraRewardTextInfo))
|
return;
|
imgExtraRewardText.SetActive(true);
|
txtExtraRewardText.SetActive(false);
|
imgExtraRewardText.SetSprite(config.ExtraRewardTextInfo);
|
}
|
else
|
{
|
if (!LanguageConfig.HasKey(config.ExtraRewardTextInfo))
|
return;
|
imgExtraRewardText.SetActive(false);
|
txtExtraRewardText.SetActive(true);
|
txtExtraRewardText.text = Language.Get(config.ExtraRewardTextInfo);
|
}
|
}
|
|
public void DisplayTab()
|
{
|
for (int i = 0; i < btnTabs.Length; i++)
|
{
|
int firstID = model.GetFirstIDByTabIndex(i);
|
FirstChargeData firstChargeData;
|
if (!model.TryGetFirstChargeDataByFirstId(firstID, out firstChargeData))
|
continue;
|
btnTabs[i].SetActive(firstChargeData.IsUnlock());
|
OrderInfoConfig orderInfoConfig;
|
if (model.TryGetOrderInfoConfigByFirstID(firstID, out orderInfoConfig))
|
{
|
txtTabTitles[i].text = Language.Get("PayMoneyNum", orderInfoConfig.PayRMBNum);
|
}
|
}
|
}
|
|
public void DisplayPercentage(int firstId)
|
{
|
if (!model.TryGetCTGConfigByFirstID(firstId, out CTGConfig ctgConfig))
|
return;
|
txtPercentage.text = Language.Get("FirstCharge03", model.maxDay, ctgConfig.Percentage);
|
}
|
|
public void DisplayButton(int firstId)
|
{
|
if (!model.TryGetFirstChargeDataByFirstId(firstId, out var firstChargeData))
|
return;
|
if (!model.TryGetOrderInfoConfigByFirstID(firstId, out OrderInfoConfig orderInfo))
|
return;
|
|
//购买
|
bool isBuy = firstChargeData.IsBuy();
|
btnBuy.SetActive(!isBuy);
|
btnHave.SetActive(isBuy);
|
txtBuy.text = Language.Get("PayMoneyNum", orderInfo.PayRMBNum);
|
//领取
|
int day = firstChargeData.GetNowBuyDay();
|
//0: 已领取 1: 不可领取 2: 可领取
|
int awardState = firstChargeData.GetHaveState(day);
|
bool isAllHave = firstChargeData.IsAllHave();
|
btnHave.interactable = awardState == 2;
|
imgNoHave.SetActive(awardState != 2);
|
imgHave.SetActive(awardState == 2);
|
imgRed.SetActive(awardState == 2);
|
if (awardState == 2)
|
{
|
txtHave.text = Language.Get("Mail09");
|
}
|
else if (awardState == 1 || (awardState == 0 && !isAllHave))
|
{
|
txtHave.text = firstChargeData.GetNextDayUnlockRemainingTime();
|
}
|
else
|
{
|
txtHave.text = Language.Get("FirstCharge04");
|
}
|
|
}
|
}
|