BattleStatisticsPart.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. local BattleStatisticsPart = class("BattleStatisticsPart")
  2. local DelayTime = 10
  3. function BattleStatisticsPart:ctor()
  4. end
  5. function BattleStatisticsPart:InitGo(host,uiGo)
  6. self.host = host
  7. self.viewLua = CommonUtil.BindGridViewItem2Lua(self.host, "BattleStatistics", uiGo)
  8. end
  9. function BattleStatisticsPart:InitPanel()
  10. self.viewLua.btnQuit:SetActive(false)
  11. --延迟显示
  12. local bIsReplay = LuaBattleBridge.CurrentBattleIsPlayRecord()
  13. if not bIsReplay then
  14. local enBattleMode = LuaBattleBridge.CurrentBattleMode()
  15. local enSubMode = LuaBattleBridge.CurrentBattleSubMode()
  16. if enBattleMode == BattleMode.Normal then --巡游BOOS
  17. DelayTime = self:GetQuitShowDelay(Enum.TaskType.Level_Battle_Count)
  18. elseif enSubMode == BattleSubMode.ClimbingTower then --爬塔
  19. DelayTime = self:GetQuitShowDelay(Enum.TaskType.Climbing_Tower_Level)
  20. end
  21. if nil ~= DelayTime then
  22. self:StartTimer(function() self:ShowQuitBtn() end,{duration = DelayTime})
  23. end
  24. end
  25. self:RefreshSpeedStatus(true)
  26. end
  27. function BattleStatisticsPart:Show(mode,battleSubMode)
  28. self:InitPanel()
  29. self.hidePnl = false
  30. self.statisticsActorNodes = {}
  31. self.statisticsActorNodes[#self.statisticsActorNodes+1] = self.viewLua.playerNode1
  32. self.statisticsActorNodes[#self.statisticsActorNodes+1] = self.viewLua.playerNode2
  33. self.statisticsActorNodes[#self.statisticsActorNodes+1] = self.viewLua.playerNode3
  34. self.statisticsActorNodes[#self.statisticsActorNodes+1] = self.viewLua.playerNode4
  35. for i = 1, #self.statisticsActorNodes do
  36. self.statisticsActorNodes[i]:SetActive(false)
  37. end
  38. self.data = LuaBattleBridge.GetBattleStatistics(mode,battleSubMode)
  39. self:OnRefreshStatistics()
  40. self.viewLua:SetActive(true)
  41. self:AddEventListener()
  42. end
  43. --退出按钮
  44. function BattleStatisticsPart:ShowQuitBtn()
  45. local bIsShow = false
  46. local enBattleMode = LuaBattleBridge.CurrentBattleMode()
  47. local enSubMode = LuaBattleBridge.CurrentBattleSubMode()
  48. if enBattleMode == BattleMode.Normal then --巡游BOOS
  49. local ConditionValue = self:GetQuitShowCondition(Enum.TaskType.Level_Battle_Count)
  50. local curMapId,curLevelId = ManagerContainer.LuaBattleMgr:GetCurMapAndLevel() --当前关卡
  51. local curUniqueId = curMapId * 10000 + curLevelId
  52. if ConditionValue ~= nil and curUniqueId >= ConditionValue then
  53. bIsShow = true
  54. end
  55. elseif enSubMode == BattleSubMode.ClimbingTower then --爬塔
  56. local TwerLevle = ManagerContainer.DataMgr.TowerDataMgr:GetCurChallengeLevel()
  57. local ConditionValue = self:GetQuitShowCondition(Enum.TaskType.Climbing_Tower_Level)
  58. if ConditionValue ~= nil and TwerLevle >= ConditionValue then
  59. bIsShow = true
  60. end
  61. end
  62. self.viewLua.btnQuit:SetActive(bIsShow)
  63. end
  64. --退出按钮延迟时间获取
  65. function BattleStatisticsPart:GetQuitShowDelay(TaskType)
  66. local val = GlobalConfig.Instance:GetConfigStrValue(264)
  67. return self:ParseData(val,TaskType)
  68. end
  69. --退出按鈕條件
  70. function BattleStatisticsPart:GetQuitShowCondition(TaskType)
  71. local val = GlobalConfig.Instance:GetConfigStrValue(263)
  72. return self:ParseData(val,TaskType)
  73. end
  74. --解析數據
  75. function BattleStatisticsPart:ParseData(val,TaskType)
  76. if val == "" or val == nil then
  77. return nil
  78. end
  79. local ShowCondition = CommonUtil.DeserializeGlobalStrToTable(val)
  80. if ShowCondition[1][1] == "" or ShowCondition[1][1] == nil then
  81. return nil
  82. end
  83. if tonumber(ShowCondition[1][1]) == TaskType then
  84. return tonumber(ShowCondition[1][2])
  85. end
  86. if ShowCondition[2][1] == "" or ShowCondition[2][1] == nil then
  87. return nil
  88. end
  89. if tonumber(ShowCondition[2][1]) == TaskType then
  90. return tonumber(ShowCondition[2][2])
  91. end
  92. return nil
  93. end
  94. function BattleStatisticsPart:Hide()
  95. self:ResetData()
  96. self:RemoveEventListener()
  97. self:Clear()
  98. self.viewLua:SetActive(false)
  99. ManagerContainer.LuaUIMgr:CloseMessageBox("QuitBattleTip")
  100. end
  101. function BattleStatisticsPart:SetCanvasOrder(order)
  102. self.viewLua.canvas.sortingOrder = order
  103. end
  104. function BattleStatisticsPart:StartTimer(func, data)
  105. self:StopTimer()
  106. if data.isFrame then
  107. self.timer = FrameTimer.New(func, data.duration)
  108. else
  109. self.timer = Timer.New(func, data.duration)
  110. end
  111. self.timer:Start()
  112. end
  113. function BattleStatisticsPart:StopTimer()
  114. if self.timer then
  115. self.timer:Stop()
  116. self.timer = nil
  117. end
  118. end
  119. function BattleStatisticsPart:AddEventListener()
  120. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.EID_Refresh_BattleStatistics,self,self.OnRefreshStatistics);
  121. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.EID_Battle_UI_VISIBLE,self,self.OnUIPartVisible);
  122. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.VIP_LV_CHANGED, self, self.OnVipLvChanged)
  123. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.RUNE_SHOP_DATA_CHANGED, self, self.OnRuneShopDataChanged)
  124. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.BATTLE_ACC_TIME_CHANGED, self, self.OnBattleAccTimeChanged)
  125. end
  126. function BattleStatisticsPart:RemoveEventListener()
  127. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.EID_Refresh_BattleStatistics,self,self.OnRefreshStatistics);
  128. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.EID_Battle_UI_VISIBLE,self,self.OnUIPartVisible);
  129. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.VIP_LV_CHANGED, self, self.OnVipLvChanged)
  130. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.RUNE_SHOP_DATA_CHANGED, self, self.OnRuneShopDataChanged)
  131. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.BATTLE_ACC_TIME_CHANGED, self, self.OnBattleAccTimeChanged)
  132. end
  133. function BattleStatisticsPart:AddUIEventListener()
  134. self.host.uiBase:AddButtonEventListener(self.viewLua.btnSpeed.button,self, self.OnClickBtnSpeed)
  135. self.host.uiBase:AddButtonEventListener(self.viewLua.viewDetailBtn.button,self, self.OnClickOpenStatisticPage)
  136. self.host.uiBase:AddButtonEventListener(self.viewLua.hideBtn.button,self, self.OnClickHide)
  137. self.host.uiBase:AddButtonEventListener(self.viewLua.btnQuit.button,self, self.OnClickQuit)
  138. end
  139. function BattleStatisticsPart:OnClickBtnSpeed()
  140. if not ManagerContainer.DataMgr.RuneShopDataMgr:CheckSpecialPrivilegeSpeed()
  141. and not self:CheckVipData()
  142. and not self.hasSpeedItem then
  143. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("SpeedUpLock")
  144. ManagerContainer.LuaGameMgr:LuaSaveGameSpeed(1)
  145. return
  146. end
  147. if ManagerContainer.LuaGameMgr:GetGameSpeed() == 2 then
  148. ManagerContainer.LuaGameMgr:LuaSaveGameSpeed(1)
  149. self.viewLua.btnSpeed.speed2:SetActive(false)
  150. self.viewLua.btnSpeed.speed1:SetActive(true)
  151. if self.hasSpeedItem then
  152. self.viewLua.targetPoint:SetActive(true)
  153. end
  154. else
  155. ManagerContainer.LuaGameMgr:LuaSaveGameSpeed(ManagerContainer.LuaGameMgr:GetGameSpeed()+1)
  156. self.viewLua.btnSpeed.speed2:SetActive(true)
  157. self.viewLua.btnSpeed.speed1:SetActive(false)
  158. if self.hasSpeedItem then
  159. self.viewLua.targetPoint:SetActive(false)
  160. end
  161. end
  162. end
  163. function BattleStatisticsPart:OnClickOpenStatisticPage()
  164. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIBattleStatistics,{LuaBattleBridge.CurrentBattleMode(),LuaBattleBridge.CurrentBattleSubMode()})
  165. end
  166. function BattleStatisticsPart:OnClickHide()
  167. if self.hidePnl == false then
  168. self.viewLua.battleCountAnim.animator:Play("UIBattleCountOut")
  169. self.hidePnl = true
  170. else
  171. self.viewLua.battleCountAnim.animator:Play("UIBattleCountIn")
  172. self.hidePnl = false
  173. end
  174. end
  175. --二次确认框退出战斗
  176. function BattleStatisticsPart:OnClickQuit()
  177. ManagerContainer.LuaUIMgr:ShowMessageBox("QuitBattleTip",nil,nil,self,self.OnForceStopBattle,nil)
  178. end
  179. --强制退出战斗
  180. function BattleStatisticsPart:OnForceStopBattle()
  181. ManagerContainer.LuaGameMgr:ForceStopBattle()
  182. ManagerContainer.LuaBattleMgr:StopAutoChallenge(true)
  183. --ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_BATTLE_FAILED,true,false);
  184. end
  185. function BattleStatisticsPart:RefreshSpeedStatus(isFirst)
  186. if not self.viewLua then
  187. self:StopSpeedTimer()
  188. return
  189. end
  190. if not Constant.OpenPay then
  191. self.viewLua.btnSpeed:SetActive(false)
  192. self:StopSpeedTimer()
  193. return
  194. end
  195. self.viewLua.btnSpeed:SetActive(true)
  196. self.viewLua.btnSpeed.speed1:SetActive(true)
  197. self.viewLua.btnSpeed.speed2:SetActive(false)
  198. local vipState = self:CheckVipData()
  199. local monthState = ManagerContainer.DataMgr.RuneShopDataMgr:CheckSpecialPrivilegeSpeed()
  200. if vipState or monthState then
  201. if ManagerContainer.LuaGameMgr.GameSpeed ~= 1 then
  202. self.viewLua.btnSpeed.speed1:SetActive(false)
  203. self.viewLua.btnSpeed.speed2:SetActive(true)
  204. end
  205. self:StopSpeedTimer()
  206. self.viewLua.speedtime:SetActive(false)
  207. self.viewLua.targetPoint:SetActive(false)
  208. else
  209. local hasSpeedItem = self.hasSpeedItem
  210. if isFirst then
  211. local sec = ManagerContainer.DataMgr.BattleAccTimeManager:GetValidTime()
  212. hasSpeedItem = (sec and sec > 0 or false)
  213. self.hasSpeedItem = hasSpeedItem
  214. end
  215. self.viewLua.speedtime:SetActive(hasSpeedItem)
  216. self.viewLua.targetPoint:SetActive(hasSpeedItem and ManagerContainer.LuaGameMgr.GameSpeed == 1)
  217. if hasSpeedItem then
  218. if ManagerContainer.LuaGameMgr.GameSpeed ~= 1 then
  219. self.viewLua.btnSpeed.speed1:SetActive(false)
  220. self.viewLua.btnSpeed.speed2:SetActive(true)
  221. end
  222. self:RefreshSpeedTimer()
  223. else
  224. ManagerContainer.LuaGameMgr:LuaSaveGameSpeed(1)
  225. self:StopSpeedTimer()
  226. end
  227. end
  228. end
  229. function BattleStatisticsPart:RefreshSpeedTimer()
  230. local sec = ManagerContainer.DataMgr.BattleAccTimeManager:GetValidTime()
  231. if not sec or sec <= 0 then
  232. local timeStr = CommonUtil.FormatTimeDMS(-1)
  233. self.viewLua.speedtime.time.text.text = string.formatbykey('SpeedCardTime', timeStr)
  234. self:StopSpeedTimer()
  235. return
  236. end
  237. if self.viewLua then
  238. local timeStr = CommonUtil.FormatTimeDMS(sec)
  239. self.viewLua.speedtime.time.text.text = string.formatbykey('SpeedCardTime', timeStr)
  240. end
  241. local validTime
  242. if sec >= 86400 then
  243. validTime = sec % 3600
  244. if validTime == 0 then validTime = 3600 end
  245. elseif sec >= 3600 then
  246. validTime = sec % 60
  247. if validTime == 0 then validTime = 60 end
  248. else
  249. validTime = 1
  250. end
  251. if self.speedTimer then
  252. self.speedTimer.duration = validTime
  253. else
  254. self.speedTimer = Timer.New(slot(self.RefreshSpeedTimer, self), validTime, -1, true)
  255. end
  256. if not self.speedTimer.running then
  257. self.speedTimer:Start()
  258. end
  259. end
  260. function BattleStatisticsPart:StopSpeedTimer()
  261. if self.speedTimer then
  262. if self.speedTimer.running then
  263. self.speedTimer:Stop()
  264. end
  265. self.speedTimer = nil
  266. end
  267. end
  268. function BattleStatisticsPart:OnVipLvChanged()
  269. self:RefreshSpeedStatus()
  270. end
  271. function BattleStatisticsPart:OnRuneShopDataChanged(runeShopType, runeShopSubType)
  272. if runeShopType == Enum.RuneShopType.SpecialPrivilege then
  273. self:RefreshSpeedStatus()
  274. end
  275. end
  276. function BattleStatisticsPart:OnBattleAccTimeChanged()
  277. self:RefreshSpeedStatus()
  278. end
  279. function BattleStatisticsPart:CheckVipData()
  280. local vipLv = ManagerContainer.DataMgr.UserData:GetVipLv()
  281. if not vipLv then
  282. return false
  283. end
  284. local vipCfg = ManagerContainer.CfgMgr:GetVipCfgById(vipLv)
  285. if vipCfg then
  286. if vipCfg.QuickBattle then
  287. if vipCfg.QuickBattle >= 1 then
  288. return true
  289. end
  290. end
  291. end
  292. return false
  293. end
  294. function BattleStatisticsPart:OnUIPartVisible(vis)
  295. self.viewLua:SetActive(vis)
  296. end
  297. function BattleStatisticsPart:GetSlotSortActor(tbFriend)
  298. --伙伴界面排序
  299. local sortedPartnerDatas = ManagerContainer.DataMgr.PartnerData:SortPartnerData()
  300. --根据伙伴界面排序 排序
  301. local sortedData = {}
  302. for j =1, tbFriend.Count do--主角第一
  303. local actor = tbFriend[j-1]
  304. local UserId = 1
  305. if tostring(UserId)==tostring(actor.fighterId) then
  306. table.insert(sortedData,actor)
  307. end
  308. end
  309. for i=1, #sortedPartnerDatas do --伙伴排序
  310. local PartnerData = sortedPartnerDatas[i]
  311. for j =1, tbFriend.Count do
  312. local actor = tbFriend[j-1]
  313. if tostring(PartnerData.id)==tostring(actor.fighterId) then
  314. table.insert(sortedData,actor)
  315. end
  316. end
  317. end
  318. return sortedData
  319. end
  320. function BattleStatisticsPart:OnRefreshStatistics()
  321. if self.data == nil then
  322. return
  323. end
  324. if self.data.FriendStatistics == nil then
  325. return
  326. end
  327. local friendList = self:GetSlotSortActor(self.data.FriendStatistics)
  328. if friendList == nil then
  329. return
  330. end
  331. for i = 1, #friendList do
  332. self:ShowFighterStatistics(self.statisticsActorNodes[i],friendList[i])
  333. end
  334. end
  335. function BattleStatisticsPart:ShowFighterStatistics(node,data)
  336. CommonUtil.LoadIcon(self.host, data.jobIcon, function (sprite)
  337. node.jobIcon.image.sprite = sprite
  338. end)
  339. node.playerName.text.text = data.actorName
  340. node.totalProgress.image.fillAmount = data.damagePercent
  341. node.progress.image.fillAmount = data.heroDamagePercent
  342. node.percent.text.text = CommonUtil.GetPreciseDecimal(data.damagePercent*100,2) .. "%"
  343. node:SetActive(true)
  344. end
  345. function BattleStatisticsPart:ResetData()
  346. if self.statisticsActorNodes ~= nil then
  347. for i= 1, #self.statisticsActorNodes do
  348. local node = self.statisticsActorNodes[i]
  349. node.jobIcon.image.sprite = nil
  350. node.playerName.text.text = ""
  351. node.totalProgress.image.fillAmount = 0
  352. node.progress.image.fillAmount = 0
  353. node.percent.text.text = ""
  354. end
  355. end
  356. end
  357. function BattleStatisticsPart:Dispose()
  358. self:StopTimer()
  359. self:Clear()
  360. self.host = nil
  361. self.viewLua = nil
  362. end
  363. function BattleStatisticsPart:Clear()
  364. self:StopSpeedTimer()
  365. self.hasSpeedItem = nil
  366. self.statisticsActorNodes = nil
  367. self.data = nil
  368. end
  369. return BattleStatisticsPart