254 lines
9.2 KiB
Lua
254 lines
9.2 KiB
Lua
local TipsManager = class("TipsManager", BaseModule)
|
|
|
|
TipsManager.ALIGN_TYPE = {
|
|
ADAPTIVE = 0,
|
|
CENTER = 1,
|
|
TOP_LEFT = 2,
|
|
TOP_CENTER = 3,
|
|
TOP_RIGHT = 4,
|
|
BOTTOM_LEFT = 5,
|
|
BOTTOM_CENTER = 6,
|
|
BOTTOM_RIGHT = 7,
|
|
LEFT_TOP = 8,
|
|
LEFT_CENTER =9,
|
|
LEFT_BOTTOM = 10,
|
|
RIGHT_TOP = 11,
|
|
RIGHT_CENTER = 12,
|
|
RIGHT_BOTTOM = 13,
|
|
CUSTOM = 14,
|
|
}
|
|
|
|
TipsManager.REWARDS_TIPS_TYPE = {
|
|
COMMON = "reward_node",
|
|
TASK = "reward2_node",
|
|
}
|
|
|
|
function TipsManager:showHelpTips(params)
|
|
params = params or {}
|
|
UIManager:showUI("app/ui/tips/help_tips", params)
|
|
end
|
|
|
|
function TipsManager:showRewardTips(rewardId, rewardType, tarPrefabObj, alignType)
|
|
if rewardType == GConst.REWARD_TYPE.ITEM then
|
|
local info = ConfigManager:getConfig("item")[rewardId]
|
|
if info then
|
|
if info.type == GConst.ItemConst.ITEM_TYPE.RANDOM_FRAGMENT or info.type == GConst.ItemConst.ITEM_TYPE.WEIGHT_FRAGMENT then
|
|
-- 随机碎片 or 权重随机碎片
|
|
self:showHeroFragmentTips(rewardId)
|
|
return
|
|
elseif info.type == GConst.ItemConst.ITEM_TYPE.BOX then
|
|
-- 宝箱
|
|
self:showBoxTips(rewardId)
|
|
return
|
|
elseif info.type == GConst.ItemConst.ITEM_TYPE.HERO_FRAGMENT then
|
|
-- 英雄碎片
|
|
ModuleManager.HeroManager:showHeroDetailUI(info.parameter, true)
|
|
return
|
|
end
|
|
end
|
|
end
|
|
local desc = self:getRewardDesc(rewardId, rewardType)
|
|
self:showDescTips(desc, tarPrefabObj, alignType)
|
|
end
|
|
|
|
function TipsManager:showRewardsBox(params)
|
|
UIManager:showUI(UIManager.UI_PATH.REWARD_BOX, params)
|
|
end
|
|
|
|
function TipsManager:showItemTips(id, tarPrefabObj, alignType)
|
|
local params = {
|
|
id = id,
|
|
aniType = UIManager.ANI_TYPE.NONE,
|
|
}
|
|
if tarPrefabObj then
|
|
alignType = alignType or TipsManager.ALIGN_TYPE.TOP_CENTER
|
|
local tarCornerScreenPos, location = self:getCornerScreenPosition(tarPrefabObj, alignType)
|
|
params.tarCornerScreenPos = tarCornerScreenPos
|
|
params.location = location
|
|
end
|
|
UIManager:showUI("app/ui/tips/item_tips", params)
|
|
end
|
|
|
|
function TipsManager:showRewardsTips(rewards, customTitleStr, tarPrefabObj, callback, alignType, showBlackBg, typeNode)
|
|
local params = {
|
|
rewards = rewards,
|
|
customTitleStr = customTitleStr,
|
|
callback = callback,
|
|
aniType = UIManager.ANI_TYPE.NONE,
|
|
}
|
|
if tarPrefabObj then
|
|
alignType = alignType or TipsManager.ALIGN_TYPE.TOP_CENTER
|
|
local tarCornerScreenPos, location = self:getCornerScreenPosition(tarPrefabObj, alignType)
|
|
params.tarCornerScreenPos = tarCornerScreenPos
|
|
params.location = location
|
|
params.showBlackBg = showBlackBg == nil or showBlackBg
|
|
params.typeNode = typeNode or TipsManager.REWARDS_TIPS_TYPE.COMMON
|
|
end
|
|
UIManager:showUI("app/ui/tips/rewards_tips", params)
|
|
end
|
|
|
|
function TipsManager:showDescTips(desc, tarPrefabObj, alignType)
|
|
local params = {
|
|
desc = desc,
|
|
aniType = UIManager.ANI_TYPE.NONE,
|
|
}
|
|
if tarPrefabObj then
|
|
alignType = alignType or TipsManager.ALIGN_TYPE.TOP_CENTER
|
|
local tarCornerScreenPos, location = self:getCornerScreenPosition(tarPrefabObj, alignType)
|
|
params.tarCornerScreenPos = tarCornerScreenPos
|
|
params.location = location
|
|
end
|
|
UIManager:showUI("app/ui/tips/desc_tips", params)
|
|
end
|
|
|
|
function TipsManager:showHeroFragmentTips(itemId)
|
|
local params = {
|
|
itemId = itemId
|
|
}
|
|
UIManager:showUI("app/ui/tips/hero_fragment_tips", params)
|
|
end
|
|
|
|
-- formation = {{id = 000, level = 000}, {id = 000, level = 000}, ...}
|
|
function TipsManager:showHeroFormation(targetObj, formation)
|
|
local tarCornerScreenPos, location = self:getCornerScreenPosition(targetObj, TipsManager.ALIGN_TYPE.BOTTOM_CENTER)
|
|
location = TipsManager.ALIGN_TYPE.CUSTOM
|
|
local params = {
|
|
tarCornerScreenPos = tarCornerScreenPos,
|
|
location = location,
|
|
formation = formation,
|
|
}
|
|
UIManager:showUI("app/ui/tips/formation_tips", params)
|
|
end
|
|
|
|
function TipsManager:showBoxTips(itemId)
|
|
local params = {
|
|
itemId = itemId
|
|
}
|
|
UIManager:showUI("app/ui/tips/box_tips", params)
|
|
end
|
|
|
|
function TipsManager:getRewardDesc(rewardId, rewardType)
|
|
if rewardType == GConst.REWARD_TYPE.ITEM then
|
|
local item18NInfo = I18N:getConfig("item")[rewardId]
|
|
if item18NInfo then
|
|
return item18NInfo.desc
|
|
end
|
|
end
|
|
return GConst.EMPTY_STRING
|
|
end
|
|
|
|
function TipsManager:showBattleBoardSkillTips(heroEntity, battleController, side, tarPrefabObj, alignType)
|
|
local params = {
|
|
heroEntity = heroEntity,
|
|
battleController = battleController,
|
|
side = side,
|
|
aniType = UIManager.ANI_TYPE.NONE,
|
|
}
|
|
if tarPrefabObj then
|
|
alignType = alignType or TipsManager.ALIGN_TYPE.TOP_CENTER
|
|
local tarCornerScreenPos, location = self:getCornerScreenPosition(tarPrefabObj, alignType)
|
|
params.tarCornerScreenPos = tarCornerScreenPos
|
|
params.location = location
|
|
end
|
|
UIManager:showUI("app/ui/tips/battle_board_skill_tips", params)
|
|
end
|
|
|
|
function TipsManager:getCornerScreenPosition(tarPrefabObj, alignType)
|
|
local uiCamera = UIManager:getUICameraComponent()
|
|
local rectTransform = tarPrefabObj:getComponent(GConst.TYPEOF_UNITY_CLASS.RECTTRANSFORM)
|
|
local pivot = rectTransform.pivot
|
|
local rect = rectTransform.rect
|
|
local isTop
|
|
local isRight
|
|
local isCenter = false
|
|
local screenPoint
|
|
local location
|
|
if alignType == TipsManager.ALIGN_TYPE.ADAPTIVE then
|
|
local screenWidth, screenHeight = GFunc.getScreenSize()
|
|
local tarMid = rectTransform:TransformPoint(BF.Vector3(rect.width*(0.5 - pivot.x), rect.height*(0.5 - pivot.y), 0))
|
|
local tarSp = uiCamera:WorldToScreenPoint(tarMid)
|
|
if tarSp.x < screenWidth*0.45 then
|
|
isRight = false
|
|
elseif tarSp.x > screenWidth*0.55 then
|
|
isRight = true
|
|
else
|
|
isCenter = true
|
|
end
|
|
if tarSp.y < screenHeight * 0.6 then
|
|
isTop = true
|
|
else
|
|
isTop = false
|
|
end
|
|
if isTop then
|
|
if isCenter then
|
|
location = TipsManager.ALIGN_TYPE.TOP_CENTER
|
|
else
|
|
if isRight then
|
|
location = TipsManager.ALIGN_TYPE.TOP_RIGHT
|
|
else
|
|
location = TipsManager.ALIGN_TYPE.TOP_LEFT
|
|
end
|
|
end
|
|
local tarCorner = rectTransform:TransformPoint(BF.Vector3(rect.width*(0.5 - pivot.x), rect.height*(1 - pivot.y), 0))
|
|
screenPoint = uiCamera:WorldToScreenPoint(tarCorner)
|
|
else
|
|
if isCenter then
|
|
location = TipsManager.ALIGN_TYPE.BOTTOM_CENTER
|
|
else
|
|
if isRight then
|
|
location = TipsManager.ALIGN_TYPE.BOTTOM_RIGHT
|
|
else
|
|
location = TipsManager.ALIGN_TYPE.BOTTOM_LEFT
|
|
end
|
|
end
|
|
local tarCorner = rectTransform:TransformPoint(BF.Vector3(rect.width*(0.5 - pivot.x), -rect.height*pivot.y, 0))
|
|
screenPoint = uiCamera:WorldToScreenPoint(tarCorner)
|
|
end
|
|
else
|
|
location = alignType
|
|
if alignType == TipsManager.ALIGN_TYPE.TOP_LEFT then
|
|
local tarCorner = rectTransform:TransformPoint(BF.Vector3(rect.width*(0.5 - pivot.x), rect.height*(1 - pivot.y), 0))
|
|
screenPoint = uiCamera:WorldToScreenPoint(tarCorner)
|
|
elseif alignType == TipsManager.ALIGN_TYPE.TOP_CENTER then
|
|
local tarCorner = rectTransform:TransformPoint(BF.Vector3(rect.width*(0.5 - pivot.x), rect.height*(1 - pivot.y), 0))
|
|
screenPoint = uiCamera:WorldToScreenPoint(tarCorner)
|
|
elseif alignType == TipsManager.ALIGN_TYPE.TOP_RIGHT then
|
|
local tarCorner = rectTransform:TransformPoint(BF.Vector3(rect.width*(0.5 - pivot.x), rect.height*(1 - pivot.y), 0))
|
|
screenPoint = uiCamera:WorldToScreenPoint(tarCorner)
|
|
elseif alignType == TipsManager.ALIGN_TYPE.BOTTOM_LEFT then
|
|
local tarCorner = rectTransform:TransformPoint(BF.Vector3(rect.width*(0.5 - pivot.x), -rect.height*pivot.y, 0))
|
|
screenPoint = uiCamera:WorldToScreenPoint(tarCorner)
|
|
elseif alignType == TipsManager.ALIGN_TYPE.BOTTOM_CENTER then
|
|
local tarCorner = rectTransform:TransformPoint(BF.Vector3(rect.width*(0.5 - pivot.x), -rect.height*pivot.y, 0))
|
|
screenPoint = uiCamera:WorldToScreenPoint(tarCorner)
|
|
elseif alignType == TipsManager.ALIGN_TYPE.BOTTOM_RIGHT then
|
|
local tarCorner = rectTransform:TransformPoint(BF.Vector3(rect.width*(0.5 - pivot.x), -rect.height*pivot.y, 0))
|
|
screenPoint = uiCamera:WorldToScreenPoint(tarCorner)
|
|
elseif alignType == TipsManager.ALIGN_TYPE.LEFT_BOTTOM then
|
|
local tarCorner = rectTransform:TransformPoint(BF.Vector3(-rect.width*pivot.x, rect.height*(0.5 - pivot.y), 0))
|
|
screenPoint = uiCamera:WorldToScreenPoint(tarCorner)
|
|
elseif alignType == TipsManager.ALIGN_TYPE.LEFT_CENTER then
|
|
local tarCorner = rectTransform:TransformPoint(BF.Vector3(-rect.width*pivot.x, rect.height*(0.5 - pivot.y), 0))
|
|
screenPoint = uiCamera:WorldToScreenPoint(tarCorner)
|
|
elseif alignType == TipsManager.ALIGN_TYPE.LEFT_TOP then
|
|
local tarCorner = rectTransform:TransformPoint(BF.Vector3(-rect.width*pivot.x, rect.height*(0.5 - pivot.y), 0))
|
|
screenPoint = uiCamera:WorldToScreenPoint(tarCorner)
|
|
elseif alignType == TipsManager.ALIGN_TYPE.RIGHT_TOP then
|
|
local tarCorner = rectTransform:TransformPoint(BF.Vector3(rect.width*(1 - pivot.x), rect.height*(0.5 - pivot.y), 0))
|
|
screenPoint = uiCamera:WorldToScreenPoint(tarCorner)
|
|
elseif alignType == TipsManager.ALIGN_TYPE.RIGHT_CENTER then
|
|
local tarCorner = rectTransform:TransformPoint(BF.Vector3(rect.width*(1 - pivot.x), rect.height*(0.5 - pivot.y), 0))
|
|
screenPoint = uiCamera:WorldToScreenPoint(tarCorner)
|
|
elseif alignType == TipsManager.ALIGN_TYPE.RIGHT_BOTTOM then
|
|
local tarCorner = rectTransform:TransformPoint(BF.Vector3(rect.width*(1 - pivot.x), rect.height*(0.5 - pivot.y), 0))
|
|
screenPoint = uiCamera:WorldToScreenPoint(tarCorner)
|
|
end
|
|
end
|
|
if screenPoint then
|
|
return BF.Vector2(screenPoint.x, screenPoint.y), location
|
|
else
|
|
return BF.Vector2(0, 0), location
|
|
end
|
|
end
|
|
|
|
return TipsManager |