|
|
- CurrencyWishView = CurrencyWishView or BaseClass(BaseView)
- local CurrencyWishView = CurrencyWishView
-
- function CurrencyWishView:__init()
- self.base_file = "currencyWish"
- self.layout_file = "CurrencyWishView"
- self.layer_name = "UI"
- self.destroy_imm = true
- self.use_background = G_USING_BG --全屏界面默认使用这个参数,非全屏界面自行设置
- self.hide_maincancas = true --全屏界面需要隐藏主UI
- --self.change_scene_close = true --是否切换场景时关闭(弹出界面使用)
- self.append_to_ctl_queue = false --是否要添加进界面堆栈
- self.need_show_money = true --是否要显示顶部的金钱栏
- self.close_fog = true
-
- self.model = CurrencyWishModel:getInstance()
-
- self.load_callback = function()
- self:LoadSuccess()
- self:AddEvent()
- end
- self.open_callback = function( )
- self:UpdateView()
- end
- self.switch_callback = function(index)
- -- self:SwitchTab(index)
- end
- self.destroy_callback = function ( )
- self:DestroySuccess()
- end
- end
-
- function CurrencyWishView:Open( )
- --self.data = data
- BaseView.Open(self)
- end
-
- function CurrencyWishView:LoadSuccess()
- local nodes = {
- "bg:img", "con_money",
-
- "normal_trade_currency_wish/normal_trade_btn:obj:img",
- "normal_trade_currency_wish/normal_trade_btn/normal_trade_btn_red:obj",
- "normal_trade_currency_wish/normal_trade_btn/normal_trade_btn_red_num:tmp", "normal_trade_currency_wish/normal_trade_desc:tmp",
- "normal_trade_currency_wish/normal_trade_bg:img",
- "normal_trade_currency_wish/normal_trade_icon:img",
- "normal_trade_currency_wish/normal_trade_reward_num:tmp", "normal_trade_currency_wish/normal_trade_count:tmp",
- "normal_trade_currency_wish/normal_trade_desc_2:tmp:obj",
-
- "special_trade_currency_wish/special_trade_bg:img", "special_trade_currency_wish/special_trade_icon:img",
- "special_trade_currency_wish/special_trade_reward_num:tmp", "special_trade_currency_wish/special_trade_count:tmp",
- "special_trade_currency_wish/special_trade_btn:img:obj",
- "special_trade_currency_wish/special_trade_btn/special_trade_btn_red:obj",
- "special_trade_currency_wish/special_trade_desc:tmp",
-
- "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",
- "exp_currency_wish/exp_btn:img:obj", "exp_currency_wish/exp_btn/exp_btn_red:obj", "exp_currency_wish/exp_btn/exp_num:tmp",
- "exp_currency_wish/exp_desc_1:tmp", "exp_currency_wish/exp_desc_2:tmp",
-
- "close_btn:obj",
- }
- self:GetChildren(nodes)
-
- lua_resM:setOutsideImageSprite(self, self.bg_img, GameResPath.GetViewBigBg("currency_wish_bg"), false)
-
- lua_resM:setImageSprite(self, self.normal_trade_bg_img, "currencyWish_asset", "currency_wish_normal_trade_bg", false)
- lua_resM:setImageSprite(self, self.normal_trade_icon_img, "currencyWish_asset", "currency_wish_normal_trade_icon", false)
- lua_resM:setImageSprite(self, self.normal_trade_btn_img, "currencyWish_asset", "currency_wish_all_btn_bg", false)
-
- lua_resM:setImageSprite(self, self.special_trade_bg_img, "currencyWish_asset", "currency_wish_special_trade_bg", false)
- lua_resM:setImageSprite(self, self.special_trade_icon_img, "currencyWish_asset", "currency_wish_special_trade_icon", false)
- lua_resM:setImageSprite(self, self.special_trade_btn_img, "currencyWish_asset", "currency_wish_free_btn_bg", false)
-
- lua_resM:setImageSprite(self, self.exp_bg_img, "currencyWish_asset", "currency_wish_exp_bg", false)
- lua_resM:setImageSprite(self, self.exp_icon_img, "currencyWish_asset", "currency_wish_exp_icon", false)
- lua_resM:setImageSprite(self, self.exp_btn_img, "currencyWish_asset", "currency_wish_special_btn_bg", false)
-
- self["icon_" .. 1] = self.normal_trade_icon
- self["icon_" .. 2] = self.special_trade_icon
- self["icon_" .. 3] = self.exp_icon
-
- if not self.money_view then
- self.money_view = UIMoneyView.New(self.con_money)
- self.money_view:SetPosition(-50,0)
- self.money_view:SetData()
- self.money_view:ChangeShowFlag("actWindow")
- end
-
- -- 补一个请求
- if not self.model:GetBaseInfo() then
- self.model:Fire(CurrencyWishConst.REQ_CURRENCY_WISH_INFO)
- end
- if self.need_refresh_view then
- self.need_refresh_view = false
- self:UpdateView()
- end
- end
-
- function CurrencyWishView:AddEvent()
- local function click_event(target)
- if target == self.close_btn_obj then
- self:Close()
- elseif target == self.normal_trade_btn_obj then
- self:TryDoCurrencyWish(CurrencyWishConst.CURRENCY_WISH_TYPE.NORMAL)
- elseif target == self.special_trade_btn_obj then
- self:TryDoCurrencyWish(CurrencyWishConst.CURRENCY_WISH_TYPE.SPECIAL)
- elseif target == self.exp_btn_obj then
- self:TryDoCurrencyWish(CurrencyWishConst.CURRENCY_WISH_TYPE.EXP)
- elseif target == self.normal_trade_desc_2_obj then
- UIToolTipMgr:getInstance():AppendGoodsTips(BagModel.StampGoodsId,nil,nil,nil,nil,nil,nil,true)
- end
- end
- AddClickEvent(self.close_btn_obj, click_event)
- AddClickEvent(self.normal_trade_btn_obj, click_event)
- AddClickEvent(self.special_trade_btn_obj, click_event)
- AddClickEvent(self.exp_btn_obj, click_event)
- AddClickEvent(self.normal_trade_desc_2_obj, click_event)
-
-
- local function on_ans_base_info()
- self:UpdateView()
- end
- self:BindEvent(self.model, CurrencyWishConst.ANS_CURRENCY_WISH_INFO, on_ans_base_info)
-
-
- local function on_update_view()
- self:UpdateView()
- end
- self:BindEvent(self.model, CurrencyWishConst.UPDATE_CURRENCY_WISH_VIEW, on_update_view)
-
- local function on_update_currency_wish_cd_time(cd_time)
- if cd_time <= 0 then
- self.special_trade_desc_tmp.text = ""
- else
- local cd_time_str = string.format("<color=%s>%s</color> 后免费", ColorUtil.GREEN_TIPS, TimeUtil:timeConvert4(cd_time))
- self.special_trade_desc_tmp.text = cd_time_str
- end
- end
- self:BindEvent(self.model, CurrencyWishConst.UPDATE_CURRENCY_WISH_CD_TIME, on_update_currency_wish_cd_time)
- end
-
- function CurrencyWishView:TryDoCurrencyWish(type)
-
- local ok_callback = function ()
- self.model:Fire(CurrencyWishConst.REQ_DO_CURRENCY_WISH, type)
- end
-
- local base_info = self.model:GetBaseInfo()
-
- --- 冷却时直接向服务端请求 让服务端返回错误码
- if type == CurrencyWishConst.CURRENCY_WISH_TYPE.NORMAL then -- 交易券消耗背包道具
- local stamp_goods_num = GoodsModel:getInstance():GetTypeGoodsNum(BagModel.StampGoodsId) --已有的交易券数量
- if stamp_goods_num < 1 then
- Message.show("物品不足")
- else
- ok_callback()
- end
- return
- elseif type == CurrencyWishConst.CURRENCY_WISH_TYPE.SPECIAL then
- if (base_info.luxurycool and base_info.luxurycool <= 0)
- or base_info.luxury_rest_times <= 0 then
- ok_callback()
- return
- end
- elseif type == CurrencyWishConst.CURRENCY_WISH_TYPE.EXP then
- if base_info.expr_rest_times <= 0 then
- ok_callback()
- return
- end
- end
-
- local cancel_callback = function ()
-
- end
- local toggle_function = function ()
- self.model.currency_wish_without_confirm = true
- end
- -- local cost_info = self.model:GetInoriCostInfo(type)
- local wish_cfg = self.model:GetCurrencyWishConfigOne(type)
- local cost_info = stringtotable(wish_cfg.consume)[1]
- local cost_type = cost_info[1]
- local cost_num = cost_info[3]
- local jin = RoleManager.Instance.mainRoleInfo.jin
- local jinLock = RoleManager.Instance.mainRoleInfo.jinLock
- local toggle_tip_data = {
- insufficientText = "",
- titleText = "提示",
- nameText = "是否花费 ",
- priceText = string.format("%s 进行祈愿", HtmlColorTxt(cost_num, "#fdffc2")),
- okText = "确认",
- cancelText = "取消",
- toggleText = " 本次登录不再提示",--8字符
- ok_callback = ok_callback,
- close_callback = cancel_callback,
- toggle_function = toggle_function,
- is_complex_ok_callback = false,
- gold_res = "ui_momey_icon_" .. cost_type,
- price = cost_num, -- config
- }
-
- if not self.model.currency_wish_without_confirm then
- GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
- else
- if cost_type == 1 and jin < cost_num then
- GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
- return
- end
- if cost_type == 2 and jin + jinLock < cost_num then
- GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
- return
- end
- ok_callback()
- end
- end
-
- function CurrencyWishView:UpdateView()
- if not self.is_loaded then
- self.need_refresh_view = true
- return
- end
-
- self.base_info = self.model:GetBaseInfo()
- if not self.base_info then
- return
- end
-
- local special_currency_wish_times = string.format("今日剩余:<color=%s>%d次</color>",
- self.base_info.luxury_rest_times > 0 and ColorUtil.GREEN_TIPS or ColorUtil.RED_DARK, self.base_info.luxury_rest_times)
-
- local exp_currency_wish_times = string.format("今日剩余:<color=%s>%d次</color>",
- self.base_info.expr_rest_times > 0 and ColorUtil.GREEN_TIPS or ColorUtil.RED_DARK, self.base_info.expr_rest_times)
-
- self.special_trade_count_tmp.text = special_currency_wish_times
- self.exp_count_tmp.text = exp_currency_wish_times
-
- local normal_wish_cfg = self.model:GetCurrencyWishConfigOne(CurrencyWishConst.CURRENCY_WISH_TYPE.NORMAL)
- local special_wish_cfg = self.model:GetCurrencyWishConfigOne(CurrencyWishConst.CURRENCY_WISH_TYPE.SPECIAL)
- local exp_wish_cfg = self.model:GetCurrencyWishConfigOne(CurrencyWishConst.CURRENCY_WISH_TYPE.EXP)
- local normal_num = stringtotable(normal_wish_cfg.base_produce)[1][3]
- local special_num = stringtotable(special_wish_cfg.base_produce)[1][3]
- local exp_num = stringtotable(exp_wish_cfg.base_produce)[1][3]
-
- -- print("Lizhijian:CurrencyWishView [start:251] ")
- -- print(normal_num, special_num, exp_num)
- -- print("Lizhijian:CurrencyWishView [end:251] ")
- self.normal_trade_reward_num_tmp.text = normal_num
- self.special_trade_reward_num_tmp.text = special_num
- self.exp_reward_num_tmp.text = exp_num
-
- if self.base_info.luxurycool <= 0 then
- self.special_trade_desc_tmp.text = ""
- self.special_trade_btn_red_obj:SetActive(true)
- else
- self.special_trade_btn_red_obj:SetActive(false)
- local cd_time_str = string.format("<color=%s>%s</color> 后免费", ColorUtil.GREEN_TIPS, TimeUtil:timeConvert4(self.base_info.luxurycool))
- self.special_trade_desc_tmp.text = cd_time_str
- end
-
- lua_resM:setImageSprite(self, self.normal_trade_btn_img, "currencyWish_asset", "currency_wish_all_btn_bg", false)
- 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)
- lua_resM:setImageSprite(self, self.exp_btn_img, "currencyWish_asset", "currency_wish_special_btn_bg", false)
-
- local stamp_goods_num = GoodsModel:getInstance():GetTypeGoodsNum(BagModel.StampGoodsId) --已有的交易券数量
- stamp_goods_num = Mathf.Clamp(stamp_goods_num, 0, 999)
- if stamp_goods_num > 99 then
- SetSizeDelta(self.normal_trade_btn_red, 36, 36)
- else
- SetSizeDelta(self.normal_trade_btn_red, 32, 32)
- end
- self.normal_trade_btn_red_obj:SetActive(stamp_goods_num ~= 0)
- self.normal_trade_btn_red_num_tmp.text = stamp_goods_num ~= 0 and stamp_goods_num or ""
- self.normal_trade_desc_2_tmp.text = string.format("祈愿消耗:<color=%s>10交易券卡</color>", ColorUtil.PURPLE_DARK)
-
-
- local role_lv = RoleManager.Instance.mainRoleInfo.level
- self.exp_desc_1_tmp.text = string.format("等级提升%s级", role_lv)
- -- 递归计算能升多少级
- local add_lv = 0
- local total_lv = TableSize(Config.Exp)
- local cur_exp = RoleManager.Instance.mainRoleInfo.exp
- local add_exp = exp_num
- local res_lv = role_lv
- local function cul_addlv_and_percentage(exp)
- if Config.Exp[role_lv + add_lv] and exp > Config.Exp[role_lv + add_lv].exp then
- exp = exp - Config.Exp[role_lv + add_lv].exp
- add_lv = add_lv + 1
- cul_addlv_and_percentage(exp)
- else
- -- 等级容错
- res_lv = role_lv + add_lv < total_lv and role_lv + add_lv or total_lv
- end
- end
- cul_addlv_and_percentage(cur_exp + add_exp)
- self.exp_desc_2_tmp.text = string.format("<color=%s>%s</color>级", ColorUtil.GREEN_TIPS, res_lv)
-
- self:DoAction()
- end
-
- function CurrencyWishView:DoAction()
- if self.is_action then
- return
- end
- self.is_action = true
- for i = 1, 3 do
- local icon = self["icon_" .. i]
- cc.ActionManager:getInstance():removeAllActionsFromTarget(icon)
- --action 1
- local pos_x, pos_y = GetAnchoredPosition(icon)
- local offset = 10
- local anim_time = 1
-
- local function moveUp1(percent)
- SetAnchoredPositionY(icon, pos_y + offset * percent)
- end
- local flowUp1 = cc.CustomUpdate.New(anim_time, moveUp1)
- -- local flowUp1 = cc.CustomUpdate.New(anim_time, moveUp1)
- local function moveDown(percent)
- SetAnchoredPositionY(icon, pos_y + offset - 2 * offset * percent)
- end
- local flowDown = cc.CustomUpdate.New(anim_time * 2, moveDown)
- -- local flowDown = cc.CustomUpdate.New(anim_time * 2, moveDown)
-
- local function moveUp2(percent)
- SetAnchoredPositionY(icon, pos_y - offset + offset * percent)
- end
- local flowUp2 = cc.CustomUpdate.New(anim_time, moveUp2)
- -- local flowUp2 = cc.CustomUpdate.New(anim_time, moveUp2)
-
-
-
- local action = cc.RepeatForever.New(cc.Sequence.New(flowUp1, flowDown, flowUp2))
- -- local final_action = cc.Sequence.New(cc.DelayTime.New(i * 0.1), action)
- local final_action = action
- local function delay_method()
- cc.ActionManager:getInstance():addAction(final_action, icon)
- end
- self.delay_method_id = setTimeout(delay_method, (i - 1) * 0.3)
- end
-
- end
-
- function CurrencyWishView:DestroySuccess()
-
- end
-
- function CurrencyWishView:__delete()
- for i = 1, 3 do
- local icon = self["icon_" .. i]
- cc.ActionManager:getInstance():removeAllActionsFromTarget(icon)
- icon = nil
- end
-
- if self.money_view then
- self.money_view:DeleteMe()
- self.money_view = nil
- end
- end
|