From fccee53d0139995ccbac630a84e85a0f346e5be4 Mon Sep 17 00:00:00 2001 From: Kasey FItton Date: Thu, 26 Sep 2024 00:23:12 +0100 Subject: [PATCH 1/2] refactor(client): scaleform rewrite refactors scaleform usage to a use a handler --- client/camera.lua | 74 ++++++++++++++++++++++------------------------- client/heli.lua | 29 ++++++++++++------- 2 files changed, 53 insertions(+), 50 deletions(-) diff --git a/client/camera.lua b/client/camera.lua index fb74fac..5488b14 100644 --- a/client/camera.lua +++ b/client/camera.lua @@ -1,7 +1,7 @@ local config = require 'config.client'.securityCameras local currentCamIndex = 0 local createdCam = 0 -local currentScaleform = -1 +local currentScaleform = nil local function getCurrentTime() local hours = GetClockHours() @@ -15,34 +15,23 @@ local function getCurrentTime() return tostring(hours .. ':' .. minutes) end -local function createInstructionalScaleform(scaleform) - scaleform = lib.requestScaleformMovie(scaleform) - PushScaleformMovieFunction(scaleform, 'CLEAR_ALL') - PopScaleformMovieFunctionVoid() - - PushScaleformMovieFunction(scaleform, 'SET_CLEAR_SPACE') - PushScaleformMovieFunctionParameterInt(200) - PopScaleformMovieFunctionVoid() - - PushScaleformMovieFunction(scaleform, 'SET_DATA_SLOT') - PushScaleformMovieFunctionParameterInt(1) - ScaleformMovieMethodAddParamPlayerNameString(GetControlInstructionalButton(1, 194, true)) - BeginTextCommandScaleformString('STRING') - AddTextComponentScaleform(locale('info.close_camera')) - EndTextCommandScaleformString() - PopScaleformMovieFunctionVoid() - - PushScaleformMovieFunction(scaleform, 'DRAW_INSTRUCTIONAL_BUTTONS') - PopScaleformMovieFunctionVoid() - - PushScaleformMovieFunction(scaleform, 'SET_BACKGROUND_COLOUR') - PushScaleformMovieFunctionParameterInt(0) - PushScaleformMovieFunctionParameterInt(0) - PushScaleformMovieFunctionParameterInt(0) - PushScaleformMovieFunctionParameterInt(80) - PopScaleformMovieFunctionVoid() - - return scaleform +local function setupIntructionalScaleform() + if not currentScaleform then + return + end + + -- empty the scaleform + currentScaleform:Method('CLEAR_ALL') + currentScaleform:MethodArgs('SET_CLEAR_SPACE', { 200 }) + + -- add the button + currentScaleform:MethodArgs('SET_DATA_SLOT', { 1, GetControlInstructionalButton(1, 177, true), 'Close Camera' }) + + -- draw the buttons + currentScaleform:Method('DRAW_INSTRUCTIONAL_BUTTONS') + + -- set the background colour + currentScaleform:MethodArgs("SET_BACKGROUND_COLOUR", { 0, 0, 0, 80 }) end local function changeSecurityCamera(x, y, z, r) @@ -51,9 +40,9 @@ local function changeSecurityCamera(x, y, z, r) createdCam = 0 end - if currentScaleform ~= -1 then - SetScaleformMovieAsNoLongerNeeded(currentScaleform) - currentScaleform = -1 + if currentScaleform then + currentScaleform:Dispose() + currentScaleform = nil end local cam = CreateCam('DEFAULT_SCRIPTED_CAMERA', true) @@ -62,15 +51,22 @@ local function changeSecurityCamera(x, y, z, r) RenderScriptCams(true, false, 0, true, true) Wait(250) createdCam = cam - currentScaleform = createInstructionalScaleform('instructional_buttons') + + currentScaleform = qbx.newScaleform('instructional_buttons') -- create the scaleform + setupIntructionalScaleform() -- setup the scaleform + currentScaleform:Draw(true) -- draw the scaleform end local function closeSecurityCamera() DestroyCam(createdCam, false) RenderScriptCams(false, false, 1, true, true) createdCam = 0 - SetScaleformMovieAsNoLongerNeeded(currentScaleform) - currentScaleform = -1 + + if currentScaleform then + currentScaleform:Dispose() + currentScaleform = nil + end + ClearTimecycleModifier() SetFocusEntity(cache.ped) if config.hideRadar then @@ -139,12 +135,12 @@ RegisterNetEvent('police:client:SetCamera', function(key, isOnline) elseif type(key) == 'number' then config.cameras[key].isOnline = isOnline else - error('police:client:SetCamera did not receive the right type of key\nreceived type: ' .. type(key) .. '\nreceived value: ' .. key) + error('police:client:SetCamera did not receive the right type of key\nreceived type: ' .. + type(key) .. '\nreceived value: ' .. key) end end) local function listenForCamControls() - DrawScaleformMovieFullscreen(currentScaleform, 255, 255, 255, 255, 0) SetTimecycleModifier('scanline_cam_cheap') SetTimecycleModifierStrength(1.0) @@ -199,11 +195,11 @@ end CreateThread(function() while true do - if createdCam == 0 or currentScaleform == -1 then + if createdCam == 0 or not currentScaleform then Wait(2000) else listenForCamControls() Wait(0) end end -end) +end) \ No newline at end of file diff --git a/client/heli.lua b/client/heli.lua index 1644e83..37368a6 100644 --- a/client/heli.lua +++ b/client/heli.lua @@ -227,23 +227,26 @@ local function handleInVehicle() if heliCam then SetTimecycleModifier('heliGunCam') SetTimecycleModifierStrength(0.3) - local scaleform = lib.requestScaleformMovie('HELI_CAM') + local cam = CreateCam('DEFAULT_SCRIPTED_FLY_CAMERA', true) AttachCamToEntity(cam, cache.vehicle, 0.0,0.0,-1.5, true) SetCamRot(cam, 0.0, 0.0, GetEntityHeading(cache.vehicle), 2) SetCamFov(cam, fov) RenderScriptCams(true, false, 0, true, false) - PushScaleformMovieFunction(scaleform, 'SET_CAM_LOGO') - PushScaleformMovieFunctionParameterInt(0) -- 0 for nothing, 1 for LSPD logo - PopScaleformMovieFunctionVoid() + + local scaleform = qbx.newScaleform("HELI_CAM") + scaleform:MethodArgs('SET_CAM_LOGO', 0) -- 0 for nothing, 1 for LSPD logo + lockedOnVehicle = nil while heliCam and not IsEntityDead(cache.ped) and cache.vehicle and isHeliHighEnough(cache.vehicle) do if IsControlJustPressed(0, toggleHeliCam) then -- Toggle Helicam turnOffCam() end + if IsControlJustPressed(0, toggleVision) then changeVision() end + local zoomValue = 0 if lockedOnVehicle then if DoesEntityExist(lockedOnVehicle) then @@ -265,21 +268,25 @@ local function handleInVehicle() vehicleDetected = getVehicleInView(cam) vehicleLockState = DoesEntityExist(vehicleDetected) and VEHICLE_LOCK_STATE.scanning or VEHICLE_LOCK_STATE.dormant end + handleZoom(cam) hideHudThisFrame() - PushScaleformMovieFunction(scaleform, 'SET_ALT_FOV_HEADING') - PushScaleformMovieFunctionParameterFloat(GetEntityCoords(cache.vehicle).z) - PushScaleformMovieFunctionParameterFloat(zoomValue) - PushScaleformMovieFunctionParameterFloat(GetCamRot(cam, 2).z) - PopScaleformMovieFunctionVoid() - DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 255, 0) + + local entityCoords = GetEntityCoords(cache.vehicle) + local camRot = GetCamRot(cam, 2).z + scaleform:MethodArgs('SET_ALT_FOV_HEADING', entityCoords, zoomValue, camRot) + Wait(0) end + heliCam = false ClearTimecycleModifier() fov = (FOV_MAX + FOV_MIN) * 0.5 -- reset to starting zoom level + + scaleform:Dispose() + scaleform = nil + RenderScriptCams(false, false, 0, true, false) -- Return to gameplay camera - SetScaleformMovieAsNoLongerNeeded(scaleform) -- Cleanly release the scaleform DestroyCam(cam, false) SetNightvision(false) SetSeethrough(false) From 1b6dc01a71d313127dbba00074fbde350efa5665 Mon Sep 17 00:00:00 2001 From: Kasey FItton Date: Thu, 26 Sep 2024 00:27:46 +0100 Subject: [PATCH 2/2] tweak(client/heli): lint issue --- client/heli.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/client/heli.lua b/client/heli.lua index 37368a6..93abdee 100644 --- a/client/heli.lua +++ b/client/heli.lua @@ -284,7 +284,6 @@ local function handleInVehicle() fov = (FOV_MAX + FOV_MIN) * 0.5 -- reset to starting zoom level scaleform:Dispose() - scaleform = nil RenderScriptCams(false, false, 0, true, false) -- Return to gameplay camera DestroyCam(cam, false)