75 lines
1.9 KiB
Lua
75 lines
1.9 KiB
Lua
---@class WB_PlayerInfo_Small_C:UUserWidget
|
|
---@field ScrollBox_Items UScrollBox
|
|
--Edit Below--
|
|
---@type WB_PlayerInfo_Small_C
|
|
local WB_PlayerInfo_Small = { bInitDoOnce = false; };
|
|
|
|
function WB_PlayerInfo_Small:Construct()
|
|
self:LuaInit();
|
|
end
|
|
|
|
WB_PlayerInfo_Small.HeadIcons = {};
|
|
|
|
function WB_PlayerInfo_Small:LuaInit()
|
|
if self.bInitDoOnce then return ; end
|
|
UGCEventSystem.AddListener(EventTypes.UpdatePlayerKDAs, self.OnUpdatePlayerKDAs, self)
|
|
UITool.ForeachAllChildren(self.ScrollBox_Items, function(index, Widget)
|
|
Widget:LuaInit();
|
|
Widget:SetVisibility(ESlateVisibility.Collapsed);
|
|
end)
|
|
--UGCEventSystem.AddListener(EventTypes.UpdateRoundWinners, self.OnUpdateRoundWinners, self);
|
|
UIManager:Register("WB_PlayerInfo_Small", self);
|
|
self.bInitDoOnce = true;
|
|
end
|
|
|
|
-- function WB_PlayerInfo_Small:Tick(MyGeometry, InDeltaTime)
|
|
|
|
-- end
|
|
|
|
-- function WB_PlayerInfo_Small:Destruct()
|
|
|
|
-- end
|
|
|
|
function WB_PlayerInfo_Small:OnUpdatePlayerKDAs(InKDAs)
|
|
local KDATable = {};
|
|
for PlayerKey, KDA in pairs(InKDAs) do
|
|
table.insert(KDATable, {
|
|
Kill = KDA.Kill,
|
|
Dead = KDA.Dead,
|
|
Assist = KDA.Assist,
|
|
KDA = (KDA.Kill + KDA.Assist) / (KDA.Dead == 0 and 1 or KDA.Dead),
|
|
PlayerKey = PlayerKey,
|
|
});
|
|
end
|
|
table.sort(KDATable, function(a, b)
|
|
if a.KDA == b.KDA then
|
|
if a.Kill == b.Kill then return a.Dead < b.Dead; end
|
|
return a.Kill > b.Kill
|
|
end
|
|
return a.KDA > b.KDA;
|
|
end)
|
|
local No = 1;
|
|
local Kda, Kill = -1, -1;
|
|
for i = 1, #KDATable do
|
|
local Item = KDATable[i];
|
|
if Kda == Item.KDA and Kill == Item.Kill then
|
|
else
|
|
No = i;
|
|
end
|
|
Item.No = No;
|
|
end
|
|
self:SetKDAItems(KDATable);
|
|
end
|
|
|
|
function WB_PlayerInfo_Small:SetKDAItems(InItems)
|
|
UITool.ForeachAllChildren(self.ScrollBox_Items, function(index, Widget)
|
|
if InItems[index] then
|
|
Widget:SetKDAItem(InItems[index]);
|
|
Widget:SetVisibility(ESlateVisibility.SelfHitTestInvisible);
|
|
else
|
|
Widget:SetVisibility(ESlateVisibility.Collapsed);
|
|
end
|
|
end)
|
|
end
|
|
|
|
return WB_PlayerInfo_Small; |