Old Lady cleaning v2
This commit is contained in:
1 parent
78444c7aae
commit
2687b81488
1 file changed
+86
-35
@@ -1,40 +1,84 @@
|
|||||||
Scaleform = {}
|
---@class Scaleform
|
||||||
|
local Scaleform = {}
|
||||||
|
|
||||||
function SetupScaleform(scaleform, Buttons)
|
-- Constants
|
||||||
local scaleform = RequestScaleformMovie(scaleform)
|
local SCALEFORM_TIMEOUT = 5000
|
||||||
local timeout = 5000
|
local BACKGROUND_COLOR_VALUE = 80
|
||||||
|
local CONTROL_TYPE = 2
|
||||||
|
local RENDER_WAIT_TIME = 2
|
||||||
|
|
||||||
|
-- Local utility functions
|
||||||
|
local function setupButton(scaleform, button)
|
||||||
|
PushScaleformMovieFunction(scaleform, button.type)
|
||||||
|
|
||||||
|
if button.int then
|
||||||
|
PushScaleformMovieFunctionParameterInt(button.int)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Handle key index setup
|
||||||
|
if button.keyIndex then
|
||||||
|
if type(button.keyIndex) == "table" then
|
||||||
|
for _, keyCode in pairs(button.keyIndex) do
|
||||||
|
N_0xe83a3e3557a56640(GetControlInstructionalButton(CONTROL_TYPE, keyCode, true))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
ScaleformMovieMethodAddParamPlayerNameString(GetControlInstructionalButton(CONTROL_TYPE, button.keyIndex[1],
|
||||||
|
true))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Handle button name setup
|
||||||
|
if button.name then
|
||||||
|
BeginTextCommandScaleformString("STRING")
|
||||||
|
AddTextComponentScaleform(button.name)
|
||||||
|
EndTextCommandScaleformString()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Handle background color
|
||||||
|
if button.type == 'SET_BACKGROUND_COLOUR' then
|
||||||
|
for _ = 1, 4 do
|
||||||
|
PushScaleformMovieFunctionParameterInt(BACKGROUND_COLOR_VALUE)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
PopScaleformMovieFunctionVoid()
|
||||||
|
end
|
||||||
|
|
||||||
|
---Creates and sets up a scaleform movie
|
||||||
|
---@param scaleformName string The name of the scaleform to load
|
||||||
|
---@param buttons table Array of button configurations
|
||||||
|
---@return number scaleform The loaded scaleform handle
|
||||||
|
local function setupScaleform(scaleformName, buttons)
|
||||||
|
local scaleform = RequestScaleformMovie(scaleformName)
|
||||||
|
local timeout = SCALEFORM_TIMEOUT
|
||||||
|
|
||||||
|
-- Wait for scaleform to load
|
||||||
while not HasScaleformMovieLoaded(scaleform) and timeout > 0 do
|
while not HasScaleformMovieLoaded(scaleform) and timeout > 0 do
|
||||||
timeout = timeout - 1
|
timeout = timeout - 1
|
||||||
Wait(0)
|
Wait(0)
|
||||||
end
|
end
|
||||||
assert(timeout > 0, 'Scaleform failed to load')
|
|
||||||
|
if timeout <= 0 then
|
||||||
|
error('Scaleform failed to load: ' .. scaleformName)
|
||||||
|
end
|
||||||
|
|
||||||
DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 0, 0)
|
DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 0, 0)
|
||||||
for i = 1,#Buttons do
|
|
||||||
PushScaleformMovieFunction(scaleform, Buttons[i].type)
|
-- Setup each button
|
||||||
if Buttons[i].int then PushScaleformMovieFunctionParameterInt(Buttons[i].int) end
|
for _, button in ipairs(buttons) do
|
||||||
if Buttons[i].keyIndex then
|
setupButton(scaleform, button)
|
||||||
if type(Buttons[i].keyIndex) == "table" then
|
|
||||||
for _, v in pairs(Buttons[i].keyIndex) do N_0xe83a3e3557a56640(GetControlInstructionalButton(2, v, true)) end
|
|
||||||
else
|
|
||||||
ScaleformMovieMethodAddParamPlayerNameString(GetControlInstructionalButton(2, Buttons[i].keyIndex[1], true))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if Buttons[i].name then
|
|
||||||
BeginTextCommandScaleformString("STRING")
|
|
||||||
AddTextComponentScaleform(Buttons[i].name)
|
|
||||||
EndTextCommandScaleformString()
|
|
||||||
end
|
|
||||||
if Buttons[i].type == 'SET_BACKGROUND_COLOUR' then
|
|
||||||
for u = 1,4 do PushScaleformMovieFunctionParameterInt(80) end
|
|
||||||
end
|
|
||||||
PopScaleformMovieFunctionVoid()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return scaleform
|
return scaleform
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Sets up instructional buttons with default configuration
|
||||||
|
---@param buttons table Optional custom button configuration
|
||||||
|
---@return number scaleform The configured instructional buttons scaleform
|
||||||
function Scaleform.SetupInstructionalButtons(buttons)
|
function Scaleform.SetupInstructionalButtons(buttons)
|
||||||
buttons = buttons or {
|
buttons = buttons or {
|
||||||
|
-- Default button configuration commented out
|
||||||
|
-- Uncomment and modify as needed
|
||||||
-- {type = "CLEAR_ALL"},
|
-- {type = "CLEAR_ALL"},
|
||||||
-- {type = "SET_CLEAR_SPACE", int = 200},
|
-- {type = "SET_CLEAR_SPACE", int = 200},
|
||||||
-- {type = "SET_DATA_SLOT", name = config?.place_object?.name or 'Place Object:', keyIndex = config?.place_object?.key or {223}, int = 5},
|
-- {type = "SET_DATA_SLOT", name = config?.place_object?.name or 'Place Object:', keyIndex = config?.place_object?.key or {223}, int = 5},
|
||||||
@@ -46,34 +90,41 @@ function Scaleform.SetupInstructionalButtons(buttons)
|
|||||||
-- {type = "DRAW_INSTRUCTIONAL_BUTTONS"},
|
-- {type = "DRAW_INSTRUCTIONAL_BUTTONS"},
|
||||||
-- {type = "SET_BACKGROUND_COLOUR"},
|
-- {type = "SET_BACKGROUND_COLOUR"},
|
||||||
}
|
}
|
||||||
local scaleform = SetupScaleform("instructional_buttons", buttons)
|
|
||||||
|
|
||||||
return scaleform
|
return setupScaleform("instructional_buttons", buttons)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Active scaleform tracking
|
||||||
|
local activeScaleform = nil
|
||||||
|
|
||||||
local runningScaleform = nil
|
---Runs a scaleform with optional update callback
|
||||||
|
---@param scaleform number The scaleform handle to run
|
||||||
|
---@param onUpdate function Optional callback for updates during runtime
|
||||||
function Scaleform.Run(scaleform, onUpdate)
|
function Scaleform.Run(scaleform, onUpdate)
|
||||||
if runningScaleform then return end
|
if activeScaleform then return end
|
||||||
runningScaleform = scaleform
|
activeScaleform = scaleform
|
||||||
|
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
while runningScaleform do
|
while activeScaleform do
|
||||||
DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 255, 0)
|
DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 255, 0)
|
||||||
|
|
||||||
if onUpdate then
|
if onUpdate then
|
||||||
shouldQuit = onUpdate()
|
local shouldStop = onUpdate()
|
||||||
if shouldQuit then
|
if shouldStop then
|
||||||
Scaleform.Stop()
|
Scaleform.Stop()
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Wait(2)
|
|
||||||
|
Wait(RENDER_WAIT_TIME)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Stops the currently running scaleform
|
||||||
function Scaleform.Stop()
|
function Scaleform.Stop()
|
||||||
runningScaleform = nil
|
activeScaleform = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
exports("Scaleform", Scaleform)
|
exports("Scaleform", Scaleform)
|
||||||
return Scaleform
|
return Scaleform
|
||||||
Reference in new issue
Block a user