mirror of
https://github.com/jimathy/jim_bridge.git
synced 2026-08-17 05:56:02 +01:00
Follow same format for notify.lua and drawText.lua
place functions into a table to better handle compatibility of each scripts function
This commit is contained in:
@@ -5,6 +5,102 @@
|
||||
various frameworks: QB, OX, GTA, and ESX.
|
||||
]]
|
||||
|
||||
-- Text system handlers
|
||||
local textHandlers = {
|
||||
qb = {
|
||||
show = function(text, image)
|
||||
if image then
|
||||
text = '<img src="'..(radarTable[image] or "")..'" style="width:12px;height:12px">'..text
|
||||
end
|
||||
exports[QBExport]:DrawText(text, 'left')
|
||||
end,
|
||||
hide = function()
|
||||
exports[QBExport]:HideText()
|
||||
end
|
||||
},
|
||||
|
||||
ox = {
|
||||
show = function(input, image, oxStyleTable)
|
||||
local inputCount = #input
|
||||
for i = 1, inputCount do
|
||||
input[i] = input[i] .. (i ~= inputCount and " \n" or "")
|
||||
end
|
||||
lib.showTextUI(table.concat(input), {
|
||||
icon = (image and radarTable[image] or image) or nil,
|
||||
position = 'left-center',
|
||||
style = oxStyleTable
|
||||
})
|
||||
end,
|
||||
hide = function()
|
||||
lib.hideTextUI()
|
||||
end
|
||||
},
|
||||
|
||||
lation = {
|
||||
show = function(input, image)
|
||||
local inputCount = #input
|
||||
for i = 1, inputCount do
|
||||
input[i] = input[i] .. (i ~= inputCount and " \n" or "")
|
||||
end
|
||||
exports.lation_ui:showText({
|
||||
description = table.concat(input),
|
||||
keybind = nil,
|
||||
icon = (image and radarTable[image] or image) or nil,
|
||||
iconColor = '#3B82F6',
|
||||
position = 'left-center'
|
||||
})
|
||||
end,
|
||||
hide = function()
|
||||
exports.lation_ui:hideText()
|
||||
end
|
||||
},
|
||||
|
||||
gta = {
|
||||
show = function(input, image, style)
|
||||
local text = ""
|
||||
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") .. "~"))
|
||||
end,
|
||||
hide = function()
|
||||
ClearAllHelpMessages()
|
||||
end
|
||||
},
|
||||
|
||||
esx = {
|
||||
show = function(text, image)
|
||||
if image then
|
||||
text = '<img src="'..(radarTable[image] or "")..'" style="width:12px;height:12px">'..text
|
||||
end
|
||||
ESX.TextUI(text, nil)
|
||||
end,
|
||||
hide = function()
|
||||
ESX.HideUI()
|
||||
end
|
||||
},
|
||||
|
||||
red = {
|
||||
show = function(input)
|
||||
local text = ""
|
||||
for i = 1, #input do
|
||||
if input[i] ~= "" then
|
||||
text = text .. input[i] .. "\n~q~"
|
||||
end
|
||||
end
|
||||
TriggerEvent("jim-redui:DrawText", text)
|
||||
end,
|
||||
hide = function()
|
||||
TriggerEvent("jim-redui:HideText")
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
--- Displays text on the screen using the configured draw text system.
|
||||
---
|
||||
--- Depending on Config.System.drawText, this function will use different methods to
|
||||
@@ -20,73 +116,33 @@
|
||||
--- drawText("img_link", { "Test line 1", "Test Line 2" }, "~g~")
|
||||
--- ```
|
||||
function drawText(image, input, style, oxStyleTable)
|
||||
local text = ""
|
||||
if not radarTable then radarTable = {} end
|
||||
if Config.System.drawText == "qb" then
|
||||
-- Concatenate lines for QB system with HTML line breaks.
|
||||
|
||||
local systemType = Config.System.drawText
|
||||
local handler = textHandlers[systemType]
|
||||
|
||||
if not handler then return end
|
||||
|
||||
if systemType == "qb" or systemType == "esx" then
|
||||
-- Concatenate lines for QB/ESX system with HTML line breaks.
|
||||
local text = ""
|
||||
for i = 1, #input do
|
||||
text = text..input[i].."</span>"..(input[i + 1] and "<br>" or "")
|
||||
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')
|
||||
handler.show(text, image)
|
||||
|
||||
elseif Config.System.drawText == "ox" then
|
||||
-- Append newline spacing to each input line.
|
||||
local inputnum = countTable(input)
|
||||
for k, v in pairs(input) do
|
||||
input[k] = v..(inputnum ~= k and " \n" or "")
|
||||
end
|
||||
lib.showTextUI(table.concat(input), { icon = (image and radarTable[image] or image) or nil, position = 'left-center', style = oxStyleTable })
|
||||
elseif systemType == "ox" then
|
||||
handler.show(input, image, oxStyleTable)
|
||||
|
||||
elseif Config.System.drawText == "lation" then
|
||||
local inputnum = countTable(input)
|
||||
for k, v in pairs(input) do
|
||||
input[k] = v..(inputnum ~= k and " \n" or "")
|
||||
end
|
||||
exports.lation_ui:showText({
|
||||
--title = " ",
|
||||
description = table.concat(input),
|
||||
keybind = nil,
|
||||
icon = (image and radarTable[image] or image) or nil,
|
||||
iconColor = '#3B82F6',
|
||||
position = 'left-center'
|
||||
})
|
||||
elseif systemType == "lation" then
|
||||
handler.show(input, image)
|
||||
|
||||
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").."~"))
|
||||
|
||||
elseif Config.System.drawText == "esx" then
|
||||
-- ESX-based text UI uses similar HTML formatting as QB.
|
||||
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
|
||||
ESX.TextUI(text, nil)
|
||||
|
||||
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)
|
||||
elseif systemType == "gta" then
|
||||
handler.show(input, image, style)
|
||||
|
||||
elseif systemType == "red" then
|
||||
handler.show(input)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -99,17 +155,8 @@ end
|
||||
--- hideText()
|
||||
--- ```
|
||||
function hideText()
|
||||
if Config.System.drawText == "qb" then
|
||||
exports[QBExport]:HideText()
|
||||
elseif Config.System.drawText == "ox" then
|
||||
lib.hideTextUI()
|
||||
elseif Config.System.drawText == "lation" then
|
||||
exports.lation_ui:hideText()
|
||||
elseif Config.System.drawText == "gta" then
|
||||
ClearAllHelpMessages()
|
||||
elseif Config.System.drawText == "esx" then
|
||||
ESX.HideUI()
|
||||
elseif Config.System.drawText == "red" then
|
||||
TriggerEvent("jim-redui:HideText")
|
||||
local handler = textHandlers[Config.System.drawText]
|
||||
if handler and handler.hide then
|
||||
handler.hide()
|
||||
end
|
||||
end
|
||||
@@ -8,10 +8,79 @@
|
||||
• okok
|
||||
• qb
|
||||
• ox
|
||||
• red (default)
|
||||
• gta (default)
|
||||
• qs-interface
|
||||
• lation
|
||||
• esx
|
||||
]]
|
||||
|
||||
local notifyFunc = {
|
||||
okok = {
|
||||
client = function(title, message, type)
|
||||
TriggerEvent('okokNotify:Alert', title, message, 6000, type)
|
||||
end,
|
||||
server = function(title, message, type, src)
|
||||
TriggerClientEvent('okokNotify:Alert', src, title, message, 6000, type)
|
||||
end,
|
||||
},
|
||||
qb = {
|
||||
client = function(title, message, type)
|
||||
TriggerEvent("QBCore:Notify", message, type)
|
||||
end,
|
||||
server = function(title, message, type, src)
|
||||
TriggerClientEvent("QBCore:Notify", src, message, type)
|
||||
end,
|
||||
},
|
||||
qs = {
|
||||
client = function(title, message, type)
|
||||
exports['qs-interface']:AddNotify(message, title, 6000)
|
||||
end,
|
||||
server = function(title, message, type, src)
|
||||
TriggerClientEvent('interface:notification', src, message, title, 6000)
|
||||
end,
|
||||
},
|
||||
ox = {
|
||||
client = function(title, message, type)
|
||||
exports.ox_lib:notify({ title = title, description = message, type = type or "success" })
|
||||
end,
|
||||
server = function(title, message, type, src)
|
||||
TriggerClientEvent('ox_lib:notify', src, { title = title, description = message, type = type or "success" })
|
||||
end,
|
||||
},
|
||||
gta = {
|
||||
client = function(title, message, type)
|
||||
exports.jim_bridge:Notify(title, message, type)
|
||||
end,
|
||||
server = function(title, message, type, src)
|
||||
TriggerClientEvent("jim-bridge:Notify", src, title, message, type)
|
||||
end,
|
||||
},
|
||||
esx = {
|
||||
client = function(title, message, type)
|
||||
exports["esx_notify"]:Notify(type, 4000, message)
|
||||
end,
|
||||
server = function(title, message, type, src)
|
||||
TriggerClientEvent(getScript()..":DisplayESXNotify", src, type, message)
|
||||
end,
|
||||
},
|
||||
lation = {
|
||||
client = function(title, message, type)
|
||||
exports.lation_ui:notify({ title = title, message = message, type = type or "success", })
|
||||
end,
|
||||
server = function(title, message, type, src)
|
||||
TriggerClientEvent("lation_ui:notify", src, { title = title, message = message, type = type or "success", })
|
||||
end,
|
||||
},
|
||||
red = {
|
||||
client = function(title, message, type)
|
||||
TriggerEvent("jim-redui:Notify", title, message, type)
|
||||
end,
|
||||
server = function(title, message, type, src)
|
||||
TriggerClientEvent("jim-redui:Notify", src, title, message, type)
|
||||
end,
|
||||
},
|
||||
}
|
||||
--- Displays notifications to the player using the configured notification system.
|
||||
---
|
||||
--- Supports multiple notification systems based on Config.System.Notify. Can be triggered from both
|
||||
@@ -32,65 +101,11 @@
|
||||
--- ```
|
||||
function triggerNotify(title, message, type, src)
|
||||
if not Config.System or not Config.System.Notify then debugPrint("Notify triggered but not set up") return end
|
||||
if Config.System.Notify == "okok" then
|
||||
if not src then
|
||||
TriggerEvent('okokNotify:Alert', title, message, 6000, type)
|
||||
else
|
||||
TriggerClientEvent('okokNotify:Alert', src, title, message, 6000, type)
|
||||
end
|
||||
elseif Config.System.Notify == "qb" then
|
||||
if not src then
|
||||
TriggerEvent("QBCore:Notify", message, type)
|
||||
else
|
||||
TriggerClientEvent("QBCore:Notify", src, message, type)
|
||||
end
|
||||
elseif Config.System.Notify == "qs" then
|
||||
if not src then
|
||||
exports['qs-interface']:AddNotify(message, title, 6000)
|
||||
else
|
||||
TriggerClientEvent('interface:notification', src, message, title, 6000)
|
||||
end
|
||||
elseif Config.System.Notify == "ox" then
|
||||
if not src then
|
||||
TriggerEvent('ox_lib:notify', { title = title, description = message, type = type or "success" })
|
||||
else
|
||||
TriggerClientEvent('ox_lib:notify', src, { title = title, description = message, type = type or "success" })
|
||||
end
|
||||
elseif Config.System.Notify == "gta" then
|
||||
if not src then
|
||||
exports.jim_bridge:Notify(title, message, type)
|
||||
else
|
||||
TriggerClientEvent("jim-bridge:Notify", src, title, message, type)
|
||||
end
|
||||
elseif Config.System.Notify == "esx" then
|
||||
if not src then
|
||||
exports["esx_notify"]:Notify(type, 4000, message)
|
||||
else
|
||||
TriggerClientEvent(getScript()..":DisplayESXNotify", src, type, message)
|
||||
end
|
||||
elseif Config.System.Notify == "lation" then
|
||||
if not src then
|
||||
exports.lation_ui:notify({
|
||||
title = title,
|
||||
message = message,
|
||||
type = type or "success",
|
||||
})
|
||||
else
|
||||
TriggerClientEvent("lation_ui:notify", src, {
|
||||
title = title,
|
||||
message = message,
|
||||
type = type or "success",
|
||||
})
|
||||
end
|
||||
|
||||
elseif Config.System.Notify == "red" then
|
||||
if isStarted("jim-redui") then
|
||||
if not src then
|
||||
TriggerEvent("jim-redui:Notify", title, message, type)
|
||||
if src then
|
||||
notifyFunc[Config.System.Notify].server(title, message, type, src)
|
||||
else
|
||||
TriggerClientEvent("jim-redui:Notify", src, title, message, type)
|
||||
end
|
||||
end
|
||||
notifyFunc[Config.System.Notify].client(title, message, type)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -103,7 +118,6 @@ end
|
||||
--- Listens for DisplayESXNotify events and triggers the ESX notification on the client.
|
||||
---
|
||||
--- @param type string The notification type.
|
||||
--- @param title string The notification title.
|
||||
--- @param text string The notification message.
|
||||
---
|
||||
--- @usage
|
||||
|
||||
Reference in New Issue
Block a user