353 lines
14 KiB
Lua
353 lines
14 KiB
Lua
require("Base/BasePanel")
|
|
local PokemonSummonPanel = Inherit(BasePanel)
|
|
local MazeTreasureSetting = ConfigManager.GetConfig(ConfigName.MazeTreasureSetting)
|
|
local bType = {
|
|
Btn1 = 1,
|
|
Btn10 = 2
|
|
}
|
|
--type与lotterySetting表中的id对应
|
|
local btns = { [bType.Btn1] = { name = "once", isInfo = Language[10577] }, [bType.Btn10] = { name = "ten", isInfo = Language[10578] } }
|
|
|
|
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
|
|
local lotterySetting = ConfigManager.GetConfig(ConfigName.LotterySetting)
|
|
local privilegeConfig = ConfigManager.GetConfig(ConfigName.PrivilegeTypeConfig)
|
|
local artResourcesConfig = ConfigManager.GetConfig(ConfigName.ArtResourcesConfig)
|
|
|
|
local freeTime = 0 --免费抽取次数
|
|
local isActive = false --是否激活特权
|
|
local leftTime = 0 --特权剩余时间
|
|
|
|
local YaojingCallPrivilegeId = 2006
|
|
|
|
function PokemonSummonPanel:InitComponent(gameObject)
|
|
self.spLoader = SpriteLoader.New()
|
|
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")
|
|
self.leftTimeObj = Util.GetGameObject(self.transform, "leftTimeObj")
|
|
self.leftTimeTxt = Util.GetGameObject(self.transform, "leftTimeObj/leftTimeTxt"):GetComponent("Text")
|
|
|
|
self.btn_shop = Util.GetGameObject(self.transform, "btn_shop")
|
|
self.btn_reward = Util.GetGameObject(self.transform, "btn_rewardPool")
|
|
|
|
self.btn_one = Util.GetGameObject(self.transform, "btngroup/once")
|
|
self.oneHintTxt = Util.GetGameObject(self.btn_one, "Tip"):GetComponent("Text")
|
|
self.btn_ten = Util.GetGameObject(self.transform, "btngroup/ten")
|
|
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[10724]
|
|
|
|
self.limitTxt = Util.GetGameObject(self.transform, "limit"):GetComponent("Text")
|
|
self.upView = SubUIManager.Open(SubUIConfig.UpView, self.gameObject.transform, { showType = UpViewOpenType.ShowLeft })
|
|
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")
|
|
self.btnEffect = Util.GetGameObject(self.btn_activate, "UI_Effect_MianBan_GuaJi_Ani")
|
|
end
|
|
|
|
function PokemonSummonPanel:BindEvent()
|
|
--奖励按钮
|
|
Util.AddClick(self.btn_reward, function()
|
|
UIManager.OpenPanel(UIName.RewardPreviewPopup, PRE_REWARD_POOL_TYPE.LING_SHOU)
|
|
end)
|
|
--激活按钮
|
|
|
|
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()--商店
|
|
end)
|
|
|
|
Util.AddClick(self.btn_back, function()
|
|
self:ClosePanel()
|
|
end)
|
|
Util.AddClick(self.btn_activate, function()
|
|
--激活特权
|
|
DynamicActivityManager.SetSelectIndex(DataType.Direct, { 7105 })
|
|
JumpManager.GoJump(MazeTreasureSetting[1].Jump)
|
|
end)
|
|
end
|
|
|
|
function PokemonSummonPanel:OnShow()
|
|
self.changZhuEffect.gameObject:SetActive(true)
|
|
self.mask.gameObject:SetActive(false)
|
|
self.Effect_Dan_posui.gameObject:SetActive(false)
|
|
CheckRedPointStatus(RedPointType.Pokemon_Recruit)
|
|
self.upView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.LingShou })
|
|
|
|
self.infoTxt.text = Language[12068]
|
|
--是否显示特权
|
|
isActive = PrivilegeManager.GetPrivilegeOpenStatusById(3004)
|
|
if isActive then
|
|
self.leftTimeObj.gameObject:SetActive(false)
|
|
Util.SetGray(self.buffImg.gameObject, false)
|
|
leftTime = PrivilegeManager.GetPrivilegeLeftTimeById(3004)
|
|
self.leftTimeTxt.text = Language[10569] .. GetLeftTimeStrByDeltaTime(leftTime)
|
|
self.btn_activate.gameObject:SetActive(false)
|
|
else
|
|
Util.SetGray(self.buffImg.gameObject, true)
|
|
self.leftTimeObj.gameObject:SetActive(false)
|
|
self.btn_activate.gameObject:SetActive(false)
|
|
end
|
|
self:refreshBtnShow() --刷新按钮显示
|
|
self:timeCountDown() --时间
|
|
|
|
Util.SetParticleSortLayer(self.changZhuEffect, self.sortingOrder + 1)
|
|
Util.SetParticleSortLayer(self.Effect_Dan_posui, self.sortingOrder + 1)
|
|
Util.SetParticleSortLayer(self.btnEffect, self.sortingOrder + 1)
|
|
end
|
|
|
|
function PokemonSummonPanel:refreshBtnShow()
|
|
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)
|
|
self.tenHintTxt.text = string.format(Language[12066],
|
|
PrivilegeManager.GetPrivilegeRemainValue(YaojingCallPrivilegeId),
|
|
PrivilegeManager.GetPrivilegeNumber(YaojingCallPrivilegeId))
|
|
self.limitTxt.text = Language[10596] .. curTimes .. "/" .. PrivilegeManager.GetPrivilegeNumber(maxtimesId)
|
|
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")
|
|
local tip = Util.GetGameObject(btn.gameObject, "Tip"):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)
|
|
|
|
local itemId = 0
|
|
local itemNum = 0
|
|
local type = 0
|
|
if n == bType.Btn1 then
|
|
type = currLottery.Id
|
|
else
|
|
type = ConfigManager.GetConfigData(ConfigName.LotterySetting, RecruitType.LingShowTen).Id
|
|
end
|
|
local d = RecruitManager.GetExpendData(type)
|
|
if isFree then
|
|
info.text = " " .. Language[10583]
|
|
else
|
|
itemId = d[1]
|
|
itemNum = d[2]
|
|
|
|
--如果当前是用妖晶抽卡 and 激活了特权
|
|
if itemId == 16 and isActive then
|
|
local currPrivilege = privilegeConfig[3004]
|
|
if currPrivilege then
|
|
local curShenzunLv = GetShenzunLv()
|
|
local conditionIndex = curShenzunLv + 1
|
|
itemNum = itemNum * (1 + currPrivilege.Condition[conditionIndex][2] / 10000)
|
|
end
|
|
end
|
|
icon.sprite = self.spLoader:LoadSprite(artResourcesConfig[itemConfig[itemId].ResourceID].Name)
|
|
info.text = m.isInfo
|
|
num.text = "x" .. PrintWanNum2(itemNum)
|
|
end
|
|
|
|
Util.AddOnceClick(btn, function()
|
|
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,
|
|
{ RecruitType.LingShowSingle, RecruitType.LingShowTen })
|
|
else
|
|
self:Recruit(RecruitType.LingShowSingle, maxtimesId, itemId, itemNum, state, freeTimesId,
|
|
{ RecruitType.LingShowSingle, RecruitType.LingShowTen })
|
|
end
|
|
elseif n == bType.Btn10 then
|
|
self:Recruit(RecruitType.LingShowTen, maxtimesId, itemId, itemNum, state, freeTimesId,
|
|
{ RecruitType.LingShowTen, RecruitType.LingShowTen })
|
|
end
|
|
end)
|
|
end
|
|
end
|
|
|
|
function PokemonSummonPanel:Recruit(id, RecruitMaxtimesId, itemId, itemNum, state, freeTimesId, recruitType)
|
|
local num = 0
|
|
if id == RecruitType.LingShowSingle then
|
|
num = 1
|
|
else
|
|
num = 10
|
|
end
|
|
|
|
--是否超过每日最大上限
|
|
if PrivilegeManager.GetPrivilegeRemainValue(RecruitMaxtimesId) < num then
|
|
PopupTipPanel.ShowTip(Language[10587])
|
|
return
|
|
end
|
|
--是否妖晶,是否超过每日妖晶最大上限
|
|
if itemId == 16 then
|
|
if PrivilegeManager.GetPrivilegeRemainValue(YaojingCallPrivilegeId) < num then
|
|
PopupTipPanel.ShowTip(Language[10599])
|
|
return
|
|
end
|
|
end
|
|
if itemId ~= 0 then
|
|
if BagManager.GetItemCountById(itemId) < itemNum then
|
|
PopupTipPanel.ShowTip(GetLanguageStrById(itemConfig[itemId].Name) .. Language[10584])
|
|
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)
|
|
self.changZhuEffect:SetActive(false)
|
|
self.Effect_Dan_posui:SetActive(true)
|
|
SoundManager.PlaySound(SoundConfig.UI_Lingshoushan)
|
|
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, nil, recruitType)
|
|
end, 1.2):Start()
|
|
end,
|
|
freeTimesId, itemId, itemNum)
|
|
end,
|
|
itemNum)
|
|
else
|
|
RecruitManager.RecruitRequest(id, function(msg)
|
|
self.changZhuEffect:SetActive(false)
|
|
self.Effect_Dan_posui:SetActive(true)
|
|
SoundManager.PlaySound(SoundConfig.UI_Lingshoushan)
|
|
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, nil, recruitType)
|
|
end, 1.2):Start()
|
|
end, freeTimesId, itemId, itemNum)
|
|
end
|
|
end
|
|
|
|
--商店
|
|
function PokemonSummonPanel:storeShow()
|
|
if not self.shopView then
|
|
self.shopView = SubUIManager.Open(SubUIConfig.ShopView, self.content.transform)
|
|
end
|
|
self.shopView:ShowShop(SHOP_TYPE.QIANKUNBOX_SHOP)
|
|
end
|
|
|
|
--时间
|
|
function PokemonSummonPanel:timeCountDown()
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
if self.timer2 then
|
|
self.timer2:Stop()
|
|
self.timer2 = nil
|
|
end
|
|
if freeTime > 0 then
|
|
self.oneHintTxt.text = string.format(Language[12069], freeTime)
|
|
else
|
|
local timeDown = CalculateSecondsNowTo_N_OClock(0) --领取按钮的倒计时
|
|
self.oneHintTxt.text = string.format(Language[12070], TimeToHMS(timeDown))
|
|
--免费次数刷新倒计时
|
|
self.timer = Timer.New(function()
|
|
if timeDown < 1 then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
return
|
|
end
|
|
timeDown = timeDown - 1
|
|
self.oneHintTxt.text = string.format(Language[12070], TimeToHMS(timeDown))
|
|
end, 1, -1, true)
|
|
self.timer:Start()
|
|
end
|
|
--特权剩余时间倒计时
|
|
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 = Language[10569] .. GetLeftTimeStrByDeltaTime(leftTime)
|
|
end, 1, -1, true)
|
|
self.timer2:Start()
|
|
end
|
|
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[10571], minute, sec)
|
|
else
|
|
return string.format(Language[10572], day, hour)
|
|
end
|
|
end
|
|
|
|
local orginLayer = 0
|
|
function PokemonSummonPanel:OnSortingOrderChange()
|
|
-- Util.AddParticleSortLayer(self.changZhuEffect, self.sortingOrder - orginLayer)
|
|
-- Util.AddParticleSortLayer(self.Effect_Dan_posui, self.sortingOrder - orginLayer)
|
|
-- Util.AddParticleSortLayer(self.btnEffect, self.sortingOrder - orginLayer)
|
|
|
|
Util.SetParticleSortLayer(self.changZhuEffect, self.sortingOrder + 1)
|
|
Util.SetParticleSortLayer(self.Effect_Dan_posui, self.sortingOrder + 1)
|
|
Util.SetParticleSortLayer(self.btnEffect, self.sortingOrder + 1)
|
|
orginLayer = self.sortingOrder
|
|
end
|
|
|
|
function PokemonSummonPanel:OnClose()
|
|
self.gameObject:SetActive(false)
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
if self.timer2 then
|
|
self.timer2:Stop()
|
|
self.timer2 = nil
|
|
end
|
|
if self.shopView then
|
|
self.shopView = SubUIManager.Close(self.shopView)
|
|
self.shopView = nil
|
|
end
|
|
end
|
|
|
|
--界面销毁时调用(用于子类重写)
|
|
function PokemonSummonPanel:OnDestroy()
|
|
self.spLoader:Destroy()
|
|
orginLayer = 0
|
|
SubUIManager.Close(self.upView)
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
if self.timer2 then
|
|
self.timer2:Stop()
|
|
self.timer2 = nil
|
|
end
|
|
end
|
|
|
|
return PokemonSummonPanel
|