local BaseTips = class("BaseTips", BaseUI) function BaseTips:isFullScreen() return false end function BaseTips:showCommonBG() return false end function BaseTips:getOffsetX() return 10 end function BaseTips:getOffsetY() return 10 end function BaseTips:getPosPercentX() return 0.25 end function BaseTips:getPosPercentY() return 0.15 end function BaseTips:getFinalX() return 0 end function BaseTips:getFinalY() return 0 end function BaseTips:locate(location, originSizeDelta, node, tarCornerScreenPos) local uiCamera = UIManager:getUICameraComponent() local tarCornerLp = CS.BF.Utils.RectTransformScreenPointToLocalPointInRectangle(UIManager:getMainCanvasTransform(), tarCornerScreenPos.x, tarCornerScreenPos.y, uiCamera) if location == ModuleManager.TipsManager.ALIGN_TYPE.TOP_CENTER then node:getTransform().pivot = BF.Vector2(0.5, 0) node:addLocalPosition(tarCornerLp.x, tarCornerLp.y + self:getOffsetY(), 0) self:adaptWhenOverScreen(node, 0.5, 0) elseif location == ModuleManager.TipsManager.ALIGN_TYPE.TOP_LEFT then node:getTransform().pivot = BF.Vector2(0, 0) node:addLocalPosition(tarCornerLp.x - node:getTransform().sizeDelta.x*self:getPosPercentX(), tarCornerLp.y + self:getOffsetY(), 0) self:adaptWhenOverScreen(node, 0, 0) elseif location == ModuleManager.TipsManager.ALIGN_TYPE.TOP_RIGHT then node:getTransform().pivot = BF.Vector2(1, 0) node:addLocalPosition(tarCornerLp.x + node:getTransform().sizeDelta.x*self:getPosPercentX(), tarCornerLp.y + self:getOffsetY(), 0) self:adaptWhenOverScreen(node, 1, 0) elseif location == ModuleManager.TipsManager.ALIGN_TYPE.BOTTOM_CENTER then node:getTransform().pivot = BF.Vector2(0.5, 1) node:addLocalPosition(tarCornerLp.x, tarCornerLp.y - self:getOffsetY(), 0) self:adaptWhenOverScreen(node, 0.5, 1) elseif location == ModuleManager.TipsManager.ALIGN_TYPE.BOTTOM_LEFT then node:getTransform().pivot = BF.Vector2(0, 1) node:addLocalPosition(tarCornerLp.x - node:getTransform().sizeDelta.x*self:getPosPercentX(), tarCornerLp.y - self:getOffsetY(), 0) self:adaptWhenOverScreen(node, 0, 1) elseif location == ModuleManager.TipsManager.ALIGN_TYPE.BOTTOM_RIGHT then node:getTransform().pivot = BF.Vector2(1, 1) node:addLocalPosition(tarCornerLp.x + node:getTransform().sizeDelta.x*self:getPosPercentX(), tarCornerLp.y - self:getOffsetY(), 0) self:adaptWhenOverScreen(node, 1, 1) elseif location == ModuleManager.TipsManager.ALIGN_TYPE.LEFT_TOP then node:getTransform().pivot = BF.Vector2(1, 0.5) local posy = node:getTransform().sizeDelta.y/2 - originSizeDelta.y*(0.5 - self:getPosPercentY()) node:addLocalPosition(tarCornerLp.x - self:getOffsetX(), tarCornerLp.y - posy, 0) self:adaptWhenOverScreen(node, 1, 0.5) elseif location == ModuleManager.TipsManager.ALIGN_TYPE.LEFT_CENTER then node:getTransform().pivot = BF.Vector2(1, 0.5) node:addLocalPosition(tarCornerLp.x - self:getOffsetX(), tarCornerLp.y, 0) self:adaptWhenOverScreen(node, 1, 0.5) elseif location == ModuleManager.TipsManager.ALIGN_TYPE.LEFT_BOTTOM then node:getTransform().pivot = BF.Vector2(1, 0.5) local posy = node:getTransform().sizeDelta.y/2 - originSizeDelta.y*(0.5 - self:getPosPercentY()) node:addLocalPosition(tarCornerLp.x - self:getOffsetX(), tarCornerLp.y + posy, 0) self:adaptWhenOverScreen(node, 1, 0.5) elseif location == ModuleManager.TipsManager.ALIGN_TYPE.RIGHT_TOP then node:getTransform().pivot = BF.Vector2(0, 0.5) local posy = node:getTransform().sizeDelta.y/2 - originSizeDelta.y*(0.5 - self:getPosPercentY()) node:addLocalPosition(tarCornerLp.x + self:getOffsetX(), tarCornerLp.y - posy, 0) self:adaptWhenOverScreen(node, 0, 0.5) elseif location == ModuleManager.TipsManager.ALIGN_TYPE.RIGHT_CENTER then node:getTransform().pivot = BF.Vector2(0, 0.5) node:addLocalPosition(tarCornerLp.x + self:getOffsetX(), tarCornerLp.y, 0) self:adaptWhenOverScreen(node, 0, 0.5) elseif location == ModuleManager.TipsManager.ALIGN_TYPE.RIGHT_BOTTOM then node:getTransform().pivot = BF.Vector2(0, 0.5) local posy = node:getTransform().sizeDelta.y/2 - originSizeDelta.y*(0.5 - self:getPosPercentY()) node:addLocalPosition(tarCornerLp.x + self:getOffsetX(), tarCornerLp.y + posy, 0) self:adaptWhenOverScreen(node, 0, 0.5) elseif location == ModuleManager.TipsManager.ALIGN_TYPE.CUSTOM then local pivot = node:getTransform().pivot node:addLocalPosition(tarCornerLp.x, tarCornerLp.y, 0) self:adaptWhenOverScreen(node, pivot.x, pivot.y) end self:finalSetPos(node) end function BaseTips:adaptWhenOverScreen(node, pivotX, pivotY) local halfWidth = GConst.DESIGN_RESOLUTION_WIDTH / 2 local halfHeight = GConst.DESIGN_RESOLUTION_HEIGHT / 2 local anchoredPos = node:getAnchoredPosition() local sizeDelta = node:getSizeDelta() local leftX = anchoredPos.x - sizeDelta.x * (pivotX - 0) local rightX = anchoredPos.x + sizeDelta.x * (1 - pivotX) local topY = anchoredPos.y + sizeDelta.y * (1 - pivotY) local bottomY = anchoredPos.y - sizeDelta.y * (pivotY - 0) local xOffset = 0 local yOffset = 0 -- 左边超出屏幕 if math.abs(leftX) > halfWidth then node:addAnchoredPosition(math.abs(leftX) - halfWidth, 0) xOffset = math.abs(leftX) - halfWidth end -- 右边超出屏幕 if math.abs(rightX) > halfWidth then node:addAnchoredPosition(halfWidth - math.abs(rightX), 0) xOffset = xOffset + math.abs(leftX) - halfWidth end -- 上边超出屏幕 if math.abs(topY) > halfHeight then node:addAnchoredPosition(0, halfHeight - math.abs(topY)) yOffset = halfHeight - math.abs(topY) end -- 下边超出屏幕 if math.abs(bottomY) > halfHeight then node:addAnchoredPosition(0, math.abs(bottomY) - halfHeight) yOffset = yOffset + math.abs(bottomY) - halfHeight end return xOffset, yOffset end function BaseTips:finalSetPos(node) node:addLocalPosition(self:getFinalX(), self:getFinalY(), 0) end function BaseTips:showCurrencyAction(pos) UIManager:showCurrencyAction(pos) end return BaseTips