MainTopView.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. local MainTopView = class("MainTopView")
  2. local ScrollNoticeView = require("UIMain/ScrollNoticeView")
  3. local showAni = "TopShow"
  4. local closeAni = "TopClose"
  5. local scrollNoticeView
  6. local updateHandle
  7. local curLimitedTime
  8. local interLimitedTime = 10
  9. local curRankTime
  10. function MainTopView:ctor()
  11. self.root = nil
  12. self.state = true
  13. self.animator = nil
  14. self.mCanvas = nil
  15. self.lastSortingOrder = 0
  16. self.defaultSortingOrder = 0
  17. end
  18. function MainTopView:Init(root, canvas, animator, sortingOrder)
  19. self.root = root
  20. self.mCanvas = canvas
  21. self.animator = animator
  22. self.defaultSortingOrder = sortingOrder
  23. self.lastSortingOrder = self.defaultSortingOrder
  24. if not scrollNoticeView then
  25. scrollNoticeView = ScrollNoticeView.new()
  26. scrollNoticeView:Init(self.root.noticeBg)
  27. end
  28. self:StartUpdate()
  29. self:InitBtnState()
  30. end
  31. function MainTopView:InitBtnState()
  32. self.root.topRoot.btnActivityTower:SetActive(false)
  33. self.root.topRoot.btnActivityDojo:SetActive(false)
  34. self.root.topRoot.btnActivityMap:SetActive(false)
  35. self.root.topRoot.btnActivityPet:SetActive(false)
  36. --开发阶段 打开主页面上的战令系统
  37. self.root.topRoot.btnAirshipRewards:SetActive(false)
  38. self.root.topRoot.btnActivitySkill:SetActive(false)
  39. self:ChangeRefreshCombineServerBtn()
  40. end
  41. function MainTopView:StartUpdate()
  42. if not updateHandle then
  43. updateHandle = UpdateBeat:CreateListener(self.Update, self)
  44. end
  45. UpdateBeat:AddListener(updateHandle)
  46. curLimitedTime = 0
  47. curRankTime = 0
  48. end
  49. function MainTopView:EndUpdate()
  50. if updateHandle ~= nil then
  51. UpdateBeat:RemoveListener(updateHandle)
  52. updateHandle = nil
  53. end
  54. end
  55. function MainTopView:Change(state, order)
  56. if self.mCanvas == nil then return end
  57. if state then
  58. if ManagerContainer.LuaUIMgr:NeedMainHideTop() then
  59. return
  60. end
  61. end
  62. if state then
  63. self.lastSortingOrder = self.mCanvas.sortingOrder
  64. self.mCanvas.sortingOrder = math.max(1000, (order or 1000) + 1)
  65. self:RefreshTopBtns(true)
  66. else
  67. self.mCanvas.sortingOrder = self.lastSortingOrder
  68. self:RefreshTopBtns(false)
  69. end
  70. if self.state ~= state then
  71. self.state = state
  72. self.animator:Play(state and showAni or closeAni, 0, 0)
  73. self:ChangeRefreshCombineServerBtn()
  74. end
  75. end
  76. function MainTopView:Resume()
  77. if self.mCanvas == nil then return end
  78. self.mCanvas.sortingOrder = self.defaultSortingOrder
  79. self.state = false
  80. self.animator:Play(closeAni)
  81. end
  82. function MainTopView:Update()
  83. if self.limitState and self.root and curLimitedTime then
  84. curLimitedTime = curLimitedTime + Time.deltaTime
  85. if curLimitedTime >= interLimitedTime then
  86. curLimitedTime = 0
  87. self:RefreshLimitEndTime()
  88. end
  89. end
  90. end
  91. function MainTopView:RefreshTopBtns(state)
  92. self.root.topRoot.topBtns:SetActive(state)
  93. if state then
  94. local _unlockState = ManagerContainer.UIFuncUnlockMgr:GetFuncLockStatusById(34);
  95. if _unlockState then
  96. self.root.topRoot.btnTask.gameObject:SetActive(state);
  97. end
  98. if Constant.OpenPay then
  99. local limitRechargeData = ManagerContainer.DataMgr.ActsDataMgr:GetLimitRechargeItem()
  100. if limitRechargeData then
  101. local isExist = limitRechargeData:IsLimitRechargeExist()
  102. self.root.topRoot.btnLimitedGift:SetActive(isExist)
  103. self.limitState = true
  104. else
  105. self.root.topRoot.btnLimitedGift:SetActive(false)
  106. self.limitState = false
  107. end
  108. else
  109. self.root.topRoot.btnLimitedGift:SetActive(false)
  110. self.limitState = false
  111. end
  112. _unlockState = ManagerContainer.UIFuncUnlockMgr:GetFuncLockStatusById(59);
  113. if _unlockState then
  114. local rewardState = ManagerContainer.DataMgr.UserData:GetQuestionRewardState()
  115. self.root.topRoot.btnQuestionnaire:SetActive(not rewardState)
  116. else
  117. self.root.topRoot.btnQuestionnaire:SetActive(false)
  118. end
  119. else
  120. self.root.topRoot.btnLimitedGift:SetActive(false)
  121. self.limitState = false
  122. end
  123. end
  124. function MainTopView:OpenLimitRecharge()
  125. --local _unlockState = ManagerContainer.UIFuncUnlockMgr:GetFuncLockStatusById(34);
  126. --if not _unlockState then
  127. -- self.root.topRoot.btnTask.gameObject:SetActive(false);
  128. -- self.limitState = false
  129. -- return
  130. --end
  131. if not Constant.OpenPay then
  132. self.root.topRoot.btnLimitedGift:SetActive(false)
  133. self.limitState = false
  134. return
  135. end
  136. local limitRechargeData = ManagerContainer.DataMgr.ActsDataMgr:GetLimitRechargeItem()
  137. if not limitRechargeData then
  138. self.limitState = false
  139. self.root.topRoot.btnLimitedGift:SetActive(false)
  140. return
  141. end
  142. local isExist = limitRechargeData:IsLimitRechargeExist()
  143. self.root.topRoot.btnLimitedGift:SetActive(isExist)
  144. if not isExist then
  145. self.limitState = false
  146. return
  147. else
  148. self.limitState = true
  149. end
  150. end
  151. function MainTopView:RefreshLimitEndTime()
  152. local limitRechargeData = ManagerContainer.DataMgr.ActsDataMgr:GetLimitRechargeItem()
  153. if not limitRechargeData then return end
  154. local isExist = limitRechargeData:IsLimitRechargeExist()
  155. if not isExist then
  156. self.limitState = false
  157. self.root.topRoot.btnLimitedGift:SetActive(false)
  158. return
  159. end
  160. end
  161. function MainTopView:RefreshAirShipActivityEnter(state)
  162. if state then
  163. local unlockState = ManagerContainer.UIFuncUnlockMgr:GetFuncLockStatusById(54)
  164. if not unlockState then
  165. state = false
  166. end
  167. end
  168. if not Constant.OpenPay then
  169. state = false
  170. end
  171. --LogError('222'..tostring(state))
  172. self.root.topRoot.btnAirshipRewards:SetActive(state)
  173. if not state then
  174. return
  175. end
  176. self:RefreshAirShipActivityEndTime()
  177. end
  178. function MainTopView:RefreshAirShipActivityEndTime()
  179. local endTime = ManagerContainer.DataMgr.RuneShopDataMgr:GetCurAirShipActivityEndTime()
  180. if not endTime then
  181. return
  182. end
  183. local text
  184. text = self.root.topRoot.btnAirshipRewards.textTime
  185. -- text.text.text = ManagerContainer.LuaTimerMgr:ParseEndTimeStamp2TimeWithUInt64(endTime)
  186. local remains = ManagerContainer.LuaTimerMgr:GetRemainSecondsWithUInt64(endTime, false)
  187. --LogError("时间"..remains)
  188. if remains > 0 then
  189. if remains <= 60 then
  190. text.text.text = I18N.T("LessOneMinu")
  191. else
  192. local time = DateTimeUtil.convertSeconds2TimeStr1(remains, true, false)
  193. text.text.text = time
  194. end
  195. end
  196. end
  197. function MainTopView:RefreshRankActivityEnter(type, state)
  198. if type == Enum.RankActivitiesType.ClimbingTower then
  199. if state then
  200. local unlockState = ManagerContainer.UIFuncUnlockMgr:GetFuncLockStatusById(60)
  201. if not unlockState then
  202. state = false
  203. end
  204. end
  205. self.root.topRoot.btnActivityTower:SetActive(state)
  206. elseif type == Enum.RankActivitiesType.Dojo then
  207. if state then
  208. local unlockState = ManagerContainer.UIFuncUnlockMgr:GetFuncLockStatusById(61)
  209. if not unlockState then
  210. state = false
  211. end
  212. end
  213. self.root.topRoot.btnActivityDojo:SetActive(state)
  214. elseif type == Enum.RankActivitiesType.MapProgress then
  215. if state then
  216. local unlockState = ManagerContainer.UIFuncUnlockMgr:GetFuncLockStatusById(64)
  217. if not unlockState then
  218. state = false
  219. end
  220. end
  221. self.root.topRoot.btnActivityMap:SetActive(state)
  222. elseif type == Enum.RankActivitiesType.Pet then
  223. if state then
  224. local unlockState = ManagerContainer.UIFuncUnlockMgr:GetFuncLockStatusById(71)
  225. if not unlockState then
  226. state = false
  227. end
  228. end
  229. self.root.topRoot.btnActivityPet:SetActive(state)
  230. elseif type == Enum.RankActivitiesType.Skill then
  231. if state then
  232. local unlockState = ManagerContainer.UIFuncUnlockMgr:GetFuncLockStatusById(71)
  233. if not unlockState then
  234. state = false
  235. end
  236. end
  237. self.root.topRoot.btnActivitySkill:SetActive(state)
  238. end
  239. self:RefreshRankActivityEndTime()
  240. end
  241. function MainTopView:RefreshRankActivityEndTime()
  242. for k,v in pairs(Enum.RankActivitiesType) do
  243. local type = v
  244. local stage, endTime, inRush = ManagerContainer.DataMgr.RankActivitiesMgr:GetCurRankActivityStageEndTime(type)
  245. if inRush then
  246. local text
  247. if type == Enum.RankActivitiesType.ClimbingTower then
  248. text = self.root.topRoot.btnActivityTower.textTime
  249. elseif type == Enum.RankActivitiesType.Dojo then
  250. text = self.root.topRoot.btnActivityDojo.textTime
  251. elseif type == Enum.RankActivitiesType.MapProgress then
  252. text = self.root.topRoot.btnActivityMap.textTime
  253. elseif type == Enum.RankActivitiesType.Pet then
  254. text = self.root.topRoot.btnActivityPet.textTime
  255. elseif type == Enum.RankActivitiesType.Skill then
  256. text = self.root.topRoot.btnActivitySkill.textTime
  257. end
  258. local remainS = ManagerContainer.LuaTimerMgr:GetRemainSecondsWithUInt64(endTime, false)
  259. if stage == 1 then
  260. if remainS <= 0 then
  261. ManagerContainer.DataMgr.RankActivitiesMgr:QueryRankActivitiesData()
  262. elseif remainS <= 60 then
  263. text.text.text = I18N.T("LessOneMinu")
  264. else
  265. local time = DateTimeUtil.convertSeconds2TimeStr1(remainS, true, false)
  266. text.text.text = time
  267. end
  268. elseif stage == 2 then
  269. text.text.text = I18N.T("RushBtnEnd")
  270. end
  271. end
  272. end
  273. end
  274. function MainTopView:InsertGMNotice(notice)
  275. if scrollNoticeView then
  276. scrollNoticeView:InsertGMNotice(notice)
  277. end
  278. end
  279. function MainTopView:ChangeRefreshCombineServerBtn()
  280. local nextTime = ManagerContainer.DataMgr.CombineServerDataMgr:GetNextTime()
  281. self.root.topRoot.btnCombineService:SetActive(nextTime and nextTime > 0)
  282. if not self.state then
  283. if self.combineServerTimer and self.combineServerTimer.running then
  284. self.combineServerTimer:Stop()
  285. end
  286. else
  287. self:RefreshCombineServerBtn()
  288. end
  289. end
  290. function MainTopView:DisposeRefreshCombineServerBtn()
  291. if self.combineServerTimer then
  292. if self.combineServerTimer.running then
  293. self.combineServerTimer:Stop()
  294. end
  295. self.combineServerTimer = nil
  296. end
  297. end
  298. function MainTopView:RefreshCombineServerBtn()
  299. local nextTime = ManagerContainer.DataMgr.CombineServerDataMgr:GetNextTime()
  300. if not nextTime or nextTime <= 0 then
  301. self:DisposeRefreshCombineServerBtn()
  302. self.root.topRoot.btnCombineService.textTime.text.text = string.formatbykey('CombinedServiceTips', 1)
  303. return
  304. end
  305. local remainS = ManagerContainer.LuaTimerMgr:GetRemainSecondsWithUInt64(nextTime)
  306. if remainS < 86400 then
  307. self:DisposeRefreshCombineServerBtn()
  308. self.root.topRoot.btnCombineService.textTime.text.text = string.formatbykey('CombinedServiceTips', 1)
  309. return
  310. end
  311. if not self.combineServerTimer then
  312. self.combineServerTimer = Timer.New(slot(self.RefreshCombineServerBtn, self), 86400, -1, true)
  313. end
  314. self.combineServerTimer.time = remainS % 86400 + 1
  315. if not self.combineServerTimer.running then
  316. self.combineServerTimer:Start()
  317. end
  318. self.root.topRoot.btnCombineService.textTime.text.text = string.formatbykey('CombinedServiceTips', Mathf.Ceil(remainS / 86400))
  319. end
  320. function MainTopView:Dispose()
  321. self:EndUpdate()
  322. self:DisposeRefreshCombineServerBtn()
  323. scrollNoticeView:Dispose()
  324. scrollNoticeView = nil
  325. self.animator = nil
  326. self.mCanvas = nil
  327. self.trans = nil
  328. end
  329. return MainTopView