UIVoyageLogView.lua 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. local UIVoyageLogView = require("UIHundredDojo/UIHundredDojoLogView_Generate")
  2. local LoadStatusLoopListCtr = require('Common/LoadStatusLoopListCtr')
  3. function UIVoyageLogView:OnAwake(data)
  4. self.controller = require("UIVoyage/UIVoyageLogCtr"):new()
  5. self.controller:Init(self)
  6. self.controller:SetData(data)
  7. end
  8. function UIVoyageLogView:AddEventListener()
  9. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.VOYAGE_LOG_CHANGED, self, self.OnLogChanged)
  10. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.VOYAGE_CHECK_AIRSHIP_CHANGED, self, self.OnQueryCompleted)
  11. end
  12. function UIVoyageLogView: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 UIVoyageLogView:Init()
  23. self.textTitle.uILocalizeScript:SetContent('VoyageLog')
  24. self.controller:InitData()
  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 UIVoyageLogView:RemoveEventListener()
  46. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  47. end
  48. function UIVoyageLogView: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 UIVoyageLogView:OnHide()
  53. end
  54. function UIVoyageLogView:OnShow(data)
  55. self.controller:SetData(data)
  56. end
  57. function UIVoyageLogView:OnClose()
  58. end
  59. function UIVoyageLogView:OnDispose()
  60. if self.loadStatusLoopListCtr then
  61. self.loadStatusLoopListCtr:Dispose()
  62. self.loadStatusLoopListCtr = nil
  63. end
  64. self.battleUid = nil
  65. self.controller:OnDispose()
  66. end
  67. function UIVoyageLogView:OnPageInEnd()
  68. self.super.OnPageInEnd(self)
  69. self.changeList.loopListView.ScrollRect.enabled = true
  70. end
  71. function UIVoyageLogView:OnLogChanged(changed, startChanged, endChanged)
  72. self.controller:RefreshLogData()
  73. self:RefreshList(startChanged)
  74. end
  75. function UIVoyageLogView:OnQueryCompleted(uid)
  76. if self.battleUid ~= uid then
  77. return
  78. end
  79. self.battleUid = nil
  80. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.VOYAGE_LOCATION_CHANGED, uid)
  81. self:OnClickCancelBtn()
  82. end
  83. function UIVoyageLogView:OnClickCancelBtn()
  84. self:UIClose()
  85. end
  86. function UIVoyageLogView:OnClickFightBtn(btn, params)
  87. local itemData = params[0]
  88. if not itemData then return end
  89. self.battleUid = itemData.target_player_uid
  90. if not self.battleUid then
  91. return
  92. end
  93. local errorCode = self.controller:SendCheckInfoReq(self.battleUid)
  94. if errorCode ~= 0 then
  95. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  96. end
  97. end
  98. function UIVoyageLogView:GetItemByIndex(loopListView, idx, dataIdx)
  99. local itemData = self.controller:GetLogById(dataIdx)
  100. if not itemData then return nil end
  101. local item = loopListView:NewListViewItem('HundredDojoLogItem')
  102. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'HundredDojoLogItem', item.gameObject)
  103. if itemLua then
  104. itemLua.fightBtn:SetActive(false)
  105. local logType = itemData.type
  106. local time = itemData.record_time
  107. itemLua.timeTxt.text.text = ManagerContainer.LuaTimerMgr:ParseTimeStamp2Format(time, '%Y-%m-%d %H:%M:%S')
  108. if logType == 1 then
  109. itemLua.contentTxt.text.text = string.formatbykey('VoyageLog01', CommonUtil.GetVaildNickName(itemData.target_player_name), self:GetItemDesc(itemData.item_list))
  110. self.uiBase:AddButtonUniqueEventListener(itemLua.fightBtn.button, self, self.OnClickFightBtn, itemData)
  111. itemLua.fightBtn:SetActive(true)
  112. elseif logType == 2 then
  113. itemLua.contentTxt.text.text = string.formatbykey('VoyageLog02', CommonUtil.GetVaildNickName(itemData.target_player_name), self:GetItemDesc(itemData.item_list))
  114. elseif logType == 3 then
  115. itemLua.contentTxt.text.text = string.formatbykey('VoyageLog03', CommonUtil.GetVaildNickName(itemData.target_player_name))
  116. else
  117. itemLua.contentTxt.text.text = ''
  118. end
  119. end
  120. ManagerContainer.LuaUIMgr:ForceRebuildLayoutImmediate(item.CachedRectTransform)
  121. return item
  122. end
  123. function UIVoyageLogView:OnBeginLoad(isBegin)
  124. local errorCode = self.controller:SendGetLogInfoReq(isBegin)
  125. if errorCode ~= 0 then
  126. self:RefreshList(isBegin)
  127. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  128. end
  129. end
  130. function UIVoyageLogView:RefreshList(isBegin)
  131. local whole = self.controller:GetLogWhole()
  132. local dataLength = self.controller:GetLogNum()
  133. self.loadStatusLoopListCtr:SetHasBegin(true)
  134. self.loadStatusLoopListCtr:OnAllLoaded()
  135. self.loadStatusLoopListCtr:RefreshMaxDataLength((whole and dataLength or (dataLength + 1)))
  136. self.loadStatusLoopListCtr:RefreshDataLength(dataLength)
  137. end
  138. function UIVoyageLogView:GetItemDesc(rewards)
  139. if not rewards then
  140. return ''
  141. end
  142. local reward
  143. local cfgId
  144. local num
  145. local itemCfgData
  146. local desc = ''
  147. for i = 1, #rewards do
  148. reward = rewards[i]
  149. cfgId = reward.key
  150. num = reward.value
  151. itemCfgData = ManagerContainer.CfgMgr:GetItemById(cfgId)
  152. if itemCfgData then
  153. if desc then
  154. desc = desc .. ' ' .. string.formatbykey(itemCfgData.Name) .. '*' .. tostring(num)
  155. else
  156. desc = string.formatbykey(itemCfgData.Name) .. '*' .. tostring(num)
  157. end
  158. end
  159. end
  160. return desc
  161. end
  162. return UIVoyageLogView