121 lines
6.0 KiB
Lua
121 lines
6.0 KiB
Lua
local WeaponInfoComp = class("WeaponInfoComp", LuaComponent)
|
|
local BTN_ICON = {"common_btn_green_2", "common_btn_grey_2"}
|
|
local DEFAULT_FACTOR = GConst.BattleConst.DEFAULT_FACTOR
|
|
|
|
function WeaponInfoComp:init()
|
|
local uiMap = self:getUIMap()
|
|
|
|
self.txName = uiMap["weapon_info.name.tx_name"]
|
|
self.imgWeapon = uiMap["weapon_info.img_weapon"]
|
|
self.txLevel = uiMap["weapon_info.level.tx_level"]
|
|
self.txDesc1 = uiMap["weapon_info.tx_desc_1"]
|
|
self.txDesc2 = uiMap["weapon_info.tx_desc_2"]
|
|
self.txAttr = uiMap["weapon_info.ScrollView.Viewport.Content.tx_attr"]
|
|
self.btnUp = uiMap["weapon_info.upgrade.btn_up"]
|
|
self.txUp = uiMap["weapon_info.upgrade.btn_up.tx_desc"]
|
|
self.txNum = uiMap["weapon_info.upgrade.btn_up.tx_num"]
|
|
self.attr = {}
|
|
for i = 1, 2 do
|
|
self.attr[i] = uiMap["weapon_info.attr_" .. i]
|
|
end
|
|
|
|
self.txDesc1:setText(I18N:getGlobalText(I18N.GlobalConst.EQUIP_DESC_4))
|
|
self.txDesc2:setText(I18N:getGlobalText(I18N.GlobalConst.EQUIP_DESC_5))
|
|
self.txUp:setText(I18N:getGlobalText(I18N.GlobalConst.EQUIP_DESC_3))
|
|
|
|
self.btnUp:addClickListener(function()
|
|
ModuleManager.EquipManager:reqUpgrade(self.heroEntity:getCfgId(), GConst.EquipConst.PART_TYPE.WEAPON)
|
|
end)
|
|
end
|
|
|
|
function WeaponInfoComp:setHeroData(heroEntity)
|
|
self.heroEntity = heroEntity
|
|
self.weaponEntity = DataManager.EquipData:getEquip(self.heroEntity:getCfgId(), GConst.EquipConst.PART_TYPE.WEAPON)
|
|
end
|
|
|
|
function WeaponInfoComp:refresh()
|
|
local nextWeaponEntity = self.weaponEntity:getNextLevelEntity()
|
|
|
|
self.txName:setText(self.weaponEntity:getName())
|
|
-- self.imgWeapon:setSprite(GConst.ATLAS_PATH.COMMON, self.weaponEntity:getIcon())
|
|
self.txLevel:setText(I18N:getGlobalText(I18N.GlobalConst.EQUIP_DESC_3) .. self.weaponEntity:getLevel().."/"..self.weaponEntity:getMaxLevel())
|
|
self.txAttr:setText(self.weaponEntity:getAttrDesc())
|
|
|
|
-- 基础属性
|
|
local diffAtk = (nextWeaponEntity:getAttack() - self.weaponEntity:getAttack()) // DEFAULT_FACTOR
|
|
local diffNormalHurt = (nextWeaponEntity:getNormalHurt() - self.weaponEntity:getNormalHurt()) // DEFAULT_FACTOR
|
|
local diffSkillHurt = (nextWeaponEntity:getSkillHurt() - self.weaponEntity:getSkillHurt()) // DEFAULT_FACTOR
|
|
local diffHp = (nextWeaponEntity:getHp() - self.weaponEntity:getHp()) // DEFAULT_FACTOR
|
|
local showAttrType = {}
|
|
for index, obj in ipairs(self.attr) do
|
|
local map = obj:genAllChildren()
|
|
local imgIcon = map["img_icon"]
|
|
local txTitle = map["tx_title"]
|
|
local txNum = map["tx_num"]
|
|
obj:setVisible(true)
|
|
|
|
if not table.containValue(showAttrType, GConst.EquipConst.ATTR_TYPE.ATK) and diffAtk > 0 then
|
|
table.insert(showAttrType, GConst.EquipConst.ATTR_TYPE.ATK)
|
|
imgIcon:setSprite(GConst.ATLAS_PATH.COMMON, "common_dec_5")
|
|
txTitle:setText("<color=#FCB501>"..I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_3).."</color>")
|
|
txNum:setText(self.weaponEntity:getAttack() // DEFAULT_FACTOR .. "<color=#A2FF29>+" .. diffAtk .. "</color>")
|
|
elseif not table.containValue(showAttrType, GConst.EquipConst.ATTR_TYPE.NORMAL_HURT) and diffNormalHurt > 0 then
|
|
table.insert(showAttrType, GConst.EquipConst.ATTR_TYPE.NORMAL_HURT)
|
|
imgIcon:setSprite(GConst.ATLAS_PATH.COMMON, "common_dec_20")
|
|
txTitle:setText("<color=#4CCFFA>"..I18N:getGlobalText(I18N.GlobalConst.ATTR_NORMAL_HURT).."</color>")
|
|
txNum:setText(self.weaponEntity:getNormalHurt() // DEFAULT_FACTOR .. "<color=#A2FF29>+" .. diffNormalHurt .. "</color>")
|
|
elseif not table.containValue(showAttrType, GConst.EquipConst.ATTR_TYPE.SKILL_HURT) and diffSkillHurt > 0 then
|
|
table.insert(showAttrType, GConst.EquipConst.ATTR_TYPE.SKILL_HURT)
|
|
imgIcon:setSprite(GConst.ATLAS_PATH.COMMON, "common_dec_21")
|
|
txTitle:setText("<color=#EC80FF>"..I18N:getGlobalText(I18N.GlobalConst.ATTR_SKILL_HURT).."</color>")
|
|
txNum:setText(self.weaponEntity:getSkillHurt() // DEFAULT_FACTOR .. "<color=#A2FF29>+" .. diffSkillHurt .. "</color>")
|
|
elseif not table.containValue(showAttrType, GConst.EquipConst.ATTR_TYPE.HP) and diffHp > 0 then
|
|
table.insert(showAttrType, GConst.EquipConst.ATTR_TYPE.HP)
|
|
imgIcon:setSprite(GConst.ATLAS_PATH.COMMON, "common_dec_4")
|
|
txTitle:setText("<color=#FB6895>"..I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_2).."</color>")
|
|
txNum:setText(self.weaponEntity:getHp() // DEFAULT_FACTOR .. "<color=#A2FF29>+" .. diffHp .. "</color>")
|
|
else
|
|
obj:setVisible(false)
|
|
end
|
|
end
|
|
|
|
-- 消耗材料
|
|
local cost = self.weaponEntity:getUpgradeMaterials()
|
|
for i = 1, 3 do
|
|
local uiMap = self:getUIMap()
|
|
local costNode = uiMap["weapon_info.upgrade.cost.cost_" .. i]
|
|
if cost[i] then
|
|
costNode:setActive(true)
|
|
local icon = uiMap["weapon_info.upgrade.cost.cost_" .. i .. ".img_icon"]
|
|
local num = uiMap["weapon_info.upgrade.cost.cost_" .. i .. ".tx_num"]
|
|
|
|
local costId = GFunc.getRewardId(cost[i])
|
|
local costNum = GFunc.getRewardNum(cost[i])
|
|
local haveNum = DataManager.BagData.ItemData:getItemNumById(costId)
|
|
if haveNum < costNum then
|
|
num:setText("<color=#FF5252>" .. haveNum .. "</color>/" .. costNum)
|
|
else
|
|
num:setText(haveNum .. "/" .. costNum)
|
|
end
|
|
-- icon:setSprite(GFunc.getIconRes(costId))
|
|
else
|
|
costNode:setActive(false)
|
|
end
|
|
end
|
|
if self.weaponEntity:isEnoughGold() then
|
|
self.txNum:setText(self.weaponEntity:getUpgradeGoldNum())
|
|
else
|
|
self.txNum:setText("<color=#FF5252>" .. self.weaponEntity:getUpgradeGoldNum() .. "</color>")
|
|
end
|
|
|
|
local canLvUp = self.weaponEntity:canLevelUp()
|
|
if canLvUp then
|
|
self.btnUp:addRedPoint(120, 50, 0.6)
|
|
self.btnUp:setSprite(GConst.ATLAS_PATH.COMMON, BTN_ICON[1])
|
|
else
|
|
self.btnUp:removeRedPoint()
|
|
self.btnUp:setSprite(GConst.ATLAS_PATH.COMMON, BTN_ICON[2])
|
|
end
|
|
end
|
|
|
|
return WeaponInfoComp |