TreasureHouseResultView = TreasureHouseResultView or BaseClass(BaseView)
|
|
local TreasureHouseResultView = TreasureHouseResultView
|
|
|
|
function TreasureHouseResultView:__init()
|
|
self.base_file = "treasureHouse"
|
|
self.layout_file = "TreasureHouseResultView"
|
|
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.blur_activity_bg = true
|
|
self.use_show_anim = true
|
|
self.use_hide_anim = true
|
|
|
|
self.model = TreasureHouseModel:getInstance()
|
|
|
|
self.item_list = {}
|
|
self.start_pos_x = 0
|
|
self.start_pos_y = 0
|
|
|
|
self.draw_num_type = 0 --结算数量类型 1|单抽 10|10连
|
|
|
|
self.load_callback = function ()
|
|
self:LoadSuccess()
|
|
self:AddEvent()
|
|
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 TreasureHouseResultView:Open(data)
|
|
self.data = data
|
|
self.pool_type = self.data.pool_type
|
|
BaseView.Open(self)
|
|
end
|
|
|
|
function TreasureHouseResultView:LoadSuccess()
|
|
local nodes = {
|
|
"resultBg:img",
|
|
"itemCon:obj",
|
|
"ScrollView", "ScrollView/Viewport/Content", "ScrollView/Viewport:img",
|
|
"visCon:obj",
|
|
"visCon/confirmBtn:obj",
|
|
"visCon/againBtn:obj",
|
|
"visCon/costIcon:img",
|
|
"visCon/costPrice:tmp",
|
|
"visCon/againBtn/againText:tmp",
|
|
}
|
|
self:GetChildren(nodes)
|
|
|
|
|
|
SetLocalPosition(self.transform, 0, 0,-1000)
|
|
|
|
local function bg_back_func( ... )
|
|
self.confirmBtn_obj:SetActive(true)
|
|
self.againBtn_obj:SetActive(true)
|
|
self.itemCon_obj:SetActive(false)
|
|
self.awarditem = TreasureHouseResultItem.New(self.itemCon)
|
|
|
|
lua_resM:setOutsideImageSprite(self, self.resultBg_img, GameResPath.GetCapsuleEggRes("capsule_egg_result_shine_837_630"))
|
|
|
|
if self.need_refreshData then
|
|
self:UpdateView(self.pool_type)
|
|
end
|
|
end
|
|
if self.background_wnd then
|
|
bg_back_func()
|
|
else
|
|
self.bg_back_func = bg_back_func
|
|
end
|
|
end
|
|
|
|
function TreasureHouseResultView:AddEvent()
|
|
local on_click = function ( click_obj )
|
|
if self.confirmBtn_obj == click_obj then--关闭界面
|
|
self:Close()
|
|
elseif self.againBtn_obj == click_obj then--再来
|
|
self:LuckStart()
|
|
end
|
|
end
|
|
AddClickEvent(self.confirmBtn_obj, on_click)
|
|
AddClickEvent(self.againBtn_obj, on_click)
|
|
end
|
|
|
|
function TreasureHouseResultView:OpenSuccess()
|
|
self:UpdateView()
|
|
end
|
|
|
|
function TreasureHouseResultView:UpdateView()
|
|
|
|
if self.is_loaded then
|
|
self.need_refreshData = false
|
|
else
|
|
self.need_refreshData = true
|
|
return
|
|
end
|
|
self.reward_list = self.data.award
|
|
|
|
self:Reset()
|
|
|
|
self.visCon_obj:SetActive(false)
|
|
|
|
if not self.reward_list or #self.reward_list == 0 then
|
|
return
|
|
end
|
|
local reward_count = #self.reward_list
|
|
if reward_count == 1 then
|
|
self.draw_num_type = 1
|
|
self.againText_tmp.text = "再来1次"
|
|
elseif reward_count>1 and reward_count<=10 then
|
|
self.draw_num_type = 10
|
|
self.againText_tmp.text = "再来10次"
|
|
end
|
|
|
|
self:UpdateCost()
|
|
|
|
local function delay_method( )
|
|
self:UpdateRewardBoxes()
|
|
self.visCon_obj:SetActive(true)
|
|
end
|
|
setTimeout(delay_method, 0.6)
|
|
|
|
end
|
|
|
|
function TreasureHouseResultView:Reset( )--重置
|
|
self:StopAction()
|
|
if self.awarditem then
|
|
self.awarditem:StopAction()
|
|
self.awarditem:SetAwardItemVis(false)
|
|
end
|
|
self.Content.anchoredPosition = Vector2(self.start_pos_x,self.start_pos_y)
|
|
|
|
for k,v in pairs(self.item_list) do
|
|
v:SetAwardItemVis(false)
|
|
v:StopAction()
|
|
end
|
|
end
|
|
|
|
function TreasureHouseResultView:UpdateRewardBoxes()
|
|
local reward_count = #self.reward_list
|
|
|
|
if reward_count == 1 then
|
|
self.itemCon_obj:SetActive(true)
|
|
self.awarditem:SetData(self.reward_list[1],1)
|
|
self.awarditem:StartAction(1)
|
|
return
|
|
end
|
|
|
|
local x = 0
|
|
local y = 0
|
|
for i = 1, reward_count do
|
|
local item = self.item_list[i]
|
|
if not item then
|
|
item = TreasureHouseResultItem.New(self.Content)
|
|
self.item_list[i] = item
|
|
end
|
|
item:SetData(self.reward_list[i],i)
|
|
x = (84 + 42) * ((i-1)%5)+5
|
|
y = -(84 + 30)* math.floor((i-1)/5)-15
|
|
item:SetPosition(x,y)
|
|
if reward_count ~= 50 then
|
|
item:StartAction(i)
|
|
end
|
|
end
|
|
self.Content.sizeDelta = Vector2(0, (84 + 30)* math.floor(reward_count/5)+15)
|
|
if self.draw_num_type == 50 then
|
|
self.Viewport_img.raycastTarget = false
|
|
self:StartAction(self.start_pos_x,self.start_pos_y)
|
|
end
|
|
end
|
|
|
|
function TreasureHouseResultView:StartAction( start_pos_x,start_pos_y )
|
|
self.cur_x = start_pos_x
|
|
self.cur_y = start_pos_y
|
|
local count = 0
|
|
local function end_func( ... )
|
|
count = count + 1
|
|
if count >= 5 then
|
|
self.Viewport_img.raycastTarget = true
|
|
end
|
|
for i=1,10 do
|
|
-- self.item_list[(count-1)*10 + i]:SetAwardData()
|
|
self.item_list[(count-1)*10 + i]:StartAction(i)
|
|
end
|
|
end
|
|
local action = cc.Sequence.New(cc.CallFunc.New(end_func),
|
|
cc.DelayTime.New(0.8),cc.MoveTo.New(0.35,cur_x,self.cur_y + 230,0),cc.CallFunc.New(end_func)--262
|
|
,cc.DelayTime.New(0.8),cc.MoveTo.New(0.35,cur_x,self.cur_y + 230*2,0),cc.CallFunc.New(end_func)
|
|
,cc.DelayTime.New(0.8),cc.MoveTo.New(0.35,cur_x,self.cur_y + 230*3,0),cc.CallFunc.New(end_func)
|
|
,cc.DelayTime.New(0.8),cc.MoveTo.New(0.35,cur_x,self.cur_y + 230*4,0),cc.CallFunc.New(end_func)
|
|
)
|
|
cc.ActionManager:getInstance():addAction(action, self.Content.transform)
|
|
end
|
|
|
|
function TreasureHouseResultView:StopAction( )
|
|
if not self.is_loaded then return end
|
|
cc.ActionManager:getInstance():removeAllActionsFromTarget(self.Content.transform)
|
|
end
|
|
|
|
|
|
function TreasureHouseResultView:UpdateCost( )
|
|
if self.draw_num_type == 1 then
|
|
self.costPrice_tmp.text = "1"
|
|
elseif self.draw_num_type == 10 then
|
|
self.costPrice_tmp.text = "10"
|
|
end
|
|
local goods_icon = GoodsModel:getInstance():GetGoodsBasicByTypeId( TreasureHouseConst.TREASURE_HOUSE_TICKET_ID ).goods_icon
|
|
lua_resM:setOutsideImageSprite(self, self.costIcon_img, GameResPath.GetGoodsIcon(goods_icon),false)
|
|
end
|
|
|
|
function TreasureHouseResultView:LuckStart( )
|
|
local goods_num = GoodsModel:getInstance():GetTypeGoodsNum(TreasureHouseConst.TREASURE_HOUSE_TICKET_ID)
|
|
local need_show = goods_num < self.pool_type
|
|
local str = ""
|
|
local buy_price = GoodsModel:getInstance():GetGoodsPrice(TreasureHouseConst.TREASURE_HOUSE_TICKET_ID)
|
|
local cost_price = (self.pool_type - goods_num) * buy_price
|
|
local function close_callback( ... )
|
|
self:Close()
|
|
end
|
|
local function ok_callback( ... )
|
|
if GoodsModel:getInstance():IsJinEnough(cost_price) then
|
|
self.model:Fire(TreasureHouseConst.REQ_TREASURE_HOUSE_SCMD, 10401, self.pool_type)
|
|
else
|
|
local qc_data = {
|
|
price = cost_price,
|
|
close_callback = close_callback,
|
|
}
|
|
GlobalEventSystem:Fire(EventName.OPEN_RECHARGE_TIP_VIEW, true, qc_data)
|
|
end
|
|
end
|
|
local function toggle_function( flag )
|
|
self.model.not_show_treasure_house_tip = flag
|
|
end
|
|
local price_asset, price_icon = WordManager:GetCommonMoneyIcon(1)
|
|
local toggle_tip_data = {
|
|
gold_ab_res = price_asset,
|
|
gold_res = price_icon,
|
|
price = cost_price,
|
|
insufficientText = "",
|
|
priceText = string.format("<color=#fdffc2>%s</color> 补足所需的珍宝阁秘钥。",cost_price),
|
|
titleText = "提示",
|
|
ok_callback = ok_callback,
|
|
toggle_function = toggle_function,
|
|
is_complex_ok_callback = true,
|
|
jump_recharge_callback = close_callback,
|
|
}
|
|
if not self.model.not_show_treasure_house_tip and cost_price > 0 then
|
|
GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
|
|
else
|
|
ok_callback()
|
|
end
|
|
end
|
|
|
|
function TreasureHouseResultView:DestroySuccess( )
|
|
if self.awarditem then
|
|
self.awarditem:DeleteMe()
|
|
self.awarditem = nil
|
|
end
|
|
|
|
for i,item in pairs(self.item_list) do
|
|
item:DeleteMe()
|
|
item = nil
|
|
end
|
|
self.item_list = {}
|
|
|
|
self:StopAction()
|
|
|
|
end
|