c1_lua/lua/app/ui/tips/equip_tips.lua
2023-04-03 10:59:13 +08:00

153 lines
5.2 KiB
Lua

local EquipEntity = require "app/userdata/bag/equip_entity"
local BaseTips = require "app/ui/tips/base_tips"
local EquipTips = class("EquipTips", BaseTips)
local QLT_SKILL_DESC_CELL = "app/ui/equip/cell/qlt_skill_desc_cell"
local QLT_REFINE_DESC_CELL = "app/ui/equip/cell/qlt_refine_desc_cell"
function EquipTips:getPrefabPath()
return "assets/prefabs/ui/tips/equip_tips.prefab"
end
function EquipTips:ctor(params)
self.equipEntity = params and params.entity
if not self.equipEntity then
local id = params and params.id
-- self.equipEntity = EquipEntity:create({id = id, lv = 1})
self.equipEntity = DataManager.BagData.EquipData:getEquipByCfgId(id)
end
end
function EquipTips:onLoadRootComplete()
self:_initObj()
end
function EquipTips:_initObj()
local uiMap = self.root:genAllChildren()
uiMap["equip_tips.bg.close_btn"]:addClickListener(function()
self:closeUI()
end)
local uiMap = self.root:genAllChildren()
self.nameTx = uiMap["equip_tips.bg.name_tx"]
self.qltTx = uiMap["equip_tips.bg.qlt_tx"]
self.slider = uiMap["equip_tips.bg.slider_bg.slider"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER)
self.sliderTx = uiMap["equip_tips.bg.slider_bg.slider_tx"]
self.attrTx = uiMap["equip_tips.bg.attr_tx"]
self.arrowImg = uiMap["equip_tips.bg.arrow_img"]
self.diffTx = uiMap["equip_tips.bg.diff_tx"]
self.lvTx = uiMap["equip_tips.bg.lv_tx"]
self.equipCell = CellManager:addCellComp(uiMap["equip_tips.bg.equip_cell"], GConst.TYPEOF_LUA_CLASS.EQUIP_CELL)
self.descTx1 = uiMap["equip_tips.bg.desc_tx_1"]
self.attrTx1 = uiMap["equip_tips.bg.attr_tx_1"]
self.bg2 = uiMap["equip_tips.bg.bg2"]
self.bg = uiMap["equip_tips.bg"]
self.skillCells = {}
self.skillTxs = {}
for i = 1, 3 do
self.skillCells[i] = CellManager:addCellComp(uiMap["equip_tips.bg.bg2.skill_cell_" .. i], GConst.TYPEOF_LUA_CLASS.SKILL_CELL)
self.skillTxs[i] = uiMap["equip_tips.bg.bg2.skill_desc_tx_" .. i]
end
end
function EquipTips:onRefresh()
local attrs = self.equipEntity:getAllOwnAttr()
local attrStr
local valueStr
for k,v in pairs(attrs) do
if not attrStr then
attrStr = GFunc.getAttrName(k)
else
attrStr = attrStr .. "&" .. GFunc.getAttrName(k)
end
if not valueStr then
valueStr = string.format("<color=%s>%s</color>", GConst.COLOR_CODE.GREEN, " +" .. GFunc.getFinalPerStr(k, v))
end
end
attrStr = attrStr .. valueStr
self.descTx1:setText(I18N:getGlobalText(I18N.GlobalConst.EQUIP_DESC_1))
self.attrTx1:setText(attrStr)
local selWearAttrBigNum
local attrs = self.equipEntity:getAllWearAttr()
local attrStr
local valueStr
for k,v in pairs(attrs) do
if not attrStr then
attrStr = GFunc.getAttrName(k)
else
attrStr = attrStr .. "&" .. GFunc.getAttrName(k)
end
if not valueStr then
selWearAttrBigNum = v
valueStr = string.format("<color=%s>%s</color>", GConst.COLOR_CODE.GREEN, " +" .. GFunc.getFinalPerStr(k, v))
end
end
attrStr = attrStr .. valueStr
self.attrTx:setText(attrStr)
local wearEquip = DataManager.FightInfoData:getWearEquipByPart(self.equipEntity:getPart())
if wearEquip then
local wearAttr = wearEquip:getAllWearAttr()
local wearWearAttrBigNum, wearWearAttrType
for k,v in pairs(wearAttr) do
wearWearAttrBigNum = v
wearWearAttrType = k
break
end
if BigNumOpt.bigNumCompare(selWearAttrBigNum, wearWearAttrBigNum) == 0 then
self.arrowImg:setVisible(false)
self.diffTx:setVisible(false)
else
local bigNum = BigNumOpt.bigNumSub(selWearAttrBigNum, wearWearAttrBigNum)
local attrStr = GFunc.getFinalPerStr(wearWearAttrType, bigNum)
if BigNumOpt.bigNumCompare(selWearAttrBigNum, wearWearAttrBigNum) > 0 then
self.arrowImg:setVisible(true)
self.diffTx:setVisible(true)
self.arrowImg:setSprite(GConst.ATLAS_PATH.COMMON, "common_arrow_1")
self.diffTx:setText(string.format("<color=%s>%s</color>", GConst.COLOR_CODE.GREEN, attrStr))
else
self.arrowImg:setVisible(true)
self.diffTx:setVisible(true)
self.arrowImg:setSprite(GConst.ATLAS_PATH.COMMON, "common_arrow_2")
self.diffTx:setText(string.format("<color=%s>%s</color>", GConst.COLOR_CODE.RED, attrStr))
end
local meshProComp = self.attrTx:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT_MESH_PRO)
self.arrowImg:setAnchoredPositionX(120 + meshProComp.preferredWidth)
self.diffTx:setAnchoredPositionX(135 + meshProComp.preferredWidth)
end
else
self.arrowImg:setVisible(false)
self.diffTx:setVisible(false)
end
local num = self.equipEntity:getCount()
local needNum = self.equipEntity:getNeedNum()
self.sliderTx:setText(num .. "/" .. needNum)
self.slider.value = num / needNum
local qlt = self.equipEntity:getQuality()
local str = string.format("<color=%s>%s</color>", GConst.QUALITY_TYPE[qlt], I18N:getGlobalText("QLT_DESC_" .. qlt))
self.qltTx:setText(str)
self.nameTx:setText(self.equipEntity:getName())
self.lvTx:setText(I18N:getGlobalText(I18N.GlobalConst.LV_POINT, self.equipEntity:getLv()))
if self.equipEntity:getPart() == 1 then
self.bg2:setVisible(true)
self.bg:setSizeDeltaY(720)
local skillIds, lvs = self.equipEntity:getSkillIds()
for i = 1, 3 do
self.skillTxs[i]:setText(GFunc.getSkillEffectStr(skillIds[i], lvs[i]))
self.skillCells[i]:refresh(skillIds[i], lvs[i])
end
else
self.bg2:setVisible(false)
self.bg:setSizeDeltaY(388)
end
self.equipCell:refresh(self.equipEntity)
end
return EquipTips