147 lines
5.8 KiB
Lua
Raw Normal View History

2025-01-04 23:00:19 +08:00
---@class W_ShowTriggerDeviceInfo_3_C:ObjectPositionWidget
---@field Image_CT UImage
---@field Image_MechanismIcon UImage
---@field Image_Ring UImage
---@field Image_T UImage
---@field Overlay_CanActive UOverlay
---@field ProgressBar_ShowEnergy UProgressBar
---@field TextBlock_HealthValue UTextBlock
---@field TextBlock_Range UTextBlock
---@field WidgetSwitcher_Active UWidgetSwitcher
---@field WidgetSwitcher_ShowText UWidgetSwitcher
---@field WidgetSwitcher_TeamIcon UWidgetSwitcher
---@field FullEnergyColor FLinearColor
---@field CanActiveColor FLinearColor
---@field CanNotActiveColor FLinearColor
--Edit Below--
---@type W_ShowTriggerDeviceInfo_3_C
local W_ShowTriggerDeviceInfo_3 = {
bInitDoOnce = false;
MaxEnergy = 1.;
LimitEnergy = 0.;
LocalCanActive = false;
};
--[==[ Construct
function W_ShowTriggerDeviceInfo:Construct()
end
-- Construct ]==]
-- function W_ShowTriggerDeviceInfo:Tick(MyGeometry, InDeltaTime)
-- end
-- function W_ShowTriggerDeviceInfo:Destruct()
-- end
function W_ShowTriggerDeviceInfo_3:InitMechanismInfo(InMaxEnergy, InLimitEnergy, MechanismType)
self.MaxEnergy = InMaxEnergy
self.LimitEnergy = InLimitEnergy
--self.TextBlock_Limit:SetText(string.format("%.0f", InLimitEnergy))
--self.TextBlock_Max:SetText(string.format("%.0f", InMaxEnergy))
self.TextBlock_Range:SetText(string.format("[ %.0f, %.0f ]", InLimitEnergy, self.MaxEnergy))
--self.TextBlock_Name:SetText(tostring(MechanismName))
-- self.LoopSetCanActive = UGCEventSystem.SetTimerLoop(self, self.CheckCanActive, 0.2)
-- 设置两图标颜色
self.Image_CT:SetColorAndOpacity(TeamConfig.TeamColor[TeamConfig.TeamType.CT])
self.Image_T:SetColorAndOpacity(TeamConfig.TeamColor[TeamConfig.TeamType.T])
local IconInfo = MechanismConfig.MechanismIconInfo[MechanismType]
if IconInfo then
local IconTex = UGCSystemLibrary.LoadAsset(IconInfo.Icon, true)
if UE.IsValid(IconTex) then
self.Image_MechanismIcon:SetBrushFromTexture(IconTex)
self.Image_MechanismIcon:SetColorAndOpacity(IconInfo.Color)
end
end
--- 更新环状能量进度条信息
UGCEventSystem.SetTimer(self,
function()
if self.LoopUpdateRingHandle == nil then
self.LoopUpdateRingHandle = UGCEventSystem.SetTimerLoop(self, self.UpdateRingInfo, 1.)
end
end,
math.random()
)
end
function W_ShowTriggerDeviceInfo_3:UpdateRingInfo()
local LocalPawn = UGCSystemLibrary.GetLocalPlayerPawn()
if LocalPawn then
local MechanismEnergy = LocalPawn:GetMechanismEnergy()
local Material = self.Image_Ring:GetDynamicMaterial()
--UGCLogSystem.Log("[W_ShowTriggerDeviceInfo_3_UpdateRingInfo] 1")
if Material ~= nil then
local TargetPercent = math.clamp(MechanismEnergy / self.MaxEnergy, 0., 1.)
Material:SetScalarParameterValue("Mask_Percent", 1. - TargetPercent)
--UGCLogSystem.Log("[W_ShowTriggerDeviceInfo_3_UpdateRingInfo] 2 TargetPercent:%s", tostring(TargetPercent))
end
if MechanismEnergy >= self.MaxEnergy then
self.Image_Ring:SetColorAndOpacity(self.FullEnergyColor)
elseif MechanismEnergy >= self.LimitEnergy then
self.Image_Ring:SetColorAndOpacity(self.CanActiveColor)
else
self.Image_Ring:SetColorAndOpacity(self.CanNotActiveColor)
end
end
end
function W_ShowTriggerDeviceInfo_3:CanActive(bActive)
if self.LocalCanActive ~= bActive then
self.LocalCanActive = bActive
if bActive then
self.Overlay_CanActive:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
self.WidgetSwitcher_ShowText:SetActiveWidgetIndex(1)
else
self.Overlay_CanActive:SetVisibility(ESlateVisibility.Collapsed)
self.WidgetSwitcher_ShowText:SetActiveWidgetIndex(0)
end
end
end
function W_ShowTriggerDeviceInfo_3:Trigger(PlayerKey, InEnergy, InMaxEnergy)
self.MaxEnergy = InMaxEnergy
self:UpdateTriggeredPlayerInfo(PlayerKey)
self:UpdateEnergyInfo(InEnergy, self.MaxEnergy)
self.WidgetSwitcher_Active:SetActiveWidgetIndex(0)
UGCLogSystem.Log("[W_ShowTriggerDeviceInfo_3_Trigger]")
end
function W_ShowTriggerDeviceInfo_3:MechanismClosed()
self.WidgetSwitcher_Active:SetActiveWidgetIndex(1)
UGCLogSystem.Log("[W_ShowTriggerDeviceInfo_3_MechanismClosed]")
end
function W_ShowTriggerDeviceInfo_3:UpdateTriggeredPlayerInfo(PlayerKey)
if PlayerKey < 0 then
self.WidgetSwitcher_Active:SetActiveWidgetIndex(1)
return
end
local PlayerTeamID = UGCGameSystem.GameState:GetPlayerTeamIDByPlayerKey(PlayerKey)
local LocalPlayerTeamID = UGCGameSystem.GameState:GetPlayerTeamIDByPlayerKey(UGCSystemLibrary.GetLocalPlayerKey())
local ShowTeamType = PlayerTeamID == LocalPlayerTeamID and TeamConfig.TeamType.CT or TeamConfig.TeamType.T
local TeamColor = TeamConfig.TeamColor[ShowTeamType]
if TeamColor then
self.ProgressBar_ShowEnergy:SetFillColorAndOpacity(TeamColor)
UGCLogSystem.Log("[W_ShowTriggerDeviceInfo_3_UpdateTriggeredPlayerInfo] Succeed, PlayerKey:%s", tostring(PlayerKey))
-- 设置队伍图标
self.WidgetSwitcher_TeamIcon:SetActiveWidgetIndex(ShowTeamType - 1)
else
UGCLogSystem.LogError("[W_ShowTriggerDeviceInfo_3_UpdateTriggeredPlayerInfo] TeamConfig.TeamColor[%s] is nil, PlayerKey:%s", tostring(PlayerTeamID), tostring(PlayerKey))
end
self.WidgetSwitcher_Active:SetActiveWidgetIndex(0)
end
function W_ShowTriggerDeviceInfo_3:UpdateEnergyInfo(InEnergy, InMaxEnergy)
self.MaxEnergy = InMaxEnergy
self.ProgressBar_ShowEnergy:SetPercent(InEnergy / self.MaxEnergy)
self.TextBlock_HealthValue:SetText(string.format("%.0f / %.0f", InEnergy, InMaxEnergy))
end
return W_ShowTriggerDeviceInfo_3;