UIExpeditionHelpView.lua 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 hour > 0 then
  115. timeStr = string.format(self.HFmt , hour,minute, second)
  116. else
  117. if minute > 0 then
  118. timeStr = string.format(self.MFmt , minute, second)
  119. else
  120. timeStr = string.format(self.SFmt, second)
  121. end
  122. end
  123. self.leftTime.text.text = timeStr
  124. end
  125. end
  126. function UIExpeditionHelpView:ShowFriendsData()
  127. if #self.controller:FriendList() > 0 then
  128. self.emptyNode:SetActive(false)
  129. local friendList = self.controller:FriendList()
  130. CommonUtil.LoopGridViewEleCreateNew(self,
  131. self.friendScrollList.loopVerticalScrollRect,
  132. self.friendScrollList.content.verticalLayoutGroup,
  133. friendList,
  134. 0,
  135. self, self.SetFriendData);
  136. else
  137. self.friendScrollList.loopVerticalScrollRect:ClearCells()
  138. self.emptyNode:SetActive(true)
  139. end
  140. end
  141. function UIExpeditionHelpView:SetFriendData(node,idx,friendData)
  142. if node == nil or friendData == nil then
  143. return
  144. end
  145. local _jbIcon = nil;
  146. local jobCfg = ManagerContainer.CfgMgr:GetJobDataById(friendData.job)
  147. if jobCfg ~= nil then
  148. _jbIcon = jobCfg.JobIcon;
  149. end
  150. local _headIcon = nil;
  151. if friendData.head ~= nil then
  152. _headIcon = friendData.head;
  153. end
  154. local _fakerData = {Level = friendData.level, ProfessionIcon = _jbIcon, HeadIcon = _headIcon, IsHero = true};
  155. CommonUtil.SetPlayerHeadAndFrame(self, node.headItem, _fakerData,false, friendData.headFrameId, self, self.OnClickPlayerHead, friendData.uid);
  156. node.playerName.text.text = friendData.name
  157. node.fightPower.text.text = tostring(friendData.fightPower)
  158. node.statusLbl.text.text = friendData:GetOnlineStatus()
  159. self.uiBase:AddButtonUniqueEventListener(node.helpBtn.button, self, self.OnClickPlayerHelp, friendData.uid)
  160. end
  161. function UIExpeditionHelpView:OnClickPlayerHelp(btn,params)
  162. local leftNum = ManagerContainer.DataMgr.ExpeditionDataMgr.maxRescuedNum - ManagerContainer.DataMgr.ExpeditionDataMgr.usedRescuedNum
  163. if leftNum <= 0 then
  164. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("ExpeditionSalvation")
  165. return
  166. end
  167. local uid = params[0]
  168. ManagerContainer.LuaUIMgr:ShowMessageBox("ExpeditionCallHelp",nil,uid,self,self.OnConfirmSendAssistReq,nil)
  169. end
  170. function UIExpeditionHelpView:OnClickPlayerHead(btn,params)
  171. local uid = params[0]
  172. ManagerContainer.LuaUIMgr:OpenRoleMessagePanel(uid)
  173. end
  174. function UIExpeditionHelpView:OnClickGuildHelp()
  175. local leftNum = ManagerContainer.DataMgr.ExpeditionDataMgr.maxRescuedNum - ManagerContainer.DataMgr.ExpeditionDataMgr.usedRescuedNum
  176. if leftNum <= 0 then
  177. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("ExpeditionSalvation")
  178. return
  179. end
  180. ManagerContainer.LuaUIMgr:ShowMessageBox("ExpeditionCallHelp",nil,0,self,self.OnConfirmSendAssistReq,nil)
  181. end
  182. function UIExpeditionHelpView:OnConfirmSendAssistReq(reqId)
  183. ManagerContainer.DataMgr.ExpeditionDataMgr:SendAssistReq(reqId)
  184. end
  185. return UIExpeditionHelpView