UIWorldBossBattleView.lua 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  1. local UIWorldBossBattleView = require("UIWorldBoss/UIWorldBossBattleView_Generate")
  2. local DOTween = DG.Tweening.DOTween
  3. local LifeBarTweenSpeed = 0.5
  4. local LifeBarTweenStopInterval = 0.1
  5. local PlayerInOutAnimTime = 0.5
  6. function UIWorldBossBattleView:OnAwake(data)
  7. self.controller = require("UIWorldBoss/UIWorldBossBattleCtr"):new()
  8. self.controller:Init(self)
  9. self.controller:SetData(data)
  10. end
  11. function UIWorldBossBattleView:AddEventListener()
  12. -- ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Refresh_Boss_Skill,self,self.OnRefreshBossSkill)
  13. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Refresh_Boss_Buff,self,self.OnRefreshBossBuff)
  14. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Refresh_Boss_Remove_Buff,self,self.OnRefreshRemoveBossBuff)
  15. -- ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Refresh_Cast_Skill, self, self.OnPlayerSkillChanged)
  16. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Refresh_Fighter_Life, self, self.OnPlayerHpChanged)
  17. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Refresh_Fighter_Sp, self, self.OnPlayerSpChanged)
  18. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.WORLD_BOSS_HP_CHANGED, self, self.OnRefreshBossLife)
  19. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.WORLD_BOSS_PLAYER_CHANGED, self, self.OnPlayerChanged)
  20. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.WORLD_BOSS_SERVER_KICKOUT_BATTLE, self, self.OnServerKickoutBattle)
  21. self.controller:SetWorldBossBattleUIReady()
  22. end
  23. function UIWorldBossBattleView:FillContent(data, uiBase)
  24. self.uiBase = uiBase
  25. local gameObject = self.uiBase:GetRoot()
  26. if gameObject ~= nil then
  27. self.gameObject = gameObject
  28. self.transform = gameObject.transform
  29. end
  30. self:InitGenerate(self.transform, data)
  31. self:Init()
  32. end
  33. function UIWorldBossBattleView:Init()
  34. self.serverKickoutBattle = false
  35. self:InitBossBlood()
  36. self:InitPlayerList()
  37. self.btnQuit:SetActive(false)
  38. self.ShowBtnTimer = ManagerContainer.LuaTimerMgr:AddTimer(15000, 1, self, self.ShowQuitBtn, nil)
  39. end
  40. function UIWorldBossBattleView:ShowQuitBtn()
  41. self.btnQuit:SetActive(true)
  42. end
  43. function UIWorldBossBattleView:RemoveEventListener()
  44. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  45. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.WORLD_BOSS_HP_CHANGED, self, self.OnRefreshBossLife)
  46. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.WORLD_BOSS_PLAYER_CHANGED, self, self.OnPlayerChanged)
  47. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.WORLD_BOSS_SERVER_KICKOUT_BATTLE, self, self.OnServerKickoutBattle)
  48. end
  49. function UIWorldBossBattleView:AddUIEventListener()
  50. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  51. self.uiBase:AddButtonEventListener(self.btnQuit.button, self, self.BtnQuitOnClick)
  52. end
  53. function UIWorldBossBattleView:OnHide()
  54. end
  55. function UIWorldBossBattleView:OnShow(data)
  56. self.controller:SetData(data)
  57. self:Init()
  58. end
  59. function UIWorldBossBattleView:OnClose()
  60. end
  61. function UIWorldBossBattleView:OnDispose()
  62. self.serverKickoutBattle = nil
  63. self:DisposeBossBlood()
  64. self:DisposePlayerList()
  65. end
  66. function UIWorldBossBattleView:OnServerKickoutBattle()
  67. self:OnRefreshBossLife()
  68. -- self:RefreshPlayerSuccess()
  69. self.serverKickoutBattle = true
  70. end
  71. --------------------------- WorldBoss ----------------------------
  72. function UIWorldBossBattleView:InitBossBlood()
  73. self:DisposeBossBlood()
  74. self.bossBuffs = {}
  75. self.bossDebuffs = {}
  76. self.bossBuffLoadHandlers = {}
  77. self.bossBloodNode:SetActive(true)
  78. self.bossBloodNode.animator:Play("BossBloddShow")
  79. local segmentPrecent = self.controller:GetBossSegmentPrecent()
  80. self.bossBlood2.image.fillAmount = segmentPrecent
  81. self.bossBlood.image.fillAmount = segmentPrecent
  82. self.lastLifeBarNum = self.controller:GetBossLifeBarNum()
  83. self:RefreshBossLifeBarNum()
  84. self.bossName.text.text = I18N.T(self.controller:GetBossName())
  85. local bossIcon = self.controller:GetBossIcon()
  86. if bossIcon ~= nil and bossIcon ~= "" then
  87. CommonUtil.LoadIcon(self.host, bossIcon, function (sprite)
  88. self.bossIcon.image.sprite = sprite
  89. end)
  90. end
  91. -- self:OnRefreshBossSkill(self.controller:GetBossInitSkillParam())
  92. end
  93. function UIWorldBossBattleView:DisposeBossBlood()
  94. if self.bossBloodSequence then
  95. self.bossBloodSequence:Kill()
  96. self.bossBloodSequence = nil
  97. end
  98. -- self:ClearBossSkillTimer()
  99. if self.bossBuffs then
  100. for i = #self.bossBuffs, 1, -1 do
  101. self:RemoveBuffIconGo(self.bossBuffs[i].icon, false)
  102. end
  103. end
  104. self.bossBuffs = nil
  105. if self.bossDebuffs then
  106. for i = #self.bossDebuffs, 1, -1 do
  107. self:RemoveBuffIconGo(self.bossDebuffs[i].icon, true)
  108. end
  109. end
  110. self.bossDebuffs = nil
  111. if self.bossBuffLoadHandlers then
  112. for buffIcon, value in pairs(self.bossBuffLoadHandlers) do
  113. self:RemoveBuffLoadHandler(buffIcon, true)
  114. end
  115. end
  116. self.bossBuffLoadHandlers = nil
  117. self.lastLifeBarNum = nil
  118. if self.bossLifeAnimTimer and self.bossLifeAnimTimer.running then
  119. self.bossLifeAnimTimer:Stop()
  120. end
  121. self.bossLifeAnimTimer = nil
  122. end
  123. function UIWorldBossBattleView:RefreshBossLifeBarNum()
  124. local lifeBarNum = self.lastLifeBarNum
  125. if lifeBarNum > 1 then
  126. self.bossLifeBarNum.text.text = 'x' .. tostring(lifeBarNum)
  127. self.bossLifeBarNum:SetActive(true)
  128. self.bossBloodBack:SetActive(true)
  129. else
  130. self.bossLifeBarNum.text.text = ''
  131. self.bossLifeBarNum:SetActive(false)
  132. self.bossBloodBack:SetActive(false)
  133. end
  134. end
  135. function UIWorldBossBattleView:OnRefreshBossLife()
  136. if self.serverKickoutBattle then return end
  137. if not self.controller:SyncBossLife() then return end
  138. local lifeBarNum = self.controller:GetBossLifeBarNum()
  139. local segmentPrecent = self.controller:GetBossSegmentPrecent()
  140. if(self.controller.bossLife<=1) then
  141. self:ShowQuitBtn()
  142. end
  143. -- 未来如果同步血量间隔很短,则需要另外启用定时器来做血量表现的更新
  144. -- 避免同帧,或者在时间很短内做频繁更新
  145. local seq = self.bossBloodSequence
  146. if seq then
  147. seq:Kill()
  148. seq = nil
  149. end
  150. seq = DOTween.Sequence()
  151. self.bossBloodSequence = seq
  152. local lastLifeBarNum = self.lastLifeBarNum
  153. self.lastLifeBarNum = lifeBarNum
  154. if lastLifeBarNum > lifeBarNum then
  155. -- boss减血了
  156. self.bossBlood.image.fillAmount = 0
  157. if lifeBarNum > 0 then
  158. local curPrecent = self.bossBlood2.image.fillAmount
  159. local lerpPercent = 1 - segmentPrecent
  160. local totalChangePrecent = curPrecent + lerpPercent
  161. local speedAverage = LifeBarTweenSpeed / totalChangePrecent
  162. seq:Append(self.bossBlood2.image:DOFillAmount(0, curPrecent * speedAverage))
  163. seq:AppendCallback(function()
  164. self.bossBlood.image.fillAmount = segmentPrecent
  165. self.bossBlood2.image.fillAmount = 1
  166. self:RefreshBossLifeBarNum()
  167. end)
  168. seq:Append(self.bossBlood2.image:DOFillAmount(segmentPrecent, lerpPercent * speedAverage))
  169. seq:AppendCallback(function()
  170. self.bossBlood.image.fillAmount = segmentPrecent
  171. self.bossBlood2.image.fillAmount = segmentPrecent
  172. end)
  173. else
  174. seq:Append(self.bossBlood2.image:DOFillAmount(0, LifeBarTweenSpeed))
  175. self.bossBloodBack:SetActive(false)
  176. seq:AppendCallback(function()
  177. self:RefreshBossLifeBarNum()
  178. end)
  179. end
  180. elseif lastLifeBarNum < lifeBarNum then
  181. -- boss加血了
  182. local curPrecent = self.bossBlood2.image.fillAmount
  183. local lerpPercent = 1 - curPrecent
  184. local totalChangePrecent = segmentPrecent + lerpPercent
  185. local speedAverage = (LifeBarTweenSpeed - LifeBarTweenStopInterval) / totalChangePrecent
  186. seq:Append(self.bossBlood2.image:DOFillAmount(1, lerpPercent * speedAverage))
  187. seq:AppendCallback(function()
  188. self.bossBlood.image.fillAmount = 1
  189. self.bossBlood2.image.fillAmount = 1
  190. end)
  191. seq:AppendInterval(LifeBarTweenStopInterval)
  192. seq:AppendCallback(function()
  193. self.bossBlood.image.fillAmount = 0
  194. self.bossBlood2.image.fillAmount = 0
  195. self:RefreshBossLifeBarNum()
  196. end)
  197. seq:Append(self.bossBlood2.image:DOFillAmount(segmentPrecent, segmentPrecent * speedAverage))
  198. seq:AppendCallback(function()
  199. self.bossBlood.image.fillAmount = segmentPrecent
  200. self.bossBlood2.image.fillAmount = segmentPrecent
  201. end)
  202. else
  203. local lastSegmentPrecent = self.bossBlood.image.fillAmount
  204. if lastSegmentPrecent > segmentPrecent then
  205. -- boss减血了
  206. self.bossBlood.image.fillAmount = segmentPrecent
  207. seq:Append(self.bossBlood2.image:DOFillAmount(segmentPrecent, LifeBarTweenSpeed))
  208. seq:AppendCallback(function()
  209. self.bossBlood.image.fillAmount = segmentPrecent
  210. self.bossBlood2.image.fillAmount = segmentPrecent
  211. end)
  212. elseif lastSegmentPrecent < segmentPrecent then
  213. -- boss加血了
  214. seq:Append(self.bossBlood2.image:DOFillAmount(segmentPrecent, LifeBarTweenSpeed))
  215. seq:AppendCallback(function()
  216. self.bossBlood.image.fillAmount = segmentPrecent
  217. self.bossBlood2.image.fillAmount = segmentPrecent
  218. end)
  219. -- else
  220. -- 上面已判定相同,理论上进不来这里
  221. end
  222. end
  223. -- if life == 0 then
  224. -- self.bossBloodNode.animator:Play("BossBloddClose");
  225. -- end
  226. end
  227. -- function UIWorldBossBattleView:OnRefreshBossSkill(skillParam)
  228. -- if self.serverKickoutBattle then return end
  229. -- if self.bossSkillNode == nil then
  230. -- return
  231. -- end
  232. -- if skillParam == nil then
  233. -- self:ClearBossSkillTimer()
  234. -- self.bossSkillNode:SetActive(false)
  235. -- return
  236. -- end
  237. -- self.bossSkillNode:SetActive(true)
  238. -- CommonUtil.LoadIcon(self, skillParam.skillIcon, function (sprite)
  239. -- self.bossSkillIcon.image.sprite = sprite
  240. -- end, self, "Boss_SkillIconAsyncIdx")
  241. -- self.bossSkillNode.forbidNode:SetActive(skillParam.IsForbidden)
  242. -- self.bossSkillNode.extraNode:SetActive(skillParam.IsEnhance)
  243. -- if skillParam.IsCasting then
  244. -- self.bossSkillProgress:SetActive(false)
  245. -- self.bossSkillCD:SetActive(false)
  246. -- self.bossSkillNode.releaseNode:SetActive(true)
  247. -- self.bossSkillNode.keepNode:SetActive(true)
  248. -- self.bossSkillNode.waitNode:SetActive(false)
  249. -- self:ClearBossSkillTimer()
  250. -- self.bossSkillNode.animator:Play("BossSkillRelease")
  251. -- else
  252. -- if skillParam.IsForbidden then
  253. -- self.bossSkillNode.animator:Play("SkillForbidden");
  254. -- else
  255. -- self.bossSkillNode.animator:Play("BossWait");
  256. -- end
  257. -- self:UpdateBossSkillCD(skillParam.cdTime,skillParam.cdTime)
  258. -- self.bossSkillProgress:SetActive(true)
  259. -- self.bossSkillCD:SetActive(true)
  260. -- self.bossSkillNode.releaseNode:SetActive(false)
  261. -- self.bossSkillNode.keepNode:SetActive(false)
  262. -- local cnt = skillParam.cdTime * 1000 / 100
  263. -- self:ClearBossSkillTimer()
  264. -- self.bossSkillTimer = ManagerContainer.LuaTimerMgr:AddTimer(100, cnt, self, self.UpdateBossSkillCDTimer, {skillParam = skillParam,totalTime = skillParam.cdTime})
  265. -- end
  266. -- end
  267. -- function UIWorldBossBattleView:UpdateBossSkillCDTimer(sequence,params)
  268. -- local skillParam = params.skillParam
  269. -- local totalTime = params.totalTime
  270. -- skillParam.cdTime = skillParam.cdTime - 0.1
  271. -- local leftTime = skillParam.cdTime;
  272. -- if leftTime < 0 then
  273. -- leftTime = 0
  274. -- end
  275. -- self:UpdateBossSkillCD(leftTime,totalTime)
  276. -- end
  277. -- function UIWorldBossBattleView:ClearBossSkillTimer()
  278. -- if self.bossSkillTimer ~= nil then
  279. -- ManagerContainer.LuaTimerMgr:RemoveTimer(self.bossSkillTimer)
  280. -- self.bossSkillTimer = nil
  281. -- end
  282. -- end
  283. -- function UIWorldBossBattleView:UpdateBossSkillCD(leftTime,totalTime)
  284. -- local time = CommonUtil.GetPreciseDecimal(leftTime,1)
  285. -- if totalTime > 0 and time > 0 then
  286. -- self.bossSkillProgress.image.fillAmount = time/totalTime
  287. -- self.bossSkillCD.text.text = tostring(time)
  288. -- else
  289. -- self.bossSkillProgress.image.fillAmount = 0
  290. -- self.bossSkillCD.text.text = ""
  291. -- end
  292. -- self.bossSkillNode.waitNode:SetActive(time == 0)
  293. -- end
  294. function UIWorldBossBattleView:OnRefreshBossBuff(buffIcon, num)
  295. if self.serverKickoutBattle then return end
  296. if self:HasBuffIconGo(buffIcon) then
  297. local info = self:GetBuffIconInfo(buffIcon)
  298. if info and info.text then
  299. if num > 0 then
  300. info.text.text = tostring(num)
  301. else
  302. info.text.text = ""
  303. end
  304. end
  305. return
  306. end
  307. local buffGo = UnityEngine.GameObject.Instantiate(self.buffTemp)
  308. buffGo:SetActive(true)
  309. buffGo.transform:SetParent(self.buffTemp.transform.parent)
  310. buffGo.transform.localScale = Vector3.one
  311. buffGo.transform.localPosition = Vector3.zero
  312. buffGo.name = buffIcon
  313. local image = nil
  314. local imageGo = buffGo.transform:Find("Image")
  315. if imageGo then
  316. image = imageGo:GetComponent(Enum.TypeInfo.Image)
  317. end
  318. local numText = nil
  319. local numTextGo = buffGo.transform:Find("num")
  320. if numTextGo then
  321. numText = numTextGo:GetComponent(Enum.TypeInfo.TextMeshProUGUI)
  322. end
  323. local temps = string.split(buffIcon, '/')
  324. local buffDesc = ""
  325. if temps ~= nil and #temps > 0 then
  326. buffDesc = temps[#temps].."_Desc"
  327. end
  328. local info = {icon = buffIcon, go = buffGo, image = image, text = numText,desc = buffDesc }
  329. self.bossBuffs[#self.bossBuffs+1] = info
  330. self:LoadBuffIcon(info, num,buffDesc)
  331. end
  332. function UIWorldBossBattleView:OnRefreshRemoveBossBuff(buffIcon)
  333. if self:HasBuffIconGo(buffIcon) then
  334. self:RemoveBuffIconGo(buffIcon)
  335. end
  336. end
  337. function UIWorldBossBattleView:HasBuffIconGo(buffIcon)
  338. if self.bossBuffs == nil then
  339. return false
  340. end
  341. for i = 1, #self.bossBuffs do
  342. if self.bossBuffs[i].icon == buffIcon then
  343. return true
  344. end
  345. end
  346. return false
  347. end
  348. function UIWorldBossBattleView:GetBuffIconInfo(buffIcon)
  349. if self.bossBuffs == nil then
  350. return nil
  351. end
  352. for i = 1, #self.bossBuffs do
  353. if self.bossBuffs[i].icon == buffIcon then
  354. return self.bossBuffs[i]
  355. end
  356. end
  357. return nil
  358. end
  359. function UIWorldBossBattleView:LoadBuffIcon(info, num,desc)
  360. if not info or not info.go then
  361. return
  362. end
  363. if info.text then
  364. if num > 0 then
  365. info.text.text = tostring(num)
  366. else
  367. info.text.text = ''
  368. end
  369. end
  370. if not info.image then
  371. return
  372. end
  373. local btn = info.go.transform:GetComponent(Enum.TypeInfo.Button)
  374. if btn ~= nil then
  375. self.uiBase:AddButtonUniqueEventListener(btn, self, self.OnClickBuff,desc)
  376. end
  377. local handler = CommonUtil.LoadIcon(self.host, info.icon, function (sprite)
  378. self.bossBuffLoadHandlers[info.icon] = nil
  379. info.image.sprite = sprite
  380. end)
  381. self.bossBuffLoadHandlers[info.icon] = handler
  382. end
  383. function UIWorldBossBattleView:OnClickBuff(btn,params)
  384. ManagerContainer.LuaUIMgr:ShowMinTips(params[0])
  385. end
  386. function UIWorldBossBattleView:RemoveBuffIconGo(buffIcon)
  387. if self.bossBuffs ~= nil then
  388. for i = 1, #self.bossBuffs do
  389. if self.bossBuffs[i].icon == buffIcon then
  390. self:RemoveBuffLoadHandler(buffIcon)
  391. CommonUtil.DestroyGO(self.bossBuffs[i].go)
  392. self.bossBuffs[i].go = nil
  393. table.remove(self.bossBuffs, i)
  394. return
  395. end
  396. end
  397. end
  398. end
  399. function UIWorldBossBattleView:RemoveBuffLoadHandler(buffIcon)
  400. if self.bossBuffLoadHandlers[buffIcon] ~= nil then
  401. ManagerContainer.ResMgr:ClearUIAsyncLoadReqsBySeqId(self.bossBuffLoadHandlers[buffIcon])
  402. self.bossBuffLoadHandlers[buffIcon] = nil
  403. end
  404. end
  405. ---------------------------- Player ------------------------------
  406. function UIWorldBossBattleView:InitPlayerList()
  407. local playerCaches = {}
  408. local index = 1
  409. while (index ~= nil) do
  410. local player = self['player' .. index]
  411. if player then
  412. table.insert(playerCaches, player)
  413. index = index + 1
  414. player:SetActive(false)
  415. else
  416. index = nil
  417. end
  418. end
  419. self.playerCaches = playerCaches -- 可以用于显示的玩家Go池
  420. self.playerMap = {}
  421. self.prePlayerIns = {} -- 正在进入的玩家 (进入动画表现中的玩家)
  422. self.prePlayerOuts = {} -- 正在退出的玩家 (退出动画表现中的玩家)
  423. self.playerInOutAnimTimer = Timer.New(function()
  424. self:EndPlayerInOutAnim()
  425. end, PlayerInOutAnimTime, -1)
  426. -- self.playerSkillCDTimer = {} -- 玩家技能CD更新的定时器
  427. self.headsBox.slideHorizontalLayoutGroup.snapEnable = false
  428. local uids = self.controller:GetDefaultInBattleUIds()
  429. local hasError = false
  430. local num = #self.playerCaches
  431. if uids then
  432. for i = 1, #uids do
  433. if num <= 0 then
  434. LogError('[Wboy] player is not enough in prefab !!!')
  435. break
  436. end
  437. local uid = uids[i]
  438. local actorSystem = self.controller:GetActorSystemByUID(uid)
  439. if actorSystem then
  440. local player = self.playerCaches[num]
  441. table.remove(self.playerCaches, num)
  442. num = num - 1
  443. self.playerMap[uid] = player
  444. player:SetActive(true)
  445. self:SetPlayerInfoInOut(player, true, actorSystem)
  446. else
  447. hasError = true
  448. end
  449. end
  450. else
  451. hasError = true
  452. end
  453. -- 默认在场景中的玩家不动画进入
  454. self.headsBox.slideHorizontalLayoutGroup:CalculateLayoutInputHorizontal()
  455. self.headsBox.slideHorizontalLayoutGroup:SetLayoutHorizontal()
  456. self.headsBox.slideHorizontalLayoutGroup:CalculateLayoutInputVertical()
  457. self.headsBox.slideHorizontalLayoutGroup:SetLayoutVertical()
  458. self.headsBox.slideHorizontalLayoutGroup.snapEnable = true
  459. if hasError then
  460. LogError('[Wboy] Script execute order is error !!!')
  461. end
  462. end
  463. function UIWorldBossBattleView:DisposePlayerList()
  464. self.playerCaches = nil
  465. self.playerMap = nil
  466. self.prePlayerIns = nil
  467. self.prePlayerOuts = nil
  468. self.prePlayerInOut = nil
  469. if self.playerInOutAnimTimer and self.playerInOutAnimTimer.running then
  470. self.playerInOutAnimTimer:Stop()
  471. end
  472. self.playerInOutAnimTimer = nil
  473. -- for _, timer in pairs(self.playerSkillCDTimer) do
  474. -- if timer and timer.running then
  475. -- timer:Stop()
  476. -- end
  477. -- end
  478. -- self.playerSkillCDTimer = nil
  479. end
  480. -- function UIWorldBossBattleView:RefreshPlayerSuccess()
  481. -- for _, player in pairs(self.playerMap) do
  482. -- self:SetPlayerSkill(player)
  483. -- end
  484. -- end
  485. function UIWorldBossBattleView:OnPlayerChanged(enters, exits)
  486. if self.serverKickoutBattle then return end
  487. self:EndPlayerInOutAnim(true)
  488. local uid
  489. for i = 1, #exits do
  490. uid = exits[i]
  491. local player = self.playerMap[uid]
  492. if player then
  493. table.insert(self.prePlayerOuts, player)
  494. player.position.animator:Play("PlayerClose")
  495. self:SetPlayerInfoInOut(player)
  496. end
  497. -- local timer = self.playerSkillCDTimer[uid]
  498. -- if timer and timer.running then
  499. -- timer:Stop()
  500. -- end
  501. -- self.playerSkillCDTimer[uid] = nil
  502. end
  503. local num = #self.playerCaches
  504. for i = 1, #enters do
  505. local enter = enters[i]
  506. uid = enter.uid
  507. local actorSystem = enter.data
  508. if actorSystem then
  509. if num <= 0 then
  510. break
  511. end
  512. --是否有变身ID
  513. if nil ~= actorSystem.userData.change_play_id and actorSystem.userData.change_play_id>0 then
  514. actorSystem:CreatePetBossActor(actorSystem.userData.change_play_id)
  515. end
  516. local player = self.playerCaches[num]
  517. table.remove(self.playerCaches, num)
  518. num = num - 1
  519. self.playerMap[uid] = player
  520. table.insert(self.prePlayerIns, player)
  521. player:SetActive(true)
  522. player.position.animator:Play("PlayerShow")
  523. self:SetPlayerInfoInOut(player, true, actorSystem)
  524. end
  525. end
  526. if self.playerInOutAnimTimer.running then
  527. self.playerInOutAnimTimer.time = PlayerInOutAnimTime
  528. else
  529. self.playerInOutAnimTimer:Start()
  530. end
  531. self.headsBox.slideHorizontalLayoutGroup.snapEnable = false
  532. self.headsBox.slideHorizontalLayoutGroup:CalculateLayoutInputHorizontal()
  533. self.headsBox.slideHorizontalLayoutGroup:SetLayoutHorizontal()
  534. self.headsBox.slideHorizontalLayoutGroup:CalculateLayoutInputVertical()
  535. self.headsBox.slideHorizontalLayoutGroup:SetLayoutVertical()
  536. self.headsBox.slideHorizontalLayoutGroup.snapEnable = true
  537. end
  538. -- function UIWorldBossBattleView:OnPlayerSkillChanged(skillParam)
  539. -- if self.serverKickoutBattle then return end
  540. -- if skillParam == nil then return end
  541. -- local uid = skillParam.actorId
  542. -- local player = self.playerMap[uid]
  543. -- if not player then return end
  544. -- self:SetPlayerSkill(player, skillParam)
  545. -- end
  546. function UIWorldBossBattleView:OnPlayerHpChanged(uid, curHp, maxHp)
  547. if self.serverKickoutBattle then return end
  548. if uid == nil then return end
  549. local player = self.playerMap[uid]
  550. if not player then return end
  551. if maxHp <= 0 then
  552. local actorSystem = self.controller:GetActorSystemByUID(uid)
  553. if actorSystem then
  554. uid = actorSystem:GetUserId()
  555. end
  556. LogError('[Wboy] maxHp is error ' .. tostring(maxHp) .. ' ' .. tostring(uid))
  557. return
  558. end
  559. if curHp <= 0 then
  560. self:SetPlayerHp(player, 0)
  561. else
  562. self:SetPlayerHp(player, SDataUtil.InvConvert(curHp) / SDataUtil.InvConvert(maxHp))
  563. end
  564. end
  565. function UIWorldBossBattleView:OnPlayerSpChanged(uid, curSp, maxSp)
  566. if self.serverKickoutBattle then return end
  567. if uid == nil then return end
  568. local player = self.playerMap[uid]
  569. if not player then return end
  570. if maxSp <= 0 then
  571. local actorSystem = self.controller:GetActorSystemByUID(uid)
  572. if actorSystem then
  573. uid = actorSystem:GetUserId()
  574. end
  575. LogError('[Wboy] maxSp is error ' .. tostring(maxSp) .. ' ' .. tostring(uid))
  576. return
  577. end
  578. if curSp <= 0 then
  579. self:SetPlayerSp(player, 0)
  580. else
  581. self:SetPlayerSp(player, SDataUtil.InvConvert(curSp) / SDataUtil.InvConvert(maxSp))
  582. end
  583. end
  584. --- 结束所有正在表现进出动画
  585. function UIWorldBossBattleView:EndPlayerInOutAnim(forceEnd)
  586. if forceEnd then
  587. if self.playerInOutAnimTimer.running then
  588. self.playerInOutAnimTimer.time = PlayerInOutAnimTime
  589. end
  590. else
  591. self.playerInOutAnimTimer:Stop()
  592. end
  593. for i = #self.prePlayerOuts, 1, -1 do
  594. local player = self.prePlayerOuts[i]
  595. self.prePlayerOuts[i] = nil
  596. player:SetActive(false)
  597. table.insert(self.playerCaches, player)
  598. end
  599. for i = #self.prePlayerIns, 1, -1 do
  600. self.prePlayerIns[i] = nil
  601. end
  602. end
  603. function UIWorldBossBattleView:SetPlayerInfoInOut(player, isIn, actorSystem)
  604. if isIn then
  605. local actorData = actorSystem:GetPlayerActorParam()
  606. local headFrameId = actorSystem:GetHeadFrameId()
  607. CommonUtil.SetPlayerHeadAndFrame(self, player.headBoxItem.headItem, actorData, false, headFrameId, self, self.OnClickPlayerHead, actorSystem:GetUserId())
  608. player.playerName.text.text = actorSystem:GetUserNickname()
  609. local userId = actorSystem:GetUserId()
  610. LuaBattleBridge.BeginTweenRecTransformPos(player.position, 0, Vector3(0,0,0))
  611. if int64.equals(userId, self.controller:GetCurUserId()) then
  612. LuaBattleBridge.BeginTweenRecTransformPos(player.position,0.1,Vector3(0,15,0))
  613. end
  614. player.transform:SetSiblingIndex(0)
  615. -- self:SetPlayerSkill(player)
  616. self:SetPlayerHp(player, 1)
  617. self:SetPlayerSp(player, 1)
  618. else
  619. -- self:SetPlayerSkill(player)
  620. self:SetPlayerHp(player, 0)
  621. self:SetPlayerSp(player, 0)
  622. end
  623. end
  624. function UIWorldBossBattleView:OnClickPlayerHead(btn,param)
  625. if self.serverKickoutBattle then return end
  626. local uid = param[0]
  627. if not uid then return end
  628. ManagerContainer.LuaUIMgr:OpenRoleMessagePanel(uid)
  629. end
  630. -- function UIWorldBossBattleView:SetPlayerSkill(player, skillInfo)
  631. -- if not player then return end
  632. -- local skill = player.skill
  633. -- if not skill then return end
  634. -- if not skillInfo then
  635. -- skill:SetActive(false)
  636. -- return
  637. -- end
  638. -- skill:SetActive(true)
  639. -- local uid = skillInfo.actorId
  640. -- local isForbidden = skillInfo.IsForbidden
  641. -- local isCasting = skillInfo.IsCasting
  642. -- local isEnhance = skillInfo.IsEnhance
  643. -- local icon = skillInfo.skillIcon
  644. -- local animName
  645. -- skill.icon.image.sprite = nil
  646. -- CommonUtil.LoadIcon(self, icon, function (sprite)
  647. -- skill.icon.image.sprite = sprite
  648. -- end, self, player.name .. "_SkillIconAsyncIdx")
  649. -- skill.forbidden:SetActive(isForbidden)
  650. -- skill.extra:SetActive(isEnhance)
  651. -- if isCasting then
  652. -- skill.release:SetActive(true)
  653. -- skill.keep:SetActive(true)
  654. -- skill.mask:SetActive(false)
  655. -- skill.wait:SetActive(false)
  656. -- skill.cD:SetActive(false)
  657. -- local timer = self.playerSkillCDTimer[uid]
  658. -- if timer and timer.running then
  659. -- timer:Stop()
  660. -- timer.cdCurTime = nil
  661. -- timer.cdMaxTime = nil
  662. -- end
  663. -- animName = 'SkillRelease'
  664. -- else
  665. -- local cdTime = skillInfo.cdTime
  666. -- if cdTime > 0 then
  667. -- self:SetPlayerSkillCD(skill, cdTime, cdTime)
  668. -- local timer = self.playerSkillCDTimer[uid]
  669. -- if not timer then
  670. -- timer = Timer.New(function()
  671. -- self:UpdatePlayerSkillCD(uid)
  672. -- end, 0.1, -1)
  673. -- self.playerSkillCDTimer[uid] = timer
  674. -- end
  675. -- timer.cdCurTime = cdTime
  676. -- timer.cdMaxTime = cdTime
  677. -- if timer.running then
  678. -- timer.time = timer.duration
  679. -- else
  680. -- timer:Start()
  681. -- end
  682. -- else
  683. -- skill.mask.image.fillAmount = 0
  684. -- skill.cD.text.text = ""
  685. -- skill.wait:SetActive(true)
  686. -- end
  687. -- skill.release:SetActive(false)
  688. -- skill.keep:SetActive(false)
  689. -- skill.mask:SetActive(true)
  690. -- skill.cD:SetActive(true)
  691. -- animName = isForbidden and 'SkillForbidden' or 'SkillWait'
  692. -- end
  693. -- if player.headBoxItem and player.headBoxItem.animator then player.headBoxItem.animator:Play(animName) end
  694. -- end
  695. -- function UIWorldBossBattleView:UpdatePlayerSkillCD(uid)
  696. -- local timer = self.playerSkillCDTimer[uid]
  697. -- if not timer then return end
  698. -- local cdMaxTime = timer.cdMaxTime or 0
  699. -- if cdMaxTime <= 0 then
  700. -- LogError("[Wboy] total skill cd is Error " .. tostring(cdMaxTime))
  701. -- return
  702. -- end
  703. -- local cdCurTime
  704. -- if timer.cdCurTime then
  705. -- timer.cdCurTime = timer.cdCurTime - 0.1
  706. -- cdCurTime = timer.cdCurTime
  707. -- else
  708. -- cdCurTime = 0
  709. -- end
  710. -- local player = self.playerMap[uid]
  711. -- if not player or not player.skill then
  712. -- -- 玩家已经不在了,删除这个定时器
  713. -- timer:Stop()
  714. -- self.playerSkillCDTimer[uid] = nil
  715. -- return
  716. -- end
  717. -- self:SetPlayerSkillCD(player.skill, cdCurTime, cdMaxTime)
  718. -- end
  719. -- function UIWorldBossBattleView:SetPlayerSkillCD(skill, leftTime, totalTime)
  720. -- local time = CommonUtil.GetPreciseDecimal(leftTime, 1)
  721. -- if time > 0 then
  722. -- skill.mask.image.fillAmount = time / totalTime
  723. -- skill.cD.text.text = tostring(time)
  724. -- else
  725. -- skill.mask.image.fillAmount = 0
  726. -- skill.cD.text.text = ""
  727. -- end
  728. -- skill.wait:SetActive(time == 0)
  729. -- end
  730. function UIWorldBossBattleView:SetPlayerHp(player, precent)
  731. if precent <= 0 then
  732. player.headBoxItem.deadNode:SetActive(true)
  733. -- player.skill:SetActive(false)
  734. else
  735. player.headBoxItem.deadNode:SetActive(false)
  736. end
  737. local hp = player.headBoxItem.hp
  738. local lastPrecent = hp.image.fillAmount
  739. if lastPrecent == precent then return end
  740. hp.image.fillAmount = precent
  741. if lastPrecent > 0.2 then
  742. if precent <= 0.2 then
  743. hp.image.sprite = hp.switchSprite:GetSprite("Bar_HP_red")
  744. end
  745. else
  746. if precent > 0.2 then
  747. hp.image.sprite = hp.switchSprite:GetSprite("Bar_HP")
  748. end
  749. end
  750. end
  751. function UIWorldBossBattleView:SetPlayerSp(player, precent)
  752. player.headBoxItem.sp.image.fillAmount = precent
  753. end
  754. function UIWorldBossBattleView:BtnQuitOnClick()
  755. local curBossHp = ManagerContainer.DataMgr.WorldBossData:GetCurHp()
  756. if curBossHp and curBossHp > 0 then
  757. -- 还有血
  758. --ManagerContainer.LuaBossBattleMgr:QuitFromWorldBossBattle()
  759. ManagerContainer.LuaBossBattleMgr:OnBattleEnd(2)
  760. else
  761. -- 没血了
  762. ManagerContainer.LuaBossBattleMgr:OnWorldBossServerKickoutBattle(1)
  763. end
  764. end
  765. return UIWorldBossBattleView