425 lines
13 KiB
Lua
425 lines
13 KiB
Lua
local UIBattleSuccessView = require("UIBattle/UIBattleSuccessView_Generate")
|
||
|
||
--region 生命周期
|
||
|
||
|
||
-- ManagerContainer.DataMgr.DanmuData:
|
||
function UIBattleSuccessView:OnAwake(data)
|
||
self.controller = require("UIBattle/UIBattleSuccessCtr"):new()
|
||
self.controller:Init(self)
|
||
self.controller:SetData(data)
|
||
end
|
||
|
||
|
||
function UIBattleSuccessView:FillContent(data, uiBase)
|
||
self.uiBase = uiBase
|
||
local gameObject = self.uiBase:GetRoot()
|
||
if gameObject ~= nil then
|
||
self.gameObject = gameObject
|
||
self.transform = gameObject.transform
|
||
end
|
||
self:InitGenerate(self.transform, data)
|
||
|
||
self:Init()
|
||
end
|
||
|
||
function UIBattleSuccessView:Init()
|
||
for i = 1, 4 do
|
||
self["role"..i]:SetActive(false)
|
||
end
|
||
local teams = ManagerContainer.DataMgr.UserData:GetTeamData(true)
|
||
for i=1, #teams do
|
||
local roleData = teams[i]
|
||
self["role"..i]:SetActive(true)
|
||
CommonUtil.LoadIcon(self, "HeroDraw/Role_"..roleData.uid, function(sprite)
|
||
self["role"..i].image.sprite = sprite
|
||
end)
|
||
end
|
||
|
||
self:ShowRewardData()
|
||
|
||
--[[
|
||
local danmuPlayerGo = self.transform:Find("Panel/CommentArea/MyDanmuPlayer")
|
||
self.danmuPlayerComp = danmuPlayerGo:GetComponent("MyDanmuPlayer")
|
||
local danmuList = {
|
||
"AAAAAAAAAAA111", "VVVVVVVVVV222", "DDDDDDDDDDD333", "FFFFFFFFF444", "EEEEEEEEE555",
|
||
"AAAAAAAAAAA111", "VVVVVVVVVV222", "DDDDDDDDDDD333", "FFFFFFFFF444", "EEEEEEEEE555",
|
||
"AAAAAAAAAAA111", "VVVVVVVVVV222", "DDDDDDDDDDD333", "FFFFFFFFF444", "EEEEEEEEE555",
|
||
"AAAAAAAAAAA111", "VVVVVVVVVV222", "DDDDDDDDDDD333", "FFFFFFFFF444", "EEEEEEEEE555",
|
||
"AAAAAAAAAAA111", "VVVVVVVVVV222", "DDDDDDDDDDD333", "FFFFFFFFF444", "EEEEEEEEE555",
|
||
"AAAAAAAAAAA111", "VVVVVVVVVV222", "DDDDDDDDDDD333", "FFFFFFFFF444", "EEEEEEEEE555",
|
||
"AAAAAAAAAAA111", "VVVVVVVVVV222", "DDDDDDDDDDD333", "FFFFFFFFF444", "EEEEEEEEE555",
|
||
"AAAAAAAAAAA111", "VVVVVVVVVV222", "DDDDDDDDDDD333", "FFFFFFFFF444", "EEEEEEEEE555",
|
||
"AAAAAAAAAAA111", "VVVVVVVVVV222", "DDDDDDDDDDD333", "FFFFFFFFF444", "EEEEEEEEE555",
|
||
}
|
||
self.danmuPlayerComp:ResetPlayer()
|
||
self.danmuPlayerComp:Play(
|
||
danmuList, 10,
|
||
function()
|
||
LogError("Danmu Play Ntf")
|
||
end,
|
||
function()
|
||
LogError("Danmu Play Finished")
|
||
end
|
||
)
|
||
]]
|
||
local canEnterAutoMode = self:CanCurrLevelEnterAutoMode()
|
||
LogWarning("自动战斗 "..tostring(canEnterAutoMode))
|
||
self.flag = 3
|
||
if canEnterAutoMode then
|
||
self.currAutoMode = ManagerContainer.LuaBattleMgr:GetAutoChallengeState()
|
||
self:AutoBatlle(self.currAutoMode)
|
||
else
|
||
ManagerContainer.LuaBattleMgr:StopAutoChallenge()
|
||
self.currAutoMode = false
|
||
self:AutoBatlle(self.currAutoMode)
|
||
end
|
||
|
||
|
||
|
||
end
|
||
|
||
function UIBattleSuccessView:CanCurrLevelEnterAutoMode()
|
||
local curMapId, curLevelId = ManagerContainer.LuaBattleMgr:GetCurMapAndLevel()
|
||
local mapLevel = curMapId * 10000 + curLevelId
|
||
local storyCfgV2 = ManagerContainer.CfgMgr:GetStoryCfgV2()
|
||
local storyTaskCfgV2 = ManagerContainer.CfgMgr:GetStoryTaskCfgV2()
|
||
local currStoryId = 10
|
||
local levelDiff = 100000
|
||
|
||
local levelData = ManagerContainer.CfgMgr:GetLevelDataById(mapLevel)
|
||
if levelData.DlgId > 0 or levelData.ForceGuideGroup > 0 then
|
||
return false
|
||
end
|
||
|
||
local keys = {}
|
||
for k in pairs(storyCfgV2) do
|
||
if type(k) == "number" then
|
||
table.insert(keys, k)
|
||
end
|
||
end
|
||
table.sort(keys)
|
||
|
||
--此处设置currStoryId和tmpMapLevel
|
||
--选择MapLevel最接近但不大于当前mapLevel的故事
|
||
for _, k in ipairs(keys) do
|
||
local v = storyCfgV2[k]
|
||
if v.MapLevel - mapLevel > 0 and v.MapLevel - mapLevel < levelDiff then
|
||
currStoryId = v.StoryId
|
||
levelDiff = v.MapLevel - mapLevel
|
||
end
|
||
end
|
||
--LogError("[RefreshStoryTaskInfo] currStoryId="..currStoryId..", levelDiff="..levelDiff)
|
||
|
||
--此处设置currTaskId,基于currStoryId从storyTaskCfgV2中查找相同的StoryId,返回id
|
||
local currTaskId = 0
|
||
for k, v in pairs(storyTaskCfgV2) do
|
||
if v.StoryId == currStoryId then
|
||
currTaskId = v.Id
|
||
end
|
||
end
|
||
if currTaskId == 0 then
|
||
LogError("[Err] RefreshStoryTaskInfo currStoryId=" .. currStoryId)
|
||
return
|
||
end
|
||
|
||
--获取后两个的StoryId和TaskId
|
||
local next1TaskId = currTaskId + 1
|
||
local next2TaskId = currTaskId + 2
|
||
local next1StoryId = storyTaskCfgV2[next1TaskId].StoryId
|
||
local next2StoryId = storyTaskCfgV2[next2TaskId].StoryId
|
||
--LogError(string.format("mapLevel=%s currTaskId=%s currStoryId=%s next1StoryId=%s next2StoryId=%s", mapLevel, currTaskId, currStoryId, next1StoryId, next2StoryId))
|
||
local subTasksFinishInfo = {}
|
||
|
||
local subLevelId = 0
|
||
for k, v in pairs(storyTaskCfgV2[currTaskId].SubTasks) do
|
||
local t = v[1]
|
||
local val = v[2]
|
||
local isFinish = false
|
||
local txt = ""
|
||
-- 子任务列表(1:关卡;2:炼之塔层数;3:StoryNpcId;4:StoryId;5:玩家等级)
|
||
if t == 1 then
|
||
if mapLevel > val then
|
||
isFinish = true
|
||
end
|
||
local levelData = ManagerContainer.CfgMgr:GetLevelDataById(val)
|
||
local bossId = levelData.BossId
|
||
local npcId = math.floor(bossId / 1000)
|
||
local npcData = ManagerContainer.CfgMgr:GetNpcCfgById(npcId)
|
||
subLevelId = subLevelId + 1
|
||
txt = string.format("关卡%s-%s: 击败BOSS【%s】", math.floor(currStoryId / 10), subLevelId, npcData["Name"])
|
||
elseif t == 2 then
|
||
local climbingTowerLv = ManagerContainer.DataMgr.TowerDataMgr:GetCurChallengeLevel()
|
||
if climbingTowerLv > val then
|
||
isFinish = true
|
||
end
|
||
elseif t == 3 then
|
||
local storyNpcId = val
|
||
local storyNpcCfg = ManagerContainer.CfgMgr:GetStoryNpcCfgByChatNpcId(tonumber(storyNpcId))
|
||
local storyId = storyNpcCfg.StoryId
|
||
txt = string.format("去MOMO撩一下女神【%s】", I18N.T(storyNpcCfg.NameKey))
|
||
if ManagerContainer.DataMgr.StoryData:IsStoryPlay(storyId) then
|
||
isFinish = true
|
||
end
|
||
elseif t == 4 then
|
||
local storyNpcId = val
|
||
local storyNpcCfg = ManagerContainer.CfgMgr:GetStoryNpcCfgByChatNpcId(tonumber(storyNpcId))
|
||
txt = string.format("回复【%s】发来的消息", I18N.T(storyNpcCfg.NameKey))
|
||
local currLevelData = ManagerContainer.CfgMgr:GetLevelDataById(mapLevel)
|
||
local storyId = currLevelData.DlgId
|
||
LogError("[RefreshStoryTaskInfo] mapLevel="..mapLevel..", storyId="..storyId)
|
||
if ManagerContainer.DataMgr.StoryData:IsStoryPlay(storyId) or storyId==0 then
|
||
isFinish = true
|
||
end
|
||
elseif t == 5 then
|
||
local curLv = ManagerContainer.DataMgr.UserData:GetRoleLv()
|
||
if curLv > val then
|
||
isFinish = true
|
||
end
|
||
end
|
||
|
||
table.insert(subTasksFinishInfo, { type = t, txt = txt, isFinish = isFinish })
|
||
end
|
||
local currTaskShowData = {
|
||
title = storyCfgV2[currStoryId].StoryTitle,
|
||
subTasksFinishInfo = subTasksFinishInfo
|
||
}
|
||
local next1TaskShowData = {
|
||
title = storyCfgV2[next1StoryId].StoryTitle,
|
||
subTasksFinishInfo = {}
|
||
}
|
||
local next2TaskShowData = {
|
||
title = storyCfgV2[next2StoryId].StoryTitle,
|
||
subTasksFinishInfo = {}
|
||
}
|
||
|
||
local firstUnfinishId = 0
|
||
for i = 1, #currTaskShowData.subTasksFinishInfo do
|
||
if currTaskShowData.subTasksFinishInfo[i].isFinish == false then
|
||
firstUnfinishId = i
|
||
break
|
||
end
|
||
end
|
||
local showDatas = {}
|
||
if firstUnfinishId > 0 then
|
||
table.insert(showDatas, currTaskShowData.subTasksFinishInfo[firstUnfinishId])
|
||
end
|
||
local step = 1
|
||
local loops = 0
|
||
while true do
|
||
local preId = firstUnfinishId - step
|
||
local postId = firstUnfinishId + step
|
||
if preId >= 1 then
|
||
table.insert(showDatas, 1, currTaskShowData.subTasksFinishInfo[preId])
|
||
end
|
||
if postId <= #currTaskShowData.subTasksFinishInfo then
|
||
table.insert(showDatas, currTaskShowData.subTasksFinishInfo[postId])
|
||
end
|
||
if preId < 1 and postId > #currTaskShowData.subTasksFinishInfo then
|
||
break
|
||
end
|
||
step = step + 1
|
||
loops = loops + 1
|
||
if loops > 10000 then break end
|
||
end
|
||
if loops > 10000 then
|
||
LogError("ERR: UIBattle RefreshStoryTaskInfo loops > 10000")
|
||
end
|
||
|
||
local maxRow = #showDatas
|
||
if maxRow > 5 then maxRow = 5 end
|
||
if currTaskShowData.subTasksFinishInfo[firstUnfinishId] then
|
||
local taskType = currTaskShowData.subTasksFinishInfo[firstUnfinishId].type
|
||
if taskType == 1 then
|
||
return true
|
||
end
|
||
end
|
||
return false
|
||
end
|
||
|
||
function UIBattleSuccessView:AddEventListener()
|
||
ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
|
||
ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.EID_DANMU_INPUT_NTF, self, self.OnDanmuInputNtf)
|
||
|
||
end
|
||
|
||
function UIBattleSuccessView:RemoveEventListener()
|
||
ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
|
||
end
|
||
|
||
function UIBattleSuccessView:AddUIEventListener()
|
||
self.uiBase:AddButtonEventListener(self.backBtn.button,self, self.OnBackBtn)
|
||
self.uiBase:AddButtonEventListener(self.btnSendDanmu.button,self, self.OnBtnSendDanmu)
|
||
|
||
self.uiBase:AddButtonUniqueEventListener(self.btn_autofight.button, self, function()
|
||
if self.timerId ~= nil then
|
||
self.flag = 3
|
||
ManagerContainer.LuaTimerMgr:RemoveTimer(self.timerId)
|
||
self.timerId = nil
|
||
end
|
||
LogWarning("自动战斗c "..tostring(self.currAutoMode))
|
||
if self.currAutoMode then
|
||
ManagerContainer.LuaBattleMgr:StopAutoChallenge()
|
||
ManagerContainer.LuaBattleMgr:SetAutoChallengeState(false)
|
||
self.currAutoMode = false
|
||
self:AutoBatlle(false)
|
||
else
|
||
if not ManagerContainer.DataMgr.RuneShopDataMgr:CheckSuperMonth() then
|
||
ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("nomonthcard")
|
||
ManagerContainer.LuaBattleMgr:StopAutoChallenge()
|
||
return
|
||
end
|
||
if canEnterAutoMode == false then
|
||
ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("CannotAutoBattle")
|
||
return
|
||
end
|
||
if ManagerContainer.LuaBattleMgr:GetAutoChallengeState() then
|
||
ManagerContainer.LuaBattleMgr:StopAutoChallenge()
|
||
else
|
||
ManagerContainer.LuaBattleMgr:SetAutoChallengeState(true)
|
||
self.currAutoMode = true
|
||
self:AutoBatlle(true)
|
||
end
|
||
end
|
||
end)
|
||
end
|
||
|
||
function UIBattleSuccessView:OnHide()
|
||
|
||
end
|
||
|
||
function UIBattleSuccessView:OnShow(data)
|
||
self.controller:SetData(data)
|
||
|
||
end
|
||
|
||
function UIBattleSuccessView:OnClose()
|
||
end
|
||
|
||
function UIBattleSuccessView:OnDispose()
|
||
self.controller:OnDispose()
|
||
end
|
||
|
||
--endregion 生命周期
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
function UIBattleSuccessView:OnBtnSendDanmu()
|
||
ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIDanmuInput, "UIBattleSuccess")
|
||
end
|
||
|
||
function UIBattleSuccessView:OnDanmuInputNtf(uiName, danmuStr)
|
||
if uiName == "UIBattleSuccess" then
|
||
LogError("[UIBattleSuccessView] OnDanmuInputNtf "..danmuStr)
|
||
self.danmuPlayerComp:PlayMySelf(danmuStr)
|
||
end
|
||
end
|
||
|
||
|
||
|
||
function UIBattleSuccessView:ShowRewardData()
|
||
local awardDatas = {}
|
||
local inputData = self.controller:GetData()
|
||
for k, v in pairs(inputData) do
|
||
if v.key ~= 4 then
|
||
table.insert(awardDatas, {cfgId = v.key, num = v.value})
|
||
end
|
||
end
|
||
CommonUtil.LoopGridViewEleCreateNew(
|
||
self, self.awardScrollView.loopHorizontalScrollRect,
|
||
self.awardContent.gridLayoutGroup,
|
||
awardDatas, 0, self, self.SetAwardItem
|
||
)
|
||
end
|
||
|
||
function UIBattleSuccessView:SetAwardItem(itemLua, idx, itemData)
|
||
CommonUtil.UpdateItemPrefab(self, itemLua, itemData, Enum.ItemIEnterType.Bag, self, self.ShowItemTips)
|
||
end
|
||
|
||
function UIBattleSuccessView:ShowItemTips(button, params)
|
||
local data = params[0]
|
||
ManagerContainer.LuaUIMgr:OpenTips(data)
|
||
end
|
||
|
||
function UIBattleSuccessView:OnBackBtn()
|
||
if self.timerId ~= nil then
|
||
ManagerContainer.LuaTimerMgr:RemoveTimer(self.timerId)
|
||
self.timerId = nil
|
||
end
|
||
if ManagerContainer.LuaBattleMgr:GetAutoChallengeState() then
|
||
ManagerContainer.LuaBattleMgr:StopAutoChallenge()
|
||
end
|
||
|
||
ManagerContainer.LuaUIMgr:ClosePage(self.uiBase.PageId)
|
||
if ManagerContainer.UIFuncUnlockMgr:NeedOpenFuncCurLevelStart(ManagerContainer.LuaBattleMgr:GetCurLevelUniqueId()) then
|
||
ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UI_FUNCLOCK_OPEN_NTF)
|
||
end
|
||
ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_UI_RETURN_HOME, true)
|
||
--ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UI_FORCE_GUIDE_TRIGGER, Enum.ForceGuideTriggerEnum.BattleWin)
|
||
end
|
||
|
||
function UIBattleSuccessView:AutoBatlle(isauto)
|
||
if self.timerId ~= nil then
|
||
ManagerContainer.LuaTimerMgr:RemoveTimer(self.timerId)
|
||
LogError("remove self.timerId: ".. tostring(self.timerId))
|
||
self.timerId = nil
|
||
end
|
||
LogError("00000 isAuto3 "..tostring(isauto))
|
||
self.text_autofight:SetActive(false)
|
||
self.text_autofight_time:SetActive(false)
|
||
|
||
if isauto then
|
||
--按钮
|
||
--self.btn_autofight.button.interactable=false
|
||
self.btn_autofight.image.sprite=self.btn_autofight.switchSprite:GetSprite("img_result_btn_auto_fighting")
|
||
|
||
--文字
|
||
|
||
self.text_autofight_time.text.text = "("..self.flag.."S)"
|
||
self.text_autofight_time:SetActive(true)
|
||
|
||
self.flag = 3
|
||
self.timerId = ManagerContainer.LuaTimerMgr:AddTimer(1000, self.flag, self, self.TimerTick, nil)
|
||
LogError("start self.timerId: ".. tostring(self.timerId))
|
||
|
||
-- self.timerId = ManagerContainer.LuaTimerMgr:AddLuaTimer(1000, 4, function()
|
||
-- flag=flag-1
|
||
-- if self.text_autofight_time then
|
||
-- self.text_autofight_time.text.text = "(" .. flag .. "S)"
|
||
-- end
|
||
-- if flag==0 then
|
||
-- self:UIClose()
|
||
-- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_CHALLENGE_AUTO)
|
||
-- end
|
||
-- end)
|
||
|
||
else
|
||
--文字
|
||
self.text_autofight:SetActive(true)
|
||
|
||
--按钮
|
||
self.btn_autofight.image.sprite = self.btn_autofight.switchSprite:GetSprite("img_result_btn_auto_fight")
|
||
end
|
||
end
|
||
|
||
function UIBattleSuccessView:TimerTick()
|
||
self.flag = self.flag or 10
|
||
self.flag=self.flag-1
|
||
if self.text_autofight_time then
|
||
self.text_autofight_time.text.text = "(" .. self.flag .. "S)"
|
||
end
|
||
if self.flag==0 then
|
||
self:UIClose()
|
||
LogError("333333333333333333333")
|
||
ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_CHALLENGE_AUTO)
|
||
end
|
||
end
|
||
|
||
|
||
return UIBattleSuccessView
|
||
|