源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

232 lines
6.4 KiB

  1. FuliNoticeView = FuliNoticeView or BaseClass(BaseItem)
  2. local FuliNoticeView = FuliNoticeView
  3. function FuliNoticeView:__init()
  4. self.base_file = "Fuli"
  5. self.layout_file = "FuliNoticeView"
  6. self.model = LoginModel:getInstance()
  7. self.index = index or 1
  8. self.tab_list = {}
  9. self.cont_height = 564 + 15
  10. self:Load()
  11. end
  12. function FuliNoticeView:Load_callback()
  13. self.nodes = {
  14. "scrollNotice/Viewport/Content/bg2:raw", "arrow_image", "scrollNotice/Viewport/Content/bg2/jump_btn:obj",
  15. }
  16. self:GetChildren(self.nodes)
  17. self.scrollTab = self:GetChild("scrollTab/Viewport/Content")
  18. self.scrollNotice = self:GetChild("scrollNotice/Viewport/Content")
  19. self.scroll_rect = self:GetChild("scrollNotice"):GetComponent("ScrollRect")
  20. self.scroll_obj = self:GetChild("scrollNotice").gameObject
  21. self.arrow_image_canvas = self.arrow_image:GetComponent("CanvasGroup")
  22. self.contentTxt = self:GetChild("scrollNotice/Viewport/Content/contentTxt"):GetComponent("TextMeshProUGUI")
  23. self:AddEvents()
  24. self.bg2.transform.pivot = Vector2(0,1)
  25. self.bg2.transform.anchorMin = Vector2(0, 1)
  26. self.bg2.transform.anchorMax = Vector2(0, 1)
  27. SetAnchoredPosition(self.bg2,0,0)
  28. if self.need_refreshData then
  29. self:UpdateView()
  30. end
  31. end
  32. function FuliNoticeView:AddEvents( )
  33. local on_scroll_end = function ( )
  34. self:StopAllAnim()
  35. self:RemoveDelayHideId()
  36. self.arrow_image_canvas.alpha = 0
  37. end
  38. BindScrollViewEndEvent(self.scroll_obj, self.scroll_rect, on_scroll_end)
  39. local function on_click( ... )
  40. if self.data then
  41. local jump_id = stringtotable(self.data.jump_id)
  42. if TableSize(jump_id) > 0 then
  43. OpenFun.Open(jump_id[1][1],jump_id[1][2])
  44. end
  45. end
  46. end
  47. AddClickEvent(self.jump_btn_obj, on_click)
  48. end
  49. function FuliNoticeView:UpdateView( )
  50. local data = self.model:GetNoticeData("fuli_view")
  51. if TableSize(data) == 0 then
  52. return
  53. end
  54. local sort_func = function ( a, b )
  55. return a.sequence < b.sequence
  56. end
  57. table.sort(data, sort_func)
  58. local callback = function (index)
  59. self.index = index
  60. for _, v in pairs(self.tab_list) do
  61. v:SetSelectState(v.index == index)
  62. end
  63. self:SwitchView(data, index)
  64. end
  65. local tab = nil
  66. for i, v in ipairs(data) do
  67. tab = self.tab_list[i]
  68. if tab == nil then
  69. tab = FuliNoticeTab.New(self.scrollTab)
  70. self.tab_list[i] = tab
  71. end
  72. tab:SetPosition(7, -61 * (i - 1)-8)
  73. tab:SetCallBack(callback)
  74. tab:SetData(v, i)
  75. end
  76. self.scrollTab.sizeDelta = Vector2(245, #data * 80)
  77. callback(self.index)
  78. end
  79. function FuliNoticeView:SwitchView(content_list, index)
  80. local banner = content_list[index].picture == "[]" and 1 or content_list[index].picture
  81. local content = content_list[index].content or ""
  82. lua_resM:setOutsideRawImage(self,self.bg2_raw,GameResPath.GetViewBigBg("notice_banner"..banner),true)
  83. self.contentTxt.text = content
  84. self.size = self.contentTxt.preferredHeight + 60 + 145--145是banner高
  85. self.scrollNotice.sizeDelta = Vector2(688, self.size)
  86. if self.size < self.cont_height then
  87. self.scroll_rect.enabled = false
  88. self:StopAllAnim()
  89. self:RemoveDelayHideId()
  90. self.arrow_image_canvas.alpha = 0
  91. else
  92. self.scroll_rect.enabled = true
  93. end
  94. SetAnchoredPositionY(self.scrollNotice, 0)
  95. self:SetTimer()
  96. --设置跳转按钮开不开
  97. local data = content_list[index]
  98. self.data = data
  99. self.jump_btn_obj:SetActive(false)
  100. if data then
  101. local jump_id = stringtotable(data.jump_id)
  102. local day_can_jump = false
  103. local lv_can_jump = false
  104. if TableSize(jump_id) > 0 then--有跳转
  105. local openDay = stringtotable(data.open_day)
  106. if TableSize(openDay) > 0 then--有配开服天数
  107. local server_open_time = ServerTimeModel:getInstance():GetOpenServerTime()
  108. local open_day = 0
  109. if server_open_time > 0 then
  110. local open_time = os.time() - server_open_time
  111. open_day = open_time / 3600 / 24
  112. -- return math.ceil(day)--当时间刚好是3600*24*n的时候 就会比服务端少算一天的时间 客户端只有经过24小时+1秒才会递进1天
  113. open_day = math.floor(open_day+1)
  114. if openDay[1][1] <= open_day and openDay[1][2] >= open_day then
  115. day_can_jump = true
  116. end
  117. end
  118. else
  119. day_can_jump = true
  120. end
  121. local jump_lv = stringtotable(data.jump_lv)
  122. if TableSize(jump_lv) > 0 then--有限制等级跳转
  123. local level = RoleManager.Instance.mainRoleInfo.level
  124. if jump_lv[1][1] <= level and jump_lv[1][2] >= level then
  125. lv_can_jump = true
  126. end
  127. else
  128. lv_can_jump = true
  129. end
  130. self.jump_btn_obj:SetActive(day_can_jump and lv_can_jump)
  131. end
  132. end
  133. end
  134. function FuliNoticeView:SetData( data )
  135. self.data = data
  136. if self.is_loaded then
  137. self.need_refreshData = false
  138. self:UpdateView()
  139. else
  140. self.need_refreshData = true
  141. end
  142. end
  143. function FuliNoticeView:SetTimer( )
  144. self:StopTimer()
  145. local time = 3
  146. local function onBoxTimer()
  147. time = time - 1
  148. if time > 0 then
  149. else
  150. local x, y_offset = GetAnchoredPosition(self.scrollNotice, 0)
  151. if self.size <= self.cont_height or y_offset ~= 0 then--后面没东西了或者玩家动过
  152. else
  153. self:FlashHideCall()
  154. self:StopAllAnim()
  155. end
  156. self:StopTimer()
  157. end
  158. end
  159. self.arrow_timer_id = GlobalTimerQuest:AddPeriodQuest(onBoxTimer, 1, -1)
  160. end
  161. function FuliNoticeView:FlashShowCall( )
  162. if self._use_delete_method then
  163. return
  164. end
  165. local function callback( )
  166. self:FlashHideCall()
  167. end
  168. self.arrow_img_anim_id = TweenLite.to(self, self.arrow_image_canvas, TweenLite.UiAnimationType.ALPHA, 1, 0.5, callback)
  169. end
  170. function FuliNoticeView:FlashHideCall( )
  171. if self._use_delete_method then
  172. return
  173. end
  174. local function callback( )
  175. self:FlashShowCall()
  176. end
  177. if not self.delay_hide_id then
  178. local function delay( )
  179. self:RemoveDelayHideId()
  180. self.arrow_img_anim_id = TweenLite.to(self, self.arrow_image_canvas, TweenLite.UiAnimationType.ALPHA, 0.3, 0.5, callback)
  181. end
  182. self.delay_hide_id = setTimeout(delay,0.2)
  183. end
  184. end
  185. function FuliNoticeView:RemoveDelayHideId( )
  186. if self.delay_hide_id then
  187. GlobalTimerQuest:CancelQuest(self.delay_hide_id)
  188. self.delay_hide_id = nil
  189. end
  190. end
  191. function FuliNoticeView:StopAllAnim( )
  192. if self.arrow_img_anim_id then
  193. TweenLite.Stop(self.arrow_img_anim_id)
  194. self.arrow_img_anim_id = nil
  195. end
  196. end
  197. function FuliNoticeView:StopTimer( )
  198. if self.arrow_timer_id then
  199. GlobalTimerQuest:CancelQuest(self.arrow_timer_id)
  200. self.arrow_timer_id = nil
  201. end
  202. end
  203. function FuliNoticeView:__delete( )
  204. for k, v in pairs(self.tab_list) do
  205. v:DeleteMe()
  206. v = nil
  207. end
  208. self.item_list = {}
  209. self.scroll_rect.onValueChanged:RemoveAllListeners()
  210. self:StopAllAnim()
  211. self:RemoveDelayHideId()
  212. self:StopTimer()
  213. end