-- 头像&头像框更换 local UIChangePlayerAvatarPopUp = UIViewClass() local TabType = CTL.Decoration.TabType local Ids_TabType = { Const_IDS.IDS_HeadPortraitAndBox_Title5, Const_IDS.IDS_HeadPortraitAndBox_Title4, Const_IDS.IDS_Decorate_Competition, Const_IDS.IDS_Decorate_ClickEffect, Const_IDS.IDS_Decorate_ChatBubble, Const_IDS.IDS_Decorate_NameDye, } local TabRedPoint = { CTL.RedPoint.RedPointKey.TownHead_Team_Head_Portrait, CTL.RedPoint.RedPointKey.TownHead_Team_Head_Frame, CTL.RedPoint.RedPointKey.TownHead_Team_Head_Competition, CTL.RedPoint.RedPointKey.TownHead_Team_Head_ClickEffect, CTL.RedPoint.RedPointKey.TownHead_Team_Head_ChatBubble, CTL.RedPoint.RedPointKey.TownHead_Team_Head_NameDye, } local GenderAll = 3 -------------------- function UIChangePlayerAvatarPopUp:OnCreated() self.curTabType = "" self.curSelectIndex = 0 self.curSelectInfo = nil self.rightLoopList = {} end function UIChangePlayerAvatarPopUp:OnOpened(context) UIUtils.SetLabelText(self.UICommonPopUpTab.txt_Title, Const_IDS.IDS_HeadPortraitAndBox_Title3) self:RegistSystemEvent(EventID.UI_PlayerHeadPortraitAndBox_Refresh, self.RefreshHeadPortraitLoop) self:RegistSystemEvent(EventID.UI_Decoration_Data_Refresh, self.RefreshDecorationLoop) for _, value in ipairs(TabRedPoint) do self:RegistSystemEvent(value, self.RefreshTabRedPoint) end self:HeadPortraitAndBoxTabInit() self.UICommonPopUpTab.loop_Tab:SelectIndex(0) UIUtils.SetCanvasSortingOrderByMainCanvas(self.gameObject:GetComponent(typeof(UnityEngine.Canvas)), self.nameCanvas, CTL.Character.UpOrder.ChannelChat) end function UIChangePlayerAvatarPopUp:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUpTab.btn_Close) end function UIChangePlayerAvatarPopUp:OnButtonClicked(comp) if comp == self.UICommonPopUpTab.btn_Close then self:CloseView() elseif comp == self.btn_Wear then if not self.curSelectInfo then return end if self.curTabType == TabType.HeadPortrait then -- 当前为头像页签 if self.curSelectInfo.IsWear then -- 当前选择的头像是装备中的 MDL.Character.SetDefaultPortrait() else MDL.Character.PortraitChangeRequest(self.curSelectInfo.ID) end elseif self.curTabType == TabType.HeadPortraitBox then -- 当前为头像框页签 if self.curSelectInfo.IsWear then -- 当前选择头像框是装备中的 MDL.Character.SetDefaultFrame() else MDL.Character.FrameChangeRequest(self.curSelectInfo.ID) end else --装饰 local typ = CTL.Decoration.GetDecorationTypeByTabType(self.curTabType) MDL.Decoration.ChooseDecorateReq(typ, self.curSelectInfo.ID) end end end function UIChangePlayerAvatarPopUp:OnCellSelect(scrollRect, index, cellTable, data) if scrollRect == self.UICommonPopUpTab.loop_Tab then self.curTabType = index if self.curTabType == TabType.HeadPortrait or self.curTabType == TabType.HeadPortraitBox then self:RefreshHeadPortraitLoop() else self:RefreshDecorationLoop() end self:SelectCurWearingItem() elseif scrollRect == self.Scroll_ChangeHero then self.curSelectIndex = index self:RefreshLeftInfo(data) if not MDL.Character.IsActiveByInfo(data) then CTL.Sound.PlayGameSound("UI_invalid") end end end function UIChangePlayerAvatarPopUp:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.UICommonPopUpTab.loop_Tab then UIUtils.SetLabelText(cellTable.txt_Name_Nomal, data) UIUtils.SetLabelText(cellTable.txt_Name_Selected, data) UIUtils.SetActive(cellTable.img_Arrow, false) UIUtils.SetActive(cellTable.img_ArrowS, false) UIUtils.SetActive(cellTable.group_SignState, false) UIUtils.SetActive(cellTable.group_SignStateS, false) local redPoint = CTL.RedPoint.GetRedPointActive(TabRedPoint[index+1]) cellTable.cell:SetRedPoint(redPoint) elseif scrollRect == self.Scroll_ChangeHero then if self.curTabType == TabType.HeadPortrait then self:RefreshHeadCell(cellTable, data) CTL.Character.SetPortraitAndFrame(cellTable.UIHeroHeadTemplate, data.ID, nil, nil, BattleDataGetter.GetAcID()) elseif self.curTabType == TabType.HeadPortraitBox then self:RefreshHeadCell(cellTable, data) CTL.Character.SetPortraitAndFrame(cellTable.UIHeroHeadTemplate, nil, data.ID, nil, BattleDataGetter.GetAcID()) else self:RefreshDecorationCell(cellTable, data) end end end function UIChangePlayerAvatarPopUp:RefreshHeadCell(cellTable, data) cellTable.state_ItemSwitch:SetState(0) UIUtils.SetActive(cellTable.img_Wearing, data.IsWear) UIUtils.SetActive(cellTable.img_New, data.IsNew) local isLock = data.OwnedType == MDL.Character.OwnedType.UnOwned or data.OwnedType == MDL.Character.OwnedType.Overdue UIUtils.SetActive(cellTable.img_Lock, isLock) end function UIChangePlayerAvatarPopUp:RefreshDecorationCell(cellTable, data) local info = MDL.Decoration.GetDecorationInfo(data.type, data.ID) UIUtils.SetActive(cellTable.img_New, info.isNew) UIUtils.SetActive(cellTable.img_Wearing, MDL.Decoration.GetWearingDecorationId(data.type) == data.ID) UIUtils.SetActive(cellTable.img_Lock, not info.isActive) if self.curTabType == TabType.Competition then cellTable.state_ItemSwitch:SetState(1) UIUtils.SetImageByAssetBundle(cellTable.Competitive, info.cfgData.Image) elseif self.curTabType == TabType.ClickEffect then cellTable.state_ItemSwitch:SetState(2) UIUtils.SetImageByAssetBundle(cellTable.ClickEffect, info.cfgData.Image) elseif self.curTabType == TabType.ChatBubble then cellTable.state_ItemSwitch:SetState(3) UIUtils.SetImageByAssetBundle(cellTable.ChatBubble, info.cfgData.Image) elseif self.curTabType == TabType.NameDye then cellTable.state_ItemSwitch:SetState(4) UIUtils.SetImageByAssetBundle(cellTable.NameDye, info.cfgData.Image) end end -------------------- function UIChangePlayerAvatarPopUp:HeadPortraitAndBoxTabInit() for key, value in ipairs(Ids_TabType) do self.UICommonPopUpTab.loop_Tab:AddData(value, 0) end end function UIChangePlayerAvatarPopUp:RefreshTabRedPoint() for i, v in ipairs(TabRedPoint) do local rpActive =CTL.RedPoint.GetRedPointActive(v) self.UICommonPopUpTab.loop_Tab:GetCellTableByIndex(i-1).cell:SetRedPoint(rpActive) end end function UIChangePlayerAvatarPopUp:RefreshHeadPortraitLoop(isKeepSelect) local count = 1 if self.curTabType == TabType.HeadPortrait then local selfGender = MDL.Player.GetSelfGender() for _, info in MDL.Character.GetPortraitsListIterator() do local isShowByGender = info.Gender == GenderAll or info.Gender == selfGender local isShowByHero = info.HeroID == 0 or MDL.HideGolden.IsShowGoldenByID(LuaConst.ShowGoldenType.Hero, info.HeroID) --觉醒头像 if info.GetType == MDL.Character.GetType.AwakenActive and info.ID == CTL.HeroAwaken.GetAwakenPortraitId(info.HeroID) then isShowByGender = CTL.HeroAwaken.IsShowHeroAwakenEntry(info.HeroID) end if isShowByGender and isShowByHero then self.rightLoopList[count] = info count = count + 1 end end elseif self.curTabType == TabType.HeadPortraitBox then for _, info in MDL.Character.GetFramesListIterator() do self.rightLoopList[count] = info count = count + 1 end end for i = #self.rightLoopList, count, -1 do table.remove(self.rightLoopList, i) end --将穿戴的放在第一位 local tmpInfo for i, v in ipairs(self.rightLoopList) do if v.IsWear then tmpInfo = table.remove(self.rightLoopList, i) break end end table.insert(self.rightLoopList, 1, tmpInfo) self:RepositionScroll(isKeepSelect) end function UIChangePlayerAvatarPopUp:RefreshDecorationLoop(isKeepSelect) table.clear(self.rightLoopList) local list = CTL.Decoration.GetDecorationListByTabType(self.curTabType) for index, value in ipairs(list) do table.insert(self.rightLoopList, value) end self:RepositionScroll(isKeepSelect) end function UIChangePlayerAvatarPopUp:RepositionScroll(isKeepSelect) -- 这里ClearCell 是为了防止切换页签的时候 MoveIndex 报错 if not isKeepSelect then self.Scroll_ChangeHero:ClearCells() end self.Scroll_ChangeHero:ReloadAll(self.rightLoopList) if isKeepSelect then for i, v in ipairs(self.rightLoopList) do if self.curSelectInfo and self.curSelectInfo.ID == v.ID then if self.curSelectIndex ~= i-1 then self.curSelectIndex = i-1 self.Scroll_ChangeHero:MoveIndex(self.curSelectIndex) end self.Scroll_ChangeHero:SelectIndex(self.curSelectIndex) break end end end end function UIChangePlayerAvatarPopUp:RefreshLeftInfo(info) self.curSelectInfo = info if self.curTabType == TabType.HeadPortrait then CTL.Character.SetPortraitAndFrame(self.UIHeroHeadTemplate, info.ID, nil, nil, BattleDataGetter.GetAcID()) UIUtils.SetLabel(self.txt_GetWay, CTL.Character.GetDescribeByPortraitId(info.ID)) -- 消除红点 if info.IsNew then MDL.Character.PortraitBrowseRequest(info.ID) end self:SetLeftHeadBasicInfo() elseif self.curTabType == TabType.HeadPortraitBox then CTL.Character.SetPortraitAndFrame(self.UIHeroHeadTemplate, nil, info.ID, nil, BattleDataGetter.GetAcID()) UIUtils.SetLabelText(self.txt_GetWay, Const_IDS[info.Describe]) -- 消除红点 if info.IsNew then MDL.Character.FrameBrowseRequest(info.ID) end self:SetLeftHeadBasicInfo() else self:RefreshDecorationLeftInfo() end end function UIChangePlayerAvatarPopUp:RefreshDecorationLeftInfo() local info = MDL.Decoration.GetDecorationInfo(self.curSelectInfo.type, self.curSelectInfo.ID) if self.curTabType == TabType.Competition then self.state_ItemSwitch:SetState(1) UIUtils.SetImageByAssetBundle(self.Competitive, info.cfgData.Image) elseif self.curTabType == TabType.ClickEffect then self.state_ItemSwitch:SetState(2) self.ClickEffect:PlayUIEffect(info.cfgData.Resource, -1) elseif self.curTabType == TabType.ChatBubble then self.state_ItemSwitch:SetState(3) UIUtils.SetImageByAssetBundle(self.ChatBubble, info.cfgData.Resource) elseif self.curTabType == TabType.NameDye then self.state_ItemSwitch:SetState(4) UIUtils.SetImageByAssetBundle(self.img_NameDye, info.cfgData.Resource) end UIUtils.SetLabelText(self.txt_Name, Const_IDS[info.cfgData.Name]) UIUtils.SetLabelText(self.txt_GetWay, Const_IDS[info.cfgData.Describe]) local isWear = MDL.Decoration.GetWearingDecorationId(self.curSelectInfo.type) == self.curSelectInfo.ID self.State_BtnWear:SetState(isWear and 1 or 0) self.btn_Wear:SetGray(isWear or not info.isActive) self.txt_PropState:EndTimer() if info.isActive then if info.expireTime > UTL.Time.GetServerTimestamp() then local time = info.expireTime - UTL.Time.GetServerTimestamp() self.txt_PropState:SetDHMSStr(UIUtils.GetLocalizedTxt(Const_IDS.IDS_HeadPortraitAndBox_Period1), UIUtils.GetLocalizedTxt(Const_IDS.IDS_HeadPortraitAndBox_Period2), UIUtils.GetLocalizedTxt(Const_IDS.IDS_HeadPortraitAndBox_Period3), UIUtils.GetLocalizedTxt(Const_IDS.IDS_HeadPortraitAndBox_Period4)) self.txt_PropState:ResetAndBeginCustomTimer(false, time, 0, nil) else self.txt_PropState:SetCDLabel(UIUtils.GetLocalizedTxt(Const_IDS.IDS_HeadPortraitAndBox_GotForever)) end self.btn_Wear.enabled = not isWear elseif info.expireTime > 0 then self.txt_PropState:SetCDLabel(UIUtils.GetLocalizedTxt(Const_IDS.IDS_HeadPortraitAndBox_overdue2)) self.btn_Wear.enabled = false else self.txt_PropState:SetCDLabel(UIUtils.GetLocalizedTxt(Const_IDS.IDS_HeadPortraitAndBox_NotGet)) self.btn_Wear.enabled = false end -- 消除红点 if info.isNew then MDL.Decoration.RemoveDecorateRedPointReq(self.curSelectInfo.type, self.curSelectInfo.ID) end end -- 设置头像、头像框基本状态信息 function UIChangePlayerAvatarPopUp:SetLeftHeadBasicInfo() self.state_ItemSwitch:SetState(0) UIUtils.SetLabelText(self.txt_Name, Const_IDS[self.curSelectInfo.Name]) self.State_BtnWear:SetState(self.curSelectInfo.IsWear and 1 or 0) self.btn_Wear:SetGray(self.curSelectInfo.IsWear or not MDL.Character.IsActiveByInfo(self.curSelectInfo)) if self.curSelectInfo.OwnedType == MDL.Character.OwnedType.Forever then self.txt_PropState:EndTimer() self.txt_PropState:SetCDLabel(UIUtils.GetLocalizedTxt(Const_IDS.IDS_HeadPortraitAndBox_GotForever)) self.btn_Wear.enabled = not self.curSelectInfo.IsWear elseif self.curSelectInfo.OwnedType == MDL.Character.OwnedType.TimeLimit then local time = self.curSelectInfo.InvalidTimeStamp - UTL.Time.GetServerTimestamp() self.txt_PropState:SetDHMSStr(UIUtils.GetLocalizedTxt(Const_IDS.IDS_HeadPortraitAndBox_Period1), UIUtils.GetLocalizedTxt(Const_IDS.IDS_HeadPortraitAndBox_Period2), UIUtils.GetLocalizedTxt(Const_IDS.IDS_HeadPortraitAndBox_Period3), UIUtils.GetLocalizedTxt(Const_IDS.IDS_HeadPortraitAndBox_Period4)) self.txt_PropState:ResetAndBeginCustomTimer(false, time, 0, nil) self.btn_Wear.enabled = not self.curSelectInfo.IsWear elseif self.curSelectInfo.OwnedType == MDL.Character.OwnedType.Overdue then self.txt_PropState:EndTimer() self.txt_PropState:SetCDLabel(UIUtils.GetLocalizedTxt(Const_IDS.IDS_HeadPortraitAndBox_overdue2)) self.btn_Wear.enabled = false elseif self.curSelectInfo.OwnedType == MDL.Character.OwnedType.UnOwned then self.txt_PropState:EndTimer() self.txt_PropState:SetCDLabel(UIUtils.GetLocalizedTxt(Const_IDS.IDS_HeadPortraitAndBox_NotGet)) self.btn_Wear.enabled = false end end function UIChangePlayerAvatarPopUp:SelectCurWearingItem() local curWearID if self.curTabType == TabType.HeadPortrait then curWearID = MDL.Character.GetCurWearPortrait() elseif self.curTabType == TabType.HeadPortraitBox then curWearID = MDL.Character.GetCurWearFrame() else --装饰 curWearID = CTL.Decoration.GetCurWearingDecorationIdByTabType(self.curTabType) end for i, v in ipairs(self.rightLoopList) do --得保证都是ID这个命名 if v.ID == curWearID then -- index从0开始,for从1开始,所以此处 -1 self.Scroll_ChangeHero:MoveIndex(i - 1) self.Scroll_ChangeHero:SelectIndex(i - 1) return end end self.Scroll_ChangeHero:MoveIndex(0) self.Scroll_ChangeHero:SelectIndex(0) end return UIChangePlayerAvatarPopUp