--[[@------------------------------------------------------------------ @description:简单文本弹窗 @author:wyb ----------------------------------------------------------------------]] UISimpleToolTips = UISimpleToolTips or BaseClass(BaseView) function UISimpleToolTips:__init() self.base_file = "common" self.layout_file = "UISimpleToolTips" self.layer_name = "Top" self.use_background = true self.click_bg_toClose = true self.background_alpha = 0 self.hide_maincancas = false self.close_mode = CloseMode.CloseDestroy self.destroy_imm = true self.load_callback = function () self:LoadSuccess() self:addEvents() end self.open_callback = function () self:SetText() end self.close_callback = function () end self.destroy_callback = function () self:Remove() end end function UISimpleToolTips:Remove() end function UISimpleToolTips:Open(desc, x, y, sx, sy) self.desc = desc self.pos_x = x self.pos_y = y self.size_x = sx self.size_y = sy BaseView.Open(self) end function UISimpleToolTips:LoadSuccess() self.panel = self:GetChild("panel") self.bg = self:GetChild("panel/bg") self.scroll = self:GetChild("panel/ScrollView/Viewport/Content") self.scroll_view = self:GetChild("panel/ScrollView") self.contentTxt = self:GetChild("panel/ScrollView/Viewport/Content/contentTxt"):GetComponent("Text") self.txt = self:GetChild("panel/ScrollView/Viewport/Content/contentTxt") end function UISimpleToolTips:addEvents() end function UISimpleToolTips:SetText() local s_x = self.size_x or self.scroll_view.transform.sizeDelta.x local s_y = self.size_y or self.scroll_view.transform.sizeDelta.y self.panel.transform.sizeDelta= Vector2(s_x+40, s_y+35) self.scroll_view.transform.sizeDelta = Vector2(s_x, s_y) self.txt.transform.sizeDelta = Vector2(s_x, s_y) self.contentTxt.text = self.desc self.scroll.sizeDelta = Vector2(s_x, self.contentTxt.preferredHeight) local con_width = self.panel.transform.sizeDelta.x local con_height = self.panel.transform.sizeDelta.y local x, y = ScreenToViewportPoint(self.pos_x, self.pos_y) if x + con_width > SrcScreenWidth then x = SrcScreenWidth - con_width - 20 end if y - con_height <= 0 then y = con_height + 80 end if y + con_height > ScreenHeight then y = ScreenHeight - con_height - 20 end self.panel.transform.anchoredPosition = Vector3(x, y, 0) end