NewerTaskMainView = NewerTaskMainView or BaseClass(BaseView) local NewerTaskMainView = NewerTaskMainView function NewerTaskMainView:__init() self.base_file = "newerTask" self.layout_file = "NewerTaskMainView" self.layer_name = "UI" self.destroy_imm = true self.use_background = true self.change_scene_close = true self.append_to_ctl_queue = true --是否要添加进界面堆栈 -- self.hide_maincancas = true self.need_show_money = false --是否要显示顶部的金钱栏 self.close_fog = true self.ignore_use_anim = true self.use_show_anim = true self.use_hide_anim = false -- self.blur_activity_bg = true -- self:AddPreLoadList("newerTask", {"NewerTaskItem"}) self.model = NewerTaskModel:getInstance() self.item_list = {} self.award_list = {} self.is_first_show = false --是否首次展示 self.load_callback = function () self:LoadSuccess() self:AddEvent() end self.open_callback = function ( ) local help_vo = GuideModel:getInstance():GetCurHelpTypeAndStep() if help_vo then if (help_vo.help_type == HelpType.NEWER_TASK_AWARD_UNLOCK and help_vo.step == 2) then if help_vo.task_id == 10090 then self.is_first_show = true self.close_need_anim = true end GlobalEventSystem:Fire(EventName.STOP_AUTO_DO_TASK) end end self:OpenSuccess() end self.destroy_callback = function ( ) self:DestroySuccess() end end function NewerTaskMainView:Open( auto_do_task ) self.auto_do_task = auto_do_task BaseView.Open(self) end function NewerTaskMainView:Close( ) self:OnCloseGuide() if not self.close_need_anim then self.use_hide_anim = true BaseView.Close(self) return end local target_pos = MainUIController.Instance:GetNewerTaskMotoPos( ) target_pos.x = target_pos.x + 35 target_pos.y = target_pos.y - 20 local target_time = 0.3 local target_scale = Vector3(0.1,0.1,0.1) local function call_back( ) BaseView.Close(self) end TweenLite.to(self, self.transform, TweenLite.UiAnimationType.POS, target_pos, target_time) TweenLite.to(self, self.transform, TweenLite.UiAnimationType.SCALE, target_scale, target_time, call_back) TweenLite.to(self, self.bg.transform, TweenLite.UiAnimationType.POS, target_pos, target_time) TweenLite.to(self, self.bg.transform, TweenLite.UiAnimationType.SCALE, target_scale, target_time) self.model_parent_obj:SetActive(false) end function NewerTaskMainView:LoadSuccess() self.nodes = { "bg:raw", "close_btn:obj", "content", "model_parent:obj:raw", "title:img","line_cont:obj", "effect_1", "effect_3", "grey_img_1:obj", "grey_img_2:obj", "grey_img_3:obj", "grey_img_4:obj", } self:GetChildren(self.nodes) lua_resM:setOutsideRawImage(self,self.bg_raw,GameResPath.GetViewBigBg("newer_task_bg"),false) self:AddUIEffect("ui_motuoyindao01", self.effect_1, self.layer_name, nil, 1, true,nil,nil,nil,nil,nil,UIPartical.RenderingOther_List.UI) self:AddUIEffect("ui_motuoyindao03", self.effect_3, self.layer_name, {x=-177.7,y=-165.5}, {x=1,y=1,z=1}, true,nil,nil,nil,nil,nil,UIPartical.RenderingOther_List.UIBackward) -- self.line_list = {} -- for i=1,4 do -- self.line_list[i] = self.line_list[i] or {} -- local res_name = "line_cont/line_" .. i -- self.line_list[i].line_obj = self:GetChild(res_name).gameObject -- self.line_list[i].line_img = self:GetChild(res_name):GetComponent("Image") -- end local function bg_back_func( ) -- 2021.7.14 界面修改为无模型 -- if self.background_wnd and self.background_wnd_raw then -- self:MoveUIToBack(self.background_wnd) -- self:MoveUIToBack(self.bg) -- end end if self.background_wnd then bg_back_func() else self.bg_back_func = bg_back_func end end function NewerTaskMainView:AddEvent() local function on_click( obj ) if obj == self.close_btn_obj then self:Close() end end AddClickEvent(self.close_btn_obj, on_click) local function on_award_update( ) --摩托车切换到翅膀,也要播放首次动画 local cur_type = self.model:GetCurShowType() if self.cur_type and cur_type ~= self.cur_type then self.is_first_show = true end self:UpdateView() end self:BindEvent(GlobalEventSystem, NewerTaskConst.UPDATE_AWARD_INFO, on_award_update) local function onGuideTrigger() self:OnTriggerGuide() end self:BindEvent(GlobalEventSystem, EventName.TRIGGER_GUIDE_TYPE, onGuideTrigger) end function NewerTaskMainView:OpenSuccess() self:UpdateView() end function NewerTaskMainView:UpdateView() local info = self.model:GetCurShowInfo() if IsTableEmpty(info) then return end self.info = info --标题 local cur_type = self.model:GetCurShowType() self.cur_type = cur_type local res_name = NewerTaskConst.TitleResName[cur_type] lua_resM:setImageSprite(self,self.title_img, "newerTask_asset", res_name) --模型 self:OnUpdateModel(cur_type) --线条 -- self.line_cont_obj:SetActive(not self.is_first_show) self.line_cont_obj:SetActive(true) -- for i=1,4 do -- local cfg = NewerTaskConst.LineInfo[i] -- SetAnchoredPosition(self.line_list[i].line_obj.transform, cfg.anchor_pos.x, cfg.anchor_pos.y) -- SetSizeDelta(self.line_list[i].line_obj.transform, cfg.size.x, cfg.size.y) -- end --进度 -- self:OnUpdateProgress(cur_type) --解锁item/奖励图标 for i=1,4 do if not self.item_list[i] then self.item_list[i] = NewerTaskItem.New(self.content) end self.item_list[i]:SetVisible(not self.is_first_show) self.item_list[i]:SetData(info[i], i, self.is_first_show, self.auto_do_task) local pos = NewerTaskConst.ItemPos[i] self.item_list[i]:SetPosition(pos.x, pos.y) -- 刷新主界面拼图状态 local is_finished = self.model:IsAwardFinish(info[i].type, info[i].task_id) if is_finished then self["grey_img_" .. i .. "_obj"]:SetActive(false) else self["grey_img_" .. i .. "_obj"]:SetActive(true) end -- if not self.award_list[i] then -- self.award_list[i] = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.award_cont) -- end -- local award_vo = stringtotable(info[i].awards) -- award_vo = award_vo and award_vo[1] or {} -- local typeId, lock = GoodsModel:getInstance():GetMappingTypeId(award_vo[1], award_vo[2]) -- self.award_list[i]:SetData(typeId, award_vo[3], nil, nil, lock) -- self.award_list[i]:SetItemSize(78, 78) -- self.award_list[i]:SetVisible(true) -- self.award_list[i]:SetPosition(237*(i-1), 0) end --首次打开的动画 self:OnUpdateAnimation() end function NewerTaskMainView:OnUpdateModel( cur_type ) if self.is_first_show then return end if self.last_model_type and self.last_model_type == cur_type then return end self.last_model_type = cur_type -- local model_res = NewerTaskConst.ModelImgRes[cur_type] -- lua_resM:setOutsideRawImage(self,self.model_img_raw,GameResPath.GetViewBigBg(model_res),true) local res_id, res_type = 1001, self.cur_type local temp_rotate = self.cur_type == 1 and 70 or 0 local temp_scale = self.cur_type == 1 and 210 or 360 local temp_position = self.cur_type == 1 and Vector3(-88,-67.5,725) or Vector3(0,110,0) local res_data = { father_node = self, transform = self.model_parent, fashion_type = res_type + 1000, figure_id = res_id, ui_model_type = UIModelCommon.ModelType.BackModel, can_rotate = false, action_name_list = {"show"}, scale = temp_scale, rotate = temp_rotate, position = temp_position, } FuncOpenModel:getInstance():SetModelRes(res_data) end function NewerTaskMainView:OnUpdateProgress( cur_type ) local cur_progress = self.model:GetProgress() or 0 self.pro_bar_img.fillAmount = cur_progress/100 end function NewerTaskMainView:OnUpdateAnimation( ) if not self.is_first_show then return end self.is_first_show = false self:CancelAnimationTimer() self.anim_step = 1 self.anim_pass_time = 0 local step = 0.1 local function on_animation( ) self.anim_pass_time = self.anim_pass_time + step if self.anim_step == 1 then self.anim_step = 2 self:OnAnimModel() elseif self.anim_pass_time > 0.1 and self.anim_step == 2 then self.anim_step = 3 self:OnAnimItem(1) elseif self.anim_pass_time > 0.3 and self.anim_step == 3 then self.anim_step = 4 self:OnAnimItem(2) elseif self.anim_pass_time > 0.5 and self.anim_step == 4 then self.anim_step = 5 self:OnAnimItem(3) elseif self.anim_pass_time > 0.7 and self.anim_step == 5 then self.anim_step = 6 self:OnAnimItem(4) elseif self.anim_pass_time > 0.9 and self.anim_step == 6 then self.anim_step = 7 self:OnAnimImageModel() elseif self.anim_pass_time > 1.1 and self.anim_step == 7 then self.anim_step = 8 self:OnLineShow() self:OnAnimUnLock() self:CancelAnimationTimer() end end self.animation_timer = GlobalTimerQuest:AddPeriodQuest(on_animation, step, -1) end function NewerTaskMainView:CancelAnimationTimer( ) if self.animation_timer then GlobalTimerQuest:CancelQuest(self.animation_timer) self.animation_timer = nil end end function NewerTaskMainView:OnAnimModel( ) local res_id, res_type = 1001, self.cur_type local temp_rotate = self.cur_type == 1 and 70 or 0 local temp_scale = self.cur_type == 1 and 210 or 360 local temp_position = self.cur_type == 1 and Vector3(-88,-67.5,725) or Vector3(0,110,0) local res_data = { father_node = self, transform = self.model_parent, fashion_type = res_type + 1000, figure_id = res_id, ui_model_type = UIModelCommon.ModelType.BackModel, can_rotate = false, action_name_list = {"show2","show"}, scale = temp_scale, rotate = temp_rotate, position = temp_position, } FuncOpenModel:getInstance():SetModelRes(res_data) end function NewerTaskMainView:OnAnimItem(index) if self.item_list[index] then self.item_list[index]:OnAnimation() end end function NewerTaskMainView:OnAnimImageModel( ) -- local model_res = NewerTaskConst.ModelImgRes[self.cur_type] -- lua_resM:setOutsideRawImage(self,self.model_img_raw,GameResPath.GetViewBigBg(model_res),true) -- self.model_parent_obj:SetActive(false) end function NewerTaskMainView:OnLineShow( ) self.line_cont_obj:SetActive(true) end function NewerTaskMainView:OnAnimUnLock( ) if self.item_list[1] then self.item_list[1]:OnUnLockHelper() end end function NewerTaskMainView:OnTriggerGuide( ) if IsNull(self.gameObject) then return end local help_vo = GuideModel:getInstance():GetCurHelpTypeAndStep() if help_vo then if help_vo.help_type == HelpType.NEWER_TASK_AWARD_UNLOCK and help_vo.step == 3 then local button = self.close_btn_obj if button then local function call_back() self:Close() end GlobalEventSystem:Fire(EventName.OPEN_GUIDE_PROMPT_VIEW,button.transform,self.transform,call_back,help_vo) end end end end function NewerTaskMainView:OnCloseGuide( ) local help_vo, help_type, step = GuideModel:getInstance():GetCurHelpTypeAndStep() if help_vo then if help_type == HelpType.NEWER_TASK_AWARD_UNLOCK then if step and step == 3 then GlobalEventSystem:Fire(EventName.FINISH_CURRENT_HELP_STEP,help_vo) GlobalEventSystem:Fire(EventName.FORCE_TO_DO_TASK) end end end GlobalEventSystem:Fire(EventName.CLOSE_GUIDE_PROMPT_VIEW) if self.auto_do_task then GlobalEventSystem:Fire(EventName.FORCE_TO_DO_TASK) end end function NewerTaskMainView:DestroySuccess( ) for k,v in pairs(self.item_list) do v:DeleteMe() v = nil end self.item_list = {} for k,v in pairs(self.award_list) do UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, v) v = nil end self.award_list = {} self:CancelAnimationTimer() end