c1_lua/lua/app/ui/hero/equip_info_comp.lua
2025-09-17 17:23:26 +08:00

151 lines
5.3 KiB
Lua

local EquipInfoComp = class("EquipInfoComp", LuaComponent)
function EquipInfoComp:init()
local uiMap = self:getUIMap()
self.atkNameTx = uiMap["equip_info.bg_5.atk_name_tx"]
self.atkTx = uiMap["equip_info.bg_5.atk_tx"]
self.hpNameTx = uiMap["equip_info.bg_6.hp_name_tx"]
self.hpTx = uiMap["equip_info.bg_6.hp_tx"]
self.attrBtn = uiMap["equip_info.bg_6.attr_btn"]
self.descTx = uiMap["equip_info.equip_node.up.desc_tx"]
self.descTx1 = uiMap["equip_info.equip_node.up.desc_tx_1"]
self.infoBtn = uiMap["equip_info.equip_node.up.info_btn"]
self.autoWaerBtn = uiMap["equip_info.equip_node.auto_waer_btn"]
self.autoWaerBtnTx = uiMap["equip_info.equip_node.auto_waer_btn.text"]
self.upBtn = uiMap["equip_info.equip_node.up_btn"]
self.upBtnTx = uiMap["equip_info.equip_node.up_btn.text"]
self.equipNode = uiMap["equip_info.equip_node"]
self.emptyTx = uiMap["equip_info.empty_tx"]
self.hpNameTx:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_2))
self.atkNameTx:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_3))
self.emptyTx:setText(I18N:getGlobalText(I18N.GlobalConst.EQUIP_HERO_DESC_7))
self.upBtnTx:setText(I18N:getGlobalText(I18N.GlobalConst.EQUIP_HERO_DESC_3))
self.autoWaerBtnTx:setText(I18N:getGlobalText(I18N.GlobalConst.EQUIP_HERO_DESC_2))
self.equipCells = {}
self.suitTxs = {}
for i = 1, 6 do
self.suitTxs[i] = uiMap["equip_info.equip_node.up.suit_tx_" .. i]
self.equipCells[i] = uiMap["equip_info.equip_node.equip_cell_" .. i]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.EQUIP_CELL)
self.equipCells[i]:addClickListener(function()
local eid = DataManager.EquipData:getPartEquipUid(self.heroEntity:getMatchType(), i)
if eid and eid > 0 then
local equipEntity = DataManager.EquipData:getEquipByUid(eid)
local parmas = {}
parmas.heroEntity = self.heroEntity
parmas.slotId = self.heroEntity:getMatchType()
parmas.part = i
parmas.uid = eid
parmas.id = equipEntity:getId()
parmas.showType = GConst.EquipConst.INFO_SHOW_TYPE.ALL_ATTR
ModuleManager.EquipManager:showEquipInfoUI(parmas)
else
ModuleManager.EquipManager:showEquipListUI(self.heroEntity, i)
end
end)
end
self.descTx:setText(I18N:getGlobalText(I18N.GlobalConst.EQUIP_HERO_DESC_4))
self.descTx1:setText(I18N:getGlobalText(I18N.GlobalConst.EQUIP_HERO_DESC_5))
self.autoWaerBtn:addClickListener(function()
local soltId = self.heroEntity:getMatchType()
local listUids = {}
for i = 1, 6 do
local equip = DataManager.EquipData:getEquipMaxScore(soltId, i)
if equip ~= nil then
table.insert(listUids, equip:getUid())
end
end
ModuleManager.EquipManager:onEquipWearReq(soltId, listUids)
end)
self.upBtn:addClickListener(function()
ModuleManager.EquipManager:showEquipGrowthUI(self.heroEntity:getMatchType(), 1)
end)
self.attrBtn:addClickListener(function()
UIManager:showUI("app/ui/hero/hero_attr_ui", {heroEntity = self.heroEntity})
end)
self.infoBtn:addClickListener(function()
ModuleManager.EquipManager:showEquipResonateUI(self.heroEntity:getMatchType(), 1)
end)
end
function EquipInfoComp:setParentUI(ui)
self.uiRoot = ui
end
function EquipInfoComp:setHeroData(heroEntity)
self.heroEntity = heroEntity
end
function EquipInfoComp:refresh()
self:refreshAttr()
self:refreshEquip()
self:refreshEquipSuit()
end
function EquipInfoComp:refreshAttr()
self.hpNameTx:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_2))
self.atkNameTx:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_3))
local lv = self.heroEntity:getLv()
local hpStr
local atkStr
if not self.heroEntity:isActived() then
hpStr = self.heroEntity:getCfgHp(self.heroEntity:getBeginLv()) // GConst.DEFAULT_FACTOR
atkStr = self.heroEntity:getCfgAtk(self.heroEntity:getBeginLv()) // GConst.DEFAULT_FACTOR
else
local curHp = self.heroEntity:getHp() // GConst.DEFAULT_FACTOR
local curAtk = self.heroEntity:getAtk() // GConst.DEFAULT_FACTOR
local addHp = (self.heroEntity:getCfgHp(lv + 1) - self.heroEntity:getCfgHp()) // GConst.DEFAULT_FACTOR
local addAtk = (self.heroEntity:getCfgAtk(lv + 1) - self.heroEntity:getCfgAtk()) // GConst.DEFAULT_FACTOR
if addHp <= 0 then
hpStr = curHp
else
hpStr = curHp .. "<color=#A2FF29>+" .. addHp .. "</color>"
end
if addAtk <= 0 then
atkStr = curAtk
else
atkStr = curAtk .. "<color=#A2FF29>+" .. addAtk .. "</color>"
end
end
self.hpTx:setText(hpStr)
self.atkTx:setText(atkStr)
end
function EquipInfoComp:refreshEquip()
local slotId = self.heroEntity:getMatchType()
self.curFormation = DataManager.FormationData:getStageFormation()
if self.curFormation[slotId] ~= self.heroEntity:getCfgId() then
self.emptyTx:setActive(true)
self.equipNode:setActive(false)
return
end
self.emptyTx:setActive(false)
self.equipNode:setActive(true)
for part = 1, 6 do
local eid = DataManager.EquipData:getPartEquipUid(slotId, part)
if eid and eid > 0 then
local equipEntity = DataManager.EquipData:getEquipByUid(eid)
self.equipCells[part]:refresh(equipEntity, slotId)
else
self.equipCells[part]:refreshEmpty(part)
end
end
end
function EquipInfoComp:refreshEquipSuit()
local suitLvs = {1, 2, 3}
local suitDescs = {
I18N:getGlobalText(I18N.GlobalConst.EQUIP_HERO_LV_1, suitLvs[1]),
I18N:getGlobalText(I18N.GlobalConst.EQUIP_HERO_LV_2, suitLvs[2]),
I18N:getGlobalText(I18N.GlobalConst.EQUIP_HERO_LV_3, suitLvs[3])
}
for i = 1, 3 do
self.suitTxs[i]:setText(suitDescs[i])
end
end
return EquipInfoComp