55 lines
1.9 KiB
Lua
55 lines
1.9 KiB
Lua
local BaseTips = require "app/ui/tips/base_tips"
|
|
local DescTips = class("DescTips", BaseTips)
|
|
|
|
function DescTips:ctor(params)
|
|
self.desc = (params.desc or GConst.EMPTY_STRING)
|
|
self.tarCornerScreenPos = params.tarCornerScreenPos
|
|
self.location = params.location
|
|
end
|
|
|
|
function DescTips:getPrefabPath()
|
|
return "assets/prefabs/ui/tips/desc_tips.prefab"
|
|
end
|
|
|
|
function DescTips:init()
|
|
local uiMap = self.root:genAllChildren()
|
|
self.bg = uiMap["item_tips.bg1.bg"]
|
|
self.bg1 = uiMap["item_tips.bg1"]
|
|
self.descTx = uiMap["item_tips.bg1.bg.desc_tx"]
|
|
end
|
|
|
|
function DescTips:onLoadRootComplete()
|
|
self:init()
|
|
local tipsBgTransform = self.bg:getTransform()
|
|
self.originSizeDelta = tipsBgTransform.sizeDelta
|
|
self.originPivot = tipsBgTransform.pivot
|
|
self.originAnchoredPosition = tipsBgTransform.anchoredPosition
|
|
self.originLocalPosition = tipsBgTransform.localPosition
|
|
end
|
|
|
|
function DescTips:onRefresh()
|
|
self.root:addClickListener(function ()
|
|
self:closeUI()
|
|
end)
|
|
|
|
self.descTx:setText(self.desc)
|
|
-- 这里原来是用preferredHeight,但是在中英文混合的时候这个值可能不准,只有改用renderedHeight
|
|
-- renderedHeight必须要先调用下ForceMeshUpdate强制刷新才有效
|
|
self.descTx:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT_MESH_PRO):ForceMeshUpdate()
|
|
self.bg:setSizeDeltaY(self.descTx:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT_MESH_PRO).renderedHeight + 18)
|
|
if self.tarCornerScreenPos then
|
|
self:locate(self.location, self.originSizeDelta, self.bg, self.tarCornerScreenPos)
|
|
end
|
|
end
|
|
|
|
function DescTips:onClose()
|
|
if self.originSizeDelta then
|
|
local tipsBgTransform = self.bg:getTransform()
|
|
tipsBgTransform.sizeDelta = self.originSizeDelta
|
|
tipsBgTransform.pivot = self.originPivot
|
|
tipsBgTransform.anchoredPosition = self.originAnchoredPosition
|
|
tipsBgTransform.localPosition = self.originLocalPosition
|
|
end
|
|
end
|
|
|
|
return DescTips |