UGCProjects/BoltGods/Script/UI/WB_PlayerInfo_Small.lua
2025-01-04 23:00:19 +08:00

74 lines
1.8 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
UITool.ForeachAllChildren(self.ScrollBox_Items, function(index, Widget)
Widget:LuaInit();
Widget:SetVisibility(ESlateVisibility.Collapsed);
end)
self.bInitDoOnce = true;
end
-- function WB_PlayerInfo_Small:Tick(MyGeometry, InDeltaTime)
-- end
-- function WB_PlayerInfo_Small:Destruct()
-- end
function WB_PlayerInfo_Small:UpdatePlayerKDAs(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;
Kda = Item.KDA;
Kill = Item.Kill;
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;