UIExpeditionRankView.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. local UIExpeditionRankView = require("UIExpedition/UIExpeditionRankView_Generate")
  2. local LoadStatusLoopListCtr = require('Common/LoadStatusLoopListCtr')
  3. function UIExpeditionRankView:OnAwake(data)
  4. self.controller = require("UIExpedition/UIExpeditionRankCtr"):new()
  5. self.controller:Init(self)
  6. self.controller:SetData(data)
  7. end
  8. function UIExpeditionRankView:AddEventListener()
  9. self.uiBase:AddButtonEventListener(self.closeBtn.button,self, self.OnClickCloseBtn)
  10. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Refresh_Expedition_RankData,self,self.OnRefreshRankList)
  11. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  12. end
  13. function UIExpeditionRankView:RemoveEventListener()
  14. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  15. end
  16. function UIExpeditionRankView:FillContent(data, uiBase)
  17. self.uiBase = uiBase
  18. local gameObject = self.uiBase:GetRoot()
  19. if gameObject ~= nil then
  20. self.gameObject = gameObject
  21. self.transform = gameObject.transform
  22. end
  23. self:InitGenerate(self.transform, data)
  24. self:Init()
  25. end
  26. --采用英灵殿排行榜模式
  27. function UIExpeditionRankView:Init()
  28. self.lastReqTime = 0
  29. ManagerContainer.DataMgr.ExpeditionDataMgr:ResetSvrIdx()
  30. self.scrollView.loopVerticalScrollRect:SetDragLuaCallback(self.OnDragScrollView)
  31. ManagerContainer.DataMgr.ExpeditionDataMgr:SendScoreRankListReq(1)
  32. -- self.rankList = ManagerContainer.DataMgr.ExpeditionDataMgr:GetListfRank()
  33. -- if self.rankList~= nil and #self.rankList >= 1 then
  34. -- self.noRankList:SetActive(false)
  35. -- self.scrollView:SetActive(true)
  36. -- CommonUtil.LoopGridViewEleCreateNew(self,
  37. -- self.scrollView.loopVerticalScrollRect,
  38. -- nil,
  39. -- self.rankList,
  40. -- 0,
  41. -- self,
  42. -- self.OnRefreshRankData)
  43. -- else
  44. -- self.noRankList:SetActive(true)
  45. -- self.scrollView:SetActive(false)
  46. -- end
  47. -- if self.loadStatusLoopListCtr then
  48. -- self.loadStatusLoopListCtr:Dispose()
  49. -- self.loadStatusLoopListCtr = nil
  50. -- end
  51. -- self.loadStatusLoopListCtr =
  52. -- LoadStatusLoopListCtr:new(self, self.scrollView.loopListView, 0, 100,
  53. -- false, nil, nil,
  54. -- true, 'LoadingItem', nil,
  55. -- self.GetItemByIndex, nil, self.OnBeginLoad)
  56. -- ManagerContainer.DataMgr.ExpeditionDataMgr:ResetSvrIdx()
  57. -- ManagerContainer.DataMgr.ExpeditionDataMgr:SendScoreRankListReq(1)
  58. end
  59. function UIExpeditionRankView:OnDragScrollView()
  60. local curTime = Time.realtimeSinceStartup
  61. if (curTime - self.lastReqTime) >= 0.1 then
  62. local svrIdx,IsOver = ManagerContainer.DataMgr.ExpeditionDataMgr:GetNextRankListNum()
  63. if not IsOver then
  64. --LogError(tostring(svrIdx))
  65. ManagerContainer.DataMgr.ExpeditionDataMgr:SendScoreRankListReq(svrIdx)
  66. end
  67. self.lastReqTime = curTime
  68. end
  69. end
  70. function UIExpeditionRankView:RemoveEventListener()
  71. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  72. end
  73. function UIExpeditionRankView:AddUIEventListener()
  74. end
  75. function UIExpeditionRankView:OnHide()
  76. end
  77. function UIExpeditionRankView:OnShow(data)
  78. self.controller:SetData(data)
  79. end
  80. --刷新
  81. function UIExpeditionRankView:OnRefreshRankList()
  82. self.rankList = ManagerContainer.DataMgr.ExpeditionDataMgr:GetListfRank()
  83. if self.rankList~= nil and #self.rankList >= 1 then
  84. self.noRankList:SetActive(false)
  85. self.scrollView:SetActive(true)
  86. CommonUtil.LoopGridViewEleCreateNew(self,
  87. self.scrollView.loopVerticalScrollRect,
  88. nil,
  89. self.rankList,
  90. 0,
  91. self,
  92. self.OnRefreshRankData)
  93. else
  94. self.noRankList:SetActive(true)
  95. self.scrollView:SetActive(false)
  96. end
  97. self:RefreshSelfRank()
  98. -- self:FinishLoadItem()
  99. end
  100. function UIExpeditionRankView:GetRankImg(rankItemLua,nidx)
  101. if nidx == 1 then
  102. return rankItemLua.rank1
  103. elseif nidx == 2 then
  104. return rankItemLua.rank2
  105. elseif nidx == 3 then
  106. return rankItemLua.rank3
  107. end
  108. end
  109. function UIExpeditionRankView:ShowRankImg(rankItemLua,Rank)
  110. self:GetRankImg(rankItemLua,1):SetActive(false)
  111. self:GetRankImg(rankItemLua,2):SetActive(false)
  112. self:GetRankImg(rankItemLua,3):SetActive(false)
  113. if Rank <= 3 and Rank > 0 then
  114. self:GetRankImg(rankItemLua,Rank):SetActive(true)
  115. end
  116. end
  117. -----------------loading loop view
  118. function UIExpeditionRankView:GetItemByIndex(loopListView, idx, dataIdx)
  119. --LogError("GetItemByIndex"..tostring(dataIdx))
  120. local itemData = ManagerContainer.DataMgr.ExpeditionDataMgr:GetRankDataByIdx(dataIdx+1)
  121. if not itemData then return nil end
  122. local item = loopListView:NewListViewItem('ExpeditionRankItem')
  123. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'ExpeditionRankItem', item.gameObject)
  124. if itemLua then
  125. self:OnRefreshRankData(itemLua,idx,itemData)
  126. end
  127. return item
  128. end
  129. function UIExpeditionRankView:FinishLoadItem()
  130. local CurNum,MaxNum = ManagerContainer.DataMgr.ExpeditionDataMgr:GetNextRankListNum()
  131. --LogError(tostring(CurNum))
  132. --LogError(tostring(MaxNum))
  133. self.loadStatusLoopListCtr:OnAllLoaded()
  134. self.loadStatusLoopListCtr:RefreshMaxDataLength(MaxNum)
  135. self.loadStatusLoopListCtr:RefreshDataLength(CurNum)
  136. end
  137. function UIExpeditionRankView:OnBeginLoad(isLeft)
  138. --LogError("OnBeginLoad")
  139. --Loading...........
  140. --LogError("Sending"..tostring(svrIdx))
  141. local svrIdx = ManagerContainer.DataMgr.ExpeditionDataMgr:GetListSvrStartIdx()
  142. ManagerContainer.DataMgr.ExpeditionDataMgr:SendScoreRankListReq(svrIdx + 1)
  143. --self:FinishLoadItem()
  144. end
  145. ----------------------------------------------
  146. function UIExpeditionRankView:OnRefreshRankData(rankItemLua,idx,rankData)
  147. if rankItemLua == nil or rankData == nil then
  148. return
  149. end
  150. local Brief = rankData.brief_info
  151. local Rank = rankData.rank
  152. local Score = rankData.score
  153. self:ShowRankImg(rankItemLua,rankData.rank)
  154. local _jobIcon = nil;
  155. local jobCfg = ManagerContainer.CfgMgr:GetJobDataById(Brief.config_id)
  156. if jobCfg ~= nil then
  157. _jobIcon = jobCfg.JobIcon
  158. end
  159. if nil == tonumber(Rank) then
  160. LogError("Expedition Rank Data Error "..tostring(Rank))
  161. end
  162. rankItemLua.guildCPTxt.text.text = tostring(Score)
  163. rankItemLua.rankTxt.text.text = tostring(Rank)
  164. rankItemLua.nameTxt.text.text = CommonUtil.GetVaildNickName(Brief.nick_name)
  165. rankItemLua.lvTxt.text.text = tostring(Brief.fight_power)
  166. local _playerHead = CommonUtil.GetPlayerHeadIcon(Brief)
  167. local _headFrameId = Brief.head_frame_id
  168. local _fakerData = {Level = Brief.level, ProfessionIcon = _jobIcon, HeadIcon = _playerHead, IsHero = true};
  169. CommonUtil.SetPlayerHeadAndFrame(self, rankItemLua.headItem, _fakerData,false, _headFrameId, self, self.OnClickPlayerHead,Brief.uid);
  170. rankItemLua.vipIcon.image.enabled = false
  171. rankItemLua.vipIcon.image.sprite = nil
  172. local vipLv = Brief.vip_level
  173. if vipLv and vipLv >= 0 then
  174. local vipCfg = ManagerContainer.CfgMgr:GetVipCfgById(vipLv)
  175. if vipCfg then
  176. CommonUtil.LoadIcon(self, vipCfg.SmallIcon, function(sprite)
  177. if sprite then
  178. rankItemLua.vipIcon.image.sprite = sprite
  179. rankItemLua.vipIcon.image.enabled = true
  180. end
  181. end)
  182. end
  183. end
  184. end
  185. function UIExpeditionRankView:RefreshSelfRank()
  186. local userData = ManagerContainer.DataMgr.UserData
  187. local tbRank = ManagerContainer.DataMgr.ExpeditionDataMgr:GetSelfRank()
  188. local Rank = tbRank.rank
  189. if nil ~= tbRank.rank and tbRank.rank == 0 then
  190. Rank = I18N.T("NoRank")
  191. end
  192. if tbRank.rank > 100 then
  193. Rank = I18N.T("NoRank")
  194. end
  195. self:ShowRankImg(self.myRank,tbRank.rank)
  196. self.myRank.guildCPTxt.text.text = tostring(tbRank.score)
  197. self.myRank.rankTxt.text.text = tostring(Rank)
  198. self.myRank.nameTxt.text.text = userData:GetUserNickname()
  199. self.myRank.lvTxt.text.text = userData:GetTotalFightPower()
  200. local _playerHead = userData:GetUserHeadIcon()
  201. local _headFrameId = ManagerContainer.DataMgr.UserData:GetHeadFrameId();
  202. local _fakerData = {Level = userData:GetRoleLv(), ProfessionIcon = userData:GetJobIcon(), HeadIcon = _playerHead, IsHero = true};
  203. CommonUtil.SetPlayerHeadAndFrame(self, self.myRank.headItem, _fakerData,false, _headFrameId, self, self.OnClickSelfHead);
  204. self.myRank.vipIcon.image.enabled = false
  205. self.myRank.vipIcon.image.sprite = nil
  206. local vipLv = userData:GetVipLv()
  207. if vipLv and vipLv >= 0 then
  208. local vipCfg = ManagerContainer.CfgMgr:GetVipCfgById(vipLv)
  209. if vipCfg then
  210. CommonUtil.LoadIcon(self, vipCfg.SmallIcon, function(sprite)
  211. if sprite then
  212. self.myRank.vipIcon.image.sprite = sprite
  213. self.myRank.vipIcon.image.enabled = true
  214. end
  215. end)
  216. end
  217. end
  218. end
  219. function UIExpeditionRankView:OnClickSelfHead()
  220. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(I18N.T("ChatError1"))
  221. end
  222. function UIExpeditionRankView:OnClickPlayerHead(btn,param)
  223. local uid = param[0]
  224. ManagerContainer.LuaUIMgr:OpenRoleMessagePanel(uid)
  225. end
  226. function UIExpeditionRankView:OnClickCloseBtn()
  227. ManagerContainer.LuaUIMgr:OpenSourceUI(self)
  228. end
  229. function UIExpeditionRankView:OnClose()
  230. end
  231. function UIExpeditionRankView:OnDispose()
  232. -- if self.loadStatusLoopListCtr then
  233. -- self.loadStatusLoopListCtr:Dispose()
  234. -- self.loadStatusLoopListCtr = nil
  235. -- end
  236. self.scrollView.loopVerticalScrollRect:ClearCells()
  237. self.controller:OnDispose()
  238. end
  239. return UIExpeditionRankView