KLChallengeBossPosPanel.lua 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. ---@class KLChallengeBossPosPanel:UIKmlLuaPanelBase
  2. ---@field view KLChallengeBossPosPanelView
  3. local KLChallengeBossPosPanel = class(UIKmlLuaPanelBase)
  4. local this = KLChallengeBossPosPanel
  5. ---创建时调用一次
  6. function this:Init()
  7. GUI:DataListInitData(self.view.boss_pos_dl,function()
  8. return self:GoldBossPosDataListItemCountFunc()
  9. end,function(realIndex)
  10. return self:GoldBossPosDataListItemGetFunc(realIndex)
  11. end,function(realIndex, kmlcontrol)
  12. return self:GoldBossPosDataListItemInitFunc(realIndex, kmlcontrol)
  13. end, function(realIndex, kmlcontrol)
  14. return self:GoldBossPosDataListItemUpdateFunc(realIndex, kmlcontrol)
  15. end)
  16. self.boss_Pos_all_item = {}
  17. GUI:DataListInitData(self.view.hurt_root_dl,function()
  18. return self:GoldBossHurtDataListItemCountFunc()
  19. end,function(realIndex)
  20. return self:GoldBossHurtDataListItemGetFunc(realIndex)
  21. end,function(realIndex, kmlcontrol)
  22. return self:GoldBossHurtDataListItemInitFunc(realIndex, kmlcontrol)
  23. end, function(realIndex, kmlcontrol)
  24. return self:GoldBossHurtDataListItemUpdateFunc(realIndex, kmlcontrol)
  25. end)
  26. self.boss_Hurt_all_item = {}
  27. end
  28. function this:InitData(data)
  29. --SL:LogTable(data,true)
  30. self.mapId = data.mapId
  31. self.time = data.time
  32. self.is_close = false
  33. -- self.monsterInfo = data.monsterInfo
  34. self.show_pos = true
  35. self.monster1 = {}
  36. self.hurtList = {}
  37. -- for i=1,10000,1 do
  38. -- if self.monsterInfo[tostring(i)] then
  39. -- table.insert(self.monster1,self.monsterInfo[tostring(i)])
  40. -- else
  41. -- break
  42. -- end
  43. -- end
  44. -- GUI:DataListUpdateData(self.view.boss_pos_dl)
  45. self:GetBossList()
  46. if self.time > 0 then
  47. self:CopyEnd(self.time)
  48. end
  49. end
  50. function this:GetBossList()
  51. SL:SendLuaNetMsg(LuaMessageIdToSever.GET_SECRET_REALM_MONSTER_LIST, {mapId=self.mapId})
  52. end
  53. ---创建或者刷新界面数据时调用
  54. function this:Refresh()
  55. end
  56. function this:SetVisible(isVisible)
  57. GUI:setVisible(self.view.root,isVisible)
  58. end
  59. ---注册UI事件和服务器消息
  60. function this:RegistEvents()
  61. -- GUI:SetToggleOnValueChange(self.view.boss_1_toggle, self, self.Boss1Click)
  62. -- GUI:SetToggleOnValueChange(self.view.boss_2_toggle, self, self.Boss2Click)
  63. -- GUI:SetToggleOnValueChange(self.view.boss_3_toggle, self, self.Boss3Click)
  64. GUI:AddOnClickEvent(self.view.exitBtn,self,self.Exit)
  65. SL:RegisterLuaNetMsg(LuaMessageIdToClient.SECRET_REALM_DAMAGE,self.HurtChange,self) --伤害展示
  66. SL:RegisterLuaNetMsg(LuaMessageIdToClient.SECRET_REALM_BOSS_LIST,self.ResBossList,self) --怪物列表
  67. SL:RegisterLuaNetMsg(LuaMessageIdToClient.SECRET_REALM_COUNT_ZEROED,self.RecretCount,self) --挑战次数使用后
  68. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_QUIT_SECRET_REALM,self.RES_QUIT_SECRET_REALM,self) --退出秘境返回
  69. SL:RegisterLUAEvent(LUA_EVENT_MONSTER_DIE, self.MonsterDie, self) --怪物死亡
  70. SL:RegisterLUAEvent(LUA_EVENT_TARGET_CAHNGE, self.SelectAttackRole, self) --玩家目标改变
  71. SL:RegisterLUAEvent(LUA_EVENT_CHANGESCENE, self.LUA_EVENT_CHANGESCENE, self)
  72. -- SL:RegisterLuaNetMsg(LuaMessageIdToClient.SECRET_REALM_COUNT,self.SecretCount,self)
  73. end
  74. function this:UnRegistEvents()
  75. SL:UnRegisterLuaNetMsg(LuaMessageIdToClient.SECRET_REALM_DAMAGE,self.HurtChange,self) --伤害展示
  76. SL:UnRegisterLuaNetMsg(LuaMessageIdToClient.SECRET_REALM_BOSS_LIST,self.ResBossList,self) --怪物列表
  77. SL:UnRegisterLuaNetMsg(LuaMessageIdToClient.SECRET_REALM_COUNT_ZEROED,self.RecretCount,self) --挑战次数使用后
  78. SL:UnRegisterLuaNetMsg(LuaMessageIdToClient.RES_QUIT_SECRET_REALM,self.RES_QUIT_SECRET_REALM,self) --退出秘境返回
  79. SL:UnRegisterLUAEvent(LUA_EVENT_MONSTER_DIE, self.MonsterDie, self) --怪物死亡
  80. SL:UnRegisterLUAEvent(LUA_EVENT_TARGET_CAHNGE, self.SelectAttackRole, self) --玩家目标改变
  81. SL:UnRegisterLUAEvent(LUA_EVENT_CHANGESCENE, self.LUA_EVENT_CHANGESCENE, self) --地图改变
  82. end
  83. function this:Exit()
  84. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_EXIT_SECRET_REALM, {repId=self.mapId})
  85. end
  86. function this:RES_QUIT_SECRET_REALM(_id,message)
  87. self.is_close = true
  88. InfoManager.copActivityInfo.hideTask = false
  89. self:CloseOnclick()
  90. SL:onLUAEvent(LUA_EVENT_SHOW_TASK)
  91. end
  92. function this:CloseOnclick()
  93. GUI:UIPanel_Close("dev/outui/ChallengeBoss/Panel/KLChallengeBossPos/KLChallengeBossPosPanel")
  94. GUI:UIPanel_Close("dev/outui/ChallengeBoss/Panel/KLChallengeBossPos/KLChallengeBossEndPanel")
  95. SL.ShowMainPanel()
  96. end
  97. function this:ResBossList(_id,message)
  98. -- if not self.show_pos then
  99. -- return
  100. -- end
  101. --SL:LogTable(message,true)
  102. self.monster1 = {}
  103. for i=1,10000,1 do
  104. if message[tostring(i)] then
  105. table.insert(self.monster1,message[tostring(i)])
  106. else
  107. break
  108. end
  109. end
  110. GUI:DataListUpdateData(self.view.boss_pos_dl)
  111. end
  112. function this:MonsterDie(_id,message)
  113. -- SL:LogError("MonsterDie---------")
  114. -- SL:LogTable(message,true)
  115. if self.hateId and self.hateId~=0 and message == self.hateId then
  116. self:ShowPosView()
  117. end
  118. end
  119. function this:SelectAttackRole(_id,selectId)
  120. if not self.hateId or self.hateId==0 then
  121. return
  122. end
  123. -- SL:LogError("SelectAttackRole---------")
  124. -- SL:LogTable(selectId,true)
  125. -- SL:LogError(self.hateId)
  126. if selectId == 0 or self.hateId ~= selectId then
  127. self:ShowPosView()
  128. end
  129. --SL:LogTable(message,true)
  130. end
  131. function this:RecretCount(_id,message)
  132. local secretRealmCount = message.secretRealmCount
  133. if secretRealmCount ~= 0 then
  134. return
  135. end
  136. local EndPanel = GUI:UIPanel_Open("dev/outui/ChallengeBoss/Panel/KLChallengeBossEnd/KLChallengeBossEndPanel")
  137. EndPanel:InitData()
  138. self.timer1 = SL:ScheduleOnce(30.2,function ()
  139. if self.is_close then
  140. return
  141. end
  142. self:Exit()
  143. end)
  144. end
  145. function this:CopyEnd(last_time)
  146. local EndPanel = GUI:UIPanel_Open("dev/outui/ChallengeBoss/Panel/KLChallengeBossEnd/KLChallengeBossEndPanel")
  147. EndPanel:InitData(last_time)
  148. self.timer2 =SL:ScheduleOnce(last_time,function ()
  149. if self.is_close then
  150. return
  151. end
  152. self:Exit()
  153. end)
  154. end
  155. function this:ShowPosView()
  156. -- SL:LogError("ShowPosView-------")
  157. self.show_pos = true
  158. GUI:setVisible(self.view.pos_root,true)
  159. GUI:setVisible(self.view.hurt_root,false)
  160. self:GetBossList()
  161. end
  162. function this:GoldBossPosDataListItemCountFunc()
  163. return #self.monster1
  164. end
  165. function this:GoldBossPosDataListItemGetFunc(realIndex)
  166. local data = self.monster1[realIndex + 1]
  167. local item = GUI:UIPanel_Open("dev/outui/ChallengeBoss/Item/KLUIChallengeBossPosItem/KLUIChallengeBossPosItem",self.view.boss_pos_dl,self,{},true)
  168. self.boss_Pos_all_item[item.view.root] = item
  169. return item.view.root
  170. end
  171. function this:GoldBossPosDataListItemInitFunc(realIndex, kmlcontrol)
  172. end
  173. function this:GoldBossPosDataListItemUpdateFunc(realIndex, kmlcontrol)
  174. local data = self.monster1[realIndex + 1]
  175. self.boss_Pos_all_item[kmlcontrol]:RefreshItem(data,self.mapId,self)
  176. end
  177. function this:GoldBossHurtDataListItemCountFunc()
  178. return #self.hurtList
  179. end
  180. function this:GoldBossHurtDataListItemGetFunc(realIndex)
  181. local data = self.hurtList[realIndex + 1]
  182. local item = GUI:UIPanel_Open("dev/outui/ChallengeBoss/Item/KLUIChallengeBossHurtItem/KLUIChallengeBossHurtItem",self.view.hurt_root_dl,self,{},true)
  183. self.boss_Hurt_all_item[item.view.root] = item
  184. return item.view.root
  185. end
  186. function this:GoldBossHurtDataListItemInitFunc(realIndex, kmlcontrol)
  187. end
  188. function this:GoldBossHurtDataListItemUpdateFunc(realIndex, kmlcontrol)
  189. local data = self.hurtList[realIndex + 1]
  190. self.boss_Hurt_all_item[kmlcontrol]:RefreshItem(data,self.mapId,realIndex + 1,self)
  191. end
  192. function this:HurtChange(_id,message)
  193. self.show_pos = false
  194. GUI:setVisible(self.view.pos_root,false)
  195. GUI:setVisible(self.view.hurt_root,true)
  196. local top3 = message.top3
  197. self.hateId = message.monsterId
  198. self.hurtList = {}
  199. for i=1,100,1 do
  200. if top3[tostring(i)] then
  201. table.insert(self.hurtList,top3[tostring(i)])
  202. else
  203. break
  204. end
  205. end
  206. GUI:DataListUpdateData(self.view.hurt_root_dl)
  207. local my = message.my
  208. if my and my.name then
  209. self.my_name = my.name
  210. else
  211. self.my_name = SL:GetMetaValue(USER_NAME)
  212. end
  213. if my and my.rank then
  214. self.my_rank = my.rank
  215. else
  216. self.my_rank = 0
  217. end
  218. if my and my.hurt then
  219. self.my_hurt = math.floor(my.hurt)
  220. else
  221. self.my_hurt = 0
  222. end
  223. self.hurtStr = self:GetSimpleNumber(self.my_hurt,"")
  224. self.rank_img = self:GetRankImg(self.my_rank)
  225. GUI:Text_setString(self.view.my_name,self.my_name)
  226. GUI:Text_setString(self.view.my_value,tostring(self.hurtStr))
  227. GUI:Text_setString(self.view.my_ranking,tostring(self.my_rank))
  228. if self.my_rank >0 and self.my_rank < 4 then
  229. GUI:setVisible(self.view.my_ranking_img,true)
  230. GUI:setVisible(self.view.my_ranking,false)
  231. GUI:Image_loadTexture(self.view.my_ranking_img,self.rank_img,"Atlas/UIChallengeBoss.spriteatlas")
  232. else
  233. GUI:setVisible(self.view.my_ranking_img,false)
  234. GUI:setVisible(self.view.my_ranking,true)
  235. end
  236. end
  237. function this:GetRankImg(rank)
  238. if rank == 1 then
  239. return "challenge_1"
  240. elseif rank == 2 then
  241. return "challenge_2"
  242. elseif rank == 3 then
  243. return "challenge_3"
  244. end
  245. end
  246. function this:GetSimpleNumber(num, places)
  247. if num < 10000 then
  248. return num
  249. elseif num < 100000000 then
  250. return string.format("%.2" .. places .. "f万", num / 10000)
  251. else
  252. return string.format("%.2" .. places .. "f亿", num / 100000000)
  253. end
  254. end
  255. function this:Close()
  256. self.is_close = true
  257. self:UnRegistEvents()
  258. if self.timer1 then
  259. SL:UnSchedule(self.timer1)
  260. self.timer1 = nil
  261. end
  262. if self.timer2 then
  263. SL:UnSchedule(self.timer2)
  264. self.timer2 = nil
  265. end
  266. end
  267. function this:LUA_EVENT_CHANGESCENE(_id,message)
  268. local map_id = message.cfgId
  269. local is_has = SL:HasConfig("cfg_repfairyland",map_id,"mapId")
  270. if not is_has then
  271. self:RES_QUIT_SECRET_REALM()
  272. end
  273. end
  274. return this