UIExpeditionHelpView.lua 7.0 KB

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