GiftPreviewView = GiftPreviewView or BaseClass(BaseView)
|
|
local GiftPreviewView = GiftPreviewView
|
|
--[[
|
|
GiftPreviewView.TabData = {
|
|
[1] = {name = "人物", level = MainRoleModel.TabOpenLevel[1]},
|
|
}
|
|
--]]
|
|
|
|
function GiftPreviewView:__init()
|
|
self.base_file = "gift"
|
|
self.layout_file = "GiftPreviewView"
|
|
self.layer_name = "Activity"
|
|
self.destroy_imm = true
|
|
self.use_background = true --全屏界面默认使用这个参数
|
|
--self.hide_maincancas = true --全屏界面需要放开隐藏主UI
|
|
self.change_scene_close = true
|
|
self.append_to_ctl_queue = false --是否要添加进界面堆栈
|
|
self.need_show_money = false --是否要显示顶部的金钱栏
|
|
self.is_set_zdepth = true
|
|
self.model = GiftModel:getInstance()
|
|
self.blur_activity_bg = true
|
|
self.click_bg_toClose = true
|
|
self.reward_item_list = {}
|
|
self.load_callback = function ()
|
|
self:LoadSuccess()
|
|
self:AddEvent()
|
|
end
|
|
self.open_callback = function ( )
|
|
self:OpenSuccess()
|
|
end
|
|
self.switch_callback = function(index)
|
|
self:SwitchTab(index)
|
|
end
|
|
self.destroy_callback = function ( )
|
|
self:DestroySuccess()
|
|
end
|
|
end
|
|
|
|
function GiftPreviewView:Open(data)
|
|
self.data = data
|
|
BaseView.Open(self)
|
|
end
|
|
|
|
function GiftPreviewView:LoadSuccess()
|
|
local nodes = {
|
|
"bg/tip_con/cost_image2:img", "bg/title",
|
|
"bg/btn/discount_bg", "bg/btn/discount:tmp",
|
|
"bg/tip_con/cur_text:tmp", "bg/tip_con/cost_image1:img", "bg/tip_con","bg/btn/btn_text:tmp",
|
|
"bg/close_btn:obj", "bg:img", "bg/tip_con/origin_text:tmp", "bg/item_con", "bg/btn:obj:imgex", "bg/refuse_btn:obj",
|
|
}
|
|
self:GetChildren(nodes)
|
|
self.btn_text_tmp.text = "优惠购买"
|
|
end
|
|
|
|
function GiftPreviewView:AddEvent()
|
|
local function on_click( target )
|
|
if target == self.btn_obj then
|
|
if self.is_not_open then
|
|
-- local str = string.format("开服第%s天开放购买哦~", self.data.start_day)
|
|
local str = "该礼包明日开放购买哦~"
|
|
Message.show(str, "fault")
|
|
return
|
|
else
|
|
local function ok_callback( ... )
|
|
GoodsModel:getInstance():Fire(GoodsModel.REQUEST_CCMD_EVENT, 15050, self.data.goods_id, self.data.type_id, 1)
|
|
self:Close()
|
|
end
|
|
-- local function toggle_function( flag )
|
|
-- self.model.gift_preview_toggle = flag
|
|
-- end
|
|
local function use_function( toggle_tip_data,call_fun_sum )
|
|
-- if not self.model.gift_preview_toggle then
|
|
-- GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
|
|
-- else
|
|
call_fun_sum()--不需要判断了 直接走
|
|
-- end
|
|
self:Close()
|
|
end
|
|
local function recharge_open_call_back( ... )
|
|
self:Close()
|
|
end
|
|
local buy_tip_data = {
|
|
gold_type = self.money_type,--货币类型
|
|
cost_price = self.cur_cost,--消耗金额
|
|
ok_callback = ok_callback,--成功
|
|
toggle_function = toggle_function,--多选
|
|
togglePriceStr = string.format("<color=#fdffc2>%s</color> 购买商品",self.cur_cost),--提示语
|
|
use_function = use_function,--最终调用
|
|
recharge_open_call_back = recharge_open_call_back,
|
|
invest_call_back = recharge_open_call_back,
|
|
}
|
|
CustomActivityModel:getInstance():BuyTips(buy_tip_data)
|
|
end
|
|
elseif target == self.close_btn_obj then
|
|
self:Close()
|
|
elseif target == self.refuse_btn_obj then
|
|
self:Close()
|
|
end
|
|
end
|
|
AddClickEvent(self.btn_obj, on_click)
|
|
AddClickEvent(self.close_btn_obj, on_click)
|
|
AddClickEvent(self.refuse_btn_obj, on_click)
|
|
local function on_close( ... )
|
|
self:Close()
|
|
end
|
|
self:BindEvent(self.model, GiftModel.CLOSE_PREVIEW_VIEW, on_close)
|
|
end
|
|
|
|
function GiftPreviewView:OpenSuccess()
|
|
self:UpdateView()
|
|
end
|
|
|
|
function GiftPreviewView:UpdateView()
|
|
if GoodsModel:getInstance():IsPaidGift(self.data.type_id) then--付费礼包
|
|
local data = self.data
|
|
self.money_type = data.diamond_list.cost_type
|
|
self.origin_cost = data.diamond_list.old_cost
|
|
self.cur_cost = data.diamond_list.now_cost
|
|
self.reward_list = data.fix_reward_list
|
|
local open_day = ServerTimeModel:getInstance():GetOpenServerDay()
|
|
self.is_not_open = false
|
|
if data.start_day then
|
|
if open_day < data.start_day then
|
|
self.is_not_open = true
|
|
end
|
|
end
|
|
if data.end_day then
|
|
if open_day > data.end_day then
|
|
self.is_not_open = true
|
|
end
|
|
end
|
|
self.btn_imgex.gray = self.is_not_open
|
|
if self.is_not_open then
|
|
SetTMPSharedMaterial(self.btn_text_tmp,ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn)
|
|
else
|
|
SetTMPSharedMaterial(self.btn_text_tmp,ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkOrangeBtn)
|
|
end
|
|
self.origin_text_tmp.text = self.origin_cost
|
|
self.cur_text_tmp.text = self.cur_cost
|
|
self.discount_tmp.text = string.format("%s折",math.ceil(self.cur_cost/self.origin_cost*10))
|
|
local len = TableSize(self.reward_list)
|
|
local offset = 12
|
|
local item_size = 114
|
|
if len == 2 then
|
|
offset = 40
|
|
end
|
|
--因为要居中对齐 所以从左边开始算起来
|
|
local start_x = 0
|
|
if len%2 == 0 then--如果是偶数个 那么居中的是空间
|
|
local num = len/2
|
|
for i=1,num do
|
|
start_x = start_x - item_size - offset
|
|
end
|
|
start_x = start_x + offset/2
|
|
else
|
|
local num = math.floor(len/2)
|
|
for i=1,num do
|
|
start_x = start_x - item_size - offset
|
|
end
|
|
start_x = start_x - item_size/2
|
|
end
|
|
for i,v in ipairs(self.reward_list) do
|
|
local item = self.reward_item_list[i]
|
|
if not item then
|
|
item = GiftPreviewItem.New(self.item_con)
|
|
self.reward_item_list[i] = item
|
|
end
|
|
item:SetData(v)
|
|
item:SetPosition((i-1)*(item_size + offset) + start_x, -10)
|
|
end
|
|
if len > 3 then
|
|
local origin_width = 520
|
|
local cur_width = (len - 3)*(item_size-10) + origin_width
|
|
SetSizeDeltaX(self.bg, cur_width)
|
|
-- SetSizeDeltaX(self.item_bg, cur_width-20)
|
|
end
|
|
else
|
|
end
|
|
if self.delay_id then
|
|
GlobalTimerQuest:CancelQuest(self.delay_id)
|
|
self.delay_id = nil
|
|
end
|
|
local function delay_method( )
|
|
SetSizeDeltaX(self.origin_text, self.origin_text_tmp.preferredWidth+1)
|
|
SetSizeDeltaX(self.cur_text, self.cur_text_tmp.preferredWidth+1)
|
|
end
|
|
self.delay_id = setTimeout(delay_method, 0.01)
|
|
self:SetMoneyIcon()
|
|
end
|
|
|
|
-- 加载货币图标
|
|
function GiftPreviewView:SetMoneyIcon()
|
|
if not self.money_type then return end
|
|
local asset, source = WordManager:GetCommonMoneyIcon(self.money_type)
|
|
lua_resM:setImageSprite(self, self.cost_image2_img, asset, source)
|
|
lua_resM:setImageSprite(self, self.cost_image1_img, asset, source)
|
|
end
|
|
|
|
function GiftPreviewView:SwitchTab( index )
|
|
|
|
end
|
|
|
|
function GiftPreviewView:DestroySuccess( )
|
|
for i,v in ipairs(self.reward_item_list) do
|
|
v:DeleteMe()
|
|
v = nil
|
|
end
|
|
self.reward_item_list = {}
|
|
if self.delay_id then
|
|
GlobalTimerQuest:CancelQuest(self.delay_id)
|
|
self.delay_id = nil
|
|
end
|
|
end
|