BattleBossBloodPart.lua 9.4 KB

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