-- @Author: HWR -- @Description: 风采弹出提示界面 WardrobeTipsView = WardrobeTipsView or BaseClass(BaseView) local WardrobeTipsView = WardrobeTipsView function WardrobeTipsView:__init() self.base_file = "wardrobe" self.layout_file = "WardrobeTipsView" self.layer_name = "Top" self.destroy_imm = true self.use_background = false --全屏界面默认使用这个参数 self.is_animating = false -- 是否在动画中 self.hide_time = 2 -- n秒后播放界面隐藏动画 self.receive_flag = nil -- 读取完界面数据后,用于发送领取协议的关键键值 self.model = WardrobeModel:getInstance() self.model.tip_view_show = true 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 WardrobeTipsView:Open(tips_data) self.tips_data = tips_data BaseView.Open(self) end --重用界面,5秒后再销毁 function WardrobeTipsView:ResetViewInfo(tips_data) self.tips_data = tips_data self.transform.anchoredPosition = Vector2(-3.5, 61.5) self.gameObject:SetActive(true) if self.delay_closeview_id then TimerQuest.CancelQuest(GlobalTimerQuest,self.delay_closeview_id) self.delay_closeview_id = nil end self:UpdateView() -- 更新数据 self:StartCloseTimer() -- 开始对界面的关闭进行计时 self:OpenAnimation() -- 播放打开界面的动画 end function WardrobeTipsView:LoadSuccess() local nodes = { "go_btn/go_btn_text:tmp", "close_timer:tmp", "go_btn:obj", "type_name_text:tmp", "icon_small_image:img", "wardrobe_con/wardrobe_text:tmp", "wardrobe_con/wardrobe_up_text:tmp", "name_text:tmp", "wardrobe_con:obj", } self:GetChildren(nodes) self.canvasGroup = self.gameObject:GetComponent("CanvasGroup") self.transform.anchoredPosition = Vector2(-3.5, 61.5) end function WardrobeTipsView:AddEvent() local function click_event(target) self:ReceiveFunc() self:ClearHideTimer() self:AutoCloseFunc() if self.is_unlock then if self.is_unlock == 1 then else GlobalEventSystem:Fire(WardrobeConst.OPEN_WARDROBE_MAIN_VIEW, WardrobeConst.TabId.SHOP, self.is_unlock + 1) end end end AddClickEvent(self.go_btn_obj, click_event) end function WardrobeTipsView:OpenSuccess() self:UpdateView() self:StartCloseTimer() self:OpenAnimation() -- 播放打开界面的动画 end function WardrobeTipsView:UpdateView() self.is_unlock = nil if self.tips_data.is_unlock then--如果是解锁商城的就有按钮 self.go_btn_obj:SetActive(true) self.name_text_tmp.text = "" local cfg = Config.Wardrobeopen for i,v in ipairs(cfg) do if v.condition <= self.tips_data.stage then self.is_unlock = v.store_id end end if self.is_unlock == 1 then self.go_btn_text_tmp.text = "确定" else self.go_btn_text_tmp.text = "前往" end self.type_name_text_tmp.text = string.format("%s %s", HtmlColorTxt("解锁", ColorUtil.YELLOW_DARK), cfg[self.is_unlock].store_name) SetAnchoredPositionX(self.wardrobe_con, 44) else self.go_btn_obj:SetActive(false) self.type_name_text_tmp.text = string.format("%s %s", HtmlColorTxt("解锁", ColorUtil.YELLOW_DARK), self.model:GetWardrobeTypeName(self.tips_data.type)) if self.tips_data.type == 9 or self.tips_data.type == 10 then--进阶和伙伴要去拿阶数 self.name_text_tmp.text = string.format("%s %s阶", self.model:GetWardrobeTypeName(self.tips_data.type), self.tips_data.color) else local goods_name = GoodsModel:getInstance():getGoodsName(self.tips_data.id, false) if SubStringGetTotalIndex(goods_name) > 4 then goods_name = SubStringUTF8(goods_name, 1, 4) .. "..." end self.name_text_tmp.text = goods_name end SetAnchoredPositionX(self.wardrobe_con, 110) end self.wardrobe_up_text_tmp.text = self.tips_data.up_value self.wardrobe_text_tmp.text = string.format("风采值 %s", HtmlColorTxt(self.tips_data.sum_wardrobe_value, ColorUtil.YELLOW_DARK)) local res_name = string.format("wardrobe_level%s", self.tips_data.stage) lua_resM:setOutsideImageSprite(self, self.icon_small_image_img, GameResPath.GetWardrobeImage(res_name), true) if self.delay_id then GlobalTimerQuest:CancelQuest(self.delay_id) self.delay_id = nil end local function delay_method( ) SetSizeDeltaX(self.wardrobe_text, self.wardrobe_text_tmp.preferredWidth+1) end self.delay_id = setTimeout(delay_method, 0.01) end -- 开始界面关闭的倒计时 function WardrobeTipsView:StartCloseTimer() self:ClearHideTimer() local end_time = self.hide_time + TimeUtil:getServerTime() local function hide_timer() local left_time = end_time - TimeUtil:getServerTime() if not self.tips_data.is_unlock then self.close_timer_tmp.text = "" else self.close_timer_tmp.text = left_time >= 0 and string.format("(%ss后自动关闭)", ColorUtil.GREEN_DARK, math.ceil(left_time+1)) or "" end if left_time < 0 then self:ClearHideTimer() self:AutoCloseFunc() self:TimeOverFunc() end end hide_timer() self.hide_timer_id = GlobalTimerQuest:AddPeriodQuest(hide_timer, 0.1, -1) -- 设置动画标志量 self.is_animating = true end -- 点击按钮后的响应 function WardrobeTipsView:ReceiveFunc( ) end -- 倒计时结束的响应 function WardrobeTipsView:TimeOverFunc( ) end function WardrobeTipsView:ClearHideTimer( ) if self.hide_timer_id then GlobalTimerQuest:CancelQuest(self.hide_timer_id) self.hide_timer_id = nil end end function WardrobeTipsView:AutoCloseFunc( ) local function callback() self:ClearHideTimer() self.gameObject:SetActive(false) local function delay_closeview( ) BaseView.Close(self) end self.delay_closeview_id = setTimeout(delay_closeview, 5) -- 设置动画标志量 self.is_animating = false -- 查看是否还没展示完成界面 self.model:Fire(WardrobeConst.OPEN_WARDROBE_TIP_VIEW, true) end self:CloseAnimation(callback) end -- 播放打开界面的动画 function WardrobeTipsView:OpenAnimation() self.canvasGroup.alpha = 0 if self.alpha_anim_id then TweenLite.Stop(self.alpha_anim_id) self.alpha_anim_id = nil end self.alpha_anim_id = TweenLite.to(self, self.canvasGroup, TweenLite.UiAnimationType.ALPHA, 1, 0.2) end -- 关闭(隐藏)界面的动画 function WardrobeTipsView:CloseAnimation(callback) self.canvasGroup.alpha = 1 if self.alpha_anim_id then TweenLite.Stop(self.alpha_anim_id) self.alpha_anim_id = nil end self.alpha_anim_id = TweenLite.to(self, self.canvasGroup,TweenLite.UiAnimationType.ALPHA, 0, 0.5) local pos_y = self.transform.anchoredPosition.y + 100 if self.pos_id then TweenLite.Stop(self.pos_id) self.pos_id = nil end self.pos_id = TweenLite.to(self, self.transform, TweenLite.UiAnimationType.ANCHORED_POSY, pos_y, 0.5, callback) end function WardrobeTipsView:DestroySuccess( ) self.model.tip_view_show = false self:ClearHideTimer() if self.delay_closeview_id then TimerQuest.CancelQuest(GlobalTimerQuest,self.delay_closeview_id) self.delay_closeview_id = nil end if self.alpha_anim_id then TweenLite.Stop(self.alpha_anim_id) self.alpha_anim_id = nil end if self.pos_id then TweenLite.Stop(self.pos_id) self.pos_id = nil end if self.delay_id then GlobalTimerQuest:CancelQuest(self.delay_id) self.delay_id = nil end end