From 1094efb80c45fb8cf36272e5bffa42a3a81b0c9b Mon Sep 17 00:00:00 2001 From: Kenshin13 <63159154+Kenshiin13@users.noreply.github.com> Date: Sat, 4 Jan 2025 13:44:21 +0100 Subject: [PATCH 1/6] feat(es_extended/client/modules/scaleform): add ESX.Scaleform.Utils.RunScaleformMovieMethod util function --- .../es_extended/client/modules/scaleform.lua | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/[core]/es_extended/client/modules/scaleform.lua b/[core]/es_extended/client/modules/scaleform.lua index 66479685c..cdb6c1768 100644 --- a/[core]/es_extended/client/modules/scaleform.lua +++ b/[core]/es_extended/client/modules/scaleform.lua @@ -99,3 +99,40 @@ function ESX.Scaleform.Utils.RequestScaleformMovie(movie) return scaleform end + +--- Executes a method on a scaleform movie with optional arguments and return value. +--- The caller is responsible for disposing of the scaleform using `SetScaleformMovieAsNoLongerNeeded`. +---@param scaleform number|string # Scaleform handle or name to request the scaleform movie +---@param methodName string # The method name to call on the scaleform +---@param returnValue? boolean # Whether to return the value from the method +---@param ... number|string|boolean # Arguments to pass to the method +---@return number, number? # The scaleform handle, and the return value if `returnValue` is true +function ESX.Scaleform.Utils.RunScaleformMovieMethod(scaleform, methodName, returnValue, ...) + scaleform = type(scaleform) == "number" and scaleform or ESX.Scaleform.Utils.RequestScaleformMovie(scaleform) + BeginScaleformMovieMethod(scaleform, methodName) + + local args = { ... } + for i, arg in ipairs(args) do + local typeArg = type(arg) + + if typeArg == "number" then + if math.type(arg) == "float" then + ScaleformMovieMethodAddParamFloat(arg) + else + ScaleformMovieMethodAddParamInt(arg) + end + elseif typeArg == "string" then + ScaleformMovieMethodAddParamTextureNameString(arg) + elseif typeArg == "boolean" then + ScaleformMovieMethodAddParamBool(arg) + end + end + + if returnValue then + return scaleform, EndScaleformMovieMethodReturnValue() + end + + EndScaleformMovieMethod() + + return scaleform +end From 68dae93211855716359040a44b02cd035183968d Mon Sep 17 00:00:00 2001 From: Kenshin13 <63159154+Kenshiin13@users.noreply.github.com> Date: Sat, 4 Jan 2025 13:47:36 +0100 Subject: [PATCH 2/6] refactor(es_extended/client/modules/scaleform): refactor ESX.Scaleform.ShowFreemodeMessage --- [core]/es_extended/client/modules/scaleform.lua | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/[core]/es_extended/client/modules/scaleform.lua b/[core]/es_extended/client/modules/scaleform.lua index cdb6c1768..014c4c3c8 100644 --- a/[core]/es_extended/client/modules/scaleform.lua +++ b/[core]/es_extended/client/modules/scaleform.lua @@ -2,12 +2,7 @@ ESX.Scaleform = {} ESX.Scaleform.Utils = {} function ESX.Scaleform.ShowFreemodeMessage(title, msg, sec) - local scaleform = ESX.Scaleform.Utils.RequestScaleformMovie("MP_BIG_MESSAGE_FREEMODE") - - BeginScaleformMovieMethod(scaleform, "SHOW_SHARD_WASTED_MP_MESSAGE") - ScaleformMovieMethodAddParamTextureNameString(title) - ScaleformMovieMethodAddParamTextureNameString(msg) - EndScaleformMovieMethod() + local scaleform = ESX.Scaleform.Utils.RunScaleformMovieMethod("MP_BIG_MESSAGE_FREEMODE", "SHOW_SHARD_WASTED_MP_MESSAGE", false, title, msg) while sec > 0 do Wait(0) From 03de1afa41e9c26a243e29d9c8c1077264246189 Mon Sep 17 00:00:00 2001 From: Kenshin13 <63159154+Kenshiin13@users.noreply.github.com> Date: Sat, 4 Jan 2025 13:48:01 +0100 Subject: [PATCH 3/6] refactor(es_extended/client/modules/scaleform): refactor ESX.Scaleform.ShowBreakingNews --- .../es_extended/client/modules/scaleform.lua | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/[core]/es_extended/client/modules/scaleform.lua b/[core]/es_extended/client/modules/scaleform.lua index 014c4c3c8..ae504cff5 100644 --- a/[core]/es_extended/client/modules/scaleform.lua +++ b/[core]/es_extended/client/modules/scaleform.lua @@ -15,25 +15,9 @@ function ESX.Scaleform.ShowFreemodeMessage(title, msg, sec) end function ESX.Scaleform.ShowBreakingNews(title, msg, bottom, sec) - local scaleform = ESX.Scaleform.Utils.RequestScaleformMovie("BREAKING_NEWS") - - BeginScaleformMovieMethod(scaleform, "SET_TEXT") - ScaleformMovieMethodAddParamTextureNameString(msg) - ScaleformMovieMethodAddParamTextureNameString(bottom) - EndScaleformMovieMethod() - - BeginScaleformMovieMethod(scaleform, "SET_SCROLL_TEXT") - ScaleformMovieMethodAddParamInt(0) -- top ticker - ScaleformMovieMethodAddParamInt(0) -- Since this is the first string, start at 0 - ScaleformMovieMethodAddParamTextureNameString(title) - - EndScaleformMovieMethod() - - BeginScaleformMovieMethod(scaleform, "DISPLAY_SCROLL_TEXT") - ScaleformMovieMethodAddParamInt(0) -- Top ticker - ScaleformMovieMethodAddParamInt(0) -- Index of string - - EndScaleformMovieMethod() + local scaleform = ESX.Scaleform.Utils.RunScaleformMovieMethod("BREAKING_NEWS", "SET_TEXT", false, msg, bottom) + ESX.Scaleform.Utils.RunScaleformMovieMethod(scaleform, "SET_SCROLL_TEXT", false, 0, 0, title) + ESX.Scaleform.Utils.RunScaleformMovieMethod(scaleform, "DISPLAY_SCROLL_TEXT", false, 0, 0) while sec > 0 do Wait(0) From ceb2fd446f7f5137c0b6f296ac23982bb7d85ad2 Mon Sep 17 00:00:00 2001 From: Kenshin13 <63159154+Kenshiin13@users.noreply.github.com> Date: Sat, 4 Jan 2025 13:48:19 +0100 Subject: [PATCH 4/6] refactor(es_extended/client/modules/scaleform): refactor ESX.Scaleform.ShowPopupWarning --- [core]/es_extended/client/modules/scaleform.lua | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/[core]/es_extended/client/modules/scaleform.lua b/[core]/es_extended/client/modules/scaleform.lua index ae504cff5..438b0b186 100644 --- a/[core]/es_extended/client/modules/scaleform.lua +++ b/[core]/es_extended/client/modules/scaleform.lua @@ -30,17 +30,7 @@ function ESX.Scaleform.ShowBreakingNews(title, msg, bottom, sec) end function ESX.Scaleform.ShowPopupWarning(title, msg, bottom, sec) - local scaleform = ESX.Scaleform.Utils.RequestScaleformMovie("POPUP_WARNING") - - BeginScaleformMovieMethod(scaleform, "SHOW_POPUP_WARNING") - - ScaleformMovieMethodAddParamFloat(500.0) -- black background - ScaleformMovieMethodAddParamTextureNameString(title) - ScaleformMovieMethodAddParamTextureNameString(msg) - ScaleformMovieMethodAddParamTextureNameString(bottom) - ScaleformMovieMethodAddParamBool(true) - - EndScaleformMovieMethod() + local scaleform = ESX.Scaleform.Utils.RunScaleformMovieMethod("POPUP_WARNING", "SHOW_POPUP_WARNING", false, 500.0, title, msg, bottom, true) while sec > 0 do Wait(0) From 8844b57d17bc9134c6a6cd54a0375f1637547829 Mon Sep 17 00:00:00 2001 From: Kenshin13 <63159154+Kenshiin13@users.noreply.github.com> Date: Sat, 4 Jan 2025 13:48:47 +0100 Subject: [PATCH 5/6] refactor(es_extended/client/modules/scaleform): refactor ESX.Scaleform.ShowTrafficMovie --- [core]/es_extended/client/modules/scaleform.lua | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/[core]/es_extended/client/modules/scaleform.lua b/[core]/es_extended/client/modules/scaleform.lua index 438b0b186..1a2f1f786 100644 --- a/[core]/es_extended/client/modules/scaleform.lua +++ b/[core]/es_extended/client/modules/scaleform.lua @@ -43,11 +43,7 @@ function ESX.Scaleform.ShowPopupWarning(title, msg, bottom, sec) end function ESX.Scaleform.ShowTrafficMovie(sec) - local scaleform = ESX.Scaleform.Utils.RequestScaleformMovie("TRAFFIC_CAM") - - BeginScaleformMovieMethod(scaleform, "PLAY_CAM_MOVIE") - - EndScaleformMovieMethod() + local scaleform = ESX.Scaleform.Utils.RunScaleformMovieMethod("TRAFFIC_CAM", "PLAY_CAM_MOVIE", false) while sec > 0 do Wait(0) From 9470bfdfdd8e8ccf9bae231344fabebdb1d93c4d Mon Sep 17 00:00:00 2001 From: Kenshin13 <63159154+Kenshiin13@users.noreply.github.com> Date: Sat, 4 Jan 2025 14:06:19 +0100 Subject: [PATCH 6/6] refactor(es_extended/client/modules/scaleform): shorter function name --- [core]/es_extended/client/modules/scaleform.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/[core]/es_extended/client/modules/scaleform.lua b/[core]/es_extended/client/modules/scaleform.lua index 1a2f1f786..31d0897e9 100644 --- a/[core]/es_extended/client/modules/scaleform.lua +++ b/[core]/es_extended/client/modules/scaleform.lua @@ -2,7 +2,7 @@ ESX.Scaleform = {} ESX.Scaleform.Utils = {} function ESX.Scaleform.ShowFreemodeMessage(title, msg, sec) - local scaleform = ESX.Scaleform.Utils.RunScaleformMovieMethod("MP_BIG_MESSAGE_FREEMODE", "SHOW_SHARD_WASTED_MP_MESSAGE", false, title, msg) + local scaleform = ESX.Scaleform.Utils.RunMethod("MP_BIG_MESSAGE_FREEMODE", "SHOW_SHARD_WASTED_MP_MESSAGE", false, title, msg) while sec > 0 do Wait(0) @@ -15,9 +15,9 @@ function ESX.Scaleform.ShowFreemodeMessage(title, msg, sec) end function ESX.Scaleform.ShowBreakingNews(title, msg, bottom, sec) - local scaleform = ESX.Scaleform.Utils.RunScaleformMovieMethod("BREAKING_NEWS", "SET_TEXT", false, msg, bottom) - ESX.Scaleform.Utils.RunScaleformMovieMethod(scaleform, "SET_SCROLL_TEXT", false, 0, 0, title) - ESX.Scaleform.Utils.RunScaleformMovieMethod(scaleform, "DISPLAY_SCROLL_TEXT", false, 0, 0) + local scaleform = ESX.Scaleform.Utils.RunMethod("BREAKING_NEWS", "SET_TEXT", false, msg, bottom) + ESX.Scaleform.Utils.RunMethod(scaleform, "SET_SCROLL_TEXT", false, 0, 0, title) + ESX.Scaleform.Utils.RunMethod(scaleform, "DISPLAY_SCROLL_TEXT", false, 0, 0) while sec > 0 do Wait(0) @@ -30,7 +30,7 @@ function ESX.Scaleform.ShowBreakingNews(title, msg, bottom, sec) end function ESX.Scaleform.ShowPopupWarning(title, msg, bottom, sec) - local scaleform = ESX.Scaleform.Utils.RunScaleformMovieMethod("POPUP_WARNING", "SHOW_POPUP_WARNING", false, 500.0, title, msg, bottom, true) + local scaleform = ESX.Scaleform.Utils.RunMethod("POPUP_WARNING", "SHOW_POPUP_WARNING", false, 500.0, title, msg, bottom, true) while sec > 0 do Wait(0) @@ -43,7 +43,7 @@ function ESX.Scaleform.ShowPopupWarning(title, msg, bottom, sec) end function ESX.Scaleform.ShowTrafficMovie(sec) - local scaleform = ESX.Scaleform.Utils.RunScaleformMovieMethod("TRAFFIC_CAM", "PLAY_CAM_MOVIE", false) + local scaleform = ESX.Scaleform.Utils.RunMethod("TRAFFIC_CAM", "PLAY_CAM_MOVIE", false) while sec > 0 do Wait(0) @@ -72,7 +72,7 @@ end ---@param returnValue? boolean # Whether to return the value from the method ---@param ... number|string|boolean # Arguments to pass to the method ---@return number, number? # The scaleform handle, and the return value if `returnValue` is true -function ESX.Scaleform.Utils.RunScaleformMovieMethod(scaleform, methodName, returnValue, ...) +function ESX.Scaleform.Utils.RunMethod(scaleform, methodName, returnValue, ...) scaleform = type(scaleform) == "number" and scaleform or ESX.Scaleform.Utils.RequestScaleformMovie(scaleform) BeginScaleformMovieMethod(scaleform, methodName)