UIHundredDojoLogView.lua 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. local UIHundredDojoLogView = require("UIHundredDojo/UIHundredDojoLogView_Generate")
  2. local LoadStatusLoopListCtr = require('Common/LoadStatusLoopListCtr')
  3. function UIHundredDojoLogView:OnAwake(data)
  4. self.controller = require("UIHundredDojo/UIHundredDojoLogCtr"):new()
  5. self.controller:Init(self)
  6. self.controller:SetData(data)
  7. end
  8. function UIHundredDojoLogView:AddEventListener()
  9. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.HUNDRED_DOJO_LOG_CHANGED, self, self.OnLogChanged)
  10. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.HUNDRED_DOJO_QUERY_AREA_DATA_COMPLETED, self, self.OnQueryCompleted)
  11. end
  12. function UIHundredDojoLogView: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 UIHundredDojoLogView:Init()
  23. self.textTitle.uILocalizeScript:SetContent('BtnChallengeLog')
  24. -- self.controller:ClearLogState()
  25. if self.loadStatusLoopListCtr then
  26. self.loadStatusLoopListCtr:Dispose()
  27. self.loadStatusLoopListCtr = nil
  28. end
  29. local logMaxNum = 0
  30. if self.controller:GetLogWhole() then
  31. logMaxNum = self.controller:GetLogNum()
  32. else
  33. logMaxNum = self.controller:GetLogMaxNum()
  34. end
  35. self.loadStatusLoopListCtr = LoadStatusLoopListCtr:new(self, self.changeList.loopListView, 0, logMaxNum,
  36. false, 'LoadingItem', Enum.ListLoadingStatus.None,
  37. true, 'LoadingItem', Enum.ListLoadingStatus.WaitLoad,
  38. self.GetItemByIndex,nil, self.OnBeginLoad)
  39. self.changeList.loopListView.ScrollRect.enabled = false
  40. local errorCode = self.controller:SendGetLogInfoReq(true)
  41. if errorCode ~= 0 then
  42. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  43. end
  44. end
  45. function UIHundredDojoLogView:RemoveEventListener()
  46. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  47. end
  48. function UIHundredDojoLogView:AddUIEventListener()
  49. self.uiBase:AddButtonEventListener(self.btnClose.button, self, self.OnClickCancelBtn)
  50. self.uiBase:AddButtonEventListener(self.AnyBtn.button,self, self.OnClickCancelBtn)
  51. end
  52. function UIHundredDojoLogView:OnHide()
  53. end
  54. function UIHundredDojoLogView:OnShow(data)
  55. self.controller:SetData(data)
  56. end
  57. function UIHundredDojoLogView:OnClose()
  58. end
  59. function UIHundredDojoLogView:OnDispose()
  60. if self.loadStatusLoopListCtr then
  61. self.loadStatusLoopListCtr:Dispose()
  62. self.loadStatusLoopListCtr = nil
  63. end
  64. self.controller:OnDispose()
  65. end
  66. function UIHundredDojoLogView:OnPageInEnd()
  67. self.super.OnPageInEnd(self)
  68. self.changeList.loopListView.ScrollRect.enabled = true
  69. end
  70. function UIHundredDojoLogView:OnLogChanged(changed, startChanged, endChanged)
  71. self.controller:RefreshLogData()
  72. self:RefreshList(startChanged)
  73. end
  74. function UIHundredDojoLogView:OnQueryCompleted(uid, areaId)
  75. if self.battleUid ~= uid then
  76. return
  77. end
  78. if not areaId then
  79. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('HundredDojoLogView1')
  80. self:OnClickCancelBtn()
  81. return
  82. end
  83. local areaCfgData = ManagerContainer.CfgMgr:GetHundredDojoCfgById(areaId)
  84. if not areaCfgData then
  85. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('HundredDojoLogView1')
  86. self:OnClickCancelBtn()
  87. return
  88. end
  89. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.HUNDRED_DOJO_LOCATION_AREA_CHANGED, uid, areaId)
  90. self:OnClickCancelBtn()
  91. end
  92. function UIHundredDojoLogView:OnClickCancelBtn()
  93. self:UIClose()
  94. end
  95. function UIHundredDojoLogView:OnClickFightBtn(btn, params)
  96. local itemData = params[0]
  97. if not itemData then return end
  98. self.battleUid = itemData.uid
  99. if not self.battleUid then
  100. return
  101. end
  102. local errorCode = self.controller:SendGetAreaInfoReq(self.battleUid)
  103. if errorCode ~= 0 then
  104. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  105. end
  106. end
  107. function UIHundredDojoLogView:GetItemByIndex(loopListView, idx, dataIdx)
  108. local itemData = self.controller:GetLogById(dataIdx)
  109. if not itemData then return nil end
  110. local item = loopListView:NewListViewItem('HundredDojoLogItem')
  111. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'HundredDojoLogItem', item.gameObject)
  112. if itemLua then
  113. itemLua.fightBtn:SetActive(false)
  114. local logType = itemData.type
  115. local time = itemData.time
  116. local areaCfgData = nil
  117. if itemData.areaId then
  118. areaCfgData = ManagerContainer.CfgMgr:GetHundredDojoCfgById(itemData.areaId)
  119. end
  120. itemLua.timeTxt.text.text = ManagerContainer.LuaTimerMgr:ParseTimeStamp2Format(time, '%Y-%m-%d %H:%M:%S')
  121. if logType == 1 then
  122. itemLua.contentTxt.text.text = string.formatbykey('HundredDojoLog_1', tostring(areaCfgData and I18N.T(areaCfgData.Name) or ''), itemData.playerName, itemData.guildName)
  123. elseif logType == 2 then
  124. if itemData.state then
  125. itemLua.contentTxt.text.text = string.formatbykey('HundredDojoLog_2', tostring(areaCfgData and I18N.T(areaCfgData.Name) or ''), itemData.playerName, itemData.guildName)
  126. else
  127. itemLua.contentTxt.text.text = string.formatbykey('HundredDojoLog_3', tostring(areaCfgData and I18N.T(areaCfgData.Name) or ''), itemData.playerName, itemData.guildName)
  128. end
  129. elseif logType == 3 then
  130. if itemData.state then
  131. if itemData.guildName and itemData.guildName ~= '' then
  132. itemLua.contentTxt.text.text = string.formatbykey('HundredDojoLog_4', tostring(areaCfgData and I18N.T(areaCfgData.Name) or ''), itemData.playerName, itemData.guildName)
  133. else
  134. itemLua.contentTxt.text.text = string.formatbykey('HundredDojoLog_5', tostring(areaCfgData and I18N.T(areaCfgData.Name) or ''), itemData.playerName, itemData.guildName)
  135. end
  136. else
  137. if itemData.guildName and itemData.guildName ~= '' then
  138. itemLua.contentTxt.text.text = string.formatbykey('HundredDojoLog_6', tostring(areaCfgData and I18N.T(areaCfgData.Name) or ''), itemData.playerName, itemData.guildName)
  139. else
  140. itemLua.contentTxt.text.text = string.formatbykey('HundredDojoLog_7', tostring(areaCfgData and I18N.T(areaCfgData.Name) or ''), itemData.playerName, itemData.guildName)
  141. end
  142. end
  143. elseif logType == 4 then
  144. if itemData.state then
  145. if itemData.guildName and itemData.guildName ~= '' then
  146. itemLua.contentTxt.text.text = string.formatbykey('HundredDojoLog_8', tostring(areaCfgData and I18N.T(areaCfgData.Name) or ''), itemData.playerName, itemData.guildName)
  147. else
  148. itemLua.contentTxt.text.text = string.formatbykey('HundredDojoLog_9', tostring(areaCfgData and I18N.T(areaCfgData.Name) or ''), itemData.playerName, itemData.guildName)
  149. end
  150. self.uiBase:AddButtonUniqueEventListener(itemLua.fightBtn.button, self, self.OnClickFightBtn, itemData)
  151. itemLua.fightBtn:SetActive(true)
  152. else
  153. if itemData.guildName and itemData.guildName ~= '' then
  154. itemLua.contentTxt.text.text = string.formatbykey('HundredDojoLog_10', tostring(areaCfgData and I18N.T(areaCfgData.Name) or ''), itemData.playerName, itemData.guildName)
  155. else
  156. itemLua.contentTxt.text.text = string.formatbykey('HundredDojoLog_11', tostring(areaCfgData and I18N.T(areaCfgData.Name) or ''), itemData.playerName, itemData.guildName)
  157. end
  158. end
  159. elseif logType == 5 then
  160. local rewardTime = itemData.rewardTime
  161. if itemData.rewardTime then
  162. if type(rewardTime) == 'userdata' then
  163. rewardTime = #rewardTime
  164. end
  165. else
  166. rewardTime = 0
  167. end
  168. itemLua.contentTxt.text.text = string.formatbykey('HundredDojoLog_12', tostring(areaCfgData and areaCfgData.Name or ''), DateTimeUtil.convertSeconds2TimeStr1(rewardTime, true, false, true))
  169. else
  170. itemLua.contentTxt.text.text = ''
  171. end
  172. end
  173. ManagerContainer.LuaUIMgr:ForceRebuildLayoutImmediate(item.CachedRectTransform)
  174. return item
  175. end
  176. function UIHundredDojoLogView:OnBeginLoad(isBegin)
  177. local errorCode = self.controller:SendGetLogInfoReq(isBegin)
  178. if errorCode ~= 0 then
  179. self:RefreshList(isBegin)
  180. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  181. end
  182. end
  183. function UIHundredDojoLogView:RefreshList(isBegin)
  184. local whole = self.controller:GetLogWhole()
  185. local dataLength = self.controller:GetLogNum()
  186. self.loadStatusLoopListCtr:SetHasBegin(true)
  187. self.loadStatusLoopListCtr:OnAllLoaded()
  188. self.loadStatusLoopListCtr:RefreshMaxDataLength((whole and dataLength or (dataLength + 1)))
  189. self.loadStatusLoopListCtr:RefreshDataLength(dataLength)
  190. end
  191. return UIHundredDojoLogView