131 lines
5.0 KiB
Lua
131 lines
5.0 KiB
Lua
---@class WB_PlayerHead_48_C:UUserWidget
|
|
---@field Border_HeadMain UBorder
|
|
---@field Common_Avatar_BP_C_0 UCommon_Avatar_BP_C
|
|
---@field Overlay_Dead UOverlay
|
|
---@field Overlay_KnockedDown UOverlay
|
|
---@field ProgressBar_Health UProgressBar
|
|
---@field WidgetSwitcher_Frame UWidgetSwitcher
|
|
--Edit Below--
|
|
local WB_PlayerHead_48 = {
|
|
bInitDoOnce = false;
|
|
IsShowHealth = false;
|
|
UpdateFPS = 3.;
|
|
IsShowFrame = true;
|
|
PlayerKey = -1;
|
|
}
|
|
|
|
--[==[ Construct
|
|
function WB_PlayerHead:Construct()
|
|
|
|
end
|
|
-- Construct ]==]
|
|
|
|
-- function WB_PlayerHead:Tick(MyGeometry, InDeltaTime)
|
|
|
|
-- end
|
|
|
|
-- function WB_PlayerHead:Destruct()
|
|
|
|
-- end
|
|
|
|
function WB_PlayerHead_48:LuaInit()
|
|
if self.bInitDoOnce then return end self.bInitDoOnce = true
|
|
UGCEventSystem.SetTimerLoop(self, self.UpdatePlayerStateInfo, 1. / self.UpdateFPS)
|
|
end
|
|
|
|
function WB_PlayerHead_48:SetShowFrame(IsShowFrame)
|
|
self.IsShowFrame = IsShowFrame
|
|
end
|
|
|
|
---@param Index 0:Nill 1:SelfTeam 2:EnemyTeam
|
|
function WB_PlayerHead_48:ShowTeamFrame(Index)
|
|
self.WidgetSwitcher_Frame:SetActiveWidgetIndex(Index)
|
|
end
|
|
|
|
function WB_PlayerHead_48:UpdatePlayerInfo(PlayerKey)
|
|
|
|
if self.PlayerKey ~= PlayerKey then
|
|
self.PlayerKey = PlayerKey
|
|
if self.PlayerKey and self.PlayerKey > 0 then
|
|
self:LuaInit()
|
|
self:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
|
local PlayerInfo = UGCGameSystem.GameState:GetPlayerHeadInfo(PlayerKey)
|
|
---@param PlayerInfo table {UID:string, IconURL:string, Gender:int, AvatarBoxId:int, PlayerLevel:int, PlayerName:string} 其中AvatarBoxId可以从PlayerState中获取
|
|
---@field InitView:fun(style:int32,uid:FString,iconURL:FString,gender:int32,frameLevel:int32,playerLevel:int32,ignoreFrame:bool,IsMySelf:bool)
|
|
local AvatarBoxId = self.IsShowFrame and PlayerInfo.AvatarBoxId or 0
|
|
self.Common_Avatar_BP_C_0:InitView(2, PlayerInfo.UIDString, PlayerInfo.IconURL, PlayerInfo.Gender, AvatarBoxId, PlayerInfo.PlayerLevel, false, false)
|
|
else
|
|
self:SetVisibility(ESlateVisibility.Collapsed)
|
|
end
|
|
end
|
|
end
|
|
|
|
function WB_PlayerHead_48:SetShowHealth(IsShow)
|
|
if IsShow ~= self.IsShowHealth then
|
|
self.IsShowHealth = IsShow
|
|
if self.IsShowHealth then
|
|
self.ProgressBar_Health:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
|
else
|
|
self.ProgressBar_Health:SetVisibility(ESlateVisibility.Collapsed)
|
|
end
|
|
end
|
|
end
|
|
|
|
EPlayerHeadInfoState = {
|
|
Alive = 1;
|
|
Death = 2;
|
|
KnockedDown = 3;
|
|
}
|
|
|
|
function WB_PlayerHead_48:UpdatePlayerStateInfo()
|
|
if self.PlayerKey == nil or self.PlayerKey < 0 then return end
|
|
local PlayerHeadState = EPlayerHeadInfoState.Alive
|
|
local PlayerPawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.PlayerKey)
|
|
if UE.IsValid(PlayerPawn) then
|
|
if UGCPawnSystem.HasPawnState(PlayerPawn, EPawnState.Dead) then
|
|
PlayerHeadState = EPlayerHeadInfoState.Death
|
|
elseif UGCPawnSystem.HasPawnState(PlayerPawn, EPawnState.Dying) then
|
|
PlayerHeadState = EPlayerHeadInfoState.KnockedDown
|
|
end
|
|
else
|
|
PlayerHeadState = EPlayerHeadInfoState.Death
|
|
end
|
|
-- 更新显示状态
|
|
self:UpdateWidgetState(PlayerHeadState)
|
|
-- 更新血量
|
|
if self.IsShowHealth and self.PlayerHeadState == EPlayerHeadInfoState.Alive then
|
|
self.ProgressBar_Health:SetPercent(UGCPawnAttrSystem.GetHealth(PlayerPawn)/ UGCPawnAttrSystem.GetHealthMax(PlayerPawn))
|
|
end
|
|
end
|
|
|
|
function WB_PlayerHead_48:UpdateWidgetState(InPlayerHeadState)
|
|
if self.PlayerHeadState ~= InPlayerHeadState then
|
|
self.PlayerHeadState = InPlayerHeadState
|
|
if self.PlayerHeadState == EPlayerHeadInfoState.Alive then
|
|
-- 存活
|
|
if self.IsShowHealth then
|
|
self.ProgressBar_Health:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
|
end
|
|
self.Overlay_KnockedDown:SetVisibility(ESlateVisibility.Collapsed)
|
|
self.Border_HeadMain:SetContentColorAndOpacity({R=1,G=1,B=1,A=1})
|
|
self.Overlay_Dead:SetVisibility(ESlateVisibility.Collapsed)
|
|
elseif self.PlayerHeadState == EPlayerHeadInfoState.Death then
|
|
-- 死亡
|
|
self.ProgressBar_Health:SetVisibility(ESlateVisibility.Collapsed)
|
|
self.Overlay_KnockedDown:SetVisibility(ESlateVisibility.Collapsed)
|
|
self.Border_HeadMain:SetContentColorAndOpacity({R=0.281250,G=0.281250,B=0.281250,A=1.000000})
|
|
self.Overlay_Dead:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
|
elseif self.PlayerHeadState == EPlayerHeadInfoState.KnockedDown then
|
|
-- 倒地
|
|
if self.IsShowHealth then
|
|
self.ProgressBar_Health:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
|
self.ProgressBar_Health:SetPercent(0)
|
|
end
|
|
self.Overlay_KnockedDown:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
|
self.Border_HeadMain:SetContentColorAndOpacity({R=1,G=1,B=1,A=1})
|
|
self.Overlay_Dead:SetVisibility(ESlateVisibility.Collapsed)
|
|
end
|
|
end
|
|
end
|
|
|
|
return WB_PlayerHead_48 |