源战役客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

232 行
7.2 KiB

  1. -- @Author: HWR
  2. -- @Description: 风采弹出提示界面
  3. WardrobeTipsView = WardrobeTipsView or BaseClass(BaseView)
  4. local WardrobeTipsView = WardrobeTipsView
  5. function WardrobeTipsView:__init()
  6. self.base_file = "wardrobe"
  7. self.layout_file = "WardrobeTipsView"
  8. self.layer_name = "Top"
  9. self.destroy_imm = true
  10. self.use_background = false --全屏界面默认使用这个参数
  11. self.is_animating = false -- 是否在动画中
  12. self.hide_time = 2 -- n秒后播放界面隐藏动画
  13. self.receive_flag = nil -- 读取完界面数据后,用于发送领取协议的关键键值
  14. self.model = WardrobeModel:getInstance()
  15. self.model.tip_view_show = true
  16. self.load_callback = function ()
  17. self:LoadSuccess()
  18. self:AddEvent()
  19. end
  20. self.open_callback = function ( )
  21. self:OpenSuccess()
  22. end
  23. self.destroy_callback = function ( )
  24. self:DestroySuccess()
  25. end
  26. end
  27. function WardrobeTipsView:Open(tips_data)
  28. self.tips_data = tips_data
  29. BaseView.Open(self)
  30. end
  31. --重用界面,5秒后再销毁
  32. function WardrobeTipsView:ResetViewInfo(tips_data)
  33. self.tips_data = tips_data
  34. self.transform.anchoredPosition = Vector2(-3.5, 61.5)
  35. self.gameObject:SetActive(true)
  36. if self.delay_closeview_id then
  37. TimerQuest.CancelQuest(GlobalTimerQuest,self.delay_closeview_id)
  38. self.delay_closeview_id = nil
  39. end
  40. self:UpdateView() -- 更新数据
  41. self:StartCloseTimer() -- 开始对界面的关闭进行计时
  42. self:OpenAnimation() -- 播放打开界面的动画
  43. end
  44. function WardrobeTipsView:LoadSuccess()
  45. local nodes = {
  46. "go_btn/go_btn_text:tmp", "close_timer:tmp", "go_btn:obj",
  47. "type_name_text:tmp", "icon_small_image:img",
  48. "wardrobe_con/wardrobe_text:tmp", "wardrobe_con/wardrobe_up_text:tmp", "name_text:tmp", "wardrobe_con:obj",
  49. }
  50. self:GetChildren(nodes)
  51. self.canvasGroup = self.gameObject:GetComponent("CanvasGroup")
  52. self.transform.anchoredPosition = Vector2(-3.5, 61.5)
  53. end
  54. function WardrobeTipsView:AddEvent()
  55. local function click_event(target)
  56. self:ReceiveFunc()
  57. self:ClearHideTimer()
  58. self:AutoCloseFunc()
  59. if self.is_unlock then
  60. if self.is_unlock == 1 then
  61. else
  62. GlobalEventSystem:Fire(WardrobeConst.OPEN_WARDROBE_MAIN_VIEW, WardrobeConst.TabId.SHOP, self.is_unlock + 1)
  63. end
  64. end
  65. end
  66. AddClickEvent(self.go_btn_obj, click_event)
  67. end
  68. function WardrobeTipsView:OpenSuccess()
  69. self:UpdateView()
  70. self:StartCloseTimer()
  71. self:OpenAnimation() -- 播放打开界面的动画
  72. end
  73. function WardrobeTipsView:UpdateView()
  74. self.is_unlock = nil
  75. if self.tips_data.is_unlock then--如果是解锁商城的就有按钮
  76. self.go_btn_obj:SetActive(true)
  77. self.name_text_tmp.text = ""
  78. local cfg = Config.Wardrobeopen
  79. for i,v in ipairs(cfg) do
  80. if v.condition <= self.tips_data.stage then
  81. self.is_unlock = v.store_id
  82. end
  83. end
  84. if self.is_unlock == 1 then
  85. self.go_btn_text_tmp.text = "确定"
  86. else
  87. self.go_btn_text_tmp.text = "前往"
  88. end
  89. self.type_name_text_tmp.text = string.format("%s %s", HtmlColorTxt("解锁", ColorUtil.YELLOW_DARK), cfg[self.is_unlock].store_name)
  90. SetAnchoredPositionX(self.wardrobe_con, 44)
  91. else
  92. self.go_btn_obj:SetActive(false)
  93. self.type_name_text_tmp.text = string.format("%s %s", HtmlColorTxt("解锁", ColorUtil.YELLOW_DARK), self.model:GetWardrobeTypeName(self.tips_data.type))
  94. if self.tips_data.type == 9 or self.tips_data.type == 10 then--进阶和伙伴要去拿阶数
  95. self.name_text_tmp.text = string.format("%s %s阶", self.model:GetWardrobeTypeName(self.tips_data.type), self.tips_data.color)
  96. else
  97. local goods_name = GoodsModel:getInstance():getGoodsName(self.tips_data.id, false)
  98. if SubStringGetTotalIndex(goods_name) > 4 then
  99. goods_name = SubStringUTF8(goods_name, 1, 4) .. "..."
  100. end
  101. self.name_text_tmp.text = goods_name
  102. end
  103. SetAnchoredPositionX(self.wardrobe_con, 110)
  104. end
  105. self.wardrobe_up_text_tmp.text = self.tips_data.up_value
  106. self.wardrobe_text_tmp.text = string.format("风采值 %s", HtmlColorTxt(self.tips_data.sum_wardrobe_value, ColorUtil.YELLOW_DARK))
  107. local res_name = string.format("wardrobe_level%s", self.tips_data.stage)
  108. lua_resM:setOutsideImageSprite(self, self.icon_small_image_img, GameResPath.GetWardrobeImage(res_name), true)
  109. if self.delay_id then
  110. GlobalTimerQuest:CancelQuest(self.delay_id)
  111. self.delay_id = nil
  112. end
  113. local function delay_method( )
  114. SetSizeDeltaX(self.wardrobe_text, self.wardrobe_text_tmp.preferredWidth+1)
  115. end
  116. self.delay_id = setTimeout(delay_method, 0.01)
  117. end
  118. -- 开始界面关闭的倒计时
  119. function WardrobeTipsView:StartCloseTimer()
  120. self:ClearHideTimer()
  121. local end_time = self.hide_time + TimeUtil:getServerTime()
  122. local function hide_timer()
  123. local left_time = end_time - TimeUtil:getServerTime()
  124. if not self.tips_data.is_unlock then
  125. self.close_timer_tmp.text = ""
  126. else
  127. self.close_timer_tmp.text = left_time >= 0 and string.format("(<color=%s>%ss</color>后自动关闭)", ColorUtil.GREEN_DARK, math.ceil(left_time+1)) or ""
  128. end
  129. if left_time < 0 then
  130. self:ClearHideTimer()
  131. self:AutoCloseFunc()
  132. self:TimeOverFunc()
  133. end
  134. end
  135. hide_timer()
  136. self.hide_timer_id = GlobalTimerQuest:AddPeriodQuest(hide_timer, 0.1, -1)
  137. -- 设置动画标志量
  138. self.is_animating = true
  139. end
  140. -- 点击按钮后的响应
  141. function WardrobeTipsView:ReceiveFunc( )
  142. end
  143. -- 倒计时结束的响应
  144. function WardrobeTipsView:TimeOverFunc( )
  145. end
  146. function WardrobeTipsView:ClearHideTimer( )
  147. if self.hide_timer_id then
  148. GlobalTimerQuest:CancelQuest(self.hide_timer_id)
  149. self.hide_timer_id = nil
  150. end
  151. end
  152. function WardrobeTipsView:AutoCloseFunc( )
  153. local function callback()
  154. self:ClearHideTimer()
  155. self.gameObject:SetActive(false)
  156. local function delay_closeview( )
  157. BaseView.Close(self)
  158. end
  159. self.delay_closeview_id = setTimeout(delay_closeview, 5)
  160. -- 设置动画标志量
  161. self.is_animating = false
  162. -- 查看是否还没展示完成界面
  163. self.model:Fire(WardrobeConst.OPEN_WARDROBE_TIP_VIEW, true)
  164. end
  165. self:CloseAnimation(callback)
  166. end
  167. -- 播放打开界面的动画
  168. function WardrobeTipsView:OpenAnimation()
  169. self.canvasGroup.alpha = 0
  170. if self.alpha_anim_id then
  171. TweenLite.Stop(self.alpha_anim_id)
  172. self.alpha_anim_id = nil
  173. end
  174. self.alpha_anim_id = TweenLite.to(self, self.canvasGroup, TweenLite.UiAnimationType.ALPHA, 1, 0.2)
  175. end
  176. -- 关闭(隐藏)界面的动画
  177. function WardrobeTipsView:CloseAnimation(callback)
  178. self.canvasGroup.alpha = 1
  179. if self.alpha_anim_id then
  180. TweenLite.Stop(self.alpha_anim_id)
  181. self.alpha_anim_id = nil
  182. end
  183. self.alpha_anim_id = TweenLite.to(self, self.canvasGroup,TweenLite.UiAnimationType.ALPHA, 0, 0.5)
  184. local pos_y = self.transform.anchoredPosition.y + 100
  185. if self.pos_id then
  186. TweenLite.Stop(self.pos_id)
  187. self.pos_id = nil
  188. end
  189. self.pos_id = TweenLite.to(self, self.transform, TweenLite.UiAnimationType.ANCHORED_POSY, pos_y, 0.5, callback)
  190. end
  191. function WardrobeTipsView:DestroySuccess( )
  192. self.model.tip_view_show = false
  193. self:ClearHideTimer()
  194. if self.delay_closeview_id then
  195. TimerQuest.CancelQuest(GlobalTimerQuest,self.delay_closeview_id)
  196. self.delay_closeview_id = nil
  197. end
  198. if self.alpha_anim_id then
  199. TweenLite.Stop(self.alpha_anim_id)
  200. self.alpha_anim_id = nil
  201. end
  202. if self.pos_id then
  203. TweenLite.Stop(self.pos_id)
  204. self.pos_id = nil
  205. end
  206. if self.delay_id then
  207. GlobalTimerQuest:CancelQuest(self.delay_id)
  208. self.delay_id = nil
  209. end
  210. end