317 lines
8.7 KiB
Lua
317 lines
8.7 KiB
Lua
require('Script.Global.WidgetManager.WidgetConfig')
|
|
|
|
WidgetManager = WidgetManager or {}
|
|
-- 是否初始化
|
|
WidgetManager.HasInitialized = false
|
|
-- 是否是主UI
|
|
WidgetManager.MainControlPanel = nil
|
|
WidgetManager.PlayerInfoPanel = nil
|
|
--WidgetManager.MainControlBaseUI = 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
|
|
else
|
|
return
|
|
end
|
|
|
|
self:Bind()
|
|
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:UnBind()
|
|
self:Release()
|
|
end
|
|
|
|
function WidgetManager:Bind()
|
|
if WidgetManager.HasInitialized == true then
|
|
return
|
|
end
|
|
end
|
|
|
|
function WidgetManager:UnBind()
|
|
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
|
|
---@return UUserWidget
|
|
function WidgetManager:LoadUI(UIType)
|
|
if UIType == nil then
|
|
UGCLogSystem.LogError("[WidgetManager_LoadUI] invalid UIType=%d", UIType)
|
|
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
|
|
|
|
if self.AllPanel[UIType] ~= nil and UE.IsValid(self.AllPanel[UIType]) then
|
|
UGCLogSystem.Log("[WidgetManager_LoadUI] UI Existed: " .. UIType)
|
|
return self.AllPanel[UIType]
|
|
end
|
|
|
|
local UIPathName = Config.Path
|
|
local UIClass = UE.LoadClass(UIPathName)
|
|
local UILayer = Config.Layer
|
|
|
|
if UIClass == nil then
|
|
UGCLogSystem.LogError("[WidgetManager_LoadUI] UIClassName[%s] Load Failed!", UIPathName)
|
|
return nil
|
|
end
|
|
|
|
if UILayer == nil then
|
|
UGCLogSystem.Log("[WidgetManager_LoadUI] invalid UILayer, UIType=%d", UIType)
|
|
return nil
|
|
end
|
|
|
|
local LocalPlayerController = self.OwnerController;
|
|
if LocalPlayerController == nil or UE.IsValid(LocalPlayerController) == false then
|
|
UGCLogSystem.LogError("[WidgetManager_LoadUI] invalid local PlayerController")
|
|
end
|
|
|
|
local UIWidget = UserWidget.NewWidgetObjectBP(LocalPlayerController, UIClass)
|
|
if UIWidget ~= nil then
|
|
UGCLogSystem.Log("[WidgetManager_LoadUI] Layer = %d", UILayer)
|
|
if Config.bAddToTouch then UGCWidgetManagerSystem.AddChildToTochButton(UIWidget); end
|
|
-- UIWidget:AddToViewport(UILayer + 10000)
|
|
UIWidget:AddToViewport(UILayer)
|
|
|
|
UIWidget:SetVisibility(ESlateVisibility.Collapsed)
|
|
|
|
self.AllPanel[UIType] = UIWidget
|
|
return UIWidget
|
|
end
|
|
|
|
return nil
|
|
end
|
|
|
|
--- 显示 UI
|
|
---@param UIType int32
|
|
---@param NeedCloseSameLayerPanel bool 是否关闭其他相同类型的UI
|
|
---@param ... 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
|
|
|
|
UGCLogSystem.Log("[WidgetManager:ShowPanel] UIType = %s", tostring(UIType));
|
|
|
|
if NeedCloseSameLayerPanel == nil then NeedCloseSameLayerPanel = true end
|
|
|
|
local Panel = self:GetPanel(UIType)
|
|
if Panel ~= nil and UE.IsValid(Panel) then
|
|
if NeedCloseSameLayerPanel then self:CloseSameLayerPanel(UIType) end
|
|
UGCLogSystem.Log("[WidgetManager_ShowPanel] Show UI: " .. tostring(UIType))
|
|
if Panel["Show"] ~= nil then
|
|
Panel:Show()
|
|
else
|
|
Panel:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
|
end
|
|
|
|
if select("#", ...) > 0 then
|
|
if Panel["InitFromParam"] ~= nil then
|
|
Panel:InitFromParam(...)
|
|
end
|
|
end
|
|
|
|
if Panel["OnShowPanel"] ~= nil then
|
|
Panel:OnShowPanel(...)
|
|
end
|
|
else
|
|
UGCLogSystem.Log("[WidgetManager_ShowPanel] Show UI Failed: " .. tostring(UIType))
|
|
end
|
|
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
|
|
return
|
|
end
|
|
local Panel = self.AllPanel[UIType]
|
|
|
|
if Panel["Hide"] ~= nil then
|
|
Panel:Hide()
|
|
else
|
|
Panel:SetVisibility(ESlateVisibility.Collapsed)
|
|
end
|
|
if Panel["OnClosePanel"] ~= nil then
|
|
Panel:OnClosePanel()
|
|
end
|
|
|
|
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
|
|
|
|
---@param bRemainNotice bool
|
|
function WidgetManager:CloseAllPanel(bRemainNotice)
|
|
for UIType, Panel in pairs(self.AllPanel) do
|
|
if bRemainNotice then
|
|
self:ClosePanel(UIType)
|
|
else
|
|
self:ClosePanel(UIType)
|
|
end
|
|
end
|
|
end
|
|
|
|
---@param bRemainNotice bool
|
|
function WidgetManager:DestroyAllPanel(bRemainNotice)
|
|
for UIType, Panel in pairs(self.AllPanel) do
|
|
if bRemainNotice then
|
|
self:DestroyPanel(UIType)
|
|
else
|
|
self:DestroyPanel(UIType)
|
|
end
|
|
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
|
|
---@return UUserWidget 获取UI
|
|
function WidgetManager:GetPanel(UIType)
|
|
local Panel = self.AllPanel[UIType]
|
|
if Panel ~= nil and UE.IsValid(Panel) then
|
|
return Panel
|
|
else
|
|
return self:LoadUI(UIType)
|
|
end
|
|
end
|
|
|
|
--- UI是否显示
|
|
---@param UIType int32
|
|
---@return bool
|
|
function WidgetManager:IsVisiblePanel(UIType)
|
|
if self:PanelIsValid(UIType) then
|
|
local Panel = self.AllPanel[UIType]
|
|
return Panel:IsVisible()
|
|
end
|
|
return false
|
|
end
|
|
|
|
---@param UIType int32
|
|
function WidgetManager:VisiblePanel(UIType)
|
|
if self:PanelIsValid(UIType) then
|
|
local Panel = self.AllPanel[UIType]
|
|
Panel:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
|
end
|
|
end
|
|
|
|
---@param UIType int32
|
|
function WidgetManager:HidePanel(UIType)
|
|
if self:PanelIsValid(UIType) then
|
|
local Panel = self.AllPanel[UIType]
|
|
Panel:SetVisibility(ESlateVisibility.Collapsed)
|
|
end
|
|
end
|
|
|
|
---@param InStr string
|
|
function WidgetManager:ShowTips(InStr)
|
|
UGCWidgetManagerSystem.ShowTipsUI(InStr);
|
|
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
|
|
UGCLogSystem.Log("[WidgetManager.HideReturnToLobbyButton] 1111")
|
|
WatchGameUIObj_InGameMgr.Button_BackToLobby:SetVisibility(ESlateVisibility.Collapsed);
|
|
end
|
|
|
|
local BattleResultMgr = GameFrontendHUD:GetLogicManagerByName("bp_battleresult");
|
|
local ObserveMgr = GameFrontendHUD:GetLogicManagerByName("observe");
|
|
|
|
local ObserveMgrInst = GameBusinessManager.GetLuaObject(ObserveMgr);
|
|
UGCLogSystem.Log("[WidgetManager.HideReturnToLobbyButton] ObserveMgrInst = %s", tostring(ObserveMgrInst))
|
|
--UGCLog.LogDev("[Watch] ObserveMgrInst ====%s", tostring(ObserveMgrInst));
|
|
|
|
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
|
|
UGCLogSystem.Log("[WidgetManager.HideReturnToLobbyButton] WatchGame_UIBPG = %s", UE.GetName(WatchGame_UIBPG))
|
|
WatchGame_UIBPG.Button_BackToLobby:SetVisibility(ESlateVisibility.Collapsed);
|
|
end
|
|
end
|
|
|
|
return WidgetManager |