using System;
|
using UnityEngine;
|
using TableConfig;
|
using UnityEngine.UI;
|
using System.Collections.Generic;
|
using System.Collections;
|
|
namespace Snxxz.UI
|
{
|
public class VipInvestWin : Window
|
{
|
[SerializeField] ScrollerController ctrl;
|
[SerializeField] Button investBtn;
|
[SerializeField] GameObject m_Realized_BGM;
|
[SerializeField] Text m_RemainingDays;//剩余天数
|
//---------------------------------
|
[SerializeField] Transform m_ButtonGroup;//按钮组
|
[SerializeField] Button m_Button_one;
|
[SerializeField] Button m_Button_Two;
|
[SerializeField] Button m_Button_Three;
|
[SerializeField] Button m_Button_Four;
|
|
[SerializeField] Button m_GoToVipBoss;
|
VipInvestModel _investModel;
|
VipInvestModel investModel { get { return _investModel ?? (_investModel = ModelCenter.Instance.GetModel<VipInvestModel>()); } }
|
ItemTipsModel _tipsModel;
|
ItemTipsModel tipsModel { get { return _tipsModel ?? (_tipsModel = ModelCenter.Instance.GetModel<ItemTipsModel>()); } }
|
|
private List<InvestConfig> configlist;
|
int cycle = 0;
|
string investIndex = "";
|
ServerInvestInfo InvestInfo;
|
public static event Action VipInvestRedPointEvent;
|
protected override void BindController()
|
{
|
ctrl.OnRefreshCell += RefreshRewardCell;
|
ctrl.lockType = EnhanceLockType.KeepVertical;
|
investBtn.AddListener(ClickInvestBtn);
|
}
|
protected override void AddListeners()
|
{
|
m_Button_one.AddListener(OnclickButtonOne);
|
m_Button_Two.AddListener(OnClickButtonTwo);
|
m_Button_Three.AddListener(OnClickButtonThree);
|
m_Button_Four.AddListener(OnClickButtonFour);
|
m_GoToVipBoss.AddListener(OnClickVipBossWin);
|
}
|
|
protected override void OnPreOpen()
|
{
|
|
InvestInfo = investModel.GetInvestInfoByType((int)InvestType.Vip);
|
cycle = investModel.GetInvestCycle(InvestInfo.curDay);
|
investIndex = investModel.GetVipInvestIndex();
|
|
if (InvestInfo.curDay <= 0)
|
{
|
m_RemainingDays.text = string.Format(Language.Get("TheRemainingNumberDays_Z"), UIHelper.GetTextColorByItemColor(TextColType.Green, 0.ToString(), true));
|
}
|
else
|
{
|
m_RemainingDays.text = string.Format(Language.Get("TheRemainingNumberDays_Z"), UIHelper.GetTextColorByItemColor(TextColType.Green, (28 - InvestInfo.curDay).ToString(), true));
|
}
|
|
if (InvestInfo.investGold <= 0)
|
{
|
m_Realized_BGM.SetActive(false);
|
investBtn.gameObject.SetActive(true);
|
cycle = 1;
|
}
|
else
|
{
|
m_Realized_BGM.SetActive(true);
|
investBtn.gameObject.SetActive(false);
|
}
|
SwithWeek(cycle);
|
//configlist = investModel.GetInvestConfiglistByCycle(cycle);
|
//CreateRewardCell();
|
investModel.RefreshInvestAct += RefreshInvestState;
|
}
|
|
protected override void OnAfterOpen()
|
{
|
if (investModel.redPointStre1.state==RedPointState.Simple)
|
{
|
investModel.IsRedpoint = false;
|
if (VipInvestRedPointEvent != null)
|
{
|
VipInvestRedPointEvent();
|
}
|
}
|
|
}
|
|
protected override void OnPreClose()
|
{
|
investModel.RefreshInvestAct -= RefreshInvestState;
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
|
|
private void RefreshInvestState(int obj)
|
{
|
if (obj == 2)
|
{
|
CreateRewardCell();
|
InvestInfo = investModel.GetInvestInfoByType((int)InvestType.Vip);
|
if (InvestInfo.investGold <= 0)
|
{
|
m_Realized_BGM.SetActive(false);
|
investBtn.gameObject.SetActive(true);
|
cycle = 1;
|
}
|
else
|
{
|
m_Realized_BGM.SetActive(true);
|
investBtn.gameObject.SetActive(false);
|
}
|
if (InvestInfo.curDay <= 0)
|
{
|
m_RemainingDays.text = string.Format(Language.Get("TheRemainingNumberDays_Z"), UIHelper.GetTextColorByItemColor(TextColType.Green, 0.ToString(), true));
|
}
|
else
|
{
|
m_RemainingDays.text = string.Format(Language.Get("TheRemainingNumberDays_Z"), UIHelper.GetTextColorByItemColor(TextColType.Green, (28 - InvestInfo.curDay).ToString(), true));
|
}
|
}
|
}
|
|
private void CreateRewardCell()
|
{
|
if (ctrl.GetNumberOfCells(ctrl.m_Scorller) > 0)
|
{
|
ctrl.m_Scorller.RefreshActiveCellViews();
|
}
|
else
|
{
|
ctrl.Refresh();
|
if (configlist != null)
|
{
|
for (int i = 0; i < configlist.Count; i++)
|
{
|
ctrl.AddCell(ScrollerDataType.Header, i);
|
}
|
}
|
ctrl.Restart();
|
}
|
int a_Week= investModel.GetInvestCycle(InvestInfo.curDay);
|
if (a_Week == cycle)
|
{
|
ctrl.JumpIndex(investModel.JumpIndex);
|
}
|
else
|
{
|
ctrl.JumpIndex(0);
|
}
|
|
}
|
|
private void RefreshRewardCell(ScrollerDataType type, CellView cell)
|
{
|
Text titleText = cell.transform.Find("Title").GetComponent<Text>();
|
Button button = cell.transform.Find("ReceiveBtn").GetComponent<Button>();
|
UIEffect uieffect = button.GetComponent<UIEffect>();
|
Text BtnText = button.transform.Find("Text").GetComponent<Text>();
|
GameObject rewardParent = cell.transform.Find("Itemlist").gameObject;
|
GameObject IsDrawImage = cell.transform.Find("IsDrawImage").gameObject;//已领取
|
GameObject IsMissImage = cell.transform.Find("IsMissImage").gameObject;//已错过
|
GameObject IsReachImage = cell.transform.Find("IsReachImage").gameObject;//未达成
|
|
int day = cell.index + 1;
|
titleText.text = string.Format(Language.Get("VipInvestmentHint"), cycle, day);
|
InvestConfig config = configlist[cell.index];
|
|
List<InvestReward> rewardlist = investModel.GetInvestRewardlistByID(config.id, config.type, config.needDay, investIndex);
|
for (int i = 0; i < rewardParent.transform.childCount; i++)
|
{
|
CommonItemBaisc itemBaisc = rewardParent.transform.GetChild(i).GetComponent<CommonItemBaisc>();
|
if (i < rewardlist.Count)
|
{
|
itemBaisc.gameObject.SetActive(true);
|
InvestReward reward = rewardlist[i];
|
ItemCellModel cellModel = new ItemCellModel(reward.id, false, reward.count, reward.isBind);
|
itemBaisc.Init(cellModel);
|
itemBaisc.cellBtn.RemoveAllListeners();
|
itemBaisc.cellBtn.AddListener(() =>
|
{
|
ItemAttrData attrData = new ItemAttrData(reward.id, false, reward.count, -1, reward.isBind);
|
tipsModel.SetItemTipsModel(attrData);
|
});
|
}
|
else
|
{
|
itemBaisc.gameObject.SetActive(false);
|
}
|
}
|
|
button.RemoveAllListeners();
|
RewardRecordState recordState = investModel.GetRecordByIndex((int)InvestType.Vip, config.needDay);
|
switch (recordState)
|
{
|
case RewardRecordState.None:
|
IsReachImage.SetActive(false);
|
IsDrawImage.SetActive(false);
|
IsMissImage.SetActive(false);
|
button.gameObject.SetActive(true);
|
button.interactable = false;
|
if (uieffect.IsPlaying)
|
{
|
uieffect.Stop();
|
}
|
button.GetComponent<ImageEx>().gray = true;
|
BtnText.color = UIHelper.GetUIColor(TextColType.White);
|
break;
|
case RewardRecordState.NoReceive:
|
IsReachImage.SetActive(false);
|
IsDrawImage.SetActive(false);
|
IsMissImage.SetActive(false);
|
button.gameObject.SetActive(true);
|
uieffect.Play();
|
BtnText.text = Language.Get("RealmPractice109");
|
button.interactable = true;
|
button.GetComponent<ImageEx>().gray = false;
|
BtnText.color = UIHelper.GetUIColor(TextColType.NavyBrown);
|
button.AddListener(() => { ClickReceiveBtn(config); });
|
break;
|
case RewardRecordState.HaveReceive:
|
if (uieffect.IsPlaying)
|
{
|
uieffect.Stop();
|
}
|
button.gameObject.SetActive(false);
|
IsDrawImage.SetActive(true);
|
IsMissImage.SetActive(false);
|
IsReachImage.SetActive(false);
|
break;
|
case RewardRecordState.Miss:
|
if (uieffect.IsPlaying)
|
{
|
uieffect.Stop();
|
}
|
button.gameObject.SetActive(false);
|
IsDrawImage.SetActive(false);
|
IsMissImage.SetActive(true);
|
IsReachImage.SetActive(false);
|
break;
|
case RewardRecordState.NoShow:
|
if (uieffect.IsPlaying)
|
{
|
uieffect.Stop();
|
}
|
button.gameObject.SetActive(true);
|
button.interactable = false;
|
BtnText.color = UIHelper.GetUIColor(TextColType.White);
|
button.GetComponent<ImageEx>().gray = true;
|
IsDrawImage.SetActive(false);
|
IsMissImage.SetActive(false);
|
IsReachImage.SetActive(false);
|
break;
|
}
|
|
}
|
|
private void ClickReceiveBtn(InvestConfig config)
|
{
|
investModel.SendGetInvestRewardQuest((int)InvestType.Vip, config.needDay);
|
}
|
|
private void ClickInvestBtn()
|
{
|
if (PlayerDatas.Instance.baseData.VIPLv < 4)
|
{
|
SysNotifyMgr.Instance.ShowTip("VipInvestmentLimit");
|
return;
|
}
|
|
|
ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("WhetherToInvest_Z"), (bool isOk) =>
|
{
|
if (isOk)
|
{
|
int getFairyJade = (int)UIHelper.GetMoneyCnt(1);
|
if (getFairyJade >= 300)
|
{
|
investModel.SendInvestQuest((int)InvestType.Vip, 0);
|
}
|
else
|
{
|
WindowCenter.Instance.Open<RechargeTipWin>();
|
}
|
|
}
|
});
|
|
}
|
|
|
private void CloseAllSelected()
|
{
|
for (int i = 0; i < m_ButtonGroup.childCount; i++)
|
{
|
var selected = m_ButtonGroup.GetChild(i).transform.Find("Selected").gameObject;
|
if (selected.activeSelf)
|
{
|
selected.SetActive(false);
|
}
|
}
|
}
|
|
private void OnclickButtonOne()
|
{
|
CloseAllSelected();
|
var selected = m_Button_one.transform.Find("Selected").gameObject;
|
if (!selected.activeSelf)
|
{
|
selected.SetActive(true);
|
}
|
cycle = 1;
|
configlist = investModel.GetInvestConfiglistByCycle(cycle);
|
CreateRewardCell();
|
}
|
|
private void OnClickButtonTwo()
|
{
|
CloseAllSelected();
|
var selected = m_Button_Two.transform.Find("Selected").gameObject;
|
if (!selected.activeSelf)
|
{
|
selected.SetActive(true);
|
}
|
cycle = 2;
|
configlist = investModel.GetInvestConfiglistByCycle(cycle);
|
CreateRewardCell();
|
}
|
private void OnClickButtonThree()
|
{
|
CloseAllSelected();
|
var selected = m_Button_Three.transform.Find("Selected").gameObject;
|
if (!selected.activeSelf)
|
{
|
selected.SetActive(true);
|
}
|
cycle = 3;
|
configlist = investModel.GetInvestConfiglistByCycle(cycle);
|
CreateRewardCell();
|
}
|
private void OnClickButtonFour()
|
{
|
CloseAllSelected();
|
var selected = m_Button_Four.transform.Find("Selected").gameObject;
|
if (!selected.activeSelf)
|
{
|
selected.SetActive(true);
|
}
|
cycle = 4;
|
configlist = investModel.GetInvestConfiglistByCycle(cycle);
|
CreateRewardCell();
|
}
|
private void OnClickVipBossWin()
|
{
|
WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.FindPreciousFrameFunc3);
|
}
|
|
private void SwithWeek(int cycle_int)
|
{
|
switch (cycle_int)
|
{
|
case 1:
|
OnclickButtonOne();
|
break;
|
case 2:
|
OnClickButtonTwo();
|
break;
|
case 3:
|
OnClickButtonThree();
|
break;
|
case 4:
|
OnClickButtonFour();
|
break;
|
default:
|
break;
|
}
|
|
}
|
}
|
}
|