---@class WB_TeamSettlement_C:UUserWidget ---@field Button_AutoReturnToLobby UButton ---@field Button_share UButton ---@field CanvasPanel_Result UCanvasPanel ---@field Image_Left UImage ---@field Image_Right UImage ---@field TextBlock_AutoReturnToLobby UTextBlock ---@field TextBlock_LeftName UTextBlock ---@field TextBlock_LeftScore UTextBlock ---@field TextBlock_Levels2_2 UTextBlock ---@field TextBlock_RightName UTextBlock ---@field TextBlock_RightScore UTextBlock ---@field VerticalBox_Left UVerticalBox ---@field VerticalBox_Right UVerticalBox ---@field WidgetSwitcher_Win UWidgetSwitcher --Edit Below-- ---@type WB_TeamSettlement_C local WB_TeamSettlement = { bInitDoOnce = false; }; function WB_TeamSettlement:Construct() UGCLogSystem.Log("[WB_TeamSettlement:Construct] 启动") UGCEventSystem.AddListener(EventTypes.UpdateGameRound, self.OnUpdateGameRound, self); UGCEventSystem.AddListener(EventTypes.ChangeProcessState, self.OnChangeProcessState, self); --UGCEventSystem.AddListener(EventTypes.UpdatePlayerKDA, self.OnUpdatePlayerKDA, self); -- 一直更新数据 UITool.BindButtonClicked(self.Button_AutoReturnToLobby, self.Button_AutoReturnToLobby_OnClicked, self) UITool.BindButtonClicked(self.Button_share, self.ShareSettlement, self) -- 设置颜色 local CTColor = TeamConfig.TeamColor[TeamConfig.TeamType.CT] local TColor = TeamConfig.TeamColor[TeamConfig.TeamType.T] self.TextBlock_LeftScore:SetColorAndOpacity({ SpecifiedColor = CTColor, ColorUseRule = 0 }) self.TextBlock_RightScore:SetColorAndOpacity({ SpecifiedColor = TColor, ColorUseRule = 0 }) self.Image_Left:SetColorAndOpacity(CTColor) self.Image_Right:SetColorAndOpacity(TColor) self:HideAllItems(); UGCLogSystem.Log("[WB_TeamSettlement:Construct] 结束") end function WB_TeamSettlement:OnShowPanel(bIsSettlement) --- 开始显示 Rank self:UpdateRank(); self:ShowSettlement(bIsSettlement); self:AutoReturnToLobby(); end function WB_TeamSettlement:OnChangeProcessState(InState) if InState == EventTypes.GameProcessStates.Gaming then -- 设置数据进来 --UGCGameState.GameStage end end function WB_TeamSettlement:ShowSettlement(bIsShow) local Vis = bIsShow and ESlateVisibility.Visible or ESlateVisibility.Collapsed; self.WidgetSwitcher_Win:SetVisibility(Vis); self.Button_AutoReturnToLobby:SetVisibility(Vis); self.Button_share:SetVisibility(Vis); local Func = function(InBox) for i = 1, InBox:GetChildrenCount() do local Item = InBox:GetChildAt(i - 1); Item:ShowSettlementItem(Vis); end end Func(self.VerticalBox_Left); Func(self.VerticalBox_Right); end function WB_TeamSettlement:SetItemTeam() for i = 0, self.VerticalBox_Left:GetChildrenCount() - 1 do local ItemLeftInst = self.VerticalBox_Left:GetChildAt(i); local ItemRightInst = self.VerticalBox_Right:GetChildAt(i); ItemLeftInst:SetTeam(DefaultSettings.LocalTeamId); ItemRightInst:SetTeam(DefaultSettings.EnemyTeamId); end end function WB_TeamSettlement:HideAllItems() local LeftCount = self.VerticalBox_Left:GetChildrenCount(); local RightCount = self.VerticalBox_Right:GetChildrenCount(); for i = 1, LeftCount do local Item = self.VerticalBox_Left:GetChildAt(i - 1); Item:SetVisibility(ESlateVisibility.Collapsed); end for i = 1, RightCount do local Item = self.VerticalBox_Right:GetChildAt(i - 1); Item:SetVisibility(ESlateVisibility.Collapsed); end end function WB_TeamSettlement:UpdateRank() UGCLogSystem.Log("[WB_TeamSettlement:UpdateRank]"); local SelfScore = UGCGameSystem.GameState:GetTeamScore(DefaultSettings.LocalTeamId) local OtherScore = UGCGameSystem.GameState:GetTeamScore(DefaultSettings.EnemyTeamId); self.TextBlock_LeftScore:SetText(tostring(SelfScore)); self.TextBlock_RightScore:SetText(tostring(OtherScore)); -- 设置胜利图标 self.WidgetSwitcher_Win:SetActiveWidgetIndex(SelfScore < OtherScore and 1 or 0); UGCLogSystem.Log("[WB_TeamSettlement:UpdateRank] Local Team Id = %s, Other Team Id = %s", tostring(DefaultSettings.LocalTeamId), tostring(DefaultSettings.EnemyTeamId)); ---@type table> local RankData = UGCGameSystem.GameState:GetPlayerRank(); local LocalTeamId, EnemyTeamId = 0, 0; for i = 1, #RankData do local RankItem = RankData[i]; if RankItem.TeamId == DefaultSettings.LocalTeamId then local Item = self.VerticalBox_Left:GetChildAt(LocalTeamId); LocalTeamId = LocalTeamId + 1 Item:SetRankData(LocalTeamId, RankItem); Item:SetVisibility(ESlateVisibility.SelfHitTestInvisible); else local Item = self.VerticalBox_Right:GetChildAt(EnemyTeamId); EnemyTeamId = EnemyTeamId + 1 Item:SetRankData(EnemyTeamId, RankItem); Item:SetVisibility(ESlateVisibility.SelfHitTestInvisible); end end UGCLogSystem.LogTree("[WB_TeamSettlement:UpdateRank] RankData = ", RankData); end function WB_TeamSettlement:AutoReturnToLobby() self.DelayReturnToLobbyTime = DefaultSettings.DelayReturnToLobbyTime self.SettlementTime = KismetSystemLibrary.GetGameTimeInSeconds(self) self.DelayReturnToLobbyTimerHandle = UGCEventSystem.SetTimerLoop(self, function() local NowTime = KismetSystemLibrary.GetGameTimeInSeconds(self) local ShowTime = math.floor(self.DelayReturnToLobbyTime - (NowTime - self.SettlementTime)) ShowTime = ShowTime >= 0 and ShowTime or 0 self.TextBlock_AutoReturnToLobby:SetText(string.format("返回大厅(%ds)", ShowTime)) if ShowTime <= 0 then self:Button_AutoReturnToLobby_OnClicked() end end, 0.5); end ---@param InData table function WB_TeamSettlement:OnUpdateGameRound(InData) local List = {}; for i, TeamId in pairs(InData) do List[TeamId] = (List[TeamId] or 0) + 1; end local TotalCount = table.getCount(InData); -- 这是自己的 local SelfScore = List[DefaultSettings.LocalTeamId]; if SelfScore == nil then SelfScore = 0; end local OtherScore = TotalCount - SelfScore; self.TextBlock_LeftScore:SetText(tostring(SelfScore)); self.TextBlock_RightScore:SetText(tostring(OtherScore)); end function WB_TeamSettlement:Button_AutoReturnToLobby_OnClicked() if self == nil or self.DoOnceReturnToLobby then return end if self.DelayReturnToLobbyTimerHandle then UGCEventSystem.StopTimer(self.DelayReturnToLobbyTimerHandle) self.DelayReturnToLobbyTimerHandle = nil end self.DoOnceReturnToLobby = true UGCLogSystem.Log("[WB_TeamSettlement_Button_AutoReturnToLobby_OnClicked]"); UGCGameSystem.ReturnToLobby() end --- 分享战绩 function WB_TeamSettlement:ShareSettlement() UGCWidgetManagerSystem.Share(); end return WB_TeamSettlement;