BattleBossBloodPart.lua 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. local BattleBossBloodPart = class("BattleBossBloodPart")
  2. function BattleBossBloodPart:ctor()
  3. self.lastLife = nil
  4. end
  5. function BattleBossBloodPart:InitGo(host,uiGo)
  6. self.minDeltaBlood = GlobalConfig.Instance:GetConfigFloatValue(137)
  7. self.host = host
  8. self.viewLua = CommonUtil.BindGridViewItem2Lua(self.host, "BattleBossBlood", uiGo)
  9. self:InitPanel()
  10. end
  11. function BattleBossBloodPart:InitPanel()
  12. end
  13. function BattleBossBloodPart:AddEventListener()
  14. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.EID_Refresh_Boss_Life,self,self.OnRefreshBossLife);
  15. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.EID_Refresh_Boss_Buff,self,self.OnRefreshBossBuff);
  16. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.EID_Refresh_Boss_Remove_Buff,self,self.OnRefreshRemoveBossBuff);
  17. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.EID_CLONE_NEW_BOSS,self,self.OnCloneNewBoss);
  18. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.EID_FIGHTING_START,self,self.OnFightingStart);
  19. end
  20. function BattleBossBloodPart:RemoveEventListener()
  21. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.EID_Refresh_Boss_Life,self,self.OnRefreshBossLife);
  22. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.EID_Refresh_Boss_Buff,self,self.OnRefreshBossBuff);
  23. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.EID_Refresh_Boss_Remove_Buff,self,self.OnRefreshRemoveBossBuff);
  24. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.EID_CLONE_NEW_BOSS,self,self.OnCloneNewBoss);
  25. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.EID_FIGHTING_START,self,self.OnFightingStart);
  26. end
  27. function BattleBossBloodPart:AddUIEventListener()
  28. self.host.uiBase:AddButtonUniqueEventListener(self.viewLua.bossIcon.button, self, self.OnClickBoss)
  29. end
  30. function BattleBossBloodPart:OnClickBoss()
  31. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIBattleBossTips,self.bossActor)
  32. end
  33. function BattleBossBloodPart:Show(bossActor,bossName,life,maxLife,skillParam)
  34. self.bossActor = bossActor
  35. self.lastLife = life
  36. self.totalTime = GlobalConfig.Instance:GetConfigIntValue(3)
  37. self.leftTime = self.totalTime
  38. self.viewLua.bossBlood2.image.fillAmount = 1
  39. self.viewLua.bossBlood.image.fillAmount = 1
  40. self.viewLua.bossBloodNode.animator:Play("BossBloddShow")
  41. self:SetBossBattleInfo(bossName,bossActor.HeadIcon)
  42. self.viewLua:SetActive(true)
  43. self:ShowLeftTime(self.totalTime)
  44. self:AddEventListener()
  45. end
  46. function BattleBossBloodPart:Hide()
  47. self:RemoveTimer()
  48. self:HideBossBattleInfo()
  49. self.viewLua:SetActive(false)
  50. self:RemoveEventListener()
  51. end
  52. function BattleBossBloodPart:OnCloneNewBoss(bossName,life,maxLife,skillParam)
  53. self.lastLife = life
  54. self.viewLua.bossBlood2.image.fillAmount = 1
  55. self.viewLua.bossBlood.image.fillAmount = 1
  56. self.viewLua.bossName.text.text = bossName
  57. end
  58. function BattleBossBloodPart:ShowLeftTime(time)
  59. if self.viewLua == nil then
  60. return
  61. end
  62. if time > 0 then
  63. self.viewLua.leftTime.text.text = FormatTimeMS(time)
  64. else
  65. self.viewLua.leftTime.text.text = "00:00"
  66. end
  67. end
  68. function BattleBossBloodPart:OnFightingStart()
  69. self.totalTime = GlobalConfig.Instance:GetConfigIntValue(3)
  70. self:OnRefreshLeftTime()
  71. self.timeHandler = ManagerContainer.LuaTimerMgr:AddTimer(300, -1,self,self.OnRefreshLeftTime,nil);
  72. end
  73. function BattleBossBloodPart:OnRefreshLeftTime()
  74. self.leftTime = self.totalTime - LuaBattleBridge.GetFightingTime()
  75. self:ShowLeftTime(self.leftTime)
  76. if self.leftTime <= 0 then
  77. self.leftTime = 0
  78. self:RemoveTimer()
  79. end
  80. end
  81. function BattleBossBloodPart:RemoveTimer()
  82. if self.timeHandler and self.timeHandler ~= 0 then
  83. ManagerContainer.LuaTimerMgr:RemoveTimer(self.timeHandler);
  84. self.timeHandler = nil;
  85. end
  86. end
  87. function BattleBossBloodPart:SetBossBattleInfo(bossName,bossIcon)
  88. self.bossBuffs = {}
  89. self.skillCDTimers = {}
  90. self.bossBuffLoadHandlers = {}
  91. self.viewLua.bossName.text.text = bossName
  92. if bossIcon ~= nil and bossIcon ~= "" then
  93. CommonUtil.LoadIcon(self.host, bossIcon, function (sprite)
  94. self.viewLua.bossIcon.image.sprite = sprite
  95. end)
  96. end
  97. local natureCfg = ManagerContainer.CfgMgr:GetNatureDataById(self.bossActor.NatureId)
  98. if natureCfg ~= nil then
  99. CommonUtil.LoadIcon(self.host, natureCfg.Icon, function (sprite)
  100. self.viewLua.bossNature.image.sprite = sprite
  101. end)
  102. end
  103. end
  104. function BattleBossBloodPart:HideBossBattleInfo()
  105. LuaBattleBridge.SetTweenFillAmount(self.viewLua.bossBlood2,false)
  106. self:Clear()
  107. end
  108. function BattleBossBloodPart:OnRefreshBossLife(life,maxLife)
  109. local deltaLife = (self.lastLife - life)/maxLife
  110. if deltaLife > 0 and deltaLife < self.minDeltaBlood and life > 0 then --掉血的时候,如果没有一定的数值不进行血条的变化
  111. return
  112. end
  113. self.lastLife = life
  114. self.viewLua.bossBlood.image.fillAmount = life / maxLife
  115. LuaBattleBridge.TweemFillAmount(self.viewLua.bossBlood2,life / maxLife,0.5)
  116. if life == 0 then
  117. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Boss_Dead)
  118. -- self.viewLua.bossBloodNode.animator:Play("BossBloddClose");
  119. end
  120. end
  121. function BattleBossBloodPart:OnRefreshBossBuff(buffIcon,num)
  122. if self:HasBuffIconGo(buffIcon) then
  123. local go = self:GetBuffIconGo(buffIcon)
  124. if go ~= nil then
  125. local numTxt = go.transform:Find("num"):GetComponent(Enum.TypeInfo.TextMeshProUGUI)
  126. if numTxt ~= nil then
  127. if num > 0 then
  128. numTxt.text = tostring(num)
  129. else
  130. numTxt.text = ""
  131. end
  132. end
  133. end
  134. return
  135. end
  136. local buffGo = UnityEngine.GameObject.Instantiate(self.viewLua.buffTemp)
  137. buffGo:SetActive(true)
  138. buffGo.transform:SetParent(self.viewLua.buffTemp.transform.parent)
  139. buffGo.transform.localScale = Vector3.one
  140. buffGo.transform.localPosition = Vector3.zero
  141. buffGo.name = buffIcon
  142. local temps = string.split(buffIcon, '/')
  143. local buffDesc = ""
  144. if temps ~= nil and #temps > 0 then
  145. buffDesc = temps[#temps].."_Desc"
  146. end
  147. self.bossBuffs[#self.bossBuffs+1] = {icon = buffIcon, go = buffGo,desc = buffDesc}
  148. self:LoadBuffIcon(buffGo,buffIcon,num,buffDesc)
  149. end
  150. function BattleBossBloodPart:OnRefreshRemoveBossBuff(buffIcon)
  151. if self:HasBuffIconGo(buffIcon) then
  152. self:RemoveBuffIconGo(buffIcon)
  153. end
  154. end
  155. function BattleBossBloodPart:HasBuffIconGo(buffIcon)
  156. if self.bossBuffs == nil then
  157. return false
  158. end
  159. for i = 1, #self.bossBuffs do
  160. if self.bossBuffs[i].icon == buffIcon then
  161. return true
  162. end
  163. end
  164. return false
  165. end
  166. function BattleBossBloodPart:GetBuffIconGo(buffIcon)
  167. if self.bossBuffs == nil then
  168. return nil
  169. end
  170. for i = 1, #self.bossBuffs do
  171. if self.bossBuffs[i].icon == buffIcon then
  172. return self.bossBuffs[i].go
  173. end
  174. end
  175. return nil
  176. end
  177. function BattleBossBloodPart:LoadBuffIcon(buffGo,buffIcon,num,desc)
  178. if buffGo == nil or buffIcon == nil then
  179. return
  180. end
  181. local img = buffGo.transform:Find("Image"):GetComponent(Enum.TypeInfo.Image)
  182. if img == nil then
  183. return
  184. end
  185. local numTxt = buffGo.transform:Find("num"):GetComponent(Enum.TypeInfo.TextMeshProUGUI)
  186. if numTxt ~= nil then
  187. if num > 0 then
  188. numTxt.text = tostring(num)
  189. else
  190. numTxt.text = ""
  191. end
  192. end
  193. local btn = buffGo.transform:GetComponent(Enum.TypeInfo.Button)
  194. if btn ~= nil then
  195. self.host.uiBase:AddButtonUniqueEventListener(btn, self, self.OnClickBuff,desc)
  196. end
  197. local handler = CommonUtil.LoadIcon(self.host, buffIcon, function (sprite)
  198. self.bossBuffLoadHandlers[buffIcon] = nil
  199. if img ~= nil and sprite ~= nil then
  200. img.sprite = sprite
  201. end
  202. end)
  203. self.bossBuffLoadHandlers[buffIcon] = handler
  204. end
  205. function BattleBossBloodPart:OnClickBuff(btn,params)
  206. ManagerContainer.LuaUIMgr:ShowMinTips(params[0])
  207. end
  208. function BattleBossBloodPart:RemoveBuffIconGo(buffIcon)
  209. if self.bossBuffs ~= nil then
  210. for i = 1, #self.bossBuffs do
  211. if self.bossBuffs[i].icon == buffIcon then
  212. self:RemoveBuffLoadHandler(buffIcon)
  213. CommonUtil.DestroyGO(self.bossBuffs[i].go)
  214. self.bossBuffs[i].go = nil
  215. table.remove(self.bossBuffs, i)
  216. return
  217. end
  218. end
  219. end
  220. end
  221. function BattleBossBloodPart:RemoveBuffLoadHandler(buffIcon)
  222. if self.bossBuffLoadHandlers[buffIcon] ~= nil then
  223. ManagerContainer.ResMgr:ClearUIAsyncLoadReqsBySeqId(self.bossBuffLoadHandlers[buffIcon])
  224. self.bossBuffLoadHandlers[buffIcon] = nil
  225. end
  226. end
  227. function BattleBossBloodPart:Clear()
  228. self:RemoveTimer()
  229. if self.bossBuffLoadHandlers ~= nil then
  230. for k,p in pairs(self.bossBuffLoadHandlers) do
  231. if p > 0 then
  232. ManagerContainer.ResMgr:ClearUIAsyncLoadReqsBySeqId(p)
  233. end
  234. end
  235. self.bossBuffLoadHandlers = nil
  236. end
  237. if self.bossBuffs ~= nil then
  238. for i = 1, #self.bossBuffs do
  239. CommonUtil.DestroyGO(self.bossBuffs[i].go)
  240. end
  241. self.bossBuffs = nil
  242. end
  243. end
  244. function BattleBossBloodPart:Dispose()
  245. self:Clear()
  246. -- 解决ID1001907
  247. self:RemoveEventListener()
  248. self.minDeltaBlood = 0
  249. self.host = nil
  250. self.viewLua = nil
  251. end
  252. return BattleBossBloodPart