local UISyncSoloBPSelect = UIViewClass() local BanPickStage = MDL.FairPlay.BanPickStageEnum --武将几个选中状态 local HERO_STATE_LEFT_PICK = 1 local HERO_STATE_RIGHT_PICK = 2 local HERO_STATE_NOT_HAVE = 3 --选将置灰状态 local LOCK_STATE_SHOW_1 = 0 --第1行亮 local LOCK_STATE_SHOW_2 = 1 --第1、2行亮 local LOCK_STATE_SHOW_3 = 2 --第2、3行亮 local LOCK_STATE_SHOW_4 = 3 --第3行亮 local LOCK_STATE_SHOW_ALL = 4 --全部亮 local LOCK_STATE_HIDE_ALL = 5 --全部置灰 local FairTournamentSuperHeroCount = DataSheetManager.FairMatchRule1V1:GetDataByID(LuaConst.ActivityType.SyncSolo).SuperGoldLimit function UISyncSoloBPSelect:OnCreated() UIUtils.SetActive(self.btn_Close, false) UIUtils.SetActive(self.btn_Confirm, true) UIUtils.SetActive(self.group_BanSelect.group_TitleBan, false) UIUtils.SetActive(self.group_BanSelect.group_TitleSelect, true) self.dragParentTrans = self.obj_DragParent.transform self.leftSuperGolderHeroCfgIdArr = {} self.formationHeroIdList = { 0, 0, 0, 0, 0, 0 } UIUtils.SetLabel(self.txt_BanSelectTip, string.FormatByIdsKey("IDS_FairTournament_CaiJinHero", FairTournamentSuperHeroCount)) end function UISyncSoloBPSelect:OnOpened(context) self:RegistSystemEvent(EventID.UI_SyncSolo_NoticeBPInfo, self.OnBPInfoNotice) for i, v in ipairs(self.group_Left.group_SelectHero) do self:RegistTriggerEvent(v.btn_FormationHero, UIEventTriggerType.BeginDrag) self:RegistTriggerEvent(v.btn_FormationHero, UIEventTriggerType.Drag) self:RegistTriggerEvent(v.btn_FormationHero, UIEventTriggerType.EndDrag) self:RegistTriggerEvent(v.btn_FormationHero, UIEventTriggerType.Drop) self:RegistTriggerEvent(v.img_Empty, UIEventTriggerType.Drop) end self:OnBPInfoNotice() self:UpdatePlayerInfo() self.heroList = CTL.FairSoloTournament.GetAllSortedHeroList() self.group_BanSelect.loop_bpHero:ReloadAll(self.heroList) end function UISyncSoloBPSelect:OnBPInfoNotice() self:UpdateData() self:OnBPStateChanged() end function UISyncSoloBPSelect:UpdatePlayerInfo() self:SetBasicInfo(self.group_Left, self.bpInfo.ownTeamPlayerInfo[1]) self:SetBasicInfo(self.group_Right, self.bpInfo.enemyTeamPlayerInfo[1]) end function UISyncSoloBPSelect:SetBasicInfo(comp, showInfo) comp.txt_Name.text = showInfo.acid == BattleDataGetter.GetAcID() and UTL.Color.FormatTextByColor("fff08b", showInfo.name) or showInfo.name UIUtils.SetLabel(comp.txt_Server, CTL.CrossServer.GetServerShowStr(showInfo.ShowServerId)) UIUtils.SetLabel(comp.txt_GuildName, showInfo.guildName) CTL.Character.SetPortraitAndFrame(comp.UIHeroHead, showInfo.PortraitId, showInfo.FrameId) end function UISyncSoloBPSelect:UpdateData() self.bpInfo = MDL.FairPlay.GetBpRoomInfo(LuaConst.ActivityType.SyncSolo) self.leftBPInfo = self.bpInfo.ownTeamPlayerInfo[1] self.rightBPInfo = self.bpInfo.enemyTeamPlayerInfo[1] self.isLeftRound = self.leftBPInfo.acid == self.bpInfo.curPickRoundPlayer self.nextTime = self.bpInfo.nextStageTime - self.bpInfo.serverTime self.bpState = self.bpInfo.curStage self:UpdateBPRoundNum() self:UpdateBPHeroData() self:RefreshIsUsedExperienceCard() end function UISyncSoloBPSelect:OnBPStateChanged() self.group_BanSelect.loop_bpHero:RefreshCells(false) UIUtils.SetActive(self.banSelectTip, self.bpState == BanPickStage.BanPick) UIUtils.SetActive(self.group_Info, self.bpState == BanPickStage.BanPick) if self.bpState == BanPickStage.BanPick then self.state_Middle:SetState(0) self.group_BanSelect.cdTimer_BP:ResetAndBeginCustomTimer(false, self.nextTime, 0, "{0}s", 1) self:UpdateBPDesc() elseif self.bpState == BanPickStage.ModifyHeroOrder then self.state_Middle:SetState(2) self.group_Adjustment.cdTimer_Adjustment:ResetAndBeginCustomTimer(false, self.nextTime, 0, "{0}s", 1) elseif self.bpState == BanPickStage.End then self.state_Middle:SetState(1) self.group_Prepare.cdTimer_Prepare:ResetAndBeginCustomTimer(false, self.nextTime, 0, "{0}s", 1) end self:UpdateBPDetail(self.group_Left, self.leftBPInfo, true) self:UpdateBPDetail(self.group_Right, self.rightBPInfo, false) self:RefreshConfirmBtn() end -- 通过先手、当前可选英雄人数、谁的回合,可计算当前是选将第几回合 function UISyncSoloBPSelect:UpdateBPRoundNum() if self.bpState ~= BanPickStage.BanPick then return end self.roundNum = 0 if self.leftBPInfo.Dice > self.rightBPInfo.Dice then --先手 if self.isLeftRound then --左方回合 if self.bpInfo.curRoundPickHeroNum == 2 then self.roundNum = 1 else self.roundNum = 3 end else if self.bpInfo.curRoundPickHeroNum == 2 then self.roundNum = 4 else self.roundNum = 2 end end else if self.isLeftRound then --左方回合 if self.bpInfo.curRoundPickHeroNum == 2 then self.roundNum = 4 else self.roundNum = 2 end else if self.bpInfo.curRoundPickHeroNum == 2 then self.roundNum = 1 else self.roundNum = 3 end end end end function UISyncSoloBPSelect:UpdateBPHeroData() for i, v in ipairs(self.leftBPInfo.pickedHeroId) do local heroId = v if self.leftBPInfo.pickedHeroAwaken[i] then heroId = CTL.HeroAwaken.EncodeHeroId(v) self.leftBPInfo.pickedHeroId[i] = heroId end self.formationHeroIdList[i] = heroId self:RefreshSingleHeroCell(i) end for i, v in ipairs(self.rightBPInfo.pickedHeroId) do if self.rightBPInfo.pickedHeroAwaken[i] then self.rightBPInfo.pickedHeroId[i] = CTL.HeroAwaken.EncodeHeroId(v) end end self.leftSuperGolderHeroCfgIdArr = {} for i, v in ipairs(self.leftBPInfo.pickedHeroId) do if v>0 and CTL.HeroSelect.IsSuperGoldHero(v) then table.insert(self.leftSuperGolderHeroCfgIdArr, v) end end end function UISyncSoloBPSelect:RefreshIsUsedExperienceCard() self.IsUsedExperienceCard = false for _, heroId in ipairs(self.formationHeroIdList) do if heroId > 0 and CTL.FairPlayCard.IsUsedExperienceCard(heroId) then self.IsUsedExperienceCard = true end end end function UISyncSoloBPSelect:UpdateBPDesc() local playerName = self.isLeftRound and self.leftBPInfo.name or self.rightBPInfo.name self.txt_Info.text = string.FormatByIdsId(Const_IDS.IDS_FairTournament_PlayerPickHero, playerName, self.bpInfo.curRoundPickHeroNum) end function UISyncSoloBPSelect:UpdateBPDetail(comp, bpInfo, isLeft) UIUtils.SetActive(comp.group_Ban, false) UIUtils.SetActive(comp.group_Select, true) if self.bpState == BanPickStage.BanPick then if isLeft then for i, cell in ipairs(comp.group_SelectHero) do local heroId = bpInfo.pickedHeroId[i] self:RefreshHeroCell(cell, heroId) end else for i, cell in ipairs(comp.group_SelectHero) do local heroId = bpInfo.pickedHeroId[i] self:RefreshHeroCell(cell, heroId) UIUtils.SetActive(cell.img_Select, false) end end if self.roundNum == 1 then --第一轮pick,pick那一方亮第一行,另一方全部置灰 self:RefreshBanPickState(isLeft, comp, LOCK_STATE_SHOW_1, LOCK_STATE_SHOW_1) elseif self.roundNum == 2 then --第二轮pick,pick那一方亮1、2行,另一方全部置灰 self:RefreshBanPickState(isLeft, comp, LOCK_STATE_SHOW_2, LOCK_STATE_SHOW_2) elseif self.roundNum == 3 then --第三轮pick,pick那一方亮2、3行,另一方全部置灰 self:RefreshBanPickState(isLeft, comp, LOCK_STATE_SHOW_3, LOCK_STATE_SHOW_3) elseif self.roundNum == 4 then --第四轮pick,pick那一方亮第3行,另一方全部置灰 self:RefreshBanPickState(isLeft, comp, LOCK_STATE_SHOW_4, LOCK_STATE_SHOW_4) end elseif self.bpState == BanPickStage.ModifyHeroOrder then --无法看到对方调整顺序 if isLeft then for i, cell in ipairs(comp.group_SelectHero) do local heroId = bpInfo.pickedHeroId[i] self:RefreshHeroCell(cell, heroId) UIUtils.SetActive(cell.img_Select, isLeft) end end comp.state_Lock:SetState(LOCK_STATE_SHOW_ALL) elseif self.bpState == BanPickStage.End then for i, cell in ipairs(comp.group_SelectHero) do local heroId = bpInfo.pickedHeroId[i] self:RefreshHeroCell(cell, heroId) UIUtils.SetActive(cell.img_Select, isLeft) end comp.state_Lock:SetState(LOCK_STATE_SHOW_ALL) end end function UISyncSoloBPSelect:RefreshBanPickState(isLeft, comp, state1, state2) if self.isLeftRound then if isLeft then comp.state_Lock:SetState(state1) else comp.state_Lock:SetState(LOCK_STATE_HIDE_ALL) end else if isLeft then comp.state_Lock:SetState(LOCK_STATE_HIDE_ALL) else comp.state_Lock:SetState(state2) end end end --获取武将bp情况 function UISyncSoloBPSelect:GetHeroState(heroId) local leftPick = false local rightPick = false if self.leftBPInfo then if self:GetIndexByHeroId(self.leftBPInfo.pickedHeroId, heroId) then leftPick = true end end if self.rightBPInfo then if self:GetIndexByHeroId(self.rightBPInfo.pickedHeroId, heroId) then rightPick = true end end if leftPick and rightPick == false then return HERO_STATE_LEFT_PICK elseif leftPick == false and rightPick then return HERO_STATE_RIGHT_PICK end if not (CTL.SyncSolo.IsBPCanSelect(heroId) or MDL.HeroAwaken.GetIsHeroAwaken(CTL.HeroAwaken.DecodeHeroId(heroId)) or MDL.SyncSolo.CheckIsExperienceFreeHero(heroId)) then return HERO_STATE_NOT_HAVE end return nil end function UISyncSoloBPSelect:OnCellInit(scrollRect, index, cellTable, data) UTL.Item.SetHeroIconByHeroId(cellTable.img_HeroHead, CTL.HeroAwaken.DecodeHeroId(data)) UIUtils.SetActive(cellTable.img_Mask_Ban, false) local isExperienceFreeHero = CTL.FairPlayCard.IsUsedExperienceCard(data) UIUtils.SetActive(cellTable.img_experience01, isExperienceFreeHero) local state = self:GetHeroState(data) if state == nil then UIUtils.SetActive(cellTable.img_Mask_Select, false) if isExperienceFreeHero and self.IsUsedExperienceCard then UIUtils.SetGray(cellTable.img_HeroHead, true) else UIUtils.SetGray(cellTable.img_HeroHead, false) end elseif state == HERO_STATE_NOT_HAVE then UIUtils.SetActive(cellTable.img_Mask_Select, false) UIUtils.SetGray(cellTable.img_HeroHead, true) else UIUtils.SetGray(cellTable.img_HeroHead, true) UIUtils.SetActive(cellTable.img_BanSelect, false) UIUtils.SetActive(cellTable.img_Mask_Select, true) UIUtils.SetActive(cellTable.img_SelectBlue, state == HERO_STATE_LEFT_PICK) UIUtils.SetActive(cellTable.img_SelectRed, state == HERO_STATE_RIGHT_PICK) end if self.bpState == BanPickStage.BanPick and self.isLeftRound then if #self.leftSuperGolderHeroCfgIdArr>=FairTournamentSuperHeroCount and not table.containValue(self.leftSuperGolderHeroCfgIdArr, data) and CTL.HeroSelect.IsSuperGoldHero(data) then UIUtils.SetGray(cellTable.img_HeroHead, true) end end --觉醒前后只能选一个 if self:GetIndexByHeroId(self.leftBPInfo.pickedHeroId, CTL.HeroAwaken.TranslateHeroId(data)) or self:GetIndexByHeroId(self.rightBPInfo.pickedHeroId, CTL.HeroAwaken.TranslateHeroId(data)) then UIUtils.SetGray(cellTable.img_HeroHead, true) end end function UISyncSoloBPSelect:OnCellClicked(scrollRect, index, cellTable, target, data) if not self.isLeftRound or self.bpState ~= BanPickStage.BanPick then return end local index = self:GetIndexByHeroId(self.formationHeroIdList, data) if index then if self:CheckIfReplace(index) == false then return end self:NotifyPickHero(index, 0) UIUtils.SetActive(cellTable.img_BanSelect, false) if self.selectBPCell then UIUtils.SetActive(self.selectBPCell.img_BanSelect, false) self.selectBPCell = nil end else self:OnClickOtherHero(cellTable, data) end end function UISyncSoloBPSelect:OnClickOtherHero(cellTable, data) local emptyIndex for i, v in ipairs(self.formationHeroIdList) do if not v or v <= 0 then emptyIndex = i break end end if emptyIndex == nil then CTL.Tips.AddTipsMsg(Const_IDS["IDS_BossChallenge_ChooseHero_FullHero"]) else local range1, range2 = self:GetRoundRange() if not self:CheckIsIllegal(data, emptyIndex, range2) then return end if emptyIndex < range1 then for i = range1, range2 do if self.formationHeroIdList[i] == nil or self.formationHeroIdList[i] <= 0 then emptyIndex = i break end end end if self:CheckIfReplace(emptyIndex) == false then logging.warn(LTAG.WARN, "clicked illegal emptyIndex:" .. emptyIndex) return end if self.selectBPCell then UIUtils.SetActive(self.selectBPCell.img_BanSelect, false) end UIUtils.SetActive(cellTable.img_BanSelect, true) self.selectBPCell = cellTable self:NotifyPickHero(emptyIndex, data) end end function UISyncSoloBPSelect:CheckIsIllegal(data, emptyIndex, range2) local state = self:GetHeroState(data) --被对方选了或者没有该英雄 if state == HERO_STATE_RIGHT_PICK or state == HERO_STATE_NOT_HAVE then logging.log(LTAG.LOG,"CheckIsIllegal 被对方选了或者没有该英雄 ") return false end --彩金数量限制 if #self.leftSuperGolderHeroCfgIdArr>=FairTournamentSuperHeroCount and CTL.HeroSelect.IsSuperGoldHero(data) then logging.log(LTAG.LOG,"CheckIsIllegal 彩金数量限制") return false end --觉醒或未觉醒的被选了 if self:GetIndexByHeroId(self.leftBPInfo.pickedHeroId, CTL.HeroAwaken.TranslateHeroId(data)) or self:GetIndexByHeroId(self.rightBPInfo.pickedHeroId, CTL.HeroAwaken.TranslateHeroId(data)) then logging.log(LTAG.LOG,"CheckIsIllegal 觉醒或未觉醒的被选了") return false end --没有可选空位 if emptyIndex > range2 then logging.log(LTAG.log,"CheckIsIllegal 没有可选空位") return false end --已选金将体验卡英雄 if self.IsUsedExperienceCard and CTL.FairPlayCard.IsUsedExperienceCard(data) then logging.log(LTAG.log,"CheckIsIllegal 已选金将体验卡英雄") return false end return true end function UISyncSoloBPSelect:RefreshConfirmBtn() if not self.isLeftRound or self.bpState ~= BanPickStage.BanPick then UIUtils.SetActive(self.btn_Confirm, false) return end local emptyIndex for i, v in ipairs(self.formationHeroIdList) do if not v or v <= 0 then emptyIndex = i break end end local _, range2 = self:GetRoundRange() local isCanConfirm = emptyIndex == nil or emptyIndex > range2 self.btn_Confirm:SetGray(not isCanConfirm, isCanConfirm) UIUtils.SetActive(self.btn_Confirm, true) end --不同回合数,只能操作相应位置的武将 function UISyncSoloBPSelect:GetRoundRange() if self.roundNum == 1 then return 1, 2 end if self.roundNum == 2 then return 1, 4 end if self.roundNum == 3 then return 3, 6 end if self.roundNum == 4 then return 5, 6 end end --判断该回合要操控的武将位置是否合法 function UISyncSoloBPSelect:CheckIfReplace(index) if self.roundNum == 1 and index > 2 then return false end if self.roundNum == 2 and index > 4 then return false end if self.roundNum == 3 and index <= 2 then return false end if self.roundNum == 4 and index <= 4 then return false end return true end --选中即通知 function UISyncSoloBPSelect:NotifyPickHero(pos, heroId) self.formationHeroIdList[pos] = heroId self:RefreshSingleHeroCell(pos) MDL.FairPlay.BanPickHeroOptReq(LuaConst.ActivityType.SyncSolo, MDL.FairPlay.BanPickHeroOptType.PickHero, self.leftBPInfo.acid, self.formationHeroIdList) end function UISyncSoloBPSelect:OnButtonClicked(comp) if not self.isLeftRound or self.bpState ~= BanPickStage.BanPick then return end if comp == self.btn_Confirm then MDL.FairPlay.BanPickHeroOptReq(LuaConst.ActivityType.SyncSolo, MDL.FairPlay.BanPickHeroOptType.Confirm, self.leftBPInfo.acid, self.formationHeroIdList) else local index = self:GetIndexByInteractiveItem(comp) if index then if self.isLeftRound and self:CheckIfReplace(index) == false then return end self:NotifyPickHero(index, 0) if self.selectBPCell then UIUtils.SetActive(self.selectBPCell.img_BanSelect, false) self.selectBPCell = nil end end end end function UISyncSoloBPSelect:RefreshSingleHeroCell(index) if index <= 6 then local heroId = self.formationHeroIdList[index] local cell = self.group_Left.group_SelectHero[index] self:RefreshHeroCell(cell, heroId) else logging.error(LTAG.ERROR, "传入的index: ", index, ", 超过了6,请检查!") end end function UISyncSoloBPSelect:RefreshHeroCell(cell, heroId) if heroId and heroId > 0 then UTL.Item.SetHeroIconByHeroId(cell.img_HeroHead, CTL.HeroAwaken.DecodeHeroId(heroId)) UIUtils.SetActive(cell.group_FormationHero, true) UIUtils.SetActive(cell.img_Empty, false) else UIUtils.SetActive(cell.group_FormationHero, false) UIUtils.SetActive(cell.img_Empty, true) end end function UISyncSoloBPSelect:OnBeginDrag(comp, eventData) if self.bpState ~= BanPickStage.ModifyHeroOrder then return end self.dragItem = GameObject.Instantiate(comp.transform.parent.parent.gameObject) self.dragItem.transform:SetParent(self.dragParentTrans, false) self.dragItem.transform:GetChild(0):GetComponentInChildren(typeof(Image)).raycastTarget = false self.dragIndex = self:GetIndexByInteractiveItem(comp) self.dragItemId = self.formationHeroIdList[self.dragIndex] end function UISyncSoloBPSelect:OnDrag(comp, eventData) if self.dragItem then UIUtils.ScreenPointToWorldPointInRectangle(self.dragItem, eventData) end end function UISyncSoloBPSelect:OnEndDrag(comp, eventData) self.dragIndex = nil self.dragItemId = nil if self.dragItem then GameObject.Destroy(self.dragItem) self.dragItem = nil end end function UISyncSoloBPSelect:OnDrop(comp, eventData) if not eventData.pointerEnter or not self.dragItemId or self.dragItemId <= 0 then self.dragIndex = nil self.dragItemId = nil if self.dragItem then GameObject.Destroy(self.dragItem) self.dragItem = nil end return end local dropIndex = self:GetIndexByInteractiveItem(comp) if dropIndex and dropIndex ~= self.dragIndex then local dragIndex = self:GetIndexByHeroId(self.formationHeroIdList, self.dragItemId) local loopDragIndex = self:GetIndexByHeroId(self.heroList, self.dragItemId) local loopDropIndex = self:GetIndexByHeroId(self.heroList, self.formationHeroIdList[dropIndex]) self.formationHeroIdList[dragIndex] = self.formationHeroIdList[dropIndex] self.formationHeroIdList[dropIndex] = self.dragItemId self:RefreshSingleHeroCell(dragIndex) self:RefreshSingleHeroCell(dropIndex) self.group_BanSelect.loop_bpHero:UpdateIndex(loopDragIndex - 1) if loopDropIndex then self.group_BanSelect.loop_bpHero:UpdateIndex(loopDropIndex - 1) end MDL.FairPlay.BanPickHeroOptReq(LuaConst.ActivityType.SyncSolo, MDL.FairPlay.BanPickHeroOptType.ChangeHeroOrder, self.leftBPInfo.acid, self.formationHeroIdList) end self.dragIndex = nil self.dragItemId = nil if self.dragItem then GameObject.Destroy(self.dragItem) self.dragItem = nil end end function UISyncSoloBPSelect:GetIndexByHeroId(list, id) for i, v in ipairs(list) do if v == id then return i end end return nil end function UISyncSoloBPSelect:GetIndexByInteractiveItem(comp) for i, v in ipairs(self.group_Left.group_SelectHero) do if comp == v.btn_FormationHero or comp == v.img_Empty then return i end end return nil end return UISyncSoloBPSelect