106 lines
No EOL
4 KiB
Lua
106 lines
No EOL
4 KiB
Lua
XUiPanelDetailTeamItem = XClass(nil, "XUiPanelDetailTeamItem")
|
||
|
||
function XUiPanelDetailTeamItem:Ctor(ui)
|
||
self.GameObject = ui.gameObject
|
||
self.Transform = ui.transform
|
||
self:InitAutoScript()
|
||
end
|
||
|
||
-- auto
|
||
-- Automatic generation of code, forbid to edit
|
||
function XUiPanelDetailTeamItem:InitAutoScript()
|
||
self:AutoInitUi()
|
||
self:AutoAddListener()
|
||
end
|
||
|
||
function XUiPanelDetailTeamItem:AutoInitUi()
|
||
self.TxtVoteNum = self.Transform:Find("TxtVoteNum"):GetComponent("Text")
|
||
self.BtnVote = self.Transform:Find("RootPanelBtn/BtnVote"):GetComponent("Button")
|
||
self.PanelCharItem1 = self.Transform:Find("layout/PanelCharItem1")
|
||
self.TxtName1 = self.Transform:Find("layout/PanelCharItem1/TxtName1"):GetComponent("Text")
|
||
self.RImgQuality1 = self.Transform:Find("layout/PanelCharItem1/RImgQuality1"):GetComponent("RawImage")
|
||
self.PanelCharItem2 = self.Transform:Find("layout/PanelCharItem2")
|
||
self.TxtName2 = self.Transform:Find("layout/PanelCharItem2/TxtName2"):GetComponent("Text")
|
||
self.RImgQuality2 = self.Transform:Find("layout/PanelCharItem2/RImgQuality2"):GetComponent("RawImage")
|
||
self.PanelCharItem3 = self.Transform:Find("layout/PanelCharItem3")
|
||
self.TxtName3 = self.Transform:Find("layout/PanelCharItem3/TxtName3"):GetComponent("Text")
|
||
self.RImgQuality3 = self.Transform:Find("layout/PanelCharItem3/RImgQuality3"):GetComponent("RawImage")
|
||
self.TxtRank = self.Transform:Find("RootPanelRank/TxtRank"):GetComponent("Text")
|
||
self.PanelImgVoted = self.Transform:Find("RootPanelBtn/PanelImgVoted")
|
||
end
|
||
|
||
function XUiPanelDetailTeamItem:RegisterClickEvent(uiNode, func)
|
||
if func == nil then
|
||
XLog.Error("XUiPanelDetailTeamItem:RegisterClickEvent函数参数错误:参数func不能为空")
|
||
return
|
||
end
|
||
|
||
if type(func) ~= "function" then
|
||
XLog.Error("XUiPanelDetailTeamItem:RegisterClickEvent函数错误, 参数func需要是function类型, func的类型是" .. type(func))
|
||
end
|
||
|
||
local listener = function(...)
|
||
func(self, ...)
|
||
end
|
||
|
||
CsXUiHelper.RegisterClickEvent(uiNode, listener)
|
||
end
|
||
|
||
function XUiPanelDetailTeamItem:AutoAddListener()
|
||
self:RegisterClickEvent(self.BtnVote, self.OnBtnVoteClick)
|
||
end
|
||
-- auto
|
||
function XUiPanelDetailTeamItem:Init(rootUi)
|
||
self.RootUi = rootUi
|
||
end
|
||
|
||
function XUiPanelDetailTeamItem:UpdateView(recommendConfig, rank, curCharacterId)
|
||
self.VoteId = recommendConfig.Id
|
||
self.CurCharacterId = curCharacterId
|
||
|
||
self.TxtRank.text = rank
|
||
|
||
local template = XCharacterConfigs.GetCharDetailParnerTemplate(self.VoteId)
|
||
local charList = template.CharacterRecomend
|
||
|
||
for i = 1, 3 do
|
||
local templateId
|
||
if i == 1 then
|
||
templateId = self.CurCharacterId
|
||
else
|
||
templateId = charList[i - 1]
|
||
end
|
||
|
||
local indexKey = string.format("CharGrid%s", i)
|
||
local itemKey = string.format("PanelCharItem%s", i)
|
||
local grid = self[indexKey]
|
||
if not grid then
|
||
grid = XUiGridCommon.New(self.RootUi, self[itemKey])
|
||
self[indexKey] = grid
|
||
end
|
||
grid:Refresh(templateId)
|
||
|
||
local quality = XCharacterConfigs.GetCharMinQuality(templateId)
|
||
self["RImgQuality" .. i]:SetRawImage(XCharacterConfigs.GetCharacterQualityIcon(quality))
|
||
self["TxtName" .. i].text = XCharacterConfigs.GetCharacterFullNameStr(templateId)
|
||
end
|
||
|
||
self:UpdateVoteView()
|
||
end
|
||
|
||
function XUiPanelDetailTeamItem:UpdateVoteView()
|
||
local voteMo = XDataCenter.VoteManager.GetVote(self.VoteId)
|
||
local isGroupVoted = XDataCenter.VoteManager.IsGroupVoted(voteMo.GroupId)
|
||
local isVoteSelected = XDataCenter.VoteManager.IsVoteSelected(voteMo.GroupId, self.VoteId)
|
||
|
||
self.BtnVote.gameObject:SetActive(not isGroupVoted)
|
||
self.PanelImgVoted.gameObject:SetActive(isGroupVoted and isVoteSelected)
|
||
self.TxtVoteNum.text = tostring(voteMo.VoteNum)
|
||
end
|
||
|
||
function XUiPanelDetailTeamItem:OnBtnVoteClick()
|
||
XUiHelper.StopAnimation()
|
||
XDataCenter.VoteManager.AddVote(self.VoteId)
|
||
end
|
||
|
||
return XUiPanelDetailTeamItem |