miduo_client/Assets/ManagedResources/~Lua/Modules/Recruit/RecruitEquipPanelNew.lua

484 lines
22 KiB
Lua

RecruitEquipPanelNew = {}
function RecruitEquipPanelNew:New(gameObject)
local b = {}
b.gameObject = gameObject
b.transform = gameObject.transform
setmetatable(b, { __index = RecruitEquipPanelNew })
return b
end
local gameSetting = ConfigManager.GetConfig(ConfigName.GameSetting)
local AllActSetConfig = ConfigManager.GetConfig(ConfigName.GlobalSystemConfig)
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
local artResourcesConfig = ConfigManager.GetConfig(ConfigName.ArtResourcesConfig)
local lotterySetting = ConfigManager.GetConfig(ConfigName.LotterySetting)
local privilegeConfig = ConfigManager.GetConfig(ConfigName.PrivilegeTypeConfig)
local specialConfig = ConfigManager.GetConfig(ConfigName.SpecialConfig)
local wishConfig = ConfigManager.GetConfig(ConfigName.WishConfig)
local getId = 0
function RecruitEquipPanelNew:InitComponent()
self.spLoader = SpriteLoader.New()
self.panel = Util.GetGameObject(self.gameObject, "Panel")
self.bg1 = Util.GetGameObject(self.gameObject, "Bg/Bg1"):GetComponent("Image")
self.bg2 = Util.GetGameObject(self.gameObject, "Bg/Bg2"):GetComponent("Image")
self.bg3 = Util.GetGameObject(self.gameObject, "Bg/Bg3"):GetComponent("Image")
self.title = Util.GetGameObject(self.panel, "title"):GetComponent("Image")
self.root = Util.GetGameObject(self.panel, "root")
self.rewardBox = Util.GetGameObject(self.panel, "btngroup/rewardBox")
self.boxIcon = Util.GetGameObject(self.rewardBox, "boxIcon")
self.slider = Util.GetGameObject(self.rewardBox, "Bg/Slider"):GetComponent("Image")
self.sliderText = Util.GetGameObject(self.rewardBox, "progress/Text"):GetComponent("Text")
self.boxNameText = Util.GetGameObject(self.rewardBox, "di/Text"):GetComponent("Text")
self.boxNameText.text = Language[12578]
self.boxBtn = Util.GetGameObject(self.rewardBox, "Btn")
self.UI_effect_RecruitPanel_box_normal = Util.GetGameObject(self.rewardBox, "UI_effect_RecruitPanel_box_normal")
effectAdapte(Util.GetGameObject(self.UI_effect_RecruitPanel_box_normal, "quan01"))
self.UI_effect_RecruitPanel_box_open = Util.GetGameObject(self.rewardBox, "UI_effect_RecruitPanel_box_open")
effectAdapte(Util.GetGameObject(self.UI_effect_RecruitPanel_box_open, "quan01"))
effectAdapte(Util.GetGameObject(self.UI_effect_RecruitPanel_box_open, "quan02"))
self.UI_effect_RecruitPanel_particle = Util.GetGameObject(self.gameObject, "UI_effect_RecruitPanel_particle")
self.previewBtn = Util.GetGameObject(self.panel, "PreviewBtn")
self.helpBtn = Util.GetGameObject(self.panel, "helpBtn")
self.helpPosition = self.helpBtn:GetComponent("RectTransform").localPosition
self.wish = Util.GetGameObject(self.panel, "wishBtn")
self.wishNoOpen = Util.GetGameObject(self.wish, "noOpen")
self.wishBtn = Util.GetGameObject(self.wishNoOpen, "Img")
self.wishTextImg = Util.GetGameObject(self.wishNoOpen, "ImgText")
self.wishText = Util.GetGameObject(self.wishTextImg, "Text"):GetComponent("Text")
self.wishTipIma = Util.GetGameObject(self.wishNoOpen, "tip"):GetComponent("Text")
self.wishOpen = Util.GetGameObject(self.wish, "upHeroGrid")
self.wishPre = Util.GetGameObject(self.wish, "upHeroPre")
self.lsth = Util.GetGameObject(self.gameObject, "btngroup/zqbg")
self.lsth.gameObject:SetActive(ActivityGiftManager.IsActivityTypeOpen(20015) ~= nil)
self.zqbgRed = Util.GetGameObject(self.gameObject, "btngroup/zqbg/red")
BindRedPointObject(RedPointType.WishEquipStore, self.zqbgRed)
self.zqbgEffect = Util.GetGameObject(self.gameObject, "btngroup/zqbg/Fx_Circle 1")
-- self.tip = Util.GetGameObject(self.panel, "tip/text"):GetComponent("Text")
self.tenTip = Util.GetGameObject(self.panel, "TenTip")
self.tenTipText = Util.GetGameObject(self.tenTip, "scroll/Text"):GetComponent("Text")
self.upper = Util.GetGameObject(self.panel, "Upper/Num"):GetComponent("Text") --Language[10596]
if not self.upHeroPreList then
self.upHeroPreList = {}
end
for i = 1, 3 do
self.upHeroPreList[i] = {}
self.upHeroPreList[i].go = Util.GetGameObject(self.wishOpen, "upHeroPre" .. i)
self.upHeroPreList[i].pos = Util.GetGameObject(self.upHeroPreList[i].go, "di")
self.upHeroPreList[i].itempos = Util.GetGameObject(self.upHeroPreList[i].go, "itempos")
self.upHeroPreList[i].item = SubUIManager.Open(SubUIConfig.ItemView, self.upHeroPreList[i].itempos.transform)
self.upHeroPreList[i].item.gameObject:SetActive(false)
self.upHeroPreList[i].item.transform:SetSiblingIndex(0)
self.upHeroPreList[i].choosed = Util.GetGameObject(self.upHeroPreList[i].go, "state")
--心愿神将现在只显示一个
if i > 1 then
self.upHeroPreList[i].go:SetActive(false)
else
self.upHeroPreList[i].go:SetActive(true)
end
end
self.btns = {}
for i = 1, 2 do
self.btns[i] = {}
self.btns[i].btn = Util.GetGameObject(self.gameObject, "btngroup/btn" .. i)
self.btns[i].layoutDi = Util.GetGameObject(self.btns[i].btn.gameObject, "layout/di"):GetComponent("Image")
self.btns[i].red = Util.GetGameObject(self.btns[i].btn.gameObject, "redPoint")
self.btns[i].info = Util.GetGameObject(self.btns[i].btn.gameObject, "layout/Text"):GetComponent("Text")
self.btns[i].icon = Util.GetGameObject(self.btns[i].btn.gameObject, "layout/icon"):GetComponent("Image")
self.btns[i].num = Util.GetGameObject(self.btns[i].btn.gameObject, "layout/num"):GetComponent("Text")
self.btns[i].time = Util.GetGameObject(self.btns[i].btn.gameObject, "time"):GetComponent("Text")
end
end
function RecruitEquipPanelNew:OnFocus()
CheckRedPointStatus(RedPointType.WishEquipStore)
end
function RecruitEquipPanelNew:BindEvent()
Util.AddOnceClick(self.lsth, function()
local isOpen = CheckFunctionOpen(FUNCTION_OPEN_TYPE.EquipWish)
local tip = GetFunctionOpenTip(FUNCTION_OPEN_TYPE.EquipWish)
if isOpen == false then
PopupTipPanel.ShowTip(tip)
return
end
JumpManager.GoJump(40082)
end)
--帮助按钮
Util.AddClick(self.helpBtn, function()
UIManager.OpenPanel(UIName.HelpPopup, self.config.HelpId, self.helpPosition.x, self.helpPosition.y)
end)
--宝箱按钮
Util.AddClick(self.boxBtn, function()
--UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.RecruitBox)
--self.UI_effect_RecruitPanel_box_normal:SetActive(true)
-- if RecruitManager.isCanOpenBox then
-- LogError("getid=========="..getId)
-- ActivityGiftManager.GetActivityRewardRequest(11901,getId)
-- else
-- UIManager.OpenPanel(UIName.WishHeroRewardPopup,self.config.ShopData[1][1])
-- end
UIManager.OpenPanel(UIName.WishHeroRewardPopup, self.config.ShopData[1][1])
end)
--奖池预览按钮
Util.AddClick(self.previewBtn, function()
UIManager.OpenPanel(UIName.HeroPreviewNewPanel, true, true, self.config.ShopData[4][1])
end)
end
function RecruitEquipPanelNew:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.Recruit.OnRecruitRefreshData, self.UpdataPanel, self)
end
function RecruitEquipPanelNew:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.Recruit.OnRecruitRefreshData, self.UpdataPanel, self)
end
function RecruitEquipPanelNew:OnSortingOrderChange(sortingOrder)
self.sortingOrder = sortingOrder
Util.SetParticleSortLayer(self.UI_effect_RecruitPanel_box_normal, self.sortingOrder + 1)
Util.SetParticleSortLayer(self.UI_effect_RecruitPanel_box_open, self.sortingOrder + 1)
Util.SetParticleSortLayer(self.UI_effect_RecruitPanel_particle, self.sortingOrder + 1)
SetParticleSortLayer(self.zqbgEffect, self.sortingOrder + 1)
end
--界面打开时调用(用于子类重写)
function RecruitEquipPanelNew:OnOpen(_Config, _index, parent)
self.config = _Config
self.parent = parent
self.gameObject.name = "RecruitEquipPanelNew" .. self.config.Id
end
function RecruitEquipPanelNew:OnShow(sortingOrder)
self.sortingOrder = sortingOrder
self:OnSortingOrderChange(sortingOrder)
self.gameObject:SetActive(true)
RecruitManager.curWishType = self.config.ShopData[1][1]
self.singleConfig = ConfigManager.GetConfigDataByDoubleKey(ConfigName.LotterySetting, "LotteryType",
self.config.ShopData[1][1], "PerCount", 1)
self.tenConfig = ConfigManager.GetConfigDataByDoubleKey(ConfigName.LotterySetting, "LotteryType",
self.config.ShopData[1][1], "PerCount", 10)
self.XianZhaoConfig = ConfigManager.GetConfigDataByKey(ConfigName.LotterySetting, "LotteryType",
TableRecruitType.xianyuan)
self:UpdataPanel()
SoundManager.PlayMusic(SoundConfig.BGM_Recruit)
if self.liveNode then
poolManager:UnLoadLive(self.liveNode.name, self.liveNode)
end
if self.config.ShopData[2][1] == 1 then
local heroConfig = ConfigManager.GetConfigData(ConfigName.HeroConfig, self.config.ShopData[2][2])
local name = GetResourcePath(heroConfig.Live)
self.liveNode = poolManager:LoadLive(name, self.root.transform, Vector3.one * heroConfig.Scale,
Vector3.New(heroConfig.Position[1], heroConfig.Position[2], 0))
self.liveNode.name = name
SetHEeroLiveToward(self.liveNode, heroConfig.Toward)
local SkeletonGraphic = self.liveNode:GetComponent("SkeletonGraphic")
SkeletonGraphic.AnimationState:SetAnimation(0, "idle", true)
end
CheckRedPointStatus(RedPointType.WishEquipStore)
end
local progresss = 0
local wishLv = 0
function RecruitEquipPanelNew:UpdataPanel()
self.bg1.sprite = self.spLoader:LoadSprite(self.config.Icon[3])
self.bg2.sprite = self.spLoader:LoadSprite(self.config.Icon[4])
self.bg3.sprite = self.spLoader:LoadSprite(self.config.Icon[8])
self.title.sprite = self.spLoader:LoadSprite(self.config.Icon[5])
--宝箱活动数据
local actconfigs = ActivityGiftManager.GetActivityInfoByType(11901)
if actconfigs then
for i = 1, #actconfigs.mission do
progresss = actconfigs.mission[i].progress
end
end
--LogError("progress==============="..progresss)
for i, v in ConfigPairs(wishConfig) do
if RecruitManager.drawTimes[4] and RecruitManager.drawTimes[4] >= v.DrawCardNumber and v.LotteryType == 4 then
wishLv = v.Level
RecruitManager.SetWishPro(v.Weight / 10000 * 100, v.MythWeight / 10000 * 100)
end
end
self.boxNameText.text = Language[12579] .. wishLv
self.title:SetNativeSize()
for i = 1, 2 do
self.btns[i].layoutDi.sprite = self.spLoader:LoadSprite(self.config.Icon[6])
end
self.parent.mask2.sprite = self.spLoader:LoadSprite(self.config.Icon[7])
self.parent.mask1.sprite = self.spLoader:LoadSprite(self.config.Icon[7])
-- self.tip.text = self.config.TitleText
self:UpdataWishPanel()
self:UpdataBoxReward()
local num = PrivilegeManager.GetPrivilegeRemainValue(self.singleConfig.MoneyTimes)
self.upper.text = string.format(GetLanguageStrById(self.config.TitleText),
PrivilegeManager.GetPrivilegeUsedTimes(self.singleConfig.MaxTimes),
privilegeConfig[self.singleConfig.MaxTimes].Condition[1][2]) --string.format(self.config.TitleText,PrivilegeManager.GetPrivilegeUsedTimes(self.singleConfig.MaxTimes),privilegeConfig[self.singleConfig.MaxTimes].Condition[1][2]..Language[12580]..num) --特权上限
self:UpdatePanelData()
self:TimeCountDown()
end
function RecruitEquipPanelNew:UpdataWishPanel()
self.tenTip.gameObject:SetActive(false)
--如果没有达到150抽按钮置灰
local data = tonumber(specialConfig[119].Value)
NetManager.ChoiceWishHeroRequest(self.config.ShopData[1][1], function()
if RecruitManager.drawTimes[4] then
LogError(" RecruitManager.drawTimes[4]===" .. RecruitManager.drawTimes[4])
if wishLv < data then
self.wishNoOpen.gameObject:SetActive(true)
self.wishOpen.gameObject:SetActive(false)
Util.SetGray(self.wishBtn, true)
self.wishText.text = string.format("%s/%s", wishLv, data)
self.wishTipIma.text = Language[12581] .. data .. Language[12582]
else
self.wishNoOpen.gameObject:SetActive(false)
self.wishOpen.gameObject:SetActive(true)
for i = 1, 1 do
local data = RecruitManager.WishEquipData[i]
local id = 0
if data then
id = data.heroTid
end
LogError("id================================" .. id)
if id > 0 then
self.upHeroPreList[i].item.gameObject:SetActive(true)
self.upHeroPreList[i].item:OnOpen(false, { id, 0 }, 1, false, false, false, self.sortingOrder)
self.upHeroPreList[i].item.frame.sprite = self.spLoader:LoadSprite(GetBgByHeroNatural(
ConfigManager.GetConfigData(ConfigName.ItemConfig, id).Quantity))
self.upHeroPreList[i].choosed:SetActive(data.status == 1)
else
self.upHeroPreList[i].item.gameObject:SetActive(false)
self.upHeroPreList[i].choosed.gameObject:SetActive(false)
end
Util.AddOnceClick(self.upHeroPreList[i].pos, function()
local tempdata = tonumber(specialConfig[119].Value)
if RecruitManager.drawTimes[4] then
RecruitManager.curWishType = self.config.ShopData[1][1]
if RecruitManager.drawTimes[4] >= tempdata then
UIManager.OpenPanel(UIName.GeneralBigPopup, GENERAL_POPUP_TYPE.WishEquipDraw)
else
PopupTipPanel.ShowTip(string.format(Language[12583],
tempdata - RecruitManager.drawTimes[4]))
end
else
PopupTipPanel.ShowTip(string.format(Language[12583], tempdata))
end
end)
end
end
else
self.wishNoOpen.gameObject:SetActive(true)
self.wishOpen.gameObject:SetActive(false)
Util.SetGray(self.wishBtn, true)
self.wishText.text = string.format("%s/%s", 0, data)
self.wishTipIma.text = Language[12581] .. data .. Language[12582]
end
--self:CheckNewWishHero()
end)
self.tenTip.gameObject:SetActive(true)
-- if RecruitManager.isTenRecruit == 0 then
-- self.tenTipText.text = "<color=#FFB83B><size=30>每次十连</size><color=#FEDA90><size=30>必得</size></color></color><color=#FFB83B><size=30>五星</size></color><color=#FEDA90><size=30>神将法宝</size></color>"
-- else
self.tenTipText.text = string.format(Language[12584], RecruitManager.GetRecruit2MustCount())
--end
end
function RecruitEquipPanelNew:UpdataBoxReward()
--local num = BagManager.GetItemCountById(self.XianZhaoConfig.CostItem[1][1])
LogError("更新宝箱显示s")
local actconfigs = ActivityGiftManager.GetActivityInfoByType(11901)
RecruitManager.isCanOpenBox = false
if actconfigs then
for i = 1, #actconfigs.mission do
local config = ConfigManager.TryGetConfigDataByDoubleKey(ConfigName.WishConfig, "Level",
actconfigs.mission[i].missionId, "LotteryType", 4)
if config and actconfigs.mission[i].state == 0 and RecruitManager.drawTimes[4] and RecruitManager.drawTimes[4] >= config.DrawCardNumber then
RecruitManager.isCanOpenBox = true
getId = actconfigs.mission[i].missionId
break
end
end
end
self.boxIcon:GetComponent("Animator").enabled = RecruitManager.isCanOpenBox
local wishData = ConfigManager.TryGetConfigDataByDoubleKey(ConfigName.WishConfig, "Level", wishLv + 1, "LotteryType",
4)
if wishData then
self.sliderText.text = string.format("%s/%s", RecruitManager.drawTimes[4] or 0, wishData.DrawCardNumber)
if RecruitManager.drawTimes[4] then
self.slider.fillAmount = RecruitManager.drawTimes[4] / wishData.DrawCardNumber
else
self.slider.fillAmount = 0 / wishData.DrawCardNumber
end
else
self.slider.fillAmount = 1
self.sliderText.text = Language[10990]
end
end
function RecruitEquipPanelNew:OnClose()
self.gameObject:SetActive(false)
if self.timer then
self.timer:Stop()
self.timer = nil
end
end
function RecruitEquipPanelNew:OnDestroy()
self.spLoader:Destroy()
if self.timer then
self.timer:Stop()
self.timer = nil
end
ClearRedPointObject(RedPointType.WishEquipStore, self.zqbgRed)
for i = 1, 3 do
if self.upHeroPreList[i] then
SubUIManager.Close(self.upHeroPreList[i].item)
end
end
self.upHeroPreList = {}
if self.liveNode then
poolManager:UnLoadLive(self.liveNode.name, self.liveNode)
self.liveNode = nil
end
end
--刷新剩余次数
function RecruitEquipPanelNew:UpdatePanelData()
local freeTime = 0
if self.singleConfig.FreeTimes and self.singleConfig.FreeTimes > 0 then
freeTime = PrivilegeManager.GetPrivilegeRemainValue(self.singleConfig.FreeTimes)
RecruitManager.freeUseTimeList[self.singleConfig.FreeTimes] = freeTime
end
--按钮赋值
for n, m in ipairs(self.btns) do
--存在免费次数 并且 免费>=1 并且是1按钮
local isFree = freeTime >= 1 and n == 1
m.icon.gameObject:SetActive(not isFree)
m.num.gameObject:SetActive(not isFree)
local itemId = 0
local itemNum = 0
local type = 0
if n == 1 then
type = self.singleConfig.Id
m.info.text = Language[10577]
m.time.gameObject:SetActive(true)
m.red.gameObject:SetActive(RecruitManager.GetRecruitBtnRedpoint1(PreConfigure
[RevertPreConfigure[self.config.ShopData[3][1]]]))
else
m.time.gameObject:SetActive(false)
type = self.tenConfig.Id
m.info.text = Language[10578]
m.red.gameObject:SetActive(RecruitManager.GetRecruitBtnRedpoint1(PreConfigure
[RevertPreConfigure[self.config.ShopData[3][2]]]))
end
if self.config.ShopData[1][1] == TableRecruitType.Youqing then
m.time.gameObject:SetActive(false)
end
local d = {}
if (isFree) then
m.time.gameObject:SetActive(false)
m.info.text = Language[10588]
else
local d = RecruitManager.GetExpendData(type)
itemId = d[1]
itemNum = d[2]
m.icon.sprite = self.spLoader:LoadSprite(artResourcesConfig[itemConfig[itemId].ResourceID].Name)
m.num.text = PrintWanNum2(itemNum)
end
Util.AddOnceClick(m.btn, function()
local isOpen = CheckFunctionOpen(FUNCTION_OPEN_TYPE.EquipWish)
local tip = GetFunctionOpenTip(FUNCTION_OPEN_TYPE.EquipWish)
if isOpen == false then
PopupTipPanel.ShowTip(tip)
return
end
if not isFree then
if BagManager.GetItemCountById(itemId) < itemNum then
PopupTipPanel.ShowTip(GetLanguageStrById(itemConfig[itemId].Name) .. Language[10584])
return
end
end
local state = PlayerPrefs.GetInt(PlayerManager.uid ..
"GeneralPopup_RecruitConfirm" .. self.config.ShopData[3][2])
LogGreen("self.config.ShopData[3][2]:" .. self.config.ShopData[3][2] .. " state:" .. state)
local recrutId = n == 1 and self.singleConfig.Id or self.tenConfig.Id
local recrutNum = n == 1 and 1 or 10
if state == 0 and itemId == 16 and not isFree then
UIManager.OpenPanel(UIName.GeneralPopup, GENERAL_POPUP_TYPE.RecruitConfirm, recrutId, function()
self:Recruit(recrutNum, recrutId, n, itemId)
end)
else
self:Recruit(recrutNum, recrutId, n, itemId)
end
end)
end
end
function RecruitEquipPanelNew:Recruit(recrutType, recrutId, bType, itemId)
if PrivilegeManager.GetPrivilegeUsedTimes(self.singleConfig.MaxTimes) + recrutType > privilegeConfig[self.singleConfig.MaxTimes].Condition[1][2] then
PopupTipPanel.ShowTip(Language[10587])
return
end
if itemId == 16 and PrivilegeManager.GetPrivilegeRemainValue(self.singleConfig.MaxTimes) < recrutType then
PopupTipPanel.ShowTip(Language[10598])
return
end
RecruitManager.RecruitRequest(recrutId, function(msg)
PrivilegeManager.RefreshPrivilegeUsedTimes(self.singleConfig.MaxTimes, recrutType) --记录抽卡次数
if itemId == 16 then
PrivilegeManager.RefreshPrivilegeUsedTimes(self.singleConfig.MoneyTimes, recrutType)
end
if bType == 1 then
UIManager.OpenPanel(UIName.WishEquipBuyOnePanel, msg.drop, recrutId,
{ self.config.ShopData[3][1], self.config.ShopData[3][2] })
else
RecruitManager.isTenRecruit = 1
UIManager.OpenPanel(UIName.WishEquipBuyTenPanel, msg.drop, recrutId,
{ self.config.ShopData[3][1], self.config.ShopData[3][2] })
end
CheckRedPointStatus(self.config.RpType)
end, self.singleConfig.FreeTimes)
end
function RecruitEquipPanelNew:TimeCountDown()
if self.timer then
self.timer:Stop()
self.timer = nil
end
local timeDown = CalculateSecondsNowTo_N_OClock(0)
self.btns[1].time.text = Language[10026] .. TimeToHMS(timeDown)
self.timer = Timer.New(function()
if timeDown < 1 then
self.timer:Stop()
self.timer = nil
return
end
timeDown = timeDown - 1
self.btns[1].time.text = Language[10026] .. TimeToHMS(timeDown)
end, 1, -1, true)
self.timer:Start()
end
--检查是否有新开放的心愿英雄
function RecruitEquipPanelNew:CheckNewWishHero()
if #RecruitManager.newWishList > 0 and #RecruitManager.newWishList < 10 then
if not GuideManager.IsFunctionGuideExist() and not GuideManager.IsInMainGuide() then
UIManager.OpenPanel(UIName.GeneralPopup, GENERAL_POPUP_TYPE.NewAddWishHero)
end
end
end
return RecruitEquipPanelNew