c1_lua/lua/app/ui/tips/battle_board_skill_tips.lua
2023-05-22 15:59:17 +08:00

115 lines
4.3 KiB
Lua

local BaseTips = require "app/ui/tips/base_tips"
local BattleBoardSkillTips = class("BattleBoardSkillTips", BaseTips)
local SELECT_SKILL_CELL = "app/ui/battle/cell/select_skill_cell"
local MIN_HEIGHT = 248
local MAX_HEIGHT = 348
local NO_SKILL_HRIGHT = 136
function BattleBoardSkillTips:ctor(params)
local elementType = params.elementType
self.params = params
self.boardSkillEntity = DataManager.BattleData:getSkillEntityByElement(elementType)
self.battleUnitEntity = DataManager.BattleData:getAtkTeam():getAllMembers()[elementType]
self.tarCornerScreenPos = params.tarCornerScreenPos
self.location = params.location
end
function BattleBoardSkillTips:getPrefabPath()
return "assets/prefabs/ui/tips/battle_skill_tips.prefab"
end
function BattleBoardSkillTips:onLoadRootComplete()
local uiMap = self.root:genAllChildren()
self.bg = uiMap["battle_skill_tips.bg_1"]
self.mask = uiMap["battle_skill_tips.mask"]
self.atkDesc = uiMap["battle_skill_tips.bg_1.atk_desc"]
self.skillDesc = uiMap["battle_skill_tips.bg_1.skill_desc"]
self.validEffectDesc = uiMap["battle_skill_tips.bg_1.valid_effect_desc"]
self.gridLayout = uiMap["battle_skill_tips.bg_1.grid_layout"]
if not self.selectSkillCells then
self.selectSkillCells = {}
for i = 1, 7 do
self.selectSkillCells[i] = CellManager:addCellComp(uiMap["battle_skill_tips.bg_1.grid_layout.skill_select_cell_" .. i], SELECT_SKILL_CELL)
end
end
local tipsBgTransform = self.bg:getTransform()
self.originSizeDelta = tipsBgTransform.sizeDelta
self.originPivot = tipsBgTransform.pivot
self.originAnchoredPosition = tipsBgTransform.anchoredPosition
self.originLocalPosition = tipsBgTransform.localPosition
end
function BattleBoardSkillTips:onRefresh()
self.mask:addClickListener(function ()
self:closeUI()
end)
local heroId = self.battleUnitEntity:getId()
local heroEntity = DataManager.HeroData:getHeroById(heroId)
if not heroEntity then
return
end
local heroNmae = ModuleManager.HeroManager:getHeroName(heroId)
local atk = self.battleUnitEntity:getAtk()
self.atkDesc:setText(I18N:getGlobalText(I18N.GlobalConst.BATTLE_DESC_9, heroNmae, atk))
self.skillDesc:setText(ModuleManager.HeroManager:getSkillDesc(heroEntity:getBaseSkill()))
self.validEffectDesc:setText(I18N:getGlobalText(I18N.GlobalConst.BATTLE_DESC_10))
local addY = self.skillDesc:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT_MESH_PRO).preferredHeight - self.skillDesc:fastGetSizeDeltaY()
if addY < 0 then
addY = 0
end
local count = 0
local rougeSkillList = heroEntity:getRogueSkillList()
for index, cell in ipairs(self.selectSkillCells) do
local rogueSkillId = rougeSkillList[index]
cell:getBaseObject():setActive(rogueSkillId ~= nil)
if rogueSkillId then
local selectedCount = DataManager.BattleData:getSkillCount(rogueSkillId)
if selectedCount > 0 then
count = count + 1
local skillId = rogueSkillId
local count = selectedCount
local value = DataManager.BattleData:getSelectSkillMap()[skillId].value or 0
cell:refresh(skillId, count)
cell:addClickListener(function()
ModuleManager.TipsManager:showDescTips(ModuleManager.HeroManager:getSkillRogueDesc(skillId, value), cell:getBaseObject())
end)
else
cell:getBaseObject():setActive(false)
end
end
end
self.gridLayout:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_GRID_LAYOUT):RefreshLayout()
if count > 5 then
addY = addY + MAX_HEIGHT
elseif count >= 1 then
addY = addY + MIN_HEIGHT
else
addY = addY + NO_SKILL_HRIGHT
self.validEffectDesc:setText(GConst.EMPTY_STRING)
end
self.bg:setSizeDeltaY(addY)
if self.tarCornerScreenPos then
self:locate(self.location, self.originSizeDelta, self.bg, self.tarCornerScreenPos)
end
end
function BattleBoardSkillTips: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 BattleBoardSkillTips