--[[ 宠物更换弹窗 ]]-- local UIPetChangeView = UIViewClass() local function CommonSortRule(a, b) -- 上阵>助阵>未上阵 -- 基础战力 -- ID从小到大 local isLineUpA = MDL.Pet.IsPetLineUp(a.Info.petUniqId) local isLineUpB = MDL.Pet.IsPetLineUp(b.Info.petUniqId) if isLineUpA == isLineUpB then local isAssistA = MDL.Pet.IsPetAssistanceFight(a.Info.petUniqId) local isAssistB = MDL.Pet.IsPetAssistanceFight(b.Info.petUniqId) if isAssistA == isAssistB then local powerA = a.Info.baseGS local powerB = b.Info.baseGS if powerA == powerB then return a.Config.ID < b.Config.ID end return powerA > powerB end return isAssistA end return isLineUpA end local function MainSortRule(a, b) local isRed_a = CTL.Pet.CheckPetLineUpRed(UIPetChangeView.changePetUniqId, a.Info.petUniqId, CTL.Pet.ChangePetPanelType.Main) local isRed_b = CTL.Pet.CheckPetLineUpRed(UIPetChangeView.changePetUniqId, b.Info.petUniqId, CTL.Pet.ChangePetPanelType.Main) if isRed_a == isRed_b then return CommonSortRule(a, b) end return isRed_a end local function AssistSortRule(a, b) local isRed_a = CTL.Pet.CheckPetLineUpRed(UIPetChangeView.changePetUniqId, a.Info.petUniqId, CTL.Pet.ChangePetPanelType.Assistance) local isRed_b = CTL.Pet.CheckPetLineUpRed(UIPetChangeView.changePetUniqId, b.Info.petUniqId, CTL.Pet.ChangePetPanelType.Assistance) if isRed_a == isRed_b then return CommonSortRule(a, b) end return isRed_a end function UIPetChangeView:OnOpened(context) self.panelType = context.panelType self.changeIndex = context.changeIndex UIPetChangeView.changePetUniqId = context.changePetUniqId if self.panelType == CTL.Pet.ChangePetPanelType.Assistance then UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_Pet_ChooseHelpPet) self.toggle_Hide:SetToggleIDS("lab_Hide", Const_IDS.IDS_AssistanceFight_ChoosePet_Hint1) else UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_PetChange) self.toggle_Hide:SetToggleIDS("lab_Hide", Const_IDS.IDS_Formation_ChangePet_ShowAllPet) end local isOn = MDL.Player.Get_TypeState(MDL.Player.WearViewToggleStateType.PetChange) if isOn == self.toggle_Hide.isOn then self:UpdateInfo() else self.toggle_Hide.isOn = isOn end end function UIPetChangeView:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end function UIPetChangeView:OnValueChanged(comp, state) if comp == self.toggle_Hide then self:UpdateInfo() MDL.Player.Set_TypeState(MDL.Player.WearViewToggleStateType.PetChange, state) end end function UIPetChangeView:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close then self:CloseView() end end function UIPetChangeView:OnCellInit(scrollRect, index, cellTable, data) local petInfo, petConfig = data.Info, data.Config local isAssist = MDL.Pet.IsPetAssistanceFight(petInfo.petUniqId) local isLineUp = MDL.Pet.IsPetLineUp(petInfo.petUniqId) cellTable.btn_Change:SetRedPoint(CTL.Pet.CheckPetLineUpRed(self.changePetUniqId, petInfo.petUniqId, self.panelType)) cellTable.state_Btn:SetState(1) if self.panelType == CTL.Pet.ChangePetPanelType.Assistance then if self.changePetUniqId and self.changePetUniqId == petInfo.petUniqId then UIUtils.SetLabelText(cellTable.lab_Change, Const_IDS.IDS_AssistanceFight_ChooseHero_Button2) cellTable.state_Btn:SetState(0) else if isAssist then UIUtils.SetLabelText(cellTable.lab_Change, Const_IDS.IDS_Horse_Title_5) else UIUtils.SetLabelText(cellTable.lab_Change, Const_IDS.IDS_AssistanceFight_ChooseHero_Button1) end end else if self.changePetUniqId then UIUtils.SetLabelText(cellTable.lab_Change, Const_IDS.IDS_Horse_Title_5) else UIUtils.SetLabelText(cellTable.lab_Change, Const_IDS.IDS_AssistanceFight_ChooseHero_Button1) end end UIUtils.SetActive(cellTable.img_Assistance, isAssist) UIUtils.SetActive(cellTable.img_ArrayUp, isLineUp) CTL.Pet.SetPetName(cellTable.txt_PetName, petInfo, petConfig) if petConfig.Quality == MDL.Pet.PetQuality.God then cellTable.txt_PetInfo.text = string.format("%s %s", UIUtils.GetLocalizedTxt(Const_IDS.IDS_GodPet),CTL.Pet.GetGodBreakDesc(petInfo, true)) else if petInfo.petVariation == MDL.Pet.PetState.Basic then cellTable.txt_PetInfo.text = string.format("%s %s", UIUtils.GetLocalizedTxt(Const_IDS.IDS_PetGeneral), CTL.Pet.GetGenerationTxt(petInfo.petGeneration)) else cellTable.txt_PetInfo.text = string.format("%s %s", UIUtils.GetLocalizedTxt(Const_IDS.IDS_PetVariation), CTL.Pet.GetGenerationTxt(petInfo.petGeneration)) end end UIUtils.SetLabel(cellTable.txt_BaseAttr, petInfo.baseGS) CTL.Pet.SetPetIconComp(cellTable.img_Item, cellTable.sprite_Rank, cellTable.txt_Level, petConfig.ID, petConfig.Stage, petInfo.petLevel) end function UIPetChangeView:OnCellClicked(scrollRect, index, cellTable, target, data) if target == cellTable.btn_Change then local petInfo = data.Info if self.panelType == CTL.Pet.ChangePetPanelType.Main then if self.changePetUniqId then UIManager.OpenView(Const_UI_Lua.UIEnum.UIPetChangeConfirm, { newPetUniqId = petInfo.petUniqId, oldPetUniqId = self.changePetUniqId, changeSlotIndex = self.changeIndex }) else MDL.Pet.PetSlotLineUpReq(self.changeIndex, petInfo.petUniqId) end else if self.changePetUniqId and petInfo.petUniqId == self.changePetUniqId then --下阵 UTL.MessageBox.ShowOKCancelBox("", Const_IDS.IDS_Pet_ChooseHero_OutHint, function() MDL.Pet.PetFormationChangeReq(MDL.Pet.FormationOptType.Sub, self.changeIndex, "0") end) else MDL.Pet.PetFormationChangeReq(MDL.Pet.FormationOptType.Sub, self.changeIndex, petInfo.petUniqId) end end end end function UIPetChangeView:UpdateInfo() self.infoList = {} local isHide = self.toggle_Hide.isOn if self.panelType == CTL.Pet.ChangePetPanelType.Assistance then --副将上阵可以显示自己,行为是下阵,不显示已上阵的 for i, v in ipairs(MDL.Pet.GetOrderedList()) do if MDL.Pet.IsPetLineUp(v.Info.petUniqId) == false then if (isHide and (MDL.Pet.IsPetAssistanceFight(v.Info.petUniqId) == false or self.changePetUniqId == v.Info.petUniqId)) or (isHide == false) then table.insert(self.infoList, v) end end end table.sort(self.infoList, AssistSortRule) else --主将上阵不可以显示自己 for i, v in ipairs(MDL.Pet.GetOrderedList()) do if v.Info.petUniqId ~= self.changePetUniqId then if isHide and MDL.Pet.IsPetLineUp(v.Info.petUniqId) == false or isHide == false then table.insert(self.infoList, v) end end end table.sort(self.infoList, MainSortRule) end self.loop_ChangePetScroll:ReloadAll(self.infoList) if self.loop_ChangePetScroll.Count > 0 then self.group_Mid:SetState(0) else self.group_Mid:SetState(1) UIUtils.SetLabelText(self.lab_NoPet, Const_IDS.IDS_Pet_ChooseHelpPet2) end end return UIPetChangeView