c1_lua/lua/app/ui/hero/weapon_info_comp.lua
2023-07-25 17:16:54 +08:00

136 lines
7.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.attrContent = uiMap["weapon_info.ScrollView.Viewport.Content"]
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))
DataManager.ShopData:checkPopGift(PayManager.PURCHARSE_ACT_TYPE.WEAPON_GIFT)
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:setTexture("assets/arts/textures/background/weapon/".. self.weaponEntity:getIconId() .. ".png")
self.txLevel:setText(I18N:getGlobalText(I18N.GlobalConst.EQUIP_DESC_3) .. self.weaponEntity:getLevel().."/"..self.weaponEntity:getMaxLevel())
self.txAttr:setText(self.weaponEntity:getAttrDesc())
local height = self.txAttr:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT_MESH_PRO).preferredHeight
self.attrContent:setSizeDeltaY(height + 5)
self.attrContent:setAnchoredPosition(0, 0)
-- 基础属性
local diffAtk = (nextWeaponEntity:getBaseAttack() - self.weaponEntity:getBaseAttack()) // DEFAULT_FACTOR
local diffNormalHurt = (nextWeaponEntity:getNormalHurt() - self.weaponEntity:getNormalHurt()) // DEFAULT_FACTOR
local diffSkillHurt = (nextWeaponEntity:getSkillHurt() - self.weaponEntity:getSkillHurt()) // DEFAULT_FACTOR
local diffHp = (nextWeaponEntity:getBaseHp() - self.weaponEntity:getBaseHp()) // 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 add = uiMap["weapon_info.upgrade.cost.cost_" .. i .. ".img_icon.img_add"]
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
local atlas, name = GFunc.getIconRes(costId)
icon:setSprite(atlas, name, function ()
icon:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_IMAGE):SetNativeSize()
end)
add:setActive(costNum - haveNum > 0)
icon:addClickListener(function()
UIManager:showUI("app/ui/dungeon/item_get_ui", {id = costId, value = costNum - haveNum < 0 and 0 or costNum - haveNum})
end)
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
self.btnUp:setTouchEnable(self.heroEntity:isActived())
local canLvUp = self.weaponEntity:canLevelUp()
if self.heroEntity:isActived() and 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