2025-03-08 13:44:05 +00:00
|
|
|
--[[
|
|
|
|
|
Text Drawing Module
|
|
|
|
|
---------------------
|
|
|
|
|
This module provides functions to display and hide text on screen using
|
|
|
|
|
various frameworks: QB, OX, GTA, and ESX.
|
|
|
|
|
]]
|
|
|
|
|
|
2025-03-01 12:58:43 +00:00
|
|
|
--- Displays text on the screen using the configured draw text system.
|
|
|
|
|
---
|
2025-03-08 13:44:05 +00:00
|
|
|
--- Depending on Config.System.drawText, this function will use different methods to
|
|
|
|
|
--- display text along with optional images/icons.
|
2025-03-01 12:58:43 +00:00
|
|
|
---
|
2025-03-08 13:44:05 +00:00
|
|
|
--- @param image string|nil Optional image/icon identifier to display with the text.
|
|
|
|
|
--- @param input table An array of strings; each string is a line of text to display.
|
|
|
|
|
--- @param style string|nil Optional style code for default GTA popups (e.g., "~g~" for green).
|
|
|
|
|
--- @param oxStyleTable table|nil Optional table specifying style parameters for the OX text UI.
|
2025-03-01 12:58:43 +00:00
|
|
|
---
|
|
|
|
|
---@usage
|
|
|
|
|
--- ```lua
|
|
|
|
|
--- drawText("img_link", { "Test line 1", "Test Line 2" }, "~g~")
|
|
|
|
|
--- ```
|
2025-03-08 13:44:05 +00:00
|
|
|
function drawText(image, input, style, oxStyleTable)
|
|
|
|
|
local text = ""
|
2025-04-01 14:15:50 +01:00
|
|
|
if not radarTable then radarTable = {} end
|
2025-03-08 13:44:05 +00:00
|
|
|
if Config.System.drawText == "qb" then
|
|
|
|
|
-- Concatenate lines for QB system with HTML line breaks.
|
|
|
|
|
for i = 1, #input do
|
|
|
|
|
text = text..input[i].."</span>"..(input[i + 1] and "<br>" or "")
|
|
|
|
|
end
|
|
|
|
|
text = text:gsub("%:", ":<span style='color:yellow'>")
|
|
|
|
|
if image then
|
|
|
|
|
text = '<img src="'..(radarTable[image] or "")..'" style="width:12px;height:12px">'..text
|
|
|
|
|
end
|
|
|
|
|
exports[QBExport]:DrawText(text, 'left')
|
2025-03-01 12:58:43 +00:00
|
|
|
|
2025-03-08 13:44:05 +00:00
|
|
|
elseif Config.System.drawText == "ox" then
|
|
|
|
|
-- Append newline spacing to each input line.
|
|
|
|
|
for k, v in pairs(input) do
|
|
|
|
|
input[k] = v.." \n"
|
|
|
|
|
end
|
|
|
|
|
lib.showTextUI(table.concat(input), { icon = (image and radarTable[image] or image) or nil, position = 'left-center', style = oxStyleTable })
|
|
|
|
|
|
|
|
|
|
elseif Config.System.drawText == "gta" then
|
|
|
|
|
-- Concatenate input lines and apply GTA style formatting.
|
|
|
|
|
for i = 1, #input do
|
|
|
|
|
if input[i] ~= "" then
|
|
|
|
|
text = text..input[i].."\n~s~"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if image then
|
|
|
|
|
text = "~BLIP_"..image.."~ "..text
|
|
|
|
|
end
|
|
|
|
|
DisplayHelpMsg(text:gsub("%:", ":~"..(style or "g").."~"))
|
2025-03-01 12:58:43 +00:00
|
|
|
|
|
|
|
|
elseif Config.System.drawText == "esx" then
|
2025-03-08 13:44:05 +00:00
|
|
|
-- ESX-based text UI uses similar HTML formatting as QB.
|
2025-03-01 12:58:43 +00:00
|
|
|
for i = 1, #input do
|
2025-03-08 13:44:05 +00:00
|
|
|
text = text..input[i].."</span>"..(input[i + 1] and "<br>" or "")
|
|
|
|
|
end
|
|
|
|
|
text = text:gsub("%:", ":<span style='color:yellow'>")
|
|
|
|
|
if image then
|
|
|
|
|
text = '<img src="'..(radarTable[image] or "")..'" style="width:12px;height:12px">'..text
|
|
|
|
|
end
|
|
|
|
|
ESX.TextUI(text, nil)
|
2025-03-11 22:41:13 +00:00
|
|
|
|
|
|
|
|
elseif Config.System.drawText == "jim" then
|
|
|
|
|
for k, v in pairs(input) do
|
|
|
|
|
input[k] = v.."<br>"
|
|
|
|
|
end
|
|
|
|
|
exports["jim-nui"]:drawText({
|
|
|
|
|
icon = nil,
|
|
|
|
|
text = text,
|
|
|
|
|
})
|
2025-04-07 20:52:59 +01:00
|
|
|
|
|
|
|
|
elseif Config.System.drawText == "red" then
|
|
|
|
|
-- Concatenate input lines and apply GTA style formatting.
|
|
|
|
|
for i = 1, #input do
|
|
|
|
|
if input[i] ~= "" then
|
|
|
|
|
text = text..input[i].."\n~q~"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
TriggerEvent("jim-redui:DrawText", text)
|
|
|
|
|
|
2025-03-08 13:44:05 +00:00
|
|
|
end
|
2025-03-01 12:58:43 +00:00
|
|
|
end
|
|
|
|
|
|
2025-03-08 13:44:05 +00:00
|
|
|
--- Hides any text currently displayed on the screen.
|
|
|
|
|
---
|
|
|
|
|
--- Clears the text using the appropriate method for the configured draw text system.
|
2025-03-01 12:58:43 +00:00
|
|
|
---
|
2025-03-08 13:44:05 +00:00
|
|
|
--- @usage
|
|
|
|
|
--- ```lua
|
|
|
|
|
--- hideText()
|
|
|
|
|
--- ```
|
2025-03-01 12:58:43 +00:00
|
|
|
function hideText()
|
|
|
|
|
if Config.System.drawText == "qb" then
|
|
|
|
|
exports[QBExport]:HideText()
|
|
|
|
|
elseif Config.System.drawText == "ox" then
|
|
|
|
|
lib.hideTextUI()
|
|
|
|
|
elseif Config.System.drawText == "gta" then
|
|
|
|
|
ClearAllHelpMessages()
|
|
|
|
|
elseif Config.System.drawText == "esx" then
|
|
|
|
|
ESX.HideUI()
|
2025-04-07 20:52:59 +01:00
|
|
|
elseif Config.System.drawText == "red" then
|
|
|
|
|
TriggerEvent("jim-redui:HideText")
|
2025-03-01 12:58:43 +00:00
|
|
|
end
|
2025-02-21 13:47:15 +00:00
|
|
|
end
|