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

356 lines
15 KiB

  1. CurrencyWishView = CurrencyWishView or BaseClass(BaseView)
  2. local CurrencyWishView = CurrencyWishView
  3. function CurrencyWishView:__init()
  4. self.base_file = "currencyWish"
  5. self.layout_file = "CurrencyWishView"
  6. self.layer_name = "UI"
  7. self.destroy_imm = true
  8. self.use_background = G_USING_BG --全屏界面默认使用这个参数,非全屏界面自行设置
  9. self.hide_maincancas = true --全屏界面需要隐藏主UI
  10. --self.change_scene_close = true --是否切换场景时关闭(弹出界面使用)
  11. self.append_to_ctl_queue = false --是否要添加进界面堆栈
  12. self.need_show_money = true --是否要显示顶部的金钱栏
  13. self.close_fog = true
  14. self.model = CurrencyWishModel:getInstance()
  15. self.load_callback = function()
  16. self:LoadSuccess()
  17. self:AddEvent()
  18. end
  19. self.open_callback = function( )
  20. self:UpdateView()
  21. end
  22. self.switch_callback = function(index)
  23. -- self:SwitchTab(index)
  24. end
  25. self.destroy_callback = function ( )
  26. self:DestroySuccess()
  27. end
  28. end
  29. function CurrencyWishView:Open( )
  30. --self.data = data
  31. BaseView.Open(self)
  32. end
  33. function CurrencyWishView:LoadSuccess()
  34. local nodes = {
  35. "bg:img", "con_money",
  36. "normal_trade_currency_wish/normal_trade_btn:obj:img",
  37. "normal_trade_currency_wish/normal_trade_btn/normal_trade_btn_red:obj",
  38. "normal_trade_currency_wish/normal_trade_btn/normal_trade_btn_red_num:tmp", "normal_trade_currency_wish/normal_trade_desc:tmp",
  39. "normal_trade_currency_wish/normal_trade_bg:img",
  40. "normal_trade_currency_wish/normal_trade_icon:img",
  41. "normal_trade_currency_wish/normal_trade_reward_num:tmp", "normal_trade_currency_wish/normal_trade_count:tmp",
  42. "normal_trade_currency_wish/normal_trade_desc_2:tmp:obj",
  43. "special_trade_currency_wish/special_trade_bg:img", "special_trade_currency_wish/special_trade_icon:img",
  44. "special_trade_currency_wish/special_trade_reward_num:tmp", "special_trade_currency_wish/special_trade_count:tmp",
  45. "special_trade_currency_wish/special_trade_btn:img:obj",
  46. "special_trade_currency_wish/special_trade_btn/special_trade_btn_red:obj",
  47. "special_trade_currency_wish/special_trade_desc:tmp",
  48. "exp_currency_wish/exp_bg:img", "exp_currency_wish/exp_icon:img", "exp_currency_wish/exp_reward_num:tmp", "exp_currency_wish/exp_count:tmp",
  49. "exp_currency_wish/exp_btn:img:obj", "exp_currency_wish/exp_btn/exp_btn_red:obj", "exp_currency_wish/exp_btn/exp_num:tmp",
  50. "exp_currency_wish/exp_desc_1:tmp", "exp_currency_wish/exp_desc_2:tmp",
  51. "close_btn:obj",
  52. }
  53. self:GetChildren(nodes)
  54. lua_resM:setOutsideImageSprite(self, self.bg_img, GameResPath.GetViewBigBg("currency_wish_bg"), false)
  55. lua_resM:setImageSprite(self, self.normal_trade_bg_img, "currencyWish_asset", "currency_wish_normal_trade_bg", false)
  56. lua_resM:setImageSprite(self, self.normal_trade_icon_img, "currencyWish_asset", "currency_wish_normal_trade_icon", false)
  57. lua_resM:setImageSprite(self, self.normal_trade_btn_img, "currencyWish_asset", "currency_wish_all_btn_bg", false)
  58. lua_resM:setImageSprite(self, self.special_trade_bg_img, "currencyWish_asset", "currency_wish_special_trade_bg", false)
  59. lua_resM:setImageSprite(self, self.special_trade_icon_img, "currencyWish_asset", "currency_wish_special_trade_icon", false)
  60. lua_resM:setImageSprite(self, self.special_trade_btn_img, "currencyWish_asset", "currency_wish_free_btn_bg", false)
  61. lua_resM:setImageSprite(self, self.exp_bg_img, "currencyWish_asset", "currency_wish_exp_bg", false)
  62. lua_resM:setImageSprite(self, self.exp_icon_img, "currencyWish_asset", "currency_wish_exp_icon", false)
  63. lua_resM:setImageSprite(self, self.exp_btn_img, "currencyWish_asset", "currency_wish_special_btn_bg", false)
  64. self["icon_" .. 1] = self.normal_trade_icon
  65. self["icon_" .. 2] = self.special_trade_icon
  66. self["icon_" .. 3] = self.exp_icon
  67. if not self.money_view then
  68. self.money_view = UIMoneyView.New(self.con_money)
  69. self.money_view:SetPosition(-50,0)
  70. self.money_view:SetData()
  71. self.money_view:ChangeShowFlag("actWindow")
  72. end
  73. -- 补一个请求
  74. if not self.model:GetBaseInfo() then
  75. self.model:Fire(CurrencyWishConst.REQ_CURRENCY_WISH_INFO)
  76. end
  77. if self.need_refresh_view then
  78. self.need_refresh_view = false
  79. self:UpdateView()
  80. end
  81. end
  82. function CurrencyWishView:AddEvent()
  83. local function click_event(target)
  84. if target == self.close_btn_obj then
  85. self:Close()
  86. elseif target == self.normal_trade_btn_obj then
  87. self:TryDoCurrencyWish(CurrencyWishConst.CURRENCY_WISH_TYPE.NORMAL)
  88. elseif target == self.special_trade_btn_obj then
  89. self:TryDoCurrencyWish(CurrencyWishConst.CURRENCY_WISH_TYPE.SPECIAL)
  90. elseif target == self.exp_btn_obj then
  91. self:TryDoCurrencyWish(CurrencyWishConst.CURRENCY_WISH_TYPE.EXP)
  92. elseif target == self.normal_trade_desc_2_obj then
  93. UIToolTipMgr:getInstance():AppendGoodsTips(BagModel.StampGoodsId,nil,nil,nil,nil,nil,nil,true)
  94. end
  95. end
  96. AddClickEvent(self.close_btn_obj, click_event)
  97. AddClickEvent(self.normal_trade_btn_obj, click_event)
  98. AddClickEvent(self.special_trade_btn_obj, click_event)
  99. AddClickEvent(self.exp_btn_obj, click_event)
  100. AddClickEvent(self.normal_trade_desc_2_obj, click_event)
  101. local function on_ans_base_info()
  102. self:UpdateView()
  103. end
  104. self:BindEvent(self.model, CurrencyWishConst.ANS_CURRENCY_WISH_INFO, on_ans_base_info)
  105. local function on_update_view()
  106. self:UpdateView()
  107. end
  108. self:BindEvent(self.model, CurrencyWishConst.UPDATE_CURRENCY_WISH_VIEW, on_update_view)
  109. local function on_update_currency_wish_cd_time(cd_time)
  110. if cd_time <= 0 then
  111. self.special_trade_desc_tmp.text = ""
  112. else
  113. local cd_time_str = string.format("<color=%s>%s</color> 后免费", ColorUtil.GREEN_TIPS, TimeUtil:timeConvert4(cd_time))
  114. self.special_trade_desc_tmp.text = cd_time_str
  115. end
  116. end
  117. self:BindEvent(self.model, CurrencyWishConst.UPDATE_CURRENCY_WISH_CD_TIME, on_update_currency_wish_cd_time)
  118. end
  119. function CurrencyWishView:TryDoCurrencyWish(type)
  120. local ok_callback = function ()
  121. self.model:Fire(CurrencyWishConst.REQ_DO_CURRENCY_WISH, type)
  122. end
  123. local base_info = self.model:GetBaseInfo()
  124. --- 冷却时直接向服务端请求 让服务端返回错误码
  125. if type == CurrencyWishConst.CURRENCY_WISH_TYPE.NORMAL then -- 交易券消耗背包道具
  126. local stamp_goods_num = GoodsModel:getInstance():GetTypeGoodsNum(BagModel.StampGoodsId) --已有的交易券数量
  127. if stamp_goods_num < 1 then
  128. Message.show("物品不足")
  129. else
  130. ok_callback()
  131. end
  132. return
  133. elseif type == CurrencyWishConst.CURRENCY_WISH_TYPE.SPECIAL then
  134. if (base_info.luxurycool and base_info.luxurycool <= 0)
  135. or base_info.luxury_rest_times <= 0 then
  136. ok_callback()
  137. return
  138. end
  139. elseif type == CurrencyWishConst.CURRENCY_WISH_TYPE.EXP then
  140. if base_info.expr_rest_times <= 0 then
  141. ok_callback()
  142. return
  143. end
  144. end
  145. local cancel_callback = function ()
  146. end
  147. local toggle_function = function ()
  148. self.model.currency_wish_without_confirm = true
  149. end
  150. -- local cost_info = self.model:GetInoriCostInfo(type)
  151. local wish_cfg = self.model:GetCurrencyWishConfigOne(type)
  152. local cost_info = stringtotable(wish_cfg.consume)[1]
  153. local cost_type = cost_info[1]
  154. local cost_num = cost_info[3]
  155. local jin = RoleManager.Instance.mainRoleInfo.jin
  156. local jinLock = RoleManager.Instance.mainRoleInfo.jinLock
  157. local toggle_tip_data = {
  158. insufficientText = "",
  159. titleText = "提示",
  160. nameText = "是否花费 ",
  161. priceText = string.format("%s 进行祈愿", HtmlColorTxt(cost_num, "#fdffc2")),
  162. okText = "确认",
  163. cancelText = "取消",
  164. toggleText = " 本次登录不再提示",--8字符
  165. ok_callback = ok_callback,
  166. close_callback = cancel_callback,
  167. toggle_function = toggle_function,
  168. is_complex_ok_callback = false,
  169. gold_res = "ui_momey_icon_" .. cost_type,
  170. price = cost_num, -- config
  171. }
  172. if not self.model.currency_wish_without_confirm then
  173. GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
  174. else
  175. if cost_type == 1 and jin < cost_num then
  176. GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
  177. return
  178. end
  179. if cost_type == 2 and jin + jinLock < cost_num then
  180. GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
  181. return
  182. end
  183. ok_callback()
  184. end
  185. end
  186. function CurrencyWishView:UpdateView()
  187. if not self.is_loaded then
  188. self.need_refresh_view = true
  189. return
  190. end
  191. self.base_info = self.model:GetBaseInfo()
  192. if not self.base_info then
  193. return
  194. end
  195. local special_currency_wish_times = string.format("今日剩余:<color=%s>%d次</color>",
  196. self.base_info.luxury_rest_times > 0 and ColorUtil.GREEN_TIPS or ColorUtil.RED_DARK, self.base_info.luxury_rest_times)
  197. local exp_currency_wish_times = string.format("今日剩余:<color=%s>%d次</color>",
  198. self.base_info.expr_rest_times > 0 and ColorUtil.GREEN_TIPS or ColorUtil.RED_DARK, self.base_info.expr_rest_times)
  199. self.special_trade_count_tmp.text = special_currency_wish_times
  200. self.exp_count_tmp.text = exp_currency_wish_times
  201. local normal_wish_cfg = self.model:GetCurrencyWishConfigOne(CurrencyWishConst.CURRENCY_WISH_TYPE.NORMAL)
  202. local special_wish_cfg = self.model:GetCurrencyWishConfigOne(CurrencyWishConst.CURRENCY_WISH_TYPE.SPECIAL)
  203. local exp_wish_cfg = self.model:GetCurrencyWishConfigOne(CurrencyWishConst.CURRENCY_WISH_TYPE.EXP)
  204. local normal_num = stringtotable(normal_wish_cfg.base_produce)[1][3]
  205. local special_num = stringtotable(special_wish_cfg.base_produce)[1][3]
  206. local exp_num = stringtotable(exp_wish_cfg.base_produce)[1][3]
  207. -- print("Lizhijian:CurrencyWishView [start:251] ")
  208. -- print(normal_num, special_num, exp_num)
  209. -- print("Lizhijian:CurrencyWishView [end:251] ")
  210. self.normal_trade_reward_num_tmp.text = normal_num
  211. self.special_trade_reward_num_tmp.text = special_num
  212. self.exp_reward_num_tmp.text = exp_num
  213. if self.base_info.luxurycool <= 0 then
  214. self.special_trade_desc_tmp.text = ""
  215. self.special_trade_btn_red_obj:SetActive(true)
  216. else
  217. self.special_trade_btn_red_obj:SetActive(false)
  218. local cd_time_str = string.format("<color=%s>%s</color> 后免费", ColorUtil.GREEN_TIPS, TimeUtil:timeConvert4(self.base_info.luxurycool))
  219. self.special_trade_desc_tmp.text = cd_time_str
  220. end
  221. lua_resM:setImageSprite(self, self.normal_trade_btn_img, "currencyWish_asset", "currency_wish_all_btn_bg", false)
  222. lua_resM:setImageSprite(self, self.special_trade_btn_img, "currencyWish_asset", self.base_info.luxurycool <= 0 and "currency_wish_free_btn_bg" or "currency_wish_special_btn_bg", false)
  223. lua_resM:setImageSprite(self, self.exp_btn_img, "currencyWish_asset", "currency_wish_special_btn_bg", false)
  224. local stamp_goods_num = GoodsModel:getInstance():GetTypeGoodsNum(BagModel.StampGoodsId) --已有的交易券数量
  225. stamp_goods_num = Mathf.Clamp(stamp_goods_num, 0, 999)
  226. if stamp_goods_num > 99 then
  227. SetSizeDelta(self.normal_trade_btn_red, 36, 36)
  228. else
  229. SetSizeDelta(self.normal_trade_btn_red, 32, 32)
  230. end
  231. self.normal_trade_btn_red_obj:SetActive(stamp_goods_num ~= 0)
  232. self.normal_trade_btn_red_num_tmp.text = stamp_goods_num ~= 0 and stamp_goods_num or ""
  233. self.normal_trade_desc_2_tmp.text = string.format("祈愿消耗:<color=%s>10交易券卡</color>", ColorUtil.PURPLE_DARK)
  234. local role_lv = RoleManager.Instance.mainRoleInfo.level
  235. self.exp_desc_1_tmp.text = string.format("等级提升%s级", role_lv)
  236. -- 递归计算能升多少级
  237. local add_lv = 0
  238. local total_lv = TableSize(Config.Exp)
  239. local cur_exp = RoleManager.Instance.mainRoleInfo.exp
  240. local add_exp = exp_num
  241. local res_lv = role_lv
  242. local function cul_addlv_and_percentage(exp)
  243. if Config.Exp[role_lv + add_lv] and exp > Config.Exp[role_lv + add_lv].exp then
  244. exp = exp - Config.Exp[role_lv + add_lv].exp
  245. add_lv = add_lv + 1
  246. cul_addlv_and_percentage(exp)
  247. else
  248. -- 等级容错
  249. res_lv = role_lv + add_lv < total_lv and role_lv + add_lv or total_lv
  250. end
  251. end
  252. cul_addlv_and_percentage(cur_exp + add_exp)
  253. self.exp_desc_2_tmp.text = string.format("<color=%s>%s</color>级", ColorUtil.GREEN_TIPS, res_lv)
  254. self:DoAction()
  255. end
  256. function CurrencyWishView:DoAction()
  257. if self.is_action then
  258. return
  259. end
  260. self.is_action = true
  261. for i = 1, 3 do
  262. local icon = self["icon_" .. i]
  263. cc.ActionManager:getInstance():removeAllActionsFromTarget(icon)
  264. --action 1
  265. local pos_x, pos_y = GetAnchoredPosition(icon)
  266. local offset = 10
  267. local anim_time = 1
  268. local function moveUp1(percent)
  269. SetAnchoredPositionY(icon, pos_y + offset * percent)
  270. end
  271. local flowUp1 = cc.CustomUpdate.New(anim_time, moveUp1)
  272. -- local flowUp1 = cc.CustomUpdate.New(anim_time, moveUp1)
  273. local function moveDown(percent)
  274. SetAnchoredPositionY(icon, pos_y + offset - 2 * offset * percent)
  275. end
  276. local flowDown = cc.CustomUpdate.New(anim_time * 2, moveDown)
  277. -- local flowDown = cc.CustomUpdate.New(anim_time * 2, moveDown)
  278. local function moveUp2(percent)
  279. SetAnchoredPositionY(icon, pos_y - offset + offset * percent)
  280. end
  281. local flowUp2 = cc.CustomUpdate.New(anim_time, moveUp2)
  282. -- local flowUp2 = cc.CustomUpdate.New(anim_time, moveUp2)
  283. local action = cc.RepeatForever.New(cc.Sequence.New(flowUp1, flowDown, flowUp2))
  284. -- local final_action = cc.Sequence.New(cc.DelayTime.New(i * 0.1), action)
  285. local final_action = action
  286. local function delay_method()
  287. cc.ActionManager:getInstance():addAction(final_action, icon)
  288. end
  289. self.delay_method_id = setTimeout(delay_method, (i - 1) * 0.3)
  290. end
  291. end
  292. function CurrencyWishView:DestroySuccess()
  293. end
  294. function CurrencyWishView:__delete()
  295. for i = 1, 3 do
  296. local icon = self["icon_" .. i]
  297. cc.ActionManager:getInstance():removeAllActionsFromTarget(icon)
  298. icon = nil
  299. end
  300. if self.money_view then
  301. self.money_view:DeleteMe()
  302. self.money_view = nil
  303. end
  304. end