87 lines
2.1 KiB
Lua
87 lines
2.1 KiB
Lua
--- 辅助解耦的存在
|
|
if UE_SERVER then return ; end
|
|
UIManager = {};
|
|
|
|
---@type table<string, UWidget>
|
|
UIManager.Widgets = {};
|
|
UIManager.WaitFuncs = {};
|
|
|
|
function UIManager:Register(InKey, InWidget)
|
|
assert(InKey ~= nil);
|
|
assert(InWidget ~= nil);
|
|
if self.Widgets[InKey] ~= nil then
|
|
if self.Widgets[InKey] == InWidget then
|
|
UGCLogSystem.Log("[UIManager:Register] 不要重复添加")
|
|
return ;
|
|
end
|
|
end
|
|
self.Widgets[InKey] = InWidget;
|
|
table.func(InWidget, "LuaInit")
|
|
if self.WaitFuncs[InKey] ~= nil then
|
|
for i, FuncInfo in pairs(self.WaitFuncs[InKey]) do
|
|
FuncInfo.Fun(InWidget, table.unpackTable(FuncInfo.Params));
|
|
end
|
|
self.WaitFuncs[InKey] = nil;
|
|
end
|
|
end
|
|
|
|
---@param InKey
|
|
---@param InFunc fun(Widget:UUserWidget, ...)
|
|
function UIManager:Get(InKey, InFunc, ...)
|
|
assert(InKey ~= nil)
|
|
local Params = { ... };
|
|
if self.Widgets[InKey] then
|
|
if type(InFunc) == 'function' then InFunc(self.Widgets[InKey]); end
|
|
return self.Widgets[InKey];
|
|
end
|
|
if self.WaitFuncs[InKey] == nil then
|
|
self.WaitFuncs[InKey] = {};
|
|
end
|
|
table.insert(self.WaitFuncs[InKey], {
|
|
Fun = InFunc,
|
|
Params = Params,
|
|
});
|
|
return nil;
|
|
end
|
|
|
|
function UIManager:Exec(InKey, InFuncName, ...)
|
|
assert(InKey ~= nil)
|
|
local param = { ... };
|
|
if self.Widgets[InKey] then
|
|
table.func(self.Widgets[InKey], InFuncName, ...);
|
|
end
|
|
end
|
|
|
|
function UIManager:Unregister(InKey)
|
|
self.Widgets[InKey] = nil;
|
|
self.WaitFuncs[InKey] = nil;
|
|
end
|
|
|
|
function UIManager:Show(InKey, ...)
|
|
-- 检查是否有函数
|
|
local Widget = self.Widgets[InKey];
|
|
if Widget == nil then return ; end
|
|
table.func(Widget, "OnShowPanel", ...);
|
|
Widget:SetVisibility(ESlateVisibility.SelfHitTestInvisible);
|
|
end
|
|
|
|
function UIManager:Hide(InKey, ...)
|
|
-- 检查是否有函数
|
|
local Widget = self.Widgets[InKey];
|
|
if Widget == nil then return ; end
|
|
table.func(Widget, "OnClosePanel", ...);
|
|
Widget:SetVisibility(ESlateVisibility.Collapsed);
|
|
end
|
|
|
|
--- 切换显示
|
|
function UIManager:TurnVisible(InKey, ...)
|
|
local Widget = self.Widgets[InKey];
|
|
if Widget == nil then return ; end
|
|
if Widget:IsVisible() then
|
|
self:Hide(InKey, ...)
|
|
else
|
|
self:Show(InKey, ...)
|
|
end
|
|
end
|
|
|
|
return UIManager; |