UINewbieBattleView.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. local UINewbieBattleView = require("UINewbie/UINewbieBattleView_Generate")
  2. function UINewbieBattleView:OnAwake(data)
  3. self.controller = require("UINewbie/UINewbieBattleCtr"):new()
  4. self.controller:Init(self)
  5. self.controller:SetData(data)
  6. end
  7. function UINewbieBattleView:AddEventListener()
  8. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Refresh_Boss_Life,self,self.OnRefreshBossLife);
  9. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Refresh_Boss_Skill,self,self.OnRefreshBossSkill);
  10. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Refresh_Boss_Buff,self,self.OnRefreshBossBuff);
  11. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Refresh_Boss_Remove_Buff,self,self.OnRefreshRemoveBossBuff);
  12. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Refresh_Cast_Skill,self,self.RefreshFighterSkill);
  13. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Refresh_Fighter_Life,self,self.RefreshFighterLife);
  14. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Refresh_Fighter_Sp,self,self.RefreshFighterSp);
  15. -- ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Show_Fighter,self,self.OnShowFighter)
  16. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_SHOW_SKIP_BATTLE,self,self.OnShowSkipBattle)
  17. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Set_UINode_Vis,self,self.OnSetUINodeVis)
  18. end
  19. function UINewbieBattleView:FillContent(data, uiBase)
  20. self.uiBase = uiBase
  21. local gameObject = self.uiBase:GetRoot()
  22. if gameObject ~= nil then
  23. self.gameObject = gameObject
  24. self.transform = gameObject.transform
  25. end
  26. self:InitGenerate(self.transform, data)
  27. self:Init()
  28. end
  29. function UINewbieBattleView:Init()
  30. self.skipBtn:SetActive(ManagerContainer.LuaBossBattleMgr.ShowSkip)
  31. self.minDeltaBlood = GlobalConfig.Instance:GetConfigFloatValue(137)
  32. self:SetData()
  33. self.bossBloodNode:SetActive(false)
  34. -- self.playerNode1:SetActive(false)
  35. self.playerNode2:SetActive(false)
  36. self.playerNode3:SetActive(false)
  37. self.playerNode4:SetActive(false)
  38. self.playerNode5:SetActive(false)
  39. self.playerNode6:SetActive(false)
  40. end
  41. function UINewbieBattleView:RemoveEventListener()
  42. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  43. end
  44. function UINewbieBattleView:AddUIEventListener()
  45. self.uiBase:AddButtonEventListener(self.skipBtn.button,self, self.OnClickSkipBattle)
  46. end
  47. function UINewbieBattleView:OnHide()
  48. end
  49. function UINewbieBattleView:OnShow(data)
  50. self.controller:SetData(data)
  51. self:Init()
  52. end
  53. function UINewbieBattleView:OnClose()
  54. self:ClearBattleSkillTimer()
  55. self.actorHeadMapping = nil
  56. if self.bossBuffLoadHandlers ~= nil then
  57. for k,p in pairs(self.bossBuffLoadHandlers) do
  58. if p > 0 then
  59. ManagerContainer.ResMgr:ClearUIAsyncLoadReqsBySeqId(p)
  60. end
  61. end
  62. self.bossBuffLoadHandlers = nil
  63. end
  64. if self.bossBuffs ~= nil then
  65. for i = 1, #self.bossBuffs do
  66. CommonUtil.DestroyGO(self.bossBuffs[i].go)
  67. end
  68. end
  69. if self.bossDebuffs ~= nil then
  70. for i = 1, #self.bossDebuffs do
  71. CommonUtil.DestroyGO(self.bossDebuffs[i].go)
  72. end
  73. end
  74. self.bossBuffs = nil
  75. self.bossDebuffs = nil
  76. end
  77. function UINewbieBattleView:OnDispose()
  78. end
  79. function UINewbieBattleView:SetData()
  80. self.lastLife = ManagerContainer.LuaBossBattleMgr.bossMaxLife
  81. self.bossBlood2.image.fillAmount = 1
  82. self.bossBlood.image.fillAmount = 1
  83. self.bossBloodNode.animator:Play("BossBloddShow")
  84. self:SetBossBattleInfo(ManagerContainer.LuaBossBattleMgr.bossName)
  85. self:OnRefreshBossSkill(ManagerContainer.LuaBossBattleMgr.bossSkillParam)
  86. end
  87. function UINewbieBattleView:SetBossBattleInfo(bossName)
  88. self.actorHeadMapping = {}
  89. self.bossBuffs = {}
  90. self.bossDebuffs = {}
  91. self.skillCDTimers = {}
  92. self.bossBuffLoadHandlers = {}
  93. local teamData = ManagerContainer.LuaGameMgr.newbieActors
  94. for i =0, teamData.Count-1 do
  95. local actor = teamData[i]
  96. local go = self:GetHeadGo(i+1)
  97. self.actorHeadMapping[i+1] = {id = actor.ID, headGo = go}
  98. self:SetPlayerData(go,actor)
  99. go:SetActive( i==0 )
  100. end
  101. self.bossName.text.text = bossName
  102. end
  103. function UINewbieBattleView:SetPlayerData(playerNode,actorData)
  104. self:SetPlayerHead(playerNode.headBoxItem.headNode,actorData)
  105. -- self:RefreshHPAndSp(playerNode.headBoxItem.barNode,actorData.Life,actorData.Life,actorData.Sp,actorData.Sp)
  106. self:SetCurSkillInfo(playerNode.headBoxItem.skillNode,actorData.CastSkillParam)
  107. playerNode.headBoxItem.deadNode:SetActive(false)
  108. playerNode.playerName.text.text = actorData.Name
  109. -- playerNode:SetActive(true)
  110. end
  111. function UINewbieBattleView:SetPlayerHead(headNode,actorData)
  112. if headNode == nil or actorData == nil then
  113. return
  114. end
  115. headNode.levelText.text.text = tostring(actorData.Level)
  116. CommonUtil.LoadIcon(self, actorData.ProfessionIcon, function (sprite)
  117. headNode.jobIcon.image.sprite = sprite
  118. end)
  119. CommonUtil.LoadIcon(self, actorData.HeadIcon, function (sprite)
  120. headNode.head.image.sprite = sprite
  121. end)
  122. end
  123. function UINewbieBattleView:SetCurSkillInfo(skillNode,skillInfo)
  124. CommonUtil.SetCurSkillInfo(skillNode,skillInfo,self,self.UpdateSkillCDTimer)
  125. end
  126. function UINewbieBattleView:UpdateSkillCDTimer(sequence,params)
  127. local skillParam = params.skillParam
  128. local totalTime = params.totalTime
  129. skillParam.cdTime = skillParam.cdTime - 0.1
  130. local leftTime = skillParam.cdTime;
  131. if leftTime < 0 then
  132. leftTime = 0
  133. end
  134. local headGo = self:GetActorHeadGo(skillParam.actorId)
  135. if headGo ~= nil then
  136. CommonUtil.UpdateSkillCD(headGo.headBoxItem.skillNode,leftTime,totalTime)
  137. end
  138. end
  139. function UINewbieBattleView:RefreshHPAndSp(barNode,hp,maxHp,sp,maxSp)
  140. if barNode == nil then
  141. return
  142. end
  143. if hp ~= nil and maxHp ~= nil then
  144. barNode.hp.image.fillAmount = hp/maxHp
  145. end
  146. if sp~=nil and maxSp~=nil then
  147. barNode.sp.image.fillAmount = sp/maxSp
  148. end
  149. end
  150. function UINewbieBattleView:RefreshFighterSkill(skillParam)
  151. if skillParam == nil then
  152. return
  153. end
  154. local headGo = self:GetActorHeadGo(skillParam.actorId)
  155. CommonUtil.SetFighterSkill(headGo.headBoxItem,skillParam,self,self.UpdateSkillCDTimer)
  156. end
  157. function UINewbieBattleView:RefreshFighterLife(actorId,life,maxLife)
  158. local headGo = self:GetActorHeadGo(actorId)
  159. if headGo ~= nil then
  160. self:RefreshHPAndSp(headGo.headBoxItem.barNode,life,maxLife,nil,nil)
  161. headGo.headBoxItem.deadNode:SetActive(life == 0)
  162. if life == 0 then
  163. headGo.headBoxItem.animator:Play("Dead")
  164. end
  165. end
  166. end
  167. function UINewbieBattleView:RefreshFighterSp(actorId,sp,maxSp)
  168. local headGo = self:GetActorHeadGo(actorId)
  169. if headGo ~= nil then
  170. self:RefreshHPAndSp(headGo.headBoxItem.barNode,nil,nil,sp,maxSp)
  171. end
  172. end
  173. function UINewbieBattleView:OnShowFighter(actorId)
  174. local headGo = self:GetActorHeadGo(actorId)
  175. if headGo ~= nil then
  176. headGo:SetActive(true)
  177. end
  178. end
  179. function UINewbieBattleView:GetActorHeadGo(actorId)
  180. if self.actorHeadMapping == nil then
  181. return nil
  182. end
  183. for i=1, #self.actorHeadMapping do
  184. if self.actorHeadMapping[i].id == actorId then
  185. return self.actorHeadMapping[i].headGo
  186. end
  187. end
  188. return nil
  189. end
  190. function UINewbieBattleView:GetHeadGo(idx)
  191. if idx == 1 then
  192. return self.playerNode1
  193. end
  194. if idx == 2 then
  195. return self.playerNode2
  196. end
  197. if idx == 3 then
  198. return self.playerNode3
  199. end
  200. if idx == 4 then
  201. return self.playerNode4
  202. end
  203. if idx == 5 then
  204. return self.playerNode5
  205. end
  206. if idx == 6 then
  207. return self.playerNode6
  208. end
  209. return nil
  210. end
  211. function UINewbieBattleView:OnRefreshBossLife(life,maxLife)
  212. local deltaLife = (self.lastLife - life)/maxLife
  213. if deltaLife>0 and deltaLife < self.minDeltaBlood and life > 0 then
  214. return
  215. end
  216. self.lastLife = life
  217. self.bossBlood.image.fillAmount = life / maxLife
  218. LuaBattleBridge.TweemFillAmount(self.bossBlood2,life / maxLife,0.5)
  219. if life == 0 then
  220. self.bossBloodNode.animator:Play("BossBloddClose");
  221. end
  222. end
  223. function UINewbieBattleView:OnRefreshBossSkill(skillParam)
  224. if self.bossSkillNode == nil or skillParam == nil then
  225. return
  226. end
  227. CommonUtil.LoadIcon(self, skillParam.skillIcon, function (sprite)
  228. self.bossSkillIcon.image.sprite = sprite
  229. end)
  230. self.bossSkillNode.forbidNode:SetActive(skillParam.IsForbidden)
  231. self.bossSkillNode.extraNode:SetActive(skillParam.IsEnhance)
  232. if skillParam.IsCasting then
  233. self.bossSkillProgress:SetActive(false)
  234. self.bossSkillCD:SetActive(false)
  235. self.bossSkillNode.releaseNode:SetActive(true)
  236. self.bossSkillNode.keepNode:SetActive(true)
  237. self.bossSkillNode.waitNode:SetActive(false)
  238. self:ClearBossSkillTimer()
  239. self.bossSkillNode.animator:Play("BossSkillRelease")
  240. else
  241. if skillParam.IsForbidden then
  242. self.bossSkillNode.animator:Play("SkillForbidden");
  243. else
  244. self.bossSkillNode.animator:Play("BossWait");
  245. end
  246. self:UpdateBossSkillCD(skillParam.cdTime,skillParam.cdTime)
  247. self.bossSkillProgress:SetActive(true)
  248. self.bossSkillCD:SetActive(true)
  249. self.bossSkillNode.releaseNode:SetActive(false)
  250. self.bossSkillNode.keepNode:SetActive(false)
  251. local cnt = skillParam.cdTime * 1000 / 100
  252. self:ClearBossSkillTimer()
  253. self.bossSkillTimer = ManagerContainer.LuaTimerMgr:AddTimer(100, cnt, self, self.UpdateBossSkillCDTimer, {skillParam = skillParam,totalTime = skillParam.cdTime})
  254. end
  255. end
  256. function UINewbieBattleView:UpdateBossSkillCD(leftTime,totalTime)
  257. local time = CommonUtil.GetPreciseDecimal(leftTime,1)
  258. if totalTime > 0 and time > 0 then
  259. self.bossSkillProgress.image.fillAmount = time/totalTime
  260. -- self.bossSkillCD.text.text = tostring(time)
  261. self.bossSkillCD.text.text = ""
  262. else
  263. self.bossSkillProgress.image.fillAmount = 0
  264. self.bossSkillCD.text.text = ""
  265. end
  266. self.bossSkillNode.waitNode:SetActive(time == 0)
  267. end
  268. function UINewbieBattleView:UpdateBossSkillCDTimer(sequence,params)
  269. local skillParam = params.skillParam
  270. local totalTime = params.totalTime
  271. skillParam.cdTime = skillParam.cdTime - 0.1
  272. local leftTime = skillParam.cdTime;
  273. if leftTime < 0 then
  274. leftTime = 0
  275. end
  276. self:UpdateBossSkillCD(leftTime,totalTime)
  277. end
  278. function UINewbieBattleView:ClearBossSkillTimer()
  279. if self.bossSkillTimer ~= nil then
  280. ManagerContainer.LuaTimerMgr:RemoveTimer(self.bossSkillTimer)
  281. self.bossSkillTimer = nil
  282. end
  283. end
  284. function UINewbieBattleView:OnRefreshBossBuff(buffIcon,isDebuff)
  285. if self:HasBuffIconGo(buffIcon,isDebuff) then
  286. return
  287. end
  288. if isDebuff then
  289. local buffGo = UnityEngine.GameObject.Instantiate(self.bossDebuffTemp)
  290. buffGo:SetActive(true)
  291. buffGo.transform:SetParent(self.bossDebuffTemp.transform.parent)
  292. buffGo.transform.localScale = Vector3.one
  293. buffGo.transform.localPosition = Vector3.zero
  294. buffGo.name = buffIcon
  295. self.bossDebuffs[#self.bossDebuffs+1] = {icon = buffIcon, go = buffGo }
  296. self:LoadBuffIcon(buffGo,buffIcon)
  297. else
  298. local buffGo = UnityEngine.GameObject.Instantiate(self.bossBuffTemp)
  299. buffGo:SetActive(true)
  300. buffGo.transform:SetParent(self.bossBuffTemp.transform.parent)
  301. buffGo.transform.localScale = Vector3.one
  302. buffGo.transform.localPosition = Vector3.zero
  303. buffGo.name = buffIcon
  304. self.bossBuffs[#self.bossBuffs+1] = {icon = buffIcon, go = buffGo }
  305. self:LoadBuffIcon(buffGo,buffIcon)
  306. end
  307. end
  308. function UINewbieBattleView:HasBuffIconGo(buffIcon,isDebuff)
  309. if isDebuff then
  310. if self.bossBuffs == nil then
  311. return false
  312. end
  313. for i = 1, #self.bossBuffs do
  314. if self.bossBuffs[i].icon == buffIcon then
  315. return true
  316. end
  317. end
  318. else
  319. if self.bossDebuffs == nil then
  320. return false
  321. end
  322. for i = 1, #self.bossDebuffs do
  323. if self.bossDebuffs[i].icon == buffIcon then
  324. return true
  325. end
  326. end
  327. end
  328. return false
  329. end
  330. function UINewbieBattleView:LoadBuffIcon(buffGo,buffIcon)
  331. if buffGo == nil or buffIcon == nil then
  332. return
  333. end
  334. local img = buffGo:GetComponent(Enum.TypeInfo.Image)
  335. if img == nil then
  336. return
  337. end
  338. local handler = CommonUtil.LoadIcon(self, buffIcon, function (sprite)
  339. self.bossBuffLoadHandlers[buffIcon] = nil
  340. if img ~= nil and sprite ~= nil then
  341. img.sprite = sprite
  342. end
  343. end)
  344. self.bossBuffLoadHandlers[buffIcon] = handler
  345. end
  346. function UINewbieBattleView:RemoveBuffIconGo(buffIcon,isDebuff)
  347. if isDebuff then
  348. if self.bossBuffs ~= nil then
  349. for i = 1, #self.bossBuffs do
  350. if self.bossBuffs[i].icon == buffIcon then
  351. self:RemoveBuffLoadHandler(buffIcon)
  352. CommonUtil.DestroyGO(self.bossBuffs[i].go)
  353. self.bossBuffs[i].go = nil
  354. table.remove(self.bossBuffs, i)
  355. return
  356. end
  357. end
  358. end
  359. else
  360. if self.bossDebuffs ~= nil then
  361. for i = 1, #self.bossDebuffs do
  362. if self.bossDebuffs[i].icon == buffIcon then
  363. self:RemoveBuffLoadHandler(buffIcon)
  364. CommonUtil.DestroyGO(self.bossDebuffs[i].go)
  365. self.bossDebuffs[i].go = nil
  366. table.remove(self.bossDebuffs, i)
  367. return
  368. end
  369. end
  370. end
  371. end
  372. end
  373. function UINewbieBattleView:RemoveBuffLoadHandler(buffIcon)
  374. if self.bossBuffLoadHandlers[buffIcon] ~= nil then
  375. ManagerContainer.ResMgr:ClearUIAsyncLoadReqsBySeqId(self.bossBuffLoadHandlers[buffIcon])
  376. self.bossBuffLoadHandlers[buffIcon] = nil
  377. end
  378. end
  379. function UINewbieBattleView:OnRefreshRemoveBossBuff(buffIcon)
  380. if self:HasBuffIconGo(buffIcon,true) then
  381. self:RemoveBuffIconGo(buffIcon,true)
  382. elseif self:HasBuffIconGo(buffIcon,false) then
  383. self:RemoveBuffIconGo(buffIcon,false)
  384. end
  385. end
  386. function UINewbieBattleView:ClearBattleSkillTimer()
  387. if self.skillCDTimers ~= nil then
  388. for v,p in pairs(self.skillCDTimers) do
  389. ManagerContainer.LuaTimerMgr:RemoveTimer(p)
  390. end
  391. self.skillCDTimers = nil
  392. end
  393. if self.bossSkillTimer ~= nil then
  394. ManagerContainer.LuaTimerMgr:RemoveTimer(self.bossSkillTimer)
  395. self.bossSkillTimer = nil
  396. end
  397. if self.actorHeadMapping ~= nil then
  398. for i= 1, #self.actorHeadMapping do
  399. CommonUtil.UpdateSkillCD(self.actorHeadMapping[i].headGo.headBoxItem.skillNode,0,1)
  400. end
  401. end
  402. self:UpdateBossSkillCD(0,0)
  403. end
  404. function UINewbieBattleView:OnShowSkipBattle()
  405. self.skipBtn:SetActive(true)
  406. end
  407. function UINewbieBattleView:OnSetUINodeVis(nodePath)
  408. if nodePath == nil then
  409. return
  410. end
  411. local nodeTrans = self.transform:Find(nodePath)
  412. if nodeTrans ~= nil then
  413. nodeTrans.gameObject:SetActive(true)
  414. end
  415. end
  416. function UINewbieBattleView:OnClickSkipBattle()
  417. LuaBattleBridge.SkipNewbieBattle()
  418. end
  419. return UINewbieBattleView