源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

155 lines
6.1 KiB

-- <*
-- @Author: Saber
-- @Description: 藏宝图:普通藏宝图奖励界面
-- *>
TreasureMapNormalRollView = TreasureMapNormalRollView or BaseClass(BaseView)
local TreasureMapNormalRollView = TreasureMapNormalRollView
function TreasureMapNormalRollView:__init()
self.base_file = "treasureMap"
self.layout_file = "TreasureMapNormalRollView"
self.layer_name = "Activity"
self.destroy_imm = true
self.use_background = true --全屏界面默认使用这个参数,非全屏界面自行设置
self.hide_maincancas = false --全屏界面需要隐藏主UI
self.change_scene_close = true --是否切换场景时关闭(弹出界面使用)
self.append_to_ctl_queue = false --是否要添加进界面堆栈
self.model = TreasureMapModel:getInstance()
self.shine_time = 4
self.show_delay_end_time = 0.3
self.auto_close_time = 10 -- 几秒后自动关闭
self.load_callback = function ()
self:LoadSuccess()
self:AddEvent()
end
self.open_callback = function ( )
self:UpdateView()
end
self.destroy_callback = function ( )
self:DestroySuccess()
end
end
function TreasureMapNormalRollView:Open(reward_data)
self.reward_data = reward_data
BaseView.Open(self)
end
function TreasureMapNormalRollView:LoadSuccess()
local nodes = {
"bg:raw", "close_btn:obj",
"icon_con:cg",
"light:imgex",
"comfirm_btn:obj",
"auto_close:tmp",
}
self:GetChildren(nodes)
lua_resM:setOutsideRawImage(self, self.bg_raw, GameResPath.GetTreasureMapImage("tm_nor_bg"))
self.awardItem = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.icon_con)
self.awardItem:SetItemSize(78, 78)
self.awardItem:SetAnchoredPosition(0, 0)
end
function TreasureMapNormalRollView:AddEvent()
local function click_event(target)
if target == self.close_btn_obj then -- 关闭按钮
self:Close()
elseif target == self.comfirm_btn_obj then -- 确认按钮
self:Close()
end
end
AddClickEvent(self.close_btn_obj, click_event)
AddClickEvent(self.comfirm_btn_obj, click_event)
end
function TreasureMapNormalRollView:UpdateView()
self:UpdateBasicData()
self:StartTreasureOpenAnim()
end
-- 加载基础数据
function TreasureMapNormalRollView:UpdateBasicData( )
local reward_cfg = Config.Treasuremaprewards[self.reward_data.reward_id]
local reward = reward_cfg and stringtotable(reward_cfg.rewards)[1] or {}
local goods_Id, lock = GoodsModel:getInstance():GetMappingTypeId(reward[1] , reward[2])
self.awardItem:SetData(goods_Id, reward[3], nil, nil, lock)
end
-- 打开的宝箱做出动画表现
function TreasureMapNormalRollView:StartTreasureOpenAnim( )
self.is_animating = true
local show_delay_end = cc.DelayTime.New(self.show_delay_end_time)
-- 光束闪烁表现
local function action_light_show_alpha_func(percent)
self.light_imgex.alpha = percent
end
local function action_light_hide_alpha_func(percent)
self.light_imgex.alpha = 1 - percent
end
-- local total_shine_time = 0
local action_tb = {}
-- for k = 1, self.shine_time do
-- math.randomseed(os.time() + 2 * k)
-- local random_time = math.random(3, 15) * 0.01
-- action_tb[#action_tb+1] = cc.CustomUpdate.New(random_time, action_light_show_alpha_func)
-- total_shine_time = total_shine_time + random_time
-- math.randomseed(os.time() + 2 * k + 1)
-- random_time = math.random(3, 15) * 0.01
-- action_tb[#action_tb+1] = cc.CustomUpdate.New(random_time, action_light_hide_alpha_func)
-- total_shine_time = total_shine_time + random_time
-- end
action_tb[#action_tb+1] = show_delay_end
local action_shine_show_final = cc.CustomUpdate.New(0.5, action_light_show_alpha_func)
action_tb[#action_tb+1] = action_shine_show_final
local action_light = cc.Sequence.New(unpack(action_tb))
cc.ActionManager:getInstance():addAction(action_light, self.light)
-- 奖励淡出表现
local function icon_con_alpha_func(percent)
self.icon_con_cg.alpha = percent
end
local function animation_end_func() -- 动画结束之后,弹出倒计时和关闭按钮
self.is_animating = false
self.close_btn_obj:SetActive(true)
self.comfirm_btn_obj:SetActive(true)
self:StartAutoCloseTimer()
end
local action_icon_con_show = cc.CustomUpdate.New(0.5, icon_con_alpha_func)
-- local action_icon_con = cc.Sequence.New(cc.DelayTime.New(total_shine_time + self.show_delay_end_time),
-- action_icon_con_show, cc.CallFunc.New(animation_end_func))
local action_icon_con = cc.Sequence.New(show_delay_end, action_icon_con_show, cc.CallFunc.New(animation_end_func))
cc.ActionManager:getInstance():addAction(action_icon_con, self.icon_con)
end
-- 自动关闭倒计时
function TreasureMapNormalRollView:StartAutoCloseTimer( )
local end_time = TimeUtil:getServerTime() + self.auto_close_time
local function auto_close_time_func()
local left_time = end_time - TimeUtil:getServerTime()
if left_time > 0 then
self.auto_close_tmp.text = string.format("<color=%s>%s</color> 秒后自动关闭", ColorUtil.GREEN_DARK, left_time)
else
self:Close()
end
end
if not self.auto_close_time_func_id then
self.auto_close_time_func_id = GlobalTimerQuest:AddPeriodQuest(auto_close_time_func, 0.5, -1)
end
end
function TreasureMapNormalRollView:DestroySuccess( )
if self.awardItem then
UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, self.awardItem)
self.awardItem = nil
end
if self.auto_close_time_func_id then
GlobalTimerQuest:CancelQuest(self.auto_close_time_func_id)
self.auto_close_time_func_id = nil
end
cc.ActionManager:getInstance():removeAllActionsFromTarget(self.light)
cc.ActionManager:getInstance():removeAllActionsFromTarget(self.icon_con)
self.model._check_tm_tips = TreasureMapConst.Normal
self.model:CheckTreasureTipUseViewOpen()
end