190 lines
5.5 KiB
Lua
190 lines
5.5 KiB
Lua
|
---@class WB_BuffButton_C:UUserWidget
|
||
|
---@field Image_CD UImage
|
||
|
---@field Image_Icon UImage
|
||
|
---@field NewButton_Main UNewButton
|
||
|
---@field TextBlock_CD UTextBlock
|
||
|
--Edit Below--
|
||
|
---@type WB_BuffButton_C
|
||
|
local WB_BuffButton = { bInitDoOnce = false; };
|
||
|
|
||
|
WB_BuffButton.CanClick = true;
|
||
|
WB_BuffButton.CDMaterial = nil;
|
||
|
|
||
|
local BuffStateType = {
|
||
|
None = 1,
|
||
|
Continue = 2,
|
||
|
Cooldown = 3,
|
||
|
}
|
||
|
|
||
|
function WB_BuffButton:Construct()
|
||
|
self:LuaInit();
|
||
|
end
|
||
|
|
||
|
function WB_BuffButton:LuaInit()
|
||
|
if self.bInitDoOnce then return ; end
|
||
|
UITool.BindButtonClicked(self.NewButton_Main, self.OnClickBuff, self);
|
||
|
UITool.EnableButtonScroll(self.NewButton_Main);
|
||
|
UGCEventSystem.AddListener(EventTypes.PlayerUseBuff, self.OnPlayerUseBuff, self)
|
||
|
self:GetDynamicMaterial();
|
||
|
self:ChangeStateColor(BuffStateType.None);
|
||
|
|
||
|
self.bInitDoOnce = true;
|
||
|
end
|
||
|
|
||
|
function WB_BuffButton:OnShowPanel(...)
|
||
|
local vars = { ... };
|
||
|
local BuffType = vars[1]
|
||
|
end
|
||
|
|
||
|
function WB_BuffButton:SetBuffType(InType)
|
||
|
if self.BuffType == InType then return false; end
|
||
|
self.BuffType = InType;
|
||
|
|
||
|
assert(InType ~= nil);
|
||
|
-- 设置数据
|
||
|
self.Cooldown = BuffConfig[InType].Cooldown;
|
||
|
self.Continue = BuffConfig[InType].Continue;
|
||
|
|
||
|
UE.AsyncLoadObject_Cached(BuffConfig[InType].ClientInfo.Icon, function(TargetObject)
|
||
|
self.Image_Icon:SetBrushFromTexture(TargetObject);
|
||
|
local Color = ELogColor[BuffConfig[InType].ClientInfo.Color];
|
||
|
self.Image_Icon:SetColorAndOpacity(VectorHelper.ArrToColor(LogColorConfig[Color]));
|
||
|
end)
|
||
|
|
||
|
return true;
|
||
|
end
|
||
|
|
||
|
function WB_BuffButton:SetBuffName(InName)
|
||
|
UGCLogSystem.Log("[WB_BuffButton:SetBuffType] Buff = %s", InName);
|
||
|
self:SetBuffType(FindBuffByName(InName));
|
||
|
end
|
||
|
|
||
|
function WB_BuffButton:GetBuffType() return self.BuffType; end
|
||
|
|
||
|
function WB_BuffButton:OnClickBuff()
|
||
|
-- 发送 RPC
|
||
|
if self.CanClick then
|
||
|
UnrealNetwork.CallUnrealRPC(LocalPlayerController, LocalPlayerController, "UseBuff", self:GetBuffType());
|
||
|
self.CanClick = false;
|
||
|
end
|
||
|
end
|
||
|
|
||
|
WB_BuffButton.BuffStateInfo = {
|
||
|
[BuffStateType.None] = {
|
||
|
IconColor = { 1, 1, 1, 1 },
|
||
|
TextColor = { 1, 1, 1, 0 },
|
||
|
CDColor = { 1, 1, 1, 0 }
|
||
|
},
|
||
|
[BuffStateType.Continue] = {
|
||
|
IconColor = { 0.302083, 0.302083, 0.302083, 0.609 },
|
||
|
TextColor = { 0, 1., 0.284620, 1 },
|
||
|
CDColor = { 0, 0.385049, 0.645833, 0.495 }
|
||
|
},
|
||
|
[BuffStateType.Cooldown] = {
|
||
|
IconColor = { 0.088542, 0.088542, 0.088542, 1 },
|
||
|
TextColor = { 1, 0, 0, 1 },
|
||
|
CDColor = { 0.020833, 0.020833, 0.020833, 0.75 }
|
||
|
},
|
||
|
};
|
||
|
|
||
|
function WB_BuffButton:ChangeStateColor(State)
|
||
|
self.Image_Icon:SetColorAndOpacity(VectorHelper.ArrToColor(self.BuffStateInfo[State].IconColor));
|
||
|
self.TextBlock_CD:SetColorAndOpacity({ SpecifiedColor = VectorHelper.ArrToColor(self.BuffStateInfo[State].TextColor), ColorUseRule = 0 });
|
||
|
self.Image_CD:SetColorAndOpacity(VectorHelper.ArrToColor(self.BuffStateInfo[State].CDColor));
|
||
|
end
|
||
|
|
||
|
function WB_BuffButton:OnPlayerUseBuff(InPlayerKey, IsSuccess, UseTime)
|
||
|
if InPlayerKey ~= LocalPlayerKey then return; end
|
||
|
if IsSuccess then
|
||
|
self:SetEnableClick(false);
|
||
|
-- 检测当前是否有冷却时间
|
||
|
self.CanClick = false;
|
||
|
if self.Continue == 0 or self.Continue == nil then
|
||
|
-- 设置为冷却
|
||
|
self.StartCooldownTime = UE.GetServerTime();
|
||
|
self:GotoCooldown(UseTime);
|
||
|
return ;
|
||
|
end
|
||
|
self:GotoContinue(UseTime);
|
||
|
else
|
||
|
self.CanClick = true;
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function WB_BuffButton:GotoContinue(InTime)
|
||
|
self.StartCooldownTime = InTime + self.Continue;
|
||
|
-- 设置为这个颜色
|
||
|
UGCLogSystem.Log("[WB_BuffButton:GotoContinue] self.StartCooldownTime = %s", tostring(self.StartCooldownTime));
|
||
|
self:SetEnableClick(false);
|
||
|
self:ChangeStateColor(BuffStateType.Continue);
|
||
|
GlobalTickTool:AddTick(self, function(o, dt, st)
|
||
|
local Time = o.StartCooldownTime - UE.GetServerTime();
|
||
|
local Percent = Time / o.Continue;
|
||
|
o:GetDynamicMaterial():SetScalarParameterValue("Mask_Percent", Percent);
|
||
|
if Time > 1 then
|
||
|
Time = math.ceil(Time);
|
||
|
o.TextBlock_CD:SetText(tostring(Time));
|
||
|
elseif Time > 0 then
|
||
|
o.TextBlock_CD:SetText(string.format('%0.1f', Time));
|
||
|
end
|
||
|
end, 0, nil, self.StartCooldownTime - UE.GetServerTime(), function(o)
|
||
|
o:GotoCooldown(o.StartCooldownTime);
|
||
|
end);
|
||
|
end
|
||
|
|
||
|
function WB_BuffButton:GotoCooldown(InTime)
|
||
|
if self.Cooldown == nil or self.Cooldown == 0 then
|
||
|
-- 当前没问题,继续执行即可
|
||
|
self:GotoNone();
|
||
|
return ;
|
||
|
end
|
||
|
self.StartNoneTime = InTime + self.Cooldown;
|
||
|
self:SetEnableClick(false);
|
||
|
self:ChangeStateColor(BuffStateType.Cooldown);
|
||
|
GlobalTickTool:AddTick(self, function(o, dt, st)
|
||
|
local Time = o.StartNoneTime - UE.GetServerTime();
|
||
|
local Percent = Time / o.Cooldown;
|
||
|
o:GetDynamicMaterial():SetScalarParameterValue("Mask_Percent", Percent);
|
||
|
if Time > 1 then
|
||
|
Time = math.ceil(Time);
|
||
|
o.TextBlock_CD:SetText(tostring(Time));
|
||
|
elseif Time > 0 then
|
||
|
o.TextBlock_CD:SetText(string.format('%0.1f', Time));
|
||
|
end
|
||
|
end, 0, nil, self.StartNoneTime - UE.GetServerTime(), function(o)
|
||
|
o:GotoNone();
|
||
|
end);
|
||
|
end
|
||
|
|
||
|
function WB_BuffButton:GotoNone()
|
||
|
self:SetEnableClick(true);
|
||
|
self:ChangeStateColor(BuffStateType.None);
|
||
|
end
|
||
|
|
||
|
function WB_BuffButton:SetEnableClick(IsEnable)
|
||
|
--self.NewButton_Main:SetIsEnabled(IsEnable);
|
||
|
self.CanClick = IsEnable;
|
||
|
end
|
||
|
|
||
|
function WB_BuffButton:GetDynamicMaterial()
|
||
|
if self.CDMaterial == nil then
|
||
|
self.CDMaterial = self.Image_CD:GetDynamicMaterial();
|
||
|
end
|
||
|
return self.CDMaterial;
|
||
|
end
|
||
|
|
||
|
function WB_BuffButton:SetBuffNone(BuffType)
|
||
|
UGCLogSystem.Log("[WB_BuffButton:SetBuffNone] 执行")
|
||
|
-- 设置成正常状态
|
||
|
self.CanClick = true;
|
||
|
end
|
||
|
|
||
|
-- function WB_BuffButton:Tick(MyGeometry, InDeltaTime)
|
||
|
|
||
|
-- end
|
||
|
|
||
|
-- function WB_BuffButton:Destruct()
|
||
|
|
||
|
-- end
|
||
|
|
||
|
return WB_BuffButton;
|