UGCProjects/Counterattack/Script/UI/SelectBuff/WB_SelectBaseBuff.lua

94 lines
3.1 KiB
Lua
Raw Normal View History

2025-01-04 23:00:19 +08:00
---@class WB_SelectBaseBuff_C:UUserWidget
---@field NewButton_Random UNewButton
---@field NewButton_Select UNewButton
---@field TextBlock_BuffDesc UTextBlock
---@field UniformGridPanel_Buffs UUniformGridPanel
--Edit Below--
local WB_SelectBaseBuff = {
bInitDoOnce = false;
Col = 5;
}
function WB_SelectBaseBuff:Construct()
self:LuaInit()
end
-- function WB_SelectBaseBuff:Tick(MyGeometry, InDeltaTime)
-- end
-- function WB_SelectBaseBuff:Destruct()
-- end
function WB_SelectBaseBuff:LuaInit()
if self.bInitDoOnce then return end
self.bInitDoOnce = true
WidgetLibrary.BindButtonClicked(self.NewButton_Select, self.SelectBuff, self)
WidgetLibrary.BindButtonClicked(self.NewButton_Random, self.CloseSelf, self)
local LocalPC = UGCSystemLibrary.GetLocalPlayerController()
local Count = 0
local AllIncreaseType = {}
for i, v in pairs(GodOfWarConfig.EIncreaseType) do
AllIncreaseType[#AllIncreaseType + 1] = v
end
table.sort(AllIncreaseType, function(a, b) return a > b end)
for i, IncreaseType in pairs(AllIncreaseType) do
local Item = nil;
Count = Count + 1
if self.UniformGridPanel_Buffs:GetChildrenCount() < Count then
Item = UserWidget.NewWidgetObjectBP(LocalPC, self:GetItemClass());
self.UniformGridPanel_Buffs:AddChild(Item)
local TargetUniformGridSlot = WidgetLayoutLibrary.SlotAsUniformGridSlot(Item)
-- 居中
TargetUniformGridSlot:SetVerticalAlignment(EVerticalAlignment.VAlign_Center)
TargetUniformGridSlot:SetHorizontalAlignment(EHorizontalAlignment.HAlign_Center)
-- 设置索引
TargetUniformGridSlot:SetColumn((Count - 1) % self.Col)
TargetUniformGridSlot:SetRow((Count - 1) // self.Col)
else
Item = self.UniformGridPanel_Buffs:GetChildAt(Count - 1)
end
Item:UpdateIncreaseType(IncreaseType)
-- 这里传入类型方便回调获取
Item:SetIndex(IncreaseType)
Item:BindClickSelect(self.ClickSelectBuff, self)
end
self:ClickSelectBuff(AllIncreaseType[1])
end
function WB_SelectBaseBuff:GetItemClass()
if not UE.IsValid(self.ItemClass) then
self.ItemClass = UE.LoadClass(UGCGameSystem.GetUGCResourcesFullPath('Asset/UI/SelectBuff/WB_BaseBuffSelectItem.WB_BaseBuffSelectItem_C'))
end
return self.ItemClass
end
function WB_SelectBaseBuff:ClickSelectBuff(IncreaseType)
for i = 1, self.UniformGridPanel_Buffs:GetChildrenCount() do
local Item = self.UniformGridPanel_Buffs:GetChildAt(i - 1)
Item:SetSelect(IncreaseType == Item:GetIndex())
end
self.IncreaseType = IncreaseType
if GodOfWarConfig.IncreaseDesc[self.IncreaseType] then
self.TextBlock_BuffDesc:SetText(GodOfWarConfig.IncreaseDesc[self.IncreaseType])
end
end
function WB_SelectBaseBuff:CloseSelf()
WidgetManager:ClosePanel(WidgetConfig.EUIType.SelectBaseBuff)
end
function WB_SelectBaseBuff:SelectBuff()
UGCSendRPCSystem.ActorRPCNotify(nil, UGCSystemLibrary.GetLocalPlayerController(), "SetBaseIncrease", self.IncreaseType)
self:CloseSelf()
end
return WB_SelectBaseBuff