Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(client): scaleform rewrite #138

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 35 additions & 39 deletions client/camera.lua
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
28 changes: 17 additions & 11 deletions client/heli.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -265,21 +268,24 @@ 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()

RenderScriptCams(false, false, 0, true, false) -- Return to gameplay camera
SetScaleformMovieAsNoLongerNeeded(scaleform) -- Cleanly release the scaleform
DestroyCam(cam, false)
SetNightvision(false)
SetSeethrough(false)
Expand Down
Loading