105 lines
2.6 KiB
Lua
105 lines
2.6 KiB
Lua
---@class WB_TestLog_C:UUserWidget
|
|
---@field VerticalBox_Logs UVerticalBox
|
|
--Edit Below--
|
|
local WB_TestLog = { bInitDoOnce = false; };
|
|
|
|
WB_TestLog.MaxLimit = 50;
|
|
WB_TestLog.ShowLogTime = 1.5;
|
|
|
|
local ItemPath = UGCGameSystem.GetUGCResourcesFullPath('Asset/UI/InTest/Log/WB_TestLogItem.WB_TestLogItem_C');
|
|
|
|
function WB_TestLog:Construct()
|
|
-- 创建很多进去
|
|
if DefaultSettings.EnableTest then
|
|
self:LuaInit();
|
|
end
|
|
end
|
|
|
|
WB_TestLog.InUseList = {};
|
|
WB_TestLog.UnusedList = {};
|
|
|
|
function WB_TestLog:LuaInit()
|
|
if self.bInitDoOnce then return ; end
|
|
UE.AsyncLoadClass_Cached(ItemPath, function(TargetClass)
|
|
for i = 1, self.MaxLimit do
|
|
local Item = UITool.AddWidgetItem(self.VerticalBox_Logs, TargetClass, self)
|
|
table.insert(self.UnusedList, Item);
|
|
Item:SetVisibility(ESlateVisibility.Collapsed);
|
|
end
|
|
UITool.ForeachAllChildren(self.VerticalBox_Logs, function(index, Widget)
|
|
Widget:LuaInit();
|
|
end);
|
|
end)
|
|
|
|
GlobalTickTool:AddTick(self, self.OnPrintLog, 3);
|
|
GlobalTickTool:AddTick(self, self.RecycleItem, 0.1);
|
|
|
|
self.bInitDoOnce = true;
|
|
end
|
|
|
|
---@class FLogItemInfo
|
|
---@field Color
|
|
---@field Str string
|
|
---@field Time float
|
|
|
|
---@type table<int32, FLogItemInfo>
|
|
WB_TestLog.LogList = {};
|
|
|
|
---@param InStr string
|
|
function WB_TestLog:AddLog(Color, InStr, ...)
|
|
local Time = UE.GetServerTime();
|
|
if Time == nil then Time = .0; end
|
|
local LogItem = {
|
|
Color = Color,
|
|
Str = string.format('[%0.1f] ', Time) .. InStr:format(...);
|
|
};
|
|
table.insert(self.LogList, LogItem);
|
|
-- 检查数量是否超过上限,如果没有超过不用管
|
|
if #self.LogList >= self.MaxLimit then
|
|
-- 显示所有
|
|
self:OnPrintLog();
|
|
end
|
|
end
|
|
|
|
function WB_TestLog:OnPrintLog(dt, st)
|
|
if table.isEmpty(self.LogList) then return; end
|
|
-- 一口气直接输出里面所有的
|
|
-- 如果不够
|
|
for i = 1, #self.LogList do
|
|
local Item = self.LogList[i];
|
|
local WidgetItem = self.UnusedList[1];
|
|
WidgetItem:SetInfo(Item);
|
|
self.InUseList[WidgetItem] = UE.GetServerTime() + self.ShowLogTime;
|
|
WidgetItem:SetVisibility(ESlateVisibility.HitTestInvisible);
|
|
table.remove(self.UnusedList, 1);
|
|
end
|
|
self.LogList = {};
|
|
end
|
|
|
|
function WB_TestLog:RecycleItem(dt, st)
|
|
if table.isEmpty(self.InUseList) then return; end
|
|
for i, v in pairs(self.InUseList) do
|
|
if st >= v then
|
|
i:SetVisibility(ESlateVisibility.Collapsed);
|
|
table.insert(self.UnusedList, i);
|
|
self.InUseList[i] = nil;
|
|
end
|
|
end
|
|
end
|
|
|
|
function WB_TestLog:AddLogItems(List)
|
|
for i, v in pairs(List) do
|
|
table.insert(self.LogList, v);
|
|
if #self.LogList >= self.MaxLimit then self:OnPrintLog(); end
|
|
end
|
|
end
|
|
|
|
-- function WB_TestLog:Tick(MyGeometry, InDeltaTime)
|
|
|
|
-- end
|
|
|
|
-- function WB_TestLog:Destruct()
|
|
|
|
-- end
|
|
|
|
return WB_TestLog; |