|
|
- CapsuleEggResultView = CapsuleEggResultView or BaseClass(BaseView)
- local CapsuleEggResultView = CapsuleEggResultView
-
- function CapsuleEggResultView:__init()
- self.base_file = "capsuleEgg"
- self.layout_file = "CapsuleEggResultView"
- 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.is_set_zdepth = true
-
- self.model = CapsuleEggModel:getInstance()
-
- CustomActivityModel:getInstance():SetGoodsCanFly(false)
-
- self.delay_show_time_list = {}
- self.delay_show_scale_list = {}
-
- self.item_list = {}
- self.start_pos_x = 0
- self.start_pos_y = 0
-
- self.draw_num_type = 0 --结算数量类型 1|单抽 10|10连 50|50连
-
- self.last_draw_time = 0
-
- 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 CapsuleEggResultView:Open(pool_type)
- self.pool_type = pool_type
- BaseView.Open(self)
- end
-
- function CapsuleEggResultView:LoadSuccess()
- local nodes = {
- "resultBg:img:obj",
- "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",
- "scoreNum:tmp",
- "effectCon:obj",
- "eggCon:obj",
- "eggCon/egg6:obj", "eggCon/egg7:obj", "eggCon/egg4:obj", "eggCon/egg3:obj",
- "eggCon/egg8:obj", "eggCon/egg5:obj", "eggCon/egg10:obj", "eggCon/egg9:obj",
- "eggCon/egg1:obj", "eggCon/egg2:obj",
-
- "visCon/lightEffect",
- "skipBtn:obj",
- }
- self:GetChildren(nodes)
-
- SetLocalPosition(self.transform, 0, 0,-1000)
-
- self.visCon_obj:SetActive(false)
-
- local function bg_back_func( ... )
- self.confirmBtn_obj:SetActive(true)
- self.againBtn_obj:SetActive(true)
- self.itemCon_obj:SetActive(false)
- self.awarditem = CapsuleEggAwardItem.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
-
- self.resultBg_obj:SetActive(false)
-
-
- SetAnchoredPosition(self.effectCon,CapsuleEggConst.DrawEffectPos.pos_x,CapsuleEggConst.DrawEffectPos.pos_y)
-
- SetAnchoredPosition(self.lightEffect,0,-40)
-
- -- self:AddUIEffect("ui_jihuoxinxitong01", self.lightEffect, self.layer_name, nil, 1.2, true,nil,nil, nil, nil,nil)
-
- for i=1,10 do
- SetAnchoredPosition(self["egg"..i],CapsuleEggConst.DrawEggPos[i].pos_x,CapsuleEggConst.DrawEggPos[i].pos_y)
- end
- end
-
- function CapsuleEggResultView:AddEvent()
- local on_click = function ( click_obj )
- if self.confirmBtn_obj == click_obj then--关闭界面
- self:Close()
- elseif self.againBtn_obj == click_obj then--再来
- if TimeUtil:getServerTimeMs()/1000 - self.last_draw_time > 1 then
- self.last_draw_time = TimeUtil:getServerTimeMs()/1000
- self:LuckStart()
- end
- elseif self.skipBtn_obj == click_obj then--跳过动画
- self:DoDrawEndFun()
- end
- end
- AddClickEvent(self.confirmBtn_obj, on_click)
- AddClickEvent(self.againBtn_obj, on_click)
- AddClickEvent(self.skipBtn_obj, on_click)
-
-
- local function on_update_result()
- if not self.is_loaded then return end
- self.resultBg_obj:SetActive(true)
- self:UpdateRewardBoxes()
- self.visCon_obj:SetActive(true)
- end
- self:BindEvent(self.model,CapsuleEggConst.REFRESH_CAPSULE_EGG_RESULT_VIEW_AFTER_BIG_REWARD,on_update_result)
- end
-
- function CapsuleEggResultView:OpenSuccess()
- self:UpdateView(self.pool_type)
- end
-
- function CapsuleEggResultView:UpdateView(pool_type)
- self.pool_type = pool_type
-
- if self.is_loaded then
- self.need_refreshData = false
- else
- self.need_refreshData = true
- return
- end
-
- local debug_test = false
- if debug_test then
- local temp_data = {}
- local tt = {}
- tt.reward_cfg_id = 13
- tt.gtype_id = 230003
- tt.goods_num = 1
- for i=1,50 do
- table.insert(temp_data,tt)
- end
- self.reward_list = temp_data
- else
- self.reward_list = self.model:GetNowRewardList()
- end
-
- 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
-
- local max_gear = self.model:GetRewardMaxGear(self.reward_list)
-
- -- lua_resM:setOutsideImageSprite(self, self.capsuleImg_img, GameResPath.GetCapsuleEggRes("capsule_egg_result_open_"..max_gear))
- -- self.shine_obj:SetActive(true)
- -- self.capsuleImg_obj:SetActive(true)
-
- if reward_count == 1 then
- self.draw_num_type = 1
- self.againText_tmp.text = "再来1次"
- self.scoreNum_tmp.text = 1
- elseif reward_count>1 and reward_count<=10 then
- self.draw_num_type = 10
- self.againText_tmp.text = "再来10次"
- self.scoreNum_tmp.text = 10
- elseif reward_count>10 and reward_count<=50 then
- self.draw_num_type = 50
- self.againText_tmp.text = "再来50次"
- self.scoreNum_tmp.text = 50
- end
-
- self:UpdateCost()
-
-
- if self.delay_show_act then
- TimerQuest.CancelQuest(GlobalTimerQuest, self.delay_show_act)
- self.delay_show_act = nil
- end
-
- for k,v in pairs(self.delay_show_time_list) do
- if v then
- TimerQuest.CancelQuest(GlobalTimerQuest, v)
- end
- end
- self.delay_show_time_list = {}
- for k,v in pairs(self.delay_show_scale_list) do
- if v then
- TimerQuest.CancelQuest(GlobalTimerQuest, v)
- end
- end
- self.delay_show_scale_list = {}
-
- self.resultBg_obj:SetActive(false)
-
- local function delay_method( )
- self:DoDrawEndFun()
- end
- self.delay_show_act = setTimeout(delay_method, 4)
-
- local effect_res = self.draw_num_type == 1 and "ui_zhuanhundanchou" or "ui_zhuanhunshilian"
- self:AddUIEffect(effect_res, self.effectCon, self.layer_name, nil, 2, false, nil, false,nil,nil,1)
-
- local egg_num = self.draw_num_type == 1 and 1 or 10
-
- if self.draw_num_type == 1 then
- SetAnchoredPosition(self["egg1"],0,-50)
- else
- SetAnchoredPosition(self["egg1"],CapsuleEggConst.DrawEggPos[1].pos_x,CapsuleEggConst.DrawEggPos[1].pos_y)
- end
-
- for i=1,10 do
- SetLocalScale(self["egg"..i],0,0,0)
- end
-
- for i=1,egg_num do
- local function delay_method_2( )
- local res_data = {
- layer_name = "Activity",
- father_node = self,
- transform = self["egg"..i],
- fashion_type = FuncOpenModel.TypeId.OtherGoods,
- figure_id = "model_otheregg_1",
- ui_model_type = UIModelCommon.ModelType.Model,
- position = CapsuleEggConst.DrawEggPos[i].model_pos,
- rotate = CapsuleEggConst.DrawEggPos[i].model_rotate,
- scale = 160,
- }
- FuncOpenModel:getInstance():SetModelRes(res_data)
- local function delay_show_scale( )
- SetLocalScale(self["egg"..i],1,1,1)
- end
- self.delay_show_scale_list[i] = setTimeout(delay_show_scale, 0.1)
- end
- self.delay_show_time_list[i] = setTimeout(delay_method_2, CapsuleEggConst.DrawEggPos[i].delay_show_time)
- end
-
- self.skipBtn_obj:SetActive(true)
- end
-
- function CapsuleEggResultView:DoDrawEndFun( )
- if self.delay_show_act then
- TimerQuest.CancelQuest(GlobalTimerQuest, self.delay_show_act)
- self.delay_show_act = nil
- end
- self:AddUIEffect("ui_jihuoxinxitong01", self.lightEffect, self.layer_name, nil, 1.2, true,nil,nil, nil, nil,nil)
- local show_big_reward_list = self.model:GetBigRewardList(self.reward_list)
- if #show_big_reward_list ~= 0 then
- self.model:Fire(CapsuleEggConst.OPEN_CAPSULE_EGG_BIG_REWARD_VIEW,show_big_reward_list)
- else
- self.model:Fire(CapsuleEggConst.REFRESH_CAPSULE_EGG_RESULT_VIEW_AFTER_BIG_REWARD)
- end
-
- lua_resM:clearRoleMode(self)
- self:ClearUIEffect(self.effectCon)
-
- self.skipBtn_obj:SetActive(false)
- end
-
- function CapsuleEggResultView:Reset( )--重置
- self:ClearUIEffect(self.lightEffect)
- self:ClearUIEffect(self.effectCon)
- 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
-
- self.skipBtn_obj:SetActive(false)
- end
-
- function CapsuleEggResultView: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 = CapsuleEggAwardItem.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 CapsuleEggResultView: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 CapsuleEggResultView:StopAction( )
- if not self.is_loaded then return end
- cc.ActionManager:getInstance():removeAllActionsFromTarget(self.Content.transform)
- end
-
-
- function CapsuleEggResultView:UpdateCost( )
- local costIcon_res = 0
- local cost_ticket_num_list = self.model:GetCostTicketNumList()
-
- local buff_kind = OperateActivityModel.MaterialSubmitBuffKind.LUCKY_OFFER --是否存在活动加成buff 挑战次数+1
- local buff_cfg,buff_info = OperateActivityModel:getInstance():GetMaterialBuffInfoByKind(buff_kind)
- -- buff_cfg = {discount = 80,data = 1}
- -- buff_info = {etime = TimeUtil:getServerTime( )+300,used = {{kdata = 10,vdata=0}}}
- self.ten_cost_num = 9
- local have_time = buff_cfg and buff_cfg.data or 0
- local show_offer_obj = false
- self.ten_buff_offer = 100
- if buff_cfg and buff_info then
- local sec = buff_info.etime - TimeUtil:getServerTime( )
- if sec > 0 then
- for k,v in pairs(buff_info.used) do
- if v.kdata == 10 then--十连还有次数
- have_time = have_time - v.vdata
- break
- end
- end
- if have_time > 0 then
- show_offer_obj = true
- self.ten_buff_offer = buff_cfg.discount
- end
- end
- end
-
-
- if self.draw_num_type == 1 then
- costIcon_res = self.model:GetCostTicketGTypeId(self.pool_type,1)
- if cost_ticket_num_list[self.pool_type][1] < 1 then
- self.costPrice_tmp.text = string.format("<%s>%s</color>/1", ColorUtil.RED_DARK, cost_ticket_num_list[self.pool_type][1])
- else
- self.costPrice_tmp.text = string.format("<%s>%s</color>/1", ColorUtil.GREEN_DARK, cost_ticket_num_list[self.pool_type][1])
- end
- elseif self.draw_num_type == 10 then
- if self.model:GetCostTicketNumList()[self.pool_type][2] > 0 then
- costIcon_res = self.model:GetCostTicketGTypeId(self.pool_type,10)
- if cost_ticket_num_list[self.pool_type][2] < 1 then
- self.costPrice_tmp.text = string.format("<%s>%s</color>/1", ColorUtil.RED_DARK, cost_ticket_num_list[self.pool_type][2])
- else
- self.costPrice_tmp.text = string.format("<%s>%s</color>/1", ColorUtil.GREEN_DARK, cost_ticket_num_list[self.pool_type][2])
- end
- else
- local cost_num = math.floor(9*self.ten_buff_offer/100 + 0.5) or 9
- costIcon_res = self.model:GetCostTicketGTypeId(self.pool_type,1)
- if cost_ticket_num_list[self.pool_type][1] < cost_num then
- self.costPrice_tmp.text = string.format("<%s>%s</color>/%s", ColorUtil.RED_DARK, cost_ticket_num_list[self.pool_type][1],cost_num)
- else
- self.costPrice_tmp.text = string.format("<%s>%s</color>/%s", ColorUtil.GREEN_DARK, cost_ticket_num_list[self.pool_type][1],cost_num)
- end
- end
- elseif self.draw_num_type == 50 then
- if self.model:GetCostTicketNumList()[self.pool_type][3] > 0 then
- costIcon_res = self.model:GetCostTicketGTypeId(self.pool_type,50)
- if cost_ticket_num_list[self.pool_type][3] < 1 then
- self.costPrice_tmp.text = string.format("<%s>%s</color>/1", ColorUtil.RED_DARK, cost_ticket_num_list[self.pool_type][3])
- else
- self.costPrice_tmp.text = string.format("<%s>%s</color>/1", ColorUtil.GREEN_DARK, cost_ticket_num_list[self.pool_type][3])
- end
- else
- costIcon_res = self.model:GetCostTicketGTypeId(self.pool_type,1)
- if cost_ticket_num_list[self.pool_type][1] < 45 then
- self.costPrice_tmp.text = string.format("<%s>%s</color>/45", ColorUtil.RED_DARK, cost_ticket_num_list[self.pool_type][1])
- else
- self.costPrice_tmp.text = string.format("<%s>%s</color>/45", ColorUtil.GREEN_DARK, cost_ticket_num_list[self.pool_type][1])
- end
- end
- end
- --print("==WQ==:CapsuleEggResultView [start:239] costIcon_res:", costIcon_res)
- lua_resM:setOutsideImageSprite(self, self.costIcon_img, GameResPath.GetGoodsIcon(costIcon_res),true)
- end
-
-
-
- function CapsuleEggResultView:LuckStart( )
- local ticket_num_list = self.model:GetCostTicketNumList()
-
- local price_asset, price_icon = WordManager:GetCommonMoneyIcon(1)
- local cost_price = 0
-
- local tickets_goods_type_id = 102305
- if self.pool_type == 1 then
- tickets_goods_type_id = 102305
- elseif self.pool_type == 2 then
- tickets_goods_type_id = 102308
- elseif self.pool_type == 3 then
- tickets_goods_type_id = 102311
- end
-
- local tickets_price = Config.Goodsprice[tickets_goods_type_id].price
-
- if self.draw_num_type == 1 then
- if ticket_num_list[self.pool_type][1] >= 1 then--有单抽券直接抽
- self.model:Fire(CapsuleEggConst.REQUEST_CCMD_EVENT,17003,self.pool_type,self.draw_num_type,0)
- return
- else--补齐
- cost_price = tickets_price
- end
- elseif self.draw_num_type == 10 then
- if ticket_num_list[self.pool_type][2] >= 1 then
- self.model:Fire(CapsuleEggConst.REQUEST_CCMD_EVENT,17003,self.pool_type,self.draw_num_type,0)
- return
- else
- local ten_need_num = math.floor(self.ten_cost_num*self.ten_buff_offer/100 + 0.5)--折扣完后要四舍五入
- if ticket_num_list[self.pool_type][1] >= ten_need_num then
- self.model:Fire(CapsuleEggConst.REQUEST_CCMD_EVENT,17003,self.pool_type,self.draw_num_type,0)
- return
- else
- cost_price = (ten_need_num-ticket_num_list[self.pool_type][1])*tickets_price
- end
- end
- elseif self.draw_num_type == 50 then
- if ticket_num_list[self.pool_type][3] >= 1 then
- self.model:Fire(CapsuleEggConst.REQUEST_CCMD_EVENT,17003,self.pool_type,self.draw_num_type,0)
- return
- else
- if ticket_num_list[self.pool_type][1] >= 45 then
- self.model:Fire(CapsuleEggConst.REQUEST_CCMD_EVENT,17003,self.pool_type,self.draw_num_type,0)
- return
- else
- cost_price = (45-ticket_num_list[self.pool_type][1])*tickets_price
- end
- end
- end
-
- local function close_callback( ... )
- self:Close()
- end
-
- local function ok_callback()
- if GoodsModel:getInstance():IsJinEnough(cost_price) then
- self.model:Fire(CapsuleEggConst.REQUEST_CCMD_EVENT,17003,self.pool_type,self.draw_num_type,0)
- return
- 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._again_draw_no_double_check = flag
- end
- 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._again_draw_no_double_check and cost_price ~= 0 then
- GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
- else
- ok_callback()
- end
- end
-
- function CapsuleEggResultView:DestroySuccess( )
- if self.delay_show_act then
- TimerQuest.CancelQuest(GlobalTimerQuest, self.delay_show_act)
- self.delay_show_act = nil
- end
-
- for k,v in pairs(self.delay_show_time_list) do
- if v then
- TimerQuest.CancelQuest(GlobalTimerQuest, v)
- end
- end
- self.delay_show_time_list = {}
- for k,v in pairs(self.delay_show_scale_list) do
- if v then
- TimerQuest.CancelQuest(GlobalTimerQuest, v)
- end
- end
- self.delay_show_scale_list = {}
-
- 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()
-
- self:ClearUIEffect(self.lightEffect)
- self:ClearUIEffect(self.effectCon)
-
- CustomActivityModel:getInstance():SetGoodsCanFly(true)
-
- end
|