Files
ox_lib/resource/interface/client/alert.lua

44 lines
937 B
Lua
Raw Normal View History

local alert = nil
---@class AlertDialogProps
---@field header string;
---@field content string;
---@field centered? boolean?;
---@field cancel? boolean?;
---@field labels? {cancel?: string, confirm?: string}
---@param data AlertDialogProps
---@return 'cancel' | 'confirm' | nil
2022-06-11 11:33:15 +02:00
function lib.alertDialog(data)
if alert then return end
alert = promise.new()
2022-06-11 11:33:15 +02:00
SetNuiFocus(true, true)
SendNUIMessage({
action = 'sendAlert',
data = data
})
return Citizen.Await(alert)
2022-06-11 11:33:15 +02:00
end
function lib.closeAlertDialog()
if not alert then return end
alert:resolve(nil)
alert = nil
SetNuiFocus(false, false)
SendNUIMessage({
action = 'closeAlertDialog'
})
end
RegisterNUICallback('closeAlert', function(data, cb)
2022-06-11 11:33:15 +02:00
cb(1)
SetNuiFocus(false, false)
local promise = alert
alert = nil
promise:resolve(data)
end)
RegisterNetEvent('ox_lib:alertDialog', lib.alertDialog)