local UIWarHorseSkin = UIViewClass() local EventSystem = require('Event/EventSystem') function UIWarHorseSkin:OnOpened(context) self.selectAppearanceId = context.appearanceId self.clickedIndex = -1 self:UpdateInfo(context.horseConfig) self:RegistSystemEvent(EventID.UI_UpdateHorseAppearance, self.OnRefreshInfo) end function UIWarHorseSkin:OnRefreshInfo() self:UpdateInfo(self.context.horseConfig) end function UIWarHorseSkin:UpdateInfo(horseConfig, isNewHorse) self.horseID = horseConfig and horseConfig.HorseID or self.horseID local horseData = MDL.WarHorse.GetInfoByID(self.horseID) self.originalAppearanceID = horseData.HorseInfo.horseAppearanceId UIUtils.SetActive(self.context.parentView.group_Hero, false) -- 将原皮肤加入第一个 local originAppearanceData = setmetatable({isOrigin = true}, {__index = horseConfig}) local showList = MDL.WarHorse.GetAppearanceDataList() table.insert(showList, 1, originAppearanceData) if self.selectAppearanceId then for index, v in ipairs(showList) do if self.selectAppearanceId == v.ID then self.clickedIndex = index - 1 break end end end self.Scroll_ChangeHero:ReloadAll(showList) if self.selectAppearanceId or (self.clickedIndex >= 0 and not isNewHorse) then self.Scroll_ChangeHero:UpdateIndex(self.clickedIndex) self.Scroll_ChangeHero:SelectIndex(self.clickedIndex, true) else local curEquippedID = MDL.WarHorse.GetEquippedAppearanceIDByHorseID(self.horseID) if curEquippedID == 0 then self.Scroll_ChangeHero:SelectIndex(0) else local curIndex for i = 1, #showList do if showList[i].ID == curEquippedID then curIndex = i break end end self.Scroll_ChangeHero:SelectIndex(curIndex - 1) end end end function UIWarHorseSkin:OnButtonClicked(comp) if comp == self.btn_Change then if self.curAppearanceData.isOrigin then MDL.WarHorse.HorseAppearanceLineSetReq(self.horseID, 0) else CTL.WarHorse.OnClickChangeBattleAppearance(self.horseID, self.curAppearanceData.ID) end end end function UIWarHorseSkin:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.Scroll_ChangeHero then UIUtils.SetActive(cellTable.img_Selected, self.clickedIndex == index) if data.isOrigin then cellTable.txt_HeroName:SetText(UIUtils.GetLocalizedTxt(Const_IDS["IDS_HorseAppearance_FirstAppearance"])) UIUtils.SetImageByAssetBundle(cellTable.img_HorseHead, data.HorsePicture) UTL.Color.SetQualityImageByType(cellTable.img_HeroBg, data.HorseQuality, UTL.Color.QualityType.CharacterUIModify) UTL.Color.SetQualityImageByType(cellTable.img_Frame, data.HorseQuality, UTL.Color.QualityType.CharacterUIFrame) UIUtils.SetActive(cellTable.mask_Locked, false) if self.originalAppearanceID > 0 then UIUtils.SetActive(cellTable.img_UsedBg, false) else UIUtils.SetActive(cellTable.img_UsedBg, true) end else cellTable.txt_HeroName:SetText(UIUtils.GetLocalizedTxt(Const_IDS[data.Name])) UIUtils.SetImageByAssetBundle(cellTable.img_HorseHead, data.HorsePicture) UTL.Color.SetQualityImageByType(cellTable.img_HeroBg, data.Color, UTL.Color.QualityType.CharacterUIModify) UTL.Color.SetQualityImageByType(cellTable.img_Frame, data.Color, UTL.Color.QualityType.CharacterUIFrame) -- 设置皮肤icon UV if #data.IconXYZ > 0 then cellTable.img_HorseHead:SetPivotCenter(data.IconXYZ[1], data.IconXYZ[2]) cellTable.img_HorseHead:SetScaleRadio(data.IconScale) end local activeState = MDL.WarHorse.GetOwnType(data.ID) UIUtils.SetActive(cellTable.mask_Locked, activeState == MDL.WarHorse.OwnedType.UnOwned or activeState == MDL.WarHorse.OwnedType.Overdue) -- 未拥有 local equippedAppearanceID = MDL.WarHorse.GetEquippedAppearanceIDByHorseID(self.horseID) if equippedAppearanceID == data.ID or (data.isOrigin and equippedAppearanceID == 0) then UIUtils.SetActive(cellTable.img_UsedBg, true) else UIUtils.SetActive(cellTable.img_UsedBg, false) end end end end function UIWarHorseSkin:OnCellSelect(scrollRect, index, cellTable, data) self.curAppearanceData = data local lastIndex = self.clickedIndex self.clickedIndex = index UIUtils.SetActive(cellTable.img_Selected, true) self:RefreshAppearanceInfo(data) scrollRect:UpdateIndex(lastIndex) if data.isOrigin then -- 更换模型 EventSystem.Dispatch(EventID.UI_WarHorse_UpdateModelShow, true, 0) else EventSystem.Dispatch(EventID.UI_WarHorse_UpdateModelShow, true, data.ID) end end function UIWarHorseSkin:RefreshAppearanceInfo(appearanceData) if appearanceData.isOrigin then UIUtils.SetActive(self.effect_Panel.gameObject, false) UIUtils.SetActive(self.img_Expiration, false) UIUtils.SetActive(self.groupLimit, true) UIUtils.SetActive(self.img_BlackBG, false) self.btn_Change:SetGray(self.originalAppearanceID == 0) UIUtils.SetLabelText(self.txt_Change, self.originalAppearanceID > 0 and Const_IDS["IDS_Team_ChangeHint_2"] or Const_IDS["IDS_HorseAppearance_Wearing"]) UIUtils.SetActive(self.btn_Change, true) else local equippedHorseID = MDL.WarHorse.GetEquippedHorseIDByAppearanceID(appearanceData.ID) local activeState = MDL.WarHorse.GetOwnType(appearanceData.ID) local isActive = activeState <= MDL.WarHorse.OwnedType.TimeLimit local isDisable = (equippedHorseID > 0 and self.horseID == equippedHorseID) or activeState >= MDL.WarHorse.OwnedType.Overdue local isSet = equippedHorseID > 0 and self.horseID == equippedHorseID UIUtils.SetActive(self.effect_Panel.gameObject, true) UIUtils.SetActive(self.img_Expiration, activeState <= MDL.WarHorse.OwnedType.Overdue) --拥有显示时间期限 UIUtils.SetActive(self.groupLimit, false) -- 战马皮肤属性 for index, v in ipairs(appearanceData.Attr_Table) do UTL.Attr.SetWarHorseScrollingAttr(self.effectTxtCollection[index], v.AttrType, v.AttrNum, false, true) end UIUtils.SetLabelText(self.txt_SourceTxt, Const_IDS[appearanceData.Describe]) -- 按钮文字状态 UIUtils.SetActive(self.img_BlackBG, not isActive) UIUtils.SetActive(self.btn_Change, isActive) UIUtils.SetLabelText(self.txt_Change, isSet and Const_IDS["IDS_HorseAppearance_Wearing"] or Const_IDS["IDS_Team_ChangeHint_2"]) self.btn_Change:SetGray(isDisable or isSet) -- 皮肤时间 CTL.WarHorse.SetStateTimerTxt(appearanceData.ID, self.txt_countDownTimer, self.img_Expiration) end end return UIWarHorseSkin