127 lines
3.4 KiB
Lua
127 lines
3.4 KiB
Lua
---@class WB_TeamScore_C:UAEUserWidget
|
|
---@field VerticalBox_Left UVerticalBox
|
|
---@field VerticalBox_Right UVerticalBox
|
|
--Edit Below--
|
|
---@type WB_TeamScore_C
|
|
local WB_TeamScore = { bInitDoOnce = false; };
|
|
|
|
---@type table<TeamId, table<int32, PlayerKDAItem1>>
|
|
WB_TeamScore.TeamKDAs = {};
|
|
|
|
function WB_TeamScore:Construct()
|
|
UGCEventSystem.AddListener(EventTypes.UpdateNewTeams, self.InitPlayers, self);
|
|
UGCEventSystem.AddListener(EventTypes.UpdatePlayerKDA, self.OnUpdatePlayerKDA, self);
|
|
end
|
|
|
|
-- function WB_TeamScore:Tick(MyGeometry, InDeltaTime)
|
|
|
|
-- end
|
|
|
|
-- function WB_TeamScore:Destruct()
|
|
|
|
-- end
|
|
|
|
function WB_TeamScore:OnUpdatePlayerKDA(InKda)
|
|
-- 构建数组,然后进行排序
|
|
local OtherTeamId = nil;
|
|
for TeamId, Info in pairs(self.TeamKDAs) do
|
|
if DefaultSettings.LocalTeamId ~= TeamId then
|
|
OtherTeamId = TeamId;
|
|
end
|
|
for i, Item in pairs(Info) do
|
|
for PlayerKey, v in pairs(UGCGameSystem.GameState.TotalPlayerKDA) do
|
|
if Item.PlayerKey == PlayerKey then
|
|
Info[i].Score = (v.Kill + v.Assist) / (v.Dead == 0 and 1 or v.Dead);
|
|
Info[i].Kill = v.Kill;
|
|
Info[i].Assist = v.Assist;
|
|
Info[i].Dead = v.Dead;
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
UGCLogSystem.LogTree(string.format("[WB_TeamScore:OnUpdatePlayerKDA] TeamKDAs ="), self.TeamKDAs)
|
|
|
|
for i, v in pairs(self.TeamKDAs) do
|
|
table.sort(self.TeamKDAs[i], function(a, b)
|
|
if a.Kill ~= b.Kill then
|
|
return a.Kill > b.Kill;
|
|
end
|
|
if a.Score ~= b.Score then
|
|
return a.Score > b.Score;
|
|
end
|
|
return a.Dead < b.Dead;
|
|
end)
|
|
end
|
|
|
|
UGCLogSystem.LogTree(string.format("[WB_TeamScore:OnUpdatePlayerKDA] self.TeamKDAs ="), self.TeamKDAs)
|
|
|
|
-- 放进去
|
|
self:SetPlayers(self.VerticalBox_Left, self.TeamKDAs[DefaultSettings.LocalTeamId]);
|
|
self:SetPlayers(self.VerticalBox_Right, self.TeamKDAs[DefaultSettings.EnemyTeamId]);
|
|
end
|
|
|
|
---@param InBox UVerticalBox
|
|
---@param InPlayerList table<int32, PlayerKDAItem1>
|
|
function WB_TeamScore:SetPlayers(InBox, InPlayerList)
|
|
if table.isEmpty(InPlayerList) then return end
|
|
for i = 1, InBox:GetChildrenCount() do
|
|
local Item = InBox:GetChildAt(i - 1);
|
|
if InPlayerList[i] ~= nil then
|
|
Item:SetPlayerKey(InPlayerList[i].PlayerKey, InPlayerList[i]);
|
|
end
|
|
end
|
|
end
|
|
|
|
---@param InTable table<TeamId, table<int32, PlayerKey>>
|
|
function WB_TeamScore:InitPlayers(InTable)
|
|
log_tree("[WB_TeamScore:InitPlayers] InTable = ", InTable);
|
|
|
|
self.TeamKDAs = {};
|
|
for TeamId, Table in pairs(InTable) do
|
|
if self.TeamKDAs[TeamId] == nil then
|
|
self.TeamKDAs[TeamId] = {};
|
|
end
|
|
|
|
for i, v in pairs(Table) do
|
|
self.TeamKDAs[TeamId][#(self.TeamKDAs[TeamId]) + 1] = {
|
|
PlayerKey = v;
|
|
Score = 0,
|
|
Kill = 0,
|
|
Dead = 0,
|
|
Assist = 0,
|
|
};
|
|
end
|
|
|
|
---@type UVerticalBox
|
|
local Box = nil;
|
|
if TeamId == DefaultSettings.LocalTeamId then
|
|
-- 说明是左边,否则是右边
|
|
Box = self.VerticalBox_Left;
|
|
else
|
|
Box = self.VerticalBox_Right;
|
|
end
|
|
|
|
local BoxCount = Box:GetChildrenCount();
|
|
local TableCount = table.getCount(Table);
|
|
|
|
if BoxCount < TableCount then
|
|
for i = 1, TableCount - BoxCount do
|
|
UITool.AddWidgetItem(Box, ObjectPath.WB_TeamScore_Item, self);
|
|
end
|
|
end
|
|
|
|
for i = 1, BoxCount do
|
|
local Item = Box:GetChildAt(i - 1);
|
|
if i <= TableCount then
|
|
Item:SetPlayerKey(Table[i]);
|
|
Item:SetVisibility(ESlateVisibility.SelfHitTestInvisible);
|
|
else
|
|
Item:SetPlayerKey(nil);
|
|
Item:SetVisibility(ESlateVisibility.Collapsed);
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
return WB_TeamScore; |