c1_lua/lua/app/ui/battle/battle_skill_select_comp.lua
2023-05-22 10:57:38 +08:00

113 lines
3.7 KiB
Lua

local BattleSkillSelectComp = class("BattleSkillSelectComp", LuaComponent)
local SELECT_SKILL_CELL = "app/ui/battle/cell/battle_select_skill_cell"
local BATTLE_COMMON_PATH = "assets/arts/textures/background/battle_common/%s.png"
local SKILL_ICON_POS = {
{x =-240, y= 165},
{x =-240, y= 0},
{x =-240, y= -165}
}
function BattleSkillSelectComp:refresh(skillList, onlyCommonSkill)
self.skillList = skillList
self.onlyCommonSkill = onlyCommonSkill
self:_playPop()
self:_display()
self:_addListeners()
end
function BattleSkillSelectComp:_display()
local uiMap = self:getUIMap()
uiMap["battle_select_skill_comp.skill_node.ad_btn.tx"]:setText(I18N:getGlobalText(I18N.GlobalConst.BATTLE_DESC_3))
local bg2 = uiMap["battle_select_skill_comp.bg_2"]
bg2:setVisible(self.onlyCommonSkill)
local bg = uiMap["battle_select_skill_comp.bg_1"]
if ModuleManager.BattleManager.battleController then
bg:setVisible(false)
bg:setTexture(string.format(BATTLE_COMMON_PATH, ModuleManager.BattleManager.battleController:getChessBoardBgName() .. "_1"), function()
bg:setVisible(true)
end)
else
bg:setVisible(true)
end
self:refreshRogueSkill()
end
function BattleSkillSelectComp:_addListeners()
local uiMap = self:getUIMap()
uiMap["battle_select_skill_comp.skill_node.ad_btn"]:addClickListener(function()
if not ModuleManager.BattleManager.battleController then
return
end
SDKManager:showFullScreenAds(BIReport.ADS_CLICK_TYPE.BATTLE_SKILL_REFRESH, function()
self.skillList = ModuleManager.BattleManager.battleController:getRandomSkillList(nil, self.onlyCommonSkill)
self:refreshRogueSkill()
end)
end)
self.canvasGroup = uiMap["battle_select_skill_comp.skill_node"]:getComponent(GConst.TYPEOF_UNITY_CLASS.CANVAS_GROUP)
self.canvasGroup.alpha = 1
self.bg = uiMap["battle_select_skill_comp.bg_1"]
uiMap["battle_select_skill_comp.look_btn"]:addTouchListener(function(eventType, x, y)
if eventType == GConst.TOUCH_EVENT.DOWN or eventType == GConst.TOUCH_EVENT.DRAG then
self.canvasGroup.alpha = 0.3
self.bg:setVisible(false)
else
self.canvasGroup.alpha = 1
self.bg:setVisible(true)
end
end)
end
function BattleSkillSelectComp:refreshRogueSkill()
local uiMap = self:getUIMap()
if not self.selectSkillCells then
self.selectSkillCells = {}
for i = 1, 3 do
self.selectSkillCells[i] = CellManager:addCellComp(uiMap["battle_select_skill_comp.skill_node.skill_select_cell_" .. i], SELECT_SKILL_CELL)
end
end
for index, cell in ipairs(self.selectSkillCells) do
local skillId = self.skillList[index]
cell:getBaseObject():setActive(skillId ~= nil)
if skillId then
cell:refresh(skillId, function(value)
self:onClickSkill(skillId, value, SKILL_ICON_POS[index])
end)
end
end
end
function BattleSkillSelectComp:onClickSkill(skillId, value, pos)
if self.isInAni then
return
end
self:hide()
ModuleManager.BattleManager:onSelectSkill(skillId, value, pos)
end
function BattleSkillSelectComp:hide()
self.baseObject:setVisible(false)
end
function BattleSkillSelectComp:_playPop()
self.isInAni = true
self.popSequence = self.baseObject:createBindTweenSequence()
local scaleTween1 = self.baseObject:getTransform():DOScale(1.05, 0.15)
self.popSequence:Append(scaleTween1)
local scaleTween2 = self.baseObject:getTransform():DOScale(1, 0.2)
self.popSequence:Append(scaleTween2)
self.popSequence:AppendCallback(function()
self.isInAni = false
self.popSequence = nil
end)
end
return BattleSkillSelectComp