源战役客户端
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.

222 lines
7.6 KiB

  1. -- <*
  2. -- @Author: huangcong
  3. -- @Description: 活动右侧特殊tips弹窗
  4. -- *>
  5. CommonActTipView = CommonActTipView or BaseClass(BaseView)
  6. local CommonActTipView = CommonActTipView
  7. function CommonActTipView:__init()
  8. self.base_file = "common"
  9. self.layout_file = "CommonActTipView"
  10. self.layer_name = "Main"
  11. self.destroy_imm = true
  12. self.use_background = false --全屏界面默认使用这个参数,非全屏界面自行设置
  13. self.anim_time = 0.5
  14. self.is_animating = false -- 是否在动画中
  15. self.show_time_str = false--是否显示剩余时间
  16. self.show_time_elapse = false --剩余时间显示
  17. self.auto_close_time = 20--关闭时间
  18. self.item_list = {}
  19. self.model = CommonModel:getInstance()
  20. self.load_callback = function ()
  21. self:LoadSuccess()
  22. self:AddEvent()
  23. end
  24. self.open_callback = function ( )
  25. self:UpdateView()
  26. end
  27. self.destroy_callback = function ( )
  28. self:DestroySuccess()
  29. end
  30. end
  31. --[[ view_data = { -- 界面数据
  32. desc = "完成首次充值领极品奖励",
  33. awardList = {},
  34. winId = 159,
  35. subId = 1,
  36. }
  37. ]]
  38. function CommonActTipView:Open(view_data)
  39. self.view_data = view_data
  40. print("huangcong:CommonActTipView [start:43] :", self.view_data)
  41. PrintTable(self.view_data)
  42. print("huangcong:CommonActTipView [end]")
  43. BaseView.Open(self)
  44. end
  45. function CommonActTipView:LoadSuccess()
  46. local nodes = {
  47. "goBtn:obj", "timeText:tmp", "closeBtn:obj", "nameText:tmp", "iconImage:img:obj","awardScroll", "awardScroll/Viewport/awardCon",
  48. }
  49. self:GetChildren(nodes)
  50. end
  51. function CommonActTipView:AddEvent()
  52. local function click_event(target)
  53. if target == self.closeBtn_obj then
  54. self:HideAnim() -- 播放关闭效果,并检查邀请缓存
  55. elseif target == self.goBtn_obj or target == self.iconImage_obj then
  56. if self.view_data and self.view_data.winId and self.view_data.subId then
  57. self:HideAnim()
  58. OpenFun.Open(self.view_data.winId,self.view_data.subId)
  59. end
  60. end
  61. end
  62. AddClickEvent(self.closeBtn_obj, click_event)
  63. AddClickEvent(self.goBtn_obj, click_event)
  64. local function close_event( ... )
  65. if not self.is_loaded or self._use_delete_method then return end
  66. self:HideAnim() -- 播放关闭效果,并检查邀请缓存
  67. end
  68. self:BindEvent(GlobalEventSystem, EventName.CLOSE_COMMON_ACT_TIPS, close_event)--更新界面
  69. end
  70. -- 更新邀请内容
  71. function CommonActTipView:UpdateView()
  72. self.nameText_tmp.text = self.view_data and self.view_data.desc or ""
  73. --资源可能有多个地址,默认activityIcon
  74. local ab_name, res_name = "activityIcon_asset", ""
  75. local is_out_res = false
  76. if self.view_data.winId and self.view_data.subId then
  77. local fun_vo = OpenFun.LinkWin[self.view_data.winId.."@"..self.view_data.subId]
  78. if fun_vo then
  79. res_name = fun_vo.icon_res
  80. lua_resM:setImageSprite(self, self.iconImage_img, ab_name, res_name,false)
  81. end
  82. end
  83. self:UpdateItemList()
  84. -- 动画重点坐标初始化
  85. self.start_anim_pos_x = 378 - ClientConfig.iphone_x_offset_right
  86. self.end_anim_pos_x = 0 - ClientConfig.iphone_x_offset_right
  87. SetAnchoredPositionX(self.transform, self.start_anim_pos_x)
  88. -- 自动关闭倒计时
  89. self:StartAutoCloseTimer()
  90. -- 播放弹出动画
  91. self:ShowAnim()
  92. end
  93. -- 自动关闭倒计时
  94. function CommonActTipView:StartAutoCloseTimer( )
  95. local end_time = self.auto_close_time + TimeUtil:getServerTime( )
  96. self:ClearAutoCloseTimer()
  97. local function auto_close_func()
  98. local left_time = end_time - TimeUtil:getServerTime( )
  99. if left_time >= 0 then
  100. if self.view_data.end_time then
  101. self.timeText_tmp.text = HtmlColorTxt(TimeUtil:convertTime(self.view_data.end_time - TimeUtil:getServerTime( )), "#0ce148")
  102. else
  103. self.timeText_tmp.text = HtmlColorTxt(TimeUtil:convertTime(left_time), "#0ce148")
  104. end
  105. else
  106. self:ClearAutoCloseTimer()
  107. self:HideAnim() -- 播放关闭效果,并检查邀请缓存
  108. end
  109. end
  110. self.auto_close_func_id = GlobalTimerQuest:AddPeriodQuest(auto_close_func, 1, -1)
  111. end
  112. function CommonActTipView:ClearAutoCloseTimer( )
  113. if self.auto_close_func_id then
  114. GlobalTimerQuest:CancelQuest(self.auto_close_func_id)
  115. self.auto_close_func_id = nil
  116. end
  117. end
  118. -- 弹出动画
  119. function CommonActTipView:ShowAnim()
  120. local function anim_callback()
  121. self.is_animating = false
  122. end
  123. self:ClearViewAnimId()
  124. self.is_animating = true
  125. self.view_anim_id = TweenLite.to(self, self.transform, TweenLite.UiAnimationType.ANCHORED_POSX,
  126. self.end_anim_pos_x, self.anim_time, anim_callback, TweenFunc.EASE_OUT_QUINT)
  127. end
  128. -- 播放关闭动画,并检测缓存是否还有其他邀请没有处理
  129. function CommonActTipView:HideAnim()
  130. local function anim_callback()
  131. self.is_animating = false
  132. self.waiting = true
  133. local cache_count = self.model:GetActTipDataCacheCount()
  134. if cache_count > 0 then
  135. self.view_data = self.model:PopActTipDataCache()
  136. cache_count = self.model:GetActTipDataCacheCount()
  137. if self.view_data then
  138. self:UpdateView()
  139. end
  140. else
  141. self:Close()
  142. end
  143. end
  144. self:ClearViewAnimId()
  145. self.is_animating = true
  146. self.view_anim_id = TweenLite.to(self, self.transform, TweenLite.UiAnimationType.ANCHORED_POSX,
  147. self.start_anim_pos_x, self.anim_time, anim_callback, TweenFunc.EASE_OUT_QUINT)
  148. end
  149. function CommonActTipView:ClearViewAnimId( )
  150. if self.view_anim_id then
  151. TweenLite.Stop(self.view_anim_id)
  152. self.view_anim_id = nil
  153. end
  154. end
  155. function CommonActTipView:DestroySuccess( )
  156. for i,item in pairs(self.item_list) do
  157. UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, item)
  158. end
  159. self.item_list = {}
  160. self:ClearViewAnimId()
  161. self:ClearAutoCloseTimer()
  162. end
  163. function CommonActTipView:UpdateItemList( )
  164. for k,v in pairs(self.item_list) do
  165. v:SetVisible(false,nil,true)
  166. end
  167. self.col_num = 3
  168. local item_list = self.view_data.awardList
  169. if not item_list or TableSize(item_list) == 0 then return end
  170. local len = #item_list
  171. --如果比最大高度要高 那就只能滚动了
  172. local offer_x = 1
  173. local offer_y = -1
  174. local space_x = 10
  175. local space_y = 0
  176. local item_width = 47
  177. local x = 0
  178. local y = 0
  179. for i, v in ipairs(item_list) do
  180. local item = self.item_list[i]
  181. if item == nil then
  182. item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem,self.awardCon)
  183. item:SetItemSize(47,47)
  184. item:SetGoodsVo(v[4])
  185. self.item_list[i] = item
  186. end
  187. local goods_Id, lock = GoodsModel:getInstance():GetMappingTypeId(v[1], v[2])
  188. local goodVo = GoodsModel:getInstance():GetGoodsBasicByTypeId(goods_Id)
  189. local stren_data = nil
  190. if v[4] then
  191. stren_data = EquipModel:getInstance():GetBagEquipAwaraItemInfo(v[4])
  192. stren_data.equip_key = "EquipView"
  193. end
  194. if goodVo then
  195. item:SetData(goods_Id, v[3], goodVo.color, stren_data, lock,true,nil)
  196. else
  197. -- error("没有找到物品信息 "..v.typeId)
  198. end
  199. item:SetVisible(true,nil,true)
  200. x = (item_width+space_x)*(i-1) + offer_x
  201. y = 0
  202. item:SetPosition(x,y)
  203. end
  204. SetSizeDeltaX(self.awardCon,#item_list*(47+10)+10)
  205. end