UGCProjects/ProjectTemp_T/Script/UI/ChildWidget/WB_PlayerSoldier_Item.lua

207 lines
6.9 KiB
Lua
Raw Permalink Normal View History

2025-01-04 23:00:19 +08:00
---@class WB_PlayerSoldier_Item_C:UUserWidget
---@field Image_BG UImage
---@field Image_PlayerIcon UImage
---@field Image_Ring UImage
---@field Image_Self UImage
---@field Image_SoldierIcon UImage
---@field Overlay_Skill UOverlay
---@field ProgressBar_Health UProgressBar
---@field TextBlock_CoolingTime UTextBlock
---@field TextBlock_PlayerName UTextBlock
---@field TextBlock_SoldierType UTextBlock
---@field TextBlock_UsageTime UTextBlock
---@field WidgetSwitcher_SkillIsReady UWidgetSwitcher
--Edit Below--
---@type WB_PlayerSoldier_Item_C
local WB_PlayerSoldier_Item = {
bInitDoOnce = false;
TeamColorV = 0.3;
};
WB_PlayerSoldier_Item.OwnerPlayerKey = 0;
function WB_PlayerSoldier_Item:Construct()
UGCEventSystem.AddListener(EventTypes.UpdatePlayerAccountInfo, self.OnUpdatePlayerAccountInfo, self)
self.Overlay_Skill:SetVisibility(ESlateVisibility.Hidden);
end
-- function WB_PlayerSoldier_Item:Tick(MyGeometry, InDeltaTime)
-- end
-- function WB_PlayerSoldier_Item:Destruct()
-- end
-- 设置玩家
function WB_PlayerSoldier_Item:SetPlayerKey(InPlayerKey)
UGCSystemLibrary.DownloadImageToUImage(self.Image_PlayerIcon, UGCGameSystem.GameState:GetHeadIconByPlayerKey(InPlayerKey));
self.OwnerPlayerKey = InPlayerKey;
self.TextBlock_PlayerName:SetText(UGCGameSystem.GameState:GetPlayerNameByPlayerKey(InPlayerKey));
-- 先将兵种设置为空
self.TextBlock_SoldierType:SetText("");
if InPlayerKey == LocalPlayerKey then
self.Image_Self:SetVisibility(ESlateVisibility.Visible);
end
UITool.TextBlockBindingProperty(self.ProgressBar_Health, "Percent", self.UpdatePlayerHealth, self)
local TeamColor = table.DeepCopy(TeamConfig.TeamColor[DefaultSettings.LocalTeamId])
if TeamColor then
TeamColor.R = TeamColor.R * self.TeamColorV
TeamColor.G = TeamColor.G * self.TeamColorV
TeamColor.B = TeamColor.B * self.TeamColorV
-- self.ProgressBar_Health:SetFillColorAndOpacity(TeamColor)
end
end
---@param InInfo table<PlayerKey, PlayerAccountInfo>
function WB_PlayerSoldier_Item:OnUpdatePlayerAccountInfo(InInfo)
local Info = InInfo[self.OwnerPlayerKey];
if Info == nil then
return;
end
if self.OwnerPlayerKey ~= 0 then
self:SetPlayerKey(self.OwnerPlayerKey);
end
end
function WB_PlayerSoldier_Item:UpdatePlayerHealth()
local TargetPawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.OwnerPlayerKey)
if TargetPawn then
return UGCPawnAttrSystem.GetHealth(TargetPawn) / UGCPawnAttrSystem.GetHealthMax(TargetPawn)
end
return 0.
end
-- 设置兵种类型
function WB_PlayerSoldier_Item:SetSoldierType(InType)
print(string.format('[WB_PlayerSoldier_Item:SetSoldierType] %s', SoldierConfig.Chinese[InType]))
self.TextBlock_SoldierType:SetText(SoldierConfig.Chinese[InType]);
-- 设置兵种Icon
-- self:Image_SoldierIcon:SetBrushFromTexture()
end
function WB_PlayerSoldier_Item:GetPlayerKey()
return self.OwnerPlayerKey;
end
function WB_PlayerSoldier_Item:HideCooldown()
self.Overlay_Skill:SetVisibility(ESlateVisibility.Collapsed);
end
function WB_PlayerSoldier_Item:Reset()
self:HideCooldown();
end
-----------------------------------------------------------------------------------------------------------
--- 更新冷却的剩余时间
---@param CoolingTime float 冷却时间
---@param TimeRemaining float 剩余时间
function WB_PlayerSoldier_Item:UpdateCoolingTime(CoolingTime, TimeRemaining)
--self:SetIsCooling(TimeRemaining > 0)
local Material = self.Image_Ring:GetDynamicMaterial()
if Material ~= nil then
Material:SetScalarParameterValue("Mask_Percent", 1. - TimeRemaining / CoolingTime);
end
self.TextBlock_CoolingTime:SetText(string.format("%.0f", TimeRemaining))
end
WB_PlayerSoldier_Item.ContinueTime = 0.;
WB_PlayerSoldier_Item.ConstContinueTime = 0.;
function WB_PlayerSoldier_Item:TriggerSoldierType()
local SoldierType = UGCGameSystem.GameState:GetSoldierTypeByPlayerKey(self.OwnerPlayerKey);
if SoldierType == nil then return; end
-- 检查是否正在执行中,如果正在执行中,则取消
if self.ContinueTimer ~= nil then
UGCEventSystem.StopTimer(self.ContinueTimer);
self.ContinueTime = 0;
self.ConstContinueTime = 0;
end
if self.Cooldownr ~= nil then
UGCEventSystem.StopTimer(self.Cooldownr);
self.Cooldown = 0;
self.ConstCooldown = 0;
end
local Skills = SoldierConfig.Skills[SoldierType];
-- 说明当前不存在技能
if table.isEmpty(Skills) or Skills.SkillType ~= SoldierConfig.ESkillType.Active then return; end
local Skill = Skills.Skills[1];
if table.isEmpty(Skill) then return; end
-- 否则就添加进来
self.Overlay_Skill:SetVisibility(ESlateVisibility.Visible);
-- 检查是否存在冷却时间
if Skill.ContinueTime == nil then
self.TextBlock_UsageTime:SetVisibility(ESlateVisibility.Hidden);
else
self.TextBlock_UsageTime:SetVisibility(ESlateVisibility.SelfHitTestInvisible);
self.TextBlock_CoolingTime:SetVisibility(ESlateVisibility.Collapsed);
self.ContinueTime = Skill.ContinueTime + 0.;
self.ConstContinueTime = self.ContinueTime;
self.ContinueTimer = UGCEventSystem.SetTimerLoop(self, function()
self.ContinueTime = self.ContinueTime - .5;
self.TextBlock_UsageTime:SetText(tostring(math.floor(self.ContinueTime)));
if self.ContinueTime <= 0 then
if self.ContinueTimer ~= nil then
self.TextBlock_UsageTime:SetVisibility(ESlateVisibility.Collapsed);
self.TextBlock_CoolingTime:SetVisibility(ESlateVisibility.SelfHitTestInvisible);
UGCEventSystem.StopTimer(self.ContinueTimer);
end
end
end, .5)
end
if Skill.Cooldown == nil then
self.TextBlock_CoolingTime:SetVisibility(ESlateVisibility.Collapsed);
else
local SkillContinueTime = Skill.ContinueTime
if SkillContinueTime == nil then
SkillContinueTime = 0;
end
self.Cooldown = Skill.Cooldown + SkillContinueTime;
self.ConstCooldown = self.Cooldown;
self.Cooldownr = UGCEventSystem.SetTimerLoop(self, function()
self.Cooldown = self.Cooldown - 0.5;
self:UpdateCoolingTime(self.ConstCooldown, self.Cooldown);
if self.Cooldown <= 0 then
if self.Cooldownr ~= nil then
self.Overlay_Skill:SetVisibility(ESlateVisibility.Collapsed);
UGCEventSystem.StopTimer(self.Cooldownr);
end
end
end, .5);
end
end
--- 设置技能是否正在冷却
---@param InbIsCooling bool
function WB_PlayerSoldier_Item:SetIsCooling(InbIsCooling)
if self.bIsCooling ~= InbIsCooling then
self.bIsCooling = InbIsCooling
if self.bIsCooling then
self.WidgetSwitcher_SkillIsReady:SetActiveWidgetIndex(0)
self.TextBlock_CoolingTime:SetVisibility(ESlateVisibility.Visible)
self.TextBlock_UsageTime:SetVisibility(ESlateVisibility.Collapsed)
else
self.WidgetSwitcher_SkillIsReady:SetActiveWidgetIndex(1)
self.TextBlock_CoolingTime:SetVisibility(ESlateVisibility.Collapsed)
end
end
end
--- 设置正在使用时剩余的时间
---@param UsageTime float
function WB_PlayerSoldier_Item:SetUsageTime(UsageTime)
if UsageTime > 0 then
self.TextBlock_UsageTime:SetVisibility(ESlateVisibility.Visible)
self.TextBlock_UsageTime:SetText(string.format("%.0f", UsageTime))
end
end
return WB_PlayerSoldier_Item;