using System.Linq;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
|
/// <summary>
|
/// 淘金自动
|
/// </summary>
|
public class GoldRushAutoWin : UIBase
|
{
|
[SerializeField] ScrollerController autoScroller;
|
[SerializeField] Toggle autoRefreshToggle;
|
|
[SerializeField] Button freeBtn;
|
[SerializeField] Transform notFreeGo;
|
|
[SerializeField] Button buyBtn;
|
[SerializeField] Text buyText;
|
[SerializeField] Text buyTipsText;
|
[SerializeField] Button autoBtn;
|
[SerializeField] Text autoText;
|
[SerializeField] Text timeText;
|
|
|
|
protected override void InitComponent()
|
{
|
freeBtn.AddListener(UseFree);
|
buyBtn.AddListener(Buy);
|
autoBtn.AddListener(Auto);
|
autoRefreshToggle.onValueChanged.AddListener((value)=>
|
{
|
autoRefreshToggle.isOn = value;
|
GoldRushManager.Instance.isAutoRefreshItem = autoRefreshToggle.isOn;
|
});
|
}
|
|
|
|
protected override void OnPreOpen()
|
{
|
GlobalTimeEvent.Instance.secondEvent += OnSecondEvent;
|
GoldRushManager.Instance.OnGoldRushInfoEvent += OnGoldRushInfoEvent;
|
autoScroller.OnRefreshCell += OnRefreshCell;
|
Display();
|
}
|
|
protected override void OnPreClose()
|
{
|
GlobalTimeEvent.Instance.secondEvent -= OnSecondEvent;
|
GoldRushManager.Instance.OnGoldRushInfoEvent -= OnGoldRushInfoEvent;
|
autoScroller.OnRefreshCell -= OnRefreshCell;
|
}
|
|
void Display()
|
{
|
CreateScroller();
|
autoRefreshToggle.isOn = GoldRushManager.Instance.isAutoRefreshItem;
|
DisplayBtns();
|
}
|
|
void CreateScroller()
|
{
|
autoScroller.Refresh();
|
for (int i = 0; i < GoldRushManager.Instance.autoRefreshItemIDs.Length; i++)
|
{
|
autoScroller.AddCell(ScrollerDataType.Header, i);
|
|
}
|
autoScroller.Restart();
|
}
|
|
|
void OnRefreshCell(ScrollerDataType type, CellView cell)
|
{
|
var _cell = cell as GoldRushAutoCell;
|
_cell.Display(cell.index);
|
}
|
|
void DisplayBtns()
|
{
|
var endTime = GoldRushManager.Instance.housekeeperEndTime;
|
if (endTime == 0)
|
{
|
freeBtn.SetActive(true);
|
notFreeGo.SetActive(false);
|
}
|
else if (TimeUtility.AllSeconds >= endTime)
|
{
|
//已过期
|
freeBtn.SetActive(false);
|
notFreeGo.SetActive(true);
|
//购买
|
buyBtn.SetActive(true);
|
buyTipsText.text = Language.Get("GoldRush45", GoldRushManager.Instance.buyAutoDaysList[0]);
|
RechargeManager.Instance.TryGetOrderInfo(GoldRushManager.Instance.buyAutoCTGIDList[0], out var orderInfo);
|
buyText.text = Language.Get("PayMoneyNum", orderInfo.PayRMBNumOnSale);
|
autoBtn.SetActive(false);
|
}
|
else
|
{
|
freeBtn.SetActive(false);
|
notFreeGo.SetActive(true);
|
//续费
|
buyBtn.SetActive(true);
|
buyTipsText.text = "";
|
buyText.text = Language.Get("GoldRush27");
|
autoBtn.SetActive(true);
|
autoText.text = Language.Get(GoldRushManager.Instance.isOpenAuto ? "GoldRush46" : "GoldRush28");
|
timeText.text = Language.Get("GoldRush29") + TimeUtility.SecondsToShortDHMS(endTime - TimeUtility.AllSeconds);
|
}
|
}
|
|
void OnSecondEvent()
|
{
|
var endTime = GoldRushManager.Instance.housekeeperEndTime;
|
if (endTime > 0 && TimeUtility.AllSeconds < endTime)
|
{
|
timeText.text = Language.Get("GoldRush29") + TimeUtility.SecondsToShortDHMS(endTime - TimeUtility.AllSeconds);
|
}
|
}
|
|
void UseFree()
|
{
|
if (GoldRushManager.Instance.housekeeperEndTime != 0)
|
return;
|
|
ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
|
Language.Get("GoldRush47"), (bool isOK) =>
|
{
|
if (isOK)
|
{
|
var pack = new CB039_tagCSGoldRushAutoFreeUse();
|
GameNetSystem.Instance.SendInfo(pack);
|
}
|
});
|
}
|
|
void Buy()
|
{
|
var endTime = GoldRushManager.Instance.housekeeperEndTime;
|
if (endTime > 0 && TimeUtility.AllSeconds < endTime)
|
{
|
//续费
|
UIManager.Instance.OpenWindow<GoldRushAutoBuyWin>();
|
}
|
else
|
{
|
//购买
|
RechargeManager.Instance.CTG(GoldRushManager.Instance.buyAutoCTGIDList[0]);
|
}
|
}
|
|
void Auto()
|
{
|
GoldRushManager.Instance.isOpenAuto = !GoldRushManager.Instance.isOpenAuto;
|
autoText.text = Language.Get(GoldRushManager.Instance.isOpenAuto ? "GoldRush46" : "GoldRush28");
|
SysNotifyMgr.Instance.ShowTip(GoldRushManager.Instance.isOpenAuto ? "GoldRush11" : "GoldRush12");
|
CloseWindow();
|
}
|
|
void OnGoldRushInfoEvent()
|
{
|
DisplayBtns();
|
}
|
}
|