179 lines
7.8 KiB
Lua
179 lines
7.8 KiB
Lua
|
|
local MonthCardPage = {}
|
|
local cardData = {
|
|
[1] = { curState = 0 ,cardType = MONTH_CARD_TYPE.MONTHCARD},
|
|
[2] = { curState = 0 ,cardType = MONTH_CARD_TYPE.LUXURYMONTHCARD}
|
|
}
|
|
local sortingOrder = 0
|
|
local addTimeNum = 30 * 24 * 60 * 60
|
|
local monthCardConFig = ConfigManager.GetConfig(ConfigName.MonthcardConfig)
|
|
|
|
function MonthCardPage:New(gameObject)
|
|
local b = {}
|
|
b.gameObject = gameObject
|
|
b.transform = gameObject.transform
|
|
setmetatable(b, { __index = MonthCardPage })
|
|
return b
|
|
end
|
|
local offSetX = {
|
|
[0] = Vector3.New(71.1,-7.34,0),
|
|
[1] = Vector3.New(188,-56,0),
|
|
[2] = Vector3.New(188,-56,0),
|
|
}
|
|
--初始化组件(用于子类重写)
|
|
function MonthCardPage:InitComponent()
|
|
self.spLoader = SpriteLoader.New()
|
|
self.grid = Util.GetGameObject(self.gameObject, "grid")
|
|
self.cardPres = {}
|
|
self.timerList = {}
|
|
for i= 1 ,self.grid.transform.childCount do
|
|
self.cardPres[i] = {}
|
|
self.cardPres[i].go = self.grid.transform:GetChild(i - 1).gameObject
|
|
self.cardPres[i].month = Util.GetGameObject(self.cardPres[i].go, "small")
|
|
self.cardPres[i].btnText = Util.GetGameObject(self.cardPres[i].month, "Text"):GetComponent("Text")
|
|
self.cardPres[i].monthRedPot = Util.GetGameObject(self.cardPres[i].month, "redPoint")
|
|
self.cardPres[i].progress = Util.GetGameObject(self.cardPres[i].go, "day/progress")
|
|
self.cardPres[i].time = Util.GetGameObject(self.cardPres[i].go, "day/time")
|
|
self.cardPres[i].day1 = Util.GetGameObject(self.cardPres[i].go, "day/Text1"):GetComponent("Text")
|
|
self.cardPres[i].day2 = Util.GetGameObject(self.cardPres[i].go, "day/Text2"):GetComponent("Text")
|
|
self.cardPres[i].icon = Util.GetGameObject(self.cardPres[i].go, "day/icon"):GetComponent("Image")
|
|
self.cardPres[i].dayRightUpText = Util.GetGameObject(self.cardPres[i].go, "Image/Text"):GetComponent("Text")
|
|
self.cardPres[i].dayRightUpIcon = Util.GetGameObject(self.cardPres[i].go, "Image/icon"):GetComponent("Image")
|
|
Util.GetGameObject(self.cardPres[i].go, "day/icon"):GetComponent("RectTransform").anchoredPosition = offSetX[GetCurLanguage()]
|
|
end
|
|
end
|
|
|
|
--绑定事件(用于子类重写)
|
|
function MonthCardPage:BindEvent()
|
|
for i = 1, #self.cardPres do
|
|
Util.AddOnceClick(self.cardPres[i].month,function()
|
|
if not cardData[i].curState then
|
|
JumpManager.GoJump(27001)
|
|
else
|
|
if self.curAllMonthCardData[cardData[i].cardType].state == 0 then
|
|
NetManager.MonthCardTakeDailyRequest(cardData[i].cardType, function(drop)
|
|
OperatingManager.SetMonthCardGetStateData(cardData[i].cardType,1)
|
|
self.curAllMonthCardData = OperatingManager.GetMonthCardData()
|
|
UIManager.OpenPanel(UIName.RewardItemPopup,drop,1,function()
|
|
self:SetCardShow(i)
|
|
end)
|
|
end)
|
|
end
|
|
end
|
|
end)
|
|
end
|
|
end
|
|
|
|
--添加事件监听(用于子类重写)
|
|
function MonthCardPage:AddListener()
|
|
Game.GlobalEvent:AddEvent(GameEvent.MoneyPay.OnPayResultSuccess, self.BuySuccess)
|
|
end
|
|
|
|
--移除事件监听(用于子类重写)
|
|
function MonthCardPage:RemoveListener()
|
|
Game.GlobalEvent:RemoveEvent(GameEvent.MoneyPay.OnPayResultSuccess, self.BuySuccess)
|
|
end
|
|
|
|
--界面打开时调用(用于子类重写)
|
|
function MonthCardPage:OnOpen(_activityConfig,_index,parent)
|
|
self.actConfig = _activityConfig
|
|
self.pageIndex = _index
|
|
self.parent = parent
|
|
end
|
|
|
|
function MonthCardPage:OnSortingOrderChange()
|
|
end
|
|
|
|
-- 打开,重新打开时回调
|
|
function MonthCardPage:OnShow(_sortingOrder)
|
|
self.gameObject:SetActive(true)
|
|
sortingOrder = _sortingOrder
|
|
|
|
OperatingManager.RefreshMonthCardEnd()
|
|
self:RefreshStoneShow()
|
|
end
|
|
|
|
-- 妖晶数量显示
|
|
function MonthCardPage:RefreshStoneShow(index)
|
|
self.curAllMonthCardData = OperatingManager.GetMonthCardData()
|
|
--月卡
|
|
for i = 1, #self.cardPres do
|
|
self:SetCardShow(i)
|
|
end
|
|
end
|
|
|
|
function MonthCardPage:SetCardShow(i)
|
|
cardData[i].curState = self.curAllMonthCardData[cardData[i].cardType] and self.curAllMonthCardData[cardData[i].cardType].endingTime ~= 0
|
|
self.cardPres[i].day1.text = Language[11377].. string.format(MoneyUtil.GetMoneyUnitName(),monthCardConFig[cardData[i].cardType].Price) ..Language[11378]--Language[11379]
|
|
self.cardPres[i].day2.text = Language[11380]..monthCardConFig[cardData[i].cardType].BaseReward[1][2] .."</color>"
|
|
self.cardPres[i].icon.sprite = self.spLoader:LoadSprite(GetResourcePath(ConfigManager.GetConfigData(ConfigName.ItemConfig,monthCardConFig[cardData[i].cardType].BaseReward[1][1]).ResourceID))
|
|
self.cardPres[i].progress:SetActive(not cardData[i].curState)
|
|
self.cardPres[i].progress:GetComponent("Text").text = "("..OperatingManager.GetmonthSaveAmt(i).."/"..monthCardConFig[cardData[i].cardType].Price..")"
|
|
self.cardPres[i].dayRightUpText = monthCardConFig[cardData[i].cardType].ContiueDays * monthCardConFig[cardData[i].cardType].BaseReward[1][2]
|
|
self.cardPres[i].dayRightUpIcon = SetIcon(self.spLoader, monthCardConFig[cardData[i].cardType].BaseReward[1][1])
|
|
self.cardPres[i].monthRedPot:SetActive(OperatingManager.RefreshMonthCardRedPoint(cardData[i].cardType))
|
|
self.cardPres[i].btnText = Language[11381]
|
|
if not cardData[i].curState then
|
|
self.cardPres[i].time:SetActive(false)
|
|
Util.SetGray(self.cardPres[i].month,false)
|
|
self.cardPres[i].month:GetComponent("Button").enabled = true
|
|
else
|
|
self.cardPres[i].time:SetActive(true)
|
|
local residueTimeNum = self.curAllMonthCardData[cardData[i].cardType].endingTime + addTimeNum - GetTimeStamp()
|
|
local dayNum = math.floor(residueTimeNum / (24 * 3600))
|
|
if dayNum > 0 then
|
|
self.cardPres[i].time:GetComponent("Text").text = Language[10480] .. dayNum ..Language[10017]
|
|
else
|
|
self:SetMonthCardTimes(residueTimeNum,self.cardPres[i].time,i)
|
|
end
|
|
if self.curAllMonthCardData[cardData[i].cardType].state == 0 then
|
|
Util.SetGray(self.cardPres[i].month,false)
|
|
self.cardPres[i].month:GetComponent("Button").enabled = true
|
|
Util.GetGameObject(self.cardPres[i].month, "Text"):GetComponent("Text").text = Language[11382]
|
|
elseif self.curAllMonthCardData[cardData[i].cardType].state == 1 then
|
|
Util.SetGray(self.cardPres[i].month,true)
|
|
self.cardPres[i].month:GetComponent("Button").enabled = false
|
|
Util.GetGameObject(self.cardPres[i].month, "Text"):GetComponent("Text").text = Language[10101]
|
|
end
|
|
end
|
|
end
|
|
|
|
function MonthCardPage:SetMonthCardTimes(timeNums,timeCom,index)
|
|
if self.timerList[index] then
|
|
self.timerList[index]:Stop()
|
|
self.timerList[index] = nil
|
|
end
|
|
timeCom:GetComponent("Text").text = Language[10023]..TimeStampToDateStr3(timeNums)
|
|
self.timerList[index] = Timer.New(function()
|
|
timeCom:GetComponent("Text").text = Language[10023]..TimeStampToDateStr3(timeNums)
|
|
if timeNums < 0 then
|
|
OperatingManager.RefreshMonthCardEnd()
|
|
self.curAllMonthCardData = OperatingManager.GetMonthCardData()
|
|
self:SetCardShow(index)
|
|
self.timerList[index]:Stop()
|
|
self.timerList[index] = nil
|
|
end
|
|
timeNums = timeNums - 1
|
|
end, 1, -1, true)
|
|
self.timerList[index]:Start()
|
|
end
|
|
|
|
--界面关闭时调用(用于子类重写)
|
|
function MonthCardPage:OnClose()
|
|
self.gameObject:SetActive(false)
|
|
end
|
|
--界面销毁时调用(用于子类重写)
|
|
function MonthCardPage:OnDestroy()
|
|
self.spLoader:Destroy()
|
|
self.cardPres = {}
|
|
for index = 1, #self.timerList do
|
|
if self.timerList[index] then
|
|
self.timerList[index]:Stop()
|
|
self.timerList[index] = nil
|
|
end
|
|
end
|
|
self.timerList = {}
|
|
end
|
|
return MonthCardPage
|
|
|