local HeroInfoCell = class("HeroInfoCell", BaseCell) local FIELD_CELL = "app/ui/gm/cell/field_cell" local HERO_INFO = { -- as = 1, heroid = 2, level = 3, ishero = 4, collision_radius = 5, group = 6, atk = 7, hp = 8, def = 9, spd = 10, crit = 11, crit_dmg = 12, acc = 13, resist = 14, move = 15, ultimate_skill_1 = 16, ultimate_skill_2 = 17, ultimate_skill_3 = 18, passive_skill_1 = 19, passive_skill_2 = 20, move_factor = 21, model_id = 22, x = 23, y = 24, z = 25 } local STRING_FIELD = { [HERO_INFO.model_id] = true } local HERO_DEFAULT_INFO_DESC = { -- [HERO_INFO.as] = "觉醒等级", [HERO_INFO.heroid] = "英雄id", [HERO_INFO.ishero] = "是英雄", [HERO_INFO.collision_radius] = "碰撞半径", [HERO_INFO.group] = "属性阵营", [HERO_INFO.atk] = "攻击", [HERO_INFO.hp] = "血量", [HERO_INFO.def] = "防御", [HERO_INFO.spd] = "行动值", [HERO_INFO.crit] = "暴击率", [HERO_INFO.crit_dmg] = "暴击伤害", [HERO_INFO.acc] = "减益命中", [HERO_INFO.resist] = "减益抵抗", [HERO_INFO.move] = "移动速度", [HERO_INFO.ultimate_skill_1] = "主动技能1", [HERO_INFO.ultimate_skill_2] = "主动技能2", [HERO_INFO.ultimate_skill_3] = "主动技能3", [HERO_INFO.passive_skill_1] = "被动技能1", [HERO_INFO.passive_skill_2] = "被动技能2", [HERO_INFO.move_factor] = "减速系数", [HERO_INFO.level] = "等级", [HERO_INFO.model_id] = "模型ID", [HERO_INFO.x] = "初始坐标X", [HERO_INFO.y] = "初始坐标Y", [HERO_INFO.z] = "初始坐标Z" } local HERO_FIELD_TRANS = { ["ultimate_skill_1"] = "active_skill_1", ["ultimate_skill_2"] = "active_skill_2", ["ultimate_skill_3"] = "active_skill_3", } function HeroInfoCell:refresh(heroInfo) self.heroInfo = heroInfo or {} self.filedList = {} if not self.heroInfo.collision_radius and not self.heroInfo.hid then local info = {} for field, index in pairs(HERO_INFO) do if heroInfo and heroInfo[field] then info[field] = heroInfo[field] else if not STRING_FIELD[index] then info[field] = 0 else info[field] = "" end end end self.heroInfo = info end local uiMap = self:getUIMap() uiMap["hero_info_cell.sync_btn.Text"]:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT).text = "配置表同步" uiMap["hero_info_cell.clear_btn.Text"]:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT).text = "清除选定" uiMap["hero_info_cell.clear_btn"]:addClickListener(function() self:refresh() end) uiMap["hero_info_cell.sync_btn"]:addClickListener(function() self:syncCfg() end) if not self.heroCell then self.heroCell = CellManager:addCellComp(uiMap["hero_info_cell.hero_cell"], GConst.TYPEOF_LUA_CLASS.HERO_CELL) end if self.heroInfo.ishero == 1 then self.heroCell:refreshWithHeroId(self.heroInfo.heroid, self.heroInfo.level, self.heroInfo.as or 0) else self.heroCell:refreshWithMonsterId(self.heroInfo.heroid) end if self.heroInfo.heroid <= 0 then self.heroCell:refreshEmpty() end uiMap["hero_info_cell.scrollrect"]:setActive(self.heroInfo.hid == nil) uiMap["hero_info_cell.sync_btn"]:setActive(self.heroInfo.hid == nil) if self.heroInfo.hid ~= nil then return end for k, v in pairs(self.heroInfo) do table.insert(self.filedList, k) end table.sort(self.filedList, function(a, b) return HERO_INFO[a] < HERO_INFO[b] end) local y = math.min(50 * #self.filedList / 5) uiMap["hero_info_cell.scrollrect"]:setSizeDeltaY(y) if self.fieldScrollRect then self.fieldScrollRect:updateAllCell() return end self.fieldScrollRect = uiMap["hero_info_cell.scrollrect"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE) self.fieldScrollRect:clearCells() self.fieldScrollRect:setFadeArgs(0, 0.3) self.fieldScrollRect:addInitCallback(function() return FIELD_CELL end) self.fieldScrollRect:addRefreshCallback(function(index, cell) local field = self.filedList[index] cell:refresh(HERO_DEFAULT_INFO_DESC[HERO_INFO[field]], self.heroInfo, field, STRING_FIELD[HERO_INFO[field]]) end) self.fieldScrollRect:refillCells(#self.filedList) end function HeroInfoCell:syncCfg() self:getHeroInfo() if self.heroInfo then local cfg if self.heroInfo.ishero == 1 then cfg = ConfigManager:getConfig("hero")[self.heroInfo.heroid] if cfg then for k, value in pairs(self.heroInfo) do local field = k if HERO_FIELD_TRANS[field] then field = HERO_FIELD_TRANS[field] end if cfg[field] then self.heroInfo[k] = cfg[field] end end end else cfg = ConfigManager:getConfig("monster")[self.heroInfo.heroid] if cfg then for k, value in pairs(self.heroInfo) do local field = k if field == "ultimate_skill_1" then if cfg["act_skillid"] and cfg["act_skillid"][1] then self.heroInfo[k] = cfg["act_skillid"][1] end elseif field == "ultimate_skill_2" then if cfg["act_skillid"] and cfg["act_skillid"][2] then self.heroInfo[k] = cfg["act_skillid"][3] end elseif field == "ultimate_skill_3" then if cfg["act_skillid"] and cfg["act_skillid"][3] then self.heroInfo[k] = cfg["act_skillid"][3] end else if cfg[field] then self.heroInfo[k] = cfg[field] end end end end end self:refresh(self.heroInfo) end end function HeroInfoCell:getHeroInfo() if self.fieldScrollRect and not self.heroInfo.hid then self.fieldScrollRect:getAllCellAndIndex(function(index, cell) local k, v = cell:getKV() self.heroInfo[k] = v end) end return self.heroInfo end return HeroInfoCell