---@class WB_PlayerScores_C:UUserWidget ---@field HorizontalBox_Items UHorizontalBox ---@field WB_PlayerScoreItem_9 UWB_PlayerScoreItem_C ---@field WB_PlayerScoreItem_16 UWB_PlayerScoreItem_C ---@field WB_PlayerScoreItem_17 UWB_PlayerScoreItem_C ---@field WB_PlayerScoreItem_18 UWB_PlayerScoreItem_C ---@field WB_PlayerScoreItem_19 UWB_PlayerScoreItem_C ---@field WB_PlayerScoreItem_20 UWB_PlayerScoreItem_C ---@field WB_PlayerScoreItem_21 UWB_PlayerScoreItem_C ---@field WB_PlayerScoreItem_22 UWB_PlayerScoreItem_C ---@field WB_PlayerScoreItem_23 UWB_PlayerScoreItem_C ---@field WB_PlayerScoreItem_24 UWB_PlayerScoreItem_C ---@field WB_PlayerScoreItem_25 UWB_PlayerScoreItem_C ---@field WB_PlayerScoreItem_26 UWB_PlayerScoreItem_C ---@field WB_PlayerScoreItem_27 UWB_PlayerScoreItem_C ---@field WB_PlayerScoreItem_28 UWB_PlayerScoreItem_C ---@field WB_PlayerScoreItem_29 UWB_PlayerScoreItem_C ---@field WB_PlayerScoreItem_30 UWB_PlayerScoreItem_C --Edit Below-- ---@type WB_PlayerScores_C local WB_PlayerScores = { bInitDoOnce = false } function WB_PlayerScores:Construct() self:LuaInit(); end function WB_PlayerScores:LuaInit() if self.bInitDoOnce then return ; end UGCLogSystem.Log("[WB_PlayerScores:LuaInit] 执行") UGCEventSystem.AddListener(EventTypes.UpdatePlayerDatas, self.OnUpdatePlayerDatas, self); UGCEventSystem.AddListener(EventTypes.UpdatePlayerKDAs, self.OnUpdatePlayerKDAs, self); -- 检查一下是否有数据 if UGCGameSystem.GameState and UGCGameSystem.GameState.PlayerDatas then self:OnUpdatePlayerDatas(UGCGameSystem.GameState.PlayerDatas); end self.bInitDoOnce = true; end function WB_PlayerScores:OnClose() WidgetManager:ClosePanel(self.UIType); end ---@param InDatas GameStatePlayerDatas function WB_PlayerScores:OnUpdatePlayerDatas(InDatas) UGCLogSystem.LogTree(string.format("[WB_PlayerScores:OnUpdatePlayerDatas] InDatas ="), InDatas) local Table = {}; for PlayerKey, Info in pairs(InDatas.AccountInfo) do table.insert(Table, { PlayerKey = PlayerKey, Kill = 0, Dead = 0, Assist = 0, TeamId = Info.TeamID; KDA = 0, }) end self:SetRanks(Table); end ---@param InKDAs PlayerKDAList function WB_PlayerScores:OnUpdatePlayerKDAs(InKDAs) local Table = {}; UGCLogSystem.LogTree(string.format("[WB_PlayerScores:OnUpdatePlayerKDAs] InKDAs ="), InKDAs) ---@type table local AccountInfo = GameState.PlayerDatas.AccountInfo; for PlayerKey, v in pairs(InKDAs) do table.insert(Table, { PlayerKey = PlayerKey, Kill = v.Kill, Dead = v.Dead, Assist = v.Assist, TeamId = AccountInfo[PlayerKey].TeamID, KDA = ((v.Kill or 0) + (v.Assist or 0)) / ((v.Dead or 0) == 0 and 1 or v.Dead), Soldier = GlobalMiniMode.PlayerSelectSoldiers[PlayerKey]; }); end UGCLogSystem.LogTree(string.format("[WB_PlayerScores:OnUpdatePlayerKDAs] Table ="), Table) self:SetRanks(Table); end function WB_PlayerScores:SetRanks(Items) table.sort(Items, function(a, b) if a.Kill == b.Kill then if a.KDA == b.KDA then if a.Dead == b.Dead then return a.Assist > b.Assist; end return a.Dead < b.Dead; end return a.KDA > b.KDA; end return a.Kill > b.Kill; end); UGCLogSystem.Log("[WB_PlayerScores:SetRanks] 111") UITool.HideAllChildren(self.HorizontalBox_Items:GetChildAt(0)); UITool.HideAllChildren(self.HorizontalBox_Items:GetChildAt(1)); UGCLogSystem.LogTree(string.format("[WB_PlayerScores:SetRanks] Items ="), Items) local LeftCount, RightCount = 0, 0; for i = 1, #Items do local ResItem = Items[i]; if ResItem.TeamId == LocalTeamId then local Item = self.HorizontalBox_Items:GetChildAt(0):GetChildAt(LeftCount); Item:SetScoreItem(ResItem); Item:SetVisibility(ESlateVisibility.SelfHitTestInvisible); LeftCount = LeftCount + 1; UGCLogSystem.Log("[WB_PlayerScores:SetRanks] 111") else local Item = self.HorizontalBox_Items:GetChildAt(1):GetChildAt(RightCount); Item:SetScoreItem(ResItem); Item:SetVisibility(ESlateVisibility.SelfHitTestInvisible); RightCount = RightCount + 1; end end UGCLogSystem.Log("[WB_PlayerScores:SetRanks] 333") end function WB_PlayerScores:UpdatePlayerSoldiers(SoldierList) UGCLogSystem.LogTree(string.format("[WB_PlayerScores:UpdatePlayerSoldiers] SoldierList ="), SoldierList) if SoldierList == nil then return; end for PlayerKey, SoldierType in pairs(SoldierList) do -- 判断当前是否是自己队伍 local Item = self:GetScoreItem(PlayerKey) if Item then Item:SetSoldier(SoldierType); else UGCLogSystem.Log("[WB_PlayerScores:UpdatePlayerSoldiers] Soldier Type = %s", tostring(SoldierType)); end end end function WB_PlayerScores:GetScoreItem(InPlayerKey) local TeamID = GameState.PlayerDatas.AccountInfo[InPlayerKey].TeamID; local SelectIndex = 0; if TeamID ~= LocalTeamId then SelectIndex = 1; end return UITool.FindItem(self.HorizontalBox_Items:GetChildAt(SelectIndex), function(Widget) return Widget:GetPlayerKey() == InPlayerKey; end); end -- function WB_PlayerScores:Tick(MyGeometry, InDeltaTime) -- end -- function WB_PlayerScores:Destruct() -- end return WB_PlayerScores