miduo_client/Assets/ManagedResources/~Lua/Modules/Popup/SupremeHeroPopup.lua

326 lines
10 KiB
Lua
Raw Normal View History

2020-08-25 15:46:38 +08:00
require("Base/BasePanel")
2020-05-09 13:31:21 +08:00
SupremeHeroPopup = Inherit(BasePanel)
local this=SupremeHeroPopup
local artResConfig = ConfigManager.GetConfig(ConfigName.ArtResourcesConfig)
local heroConfig = ConfigManager.GetConfig(ConfigName.HeroConfig)
local activityConfig = ConfigManager.GetConfig(ConfigName.ActivityRewardConfig)
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
local live2dResName = ""
local heroId = 0
local heroData = {}
local actIsOpen = false
local finishedNum = 0
local missionData = {}
local idList = {
[1] = 30,
[2] = 31,
[3] = 32,
}
local orginLayer = 0
-- 界面是否可以关闭
local canClose = false
---剑影迷踪
--初始化组件(用于子类重写)
function SupremeHeroPopup:InitComponent()
orginLayer = 0
this.panel = Util.GetGameObject(self.gameObject,"Panel")
this.middle = Util.GetGameObject(this.panel,"Middle")
this.doneBtn = Util.GetGameObject(this.middle,"DoneBtn")
this.btnText = Util.GetGameObject(this.doneBtn, "Text"):GetComponent("Text")
this.previewBtn = Util.GetGameObject(this.middle, "PreviewBtn")
this.taskProgress = Util.GetGameObject(this.middle, "di/TaskProgress"):GetComponent("Text")--完成进度
2020-08-17 15:59:33 +08:00
this.tipText = Util.GetGameObject(this.middle, "textTime (1)"):GetComponent("Text")
2020-05-09 13:31:21 +08:00
this.click = Util.GetGameObject(this.middle, "PreviewBtn/click")
2020-06-08 13:57:30 +08:00
this.clickName = Util.GetGameObject(this.middle, "PreviewBtn/di/Name"):GetComponent("Text")
2020-08-17 15:59:33 +08:00
this.proImage = Util.GetGameObject(this.middle, "PreviewBtn/di/Image"):GetComponent("Image")
2020-05-09 13:31:21 +08:00
this.rewardTitle = {}--奖励要求
this.rewardBtn = {}--奖励前往按钮
this.doneImg = {}
this.iconGrid = {}
this.itemTitle = {}
this.itemList = {}
this.btnGet={}
2020-05-09 13:31:21 +08:00
for i = 1, 3 do
this.rewardTitle[i] = Util.GetGameObject(this.middle, "Reward/Panel".. i .."/Button/Text"):GetComponent("Text")
this.rewardBtn[i] = Util.GetGameObject(this.middle, "Reward/Panel".. i .."/Button")
this.iconGrid[i] = Util.GetGameObject(this.middle, "Reward/Panel".. i .."/frame")
this.doneImg[i] = Util.GetGameObject(this.middle, "Reward/Panel".. i .. "/doneImg")
this.btnGet[i] = Util.GetGameObject(this.middle, "Reward/Panel".. i .. "/BtnGet")
2020-05-09 13:31:21 +08:00
this.itemTitle[i] = Util.GetGameObject(this.middle, "Reward/Panel".. i .."/Image/Title"):GetComponent("Text")
end
this.activityTime = Util.GetGameObject(self.gameObject, "Panel/Middle/freshTime"):GetComponent("Text")--活动时间
this.backBtn = Util.GetGameObject(self.gameObject, "Panel/btnBack")
2020-08-24 16:07:08 +08:00
this.effectRoot = Util.GetGameObject(self.gameObject, "effect (1)")
2020-05-09 13:31:21 +08:00
2020-08-24 16:07:08 +08:00
effectAdapte(Util.GetGameObject(this.effectRoot, "Partical"))
effectAdapte(Util.GetGameObject(this.effectRoot, "Particle (1)"))
effectAdapte(Util.GetGameObject(this.effectRoot, "saoguang"))
effectAdapte(Util.GetGameObject(this.effectRoot, "saoguang (2)"))
-- effectAdapte(Util.GetGameObject(this.effectRoot, "normal/kuang03/biankuang03"))
-- effectAdapte(Util.GetGameObject(this.effectRoot, "normal/kuang03/saoguang03"))
2020-05-09 13:31:21 +08:00
this.LoadLive2D()
end
function SupremeHeroPopup:OnSortingOrderChange()
Util.AddParticleSortLayer(this.effectRoot, self.sortingOrder - orginLayer)
orginLayer = self.sortingOrder
end
function this.LoadLive2D()
-- 加载一个立绘
this.live2d = nil
local liveId = ActivityGiftManager.GetActivityDataById(42).Drawing
heroId = liveId or 10011
liveId = heroConfig[heroId].Live
2020-06-08 13:57:30 +08:00
this.clickName.text = heroConfig[heroId].ReadingName
2020-08-17 15:59:33 +08:00
this.tipText.text = Language[12293] .. heroConfig[heroId].ReadingName
2020-05-09 13:31:21 +08:00
live2dResName = artResConfig[liveId].Name
2020-08-17 15:59:33 +08:00
this.proImage.sprite = Util.LoadSprite(GetProStrImageByProNum(heroConfig[heroId].PropertyName))
2020-05-09 13:31:21 +08:00
end
-- 注册三个跳转事件
local jumpEvnt = {
[1] = function()
JumpManager.GoJump(26082)
end,
[2] = function()
2020-06-23 18:36:24 +08:00
PopupTipPanel.ShowTip(Language[11608])
2020-05-09 13:31:21 +08:00
end,
[3] = function ()
JumpManager.GoJump(36004)
end,
}
--绑定事件(用于子类重写)
function SupremeHeroPopup:BindEvent()
--返回按钮
Util.AddClick(this.backBtn,function()
if not canClose then return end
self:ClosePanel()
end)
--完成按钮
Util.AddClick(this.doneBtn,function()
if actIsOpen then
if this.GetRewardState() == 2 then
2020-08-24 16:07:08 +08:00
NetManager.GetActivityRewardRequest(0, ActivityTypeDef.SupremeHero, function (drop)
2020-05-09 13:31:21 +08:00
UIManager.OpenPanel(UIName.RewardItemPopup, drop, 1)
for i = 1, #missionData do
missionData[i] = 3
end
Util.SetGray(this.doneBtn, true)
this.doneBtn:GetComponent("Button").enabled = false
2020-06-23 18:36:24 +08:00
this.btnText.text = Language[10350]
2020-05-09 13:31:21 +08:00
CheckRedPointStatus(RedPointType.SupremeHero)
end)
end
else
2020-06-23 18:36:24 +08:00
PopupTipPanel.ShowTip(Language[10029])
2020-05-09 13:31:21 +08:00
end
end)
--预览按钮
Util.AddClick(this.previewBtn,function()
UIManager.OpenPanel(UIName.RoleGetInfoPopup, false, heroId, heroData.Star)
end)
--各任务前往按钮
for i = 1, #this.rewardBtn do
Util.AddClick(this.rewardBtn[i],function()
if this.GetMissionState(i) == 0 then
2020-05-09 13:31:21 +08:00
Game.GlobalEvent:DispatchEvent(GameEvent.PatFace.PatFaceClear)
jumpEvnt[i]()
self:ClosePanel()
end
end)
end
Util.AddClick(this.click, function()
UIManager.OpenPanel(UIName.RoleGetInfoPopup, false, heroId, heroData.Star)
end)
end
--添加事件监听(用于子类重写)
function SupremeHeroPopup:AddListener()
end
--移除事件监听(用于子类重写)
function SupremeHeroPopup:RemoveListener()
end
--界面打开时调用(用于子类重写)
local fun = nil
function SupremeHeroPopup:OnOpen(_fun)
fun = _fun
end
function SupremeHeroPopup:OnShow()
actIsDone = false
--初始化静态显示数据
this.InitShow()
canClose = false
this.effectTime = nil
this.effectTime = Timer.New(function ()
canClose = true
end, 1.2)
this.effectTime:Start()
end
function this.InitShow()
ActivityGiftManager.isFirstForSupremeHero=true
CheckRedPointStatus(RedPointType.SupremeHero)
heroData = heroConfig[heroId]
-- 获取任务完成状态
local total = 3
finishedNum, missionData = ActivityGiftManager.GetTaskData()
this.SetMissionData()
actIsOpen = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.SupremeHero) > 0
local color = finishedNum < total and "#FF0000FF" or "#F4D98AFF"
this.taskProgress.text = string.format(" <color=%s>%s</color>/3", color, finishedNum)
Util.SetGray(this.doneBtn, this.GetRewardState() ~= 2)
this.doneBtn:GetComponent("Button").enabled = this.IsMissionDone()
local textList = {
2020-06-23 18:36:24 +08:00
[1] = Language[10366],
[2] = Language[10022],
[3] = Language[10350],
2020-05-09 13:31:21 +08:00
}
this.btnText.text = textList[this.GetRewardState()]
-- 设置图标显示
this.SetIconAndTitle()
-- 开始倒计时
local endTime = ActivityGiftManager.GetTaskEndTime(ActivityTypeDef.SupremeHero)
this.activityTime.text = ""
if not this.timer then
this.timer = Timer.New(function ()
local tempTime = endTime - PlayerManager.serverTime
if tempTime > 0 then
if tempTime>= 86400 then
this.activityTime.text = TimeToDH(tempTime)
else
this.activityTime.text = TimeToHMS(tempTime)
end
2020-05-09 13:31:21 +08:00
else
2020-06-23 18:36:24 +08:00
this.activityTime.text = Language[10124]
2020-05-09 13:31:21 +08:00
Util.SetGray(this.doneBtn, true)
this.doneBtn:GetComponent("Button").enabled = false
this.timer:Stop()
end
end, 1, -1, true)
end
this.timer:Start()
end
function this.SetIconAndTitle()
for i = 1, 3 do
local actData = activityConfig[idList[i]]
this.itemTitle[i].text = actData.ContentsShow
if actData.ExtraParm == 0 then
2020-06-23 18:36:24 +08:00
Log(string.format(Language[11609], idList[i]))
Log(Language[11610])
2020-05-09 13:31:21 +08:00
return
end
local itemId = actData.ExtraParm
if not this.itemList[i] then
this.itemList[i] = SubUIManager.Open(SubUIConfig.ItemView, this.iconGrid[i].transform)
end
this.itemList[i]:OnOpen(false, {itemId, 0}, 0.92)
end
end
-- 活动是否完成
function this.IsMissionDone()
return finishedNum == 3
end
function this.SetMissionData()
local data= ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.SupremeHero)
2020-05-09 13:31:21 +08:00
for i = 1, 3 do
this.rewardBtn[i]:SetActive(this.GetMissionState(i) == 0)
2020-08-24 18:24:42 +08:00
this.doneImg[i]:SetActive(this.GetMissionState(i) == 1)
this.btnGet[i]:SetActive(false)
if i == 3 then
2020-08-24 16:07:08 +08:00
this.btnGet[i]:SetActive(this.GetMissionState(i) == 3)
Util.AddOnceClick(this.btnGet[i],function()
NetManager.GetActivityRewardRequest(data.mission[i].missionId, data.activityId,function(drop)
UIManager.OpenPanel(UIName.RewardItemPopup,drop,1,function()
this.InitShow()
end)
end)
end)
end
2020-05-09 13:31:21 +08:00
end
end
function this.GetMissionState(index)
return missionData[index]
2020-05-09 13:31:21 +08:00
end
function this.GetRewardState()
if not this.IsMissionDone() then
return 1
else
local doneNum = 0
for i = 1, 3 do
if missionData[i] == 2 then
doneNum = doneNum + 1
end
end
local state = doneNum == 3 and 3 or 2
return state
end
end
--界面关闭时调用(用于子类重写)
function SupremeHeroPopup:OnClose()
if this.timer then
this.timer:Stop()
this.timer = nil
end
if this.effectTime then
this.effectTime:Stop()
this.effectTime = nil
end
if PlayerPrefs.GetInt(PlayerManager.uid .. "SUPREME") == 0 then
PlayerPrefs.SetInt(PlayerManager.uid .. "SUPREME", 1)
end
if fun then
fun()
fun = nil
end
this.itemList = {}
end
--界面销毁时调用(用于子类重写)
function SupremeHeroPopup:OnDestroy()
--if this.live2d then
-- poolManager:UnLoadLive(live2dResName, this.live2d)
-- this.live2d = nil
--end
end
2020-06-23 18:36:24 +08:00
return SupremeHeroPopup