local UIWarHorseChangeView = UIViewClass() local EventSystem = require('Event/EventSystem') --排序规则:未装备 > 已装备 > 品质 local function sortRule(a,b) if a.HeroID ~= nil and b.HeroID == nil then return true elseif a.HeroID == nil and b.HeroID ~= nil then return false else if a.ConfigInfo.HorseQuality ~= b.ConfigInfo.HorseQuality then return a.ConfigInfo.HorseQuality > b.ConfigInfo.HorseQuality else return a.ConfigInfo.HorseID < b.ConfigInfo.HorseID end end end function UIWarHorseChangeView:OnOpened(context) UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_Horse_Change_2) UIUtils.SetLabelText(self.lab_NoWarHorse, Const_IDS.IDS_Horse_Change_2) self.toggle_Hide:SetToggleIDS("lab_Hide", Const_IDS.IDS_Horse_Change_1) self.heroId = context.HeroID self.curInfo = context.HorseInfo --服务器Info self:UpdateInfo() local isOn = false if self.curInfo ~= nil then isOn = MDL.Player.Get_TypeState(MDL.Player.WearViewToggleStateType.HorseChange) else isOn = MDL.Player.Get_TypeState(MDL.Player.WearViewToggleStateType.HorseWear) end if isOn == self.toggle_Hide.isOn then self:UpdateCell(isOn) else self.toggle_Hide.isOn = isOn end end function UIWarHorseChangeView:UpdateInfo() local horseInfoDir = MDL.WarHorse.GetActiveHorseInfoDic() if horseInfoDir == nil then self.infoList = nil else self.infoList = {} if self.curInfo then --更换 for _,v in pairs(horseInfoDir) do if v.ID ~= self.curInfo.Id then table.insert(self.infoList,v) end end else --穿戴 for _,v in pairs(horseInfoDir) do table.insert(self.infoList,v) end end end if self.infoList and #self.infoList > 0 then table.sort(self.infoList,sortRule) self.group_Mid:SetState(0) else --无激活坐骑 self.group_Mid:SetState(1) UIUtils.SetActive(self.toggle_Hide.gameObject,false) end end function UIWarHorseChangeView:OnCellInit(scrollRect, index, cellTable, data) local btnLabel = self.curInfo and Const_IDS["IDS_Horse_Title_5"] or Const_IDS["IDS_Horse_Change_5"] UIUtils.SetLabelText(cellTable.Text, btnLabel) cellTable.txt_Qua.text = data.ConfigInfo.HorseTalent if CTL.WarHorse.GetHorousBreakRelation(data.ConfigInfo.HorseID, self.heroId, false) then -- 有战骑羁绊时特殊显示 cellTable.txt_WarHorseName.text = string.FormatByIdsId(Const_IDS.IDS_HorseRelation_ExclusiveHorse, UTL.Color.FormatQualityText(UIUtils.GetLocalizedTxt(Const_IDS[data.ConfigInfo.HorseName]), data.ConfigInfo.HorseQuality)) else cellTable.txt_WarHorseName.text = UTL.Color.FormatQualityText(UIUtils.GetLocalizedTxt(Const_IDS[data.ConfigInfo.HorseName]), data.ConfigInfo.HorseQuality) end local itemId = data.ConfigInfo.Item_Table[1].ItemID UTL.Item.ItemSquareIcon(cellTable.img_Item, cellTable.sprite_Rank, itemId) UTL.Item.PlayItemEffect(cellTable, itemId) if data.HorseInfo.starLevel == 0 then UIUtils.SetActive(cellTable.bg_Strengthen.gameObject, false) else UIUtils.SetLabel(cellTable.lab_Strengthen, "+" .. data.HorseInfo.starLevel) UIUtils.SetActive(cellTable.bg_Strengthen.gameObject, true) end if data.HeroID then cellTable.obj_state:SetState(0) local heroData = DataSheetManager.HeroNum:GetDataByID(data.HeroID) UIUtils.SetLabelText(cellTable.lab_HeroName, Const_IDS[heroData.NameIDS]) else cellTable.obj_state:SetState(1) end local gsExceed = false if data.HeroID == nil and self.curInfo ~= nil then gsExceed = data.HorseInfo.gs + CTL.WarHorse.GetHorousRelationSkillGs(data.ConfigInfo.HorseID, self.heroId) > self.curInfo.gs + CTL.WarHorse.GetHorousRelationSkillGs(self.curInfo.Id, self.heroId) end if self.curInfo == nil and CTL.WarHorse.CheckHeroHorseIfWear(self.heroId) then --穿戴红点 cellTable.btn_Change:SetRedPoint(data.HeroID == nil) elseif self.curInfo ~= nil and gsExceed then --替换红点 cellTable.btn_Change:SetRedPoint(true) else cellTable.btn_Change:SetRedPoint(false) end UIUtils.SetActive(cellTable.img_Assistance, MDL.AssistanceFight.IsHorseOnAssistancePos(data.ConfigInfo.HorseID)) end function UIWarHorseChangeView:OnCellClicked(scrollRect, index, cellTable, target, data) if target == cellTable.btn_Change then if self.curInfo then--替换 local func = function() MDL.WarHorse.HorseEquipRequest(self.heroId, data.ConfigInfo.HorseID, Const_IDS.IDS_Horse_Change_6) self:CloseView() end UTL.MessageBox.ShowOKCancelBox(nil, Const_IDS.IDS_Horse_Change_3, func, nil) else--穿戴 MDL.WarHorse.HorseEquipRequest(self.heroId, data.ConfigInfo.HorseID, Const_IDS.IDS_Horse_Change_4) self:CloseView() end end end function UIWarHorseChangeView:OnValueChanged(comp, state) if comp == self.toggle_Hide then self:UpdateCell(state) end end function UIWarHorseChangeView:UpdateCell(state) self.loop_ChangeWarHorseScroll:ClearCells() local isEmpty = true if self.infoList then for i = 1, #self.infoList do if (state == false or (state == true and self.infoList[i].HeroID == nil)) then isEmpty = false self.loop_ChangeWarHorseScroll:AddData(self.infoList[i], 0) end end end if isEmpty then self.group_Mid:SetState(1) else self.group_Mid:SetState(0) end if self.curInfo ~= nil then MDL.Player.Set_TypeState(MDL.Player.WearViewToggleStateType.HorseChange, state) else MDL.Player.Set_TypeState(MDL.Player.WearViewToggleStateType.HorseWear, state) end end function UIWarHorseChangeView:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end function UIWarHorseChangeView:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close then self:CloseView() end end return UIWarHorseChangeView