|
DailyRechargeBaseView = DailyRechargeBaseView or BaseClass(BaseView)
|
|
local DailyRechargeBaseView = DailyRechargeBaseView
|
|
|
|
DailyRechargeBaseView.ShowType = {
|
|
Recharge = 1,
|
|
Pellet = 2,
|
|
}
|
|
|
|
DailyRechargeBaseView.Action = {-- 滚动动画参数
|
|
move_y = 0.25,--负数向下 正数向上 每帧移动的距离
|
|
delay_time = 2,--玩家手动操作以后 这个时间倒计时 播放动画
|
|
space = 15,--间距参数
|
|
chuanwen_delay_time = 10,--每条轮播传闻之间的间隔
|
|
chuanwen_play_time = 20,--每条轮播传闻从左滚到右的时间
|
|
chuanwen_start_time = 1.5,--轮播传闻启动时间
|
|
item_height = 70,
|
|
}
|
|
|
|
function DailyRechargeBaseView:__init()
|
|
self.base_file = "dailyRecharge"
|
|
self.layout_file = "DailyRechargeBaseView"
|
|
self.layer_name = "UI"
|
|
self.destroy_imm = true
|
|
self.change_scene_close = true
|
|
self.append_to_ctl_queue = true --是否要添加进界面堆栈
|
|
self.need_show_money = false --是否要显示顶部的金钱栏
|
|
-- self.is_set_zdepth = true
|
|
self.click_bg_toClose = false
|
|
------------------------
|
|
-- 一级全屏界面:
|
|
self.hide_maincancas = true --隐藏主界面
|
|
self.use_background = true --不一定显示遮罩
|
|
-- 二级界面:
|
|
-- self.hide_maincancas = false --是否需要隐藏主界面,看策划需求
|
|
-- self.use_background = true --需要遮罩
|
|
------------------------
|
|
|
|
self.model = RechargeActivityModel:getInstance()
|
|
self.show_type = DailyRechargeBaseView.ShowType.Recharge
|
|
self.award_list = {}
|
|
|
|
self.load_callback = function ()
|
|
self:LoadSuccess()
|
|
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 DailyRechargeBaseView:Open( sub_info,show_type )
|
|
if self.pellet_sub_view and self.pellet_sub_view.isGaming then
|
|
Message.show("弹球飞行中,请稍后...")
|
|
return
|
|
end
|
|
self.sub_type = sub_info or self.sub_type--子信息
|
|
self.show_type = show_type or self.show_type--展示类型
|
|
BaseView.Open(self)
|
|
end
|
|
|
|
function DailyRechargeBaseView:LoadSuccess()
|
|
local nodes = {
|
|
"container",
|
|
|
|
--以下节点全部归属于弹珠机
|
|
"pelletCon/big_title_1:obj", "pelletCon/btn_help:obj","pelletCon/bg_1:raw", "pelletCon/closeBtn:obj", "pelletCon/con_right/btn_switch/red_switch:obj",
|
|
"pelletCon/con_right/ScrollView_item:scroll", "pelletCon/con_right/ScrollView_item/Viewport/Content_item", "pelletCon/con_right/btn_switch:obj",
|
|
"pelletCon/con_right/lb_money_have:tmp:obj", "pelletCon/con_right/icon_cost:img:obj",
|
|
"pelletCon/btn_back:obj","pelletCon:obj"
|
|
}
|
|
self:GetChildren(nodes)
|
|
self:AddEvent()
|
|
|
|
lua_resM:setOutsideRawImage(self,self.bg_1_raw,GameResPath.GetViewBigBg("dailyRecharge_bg"),false)
|
|
self.money_view = self.money_view or self:CreateItem(UIMoneyView, self.transform, self.layer_name)
|
|
self.money_view:SetData()
|
|
self.money_view:SetPosition(50,ScreenHeight/2-25)
|
|
self.money_view:ChangeShowFlag( "DailyRechargePellet",self.model:GetPelletTicketId( self.sub_type ) )
|
|
|
|
self:SetRightReward()
|
|
end
|
|
|
|
function DailyRechargeBaseView:SetRightReward( )
|
|
if self.award_list and (not self.award_list[1]) then
|
|
-- 一次就好
|
|
local base_info = self.model:GetPelletBasicInfo()
|
|
if not base_info then return end
|
|
local award_cfg = self.model:GetPelletRewardCfg(true,true,base_info.round)
|
|
if award_cfg then
|
|
self:CreateAward(award_cfg)
|
|
end
|
|
end
|
|
end
|
|
|
|
function DailyRechargeBaseView:RefreshRed( )
|
|
self.red_switch_obj:SetActive(self.model:GetPelletRed())
|
|
end
|
|
|
|
function DailyRechargeBaseView:AddEvent()
|
|
local function call_back( target )
|
|
if target == self.closeBtn_obj then
|
|
--[[if self.pellet_sub_view and self.pellet_sub_view.isGaming then
|
|
Message.show("弹球飞行中,请稍后...")
|
|
return
|
|
end--]]
|
|
if self.show_type == DailyRechargeBaseView.ShowType.Pellet then
|
|
self.show_type = DailyRechargeBaseView.ShowType.Recharge
|
|
self:UpdateView()
|
|
else
|
|
self:Close()
|
|
end
|
|
elseif target == self.btn_help_obj then
|
|
EventSystem.Fire(GlobalEventSystem,EventName.OPEN_INSTRUCTION_VIEW, "33106")
|
|
elseif target == self.btn_switch_obj then
|
|
if self.pellet_sub_view and self.pellet_sub_view.isGaming then
|
|
Message.show("弹球飞行中,请稍后...")
|
|
return
|
|
end
|
|
self.show_type = DailyRechargeBaseView.ShowType.Pellet
|
|
self:UpdateView()
|
|
elseif target == self.btn_back_obj then
|
|
self.show_type = DailyRechargeBaseView.ShowType.Recharge
|
|
self:UpdateView()
|
|
end
|
|
end
|
|
AddClickEvent(self.btn_help_obj,call_back,false)
|
|
AddClickEvent(self.closeBtn_obj,call_back,false)
|
|
AddClickEvent(self.btn_switch_obj,call_back,false)
|
|
AddClickEvent(self.btn_back_obj,call_back,false)
|
|
|
|
local function onBagChange()
|
|
self:RefreshRightInfo()
|
|
end
|
|
self:BindEvent(GoodsModel:getInstance(), GoodsModel.CHANGE_BAGLIST, onBagChange)
|
|
|
|
local function stop_award_action( ... )
|
|
self:StopAwardAction()
|
|
self:StartAwardActionTimeDelay()
|
|
end
|
|
AddDragBeginEvent(self.ScrollView_item.gameObject,stop_award_action)
|
|
|
|
local function UPDATE_PELLET_INFO( )
|
|
self:SetRightReward()
|
|
end
|
|
self:BindEvent(RechargeActivityModel:getInstance(), RechargeActivityModel.UPDATE_PELLET_INFO, UPDATE_PELLET_INFO)
|
|
end
|
|
|
|
function DailyRechargeBaseView:OpenSuccess()
|
|
self:UpdateView()
|
|
end
|
|
|
|
function DailyRechargeBaseView:UpdateView()
|
|
self.pelletCon_obj:SetActive(self.show_type == DailyRechargeBaseView.ShowType.Pellet)
|
|
self:RefreshRightInfo()
|
|
|
|
if self.show_type == DailyRechargeBaseView.ShowType.Recharge then
|
|
self.recharge_sub_view = self.recharge_sub_view or self:CreateItem(DailyRechargeSubView, self.container, self.layer_name,self.sub_type)
|
|
self.recharge_sub_view:SetVisible( true )
|
|
self.recharge_sub_view:UpdateView()
|
|
local function close_call_back( ... )
|
|
self:Close()
|
|
end
|
|
local function pellet_call_back( ... )
|
|
if self.pellet_sub_view and self.pellet_sub_view.isGaming then
|
|
Message.show("弹球飞行中,请稍后...")
|
|
return
|
|
end
|
|
self.show_type = DailyRechargeBaseView.ShowType.Pellet
|
|
self:UpdateView()
|
|
end
|
|
self.recharge_sub_view:SetFuncCallBack(pellet_call_back,close_call_back)
|
|
if self.pellet_sub_view then
|
|
self.pellet_sub_view:SetVisible( false,true )
|
|
if self.pellet_sub_view.isGaming == true then
|
|
if not self.pellet_sub_view.break_game_mask_req then
|
|
local validation_data = CustomActivityModel:getInstance():GetPelletEventValidationData()
|
|
if validation_data.errcode == 1 then -- 验证通过,完成弹珠机
|
|
CustomActivityModel:getInstance():Fire(CustomActivityModel.PROTO_CCMD_EVENT, 33184, 0, self.sub_type)
|
|
end
|
|
end
|
|
self.pellet_sub_view:ResetGame()
|
|
end
|
|
end
|
|
else
|
|
self.pellet_sub_view = self.pellet_sub_view or self:CreateItem(DailyRechargePelletView, self.container, self.layer_name,self.sub_type)
|
|
self.pellet_sub_view:SetVisible( true,true )
|
|
self.pellet_sub_view:ResetGame()
|
|
if self.recharge_sub_view then
|
|
self.recharge_sub_view:SetVisible( false )
|
|
end
|
|
end
|
|
end
|
|
|
|
function DailyRechargeBaseView:RefreshRightInfo( )
|
|
local cost_id = self.model:GetPelletTicketId( self.sub_type )
|
|
local cost_basic = GoodsModel:getInstance():GetGoodsBasicByTypeId( cost_id )
|
|
local num = cost_id and GoodsModel:getInstance():GetTypeGoodsNum( cost_id ) or 0
|
|
if cost_basic and cost_basic.goods_icon then
|
|
lua_resM:setOutsideImageSprite(self,self.icon_cost_img,GameResPath.GetGoodsIcon(cost_basic.goods_icon),false)
|
|
end
|
|
self.lb_money_have_tmp.text = "x1"
|
|
self:RefreshRed()
|
|
end
|
|
|
|
function DailyRechargeBaseView:DestroySuccess( )
|
|
if self.pellet_sub_view and self.pellet_sub_view.isGaming == true then
|
|
--如果弹珠界面正在动画,而且还没去请求奖励,那么帮他完成
|
|
if not self.pellet_sub_view.break_game_mask_req then
|
|
local validation_data = CustomActivityModel:getInstance():GetPelletEventValidationData()
|
|
if validation_data.errcode == 1 then -- 验证通过,完成弹珠机
|
|
CustomActivityModel:getInstance():Fire(CustomActivityModel.PROTO_CCMD_EVENT, 33184, 0, self.sub_type)
|
|
end
|
|
end
|
|
end
|
|
|
|
if self.time_id then
|
|
GlobalTimerQuest:CancelQuest(self.time_id)
|
|
self.time_id = nil
|
|
end
|
|
|
|
if self.time_id1 then
|
|
GlobalTimerQuest:CancelQuest(self.time_id1)
|
|
self.time_id1 = nil
|
|
end
|
|
if self.ScrollView_item_scroll then
|
|
self.ScrollView_item_scroll.onValueChanged:RemoveAllListeners()
|
|
end
|
|
|
|
if self.award_list then
|
|
for k,v in pairs(self.award_list) do
|
|
UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, v)
|
|
end
|
|
self.award_list = {}
|
|
end
|
|
end
|
|
|
|
--------------------------------------------------------新动画start-------------------------
|
|
function DailyRechargeBaseView:StartAwardAction( )--开始滚动运动
|
|
local function func()
|
|
local new_pos_x,new_pos_y = GetAnchoredPosition(self.Content_item.transform)
|
|
SetAnchoredPosition(self.Content_item.transform,new_pos_x,new_pos_y + DailyRechargeBaseView.Action.move_y)
|
|
end
|
|
if not self.time_id then
|
|
self.time_id = GlobalTimerQuest:AddPeriodQuest(func,0.01,-1)
|
|
end
|
|
end
|
|
|
|
function DailyRechargeBaseView:StopAwardAction()--停止动画
|
|
if self.time_id then
|
|
GlobalTimerQuest:CancelQuest(self.time_id)
|
|
self.time_id = nil
|
|
end
|
|
end
|
|
|
|
function DailyRechargeBaseView:StartAwardActionTimeDelay( )--开启动画播放倒计时
|
|
if self.time_id1 then
|
|
GlobalTimerQuest:CancelQuest(self.time_id1)
|
|
self.time_id1 = nil
|
|
end
|
|
local function func()
|
|
self:StartAwardAction()
|
|
end
|
|
if not self.time_id1 then
|
|
self.time_id1 = GlobalTimerQuest:AddPeriodQuest(func,DailyRechargeBaseView.Action.delay_time)
|
|
end
|
|
end
|
|
|
|
function DailyRechargeBaseView:CreateAward( award_cfg )--创建图片节点
|
|
local show_list_data = award_cfg
|
|
local len = TableSize(show_list_data)
|
|
self.len = len > 20 and 20 or len
|
|
local offer_y = (59 + DailyRechargeBaseView.Action.space)
|
|
self.offer_y = offer_y
|
|
local width = len*offer_y
|
|
self.max_right = width/2
|
|
self.max_left = -width/2
|
|
|
|
for i = 1, len do
|
|
if not self.award_list[i] then
|
|
self.award_list[i] = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem,self.Content_item)
|
|
self.award_list[i]:SetPosition(-48,-(offer_y * i)+10)
|
|
self.award_list[i]:SetItemSize(59,59)
|
|
self.award_list[i]:SetIsAct(true)
|
|
end
|
|
self.award_list[i]:SetDataWithMapId(show_list_data[i][2], show_list_data[i][3], show_list_data[i][1])
|
|
end
|
|
self.all_hight = len*offer_y
|
|
self.Content_item.sizeDelta = Vector2(DailyRechargeBaseView.Action.item_height,self.all_hight)
|
|
self.vis_down = -self.all_hight/2--下可视极限
|
|
self.vis_up = self.all_hight/2--上可视极限
|
|
|
|
self.old_pos_x,self.old_pos_y = GetAnchoredPosition(self.Content_item.transform)
|
|
local callback = function( )
|
|
local _,new_pos_y = GetAnchoredPosition(self.Content_item.transform)
|
|
for k,v in pairs(self.award_list) do
|
|
if v.transform then
|
|
local abs_pos = v.transform:TransformPoint(Vector3.zero)
|
|
local pos = self.transform:InverseTransformPoint(Vector3.New(abs_pos.x, abs_pos.y, 0))
|
|
------------------------------------------无限滚动 到某一极限值 向左开头的item移到最后 向右最后的item移到最前
|
|
if new_pos_y < self.old_pos_y then--往下移动
|
|
if pos.y < self.vis_down then
|
|
local real_x,real_y = GetAnchoredPosition(v.transform)
|
|
real_y = real_y + self.all_hight
|
|
SetAnchoredPosition(v.transform, real_x,real_y)
|
|
end
|
|
else--往上动
|
|
if pos.y > self.vis_up then
|
|
local real_x,real_y = GetAnchoredPosition(v.transform)
|
|
real_y = real_y - self.all_hight
|
|
SetAnchoredPosition(v.transform, real_x,real_y)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
self.old_pos_y = new_pos_y
|
|
end
|
|
self.ScrollView_item_scroll.onValueChanged:AddListener(callback)
|
|
-------------------------
|
|
self:StartAwardAction()
|
|
end
|
|
--------------------------------------------------------新动画end-------------------------
|
|
|
|
function DailyRechargeBaseView:HideChangeCall( show_status )
|
|
if self.show_type == DailyRechargeBaseView.ShowType.Pellet then
|
|
if self.pellet_sub_view then
|
|
--如果弹珠界面正在动画,而且还没去请求奖励,那么帮他完成
|
|
if self.pellet_sub_view.isGaming == true and (not self.pellet_sub_view.break_game_mask_req) then
|
|
local validation_data = CustomActivityModel:getInstance():GetPelletEventValidationData()
|
|
if validation_data.errcode == 1 then -- 验证通过,完成弹珠机
|
|
CustomActivityModel:getInstance():Fire(CustomActivityModel.PROTO_CCMD_EVENT, 33184, 0, self.sub_type)
|
|
end
|
|
end
|
|
self.pellet_sub_view:ResetGame()
|
|
end
|
|
end
|
|
end
|
|
|
|
function DailyRechargeBaseView:CancelHide( )
|
|
BaseView.CancelHide(self)
|
|
if self.is_loaded then
|
|
if self.show_type == DailyRechargeBaseView.ShowType.Recharge then
|
|
self.recharge_sub_view = self.recharge_sub_view or self:CreateItem(DailyRechargeSubView, self.container, self.layer_name,self.sub_type)
|
|
self.recharge_sub_view:SetVisible( true )
|
|
self.recharge_sub_view:UpdateView()
|
|
end
|
|
end
|
|
end
|