---@class WB_TeamIcon_C:UUserWidget ---@field Image_Hold UImage ---@field TextBlock_Dis UTextBlock ---@field WidgetSwitcher_Team UWidgetSwitcher --Edit Below-- ---@type WB_TeamIcon_C local WB_TeamIcon = { bInitDoOnce = false } function WB_TeamIcon:Construct() self:LuaInit(); end function WB_TeamIcon:LuaInit() if self.bInitDoOnce then return; end UGCEventSystem.AddListener(EventTypes.PlayerDead, self.OnPlayerDead, self); UGCEventSystem.AddListener(EventTypes.PlayerRespawn, self.OnPlayerRespawn, self); self.bInitDoOnce = true; end function WB_TeamIcon:Tick(MyGeometry, InDeltaTime) end -- function WB_TeamIcon:Destruct() -- end WB_TeamIcon.Owner = nil; WB_TeamIcon.OwnerComponent = nil; function WB_TeamIcon:SetOwnerHold(InActor, InComponent) self.Owner = InActor; self.OwnerComponent = InComponent; end function WB_TeamIcon:SetTeamId(InTeamId) if InTeamId == 0 then self.WidgetSwitcher_Team:SetVisibility(ESlateVisibility.Collapsed); else self.WidgetSwitcher_Team:SetVisibility(ESlateVisibility.HitTestInvisible); self.WidgetSwitcher_Team:SetActiveWidgetIndex(InTeamId - 1); end end function WB_TeamIcon:GetCanvasSlot() return WidgetLayoutLibrary.SlotAsCanvasSlot(self.WidgetSwitcher_Team); end WB_TeamIcon.Material = nil; function WB_TeamIcon:GetMaterial() if self.Material == nil then self.Material = self.Image_Hold:GetDynamicMaterial() end return self.Material; end WB_TeamIcon.TotalHoldTime = 0; function WB_TeamIcon:SetHoldTime(Curr, Total) if self.TotalHoldTime == 0 then self.TotalHoldTime = Total; end local Percent = Curr / Total; self:GetMaterial():SetScalarParameterValue("Mask_Percent", 1 - Percent); if Curr == 0 then self.WidgetSwitcher_Team:SetVisibility(ESlateVisibility.Collapsed); else self.WidgetSwitcher_Team:SetVisibility(ESlateVisibility.HitTestInvisible); self.WidgetSwitcher_Team:SetActiveWidgetIndex(Curr < 0 and 1 or 0); for TeamId, Symbol in pairs(TeamScoreSymbol) do if Curr / Symbol > 0 then -- 说明是自己 self.Image_Hold:SetColorAndOpacity(VectorHelper.ArrToColor(TeamColor[TeamId])); break ; end end end end function WB_TeamIcon:OnTick0_1(dt, st) self:SetLocalPawnDis(); end WB_TeamIcon.CachedDistance = 0; function WB_TeamIcon:SetLocalPawnDis() if LocalPlayerKey == nil then return; end local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(LocalPlayerKey); if UE.IsValidPawn(Pawn) and self.Owner then local Dis = math.ceil(VectorHelper.GetActorDis2D(Pawn, self.Owner) / 100); if Dis ~= self.CachedDistance then self.CachedDistance = Dis; self.TextBlock_Dis:SetText(tostring(self.CachedDistance) .. 'm'); self.OwnerComponent:RequestRedraw(); end end end -- 死亡之后隐藏一下 function WB_TeamIcon:SetImageSize() -- 设置大小 local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(LocalPlayerKey); if UE.IsValidPawn(Pawn) then local CanvasSlot = self:GetCanvasSlot(); -- 这是距离 local Max, Min = 200, 40; local Dis = VectorHelper.GetActorDis2D(Pawn, self.Owner) / 100; local Size = 0; if Dis > 200 then Size = Max; elseif Dis > 20 then Size = 1960 / 9 - Dis * 8 / 9; else Size = 40; end CanvasSlot:SetSize({ X = Size, Y = Size, }); else self:SetVisibility(ESlateVisibility.Collapsed); end end return WB_TeamIcon