338 lines
11 KiB
Lua
338 lines
11 KiB
Lua
require("Base/BasePanel")
|
|
local TianShuMiJuanMainPanel = Inherit(BasePanel)
|
|
local this = TianShuMiJuanMainPanel
|
|
local gameSetting = ConfigManager.GetConfig(ConfigName.GameSetting)
|
|
local redPointList = {}
|
|
-- Tab管理器
|
|
local TabBox = require("Modules/Common/TabBox")
|
|
local tabs = {
|
|
[1] = { --神将
|
|
default = "r_hero_xuanze_002",
|
|
lock = "r_hero_xuanze_002",
|
|
select = "r_hero_xuanze_001",
|
|
tabName = Language[12903],
|
|
rpType = RedPointType.Hero_Fetter,
|
|
funcType = -1,
|
|
bg = "t_tianshumijuan_shengjiangditu",
|
|
zi = "t_tianshumijuan_shenjiangpian_zi_zh",
|
|
},
|
|
[2] = { --魂印
|
|
default = "r_hero_xuanze_002",
|
|
lock = "r_hero_xuanze_002",
|
|
select = "r_hero_xuanze_001",
|
|
tabName = Language[12904],
|
|
rpType = RedPointType.SoulPrint_Fetter,
|
|
funcType = FUNCTION_OPEN_TYPE.hunyin,
|
|
bg = "t_tianshumijuan_hunyinditu",
|
|
zi = "t_tianshumijuan_hunyingpian_zi_zh", --gamesetting.EquipSignUnlock
|
|
},
|
|
[3] = { --灵兽
|
|
default = "r_hero_xuanze_002",
|
|
lock = "r_hero_xuanze_002",
|
|
select = "r_hero_xuanze_001",
|
|
tabName = Language[12905],
|
|
rpType = RedPointType.TianShuPokemon_Fetter,
|
|
funcType = FUNCTION_OPEN_TYPE.POKEMON,
|
|
bg = "t_tianshumijuan_lingshouditu",
|
|
zi = "t_tianshumijuan_lingshoupian_zi_zh",
|
|
},
|
|
[4] = { --装备
|
|
default = "r_hero_xuanze_002",
|
|
lock = "r_hero_xuanze_002",
|
|
select = "r_hero_xuanze_001",
|
|
tabName = Language[12906],
|
|
rpType = RedPointType.Equip_Fetter,
|
|
funcType = FUNCTION_OPEN_TYPE.COMPOUND,
|
|
bg = "t_tianshumijuan_shengjiangditu",
|
|
zi = "t_tianshumijuan_zhuangbeipian_zi_zh",
|
|
},
|
|
[5] = { --神兵
|
|
default = "r_hero_xuanze_002",
|
|
lock = "r_hero_xuanze_002",
|
|
select = "r_hero_xuanze_001",
|
|
tabName = Language[12907],
|
|
rpType = RedPointType.Weapon_Fetter,
|
|
funcType = FUNCTION_OPEN_TYPE.GodWeapon,
|
|
bg = "t_tianshumijuan_lingshouditu"
|
|
,
|
|
zi = "GodWeaponAtlas_handbook_title_zh",
|
|
},
|
|
[6] = { --法宝
|
|
default = "r_hero_xuanze_002",
|
|
lock = "r_hero_xuanze_002",
|
|
select = "r_hero_xuanze_001",
|
|
tabName = Language[12908],
|
|
rpType = RedPointType.Treasure_Fetter,
|
|
funcType = -1,
|
|
bg = "t_tianshumijuan_lingshouditu"
|
|
,
|
|
zi = "GodWeaponAtlas_handbook_title_zh",
|
|
},
|
|
[7] = { --法相
|
|
default = "r_hero_xuanze_002",
|
|
lock = "r_hero_xuanze_002",
|
|
select = "r_hero_xuanze_001",
|
|
tabName = Language[12909],
|
|
rpType = RedPointType.FaXiang_Fetter,
|
|
funcType = FUNCTION_OPEN_TYPE.FaXiang,
|
|
bg = "t_tianshumijuan_lingshouditu"
|
|
,
|
|
zi = "GodWeaponAtlas_handbook_title_zh",
|
|
},
|
|
[8] = { --身外化身
|
|
default = "r_hero_xuanze_002",
|
|
lock = "r_hero_xuanze_002",
|
|
select = "r_hero_xuanze_001",
|
|
tabName = Language[12910],
|
|
rpType = RedPointType.HuaShen_Fetter,
|
|
funcType = FUNCTION_OPEN_TYPE.Incarnation,
|
|
bg = "t_tianshumijuan_lingshouditu"
|
|
,
|
|
zi = "GodWeaponAtlas_handbook_title_zh",
|
|
},
|
|
}
|
|
local status = {
|
|
[0] = Language[10201],
|
|
[1] = Language[10723],
|
|
[2] = Language[12911],
|
|
}
|
|
local curPage = 1
|
|
local data = {}
|
|
local curShai = 0 --0 全部 1 已激活 2 未激活
|
|
local curData = {}
|
|
--初始化组件(用于子类重写)
|
|
function TianShuMiJuanMainPanel:InitComponent()
|
|
this.spLoader = SpriteLoader.New()
|
|
self.itemPreList = {}
|
|
|
|
self.tabbox = Util.GetGameObject(self.gameObject, "bg/tabbox")
|
|
self.bg = Util.GetGameObject(self.gameObject, "bg/Bg"):GetComponent("Image")
|
|
--self.title = Util.GetGameObject(self.gameObject,"bg/title"):GetComponent("Image") --TextTitle
|
|
self.title = Util.GetGameObject(self.gameObject, "bg/TextTitle"):GetComponent("Text")
|
|
self.btnBack = Util.GetGameObject(self.gameObject, "bg/btnBack")
|
|
self.shai = Util.GetGameObject(self.gameObject, "shai")
|
|
self.shaiText = Util.GetGameObject(self.shai, "Text"):GetComponent("Text")
|
|
--SetTextVerTial(self.shaiText, Vector3.New(30, 0, 0), nil, nil, 10)
|
|
self.fetterItem = Util.GetGameObject(self.gameObject, "fetterItem")
|
|
local grid = Util.GetGameObject(self.gameObject, "bg/fetterGrid")
|
|
local v21 = grid.transform.rect
|
|
self.scroll = SubUIManager.Open(SubUIConfig.ScrollCycleView, grid.transform, self.fetterItem, nil,
|
|
Vector2.New(v21.width, v21.height), 1, 2, Vector2.New(30, 50))
|
|
self.empty = Util.GetGameObject(self.gameObject, "bg/NoneImage")
|
|
|
|
--self.Image = Util.GetGameObject(self.gameObject,"bg/static/Image (1)"):GetComponent("RectTransform")
|
|
end
|
|
|
|
function TianShuMiJuanMainPanel.SetTabAdapter(newTab, index, status)
|
|
local img = Util.GetGameObject(newTab.gameObject, "img"):GetComponent("Image")
|
|
local redpot = Util.GetGameObject(newTab.gameObject, "redpot")
|
|
local tabName = Util.GetGameObject(newTab.gameObject, "Text"):GetComponent("Text")
|
|
local lock = Util.GetGameObject(newTab.gameObject, "lock")
|
|
if tabs[index].rpType > 0 then
|
|
if redPointList[tabs[index].rpType] then
|
|
ClearRedPointObject(tabs[index].rpType, redPointList[tabs[index].rpType])
|
|
end
|
|
BindRedPointObject(tabs[index].rpType, redpot)
|
|
redPointList[tabs[index].rpType] = redpot
|
|
end
|
|
img.sprite = this.spLoader:LoadSprite(tabs[index][status])
|
|
tabName.text = tabs[index].tabName
|
|
if status == "lock" then
|
|
lock.gameObject:SetActive(true)
|
|
else
|
|
lock.gameObject:SetActive(false)
|
|
end
|
|
if tabs[index].funcType < 1 then
|
|
newTab.gameObject:SetActive(true)
|
|
else
|
|
local config = ConfigManager.GetConfigData(ConfigName.GlobalSystemConfig, tabs[index].funcType)
|
|
if config and config.IsOpen == 0 then
|
|
newTab.gameObject:SetActive(false)
|
|
else
|
|
newTab.gameObject:SetActive(true)
|
|
end
|
|
--屏蔽装备篇
|
|
if index == 4 then
|
|
newTab.gameObject:SetActive(false)
|
|
end
|
|
end
|
|
end
|
|
|
|
function TianShuMiJuanMainPanel.TabIsLockCheck(index)
|
|
if tabs[index].funcType > 0 then
|
|
if ActTimeCtrlManager.SingleFuncState(tabs[index].funcType) then
|
|
return false
|
|
else
|
|
return true, ActTimeCtrlManager.SystemOpenTip(tabs[index].funcType)
|
|
end
|
|
else
|
|
return false
|
|
end
|
|
end
|
|
|
|
function TianShuMiJuanMainPanel.SetChangeTabCallBack(index)
|
|
if curPage == index then
|
|
return
|
|
end
|
|
curPage = index
|
|
curShai = 0
|
|
this:OnShow(self)
|
|
end
|
|
|
|
--绑定事件(用于子类重写)
|
|
function TianShuMiJuanMainPanel:BindEvent()
|
|
Util.AddClick(self.btnBack, function()
|
|
self:ClosePanel()
|
|
end)
|
|
Util.AddClick(self.shai, function()
|
|
curShai = curShai + 1
|
|
curShai = curShai % 3
|
|
self.shaiText.text = status[curShai]
|
|
curData = self:ShaiData()
|
|
self:RefreshData(curData)
|
|
end)
|
|
self.tabBox = TabBox.New()
|
|
self.tabBox:SetTabAdapter(self.SetTabAdapter)
|
|
self.tabBox:SetTabIsLockCheck(self.TabIsLockCheck)
|
|
self.tabBox:SetChangeTabCallBack(self.SetChangeTabCallBack)
|
|
end
|
|
|
|
--添加事件监听(用于子类重写)
|
|
function TianShuMiJuanMainPanel:AddListener()
|
|
|
|
end
|
|
|
|
--移除事件监听(用于子类重写)
|
|
function TianShuMiJuanMainPanel:RemoveListener()
|
|
|
|
end
|
|
|
|
--界面打开时调用(用于子类重写)
|
|
function TianShuMiJuanMainPanel:OnOpen(...)
|
|
local args = { ... }
|
|
curPage = args[1] or 1
|
|
curShai = 0
|
|
self.shaiText.text = status[curShai]
|
|
self.tabBox:Init(self.tabbox.gameObject, tabs, curPage)
|
|
end
|
|
|
|
-- 打开,重新打开时回调
|
|
function TianShuMiJuanMainPanel:OnShow()
|
|
self.shaiText.text = status[curShai]
|
|
self.bg.sprite = this.spLoader:LoadSprite(tabs[curPage].bg)
|
|
self.title.text = tabs[curPage].tabName --this.spLoader:LoadSprite(tabs[curPage].zi)
|
|
data = TianShuMiJuanManger.GetFetterDataByFetterType(curPage)
|
|
curData = self:ShaiData()
|
|
self:RefreshData()
|
|
end
|
|
|
|
function TianShuMiJuanMainPanel:RefreshData()
|
|
--self:ChengeSize()
|
|
self:SortData()
|
|
self.scroll:ForeachItemGO(function(index, go)
|
|
go.gameObject:SetActive(false)
|
|
end)
|
|
if not curData or #curData < 1 then
|
|
self.empty.gameObject:SetActive(true)
|
|
self.scroll.gameObject:SetActive(false)
|
|
else
|
|
self.empty.gameObject:SetActive(false)
|
|
self.scroll.gameObject:SetActive(true)
|
|
self.scroll:SetData(curData, function(index, go)
|
|
self:SetSingleData(go, curData[index], index)
|
|
end)
|
|
self.scroll:SetIndex(1)
|
|
end
|
|
end
|
|
|
|
--灯笼大小变化
|
|
function TianShuMiJuanMainPanel:ChengeSize()
|
|
if GetCurLanguage() == -1 then return end
|
|
local width = GetPreferredWidth(self.shaiText.transform)
|
|
local vec = self.Image.transform.sizeDelta
|
|
local shaiVect = self.shai:GetComponent("RectTransform").transform.sizeDelta
|
|
if width > 120 then
|
|
vec.y = width + 400
|
|
shaiVect.y = width + 50
|
|
else
|
|
vec.y = 482
|
|
shaiVect.y = 161
|
|
end
|
|
self.Image.transform.sizeDelta = vec
|
|
self.shai:GetComponent("RectTransform").transform.sizeDelta = shaiVect
|
|
end
|
|
|
|
function TianShuMiJuanMainPanel:ShaiData()
|
|
if not data or #data < 1 then
|
|
return
|
|
end
|
|
local shaiValue = 0
|
|
if curShai == 0 then
|
|
return data
|
|
elseif curShai == 1 then
|
|
shaiValue = 1
|
|
else
|
|
shaiValue = 0
|
|
end
|
|
local returnData = {}
|
|
for k, v in ipairs(data) do
|
|
if shaiValue ~= 0 and v.enabled == shaiValue then
|
|
table.insert(returnData, v)
|
|
elseif shaiValue == 0 and v.enabled < 1 then
|
|
table.insert(returnData, v)
|
|
end
|
|
end
|
|
return returnData
|
|
end
|
|
|
|
local sortData = {
|
|
[0] = 0,
|
|
[1] = 1,
|
|
[-1] = 2,
|
|
}
|
|
function TianShuMiJuanMainPanel:SortData()
|
|
if not curData or #curData < 1 then
|
|
return
|
|
end
|
|
table.sort(curData, function(a, b)
|
|
if sortData[a.enabled] == sortData[b.enabled] then
|
|
return a.id < b.id
|
|
end
|
|
return sortData[a.enabled] < sortData[b.enabled]
|
|
end)
|
|
end
|
|
|
|
function TianShuMiJuanMainPanel:SetSingleData(go, item, index)
|
|
if not self.itemPreList[go] then
|
|
self.itemPreList[go] = SubUIManager.Open(SubUIConfig.FetterItem, go.transform)
|
|
end
|
|
if not item then
|
|
go.gameObject:SetActive(false)
|
|
return
|
|
end
|
|
go.gameObject:SetActive(true)
|
|
self.itemPreList[go]:SetData(item, self, curPage)
|
|
end
|
|
|
|
--界面关闭时调用(用于子类重写)
|
|
function TianShuMiJuanMainPanel:OnClose()
|
|
curPage = 0
|
|
curShai = 0
|
|
end
|
|
|
|
--界面销毁时调用(用于子类重写)
|
|
function TianShuMiJuanMainPanel:OnDestroy()
|
|
this.spLoader:Destroy()
|
|
for k, v in pairs(redPointList) do
|
|
ClearRedPointObject(k, v)
|
|
end
|
|
for k, v in pairs(self.itemPreList) do
|
|
SubUIManager.Close(v)
|
|
end
|
|
SubUIManager.Close(self.scroll)
|
|
self.itemPreList = {}
|
|
redPointList = {}
|
|
end
|
|
|
|
return this
|