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)) local gift = DataManager.ShopData:getPopUpGiftByType(PayManager.PURCHARSE_ACT_TYPE.WEAPON_GIFT) if gift and #gift > 0 then ModuleManager.ShopManager:triggerGiftPopUI(PayManager.PURCHARSE_TYPE.ACT_GIFT, gift[1]) end 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) self.attrContent:setAnchoredPosition(0, 0) -- 基础属性 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(""..I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_3).."") txNum:setText(self.weaponEntity:getAttack() // DEFAULT_FACTOR .. "+" .. diffAtk .. "") 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(""..I18N:getGlobalText(I18N.GlobalConst.ATTR_NORMAL_HURT).."") txNum:setText(self.weaponEntity:getNormalHurt() // DEFAULT_FACTOR .. "+" .. diffNormalHurt .. "") 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(""..I18N:getGlobalText(I18N.GlobalConst.ATTR_SKILL_HURT).."") txNum:setText(self.weaponEntity:getSkillHurt() // DEFAULT_FACTOR .. "+" .. diffSkillHurt .. "") 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(""..I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_2).."") txNum:setText(self.weaponEntity:getHp() // DEFAULT_FACTOR .. "+" .. diffHp .. "") 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("" .. haveNum .. "/" .. 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("" .. self.weaponEntity:getUpgradeGoldNum() .. "") 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