-- <*
|
|
-- @Author: Saber
|
|
-- @Description: 藏宝图系统:高级藏宝图抽奖界面
|
|
-- *>
|
|
TreasureMapAdvanceRollView = TreasureMapAdvanceRollView or BaseClass(BaseView)
|
|
local TreasureMapAdvanceRollView = TreasureMapAdvanceRollView
|
|
local cos = math.cos
|
|
local sin = math.sin
|
|
local rad = math.rad
|
|
local deg = math.deg
|
|
local Quaternion = Quaternion
|
|
local TweenFunc = TweenFunc
|
|
local ClampAngleType2 = ClampAngleType2
|
|
|
|
function TreasureMapAdvanceRollView:__init()
|
|
self.base_file = "treasureMap"
|
|
self.layout_file = "TreasureMapAdvanceRollView"
|
|
self.layer_name = "UI"
|
|
self.destroy_imm = true
|
|
self.use_background = true --全屏界面默认使用这个参数,非全屏界面自行设置
|
|
self.hide_maincancas = false --全屏界面需要隐藏主UI
|
|
self.change_scene_close = true --是否切换场景时关闭(弹出界面使用)
|
|
self.auto_close_time = 10
|
|
self.model = TreasureMapModel:getInstance()
|
|
|
|
self.item_pos_radius = 190 -- 抽奖节点分布在容器内的分布半径
|
|
self.roll_item_list = {}
|
|
|
|
self.load_callback = function ()
|
|
self:LoadSuccess()
|
|
self:AddEvent()
|
|
end
|
|
self.open_callback = function ( )
|
|
self:UpdateView()
|
|
end
|
|
self.destroy_callback = function ( )
|
|
self:DestroySuccess()
|
|
self.model._tm_can_fly_goods = true -- 解除道具飞入表现限制
|
|
end
|
|
end
|
|
|
|
function TreasureMapAdvanceRollView:Open(vo)
|
|
self.result_data = vo
|
|
BaseView.Open(self)
|
|
end
|
|
|
|
function TreasureMapAdvanceRollView:LoadSuccess()
|
|
local nodes = {
|
|
"adv_role:raw", "bg:raw", -- 背景图相关
|
|
"item_con", -- 奖励节点
|
|
"selected:obj",
|
|
"close_btn:obj",
|
|
"pro_fill:img", "feedback_btn:obj", "feedback_red:obj",
|
|
"pin",
|
|
"roll_btn:obj:img", "roll_btn/roll_btn_lb:tmp",
|
|
"preview_btn:obj",
|
|
"tip_bg:obj", "tip_lb:tmp",
|
|
}
|
|
self:GetChildren(nodes)
|
|
-- 暂时屏蔽再次使用高级藏宝图的按钮
|
|
self.roll_btn_img.raycastTarget = false
|
|
-- 加载背景图
|
|
lua_resM:setOutsideRawImage(self, self.adv_role_raw, GameResPath.GetRoleBg("tm_adv_role_336_608"), false)
|
|
lua_resM:setOutsideRawImage(self, self.bg_raw, GameResPath.GetViewBigBg("tm_adv_bg"), false)
|
|
end
|
|
|
|
function TreasureMapAdvanceRollView:AddEvent()
|
|
local function click_event(target)
|
|
if target == self.close_btn_obj then -- 关闭界面
|
|
self.model._check_tm_tips = TreasureMapConst.Advance
|
|
self:Close()
|
|
elseif target == self.roll_btn_obj then -- 再次摇奖(重新开始高级藏宝图寻宝)
|
|
self:OnRollBtnClicked()
|
|
elseif target == self.preview_btn_obj then -- 查看奖励预览
|
|
self.model:Fire(TreasureMapConst.OPEN_REWARD_PERVIEW_VIEW, true, TreasureMapConst.Advance)
|
|
elseif target == self.feedback_btn_obj then -- 查看遗宝界面(月度次数奖励)
|
|
self.model:Fire(TreasureMapConst.OPEN_FEEDBACK_VIEW, true)
|
|
end
|
|
end
|
|
AddClickEvent(self.close_btn_obj, click_event)
|
|
AddClickEvent(self.roll_btn_obj, click_event)
|
|
AddClickEvent(self.preview_btn_obj, click_event)
|
|
AddClickEvent(self.feedback_btn_obj, click_event)
|
|
|
|
local function updateFeedbackRed(red_type)
|
|
if red_type and red_type == TreasureMapConst.RedType.MonthReward then
|
|
self:UpdateFeedbackRed()
|
|
end
|
|
end
|
|
self:BindEvent(self.model, TreasureMapConst.UPDATE_TREASUREMAP_RED, updateFeedbackRed)
|
|
|
|
local function updateMonthTimesData()
|
|
self:UpdateMonthTimesData()
|
|
end
|
|
self:BindEvent(self.model, TreasureMapConst.UPDATE_MONTH_TIMES_DATA, updateMonthTimesData)
|
|
end
|
|
|
|
function TreasureMapAdvanceRollView:UpdateView()
|
|
self:UpdateMonthTimesData()
|
|
self:UpdateRewardItems()
|
|
self:StartRollItemAnim()
|
|
self:UpdateFeedbackRed()
|
|
end
|
|
|
|
-- 更新界面基础数据
|
|
function TreasureMapAdvanceRollView:UpdateMonthTimesData( )
|
|
-- 更新遗宝进度
|
|
local momth_times_data = self.model:GetAdvTreasureMapMonthTimesData()
|
|
local month_times_reward_cfg = self.model:GetTreasureMapMonthTimesRewardCfg()
|
|
local percentage = 0
|
|
if momth_times_data and month_times_reward_cfg then
|
|
local times = momth_times_data.times
|
|
local cfg_num = #month_times_reward_cfg
|
|
local v = nil
|
|
for k = 1, cfg_num do
|
|
v = month_times_reward_cfg[k]
|
|
-- 满足了本次的领取条件但 未领取,或者超过了最高档位所需次数
|
|
if v[1] <= times and (not momth_times_data.receive_list[v[1]] or k == cfg_num) then
|
|
percentage = 1
|
|
break
|
|
end
|
|
if v[1] > times then -- 这个档位的次数都没有满足,就获取百分比
|
|
percentage = times / v[1]
|
|
break
|
|
end
|
|
end
|
|
end
|
|
self.pro_fill_img.fillAmount = percentage
|
|
self:FeedbackBtnAction(percentage >= 1)
|
|
end
|
|
|
|
function TreasureMapAdvanceRollView:FeedbackBtnAction(show)
|
|
cc.ActionManager:getInstance():removeAllActionsFromTarget(self.feedback_btn)
|
|
if show then
|
|
local action1 = cc.ScaleTo.New(0.3, 0.95, 0.95, 0.95)
|
|
local action2 = cc.ScaleTo.New(0.3, 1.05, 1.05, 1.05)
|
|
local action = cc.RepeatForever.New(cc.Sequence.New(action1, action2))
|
|
cc.ActionManager:getInstance():addAction(action, self.feedback_btn)
|
|
else
|
|
SetLocalScale(self.feedback_btn, 1, 1, 1)
|
|
end
|
|
end
|
|
|
|
-- 创建奖励道具
|
|
function TreasureMapAdvanceRollView:UpdateRewardItems( )
|
|
self.reward_item_data = self.model:GetRollRewardItemData(self.result_data)
|
|
-- self.target_index = target_index
|
|
local item_num = TableSize(self.reward_item_data)
|
|
local angle_offset = 360 / item_num
|
|
local start_angle = 90 - angle_offset/2
|
|
local rad_start_angle
|
|
local item
|
|
for k, v in ipairs(self.reward_item_data) do
|
|
item = self.roll_item_list[k]
|
|
if not item then
|
|
item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.item_con)
|
|
item:SetItemSize(78, 78)
|
|
self.roll_item_list[k] = item
|
|
end
|
|
item:SetVisible(true)
|
|
rad_start_angle = rad(start_angle)
|
|
-- 坐标设置:y正向为起点顺时针分布
|
|
item:SetAnchoredPosition(self.item_pos_radius * cos(rad_start_angle) + 280 - 39, self.item_pos_radius * sin(rad_start_angle) - 280 + 39)
|
|
local reward_data = stringtotable(v.rewards)[1]
|
|
local typeId, lock = GoodsModel:getInstance():GetMappingTypeId(reward_data[1], reward_data[2])
|
|
item:SetData(typeId, reward_data[3], nil, nil, lock)
|
|
item._angle = start_angle
|
|
-- 变换角度
|
|
start_angle = ClampAngleType2(start_angle - angle_offset)
|
|
end
|
|
end
|
|
|
|
-- 开始抽奖动画
|
|
function TreasureMapAdvanceRollView:StartRollItemAnim()
|
|
cc.ActionManager:getInstance():removeAllActionsFromTarget(self.pin)
|
|
local angel = self:AnimRotateAngle()
|
|
local anim_end_fun = function()
|
|
self.is_animating = false
|
|
|
|
self.selected_obj:SetActive(true)
|
|
local selected_angel = math.ceil(angel / 36) * 36
|
|
self.selected.localRotation = Quaternion.Euler(0, 0, selected_angel)
|
|
|
|
self:ShowGetReward()
|
|
self:AutoCloseTimer()
|
|
-- self.roll_btn_lb_tmp.text = "再次寻宝"
|
|
end
|
|
local start_angel = self.pin.localEulerAngles.z
|
|
start_angel = ClampAngleType2(start_angel)
|
|
|
|
self.selected_obj:SetActive(false)
|
|
-- local selected_angel = self.selected.localEulerAngles.z
|
|
-- 播放动画
|
|
local pin_action_callback = function(percent)
|
|
local ratio = self:AnimPercentageAmount(percent)
|
|
local temp_angle = angel * ratio
|
|
local temp_angle2 = start_angel * (1-ratio)
|
|
self.pin.localRotation = Quaternion.Euler(0, 0, temp_angle2 + temp_angle)
|
|
-- 更新选中节点的旋转角度
|
|
-- local temp_spin_angel = ClampAngleType2(temp_angle2 + temp_angle)
|
|
-- temp_spin_angel = math.ceil(temp_spin_angel / 36) * 36
|
|
-- if temp_spin_angel ~= selected_angel then
|
|
-- selected_angel = temp_spin_angel
|
|
-- self.selected.localRotation = Quaternion.Euler(0, 0, selected_angel)
|
|
-- end
|
|
end
|
|
local anim_time = self.model:GetTreasureMapKvCfg("advanced_map_speed").value
|
|
local spin_action = cc.CustomUpdate.New(anim_time, pin_action_callback)
|
|
spin_action = cc.Sequence.New(spin_action, cc.CallFunc.New(anim_end_fun))
|
|
cc.ActionManager:getInstance():addAction(spin_action, self.pin)
|
|
-- 修改文本
|
|
self.roll_btn_lb_tmp.text = "挖宝中..."
|
|
self.is_animating = true
|
|
-- 清掉藏宝图数据
|
|
self.model:SetCurrentTreasureData(nil)
|
|
end
|
|
|
|
function TreasureMapAdvanceRollView:AnimPercentageAmount(ratio)
|
|
local div = TreasureMapConst.SpeedUpRatio
|
|
if ratio < div then
|
|
return div * TweenFunc.easeInQuint(ratio/div)
|
|
else
|
|
return (1-div) * TweenFunc.easeOutQuint((ratio-div)/(1-div)) + div
|
|
end
|
|
end
|
|
|
|
-- 获取抽中道具所在的角度,并推算出一个n圈的终点角度
|
|
function TreasureMapAdvanceRollView:AnimRotateAngle()
|
|
local target_angle
|
|
self.target_index = 1
|
|
for k, v in ipairs(self.roll_item_list) do
|
|
if self.reward_item_data[k].reward_id == self.result_data.reward_id then -- 获取抽中档位所在的节点的角度,并做一个减少90度的偏移,求得旋转指针最后的角度
|
|
self.target_index = k
|
|
target_angle = v._angle - 90
|
|
break
|
|
end
|
|
end
|
|
-- print("Saber:TreasureMapAdvanceRollView [204] self.target_index: ",self.target_index)
|
|
target_angle = target_angle + math.random(-15, 15) -- 在节点范围内进行一个合理的偏移
|
|
-- 起始角度必须先将指针的角度归零
|
|
-- 默认转10圈,然后停在目标角度范围内
|
|
local angle = TreasureMapConst.AnimRollTime * -360 + target_angle
|
|
return angle
|
|
end
|
|
|
|
-- 展示获得道具的表现
|
|
function TreasureMapAdvanceRollView:ShowGetReward( )
|
|
--触发快捷使用
|
|
OperateActivityModel:getInstance():Fire(OperateActivityModel.QUIK_USE, true)
|
|
--道具飞背包
|
|
local goods_data = stringtotable(self.reward_item_data[self.target_index].rewards)[1]
|
|
local goods_Id, lock = GoodsModel:getInstance():GetMappingTypeId(goods_data[1] , goods_data[2])
|
|
local goods_fly_data = {[1] = goods_Id}
|
|
if TableSize(goods_fly_data) > 0 then
|
|
MainUIModel:getInstance():PlayGoodsFlyList(goods_fly_data)
|
|
end
|
|
--飘字
|
|
local goods_fly_data = {
|
|
[1] = {
|
|
goods_type_id = goods_Id,
|
|
num = goods_data[3],
|
|
}
|
|
}
|
|
if TableSize(goods_fly_data) > 0 then
|
|
MainUIModel:getInstance():AddFloatInfo(goods_fly_data, true)
|
|
end
|
|
end
|
|
|
|
function TreasureMapAdvanceRollView:UpdateFeedbackRed( )
|
|
self.feedback_red_obj:SetActive(self.model:GetTreasureMapRed(TreasureMapConst.RedType.MonthReward))
|
|
end
|
|
|
|
function TreasureMapAdvanceRollView:AutoCloseTimer( )
|
|
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.roll_btn_lb_tmp.text = string.format("%s 秒后自动关闭", left_time)
|
|
else
|
|
self.model._check_tm_tips = TreasureMapConst.Advance
|
|
self:Close()
|
|
end
|
|
end
|
|
auto_close_time_func()
|
|
self:ClearAutoCloseTimer()
|
|
self.auto_close_time_func_id = GlobalTimerQuest:AddPeriodQuest(auto_close_time_func, 0.5, -1)
|
|
end
|
|
|
|
function TreasureMapAdvanceRollView:ClearAutoCloseTimer( )
|
|
if self.auto_close_time_func_id then
|
|
GlobalTimerQuest:CancelQuest(self.auto_close_time_func_id)
|
|
self.auto_close_time_func_id = nil
|
|
end
|
|
end
|
|
|
|
-- 再次摇奖按钮
|
|
function TreasureMapAdvanceRollView:OnRollBtnClicked( )
|
|
if self.is_animating then
|
|
Message.show("挖宝中...", "fault")
|
|
return
|
|
end
|
|
local goods_id = TreasureMapConst.GoodId[TreasureMapConst.Advance]
|
|
local left_goods_num = GoodsModel:getInstance():GetTypeGoodsNum(goods_id)
|
|
if left_goods_num <= 0 then -- 提示购买高级藏宝图
|
|
self.model:BuyTreasureMapItemFunc(TreasureMapConst.Advance)
|
|
-- ShopModel:getInstance():Fire(ShopModel.OPEN_SHOP_BUY_TIP_VIEW, goods_id, 1)
|
|
else
|
|
local function ok( ... )
|
|
self.model._check_tm_tips = false
|
|
self:Close()
|
|
self.model:Fire(TreasureMapConst.REQUEST_CCMD_EVENT, 42401, TreasureMapConst.Advance)
|
|
end
|
|
local ask_str = "是否再次进行高级寻宝?"
|
|
Alert.show(ask_str,Alert.Type.Two,ok,nil,"确定","取消")
|
|
end
|
|
end
|
|
|
|
function TreasureMapAdvanceRollView:DestroySuccess( )
|
|
cc.ActionManager:getInstance():removeAllActionsFromTarget(self.feedback_btn)
|
|
if self.is_animating then
|
|
self:ShowGetReward()
|
|
end
|
|
cc.ActionManager:getInstance():addAction(spin_action, self.pin)
|
|
|
|
for k, v in pairs(self.roll_item_list) do
|
|
UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, v)
|
|
end
|
|
self:ClearAutoCloseTimer()
|
|
self.roll_item_list = nil
|
|
self.model:CheckTreasureTipUseViewOpen()
|
|
end
|