130 lines
4.1 KiB
Lua
130 lines
4.1 KiB
Lua
|
---@class WB_PlayerSoldiers_C:UAEUserWidget
|
||
|
---@field VerticalBox_Players UVerticalBox
|
||
|
---@field WB_PlayerSoldier_Item_Self UWB_PlayerSoldier_Item_C
|
||
|
--Edit Below--
|
||
|
---@type WB_PlayerSoldiers_C
|
||
|
local WB_PlayerSoldiers = { bInitDoOnce = false; };
|
||
|
|
||
|
--- 支持显示的数量
|
||
|
WB_PlayerSoldiers.TargetShowCount = 4;
|
||
|
---@type table<PlayerKey, WB_PlayerSoldier_Item_C> 玩家子UI列表
|
||
|
WB_PlayerSoldiers.PlayerKeyItems = {};
|
||
|
|
||
|
function WB_PlayerSoldiers:Construct()
|
||
|
UGCLogSystem.Log("[WB_PlayerSoldiers:Construct] 执行")
|
||
|
self:LuaInit();
|
||
|
end
|
||
|
|
||
|
function WB_PlayerSoldiers:LuaInit()
|
||
|
if self.bInitDoOnce then return; end
|
||
|
self.bInitDoOnce = true;
|
||
|
|
||
|
UGCEventSystem.AddListener(EventTypes.PlayerUseBuff, self.OnPlayerUseBuff, self);
|
||
|
UGCEventSystem.AddListener(EventTypes.UpdatePlayerKDAs, self.OnUpdatePlayerKDAs, self);
|
||
|
|
||
|
UITool.ForeachAllChildren(self.VerticalBox_Players, function(index, Widget)
|
||
|
Widget:SetVisibility(ESlateVisibility.Collapsed);
|
||
|
Widget:LuaInit();
|
||
|
end);
|
||
|
|
||
|
local KDA = MiniTool:GetValue("PlayerKDAs");
|
||
|
if KDA then
|
||
|
UGCLogSystem.LogTree(string.format("[WB_PlayerSoldiers:LuaInit] KDA"), KDA);
|
||
|
ObjectPath.AddFunc("WB_PlayerSoldier_Item", function(TargetClass)
|
||
|
UGCLogSystem.Log("[WB_PlayerSoldiers:LuaInit] 加载成功");
|
||
|
self:FillList(KDA);
|
||
|
end)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
-- function WB_PlayerSoldiers:Tick(MyGeometry, InDeltaTime) end
|
||
|
-- function WB_PlayerSoldiers:Destruct() end
|
||
|
|
||
|
function WB_PlayerSoldiers:SetPlayerSoldiers(PlayerSoldiers)
|
||
|
UGCLogSystem.LogTree(string.format("[WB_PlayerSoldiers:SetPlayerSoldiers] PlayerSoldiers ="), PlayerSoldiers)
|
||
|
for PlayerKey, Soldier in pairs(PlayerSoldiers) do
|
||
|
if PlayerKey == LocalPlayerKey then
|
||
|
self.WB_PlayerSoldier_Item_Self:SetSoldierType(Soldier);
|
||
|
end
|
||
|
if self.PlayerKeyItems[PlayerKey] then
|
||
|
self.PlayerKeyItems[PlayerKey]:SetSoldierType(Soldier);
|
||
|
--self.PlayerKeyItems[PlayerKey]:SetVisibility(ESlateVisibility.HitTestInvisible);
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
---@param InDatas GameStatePlayerDatas
|
||
|
function WB_PlayerSoldiers:OnUpdatePlayerDatas(InDatas)
|
||
|
for PlayerKey, Info in pairs(InDatas) do
|
||
|
if Info.TeamID == LocalTeamId then
|
||
|
if self.PlayerKeyItems[PlayerKey] == nil then
|
||
|
local Widget = nil;
|
||
|
if self.VerticalBox_Players:GetChildrenCount() > 0 then
|
||
|
-- 设置进去
|
||
|
Widget = self.VerticalBox_Players:GetChildAt(0);
|
||
|
self.VerticalBox_Players:RemoveChildAt(0);
|
||
|
else
|
||
|
Widget = UITool.CreateWidget(ObjectPath.WB_PlayerSoldier_Item, self);
|
||
|
end
|
||
|
Widget:SetPlayerKey(PlayerKey);
|
||
|
self.PlayerKeyItems[PlayerKey] = Widget;
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
-- 执行到这里的时候
|
||
|
if LocalPlayerKey then
|
||
|
self.WB_PlayerSoldier_Item_Self:SetPlayerKey(LocalPlayerKey);
|
||
|
end
|
||
|
end
|
||
|
|
||
|
--- 填充列表
|
||
|
---@param KDAList table<PlayerKey, PlayerKDAItem>
|
||
|
function WB_PlayerSoldiers:FillList(KDAList)
|
||
|
if KDAList == nil then
|
||
|
if MiniGameManager then KDAList = MiniGameManager.PlayerKDAs; end
|
||
|
if table.isEmpty(KDAList) then return; end
|
||
|
end
|
||
|
local List = {};
|
||
|
for PlayerKey, Item in pairs(KDAList) do
|
||
|
table.insert(List, {
|
||
|
PlayerKey = PlayerKey,
|
||
|
Kill = Item.Kill,
|
||
|
});
|
||
|
end
|
||
|
table.sort(List, function(a, b) return a.Kill > b.Kill; end);
|
||
|
|
||
|
UITool.HideAllChildren(self.VerticalBox_Players);
|
||
|
self.VerticalBox_Players:ClearChildren();
|
||
|
|
||
|
for i = 1, self.TargetShowCount do
|
||
|
local Item = List[i];
|
||
|
local Widget = self.PlayerKeyItems[Item.PlayerKey];
|
||
|
if Widget == nil then
|
||
|
-- 创建一个新的
|
||
|
Widget = UITool.CreateWidget(ObjectPath.WB_PlayerSoldier_Item, self);
|
||
|
self.PlayerKeyItems[Item.PlayerKey] = Widget;
|
||
|
end
|
||
|
Widget:SetVisibility(ESlateVisibility.HitTestInvisible);
|
||
|
Widget:SetKillNum(Item.Kill);
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function WB_PlayerSoldiers:OnPlayerUseBuff(InPlayerKey, Success, ExecTime)
|
||
|
if self.PlayerKeyItems[InPlayerKey] then
|
||
|
self.PlayerKeyItems[InPlayerKey]:SetBuffUse(Success, ExecTime);
|
||
|
end
|
||
|
end
|
||
|
|
||
|
-- 永远执行不到
|
||
|
function WB_PlayerSoldiers:OnResetRound()
|
||
|
for PlayerKey, Widget in pairs(self.PlayerKeyItems) do Widget:ResetItem(); end
|
||
|
end
|
||
|
|
||
|
---@param InList table<PlayerKey, PlayerKDAItem>
|
||
|
function WB_PlayerSoldiers:OnUpdatePlayerKDAs(InList)
|
||
|
if table.isEmpty(InList) then return; end
|
||
|
-- 计算前三
|
||
|
self:FillList(InList);
|
||
|
end
|
||
|
|
||
|
return WB_PlayerSoldiers;
|