312 lines
13 KiB
Lua
312 lines
13 KiB
Lua
local QianKunBox = quick_class("QianKunBox")
|
|
local ActivityDetail = require("Modules/DynamicActivity/ActivityDetail")--活动详情
|
|
local parent
|
|
local iconsData = nil
|
|
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
|
|
local artConfig = ConfigManager.GetConfig(ConfigName.ArtResourcesConfig)
|
|
local lotterySetting=ConfigManager.GetConfig(ConfigName.LotterySetting)
|
|
local privilegeConfig=ConfigManager.GetConfig(ConfigName.PrivilegeTypeConfig)
|
|
local artResourcesConfig =ConfigManager.GetConfig(ConfigName.ArtResourcesConfig)
|
|
local lotterySpecialConfig = ConfigManager.GetConfig(ConfigName.LotterySpecialConfig)
|
|
local orginLayer = 0
|
|
|
|
local activityId = 0
|
|
local singleRecruit = nil
|
|
local tenRecruit = nil
|
|
|
|
local bType={
|
|
Btn1=1,
|
|
Btn10=2
|
|
}
|
|
--type与lotterySetting表中的id对应
|
|
local btns={ [bType.Btn1]={name="bottom/btnOne",isInfo=Language[10478]}, [bType.Btn10]={name="bottom/btnTen",isInfo=Language[10479]}}
|
|
|
|
|
|
function QianKunBox:ctor(mainPanel, gameObject)
|
|
self.mainPanel = mainPanel.transform
|
|
self.gameObject = gameObject
|
|
self:InitComponent(gameObject)
|
|
self:BindEvent()
|
|
end
|
|
|
|
function QianKunBox:InitComponent(gameObject)
|
|
|
|
self.tabList = Util.GetGameObject(self.mainPanel,"bg/tabbox")
|
|
self.btnBack = Util.GetGameObject(self.mainPanel,"bg/btnBack")
|
|
self.bottomBar = Util.GetGameObject(self.mainPanel,"bg/bottomBar")
|
|
--midDown
|
|
self.midDown = Util.GetGameObject(gameObject,"midDown")
|
|
self.midDowntips1 = Util.GetGameObject(self.midDown,"tips/tips1"):GetComponent("Text")
|
|
-- self.leftUptips1 = Util.GetGameObject(self.midDown,"tips/tips1/times"):GetComponent("Text")
|
|
self.leftUpTime = Util.GetGameObject(self.midDown,"tips/tips2/time"):GetComponent("Text")
|
|
self.btnHelp= Util.GetGameObject(gameObject,"btnHelp")
|
|
self.helpPosition=self.btnHelp:GetComponent("RectTransform").localPosition
|
|
--rightUp
|
|
self.rightUp = Util.GetGameObject(gameObject,"rightUp")
|
|
self.btnReward = Util.GetGameObject(self.rightUp,"reward")
|
|
self.btnStore = Util.GetGameObject(self.rightUp,"store")
|
|
--center
|
|
self.center = Util.GetGameObject(gameObject,"center")
|
|
self.icons = Util.GetGameObject(self.center,"icons")
|
|
--bottom
|
|
self.bottom = Util.GetGameObject(gameObject,"bottom")
|
|
self.btnOne = Util.GetGameObject(self.bottom,"btnOne")
|
|
self.di1 = Util.GetGameObject(self.bottom,"countDown/di1")
|
|
self.btnTime = Util.GetGameObject(self.bottom,"countDown/di1/time"):GetComponent("Text")
|
|
self.btnTen1 = Util.GetGameObject(self.bottom,"btnTen1")
|
|
self.btnTen2 = Util.GetGameObject(self.bottom,"btnTen2")
|
|
self.btnTimes= Util.GetGameObject(self.bottom,"countDown/di2/time"):GetComponent("Text")
|
|
ForceRebuildLayout(self.btnTimes.gameObject.transform.parent)
|
|
--limit
|
|
self.limit = Util.GetGameObject(gameObject,"limitdi/limit"):GetComponent("Text")
|
|
--detail
|
|
self.detail = Util.GetGameObject(gameObject,"detail")
|
|
--shop
|
|
self.shop = Util.GetGameObject(gameObject,"shop")
|
|
self.shopBack = Util.GetGameObject(self.shop,"shopBack/btnBack")
|
|
self.content = Util.GetGameObject(self.shop,"content")
|
|
self.effect = Util.GetGameObject(self.gameObject, "Effect_UI_changjing_qiankuanbaoguo")
|
|
end
|
|
|
|
function QianKunBox:BindEvent()
|
|
Util.AddClick(self.btnHelp,function()
|
|
UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.QianKunBox,self.helpPosition.x,self.helpPosition.y)
|
|
end)
|
|
Util.AddClick(self.btnReward,function()
|
|
self.effect:SetActive(false)
|
|
ActivityDetail.new(self.detail,2,self.effect)
|
|
end)
|
|
Util.AddClick(self.btnStore,function()
|
|
self.effect:SetActive(false)
|
|
self.shop:SetActive(true)
|
|
self.btnBack:SetActive(false)
|
|
self.tabList:SetActive(false)
|
|
self.bottomBar:SetActive(false)
|
|
self:storeShow()--商店
|
|
end)
|
|
Util.AddClick(self.shopBack,function()
|
|
self.effect:SetActive(true)
|
|
self.shop:SetActive(false)
|
|
self.btnBack:SetActive(true)
|
|
self.tabList:SetActive(true)
|
|
self.bottomBar:SetActive(true)
|
|
parent.UpView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.QianKunBox })
|
|
self:OnShow(orginLayer,parent)
|
|
end)
|
|
end
|
|
|
|
function QianKunBox:OnShow(sortingOrder,_parent)
|
|
parent = _parent
|
|
Util.AddParticleSortLayer(self.effect, sortingOrder - orginLayer)
|
|
orginLayer = sortingOrder
|
|
activityId = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.QianKunBox)
|
|
if not activityId or activityId <= 0 then return end
|
|
local array = ConfigManager.GetAllConfigsDataByKey(ConfigName.LotterySetting,"ActivityId",activityId)
|
|
singleRecruit = array[1]
|
|
tenRecruit = array[2]
|
|
iconsData = ConfigManager.GetAllConfigsDataByKey(ConfigName.LotteryRewardConfig,"Pool",singleRecruit.DiamondBoxContain[1][1])
|
|
self.gameObject:SetActive(true)
|
|
self:refreshMagicNum()
|
|
self:refreshBtnShow()--刷新按钮显示
|
|
|
|
self:contentShow()--五个魂印头像
|
|
self:timeCountDown()--时间
|
|
|
|
end
|
|
|
|
function QianKunBox:refreshBtnShow()
|
|
-- self.btnTen2:SetActive(BagManager.GetItemCountById(16)>=2000)
|
|
-- self.btnTen1:SetActive(BagManager.GetItemCountById(16)<2000)
|
|
|
|
self.shop:SetActive(false)
|
|
local freeTimesId=lotterySetting[singleRecruit.Id].FreeTimes
|
|
local maxtimesId=lotterySetting[singleRecruit.Id].MaxTimes --lotterySetting表中的MaxTimes对应privilegeConfig表中的id
|
|
local curTimes=PrivilegeManager.GetPrivilegeUsedTimes(maxtimesId)
|
|
local freeTime= 0
|
|
self.limit.text = Language[10483]..curTimes.."/"..privilegeConfig[maxtimesId].Condition[1][2]
|
|
self.di1:SetActive(true)
|
|
if freeTimesId>0 then
|
|
freeTime= PrivilegeManager.GetPrivilegeRemainValue(freeTimesId)
|
|
RecruitManager.freeUseTimeList[freeTimesId]=freeTime
|
|
end
|
|
|
|
--按钮赋值
|
|
for n, m in ipairs(btns) do
|
|
local btn=Util.GetGameObject(self.gameObject,m.name)
|
|
local redPot=Util.GetGameObject(btn.gameObject,"redPoint")
|
|
local info=Util.GetGameObject(btn.gameObject,"layout/info"):GetComponent("Text")
|
|
local icon=Util.GetGameObject(btn.gameObject,"layout/icon"):GetComponent("Image")
|
|
local num=Util.GetGameObject(btn.gameObject,"layout/num"):GetComponent("Text")
|
|
|
|
--存在免费次数 并且 免费>=1 并且是1按钮
|
|
local isFree=freeTime and freeTime >= 1 and n==bType.Btn1
|
|
redPot.gameObject:SetActive(isFree)
|
|
icon.gameObject:SetActive(not isFree)
|
|
num.gameObject:SetActive(not isFree)
|
|
if n==bType.Btn1 and isFree then
|
|
self.di1:SetActive(false)
|
|
end
|
|
|
|
|
|
local itemId=0
|
|
local itemNum=0
|
|
local type = 0
|
|
if n==bType.Btn1 then
|
|
type = singleRecruit.Id
|
|
else
|
|
type = tenRecruit.Id
|
|
end
|
|
local d=RecruitManager.GetExpendData(type)
|
|
if(isFree) then
|
|
info.text=Language[10493]
|
|
else
|
|
itemId=d[1]
|
|
itemNum=d[2]
|
|
-- LogPink("itemId:"..itemId.." itemNum:"..itemNum)
|
|
icon.sprite=Util.LoadSprite(artResourcesConfig[itemConfig[itemId].ResourceID].Name)
|
|
info.text=m.isInfo
|
|
num.text= tostring(itemNum)
|
|
end
|
|
|
|
Util.AddOnceClick(btn,function()
|
|
if not isFree then
|
|
if BagManager.GetItemCountById(itemId)<d[2] then
|
|
PopupTipPanel.ShowTip(GetLanguageStrById(itemConfig[itemId].Name)..Language[10486])
|
|
return
|
|
end
|
|
end
|
|
local state = PlayerPrefs.GetInt(PlayerManager.uid.."GeneralPopup_RecruitConfirm"..RecruitType.QianKunBoxTen)
|
|
if n==bType.Btn1 then
|
|
if PrivilegeManager.GetPrivilegeUsedTimes(maxtimesId)+1>privilegeConfig[maxtimesId].Condition[1][2] then
|
|
PopupTipPanel.ShowTip(Language[10485])
|
|
return
|
|
end
|
|
local recruitOne = function()
|
|
RecruitManager.RecruitRequest(singleRecruit.Id, function(msg)
|
|
PrivilegeManager.RefreshPrivilegeUsedTimes(maxtimesId,1)--记录抽卡次数
|
|
UIManager.OpenPanel(UIName.QianKunBoxBuyOnePanel, msg.drop,singleRecruit.Id,{RecruitType.QianKunBoxSingle,RecruitType.QianKunBoxTen})
|
|
CheckRedPointStatus(RedPointType.QianKunBox)
|
|
end,freeTimesId)
|
|
end
|
|
if state==0 and d[1] ==16 and not isFree then
|
|
UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.RecruitConfirm,singleRecruit.Id,recruitOne)
|
|
else
|
|
recruitOne()
|
|
end
|
|
elseif n==bType.Btn10 then
|
|
if PrivilegeManager.GetPrivilegeUsedTimes(maxtimesId)+10>privilegeConfig[maxtimesId].Condition[1][2] then
|
|
PopupTipPanel.ShowTip(Language[10485])
|
|
return
|
|
end
|
|
local recruitTen = function()
|
|
RecruitManager.RecruitRequest(tenRecruit.Id, function(msg)
|
|
PrivilegeManager.RefreshPrivilegeUsedTimes(maxtimesId,10)--记录抽卡次数
|
|
UIManager.OpenPanel(UIName.QianKunBoxBuyTenPanel, msg.drop,tenRecruit.Id,{RecruitType.QianKunBoxTen,RecruitType.QianKunBoxTen})
|
|
CheckRedPointStatus(RedPointType.QianKunBox)
|
|
end,freeTimesId)
|
|
end
|
|
if state==0 and d[1] ==16 and not isFree then
|
|
UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.RecruitConfirm,tenRecruit.Id,recruitTen)
|
|
else
|
|
recruitTen()
|
|
end
|
|
end
|
|
end)
|
|
end
|
|
end
|
|
|
|
--五个魂印头像
|
|
function QianKunBox:contentShow()
|
|
for i = 1, 5 do
|
|
local icon = Util.GetGameObject(self.icons,"icon"..i.."/icon"):GetComponent("Image")
|
|
local kuang = Util.GetGameObject(self.icons,"icon"..i.."/kuang"):GetComponent("Image")
|
|
local name = artConfig[itemConfig[iconsData[i].Reward[1]].ResourceID].Name
|
|
icon.sprite = Util.LoadSprite(name)
|
|
if itemConfig[iconsData[i].Reward[1]].Quantity == 5 then--金色
|
|
kuang.sprite = Util.LoadSprite("r_hunyin_hunyinkuanghuang001")
|
|
end
|
|
--点击能查看魂印信息
|
|
Util.AddOnceClick(kuang.gameObject,function ()
|
|
UIManager.OpenPanel(UIName.SoulPrintPopUp,nil,nil,iconsData[i].Reward[1],nil,nil)
|
|
end)
|
|
end
|
|
end
|
|
|
|
--商店
|
|
function QianKunBox:storeShow()
|
|
if not self.shopView then
|
|
self.shopView = SubUIManager.Open(SubUIConfig.ShopView, self.content.transform)
|
|
end
|
|
self.shopView:ShowShop(SHOP_TYPE.QIANKUNBOX_SHOP,orginLayer)
|
|
end
|
|
|
|
--时间
|
|
function QianKunBox:timeCountDown()
|
|
local timeDown=CalculateSecondsNowTo_N_OClock(0)--领取按钮的倒计时
|
|
self.btnTime.text = TimeToHMS(timeDown)
|
|
-- self.shopData = ShopManager.GetShopDataByType(SHOP_TYPE.QIANKUNBOX_SHOP)--获取活动信息
|
|
self.shopData =ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.QianKunBox)
|
|
self.leftUpTime.text = self:TimeToDHMS(self.shopData.endTime - PlayerManager.serverTime)--活动结束的倒计时
|
|
self.timer = Timer.New(function()
|
|
self.leftUpTime.text = self:TimeToDHMS(self.shopData.endTime - PlayerManager.serverTime)
|
|
self.btnTime.text = TimeToHMS(timeDown)
|
|
if timeDown < 1 then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
return
|
|
end
|
|
timeDown = timeDown -1
|
|
end, 1, -1, true)
|
|
self.timer:Start()
|
|
end
|
|
|
|
--- 将一段时间转换为天时分秒
|
|
function QianKunBox:TimeToDHMS(second)
|
|
local day = math.floor(second / (24 * 3600))
|
|
local minute = math.floor(second / 60) % 60
|
|
local sec = math.floor(second % 60)
|
|
local hour = math.floor(math.floor(second - day * 24 * 3600 - sec - minute * 60) / 3600)
|
|
if day <= 0 and hour <= 0 then
|
|
return string.format(Language[10472],minute, sec)
|
|
else
|
|
return string.format(Language[10473],day, hour)
|
|
end
|
|
end
|
|
|
|
function QianKunBox:refreshMagicNum()
|
|
local actData = ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.QianKunBox)
|
|
local d = ConfigManager.GetAllConfigsDataByKey(ConfigName.LotterySpecialConfig,"Type",singleRecruit.MergePool)
|
|
-- self.leftUptips1.text = d[1].Count-math.floor(actData.value/1000)
|
|
local t = d[1].Count-math.floor(actData.value/1000)
|
|
self.btnTimes.text = tostring(d[2].Count-actData.value%1000)..Language[12185]
|
|
self.midDowntips1.text = Language[10495]..t..Language[10496]
|
|
end
|
|
|
|
function QianKunBox:OnSortingOrderChange(_sortingOrder)
|
|
orginLayer = _sortingOrder
|
|
end
|
|
|
|
function QianKunBox:OnHide()
|
|
self.gameObject:SetActive(false)
|
|
self.detail.gameObject:SetActive(false)
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
if self.shopView then
|
|
self.shopView = SubUIManager.Close(self.shopView)
|
|
self.shopView = nil
|
|
end
|
|
end
|
|
|
|
--添加事件监听(用于子类重写)
|
|
function QianKunBox:AddListener()
|
|
|
|
end
|
|
|
|
--移除事件监听(用于子类重写)
|
|
function QianKunBox:RemoveListener()
|
|
|
|
end
|
|
|
|
return QianKunBox |