UGCProjects/GZJ/Script/UI/WBP_AttributePanel.lua

132 lines
5.2 KiB
Lua
Raw Normal View History

2025-01-08 22:46:12 +08:00
---@class WBP_AttributePanel_C:UUserWidget
---@field NewButton_Toggle UNewButton
---@field Panel_AdvanceAttributes UCanvasPanel
---@field Panel_BaseAttributes UCanvasPanel
---@field Panel_BG UWBP_WidgetHeader_C
---@field Panel_BonusAttributes UCanvasPanel
---@field Panel_EconomyAttributes UCanvasPanel
---@field Panel_GrowthAttributes UCanvasPanel
---@field Panel_Main UCanvasPanel
---@field TextBlock_Adv_AdditionalAttack UTextBlock
---@field TextBlock_Adv_CriticalAttack UTextBlock
---@field TextBlock_Adv_CriticalAttackRate UTextBlock
---@field TextBlock_Adv_DefencePenetration UTextBlock
---@field TextBlock_Adv_DefencePenetrationPercent UTextBlock
---@field TextBlock_Adv_FinalAttack UTextBlock
---@field TextBlock_Adv_FireAttack UTextBlock
---@field TextBlock_Base_Attack UTextBlock
---@field TextBlock_Base_AttackIntervalReduction UTextBlock
---@field TextBlock_Base_AttackRange UTextBlock
---@field TextBlock_Base_AttackSpeed UTextBlock
---@field TextBlock_Base_DamageReduction UTextBlock
---@field TextBlock_Base_Defence UTextBlock
---@field TextBlock_Base_EvadeRate UTextBlock
---@field TextBlock_Base_MaxEnergy UTextBlock
---@field TextBlock_Base_MaxHP UTextBlock
---@field TextBlock_Base_RecoverEnergy UTextBlock
---@field TextBlock_Base_RecoverEnergyPercent UTextBlock
---@field TextBlock_Base_RecoverHP UTextBlock
---@field TextBlock_Base_RecoverHPPercent UTextBlock
---@field TextBlock_Base_Toughness UTextBlock
---@field TextBlock_Base_Vamp UTextBlock
---@field TextBlock_Bonus_Attack UTextBlock
---@field TextBlock_Bonus_CriticalAttack UTextBlock
---@field TextBlock_Bonus_DamageReduction UTextBlock
---@field TextBlock_Bonus_Defence UTextBlock
---@field TextBlock_Bonus_FireAttack UTextBlock
---@field TextBlock_Bonus_MaxHP UTextBlock
---@field TextBlock_Eco_CoinPoint UTextBlock
---@field TextBlock_Eco_DropRate UTextBlock
---@field TextBlock_Eco_Exp UTextBlock
---@field TextBlock_Eco_HangupRoomMonsterNum UTextBlock
---@field TextBlock_Eco_HangupRoomRefreshRate UTextBlock
---@field TextBlock_Eco_KillPoint UTextBlock
---@field TextBlock_Growth_Attack UTextBlock
---@field TextBlock_Growth_Fire_Attack UTextBlock
---@field TextBlock_Growth_Fire_MaxHP UTextBlock
---@field TextBlock_Growth_Kill_Attack UTextBlock
---@field TextBlock_Growth_Kill_CoinPoint UTextBlock
---@field TextBlock_Growth_Kill_MaxHP UTextBlock
---@field TextBlock_Growth_KillPoint UTextBlock
---@field TextBlock_Growth_MaxHP UTextBlock
--Edit Below--
local WBP_AttributePanel = {
bInitDoOnce = false,
Collapsed = true,
};
function WBP_AttributePanel:Construct()
self.Panel_BG:Construct()
self.Collapsed = true
local MainPanelSlot = WidgetLayoutLibrary.SlotAsCanvasSlot(self.Panel_Main)
MainPanelSlot:SetSize({X = 320.0, Y = 400})
self.Panel_BonusAttributes:SetVisibility(ESlateVisibility.Collapsed)
self.Panel_EconomyAttributes:SetVisibility(ESlateVisibility.Collapsed)
local PlayerState = GameDataManager.GetLocalPlayerState()
if UE.IsValid(PlayerState) then
self:OnPlayerAttributeChanged(PlayerState.Attributes)
end
EventSystem:AddListener(EventType.OnPlayerAttributeChanged, WBP_AttributePanel.OnPlayerAttributeChanged, self)
self.NewButton_Toggle.OnClicked:Add(WBP_AttributePanel.OnToggleButtonClicked, self)
end
function WBP_AttributePanel:Destruct()
self.NewButton_Toggle.OnClicked:Remove(WBP_AttributePanel.OnToggleButtonClicked, self)
EventSystem:RemoveListener(EventType.OnPlayerAttributeChanged, WBP_AttributePanel.OnPlayerAttributeChanged, self)
end
function WBP_AttributePanel:OnPlayerAttributeChanged(InAttributes)
local NewAttribute = {}
for i, v in pairs(InAttributes) do
-- 只能取 j
for j, k in pairs(v) do
local Val = 0
for c, d in pairs(InAttributes) do
Val = Val + InAttributes[c][j]
end
NewAttribute[j] = Val
end
break
end
for AttributeName, Value in pairs(NewAttribute) do
local TextBlockName = "TextBlock_"..AttributeName
local TextBlock = self[TextBlockName]
if UE.IsValid(TextBlock) then
local Txt = ""
local DisplayType = GlobalFunctions.GetAttributeDisplayType(AttributeName)
if DisplayType == EAttributeDisplayType.Percent then
Txt = Txt.." "..tostring(math.ceil(Value * 100.0)).."%"
else
Txt = Txt..tostring(math.ceil(Value))
end
TextBlock:SetText(Txt)
end
end
end
function WBP_AttributePanel:OnToggleButtonClicked()
local MainPanelSlot = WidgetLayoutLibrary.SlotAsCanvasSlot(self.Panel_Main)
if self.Collapsed == true then
self.Collapsed = false
MainPanelSlot:SetSize({X = 320.0, Y = 570})
self.NewButton_Toggle:SetRenderScale({X=1, Y=-1})
self.Panel_BonusAttributes:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
self.Panel_EconomyAttributes:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
else
self.Collapsed = true
MainPanelSlot:SetSize({X = 320.0, Y = 400})
self.NewButton_Toggle:SetRenderScale({X=1, Y=1})
self.Panel_BonusAttributes:SetVisibility(ESlateVisibility.Collapsed)
self.Panel_EconomyAttributes:SetVisibility(ESlateVisibility.Collapsed)
end
end
return WBP_AttributePanel;