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

345 行
13 KiB

  1. CurrencyExchangeView = CurrencyExchangeView or BaseClass(BaseView)
  2. local CurrencyExchangeView = CurrencyExchangeView
  3. function CurrencyExchangeView:__init()
  4. self.base_file = "bag"
  5. self.layout_file = "CurrencyExchangeView"
  6. self.layer_name = "Activity"
  7. self.destroy_imm = true
  8. self.use_background = true
  9. self.change_scene_close = true
  10. self.hide_maincancas = true --是否隐藏主界面
  11. self.append_to_ctl_queue = false --是否要添加进界面堆栈
  12. self.need_show_money = false --是否要显示顶部的金钱栏
  13. self.click_bg_toClose = false
  14. self.is_set_zdepth = true
  15. self.blur_activity_bg = true
  16. -- self.use_show_anim = true
  17. -- self.use_hide_anim = true
  18. self.jump_close = true
  19. self.model = BagModel:getInstance()
  20. self.stamp_exchange_num = 10 -- 一张交易卡券能兑换的交易券数量
  21. self.diamond_expend_num = 40 -- 使用彩钻兑换一次交易券需要消耗的彩钻数
  22. self.diamond_exchange_can_get_num = self.diamond_expend_num*15 -- 使用彩钻兑换一次能获得的交易券数量
  23. self.diamond_free_exchange_num = 0 --彩钻石免费兑换次数
  24. self.load_callback = function ()
  25. self:LoadSuccess()
  26. self:AddEvent()
  27. self.model.update_all_currency_exchange_view = true
  28. self.model:Fire(BagModel.REQUEST_PROTOCOL,15026) --彩钻兑换交易券次数情况
  29. end
  30. self.open_callback = function ( )
  31. -- self:OpenSuccess()
  32. end
  33. self.close_win_callback = function ( )
  34. self:Close()
  35. end
  36. self.destroy_callback = function ( )
  37. self:DestroySuccess()
  38. end
  39. end
  40. function CurrencyExchangeView:Open()
  41. BaseView.Open(self)
  42. end
  43. function CurrencyExchangeView:LoadSuccess()
  44. local nodes = {
  45. "bg:raw", --背景
  46. "money_icon_1:img", "money_icon_2:img", --货币图标
  47. "props_award_con",
  48. "goVipBtn:obj", --跳转按钮
  49. "diamond_left_num:tmp",
  50. "close_btn:obj", --关闭按钮
  51. "diamond_free_time_label:tmp", --免费兑换文本
  52. "propsExchangeBtn:obj", "diamondExchangeBtn:obj", --兑换按钮
  53. "diamondExchangeBtn/diamondExchangeText:tmp", --彩钻兑换按钮文字
  54. "diamondExchangeBtn/diamondExchangeLabelCon:obj", --彩钻兑换花费栏
  55. "propsExchangeBtn/propsRed:obj", "diamondExchangeBtn/diamondRed:obj", --兑换按钮红点
  56. "moneyCon",
  57. "money_icon_1/can_get_money_1:txt",
  58. "life_skill_critical_label:tmp",
  59. }
  60. self:GetChildren(nodes)
  61. -- self.money_view = UIMoneyView.New(self.moneyCon)
  62. -- self.money_view:SetPosition(0,0)
  63. -- self.money_view:SetData()
  64. lua_resM:setOutsideRawImage(self,self.bg_raw,GameResPath.GetViewBigBg("currency_exchange_bg"))
  65. self.props_award = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.props_award_con)
  66. self.props_award:SetItemSize(78, 78)
  67. self.props_award:SetData(BagModel.StampGoodsId)
  68. local goods_num = GoodsModel:getInstance():GetTypeGoodsNum(101014)
  69. local get_str = HtmlColorTxt(goods_num, goods_num < 1 and ColorUtil.RED_DARK or ColorUtil.GREEN_TIPS).."/".. 1
  70. self.props_award:IsGetGoods(true,get_str,false)
  71. if self.need_refresh_view then
  72. self:UpdateView()
  73. end
  74. end
  75. function CurrencyExchangeView:AddEvent()
  76. local on_click = function ( click_obj )
  77. if self.goVipBtn_obj == click_obj then --跳转vip
  78. self:Close()
  79. OpenFun.Open(450,2)
  80. elseif self.close_btn_obj == click_obj then
  81. self:Close()
  82. elseif self.propsExchangeBtn_obj == click_obj then--使用道具兑换
  83. self:DoExchange(1)
  84. elseif self.diamondExchangeBtn_obj == click_obj then--使用彩钻兑换
  85. self:DoExchange(2)
  86. end
  87. end
  88. AddClickEvent(self.goVipBtn_obj, on_click)
  89. AddClickEvent(self.close_btn_obj, on_click)
  90. AddClickEvent(self.propsExchangeBtn_obj, on_click)
  91. AddClickEvent(self.diamondExchangeBtn_obj, on_click)
  92. local function Update_currency_view()
  93. if self.is_loaded then
  94. self:UpdateDiamondExchange()
  95. self:UpdatePropsExchange()
  96. end
  97. end
  98. self:BindEvent(self.model, BagModel.UPDATE_CURRENCY_EXCHANGE_VIEW,Update_currency_view)
  99. --货币礼包数量更新时,也要刷新界面
  100. local function on_update_currency_goods_num()
  101. if self.is_loaded then
  102. self:UpdatePropsExchange()
  103. end
  104. end
  105. self.model:Bind(BagModel.UPDATE_CURRENCY_GOODS_NUM,on_update_currency_goods_num)
  106. --刷新交易券兑换
  107. local function update_currency_exchange_red()
  108. self:SetCurrencyExchangeRed()
  109. end
  110. self:BindEvent(self.model,BagModel.ANS_UPDATE_CURRENCY_EXCHANGE_RED,update_currency_exchange_red)
  111. self:BindEvent(GlobalEventSystem,EventName.UPDATE_BAG_RED,update_currency_exchange_red)
  112. update_currency_exchange_red()
  113. --打开界面时请求15026,并刷新界面
  114. local function on_update_view()
  115. if self.is_loaded then
  116. self.need_refresh_view = false
  117. self:UpdateView()
  118. else
  119. self.need_refresh_view = true
  120. end
  121. end
  122. self.model:Bind(BagModel.UPDATE_CURRENCY_VIEW,on_update_view)
  123. end
  124. function CurrencyExchangeView:SetCurrencyExchangeRed( )
  125. local bool = self.model:GetCurrencyExchangeRed()
  126. local props_red = self.model:GetCurrencyExchangePropsRed()
  127. local diamond_red = self.model:GetCurrencyExchangeDiamondRed()
  128. self.propsRed_obj:SetActive(props_red)
  129. self.diamondRed_obj:SetActive(diamond_red)
  130. end
  131. function CurrencyExchangeView:DoExchange(exchange_type)
  132. if exchange_type == 1 then--使用道具兑换
  133. local props_times = GoodsModel:getInstance():GetTypeGoodsNum(BagModel.StampGoodsId) --已有的交易券数量
  134. if props_times == 0 then
  135. Message.show("数量不足","fault")
  136. else
  137. self.model:Fire(BagModel.REQUEST_PROTOCOL,15022,0,props_times)
  138. lua_soundM:PlayEffect(self, "success",false,LuaSoundManager.SOUND_TYPE.UI)
  139. end
  140. elseif exchange_type == 2 then--使用彩钻兑换
  141. if self.exchange_btn_state == 2 then
  142. self:Close()
  143. OpenFun.Open(450,2)
  144. return
  145. end
  146. local free_time = self.model.currency_exchange_free_time
  147. local diamond_times = self.model:GetCurrencyExchangeNumsNow() --剩余的使用彩钻兑换次数
  148. local is_free = free_time and free_time ~= 0 and free_time <= TimeUtil:getServerTime()
  149. local diamond_exchange_times = is_free and 1 or diamond_times
  150. if diamond_exchange_times == 0 then
  151. Message.show("剩余兑换次数不足","fault")
  152. else
  153. local function ok_callback( ... )
  154. self.model:Fire(BagModel.REQUEST_PROTOCOL,15022,1,0)
  155. lua_soundM:PlayEffect(self, "success",false,LuaSoundManager.SOUND_TYPE.UI)
  156. end
  157. local function toggle_function( flag )
  158. self.model._diamond_exchange_no_double_check = flag
  159. end
  160. local function use_function( toggle_tip_data,call_fun_sum )
  161. if not self.model._diamond_exchange_no_double_check and self.diamond_expend_num ~= 0 then
  162. GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
  163. else
  164. call_fun_sum()
  165. end
  166. end
  167. local buy_tip_data = {
  168. gold_type = 1,--货币类型
  169. cost_price = self.diamond_expend_num,--消耗金额
  170. ok_callback = ok_callback,--成功
  171. toggle_function = toggle_function,--多选
  172. togglePriceStr = string.format("<color=#fdffc2>%s</color> 进行兑换",self.diamond_expend_num),--提示语
  173. use_function = use_function,--最终调用
  174. }
  175. if is_free then
  176. ok_callback()
  177. else
  178. CustomActivityModel:getInstance():BuyTips(buy_tip_data)
  179. end
  180. end
  181. end
  182. end
  183. function CurrencyExchangeView:OpenSuccess()
  184. self:UpdateView()
  185. end
  186. function CurrencyExchangeView:UpdateView( )
  187. self:UpdatePropsExchange()
  188. self:UpdateDiamondExchange()
  189. --宠物生活技能 彩钻兑换交易券有概率暴击,收益翻倍
  190. local life_skill_active = PetModel:getInstance():IsLifeSkillActived(PetConst.LifeSkill.CurrencyExchangeCritical)
  191. local life_skill_ratio = PetModel:getInstance():GetPetLifeSkillRatio(PetConst.LifeSkill.CurrencyExchangeCritical)
  192. if life_skill_active then
  193. self.life_skill_critical_label_tmp.text = string.format("<color=#2CF86F>%s%%概率双倍</color>",life_skill_ratio)
  194. else
  195. self.life_skill_critical_label_tmp.text = ""
  196. end
  197. end
  198. --刷新道具兑换相关界面变化
  199. function CurrencyExchangeView:UpdatePropsExchange( )
  200. if not self.is_loaded then return end
  201. local stamp_goods_num = GoodsModel:getInstance():GetTypeGoodsNum(BagModel.StampGoodsId) --已有的交易券数量
  202. local free_time = self.model.currency_exchange_free_time
  203. self.diamond_free_exchange_num = (free_time and free_time ~= 0 and free_time <= TimeUtil:getServerTime()) and 1 or 0
  204. -- local show_props_num = stamp_goods_num > 0 and stamp_goods_num or 1
  205. -- self.props_left_num_2_tmp.text = show_props_num
  206. -- self.can_get_num_1_tmp.text = "x"..self.stamp_exchange_num
  207. -- local num_color_str = stamp_goods_num > 0 and ColorUtil.GREEN_TIPS or ColorUtil.RED_DARK
  208. -- self.props_left_num_tmp.text = string.format("总共可获得 <color=%s>%s</color>",num_color_str,stamp_goods_num*self.stamp_exchange_num)
  209. -- SetAnchoredPositionX(self.money_icon_3,450 + self.props_left_num_tmp.preferredWidth/2 + 18)
  210. if stamp_goods_num > 0 then
  211. self.can_get_money_1_txt.text = stamp_goods_num*self.stamp_exchange_num
  212. else
  213. self.can_get_money_1_txt.text = self.stamp_exchange_num
  214. end
  215. local goods_num = GoodsModel:getInstance():GetTypeGoodsNum(101014)
  216. local get_str = HtmlColorTxt(goods_num, goods_num < 1 and ColorUtil.RED_DARK or ColorUtil.GREEN_TIPS).."/".. 1
  217. self.props_award:IsGetGoods(true,get_str,false)
  218. end
  219. --刷新彩钻兑换相关界面变化
  220. function CurrencyExchangeView:UpdateDiamondExchange()
  221. local left_exchange_times = self.model:GetCurrencyExchangeNumsNow() --剩余的使用彩钻兑换次数
  222. local free_time = self.model.currency_exchange_free_time
  223. self.diamond_free_exchange_num = (free_time and free_time ~= 0 and free_time <= TimeUtil:getServerTime()) and 1 or 0
  224. if self.diamond_free_exchange_num > 0 then--有免费
  225. self.diamondExchangeLabelCon_obj:SetActive(false)
  226. self.diamondExchangeText_tmp.text = "免费兑换"
  227. self.exchange_btn_state = 1
  228. self.diamond_left_num_tmp.text = string.format("<color=%s>本次免费</color>",ColorUtil.GREEN_TIPS)
  229. else
  230. local my_vip_flag = RoleManager.Instance.mainRoleInfo.vip_flag
  231. local max_privilege_vip = self.model:GetCurreccyExchangeMaxVip()
  232. if left_exchange_times > 0 or my_vip_flag >= max_privilege_vip then--有次数或者已经达到了最高权限的vip
  233. self.diamondExchangeLabelCon_obj:SetActive(true)
  234. self.diamondExchangeText_tmp.text = ""
  235. self.exchange_btn_state = 1
  236. local num_color_str = left_exchange_times > 0 and ColorUtil.GREEN_TIPS or ColorUtil.RED_DARK
  237. self.diamond_left_num_tmp.text = string.format("今日可兑换次数: <color=%s>%s</color>",num_color_str,left_exchange_times)
  238. else--没次数且没达到最高权限vip,提示去提升vip
  239. self.diamondExchangeLabelCon_obj:SetActive(false)
  240. self.diamondExchangeText_tmp.text = "提升VIP"
  241. self.exchange_btn_state = 2
  242. self:UpdateVipTips()
  243. end
  244. end
  245. -- self.can_get_num_2_tmp.text = "x"..self.diamond_exchange_can_get_num
  246. self:UpdateFreeExchangeTime()
  247. end
  248. --升vip的提示tips
  249. function CurrencyExchangeView:UpdateVipTips( )
  250. local my_vip_flag = RoleManager.Instance.mainRoleInfo.vip_flag
  251. local next_vip_flag = my_vip_flag+1
  252. local max_privilege_vip = self.model:GetCurreccyExchangeMaxVip()
  253. if my_vip_flag >= max_privilege_vip then--已经是最高权限vip
  254. self.diamond_left_num_tmp.text = string.format("今日可兑换次数: <color=%s>0</color>",ColorUtil.RED_DARK)
  255. else
  256. local now_max_exchange_times = self.model:GetCurrencyExchangeNumsByVip()
  257. local next_max_exchange_times = self.model:GetCurrencyVipPrivilege(next_vip_flag) and self.model:GetCurrencyVipPrivilege(next_vip_flag).value or 0
  258. local up_exchange_times = next_max_exchange_times-now_max_exchange_times
  259. self.diamond_left_num_tmp.text = string.format("<color=%s>VIP%d</color> 可增加 <color=%s>%d</color> 次彩钻兑换",ColorUtil.GREEN_TIPS,next_vip_flag,ColorUtil.GREEN_TIPS,up_exchange_times)
  260. end
  261. end
  262. function CurrencyExchangeView:DestroySuccess( )
  263. if self.props_award then
  264. UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, self.props_award)
  265. self.props_award = nil
  266. end
  267. self:StopFreeTimer()
  268. if self.money_view then
  269. self.money_view:DeleteMe()
  270. self.money_view = nil
  271. end
  272. end
  273. function CurrencyExchangeView:UpdateFreeExchangeTime()
  274. local free_time = self.model.currency_exchange_free_time
  275. local function timer_func()
  276. local time = free_time - TimeUtil:getServerTime()
  277. local color = ColorUtil.GREEN_TIPS
  278. if time <= 0 then
  279. self.diamond_free_exchange_num = 1
  280. self.diamond_free_time_label_tmp.text = string.format("可免费兑换%s次", HtmlColorTxt(1 , color))
  281. self:StopFreeTimer()
  282. else
  283. local time_color = ColorUtil.GREEN_TIPS
  284. local time_str = TimeUtil:timeConvert17(time)
  285. self.diamond_free_time_label_tmp.text = string.format("<color=%s>%s</color> 后可免费兑换%s次", "#ffffff", time_str, HtmlColorTxt(1 , color))
  286. end
  287. end
  288. if not self.free_timer then
  289. self.free_timer = GlobalTimerQuest:AddPeriodQuest(timer_func, 1)
  290. end
  291. timer_func()
  292. end
  293. function CurrencyExchangeView:StopFreeTimer( )
  294. if self.free_timer then
  295. GlobalTimerQuest:CancelQuest(self.free_timer)
  296. self.free_timer = nil
  297. end
  298. end