UIWorldBossListView.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. local UIWorldBossListView = require("UIWorldBoss/UIWorldBossListView_Generate")
  2. function UIWorldBossListView:OnAwake(data)
  3. self.controller = require("UIWorldBoss/UIWorldBossListCtr"):new()
  4. self.controller:Init(self)
  5. self.controller:SetData(data)
  6. end
  7. function UIWorldBossListView:AddEventListener()
  8. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.WORLD_BOSS_LIST_CHANGED, self, self.OnWorldBossListChanged)
  9. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.WORLD_BOSS_CHALLENGE_COUNT_CHANGED, self, self.OnWorldBossChallengeCountChanged)
  10. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.VIP_LV_CHANGED, self, self.OnVipLvChanged)
  11. end
  12. function UIWorldBossListView:FillContent(data, uiBase)
  13. self.uiBase = uiBase
  14. local gameObject = self.uiBase:GetRoot()
  15. if gameObject ~= nil then
  16. self.gameObject = gameObject
  17. self.transform = gameObject.transform
  18. end
  19. self:InitGenerate(self.transform, data)
  20. self:Init()
  21. end
  22. function UIWorldBossListView:Init()
  23. self.controller:InitData()
  24. self:InitList()
  25. self:RefreshList()
  26. self:RefreshChallengeCount()
  27. end
  28. function UIWorldBossListView:RemoveEventListener()
  29. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  30. end
  31. function UIWorldBossListView:AddUIEventListener()
  32. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  33. self.uiBase:AddButtonEventListener(self.btnBack.button, self, self.OnClickBackBtn)
  34. self.uiBase:AddButtonEventListener(self.AnyBtn.button, self, self.OnClickBackBtn)
  35. self.uiBase:AddButtonEventListener(self.btnRefresh.button, self, self.OnClickRefreshBtn)
  36. self.uiBase:AddButtonEventListener(self.btnPlayRule.button, self, self.OnClickPlayRuleBtn)
  37. end
  38. function UIWorldBossListView:OnHide()
  39. -- if self.updateTimer then
  40. -- self.updateTimer:Stop()
  41. -- end
  42. -- self.updateTimer = nil
  43. -- self.controller:ClearWorldBossList()
  44. end
  45. function UIWorldBossListView:OnShow(data)
  46. self.controller:SetData(data)
  47. -- self:RefreshList()
  48. -- self:RefreshChallengeCount()
  49. end
  50. function UIWorldBossListView:OnClose()
  51. end
  52. function UIWorldBossListView:OnDispose()
  53. local loopGridView = self.list.loopGridView
  54. loopGridView:Dispose()
  55. if self.updateTimer then
  56. self.updateTimer:Stop()
  57. end
  58. self.updateTimer = nil
  59. end
  60. function UIWorldBossListView:OnWorldBossListChanged()
  61. self.controller:RefreshWorldBossList()
  62. self:RefreshList()
  63. end
  64. function UIWorldBossListView:OnWorldBossChallengeCountChanged()
  65. self.controller:RefreshMaxCount()
  66. self:RefreshChallengeCount()
  67. end
  68. function UIWorldBossListView:OnVipLvChanged()
  69. self.controller:RefreshMaxCount()
  70. self:RefreshChallengeCount()
  71. end
  72. function UIWorldBossListView:InitList()
  73. self.list.loopGridView:InitGridView(0, function(gridView, itemIndex, row, column)
  74. return self:GetItemByRowColumn(gridView, itemIndex, row, column)
  75. end, nil)
  76. if self.updateTimer then
  77. self.updateTimer:Stop()
  78. end
  79. self.updateTimer = nil
  80. self.updateTimer = Timer.New(function()
  81. self:UpdateCheckTimer()
  82. end, 1, -1)
  83. self.updateTimer:Start()
  84. end
  85. function UIWorldBossListView:GetItemByRowColumn(gridView, itemIndex, row, column)
  86. local itemData = self.controller:GetWorldBossByItemIndex(itemIndex)
  87. if not itemData then
  88. return nil
  89. end
  90. local item = gridView:NewListViewItem('WorldBossItem')
  91. local itemlua = CommonUtil.BindGridViewItem2Lua(self, 'WorldBossItem', item.gameObject)
  92. itemlua.bossImage.image.sprite = nil
  93. itemlua.bossImage.image.enabled = false
  94. local bossId = itemData.bossId
  95. local bosstype = itemData.boss_summon_type
  96. local worldBossCfgData = ManagerContainer.DataMgr.WorldBossData:GetWorldBossDataById(bossId,bosstype)
  97. local rewardDatas = nil
  98. local lockLevelId = nil
  99. if worldBossCfgData then
  100. CommonUtil.LoadIcon(self, worldBossCfgData.BossPicture, function (sprite)
  101. itemlua.bossImage.image.sprite = sprite
  102. itemlua.bossImage.image.enabled = true
  103. end, itemlua, "WorldBossItemIconAsyncIdx")
  104. lockLevelId = worldBossCfgData.Tiaozhantiaojian
  105. rewardDatas = worldBossCfgData.FirstReward
  106. local summonId = itemData.cfgId
  107. local npcCfgData = ManagerContainer.CfgMgr:GetNpcCfgById(summonId)
  108. if npcCfgData then
  109. itemlua.bossName.text.text = I18N.SetLanguageValue(npcCfgData.Name)
  110. else
  111. LogError('[Wboy] Can not find Npc ' .. tostring(summonId))
  112. end
  113. else
  114. LogError('[Wboy] Can not find WorldBoss ' .. tostring(bossId))
  115. end
  116. self:RefreshItemRewards(itemlua, rewardDatas)
  117. itemlua.btnChallengeCoast:SetActive(false)
  118. itemlua.btnChallenge:SetActive(false)
  119. if lockLevelId then
  120. local locked = true
  121. local curLevelId = self.controller:GetCurLevelId()
  122. if curLevelId then
  123. locked = (curLevelId < lockLevelId)
  124. end
  125. if locked then
  126. local levelName = ''
  127. local levelCfgData = ManagerContainer.CfgMgr:GetLevelDataById(lockLevelId)
  128. if levelCfgData then
  129. levelName = I18N.T(levelCfgData.Name)
  130. end
  131. itemlua.textLock.uILocalizeScript:SetContentAndValues('FunUnLock11', {levelName})
  132. itemlua.lock:SetActive(true)
  133. itemlua.hp:SetActive(false)
  134. itemlua.btnChallenge:SetActive(false)
  135. itemlua.leaveTimer:SetActive(false)
  136. itemlua.labelLeave:SetActive(false)
  137. itemlua.reviveTimer:SetActive(false)
  138. CommonUtil.NeedUIGray(itemlua.bossImage.image, false)
  139. return item
  140. end
  141. end
  142. local isLeaving = false
  143. local isEnter = false
  144. if itemData.expireTime and itemData.expireTime > 0 then
  145. isLeaving = true
  146. isEnter = false
  147. elseif itemData.nextTime and itemData.nextTime > 0 then
  148. isLeaving = false
  149. isEnter = true
  150. end
  151. if isLeaving then
  152. local button
  153. local ItemId = 0
  154. local CostNum = 0
  155. if worldBossCfgData.Consume then
  156. button = itemlua.btnChallengeCoast
  157. ItemId = worldBossCfgData.Consume[1][1]
  158. CostNum = worldBossCfgData.Consume[1][2]
  159. itemlua.CostNum.text.text = tostring(CostNum)
  160. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(ItemId)
  161. CommonUtil.LoadIcon(self, itemCfgData.MiniIcon, function (sprite)
  162. itemlua.CostIcon.image.sprite = sprite
  163. end)
  164. else
  165. button = itemlua.btnChallenge
  166. end
  167. button:SetActive(true)
  168. -- button.button.interactable = (not itemData.isFight)
  169. -- if not itemData.isFight then
  170. -- self.uiBase:AddButtonUniqueEventListener(button.button, self, self.OnClickChallengeBtn, itemIndex,ItemId,CostNum)
  171. -- end
  172. self.uiBase:AddButtonUniqueEventListener(button.button, self, self.OnClickChallengeBtn, itemIndex,ItemId,CostNum)
  173. end
  174. itemlua.lock:SetActive(false)
  175. itemlua.hp:SetActive(true)
  176. local precent = (itemData.curHp / itemData.totalHp)
  177. local precentVaild = CommonUtil.GetPreciseDecimalFloor(precent * 100, 2)
  178. if precentVaild <= 0 and itemData.curHp > 0 then
  179. precentVaild = 0.01
  180. end
  181. itemlua.bossHP.text.text = tostring(precentVaild) .. '%'
  182. itemlua.slider.slider.value = precent
  183. itemlua.leaveTimer:SetActive(isLeaving)
  184. itemlua.labelLeave:SetActive(isEnter)
  185. itemlua.reviveTimer:SetActive(isEnter)
  186. CommonUtil.NeedUIGray(itemlua.bossImage.image, isEnter)
  187. self:UpdateItemLuaTime(itemlua, itemData)
  188. return item
  189. end
  190. function UIWorldBossListView:SureBuyChallengeNumBtn(params)
  191. local cfgdata = GlobalConfig.Instance:GetConfigStrValue(362)
  192. local costData = CommonUtil.DeserializeGlobalStrToNumberTable(cfgdata)
  193. local count = self.controller:GetChallengeCount() or 0
  194. local maxCount = self.controller:GetMaxCount() or 0
  195. if maxCount < count then
  196. maxCount = count
  197. end
  198. local hasCount = maxCount - count
  199. if hasCount > 0 then
  200. if costData then
  201. local curCost = costData[count + 1]
  202. if curCost then
  203. local costId = curCost[1]
  204. local costNum = curCost[2]
  205. local hasNum = CommonUtil.GetOwnResCountByItemId(costId)
  206. if hasNum >= costNum then
  207. local itemIndex = params[1]
  208. local CostitemId = params[2]
  209. local ItemCostCount = params[3]
  210. local itemData = self.controller:GetWorldBossByItemIndex(itemIndex)
  211. if not itemData then return end
  212. if CostitemId > 0 then
  213. local CurItemCount = CommonUtil.GetOwnResCountByItemId(CostitemId)
  214. if CurItemCount < ItemCostCount then
  215. CommonUtil.PopErrorTips("WorldBossChangePlay")
  216. return
  217. end
  218. end
  219. self.controller:SendChallengeBossReq(itemData.bossId, itemData.bossSummonIdx)
  220. else
  221. CommonUtil.ItemNotEnoughHandle(curCost[1], Enum.UIPageName.UIWorldBossList)
  222. end
  223. end
  224. end
  225. else
  226. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("LackBuyTimes")
  227. end
  228. end
  229. function UIWorldBossListView:RefreshItemRewards(itemlua, rewardDatas)
  230. local index = 1
  231. if rewardDatas then
  232. if type(rewardDatas[1]) == 'number' then
  233. rewardDatas = {rewardDatas}
  234. end
  235. local rewardNum = Mathf.Min(#rewardDatas, 3)
  236. for i = 1, rewardNum do
  237. local slot = itemlua['slot' .. index]
  238. if slot then
  239. local itemCfgId = rewardDatas[i][1]
  240. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(itemCfgId)
  241. if itemCfgData then
  242. slot:SetActive(true)
  243. local itemNum = rewardDatas[i][2]
  244. local logicData = {cfgId = itemCfgId, num = itemNum}
  245. CommonUtil.UpdateItemPrefab(self, slot.iconSmallItem, logicData, Enum.ItemIEnterType.Bag, self, self.ShowItemTips)
  246. index = index + 1
  247. end
  248. end
  249. end
  250. end
  251. for i = index, 3 do
  252. local slot = itemlua['slot' .. i]
  253. if slot then
  254. slot:SetActive(false)
  255. end
  256. end
  257. end
  258. function UIWorldBossListView:ShowItemTips(button, params)
  259. local data = params[0]
  260. --ManagerContainer.LuaUIMgr:OpenItemTips(data.cfgId, nil, data)
  261. ManagerContainer.LuaUIMgr:OpenTips(data)
  262. end
  263. function UIWorldBossListView:RefreshList()
  264. local worldBossDatas = self.controller:GetWorldBossList()
  265. local num = worldBossDatas and #worldBossDatas or 0
  266. if num <= 0 then
  267. self.list.loopGridView:SetListItemCount(0, true)
  268. self.noBoss:SetActive(true)
  269. return
  270. end
  271. self.noBoss:SetActive(false)
  272. self.list.loopGridView:RefreshListByIndex(num, 0)
  273. end
  274. function UIWorldBossListView:RefreshChallengeCount()
  275. local count = self.controller:GetChallengeCount() or 0
  276. local maxCount = self.controller:GetMaxCount() or 0
  277. if maxCount < count then
  278. maxCount = count
  279. end
  280. self.num.text.text = string.formatbykey('WorldBossFightTimes', (maxCount - count))--WorldBossFightTimes --DscFightTimes
  281. end
  282. function UIWorldBossListView:UpdateCheckTimer()
  283. local worldBossDatas = self.controller:GetWorldBossList()
  284. if not worldBossDatas then return end
  285. local num = #worldBossDatas
  286. if num <= 0 then return end
  287. local curTime = ManagerContainer.LuaTimerMgr:CurLuaServerTime()
  288. local nextUpdateTime = nil
  289. for i = 1, num do
  290. nextUpdateTime = self.controller:GetNextUpdateTime(i)
  291. if nextUpdateTime == nil or (int64.__lt(0, nextUpdateTime) and int64.__le(nextUpdateTime, curTime)) then
  292. local worldBossData = worldBossDatas[i]
  293. -- 需要更新时间
  294. self.controller:RefreshNextUpdateTime(worldBossData, i, curTime)
  295. self:UpdateItemShowTime(i, worldBossData, curTime)
  296. end
  297. end
  298. end
  299. function UIWorldBossListView:UpdateItemShowTime(i, worldBossData, curTime)
  300. if not worldBossData then return end
  301. local item = self.list.loopGridView:GetShownItemByItemIndex(i - 1)
  302. if not item then return end
  303. local itemlua = CommonUtil.BindGridViewItem2Lua(self, 'WorldBossItem', item.gameObject)
  304. if not itemlua then return end
  305. self:UpdateItemLuaTime(itemlua, worldBossData, curTime)
  306. end
  307. function UIWorldBossListView:UpdateItemLuaTime(itemlua, worldBossData, curTime)
  308. if not itemlua then return end
  309. if not worldBossData then return end
  310. if not curTime then curTime = ManagerContainer.LuaTimerMgr:CurLuaServerTime() end
  311. local remainTime = 0
  312. if int64.__lt(0, worldBossData.expireTime) then
  313. remainTime = (worldBossData.expireTime - curTime) / 1000
  314. remainTime = type(remainTime) == "number" and remainTime or #remainTime
  315. remainTime = Mathf.Ceil(remainTime)
  316. if remainTime / 60 >= 1 then
  317. itemlua.leaveTimer.text.text.text = I18N.SetLanguageValue('OutTime1', DateTimeUtil.convertSeconds2TimeStr1(remainTime, true, true))
  318. else
  319. itemlua.leaveTimer.text.text.text = I18N.SetLanguageValue('OutTime2')
  320. end
  321. elseif int64.__lt(0, worldBossData.nextTime) then
  322. remainTime = (worldBossData.nextTime - curTime) / 1000
  323. remainTime = type(remainTime) == "number" and remainTime or #remainTime
  324. remainTime = Mathf.Ceil(remainTime)
  325. itemlua.reviveTimer.text.text.text = I18N.SetLanguageValue('InTime1', DateTimeUtil.convertSeconds2TimeStr1(remainTime, true, true))
  326. end
  327. end
  328. function UIWorldBossListView:OnClickChallengeBtn(btn, params)
  329. local itemIndex = params[0]
  330. local CostitemId = params[1]
  331. local ItemCostCount = params[2]
  332. local itemData = self.controller:GetWorldBossByItemIndex(itemIndex)
  333. if not itemData then return end
  334. --itemData.isFight = false
  335. --CostitemId = 0
  336. --self.controller:SendChallengeBossReq(itemData.bossId, itemData.bossSummonIdx)
  337. if not itemData.isFight then
  338. if CostitemId > 0 then
  339. local CurItemCount = CommonUtil.GetOwnResCountByItemId(CostitemId)
  340. if CurItemCount < ItemCostCount then
  341. CommonUtil.PopErrorTips("WorldBossChangePlay")
  342. return
  343. end
  344. end
  345. --LogError("---------------SendChallengeBossReq---------------------")
  346. self.controller:SendChallengeBossReq(itemData.bossId, itemData.bossSummonIdx)
  347. else
  348. CommonUtil.PopErrorTips("214")
  349. -- local cfgdata = GlobalConfig.Instance:GetConfigStrValue(362)
  350. -- local costData = CommonUtil.DeserializeGlobalStrToNumberTable(cfgdata)
  351. -- local count = self.controller:GetChallengeCount() or 0
  352. -- local maxCount = self.controller:GetMaxCount() or 0
  353. -- if maxCount < count then
  354. -- maxCount = count
  355. -- end
  356. -- local hasCount = maxCount - count
  357. -- if hasCount > 0 then
  358. -- if costData then
  359. -- local curCost = costData[count + 1]
  360. -- if curCost then
  361. -- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIDojoBuyTimes, {curCost[2], nil, self.SureBuyChallengeNumBtn, self,{itemIndex,CostitemId,ItemCostCount}})
  362. -- end
  363. -- else
  364. -- ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("LackBuyTimes")
  365. -- end
  366. -- else
  367. -- ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("LackBuyTimes")
  368. -- end
  369. end
  370. end
  371. function UIWorldBossListView:OnClickBackBtn()
  372. ManagerContainer.LuaUIMgr:OpenSourceUI(self)
  373. -- self:UIClose()
  374. end
  375. function UIWorldBossListView:OnClickRefreshBtn()
  376. local errorCode = self.controller:SendRefreshBossListReq()
  377. if errorCode ~= 0 then
  378. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(100007)
  379. end
  380. end
  381. function UIWorldBossListView:OnClickPlayRuleBtn()
  382. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPlayRule, {'PlayExplainTitle', 'WorldBossPlayExplain'})
  383. end
  384. return UIWorldBossListView