|
CurrencyExchangeView = CurrencyExchangeView or BaseClass(BaseView)
|
|
local CurrencyExchangeView = CurrencyExchangeView
|
|
|
|
function CurrencyExchangeView:__init()
|
|
self.base_file = "bag"
|
|
self.layout_file = "CurrencyExchangeView"
|
|
self.layer_name = "Activity"
|
|
self.destroy_imm = true
|
|
self.use_background = true
|
|
self.change_scene_close = true
|
|
self.hide_maincancas = true --是否隐藏主界面
|
|
self.append_to_ctl_queue = false --是否要添加进界面堆栈
|
|
self.need_show_money = false --是否要显示顶部的金钱栏
|
|
self.click_bg_toClose = false
|
|
self.is_set_zdepth = true
|
|
|
|
self.blur_activity_bg = true
|
|
-- self.use_show_anim = true
|
|
-- self.use_hide_anim = true
|
|
|
|
self.jump_close = true
|
|
|
|
self.model = BagModel:getInstance()
|
|
|
|
self.stamp_exchange_num = 10 -- 一张交易卡券能兑换的交易券数量
|
|
self.diamond_expend_num = 40 -- 使用彩钻兑换一次交易券需要消耗的彩钻数
|
|
self.diamond_exchange_can_get_num = self.diamond_expend_num*15 -- 使用彩钻兑换一次能获得的交易券数量
|
|
self.diamond_free_exchange_num = 0 --彩钻石免费兑换次数
|
|
|
|
|
|
|
|
|
|
self.load_callback = function ()
|
|
self:LoadSuccess()
|
|
self:AddEvent()
|
|
self.model.update_all_currency_exchange_view = true
|
|
self.model:Fire(BagModel.REQUEST_PROTOCOL,15026) --彩钻兑换交易券次数情况
|
|
end
|
|
self.open_callback = function ( )
|
|
-- self:OpenSuccess()
|
|
end
|
|
self.close_win_callback = function ( )
|
|
self:Close()
|
|
end
|
|
self.destroy_callback = function ( )
|
|
self:DestroySuccess()
|
|
end
|
|
end
|
|
|
|
function CurrencyExchangeView:Open()
|
|
BaseView.Open(self)
|
|
end
|
|
|
|
function CurrencyExchangeView:LoadSuccess()
|
|
local nodes = {
|
|
"bg:raw", --背景
|
|
"money_icon_1:img", "money_icon_2:img", --货币图标
|
|
"props_award_con",
|
|
"goVipBtn:obj", --跳转按钮
|
|
"diamond_left_num:tmp",
|
|
"close_btn:obj", --关闭按钮
|
|
"diamond_free_time_label:tmp", --免费兑换文本
|
|
"propsExchangeBtn:obj", "diamondExchangeBtn:obj", --兑换按钮
|
|
"diamondExchangeBtn/diamondExchangeText:tmp", --彩钻兑换按钮文字
|
|
"diamondExchangeBtn/diamondExchangeLabelCon:obj", --彩钻兑换花费栏
|
|
"propsExchangeBtn/propsRed:obj", "diamondExchangeBtn/diamondRed:obj", --兑换按钮红点
|
|
"moneyCon",
|
|
"money_icon_1/can_get_money_1:txt",
|
|
"life_skill_critical_label:tmp",
|
|
}
|
|
self:GetChildren(nodes)
|
|
|
|
-- self.money_view = UIMoneyView.New(self.moneyCon)
|
|
-- self.money_view:SetPosition(0,0)
|
|
-- self.money_view:SetData()
|
|
|
|
lua_resM:setOutsideRawImage(self,self.bg_raw,GameResPath.GetViewBigBg("currency_exchange_bg"))
|
|
|
|
self.props_award = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.props_award_con)
|
|
self.props_award:SetItemSize(78, 78)
|
|
self.props_award:SetData(BagModel.StampGoodsId)
|
|
local goods_num = GoodsModel:getInstance():GetTypeGoodsNum(101014)
|
|
local get_str = HtmlColorTxt(goods_num, goods_num < 1 and ColorUtil.RED_DARK or ColorUtil.GREEN_TIPS).."/".. 1
|
|
self.props_award:IsGetGoods(true,get_str,false)
|
|
|
|
if self.need_refresh_view then
|
|
self:UpdateView()
|
|
end
|
|
end
|
|
|
|
function CurrencyExchangeView:AddEvent()
|
|
local on_click = function ( click_obj )
|
|
if self.goVipBtn_obj == click_obj then --跳转vip
|
|
self:Close()
|
|
OpenFun.Open(450,2)
|
|
elseif self.close_btn_obj == click_obj then
|
|
self:Close()
|
|
elseif self.propsExchangeBtn_obj == click_obj then--使用道具兑换
|
|
self:DoExchange(1)
|
|
elseif self.diamondExchangeBtn_obj == click_obj then--使用彩钻兑换
|
|
self:DoExchange(2)
|
|
end
|
|
end
|
|
AddClickEvent(self.goVipBtn_obj, on_click)
|
|
AddClickEvent(self.close_btn_obj, on_click)
|
|
AddClickEvent(self.propsExchangeBtn_obj, on_click)
|
|
AddClickEvent(self.diamondExchangeBtn_obj, on_click)
|
|
|
|
local function Update_currency_view()
|
|
if self.is_loaded then
|
|
self:UpdateDiamondExchange()
|
|
self:UpdatePropsExchange()
|
|
end
|
|
end
|
|
self:BindEvent(self.model, BagModel.UPDATE_CURRENCY_EXCHANGE_VIEW,Update_currency_view)
|
|
|
|
--货币礼包数量更新时,也要刷新界面
|
|
local function on_update_currency_goods_num()
|
|
if self.is_loaded then
|
|
self:UpdatePropsExchange()
|
|
end
|
|
end
|
|
self.model:Bind(BagModel.UPDATE_CURRENCY_GOODS_NUM,on_update_currency_goods_num)
|
|
|
|
|
|
--刷新交易券兑换
|
|
local function update_currency_exchange_red()
|
|
self:SetCurrencyExchangeRed()
|
|
end
|
|
self:BindEvent(self.model,BagModel.ANS_UPDATE_CURRENCY_EXCHANGE_RED,update_currency_exchange_red)
|
|
self:BindEvent(GlobalEventSystem,EventName.UPDATE_BAG_RED,update_currency_exchange_red)
|
|
update_currency_exchange_red()
|
|
|
|
--打开界面时请求15026,并刷新界面
|
|
local function on_update_view()
|
|
if self.is_loaded then
|
|
self.need_refresh_view = false
|
|
self:UpdateView()
|
|
else
|
|
self.need_refresh_view = true
|
|
end
|
|
end
|
|
self.model:Bind(BagModel.UPDATE_CURRENCY_VIEW,on_update_view)
|
|
end
|
|
|
|
function CurrencyExchangeView:SetCurrencyExchangeRed( )
|
|
local bool = self.model:GetCurrencyExchangeRed()
|
|
local props_red = self.model:GetCurrencyExchangePropsRed()
|
|
local diamond_red = self.model:GetCurrencyExchangeDiamondRed()
|
|
self.propsRed_obj:SetActive(props_red)
|
|
self.diamondRed_obj:SetActive(diamond_red)
|
|
end
|
|
|
|
function CurrencyExchangeView:DoExchange(exchange_type)
|
|
if exchange_type == 1 then--使用道具兑换
|
|
local props_times = GoodsModel:getInstance():GetTypeGoodsNum(BagModel.StampGoodsId) --已有的交易券数量
|
|
if props_times == 0 then
|
|
Message.show("数量不足","fault")
|
|
else
|
|
self.model:Fire(BagModel.REQUEST_PROTOCOL,15022,0,props_times)
|
|
lua_soundM:PlayEffect(self, "success",false,LuaSoundManager.SOUND_TYPE.UI)
|
|
end
|
|
elseif exchange_type == 2 then--使用彩钻兑换
|
|
if self.exchange_btn_state == 2 then
|
|
self:Close()
|
|
OpenFun.Open(450,2)
|
|
return
|
|
end
|
|
|
|
local free_time = self.model.currency_exchange_free_time
|
|
local diamond_times = self.model:GetCurrencyExchangeNumsNow() --剩余的使用彩钻兑换次数
|
|
local is_free = free_time and free_time ~= 0 and free_time <= TimeUtil:getServerTime()
|
|
local diamond_exchange_times = is_free and 1 or diamond_times
|
|
if diamond_exchange_times == 0 then
|
|
Message.show("剩余兑换次数不足","fault")
|
|
else
|
|
local function ok_callback( ... )
|
|
self.model:Fire(BagModel.REQUEST_PROTOCOL,15022,1,0)
|
|
lua_soundM:PlayEffect(self, "success",false,LuaSoundManager.SOUND_TYPE.UI)
|
|
end
|
|
local function toggle_function( flag )
|
|
self.model._diamond_exchange_no_double_check = flag
|
|
end
|
|
local function use_function( toggle_tip_data,call_fun_sum )
|
|
if not self.model._diamond_exchange_no_double_check and self.diamond_expend_num ~= 0 then
|
|
GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
|
|
else
|
|
call_fun_sum()
|
|
end
|
|
end
|
|
local buy_tip_data = {
|
|
gold_type = 1,--货币类型
|
|
cost_price = self.diamond_expend_num,--消耗金额
|
|
ok_callback = ok_callback,--成功
|
|
toggle_function = toggle_function,--多选
|
|
togglePriceStr = string.format("<color=#fdffc2>%s</color> 进行兑换",self.diamond_expend_num),--提示语
|
|
use_function = use_function,--最终调用
|
|
}
|
|
if is_free then
|
|
ok_callback()
|
|
else
|
|
CustomActivityModel:getInstance():BuyTips(buy_tip_data)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function CurrencyExchangeView:OpenSuccess()
|
|
self:UpdateView()
|
|
end
|
|
|
|
function CurrencyExchangeView:UpdateView( )
|
|
self:UpdatePropsExchange()
|
|
self:UpdateDiamondExchange()
|
|
|
|
--宠物生活技能 彩钻兑换交易券有概率暴击,收益翻倍
|
|
local life_skill_active = PetModel:getInstance():IsLifeSkillActived(PetConst.LifeSkill.CurrencyExchangeCritical)
|
|
local life_skill_ratio = PetModel:getInstance():GetPetLifeSkillRatio(PetConst.LifeSkill.CurrencyExchangeCritical)
|
|
if life_skill_active then
|
|
self.life_skill_critical_label_tmp.text = string.format("<color=#2CF86F>%s%%概率双倍</color>",life_skill_ratio)
|
|
else
|
|
self.life_skill_critical_label_tmp.text = ""
|
|
end
|
|
|
|
end
|
|
|
|
--刷新道具兑换相关界面变化
|
|
function CurrencyExchangeView:UpdatePropsExchange( )
|
|
if not self.is_loaded then return end
|
|
|
|
local stamp_goods_num = GoodsModel:getInstance():GetTypeGoodsNum(BagModel.StampGoodsId) --已有的交易券数量
|
|
|
|
local free_time = self.model.currency_exchange_free_time
|
|
self.diamond_free_exchange_num = (free_time and free_time ~= 0 and free_time <= TimeUtil:getServerTime()) and 1 or 0
|
|
|
|
-- local show_props_num = stamp_goods_num > 0 and stamp_goods_num or 1
|
|
-- self.props_left_num_2_tmp.text = show_props_num
|
|
|
|
-- self.can_get_num_1_tmp.text = "x"..self.stamp_exchange_num
|
|
|
|
-- local num_color_str = stamp_goods_num > 0 and ColorUtil.GREEN_TIPS or ColorUtil.RED_DARK
|
|
-- self.props_left_num_tmp.text = string.format("总共可获得 <color=%s>%s</color>",num_color_str,stamp_goods_num*self.stamp_exchange_num)
|
|
-- SetAnchoredPositionX(self.money_icon_3,450 + self.props_left_num_tmp.preferredWidth/2 + 18)
|
|
if stamp_goods_num > 0 then
|
|
self.can_get_money_1_txt.text = stamp_goods_num*self.stamp_exchange_num
|
|
else
|
|
self.can_get_money_1_txt.text = self.stamp_exchange_num
|
|
end
|
|
|
|
local goods_num = GoodsModel:getInstance():GetTypeGoodsNum(101014)
|
|
local get_str = HtmlColorTxt(goods_num, goods_num < 1 and ColorUtil.RED_DARK or ColorUtil.GREEN_TIPS).."/".. 1
|
|
self.props_award:IsGetGoods(true,get_str,false)
|
|
end
|
|
|
|
--刷新彩钻兑换相关界面变化
|
|
function CurrencyExchangeView:UpdateDiamondExchange()
|
|
local left_exchange_times = self.model:GetCurrencyExchangeNumsNow() --剩余的使用彩钻兑换次数
|
|
|
|
local free_time = self.model.currency_exchange_free_time
|
|
self.diamond_free_exchange_num = (free_time and free_time ~= 0 and free_time <= TimeUtil:getServerTime()) and 1 or 0
|
|
|
|
if self.diamond_free_exchange_num > 0 then--有免费
|
|
self.diamondExchangeLabelCon_obj:SetActive(false)
|
|
self.diamondExchangeText_tmp.text = "免费兑换"
|
|
self.exchange_btn_state = 1
|
|
self.diamond_left_num_tmp.text = string.format("<color=%s>本次免费</color>",ColorUtil.GREEN_TIPS)
|
|
else
|
|
local my_vip_flag = RoleManager.Instance.mainRoleInfo.vip_flag
|
|
local max_privilege_vip = self.model:GetCurreccyExchangeMaxVip()
|
|
if left_exchange_times > 0 or my_vip_flag >= max_privilege_vip then--有次数或者已经达到了最高权限的vip
|
|
self.diamondExchangeLabelCon_obj:SetActive(true)
|
|
self.diamondExchangeText_tmp.text = ""
|
|
self.exchange_btn_state = 1
|
|
local num_color_str = left_exchange_times > 0 and ColorUtil.GREEN_TIPS or ColorUtil.RED_DARK
|
|
self.diamond_left_num_tmp.text = string.format("今日可兑换次数: <color=%s>%s</color>",num_color_str,left_exchange_times)
|
|
else--没次数且没达到最高权限vip,提示去提升vip
|
|
self.diamondExchangeLabelCon_obj:SetActive(false)
|
|
self.diamondExchangeText_tmp.text = "提升VIP"
|
|
self.exchange_btn_state = 2
|
|
self:UpdateVipTips()
|
|
end
|
|
end
|
|
|
|
-- self.can_get_num_2_tmp.text = "x"..self.diamond_exchange_can_get_num
|
|
|
|
self:UpdateFreeExchangeTime()
|
|
end
|
|
|
|
--升vip的提示tips
|
|
function CurrencyExchangeView:UpdateVipTips( )
|
|
local my_vip_flag = RoleManager.Instance.mainRoleInfo.vip_flag
|
|
local next_vip_flag = my_vip_flag+1
|
|
local max_privilege_vip = self.model:GetCurreccyExchangeMaxVip()
|
|
|
|
if my_vip_flag >= max_privilege_vip then--已经是最高权限vip
|
|
self.diamond_left_num_tmp.text = string.format("今日可兑换次数: <color=%s>0</color>",ColorUtil.RED_DARK)
|
|
else
|
|
local now_max_exchange_times = self.model:GetCurrencyExchangeNumsByVip()
|
|
local next_max_exchange_times = self.model:GetCurrencyVipPrivilege(next_vip_flag) and self.model:GetCurrencyVipPrivilege(next_vip_flag).value or 0
|
|
local up_exchange_times = next_max_exchange_times-now_max_exchange_times
|
|
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)
|
|
end
|
|
end
|
|
|
|
function CurrencyExchangeView:DestroySuccess( )
|
|
if self.props_award then
|
|
UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, self.props_award)
|
|
self.props_award = nil
|
|
end
|
|
|
|
self:StopFreeTimer()
|
|
|
|
if self.money_view then
|
|
self.money_view:DeleteMe()
|
|
self.money_view = nil
|
|
end
|
|
end
|
|
|
|
function CurrencyExchangeView:UpdateFreeExchangeTime()
|
|
local free_time = self.model.currency_exchange_free_time
|
|
|
|
local function timer_func()
|
|
local time = free_time - TimeUtil:getServerTime()
|
|
local color = ColorUtil.GREEN_TIPS
|
|
if time <= 0 then
|
|
self.diamond_free_exchange_num = 1
|
|
self.diamond_free_time_label_tmp.text = string.format("可免费兑换%s次", HtmlColorTxt(1 , color))
|
|
self:StopFreeTimer()
|
|
else
|
|
local time_color = ColorUtil.GREEN_TIPS
|
|
local time_str = TimeUtil:timeConvert17(time)
|
|
self.diamond_free_time_label_tmp.text = string.format("<color=%s>%s</color> 后可免费兑换%s次", "#ffffff", time_str, HtmlColorTxt(1 , color))
|
|
end
|
|
end
|
|
if not self.free_timer then
|
|
self.free_timer = GlobalTimerQuest:AddPeriodQuest(timer_func, 1)
|
|
end
|
|
timer_func()
|
|
end
|
|
|
|
function CurrencyExchangeView:StopFreeTimer( )
|
|
if self.free_timer then
|
|
GlobalTimerQuest:CancelQuest(self.free_timer)
|
|
self.free_timer = nil
|
|
end
|
|
end
|