179 lines
5.7 KiB
Lua
179 lines
5.7 KiB
Lua
|
---@class WB_PlayerSoldier_Item_C:UUserWidget
|
||
|
---@field Image_PlayerIcon UImage
|
||
|
---@field Image_Ring UImage
|
||
|
---@field Image_SoldierIcon UImage
|
||
|
---@field Overlay_Skill UOverlay
|
||
|
---@field ProgressBar_Health UProgressBar
|
||
|
---@field TextBlock_CoolingTime UTextBlock
|
||
|
---@field TextBlock_Kill UTextBlock
|
||
|
---@field TextBlock_PlayerName UTextBlock
|
||
|
---@field TextBlock_SoldierType UTextBlock
|
||
|
---@field WidgetSwitcher_IsSelf UWidgetSwitcher
|
||
|
---@field WidgetSwitcher_SkillIsReady UWidgetSwitcher
|
||
|
--Edit Below--
|
||
|
---@type WB_PlayerSoldier_Item_C
|
||
|
local WB_PlayerSoldier_Item = {};
|
||
|
|
||
|
WB_PlayerSoldier_Item.bInitDoOnce = false;
|
||
|
WB_PlayerSoldier_Item.PlayerKey = 0;
|
||
|
WB_PlayerSoldier_Item.Material = nil;
|
||
|
WB_PlayerSoldier_Item.Colors = {
|
||
|
[0] = { 0.065244, 0.178721, 0.604167, },
|
||
|
[1] = { 0.604167, 0.190859, 0, }
|
||
|
};
|
||
|
WB_PlayerSoldier_Item.CoolColors = {
|
||
|
[1] = { 1, 0.151042, 0.151042, },
|
||
|
[2] = { 0, 1, 0.000386 },
|
||
|
}
|
||
|
|
||
|
function WB_PlayerSoldier_Item:Construct()
|
||
|
self:LuaInit();
|
||
|
end
|
||
|
|
||
|
function WB_PlayerSoldier_Item:LuaInit()
|
||
|
if self.bInitDoOnce then return ; end
|
||
|
|
||
|
self:SetBuffNone();
|
||
|
if self.PlayerKey then
|
||
|
self:SetPlayerKey(self.PlayerKey);
|
||
|
end
|
||
|
|
||
|
self.TextBlock_Kill:SetText(0);
|
||
|
|
||
|
self.bInitDoOnce = true;
|
||
|
end
|
||
|
|
||
|
-- 设置玩家
|
||
|
function WB_PlayerSoldier_Item:SetPlayerKey(InPlayerKey)
|
||
|
if InPlayerKey == nil or InPlayerKey == 0 then return; end
|
||
|
self.PlayerKey = InPlayerKey;
|
||
|
if self.TextBlock_PlayerName then
|
||
|
self.TextBlock_PlayerName:SetText(UE.GetPlayerName(InPlayerKey));
|
||
|
end
|
||
|
-- 先将兵种设置为空
|
||
|
if self.WidgetSwitcher_IsSelf then
|
||
|
self.WidgetSwitcher_IsSelf:SetActiveWidgetIndex(InPlayerKey == LocalPlayerKey and 1 or 0);
|
||
|
end
|
||
|
|
||
|
if self.Image_PlayerIcon then
|
||
|
UITool.DownloadImage(UE.GetPlayerIconURL(InPlayerKey), function(TargetObj)
|
||
|
self.Image_PlayerIcon:SetBrushFromTextureDynamic(TargetObj);
|
||
|
end);
|
||
|
end
|
||
|
|
||
|
if self.ProgressBar_Health then
|
||
|
self.ProgressBar_Health:SetFillColorAndOpacity(VectorHelper.ArrToColor(self.Colors[InPlayerKey == LocalPlayerKey and 1 or 0]));
|
||
|
UITool.TextBlockBindingProperty(self.ProgressBar_Health, "Percent", self.UpdatePlayerHealth, self)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function WB_PlayerSoldier_Item:UpdatePlayerHealth()
|
||
|
local TargetPawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.PlayerKey)
|
||
|
if TargetPawn then
|
||
|
return UGCPawnAttrSystem.GetHealth(TargetPawn) / UGCPawnAttrSystem.GetHealthMax(TargetPawn)
|
||
|
end
|
||
|
return 0.
|
||
|
end
|
||
|
|
||
|
-- 设置兵种类型
|
||
|
function WB_PlayerSoldier_Item:SetSoldierType(InType)
|
||
|
if InType == nil then return; end
|
||
|
local SoldierName = SoldierConfig[InType].Info.Name;
|
||
|
UGCLogSystem.Log('[WB_PlayerSoldier_Item:SetSoldierType] %s', SoldierName);
|
||
|
self.TextBlock_SoldierType:SetText(SoldierName);
|
||
|
end
|
||
|
|
||
|
function WB_PlayerSoldier_Item:GetPlayerKey()
|
||
|
return self.PlayerKey;
|
||
|
end
|
||
|
|
||
|
WB_PlayerSoldier_Item.Cooldown = 0;
|
||
|
WB_PlayerSoldier_Item.Continue = 0;
|
||
|
WB_PlayerSoldier_Item.CooldownStartTime = 0;
|
||
|
WB_PlayerSoldier_Item.EndTime = 0;
|
||
|
|
||
|
function WB_PlayerSoldier_Item:SetBuffUse(Success, ExecTime)
|
||
|
if Success == false then return ; end
|
||
|
local SoldierType = GlobalMiniMode.PlayerSelectSoldiers[self.PlayerKey];
|
||
|
if SoldierType == nil then return ; end
|
||
|
local Buff = SoldierConfig[SoldierType].Buff;
|
||
|
if Buff == nil then return ; end
|
||
|
local BuffType = EBuffType[Buff.Name]
|
||
|
if BuffType == nil then return ; end
|
||
|
self.Cooldown = BuffConfig[BuffType].Cooldown
|
||
|
self.Continue = BuffConfig[BuffType].Continue;
|
||
|
self.CooldownStartTime = ExecTime + (self.Continue or 0);
|
||
|
self.EndTime = self.CooldownStartTime + (self.Cooldown or 0);
|
||
|
|
||
|
if self.Continue ~= nil and self.Continue > 0 then
|
||
|
self:SetBuffUsing();
|
||
|
else
|
||
|
self:SetBuffCooling();
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function WB_PlayerSoldier_Item:SetBuffUsing()
|
||
|
-- 显示出来
|
||
|
self.Overlay_Skill:SetVisibility(ESlateVisibility.HitTestInvisible);
|
||
|
self.TextBlock_CoolingTime:SetText(string.format('%0.f', self.Continue));
|
||
|
self.TextBlock_CoolingTime:SetColorAndOpacity(UITool.MakeSlateColor(self.CoolColors[2]));
|
||
|
|
||
|
GlobalTickTool:AddTick(self, function(o, dt, st)
|
||
|
local Percent = (o.CooldownStartTime - st) / o.Continue
|
||
|
self:GetMaterial():SetScalarParameterValue("Mask_Percent", 1. - Percent);
|
||
|
if o.CooldownStartTime - st > 1 then
|
||
|
self.TextBlock_CoolingTime:SetText(math.ceil(o.CooldownStartTime - st));
|
||
|
else
|
||
|
self.TextBlock_CoolingTime:SetText(string.format('%0.1f', o.CooldownStartTime - st));
|
||
|
end
|
||
|
end, nil, nil, self.CooldownStartTime - UE.GetServerTime(), function(o)
|
||
|
o:SetBuffCooling();
|
||
|
end)
|
||
|
end
|
||
|
|
||
|
function WB_PlayerSoldier_Item:SetBuffCooling()
|
||
|
if self.Cooldown == nil or self.Cooldown == 0 then
|
||
|
self:SetBuffNone();
|
||
|
return ;
|
||
|
end
|
||
|
self.TextBlock_CoolingTime:SetText(string.format('%0.f', self.Cooldown));
|
||
|
self.TextBlock_CoolingTime:SetColorAndOpacity(UITool.MakeSlateColor(self.CoolColors[1]));
|
||
|
GlobalTickTool:AddTick(self, function(o, dt, st)
|
||
|
local Percent = (o.EndTime - st) / o.Continue
|
||
|
o:GetMaterial():SetScalarParameterValue("Mask_Percent", 1. - Percent);
|
||
|
if o.EndTime - st > 1 then
|
||
|
self.TextBlock_CoolingTime:SetText(math.ceil(o.EndTime - st));
|
||
|
else
|
||
|
self.TextBlock_CoolingTime:SetText(string.format('%0.1f', o.EndTime - st));
|
||
|
end
|
||
|
end, nil, nil, self.EndTime - UE.GetServerTime(), function(o)
|
||
|
self:SetBuffNone();
|
||
|
end)
|
||
|
end
|
||
|
|
||
|
function WB_PlayerSoldier_Item:SetBuffNone()
|
||
|
self.Overlay_Skill:SetVisibility(ESlateVisibility.Collapsed);
|
||
|
end
|
||
|
|
||
|
function WB_PlayerSoldier_Item:GetMaterial()
|
||
|
if self.Material == nil then
|
||
|
self.Material = self.Image_Ring:GetDynamicMaterial();
|
||
|
end
|
||
|
return self.Material;
|
||
|
end
|
||
|
|
||
|
function WB_PlayerSoldier_Item:SetKillNum(InNum)
|
||
|
if self.TextBlock_Kill then
|
||
|
self.TextBlock_Kill:SetText(InNum);
|
||
|
end
|
||
|
end
|
||
|
|
||
|
-- function WB_PlayerSoldier_Item:Tick(MyGeometry, InDeltaTime)
|
||
|
|
||
|
-- end
|
||
|
|
||
|
-- function WB_PlayerSoldier_Item:Destruct()
|
||
|
|
||
|
-- end
|
||
|
|
||
|
return WB_PlayerSoldier_Item;
|