UGCProjects/TrainingCamp/Script/UI/Tool/WB_PlayerAttribute.lua
2025-01-04 23:00:19 +08:00

73 lines
2.5 KiB
Lua

---@class WB_PlayerAttribute_C:UAEUserWidget
---@field ShowAttr UWidgetAnimation
---@field VerticalBox_Attrs UVerticalBox
--Edit Below--
---@type WB_PlayerAttribute_C
local WB_PlayerAttribute = { bInitDoOnce = false; };
---@type table<string, WB_AttributeItem_C>
WB_PlayerAttribute.AllItems = {};
WB_PlayerAttribute.bShowAttr = false;
WB_PlayerAttribute.ShowHealth = false;
function WB_PlayerAttribute:Construct()
self:LuaInit();
end
function WB_PlayerAttribute:LuaInit()
if self.bInitDoOnce then return end
-- 进行初始化
local Count = self.VerticalBox_Attrs:GetChildrenCount();
UITool.AdaptChildren(self.VerticalBox_Attrs, table.getCount(DefaultSettings.BenefitInto) + (self.ShowHealth and 1 or 0) - 1, ObjectPath.WB_AttributeItem)
for i, v in pairs(DefaultSettings.BenefitInto) do
local Item = self.VerticalBox_Attrs:GetChildAt(i - 1);
Item:SetText(v.Chinese);
self.AllItems[i] = Item;
Item:SetValue(1);
end
self.AllItems[DefaultSettings.EPawnBenefitType.Shield]:SetValue(0);
if self.ShowHealth then
local Item = self.VerticalBox_Attrs:GetChildAt(self.VerticalBox_Attrs:GetChildrenCount() - 1)
Item:SetText("生命值");
self.AllItems[#self.AllItems + 1] = Item;
end
UGCLogSystem.LogTree(string.format("[WB_PlayerAttribute:Construct] self.AllItems ="), self.AllItems)
---self:PlayAnimation(self.ShowTip, 0, 1, EUMGSequencePlayMode.Forward, 1.0)
--self:PlayAnimation(self.ShowAttr, 0, 1, EUMGSequencePlayMode.Reverse, 1)
--self.Button_Attr.OnClicked:Add(self.OnClickAttr, self)
--UGCEventSystem.AddListener(EventTypes.PlayerAttributeChanged, self.OnAttributeChanged, self)
self.bInitDoOnce = true;
end
function WB_PlayerAttribute:OnClickAttr()
local Mode = EUMGSequencePlayMode.Forward;
if self.bShowAttr then
Mode = EUMGSequencePlayMode.Reverse;
end
self:PlayAnimation(self.ShowAttr, 0, 1, Mode, 1)
self.bShowAttr = not self.bShowAttr;
end
---@param InVal table<PlayerKey, PlayerAttributeItem_BigFight>
function WB_PlayerAttribute:OnAttributeChanged(InVal)
UGCLogSystem.LogTree(string.format("[WB_PlayerAttribute:OnAttributeChanged] Table ="), InVal)
for i, v in pairs(InVal) do
local Item = self.AllItems[i]
if Item then Item:SetValue(v); end
end
local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(LocalPlayerController.PlayerKey);
self.AllItems[#self.AllItems]:SetValue(UGCPawnAttrSystem.GetHealth(Pawn));
end
-- function WB_PlayerAttribute:Tick(MyGeometry, InDeltaTime)
-- end
-- function WB_PlayerAttribute:Destruct()
-- end
return WB_PlayerAttribute;