77]]
88CreateThread (function ()Config .LoadPlugin (" recordPrinter" ,function (pluginConfig )
99local printQueue = {}
10+ local function prettyFileName (path ,opts )
11+ opts = opts or {}
12+ local max_len = opts .max_len == nil and 40 or opts .max_len
13+ local keep_ext = opts .keep_ext or false
14+ local dash_style = opts .dash_style or " spaced-dash" -- choices: space | spaced-dash | keep
15+
16+ -- 1) take just the last path segment
17+ local base = path :match (" ([^/\\ ]+)$" )or path
18+
19+ -- 2) optionally drop extension
20+ local ext = base :match (" %.[%w]+$" )or " "
21+ local name = keep_ext and base or base :gsub (" %.[%w]+$" ," " )
22+
23+ -- 3) strip leading UUID (8-4-4-4-12) + common separators
24+ local uuidPattern = " ^(%x%x%x%x%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%x%x%x%x%x%x%x%x)[%s%-%_]*"
25+ name = name :gsub (uuidPattern ," " )
26+
27+ -- 4) normalize separators
28+ name = name :gsub (" [_]+" ," " )-- underscores -> spaces
29+ if dash_style == " space" then
30+ name = name :gsub (" %s*%-%s*" ," " )
31+ elseif dash_style == " spaced-dash" then
32+ name = name :gsub (" %s*%-%s*" ," -" )
33+ else
34+ -- "keep": leave dashes as-is
35+ end
36+
37+ -- 5) trim & collapse whitespace
38+ name = name :gsub (" %s+" ," " ):gsub (" ^%s+" ," " ):gsub (" %s+$" ," " )
39+
40+ -- 6) clip if too long
41+ if max_len and # name > max_len then
42+ name = name :sub (1 ,max_len - 1 ).. " …"
43+ end
44+
45+ if keep_ext and ext ~= " " then
46+ name = name .. ext
47+ end
48+
49+ -- fallback
50+ if name == " " then name = " (untitled)" end
51+ return name
52+ end
1053RegisterNetEvent (' SonoranCAD::recordPrinter:PrintQueue' ,function (data )
1154table.insert (printQueue ,data )
1255-- Check queue size
@@ -24,11 +67,21 @@ CreateThread(function() Config.LoadPlugin("recordPrinter", function(pluginConfig
2467 })
2568end )
2669RegisterCommand (pluginConfig .printQueueCommand ,function ()
70+ if # printQueue == 0 then
71+ sendChat ({255 ,200 ,0 }," Your print queue is empty." )
72+ return
73+ end
74+
2775for i ,url in ipairs (printQueue )do
76+ local rawPath = url
77+ if type (rawPath )~= ' string' then
78+ rawPath = tostring (rawPath or ' ' )
79+ end
80+ local displayName = prettyFileName (rawPath , {keep_ext = true ,max_len = pluginConfig .queueDisplayMaxLength or 48 })
2881TriggerEvent (' chat:addMessage' , {
2982color = {0 ,255 ,0 },
3083multiline = true ,
31- args = {" Record Printer" ," Record" .. i .. " :" .. url }
84+ args = {" Record Printer" ," Record" .. i .. " :" .. displayName }
3285 })
3386end
3487end ,false )
@@ -109,7 +162,7 @@ CreateThread(function() Config.LoadPlugin("recordPrinter", function(pluginConfig
109162return isInVehicleWithPrinter (4.0 )or isNearPrinterObject (3.5 )or isAtPrinterCoord (3.5 )
110163end
111164
112- local function sendChat (color ,msg )
165+ function sendChat (color ,msg )
113166TriggerEvent (' chat:addMessage' , {
114167color = color or {255 ,255 ,255 },
115168multiline = true ,
@@ -156,8 +209,15 @@ CreateThread(function() Config.LoadPlugin("recordPrinter", function(pluginConfig
156209
157210-- For now, just notify and remove it from the queue after "printing"
158211sendChat ({0 ,255 ,0 }, (" Printing: queue #%d" ):format (idx ))
212+ SendNuiMessage (json .encode ({action = ' openUI' ,link = url ,first = true ,type = ' pdf' ,recordPrinter = true }))
213+ SetNuiFocus (true ,true )
159214table.remove (printQueue ,idx )
160215end ,false )
216+ TriggerEvent (' chat:addSuggestion' ,' /' .. pluginConfig .printCommand ,' Print a record from your print queue.' , {
217+ {name = ' index' ,help = ' The position in your print queue to print (see /' .. pluginConfig .printQueueCommand .. ' )' }
218+ })
219+ TriggerEvent (' chat:addSuggestion' ,' /' .. pluginConfig .printQueueCommand ,' View your current print queue.' )
220+ TriggerEvent (' chat:addSuggestion' ,' /' .. pluginConfig .clearPrintQueueCommand ,' Clear your current print queue.' )
161221-- State
162222local holdingDoc = false
163223local doc_link = nil
@@ -287,11 +347,10 @@ CreateThread(function() Config.LoadPlugin("recordPrinter", function(pluginConfig
287347DeleteEntity (e .entityObject )
288348end
289349TriggerServerEvent (' SonoranPDF:destroyWorldPDF' ,closestId )
290- SendNuiMessage (json .encode ({action = ' openui ' ,link = e .pdf_link ,first = false ,type = ' pdf' }))
350+ SendNuiMessage (json .encode ({action = ' openUI ' ,link = e .pdf_link ,first = false ,type = ' pdf' , recordPrinter = true }))
291351ToggleDocHold (true )
292352SetNuiFocusKeepInput (true )
293353table.remove (WorldDocs ,closestId )
294- DisplayNotification (pluginConfig .translations .putPhotoAway )
295354end
296355
297356-- G: destroy in world
@@ -315,30 +374,27 @@ CreateThread(function() Config.LoadPlugin("recordPrinter", function(pluginConfig
315374-- QB: item.info.pdf_link
316375local link = (item and item .info and item .info .pdf_link )or nil
317376if not link or link == ' ' then return end
318- SendNuiMessage (json .encode ({action = ' openui ' ,link = link ,first = false ,type = ' pdf' }))
377+ SendNuiMessage (json .encode ({action = ' openUI ' ,link = link ,first = false ,type = ' pdf' , recordPrinter = true }))
319378ToggleDocHold (true )
320- SetNuiFocusKeepInput (true )
321- DisplayNotification (pluginConfig .translations .putPhotoAway )
379+ SetNuiFocus (true ,true )
322380end )
323381
324382RegisterNetEvent (' sonoran:lookpdf:esx' ,function (item )
325383-- ESX (ox): entry.metadata.pdf_link
326384local link = (item and item .metadata and item .metadata .pdf_link )or nil
327385if not link or link == ' ' then return end
328- SendNuiMessage (json .encode ({action = ' openui ' ,link = link ,first = false ,type = ' pdf' }))
386+ SendNuiMessage (json .encode ({action = ' openUI ' ,link = link ,first = false ,type = ' pdf' , recordPrinter = true }))
329387ToggleDocHold (true )
330- SetNuiFocusKeepInput (true )
331- DisplayNotification (pluginConfig .translations .putPhotoAway )
388+ SetNuiFocus (true ,true )
332389end )
333390
334391-- Optional: direct open (e.g., when a brand-new PDF is produced and you want it to be “First” so putting away adds to inventory)
335392RegisterNetEvent (' SonoranPDF:Open' ,function (url )
336393if not url or url == ' ' then return end
337394doc_link = url
338- SendNuiMessage (json .encode ({action = ' openui ' ,link = url ,first = true ,type = ' pdf' }))-- first=true -> inventory put-away
395+ SendNuiMessage (json .encode ({action = ' openUI ' ,link = url ,first = true ,type = ' pdf' , recordPrinter = true }))-- first=true -> inventory put-away
339396ToggleDocHold (true )
340- SetNuiFocusKeepInput (true )
341- DisplayNotification (pluginConfig .translations .pressToDrop )
397+ SetNuiFocus (true ,true )
342398end )
343399
344400-- =========================
@@ -422,7 +478,7 @@ CreateThread(function() Config.LoadPlugin("recordPrinter", function(pluginConfig
422478if holdingDoc then
423479DisableControlAction (0 ,202 ,true )-- BACK
424480if IsDisabledControlJustPressed (0 ,202 )then
425- SendNuiMessage (json .encode ({action = ' closeui' }))
481+ SendNuiMessage (json .encode ({action = ' closeui' , recordPrinter = true }))
426482DisableControlAction (0 ,202 ,false )
427483SetNuiFocus (false ,false )
428484end
@@ -464,4 +520,4 @@ CreateThread(function() Config.LoadPlugin("recordPrinter", function(pluginConfig
464520map_net = nil
465521end
466522end
467- end )end )
523+ end )end )