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

297 lines
13 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

local TimeLimitedCall= quick_class("TimeLimitedCall")
local ActivityDetail = require("Modules/Operating/ActivityDetail")--活动详情
local RewardPreview = require("Modules/Operating/RewardPreview")--奖励预览
local sortingOrder = 0
local lotterySetting=ConfigManager.GetConfig(ConfigName.LotterySetting)
local privilegeConfig=ConfigManager.GetConfig(ConfigName.PrivilegeTypeConfig)
local artResourcesConfig =ConfigManager.GetConfig(ConfigName.ArtResourcesConfig)
local itemConfig=ConfigManager.GetConfig(ConfigName.ItemConfig)
local heroConfig=ConfigManager.GetConfig(ConfigName.HeroConfig)
--按钮类型
local bType={
Btn1=1,
Btn10=2
}
--type与lotterySetting表中的id对应
local btns={ [bType.Btn1]={name="btngroup/once",isInfo=Language[10644],type=RecruitType.TimeLimitSingle}, [bType.Btn10]={name="btngroup/ten",isInfo=Language[12182],type=RecruitType.TimeLimitTen}}
local tabs={"btngroup/activity","btngroup/reward"}
local secectTab=-1
local hero={[1]={name="Bg/hero1",id=10001,hero="x_xianshizaohuan_fx"},[2]={name="Bg/hero3",id=10041,hero="x_xianshizaohuan_ttjz"},[3]={name="Bg/hero2",id=10089,hero="x_xianshizaohuan_rd"}}
local curTimes=0
local curLv=0 --当前阶段id
local curLvstate=0 --当前阶段的状态 0可领奖1已领奖 2不可领奖
function TimeLimitedCall:ctor(mainPanel, gameObject)
self.mainPanel = mainPanel
self.gameObject = gameObject
self:InitComponent(gameObject)
self:BindEvent()
end
function TimeLimitedCall:InitComponent(gameObject)
self.helpBtn = Util.GetGameObject(self.gameObject,"btngroup/help")
self.helpPosition=self.helpBtn:GetComponent("RectTransform").localPosition
self.activityBtn = Util.GetGameObject(self.gameObject,"btngroup/activity")
self.rewardBtn = Util.GetGameObject(self.gameObject,"btngroup/reward")
self.timeupdate=Util.GetGameObject(self.gameObject,"timeupdate"):GetComponent("Text") --剩余时间
self.upper=Util.GetGameObject(self.gameObject,"maxtimes"):GetComponent("Text") ---召唤上限
self.slider = Util.GetGameObject(self.gameObject, "nextlevel/Slider"):GetComponent("Slider")
self.sliderText=Util.GetGameObject(self.gameObject,"nextlevel/Text"):GetComponent("Text")
self.curtext = Util.GetGameObject(self.gameObject, "curvalue/Text"):GetComponent("Text")
self.frame = Util.GetGameObject(self.gameObject, "curvalue/frame"):GetComponent("Image")
self.nextReward = Util.GetGameObject(self.gameObject, "nextlevel/reward")
self.icon = Util.GetGameObject(self.frame.gameObject, "icon"):GetComponent("Image")
self.detail= Util.GetGameObject(self.gameObject, "detail")
self.reward= Util.GetGameObject(self.gameObject, "reward")
self.getBtn=Util.GetGameObject(self.gameObject,"nextlevel")
self.effect=Util.GetGameObject(self.gameObject,"juneng_chenggong")
self.hero1 = Util.GetGameObject(self.gameObject,"Bg/hero1")
self.hero2 = Util.GetGameObject(self.gameObject,"Bg/hero2")
self.hero3 = Util.GetGameObject(self.gameObject,"Bg/hero3")
end
function TimeLimitedCall:BindEvent()
Util.AddClick(self.helpBtn, function()
UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.TimeLimitedCall,self.helpPosition.x,self.helpPosition.y)
--UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.TimeLimitedCall,self.helpPosition.x,self.helpPosition.y)
end)
Util.AddClick(self.activityBtn, function()
secectTab=1
self:RefreshTabBtn()
ActivityDetail.new(self.detail)
end)
Util.AddClick(self.rewardBtn, function()
secectTab=2
self:RefreshTabBtn()
local fb = ConfigManager.GetConfigData(ConfigName.FakeBattle, 1001)
local testFightData = {
fightData = loadstring("return "..fb.FightData)(),
fightSeed = fb.TimeSeed,
fightType = 0,
maxRound = 20
}
UIManager.OpenPanel(UIName.BattlePanel, testFightData, BATTLE_TYPE.Test)
end)
Util.AddClick(self.hero1, function()
UIManager.OpenPanel(UIName.RoleGetInfoPopup, false, 10001, 5)
end)
Util.AddClick(self.hero2, function()
UIManager.OpenPanel(UIName.RoleGetInfoPopup, false, 10089, 5)
end)
Util.AddClick(self.hero3, function()
UIManager.OpenPanel(UIName.RoleGetInfoPopup, false, 10041, 5)
end)
end
function TimeLimitedCall:OnShow(_sortingOrder)
sortingOrder = _sortingOrder
self.gameObject:SetActive(true)
local UpHero=RecruitManager.GetRewardPreviewData(PRE_REWARD_POOL_TYPE.TIME_LIMITED_UP)
table.sort(UpHero,function(a,b) return a.Reward[1]<b.Reward[1] end)
for n,m in ipairs(hero) do
Util.GetGameObject(self.gameObject,m.name.."/hero"):GetComponent("Image").sprite=Util.LoadSprite(m.hero)
local configinfo= ConfigManager.GetConfigDataByKey(ConfigName.HeroConfig, "Id", UpHero[n].Reward[1])
Util.GetGameObject(self.gameObject,m.name.."/icon"):GetComponent("Image").sprite=Util.LoadSprite(GetJobSpriteStrByJobNum(configinfo.PropertyName))
Util.GetGameObject(self.gameObject,m.name.."/name"):GetComponent("Text").text=configinfo.ReadingName
--SetHeroStars(Util.GetGameObject(self.gameObject,m.name.."/starlayout"),5)
end
secectTab=-1
self:RefreshTabBtn()
self:RefreshGetHeroTimes()
self:TimeCountDown()
self:RefreshNextLevelReward()
end
function TimeLimitedCall:RefreshTabBtn()
for n, m in pairs(tabs) do
if n~=secectTab then
Util.GetGameObject(self.gameObject,tabs[n].."/select").gameObject:SetActive(false)
else
Util.GetGameObject(self.gameObject,tabs[n].."/select").gameObject:SetActive(true)
end
end
end
function TimeLimitedCall:RefreshNextLevelReward()
local curActivityId=0
curActivityId=ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.FindFairy)
local data1= ConfigManager.GetAllConfigsDataByKey(ConfigName.ActivityRewardConfig,"ActivityId",curActivityId) --通过活动id获取阶段任务
local rewarditem
for n,m in ipairs(data1) do
if(curTimes>=m.Values[1][1]) then
curLvstate= self:GetMissionStateById(m.Id,curActivityId)
if curLvstate==0 then
curLvstate=0
curLv=m.Id
rewarditem=m
break
end
else
curLvstate=2
curLv=m.Id
rewarditem=m
break
end
end
local o= SubUIManager.Open(SubUIConfig.ItemView,self.nextReward.transform)
o:OnOpen(false, {rewarditem.Reward[1][1],rewarditem.Reward[1][2]}, 0.73, false)
o.gameObject:SetActive(true)
Util.GetGameObject(o.gameObject,"item/frame"):GetComponent("Button").enabled=false
if (curLvstate==0) then
self.slider.gameObject:SetActive(false)
local vec=self.sliderText.transform:GetComponent("RectTransform").anchoredPosition3D
vec.y=22.4
self.sliderText.transform:GetComponent("RectTransform").anchoredPosition3D=vec
self.sliderText.text=Language[12183]
self.sliderText.fontSize=26
Util.AddOnceClick(self.getBtn,function()
NetManager.GetActivityRewardRequest(curLv, curActivityId,
function(respond)
UIManager.OpenPanel(UIName.RewardItemPopup, respond, 1)
self:RefreshNextLevelReward()
self:RefreshGetHeroTimes()
end)
end)
self.effect.gameObject:SetActive(true)
else
self.slider.gameObject:SetActive(true)
Util.GetGameObject(self.slider.gameObject,"Text"):GetComponent("Text").text=curTimes.."/"..rewarditem.Values[1][1]
local vec=self.sliderText.transform:GetComponent("RectTransform").anchoredPosition3D
vec.y=22.4
self.sliderText.transform:GetComponent("RectTransform").anchoredPosition3D=vec
self.sliderText.text=Language[12184]..curTimes.."/"..rewarditem.Values[1][1]
self.sliderText.fontSize=26
self.slider.value=curTimes/rewarditem.Values[1][1]
self.effect.gameObject:SetActive(false)
Util.AddOnceClick(self.getBtn,function()
RewardPreview.new(self.reward)
end)
end
end
function TimeLimitedCall:GetMissionStateById(num,activityId)
local mission= ActivityGiftManager.GetActivityInfo(activityId,num) --从后端获取到的阶段数据
return mission.state
end
--刷新剩余次数
function TimeLimitedCall:RefreshGetHeroTimes()
local freeTimesId=lotterySetting[RecruitType.TimeLimitSingle].FreeTimes
local maxtimesId=lotterySetting[RecruitType.TimeLimitSingle].MaxTimes --lotterySetting表中的MaxTimes对应privilegeConfig表中的id
curTimes=PrivilegeManager.GetPrivilegeUsedTimes(maxtimesId)
self.curtext.text=curTimes
self.upper.text= Language[12185]..curTimes.."/"..privilegeConfig[maxtimesId].Condition[1][2]--特权上限
local freeTime= 0
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/Text"):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.timeupdate.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.SingleRecruitPanel, msg.drop.Hero[1],m.type,bType.Btn1)
CheckRedPointStatus(RedPointType.TimeLimited)
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.SingleRecruitPanel, msg.drop.Hero, m.type,bType.Btn10)
CheckRedPointStatus(RedPointType.TimeLimited)
end,freeTimesId)
end
end)
end
end
--刷新时间
function TimeLimitedCall:TimeCountDown()
if self.timer then
self.timer:Stop()
self.timer = nil
end
local timeDown=CalculateSecondsNowTo_N_OClock(5)--ActivityGiftManager.GetTaskRemainTime(ActivityTypeDef.FindFairy)
self.timeupdate.text = TimeToHMS(timeDown).."后刷新"
self.timer = Timer.New(function()
if timeDown < 1 then
self.timer:Stop()
self.timer = nil
return
end
timeDown = timeDown - 1
self.timeupdate.text = TimeToHMS(timeDown).."后刷新"
end, 1, -1, true)
self.timer:Start()
end
function TimeLimitedCall:OnHide()
self.gameObject:SetActive(false)
if self.timer then
self.timer:Stop()
self.timer = nil
end
end
function TimeLimitedCall:OnDestroy()
ActivityDetail.OnDestroy()
RewardPreview.OnDestroy()
end
return TimeLimitedCall