404 lines
14 KiB
Lua
404 lines
14 KiB
Lua
local UpStarGift = {}
|
|
local rechargeNum = 0
|
|
local GlobalActConfig = ConfigManager.GetConfig(ConfigName.GlobalActivity)
|
|
local heroConfig = ConfigManager.GetConfig(ConfigName.HeroConfig)
|
|
function UpStarGift:New(gameObject)
|
|
local b = {}
|
|
b.gameObject = gameObject
|
|
b.transform = gameObject.transform
|
|
setmetatable(b, { __index = UpStarGift })
|
|
return b
|
|
end
|
|
|
|
|
|
--添加事件监听(用于子类重写)
|
|
function UpStarGift:AddListener()
|
|
Game.GlobalEvent:AddEvent(GameEvent.Bag.BagGold, self.EventRefreshData, self)
|
|
Game.GlobalEvent:AddEvent(GameEvent.DynamicTask.OnMissionChange, self.EventRefreshData, self)
|
|
Game.GlobalEvent:AddEvent(GameEvent.Activity.OnActivityProgressStateChange, self.EventRefreshData, self)
|
|
end
|
|
|
|
--移除事件监听(用于子类重写)
|
|
function UpStarGift:RemoveListener()
|
|
Game.GlobalEvent:RemoveEvent(GameEvent.Bag.BagGold, self.EventRefreshData, self)
|
|
Game.GlobalEvent:RemoveEvent(GameEvent.DynamicTask.OnMissionChange, self.EventRefreshData,self)
|
|
Game.GlobalEvent:RemoveEvent(GameEvent.Activity.OnActivityProgressStateChange, self.EventRefreshData,self)
|
|
end
|
|
|
|
function UpStarGift:EventRefreshData()
|
|
self:RefreshData(true,false,false)
|
|
end
|
|
|
|
function UpStarGift:InitComponent()
|
|
self.spLoader = SpriteLoader.New()
|
|
self.bg = Util.GetGameObject(self.gameObject, "Bg/banner")
|
|
self.titleBgIma = self.bg:GetComponent("Image")
|
|
self.titleIma = Util.GetGameObject(self.bg,"titleIma"):GetComponent("Image")
|
|
self.titleTipBg = Util.GetGameObject(self.bg,"titleTipBg"):GetComponent("Image")
|
|
self.titleTip = Util.GetGameObject(self.bg,"titleTip"):GetComponent("Text")
|
|
|
|
self.scrollItem = Util.GetGameObject(self.gameObject, "scrollItem")
|
|
self.scrollItemPos = self.scrollItem.transform.localPosition
|
|
self.scrollItemRect = self.scrollItem.transform.rect
|
|
self.btnHelp = Util.GetGameObject(self.gameObject, "btnHelp")
|
|
self.helpPosition = self.btnHelp:GetComponent("RectTransform").localPosition
|
|
self.itemPre = Util.GetGameObject(self.gameObject, "ItemPre")
|
|
self.sortingOrder = 0
|
|
|
|
self.time = Util.GetGameObject(self.gameObject, "Bg/banner/time")
|
|
self.timeText = Util.GetGameObject(self.time, "timeText"):GetComponent("Text")
|
|
self.ItemList = {}
|
|
|
|
|
|
self.btnAdd = Util.GetGameObject(self.gameObject, "Bg/banner/btnAdd")
|
|
self.btnChoose = Util.GetGameObject(self.gameObject, "Bg/banner/btnChoose")
|
|
self.btnLock = Util.GetGameObject(self.gameObject, "Bg/banner/btnLock")
|
|
self.liveRoot = Util.GetGameObject(self.gameObject, "Bg/banner/live/liveRoot")
|
|
|
|
end
|
|
|
|
function UpStarGift:BindEvent()
|
|
Util.AddClick(self.btnHelp,function()
|
|
UIManager.OpenPanel(UIName.HelpPopup,self.actConfig.HelpId,self.helpPosition.x,self.helpPosition.y)
|
|
end)
|
|
Util.AddClick(self.btnAdd,function()
|
|
local choose, isTemp = self:GetCurChooseHero()
|
|
if not isTemp then
|
|
PopupTipPanel.ShowTip("当前已处于锁定状态")
|
|
return
|
|
end
|
|
local heroList = self:GetHeroList()
|
|
if not heroList or #heroList <= 0 then
|
|
PopupTipPanel.ShowTip("未找到本期活动的英雄信息")
|
|
return
|
|
end
|
|
-- 打开选择界面
|
|
UIManager.OpenPanel(UIName.GeneralBigPopup,GENERAL_POPUP_TYPE.ChooseUpHero, heroList, choose, function(chooseId)
|
|
self.tempChoose = chooseId
|
|
PlayerPrefs.SetInt(PlayerManager.uid.."_UpStarGift_TempChoose", chooseId)
|
|
-- 刷新界面限显示
|
|
self:RefreshData(true,true,true)
|
|
end, "选择英雄")
|
|
|
|
|
|
end)
|
|
Util.AddClick(self.btnChoose,function()
|
|
local choose, isTemp = self:GetCurChooseHero()
|
|
if not isTemp then
|
|
PopupTipPanel.ShowTip("当前已处于锁定状态")
|
|
return
|
|
end
|
|
local heroList = self:GetHeroList()
|
|
if not heroList or #heroList <= 0 then
|
|
PopupTipPanel.ShowTip("未找到本期活动的英雄信息")
|
|
return
|
|
end
|
|
|
|
-- 打开选择界面
|
|
UIManager.OpenPanel(UIName.GeneralBigPopup,GENERAL_POPUP_TYPE.ChooseUpHero, heroList, choose, function(chooseId)
|
|
self.tempChoose = chooseId
|
|
PlayerPrefs.SetInt(PlayerManager.uid.."_UpStarGift_TempChoose", chooseId)
|
|
-- 刷新界面限显示
|
|
self:RefreshData(true,true,true)
|
|
end, "选择英雄")
|
|
|
|
end)
|
|
Util.AddClick(self.btnLock,function()
|
|
local choose, isTemp = self:GetCurChooseHero()
|
|
if not choose or choose == 0 then
|
|
PopupTipPanel.ShowTip("请先选择一个英雄")
|
|
return
|
|
end
|
|
if not isTemp then
|
|
PopupTipPanel.ShowTip("当前已处于锁定状态")
|
|
return
|
|
end
|
|
|
|
local con = ConfigManager.TryGetConfigData(ConfigName.HeroConfig, choose)
|
|
if not con then
|
|
LogError("未找到英雄:"..tostring(choose))
|
|
return
|
|
end
|
|
local msg = string.format("<color=#da9648>%s</color>将锁定为本次活动的指定英雄,锁定后无法修改。", con.ReadingName)
|
|
MsgPanel.ShowTwo(msg, nil, function()
|
|
NetManager.UpStarActivitySelectRequest(self.actId, choose, function()
|
|
PopupTipPanel.ShowTip("锁定成功")
|
|
end)
|
|
end, nil, "锁 定")
|
|
end)
|
|
end
|
|
|
|
--界面打开时调用(用于子类重写)
|
|
function UpStarGift:OnOpen(_activityConfig,_index,parent)
|
|
self.actConfig = _activityConfig
|
|
self.pageIndex = _index
|
|
self.parent = parent
|
|
self.gameObject.name = "CommonActPage"..self.actConfig.Id
|
|
|
|
self.tempChoose = PlayerPrefs.GetInt(PlayerManager.uid.."_UpStarGift_TempChoose", 0)
|
|
end
|
|
|
|
function UpStarGift:OnSortingOrderChange()
|
|
end
|
|
|
|
-- 打开,重新打开时回调
|
|
function UpStarGift:OnShow(_sortingOrder)
|
|
self.gameObject:SetActive(true)
|
|
self.sortingOrder = _sortingOrder or self.sortingOrder
|
|
self.actId = self.actConfig.ActId
|
|
self.actType = self.actConfig.ActiveType
|
|
|
|
|
|
if self.actConfig.IfBack == 1 then
|
|
if self.actType > 0 then
|
|
local id = ActivityGiftManager.IsActivityTypeOpen(self.actType)
|
|
if id and id > 0 then
|
|
self.actId = id
|
|
local actConfig
|
|
local actConfig = ConfigManager.TryGetConfigDataByThreeKey(ConfigName.ActivityGroups,"ActId",GlobalActConfig[id].ShowArt,"PageType",self.actConfig.PageType,"ActiveType",self.actConfig.ActiveType)
|
|
if not actConfig then
|
|
actConfig = ConfigManager.TryGetConfigDataByThreeKey(ConfigName.ActivityGroups,"ActId",id,"PageType",self.actConfig.PageType,"ActiveType",self.actConfig.ActiveType)
|
|
end
|
|
if actConfig then
|
|
self.actConfig = actConfig
|
|
end
|
|
else
|
|
LogRed("活动类型:"..tostring(self.actType).."的活动未开启")
|
|
end
|
|
end
|
|
end
|
|
if self.actConfig.Icon[3] and self.actConfig.Icon[3] ~= "" then
|
|
self.titleBgIma.sprite = self.spLoader:LoadSprite(self.actConfig.Icon[3])
|
|
self.titleBgIma:SetNativeSize()
|
|
end
|
|
if self.actConfig.Icon[4] and self.actConfig.Icon[4] ~= "" then
|
|
self.titleIma.gameObject:SetActive(true)
|
|
self.titleIma.sprite = self.spLoader:LoadSprite(self.actConfig.Icon[4])
|
|
self.titleIma:SetNativeSize()
|
|
self.titleIma.transform.localPosition = Vector3.New(self.actConfig.TitleImapos[1],self.actConfig.TitleImapos[2],self.actConfig.TitleImapos[3])
|
|
else
|
|
self.titleIma.gameObject:SetActive(false)
|
|
end
|
|
|
|
if self.actConfig.Icon[5] and self.actConfig.Icon[5] ~= "" then
|
|
self.titleTipBg.gameObject:SetActive(true)
|
|
else
|
|
self.titleTipBg.gameObject:SetActive(false)
|
|
end
|
|
|
|
if self.actConfig.TitleText and self.actConfig.TitleText ~= "" then
|
|
local str = string.split(GetLanguageStrById(self.actConfig.TitleText),"|")
|
|
self.titleTip.text = str[1]
|
|
self.titleTip.transform.localPosition = Vector3.New((str[2] or 0),(str[3] or 0),(str[4] or 0))
|
|
self.titleTip.gameObject:SetActive(true)
|
|
else
|
|
self.titleTip.gameObject:SetActive(false)
|
|
end
|
|
|
|
self.parent.tabbox.gameObject:SetActive(false)
|
|
|
|
if not self.scrollView then
|
|
local rootHight = self.scrollItemRect.height
|
|
local width = self.scrollItemRect.width
|
|
self.itemPre:GetComponent("RectTransform").sizeDelta = Vector2.New(1080,162)
|
|
local vec = self.scrollItem.transform.localPosition
|
|
vec.y = self.scrollItemPos.y - 100
|
|
self.scrollItem.transform.localPosition = vec
|
|
|
|
self.scrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, self.scrollItem.transform,
|
|
self.itemPre, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0, 10))
|
|
self.scrollView.moveTween.MomentumAmount = 1
|
|
self.scrollView.moveTween.Strength = 2
|
|
end
|
|
|
|
if self.actConfig.HelpId and self.actConfig.HelpId > 0 then
|
|
self.btnHelp.gameObject:SetActive(true)
|
|
else
|
|
self.btnHelp.gameObject:SetActive(false)
|
|
end
|
|
--拿取数据
|
|
self:RefreshData(true,true,true)
|
|
end
|
|
--刷新数据
|
|
function UpStarGift:RefreshData(isUpdata,isTop,isAni)
|
|
self.ActData = CommonActPageManager.GetData(self.actType)
|
|
if self.actConfig.RpType > 0 then
|
|
CheckRedPointStatus(self.actConfig.RpType)
|
|
end
|
|
|
|
-- 按钮显示
|
|
local choose, isTemp = self:GetCurChooseHero()
|
|
self.btnAdd:SetActive(choose == 0 and isTemp)
|
|
self.btnChoose:SetActive(isTemp)
|
|
self.btnLock:SetActive(isTemp)
|
|
|
|
self:RefreshActData(isTop,isAni)
|
|
self:RefreshTime()
|
|
self:RefreshLive()
|
|
end
|
|
|
|
-- 获取本期活动的神将列表
|
|
function UpStarGift:GetHeroList()
|
|
local heroList = {}
|
|
-- 显示列表
|
|
for k, v in ipairs(self.ActData.rewards) do
|
|
if v.targetId then
|
|
heroList[v.targetId] = 1
|
|
end
|
|
end
|
|
local heros = {}
|
|
for heroId, _ in pairs(heroList) do
|
|
table.insert(heros, {heroId, heroConfig[heroId].PropertyName})
|
|
end
|
|
return heros
|
|
end
|
|
|
|
-- 获取当前选择的人(临时/锁定)
|
|
function UpStarGift:GetCurChooseHero()
|
|
local choose = 0
|
|
local isTemp = true
|
|
if self.ActData.value and self.ActData.value ~= 0 then
|
|
choose = self.ActData.value
|
|
isTemp = false
|
|
end
|
|
if choose == 0 and self.tempChoose and self.tempChoose ~= 0 then
|
|
-- 检测一遍临时选择的正确性,选择的人物保存到本地,这里是为了防止两期活动数据冲突
|
|
local heroList = self:GetHeroList()
|
|
local isHave = false
|
|
for _, h in ipairs(heroList) do
|
|
if h[1] == self.tempChoose then
|
|
isHave = true
|
|
end
|
|
end
|
|
if not isHave then
|
|
self.tempChoose = 0
|
|
end
|
|
--
|
|
choose = self.tempChoose
|
|
isTemp = true
|
|
end
|
|
return choose, isTemp
|
|
end
|
|
|
|
-- 获取奖励列表
|
|
function UpStarGift:GetRewardDataList()
|
|
local choose = self:GetCurChooseHero()
|
|
-- 没有的话就选第一个人作为默认显示的奖励
|
|
if choose == 0 then
|
|
choose = self.ActData.rewards[7].targetId
|
|
end
|
|
-- 显示列表
|
|
local dataList = {}
|
|
for k, v in ipairs(self.ActData.rewards) do
|
|
if v.targetId == choose then
|
|
table.insert(dataList, v)
|
|
end
|
|
end
|
|
table.sort(dataList, function(a, b)
|
|
return a.missionId < b.missionId
|
|
end)
|
|
return dataList
|
|
end
|
|
|
|
--刷新活动数据
|
|
function UpStarGift:RefreshActData(isTop,isAni)
|
|
self.scrollView:ForeachItemGO(function(index, go)
|
|
go.gameObject:SetActive(false)
|
|
end)
|
|
local dataList = self:GetRewardDataList()
|
|
self.scrollView:SetData(dataList, function (index, item)
|
|
self:ShowSingleData(item, dataList[index],index)
|
|
end,not isTop,not isAni)
|
|
end
|
|
|
|
function UpStarGift:ShowSingleData(item,sdata,index)
|
|
if not self.ItemList then
|
|
self.ItemList = {}
|
|
end
|
|
if not self.ItemList[item] then
|
|
local subConfig = SubUIConfig[self.actConfig.UIName[2]]
|
|
self.ItemList[item] = SubUIManager.Open(subConfig,item.transform)
|
|
end
|
|
if not sdata then
|
|
item.gameObject:SetActive(false)
|
|
return
|
|
end
|
|
item.gameObject:SetActive(true)
|
|
self.ItemList[item]:SetData(sdata,self,self.sortingOrder,self.ActData,self.actConfig)
|
|
end
|
|
|
|
function UpStarGift:RefreshTime()
|
|
if self.actConfig.ShowTime == 0 then
|
|
self.time:SetActive(false)
|
|
return
|
|
end
|
|
|
|
if self.localTimer then
|
|
self.localTimer:Stop()
|
|
self.localTimer = nil
|
|
end
|
|
local freshTime = self.ActData.endTime - GetTimeStamp()
|
|
|
|
local update = function()
|
|
if self.actConfig.ShowTime == 1 then
|
|
self.timeText.text = Language[10023]..TimeToFelaxible(freshTime)
|
|
elseif self.actConfig.ShowTime == 2 then
|
|
self.timeText.text = Language[10023]..TimeToDHMS(freshTime)
|
|
elseif self.actConfig.ShowTime == 3 then
|
|
self.timeText.text = Language[10023]..TimeToHMS(freshTime)
|
|
end
|
|
end
|
|
update()
|
|
self.localTimer = Timer.New(function ()
|
|
freshTime = freshTime - 1
|
|
update()
|
|
if freshTime <= 0 then
|
|
self.parent:ClosePanel()
|
|
end
|
|
end, 1, -1, true)
|
|
self.localTimer:Start()
|
|
end
|
|
|
|
|
|
function UpStarGift:RefreshLive()
|
|
ClearChild(self.liveRoot)
|
|
local choose = self:GetCurChooseHero()
|
|
if choose and choose ~= 0 then
|
|
local data= ConfigManager.GetConfigData(ConfigName.HeroConfig, choose)
|
|
if not data then
|
|
return
|
|
end
|
|
local live = poolManager:LoadLive(GetResourcePath(data.Live), self.liveRoot.transform,
|
|
Vector3.one * data.Scale, Vector3.New(data.Position[1], data.Position[2], 0))
|
|
live:GetComponent("SkeletonGraphic").AnimationState:SetAnimation(0, "idle", true)
|
|
live.transform.sizeDelta = Vector2.New(10000, 10000)
|
|
end
|
|
end
|
|
|
|
function UpStarGift:OnClose()
|
|
self.parent.tabbox.gameObject:SetActive(true)
|
|
self.gameObject:SetActive(false)
|
|
if self.localTimer then
|
|
self.localTimer:Stop()
|
|
self.localTimer = nil
|
|
end
|
|
end
|
|
|
|
function UpStarGift:OnDestroy()
|
|
self.spLoader:Destroy()
|
|
if self.localTimer then
|
|
self.localTimer:Stop()
|
|
self.localTimer = nil
|
|
end
|
|
for k,v in pairs(self.ItemList) do
|
|
SubUIManager.Close(v)
|
|
end
|
|
self.ItemList = {}
|
|
if self.scrollView then
|
|
SubUIManager.Close(self.scrollView)
|
|
end
|
|
self.scrollView=nil
|
|
self.scrollItem.transform.localPosition = self.scrollItemPos
|
|
end
|
|
|
|
return UpStarGift |