2022-06-17 20:29:40 +02:00
|
|
|
local alert = nil
|
|
|
|
|
|
2022-09-18 09:06:32 +10:00
|
|
|
---@class AlertDialogProps
|
|
|
|
|
---@field header string;
|
|
|
|
|
---@field content string;
|
|
|
|
|
---@field centered? boolean?;
|
|
|
|
|
---@field cancel? boolean?;
|
|
|
|
|
|
|
|
|
|
---@param data AlertDialogProps
|
|
|
|
|
---@return 'cancel' | 'confirm' | nil
|
2022-06-11 11:33:15 +02:00
|
|
|
function lib.alertDialog(data)
|
2022-06-17 20:29:40 +02:00
|
|
|
if alert then return end
|
|
|
|
|
alert = promise.new()
|
|
|
|
|
|
2022-06-11 11:33:15 +02:00
|
|
|
SetNuiFocus(true, true)
|
|
|
|
|
SendNUIMessage({
|
|
|
|
|
action = 'sendAlert',
|
|
|
|
|
data = data
|
|
|
|
|
})
|
2022-06-17 20:29:40 +02:00
|
|
|
|
|
|
|
|
return Citizen.Await(alert)
|
2022-06-11 11:33:15 +02:00
|
|
|
end
|
|
|
|
|
|
2022-06-17 20:29:40 +02:00
|
|
|
RegisterNUICallback('closeAlert', function(data, cb)
|
2022-06-11 11:33:15 +02:00
|
|
|
cb(1)
|
|
|
|
|
SetNuiFocus(false, false)
|
2022-08-17 23:47:31 +02:00
|
|
|
local promise = alert
|
2022-06-17 20:29:40 +02:00
|
|
|
alert = nil
|
2022-08-17 23:47:31 +02:00
|
|
|
promise:resolve(data)
|
2022-06-17 01:23:56 -07:00
|
|
|
end)
|
|
|
|
|
|
2022-09-18 09:06:32 +10:00
|
|
|
RegisterNetEvent('ox_lib:alertDialog', lib.alertDialog)
|