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

195 lines
7.6 KiB
Lua
Raw Normal View History

2021-09-22 20:47:13 +08:00
require("Base/BasePanel")
LikeAbilityPanel = Inherit(BasePanel)
2021-09-26 09:54:58 +08:00
--<size=32><color=#fdf5e5>全体生命</color></size> --白色
--<size=32><color=#fc902c>特权</color></size>--橙色
--<size=32><color=#fed97f>总好感度属性:</color></size> --黄色
--<color=#5dc446>+500</color></size> --绿色
2021-09-22 20:47:13 +08:00
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")
2021-09-26 09:54:58 +08:00
local v = self.heroGrid:GetComponent("RectTransform").rect
self.heroScroll = SubUIManager.Open(SubUIConfig.ScrollCycleView,self.heroGrid.transform,self.heroPre, nil, Vector2.New(v.width, v.height), 1, 4, Vector2.New(50,50))
2021-09-22 20:47:13 +08:00
self.btnPrant = Util.GetGameObject(self.gameObject, "Tabs")
for i = 0, 4 do
2021-09-26 09:54:58 +08:00
tabs[i] = Util.GetGameObject(self.btnPrant,"grid/Btn" .. i)
2021-09-22 20:47:13 +08:00
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")
2021-09-26 09:54:58 +08:00
--h_haogandu_1 h_haogandu_2 h_haogandu_3
self.likeabilitymask = Util.GetGameObject(self.likeabilityDi.transform, "mask"):GetComponent("Image")
--self.likeabilitymask.fillAmount
2021-09-22 20:47:13 +08:00
self.lv = Util.GetGameObject(self.likeabilityBtn, "lv"):GetComponent("Text")
self.progress = Util.GetGameObject(self.likeabilityBtn, "progress"):GetComponent("Text")
self.pro = Util.GetGameObject(self.transform, "di/pro")
2021-09-26 09:54:58 +08:00
self.proContent = Util.GetGameObject(self.pro, "content")
2021-09-22 20:47:13 +08:00
self.proGrid = Util.GetGameObject(self.transform, "di/proScroll")
self.proList = {}
2021-09-26 09:54:58 +08:00
self.noneGo = Util.GetGameObject(self.transform, "NoneImage")
2021-09-22 20:47:13 +08:00
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()
2021-09-26 09:54:58 +08:00
UIManager.OpenPanel(UIName.LikeabilityPopup)
2021-09-22 20:47:13 +08:00
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()
2021-09-26 09:54:58 +08:00
self:UpdateTopLayoutPanel()
2021-09-22 20:47:13 +08:00
end
function LikeAbilityPanel:UpdateTopLayoutPanel()
local num,lv,totalNum = LikabilityManager.GetTotalHeroLikeLv(-1)
2021-09-26 09:54:58 +08:00
local config = ConfigManager.GetConfigDataByDoubleKey(ConfigName.LikeAbility,"Type",1,"Level",lv)
self.likeabilityDi.sprite = self.spLoader:LoadSprite(config.Bg)
2021-09-22 20:47:13 +08:00
self.lv.text = lv
2021-09-26 09:54:58 +08:00
if not totalNum or totalNum <= 0 then
self.likeabilitymask.fillAmount = 1
self.progress.text = "好感度最佳"
else
self.likeabilitymask.fillAmount = num/totalNum
2021-09-26 10:18:51 +08:00
self.progress.text = string.format("%s/%s",num,totalNum)
2021-09-26 09:54:58 +08:00
end
2021-09-22 20:47:13 +08:00
self:UpDataProList(lv)
end
function LikeAbilityPanel:UpDataProList(lv)
2021-09-26 10:18:51 +08:00
local pro1 = LikabilityManager.GetViewProData(1,-1,lv,"<color=#fed97f>总好感度属性:</color>","","<color=#%s>全体%s 全体%s</color>","",nil)
local pro2 = LikabilityManager.GetViewProData(1,lv,lv,"<color=#fed97f>当前等级加成:</color>","","<color=#%s>属性:%s %s</color>","<color=#%s>特权:%s</color>",nil)
2021-09-22 20:47:13 +08:00
for i = 1,#self.proList do
self.proList[i].go.gameObject:SetActive(false)
end
2021-09-26 09:54:58 +08:00
self:UpDataProSingleList(pro1,1)
self:UpDataProSingleList(pro2,2)
2021-09-22 20:47:13 +08:00
end
function LikeAbilityPanel:UpDataProSingleList(data,index)
if not self.proList[index] then
self.proList[index] = {}
self.proList[index].go = newObjToParent(self.pro,self.proGrid)
2021-09-26 13:55:57 +08:00
self.proList[index].title = Util.GetGameObject(self.proList[index].go, "title"):GetComponent("Text")
2021-09-22 20:47:13 +08:00
end
2021-09-26 13:55:57 +08:00
self.proList[index].go.gameObject:SetActive(true)
self.proList[index].title.text = data.content
2021-09-26 09:54:58 +08:00
for i = 1,math.max(#self.proList[index],#data.prolist) do
2021-09-26 10:18:51 +08:00
if not data.prolist[i] then
2021-09-26 09:54:58 +08:00
self.proList[index][i].go.gameObject:SetActive(false)
else
if not self.proList[index][i] then
self.proList[index][i] = {}
self.proList[index][i].go = newObjToParent(self.proContent,self.proList[index].go)
self.proList[index][i].goText = self.proList[index][i].go:GetComponent("Text")
2021-09-26 13:55:57 +08:00
end
if data.prolist[i] == "" then
self.proList[index][i].go.gameObject:SetActive(false)
else
self.proList[index][i].go.gameObject:SetActive(true)
self.proList[index][i].goText.text = data.prolist[i]
2021-09-26 09:54:58 +08:00
end
end
2021-09-22 20:47:13 +08:00
end
2021-09-26 13:55:57 +08:00
2021-09-22 20:47:13 +08:00
end
function LikeAbilityPanel:UpdataHeroDataPanel()
2021-09-26 09:54:58 +08:00
if not heroData or #heroData < 1 then
self.noneGo.gameObject:SetActive(true)
self.heroScroll.gameObject:SetActive(false)
else
self.noneGo.gameObject:SetActive(false)
self.heroScroll.gameObject:SetActive(true)
end
2021-09-22 20:47:13 +08:00
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))
2021-09-26 09:54:58 +08:00
SetHeroBg(self.spLoader,card ,bg ,data.Star,data.Quality)
2021-09-22 20:47:13 +08:00
local pro = Util.GetGameObject(_go.transform, "card/pro/Image"):GetComponent("Image")
2021-09-26 09:54:58 +08:00
pro.sprite = self.spLoader:LoadSprite(GetProStrImageByProNum(data.PropertyName))
2021-09-22 20:47:13 +08:00
local choose = Util.GetGameObject(card, "choosed")
choose.gameObject:SetActive(false)
2021-09-26 09:54:58 +08:00
local num,lv,totalNum = LikabilityManager.GetTotalHeroLikeLv(data.Id)
2021-09-22 20:47:13 +08:00
local level = Util.GetGameObject(card, "likeability/lv"):GetComponent("Text")
level.text = lv
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