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

212 lines
6.5 KiB

  1. GiftPreviewView = GiftPreviewView or BaseClass(BaseView)
  2. local GiftPreviewView = GiftPreviewView
  3. --[[
  4. GiftPreviewView.TabData = {
  5. [1] = {name = "人物", level = MainRoleModel.TabOpenLevel[1]},
  6. }
  7. --]]
  8. function GiftPreviewView:__init()
  9. self.base_file = "gift"
  10. self.layout_file = "GiftPreviewView"
  11. self.layer_name = "Activity"
  12. self.destroy_imm = true
  13. self.use_background = true --全屏界面默认使用这个参数
  14. --self.hide_maincancas = true --全屏界面需要放开隐藏主UI
  15. self.change_scene_close = true
  16. self.append_to_ctl_queue = false --是否要添加进界面堆栈
  17. self.need_show_money = false --是否要显示顶部的金钱栏
  18. self.is_set_zdepth = true
  19. self.model = GiftModel:getInstance()
  20. self.blur_activity_bg = true
  21. self.click_bg_toClose = true
  22. self.reward_item_list = {}
  23. self.load_callback = function ()
  24. self:LoadSuccess()
  25. self:AddEvent()
  26. end
  27. self.open_callback = function ( )
  28. self:OpenSuccess()
  29. end
  30. self.switch_callback = function(index)
  31. self:SwitchTab(index)
  32. end
  33. self.destroy_callback = function ( )
  34. self:DestroySuccess()
  35. end
  36. end
  37. function GiftPreviewView:Open(data)
  38. self.data = data
  39. BaseView.Open(self)
  40. end
  41. function GiftPreviewView:LoadSuccess()
  42. local nodes = {
  43. "bg/tip_con/cost_image2:img", "bg/title",
  44. "bg/btn/discount_bg", "bg/btn/discount:tmp",
  45. "bg/tip_con/cur_text:tmp", "bg/tip_con/cost_image1:img", "bg/tip_con","bg/btn/btn_text:tmp",
  46. "bg/close_btn:obj", "bg:img", "bg/tip_con/origin_text:tmp", "bg/item_con", "bg/btn:obj:imgex", "bg/refuse_btn:obj",
  47. }
  48. self:GetChildren(nodes)
  49. self.btn_text_tmp.text = "优惠购买"
  50. end
  51. function GiftPreviewView:AddEvent()
  52. local function on_click( target )
  53. if target == self.btn_obj then
  54. if self.is_not_open then
  55. -- local str = string.format("开服第%s天开放购买哦~", self.data.start_day)
  56. local str = "该礼包明日开放购买哦~"
  57. Message.show(str, "fault")
  58. return
  59. else
  60. local function ok_callback( ... )
  61. GoodsModel:getInstance():Fire(GoodsModel.REQUEST_CCMD_EVENT, 15050, self.data.goods_id, self.data.type_id, 1)
  62. self:Close()
  63. end
  64. -- local function toggle_function( flag )
  65. -- self.model.gift_preview_toggle = flag
  66. -- end
  67. local function use_function( toggle_tip_data,call_fun_sum )
  68. -- if not self.model.gift_preview_toggle then
  69. -- GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
  70. -- else
  71. call_fun_sum()--不需要判断了 直接走
  72. -- end
  73. self:Close()
  74. end
  75. local function recharge_open_call_back( ... )
  76. self:Close()
  77. end
  78. local buy_tip_data = {
  79. gold_type = self.money_type,--货币类型
  80. cost_price = self.cur_cost,--消耗金额
  81. ok_callback = ok_callback,--成功
  82. toggle_function = toggle_function,--多选
  83. togglePriceStr = string.format("<color=#fdffc2>%s</color> 购买商品",self.cur_cost),--提示语
  84. use_function = use_function,--最终调用
  85. recharge_open_call_back = recharge_open_call_back,
  86. invest_call_back = recharge_open_call_back,
  87. }
  88. CustomActivityModel:getInstance():BuyTips(buy_tip_data)
  89. end
  90. elseif target == self.close_btn_obj then
  91. self:Close()
  92. elseif target == self.refuse_btn_obj then
  93. self:Close()
  94. end
  95. end
  96. AddClickEvent(self.btn_obj, on_click)
  97. AddClickEvent(self.close_btn_obj, on_click)
  98. AddClickEvent(self.refuse_btn_obj, on_click)
  99. local function on_close( ... )
  100. self:Close()
  101. end
  102. self:BindEvent(self.model, GiftModel.CLOSE_PREVIEW_VIEW, on_close)
  103. end
  104. function GiftPreviewView:OpenSuccess()
  105. self:UpdateView()
  106. end
  107. function GiftPreviewView:UpdateView()
  108. if GoodsModel:getInstance():IsPaidGift(self.data.type_id) then--付费礼包
  109. local data = self.data
  110. self.money_type = data.diamond_list.cost_type
  111. self.origin_cost = data.diamond_list.old_cost
  112. self.cur_cost = data.diamond_list.now_cost
  113. self.reward_list = data.fix_reward_list
  114. local open_day = ServerTimeModel:getInstance():GetOpenServerDay()
  115. self.is_not_open = false
  116. if data.start_day then
  117. if open_day < data.start_day then
  118. self.is_not_open = true
  119. end
  120. end
  121. if data.end_day then
  122. if open_day > data.end_day then
  123. self.is_not_open = true
  124. end
  125. end
  126. self.btn_imgex.gray = self.is_not_open
  127. if self.is_not_open then
  128. SetTMPSharedMaterial(self.btn_text_tmp,ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn)
  129. else
  130. SetTMPSharedMaterial(self.btn_text_tmp,ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkOrangeBtn)
  131. end
  132. self.origin_text_tmp.text = self.origin_cost
  133. self.cur_text_tmp.text = self.cur_cost
  134. self.discount_tmp.text = string.format("%s折",math.ceil(self.cur_cost/self.origin_cost*10))
  135. local len = TableSize(self.reward_list)
  136. local offset = 12
  137. local item_size = 114
  138. if len == 2 then
  139. offset = 40
  140. end
  141. --因为要居中对齐 所以从左边开始算起来
  142. local start_x = 0
  143. if len%2 == 0 then--如果是偶数个 那么居中的是空间
  144. local num = len/2
  145. for i=1,num do
  146. start_x = start_x - item_size - offset
  147. end
  148. start_x = start_x + offset/2
  149. else
  150. local num = math.floor(len/2)
  151. for i=1,num do
  152. start_x = start_x - item_size - offset
  153. end
  154. start_x = start_x - item_size/2
  155. end
  156. for i,v in ipairs(self.reward_list) do
  157. local item = self.reward_item_list[i]
  158. if not item then
  159. item = GiftPreviewItem.New(self.item_con)
  160. self.reward_item_list[i] = item
  161. end
  162. item:SetData(v)
  163. item:SetPosition((i-1)*(item_size + offset) + start_x, -10)
  164. end
  165. if len > 3 then
  166. local origin_width = 520
  167. local cur_width = (len - 3)*(item_size-10) + origin_width
  168. SetSizeDeltaX(self.bg, cur_width)
  169. -- SetSizeDeltaX(self.item_bg, cur_width-20)
  170. end
  171. else
  172. end
  173. if self.delay_id then
  174. GlobalTimerQuest:CancelQuest(self.delay_id)
  175. self.delay_id = nil
  176. end
  177. local function delay_method( )
  178. SetSizeDeltaX(self.origin_text, self.origin_text_tmp.preferredWidth+1)
  179. SetSizeDeltaX(self.cur_text, self.cur_text_tmp.preferredWidth+1)
  180. end
  181. self.delay_id = setTimeout(delay_method, 0.01)
  182. self:SetMoneyIcon()
  183. end
  184. -- 加载货币图标
  185. function GiftPreviewView:SetMoneyIcon()
  186. if not self.money_type then return end
  187. local asset, source = WordManager:GetCommonMoneyIcon(self.money_type)
  188. lua_resM:setImageSprite(self, self.cost_image2_img, asset, source)
  189. lua_resM:setImageSprite(self, self.cost_image1_img, asset, source)
  190. end
  191. function GiftPreviewView:SwitchTab( index )
  192. end
  193. function GiftPreviewView:DestroySuccess( )
  194. for i,v in ipairs(self.reward_item_list) do
  195. v:DeleteMe()
  196. v = nil
  197. end
  198. self.reward_item_list = {}
  199. if self.delay_id then
  200. GlobalTimerQuest:CancelQuest(self.delay_id)
  201. self.delay_id = nil
  202. end
  203. end