miduo_client/Assets/ManagedResources/~Lua/Modules/Pokemon/PokemonSummonPanel.lua

328 lines
13 KiB
Lua
Raw Normal View History

2020-09-29 15:13:06 +08:00
require("Base/BasePanel")
local PokemonSummonPanel = Inherit(BasePanel)
2020-10-15 19:27:41 +08:00
local MazeTreasureSetting = ConfigManager.GetConfig(ConfigName.MazeTreasureSetting)
2020-09-29 15:13:06 +08:00
local bType={
Btn1=1,
Btn10=2
}
--type与lotterySetting表中的id对应
local btns={ [bType.Btn1]={name="Btn1",isInfo=Language[10644]}, [bType.Btn10]={name="Btn10",isInfo=Language[12182]}}
2020-11-05 03:03:08 +08:00
2020-09-29 15:13:06 +08:00
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
local lotterySetting=ConfigManager.GetConfig(ConfigName.LotterySetting)
local privilegeConfig=ConfigManager.GetConfig(ConfigName.PrivilegeTypeConfig)
local artResourcesConfig =ConfigManager.GetConfig(ConfigName.ArtResourcesConfig)
2020-11-05 03:03:08 +08:00
2020-10-15 19:27:41 +08:00
local freeTime= 0 --免费抽取次数
local isActive=false --是否激活特权
2020-10-17 13:11:34 +08:00
local leftTime=0 --特权剩余时间
2020-10-29 15:08:22 +08:00
local YaojingCallPrivilegeId = 2006
2020-09-29 15:13:06 +08:00
function PokemonSummonPanel:InitComponent(gameObject)
self.btn_back=Util.GetGameObject(self.transform, "btn_back")
self.buffImg=Util.GetGameObject(self.transform, "tokenImg"):GetComponent("Image")
self.infoTxt=Util.GetGameObject(self.transform,"hint"):GetComponent("Text")
2020-11-05 03:03:08 +08:00
self.leftTimeObj=Util.GetGameObject(self.transform, "leftTimeObj")
self.leftTimeTxt=Util.GetGameObject(self.transform,"leftTimeObj/leftTimeTxt"):GetComponent("Text")
2020-09-29 15:13:06 +08:00
self.btn_shop=Util.GetGameObject(self.transform,"btn_shop")
self.btn_reward=Util.GetGameObject(self.transform,"btn_rewardPool")
2020-11-05 03:03:08 +08:00
2020-09-29 15:13:06 +08:00
self.btn_one=Util.GetGameObject(self.transform,"Btn1")
2020-11-05 03:03:08 +08:00
self.oneHintTxt=Util.GetGameObject(self.btn_one,"Tip"):GetComponent("Text")
2020-09-29 15:13:06 +08:00
self.btn_ten=Util.GetGameObject(self.transform,"Btn10")
2020-11-05 03:03:08 +08:00
self.tenHintTxt=Util.GetGameObject(self.btn_ten,"Tip"):GetComponent("Text")
self.btn_activate=Util.GetGameObject(self.transform,"btn_activate")
Util.GetGameObject(self.btn_activate,"Text"):GetComponent("Text").text=Language[12411]
self.limitTxt=Util.GetGameObject(self.transform,"limit"):GetComponent("Text")
self.upView = SubUIManager.Open(SubUIConfig.UpView, self.gameObject.transform, { showType = UpViewOpenType.ShowLeft})
2020-11-02 06:30:41 +08:00
self.changZhuEffect = Util.GetGameObject(self.transform,"effect/Effect_Dan_changzhu")
self.Effect_Dan_posui = Util.GetGameObject(self.transform,"effect/Effect_Dan_posui")
self.mask = Util.GetGameObject(self.transform,"mask")
2020-09-29 15:13:06 +08:00
end
function PokemonSummonPanel:BindEvent()
--奖励按钮
Util.AddClick(self.btn_reward,function()
2020-10-15 19:27:41 +08:00
UIManager.OpenPanel(UIName.RewardPreviewPopup, PRE_REWARD_POOL_TYPE.LING_SHOU)
2020-09-29 15:13:06 +08:00
end)
--激活按钮
2020-10-15 19:27:41 +08:00
Util.AddClick(self.btn_shop,function()
JumpManager.GoJump(3002)
--self.shop:SetActive(true)
--self.btnBack:SetActive(false)
--self.livename = "live2d_ui_h_52_xx_pf1"
--self.liveNode = poolManager:LoadLive(self.livename, self.live.transform, Vector3.New(0.25,0.25,0.25), Vector3.New(123,214,0))
--self:storeShow()--商店
2020-09-29 15:13:06 +08:00
end)
2020-10-15 19:27:41 +08:00
2020-09-29 15:13:06 +08:00
Util.AddClick(self.btn_back,function()
2020-11-05 03:03:08 +08:00
self:ClosePanel()
2020-09-29 15:13:06 +08:00
end)
2020-10-15 19:27:41 +08:00
Util.AddClick(self.btn_activate,function()
--激活特权
JumpManager.GoJump(MazeTreasureSetting[1].Jump)
end)
2020-09-29 15:13:06 +08:00
end
2020-11-05 03:03:08 +08:00
function PokemonSummonPanel:OnShow()
2020-11-02 06:30:41 +08:00
self.changZhuEffect.gameObject:SetActive(true)
self.mask.gameObject:SetActive(false)
self.Effect_Dan_posui.gameObject:SetActive(false)
CheckRedPointStatus(RedPointType.Pokemon_Recruit)
2020-10-15 19:27:41 +08:00
self.upView:OnOpen({showType = UpViewOpenType.ShowLeft, panelType = PanelType.LingShou})
2020-11-05 03:03:08 +08:00
2020-09-29 15:13:06 +08:00
self.infoTxt.text=Language[12415]
--是否显示特权
2020-10-15 19:27:41 +08:00
isActive = PrivilegeManager.GetPrivilegeOpenStatusById(3004)
if isActive then
2020-09-29 15:13:06 +08:00
self.leftTimeObj.gameObject:SetActive(true)
2020-10-15 19:27:41 +08:00
Util.SetGray(self.buffImg.gameObject,false)
2020-10-17 13:11:34 +08:00
leftTime = PrivilegeManager.GetPrivilegeLeftTimeById(3004)
2020-10-15 19:27:41 +08:00
self.leftTimeTxt.text= "剩余:"..GetLeftTimeStrByDeltaTime(leftTime)
2020-09-29 15:13:06 +08:00
self.btn_activate.gameObject:SetActive(false)
else
2020-10-15 19:27:41 +08:00
Util.SetGray(self.buffImg.gameObject,true)
2020-09-29 15:13:06 +08:00
self.leftTimeObj.gameObject:SetActive(false)
self.btn_activate.gameObject:SetActive(true)
2020-10-15 19:27:41 +08:00
end
2020-09-29 15:13:06 +08:00
self:refreshBtnShow()--刷新按钮显示
2020-10-15 19:27:41 +08:00
self:timeCountDown()--时间
2020-09-29 15:13:06 +08:00
end
function PokemonSummonPanel:refreshBtnShow()
2020-11-05 03:03:08 +08:00
local currLottery = ConfigManager.GetConfigData(ConfigName.LotterySetting,RecruitType.LingShowSingle)
local freeTimesId = currLottery.FreeTimes
local maxtimesId = currLottery.MaxTimes --lotterySetting表中的MaxTimes对应privilegeConfig表中的id
local curTimes = PrivilegeManager.GetPrivilegeUsedTimes(maxtimesId)
2020-10-29 15:08:22 +08:00
self.tenHintTxt.text=string.format("妖晶召唤次数:%s/%s",PrivilegeManager.GetPrivilegeRemainValue(YaojingCallPrivilegeId), PrivilegeManager.GetPrivilegeNumber(YaojingCallPrivilegeId))
self.limitTxt.text = Language[12225]..curTimes.."/"..PrivilegeManager.GetPrivilegeNumber(maxtimesId)
2020-11-05 03:03:08 +08:00
if freeTimesId > 0 then
freeTime = PrivilegeManager.GetPrivilegeRemainValue(freeTimesId)
RecruitManager.freeUseTimeList[freeTimesId] = freeTime
2020-09-29 15:13:06 +08:00
end
--按钮赋值
for n, m in ipairs(btns) do
2020-11-05 03:03:08 +08:00
local btn = Util.GetGameObject(self.gameObject,m.name)
local redPot = Util.GetGameObject(btn.gameObject,"RedPoint")
local info = Util.GetGameObject(btn.gameObject,"Content/Info"):GetComponent("Text")
local icon = Util.GetGameObject(btn.gameObject,"Content/Icon"):GetComponent("Image")
local num = Util.GetGameObject(btn.gameObject,"Content/Num"):GetComponent("Text")
local tip = Util.GetGameObject(btn.gameObject,"Tip"):GetComponent("Text")
2020-09-29 15:13:06 +08:00
--存在免费次数 并且 免费>=1 并且是1按钮
2020-11-05 03:03:08 +08:00
local isFree = freeTime and freeTime >= 1 and n == bType.Btn1
2020-09-29 15:13:06 +08:00
redPot.gameObject:SetActive(isFree)
icon.gameObject:SetActive(not isFree)
2020-10-15 19:27:41 +08:00
num.gameObject:SetActive(not isFree)
2020-11-05 03:03:08 +08:00
2020-09-29 15:13:06 +08:00
local itemId=0
local itemNum=0
local type = 0
2020-11-05 03:03:08 +08:00
if n == bType.Btn1 then
type = currLottery.Id
2020-09-29 15:13:06 +08:00
else
2020-11-05 03:03:08 +08:00
type = ConfigManager.GetConfigData(ConfigName.LotterySetting,RecruitType.LingShowTen).Id
2020-09-29 15:13:06 +08:00
end
2020-11-05 03:03:08 +08:00
local d = RecruitManager.GetExpendData(type)
2020-10-15 19:27:41 +08:00
if isFree then
2020-09-29 15:13:06 +08:00
info.text=Language[11759]
else
2020-11-05 03:03:08 +08:00
itemId = d[1]
itemNum = d[2]
2020-10-15 19:27:41 +08:00
--如果当前是用妖晶抽卡 and 激活了特权
2020-11-05 03:03:08 +08:00
if itemId == 16 and isActive then
local currPrivilege = privilegeConfig[3004]
if currPrivilege then
itemNum = itemNum * (1 + currPrivilege.Condition[1][2]/10000)
end
2020-10-15 19:27:41 +08:00
end
2020-11-05 03:03:08 +08:00
icon.sprite = Util.LoadSprite(artResourcesConfig[itemConfig[itemId].ResourceID].Name)
info.text = m.isInfo
2020-10-28 09:17:20 +08:00
num.text = "x"..itemNum
2020-09-29 15:13:06 +08:00
end
Util.AddOnceClick(btn,function()
2020-11-05 03:03:08 +08:00
local state = PlayerPrefs.GetInt(PlayerManager.uid.."GeneralPopup_RecruitConfirm"..RecruitType.LingShowTen)
if n == bType.Btn1 then
if isFree then
self:Recruit(RecruitType.LingShowSingle,maxtimesId,0,0,state,freeTimesId)
2020-09-29 15:13:06 +08:00
else
2020-11-05 03:03:08 +08:00
self:Recruit(RecruitType.LingShowSingle,maxtimesId,itemId,itemNum,state,freeTimesId)
2020-09-29 15:13:06 +08:00
end
elseif n==bType.Btn10 then
2020-11-05 03:03:08 +08:00
self:Recruit(RecruitType.LingShowTen,maxtimesId,itemId,itemNum,state,freeTimesId)
2020-09-29 15:13:06 +08:00
end
end)
end
end
2020-11-05 03:03:08 +08:00
function PokemonSummonPanel:Recruit(id,RecruitMaxtimesId,itemId,itemNum,state,freeTimesId)
local num = 0
if id == RecruitType.LingShowSingle then
num = 1
else
num = 10
end
2020-10-23 19:30:32 +08:00
2020-11-05 03:03:08 +08:00
--是否超过每日最大上限
2020-10-29 15:08:22 +08:00
if PrivilegeManager.GetPrivilegeRemainValue(RecruitMaxtimesId) < num then
2020-11-05 03:03:08 +08:00
PopupTipPanel.ShowTip(Language[11760])
return
end
--是否妖晶,是否超过每日妖晶最大上限
if itemId == 16 then
2020-10-29 15:08:22 +08:00
if PrivilegeManager.GetPrivilegeRemainValue(YaojingCallPrivilegeId) < num then
2020-11-05 03:03:08 +08:00
PopupTipPanel.ShowTip("今日妖晶召唤次数不足!")
return
end
end
if itemId ~= 0 then
if BagManager.GetItemCountById(itemId) < itemNum then
PopupTipPanel.ShowTip(itemConfig[itemId].Name..Language[10492])
return
end
end
if itemId == 16 and state == 0 then
UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.RecruitConfirm,id,
function()
RecruitManager.RecruitRequest(id,
function(msg)
2020-11-02 06:30:41 +08:00
self.changZhuEffect:SetActive(false)
self.Effect_Dan_posui:SetActive(true)
self.mask.gameObject:SetActive(true)
Timer.New(function()
self.mask.gameObject:SetActive(false)
self.Effect_Dan_posui:SetActive(false)
self.changZhuEffect:SetActive(true)
PrivilegeManager.RefreshPrivilegeUsedTimes(RecruitMaxtimesId,num)--记录抽卡次数
PrivilegeManager.RefreshPrivilegeUsedTimes(YaojingCallPrivilegeId,num)--记录妖晶抽卡次数
UIManager.OpenPanel(UIName.PokemonSingleResultPanel,id,msg.drop)
--CheckRedPointStatus(RedPointType.QianKunBox)
end,1.2):Start()
2020-11-05 03:03:08 +08:00
end,
freeTimesId,itemId,itemNum)
end,
itemNum)
else
RecruitManager.RecruitRequest(id, function(msg)
2020-11-02 06:30:41 +08:00
self.changZhuEffect:SetActive(false)
self.Effect_Dan_posui:SetActive(true)
self.mask.gameObject:SetActive(true)
Timer.New(function()
self.mask.gameObject:SetActive(false)
self.Effect_Dan_posui:SetActive(false)
self.changZhuEffect:SetActive(true)
PrivilegeManager.RefreshPrivilegeUsedTimes(RecruitMaxtimesId,num)--记录抽卡次数
if itemId == 16 then
PrivilegeManager.RefreshPrivilegeUsedTimes(YaojingCallPrivilegeId,num)--记录妖晶抽卡次数
end
UIManager.OpenPanel(UIName.PokemonSingleResultPanel,id,msg.drop)
end,1.2):Start()
2020-11-05 03:03:08 +08:00
--CheckRedPointStatus(RedPointType.QianKunBox)
end,freeTimesId,itemId,itemNum)
end
end
2020-09-29 15:13:06 +08:00
--商店
function PokemonSummonPanel:storeShow()
if not self.shopView then
self.shopView = SubUIManager.Open(SubUIConfig.ShopView, self.content.transform)
end
2020-11-05 03:03:08 +08:00
self.shopView:ShowShop(SHOP_TYPE.QIANKUNBOX_SHOP)
2020-09-29 15:13:06 +08:00
end
--时间
function PokemonSummonPanel:timeCountDown()
2020-10-29 15:54:25 +08:00
if self.timer then
self.timer:Stop()
self.timer = nil
end
if self.timer2 then
self.timer2:Stop()
self.timer2 = nil
end
2020-10-15 19:27:41 +08:00
if freeTime>0 then
self.oneHintTxt.text=string.format(Language[12400],freeTime)
else
2020-10-29 15:54:25 +08:00
local timeDown = CalculateSecondsNowTo_N_OClock(5)--领取按钮的倒计时
self.oneHintTxt.text =string.format(Language[12412],TimeToHMS(timeDown))
--免费次数刷新倒计时
self.timer = Timer.New(function()
if timeDown < 1 then
self.timer:Stop()
self.timer = nil
2020-10-22 15:15:09 +08:00
return
end
2020-10-29 15:54:25 +08:00
timeDown = timeDown -1
self.oneHintTxt.text = string.format(Language[12412],TimeToHMS(timeDown))
2020-10-22 15:15:09 +08:00
end, 1, -1, true)
2020-10-29 15:54:25 +08:00
self.timer:Start()
2020-10-22 15:15:09 +08:00
end
2020-10-29 15:54:25 +08:00
--特权剩余时间倒计时
if leftTime>0 then
self.timer2 = Timer.New(function()
if leftTime < 1 then
self.timer2:Stop()
self.timer2 = nil
return
end
leftTime = leftTime -1
self.leftTimeTxt.text= "剩余:"..GetLeftTimeStrByDeltaTime(leftTime)
end, 1, -1, true)
self.timer2:Start()
end
2020-09-29 15:13:06 +08:00
end
--- 将一段时间转换为天时分秒
function PokemonSummonPanel:TimeToDHMS(second)
local day = math.floor(second / (24 * 3600))
local minute = math.floor(second / 60) % 60
local sec = 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[12231],minute, sec)
else
return string.format(Language[12232],day, hour)
end
end
2020-11-02 06:30:41 +08:00
local orginLayer = 0
function PokemonSummonPanel:OnSortingOrderChange()
Util.AddParticleSortLayer(self.changZhuEffect, self.sortingOrder - orginLayer)
Util.AddParticleSortLayer(self.Effect_Dan_posui, self.sortingOrder - orginLayer)
orginLayer = self.sortingOrder
2020-09-29 15:13:06 +08:00
end
2020-10-28 17:07:06 +08:00
function PokemonSummonPanel:OnClose()
2020-09-29 15:13:06 +08:00
self.gameObject:SetActive(false)
if self.timer then
self.timer:Stop()
self.timer = nil
end
2020-10-29 15:54:25 +08:00
if self.timer2 then
self.timer2:Stop()
self.timer2 = nil
end
2020-09-29 15:13:06 +08:00
if self.shopView then
self.shopView = SubUIManager.Close(self.shopView)
self.shopView = nil
end
end
2020-10-15 19:27:41 +08:00
--界面销毁时调用(用于子类重写)
function PokemonSummonPanel:OnDestroy()
2020-11-02 10:58:48 +08:00
orginLayer = 0
2020-10-15 19:27:41 +08:00
SubUIManager.Close(self.upView)
2020-10-28 17:07:06 +08:00
if self.timer then
self.timer:Stop()
self.timer = nil
end
if self.timer2 then
self.timer2:Stop()
self.timer2 = nil
end
2020-10-15 19:27:41 +08:00
end
2020-09-29 15:13:06 +08:00
return PokemonSummonPanel