---@class WB_Title2_C:UUserWidget ---@field Button_Score UButton ---@field TextBlock_CountDown UTextBlock ---@field TextBlock_EnemyScore UTextBlock ---@field TextBlock_SelfScore UTextBlock ---@field TextBlock_Time UTextBlock --Edit Below-- local WB_Title2 = { bInitDoOnce = false } WB_Title2.ShowRoundTimes = false; WB_Title2.IsShowScore = false; WB_Title2.Owner = nil; WB_Title2.Func = nil; function WB_Title2:Construct() self:LuaInit(); end -- function WB_Title2:Tick(MyGeometry, InDeltaTime) -- end function WB_Title2:Destruct() UGCEventSystem.RemoveListener(EventTypes.CountDownTimeChange, self.OnCountDownChange, self) UGCEventSystem.RemoveListener(EventTypes.UpdateRoundTimes, self.OnUpdateRoundTimes, self) UGCEventSystem.RemoveListener(EventTypes.UpdatePlayerKDAs, self.OnUpdatePlayerKDAs, self) --UGCEventSystem.RemoveListener(EventTypes.UpdateRoundWinners, self.OnUpdateRoundWinners, self) end function WB_Title2:LuaInit() if self.bInitDoOnce then return ; end UGCEventSystem.AddListener(EventTypes.CountDownTimeChange, self.OnCountDownChange, self) UGCEventSystem.AddListener(EventTypes.UpdateRoundTimes, self.OnUpdateRoundTimes, self) --UGCEventSystem.AddListener(EventTypes.UpdateRoundWinners, self.OnUpdateRoundWinners, self) UGCEventSystem.AddListener(EventTypes.UpdatePlayerKDAs, self.OnUpdatePlayerKDAs, self) UITool.BindButtonClicked(self.Button_Score, self.OnShowScore, self) self.TextBlock_Time:SetText("0") self.TextBlock_SelfScore:SetText("0") self.TextBlock_EnemyScore:SetText("0") if self.ShowRoundTimes then self.TextBlock_Time:SetVisibility(ESlateVisibility.SelfHitTestInvisible); else self.TextBlock_Time:SetVisibility(ESlateVisibility.Collapsed); end self.bInitDoOnce = true; end function WB_Title2:OnCountDownChange(InTime) if not self.ShowRoundTimes then UGCLogSystem.Log("[WB_Title2:OnCountDownChange] InTime = %s", tostring(InTime)); if InTime <= 0 then self.TextBlock_CountDown:SetText("00:00") else self.TextBlock_CountDown:SetText(string.format("%02d:%02d", InTime // 60, InTime % 60)); end end end function WB_Title2:OnShowScore() if self.Owner and self.Func then self.Func(self.Owner); end end function WB_Title2:OnUpdateRoundTimes(InTimes, InTotal) UGCLogSystem.Log("[WB_Main:OnUpdateRoundTimes] InTimes = %s, InTotal = %s", tostring(InTimes), tostring(InTotal)); if InTimes ~= nil and InTotal ~= nil then self.TextBlock_Time:SetText(tostring(InTotal - InTimes)); end end function WB_Title2:SetOwner(InOwner, InFunc) self.Owner = InOwner; self.Func = InFunc; end function WB_Title2:OnUpdateRoundWinners(InWinners) local Rounds = {}; for i, v in pairs(InWinners) do if Rounds[v.Winner] == nil then Rounds[v.Winner] = 1 else Rounds[v.Winner] = 1 + Rounds[v.Winner]; end end local Func = function(InPlayerKey) if InPlayerKey == nil then return 0; end if Rounds[InPlayerKey] then return Rounds[InPlayerKey]; end return 0; end UGCLogSystem.LogTree(string.format("[WB_Title2:OnUpdateRoundWinners] Rounds"), Rounds); for i, v in pairs(Rounds) do if i == LocalPlayerKey then self.TextBlock_SelfScore:SetText(Func(i)); else self.TextBlock_EnemyScore:SetText(Func(i)); end end end function WB_Title2:OnUpdatePlayerKDAs(InKDAs) local Self, Total, Max = 0, 0, 0; for PlayerKey, Kda in pairs(InKDAs) do if PlayerKey == LocalPlayerKey then Self = Kda.Kill; end if Kda.Kill > Max then Max = Kda.Kill; end Total = Total + Kda.Kill; end self.TextBlock_SelfScore:SetText(Self); self.TextBlock_EnemyScore:SetText(Max); if Self == Max then -- 设置颜色 else -- 设置颜色 end end return WB_Title2