local UIFairPlayMainPanel = UIViewClass() local PVPSound = { [LuaConst.ActivityType.TVT] = "UI_yanwu", [LuaConst.ActivityType.BossChallenge] = "UI_switch", [LuaConst.ActivityType.SyncSolo] = "UI_yanwu", [LuaConst.ActivityType.SyncFourCountryWar] = "UI_switch", [LuaConst.ActivityType.FairSoloTournament] = "UI_yanwu", [LuaConst.ActivityType.TeamFairChampionship] = "UI_yanwu", } local PVPLocalizationIDS = { [LuaConst.ActivityType.SyncSolo] = "IDS_FairPlay_1v1", [LuaConst.ActivityType.TVT] = "IDS_FairPlay_3v3", [LuaConst.ActivityType.BossChallenge] = "IDS_FairPlay_BOSS", [LuaConst.ActivityType.Sync100] = "IDS_FairPlay_EatChicken", [LuaConst.ActivityType.SyncFourCountryWar] = "IDS_5v5Sync_Title", [LuaConst.ActivityType.FairSoloTournament] = "IDS_Fair1V1Season_Title", [LuaConst.ActivityType.TeamFairChampionship] = "IDS_Fair1V1Season_Title", } local DisplayActivity = { LuaConst.ActivityType.TVT, LuaConst.ActivityType.BossChallenge, LuaConst.ActivityType.SyncSolo, LuaConst.ActivityType.SyncFourCountryWar, LuaConst.ActivityType.FairSoloTournament, LuaConst.ActivityType.TeamFairChampionship, LuaConst.ActivityType.Sync100, } local function SortFairPlayCell(a, b) local a_State, b_State = 0, 0 if a == LuaConst.ActivityType.SyncFourCountryWar then a_State = MDL.SyncFourCountryWar.IsOpen() and 1 or 0 elseif a == LuaConst.ActivityType.FairSoloTournament then local curState = MDL.FairSoloTournament.GetCurMatchTimeID() a_State = (curState > MDL.FairSoloTournament.Enum_BigStage.FairAdvance and curState < MDL.FairSoloTournament.Enum_BigStage.FairDisplay) and 1 or 0 end if b == LuaConst.ActivityType.SyncFourCountryWar then b_State = MDL.SyncFourCountryWar.IsOpen() and 1 or 0 elseif b == LuaConst.ActivityType.FairSoloTournament then local curState = MDL.FairSoloTournament.GetCurMatchTimeID() b_State = (curState > MDL.FairSoloTournament.Enum_BigStage.FairAdvance and curState < MDL.FairSoloTournament.Enum_BigStage.FairDisplay) and 1 or 0 end if a_State == b_State then local activityA = DataSheetManager.ActivityData:GetDataByID(a) local activityB = DataSheetManager.ActivityData:GetDataByID(b) if activityA.Sort ~= activityB.Sort then return activityA.Sort > activityB.Sort else return a < b end else return a_State > b_State end end function UIFairPlayMainPanel:OnOpened(context) self:RegistSystemEvent(EventID.UI_FairPlay_RewardChestClaim, self.RefreshFairPlayPoints) self:RegistSystemEvent(EventID.UI_FairPlay_FairPlayInfoRefresh, self.RefreshFairPlayPoints) self:RegistSystemEvent(EventID.UI_FairPlay_SyncSoloSeasonInfoUpdate, self.RefreshActivitiesCells) self:RegistSystemEvent(EventID.UI_FairPlay_TVTSeasonInfoUpdate, self.RefreshActivitiesCells) self:RegistSystemEvent(EventID.UI_FairPlay_BossChallengeSeasonInfoUpdate, self.RefreshActivitiesCells) self:RegistSystemEvent(EventID.FunctionUnlockUpdate, self.RefreshActivitiesCells) self:RegistSystemEvent(EventID.FunctionUnlockUpdate, self.RefreshPKEntry) self:RegistSystemEvent(CTL.RedPoint.RedPointKey.FairPlay_KingChallenge, self.RefreshKingChallengeEntry) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS.IDS_ActivityName_BalanceBattle) self.chestAnchorPosX, self.chestAnchorPosY = self.group_Gift.cell_Chest.gameObject.transform:GetAnchoredPosition() local displayActivityRegion = DisplayActivity table.sort(displayActivityRegion, SortFairPlayCell) self.IconPath = ConstAssetPathConfig.IconPath1 for i = 1, #displayActivityRegion do local activityData = DataSheetManager.ActivityData:GetDataByID(displayActivityRegion[i]) self.scroll_Activities:AddData(activityData, 0) end self:RefreshFairPlayPoints() if context and context.chestIndex then local px = self.group_Gift.group_Chest[context.chestIndex].event_Reward.transform:GetPosition() self:ShowChestReward(self.chestData[context.chestIndex].Item_Table, px) end self:RefreshPKEntry() self:RefreshKingChallengeEntry() end function UIFairPlayMainPanel:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.scroll_Activities then local activityData = DataSheetManager.ActivityData:GetDataByID(data.ID) local doubleData = DataSheetManager.FairPlayDoubleActivation:GetDataByDay(UTL.Time.GetServerWeekday()).ActivityDataID local isInActivityTime = CTL.Activities.IsActivityInOpeningTime(data.ID) UIUtils.SetActive(cellTable.img_Double, table.containValue(doubleData, data.ID)) UIUtils.SetLabelText(cellTable.lab_PVP, Const_IDS[data.Activity]) UIUtils.SetActive(cellTable.img_Fair, data.IsDisplayFairHint) UIUtils.SetImageByAssetBundle(cellTable.sprite_Activities, string.format(self.IconPath, activityData.BriefIntroductionImage)) if data.ID == LuaConst.ActivityType.SyncSolo then cellTable.cell:SetRedPoint(CTL.RedPoint.GetRedPointActive(CTL.RedPoint.RedPointKey.FairPlay_SyncSolo)) elseif data.ID == LuaConst.ActivityType.TVT then cellTable.cell:SetRedPoint(CTL.RedPoint.GetRedPointActive(CTL.RedPoint.RedPointKey.FairPlay_SyncTeamPVP)) end if cellTable.loc_Title.CurState == 0 then cellTable.loc_Title:SetImage(0, activityData.BackgroundImage, true) else cellTable.loc_Title:SetText(0, UIUtils.GetLocalizedTxt(Const_IDS[PVPLocalizationIDS[data.ID]])) end local unlockId = activityData.FuctionUnlockID local isUnlock = true if unlockId then isUnlock = MDL.Unlock.IsUnlock(unlockId) end cellTable.state_Type:SetState(activityData.SheetType == 4 and 1 or 0) local desc, time = UTL.Time.GetDateDescAndTime(activityData.Time_Table) if activityData.SheetType == 4 then UIUtils.SetLabelText(cellTable.group_Season.lab_TimeTitle, Const_IDS.IDS_FairPlay_OpenTime_Title) cellTable.group_Season.lab_Time.text = desc .. " " .. time else cellTable.group_General.lab_Time.text = desc .. " " .. time end if GameAppInfo.IsVietnamPackage() then cellTable.group_General.lab_Time.text = time end ---临时代码先这么写死 if data.ID == LuaConst.ActivityType.Sync100 then cellTable.group_General.state_OpenTime:SetState(1) UIUtils.SetActive(cellTable.img_Locked, true) UIUtils.SetComponentGray(cellTable.cell, true) return end local state_OpenTime = cellTable.group_General.state_OpenTime if activityData.SheetType == 4 then state_OpenTime = cellTable.group_Season.state_OpenTime end if isUnlock then if data.ID == LuaConst.ActivityType.FairSoloTournament then local curState = MDL.FairSoloTournament.GetCurMatchTimeID() if curState > 0 and curState < MDL.FairSoloTournament.Enum_BigStage.FairDisplay then if curState == MDL.FairSoloTournament.Enum_BigStage.FairAdvance then state_OpenTime:SetState(5) else state_OpenTime:SetState(3) end else state_OpenTime:SetState(4) end elseif data.ID == LuaConst.ActivityType.TeamFairChampionship then local curBigStageID = MDL.TeamFairChampionship.GetCurBigStageID() if curBigStageID > 0 and curBigStageID < MDL.TeamFairChampionship.Enum_BigStage.Display then if curState == MDL.TeamFairChampionship.Enum_BigStage.Advance then state_OpenTime:SetState(5) else state_OpenTime:SetState(3) end else state_OpenTime:SetState(4) end elseif data.ID == LuaConst.ActivityType.SyncFourCountryWar then local isOpen = MDL.SyncFourCountryWar.IsOpen() state_OpenTime:SetState(isOpen and 3 or 4) else if isInActivityTime then local isSeasonOpen = true if data.ID == LuaConst.ActivityType.SyncSolo then isSeasonOpen = CTL.SyncSolo.IsSeasonOpen() elseif data.ID == LuaConst.ActivityType.TVT then isSeasonOpen = CTL.SyncTeamPVP.IsSeasonOpen() elseif data.ID == LuaConst.ActivityType.BossChallenge then isSeasonOpen = CTL.BossChallenge.IsSeasonOpen(CTL.BossChallenge.GetSeasonId()) end state_OpenTime:SetState(isSeasonOpen and 3 or 4) else state_OpenTime:SetState(2) end end else state_OpenTime:SetState(0) end UIUtils.SetActive(cellTable.img_Locked, not isUnlock) UIUtils.SetComponentGray(cellTable.cell, not isUnlock) elseif scrollRect == self.group_Gift.ChestRewardScroll then UTL.Item.SetItemCell(cellTable.item, data.ItemID, data.ItemNum) end end function UIFairPlayMainPanel:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.scroll_Activities then ---临时代码先这么写死 if data.ID == LuaConst.ActivityType.Sync100 then CTL.Tips.AddTipsMsg(Const_IDS["IDS_5v5Sync_TestClose"]) CTL.Sound.PlayGameSound("UI_invalid") return end local activityData = DataSheetManager.ActivityData:GetDataByID(data.ID) local isInActivity = CTL.Activities.IsOpeningTime(data.ID) local unlockId = activityData.FuctionUnlockID local IsUnlock = true local unlockText = nil if unlockId then IsUnlock, unlockText = MDL.Unlock.IsClientUnlockWithText(unlockId, "IDS_Activity_Condition_01") end if IsUnlock then if data.ID == LuaConst.ActivityType.TVT then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UISyncTeamPVPMainPanel) elseif data.ID == LuaConst.ActivityType.BossChallenge then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIBossChallengeMain) elseif data.ID == LuaConst.ActivityType.SyncSolo then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UISyncSoloMainPanel) elseif data.ID == LuaConst.ActivityType.SyncFourCountryWar then local isOpen, showTips = CTL.Activities.CanOpenDetailView(data.ID) if not isOpen then CTL.Tips.AddTipsMsg(Const_IDS["IDS_NewActivityTab_Hint_1"]) return end CTL.Activities.OpenActivityWindowByID(data.ID) elseif data.ID == LuaConst.ActivityType.FairSoloTournament then local curState = MDL.FairSoloTournament.GetCurMatchTimeID() if curState > 0 then if curState == MDL.FairSoloTournament.Enum_BigStage.FairAdvance then CTL.Tips.AddTipsMsg(Const_IDS["IDS_NewActivityTab_Hint_5"]) return else CTL.Activities.OpenActivityWindowByID(data.ID) end else CTL.Tips.AddTipsMsg(Const_IDS["IDS_NewActivityTab_Hint_1"]) return end elseif data.ID == LuaConst.ActivityType.TeamFairChampionship then local curState = MDL.TeamFairChampionship.GetCurBigStageID() if curState > 0 then if curState == MDL.TeamFairChampionship.Enum_BigStage.Advance then CTL.Tips.AddTipsMsg(Const_IDS["IDS_NewActivityTab_Hint_5"]) return else CTL.Activities.OpenActivityWindowByID(data.ID) end else CTL.Tips.AddTipsMsg(Const_IDS["IDS_NewActivityTab_Hint_1"]) return end end CTL.Sound.PlayGameSound(PVPSound[data.ID]) else CTL.Sound.PlayGameSound("UI_invalid") if not IsUnlock then CTL.Tips.AddTipsMsg(unlockText) elseif not isInActivity then CTL.Tips.AddTipsMsg(Const_IDS["IDS_FairPlay_3v3NotOpen"]) end end elseif scrollRect == self.group_Gift.ChestRewardScroll then UTL.ItemTips.ShowCommonTipsById(data.ItemID) end end function UIFairPlayMainPanel:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIFairPlayMainPanel:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_close then self:CloseView(true) elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.group_Gift.btn_Close then self:ClearChestViews() elseif comp == self.UITemplateTitlePanel.btn_Info then local timeStr = UTL.Time.GetDiffLocalStrById(1) UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, { id = LuaConst.NoteID.FairPlay, params = { timeStr } }) elseif comp == self.btn_PK then UIManager.OpenView(Const_UI_Lua.UIEnum.UIPKRoomList, { needQuery = true }) elseif comp == self.event_Replay then CTL.Replay.OpenMainPanel() elseif comp == self.event_History then --我的战绩界面 CTL.Replay.OnMyRecordsPanel() elseif comp == self.btn_KingChallenge then --王者挑战 UIManager.OpenView(Const_UI_Lua.UIEnum.UIKingChallengeMainPanel) else self:OnClickChests(comp) end end -- 刷新底部活跃度 function UIFairPlayMainPanel:RefreshFairPlayPoints() --刷新底部活跃度数值 self.fairPlayPoint = MDL.FairPlay.GetFairPlayPoint() self.group_Gift.txt_TotalPoint.text = self.fairPlayPoint self:SetRewardChests() end --展示宝箱奖励 local UIFairPlayChestKey = "UIFairPlayChestKey" function UIFairPlayMainPanel:SetRewardChests() local rewardCount = DataSheetManager.FairPlayActivation:GetDataCount() local maxValue = 0 for i, v in DataSheetManager.FairPlayActivation:GetEnumerator() do if v.FairPlayActivationNum > maxValue then maxValue = v.FairPlayActivationNum end end self.group_Gift.Fill.fillAmount = self.fairPlayPoint / maxValue self.chestData = {} local width = self.group_Gift.Fill.gameObject.transform:GetSizeDelta() local singleWidth = width / rewardCount local isGot = MDL.FairPlay.GetFairPlayRewardState() for k, v in DataSheetManager.FairPlayActivation:GetEnumerator() do if self.group_Gift.group_Chest[k] == nil then self:InstantiateCollection(self.group_Gift.group_Chest, self.group_Gift.cell_Chest.gameObject) end local curChest = self.group_Gift.group_Chest[k] local offsetX = singleWidth * k curChest.gameObject.transform:SetAnchoredPosition(offsetX, self.chestAnchorPosY) self.chestData[k] = {} self.chestData[k].ID = v.ID self.chestData[k].Score = v.FairPlayActivationNum self.chestData[k].Item_Table = DataSheetManager.FairPlayRewardRepeat:GetDataByAttrRepeatID(v.RewardRepeat).Item_Table self.chestData[k].isGot = isGot[k] self:SetChestImgByState(self.group_Gift.group_Chest[k].state_Chest, isGot[k], self.group_Gift.group_Chest[k].effect_Reward, self.group_Gift.group_Chest[k].img_Dot_Unreached_01) UIUtils.SetLabel(self.group_Gift.group_Chest[k].lab_Reward, v.FairPlayActivationNum) UIUtils.SetActive(curChest.gameObject, true) end end function UIFairPlayMainPanel:SetChestImgByState(state, isGot, effectComp, Dot) if isGot == MDL.FairPlay.RewardState.WaitForGet then effectComp:PlayUIEffect() else effectComp:StopUIEffect() end if isGot ~= 0 then UIUtils.SetActive(Dot, true) end state:SetState(isGot) end function UIFairPlayMainPanel:OnClickChests(comp) for i = 1, #self.group_Gift.group_Chest do if comp == self.group_Gift.group_Chest[i].event_Reward then if self.fairPlayPoint >= self.chestData[i].Score and self.chestData[i].isGot == MDL.FairPlay.RewardState.WaitForGet then MDL.FairPlay.FairPlayGetRewardReq(i - 1) else local px = comp.transform:GetPosition() self:ShowChestReward(self.chestData[i].Item_Table, px) self:SaveChestOpenIndex(i) end end end end function UIFairPlayMainPanel:SaveChestOpenIndex(index) if self.context then self.context.chestIndex = index else self.context = { chestIndex = index } end end function UIFairPlayMainPanel:ShowChestReward(Item_Table, locateX) local rewardData = Item_Table UIUtils.SetActive(self.group_Gift.info_Reward.gameObject, true) UIUtils.SetActive(self.Bottom, true) self.group_Gift.ChestRewardScroll:ReloadAll(rewardData) self.group_Gift.info_Reward.transform:SetPosition(locateX, nil, nil) end function UIFairPlayMainPanel:ClearChestViews() UIUtils.SetActive(self.Bottom, false) UIUtils.SetActive(self.group_Gift.info_Reward.gameObject, false) if self.context and self.context.chestIndex then self.context.chestIndex = nil end end function UIFairPlayMainPanel:RefreshActivitiesCells() self.scroll_Activities:RefreshCells(false) end function UIFairPlayMainPanel:RefreshPKEntry(funcID, isUnlock) if funcID then if funcID == MDL.Unlock.FunctionType.SyncSoloPK or funcID == MDL.Unlock.FunctionType.SyncTVTPK then local PKTabs = CTL.CustomRoom.GetPKRoomListLeftTab() self.isUnlockPKRoom = #PKTabs > 0 UIUtils.SetActive(self.btn_PK, self.isUnlockPKRoom) elseif funcID == MDL.Unlock.FunctionType.KingChallenge then UIUtils.SetActive(self.btn_KingChallenge, CTL.KingChallenge.IsShowKingChallengeEntry()) end end end function UIFairPlayMainPanel:RefreshKingChallengeEntry() UIUtils.SetActive(self.btn_KingChallenge, CTL.KingChallenge.IsShowKingChallengeEntry()) local KingChallengeSpecialSeasonID = DataSheetManager.ConstData:GetDataByID("KingChallengeSpecialSeasonID").IntValue UIUtils.SetActive(self.img_treble , MDL.KingChallenge.GetCurBigSeasonId() == KingChallengeSpecialSeasonID) self.btn_KingChallenge:SetRedPoint(CTL.RedPoint.GetRedPointActive(CTL.RedPoint.RedPointKey.FairPlay_KingChallenge)) end return UIFairPlayMainPanel