From c2ab7e828dc9b593d2245269d3740d428306da41 Mon Sep 17 00:00:00 2001 From: Zaurzo <101999193+Zaurzo@users.noreply.github.com> Date: Sun, 14 May 2023 16:24:51 -0400 Subject: [PATCH 1/2] Add AddLegacyType & GetLegacyTypes --- garrysmod/lua/includes/modules/notification.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/garrysmod/lua/includes/modules/notification.lua b/garrysmod/lua/includes/modules/notification.lua index 2e650a2334..c490a3a405 100644 --- a/garrysmod/lua/includes/modules/notification.lua +++ b/garrysmod/lua/includes/modules/notification.lua @@ -84,6 +84,21 @@ function AddLegacy( text, type, length ) end +function AddLegacyType( legacyName, materialName ) + if ( !isstring( legacyName ) ) then error( "bad argument #1 to 'AddLegacyType' (string expected, got " .. type( legacyName ) .. ")", 2 ) return end + if ( !isstring( materialName ) ) then error( "bad argument #2 to 'AddLegacyType' (string expected, got " .. type( materialName ) .. ")", 2 ) return end + + local mat = Material( materialName ) + + if ( !mat || mat:IsError() ) then return end + + NoticeMaterial[ legacyName ] = mat +end + +function GetLegacyTypes() + return NoticeMaterial +end + -- This is ugly because it's ripped straight from the old notice system local function UpdateNotice( pnl, total_h ) From 6b5cb608a38307c3995031bc841edcac6bae1a26 Mon Sep 17 00:00:00 2001 From: Zaurzo <101999193+Zaurzo@users.noreply.github.com> Date: Wed, 22 Nov 2023 22:22:13 -0500 Subject: [PATCH 2/2] Add proper return and fallback - Return the created IMaterial for the icon on success - If the material is nil or an error, fallback to the generic notify icon and return false --- garrysmod/lua/includes/modules/notification.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/garrysmod/lua/includes/modules/notification.lua b/garrysmod/lua/includes/modules/notification.lua index c490a3a405..4e5a6ec18d 100644 --- a/garrysmod/lua/includes/modules/notification.lua +++ b/garrysmod/lua/includes/modules/notification.lua @@ -84,15 +84,23 @@ function AddLegacy( text, type, length ) end +local matNotifyGeneric = NoticeMaterial[ NOTIFY_GENERIC ] + function AddLegacyType( legacyName, materialName ) if ( !isstring( legacyName ) ) then error( "bad argument #1 to 'AddLegacyType' (string expected, got " .. type( legacyName ) .. ")", 2 ) return end if ( !isstring( materialName ) ) then error( "bad argument #2 to 'AddLegacyType' (string expected, got " .. type( materialName ) .. ")", 2 ) return end local mat = Material( materialName ) - if ( !mat || mat:IsError() ) then return end + if ( !mat || mat:IsError() ) then + NoticeMaterial[ legacyName ] = matNotifyGeneric + + return false + end NoticeMaterial[ legacyName ] = mat + + return mat end function GetLegacyTypes()