feat(esx_lib/scaleform): move scaleform helpers to xLib

This commit is contained in:
ASTROWwwW
2026-06-16 21:03:41 +02:00
parent f4af0d90bd
commit 6a72181992
3 changed files with 56 additions and 26 deletions
+11
View File
@@ -46,3 +46,14 @@ ESX.Streaming = {
RequestAnimDict = xLib.streaming.requestAnimDict,
RequestWeaponAsset = xLib.streaming.requestWeaponAsset,
}
ESX.Scaleform = {
ShowFreemodeMessage = xLib.scaleform.showFreemodeMessage,
ShowBreakingNews = xLib.scaleform.showBreakingNews,
ShowPopupWarning = xLib.scaleform.showPopupWarning,
ShowTrafficMovie = xLib.scaleform.showTrafficMovie,
Utils = {
RequestScaleformMovie = xLib.scaleform.utils.requestScaleformMovie,
RunMethod = xLib.scaleform.utils.runMethod,
},
}
-1
View File
@@ -57,7 +57,6 @@ client_scripts {
'client/modules/death.lua',
'client/modules/npwd.lua',
'client/modules/interactions.lua',
'client/modules/scaleform.lua',
}
ui_page {
@@ -1,22 +1,12 @@
ESX.Scaleform = {}
ESX.Scaleform.Utils = {}
---@class scaleformlib
xLib.scaleform = {}
xLib.scaleform.utils = {}
function ESX.Scaleform.ShowFreemodeMessage(title, msg, sec)
local scaleform = ESX.Scaleform.Utils.RunMethod("MP_BIG_MESSAGE_FREEMODE", "SHOW_SHARD_WASTED_MP_MESSAGE", false, title, msg)
local endTime = GetGameTimer() + (sec * 1000)
while GetGameTimer() < endTime do
Wait(0)
DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 255, 0)
end
SetScaleformMovieAsNoLongerNeeded(scaleform)
end
function ESX.Scaleform.ShowBreakingNews(title, msg, bottom, sec)
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)
---@param title string
---@param msg string
---@param sec number
function xLib.scaleform.showFreemodeMessage(title, msg, sec)
local scaleform = xLib.scaleform.utils.runMethod("MP_BIG_MESSAGE_FREEMODE", "SHOW_SHARD_WASTED_MP_MESSAGE", false, title, msg)
local endTime = GetGameTimer() + (sec * 1000)
while GetGameTimer() < endTime do
@@ -27,8 +17,14 @@ function ESX.Scaleform.ShowBreakingNews(title, msg, bottom, sec)
SetScaleformMovieAsNoLongerNeeded(scaleform)
end
function ESX.Scaleform.ShowPopupWarning(title, msg, bottom, sec)
local scaleform = ESX.Scaleform.Utils.RunMethod("POPUP_WARNING", "SHOW_POPUP_WARNING", false, 500.0, title, msg, bottom, true)
---@param title string
---@param msg string
---@param bottom string
---@param sec number
function xLib.scaleform.showBreakingNews(title, msg, bottom, sec)
local scaleform = xLib.scaleform.utils.runMethod("BREAKING_NEWS", "SET_TEXT", false, msg, bottom)
xLib.scaleform.utils.runMethod(scaleform, "SET_SCROLL_TEXT", false, 0, 0, title)
xLib.scaleform.utils.runMethod(scaleform, "DISPLAY_SCROLL_TEXT", false, 0, 0)
local endTime = GetGameTimer() + (sec * 1000)
while GetGameTimer() < endTime do
@@ -39,8 +35,12 @@ function ESX.Scaleform.ShowPopupWarning(title, msg, bottom, sec)
SetScaleformMovieAsNoLongerNeeded(scaleform)
end
function ESX.Scaleform.ShowTrafficMovie(sec)
local scaleform = ESX.Scaleform.Utils.RunMethod("TRAFFIC_CAM", "PLAY_CAM_MOVIE", false)
---@param title string
---@param msg string
---@param bottom string
---@param sec number
function xLib.scaleform.showPopupWarning(title, msg, bottom, sec)
local scaleform = xLib.scaleform.utils.runMethod("POPUP_WARNING", "SHOW_POPUP_WARNING", false, 500.0, title, msg, bottom, true)
local endTime = GetGameTimer() + (sec * 1000)
while GetGameTimer() < endTime do
@@ -51,7 +51,22 @@ function ESX.Scaleform.ShowTrafficMovie(sec)
SetScaleformMovieAsNoLongerNeeded(scaleform)
end
function ESX.Scaleform.Utils.RequestScaleformMovie(movie)
---@param sec number
function xLib.scaleform.showTrafficMovie(sec)
local scaleform = xLib.scaleform.utils.runMethod("TRAFFIC_CAM", "PLAY_CAM_MOVIE", false)
local endTime = GetGameTimer() + (sec * 1000)
while GetGameTimer() < endTime do
Wait(0)
DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 255, 0)
end
SetScaleformMovieAsNoLongerNeeded(scaleform)
end
---@param movie string
---@return number
function xLib.scaleform.utils.requestScaleformMovie(movie)
local scaleform = RequestScaleformMovie(movie)
while not HasScaleformMovieLoaded(scaleform) do
@@ -68,8 +83,11 @@ 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.RunMethod(scaleform, methodName, returnValue, ...)
scaleform = type(scaleform) == "number" and scaleform or ESX.Scaleform.Utils.RequestScaleformMovie(scaleform)
function xLib.scaleform.utils.runMethod(scaleform, methodName, returnValue, ...)
if type(scaleform) ~= "number" then
scaleform = xLib.scaleform.utils.requestScaleformMovie(scaleform)
end
BeginScaleformMovieMethod(scaleform, methodName)
local args = { ... }
@@ -97,3 +115,5 @@ function ESX.Scaleform.Utils.RunMethod(scaleform, methodName, returnValue, ...)
return scaleform
end
return xLib.scaleform