238 lines
7.6 KiB
Lua
238 lines
7.6 KiB
Lua
require('Script.Global.WidgetManager.WidgetConfig')
|
|
|
|
WidgetManager = WidgetManager or {}
|
|
-- 是否初始化
|
|
WidgetManager.HasInitialized = false
|
|
-- 是否是主UI
|
|
WidgetManager.MainControlPanel = nil
|
|
WidgetManager.PlayerInfoPanel = nil
|
|
WidgetManager.AllPanel = {}
|
|
WidgetManager.OwnerController = nil
|
|
WidgetManager.PlayerHeadSculpture = {} -- 玩家头像 {URL = UTexture2DDynamic*, ...}
|
|
WidgetManager.WeaponImage = {} -- 武器图片 {URL = UTexture2DDynamic*, ...}
|
|
|
|
---@param OwnerController APlayerController
|
|
function WidgetManager:Init(OwnerController)
|
|
if UE.IsValid(OwnerController) then self.OwnerController = OwnerController end
|
|
self:InitBaseUI();
|
|
|
|
for _, UIType in pairs(WidgetConfig.EUIType) do
|
|
if UIType > WidgetConfig.EUIType.Default then
|
|
self:LoadUI(UIType)
|
|
end
|
|
end
|
|
|
|
self.HasInitialized = true
|
|
end
|
|
|
|
function WidgetManager:UnInit()
|
|
self:Release()
|
|
end
|
|
|
|
function WidgetManager:ShowOrClosePanel(UIType, IsShow)
|
|
if UGCGameSystem.IsServer() then return end
|
|
UGCLogSystem.Log("[WidgetManager:ShowOrClosePanel] UIType: %d", UIType)
|
|
if IsShow then
|
|
self:ShowPanel(UIType)
|
|
else
|
|
self:ClosePanel(UIType)
|
|
end
|
|
end
|
|
|
|
function WidgetManager:InitBaseUI()
|
|
WidgetConfig.HideDefaultUI(true);
|
|
end
|
|
|
|
---@param UIType int32
|
|
---@param Func fun(Widget: UUserWidget)
|
|
---@return UUserWidget
|
|
function WidgetManager:LoadUI(UIType, Func, Params)
|
|
if UIType == nil then return nil end
|
|
local Config = WidgetConfig.HUDConfig[UIType]
|
|
if Config == nil then
|
|
UGCLogSystem.Log("[WidgetManager:LoadUI] InValid UIType = %d config, skipped!", UIType)
|
|
return nil;
|
|
end
|
|
UGCLogSystem.LogTree(string.format("[WidgetManager:LoadUI] Params ="), Params)
|
|
if self.AllPanel[UIType] ~= nil and UE.IsValid(self.AllPanel[UIType]) then
|
|
if Func then Func(self.AllPanel[UIType], Params); end
|
|
return self.AllPanel[UIType];
|
|
end
|
|
local UIPathName = Config.Path;
|
|
UE.AsyncLoadClass(Config.Path, function(UIClass)
|
|
local Config1 = WidgetConfig.HUDConfig[UIType]
|
|
local UILayer = Config1.Layer;
|
|
if UILayer == nil then UILayer = WidgetConfig.EUILayerGroup.Medium; end
|
|
if self.AllPanel[UIType] ~= nil then
|
|
if Func then Func(self.AllPanel[UIType], Params); end
|
|
return ;
|
|
end
|
|
local UIWidget = UserWidget.NewWidgetObjectBP(LocalPlayerController, UIClass);
|
|
if UIWidget ~= nil then
|
|
-- 查看是否需要添加到自定义面板上
|
|
if Config1.bAddToTouch then UGCWidgetManagerSystem.AddChildToTochButton(UIWidget); end
|
|
UIWidget:AddToViewport(UILayer);
|
|
UIWidget:SetVisibility(ESlateVisibility.Collapsed);
|
|
UIWidget.UIType = UIType;
|
|
if self.AllPanel[UIType] == nil then self.AllPanel[UIType] = UIWidget; end
|
|
end
|
|
if Func then Func(UIWidget, Params); end
|
|
end);
|
|
|
|
return nil;
|
|
end
|
|
|
|
--- 显示 UI
|
|
---@param UIType int32
|
|
---@param NeedCloseSameLayerPanel bool 是否关闭其他相同类型的UI
|
|
---@tparam table
|
|
function WidgetManager:ShowPanel(UIType, NeedCloseSameLayerPanel, ...)
|
|
UGCLogSystem.Log("[WidgetManager:ShowPanel] UIType = %s", tostring(UIType));
|
|
|
|
if UIType == nil or UIType == WidgetConfig.EUIType.Default then
|
|
UGCLogSystem.Log("[WidgetManager_ShowPanel] Invalid UIType = %d", UIType);
|
|
return
|
|
end
|
|
local Params = { ... }
|
|
UGCLogSystem.Log("[WidgetManager:ShowPanel] UIType = %s", tostring(UIType));
|
|
UGCLogSystem.LogTree(string.format("[WidgetManager:ShowPanel] Params ="), Params)
|
|
if NeedCloseSameLayerPanel == nil then NeedCloseSameLayerPanel = true end
|
|
|
|
local Func = function(Widget, p)
|
|
if Widget ~= nil and UE.IsValid(Widget) then
|
|
if NeedCloseSameLayerPanel then self:CloseSameLayerPanel(UIType) end
|
|
UGCLogSystem.Log("[WidgetManager:ShowPanel] Show UI: " .. tostring(UIType));
|
|
table.func(Widget, 'Show');
|
|
Widget:SetVisibility(ESlateVisibility.SelfHitTestInvisible);
|
|
table.func(Widget, 'OnShowPanel', table.unpackTable(p));
|
|
else
|
|
UGCLogSystem.Log("[WidgetManager_ShowPanel] Show UI Failed: " .. tostring(UIType))
|
|
end
|
|
end
|
|
|
|
local Panel = self:GetPanel(UIType, Func, Params);
|
|
end
|
|
|
|
---@param UIType int32
|
|
---@param WorldPosition Vector3D @UI生成的三维世界坐标
|
|
function WidgetManager:ShowUIWithWorldPosition(UIType, WorldPosition)
|
|
if WorldPosition == nil then
|
|
UGCLogSystem.LogError("[WidgetManager] WorldPosition is nil")
|
|
return
|
|
end
|
|
self:ShowPanel(UIType);
|
|
end
|
|
|
|
---@return int32
|
|
function WidgetManager:GetPanelLayer(UIType)
|
|
return WidgetConfig.HUDConfig[UIType].Layer
|
|
end
|
|
|
|
--- 关闭同层级的所有UI
|
|
---@param InUIType int32
|
|
function WidgetManager:CloseSameLayerPanel(InUIType)
|
|
local CurLayer = WidgetConfig.HUDConfig[InUIType].Layer
|
|
for UIType, Config in pairs(WidgetConfig.HUDConfig) do
|
|
if UIType ~= InUIType and Config.Layer == CurLayer then
|
|
self:ClosePanel(UIType)
|
|
end
|
|
end
|
|
end
|
|
|
|
---@param UIType int32
|
|
function WidgetManager:ClosePanel(UIType)
|
|
if not self:PanelIsValid(UIType) then
|
|
UGCLogSystem.Log("[WidgetManager:ClosePanel] 执行")
|
|
return
|
|
end
|
|
local Panel = self.AllPanel[UIType]
|
|
table.func(Panel, 'Hide')
|
|
Panel:SetVisibility(ESlateVisibility.Collapsed)
|
|
table.func(Panel, 'OnClosePanel')
|
|
if WidgetConfig.HUDConfig[UIType].bShowOnce then self:DestroyPanel(UIType); end
|
|
end
|
|
|
|
---@param UIType int32
|
|
function WidgetManager:DestroyPanel(UIType)
|
|
if not self:PanelIsValid(UIType) then return end
|
|
local Panel = self.AllPanel[UIType]
|
|
Panel:RemoveFromParent()
|
|
self.AllPanel[UIType] = nil
|
|
end
|
|
|
|
function WidgetManager:CloseAllPanel()
|
|
for UIType, Panel in pairs(self.AllPanel) do self:ClosePanel(UIType) end
|
|
end
|
|
|
|
function WidgetManager:DestroyAllPanel()
|
|
for UIType, Panel in pairs(self.AllPanel) do self:DestroyPanel(UIType) end
|
|
end
|
|
|
|
---@param UIType int32
|
|
---@return bool 是否存在UI
|
|
function WidgetManager:PanelIsValid(UIType)
|
|
local Panel = self.AllPanel[UIType]
|
|
return Panel ~= nil and UE.IsValid(Panel)
|
|
end
|
|
|
|
---获取UI
|
|
---@param UIType int32
|
|
---@param Func fun(Widget:UUserWidget)
|
|
---@return UUserWidget 获取UI
|
|
function WidgetManager:GetPanel(UIType, Func, Params)
|
|
local Panel = self.AllPanel[UIType]
|
|
if Panel ~= nil and UE.IsValid(Panel) then
|
|
if Func then Func(Panel, Params); end
|
|
return Panel;
|
|
else
|
|
return self:LoadUI(UIType, Func, Params)
|
|
end
|
|
end
|
|
|
|
--- UI是否显示
|
|
---@param UIType int32
|
|
---@return bool
|
|
function WidgetManager:IsVisiblePanel(UIType)
|
|
if self:PanelIsValid(UIType) then return self.AllPanel[UIType]:IsVisible() end
|
|
return false
|
|
end
|
|
|
|
---@param UIType int32
|
|
function WidgetManager:VisiblePanel(UIType)
|
|
if self:PanelIsValid(UIType) then
|
|
self.AllPanel[UIType]:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
|
end
|
|
end
|
|
|
|
---@param UIType int32
|
|
function WidgetManager:HidePanel(UIType)
|
|
if self:PanelIsValid(UIType) then
|
|
self.AllPanel[UIType]:SetVisibility(ESlateVisibility.Collapsed)
|
|
end
|
|
end
|
|
|
|
---@param InStr string
|
|
function WidgetManager:ShowTips(InStr, ...) UGCWidgetManagerSystem.ShowTipsUI(InStr:format(...)); end
|
|
|
|
function WidgetManager.HideReturnToLobbyButton()
|
|
UGCLogSystem.Log("[WidgetManager.HideReturnToLobbyButton] 执行")
|
|
local InGameMgr = GameFrontendHUD:GetLogicManagerByName("ingame");
|
|
local WatchGameUIObj_InGameMgr = GameBusinessManager.GetWidgetFromName(InGameMgr, "WatchGame_UIBP_C");
|
|
if WatchGameUIObj_InGameMgr then
|
|
WatchGameUIObj_InGameMgr.Button_BackToLobby:SetVisibility(ESlateVisibility.Collapsed);
|
|
end
|
|
|
|
local WatchGameUI = GetUIObject(bp_battleresult, "WatchGame_UIBP_C");
|
|
if WatchGameUI then
|
|
UGCLogSystem.Log("[WidgetManager.HideReturnToLobbyButton] 隐藏起来")
|
|
WatchGameUI.Button_BackToLobby:SetVisibility(ESlateVisibility.Collapsed);
|
|
WatchGameUI.GridPanel_1:SetVisibility(ESlateVisibility.Hidden);
|
|
end
|
|
|
|
local WatchGame_UIBPG = UGCWidgetManagerSystem.GetGlobalOBUI();
|
|
if WatchGame_UIBPG then
|
|
WatchGame_UIBPG.Button_BackToLobby:SetVisibility(ESlateVisibility.Collapsed);
|
|
end
|
|
end
|
|
|
|
return WidgetManager |