2025-01-04 23:00:19 +08:00

91 lines
2.4 KiB
Lua

---@class WB_Bolts_C:UUserWidget
---@field HorizontalBox_0 UHorizontalBox
---@field VerticalBox_Bolts UVerticalBox
--Edit Below--
local WB_Bolts = { bInitDoOnce = false }
function WB_Bolts:Construct()
self:LuaInit();
end
function WB_Bolts:LuaInit()
if self.bInitDoOnce then return ; end
-- 包含一下
self.bInitDoOnce = false;
end
function WB_Bolts:SetPlayerBolts(InList)
UITool.HideAllChildren(self.VerticalBox_Bolts);
-- 创建一下
UGCLogSystem.LogTree(string.format("[WB_Bolts:SetPlayerBolts] InList ="), InList)
UITool.AdaptChildren(self.VerticalBox_Bolts, table.getCount(InList), ObjectPath.WB_BoltItem)
local Bolts = {};
for BoltType, Count in pairs(InList) do
if Count > 0 then
table.insert(Bolts, {
Bolt = BoltType,
Count = Count,
});
end
end
UITool.ForeachAllChildren(self.VerticalBox_Bolts, function(index, Widget)
if Bolts[index] then
Widget:SetBolt(Bolts[index]);
Widget:SetBoltType(Bolts[index].Bolt);
Widget:SetVisibility(ESlateVisibility.SelfHitTestInvisible);
else
Widget:SetVisibility(ESlateVisibility.Collapsed);
end
end);
if self.BoltType then
self:SetPlayerSelectBolt(self.BoltType);
end
end
WB_Bolts.CurrItem = nil;
WB_Bolts.BoltType = nil;
function WB_Bolts:SetPlayerSelectBolt(InBolt)
-- 这是当前选择的
self.BoltType = InBolt;
if self.CurrItem ~= nil then
self.CurrItem:SetSelect(false);
self.CurrItem = nil;
end
if type(InBolt) == 'nil' then
UGCLogSystem.Log("[WB_Bolts:SetPlayerSelectBolt] InBolt 为空")
elseif type(InBolt) == 'number' then
UGCLogSystem.Log("[WB_Bolts:SetPlayerSelectBolt] InBolt = %s", TableHelper.printEnum(EBoltBuffType, InBolt));
for i = 1, self.VerticalBox_Bolts:GetChildrenCount() do
local Item = self.VerticalBox_Bolts:GetChildAt(i - 1);
local BoltType = Item:GetBoltType();
UGCLogSystem.Log("[WB_Bolts:SetPlayerSelectBolt] BoltType = %s", tostring(BoltType));
if BoltType == InBolt then
Item:SetSelect(true);
self.CurrItem = Item;
break;
end
end
end
end
function WB_Bolts:FindItemByBolt(InBolt)
if InBolt == nil then return ; end
UGCLogSystem.Log("[WB_Bolts:FindItemByBolt] InBolt = %s", tostring(InBolt));
return UITool.FindItem(self.VerticalBox_Bolts, function(Widget)
local Bolt = Widget.BoltType;
UGCLogSystem.Log("[WB_Bolts:FindItemByBolt] Bolt = %s", tostring(Bolt));
return Bolt == InBolt;
end);
end
-- function WB_Bolts:Tick(MyGeometry, InDeltaTime)
-- end
-- function WB_Bolts:Destruct()
-- end
return WB_Bolts