UIVoyageRankView.lua 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. local UIVoyageRankView = require("UIVoyage/UIVoyageRankView_Generate")
  2. local LoadStatusLoopListCtr = require('Common/LoadStatusLoopListCtr')
  3. function UIVoyageRankView:OnAwake(data)
  4. self.controller = require("UIVoyage/UIVoyageRankCtr"):new()
  5. self.controller:Init(self)
  6. self.controller:SetData(data)
  7. end
  8. function UIVoyageRankView:AddEventListener()
  9. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.VOYAGE_RANK_CHANGED, self, self.OnVoyageRankChanged)
  10. end
  11. function UIVoyageRankView:FillContent(data, uiBase)
  12. self.uiBase = uiBase
  13. local gameObject = self.uiBase:GetRoot()
  14. if gameObject ~= nil then
  15. self.gameObject = gameObject
  16. self.transform = gameObject.transform
  17. end
  18. self:InitGenerate(self.transform, data)
  19. self:Init()
  20. end
  21. function UIVoyageRankView:Init()
  22. self.controller:InitData()
  23. if self.loadStatusLoopListCtr then
  24. self.loadStatusLoopListCtr:Dispose()
  25. self.loadStatusLoopListCtr = nil
  26. end
  27. local maxNum = self.controller:GetMaxNum()
  28. self.loadStatusLoopListCtr = LoadStatusLoopListCtr:new(self, self.rankList.loopListView, 0, maxNum,
  29. false, 'LoadingItem', Enum.ListLoadingStatus.None,
  30. true, 'LoadingItem', Enum.ListLoadingStatus.WaitLoad,
  31. self.GetItemByIndex,nil, self.OnBeginLoad)
  32. self.rankList.loopListView.ScrollRect.enabled = false
  33. local errorCode = self.controller:SendGetVoyageRankDatasReq(true)
  34. if errorCode ~= 0 then
  35. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  36. end
  37. self:RefreshSelfVoyageRankItem()
  38. end
  39. function UIVoyageRankView:RemoveEventListener()
  40. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  41. end
  42. function UIVoyageRankView:AddUIEventListener()
  43. self.uiBase:AddButtonEventListener(self.btnClose.button, self, self.OnClickCancelBtn)
  44. self.uiBase:AddButtonEventListener(self.AnyBtn.button,self, self.OnClickCancelBtn)
  45. end
  46. function UIVoyageRankView:OnHide()
  47. end
  48. function UIVoyageRankView:OnShow(data)
  49. self.controller:SetData(data)
  50. end
  51. function UIVoyageRankView:OnClose()
  52. end
  53. function UIVoyageRankView:OnDispose()
  54. if self.loadStatusLoopListCtr then
  55. self.loadStatusLoopListCtr:Dispose()
  56. self.loadStatusLoopListCtr = nil
  57. end
  58. self.controller:OnDispose()
  59. end
  60. function UIVoyageRankView:OnPageInEnd()
  61. self.super.OnPageInEnd(self)
  62. self.rankList.loopListView.ScrollRect.enabled = true
  63. end
  64. function UIVoyageRankView:OnVoyageRankChanged()
  65. self:RefreshList()
  66. end
  67. function UIVoyageRankView:OnClickCancelBtn()
  68. self:UIClose()
  69. end
  70. function UIVoyageRankView:GetItemByIndex(loopListView, idx, dataIdx)
  71. local itemData = self.controller:GetRankDataById(dataIdx + 1)
  72. if not itemData then return nil end
  73. local item = loopListView:NewListViewItem('VoyageRankItem')
  74. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'VoyageRankItem', item.gameObject)
  75. if itemLua then
  76. local playerBrief = itemData.playerBrief
  77. local data = {IsHero = true}
  78. local headFrameId = nil
  79. local vipLv = nil
  80. local name = nil
  81. if playerBrief then
  82. local uid = playerBrief.uid
  83. vipLv = playerBrief.vipLv
  84. headFrameId = playerBrief.headFrame
  85. if int64.equals(uid, ManagerContainer.DataMgr.UserData:GetUserId()) then
  86. headFrameId = ManagerContainer.DataMgr.UserData:GetHeadFrameId()
  87. vipLv = ManagerContainer.DataMgr.UserData:GetVipLv()
  88. end
  89. local jobCfg = ManagerContainer.CfgMgr:GetJobDataById(playerBrief.configId)
  90. local jobIcon = ''
  91. if jobCfg then
  92. jobIcon = jobCfg.JobIcon
  93. end
  94. data.Level = playerBrief.level
  95. data.ProfessionIcon = jobIcon
  96. data.HeadIcon = playerBrief.headPortraitName
  97. name = playerBrief.nickName
  98. end
  99. self:RefreshVoyageRankItem(itemLua, name, vipLv, data, headFrameId, itemData.score, itemData.rank)
  100. end
  101. return item
  102. end
  103. function UIVoyageRankView:RefreshSelfVoyageRankItem()
  104. local userdata = ManagerContainer.DataMgr.UserData
  105. local data = {IsHero = true}
  106. data.Level = userdata:GetRoleLv()
  107. local jobCfg = ManagerContainer.CfgMgr:GetJobDataById(userdata:GetJobCfgId())
  108. local jobIcon = ''
  109. if jobCfg then
  110. jobIcon = jobCfg.JobIcon
  111. end
  112. data.ProfessionIcon = jobIcon
  113. data.HeadIcon = userdata:GetUserHeadIcon()
  114. local headFrameId = userdata:GetHeadFrameId()
  115. local vipLv = userdata:GetVipLv()
  116. local name = userdata:GetUserNickname()
  117. self:RefreshVoyageRankItem(self.selfVoyageRankItem, name, vipLv, data, headFrameId, self.controller:GetSelfScore(), self.controller:GetSelfRank())
  118. end
  119. function UIVoyageRankView:RefreshVoyageRankItem(itemLua, name, vipLv, headData, headFrameId, score, rank)
  120. itemLua.nameTxt.text.text = tostring(name)
  121. if not score or score <= 0 then
  122. itemLua.scoreTxt.text.text = "0"
  123. else
  124. itemLua.scoreTxt.text.text = tostring(score)
  125. end
  126. if not rank or rank <= 0 then
  127. itemLua.rankTxt.text.text = string.formatbykey('NoRank')
  128. itemLua.rankTxt:SetActive(true)
  129. itemLua.rankSp:SetActive(false)
  130. elseif rank == 1 then
  131. itemLua.rankTxt:SetActive(false)
  132. itemLua.rankSp.uIImageSwitchSprite:ChangeSprite(0)
  133. itemLua.rankSp:SetActive(true)
  134. elseif rank == 2 then
  135. itemLua.rankTxt:SetActive(false)
  136. itemLua.rankSp.uIImageSwitchSprite:ChangeSprite(1)
  137. itemLua.rankSp:SetActive(true)
  138. elseif rank == 3 then
  139. itemLua.rankTxt:SetActive(false)
  140. itemLua.rankSp.uIImageSwitchSprite:ChangeSprite(2)
  141. itemLua.rankSp:SetActive(true)
  142. else
  143. itemLua.rankTxt.text.text = tostring(rank)
  144. itemLua.rankTxt:SetActive(true)
  145. itemLua.rankSp:SetActive(false)
  146. end
  147. itemLua.headItem.head.button.enabled = false
  148. CommonUtil.SetPlayerHeadAndFrame(self, itemLua.headItem, headData, false, headFrameId)
  149. itemLua.vipIcon.image.enabled = false
  150. itemLua.vipIcon.image.sprite = nil
  151. if vipLv and vipLv >= 0 then
  152. local vipCfg = ManagerContainer.CfgMgr:GetVipCfgById(vipLv)
  153. if vipCfg then
  154. CommonUtil.LoadIcon(self, vipCfg.SmallIcon, function(sprite)
  155. if sprite then
  156. itemLua.vipIcon.image.sprite = sprite
  157. itemLua.vipIcon.image.enabled = true
  158. end
  159. end, itemLua, 'VipIcon')
  160. end
  161. end
  162. end
  163. function UIVoyageRankView:OnBeginLoad(isBegin)
  164. local errorCode = self.controller:SendGetVoyageRankDatasReq(isBegin)
  165. if errorCode ~= 0 then
  166. self:RefreshList(isBegin)
  167. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  168. end
  169. end
  170. function UIVoyageRankView:RefreshList()
  171. local rankDatas = self.controller:GetRankDatas()
  172. local maxNum = self.controller:GetMaxNum()
  173. local whole = false
  174. local dataLength = 0
  175. if rankDatas then
  176. dataLength = #rankDatas
  177. whole = (dataLength >= maxNum)
  178. end
  179. self.loadStatusLoopListCtr:SetHasBegin(true)
  180. self.loadStatusLoopListCtr:OnAllLoaded()
  181. self.loadStatusLoopListCtr:RefreshMaxDataLength((whole and dataLength or (dataLength + 1)))
  182. self.loadStatusLoopListCtr:RefreshDataLength(dataLength)
  183. self:RefreshSelfVoyageRankItem()
  184. end
  185. return UIVoyageRankView