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

347 lines
15 KiB
Lua
Raw Normal View History

2025-03-14 11:58:20 +08:00
require("Base/BasePanel")
2020-05-09 13:31:21 +08:00
RecruitPanel = Inherit(BasePanel)
local this = RecruitPanel
--local preList
local i = 0
local canDrag = true
local gameSetting = ConfigManager.GetConfig(ConfigName.GameSetting)
local AllActSetConfig = ConfigManager.GetConfig(ConfigName.GlobalSystemConfig)
2024-09-06 10:38:56 +08:00
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
local artResourcesConfig = ConfigManager.GetConfig(ConfigName.ArtResourcesConfig)
local lotterySetting = ConfigManager.GetConfig(ConfigName.LotterySetting)
local privilegeConfig = ConfigManager.GetConfig(ConfigName.PrivilegeTypeConfig)
2021-06-30 10:23:57 +08:00
local specialConfig = ConfigManager.GetConfig(ConfigName.SpecialConfig)
2020-05-09 13:31:21 +08:00
local orginLayer = 0
2020-05-25 19:16:23 +08:00
--抽卡类型
2024-09-06 10:38:56 +08:00
local rType = {
Normal = 1, --普通
Friend = 2, --友情
Hero = 3 --神将
2020-05-25 19:16:23 +08:00
}
--按钮类型
2024-09-06 10:38:56 +08:00
local bType = {
Btn1 = 1,
Btn10 = 2
2020-05-25 19:16:23 +08:00
}
--抽卡配置
2024-09-06 10:38:56 +08:00
local preConfigure = {
[rType.Normal] = {
bgAtlas = "c_chouka_putong_zh",
privilegeId = 38,
btn = {
[bType.Btn1] = { name = "Btn1", isInfo = Language[10577], type = RecruitType.NormalSingle }, --按钮配置 若有字段 则显示组件并显示内容
[bType.Btn10] = { name = "Btn10", isInfo = Language[10833], type = RecruitType.NormalTen }
2020-05-25 19:16:23 +08:00
},
},
2024-09-06 10:38:56 +08:00
[rType.Friend] = {
bgAtlas = "c_chouka_youqing_zh",
btn = {
[bType.Btn1] = { name = "Btn1", isInfo = Language[10577], type = RecruitType.FriendSingle },
[bType.Btn10] = { name = "Btn10", isInfo = Language[10833], type = RecruitType.FriendTen }
},
2020-05-25 19:16:23 +08:00
},
2024-09-06 10:38:56 +08:00
[rType.Hero] = {
bgAtlas = "c_chouka_shenjiang_zh",
privilegeId = 14,
btn = {
[bType.Btn1] = { name = "Btn1", isInfo = Language[10577], type = RecruitType.Single },
[bType.Btn10] = { name = "Btn10", isInfo = Language[10833], type = RecruitType.Ten }
2020-05-25 19:16:23 +08:00
},
}
}
--预设容器
2024-09-06 10:38:56 +08:00
local preList = {}
2020-05-25 19:16:23 +08:00
--倒计时容器
2024-09-06 10:38:56 +08:00
local timeList = {}
2020-05-25 19:16:23 +08:00
2020-05-09 13:31:21 +08:00
function RecruitPanel:InitComponent()
2021-04-21 13:12:04 +08:00
this.spLoader = SpriteLoader.New()
2024-09-06 10:38:56 +08:00
this.mask = Util.GetGameObject(self.transform, "Bg/Mask")
2020-05-25 19:16:23 +08:00
this.backBtn = Util.GetGameObject(self.transform, "BackBtn/Btn")
2024-09-06 10:38:56 +08:00
this.upView = SubUIManager.Open(SubUIConfig.UpView, self.gameObject.transform,
{ showType = UpViewOpenType.ShowLeft, panelType = PanelType.Recruit })
2020-05-25 19:16:23 +08:00
this.slider = Util.GetGameObject(self.transform, "rewardBox/content/Slider"):GetComponent("Image")
2020-06-28 17:48:49 +08:00
this.sliderText = Util.GetGameObject(self.transform, "Text"):GetComponent("Text")
2020-05-09 13:31:21 +08:00
2020-05-25 19:16:23 +08:00
this.tenTip = Util.GetGameObject(this.gameObject, "TenTip")
this.tenTipText = Util.GetGameObject(this.gameObject, "TenTip/Text"):GetComponent("Text")
2020-05-25 19:16:23 +08:00
this.previewBtn = Util.GetGameObject(this.gameObject, "PreviewBtn")
2024-09-06 10:38:56 +08:00
this.UI_effect_RecruitPanel_box_normal = Util.GetGameObject(self.transform,
"rewardBox/content/UI_effect_RecruitPanel_box_normal")
2020-05-25 19:16:23 +08:00
effectAdapte(Util.GetGameObject(this.UI_effect_RecruitPanel_box_normal, "quan01"))
2024-09-06 10:38:56 +08:00
self.UI_effect_RecruitPanel_box_open = Util.GetGameObject(self.transform,
"rewardBox/content/UI_effect_RecruitPanel_box_open")
2020-05-09 13:31:21 +08:00
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.transform, "UI_effect_RecruitPanel_particle")
2020-05-25 19:16:23 +08:00
2024-09-06 10:38:56 +08:00
this.panel = Util.GetGameObject(this.gameObject, "Panel")
this.content = Util.GetGameObject(this.panel, "Content") --抽卡父节点
this.pre = Util.GetGameObject(this.content, "Pre") --抽卡预设
2020-05-25 19:16:23 +08:00
2024-09-06 10:38:56 +08:00
this.boxBtn = Util.GetGameObject(this.gameObject, "rewardBox/content/boxIcon/Btn")
this.upper = Util.GetGameObject(this.gameObject, "Upper/Num"):GetComponent("Text") --召唤上限
2021-06-29 11:30:26 +08:00
2024-09-06 10:38:56 +08:00
this.wishBtn = Util.GetGameObject(this.gameObject, "wishBtn")
2022-04-25 11:31:32 +08:00
this.wishBtn:SetActive(false)
2024-09-06 10:38:56 +08:00
this.wishImg = Util.GetGameObject(this.wishBtn, "Img")
this.wishTextImg = Util.GetGameObject(this.wishBtn, "ImgText")
this.wishText = Util.GetGameObject(this.wishTextImg, "Text"):GetComponent("Text")
2021-06-30 13:51:47 +08:00
this.helpBtn = Util.GetGameObject(this.gameObject, "helpBtn")
this.helpPosition = this.helpBtn:GetComponent("RectTransform").localPosition
2020-05-09 13:31:21 +08:00
end
function RecruitPanel:BindEvent()
2020-05-25 19:16:23 +08:00
Util.AddClick(this.backBtn, function()
2020-05-09 13:31:21 +08:00
self:ClosePanel()
PlaySoundWithoutClick(SoundConfig.Sound_UICancel)
end)
2021-06-30 13:51:47 +08:00
--帮助按钮
Util.AddClick(this.helpBtn, function()
2024-09-06 10:38:56 +08:00
UIManager.OpenPanel(UIName.HelpPopup, HELP_TYPE.WishCard, this.helpPosition.x, this.helpPosition.y)
2021-06-30 13:51:47 +08:00
end)
2020-05-25 19:16:23 +08:00
--宝箱按钮
2024-09-06 10:38:56 +08:00
Util.AddClick(this.boxBtn, function()
UIManager.OpenPanel(UIName.GeneralPopup, GENERAL_POPUP_TYPE.RecruitBox)
2020-05-09 13:31:21 +08:00
Util.GetGameObject(self.transform, "rewardBox/content/boxIcon"):GetComponent("Animator").enabled = false
2020-05-25 19:16:23 +08:00
this.UI_effect_RecruitPanel_box_normal:SetActive(true)
2020-05-09 13:31:21 +08:00
end)
2020-05-25 19:16:23 +08:00
--奖池预览按钮
Util.AddClick(this.previewBtn, function()
2024-09-06 10:38:56 +08:00
UIManager.OpenPanel(UIName.HeroPreviewPanel, true)
end)
2021-06-29 11:30:26 +08:00
--心愿抽卡界面
Util.AddClick(this.wishBtn, function()
2021-06-30 10:23:57 +08:00
local data = tonumber(specialConfig[119].Value)
if RecruitManager.drawTimes[1] then
if RecruitManager.drawTimes[1] >= data then
2024-09-06 10:38:56 +08:00
UIManager.OpenPanel(UIName.GeneralBigPopup, GENERAL_POPUP_TYPE.WishDraw)
else
2024-09-06 10:38:56 +08:00
PopupTipPanel.ShowTip(string.format(Language[12583], data - RecruitManager.drawTimes[1]))
end
2021-06-30 10:23:57 +08:00
else
2024-09-06 10:38:56 +08:00
PopupTipPanel.ShowTip(string.format(Language[12583], data))
2021-06-30 10:23:57 +08:00
end
2020-05-09 13:31:21 +08:00
end)
end
function RecruitPanel:AddListener()
2020-05-25 19:16:23 +08:00
Game.GlobalEvent:AddEvent(GameEvent.Recruit.OnRecruitRefreshData, this.UpdatePanelData)
2020-05-09 13:31:21 +08:00
end
function RecruitPanel:RemoveListener()
2020-05-25 19:16:23 +08:00
Game.GlobalEvent:RemoveEvent(GameEvent.Recruit.OnRecruitRefreshData, this.UpdatePanelData)
2020-05-09 13:31:21 +08:00
end
2024-09-06 10:38:56 +08:00
2020-05-09 13:31:21 +08:00
function RecruitPanel:OnSortingOrderChange()
2020-05-25 19:16:23 +08:00
Util.AddParticleSortLayer(this.UI_effect_RecruitPanel_box_normal, self.sortingOrder - orginLayer)
2020-05-09 13:31:21 +08:00
Util.AddParticleSortLayer(self.UI_effect_RecruitPanel_box_open, self.sortingOrder - orginLayer)
Util.AddParticleSortLayer(self.UI_effect_RecruitPanel_particle, self.sortingOrder - orginLayer)
orginLayer = self.sortingOrder
end
2020-05-25 19:16:23 +08:00
2020-05-09 13:31:21 +08:00
function RecruitPanel:OnShow(...)
2020-05-25 19:16:23 +08:00
this.upView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.Recruit })
this.UpdatePanelData()
--如果没有达到150抽按钮置灰
local data = tonumber(specialConfig[119].Value)
if RecruitManager.drawTimes[1] then
if RecruitManager.drawTimes[1] < data then
2024-09-06 10:38:56 +08:00
Util.SetGray(this.wishImg, true)
this.wishTextImg:SetActive(true)
2024-09-06 10:38:56 +08:00
this.wishText.text = string.format("%s/%s", RecruitManager.drawTimes[1], data)
else
2024-09-06 10:38:56 +08:00
Util.SetGray(this.wishImg, false)
this.wishTextImg:SetActive(false)
end
else
this.wishTextImg:SetActive(true)
2024-09-06 10:38:56 +08:00
Util.SetGray(this.wishImg, true)
this.wishText.text = string.format("%s/%s", 0, data)
end
2020-05-09 13:31:21 +08:00
SoundManager.PlayMusic(SoundConfig.BGM_Recruit)
2020-05-25 19:16:23 +08:00
if this.liveNode then
poolManager:UnLoadLive("live2d_npc_chouka", this.liveNode)
2020-05-09 13:31:21 +08:00
end
2024-09-06 10:38:56 +08:00
this.liveNode = poolManager:LoadLive("live2d_npc_chouka", this.mask.transform, Vector3.one * 0.45,
Vector3.New(253, -586, 0))
2020-05-09 13:31:21 +08:00
end
2020-05-25 19:16:23 +08:00
function RecruitPanel:OnClose()
if this.timer then
this.timer:Stop()
this.timer = nil
2020-05-09 13:31:21 +08:00
end
end
2020-05-25 19:16:23 +08:00
function RecruitPanel:OnDestroy()
2021-04-21 13:12:04 +08:00
this.spLoader:Destroy()
2020-05-25 19:16:23 +08:00
SubUIManager.Close(this.upView)
2024-09-06 10:38:56 +08:00
preList = {}
timeList = {}
2020-05-25 19:16:23 +08:00
if this.liveNode then
poolManager:UnLoadLive("live2d_npc_chouka", this.liveNode)
2020-05-09 13:31:21 +08:00
end
end
2020-05-25 19:16:23 +08:00
function this.UpdatePanelData()
2024-09-06 10:38:56 +08:00
local maxTimesId = lotterySetting[1].MaxTimes --特权上限ID
2020-05-25 19:16:23 +08:00
--初始化组件
for i, v in ipairs(preConfigure) do
2024-09-06 10:38:56 +08:00
local o = preList[i]
2020-05-25 19:16:23 +08:00
if not o then
2024-09-06 10:38:56 +08:00
o = newObjToParent(this.pre, this.content)
o.name = "Pre" .. i
preList[i] = o
2020-05-25 19:16:23 +08:00
end
2024-09-06 10:38:56 +08:00
local bg = Util.GetGameObject(preList[i], "Bg"):GetComponent("Image")
local time = Util.GetGameObject(preList[i], "Time"):GetComponent("Text")
2020-05-25 19:16:23 +08:00
2024-09-06 10:38:56 +08:00
bg.sprite = this.spLoader:LoadSprite(v.bgAtlas)
local freeTime = 0
2020-05-25 19:16:23 +08:00
if v.privilegeId then
2024-09-06 10:38:56 +08:00
freeTime = PrivilegeManager.GetPrivilegeRemainValue(v.privilegeId)
RecruitManager.freeUseTimeList[v.privilegeId] = freeTime --特权免费次数赋值
table.insert(timeList, { timeObj = time }) --将倒计时预设存入
2020-05-25 19:16:23 +08:00
end
2024-09-06 10:38:56 +08:00
time.gameObject:SetActive((not freeTime or freeTime <= 0) and i ~= rType.Friend) --若不存在数据 或没免费次数 显示倒计时
2020-05-25 19:16:23 +08:00
--按钮赋值
for n, m in ipairs(v.btn) do
2024-09-06 10:38:56 +08:00
local btn = Util.GetGameObject(o, m.name)
local tip = Util.GetGameObject(o, m.name .. "/Tip"):GetComponent("Text")
local redPot = Util.GetGameObject(o, m.name .. "/RedPoint")
local info = Util.GetGameObject(o, m.name .. "/Content/Info"):GetComponent("Text")
local icon = Util.GetGameObject(o, m.name .. "/Content/Icon"):GetComponent("Image")
local num = Util.GetGameObject(o, m.name .. "/Content/Num"):GetComponent("Text")
2020-05-25 19:16:23 +08:00
--组件的显示 若上方有配置就显示 没配置不显示
tip.gameObject:SetActive(not not m.isTip) --若不存在m.isTip 返回true not true为false
info.gameObject:SetActive(not not m.isInfo)
--存在免费次数 并且 免费>=1 并且是1按钮
2024-09-06 10:38:56 +08:00
local isFree = freeTime and freeTime >= 1 and n == bType.Btn1
icon.gameObject:SetActive(not isFree or n == bType.Btn10 or i == rType.Friend)
num.gameObject:SetActive(not isFree or n == bType.Btn10 or i == rType.Friend)
2020-05-25 19:16:23 +08:00
2024-09-06 10:38:56 +08:00
tip.text = m.isTip and m.isTip or ""
info.text = m.isInfo and m.isInfo or ""
2020-05-25 19:16:23 +08:00
2024-09-06 10:38:56 +08:00
local itemId = 0
local itemNum = 0
local d = RecruitManager.GetExpendData(m.type)
2021-06-01 19:47:54 +08:00
local redPoint = false
if v.privilegeId then
2024-09-06 10:38:56 +08:00
redPoint = RecruitManager.GetRecruitBtnRedpoint(m.type, v.privilegeId)
2021-06-01 19:47:54 +08:00
else
redPoint = RecruitManager.GetRecruitBtnRedpoint(m.type)
end
redPot:SetActive(redPoint)
2020-05-25 19:16:23 +08:00
if isFree then --若1按钮有免费次数 后面逻辑不走了
2024-09-06 10:38:56 +08:00
info.text = Language[10588]
2020-05-25 19:16:23 +08:00
else
2024-09-06 10:38:56 +08:00
itemId = d[1]
itemNum = d[2]
icon.sprite = this.spLoader:LoadSprite(artResourcesConfig[itemConfig[itemId].ResourceID].Name)
num.text = "×" .. itemNum
2020-05-25 19:16:23 +08:00
end
2024-09-06 10:38:56 +08:00
Util.AddOnceClick(btn, function()
2020-05-25 19:16:23 +08:00
if not isFree then
2024-09-06 10:38:56 +08:00
if BagManager.GetItemCountById(itemId) < d[2] then
PopupTipPanel.ShowTip(GetLanguageStrById(itemConfig[itemId].Name) .. Language[10584])
2020-05-25 19:16:23 +08:00
return
end
end
2024-09-06 10:38:56 +08:00
local state = PlayerPrefs.GetInt(PlayerManager.uid .. "GeneralPopup_RecruitConfirm" .. RecruitType.Ten)
if n == bType.Btn1 then
if PrivilegeManager.GetPrivilegeUsedTimes(maxTimesId) + 1 > privilegeConfig[maxTimesId].Condition[1][2] then
2024-08-29 21:36:51 +08:00
PopupTipPanel.ShowTip(Language[10587])
2020-05-25 19:16:23 +08:00
return
end
2020-07-28 15:24:11 +08:00
--抽卡
local recruitOne = function()
RecruitManager.RecruitRequest(m.type, function(msg)
2024-09-06 10:38:56 +08:00
PrivilegeManager.RefreshPrivilegeUsedTimes(maxTimesId, 1) --记录抽卡次数
UIManager.OpenPanel(UIName.SingleRecruitPanel, msg.drop.Hero[1], m.type, bType.Btn1,
{ v.btn[bType.Btn1].type, v.btn[bType.Btn10].type })
end, v.privilegeId)
2020-07-28 15:24:11 +08:00
end
2024-09-06 10:38:56 +08:00
if state == 0 and d[1] == 16 and not isFree then
UIManager.OpenPanel(UIName.GeneralPopup, GENERAL_POPUP_TYPE.RecruitConfirm, RecruitType.Single,
recruitOne)
2020-07-28 15:24:11 +08:00
else
recruitOne()
end
2024-09-06 10:38:56 +08:00
elseif n == bType.Btn10 then
if PrivilegeManager.GetPrivilegeUsedTimes(maxTimesId) + 10 > privilegeConfig[maxTimesId].Condition[1][2] then
2024-08-29 21:36:51 +08:00
PopupTipPanel.ShowTip(Language[10587])
2020-05-25 19:16:23 +08:00
return
end
2020-07-28 15:24:11 +08:00
--抽卡
local recruitTen = function()
RecruitManager.RecruitRequest(m.type, function(msg)
2024-09-06 10:38:56 +08:00
PrivilegeManager.RefreshPrivilegeUsedTimes(maxTimesId, 10) --记录抽卡次数
UIManager.OpenPanel(UIName.SingleRecruitPanel, msg.drop.Hero, m.type, bType.Btn10,
{ v.btn[bType.Btn10].type, v.btn[bType.Btn10].type })
2020-07-28 15:24:11 +08:00
if m.type == 11 then
RecruitManager.isTenRecruit = 1
end
2024-09-06 10:38:56 +08:00
end, v.privilegeId)
2020-07-28 15:24:11 +08:00
end
2024-09-06 10:38:56 +08:00
if state == 0 and d[1] == 16 and not isFree then
UIManager.OpenPanel(UIName.GeneralPopup, GENERAL_POPUP_TYPE.RecruitConfirm, RecruitType.Ten,
recruitTen)
2020-07-28 15:24:11 +08:00
else
recruitTen()
end
2020-05-25 19:16:23 +08:00
end
end)
end
end
2020-09-25 14:11:05 +08:00
this.TimeCountDown()
2024-09-06 10:38:56 +08:00
local num = BagManager.GetItemCountById(lotterySetting[RecruitType.RecruitBox].CostItem[1][1])
RecruitManager.isCanOpenBox = num >= lotterySetting[RecruitType.RecruitBox].CostItem[1][2]
this.slider.fillAmount = num / lotterySetting[RecruitType.RecruitBox].CostItem[1][2]
2020-05-25 19:16:23 +08:00
this.sliderText.text = string.format("%s/%s", num, lotterySetting[RecruitType.RecruitBox].CostItem[1][2])
2024-09-06 10:38:56 +08:00
Util.GetGameObject(this.transform, "rewardBox/content/boxIcon"):GetComponent("Animator").enabled = RecruitManager
.isCanOpenBox
2020-05-25 19:16:23 +08:00
this.UI_effect_RecruitPanel_box_normal:SetActive(not RecruitManager.isCanOpenBox)
this.tenTip:SetActive(true)
if RecruitManager.isTenRecruit == 0 then
2024-08-29 21:36:51 +08:00
this.tenTipText.text = Language[12585]
else
2024-09-06 10:38:56 +08:00
this.tenTipText.text = string.format(Language[12586], RecruitManager.GetRecruit3MustCount())
end
2024-09-06 10:38:56 +08:00
this.upper.text = Language[10596] ..
PrivilegeManager.GetPrivilegeUsedTimes(maxTimesId) ..
"/" .. privilegeConfig[maxTimesId].Condition[1][2] --特权上限
2020-05-09 13:31:21 +08:00
end
2020-05-25 19:16:23 +08:00
function this.TimeCountDown()
if this.timer then
this.timer:Stop()
this.timer = nil
end
2024-09-06 10:38:56 +08:00
local timeDown = CalculateSecondsNowTo_N_OClock(0)
timeList[1].timeObj.text = Language[10026] .. TimeToHMS(timeDown)
timeList[2].timeObj.text = Language[10026] .. TimeToHMS(timeDown)
2020-05-25 19:16:23 +08:00
this.timer = Timer.New(function()
if timeDown < 1 then
this.timer:Stop()
this.timer = nil
--结束逻辑
2020-05-09 13:31:21 +08:00
2020-05-25 19:16:23 +08:00
return
end
timeDown = timeDown - 1
2024-09-06 10:38:56 +08:00
timeList[1].timeObj.text = Language[10026] .. TimeToHMS(timeDown)
timeList[2].timeObj.text = Language[10026] .. TimeToHMS(timeDown)
2020-05-25 19:16:23 +08:00
end, 1, -1, true)
this.timer:Start()
2020-05-09 13:31:21 +08:00
end
2024-09-06 10:38:56 +08:00
return RecruitPanel