UGCProjects/SoloKing/Script/UI/Child/WB_PlayerInfoItem.lua

123 lines
3.6 KiB
Lua
Raw Normal View History

2025-01-04 23:00:19 +08:00
---@class WB_PlayerInfoItem_C:UUserWidget
---@field Button_AddFri UButton
---@field Image_HeadIcon UImage
---@field Image_WeaponIcon UImage
---@field Overlay_MVP UOverlay
---@field TextBlock_BodySize UTextBlock
---@field TextBlock_Damage UTextBlock
---@field TextBlock_KDA UTextBlock
---@field TextBlock_No UTextBlock
---@field TextBlock_PlayerName UTextBlock
---@field WidgetSwitcher_0 UWidgetSwitcher
---@field WidgetSwitcher_IsSelf UWidgetSwitcher
--Edit Below--
---@type WB_PlayerInfoItem_C
local WB_PlayerInfoItem = { bInitDoOnce = false; };
WB_PlayerInfoItem.PlayerKey = 0;
function WB_PlayerInfoItem:Construct()
self:LuaInit();
end
function WB_PlayerInfoItem:LuaInit()
if self.bInitDoOnce then return ; end
self.Button_AddFri.OnClicked:Add(self.OnClickAddFriend, self)
UITool.EnableButtonScroll(self.Button_AddFri)
self.bInitDoOnce = true;
end
--function WB_PlayerInfoItem:SetAsTitle()
-- self:SetIsMVP(false);
-- self:IsSelf(false);
--
--end
function WB_PlayerInfoItem:SetIsMVP(IsMVP)
if IsMVP then
if not self.IsGaming then
self.Overlay_MVP:SetVisibility(ESlateVisibility.SelfHitTestInvisible);
end
end
end
function WB_PlayerInfoItem:IsSelf(IsSelf)
if IsSelf then
self.WidgetSwitcher_IsSelf:SetActiveWidgetIndex(1)
else
self.WidgetSwitcher_IsSelf:SetActiveWidgetIndex(0)
--if not self.IsGaming then self.Button_AddFri:SetVisibility(ESlateVisibility.Hidden); end
end
end
function WB_PlayerInfoItem:OnClickAddFriend()
---@type PlayerAccountInfo
local AccountInfo = UE.GetAccountInfo(self.PlayerKey);
UGCLogSystem.LogTree(string.format("[WB_PlayerInfoItem:OnClickAddFriend] AccountInfo ="), AccountInfo)
if AccountInfo then
UGCGameSystem.AddFriend(AccountInfo.UID);
end
end
WB_PlayerInfoItem.IsGaming = false;
function WB_PlayerInfoItem:SetInGaming()
self.Overlay_MVP.SetVisibility(ESlateVisibility.Collapsed);
self.Button_AddFri:SetVisibility(ESlateVisibility.Collapsed);
self.Overlay_Damage:SetVisibility(ESlateVisibility.Collapsed);
self.IsGaming = true;
end
--- 设置信息
function WB_PlayerInfoItem:SetItemInfo(Index, Info)
UGCLogSystem.Log("[WB_PlayerInfoItem:SetItemInfo] Index = %s", tostring(Index));
if Info == nil then return ; end
self.TextBlock_No:SetText(tostring(Index));
---@type PlayerKey
local PlayerKey = Info.Winner;
if PlayerKey then
local PlayerInfo = UE.GetAccountInfo(PlayerKey);
if PlayerInfo then
self.TextBlock_PlayerName:SetText(PlayerInfo.PlayerName);
UITool.DownloadImage(PlayerInfo.IconURL, function(Texture)
self.Image_HeadIcon:SetBrushFromTextureDynamic(Texture);
end)
end
else
self.TextBlock_PlayerName:SetText("--平局--");
self.Image_HeadIcon:SetVisibility(ESlateVisibility.Hidden)
end
if Info.Time then
if Info.Time > 100 then
self.TextBlock_Damage:SetText(string.format('%0.0f', Info.Time));
else
self.TextBlock_Damage:SetText(string.format('%0.1f', Info.Time));
end
self.TextBlock_Damage:SetVisibility(ESlateVisibility.SelfHitTestInvisible);
else
self.TextBlock_Damage:SetVisibility(ESlateVisibility.Collapsed);
end
self:IsSelf(PlayerKey == LocalPlayerKey);
if Info.Weapon then
local WeaponInfo = UGCItemSystem.GetItemData(Info.Weapon);
if WeaponInfo then
self.TextBlock_BodySize:SetText(WeaponInfo.ItemName);
UE.AsyncLoadObject_Cached(WeaponInfo.ItemWhiteIcon_n, function(TargetObject)
self.Image_WeaponIcon:SetBrushFromTexture(TargetObject);
end)
end
else
self.Image_WeaponIcon:SetVisibility(ESlateVisibility.Hidden);
end
end
-- function WB_PlayerInfoItem:Tick(MyGeometry, InDeltaTime)
-- end
-- function WB_PlayerInfoItem:Destruct()
-- end
return WB_PlayerInfoItem;