miduo_client/Assets/ManagedResources/~Lua/Modules/Operating/GMSong10WanPanel.lua

241 lines
9.0 KiB
Lua

require("Base/BasePanel")
GMSong10WanPanel = Inherit(BasePanel)
local this = GMSong10WanPanel
local zhenchongConfig = ConfigManager.GetConfig(ConfigName.SuperZhenChong)
local sortingOrder = 0
local lineTime = 0
local activityData
local allValue = 0
local rewardTime = 0
local isCanGet = false
local deleteTime = 0
local currShowRed = nil
local rewardNum = 0
--初始化组件(用于子类重写)
function GMSong10WanPanel:InitComponent()
this.spLoader = SpriteLoader.New()
this.btn_close = Util.GetGameObject(self.gameObject, "bg/closeBtn")
this.btn_get = Util.GetGameObject(self.gameObject, "bg/btn_get")
this.getRed = Util.GetGameObject(self.gameObject, "bg/btn_get/red")
this.itemPre = Util.GetGameObject(self.gameObject, "itemPre")
this.scroll = Util.GetGameObject(self.gameObject, "bg/rect")
this.shopItemPre = Util.GetGameObject(self.gameObject, "rewardPre")
this.timeTxt = Util.GetGameObject(self.gameObject, "bg/timeText"):GetComponent("Text")
this.getTxt = Util.GetGameObject(self.gameObject, "bg/getTxt"):GetComponent("Text")
this.noGetTxt = Util.GetGameObject(self.gameObject, "bg/noGetTxt"):GetComponent("Text")
--设置滚动条
local rootHight = this.scroll.transform.rect.height
local width = this.scroll.transform.rect.width
this.scrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.scroll.transform,
this.shopItemPre, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0, 12), false)
this.scrollView.moveTween.MomentumAmount = 1
this.scrollView.moveTween.Strength = 2
this.itemList = {}
this.timer = nil
end
--绑定事件(用于子类重写)
function GMSong10WanPanel:BindEvent()
Util.AddOnceClick(this.btn_close, function()
self:ClosePanel()
end)
Util.AddOnceClick(this.btn_get, function()
if isCanGet then
NetManager.GetActivityRewardRequest(1, 11201, function(msg)
UIManager.OpenPanel(UIName.RewardItemPopup, msg, 1, function()
isCanGet = false
this.getRed:SetActive(false)
deleteTime = 0
self:OnShow()
end)
end)
end
end)
end
--添加事件监听(用于子类重写)
function GMSong10WanPanel:AddListener()
end
--移除事件监听(用于子类重写)
function GMSong10WanPanel:RemoveListener()
end
--界面打开时调用(用于子类重写)
function GMSong10WanPanel:OnOpen()
end
function GMSong10WanPanel:OnFocus()
end
function GMSong10WanPanel:OnSortingOrderChange()
end
-- 打开,重新打开时回调
function GMSong10WanPanel:OnShow()
activityData = ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.Song10Wan)
LogError("value==================" .. activityData.value)
this.getTxt.text = string.format(Language[11992], activityData.value)
local lastState = -1
local dayList = {}
if activityData then
local maxId = 0
for i = 1, #activityData.mission do
local id = activityData.mission[i].missionId
if zhenchongConfig[id] then
--LogError("id==="..id)
local aaa = zhenchongConfig[id]
allValue = allValue + aaa.RewardValue
if not dayList[aaa.day] then
local day = {}
day.reward = {}
table.insert(day.reward, aaa.Reward)
dayList[aaa.day] = day
else
table.insert(dayList[aaa.day].reward, aaa.Reward)
end
local state = activityData.mission[i].state
dayList[aaa.day].reward.state = state
local progress = activityData.mission[i].progress
if lastState ~= 0 and progress >= 0 then
maxId = id
lineTime = progress
if state == 0 and rewardTime == 0 then
rewardTime = aaa.Time
end
end
if state == 1 then
isCanGet = true
end
lastState = state
end
end
rewardNum = 0
this.timeTxt.text = ""
this.scrollView:SetData(dayList, function(index, rewardItem)
this:UpdateSingleInfo(rewardItem, dayList[index], index)
end, not false, not false)
this.scrollView:SetIndex(maxId / 4)
if deleteTime > 0 then
this.timer = Timer.New(function()
--LogError("needTime=="..needTime)
deleteTime = deleteTime - 1
if deleteTime <= 0 then
isCanGet = true
this.timeTxt.text = Language[11993]
this.getRed:SetActive(true)
currShowRed:SetActive(true)
this.timer:Stop()
this.timer = nil
else
this.timeTxt.text = string.format(Language[11994] .. "%s", TimeToFelaxible(deleteTime))
end
end, 1, -1, true)
this.timer:Start()
end
end
this.getRed:SetActive(isCanGet)
this.noGetTxt.text = string.format(Language[11995], allValue - activityData.value)
end
function this:UpdateSingleInfo(go, data, index)
local dayTxt = Util.GetGameObject(go, "GameObject/Text"):GetComponent("Text")
dayTxt.text = string.format(Language[10021], index)
local grid = Util.GetGameObject(go, "GameObject/content")
if not this.itemList[go] then
this.itemList[go] = {}
end
if this.timer then
this.timer:Stop()
this.timer = nil
end
for i = 1, #this.itemList[go] do
this.itemList[go][i].go.gameObject:SetActive(false)
end
for i = 1, #data.reward do
if not this.itemList[go][i] then
this.itemList[go][i] = {}
this.itemList[go][i].go = newObjToParent(this.itemPre, grid)
this.itemList[go][i].pos = Util.GetGameObject(this.itemList[go][i].go, "itemPos")
this.itemList[go][i].red = Util.GetGameObject(this.itemList[go][i].go, "redPoint")
this.itemList[go][i].get = Util.GetGameObject(this.itemList[go][i].go, "yilingqu")
this.itemList[go][i].out = Util.GetGameObject(this.itemList[go][i].go, "guoqi")
this.itemList[go][i].name = Util.GetGameObject(this.itemList[go][i].go, "name")
this.itemList[go][i].itemView = SubUIManager.Open(SubUIConfig.ItemView, this.itemList[go][i].pos.transform)
end
this.itemList[go][i].go.gameObject:SetActive(true)
this.itemList[go][i].red:SetActive(false)
this.itemList[go][i].get:SetActive(false)
this.itemList[go][i].out:SetActive(false)
this.itemList[go][i].itemView:OnOpen(false, data.reward[i], 0.75, false, false, false, self.sortingOrder)
local itemConfig = ConfigManager.GetConfigData(ConfigName.ItemConfig, data.reward[i][1])
this.itemList[go][i].name:GetComponent("Text").text = itemConfig.Name
local id = (index - 1) * 4 + i
local state = activityData.mission[id].state --data.reward[i].state
local progress = activityData.mission[id].progress
local config = ConfigManager.GetConfigData(ConfigName.SuperZhenChong, id)
--LogError("state====="..state)
if state == 0 then
if progress ~= -1 then
local cha = tonumber(GetTimeStamp() - ActivityGiftManager.loginTime)
local needTime = config.Time - (lineTime + cha)
this.getRed:SetActive(false)
if needTime > 0 and deleteTime == 0 then
this.timeTxt.gameObject:SetActive(true)
deleteTime = needTime
currShowRed = this.itemList[go][i].red
--this.timeTxt.gameObject:SetActive(false)
end
if needTime <= 0 then
if rewardTime ~= 0 then
isCanGet = true
this.itemList[go][i].red:SetActive(true)
end
end
end
elseif state == 1 then
this.itemList[go][i].red:SetActive(true)
elseif state == 2 then
this.itemList[go][i].get:SetActive(true)
rewardNum = rewardNum + 1
elseif state == 3 then
this.itemList[go][i].out:SetActive(true)
end
end
--LogError("deleteTime==="..deleteTime)
end
--界面关闭时调用(用于子类重写)
function GMSong10WanPanel:OnClose()
if this.timer then
this.timer:Stop()
this.timer = nil
end
allValue = 0
rewardTime = 0
deleteTime = 0
rewardNum = 0
this.getRed:SetActive(false)
if currShowRed then
currShowRed:SetActive(false)
currShowRed = nil
end
CheckRedPointStatus(RedPointType.song10Wan)
end
--界面销毁时调用(用于子类重写)
function GMSong10WanPanel:OnDestroy()
this.spLoader:Destroy()
if this.timer then
this.timer:Stop()
this.timer = nil
end
end
return GMSong10WanPanel