204 lines
6.7 KiB
Lua
204 lines
6.7 KiB
Lua
local HeroChooseUI = class("HeroChooseUI", BaseUI)
|
|
|
|
local HERO_INFO_CELL = "app/ui/gm/cell/hero_info_cell"
|
|
|
|
local TYPE = {
|
|
HERO = 1,
|
|
MONSTER = 2,
|
|
HERO_BAG = 3
|
|
}
|
|
|
|
function HeroChooseUI:isFullScreen()
|
|
return false
|
|
end
|
|
|
|
function HeroChooseUI:getPrefabPath()
|
|
return "assets/prefabs/ui/gm/hero_choose_ui.prefab"
|
|
end
|
|
|
|
function HeroChooseUI:ctor(params)
|
|
self.heroInfo = params.heroInfo
|
|
self.callback = params.callback
|
|
end
|
|
|
|
function HeroChooseUI:onLoadRootComplete()
|
|
self._baseRootCanvas.sortingOrder = 30002 -- 比develop面板高一点
|
|
self:_display()
|
|
self:_addListeners()
|
|
end
|
|
|
|
function HeroChooseUI:_display()
|
|
local uiMap = self.root:genAllChildren()
|
|
uiMap["hero_choose_ui.close_btn (1).Text"]:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT).text = "确认"
|
|
|
|
self:refreshCurHero(self.heroInfo)
|
|
self:changeType(TYPE.HERO)
|
|
end
|
|
|
|
function HeroChooseUI:_addListeners()
|
|
local uiMap = self.root:genAllChildren()
|
|
uiMap["hero_choose_ui.close_btn"]:addClickListener(function()
|
|
self:closeUI()
|
|
end)
|
|
|
|
uiMap["hero_choose_ui.ok_btn"]:addClickListener(function()
|
|
self:closeUI()
|
|
if self.callback then
|
|
local heroInfo
|
|
if self.infoCell and self.infoCell:getHeroInfo() then
|
|
heroInfo = clone(self.infoCell:getHeroInfo())
|
|
end
|
|
self.callback(heroInfo)
|
|
end
|
|
end)
|
|
|
|
uiMap["hero_choose_ui.scroll_rect.hero"]:addClickListener(function()
|
|
self:changeType(TYPE.HERO)
|
|
end)
|
|
|
|
uiMap["hero_choose_ui.scroll_rect.monster"]:addClickListener(function()
|
|
self:changeType(TYPE.MONSTER)
|
|
end)
|
|
|
|
uiMap["hero_choose_ui.scroll_rect.hero_bag"]:addClickListener(function()
|
|
self:changeType(TYPE.HERO_BAG)
|
|
end)
|
|
end
|
|
|
|
function HeroChooseUI:_refreshHeroScroll()
|
|
if not self.heroList then
|
|
self.heroList = {}
|
|
for id, info in pairs(ConfigManager:getConfig("hero")) do
|
|
table.insert(self.heroList, {id = id, cfg = info})
|
|
end
|
|
table.sort(self.heroList, function(a, b)
|
|
if a.cfg.qlt == b.cfg.qlt then
|
|
return a.id > b.id
|
|
else
|
|
return a.cfg.qlt > b.cfg.qlt
|
|
end
|
|
end)
|
|
|
|
self.monsterList = {}
|
|
for id, info in pairs(ConfigManager:getConfig("monster")) do
|
|
table.insert(self.monsterList, {id = id, cfg = info})
|
|
end
|
|
table.sort(self.monsterList, function(a, b)
|
|
if a.cfg.qlt == b.cfg.qlt then
|
|
return a.id > b.id
|
|
else
|
|
return a.cfg.qlt > b.cfg.qlt
|
|
end
|
|
end)
|
|
|
|
self.heroBagList = {}
|
|
for hid, entity in pairs(DataManager.HeroData:getAllHero()) do
|
|
table.insert(self.heroBagList, entity)
|
|
end
|
|
table.sort(self.heroBagList, function(a, b)
|
|
if a:getQuality() == b:getQuality() then
|
|
return a:getHid() > b:getHid()
|
|
else
|
|
return a:getQuality() > b:getQuality()
|
|
end
|
|
end)
|
|
end
|
|
|
|
if self.curPage == TYPE.HERO then
|
|
self.curList = self.heroList
|
|
elseif self.curPage == TYPE.MONSTER then
|
|
self.curList = self.monsterList
|
|
else
|
|
self.curList = self.heroBagList
|
|
end
|
|
|
|
if self.scrollRect then
|
|
self.scrollRect:clearCells()
|
|
self.scrollRect:refillCells(#self.curList)
|
|
return
|
|
end
|
|
|
|
local uiMap = self.root:genAllChildren()
|
|
local scrollView = uiMap["hero_choose_ui.scroll_rect"]
|
|
self.scrollRect = scrollView:getLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE)
|
|
self.scrollRect:clearCells()
|
|
self.scrollRect:setFadeArgs(0, 0.3)
|
|
self.scrollRect:addInitCallback(function()
|
|
return GConst.TYPEOF_LUA_CLASS.HERO_CELL
|
|
end)
|
|
self.scrollRect:addRefreshCallback(function(index, cell)
|
|
if self.curPage ~= TYPE.MONSTER then
|
|
if self.curPage == TYPE.HERO_BAG then
|
|
cell:refreshWithHeroId(self.curList[index]:getId(), self.curList[index]:getLv(), self.curList[index]:getAscended())
|
|
else
|
|
cell:refreshWithHeroId(self.curList[index].id, 1, 0)
|
|
end
|
|
else
|
|
cell:refreshWithMonsterId(self.curList[index].id)
|
|
end
|
|
cell:addClickListener(function()
|
|
local params
|
|
|
|
if self.curPage == TYPE.HERO_BAG then
|
|
params = {}
|
|
local entity = self.curList[index]
|
|
params.ishero = 1
|
|
params.heroid = entity:getId()
|
|
params.level = entity:getLv()
|
|
params.as = entity:getAscended()
|
|
params.hid = entity:getHid()
|
|
else
|
|
if self.heroInfo and self.heroInfo.heroid == self.curList[index].id then
|
|
params = clone(self.heroInfo)
|
|
else
|
|
params = {heroid = self.curList[index].id, level= 1, as = 0}
|
|
end
|
|
|
|
params.as = 0
|
|
params.ishero = self.curPage == TYPE.MONSTER and 0 or 1
|
|
params.hid = nil
|
|
end
|
|
self:refreshCurHero(params)
|
|
end)
|
|
end)
|
|
self.scrollRect:refillCells(#self.curList)
|
|
end
|
|
|
|
function HeroChooseUI:refreshCurHero(heroInfo)
|
|
if not self.infoCell then
|
|
local uiMap = self.root:genAllChildren()
|
|
self.infoCell = CellManager:addCellComp(uiMap["hero_choose_ui.hero_node.hero_info_cell"], HERO_INFO_CELL)
|
|
end
|
|
self.infoCell:refresh(heroInfo)
|
|
end
|
|
|
|
function HeroChooseUI:changeType(type)
|
|
if self.curPage == type then
|
|
return
|
|
end
|
|
self.curPage = type
|
|
local uiMap = self.root:genAllChildren()
|
|
local heroBtn = uiMap["hero_choose_ui.scroll_rect.hero"]
|
|
local heroBtnText = uiMap["hero_choose_ui.scroll_rect.hero.Text"]
|
|
|
|
local monsterBtn = uiMap["hero_choose_ui.scroll_rect.monster"]
|
|
local monsterBtntext = uiMap["hero_choose_ui.scroll_rect.monster.Text"]
|
|
|
|
local heroBagBtn = uiMap["hero_choose_ui.scroll_rect.hero_bag"]
|
|
local heroBagBtnText = uiMap["hero_choose_ui.scroll_rect.hero_bag.Text"]
|
|
|
|
local normalSprite = "common_menu_3"
|
|
local highlightSprite = "common_menu_1"
|
|
|
|
heroBtn:setSprite(GConst.ATLAS_PATH.COMMON, self.curPage == TYPE.HERO and highlightSprite or normalSprite)
|
|
monsterBtn:setSprite(GConst.ATLAS_PATH.COMMON, self.curPage == TYPE.MONSTER and highlightSprite or normalSprite)
|
|
heroBagBtn:setSprite(GConst.ATLAS_PATH.COMMON, self.curPage == TYPE.HERO_BAG and highlightSprite or normalSprite)
|
|
|
|
heroBtnText:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT).text = "hero"
|
|
monsterBtntext:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT).text = "monster"
|
|
heroBagBtnText:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT).text = "英雄背包"
|
|
|
|
self:_refreshHeroScroll()
|
|
end
|
|
|
|
return HeroChooseUI |