2022-06-17 20:29:40 +02:00
|
|
|
local alert = nil
|
2022-12-30 11:16:33 +01:00
|
|
|
local keepInput = IsNuiFocusKeepingInput()
|
|
|
|
|
|
|
|
|
|
local function resetFocus()
|
|
|
|
|
SetNuiFocus(false, false)
|
|
|
|
|
SetNuiFocusKeepInput(keepInput)
|
|
|
|
|
end
|
2022-06-17 20:29:40 +02:00
|
|
|
|
2022-09-18 09:06:32 +10:00
|
|
|
---@class AlertDialogProps
|
|
|
|
|
---@field header string;
|
|
|
|
|
---@field content string;
|
|
|
|
|
---@field centered? boolean?;
|
|
|
|
|
---@field cancel? boolean?;
|
2022-12-08 11:46:21 +01:00
|
|
|
---@field labels? {cancel?: string, confirm?: string}
|
2022-09-18 09:06:32 +10:00
|
|
|
|
|
|
|
|
---@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-12-30 11:16:33 +01:00
|
|
|
keepInput = IsNuiFocusKeepingInput()
|
|
|
|
|
|
2022-06-11 11:33:15 +02:00
|
|
|
SetNuiFocus(true, true)
|
2022-12-30 11:16:33 +01:00
|
|
|
SetNuiFocusKeepInput(false)
|
2022-06-11 11:33:15 +02:00
|
|
|
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-09-29 11:39:30 +02:00
|
|
|
function lib.closeAlertDialog()
|
|
|
|
|
if not alert then return end
|
|
|
|
|
alert:resolve(nil)
|
|
|
|
|
alert = nil
|
2022-12-30 11:16:33 +01:00
|
|
|
resetFocus()
|
2022-09-29 11:39:30 +02:00
|
|
|
SendNUIMessage({
|
|
|
|
|
action = 'closeAlertDialog'
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
2022-06-17 20:29:40 +02:00
|
|
|
RegisterNUICallback('closeAlert', function(data, cb)
|
2022-06-11 11:33:15 +02:00
|
|
|
cb(1)
|
2022-12-30 11:16:33 +01:00
|
|
|
resetFocus()
|
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-12-30 11:16:33 +01:00
|
|
|
RegisterNetEvent('ox_lib:alertDialog', lib.alertDialog)
|