UIExpeditionHelpView.lua 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. local UIExpeditionHelpView = require("UIExpedition/UIExpeditionHelpView_Generate")
  2. function UIExpeditionHelpView:OnAwake(data)
  3. self.controller = require("UIExpedition/UIExpeditionHelpCtr"):new()
  4. self.controller:Init(self)
  5. self.controller:SetData(data)
  6. end
  7. function UIExpeditionHelpView:AddEventListener()
  8. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name,UIEventNames.EID_Refresh_FriendData,self,self.OnRefreshData)
  9. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name,UIEventNames.EID_Expedition_RefreshData,self,self.RefreshLeftTimes)
  10. end
  11. function UIExpeditionHelpView: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 UIExpeditionHelpView:Init()
  22. ManagerContainer.DataMgr.FriendDataMgr:SetExpedotopmHelpList(true)
  23. self.controller:InitFriendData()
  24. self.lastReqTime = 0
  25. self.friendScrollList.loopVerticalScrollRect:SetDragLuaCallback(self.OnDragScrollView)
  26. self:ShowFriendsData()
  27. if not self.controller:IsReqFinished() then
  28. self:OnDragScrollView()
  29. end
  30. self:RefreshLeftTimes()
  31. end
  32. function UIExpeditionHelpView:RemoveEventListener()
  33. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  34. end
  35. function UIExpeditionHelpView:AddUIEventListener()
  36. self.uiBase:AddButtonEventListener(self.AnyBtn.button,self, self.OnClickClose)
  37. self.uiBase:AddButtonEventListener(self.closeBtn.button,self, self.OnClickClose)
  38. self.uiBase:AddButtonEventListener(self.guildHelpBtn.button, self, self.OnClickGuildHelp)
  39. end
  40. function UIExpeditionHelpView:OnHide()
  41. end
  42. function UIExpeditionHelpView:OnShow(data)
  43. self.controller:SetData(data)
  44. end
  45. function UIExpeditionHelpView:OnClose()
  46. self:ClearLeftTimeTimer()
  47. ManagerContainer.DataMgr.FriendDataMgr:SetExpedotopmHelpList(false)
  48. self.friendScrollList.loopVerticalScrollRect:SetDragLuaCallback(nil)
  49. self.friendScrollList.loopVerticalScrollRect:ClearCells()
  50. end
  51. function UIExpeditionHelpView:OnDispose()
  52. self.controller:OnDispose()
  53. end
  54. function UIExpeditionHelpView:OnClickClose()
  55. self:UIClose()
  56. end
  57. function UIExpeditionHelpView:OnRefreshData()
  58. --self.controller:RefreshFriendList()
  59. self:ShowFriendsData()
  60. end
  61. function UIExpeditionHelpView:OnDragScrollView()
  62. if not self.controller:IsReqFinished() then
  63. local curTime = Time.realtimeSinceStartup
  64. if (curTime - self.lastReqTime) >= 0.1 then
  65. self.controller:ReqestFriendBriefData()
  66. self.lastReqTime = curTime
  67. end
  68. end
  69. end
  70. function UIExpeditionHelpView:RefreshLeftTimes()
  71. local leftRescuedNum = ManagerContainer.DataMgr.ExpeditionDataMgr.maxRescuedNum - ManagerContainer.DataMgr.ExpeditionDataMgr.usedRescuedNum
  72. self.leftRescuedNumTxt.text.text = tostring(leftRescuedNum)
  73. local inGuild = ManagerContainer.DataMgr.GuildDataMgr:HasGuild()
  74. CommonUtil.NeedUIGray(self.guildImg.image,not inGuild)
  75. if inGuild then
  76. local leftTime = ManagerContainer.DataMgr.ExpeditionDataMgr.guildAssistingEndTime - ManagerContainer.LuaTimerMgr:GetTimeSecond()
  77. if leftTime > 0 then
  78. self.guildHelpBtn:SetActive(false)
  79. self.guildCDTxt:SetActive(true)
  80. self:ClearLeftTimeTimer()
  81. self.updateLeftTimeTimer = ManagerContainer.LuaTimerMgr:AddTimer(1000, leftTime,self,self.UpdateLeftTime,nil)
  82. self:UpdateLeftTime()
  83. else
  84. self.guildHelpBtn:SetActive(true)
  85. self.guildCDTxt:SetActive(false)
  86. end
  87. else
  88. self.guildHelpBtn:SetActive(false)
  89. self.guildCDTxt:SetActive(false)
  90. end
  91. end
  92. function UIExpeditionHelpView:ClearLeftTimeTimer()
  93. if self.updateLeftTimeTimer~= nil then
  94. ManagerContainer.LuaTimerMgr:RemoveTimer(self.updateLeftTimeTimer)
  95. self.updateLeftTimeTimer = nil
  96. end
  97. end
  98. function UIExpeditionHelpView:UpdateLeftTime()
  99. local leftTime = ManagerContainer.DataMgr.ExpeditionDataMgr.guildAssistingEndTime - ManagerContainer.LuaTimerMgr:GetTimeSecond()
  100. if leftTime < 1 then
  101. self:ClearLeftTimeTimer()
  102. self.guildHelpBtn:SetActive(true)
  103. self.guildCDTxt:SetActive(false)
  104. else
  105. local day,hour,minute,second = ConvertTimeForm(leftTime)
  106. local timeStr = ""
  107. if hour > 0 then
  108. timeStr = string.format("%02d时%02d分%02d秒", hour,minute, second)
  109. else
  110. if minute > 0 then
  111. timeStr = string.format("%02d分%02d秒", minute, second)
  112. else
  113. timeStr = string.format("%02d秒", second)
  114. end
  115. end
  116. self.leftTime.text.text = timeStr
  117. end
  118. end
  119. function UIExpeditionHelpView:ShowFriendsData()
  120. if #self.controller:FriendList() > 0 then
  121. self.emptyNode:SetActive(false)
  122. local friendList = self.controller:FriendList()
  123. CommonUtil.LoopGridViewEleCreateNew(self,
  124. self.friendScrollList.loopVerticalScrollRect,
  125. self.friendScrollList.content.verticalLayoutGroup,
  126. friendList,
  127. 0,
  128. self, self.SetFriendData);
  129. else
  130. self.friendScrollList.loopVerticalScrollRect:ClearCells()
  131. self.emptyNode:SetActive(true)
  132. end
  133. end
  134. function UIExpeditionHelpView:SetFriendData(node,idx,friendData)
  135. if node == nil or friendData == nil then
  136. return
  137. end
  138. local _jbIcon = nil;
  139. local jobCfg = ManagerContainer.CfgMgr:GetJobDataById(friendData.job)
  140. if jobCfg ~= nil then
  141. _jbIcon = jobCfg.JobIcon;
  142. end
  143. local _headIcon = nil;
  144. if friendData.head ~= nil then
  145. _headIcon = friendData.head;
  146. end
  147. local _fakerData = {Level = friendData.level, ProfessionIcon = _jbIcon, HeadIcon = _headIcon, IsHero = true};
  148. CommonUtil.SetPlayerHeadAndFrame(self, node.headItem, _fakerData,false, friendData.headFrameId, self, self.OnClickPlayerHead, friendData.uid);
  149. node.playerName.text.text = friendData.name
  150. node.fightPower.text.text = tostring(friendData.fightPower)
  151. node.statusLbl.text.text = friendData:GetOnlineStatus()
  152. self.uiBase:AddButtonUniqueEventListener(node.helpBtn.button, self, self.OnClickPlayerHelp, friendData.uid)
  153. end
  154. function UIExpeditionHelpView:OnClickPlayerHelp(btn,params)
  155. local leftNum = ManagerContainer.DataMgr.ExpeditionDataMgr.maxRescuedNum - ManagerContainer.DataMgr.ExpeditionDataMgr.usedRescuedNum
  156. if leftNum <= 0 then
  157. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("ExpeditionSalvation")
  158. return
  159. end
  160. local uid = params[0]
  161. ManagerContainer.LuaUIMgr:ShowMessageBox("ExpeditionCallHelp",nil,uid,self,self.OnConfirmSendAssistReq,nil)
  162. end
  163. function UIExpeditionHelpView:OnClickPlayerHead(btn,params)
  164. local uid = params[0]
  165. ManagerContainer.LuaUIMgr:OpenRoleMessagePanel(uid)
  166. end
  167. function UIExpeditionHelpView:OnClickGuildHelp()
  168. local leftNum = ManagerContainer.DataMgr.ExpeditionDataMgr.maxRescuedNum - ManagerContainer.DataMgr.ExpeditionDataMgr.usedRescuedNum
  169. if leftNum <= 0 then
  170. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("ExpeditionSalvation")
  171. return
  172. end
  173. ManagerContainer.LuaUIMgr:ShowMessageBox("ExpeditionCallHelp",nil,0,self,self.OnConfirmSendAssistReq,nil)
  174. end
  175. function UIExpeditionHelpView:OnConfirmSendAssistReq(reqId)
  176. ManagerContainer.DataMgr.ExpeditionDataMgr:SendAssistReq(reqId)
  177. end
  178. return UIExpeditionHelpView