miduo_client/Assets/ManagedResources/~Lua/Modules/Likability/LikeAbilityPanel.lua

178 lines
6.4 KiB
Lua
Raw Normal View History

2021-09-22 20:47:13 +08:00
require("Base/BasePanel")
LikeAbilityPanel = Inherit(BasePanel)
local sortOrder = 0
local tabs = {}
local tabsImg = {"z_icon_01_zh", "r_hero_huo 1_zh", "r_hero_feng 1_zh", "r_hero_shui 1_zh", "r_hero_dadi 1_zh"}
local proId = 0
local heroData = {}
function LikeAbilityPanel:InitComponent()
self.spLoader = SpriteLoader.New()
self.help = Util.GetGameObject(self.transform, "help")
self.helpPos = self.help:GetComponent("RectTransform").localPosition
self.btnBack = Util.GetGameObject(self.transform, "btnBack")
self.heroGrid = Util.GetGameObject(self.transform, "heroScroll")
self.heroPre = Util.GetGameObject(self.transform, "heroPre")
local v = Util.GetGameObject(self.gameObject, "rect"):GetComponent("RectTransform").rect
self.heroScroll = SubUIManager.Open(SubUIConfig.ScrollCycleView,self.heroPre, self.heroGrid, Vector2.New(v.width, v.height), 1, 3, Vector3.zero)
self.btnPrant = Util.GetGameObject(self.gameObject, "Tabs")
for i = 0, 4 do
tabs[i] = Util.GetGameObject(self.btnPrant"grid/Btn" .. i)
if tabsImg[i + 1] then
Util.GetGameObject(tabs[i], "Image"):GetComponent("Image").sprite = self.spLoader:LoadSprite(tabsImg[i + 1])
end
end
self.selectBtn = Util.GetGameObject(self.btnPrant, "selectBtn")
self.likeabilityBtn = Util.GetGameObject(self.gameObject, "likeabilityBtn")
self.likeabilityDi = Util.GetGameObject(self.likeabilityBtn, "di"):GetComponent("Image")
self.likeabilitymask = Util.GetGameObject(self.likeabilityDi, "mask"):GetComponent("Image")
self.lv = Util.GetGameObject(self.likeabilityBtn, "lv"):GetComponent("Text")
self.progress = Util.GetGameObject(self.likeabilityBtn, "progress"):GetComponent("Text")
self.title = Util.GetGameObject(self.gameObject, "titleDi/title"):GetComponent("Text")
self.pro = Util.GetGameObject(self.transform, "di/pro")
self.proGrid = Util.GetGameObject(self.transform, "di/proScroll")
self.proList = {}
end
function LikeAbilityPanel:BindEvent()
for i = 0, 4 do
Util.AddClick(tabs[i], function()
if i == proId then
proId = ProIdConst.All
else
proId = i
end
heroData = LikabilityManager.GetCurSortHeroListData(proId)
self:SetSelectBtn()
self:UpdataHeroDataPanel()
end)
end
Util.AddClick(self.btnBack, function()
self:ClosePanel()
end)
Util.AddClick(self.help, function()
UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.Likeability,self.helpPos.x, self.helpPos.y)
end)
Util.AddClick(self.likeabilityBtn, function()
end)
end
--添加事件监听(用于子类重写)
function LikeAbilityPanel:AddListener()
end
--移除事件监听(用于子类重写)
function LikeAbilityPanel:RemoveListener()
end
function LikeAbilityPanel:OnSortingOrderChange()
end
function LikeAbilityPanel:OnOpen()
end
function LikeAbilityPanel:OnShow()
heroData = LikabilityManager.GetCurSortHeroListData(proId)
self:SetSelectBtn()
self:UpdataHeroDataPanel()
end
function LikeAbilityPanel:UpdateTopLayoutPanel()
local num,lv,totalNum = LikabilityManager.GetTotalHeroLikeLv(-1)
self.likeabilityDi.sprite = self.spLoader:LoadSprite()
self.likeabilitymask.sprite = self.spLoader:LoadSprite()
self.lv.text = lv
self.progress.text = string.format("%s/%s",num,totalNum)
self.title.text = "【好感度】总加成"
self:UpDataProList(lv)
end
function LikeAbilityPanel:UpDataProList(lv)
local list = {}
local proList = {}
local pro1 = LikabilityManager:GetViewProData(1,-1,lv,"0总好感度属性","全体%s 全体%s","",nil)
table.insert(list,pro1)
local pro2 = LikabilityManager:GetViewProData(1,lv,lv,"0当前等级加成","属性:%s %s","特权:%s",nil)
table.insert(list,pro2)
for i = 1,#self.proList do
self.proList[i].go.gameObject:SetActive(false)
end
local index = 0
for i = 1,#list do
for k,v in ipairs(list[i]) do
self:UpDataProSingleList(list[i],index)
index = index + 1
end
end
end
function LikeAbilityPanel:UpDataProSingleList(data,index)
if not self.proList[index] then
self.proList[index] = {}
self.proList[index].go = newObjToParent(self.pro,self.proGrid)
end
self.proList[index].go.gameObject:SetActive(true)
self.proList[index].point = Util.GetGameObject(self.proList[index].go, "point")
self.proList[index].title = Util.GetGameObject(self.proList[index].go, "title"):GetComponent("Text")
if tonumber(string.sub(data,1,1)) == 0 then
self.proList[index].point.gameObject:SetActive(true)
else
self.proList[index].point.gameObject:SetActive(false)
end
self.proList[index].title.text = data
end
function LikeAbilityPanel:UpdataHeroDataPanel()
self.heroScroll:ForeachItemGO(function(index,go)
go.gameObject:SetActive(false)
end)
self.heroScroll:SetData(heroData, function (index, go)
self:SingleHeroDataShow(go, heroData[index])
end)
end
function LikeAbilityPanel:SingleHeroDataShow(_go,data)
local card = Util.GetGameObject(_go.transform, "card")
local bg = Util.GetGameObject(card, "bg")
local icon = Util.GetGameObject(card, "icon"):GetComponent("Image")
icon.sprite = self.spLoader:LoadSprite(GetResourcePath(data.Painting))
SetHeroBg(self.spLoader,card ,bg ,heroData.Star,heroData.Quality)
local pro = Util.GetGameObject(_go.transform, "card/pro/Image"):GetComponent("Image")
pro.sprite = self.spLoader:LoadSprite(GetProStrImageByProNum(heroData.PropertyName))
local choose = Util.GetGameObject(card, "choosed")
choose.gameObject:SetActive(false)
local num,lv,totalNum = LikabilityManager.GetTotalHeroLikeLv(heroData.Id)
local level = Util.GetGameObject(card, "likeability/lv"):GetComponent("Text")
local progress = Util.GetGameObject(card, "likeability/progress"):GetComponent("Text")
level.text = lv
progress.text = num.."/"..totalNum
Util.AddOnceClick(card, function()
UIManager.OpenPanel(UIName.HeroLikeAbilityPanel,data)
end)
end
function LikeAbilityPanel:SetSelectBtn()
self.selectBtn.transform:SetParent(tabs[proId].transform)
self.selectBtn:GetComponent("RectTransform").localPosition = Vector3.zero
end
function LikeAbilityPanel:OnClose()
end
--界面销毁时调用(用于子类重写)
function LikeAbilityPanel:OnDestroy()
self.spLoader:Destroy()
self.proList = {}
end
return LikeAbilityPanel