UIVoyageRobberyView.lua 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. local UIVoyageRobberyView = require("UIVoyage/UIVoyageRobberyView_Generate")
  2. function UIVoyageRobberyView:OnAwake(data)
  3. self.controller = require("UIVoyage/UIVoyageRobberyCtr"):new()
  4. self.controller:Init(self)
  5. self.controller:SetData(data)
  6. end
  7. function UIVoyageRobberyView:AddEventListener()
  8. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.VOYAGE_CHALLENGE_NUM_CHANGED, self, self.RefreshRobNum)
  9. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.VOYAGE_CHECK_AIRSHIP_CHANGED, self, self.OnCheckAirShipChanged)
  10. end
  11. function UIVoyageRobberyView: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 UIVoyageRobberyView:Init()
  22. local trans = self.transform:Find('UIAnimator/Window/BG/Content/ShipHolder/AirShipItem')
  23. local item = {}
  24. item.gameObject = trans.gameObject
  25. item.transform = trans
  26. item.animator = trans:GetComponent(Enum.TypeInfo.Animator)
  27. item.me = trans:Find("Me").gameObject
  28. item.fan = trans:Find("Ship/Fan").gameObject
  29. item.switchSprite = trans:Find("Ship/Body"):GetComponent(Enum.TypeInfo.UIImageSwitchSprite)
  30. self.airShipItem = item
  31. self.controller:InitData()
  32. self:RefreshView()
  33. self:RefreshRobNum()
  34. self.box:SetActive(true)
  35. end
  36. function UIVoyageRobberyView:RemoveEventListener()
  37. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  38. end
  39. function UIVoyageRobberyView:AddUIEventListener()
  40. self.uiBase:AddButtonUniqueEventListener(self.AnyBtn.button,self, self.OnClickCloseBtn)
  41. self.uiBase:AddButtonUniqueEventListener(self.btnClose.button, self, self.OnClickCloseBtn)
  42. self.uiBase:AddButtonUniqueEventListener(self.btnCancle.button, self, self.OnClickCloseBtn)
  43. self.uiBase:AddButtonUniqueEventListener(self.btnChallenge.button, self, self.OnClickChallengeBtn)
  44. end
  45. function UIVoyageRobberyView:OnHide()
  46. end
  47. function UIVoyageRobberyView:OnShow(data)
  48. self.controller:SetData(data)
  49. self.box:SetActive(true)
  50. end
  51. function UIVoyageRobberyView:OnClose()
  52. end
  53. function UIVoyageRobberyView:OnDispose()
  54. if self.endTimer then
  55. self.endTimer:Stop()
  56. self.endTimer = nil
  57. end
  58. self.airShipItem = nil
  59. self.controller:OnDispose()
  60. end
  61. function UIVoyageRobberyView:OnCheckAirShipChanged(uid)
  62. local airShipData = self.controller:GetAirShipData()
  63. if airShipData and airShipData.uid == uid then
  64. local name = airShipData:GetName()
  65. if not name then
  66. self.nameSp:SetActive(false)
  67. else
  68. self.nameSp:SetActive(true)
  69. self.nameTxt.text.text = string.formatbykey('RobShipName', airShipData:GetServerId(), name)
  70. end
  71. end
  72. end
  73. function UIVoyageRobberyView:OnClickCloseBtn()
  74. self:UIClose()
  75. end
  76. function UIVoyageRobberyView:OnClickChallengeBtn()
  77. local airShipData = self.controller:GetAirShipData()
  78. if not airShipData then
  79. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('VoyageErrorTips01')
  80. return
  81. end
  82. local selfuid = ManagerContainer.DataMgr.UserData:GetUserId()
  83. if airShipData.uid == selfuid then
  84. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('VoyageErrorTips02')
  85. return
  86. end
  87. local cfgData = ManagerContainer.CfgMgr:GetVoyageAirShipCfgById(airShipData.quality)
  88. local curTime = ManagerContainer.LuaTimerMgr:CurLuaServerTime()
  89. local sec = (airShipData.endTime - curTime) / 1000
  90. sec = type(sec) == "number" and sec or #sec
  91. local time = airShipData.duration or 1
  92. if sec > time then
  93. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('VoyageErrorTips03')
  94. return
  95. elseif sec <= 0 then
  96. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('VoyageFinishTips')
  97. return
  98. end
  99. local errorCode = self.controller:SendChallengeReq(airShipData.uid, airShipData.endTime)
  100. if errorCode ~= 0 then
  101. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  102. end
  103. end
  104. function UIVoyageRobberyView:RefreshRobNum()
  105. self.robNum.text.text = tostring(self.controller:GetRemindRobNum())
  106. end
  107. function UIVoyageRobberyView:RefreshView()
  108. if self.endTimer then
  109. self.endTimer:Stop()
  110. end
  111. local airShipData = self.controller:GetAirShipData()
  112. if airShipData then
  113. local cfgData = ManagerContainer.CfgMgr:GetVoyageAirShipCfgById(airShipData.quality)
  114. if cfgData then
  115. local rewards = cfgData.RobberyReward
  116. if rewards then
  117. self:RefreshCurrencyItem(self.currency1, rewards[1])
  118. self:RefreshCurrencyItem(self.currency2, rewards[2])
  119. self:RefreshCurrencyItem(self.currency3, rewards[3])
  120. else
  121. self:RefreshCurrencyItem(self.currency1, nil)
  122. self:RefreshCurrencyItem(self.currency2, nil)
  123. self:RefreshCurrencyItem(self.currency3, nil)
  124. end
  125. self.airShipItem.gameObject:SetActive(true)
  126. self.timer:SetActive(true)
  127. self:RefreshEndTimer()
  128. local name = airShipData:GetName()
  129. if not name then
  130. self.nameSp:SetActive(false)
  131. self.controller:SendCheckInfoReq(airShipData.uid, airShipData.endTime)
  132. else
  133. self.nameSp:SetActive(true)
  134. self.nameTxt.text.text = string.formatbykey('RobShipName', airShipData:GetServerId(), name)
  135. end
  136. return
  137. end
  138. end
  139. self:RefreshCurrencyItem(self.currency1, nil)
  140. self:RefreshCurrencyItem(self.currency2, nil)
  141. self:RefreshCurrencyItem(self.currency3, nil)
  142. self.beRobNum.text.text = '0/0'
  143. self.airShipItem.gameObject:SetActive(false)
  144. self.nameSp:SetActive(false)
  145. self.timer:SetActive(false)
  146. self.btnChallenge:SetActive(false)
  147. end
  148. function UIVoyageRobberyView:RefreshEndTimer()
  149. local airShipData = self.controller:RefreshAndGetAirShipData()
  150. if not airShipData then
  151. self:RefreshView()
  152. return
  153. end
  154. local cfgData = ManagerContainer.CfgMgr:GetVoyageAirShipCfgById(airShipData.quality)
  155. if not cfgData then
  156. self:RefreshView()
  157. return
  158. end
  159. self.airShipItem.animator:Play('AirShipRun')
  160. local quality = self.controller:RefreshQuality()
  161. local beChallengeNum = self.controller:RefreshBeChallengeNum()
  162. if beChallengeNum then
  163. self.beRobNum.text.text = tostring(beChallengeNum) .. '/' .. tostring(cfgData.RobberyTimes)
  164. if beChallengeNum >= cfgData.RobberyTimes then
  165. quality = 0
  166. end
  167. end
  168. if quality then
  169. self.airShipItem.switchSprite:ChangeSprite(quality)
  170. self.airShipItem.fan:SetActive(quality > 0)
  171. end
  172. local remainTime = (airShipData.endTime - ManagerContainer.LuaTimerMgr:CurLuaServerTime()) / 1000
  173. remainTime = type(remainTime) == "number" and remainTime or #remainTime
  174. self.timerTxt.text.text = DateTimeUtil.convertSeconds2TimeStr1(remainTime, true, true, false)
  175. if remainTime <= 0 then
  176. if self.endTimer then
  177. self.endTimer:Stop()
  178. end
  179. else
  180. if not self.endTimer then
  181. self.endTimer = Timer.New(slot(self.RefreshEndTimer, self), 1, -1)
  182. end
  183. if not self.endTimer.running then
  184. self.endTimer:Start()
  185. end
  186. end
  187. end
  188. function UIVoyageRobberyView:RefreshCurrencyItem(currency, reward)
  189. if not currency then return end
  190. currency.icon.image.enabled = false
  191. currency.icon.image.sprite = nil
  192. if reward then
  193. local cfgId = reward[1] or 0
  194. local num = reward[2] or 0
  195. local cfgData = ManagerContainer.CfgMgr:GetItemById(cfgId)
  196. if cfgData then
  197. CommonUtil.LoadIcon(self, cfgData.MiniIcon, function(sprite)
  198. currency.icon.image.sprite = sprite
  199. currency.icon.image.enabled = true
  200. end)
  201. end
  202. currency.text.text.text = tostring(num)
  203. currency:SetActive(true)
  204. else
  205. currency:SetActive(false)
  206. end
  207. end
  208. return UIVoyageRobberyView