miduo_client/Assets/ManagedResources/~Lua/Modules/TreasureOfHeaven/RecruitTreasurePanel.lua

350 lines
14 KiB
Lua

local RecruitTreasurePanel = {}
local this = RecruitTreasurePanel
local sortingOrder = 0
local redPointTypeList = {}
local curPage = 0
local curId=0
-- Tab管理器
local TabBox = require("Modules/Common/TabBox")
local configs = ConfigManager.GetAllConfigsDataByKey(ConfigName.ActivityGroups,"PageType",ActivityTypeDef.RecruitTreasure)
function RecruitTreasurePanel:New(gameObject)
local b = {}
b.gameObject = gameObject
b.transform = gameObject.transform
setmetatable(b, { __index = RecruitTreasurePanel })
return b
end
local itemnum = 0
--初始化组件(用于子类重写)
function RecruitTreasurePanel:InitComponent()
this.spLoader = SpriteLoader.New()
this.quesBtn = Util.GetGameObject(self.transform, "bg/quesBtn")
this.helpPosition=this.quesBtn:GetComponent("RectTransform").localPosition
this.titleImage = Util.GetGameObject(self.transform, "bg/titleName"):GetComponent("Image")
this.buyBtn = Util.GetGameObject(self.transform, "bg/topBar/buyBtn")
this.Text1 = Util.GetGameObject(this.buyBtn, "buy"):GetComponent("Text")
this.tips = Util.GetGameObject(self.transform, "bg/topBar/tips"):GetComponent("Text")
this.topBarImage = Util.GetGameObject(self.transform, "bg/topBar"):GetComponent("Image")
--Content
this.scoreText = Util.GetGameObject(self.transform, "bg/pageContent/bg/score/number"):GetComponent("Text")
this.treasureList = Util.GetGameObject(self.transform, "bg/pageContent/treasureList")
this.itemPre = Util.GetGameObject(self.transform, "bg/pageContent/itemPro")
local v = this.treasureList:GetComponent("RectTransform").rect
--设置滚动条
this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView,this.treasureList.transform,this.itemPre,nil,Vector2.New(v.width, v.height),1,1,Vector2.New(100, 25))
this.ScrollView.gameObject:GetComponent("RectTransform").anchoredPosition = Vector2.New(0, 0)
this.ScrollView.gameObject:GetComponent("RectTransform").anchorMin = Vector2.New(0.5, 0.5)
this.ScrollView.gameObject:GetComponent("RectTransform").anchorMax = Vector2.New(0.5, 0.5)
this.ScrollView.gameObject:GetComponent("RectTransform").pivot = Vector2.New(0.5, 0.5)
this.ScrollView.moveTween.MomentumAmount = 1
this.ScrollView.moveTween.Strength = 2
this.btn_qmfl=Util.GetGameObject(self.transform, "bg/topBar/btn_qmfl")
this.btn_qmfl_red=Util.GetGameObject(self.transform, "bg/topBar/btn_qmfl/red")
this.btn_qmfl_red:SetActive(false)
this.btn_qmfl:GetComponent("Image").sprite =this.spLoader:LoadSprite("GM_qmfl_botton_zh")
this.tabbox = Util.GetGameObject(self.gameObject, "bg/pageContent/tabbox")
end
--绑定事件(用于子类重写)
function RecruitTreasurePanel:BindEvent()
Util.AddClick(this.quesBtn,function()
UIManager.OpenPanel(UIName.HelpPopup,this.actConfig.HelpId,this.helpPosition.x,this.helpPosition.y)
end)
Util.AddClick(this.btn_qmfl,function()
--LogGreen(this.helpPosition.x.."+"..this.helpPosition.
UIManager.OpenPanel(UIName.QuanMinFLPanel,curId)
end)
-- 初始化Tab管理器
this.PageTabCtrl = TabBox.New()
this.PageTabCtrl:SetTabAdapter(this.PageTabAdapter)
this.PageTabCtrl:SetTabIsLockCheck(this.PageTabIsLockCheck)
this.PageTabCtrl:SetChangeTabCallBack(this.OnPageTabChange)
end
function this.PageTabAdapter(tab, index, status)
local img = Util.GetGameObject(tab, "img"):GetComponent("Image")
local select = Util.GetGameObject(tab, "select"):GetComponent("Image")
local tip = Util.GetGameObject(tab, "tip"):GetComponent("Text")
local redpot = Util.GetGameObject(tab, "redpot")
if status == "select" then
select.gameObject:SetActive(true)
tip.text = string.format("<color=#%s>%s</color>","FDF4D6",configs[index].Icon[1])
else
select.gameObject:SetActive(false)
tip.text = string.format("<color=#%s>%s</color>","B5A481",configs[index].Icon[1])
end
if redPointTypeList[configs[index].RpType] then
ClearRedPointObject(configs[index].RpType,redPointTypeList[configs[index].RpType])
redPointTypeList[configs[index].RpType] = nil
end
if not configs[index].RpType or configs[index].RpType < 1 then
redpot.gameObject:SetActive(false)
else
BindRedPointObject(configs[index].RpType,redpot)
redPointTypeList[configs[index].RpType] = redpot
end
local data = ActivityGiftManager.GetActivityInfoByType(configs[index].ActId)
if data then
tab.gameObject:SetActive(true)
else
tab.gameObject:SetActive(false)
end
end
function this.PageTabIsLockCheck()
return false
end
function this.OnPageTabChange(index)
curPage = index
this.actId = configs[curPage].ActId
this.tips.text = configs[curPage].TitleText
this.topBarImage.sprite = this.spLoader:LoadSprite(configs[curPage].Icon[2])
this:refresh()
end
function RecruitTreasurePanel:OnSortingOrderChange()
end
--添加事件监听(用于子类重写)
function RecruitTreasurePanel:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.TreasureOfHeaven.RechargeSuccess,this.refresh,self)
end
--移除事件监听(用于子类重写)
function RecruitTreasurePanel:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.TreasureOfHeaven.RechargeSuccess,this.refresh,self)
end
--界面打开时调用(用于子类重写)
function RecruitTreasurePanel:OnOpen(_activityConfig,_index,parent)
this.actConfig = _activityConfig
this.pageIndex = _index
this.parent = parent
end
function RecruitTreasurePanel:OnFocus()
this.btn_qmfl_red:SetActive(RecruitTreasureManager.GetQuanMinRed(curId))
end
-- 打开,重新打开时回调
function RecruitTreasurePanel:OnShow(_sortingOrder)
self.gameObject:SetActive(true)
sortingOrder = _sortingOrder
this.actType = this.actConfig.ActiveType > 0 and this.actConfig.ActiveType or this.actConfig.FunType
curId=ActivityGiftManager.GetActivityIdByType(this.actType)
LogError("this.acttype===="..this.actType.." curid=="..curId)
this.btn_qmfl_red:SetActive(RecruitTreasureManager.GetQuanMinRed(curId))
this.btn_qmfl:SetActive(ActivityGiftManager.GetActivityInfoByType(10502)~=nil and this.actType==7 and ActivityGiftManager.CheckIsHaveHaveQMFL(this.actType,curId) )
this.titleImage.sprite = this.spLoader:LoadSprite(this.actConfig.Icon[3])
local activeNum = 0
curPage = 0
for i = 1,#configs do
this.actData = ActivityGiftManager.GetActivityInfoByType(configs[i].ActId)
if this.actData then
activeNum = activeNum + 1
if curPage < 1 then
this.treasureData = RecruitTreasureManager.GetRecruitTreasureData(configs[i].ActId,configs[i].ShopData[1][1])
for j = 1,#this.treasureData do
if this.treasureData[j].state == 2 or this.treasureData[j].state == 3 then
curPage = i
end
end
end
end
end
if activeNum == 1 then
this.tabbox.gameObject:SetActive(false)
else
this.tabbox.gameObject:SetActive(true)
end
if curPage < 1 then
curPage = activeNum
end
this.PageTabCtrl:Init(this.tabbox.gameObject, configs,curPage)
end
function RecruitTreasurePanel:refresh()
this.treasureData = RecruitTreasureManager.GetRecruitTreasureData(configs[curPage].ActId,configs[curPage].ShopData[1][1])
this.actData = ActivityGiftManager.GetActivityInfoByType(configs[curPage].ActId)
this.isBuy = RecruitTreasureManager.CheckIsBuyTreasureByGoodsId(configs[curPage].ShopData[1][1])
self:topBar()
self:showTaskList()
end
--topBar按钮状态
function RecruitTreasurePanel:topBar()
--设置礼包购买按钮状态
this.buyBtn:GetComponent("Button").interactable = not this.isBuy
this.Text1.text = not this.isBuy and "激活基金" or "已激活"
Util.AddOnceClick(this.buyBtn,function()
UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.HeavenUnlockExtraRewardPanel,configs[curPage].ShopData[1][2],configs[curPage].ActId)
end)
end
--任务列表
function RecruitTreasurePanel:showTaskList(isTop,isAni)
this.scoreText.text = this.actData.value
if not this.itemsList then
this.itemsList = {}
end
this.ScrollView:SetData(this.treasureData,function(index, rewardItem)
self:SingleTask(rewardItem, this.treasureData[index])
end,not isTop,not isAni)
-- -1 完美领取 1 已领取 2 未领取过可领取 3 领取过可完美领取 0 未达成
--定位打开界面时位置
local t = 0
for i = 1, #this.treasureData do
if this.treasureData[i].state == 2 or this.treasureData[i].state == 3 then
t = i
break
end
end
if t == 0 then
for i = 1, #this.treasureData do
if this.treasureData[i].state == 0 then
t = i
break
end
end
end
this.ScrollView:SetIndex(t)
end
--单个任务
function RecruitTreasurePanel:SingleTask(rewardItem, singleData)
local scoreLevel = Util.GetGameObject(rewardItem, "scoreLevel"):GetComponent("Text")
local scroll1 = Util.GetGameObject(rewardItem, "scroll1")
local scroll2 = Util.GetGameObject(rewardItem, "scroll2")
if not this.itemsList[rewardItem] then
this.itemsList[rewardItem] = {}
end
for k,v in pairs(this.itemsList[rewardItem]) do
v.gameObject:SetActive(false)
end
for i = 1 ,#singleData.reward do
local parent
if singleData.reward[i].type == 1 then
parent = scroll1
else
parent = scroll2
end
if not this.itemsList[rewardItem][i] then
this.itemsList[rewardItem][i] = SubUIManager.Open(SubUIConfig.ItemView,parent.transform)
end
this.itemsList[rewardItem][i].transform:SetParent(parent.transform)
this.itemsList[rewardItem][i].transform.localScale = Vector3.one
this.itemsList[rewardItem][i].transform.localPosition = Vector3.zero
this.itemsList[rewardItem][i].gameObject:SetActive(true)
this.itemsList[rewardItem][i]:OnOpen(false, {singleData.reward[i].id, singleData.reward[i].num}, 0.8, false)
end
scoreLevel.text = singleData.cout
--初始化按钮状态
self:InitButtonState(rewardItem, singleData)
end
--初始化按钮状态
function RecruitTreasurePanel:InitButtonState(rewardItem, singleData)
local btnDeal = Util.GetGameObject(rewardItem, "btnDeal")
local get = Util.GetGameObject(rewardItem, "btnDeal/get")
local getAgain = Util.GetGameObject(rewardItem, "btnDeal/getAgain")
local unfinished = Util.GetGameObject(rewardItem, "btnDeal/unfinished")
local finished = Util.GetGameObject(rewardItem, "finished")
local redPoint = Util.GetGameObject(rewardItem, "btnDeal/redPoint")
--当前任务领取情况
local state = singleData.state
--判断
if state == 0 then
btnDeal.gameObject:SetActive(true)
get.gameObject:SetActive(false)
getAgain.gameObject:SetActive(false)
unfinished.gameObject:SetActive(true)
finished.gameObject:SetActive(false)
redPoint:SetActive(false)
elseif state == 3 then
btnDeal.gameObject:SetActive(true)
get.gameObject:SetActive(false)
getAgain.gameObject:SetActive(true)
unfinished.gameObject:SetActive(false)
finished.gameObject:SetActive(false)
redPoint:SetActive(true)
elseif state == 2 then
btnDeal.gameObject:SetActive(true)
get.gameObject:SetActive(true)
getAgain.gameObject:SetActive(false)
unfinished.gameObject:SetActive(false)
finished.gameObject:SetActive(false)
redPoint:SetActive(true)
elseif state == 1 then
btnDeal.gameObject:SetActive(true)
get.gameObject:SetActive(false)
getAgain.gameObject:SetActive(true)
unfinished.gameObject:SetActive(false)
finished.gameObject:SetActive(false)
redPoint:SetActive(false)
elseif state == -1 then
btnDeal.gameObject:SetActive(false)
get.gameObject:SetActive(false)
getAgain.gameObject:SetActive(false)
unfinished.gameObject:SetActive(false)
finished.gameObject:SetActive(true)
redPoint:SetActive(false)
end
--添加点击事件
Util.AddOnceClick(btnDeal,function()
self:OnBtnDealClicked(rewardItem,singleData)
end)
end
--按钮事件
function RecruitTreasurePanel:OnBtnDealClicked(rewardItem,singleData)
if singleData.state == 0 then
PopupTipPanel.ShowTip(Language[11330])
elseif singleData.state == 3 or singleData.state == 2 then
NetManager.GetActivityRewardRequest(singleData.missionId,configs[curPage].ActId,function(msg)
UIManager.OpenPanel(UIName.RewardItemPopup,msg,1,function()
--需要刷新界面
if not this.isBuy then--判断是否已经购买了礼包
singleData.state = 1
else
singleData.state = -1
end
self:SingleTask(rewardItem, singleData)
--self:refresh()--刷新界面
CheckRedPointStatus(configs[curPage].RpType)
end)
end)
elseif singleData.state == 1 then
UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.HeavenUnlockExtraRewardPanel,configs[curPage].ShopData[1][2],configs[curPage].ActId)
end
end
--界面关闭时调用(用于子类重写)
function RecruitTreasurePanel:OnClose()
self.gameObject:SetActive(false)
end
--界面销毁时调用(用于子类重写)
function RecruitTreasurePanel:OnDestroy()
this.spLoader:Destroy()
for k,v in pairs(this.itemsList) do
for n,m in pairs(v) do
SubUIManager.Close(m)
end
end
this.itemsList = {}
if this.ScrollView then
SubUIManager.Close(this.ScrollView)
this.ScrollView = nil
end
end
return RecruitTreasurePanel