UIGuildHuntBattleView.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. local UIGuildHuntBattleView = require("UIGuild/UIGuildHuntBattleView_Generate")
  2. local BattleHeadsBoxPart = require("UIBattle/BattleHeadsBoxPart")
  3. -- local GUILD_HUNT_BATTLE_SPEED_KEY = 'GUILD_HUNT_BATTLE_SPEED'
  4. local BOX_ANIM_TIME = 0.86
  5. local MinChangePercent = 0.1
  6. function UIGuildHuntBattleView:OnAwake(data)
  7. self.controller = require("UIGuild/UIGuildHuntBattleCtr"):new()
  8. self.controller:Init(self)
  9. self.controller:SetData(data)
  10. end
  11. function UIGuildHuntBattleView:AddEventListener()
  12. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.GUILD_HUNT_BOSS_HURT_CHANGED, self, self.OnHurtChanged)
  13. end
  14. function UIGuildHuntBattleView:FillContent(data, uiBase)
  15. self.uiBase = uiBase
  16. local gameObject = self.uiBase:GetRoot()
  17. if gameObject ~= nil then
  18. self.gameObject = gameObject
  19. self.transform = gameObject.transform
  20. end
  21. self:InitGenerate(self.transform, data)
  22. self:Init()
  23. end
  24. function UIGuildHuntBattleView:Init()
  25. local isDemon = self.controller:GetData()
  26. self.huntGroup:SetActive(not isDemon)
  27. self.demonGroup:SetActive(isDemon)
  28. if not isDemon then
  29. LuaBattleBridge.TweemFillAmount(self.bossBlood, 0, 0)
  30. self.bossBlood2.image.fillAmount = 0
  31. self:RefreshAwards()
  32. else
  33. self.lastharm = 0
  34. local sommonId = ManagerContainer.DataMgr.GuildDemonData:GetSommonId()
  35. local npcCfg = ManagerContainer.CfgMgr:GetNpcCfgById(sommonId)
  36. if npcCfg then
  37. CommonUtil.LoadIcon(self, Constant.Natural_Icons..npcCfg.NatureId, function(sprite)
  38. self.bossNature.image.sprite = sprite
  39. end)
  40. CommonUtil.LoadIcon(self, npcCfg.Head, function(sprite)
  41. self.bossIcon.image.sprite = sprite
  42. end)
  43. end
  44. --Constant.Natural_Icons
  45. end
  46. self.controller:InitData()
  47. self.hurtChanged = true
  48. self:RefreshBlood()
  49. if not self.bloodTimer then
  50. self.bloodTimer = FrameTimer.New(slot(self.RefreshBlood, self), 1, -1)
  51. end
  52. if not self.bloodTimer.running then
  53. self.bloodTimer:Start()
  54. end
  55. -- local curSpeed = ManagerContainer.LuaGameMgr:GetGameSpeed()
  56. -- local saveSpeed = ManagerContainer.PlayerPrefsMgr:GetInt(GUILD_HUNT_BATTLE_SPEED_KEY, curSpeed)
  57. -- if curSpeed ~= saveSpeed then
  58. -- ManagerContainer.LuaGameMgr:SetGameSpeed(saveSpeed)
  59. -- curSpeed = saveSpeed
  60. -- end
  61. -- self.btnSpeed.speed1:SetActive(curSpeed == 1)
  62. -- self.btnSpeed.speed2:SetActive(curSpeed == 2)
  63. self.leftFightingTime = self.controller:FightingTime()
  64. self.leftTime.text.text = FormatTimeMS(self.leftFightingTime)
  65. -- 不能用1000,因为如果速度加快了,就不是1秒变化了
  66. self.leftFightingTimeHandler = ManagerContainer.LuaTimerMgr:AddTimer(300, -1, self, self.OnShowLeftFightingTime, nil)
  67. if self.HeadsBoxPart == nil then
  68. self.HeadsBoxPart = BattleHeadsBoxPart:new()
  69. end
  70. self.HeadsBoxPart:InitGo(self,self.uiBase:FindChildGo("UIBattle/BattleHeadsBox"))
  71. self.HeadsBoxPart:Show()
  72. end
  73. function UIGuildHuntBattleView:RemoveEventListener()
  74. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  75. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.EID_Refresh_Boss_Buff,self,self.OnRefreshBossBuff);
  76. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.EID_Refresh_Boss_Remove_Buff,self,self.OnRefreshRemoveBossBuff);
  77. end
  78. function UIGuildHuntBattleView:AddUIEventListener()
  79. -- self.uiBase:AddButtonUniqueEventListener(self.btnSpeed.button, self, self.OnClickSpeedBtn)
  80. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.EID_Refresh_Boss_Buff,self,self.OnRefreshBossBuff);
  81. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.EID_Refresh_Boss_Remove_Buff,self,self.OnRefreshRemoveBossBuff);
  82. self.HeadsBoxPart:AddUIEventListener()
  83. end
  84. function UIGuildHuntBattleView:OnHide()
  85. end
  86. -----------------------------------Boss buff
  87. function UIGuildHuntBattleView:OnRefreshRemoveBossBuff(buffIcon)
  88. if self:HasBuffIconGo(buffIcon) then
  89. self:RemoveBuffIconGo(buffIcon)
  90. end
  91. end
  92. function UIGuildHuntBattleView:HasBuffIconGo(buffIcon)
  93. if self.bossBuffs == nil then
  94. return false
  95. end
  96. for i = 1, #self.bossBuffs do
  97. if self.bossBuffs[i].icon == buffIcon then
  98. return true
  99. end
  100. end
  101. return false
  102. end
  103. function UIGuildHuntBattleView:GetBuffIconGo(buffIcon)
  104. if self.bossBuffs == nil then
  105. return nil
  106. end
  107. for i = 1, #self.bossBuffs do
  108. if self.bossBuffs[i].icon == buffIcon then
  109. return self.bossBuffs[i].go
  110. end
  111. end
  112. return nil
  113. end
  114. function UIGuildHuntBattleView:LoadBuffIcon(buffGo,buffIcon,num,desc)
  115. if buffGo == nil or buffIcon == nil then
  116. return
  117. end
  118. local img = buffGo.transform:Find("Image"):GetComponent(Enum.TypeInfo.Image)
  119. if img == nil then
  120. return
  121. end
  122. local numTxt = buffGo.transform:Find("num"):GetComponent(Enum.TypeInfo.TextMeshProUGUI)
  123. if numTxt ~= nil then
  124. if num > 0 then
  125. numTxt.text = tostring(num)
  126. else
  127. numTxt.text = ""
  128. end
  129. end
  130. local btn = buffGo.transform:GetComponent(Enum.TypeInfo.Button)
  131. if btn ~= nil then
  132. self.uiBase:AddButtonUniqueEventListener(btn, self, self.OnClickBuff,desc)
  133. end
  134. local handler = CommonUtil.LoadIcon(self, buffIcon, function (sprite)
  135. self.bossBuffLoadHandlers[buffIcon] = nil
  136. if img ~= nil and sprite ~= nil then
  137. img.sprite = sprite
  138. end
  139. end)
  140. if nil == self.bossBuffLoadHandlers then
  141. self.bossBuffLoadHandlers = {}
  142. end
  143. self.bossBuffLoadHandlers[buffIcon] = handler
  144. end
  145. function UIGuildHuntBattleView:OnRefreshBossBuff(buffIcon,num)
  146. if self:HasBuffIconGo(buffIcon) then
  147. local go = self:GetBuffIconGo(buffIcon)
  148. if go ~= nil then
  149. local numTxt = go.transform:Find("num"):GetComponent(Enum.TypeInfo.TextMeshProUGUI)
  150. if numTxt ~= nil then
  151. if num > 0 then
  152. numTxt.text = tostring(num)
  153. else
  154. numTxt.text = ""
  155. end
  156. end
  157. end
  158. return
  159. end
  160. local buffGo = UnityEngine.GameObject.Instantiate(self.buffTemp)
  161. buffGo:SetActive(true)
  162. buffGo.transform:SetParent(self.buffTemp.transform.parent)
  163. buffGo.transform.localScale = Vector3.one
  164. buffGo.transform.localPosition = Vector3.zero
  165. buffGo.name = buffIcon
  166. local temps = string.split(buffIcon, '/')
  167. local buffDesc = ""
  168. if temps ~= nil and #temps > 0 then
  169. buffDesc = temps[#temps].."_Desc"
  170. end
  171. if nil == self.bossBuffs then
  172. self.bossBuffs = {}
  173. end
  174. self.bossBuffs[#self.bossBuffs+1] = {icon = buffIcon, go = buffGo,desc = buffDesc}
  175. self:LoadBuffIcon(buffGo,buffIcon,num,buffDesc)
  176. end
  177. function UIGuildHuntBattleView:OnClickBuff(btn,params)
  178. ManagerContainer.LuaUIMgr:ShowMinTips(params[0])
  179. end
  180. function UIGuildHuntBattleView:RemoveBuffIconGo(buffIcon)
  181. if self.bossBuffs ~= nil then
  182. for i = 1, #self.bossBuffs do
  183. if self.bossBuffs[i].icon == buffIcon then
  184. self:RemoveBuffLoadHandler(buffIcon)
  185. CommonUtil.DestroyGO(self.bossBuffs[i].go)
  186. self.bossBuffs[i].go = nil
  187. table.remove(self.bossBuffs, i)
  188. return
  189. end
  190. end
  191. end
  192. end
  193. function UIGuildHuntBattleView:RemoveBuffLoadHandler(buffIcon)
  194. if self.bossBuffLoadHandlers[buffIcon] ~= nil then
  195. ManagerContainer.ResMgr:ClearUIAsyncLoadReqsBySeqId(self.bossBuffLoadHandlers[buffIcon])
  196. self.bossBuffLoadHandlers[buffIcon] = nil
  197. end
  198. end
  199. function UIGuildHuntBattleView:Clear()
  200. if self.bossBuffLoadHandlers ~= nil then
  201. for k,p in pairs(self.bossBuffLoadHandlers) do
  202. if p > 0 then
  203. ManagerContainer.ResMgr:ClearUIAsyncLoadReqsBySeqId(p)
  204. end
  205. end
  206. self.bossBuffLoadHandlers = nil
  207. end
  208. if self.bossBuffs ~= nil then
  209. for i = 1, #self.bossBuffs do
  210. CommonUtil.DestroyGO(self.bossBuffs[i].go)
  211. end
  212. self.bossBuffs = nil
  213. end
  214. end
  215. ---------------
  216. function UIGuildHuntBattleView:OnShow(data)
  217. self.controller:SetData(data)
  218. end
  219. function UIGuildHuntBattleView:OnClose()
  220. self:ClearLeftFightingTimer()
  221. if self.HeadsBoxPart ~= nil then
  222. self.HeadsBoxPart:Dispose()
  223. self.HeadsBoxPart = nil
  224. end
  225. if self.bloodTimer then
  226. self.bloodTimer:Stop()
  227. self.bloodTimer = nil
  228. end
  229. end
  230. function UIGuildHuntBattleView:OnDispose()
  231. self.controller:OnDispose()
  232. end
  233. function UIGuildHuntBattleView:OnHurtChanged()
  234. self.hurtChanged = true
  235. end
  236. -- function UIGuildHuntBattleView:OnClickSpeedBtn()
  237. -- if ManagerContainer.LuaGameMgr:GetGameSpeed() == 2 then
  238. -- ManagerContainer.LuaGameMgr:SetGameSpeed(1)
  239. -- ManagerContainer.PlayerPrefsMgr:SetInt(GUILD_HUNT_BATTLE_SPEED_KEY, 1)
  240. -- self.btnSpeed.speed2:SetActive(false)
  241. -- self.btnSpeed.speed1:SetActive(true)
  242. -- else
  243. -- ManagerContainer.LuaGameMgr:SetGameSpeed(2)
  244. -- ManagerContainer.PlayerPrefsMgr:SetInt(GUILD_HUNT_BATTLE_SPEED_KEY, 2)
  245. -- self.btnSpeed.speed2:SetActive(true)
  246. -- self.btnSpeed.speed1:SetActive(false)
  247. -- end
  248. -- end
  249. function UIGuildHuntBattleView:OnShowLeftFightingTime()
  250. self.leftFightingTime = self.controller:FightingTime()
  251. if self.leftFightingTime <= 0 then
  252. self:ClearLeftFightingTimer()
  253. end
  254. self.leftTime.text.text = FormatTimeMS(self.leftFightingTime)
  255. end
  256. function UIGuildHuntBattleView:ClearLeftFightingTimer()
  257. if self.leftFightingTimeHandler ~= nil then
  258. ManagerContainer.LuaTimerMgr:RemoveTimer(self.leftFightingTimeHandler)
  259. self.leftFightingTimeHandler = nil
  260. end
  261. end
  262. function UIGuildHuntBattleView:RefreshAwards()
  263. local iconPath = self.controller:GetRewardIcon()
  264. CommonUtil.LoadIcon(self, iconPath, function(sprite)
  265. self.iconBox.image.sprite = sprite
  266. end)
  267. local num = self.controller:GetRewardNum()
  268. self.lvNumber.text.text = tostring(num)
  269. end
  270. function UIGuildHuntBattleView:RefreshBlood()
  271. if not self.hurtChanged then return end
  272. self.hurtChanged = false
  273. local isDemon = self.controller:GetData()
  274. if not isDemon then
  275. local curDamage = self.controller:GetCurDamage()
  276. local min, max = self.controller:GetCurRewardRange()
  277. self.hPNumber.text.text = tostring(curDamage) .. '/' .. tostring(max)
  278. local percentVal = curDamage - min
  279. local percentValMax = max - min
  280. local percent = 0
  281. if percentValMax <= 0 then
  282. percent = 1
  283. else
  284. percent = (percentVal / percentValMax)
  285. end
  286. if percent >= 1 then
  287. self.boxBg.animator:Play('BoxIn', -1, 0)
  288. self.boxBg.animator:Update(0)
  289. percent = 1
  290. end
  291. if percent < MinChangePercent then
  292. LuaBattleBridge.TweemFillAmount(self.bossBlood, 0, 0)
  293. self.bossBlood2.image.fillAmount = 0
  294. else
  295. if self.bossBlood.image.fillAmount > percent then
  296. self.bossBlood.image.fillAmount = 0
  297. end
  298. LuaBattleBridge.TweemFillAmount(self.bossBlood, percent, BOX_ANIM_TIME)
  299. self.bossBlood2.image.fillAmount = percent
  300. end
  301. if self.controller:RefreshDamage() then
  302. self:RefreshAwards()
  303. end
  304. else
  305. local harm = ManagerContainer.DataMgr.GuildDemonData:GetRecordDemonValue()
  306. if harm > self.lastharm then
  307. self.number.animator:Play('DmgNumber', -1, 0)
  308. self.number.animator:Update(0)
  309. self.lastharm = harm
  310. end
  311. local harmStr = CommonUtil.FormatNumber(harm,true)
  312. local lenth = #harmStr
  313. for i = 1, 10 do
  314. local tpStr = string.sub(harmStr,i,i)
  315. if tpStr == '.' then
  316. tpStr = 'del'
  317. end
  318. if i <= lenth then
  319. self["lable"..i]:SetActive(true)
  320. CommonUtil.LoadIcon(self, "IconScore/demon_number_"..tpStr, function(sprite)
  321. self["lable"..i].image.sprite = sprite
  322. end)
  323. else
  324. self["lable"..i]:SetActive(false)
  325. end
  326. end
  327. end
  328. end
  329. return UIGuildHuntBattleView