UIExpeditionHelpView.lua 7.1 KB

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