--通用兑换展示界面 ComDialogueShowView = ComDialogueShowView or BaseClass(BaseView) local ComDialogueShowView = ComDialogueShowView ComDialogueShowView.Type = { DunNomal = 1,--副本进入 DunWave = 2,--波数类型 DunForever = 3,--副本进入永久类型 } function ComDialogueShowView:__init() self.base_file = "uiComponent" self.layout_file = "ComDialogueShowView" self.layer_name = "Top" self.mask_open_sound = true self.mask_close_sound = true self.use_background = false self.destroy_imm = true self.change_scene_close = false self.append_to_ctl_queue = false --是否要添加进界面堆栈 self.need_show_money = false --是否要显示顶部的金钱栏 self.model = MainUIModel:getInstance() self.width = 408--预制宽度 self.origin_x = 0--起始X坐标 self.delay_time = 5--默认时间 self.tween_lite_list = {} self.load_callback = function () self:LoadSuccess() self:AddEvent() end self.open_callback = function ( ) self:OpenSuccess() end self.destroy_callback = function ( ) self:DestroySuccess() end end function ComDialogueShowView:DestroySuccess() self:StopDialogueAction() end function ComDialogueShowView:LoadSuccess() local nodes = { "con/nameBg:img", "con/desc:tmp", "con/bg:img", "con:obj", "con/name:tmp", "con/headImg:img", } self:GetChildren(nodes) --创建时默认将alpha置为0隐藏 self.con_obj:GetComponent("CanvasGroup").alpha = 0 lua_resM:setImageSprite(self, self.nameBg_img, "comDialogue_asset", "com_dialogue_name_bg") lua_resM:setImageSprite(self, self.bg_img, "comDialogue_asset", "com_dialogue_bg") if self.need_refreshData then self:UpdateView( ) end self.transform.anchoredPosition = Vector2(ClientConfig.iphone_x_offset_left, -121) end function ComDialogueShowView:AddEvent() -- local function onBtnClickHandler(target,x,y) -- if target == self.mask_bg_obj then--关闭 -- self:Close() -- end -- end -- AddClickEvent(self.mask_bg_obj,onBtnClickHandler,1) local function onOrientationChange() self.transform.anchoredPosition = Vector2(ClientConfig.iphone_x_offset_left, -121) end self:BindEvent(GlobalEventSystem, EventName.ORIENTATION_DID_CHANGE, onOrientationChange) -- local data = { -- head_type = 1, -- desc = "当时我很机智,我说我不会游泳 我妈妈会游泳,再说你也会!", -- head_name = "赤骨光子", -- hide_time = 5, -- dalay_time = 3, -- is_task_type = false,--是否是任务配置类型 如果是要隐藏功能预告界面 -- } local function onShowDialogueView(data)--展示对话界面 if not self.is_loaded or not data or not data.head_type then return end data.desc = ChuanWenManager:getInstance():FormatColorTag2(data.desc)--这边要解析一下颜色 self:StopDialogueAction() local function dalayFunc( ... ) if data.is_task_type then GlobalEventSystem:Fire(EventName.HIDE_LEFT_MIDDLE_VIEW, true, MainUIModel.MAIN_MODE) end self:StartDialogueAction(data) end self.delay_timer_id = setTimeout(dalayFunc,data.dalay_time) end self:BindEvent(GlobalEventSystem, EventName.SHOW_COM_DIALOGUE_SHOW_VIEW, onShowDialogueView) local function stopDialogueFunc( ... ) self:StopDialogueAction() end self:BindEvent(GlobalEventSystem, EventName.STOP_COM_DIALOGUE_SHOW_VIEW, onShowDialogueView) local function changeSceneViewFuc( ... )--切换场景就要隐藏 self:StopDialogueAction() end self:BindEvent(GlobalEventSystem, SceneEventType.SCENE_CHANGED, changeSceneViewFuc) end --data.delay_time--关闭时间 --data.title_res--标题资源 --data.title_ab_name--标题资源ab包路径 --data.award = {kind,type_id,goods_num,goods_vo} --data.col_num = 6 -- 每行展示的个数 function ComDialogueShowView:Open( ) BaseView.Open(self) end function ComDialogueShowView:OpenSuccess( ) self:UpdateView() end function ComDialogueShowView:UpdateView( ) if self.is_loaded then self.need_refreshData = false else self.need_refreshData = true return end if not self.data then return end end --开始对话展示 function ComDialogueShowView:StartDialogueAction( data ) lua_resM:setImageSprite(self, self.headImg_img, "comDialogue_asset", "com_dialogue_head_"..data.head_type, true) self.name_tmp.text = data.head_name self.desc_tmp.text = data.desc self:UpdateTime(data) local function anim_end_func( ... ) end local pos = data.pos or Vector3(0,0,0) self.tween_lite_list[1] = TweenLite.to(self, self.con.transform, TweenLite.UiAnimationType.POS, pos, 0.3) self.tween_lite_list[2] = TweenLite.to(self, self.con, TweenLite.UiAnimationType.ALPHA_ALL, 1, 0.3,anim_end_func) -- 通知动画开始 GlobalEventSystem:Fire(EventName.START_COM_DIALOGUE_SHOW_ANIM) self.model:SetDialogueActionFlag(true) end function ComDialogueShowView:HideDialogueAction( data ) self.con_obj:GetComponent("CanvasGroup").alpha = 1 SetAnchoredPosition(self.con,0,0) local function anim_end_func( ... )--动画执行完要吧功能预告展示回来 self:StopDialogueAction(data) end local pos = Vector3(-self.width,0,0) self.tween_lite_list[3] = TweenLite.to(self, self.con.transform, TweenLite.UiAnimationType.POS, pos, 0.3,anim_end_func) self.tween_lite_list[4] = TweenLite.to(self, self.con, TweenLite.UiAnimationType.ALPHA_ALL, 0, 0.3,anim_end_func) end --停止对话展示 function ComDialogueShowView:StopDialogueAction( data ) if data and data.is_task_type then GlobalEventSystem:Fire(EventName.HIDE_LEFT_MIDDLE_VIEW, false, MainUIModel.MAIN_MODE) end -- 对话展示结束后通知绑定了这个事件的界面用于做其他的展示逻辑 self.model:SetDialogueActionFlag(false) GlobalEventSystem:Fire(EventName.FINISHED_COM_DIALOGUE_SHOW_ANIM) self.con_obj:GetComponent("CanvasGroup").alpha = 0 SetAnchoredPosition(self.con,-self.width,0) if self.timer_id then GlobalTimerQuest:CancelQuest(self.timer_id) self.timer_id = nil end if self.delay_timer_id then GlobalTimerQuest:CancelQuest(self.delay_timer_id) self.delay_timer_id = nil end for i,v in ipairs(self.tween_lite_list) do if v then TweenLite.Stop(v) v = nil end end end function ComDialogueShowView:UpdateTime( data ) local time = data.hide_time or self.delay_time local function countDown() if self._use_delete_method then return end if not data then return end time = time - 1 if time > 0 then else self:HideDialogueAction(data) end end countDown() if not self.timer_id then self.timer_id = GlobalTimerQuest:AddPeriodQuest(countDown,1) end end