miduo_client/Assets/ManagedResources/~Lua/Modules/Operating/QianKunBox.lua

238 lines
9.7 KiB
Lua

local QianKunBox = quick_class("QianKunBox")
local ActivityDetail = require("Modules/Operating/ActivityDetail")--活动详情
local iconsData = ConfigManager.GetAllConfigsDataByKey(ConfigName.LotteryRewardConfig,"Pool",4401)
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 orginLayer = 0
local bType={
Btn1=1,
Btn10=2
}
--type与lotterySetting表中的id对应
local btns={ [bType.Btn1]={name="bottom/btnOne",isInfo=Language[10644],type=RecruitType.QianKunBoxSingle}, [bType.Btn10]={name="bottom/btnTen",isInfo=Language[12182],type=RecruitType.QianKunBoxTen}}
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/tabList")
self.btnBack = Util.GetGameObject(self.mainPanel,"bg/btnBack")
self.bottomBar = Util.GetGameObject(self.mainPanel,"bg/bottomBar")
--leftUp
self.leftUp = Util.GetGameObject(gameObject,"leftUp")
self.leftUptips1 = Util.GetGameObject(self.leftUp,"tips/tips1"):GetComponent("Text")
self.leftUpTime = Util.GetGameObject(self.leftUp,"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.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")
self.limit = Util.GetGameObject(self.bottom,"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.live = Util.GetGameObject(self.shop,"live")
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()
ActivityDetail.new(self.detail,2)
end)
Util.AddClick(self.btnStore,function()
self.shop:SetActive(true)
self.btnBack:SetActive(false)
self.tabList:SetActive(false)
self.bottomBar:SetActive(false)
end)
Util.AddClick(self.shopBack,function()
self.shop:SetActive(false)
self.btnBack:SetActive(true)
self.tabList:SetActive(true)
self.bottomBar:SetActive(true)
end)
end
function QianKunBox:OnShow()
self.gameObject:SetActive(true)
self:refreshMagicNum()
self:refreshBtnShow()--刷新按钮显示
self:contentShow()--五个魂印头像
self:storeShow()--商店
self:timeCountDown()--时间
end
function QianKunBox:refreshBtnShow()
-- self.btnTen2:SetActive(BagManager.GetItemCountById(16)>=2000)
-- self.btnTen1:SetActive(BagManager.GetItemCountById(16)<2000)
local freeTimesId=lotterySetting[RecruitType.QianKunBoxSingle].FreeTimes
local maxtimesId=lotterySetting[RecruitType.QianKunBoxSingle].MaxTimes --lotterySetting表中的MaxTimes对应privilegeConfig表中的id
local curTimes=PrivilegeManager.GetPrivilegeUsedTimes(maxtimesId)
local freeTime= 0
self.limit.text = "今日召唤上限:"..curTimes.."/"..privilegeConfig[maxtimesId].Condition[1][2]
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)
self.btnTime.gameObject:SetActive(not isFree)
local itemId=0
local itemNum=0
local d
if(isFree) then
info.text=Language[11759]
else
d=RecruitManager.GetExpendData(m.type)
itemId=d[1]
itemNum=d[2]
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(itemConfig[itemId].Name..Language[10492])
return
end
end
if n==bType.Btn1 then
if PrivilegeManager.GetPrivilegeUsedTimes(maxtimesId)+1>privilegeConfig[maxtimesId].Condition[1][2] then
PopupTipPanel.ShowTip(Language[11760])
return
end
RecruitManager.RecruitRequest(m.type, function(msg)
PrivilegeManager.RefreshPrivilegeUsedTimes(maxtimesId,1)--记录抽卡次数
UIManager.OpenPanel(UIName.QianKunBoxBuyOnePanel,msg.drop)
CheckRedPointStatus(RedPointType.QianKunBox)
end,freeTimesId)
elseif n==bType.Btn10 then
if PrivilegeManager.GetPrivilegeUsedTimes(maxtimesId)+10>privilegeConfig[maxtimesId].Condition[1][2] then
PopupTipPanel.ShowTip(Language[11760])
return
end
RecruitManager.RecruitRequest(m.type, function(msg)
PrivilegeManager.RefreshPrivilegeUsedTimes(maxtimesId,10)--记录抽卡次数
UIManager.OpenPanel(UIName.QianKunBoxBuyTenPanel,msg.drop)
CheckRedPointStatus(RedPointType.QianKunBox)
end,freeTimesId)
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)
self.live = poolManager:LoadLive("live2d_ui_h_52_xx_pf1", self.live.transform, Vector3.New(0.25,0.25,0.25), Vector3.New(123,214,0))
end
--时间
function QianKunBox:timeCountDown()
local timeDown=CalculateSecondsNowTo_N_OClock(5)--领取按钮的倒计时
self.btnTime.text = TimeToHMS(timeDown)
self.shopData = ShopManager.GetShopDataByType(SHOP_TYPE.QIANKUNBOX_SHOP)--获取活动信息
self.leftUpTime.text = TimeToDHMS(self.shopData.endTime - GetTimeStamp())--活动结束的倒计时
self.timer = Timer.New(function()
self.leftUpTime.text = TimeToDHMS(self.shopData.endTime - GetTimeStamp())
self.btnTime.text = TimeToHMS(timeDown)
timeDown = timeDown -1
end, 1, -1, true)
self.timer:Start()
end
function QianKunBox:refreshMagicNum()
local actData = ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.QianKunBox)
LogYellow("ID:"..actData.activityId.." value"..actData.value)
self.leftUptips1.text = 100-math.floor(actData.value/1000).."次内必得红色魂印"
self.btnTimes.text = 30-actData.value%1000
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
end
function QianKunBox:OnDestroy()
if self.shopView then
self.shopView = SubUIManager.Close(self.shopView)
self.shopView = nil
end
poolManager:UnLoadLive("live2d_ui_h_52_xx_pf1", self.live)
end
return QianKunBox