261 lines
9.7 KiB
Lua
261 lines
9.7 KiB
Lua
---@class WBP_NoticeLayer_C:UUserWidget
|
|
---@field AttackWaveNoticePanel UCanvasPanel
|
|
---@field AttackWaveRemainTimeNoticePanel UCanvasPanel
|
|
---@field CountDownNoticePanel UCanvasPanel
|
|
---@field GeneralNoticePanel UCanvasPanel
|
|
---@field InitialNoticePanel UCanvasPanel
|
|
---@field Notice_AttackWave UWBP_AttackWaveNotice_C
|
|
---@field Notice_AttackWaveRemainTime UWBP_AttackWaveRemainTimeNotice_C
|
|
---@field Notice_CountDown UWBP_CountDownNotice_C
|
|
---@field Notice_General UWBP_GlobalNotice_C
|
|
---@field Notice_Initial UWBP_InitialNotice_C
|
|
---@field Notice_Respawn UWBP_RespawnNotice_C
|
|
---@field Notice_Rolling UWBP_RollingNoticePanel_C
|
|
---@field Notice_Warning UWBP_WarningFrameNotice_C
|
|
---@field RespawnNoticePanel UCanvasPanel
|
|
---@field RollingNoticePanel UCanvasPanel
|
|
---@field WarningNoticePanel UCanvasPanel
|
|
--Edit Below--
|
|
local WBP_NoticeLayer = {
|
|
bInitDoOnce = false,
|
|
NoticeMap = {},
|
|
NoticeWidgets = {},
|
|
};
|
|
|
|
function WBP_NoticeLayer:Construct()
|
|
self.NoticeWidgets = {
|
|
[ECustomNoticeType.AttackWaveNotice] = self.Notice_AttackWave,
|
|
[ECustomNoticeType.AttackWaveRemainTimeNotice] = self.Notice_AttackWaveRemainTime,
|
|
[ECustomNoticeType.GeneralNotice] = self.Notice_General,
|
|
[ECustomNoticeType.RespawnNotice] = self.Notice_Respawn,
|
|
[ECustomNoticeType.InitialNotice] = self.Notice_Initial,
|
|
[ECustomNoticeType.CountDownNotice] = self.Notice_CountDown,
|
|
[ECustomNoticeType.GlobalWarningNotice] = self.Notice_Warning,
|
|
}
|
|
self.NoticeMap = {
|
|
[ECustomNoticeType.AttackWaveNotice] = {},
|
|
[ECustomNoticeType.AttackWaveRemainTimeNotice] = {},
|
|
[ECustomNoticeType.GeneralNotice] = {},
|
|
[ECustomNoticeType.RespawnNotice] = {},
|
|
[ECustomNoticeType.InitialNotice] = {},
|
|
[ECustomNoticeType.CountDownNotice] = {},
|
|
[ECustomNoticeType.GlobalWarningNotice] = {},
|
|
}
|
|
|
|
for _, NoticeWidget in pairs(self.NoticeWidgets) do
|
|
NoticeWidget:SetVisibility(ESlateVisibility.Collapsed)
|
|
end
|
|
|
|
EventSystem:AddListener(EventType.OnGameStageChanged, WBP_NoticeLayer.OnGameStageChange, self)
|
|
|
|
self:OnGameStageChange(UGCGameSystem.GameState.GameStage)
|
|
|
|
self.bCanEverTick = true
|
|
end
|
|
|
|
function WBP_NoticeLayer:Destruct()
|
|
self.bCanEverTick = false
|
|
self.NoticeWidgets = nil
|
|
self.NoticeMap = nil
|
|
EventSystem:RemoveListener(EventType.OnGameStageChanged, WBP_NoticeLayer.OnGameStageChange, self)
|
|
end
|
|
|
|
function WBP_NoticeLayer:Tick(MyGeometry, InDeltaTime)
|
|
for NoticeType, NoticeDataList in pairs(self.NoticeMap) do
|
|
if table.getCount(NoticeDataList) > 0 then
|
|
local NoticeData = NoticeDataList[1]
|
|
NoticeData.Duration = NoticeData.Duration + InDeltaTime
|
|
if NoticeData.Duration >= NoticeData.ShowTime then
|
|
self:DefaultCloseNotice(NoticeData)
|
|
table.remove(NoticeDataList, 1)
|
|
if table.getCount(NoticeDataList) > 0 then
|
|
local NextIndex, NextValue = next(NoticeDataList)
|
|
if NextIndex ~= nil and NextValue ~= nil then
|
|
self:CreateNewNotice(NextValue)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function WBP_NoticeLayer:OnGameStageChange(GameStage)
|
|
if GameStage ~= EGameStage.WaitForPlayer then
|
|
self.InitialNoticePanel:SetVisibility(ESlateVisibility.Collapsed)
|
|
else
|
|
self.InitialNoticePanel:SetVisibility(ESlateVisibility.HitTestInvisible)
|
|
end
|
|
end
|
|
|
|
function WBP_NoticeLayer:InitFromParam(NoticeType, ...)
|
|
self:ShowNotice(NoticeType, ...)
|
|
end
|
|
|
|
function WBP_NoticeLayer:ShowNotice(NoticeType, ...)
|
|
if select("#", ...) <= 0 then
|
|
return
|
|
end
|
|
|
|
local NoticeShowTime = 2.0
|
|
|
|
local Params = {}
|
|
local InParam = {...}
|
|
|
|
if NoticeType == ECustomNoticeType.GeneralNotice then
|
|
for _, value in ipairs(InParam) do
|
|
local ValueType = type(value)
|
|
if ValueType == "string" then
|
|
if Params["Txt"] == nil then
|
|
Params["Txt"] = {}
|
|
end
|
|
table.insert(Params["Txt"], value)
|
|
elseif ValueType == "boolean" then
|
|
Params["ShowAlert"] = value
|
|
elseif ValueType == "number" then
|
|
NoticeShowTime = value
|
|
end
|
|
end
|
|
elseif NoticeType == ECustomNoticeType.RollingNotice then
|
|
self.Notice_Rolling:OnReceiveRollingNoticeData(...)
|
|
return
|
|
elseif NoticeType == ECustomNoticeType.RespawnNotice then
|
|
Params["Time"] = InParam[1]
|
|
NoticeShowTime = tonumber(InParam[1]) + 0.5
|
|
elseif NoticeType == ECustomNoticeType.AttackWaveNotice then
|
|
Params["CurWave"] = InParam[1]
|
|
Params["TotalWave"] = InParam[2]
|
|
NoticeShowTime = 500.0
|
|
elseif NoticeType == ECustomNoticeType.AttackWaveRemainTimeNotice then
|
|
Params["RemainTime"] = InParam[1]
|
|
elseif NoticeType == ECustomNoticeType.InitialNotice then
|
|
if UGCGameSystem.GameState.GameStage == EGameStage.WaitForPlayer then
|
|
local WaitForPlayerRemainTime = UGCGameSystem.GameState.WaitPlayerJoinTime
|
|
if WaitForPlayerRemainTime > 0.5 then
|
|
NoticeShowTime = WaitForPlayerRemainTime - 0.5
|
|
else
|
|
return
|
|
end
|
|
else
|
|
NoticeShowTime = 0.1
|
|
end
|
|
elseif NoticeType == ECustomNoticeType.CountDownNotice then
|
|
for _, value in ipairs(InParam) do
|
|
local ValueType = type(value)
|
|
if ValueType == "string" then
|
|
Params["Txt"] = value
|
|
elseif ValueType == "number" then
|
|
Params["Time"] = value
|
|
NoticeShowTime = tonumber(value) + 0.5
|
|
elseif ValueType == "boolean" then
|
|
Params["ShowAlert"] = value
|
|
end
|
|
end
|
|
elseif NoticeType == ECustomNoticeType.GlobalWarningNotice then
|
|
local InNoticeShowTime = -1.0
|
|
for _, value in ipairs(InParam) do
|
|
local ValueType = type(value)
|
|
if ValueType == "string" then
|
|
Params["Txt"] = value
|
|
elseif ValueType == "number" then
|
|
InNoticeShowTime = tonumber(value) + 0.5
|
|
elseif ValueType == "boolean" then
|
|
Params["NeedFrame"] = value
|
|
end
|
|
end
|
|
NoticeShowTime = InNoticeShowTime > 0 and InNoticeShowTime or 5.0
|
|
end
|
|
|
|
local NoticeData = {
|
|
Type = NoticeType,
|
|
ShowTime = NoticeShowTime,
|
|
Duration = 0,
|
|
Params = Params,
|
|
}
|
|
self:ShowGameNotice(NoticeData)
|
|
end
|
|
|
|
function WBP_NoticeLayer:ShowGameNotice(InNoticeData)
|
|
local NoticeList = self.NoticeMap[InNoticeData.Type]
|
|
local NoticeWidget = self.NoticeWidgets[InNoticeData.Type]
|
|
if table.getCount(NoticeList) > 0 then
|
|
local NoticeNow = NoticeList[1]
|
|
if UE.IsValid(NoticeWidget) and NoticeNow.Type == InNoticeData.Type then
|
|
if NoticeNow.Type == ECustomNoticeType.GeneralNotice then
|
|
if self:HasSameGeneralNotice(InNoticeData) then
|
|
return
|
|
end
|
|
local NoticeNowRemainTime = NoticeNow.ShowTime - NoticeNow.Duration
|
|
if InNoticeData.ShowTime - NoticeNowRemainTime > 2.0 then
|
|
InNoticeData.ShowTime = InNoticeData.ShowTime - NoticeNowRemainTime
|
|
end
|
|
table.insert(self.NoticeMap[InNoticeData.Type], InNoticeData)
|
|
else
|
|
NoticeNow.Duration = 0.0
|
|
NoticeNow.ShowTime = InNoticeData.ShowTime
|
|
NoticeNow.Params = InNoticeData.Params
|
|
NoticeWidget:InitNoticeFromParam(InNoticeData.Params)
|
|
end
|
|
else
|
|
self:DefaultCloseNotice(InNoticeData)
|
|
self.NoticeMap[InNoticeData.Type] = {}
|
|
end
|
|
else
|
|
table.insert(self.NoticeMap[InNoticeData.Type], InNoticeData)
|
|
self:CreateNewNotice(InNoticeData)
|
|
end
|
|
end
|
|
|
|
function WBP_NoticeLayer:CreateNewNotice(NoticeData)
|
|
local NoticeType = NoticeData.Type
|
|
local NoticeWidget = self.NoticeWidgets[NoticeType]
|
|
NoticeWidget:InitNoticeFromParam(NoticeData.Params)
|
|
NoticeWidget:ShowEnterAnimation()
|
|
return NoticeWidget
|
|
end
|
|
|
|
function WBP_NoticeLayer:DefaultCloseNotice(InNoticeData)
|
|
local NoticeWidget = self.NoticeWidgets[InNoticeData.Type]
|
|
if UE.IsValid(NoticeWidget) then
|
|
NoticeWidget:DefaultClose()
|
|
end
|
|
end
|
|
|
|
function WBP_NoticeLayer:HasSameGeneralNotice(InNoticeData)
|
|
local CurNoticeTextType = type(InNoticeData.Params.Txt)
|
|
local CurNoticeText = InNoticeData.Params.Txt
|
|
for _, NoticeData in pairs(self.NoticeMap[InNoticeData.Type]) do
|
|
local PreNoticeText = NoticeData.Params.Txt
|
|
if type(PreNoticeText) == CurNoticeTextType then
|
|
if CurNoticeTextType == 'string' then
|
|
if CurNoticeText == PreNoticeText then
|
|
return true
|
|
end
|
|
else
|
|
if table.getCount(CurNoticeText) > 0 and table.getCount(CurNoticeText) == table.getCount(PreNoticeText) then
|
|
local NoticeTextStr1 = ""
|
|
local NoticeTextStr2 = ""
|
|
for i = 1 , table.getCount(CurNoticeText) do
|
|
NoticeTextStr1 = NoticeTextStr1..CurNoticeText[i]
|
|
NoticeTextStr2 = NoticeTextStr2..PreNoticeText[i]
|
|
end
|
|
if NoticeTextStr1 == NoticeTextStr2 then
|
|
return true
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
return false
|
|
end
|
|
|
|
function WBP_NoticeLayer:CloseRemainGeneralNotice()
|
|
self.bCanEverTick = false
|
|
|
|
for NoticeType, Widget in pairs(self.NoticeWidgets) do
|
|
if NoticeType ~= ECustomNoticeType.GeneralNotice then
|
|
Widget:SetVisibility(ESlateVisibility.Collapsed)
|
|
end
|
|
end
|
|
end
|
|
|
|
return WBP_NoticeLayer; |