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

357 lines
14 KiB
Lua
Raw Normal View History

2021-12-10 13:41:03 +08:00
local RecruitTreasurePanel = {}
local this = RecruitTreasurePanel
local sortingOrder = 0
local redPointTypeList = {}
local curPage = 0
2024-09-20 18:03:36 +08:00
local curId = 0
2021-12-10 13:41:03 +08:00
-- Tab管理器
local TabBox = require("Modules/Common/TabBox")
2024-09-20 18:03:36 +08:00
local configs = ConfigManager.GetAllConfigsDataByKey(ConfigName.ActivityGroups, "PageType",
ActivityTypeDef.RecruitTreasure)
2021-12-10 13:41:03 +08:00
function RecruitTreasurePanel:New(gameObject)
local b = {}
b.gameObject = gameObject
b.transform = gameObject.transform
setmetatable(b, { __index = RecruitTreasurePanel })
return b
end
2024-09-20 18:03:36 +08:00
2021-12-10 13:41:03 +08:00
local itemnum = 0
--初始化组件(用于子类重写)
function RecruitTreasurePanel:InitComponent()
this.spLoader = SpriteLoader.New()
this.quesBtn = Util.GetGameObject(self.transform, "bg/quesBtn")
2024-09-20 18:03:36 +08:00
this.helpPosition = this.quesBtn:GetComponent("RectTransform").localPosition
2021-12-10 13:41:03 +08:00
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")
2021-12-10 14:58:14 +08:00
this.topBarImage = Util.GetGameObject(self.transform, "bg/topBar"):GetComponent("Image")
2021-12-10 13:41:03 +08:00
--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")
2021-12-10 14:58:14 +08:00
local v = this.treasureList:GetComponent("RectTransform").rect
2021-12-10 13:41:03 +08:00
--设置滚动条
2024-09-20 18:03:36 +08:00
this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.treasureList.transform, this.itemPre, nil,
Vector2.New(v.width, v.height), 1, 1, Vector2.New(100, 25))
2021-12-10 13:41:03 +08:00
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
2024-09-20 18:03:36 +08:00
this.btn_qmfl = Util.GetGameObject(self.transform, "bg/topBar/btn_qmfl")
this.btn_qmfl_red = Util.GetGameObject(self.transform, "bg/topBar/btn_qmfl/red")
2022-12-16 17:04:19 +08:00
this.btn_qmfl_red:SetActive(false)
2024-09-20 18:03:36 +08:00
this.btn_qmfl:GetComponent("Image").sprite = this.spLoader:LoadSprite("GM_qmfl_botton_zh")
2021-12-10 13:41:03 +08:00
this.tabbox = Util.GetGameObject(self.gameObject, "bg/pageContent/tabbox")
end
--绑定事件(用于子类重写)
function RecruitTreasurePanel:BindEvent()
2024-09-20 18:03:36 +08:00
Util.AddClick(this.quesBtn, function()
UIManager.OpenPanel(UIName.HelpPopup, this.actConfig.HelpId, this.helpPosition.x, this.helpPosition.y)
2021-12-10 13:41:03 +08:00
end)
2024-09-20 18:03:36 +08:00
Util.AddClick(this.btn_qmfl, function()
2022-09-15 16:48:56 +08:00
--LogGreen(this.helpPosition.x.."+"..this.helpPosition.
2024-09-20 18:03:36 +08:00
UIManager.OpenPanel(UIName.QuanMinFLPanel, curId)
2022-09-15 16:48:56 +08:00
end)
2021-12-10 13:41:03 +08:00
-- 初始化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)
2024-09-20 18:03:36 +08:00
tip.text = string.format("<color=#%s>%s</color>", "FDF4D6", configs[index].Icon[1])
2021-12-10 13:41:03 +08:00
else
select.gameObject:SetActive(false)
2024-09-20 18:03:36 +08:00
tip.text = string.format("<color=#%s>%s</color>", "B5A481", configs[index].Icon[1])
2021-12-10 13:41:03 +08:00
end
if redPointTypeList[configs[index].RpType] then
2024-09-20 18:03:36 +08:00
ClearRedPointObject(configs[index].RpType, redPointTypeList[configs[index].RpType])
2021-12-10 13:41:03 +08:00
redPointTypeList[configs[index].RpType] = nil
end
if not configs[index].RpType or configs[index].RpType < 1 then
redpot.gameObject:SetActive(false)
2024-09-20 18:03:36 +08:00
else
BindRedPointObject(configs[index].RpType, redpot)
2021-12-10 13:41:03 +08:00
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
2021-12-10 14:58:14 +08:00
this.actId = configs[curPage].ActId
2024-09-20 18:03:36 +08:00
this.tips.text = GetLanguageStrById(configs[curPage].TitleText)
2021-12-10 14:58:14 +08:00
this.topBarImage.sprite = this.spLoader:LoadSprite(configs[curPage].Icon[2])
2021-12-10 13:41:03 +08:00
this:refresh()
end
2022-05-19 17:30:26 +08:00
function RecruitTreasurePanel:OnSortingOrderChange()
2021-12-10 13:41:03 +08:00
end
--添加事件监听(用于子类重写)
function RecruitTreasurePanel:AddListener()
2024-09-20 18:03:36 +08:00
Game.GlobalEvent:AddEvent(GameEvent.TreasureOfHeaven.RechargeSuccess, this.refresh, self)
2021-12-10 13:41:03 +08:00
end
--移除事件监听(用于子类重写)
function RecruitTreasurePanel:RemoveListener()
2024-09-20 18:03:36 +08:00
Game.GlobalEvent:RemoveEvent(GameEvent.TreasureOfHeaven.RechargeSuccess, this.refresh, self)
2021-12-10 13:41:03 +08:00
end
--界面打开时调用(用于子类重写)
2024-09-20 18:03:36 +08:00
function RecruitTreasurePanel:OnOpen(_activityConfig, _index, parent)
2021-12-10 13:41:03 +08:00
this.actConfig = _activityConfig
this.pageIndex = _index
this.parent = parent
end
2022-12-16 17:04:19 +08:00
function RecruitTreasurePanel:OnFocus()
this.btn_qmfl_red:SetActive(RecruitTreasureManager.GetQuanMinRed(curId))
end
2024-09-20 18:03:36 +08:00
2021-12-10 13:41:03 +08:00
-- 打开,重新打开时回调
2022-09-15 16:48:56 +08:00
2021-12-10 13:41:03 +08:00
function RecruitTreasurePanel:OnShow(_sortingOrder)
self.gameObject:SetActive(true)
sortingOrder = _sortingOrder
this.actType = this.actConfig.ActiveType > 0 and this.actConfig.ActiveType or this.actConfig.FunType
2024-09-20 18:03:36 +08:00
curId = ActivityGiftManager.GetActivityIdByType(this.actType)
LogError("this.acttype====" .. this.actType .. " curid==" .. curId)
2022-12-16 17:04:19 +08:00
this.btn_qmfl_red:SetActive(RecruitTreasureManager.GetQuanMinRed(curId))
2024-09-20 18:03:36 +08:00
this.btn_qmfl:SetActive(ActivityGiftManager.GetActivityInfoByType(10502) ~= nil and this.actType == 7 and
ActivityGiftManager.CheckIsHaveHaveQMFL(this.actType, curId))
2021-12-10 13:41:03 +08:00
this.titleImage.sprite = this.spLoader:LoadSprite(this.actConfig.Icon[3])
local activeNum = 0
curPage = 0
2024-09-20 18:03:36 +08:00
for i = 1, #configs do
2021-12-10 13:41:03 +08:00
this.actData = ActivityGiftManager.GetActivityInfoByType(configs[i].ActId)
if this.actData then
activeNum = activeNum + 1
if curPage < 1 then
2024-09-20 18:03:36 +08:00
this.treasureData = RecruitTreasureManager.GetRecruitTreasureData(configs[i].ActId,
configs[i].ShopData[1][1])
for j = 1, #this.treasureData do
2021-12-10 13:41:03 +08:00
if this.treasureData[j].state == 2 or this.treasureData[j].state == 3 then
curPage = i
end
end
end
end
end
2024-09-20 18:03:36 +08:00
2021-12-10 13:41:03 +08:00
if activeNum == 1 then
this.tabbox.gameObject:SetActive(false)
else
this.tabbox.gameObject:SetActive(true)
end
if curPage < 1 then
curPage = activeNum
end
2024-09-20 18:03:36 +08:00
this.PageTabCtrl:Init(this.tabbox.gameObject, configs, curPage)
2021-12-10 13:41:03 +08:00
end
function RecruitTreasurePanel:refresh()
2024-09-20 18:03:36 +08:00
this.treasureData = RecruitTreasureManager.GetRecruitTreasureData(configs[curPage].ActId,
configs[curPage].ShopData[1][1])
2021-12-10 14:58:14 +08:00
this.actData = ActivityGiftManager.GetActivityInfoByType(configs[curPage].ActId)
2024-09-20 18:03:36 +08:00
this.isBuy = RecruitTreasureManager.CheckIsBuyTreasureByGoodsId(configs[curPage].ShopData[1][1])
2021-12-10 13:41:03 +08:00
self:topBar()
self:showTaskList()
end
--topBar按钮状态
function RecruitTreasurePanel:topBar()
--设置礼包购买按钮状态
this.buyBtn:GetComponent("Button").interactable = not this.isBuy
2024-08-29 21:36:51 +08:00
this.Text1.text = not this.isBuy and Language[12913] or Language[10723]
2024-09-20 18:03:36 +08:00
Util.AddOnceClick(this.buyBtn, function()
UIManager.OpenPanel(UIName.GeneralPopup, GENERAL_POPUP_TYPE.HeavenUnlockExtraRewardPanel,
configs[curPage].ShopData[1][2], configs[curPage].ActId)
2021-12-10 13:41:03 +08:00
end)
end
--任务列表
2024-09-20 18:03:36 +08:00
function RecruitTreasurePanel:showTaskList(isTop, isAni)
2021-12-10 13:41:03 +08:00
this.scoreText.text = this.actData.value
if not this.itemsList then
this.itemsList = {}
end
2024-09-20 18:03:36 +08:00
this.ScrollView:SetData(this.treasureData, function(index, rewardItem)
2021-12-10 13:41:03 +08:00
self:SingleTask(rewardItem, this.treasureData[index])
2024-09-20 18:03:36 +08:00
end, not isTop, not isAni)
2021-12-10 13:41:03 +08:00
-- -1 完美领取 1 已领取 2 未领取过可领取 3 领取过可完美领取 0 未达成
--定位打开界面时位置
local t = 0
2024-09-20 18:03:36 +08:00
for i = 1, #this.treasureData do
if this.treasureData[i].state == 2 or this.treasureData[i].state == 3 then
t = i
break
2021-12-10 13:41:03 +08:00
end
2024-09-20 18:03:36 +08:00
end
2021-12-10 13:41:03 +08:00
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
2024-09-20 18:03:36 +08:00
for k, v in pairs(this.itemsList[rewardItem]) do
2021-12-10 13:41:03 +08:00
v.gameObject:SetActive(false)
end
2024-09-20 18:03:36 +08:00
for i = 1, #singleData.reward do
2021-12-10 13:41:03 +08:00
local parent
if singleData.reward[i].type == 1 then
parent = scroll1
else
parent = scroll2
end
if not this.itemsList[rewardItem][i] then
2024-09-20 18:03:36 +08:00
this.itemsList[rewardItem][i] = SubUIManager.Open(SubUIConfig.ItemView, parent.transform)
2021-12-10 13:41:03 +08:00
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)
2024-09-20 18:03:36 +08:00
this.itemsList[rewardItem][i]:OnOpen(false, { singleData.reward[i].id, singleData.reward[i].num }, 0.8, false)
2021-12-10 13:41:03 +08:00
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")
--当前任务领取情况
2024-09-20 18:03:36 +08:00
local state = singleData.state
2021-12-10 13:41:03 +08:00
--判断
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
--添加点击事件
2024-09-20 18:03:36 +08:00
Util.AddOnceClick(btnDeal, function()
self:OnBtnDealClicked(rewardItem, singleData)
2021-12-10 13:41:03 +08:00
end)
end
--按钮事件
2024-09-20 18:03:36 +08:00
function RecruitTreasurePanel:OnBtnDealClicked(rewardItem, singleData)
2021-12-10 13:41:03 +08:00
if singleData.state == 0 then
2024-08-29 21:36:51 +08:00
PopupTipPanel.ShowTip(Language[11040])
2021-12-10 13:41:03 +08:00
elseif singleData.state == 3 or singleData.state == 2 then
2024-09-20 18:03:36 +08:00
NetManager.GetActivityRewardRequest(singleData.missionId, configs[curPage].ActId, function(msg)
UIManager.OpenPanel(UIName.RewardItemPopup, msg, 1, function()
2021-12-10 13:41:03 +08:00
--需要刷新界面
2024-09-20 18:03:36 +08:00
if not this.isBuy then --判断是否已经购买了礼包
2021-12-10 13:41:03 +08:00
singleData.state = 1
else
singleData.state = -1
end
self:SingleTask(rewardItem, singleData)
--self:refresh()--刷新界面
CheckRedPointStatus(configs[curPage].RpType)
2024-09-20 18:03:36 +08:00
end)
2021-12-10 13:41:03 +08:00
end)
elseif singleData.state == 1 then
2024-09-20 18:03:36 +08:00
UIManager.OpenPanel(UIName.GeneralPopup, GENERAL_POPUP_TYPE.HeavenUnlockExtraRewardPanel,
configs[curPage].ShopData[1][2], configs[curPage].ActId)
2021-12-10 13:41:03 +08:00
end
end
--界面关闭时调用(用于子类重写)
function RecruitTreasurePanel:OnClose()
self.gameObject:SetActive(false)
end
--界面销毁时调用(用于子类重写)
function RecruitTreasurePanel:OnDestroy()
this.spLoader:Destroy()
2024-09-20 18:03:36 +08:00
for k, v in pairs(this.itemsList) do
for n, m in pairs(v) do
2021-12-10 14:58:14 +08:00
SubUIManager.Close(m)
end
end
2021-12-10 13:41:03 +08:00
this.itemsList = {}
if this.ScrollView then
SubUIManager.Close(this.ScrollView)
this.ScrollView = nil
end
end
2024-09-20 18:03:36 +08:00
return RecruitTreasurePanel