420 lines
15 KiB
Lua
420 lines
15 KiB
Lua
|
require("Base/BasePanel")
|
|||
|
local WeekCardPanel = Inherit(BasePanel)
|
|||
|
local sortingOrder = 0
|
|||
|
local _WeekcardConfig = ConfigManager.GetConfig(ConfigName.WeekcardConfig)
|
|||
|
local weekReward=ConfigManager.GetConfig(ConfigName.WeekRewardConfig)
|
|||
|
local _ItemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
|
|||
|
local _RechargeCommodityConfig = ConfigManager.GetConfig(ConfigName.RechargeCommodityConfig)
|
|||
|
local weekcardR=nil
|
|||
|
--初始化组件(用于子类重写)
|
|||
|
function WeekCardPanel:InitComponent()
|
|||
|
self.spLoader = SpriteLoader.New()
|
|||
|
self.grid = Util.GetGameObject(self.gameObject, "grid")
|
|||
|
self.cardPres = {}
|
|||
|
self.timerList = {}
|
|||
|
self.tabs={}
|
|||
|
self.selectObj=Util.GetGameObject(self.gameObject, "selectObj")
|
|||
|
self.selectTxt=Util.GetGameObject(self.gameObject, "selectObj/Text"):GetComponent("Text")
|
|||
|
self.info1=Util.GetGameObject(self.gameObject, "info1"):GetComponent("Text")
|
|||
|
self.info2=Util.GetGameObject(self.gameObject, "info2"):GetComponent("Text")
|
|||
|
self.info1.text="购买后可连续7日领取奖励"
|
|||
|
self.info2.text="每日0点刷新,奖励可累计领取"
|
|||
|
self.titleImg=Util.GetGameObject(self.gameObject, "titleImg"):GetComponent("Image")
|
|||
|
self.titleImg.sprite=self.spLoader:LoadSprite("r_zhouka_zksh_zh")
|
|||
|
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].bg = self.cardPres[i].go:GetComponent("Image")
|
|||
|
self.cardPres[i].name = Util.GetGameObject(self.cardPres[i].go, "nameBg/name"):GetComponent("Text")
|
|||
|
self.cardPres[i].nameBg = Util.GetGameObject(self.cardPres[i].go, "nameBg"):GetComponent("Image")
|
|||
|
self.cardPres[i].icon = Util.GetGameObject(self.cardPres[i].go, "icon"):GetComponent("Image")
|
|||
|
self.cardPres[i].hint = Util.GetGameObject(self.cardPres[i].go, "hint"):GetComponent("Text")
|
|||
|
self.cardPres[i].Text = Util.GetGameObject(self.cardPres[i].go, "Text"):GetComponent("Text")
|
|||
|
-- self.cardPres[i].icon1 = Util.GetGameObject(self.cardPres[i].go, "tip1/icon"):GetComponent("Image")
|
|||
|
-- self.cardPres[i].icon2 = Util.GetGameObject(self.cardPres[i].go, "tip2/icon"):GetComponent("Image")
|
|||
|
-- self.cardPres[i].icon3 = Util.GetGameObject(self.cardPres[i].go, "Image/icon"):GetComponent("Image")
|
|||
|
|
|||
|
-- self.cardPres[i].dayNum = Util.GetGameObject(self.cardPres[i].go, "tip1/num"):GetComponent("Text")
|
|||
|
-- self.cardPres[i].curNum = Util.GetGameObject(self.cardPres[i].go, "tip2/num"):GetComponent("Text")
|
|||
|
-- self.cardPres[i].allNum = Util.GetGameObject(self.cardPres[i].go, "Image/Text"):GetComponent("Text")
|
|||
|
|
|||
|
self.cardPres[i].btn = Util.GetGameObject(self.cardPres[i].go, "btn")
|
|||
|
self.cardPres[i].btnImg = Util.GetGameObject(self.cardPres[i].go, "btn"):GetComponent("Image")
|
|||
|
self.cardPres[i].btnText = Util.GetGameObject(self.cardPres[i].go, "btn/Text"):GetComponent("Text")
|
|||
|
self.cardPres[i].red = Util.GetGameObject(self.cardPres[i].go, "btn/redPoint")
|
|||
|
self.cardPres[i].rewardGrid = Util.GetGameObject(self.cardPres[i].go, "grid")
|
|||
|
self.cardPres[i].rewards={}
|
|||
|
for j= 1 ,self.cardPres[i].rewardGrid.transform.childCount do
|
|||
|
table.insert(self.cardPres[i].rewards,self.cardPres[i].rewardGrid.transform:GetChild(j - 1).gameObject)
|
|||
|
self.cardPres[i].rewardGrid.transform:GetChild(j - 1).gameObject:SetActive(false)
|
|||
|
end
|
|||
|
|
|||
|
end
|
|||
|
self.btnBack = Util.GetGameObject(self.gameObject,"btnClose")
|
|||
|
self.helpBtn = Util.GetGameObject(self.gameObject, "helpBtn")
|
|||
|
|
|||
|
for i=1,5 do
|
|||
|
table.insert(self.tabs,Util.GetGameObject(self.gameObject, "scrollrect/tabs/"..i))
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--绑定事件(用于子类重写)
|
|||
|
function WeekCardPanel:BindEvent()
|
|||
|
Util.AddClick(self.helpBtn, function()
|
|||
|
local pos = self.helpBtn.transform.localPosition
|
|||
|
UIManager.OpenPanel(UIName.HelpPopup, HELP_TYPE.WeekCard, pos.x, pos.y)
|
|||
|
end)
|
|||
|
Util.AddClick(self.btnBack, function()
|
|||
|
self:ClosePanel()
|
|||
|
end)
|
|||
|
end
|
|||
|
|
|||
|
--添加事件监听(用于子类重写)
|
|||
|
function WeekCardPanel:AddListener()
|
|||
|
Game.GlobalEvent:AddEvent(GameEvent.WeekCard.OnWeekCardUpdate, self.RefreshShow, self)
|
|||
|
end
|
|||
|
|
|||
|
--移除事件监听(用于子类重写)
|
|||
|
function WeekCardPanel:RemoveListener()
|
|||
|
Game.GlobalEvent:RemoveEvent(GameEvent.WeekCard.OnWeekCardUpdate, self.RefreshShow, self)
|
|||
|
end
|
|||
|
|
|||
|
--界面打开时调用(用于子类重写)
|
|||
|
function WeekCardPanel:OnOpen(args)
|
|||
|
-- self.actConfig = _activityConfig
|
|||
|
-- self.pageIndex = _index
|
|||
|
-- self.parent = parent
|
|||
|
activityId=args
|
|||
|
end
|
|||
|
|
|||
|
function WeekCardPanel:OnSortingOrderChange()
|
|||
|
end
|
|||
|
|
|||
|
-- 打开,重新打开时回调
|
|||
|
local allcards={}
|
|||
|
local curKey=0
|
|||
|
local curIndex=0
|
|||
|
--local activityId=0
|
|||
|
function WeekCardPanel:OnShow()
|
|||
|
self.gameObject:SetActive(true)
|
|||
|
sortingOrder = _sortingOrder
|
|||
|
-- 查看周卡界面刷新红点
|
|||
|
PlayerPrefs.SetInt("IsCheckWeekCard_"..PlayerManager.uid, 1)
|
|||
|
CheckRedPointStatus(RedPointType.WeekCardOpen)
|
|||
|
local id = ActivityGiftManager.GetActivityTypeInfo(102)
|
|||
|
LogError("id.activityId=="..activityId)
|
|||
|
weekcardR=ConfigManager.GetConfigDataByKey(ConfigName.WeekcardRotationConfig,"GlobalActivity",id.activityId)
|
|||
|
--weekcardR=ConfigManager.GetConfigData(ConfigName.WeekcardRotationConfig,1)
|
|||
|
local cardTypes={}
|
|||
|
for i=1,#weekcardR.WeekcardType do
|
|||
|
local id=weekcardR.WeekcardType[i][3]
|
|||
|
local min=weekcardR.WeekcardType[i][1]
|
|||
|
local max=weekcardR.WeekcardType[i][2]
|
|||
|
LogError(" "..id)
|
|||
|
local type=_WeekcardConfig[id].Type
|
|||
|
local data=WeekCardManager.GetWeekCardData(id)
|
|||
|
--已经购买
|
|||
|
if data then
|
|||
|
if allcards[type]==nil then
|
|||
|
allcards[type]={}
|
|||
|
end
|
|||
|
table.insert(allcards[type],_WeekcardConfig[id])
|
|||
|
table.insert(cardTypes,_WeekcardConfig[id].WeekcardType)
|
|||
|
else
|
|||
|
if PlayerManager.level>=min and PlayerManager.level<=max and not cardTypes[_WeekcardConfig[id].WeekcardType] then
|
|||
|
if allcards[type]==nil then
|
|||
|
allcards[type]={}
|
|||
|
end
|
|||
|
table.insert(allcards[type],_WeekcardConfig[id])
|
|||
|
end
|
|||
|
end
|
|||
|
--table.insert(allcards,weekcardR.WeekcardType[i][3])
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
for i=1, 5 do
|
|||
|
self.tabs[i]:SetActive(false)
|
|||
|
end
|
|||
|
local i=0
|
|||
|
local firstKey=0
|
|||
|
for key, value in pairs(allcards) do
|
|||
|
i=i+1
|
|||
|
self.tabs[i]:SetActive(true)
|
|||
|
local name=Util.GetGameObject(self.tabs[i], "Text"):GetComponent("Text")
|
|||
|
name.text=value[1].Desc
|
|||
|
local red=Util.GetGameObject(self.tabs[i], "redpoint")
|
|||
|
red:SetActive(false)
|
|||
|
if firstKey == 0 then
|
|||
|
firstKey = key
|
|||
|
curIndex=i
|
|||
|
end
|
|||
|
local kk=key
|
|||
|
Util.AddClick(self.tabs[i], function()
|
|||
|
|
|||
|
curKey=kk
|
|||
|
curIndex=i
|
|||
|
self:SetCardWind(curKey)
|
|||
|
end)
|
|||
|
--LogError("key=="..key.." value=="..value[1].Id.." value2=="..value[2].Id)
|
|||
|
end
|
|||
|
|
|||
|
if curKey==0 then
|
|||
|
curKey=firstKey
|
|||
|
end
|
|||
|
self:SetCardWind(firstKey)
|
|||
|
end
|
|||
|
|
|||
|
-- 妖晶数量显示
|
|||
|
function WeekCardPanel:RefreshShow()
|
|||
|
-- local allData = WeekCardManager.GetWeekCardDataArray()
|
|||
|
-- --月卡
|
|||
|
-- for i = 1, #self.cardPres do
|
|||
|
-- if allData[i] then
|
|||
|
-- self:SetCardShow(i, allData[i])
|
|||
|
-- end
|
|||
|
-- end
|
|||
|
LogError("刷新周卡界面 curkey=="..curKey)
|
|||
|
self:SetCardWind(curKey)
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
--设置周卡界面
|
|||
|
function WeekCardPanel:SetCardWind(key)
|
|||
|
curkey=key
|
|||
|
LogError("currkey=="..key)
|
|||
|
if allcards[curkey] then
|
|||
|
local aaa=0
|
|||
|
for k, value in pairs(allcards) do
|
|||
|
LogError("k=="..k)
|
|||
|
aaa=aaa+1
|
|||
|
if k==curkey then
|
|||
|
break
|
|||
|
end
|
|||
|
end
|
|||
|
self.selectObj.transform:SetParent(self.tabs[aaa].transform)
|
|||
|
self.selectObj.transform.localScale = Vector3.one
|
|||
|
self.selectObj.transform.localPosition = Vector3.zero
|
|||
|
self.selectTxt:GetComponent("Text").text = Util.GetGameObject(self.tabs[aaa], "Text"):GetComponent("Text").text
|
|||
|
for i=1,#allcards[curkey] do
|
|||
|
self:ShowCardInfo(i,allcards[curkey][i])
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
|
|||
|
--显示周卡信息
|
|||
|
function WeekCardPanel:ShowCardInfo(index,config)
|
|||
|
local pre = self.cardPres[index]
|
|||
|
if not pre then
|
|||
|
return
|
|||
|
end
|
|||
|
if not config then
|
|||
|
return
|
|||
|
end
|
|||
|
-- 背景
|
|||
|
|
|||
|
-- 物品名称
|
|||
|
if config.QualityType==1 then
|
|||
|
pre.name.text = "普通"
|
|||
|
pre.bg.sprite = self.spLoader:LoadSprite("r_zhouka_card_bg2")
|
|||
|
pre.btnImg.sprite=self.spLoader:LoadSprite("r_zhouka_btn_an")
|
|||
|
pre.nameBg.sprite=self.spLoader:LoadSprite("r_zhouka_btn_bg2")
|
|||
|
|
|||
|
else
|
|||
|
pre.name.text = "豪华"
|
|||
|
pre.bg.sprite = self.spLoader:LoadSprite("r_zhouka_card_bg1")
|
|||
|
pre.btnImg.sprite=self.spLoader:LoadSprite("r_zhouka_btn_liang")
|
|||
|
pre.nameBg.sprite=self.spLoader:LoadSprite("r_zhouka_btn_bg1")
|
|||
|
end
|
|||
|
|
|||
|
-- 每日奖励数量
|
|||
|
local itemId = 0
|
|||
|
local dayNum = 0
|
|||
|
-- pre.rewards
|
|||
|
-- weekReward
|
|||
|
local allNum=0
|
|||
|
local name=""
|
|||
|
local icon=""
|
|||
|
local oneNum=0
|
|||
|
for i=1,#config.BaseRewardID do
|
|||
|
if pre.rewards[i] then
|
|||
|
pre.rewards[i]:SetActive(true)
|
|||
|
local dayTxt=Util.GetGameObject(pre.rewards[i],"day"):GetComponent("Text")
|
|||
|
dayTxt.text="第"..NumToChinese[config.BaseRewardID[i][1]].."天"
|
|||
|
local rewardId=config.BaseRewardID[i][2]
|
|||
|
if weekReward[rewardId] then
|
|||
|
local id= weekReward[rewardId].BaseReward[1]
|
|||
|
local num= weekReward[rewardId].BaseReward[2]
|
|||
|
name=_ItemConfig[id].Name
|
|||
|
oneNum=num
|
|||
|
icon=GetResourcePath(_ItemConfig[id].ResourceID)
|
|||
|
pre.rewards[i]:GetComponent("Image").sprite=self.spLoader:LoadSprite(GetQuantityImageByquality(_ItemConfig[id].Quantity))
|
|||
|
local icon1=Util.GetGameObject(pre.rewards[i],"Image"):GetComponent("Image")
|
|||
|
icon1.sprite=self.spLoader:LoadSprite(icon)
|
|||
|
local stateTxt=Util.GetGameObject(pre.rewards[i],"Text"):GetComponent("Text")
|
|||
|
local numTxt=Util.GetGameObject(pre.rewards[i],"num"):GetComponent("Text")
|
|||
|
if num>10000 then
|
|||
|
numTxt.text=PrintWanNum2(num)
|
|||
|
else
|
|||
|
numTxt.text=num
|
|||
|
end
|
|||
|
allNum=allNum+num
|
|||
|
end
|
|||
|
|
|||
|
-- pre.rewards[i]:GetComponent("Image").sprite=self.spLoader:LoadSprite(config.TypeImage)
|
|||
|
end
|
|||
|
end
|
|||
|
pre.icon.sprite = self.spLoader:LoadSprite(icon)
|
|||
|
pre.Text.text = name.."*"..PrintWanNum2(oneNum)
|
|||
|
pre.hint.text = "共计"..PrintWanNum2(allNum)..name
|
|||
|
local rechargeCfg = _RechargeCommodityConfig[config.RechargeId]
|
|||
|
if not rechargeCfg then
|
|||
|
return
|
|||
|
end
|
|||
|
local data=WeekCardManager.GetWeekCardData(config.Id)
|
|||
|
-- 按钮状态
|
|||
|
if data then
|
|||
|
local getNum=0
|
|||
|
for i=1,#data.leaveGetRewardDays do
|
|||
|
if data.leaveGetRewardDays[i].state==1 then
|
|||
|
getNum=getNum+1
|
|||
|
end
|
|||
|
end
|
|||
|
if getNum > 0 then
|
|||
|
-- 领取奖励
|
|||
|
pre.btnText.text = "领取"
|
|||
|
pre.red:SetActive(true)
|
|||
|
Util.SetGray(pre.btn, false)
|
|||
|
Util.AddOnceClick(pre.btn, function()
|
|||
|
local id = ActivityGiftManager.GetActivityTypeInfo(102)
|
|||
|
LogError("cardid=="..data.id.." id=="..id.activityId)
|
|||
|
WeekCardManager.RequestGetWeekCardReward(data.id, id.activityId,function()
|
|||
|
-- 刷新显示
|
|||
|
self:RefreshShow()
|
|||
|
end)
|
|||
|
end)
|
|||
|
else
|
|||
|
-- 已领取
|
|||
|
pre.btnText.text = "已领取"
|
|||
|
pre.red:SetActive(false)
|
|||
|
Util.SetGray(pre.btn, true)
|
|||
|
Util.AddOnceClick(pre.btn, function()
|
|||
|
PopupTipPanel.ShowTip("您已领取该奖励")
|
|||
|
end)
|
|||
|
end
|
|||
|
else
|
|||
|
-- 购买周卡
|
|||
|
pre.btnText.text = MoneyUtil.GetMoneyUnitNameWithMoney(rechargeCfg.Price)
|
|||
|
pre.red:SetActive(false)
|
|||
|
Util.SetGray(pre.btn, false)
|
|||
|
Util.AddOnceClick(pre.btn, function()
|
|||
|
PayManager.Pay(config.RechargeId, function(id)
|
|||
|
-- 前端修改购买状态
|
|||
|
--data.isBuy = true
|
|||
|
--WeekCardManager.UpdateWeekCardData(data)
|
|||
|
-- 刷新显示
|
|||
|
--self:SetCardWind(curKey)
|
|||
|
end)
|
|||
|
end)
|
|||
|
end
|
|||
|
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
function WeekCardPanel:SetCardShow(index, data)
|
|||
|
local pre = self.cardPres[index]
|
|||
|
if not pre then
|
|||
|
return
|
|||
|
end
|
|||
|
local config = _WeekcardConfig[data.id]
|
|||
|
if not config then
|
|||
|
return
|
|||
|
end
|
|||
|
-- 背景
|
|||
|
pre.bg.sprite = self.spLoader:LoadSprite(config.BgImage)
|
|||
|
-- 物品名称
|
|||
|
pre.name.sprite = self.spLoader:LoadSprite(config.TypeImage)
|
|||
|
pre.name:SetNativeSize()
|
|||
|
-- 每日奖励数量
|
|||
|
local itemId = 0
|
|||
|
local dayNum = 0
|
|||
|
if config.BaseReward and config.BaseReward[1] then
|
|||
|
itemId = config.BaseReward[1][1]
|
|||
|
dayNum = config.BaseReward[1][2]
|
|||
|
end
|
|||
|
pre.dayNum.text = PrintWanNum2(dayNum)
|
|||
|
-- 当前累计奖励数量
|
|||
|
local curNum = dayNum * data.leaveGetRewardDays or 0
|
|||
|
pre.curNum.text = PrintWanNum2(curNum)
|
|||
|
pre.curNum.transform.parent.gameObject:SetActive(curNum ~= 0) -- 累计数量为0时不显示
|
|||
|
-- 总奖励数量
|
|||
|
local continueDay = config.ContiueDays or 0
|
|||
|
local allNum = dayNum * continueDay
|
|||
|
pre.allNum.text = PrintWanNum2(allNum)
|
|||
|
-- 设置物品图片显示
|
|||
|
local sprite = SetIcon(self.spLoader, itemId)
|
|||
|
pre.icon.sprite = sprite
|
|||
|
pre.icon1.sprite = sprite
|
|||
|
pre.icon2.sprite = sprite
|
|||
|
pre.icon3.sprite = sprite
|
|||
|
|
|||
|
local rechargeCfg = _RechargeCommodityConfig[config.RechargeId]
|
|||
|
if not rechargeCfg then
|
|||
|
return
|
|||
|
end
|
|||
|
|
|||
|
-- 按钮状态
|
|||
|
if data.isBuy then
|
|||
|
if data.leaveGetRewardDays > 0 then
|
|||
|
-- 领取奖励
|
|||
|
pre.btnText.text = "领取"
|
|||
|
pre.red:SetActive(true)
|
|||
|
Util.SetGray(pre.btn, false)
|
|||
|
Util.AddOnceClick(pre.btn, function()
|
|||
|
WeekCardManager.RequestGetWeekCardReward(data.id, function()
|
|||
|
-- 刷新显示
|
|||
|
self:RefreshShow()
|
|||
|
end)
|
|||
|
end)
|
|||
|
else
|
|||
|
-- 已领取
|
|||
|
pre.btnText.text = "已领取"
|
|||
|
pre.red:SetActive(false)
|
|||
|
Util.SetGray(pre.btn, true)
|
|||
|
Util.AddOnceClick(pre.btn, function()
|
|||
|
PopupTipPanel.ShowTip("您已领取该奖励")
|
|||
|
end)
|
|||
|
end
|
|||
|
else
|
|||
|
-- 购买周卡
|
|||
|
pre.btnText.text = MoneyUtil.GetMoneyUnitNameWithMoney(rechargeCfg.Price)
|
|||
|
pre.red:SetActive(false)
|
|||
|
Util.SetGray(pre.btn, false)
|
|||
|
Util.AddOnceClick(pre.btn, function()
|
|||
|
PayManager.Pay(config.RechargeId, function(id)
|
|||
|
-- 前端修改购买状态
|
|||
|
data.isBuy = true
|
|||
|
WeekCardManager.UpdateWeekCardData(data)
|
|||
|
-- 刷新显示
|
|||
|
self:RefreshShow()
|
|||
|
end)
|
|||
|
end)
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--界面关闭时调用(用于子类重写)
|
|||
|
function WeekCardPanel:OnClose()
|
|||
|
|
|||
|
end
|
|||
|
--界面销毁时调用(用于子类重写)
|
|||
|
function WeekCardPanel:OnDestroy()
|
|||
|
self.spLoader:Destroy()
|
|||
|
self.cardPres = {}
|
|||
|
end
|
|||
|
return WeekCardPanel
|
|||
|
|